VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/fs/isomakercmd.cpp@ 107737

最後變更 在這個檔案從107737是 107737,由 vboxsync 提交於 2 月 前

src/VBox/Runtime/common/fs/isomakercmd.cpp: Fixed warnings found by Parfait (unread variable). jiraref:VBP-1424

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 163.2 KB
 
1/* $Id: isomakercmd.cpp 107737 2025-01-14 09:20:59Z vboxsync $ */
2/** @file
3 * IPRT - ISO Image Maker Command.
4 */
5
6/*
7 * Copyright (C) 2017-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.alldomusa.eu.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#define LOG_GROUP RTLOGGROUP_FS
42#include "internal/iprt.h"
43#include <iprt/fsisomaker.h>
44
45#include <iprt/asm.h>
46#include <iprt/assert.h>
47#include <iprt/buildconfig.h>
48#include <iprt/ctype.h>
49#include <iprt/file.h>
50#include <iprt/fsvfs.h>
51#include <iprt/err.h>
52#include <iprt/getopt.h>
53#include <iprt/log.h>
54#include <iprt/mem.h>
55#include <iprt/message.h>
56#include <iprt/path.h>
57#include <iprt/rand.h>
58#include <iprt/stream.h>
59#include <iprt/string.h>
60#include <iprt/vfs.h>
61#include <iprt/formats/iso9660.h>
62
63
64/*********************************************************************************************************************************
65* Defined Constants And Macros *
66*********************************************************************************************************************************/
67/** Maximum number of name specifiers we allow. */
68#define RTFSISOMAKERCMD_MAX_NAMES 8
69
70/** Maximum directory recursions when adding a directory tree. */
71#define RTFSISOMAKERCMD_MAX_DIR_RECURSIONS 32
72
73/** @name Name specifiers
74 * @{ */
75#define RTFSISOMAKERCMDNAME_PRIMARY_ISO RTFSISOMAKER_NAMESPACE_ISO_9660
76#define RTFSISOMAKERCMDNAME_JOLIET RTFSISOMAKER_NAMESPACE_JOLIET
77#define RTFSISOMAKERCMDNAME_UDF RTFSISOMAKER_NAMESPACE_UDF
78#define RTFSISOMAKERCMDNAME_HFS RTFSISOMAKER_NAMESPACE_HFS
79
80#define RTFSISOMAKERCMDNAME_PRIMARY_ISO_ROCK_RIDGE RT_BIT_32(16)
81#define RTFSISOMAKERCMDNAME_JOLIET_ROCK_RIDGE RT_BIT_32(17)
82
83#define RTFSISOMAKERCMDNAME_JOLIET_TRANS_TBL RT_BIT_32(20)
84#define RTFSISOMAKERCMDNAME_PRIMARY_ISO_TRANS_TBL RT_BIT_32(21)
85#define RTFSISOMAKERCMDNAME_UDF_TRANS_TBL RT_BIT_32(22)
86#define RTFSISOMAKERCMDNAME_HFS_TRANS_TBL RT_BIT_32(23)
87
88#define RTFSISOMAKERCMDNAME_MAJOR_MASK \
89 (RTFSISOMAKERCMDNAME_PRIMARY_ISO | RTFSISOMAKERCMDNAME_JOLIET | RTFSISOMAKERCMDNAME_UDF | RTFSISOMAKERCMDNAME_HFS)
90
91#define RTFSISOMAKERCMDNAME_MINOR_MASK \
92 ( RTFSISOMAKERCMDNAME_PRIMARY_ISO_ROCK_RIDGE | RTFSISOMAKERCMDNAME_PRIMARY_ISO_TRANS_TBL \
93 | RTFSISOMAKERCMDNAME_JOLIET_ROCK_RIDGE | RTFSISOMAKERCMDNAME_JOLIET_TRANS_TBL \
94 | RTFSISOMAKERCMDNAME_UDF_TRANS_TBL \
95 | RTFSISOMAKERCMDNAME_HFS_TRANS_TBL)
96AssertCompile((RTFSISOMAKERCMDNAME_MAJOR_MASK & RTFSISOMAKERCMDNAME_MINOR_MASK) == 0);
97/** @} */
98
99
100/*********************************************************************************************************************************
101* Structures and Typedefs *
102*********************************************************************************************************************************/
103typedef enum RTFSISOMAKERCMDOPT
104{
105 RTFSISOMAKERCMD_OPT_FIRST = 1000,
106
107 RTFSISOMAKERCMD_OPT_IPRT_ISO_MAKER_FILE_MARKER,
108 RTFSISOMAKERCMD_OPT_OUTPUT_BUFFER_SIZE,
109 RTFSISOMAKERCMD_OPT_RANDOM_OUTPUT_BUFFER_SIZE,
110 RTFSISOMAKERCMD_OPT_RANDOM_ORDER_VERIFICATION,
111 RTFSISOMAKERCMD_OPT_NAME_SETUP,
112 RTFSISOMAKERCMD_OPT_NAME_SETUP_FROM_IMPORT,
113
114 RTFSISOMAKERCMD_OPT_ROCK_RIDGE,
115 RTFSISOMAKERCMD_OPT_LIMITED_ROCK_RIDGE,
116 RTFSISOMAKERCMD_OPT_NO_ROCK_RIDGE,
117 RTFSISOMAKERCMD_OPT_NO_JOLIET,
118
119 RTFSISOMAKERCMD_OPT_IMPORT_ISO,
120 RTFSISOMAKERCMD_OPT_PUSH_ISO,
121 RTFSISOMAKERCMD_OPT_PUSH_ISO_NO_JOLIET,
122 RTFSISOMAKERCMD_OPT_PUSH_ISO_NO_ROCK,
123 RTFSISOMAKERCMD_OPT_PUSH_ISO_NO_ROCK_NO_JOLIET,
124 RTFSISOMAKERCMD_OPT_POP,
125
126 RTFSISOMAKERCMD_OPT_ELTORITO_NEW_ENTRY,
127 RTFSISOMAKERCMD_OPT_ELTORITO_ADD_IMAGE,
128 RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_12,
129 RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_144,
130 RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_288,
131
132 RTFSISOMAKERCMD_OPT_RATIONAL_ATTRIBS,
133 RTFSISOMAKERCMD_OPT_STRICT_ATTRIBS,
134 RTFSISOMAKERCMD_OPT_NO_FILE_MODE,
135 RTFSISOMAKERCMD_OPT_NO_DIR_MODE,
136 RTFSISOMAKERCMD_OPT_CHMOD,
137 RTFSISOMAKERCMD_OPT_CHOWN,
138 RTFSISOMAKERCMD_OPT_CHGRP,
139
140 /*
141 * Compatibility options:
142 */
143 RTFSISOMAKERCMD_OPT_ABSTRACT_FILE_ID,
144 RTFSISOMAKERCMD_OPT_ALLOW_LEADING_DOTS,
145 RTFSISOMAKERCMD_OPT_ALLOW_LIMITED_SIZE,
146 RTFSISOMAKERCMD_OPT_ALLOW_LOWERCASE,
147 RTFSISOMAKERCMD_OPT_ALLOW_MULTI_DOT,
148 RTFSISOMAKERCMD_OPT_ALPHA_BOOT,
149 RTFSISOMAKERCMD_OPT_APPLE,
150 RTFSISOMAKERCMD_OPT_BIBLIOGRAPHIC_FILE_ID,
151 RTFSISOMAKERCMD_OPT_CHECK_OLD_NAMES,
152 RTFSISOMAKERCMD_OPT_CHECK_SESSION,
153 RTFSISOMAKERCMD_OPT_COPYRIGHT_FILE_ID,
154 RTFSISOMAKERCMD_OPT_DETECT_HARDLINKS,
155 RTFSISOMAKERCMD_OPT_DIR_MODE,
156 RTFSISOMAKERCMD_OPT_DVD_VIDEO,
157 RTFSISOMAKERCMD_OPT_ELTORITO_PLATFORM_ID,
158 RTFSISOMAKERCMD_OPT_ELTORITO_HARD_DISK_BOOT,
159 RTFSISOMAKERCMD_OPT_ELTORITO_INFO_TABLE,
160 RTFSISOMAKERCMD_OPT_ELTORITO_LOAD_SEG,
161 RTFSISOMAKERCMD_OPT_ELTORITO_LOAD_SIZE,
162 RTFSISOMAKERCMD_OPT_ELTORITO_NO_BOOT,
163 RTFSISOMAKERCMD_OPT_ELTORITO_NO_EMULATION_BOOT,
164 RTFSISOMAKERCMD_OPT_EXCLUDE_LIST,
165 RTFSISOMAKERCMD_OPT_FILE_MODE,
166 RTFSISOMAKERCMD_OPT_FORCE_RR,
167 RTFSISOMAKERCMD_OPT_GID,
168 RTFSISOMAKERCMD_OPT_GRAFT_POINTS,
169 RTFSISOMAKERCMD_OPT_GUI,
170 RTFSISOMAKERCMD_OPT_HFS_AUTO,
171 RTFSISOMAKERCMD_OPT_HFS_BLESS,
172 RTFSISOMAKERCMD_OPT_HFS_BOOT_FILE,
173 RTFSISOMAKERCMD_OPT_HFS_CAP,
174 RTFSISOMAKERCMD_OPT_HFS_CHRP_BOOT,
175 RTFSISOMAKERCMD_OPT_HFS_CLUSTER_SIZE,
176 RTFSISOMAKERCMD_OPT_HFS_CREATOR,
177 RTFSISOMAKERCMD_OPT_HFS_DAVE,
178 RTFSISOMAKERCMD_OPT_HFS_DOUBLE,
179 RTFSISOMAKERCMD_OPT_HFS_ENABLE,
180 RTFSISOMAKERCMD_OPT_HFS_ETHERSHARE,
181 RTFSISOMAKERCMD_OPT_HFS_EXCHANGE,
182 RTFSISOMAKERCMD_OPT_HFS_HIDE,
183 RTFSISOMAKERCMD_OPT_HFS_HIDE_LIST,
184 RTFSISOMAKERCMD_OPT_HFS_ICON_POSITION,
185 RTFSISOMAKERCMD_OPT_HFS_INPUT_CHARSET,
186 RTFSISOMAKERCMD_OPT_HFS_MAC_NAME,
187 RTFSISOMAKERCMD_OPT_HFS_MACBIN,
188 RTFSISOMAKERCMD_OPT_HFS_MAGIC,
189 RTFSISOMAKERCMD_OPT_HFS_MAP,
190 RTFSISOMAKERCMD_OPT_HFS_NETATALK,
191 RTFSISOMAKERCMD_OPT_HFS_NO_DESKTOP,
192 RTFSISOMAKERCMD_OPT_HFS_OSX_DOUBLE,
193 RTFSISOMAKERCMD_OPT_HFS_OSX_HFS,
194 RTFSISOMAKERCMD_OPT_HFS_OUTPUT_CHARSET,
195 RTFSISOMAKERCMD_OPT_HFS_PARMS,
196 RTFSISOMAKERCMD_OPT_HFS_PART,
197 RTFSISOMAKERCMD_OPT_HFS_PREP_BOOT,
198 RTFSISOMAKERCMD_OPT_HFS_PROBE,
199 RTFSISOMAKERCMD_OPT_HFS_ROOT_INFO,
200 RTFSISOMAKERCMD_OPT_HFS_SFM,
201 RTFSISOMAKERCMD_OPT_HFS_SGI,
202 RTFSISOMAKERCMD_OPT_HFS_SINGLE,
203 RTFSISOMAKERCMD_OPT_HFS_TYPE,
204 RTFSISOMAKERCMD_OPT_HFS_UNLOCK,
205 RTFSISOMAKERCMD_OPT_HFS_USHARE,
206 RTFSISOMAKERCMD_OPT_HFS_VOL_ID,
207 RTFSISOMAKERCMD_OPT_HFS_XINET,
208 RTFSISOMAKERCMD_OPT_HIDDEN,
209 RTFSISOMAKERCMD_OPT_HIDDEN_LIST,
210 RTFSISOMAKERCMD_OPT_HIDE,
211 RTFSISOMAKERCMD_OPT_HIDE_JOLIET,
212 RTFSISOMAKERCMD_OPT_HIDE_JOLIET_LIST,
213 RTFSISOMAKERCMD_OPT_HIDE_JOLIET_TRANS_TBL,
214 RTFSISOMAKERCMD_OPT_HIDE_LIST,
215 RTFSISOMAKERCMD_OPT_HIDE_RR_MOVED,
216 RTFSISOMAKERCMD_OPT_HPPA_BOOTLOADER,
217 RTFSISOMAKERCMD_OPT_HPPA_CMDLINE,
218 RTFSISOMAKERCMD_OPT_HPPA_KERNEL_32,
219 RTFSISOMAKERCMD_OPT_HPPA_KERNEL_64,
220 RTFSISOMAKERCMD_OPT_HPPA_RAMDISK,
221 RTFSISOMAKERCMD_OPT_INPUT_CHARSET,
222 RTFSISOMAKERCMD_OPT_ISO_LEVEL,
223 RTFSISOMAKERCMD_OPT_JIGDO_COMPRESS,
224 RTFSISOMAKERCMD_OPT_JIGDO_EXCLUDE,
225 RTFSISOMAKERCMD_OPT_JIGDO_FORCE_MD5,
226 RTFSISOMAKERCMD_OPT_JIGDO_JIGDO,
227 RTFSISOMAKERCMD_OPT_JIGDO_MAP,
228 RTFSISOMAKERCMD_OPT_JIGDO_MD5_LIST,
229 RTFSISOMAKERCMD_OPT_JIGDO_MIN_FILE_SIZE,
230 RTFSISOMAKERCMD_OPT_JIGDO_TEMPLATE,
231 RTFSISOMAKERCMD_OPT_JOLIET_CHARSET,
232 RTFSISOMAKERCMD_OPT_JOLIET_LEVEL,
233 RTFSISOMAKERCMD_OPT_JOLIET_LONG,
234 RTFSISOMAKERCMD_OPT_LOG_FILE,
235 RTFSISOMAKERCMD_OPT_MAX_ISO9660_FILENAMES,
236 RTFSISOMAKERCMD_OPT_MIPS_BOOT,
237 RTFSISOMAKERCMD_OPT_MIPSEL_BOOT,
238 RTFSISOMAKERCMD_OPT_NEW_DIR_MODE,
239 RTFSISOMAKERCMD_OPT_NO_BACKUP_FILES,
240 RTFSISOMAKERCMD_OPT_NO_DETECT_HARDLINKS,
241 RTFSISOMAKERCMD_OPT_NO_ISO_TRANSLATE,
242 RTFSISOMAKERCMD_OPT_NO_PAD,
243 RTFSISOMAKERCMD_OPT_NO_RR,
244 RTFSISOMAKERCMD_OPT_NO_SPLIT_SYMLINK_COMPONENTS,
245 RTFSISOMAKERCMD_OPT_NO_SPLIT_SYMLINK_FIELDS,
246 RTFSISOMAKERCMD_OPT_OLD_ROOT,
247 RTFSISOMAKERCMD_OPT_OUTPUT_CHARSET,
248 RTFSISOMAKERCMD_OPT_PAD,
249 RTFSISOMAKERCMD_OPT_PATH_LIST,
250 RTFSISOMAKERCMD_OPT_PRINT_SIZE,
251 RTFSISOMAKERCMD_OPT_QUIET,
252 RTFSISOMAKERCMD_OPT_RELAXED_FILENAMES,
253 RTFSISOMAKERCMD_OPT_ROOT,
254 RTFSISOMAKERCMD_OPT_SORT,
255 RTFSISOMAKERCMD_OPT_SPARC_BOOT,
256 RTFSISOMAKERCMD_OPT_SPARC_LABEL,
257 RTFSISOMAKERCMD_OPT_SPLIT_OUTPUT,
258 RTFSISOMAKERCMD_OPT_STREAM_FILE_NAME,
259 RTFSISOMAKERCMD_OPT_STREAM_MEDIA_SIZE,
260 RTFSISOMAKERCMD_OPT_SUNX86_BOOT,
261 RTFSISOMAKERCMD_OPT_SUNX86_LABEL,
262 RTFSISOMAKERCMD_OPT_SYSTEM_ID,
263 RTFSISOMAKERCMD_OPT_TRANS_TBL_NAME,
264 RTFSISOMAKERCMD_OPT_UDF,
265 RTFSISOMAKERCMD_OPT_UID,
266 RTFSISOMAKERCMD_OPT_USE_FILE_VERSION,
267 RTFSISOMAKERCMD_OPT_VOLUME_ID,
268 RTFSISOMAKERCMD_OPT_VOLUME_SET_ID,
269 RTFSISOMAKERCMD_OPT_VOLUME_SET_SEQ_NO,
270 RTFSISOMAKERCMD_OPT_VOLUME_SET_SIZE,
271 RTFSISOMAKERCMD_OPT_END
272} RTFSISOMAKERCMDOPT;
273
274
275/**
276 * El Torito boot entry.
277 */
278typedef struct RTFSISOMKCMDELTORITOENTRY
279{
280 /** The type of this entry. */
281 enum
282 {
283 kEntryType_Invalid = 0,
284 kEntryType_Validation, /**< Same as kEntryType_SectionHeader, just hardcoded #0. */
285 kEntryType_SectionHeader,
286 kEntryType_Default, /**< Same as kEntryType_Section, just hardcoded #1. */
287 kEntryType_Section
288 } enmType;
289 /** Type specific data. */
290 union
291 {
292 struct
293 {
294 /** The platform ID (ISO9660_ELTORITO_PLATFORM_ID_XXX). */
295 uint8_t idPlatform;
296 /** Some string for the header. */
297 const char *pszString;
298 } Validation,
299 SectionHeader;
300 struct
301 {
302 /** The name of the boot image wihtin the ISO (-b option). */
303 const char *pszImageNameInIso;
304 /** The object ID of the image in the ISO. This is set to UINT32_MAX when
305 * pszImageNameInIso is used (i.e. -b option) and we've delayed everything
306 * boot related till after all files have been added to the image. */
307 uint32_t idxImageObj;
308 /** Whether to insert boot info table into the image. */
309 bool fInsertBootInfoTable;
310 /** Bootble or not. Possible to make BIOS set up emulation w/o booting it. */
311 bool fBootable;
312 /** The media type (ISO9660_ELTORITO_BOOT_MEDIA_TYPE_XXX). */
313 uint8_t bBootMediaType;
314 /** File system / partition type. */
315 uint8_t bSystemType;
316 /** Load address divided by 0x10. */
317 uint16_t uLoadSeg;
318 /** Number of sectors (512) to load. */
319 uint16_t cSectorsToLoad;
320 } Section,
321 Default;
322 } u;
323} RTFSISOMKCMDELTORITOENTRY;
324/** Pointer to an el torito boot entry. */
325typedef RTFSISOMKCMDELTORITOENTRY *PRTFSISOMKCMDELTORITOENTRY;
326
327/**
328 * ISO maker command options & state.
329 */
330typedef struct RTFSISOMAKERCMDOPTS
331{
332 /** The handle to the ISO maker. */
333 RTFSISOMAKER hIsoMaker;
334 /** Set if we're creating a virtual image maker, i.e. producing something
335 * that is going to be read from only and not written to disk. */
336 bool fVirtualImageMaker;
337 /** Extended error info. This is a stderr alternative for the
338 * fVirtualImageMaker case (stdout goes to LogRel). */
339 PRTERRINFO pErrInfo;
340
341 /** The output file.
342 * This is NULL when fVirtualImageMaker is set. */
343 const char *pszOutFile;
344 /** Special buffer size to use for testing the ISO maker code reading. */
345 uint32_t cbOutputReadBuffer;
346 /** Use random output read buffer size. cbOutputReadBuffer works as maximum
347 * when this is enabled. */
348 bool fRandomOutputReadBufferSize;
349 /** Do output verification, but do it in random order if non-zero. The
350 * values gives the block size to use. */
351 uint32_t cbRandomOrderVerifciationBlock;
352
353 /** Index of the top source stack entry, -1 if empty. */
354 int32_t iSrcStack;
355 struct
356 {
357 /** The root VFS dir or the CWD for relative paths. */
358 RTVFSDIR hSrcDir;
359 /** The current source VFS, NIL_RTVFS if the regular file system is used. */
360 RTVFS hSrcVfs;
361 /** The specifier for hSrcVfs (error messages). */
362 const char *pszSrcVfs;
363 /** The option for hSrcVfs.
364 * This is NULL for a CWD passed via the API that shouldn't be popped. */
365 const char *pszSrcVfsOption;
366 } aSrcStack[5];
367
368 /** @name Processing of inputs
369 * @{ */
370 /** The namespaces (RTFSISOMAKER_NAMESPACE_XXX) we're currently adding
371 * input to. */
372 uint32_t fDstNamespaces;
373 /** The number of name specifiers we're currently operating with. */
374 uint32_t cNameSpecifiers;
375 /** Name specifier configurations.
376 * For instance given "name0=name1=name2=name3=source-file" we will add
377 * source-file to the image with name0 as the name in the namespace and
378 * sub-name specified by aNameSpecifiers[0], name1 in aNameSpecifiers[1],
379 * and so on. This allows exact control over which names a file will
380 * have in each namespace (primary-iso, joliet, udf, hfs) and sub-namespace
381 * (rock-ridge, trans.tbl).
382 */
383 uint32_t afNameSpecifiers[RTFSISOMAKERCMD_MAX_NAMES];
384 /** The forced directory mode. */
385 RTFMODE fDirMode;
386 /** Set if fDirMode should be applied. */
387 bool fDirModeActive;
388 /** Set if fFileMode should be applied. */
389 bool fFileModeActive;
390 /** The force file mode. */
391 RTFMODE fFileMode;
392 /** @} */
393
394 /** @name Booting related options and state.
395 * @{ */
396 /** Number of boot catalog entries (aBootCatEntries). */
397 uint32_t cBootCatEntries;
398 /** Boot catalog entries. */
399 RTFSISOMKCMDELTORITOENTRY aBootCatEntries[64];
400 /** @} */
401
402 /** @name Filtering
403 * @{ */
404 /** The trans.tbl filename when enabled. We must not import these files. */
405 const char *pszTransTbl;
406 /** @} */
407
408 /** Number of items (files, directories, images, whatever) we've added. */
409 uint32_t cItemsAdded;
410} RTFSISOMAKERCMDOPTS;
411typedef RTFSISOMAKERCMDOPTS *PRTFSISOMAKERCMDOPTS;
412typedef RTFSISOMAKERCMDOPTS const *PCRTFSISOMAKERCMDOPTS;
413
414
415/**
416 * One parsed name.
417 */
418typedef struct RTFSISOMKCMDPARSEDNAME
419{
420 /** Copy of the corresponding RTFSISOMAKERCMDOPTS::afNameSpecifiers
421 * value. */
422 uint32_t fNameSpecifiers;
423 /** The length of the specified path. */
424 uint32_t cchPath;
425 /** Specified path. */
426 char szPath[RTPATH_MAX];
427} RTFSISOMKCMDPARSEDNAME;
428/** Pointer to a parsed name. */
429typedef RTFSISOMKCMDPARSEDNAME *PRTFSISOMKCMDPARSEDNAME;
430/** Pointer to a const parsed name. */
431typedef RTFSISOMKCMDPARSEDNAME const *PCRTFSISOMKCMDPARSEDNAME;
432
433
434/**
435 * Parsed names.
436 */
437typedef struct RTFSISOMKCMDPARSEDNAMES
438{
439 /** Number of names. */
440 uint32_t cNames;
441 /** Number of names with the source. */
442 uint32_t cNamesWithSrc;
443 /** Special source types.
444 * Used for conveying commands to do on names intead of adding a source.
445 * Only used when adding generic stuff w/o any options involved. */
446 enum
447 {
448 kSrcType_None,
449 kSrcType_Normal,
450 kSrcType_NormalSrcStack,
451 kSrcType_Remove,
452 kSrcType_MustRemove
453 } enmSrcType;
454 /** The parsed names. */
455 RTFSISOMKCMDPARSEDNAME aNames[RTFSISOMAKERCMD_MAX_NAMES + 1];
456} RTFSISOMKCMDPARSEDNAMES;
457/** Pointer to parsed names. */
458typedef RTFSISOMKCMDPARSEDNAMES *PRTFSISOMKCMDPARSEDNAMES;
459/** Pointer to const parsed names. */
460typedef RTFSISOMKCMDPARSEDNAMES *PCRTFSISOMKCMDPARSEDNAMES;
461
462
463/*********************************************************************************************************************************
464* Global Variables *
465*********************************************************************************************************************************/
466/*
467 * Parse the command line. This is similar to genisoimage and mkisofs,
468 * thus the single dash long name aliases.
469 */
470static const RTGETOPTDEF g_aRtFsIsoMakerOptions[] =
471{
472 /*
473 * Unique IPRT ISO maker options.
474 */
475 { "--name-setup", RTFSISOMAKERCMD_OPT_NAME_SETUP, RTGETOPT_REQ_STRING },
476 { "--name-setup-from-import", RTFSISOMAKERCMD_OPT_NAME_SETUP_FROM_IMPORT, RTGETOPT_REQ_NOTHING },
477 { "--import-iso", RTFSISOMAKERCMD_OPT_IMPORT_ISO, RTGETOPT_REQ_STRING },
478 { "--push-iso", RTFSISOMAKERCMD_OPT_PUSH_ISO, RTGETOPT_REQ_STRING },
479 { "--push-iso-no-joliet", RTFSISOMAKERCMD_OPT_PUSH_ISO_NO_JOLIET, RTGETOPT_REQ_STRING },
480 { "--push-iso-no-rock", RTFSISOMAKERCMD_OPT_PUSH_ISO_NO_ROCK, RTGETOPT_REQ_STRING },
481 { "--push-iso-no-rock-no-joliet", RTFSISOMAKERCMD_OPT_PUSH_ISO_NO_ROCK_NO_JOLIET, RTGETOPT_REQ_STRING },
482 { "--pop", RTFSISOMAKERCMD_OPT_POP, RTGETOPT_REQ_NOTHING },
483
484 { "--rock-ridge", RTFSISOMAKERCMD_OPT_ROCK_RIDGE, RTGETOPT_REQ_NOTHING },
485 { "--limited-rock-ridge", RTFSISOMAKERCMD_OPT_LIMITED_ROCK_RIDGE, RTGETOPT_REQ_NOTHING },
486 { "--no-rock-ridge", RTFSISOMAKERCMD_OPT_NO_ROCK_RIDGE, RTGETOPT_REQ_NOTHING },
487 { "--no-joliet", RTFSISOMAKERCMD_OPT_NO_JOLIET, RTGETOPT_REQ_NOTHING },
488 { "--joliet-ucs-level", RTFSISOMAKERCMD_OPT_JOLIET_LEVEL, RTGETOPT_REQ_UINT8 },
489
490 { "--rational-attribs", RTFSISOMAKERCMD_OPT_RATIONAL_ATTRIBS, RTGETOPT_REQ_NOTHING },
491 { "--strict-attribs", RTFSISOMAKERCMD_OPT_STRICT_ATTRIBS, RTGETOPT_REQ_NOTHING },
492 { "--no-file-mode", RTFSISOMAKERCMD_OPT_NO_FILE_MODE, RTGETOPT_REQ_NOTHING },
493 { "--no-dir-mode", RTFSISOMAKERCMD_OPT_NO_DIR_MODE, RTGETOPT_REQ_NOTHING },
494 { "--chmod", RTFSISOMAKERCMD_OPT_CHMOD, RTGETOPT_REQ_STRING },
495 { "--chown", RTFSISOMAKERCMD_OPT_CHOWN, RTGETOPT_REQ_STRING },
496 { "--chgrp", RTFSISOMAKERCMD_OPT_CHGRP, RTGETOPT_REQ_STRING },
497
498 { "--eltorito-new-entry", RTFSISOMAKERCMD_OPT_ELTORITO_NEW_ENTRY, RTGETOPT_REQ_NOTHING },
499 { "--eltorito-add-image", RTFSISOMAKERCMD_OPT_ELTORITO_ADD_IMAGE, RTGETOPT_REQ_STRING },
500 { "--eltorito-floppy-12", RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_12, RTGETOPT_REQ_NOTHING },
501 { "--eltorito-floppy-144", RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_144, RTGETOPT_REQ_NOTHING },
502 { "--eltorito-floppy-288", RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_288, RTGETOPT_REQ_NOTHING },
503
504 { "--iprt-iso-maker-file-marker", RTFSISOMAKERCMD_OPT_IPRT_ISO_MAKER_FILE_MARKER, RTGETOPT_REQ_STRING },
505 { "--iprt-iso-maker-file-marker-ms", RTFSISOMAKERCMD_OPT_IPRT_ISO_MAKER_FILE_MARKER, RTGETOPT_REQ_STRING },
506 { "--iprt-iso-maker-file-marker-ms-crt", RTFSISOMAKERCMD_OPT_IPRT_ISO_MAKER_FILE_MARKER, RTGETOPT_REQ_STRING },
507 { "--iprt-iso-maker-file-marker-bourne", RTFSISOMAKERCMD_OPT_IPRT_ISO_MAKER_FILE_MARKER, RTGETOPT_REQ_STRING },
508 { "--iprt-iso-maker-file-marker-bourne-sh", RTFSISOMAKERCMD_OPT_IPRT_ISO_MAKER_FILE_MARKER, RTGETOPT_REQ_STRING },
509
510 { "--output-buffer-size", RTFSISOMAKERCMD_OPT_OUTPUT_BUFFER_SIZE, RTGETOPT_REQ_UINT32 },
511 { "--random-output-buffer-size", RTFSISOMAKERCMD_OPT_RANDOM_OUTPUT_BUFFER_SIZE, RTGETOPT_REQ_NOTHING },
512 { "--random-order-verification", RTFSISOMAKERCMD_OPT_RANDOM_ORDER_VERIFICATION, RTGETOPT_REQ_UINT32 },
513
514#define DD(a_szLong, a_chShort, a_fFlags) { a_szLong, a_chShort, a_fFlags }, { "-" a_szLong, a_chShort, a_fFlags }
515
516 /*
517 * genisoimage/mkisofs compatibility options we've implemented:
518 */
519 /* booting: */
520 { "--generic-boot", 'G', RTGETOPT_REQ_STRING },
521 DD("-eltorito-boot", 'b', RTGETOPT_REQ_STRING ),
522 DD("-eltorito-alt-boot", RTFSISOMAKERCMD_OPT_ELTORITO_NEW_ENTRY, RTGETOPT_REQ_NOTHING ),
523 DD("-eltorito-platform-id", RTFSISOMAKERCMD_OPT_ELTORITO_PLATFORM_ID, RTGETOPT_REQ_STRING ),
524 DD("-hard-disk-boot", RTFSISOMAKERCMD_OPT_ELTORITO_HARD_DISK_BOOT, RTGETOPT_REQ_NOTHING ),
525 DD("-no-emulation-boot", RTFSISOMAKERCMD_OPT_ELTORITO_NO_EMULATION_BOOT, RTGETOPT_REQ_NOTHING ),
526 DD("-no-boot", RTFSISOMAKERCMD_OPT_ELTORITO_NO_BOOT, RTGETOPT_REQ_NOTHING ),
527 DD("-boot-load-seg", RTFSISOMAKERCMD_OPT_ELTORITO_LOAD_SEG, RTGETOPT_REQ_UINT16 ),
528 DD("-boot-load-size", RTFSISOMAKERCMD_OPT_ELTORITO_LOAD_SIZE, RTGETOPT_REQ_UINT16 ),
529 DD("-boot-info-table", RTFSISOMAKERCMD_OPT_ELTORITO_INFO_TABLE, RTGETOPT_REQ_NOTHING ),
530 { "--boot-catalog", 'c', RTGETOPT_REQ_STRING },
531
532 /* String props: */
533 DD("-abstract", RTFSISOMAKERCMD_OPT_ABSTRACT_FILE_ID, RTGETOPT_REQ_STRING ),
534 { "--application-id", 'A', RTGETOPT_REQ_STRING },
535 DD("-biblio", RTFSISOMAKERCMD_OPT_BIBLIOGRAPHIC_FILE_ID, RTGETOPT_REQ_STRING ),
536 DD("-copyright", RTFSISOMAKERCMD_OPT_COPYRIGHT_FILE_ID, RTGETOPT_REQ_STRING ),
537 DD("-publisher", 'P', RTGETOPT_REQ_STRING ),
538 { "--preparer", 'p', RTGETOPT_REQ_STRING },
539 DD("-sysid", RTFSISOMAKERCMD_OPT_SYSTEM_ID, RTGETOPT_REQ_STRING ),
540 { "--volume-id", RTFSISOMAKERCMD_OPT_VOLUME_ID, RTGETOPT_REQ_STRING }, /* should've been '-V' */
541 DD("-volid", RTFSISOMAKERCMD_OPT_VOLUME_ID, RTGETOPT_REQ_STRING ),
542 DD("-volset", RTFSISOMAKERCMD_OPT_VOLUME_SET_ID, RTGETOPT_REQ_STRING ),
543
544 /* Other: */
545 DD("-file-mode", RTFSISOMAKERCMD_OPT_FILE_MODE, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_OCT ),
546 DD("-dir-mode", RTFSISOMAKERCMD_OPT_DIR_MODE, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_OCT ),
547 DD("-new-dir-mode", RTFSISOMAKERCMD_OPT_NEW_DIR_MODE, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_OCT ),
548 DD("-graft-points", RTFSISOMAKERCMD_OPT_GRAFT_POINTS, RTGETOPT_REQ_NOTHING ),
549 DD("--iso-level", RTFSISOMAKERCMD_OPT_ISO_LEVEL, RTGETOPT_REQ_UINT8 ),
550 { "--long-names", 'l', RTGETOPT_REQ_NOTHING },
551 { "--output", 'o', RTGETOPT_REQ_STRING },
552 { "--joliet", 'J', RTGETOPT_REQ_NOTHING },
553 DD("-ucs-level", RTFSISOMAKERCMD_OPT_JOLIET_LEVEL, RTGETOPT_REQ_UINT8 ),
554 DD("-rock", 'R', RTGETOPT_REQ_NOTHING ),
555 DD("-rational-rock", 'r', RTGETOPT_REQ_NOTHING ),
556 DD("-pad", RTFSISOMAKERCMD_OPT_PAD, RTGETOPT_REQ_NOTHING ),
557 DD("-no-pad", RTFSISOMAKERCMD_OPT_NO_PAD, RTGETOPT_REQ_NOTHING ),
558
559 /*
560 * genisoimage/mkisofs compatibility:
561 */
562 DD("-allow-limited-size", RTFSISOMAKERCMD_OPT_ALLOW_LIMITED_SIZE, RTGETOPT_REQ_NOTHING ),
563 DD("-allow-leading-dots", RTFSISOMAKERCMD_OPT_ALLOW_LEADING_DOTS, RTGETOPT_REQ_NOTHING ),
564 DD("-ldots", RTFSISOMAKERCMD_OPT_ALLOW_LEADING_DOTS, RTGETOPT_REQ_NOTHING ),
565 DD("-allow-lowercase", RTFSISOMAKERCMD_OPT_ALLOW_LOWERCASE, RTGETOPT_REQ_NOTHING ),
566 DD("-allow-multidot", RTFSISOMAKERCMD_OPT_ALLOW_MULTI_DOT, RTGETOPT_REQ_NOTHING ),
567 DD("-cache-inodes", RTFSISOMAKERCMD_OPT_DETECT_HARDLINKS, RTGETOPT_REQ_NOTHING ),
568 DD("-no-cache-inodes", RTFSISOMAKERCMD_OPT_NO_DETECT_HARDLINKS, RTGETOPT_REQ_NOTHING ),
569 DD("-alpha-boot", RTFSISOMAKERCMD_OPT_ALPHA_BOOT, RTGETOPT_REQ_STRING ),
570 DD("-hppa-bootloader", RTFSISOMAKERCMD_OPT_HPPA_BOOTLOADER, RTGETOPT_REQ_STRING ),
571 DD("-hppa-cmdline", RTFSISOMAKERCMD_OPT_HPPA_CMDLINE, RTGETOPT_REQ_STRING ),
572 DD("-hppa-kernel-32", RTFSISOMAKERCMD_OPT_HPPA_KERNEL_32, RTGETOPT_REQ_STRING ),
573 DD("-hppa-kernel-64", RTFSISOMAKERCMD_OPT_HPPA_KERNEL_64, RTGETOPT_REQ_STRING ),
574 DD("-hppa-ramdisk", RTFSISOMAKERCMD_OPT_HPPA_RAMDISK, RTGETOPT_REQ_STRING ),
575 DD("-mips-boot", RTFSISOMAKERCMD_OPT_MIPS_BOOT, RTGETOPT_REQ_STRING ),
576 DD("-mipsel-boot", RTFSISOMAKERCMD_OPT_MIPSEL_BOOT, RTGETOPT_REQ_STRING ),
577 DD("-sparc-boot", 'B', RTGETOPT_REQ_STRING ),
578 { "--cd-extra", 'C', RTGETOPT_REQ_STRING },
579 DD("-check-oldnames", RTFSISOMAKERCMD_OPT_CHECK_OLD_NAMES, RTGETOPT_REQ_NOTHING ),
580 DD("-check-session", RTFSISOMAKERCMD_OPT_CHECK_SESSION, RTGETOPT_REQ_STRING ),
581 { "--dont-append-dot", 'd', RTGETOPT_REQ_NOTHING },
582 { "--deep-directories", 'D', RTGETOPT_REQ_NOTHING },
583 DD("-dvd-video", RTFSISOMAKERCMD_OPT_DVD_VIDEO, RTGETOPT_REQ_NOTHING ),
584 DD("-follow-symlinks", 'f', RTGETOPT_REQ_NOTHING ),
585 DD("-gid", RTFSISOMAKERCMD_OPT_GID, RTGETOPT_REQ_UINT32 ),
586 DD("-gui", RTFSISOMAKERCMD_OPT_GUI, RTGETOPT_REQ_NOTHING ),
587 DD("-hide", RTFSISOMAKERCMD_OPT_HIDE, RTGETOPT_REQ_STRING ),
588 DD("-hide-list", RTFSISOMAKERCMD_OPT_HIDE_LIST, RTGETOPT_REQ_STRING ),
589 DD("-hidden", RTFSISOMAKERCMD_OPT_HIDDEN, RTGETOPT_REQ_STRING ),
590 DD("-hidden-list", RTFSISOMAKERCMD_OPT_HIDDEN_LIST, RTGETOPT_REQ_STRING ),
591 DD("-hide-joliet", RTFSISOMAKERCMD_OPT_HIDE_JOLIET, RTGETOPT_REQ_STRING ),
592 DD("-hide-joliet-list", RTFSISOMAKERCMD_OPT_HIDE_JOLIET_LIST, RTGETOPT_REQ_STRING ),
593 DD("-hide-joliet-trans-tbl", RTFSISOMAKERCMD_OPT_HIDE_JOLIET_TRANS_TBL, RTGETOPT_REQ_NOTHING ),
594 DD("-hide-rr-moved", RTFSISOMAKERCMD_OPT_HIDE_RR_MOVED, RTGETOPT_REQ_NOTHING ),
595 DD("-input-charset", RTFSISOMAKERCMD_OPT_INPUT_CHARSET, RTGETOPT_REQ_STRING ),
596 DD("-output-charset", RTFSISOMAKERCMD_OPT_OUTPUT_CHARSET, RTGETOPT_REQ_STRING ),
597 DD("-joliet-long", RTFSISOMAKERCMD_OPT_JOLIET_LONG, RTGETOPT_REQ_NOTHING ),
598 DD("-jcharset", RTFSISOMAKERCMD_OPT_JOLIET_CHARSET, RTGETOPT_REQ_STRING ),
599 { "--leading-dot", 'L', RTGETOPT_REQ_NOTHING },
600 DD("-jigdo-jigdo", RTFSISOMAKERCMD_OPT_JIGDO_JIGDO, RTGETOPT_REQ_STRING ),
601 DD("-jigdo-template", RTFSISOMAKERCMD_OPT_JIGDO_TEMPLATE, RTGETOPT_REQ_STRING ),
602 DD("-jigdo-min-file-size", RTFSISOMAKERCMD_OPT_JIGDO_MIN_FILE_SIZE, RTGETOPT_REQ_UINT64 ),
603 DD("-jigdo-force-md5", RTFSISOMAKERCMD_OPT_JIGDO_FORCE_MD5, RTGETOPT_REQ_STRING ),
604 DD("-jigdo-exclude", RTFSISOMAKERCMD_OPT_JIGDO_EXCLUDE, RTGETOPT_REQ_STRING ),
605 DD("-jigdo-map", RTFSISOMAKERCMD_OPT_JIGDO_MAP, RTGETOPT_REQ_STRING ),
606 DD("-md5-list", RTFSISOMAKERCMD_OPT_JIGDO_MD5_LIST, RTGETOPT_REQ_STRING ),
607 DD("-jigdo-template-compress", RTFSISOMAKERCMD_OPT_JIGDO_COMPRESS, RTGETOPT_REQ_STRING ),
608 DD("-log-file", RTFSISOMAKERCMD_OPT_LOG_FILE, RTGETOPT_REQ_STRING ),
609 { "--exclude", 'm', RTGETOPT_REQ_STRING },
610 { "--exclude", 'x', RTGETOPT_REQ_STRING },
611 DD("-exclude-list", RTFSISOMAKERCMD_OPT_EXCLUDE_LIST, RTGETOPT_REQ_STRING ),
612 DD("-max-iso9660-filenames", RTFSISOMAKERCMD_OPT_MAX_ISO9660_FILENAMES, RTGETOPT_REQ_NOTHING ),
613 { "--merge", 'M', RTGETOPT_REQ_STRING },
614 DD("-dev", 'M', RTGETOPT_REQ_STRING ),
615 { "--omit-version-numbers", 'N', RTGETOPT_REQ_NOTHING },
616 DD("-nobak", RTFSISOMAKERCMD_OPT_NO_BACKUP_FILES, RTGETOPT_REQ_NOTHING ),
617 DD("-no-bak", RTFSISOMAKERCMD_OPT_NO_BACKUP_FILES, RTGETOPT_REQ_NOTHING ),
618 DD("-force-rr", RTFSISOMAKERCMD_OPT_FORCE_RR, RTGETOPT_REQ_NOTHING ),
619 DD("-no-rr", RTFSISOMAKERCMD_OPT_NO_RR, RTGETOPT_REQ_NOTHING ),
620 DD("-no-split-symlink-components", RTFSISOMAKERCMD_OPT_NO_SPLIT_SYMLINK_COMPONENTS, RTGETOPT_REQ_NOTHING ),
621 DD("-no-split-symlink-fields", RTFSISOMAKERCMD_OPT_NO_SPLIT_SYMLINK_FIELDS, RTGETOPT_REQ_NOTHING ),
622 DD("-path-list", RTFSISOMAKERCMD_OPT_PATH_LIST, RTGETOPT_REQ_STRING ),
623 DD("-print-size", RTFSISOMAKERCMD_OPT_PRINT_SIZE, RTGETOPT_REQ_NOTHING ),
624 DD("-quiet", RTFSISOMAKERCMD_OPT_QUIET, RTGETOPT_REQ_NOTHING ),
625 DD("-relaxed-filenames", RTFSISOMAKERCMD_OPT_RELAXED_FILENAMES, RTGETOPT_REQ_NOTHING ),
626 DD("-root", RTFSISOMAKERCMD_OPT_ROOT, RTGETOPT_REQ_STRING ),
627 DD("-old-root", RTFSISOMAKERCMD_OPT_OLD_ROOT, RTGETOPT_REQ_STRING ),
628 DD("-sort", RTFSISOMAKERCMD_OPT_SORT, RTGETOPT_REQ_STRING ),
629 DD("-sparc-boot", RTFSISOMAKERCMD_OPT_SPARC_BOOT, RTGETOPT_REQ_STRING ),
630 DD("-sparc-label", RTFSISOMAKERCMD_OPT_SPARC_LABEL, RTGETOPT_REQ_STRING ),
631 DD("-split-output", RTFSISOMAKERCMD_OPT_SPLIT_OUTPUT, RTGETOPT_REQ_NOTHING ),
632 DD("-stream-media-size", RTFSISOMAKERCMD_OPT_STREAM_MEDIA_SIZE, RTGETOPT_REQ_UINT64 ),
633 DD("-stream-file-name", RTFSISOMAKERCMD_OPT_STREAM_FILE_NAME, RTGETOPT_REQ_STRING ),
634 DD("-sunx86-boot", RTFSISOMAKERCMD_OPT_SUNX86_BOOT, RTGETOPT_REQ_STRING ),
635 DD("-sunx86-label", RTFSISOMAKERCMD_OPT_SUNX86_LABEL, RTGETOPT_REQ_STRING ),
636 { "--trans-tbl", 'T', RTGETOPT_REQ_NOTHING },
637 DD("-table-name", RTFSISOMAKERCMD_OPT_TRANS_TBL_NAME, RTGETOPT_REQ_STRING ),
638 DD("-udf", RTFSISOMAKERCMD_OPT_UDF, RTGETOPT_REQ_NOTHING ),
639 DD("-uid", RTFSISOMAKERCMD_OPT_UID, RTGETOPT_REQ_UINT32 ),
640 DD("-use-fileversion", RTFSISOMAKERCMD_OPT_USE_FILE_VERSION, RTGETOPT_REQ_NOTHING ),
641 { "--untranslated-filenames", 'U', RTGETOPT_REQ_NOTHING },
642 DD("-no-iso-translate", RTFSISOMAKERCMD_OPT_NO_ISO_TRANSLATE, RTGETOPT_REQ_NOTHING ),
643 DD("-volset-size", RTFSISOMAKERCMD_OPT_VOLUME_SET_SIZE, RTGETOPT_REQ_UINT32 ),
644 DD("-volset-seqno", RTFSISOMAKERCMD_OPT_VOLUME_SET_SEQ_NO, RTGETOPT_REQ_UINT32 ),
645 { "--transpared-compression", 'z', RTGETOPT_REQ_NOTHING },
646
647 /* HFS and ISO-9660 apple extensions. */
648 DD("-hfs", RTFSISOMAKERCMD_OPT_HFS_ENABLE, RTGETOPT_REQ_NOTHING ),
649 DD("-apple", RTFSISOMAKERCMD_OPT_APPLE, RTGETOPT_REQ_NOTHING ),
650 DD("-map", RTFSISOMAKERCMD_OPT_HFS_MAP, RTGETOPT_REQ_STRING ),
651 DD("-magic", RTFSISOMAKERCMD_OPT_HFS_MAGIC, RTGETOPT_REQ_STRING ),
652 DD("-hfs-creator", RTFSISOMAKERCMD_OPT_HFS_CREATOR, RTGETOPT_REQ_STRING ),
653 DD("-hfs-type", RTFSISOMAKERCMD_OPT_HFS_TYPE, RTGETOPT_REQ_STRING ),
654 DD("-probe", RTFSISOMAKERCMD_OPT_HFS_PROBE, RTGETOPT_REQ_NOTHING ),
655 DD("-no-desktop", RTFSISOMAKERCMD_OPT_HFS_NO_DESKTOP, RTGETOPT_REQ_NOTHING ),
656 DD("-mac-name", RTFSISOMAKERCMD_OPT_HFS_MAC_NAME, RTGETOPT_REQ_NOTHING ),
657 DD("-boot-hfs-file", RTFSISOMAKERCMD_OPT_HFS_BOOT_FILE, RTGETOPT_REQ_STRING ),
658 DD("-part", RTFSISOMAKERCMD_OPT_HFS_PART, RTGETOPT_REQ_NOTHING ),
659 DD("-auto", RTFSISOMAKERCMD_OPT_HFS_AUTO, RTGETOPT_REQ_STRING ),
660 DD("-cluster-size", RTFSISOMAKERCMD_OPT_HFS_CLUSTER_SIZE, RTGETOPT_REQ_UINT32 ),
661 DD("-hide-hfs", RTFSISOMAKERCMD_OPT_HFS_HIDE, RTGETOPT_REQ_STRING ),
662 DD("-hide-hfs-list", RTFSISOMAKERCMD_OPT_HFS_HIDE_LIST, RTGETOPT_REQ_STRING ),
663 DD("-hfs-volid", RTFSISOMAKERCMD_OPT_HFS_VOL_ID, RTGETOPT_REQ_STRING ),
664 DD("-icon-position", RTFSISOMAKERCMD_OPT_HFS_ICON_POSITION, RTGETOPT_REQ_NOTHING ),
665 DD("-root-info", RTFSISOMAKERCMD_OPT_HFS_ROOT_INFO, RTGETOPT_REQ_STRING ),
666 DD("-prep-boot", RTFSISOMAKERCMD_OPT_HFS_PREP_BOOT, RTGETOPT_REQ_STRING ),
667 DD("-chrp-boot", RTFSISOMAKERCMD_OPT_HFS_CHRP_BOOT, RTGETOPT_REQ_NOTHING ),
668 DD("-input-hfs-charset", RTFSISOMAKERCMD_OPT_HFS_INPUT_CHARSET, RTGETOPT_REQ_STRING ),
669 DD("-output-hfs-charset", RTFSISOMAKERCMD_OPT_HFS_OUTPUT_CHARSET, RTGETOPT_REQ_STRING ),
670 DD("-hfs-unlock", RTFSISOMAKERCMD_OPT_HFS_UNLOCK, RTGETOPT_REQ_NOTHING ),
671 DD("-hfs-bless", RTFSISOMAKERCMD_OPT_HFS_BLESS, RTGETOPT_REQ_STRING ),
672 DD("-hfs-parms", RTFSISOMAKERCMD_OPT_HFS_PARMS, RTGETOPT_REQ_STRING ),
673 { "--cap", RTFSISOMAKERCMD_OPT_HFS_CAP, RTGETOPT_REQ_NOTHING },
674 { "--netatalk", RTFSISOMAKERCMD_OPT_HFS_NETATALK, RTGETOPT_REQ_NOTHING },
675 { "--double", RTFSISOMAKERCMD_OPT_HFS_DOUBLE, RTGETOPT_REQ_NOTHING },
676 { "--ethershare", RTFSISOMAKERCMD_OPT_HFS_ETHERSHARE, RTGETOPT_REQ_NOTHING },
677 { "--ushare", RTFSISOMAKERCMD_OPT_HFS_USHARE, RTGETOPT_REQ_NOTHING },
678 { "--exchange", RTFSISOMAKERCMD_OPT_HFS_EXCHANGE, RTGETOPT_REQ_NOTHING },
679 { "--sgi", RTFSISOMAKERCMD_OPT_HFS_SGI, RTGETOPT_REQ_NOTHING },
680 { "--xinet", RTFSISOMAKERCMD_OPT_HFS_XINET, RTGETOPT_REQ_NOTHING },
681 { "--macbin", RTFSISOMAKERCMD_OPT_HFS_MACBIN, RTGETOPT_REQ_NOTHING },
682 { "--single", RTFSISOMAKERCMD_OPT_HFS_SINGLE, RTGETOPT_REQ_NOTHING },
683 { "--dave", RTFSISOMAKERCMD_OPT_HFS_DAVE, RTGETOPT_REQ_NOTHING },
684 { "--sfm", RTFSISOMAKERCMD_OPT_HFS_SFM, RTGETOPT_REQ_NOTHING },
685 { "--osx-double", RTFSISOMAKERCMD_OPT_HFS_OSX_DOUBLE, RTGETOPT_REQ_NOTHING },
686 { "--osx-hfs", RTFSISOMAKERCMD_OPT_HFS_OSX_HFS, RTGETOPT_REQ_NOTHING },
687#undef DD
688};
689
690#ifndef RT_OS_OS2 /* fixme */
691# include "isomakercmd-man.h"
692#endif
693
694
695/*********************************************************************************************************************************
696* Internal Functions *
697*********************************************************************************************************************************/
698static int rtFsIsoMakerCmdParse(PRTFSISOMAKERCMDOPTS pOpts, unsigned cArgs, char **papszArgs, unsigned cDepth);
699
700
701/**
702 * Wrapper around RTErrInfoSetV / RTMsgErrorV.
703 *
704 * @returns @a rc
705 * @param pOpts The ISO maker command instance.
706 * @param rc The return code.
707 * @param pszFormat The message format.
708 * @param ... The message format arguments.
709 */
710static int rtFsIsoMakerCmdErrorRc(PRTFSISOMAKERCMDOPTS pOpts, int rc, const char *pszFormat, ...)
711{
712 va_list va;
713 va_start(va, pszFormat);
714 if (pOpts->pErrInfo)
715 RTErrInfoSetV(pOpts->pErrInfo, rc, pszFormat, va);
716 else
717 RTMsgErrorV(pszFormat, va);
718 va_end(va);
719 return rc;
720}
721
722
723/**
724 * Wrapper around RTErrInfoSetV / RTMsgErrorV for doing the job of
725 * RTVfsChainMsgError.
726 *
727 * @returns @a rc
728 * @param pOpts The ISO maker command instance.
729 * @param pszFunction The API called.
730 * @param pszSpec The VFS chain specification or file path passed to the.
731 * @param rc The return code.
732 * @param offError The error offset value returned (0 if not captured).
733 * @param pErrInfo Additional error information. Optional.
734 */
735static int rtFsIsoMakerCmdChainError(PRTFSISOMAKERCMDOPTS pOpts, const char *pszFunction, const char *pszSpec, int rc,
736 uint32_t offError, PRTERRINFO pErrInfo)
737{
738 if (RTErrInfoIsSet(pErrInfo))
739 {
740 if (offError > 0)
741 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc,
742 "%s failed with rc=%Rrc: %s\n"
743 " '%s'\n"
744 " %*s^",
745 pszFunction, rc, pErrInfo->pszMsg, pszSpec, offError, "");
746 else
747 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "%s failed to open '%s': %Rrc: %s",
748 pszFunction, pszSpec, rc, pErrInfo->pszMsg);
749 }
750 else
751 {
752 if (offError > 0)
753 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc,
754 "%s failed with rc=%Rrc:\n"
755 " '%s'\n"
756 " %*s^",
757 pszFunction, rc, pszSpec, offError, "");
758 else
759 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "%s failed to open '%s': %Rrc", pszFunction, pszSpec, rc);
760 }
761 return rc;
762}
763
764
765/**
766 * Wrapper around RTErrInfoSetV / RTMsgErrorV for displaying syntax errors.
767 *
768 * @returns VERR_INVALID_PARAMETER
769 * @param pOpts The ISO maker command instance.
770 * @param pszFormat The message format.
771 * @param ... The message format arguments.
772 */
773static int rtFsIsoMakerCmdSyntaxError(PRTFSISOMAKERCMDOPTS pOpts, const char *pszFormat, ...)
774{
775 va_list va;
776 va_start(va, pszFormat);
777 if (pOpts->pErrInfo)
778 RTErrInfoSetV(pOpts->pErrInfo, VERR_INVALID_PARAMETER, pszFormat, va);
779 else
780 RTMsgErrorV(pszFormat, va);
781 va_end(va);
782 return VERR_INVALID_PARAMETER;
783}
784
785
786/**
787 * Wrapper around RTPrintfV / RTLogRelPrintfV.
788 *
789 * @param pOpts The ISO maker command instance.
790 * @param pszFormat The message format.
791 * @param ... The message format arguments.
792 */
793static void rtFsIsoMakerPrintf(PRTFSISOMAKERCMDOPTS pOpts, const char *pszFormat, ...)
794{
795 va_list va;
796 va_start(va, pszFormat);
797 if (pOpts->pErrInfo)
798 RTLogRelPrintfV(pszFormat, va);
799 else
800 RTPrintfV(pszFormat, va);
801 va_end(va);
802}
803
804/**
805 * Deletes the state and returns @a rc.
806 *
807 * @returns @a rc.
808 * @param pOpts The ISO maker command instance to delete.
809 * @param rc The status code to return.
810 */
811static int rtFsIsoMakerCmdDeleteState(PRTFSISOMAKERCMDOPTS pOpts, int rc)
812{
813 if (pOpts->hIsoMaker != NIL_RTFSISOMAKER)
814 {
815 RTFsIsoMakerRelease(pOpts->hIsoMaker);
816 pOpts->hIsoMaker = NIL_RTFSISOMAKER;
817 }
818
819 while (pOpts->iSrcStack >= 0)
820 {
821 RTVfsDirRelease(pOpts->aSrcStack[pOpts->iSrcStack].hSrcDir);
822 RTVfsRelease(pOpts->aSrcStack[pOpts->iSrcStack].hSrcVfs);
823 pOpts->aSrcStack[pOpts->iSrcStack].hSrcDir = NIL_RTVFSDIR;
824 pOpts->aSrcStack[pOpts->iSrcStack].hSrcVfs = NIL_RTVFS;
825 pOpts->iSrcStack--;
826 }
827
828 return rc;
829}
830
831
832/**
833 * Print the usage.
834 *
835 * @param pOpts Options for print metho.
836 * @param pszProgName The program name.
837 */
838static void rtFsIsoMakerCmdUsage(PRTFSISOMAKERCMDOPTS pOpts, const char *pszProgName)
839{
840#ifndef RT_OS_OS2 /* fixme */
841 if (!pOpts->pErrInfo)
842 RTMsgRefEntryHelp(g_pStdOut, &g_viso);
843 else
844#endif
845 rtFsIsoMakerPrintf(pOpts, "Usage: %s [options] [@commands.rsp] <filespec...>\n",
846 RTPathFilename(pszProgName));
847}
848
849
850/**
851 * Verifies the image content by reading blocks in random order.
852 *
853 * This is for exercise the virtual ISO code better and test that we get the
854 * same data when reading something twice.
855 *
856 * @returns IPRT status code.
857 * @param pOpts The ISO maker command instance.
858 * @param hVfsSrcFile The source file (virtual ISO).
859 * @param hVfsDstFile The destination file (image file on disk).
860 * @param cbImage The size of the ISO.
861 */
862static int rtFsIsoMakerCmdVerifyImageInRandomOrder(PRTFSISOMAKERCMDOPTS pOpts, RTVFSFILE hVfsSrcFile,
863 RTVFSFILE hVfsDstFile, uint64_t cbImage)
864{
865 /*
866 * Figure the buffer (block) size and allocate a bitmap for noting down blocks we've covered.
867 */
868 int rc;
869 size_t cbBuf = RT_MAX(pOpts->cbRandomOrderVerifciationBlock, 1);
870 uint64_t cBlocks64 = (cbImage + cbBuf - 1) / cbBuf;
871 if (cBlocks64 > _512M)
872 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_OUT_OF_RANGE,
873 "verification block count too high: cBlocks=%#RX64 (cbBuf=%#zx), max 512M", cBlocks64, cbBuf);
874 uint32_t cBlocks = (uint32_t)cBlocks64;
875 uint32_t cbBitmap = (cBlocks + 63) / 8;
876 if (cbBitmap > _64M)
877 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_OUT_OF_RANGE,
878 "verification bitmap too big: cbBitmap=%#RX32 (cbBuf=%#zx), max 64MB", cbBitmap, cbBuf);
879 void *pvSrcBuf = RTMemTmpAlloc(cbBuf);
880 void *pvDstBuf = RTMemTmpAlloc(cbBuf);
881 void *pvBitmap = RTMemTmpAllocZ(cbBitmap);
882 if (pvSrcBuf && pvDstBuf && pvBitmap)
883 {
884 /* Must set the unused bits in the top qword. */
885 for (uint32_t i = RT_ALIGN_32(cBlocks, 64) - 1; i >= cBlocks; i--)
886 ASMBitSet(pvBitmap, i);
887
888 /*
889 * Do the verification.
890 */
891 rtFsIsoMakerPrintf(pOpts, "Verifying image in random order using %zu (%#zx) byte blocks: %#RX32 in blocks\n",
892 cbBuf, cbBuf, cBlocks);
893
894 rc = VINF_SUCCESS;
895 uint64_t cLeft = cBlocks;
896 while (cLeft-- > 0)
897 {
898 /*
899 * Figure out which block to check next.
900 */
901 uint32_t iBlock = RTRandU32Ex(0, cBlocks - 1);
902 if (!ASMBitTestAndSet(pvBitmap, iBlock))
903 Assert(iBlock < cBlocks);
904 else
905 {
906 /* try 32 other random numbers. */
907 bool fBitSet;
908 unsigned cTries = 0;
909 do
910 {
911 iBlock = RTRandU32Ex(0, cBlocks - 1);
912 fBitSet = ASMBitTestAndSet(pvBitmap, iBlock);
913 } while (fBitSet && ++cTries < 32);
914 if (fBitSet)
915 {
916 /* Look for the next clear bit after it (with wrap around). */
917 int iHit = ASMBitNextClear(pvBitmap, RT_ALIGN_32(cBlocks, 64), iBlock);
918 Assert(iHit < (int32_t)cBlocks);
919 if (iHit < 0)
920 {
921 iHit = ASMBitFirstClear(pvBitmap, RT_ALIGN_32(iBlock, 64));
922 Assert(iHit < (int32_t)cBlocks);
923 }
924 if (iHit >= 0)
925 {
926 fBitSet = ASMBitTestAndSet(pvBitmap, iHit);
927 if (!fBitSet)
928 iBlock = iHit;
929 else
930 {
931 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_INTERNAL_ERROR_3,
932 "Bitmap weirdness: iHit=%#x iBlock=%#x cLeft=%#x cBlocks=%#x",
933 iHit, iBlock, cLeft, cBlocks);
934 if (!pOpts->pErrInfo)
935 RTMsgInfo("Bitmap: %#RX32 bytes\n%.*Rhxd", cbBitmap, cbBitmap, pvBitmap);
936 break;
937 }
938 }
939 else
940 {
941 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_INTERNAL_ERROR_2,
942 "Bitmap weirdness: iBlock=%#x cLeft=%#x cBlocks=%#x",
943 iBlock, cLeft, cBlocks);
944 if (!pOpts->pErrInfo)
945 RTMsgInfo("Bitmap: %#RX32 bytes\n%.*Rhxd", cbBitmap, cbBitmap, pvBitmap);
946 break;
947 }
948 }
949 }
950 Assert(ASMBitTest(pvBitmap, iBlock));
951
952 /*
953 * Figure out how much and where to read (last block fun).
954 */
955 uint64_t offBlock = iBlock * (uint64_t)cbBuf;
956 size_t cbToRead = cbBuf;
957 if (iBlock + 1 < cBlocks)
958 { /* likely */ }
959 else if (cbToRead > cbImage - offBlock)
960 cbToRead = (size_t)(cbImage - offBlock);
961 Assert(offBlock + cbToRead <= cbImage);
962
963 /*
964 * Read the blocks.
965 */
966 //RTPrintf("Reading block #%#x at %#RX64\n", iBlock, offBlock);
967 rc = RTVfsFileReadAt(hVfsDstFile, offBlock, pvDstBuf, cbToRead, NULL);
968 if (RT_SUCCESS(rc))
969 {
970 memset(pvSrcBuf, 0xdd, cbBuf);
971 rc = RTVfsFileReadAt(hVfsSrcFile, offBlock, pvSrcBuf, cbToRead, NULL);
972 if (RT_SUCCESS(rc))
973 {
974 if (memcmp(pvDstBuf, pvSrcBuf, cbToRead) == 0)
975 continue;
976 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_MISMATCH,
977 "Block #%#x differs! offBlock=%#RX64 cbToRead=%#zu\n"
978 "Virtual ISO (source):\n%.*Rhxd\nWritten ISO (destination):\n%.*Rhxd",
979 iBlock, offBlock, cbToRead, cbToRead, pvSrcBuf, cbToRead, pvDstBuf);
980 }
981 else
982 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc,
983 "Error reading %#zx bytes source (virtual ISO) block #%#x at %#RX64: %Rrc",
984 cbToRead, iBlock, offBlock, rc);
985 }
986 else
987 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc,
988 "Error reading %#zx bytes destination (written ISO) block #%#x at %#RX64: %Rrc",
989 cbToRead, iBlock, offBlock, rc);
990 break;
991 }
992
993 if (RT_SUCCESS(rc))
994 rtFsIsoMakerPrintf(pOpts, "Written image verified fine!\n");
995 }
996 else if (!pvSrcBuf || !pvDstBuf)
997 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_NO_TMP_MEMORY, "RTMemTmpAlloc(%#zx) failed", cbBuf);
998 else
999 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_NO_TMP_MEMORY, "RTMemTmpAlloc(%#zx) failed", cbBuf);
1000 RTMemTmpFree(pvBitmap);
1001 RTMemTmpFree(pvDstBuf);
1002 RTMemTmpFree(pvSrcBuf);
1003 return rc;
1004}
1005
1006
1007/**
1008 * Writes the image to file, no checking, no special buffering.
1009 *
1010 * @returns IPRT status code.
1011 * @param pOpts The ISO maker command instance.
1012 * @param hVfsSrcFile The source file from the ISO maker.
1013 * @param hVfsDstFile The destination file (image file on disk).
1014 * @param cbImage The size of the ISO.
1015 * @param ppvBuf Pointer to the buffer pointer. The buffer will
1016 * be reallocated, but we want the luxary of the
1017 * caller freeing it.
1018 */
1019static int rtFsIsoMakerCmdWriteImageRandomBufferSize(PRTFSISOMAKERCMDOPTS pOpts, RTVFSFILE hVfsSrcFile, RTVFSFILE hVfsDstFile,
1020 uint64_t cbImage, void **ppvBuf)
1021{
1022 /*
1023 * Copy the virtual image bits to the destination file.
1024 */
1025 void *pvBuf = *ppvBuf;
1026 uint32_t cbMaxBuf = pOpts->cbOutputReadBuffer > 0 ? pOpts->cbOutputReadBuffer : _64K;
1027 uint64_t offImage = 0;
1028 while (offImage < cbImage)
1029 {
1030 /* Figure out how much to copy this time. */
1031 size_t cbToCopy = RTRandU32Ex(1, cbMaxBuf - 1);
1032 if (offImage + cbToCopy < cbImage)
1033 { /* likely */ }
1034 else
1035 cbToCopy = (size_t)(cbImage - offImage);
1036 RTMemFree(pvBuf);
1037 *ppvBuf = pvBuf = RTMemTmpAlloc(cbToCopy);
1038 if (pvBuf)
1039 {
1040 /* Do the copying. */
1041 int rc = RTVfsFileReadAt(hVfsSrcFile, offImage, pvBuf, cbToCopy, NULL);
1042 if (RT_SUCCESS(rc))
1043 {
1044 rc = RTVfsFileWriteAt(hVfsDstFile, offImage, pvBuf, cbToCopy, NULL);
1045 if (RT_SUCCESS(rc))
1046 offImage += cbToCopy;
1047 else
1048 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error %Rrc writing %#zx bytes at offset %#RX64 to '%s'",
1049 rc, cbToCopy, offImage, pOpts->pszOutFile);
1050 }
1051 else
1052 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error %Rrc read %#zx bytes at offset %#RX64", rc, cbToCopy, offImage);
1053 }
1054 else
1055 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NO_TMP_MEMORY, "RTMemTmpAlloc(%#zx) failed", cbToCopy);
1056 }
1057 return VINF_SUCCESS;
1058}
1059
1060
1061/**
1062 * Writes the image to file, no checking, no special buffering.
1063 *
1064 * @returns IPRT status code.
1065 * @param pOpts The ISO maker command instance.
1066 * @param hVfsSrcFile The source file from the ISO maker.
1067 * @param hVfsDstFile The destination file (image file on disk).
1068 * @param cbImage The size of the ISO.
1069 * @param pvBuf Pointer to read buffer.
1070 * @param cbBuf The buffer size.
1071 */
1072static int rtFsIsoMakerCmdWriteImageSimple(PRTFSISOMAKERCMDOPTS pOpts, RTVFSFILE hVfsSrcFile, RTVFSFILE hVfsDstFile,
1073 uint64_t cbImage, void *pvBuf, size_t cbBuf)
1074{
1075 /*
1076 * Copy the virtual image bits to the destination file.
1077 */
1078 uint64_t offImage = 0;
1079 while (offImage < cbImage)
1080 {
1081 /* Figure out how much to copy this time. */
1082 size_t cbToCopy = cbBuf;
1083 if (offImage + cbToCopy < cbImage)
1084 { /* likely */ }
1085 else
1086 cbToCopy = (size_t)(cbImage - offImage);
1087
1088 /* Do the copying. */
1089 int rc = RTVfsFileReadAt(hVfsSrcFile, offImage, pvBuf, cbToCopy, NULL);
1090 if (RT_SUCCESS(rc))
1091 {
1092 rc = RTVfsFileWriteAt(hVfsDstFile, offImage, pvBuf, cbToCopy, NULL);
1093 if (RT_SUCCESS(rc))
1094 offImage += cbToCopy;
1095 else
1096 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error %Rrc writing %#zx bytes at offset %#RX64 to '%s'",
1097 rc, cbToCopy, offImage, pOpts->pszOutFile);
1098 }
1099 else
1100 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error %Rrc read %#zx bytes at offset %#RX64", rc, cbToCopy, offImage);
1101 }
1102 return VINF_SUCCESS;
1103}
1104
1105
1106/**
1107 * Writes the image to file.
1108 *
1109 * @returns IPRT status code.
1110 * @param pOpts The ISO maker command instance.
1111 * @param hVfsSrcFile The source file from the ISO maker.
1112 */
1113static int rtFsIsoMakerCmdWriteImage(PRTFSISOMAKERCMDOPTS pOpts, RTVFSFILE hVfsSrcFile)
1114{
1115 /*
1116 * Get the image size and setup the copy buffer.
1117 */
1118 uint64_t cbImage;
1119 int rc = RTVfsFileQuerySize(hVfsSrcFile, &cbImage);
1120 if (RT_SUCCESS(rc))
1121 {
1122 rtFsIsoMakerPrintf(pOpts, "Image size: %'RU64 (%#RX64) bytes\n", cbImage, cbImage);
1123
1124 uint32_t cbBuf = pOpts->cbOutputReadBuffer == 0 ? _1M : pOpts->cbOutputReadBuffer;
1125 void *pvBuf = RTMemTmpAlloc(cbBuf);
1126 if (pvBuf)
1127 {
1128 /*
1129 * Open the output file.
1130 */
1131 RTVFSFILE hVfsDstFile;
1132 uint32_t offError;
1133 RTERRINFOSTATIC ErrInfo;
1134 rc = RTVfsChainOpenFile(pOpts->pszOutFile,
1135 RTFILE_O_READWRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_WRITE
1136 | (0664 << RTFILE_O_CREATE_MODE_SHIFT),
1137 &hVfsDstFile, &offError, RTErrInfoInitStatic(&ErrInfo));
1138 if (RT_SUCCESS(rc))
1139 {
1140 /*
1141 * Apply the desired writing method.
1142 */
1143 if (!pOpts->fRandomOutputReadBufferSize)
1144 rc = rtFsIsoMakerCmdWriteImageRandomBufferSize(pOpts, hVfsSrcFile, hVfsDstFile, cbImage, &pvBuf);
1145 else
1146 rc = rtFsIsoMakerCmdWriteImageSimple(pOpts, hVfsSrcFile, hVfsDstFile, cbImage, pvBuf, cbBuf);
1147 RTMemTmpFree(pvBuf);
1148
1149 if (RT_SUCCESS(rc) && pOpts->cbRandomOrderVerifciationBlock > 0)
1150 rc = rtFsIsoMakerCmdVerifyImageInRandomOrder(pOpts, hVfsSrcFile, hVfsDstFile, cbImage);
1151
1152 /*
1153 * Flush the output file before releasing it.
1154 */
1155 if (RT_SUCCESS(rc))
1156 {
1157 rc = RTVfsFileFlush(hVfsDstFile);
1158 if (RT_FAILURE(rc))
1159 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTVfsFileFlush failed on '%s': %Rrc", pOpts->pszOutFile, rc);
1160 }
1161
1162 RTVfsFileRelease(hVfsDstFile);
1163 }
1164 else
1165 {
1166 RTMemTmpFree(pvBuf);
1167 rc = rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainOpenFile", pOpts->pszOutFile, rc, offError, &ErrInfo.Core);
1168 }
1169 }
1170 else
1171 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_NO_TMP_MEMORY, "RTMemTmpAlloc(%zu) failed", cbBuf);
1172 }
1173 else
1174 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTVfsFileQuerySize failed: %Rrc", rc);
1175 return rc;
1176}
1177
1178
1179/**
1180 * Formats @a fNameSpecifiers into a '+' separated list of names.
1181 *
1182 * @returns pszDst
1183 * @param fNameSpecifiers The name specifiers.
1184 * @param pszDst The destination bufer.
1185 * @param cbDst The size of the destination buffer.
1186 */
1187static char *rtFsIsoMakerCmdNameSpecifiersToString(uint32_t fNameSpecifiers, char *pszDst, size_t cbDst)
1188{
1189 static struct { const char *pszName; uint32_t cchName; uint32_t fSpec; } const s_aSpecs[] =
1190 {
1191 { RT_STR_TUPLE("primary"), RTFSISOMAKERCMDNAME_PRIMARY_ISO },
1192 { RT_STR_TUPLE("primary-rock"), RTFSISOMAKERCMDNAME_PRIMARY_ISO_ROCK_RIDGE },
1193 { RT_STR_TUPLE("primary-trans-tbl"), RTFSISOMAKERCMDNAME_PRIMARY_ISO_TRANS_TBL },
1194 { RT_STR_TUPLE("joliet"), RTFSISOMAKERCMDNAME_JOLIET },
1195 { RT_STR_TUPLE("joliet-rock"), RTFSISOMAKERCMDNAME_JOLIET_ROCK_RIDGE },
1196 { RT_STR_TUPLE("joliet-trans-tbl"), RTFSISOMAKERCMDNAME_JOLIET_TRANS_TBL },
1197 { RT_STR_TUPLE("udf"), RTFSISOMAKERCMDNAME_UDF },
1198 { RT_STR_TUPLE("udf-trans-tbl"), RTFSISOMAKERCMDNAME_UDF_TRANS_TBL },
1199 { RT_STR_TUPLE("hfs"), RTFSISOMAKERCMDNAME_HFS },
1200 { RT_STR_TUPLE("hfs-trans-tbl"), RTFSISOMAKERCMDNAME_HFS_TRANS_TBL },
1201 };
1202
1203 Assert(cbDst > 0);
1204 char *pszRet = pszDst;
1205 for (uint32_t i = 0; i < RT_ELEMENTS(s_aSpecs); i++)
1206 if (s_aSpecs[i].fSpec & fNameSpecifiers)
1207 {
1208 if (pszDst != pszRet && cbDst > 1)
1209 {
1210 *pszDst++ = '+';
1211 cbDst--;
1212 }
1213 if (cbDst > s_aSpecs[i].cchName)
1214 {
1215 memcpy(pszDst, s_aSpecs[i].pszName, s_aSpecs[i].cchName);
1216 cbDst -= s_aSpecs[i].cchName;
1217 pszDst += s_aSpecs[i].cchName;
1218 }
1219 else if (cbDst > 1)
1220 {
1221 memcpy(pszDst, s_aSpecs[i].pszName, cbDst - 1);
1222 pszDst += cbDst - 1;
1223 cbDst = 1;
1224 }
1225
1226 fNameSpecifiers &= ~s_aSpecs[i].fSpec;
1227 if (!fNameSpecifiers)
1228 break;
1229 }
1230 *pszDst = '\0';
1231 return pszRet;
1232}
1233
1234
1235/**
1236 * Parses the --name-setup option.
1237 *
1238 * @returns IPRT status code.
1239 * @param pOpts The ISO maker command instance.
1240 * @param pszSpec The name setup specification.
1241 */
1242static int rtFsIsoMakerCmdOptNameSetup(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSpec)
1243{
1244 /*
1245 * Comma separated list of one or more specifiers.
1246 */
1247 uint32_t fNamespaces = 0;
1248 uint32_t fPrevMajor = 0;
1249 uint32_t iNameSpecifier = 0;
1250 uint32_t offSpec = 0;
1251 do
1252 {
1253 /*
1254 * Parse up to the next colon or end of string.
1255 */
1256 uint32_t fNameSpecifier = 0;
1257 char ch;
1258 while ( (ch = pszSpec[offSpec]) != '\0'
1259 && ch != ',')
1260 {
1261 if (RT_C_IS_SPACE(ch) || ch == '+' || ch == '|') /* space, '+' and '|' are allowed as name separators. */
1262 offSpec++;
1263 else
1264 {
1265 /* Find the end of the name. */
1266 uint32_t offEndSpec = offSpec + 1;
1267 while ( (ch = pszSpec[offEndSpec]) != '\0'
1268 && ch != ','
1269 && ch != '+'
1270 && ch != '|'
1271 && !RT_C_IS_SPACE(ch))
1272 offEndSpec++;
1273
1274#define IS_EQUAL(a_sz) (cchName == sizeof(a_sz) - 1U && strncmp(pchName, a_sz, sizeof(a_sz) - 1U) == 0)
1275 const char * const pchName = &pszSpec[offSpec];
1276 uint32_t const cchName = offEndSpec - offSpec;
1277 /* major namespaces */
1278 if ( IS_EQUAL("iso")
1279 || IS_EQUAL("primary")
1280 || IS_EQUAL("iso9660")
1281 || IS_EQUAL("iso-9660")
1282 || IS_EQUAL("primary-iso")
1283 || IS_EQUAL("iso-primary") )
1284 {
1285 fNameSpecifier |= RTFSISOMAKERCMDNAME_PRIMARY_ISO;
1286 fNamespaces |= fPrevMajor = RTFSISOMAKER_NAMESPACE_ISO_9660;
1287 }
1288 else if (IS_EQUAL("joliet"))
1289 {
1290 fNameSpecifier |= RTFSISOMAKERCMDNAME_JOLIET;
1291 fNamespaces |= fPrevMajor = RTFSISOMAKER_NAMESPACE_JOLIET;
1292 }
1293 else if (IS_EQUAL("udf"))
1294 {
1295#if 0
1296 fNameSpecifier |= RTFSISOMAKERCMDNAME_UDF;
1297 fNamespaces |= fPrevMajor = RTFSISOMAKER_NAMESPACE_UDF;
1298#else
1299 return rtFsIsoMakerCmdSyntaxError(pOpts, "UDF support is currently not implemented");
1300#endif
1301 }
1302 else if (IS_EQUAL("hfs") || IS_EQUAL("hfsplus"))
1303 {
1304#if 0
1305 fNameSpecifier |= RTFSISOMAKERCMDNAME_HFS;
1306 fNamespaces |= fPrevMajor = RTFSISOMAKER_NAMESPACE_HFS;
1307#else
1308 return rtFsIsoMakerCmdSyntaxError(pOpts, "Hybrid HFS+ support is currently not implemented");
1309#endif
1310 }
1311 /* rock ridge */
1312 else if ( IS_EQUAL("rr")
1313 || IS_EQUAL("rock")
1314 || IS_EQUAL("rock-ridge"))
1315 {
1316 if (fPrevMajor == RTFSISOMAKERCMDNAME_PRIMARY_ISO)
1317 fNameSpecifier |= RTFSISOMAKERCMDNAME_PRIMARY_ISO_ROCK_RIDGE;
1318 else if (fPrevMajor == RTFSISOMAKERCMDNAME_JOLIET)
1319 fNameSpecifier |= RTFSISOMAKERCMDNAME_JOLIET_ROCK_RIDGE;
1320 else
1321 return rtFsIsoMakerCmdSyntaxError(pOpts, "unqualified rock-ridge name specifier");
1322 }
1323 else if ( IS_EQUAL("iso-rr") || IS_EQUAL("iso-rock") || IS_EQUAL("iso-rock-ridge")
1324 || IS_EQUAL("primary-rr") || IS_EQUAL("primary-rock") || IS_EQUAL("primary-rock-ridge")
1325 || IS_EQUAL("iso9660-rr") || IS_EQUAL("iso9660-rock") || IS_EQUAL("iso9660-rock-ridge")
1326 || IS_EQUAL("iso-9660-rr") || IS_EQUAL("iso-9660-rock") || IS_EQUAL("iso-9660-rock-ridge")
1327 || IS_EQUAL("primaryiso-rr") || IS_EQUAL("primaryiso-rock") || IS_EQUAL("primaryiso-rock-ridge")
1328 || IS_EQUAL("primary-iso-rr") || IS_EQUAL("primary-iso-rock") || IS_EQUAL("primary-iso-rock-ridge") )
1329 {
1330 fNameSpecifier |= RTFSISOMAKERCMDNAME_PRIMARY_ISO_ROCK_RIDGE;
1331 if (!(fNamespaces & RTFSISOMAKERCMDNAME_PRIMARY_ISO))
1332 return rtFsIsoMakerCmdSyntaxError(pOpts, "iso-9660-rock-ridge must come after the iso-9660 name specifier");
1333 }
1334 else if (IS_EQUAL("joliet-rr") || IS_EQUAL("joliet-rock") || IS_EQUAL("joliet-rock-ridge"))
1335 {
1336 fNameSpecifier |= RTFSISOMAKERCMDNAME_JOLIET_ROCK_RIDGE;
1337 if (!(fNamespaces & RTFSISOMAKERCMDNAME_JOLIET))
1338 return rtFsIsoMakerCmdSyntaxError(pOpts, "joliet-rock-ridge must come after the joliet name specifier");
1339 }
1340 /* trans.tbl */
1341 else if (IS_EQUAL("trans") || IS_EQUAL("trans-tbl"))
1342 {
1343 if (fPrevMajor == RTFSISOMAKERCMDNAME_PRIMARY_ISO)
1344 fNameSpecifier |= RTFSISOMAKERCMDNAME_PRIMARY_ISO_TRANS_TBL;
1345 else if (fPrevMajor == RTFSISOMAKERCMDNAME_JOLIET)
1346 fNameSpecifier |= RTFSISOMAKERCMDNAME_JOLIET_TRANS_TBL;
1347 else
1348 return rtFsIsoMakerCmdSyntaxError(pOpts, "unqualified trans-tbl name specifier");
1349 }
1350 else if ( IS_EQUAL("iso-trans") || IS_EQUAL("iso-trans-tbl")
1351 || IS_EQUAL("primary-trans") || IS_EQUAL("primary-trans-tbl")
1352 || IS_EQUAL("iso9660-trans") || IS_EQUAL("iso9660-trans-tbl")
1353 || IS_EQUAL("iso-9660-trans") || IS_EQUAL("iso-9660-trans-tbl")
1354 || IS_EQUAL("primaryiso-trans") || IS_EQUAL("primaryiso-trans-tbl")
1355 || IS_EQUAL("primary-iso-trans") || IS_EQUAL("primary-iso-trans-tbl") )
1356 {
1357 fNameSpecifier |= RTFSISOMAKERCMDNAME_PRIMARY_ISO_TRANS_TBL;
1358 if (!(fNamespaces & RTFSISOMAKERCMDNAME_PRIMARY_ISO))
1359 return rtFsIsoMakerCmdSyntaxError(pOpts, "iso-9660-trans-tbl must come after the iso-9660 name specifier");
1360 }
1361 else if (IS_EQUAL("joliet-trans") || IS_EQUAL("joliet-trans-tbl"))
1362 {
1363 fNameSpecifier |= RTFSISOMAKERCMDNAME_JOLIET_TRANS_TBL;
1364 if (!(fNamespaces & RTFSISOMAKERCMDNAME_JOLIET))
1365 return rtFsIsoMakerCmdSyntaxError(pOpts, "joliet-trans-tbl must come after the joliet name specifier");
1366 }
1367 else if (IS_EQUAL("udf-trans") || IS_EQUAL("udf-trans-tbl"))
1368 {
1369 fNameSpecifier |= RTFSISOMAKERCMDNAME_UDF_TRANS_TBL;
1370 if (!(fNamespaces & RTFSISOMAKERCMDNAME_UDF))
1371 return rtFsIsoMakerCmdSyntaxError(pOpts, "udf-trans-tbl must come after the udf name specifier");
1372 }
1373 else if (IS_EQUAL("hfs-trans") || IS_EQUAL("hfs-trans-tbl"))
1374 {
1375 fNameSpecifier |= RTFSISOMAKERCMDNAME_HFS_TRANS_TBL;
1376 if (!(fNamespaces & RTFSISOMAKERCMDNAME_HFS))
1377 return rtFsIsoMakerCmdSyntaxError(pOpts, "hfs-trans-tbl must come after the hfs name specifier");
1378 }
1379 else
1380 return rtFsIsoMakerCmdSyntaxError(pOpts, "unknown name specifier '%.*s'", cchName, pchName);
1381#undef IS_EQUAL
1382 offSpec = offEndSpec;
1383 }
1384 } /* while same specifier */
1385
1386 /*
1387 * Check that it wasn't empty.
1388 */
1389 if (fNameSpecifier == 0)
1390 return rtFsIsoMakerCmdSyntaxError(pOpts, "name specifier #%u (0-based) is empty ", iNameSpecifier);
1391
1392 /*
1393 * Complain if a major namespace name is duplicated. The rock-ridge and
1394 * trans.tbl names are simple to replace, the others affect the two former
1395 * names and are therefore not allowed twice in the list.
1396 */
1397 uint32_t i = iNameSpecifier;
1398 while (i-- > 0)
1399 {
1400 uint32_t fRepeated = (fNameSpecifier & RTFSISOMAKERCMDNAME_MAJOR_MASK)
1401 & (pOpts->afNameSpecifiers[i] & RTFSISOMAKERCMDNAME_MAJOR_MASK);
1402 if (fRepeated)
1403 {
1404 char szTmp[128];
1405 return rtFsIsoMakerCmdSyntaxError(pOpts, "repeating name specifier%s: %s", RT_IS_POWER_OF_TWO(fRepeated) ? "" : "s",
1406 rtFsIsoMakerCmdNameSpecifiersToString(fRepeated, szTmp, sizeof(szTmp)));
1407 }
1408 }
1409
1410 /*
1411 * Add it.
1412 */
1413 if (iNameSpecifier >= RT_ELEMENTS(pOpts->afNameSpecifiers))
1414 return rtFsIsoMakerCmdSyntaxError(pOpts, "too many name specifiers (max %d)", RT_ELEMENTS(pOpts->afNameSpecifiers));
1415 pOpts->afNameSpecifiers[iNameSpecifier] = fNameSpecifier;
1416 iNameSpecifier++;
1417
1418 /*
1419 * Next, if any.
1420 */
1421 if (pszSpec[offSpec] == ',')
1422 offSpec++;
1423 } while (pszSpec[offSpec] != '\0');
1424
1425 pOpts->cNameSpecifiers = iNameSpecifier;
1426 pOpts->fDstNamespaces = fNamespaces;
1427
1428 return VINF_SUCCESS;
1429}
1430
1431
1432/**
1433 * Handles the --name-setup-from-import option.
1434 *
1435 * @returns IPRT status code.
1436 * @param pOpts The ISO maker command instance.
1437 */
1438static int rtFsIsoMakerCmdOptNameSetupFromImport(PRTFSISOMAKERCMDOPTS pOpts)
1439{
1440 /*
1441 * Figure out what's on the ISO.
1442 */
1443 uint32_t fNamespaces = RTFsIsoMakerGetPopulatedNamespaces(pOpts->hIsoMaker);
1444 AssertReturn(fNamespaces != UINT32_MAX, VERR_INVALID_HANDLE);
1445 if (fNamespaces != 0)
1446 {
1447 if ( (fNamespaces & RTFSISOMAKER_NAMESPACE_ISO_9660)
1448 && RTFsIsoMakerGetRockRidgeLevel(pOpts->hIsoMaker) > 0)
1449 fNamespaces |= RTFSISOMAKERCMDNAME_PRIMARY_ISO_ROCK_RIDGE;
1450
1451 if ( (fNamespaces & RTFSISOMAKER_NAMESPACE_JOLIET)
1452 && RTFsIsoMakerGetJolietRockRidgeLevel(pOpts->hIsoMaker) > 0)
1453 fNamespaces |= RTFSISOMAKERCMDNAME_JOLIET_ROCK_RIDGE;
1454
1455 /*
1456 * The TRANS.TBL files cannot be disabled at present and the importer
1457 * doesn't check whether they are there or not, so carry them on from
1458 * the previous setup.
1459 */
1460 uint32_t fOld = 0;
1461 uint32_t i = pOpts->cNameSpecifiers;
1462 while (i-- > 0)
1463 fOld |= pOpts->afNameSpecifiers[0];
1464 if (fNamespaces & RTFSISOMAKER_NAMESPACE_ISO_9660)
1465 fNamespaces |= fOld & RTFSISOMAKERCMDNAME_PRIMARY_ISO_TRANS_TBL;
1466 if (fNamespaces & RTFSISOMAKER_NAMESPACE_JOLIET)
1467 fNamespaces |= fOld & RTFSISOMAKERCMDNAME_PRIMARY_ISO_TRANS_TBL;
1468 if (fNamespaces & RTFSISOMAKER_NAMESPACE_UDF)
1469 fNamespaces |= fOld & RTFSISOMAKERCMDNAME_UDF_TRANS_TBL;
1470 if (fNamespaces & RTFSISOMAKER_NAMESPACE_HFS)
1471 fNamespaces |= fOld & RTFSISOMAKERCMDNAME_HFS_TRANS_TBL;
1472
1473 /*
1474 * Apply the new configuration.
1475 */
1476 pOpts->cNameSpecifiers = 1;
1477 pOpts->afNameSpecifiers[0] = fNamespaces;
1478 pOpts->fDstNamespaces = fNamespaces & RTFSISOMAKERCMDNAME_MAJOR_MASK;
1479
1480 char szTmp[128];
1481 rtFsIsoMakerPrintf(pOpts, "info: --name-setup-from-import determined: --name-setup=%s\n",
1482 rtFsIsoMakerCmdNameSpecifiersToString(fNamespaces, szTmp, sizeof(szTmp)));
1483 return VINF_SUCCESS;
1484 }
1485 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_DRIVE_IS_EMPTY, "--name-setup-from-import used on an empty ISO");
1486}
1487
1488
1489/**
1490 * Checks if we should use the source stack or the regular file system for
1491 * opening a source.
1492 *
1493 * @returns true / false.
1494 * @param pOpts The ISO maker command instance.
1495 * @param pszSrc The source path under consideration.
1496 */
1497static bool rtFsIsoMakerCmdUseSrcStack(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSrc)
1498{
1499 /* Not if there isn't any stack. */
1500 if (pOpts->iSrcStack < 0)
1501 return false;
1502
1503 /* Not if we've got a :iprtvfs: incantation. */
1504 if (RTVfsChainIsSpec(pszSrc))
1505 return false;
1506
1507 /* If the top entry is a CWD rather than a VFS, we only do it for root-less paths. */
1508 if (pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfsOption == NULL)
1509 {
1510 if (RTPathStartsWithRoot(pszSrc))
1511 return false;
1512 }
1513 return true;
1514}
1515
1516
1517/**
1518 * Processes a non-option argument.
1519 *
1520 * @returns IPRT status code.
1521 * @param pOpts The ISO maker command instance.
1522 * @param pszSpec The specification of what to add.
1523 * @param fWithSrc Whether the specification includes a source path
1524 * or not.
1525 * @param pParsed Where to return the parsed name specification.
1526 */
1527static int rtFsIsoMakerCmdParseNameSpec(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSpec, bool fWithSrc,
1528 PRTFSISOMKCMDPARSEDNAMES pParsed)
1529{
1530 const char * const pszSpecIn = pszSpec;
1531 uint32_t const cMaxNames = pOpts->cNameSpecifiers + fWithSrc;
1532
1533 /*
1534 * Split it up by '='.
1535 */
1536 pParsed->cNames = 0;
1537 pParsed->cNamesWithSrc = 0;
1538 pParsed->enmSrcType = fWithSrc ? RTFSISOMKCMDPARSEDNAMES::kSrcType_Normal : RTFSISOMKCMDPARSEDNAMES::kSrcType_None;
1539 for (;;)
1540 {
1541 const char *pszEqual = strchr(pszSpec, '=');
1542 size_t cchName = pszEqual ? pszEqual - pszSpec : strlen(pszSpec);
1543 bool fNeedSlash = (pszEqual || !fWithSrc) && !RTPATH_IS_SLASH(*pszSpec) && cchName > 0;
1544 if (cchName + fNeedSlash >= sizeof(pParsed->aNames[pParsed->cNamesWithSrc].szPath))
1545 return rtFsIsoMakerCmdSyntaxError(pOpts, "name #%u (0-based) is too long: %s", pParsed->cNamesWithSrc, pszSpecIn);
1546 if (pParsed->cNamesWithSrc >= cMaxNames)
1547 return rtFsIsoMakerCmdSyntaxError(pOpts, "too many names specified (max %u%s): %s",
1548 pOpts->cNameSpecifiers, fWithSrc ? " + source" : "", pszSpecIn);
1549 if (!fNeedSlash)
1550 memcpy(pParsed->aNames[pParsed->cNamesWithSrc].szPath, pszSpec, cchName);
1551 else
1552 {
1553 memcpy(&pParsed->aNames[pParsed->cNamesWithSrc].szPath[1], pszSpec, cchName);
1554 pParsed->aNames[pParsed->cNamesWithSrc].szPath[0] = RTPATH_SLASH;
1555 cchName++;
1556 }
1557 pParsed->aNames[pParsed->cNamesWithSrc].szPath[cchName] = '\0';
1558 pParsed->aNames[pParsed->cNamesWithSrc].cchPath = (uint32_t)cchName;
1559 pParsed->cNamesWithSrc++;
1560
1561 if (!pszEqual)
1562 {
1563 if (fWithSrc)
1564 {
1565 if (!cchName)
1566 return rtFsIsoMakerCmdSyntaxError(pOpts, "empty source file name: %s", pszSpecIn);
1567 if (cchName == 8 && strcmp(pszSpec, ":remove:") == 0)
1568 pParsed->enmSrcType = RTFSISOMKCMDPARSEDNAMES::kSrcType_Remove;
1569 else if (cchName == 13 && strcmp(pszSpec, ":must-remove:") == 0)
1570 pParsed->enmSrcType = RTFSISOMKCMDPARSEDNAMES::kSrcType_MustRemove;
1571 else if (rtFsIsoMakerCmdUseSrcStack(pOpts, pszSpec))
1572 pParsed->enmSrcType = RTFSISOMKCMDPARSEDNAMES::kSrcType_NormalSrcStack;
1573 }
1574 break;
1575 }
1576 pszSpec = pszEqual + 1;
1577 }
1578
1579 /*
1580 * If there are too few names specified, move the source and repeat the
1581 * last non-source name. If only source, convert source into a name spec.
1582 */
1583 if (pParsed->cNamesWithSrc < cMaxNames)
1584 {
1585 uint32_t iSrc;
1586 if (!fWithSrc)
1587 iSrc = pParsed->cNamesWithSrc - 1;
1588 else
1589 {
1590 pParsed->aNames[pOpts->cNameSpecifiers] = pParsed->aNames[pParsed->cNamesWithSrc - 1];
1591 iSrc = pParsed->cNamesWithSrc >= 2 ? pParsed->cNamesWithSrc - 2 : 0;
1592 }
1593
1594 /* If the source is a input file name specifier, reduce it to something that starts with a slash. */
1595 if (pParsed->cNamesWithSrc == 1 && fWithSrc)
1596 {
1597 const char *pszSrc = pParsed->aNames[iSrc].szPath;
1598 char *pszFinalPath = NULL;
1599 if (RTVfsChainIsSpec(pParsed->aNames[iSrc].szPath))
1600 {
1601 uint32_t offError;
1602 int rc = RTVfsChainQueryFinalPath(pParsed->aNames[iSrc].szPath, &pszFinalPath, &offError);
1603 if (RT_FAILURE(rc))
1604 return rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainQueryFinalPath",
1605 pParsed->aNames[iSrc].szPath, rc, offError, NULL);
1606 pszSrc = pszFinalPath;
1607 }
1608
1609 /* Find the start of the last component, ignoring trailing slashes. */
1610 size_t cchSrc = strlen(pszSrc);
1611 size_t offLast = cchSrc;
1612 while (offLast > 0 && RTPATH_IS_SLASH(pszSrc[offLast - 1]))
1613 offLast--;
1614 while (offLast > 0 && !RTPATH_IS_SLASH(pszSrc[offLast - 1]))
1615 offLast--;
1616
1617 /* Move it up front with a leading slash. */
1618 if (offLast > 0 || !RTPATH_IS_SLASH(*pszSrc))
1619 {
1620 pParsed->aNames[iSrc].cchPath = 1 + (uint32_t)(cchSrc - offLast);
1621 if (pParsed->aNames[iSrc].cchPath >= sizeof(pParsed->aNames[iSrc].szPath))
1622 return rtFsIsoMakerCmdSyntaxError(pOpts, "name too long: %s", pszSpecIn);
1623
1624 memmove(&pParsed->aNames[iSrc].szPath[1], &pszSrc[offLast], pParsed->aNames[iSrc].cchPath);
1625 }
1626 else
1627 pParsed->aNames[iSrc].cchPath = 1;
1628 pParsed->aNames[iSrc].szPath[0] = RTPATH_SLASH;
1629
1630 if (pszFinalPath)
1631 RTStrFree(pszFinalPath);
1632 }
1633
1634 for (uint32_t iDst = iSrc + 1; iDst < pOpts->cNameSpecifiers; iDst++)
1635 pParsed->aNames[iDst] = pParsed->aNames[iSrc];
1636
1637 pParsed->cNamesWithSrc = cMaxNames;
1638 }
1639 pParsed->cNames = pOpts->cNameSpecifiers;
1640
1641 /*
1642 * Copy the specifier flags and check that the paths all starts with slashes.
1643 */
1644 for (uint32_t i = 0; i < pOpts->cNameSpecifiers; i++)
1645 {
1646 pParsed->aNames[i].fNameSpecifiers = pOpts->afNameSpecifiers[i];
1647 Assert( pParsed->aNames[i].cchPath == 0
1648 || RTPATH_IS_SLASH(pParsed->aNames[i].szPath[0]));
1649 }
1650
1651 return VINF_SUCCESS;
1652}
1653
1654
1655/**
1656 * Enteres an object into the namespace by full paths.
1657 *
1658 * This is used by rtFsIsoMakerCmdOptEltoritoSetBootCatalogPath and
1659 * rtFsIsoMakerCmdAddFile.
1660 *
1661 * @returns IPRT status code.
1662 * @param pOpts The ISO maker command instance.
1663 * @param idxObj The configuration index of the object to be named.
1664 * @param pParsed The parsed names.
1665 * @param pszSrcOrName Source file or name.
1666 */
1667static int rtFsIsoMakerCmdSetObjPaths(PRTFSISOMAKERCMDOPTS pOpts, uint32_t idxObj, PCRTFSISOMKCMDPARSEDNAMES pParsed,
1668 const char *pszSrcOrName)
1669{
1670 int rc = VINF_SUCCESS;
1671 for (uint32_t i = 0; i < pParsed->cNames; i++)
1672 if (pParsed->aNames[i].cchPath > 0)
1673 {
1674 if (pParsed->aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK)
1675 {
1676 rc = RTFsIsoMakerObjSetPath(pOpts->hIsoMaker, idxObj,
1677 pParsed->aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK,
1678 pParsed->aNames[i].szPath);
1679 if (RT_FAILURE(rc))
1680 {
1681 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error setting name '%s' on '%s': %Rrc",
1682 pParsed->aNames[i].szPath, pszSrcOrName, rc);
1683 break;
1684 }
1685 }
1686 if (pParsed->aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MINOR_MASK)
1687 {
1688 /** @todo add APIs for this. */
1689 }
1690 }
1691 return rc;
1692}
1693
1694
1695/**
1696 * Adds a file.
1697 *
1698 * @returns IPRT status code.
1699 * @param pOpts The ISO maker command instance.
1700 * @param pszSrc The path to the source file.
1701 * @param pParsed The parsed names.
1702 * @param pidxObj Where to return the configuration index for the
1703 * added file. Optional.
1704 */
1705static int rtFsIsoMakerCmdAddFile(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSrc, PCRTFSISOMKCMDPARSEDNAMES pParsed,
1706 uint32_t *pidxObj)
1707{
1708 int rc;
1709 uint32_t idxObj = UINT32_MAX;
1710 if (pParsed->enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_NormalSrcStack)
1711 {
1712 RTVFSFILE hVfsFileSrc;
1713 rc = RTVfsDirOpenFile(pOpts->aSrcStack[pOpts->iSrcStack].hSrcDir, pszSrc,
1714 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsFileSrc);
1715 if (RT_FAILURE(rc))
1716 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error opening '%s' (%s '%s'): %Rrc",
1717 pszSrc, pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfsOption ? "inside" : "relative to",
1718 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfs, rc);
1719
1720 rc = RTFsIsoMakerAddUnnamedFileWithVfsFile(pOpts->hIsoMaker, hVfsFileSrc, &idxObj);
1721 RTVfsFileRelease(hVfsFileSrc);
1722 if (RT_FAILURE(rc))
1723 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error adding '%s' (VFS): %Rrc", pszSrc, rc);
1724 }
1725 else
1726 {
1727 rc = RTFsIsoMakerAddUnnamedFileWithSrcPath(pOpts->hIsoMaker, pszSrc, &idxObj);
1728 if (RT_FAILURE(rc))
1729 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error adding '%s': %Rrc", pszSrc, rc);
1730 }
1731
1732
1733 pOpts->cItemsAdded++;
1734 if (pidxObj)
1735 *pidxObj = idxObj;
1736
1737 return rtFsIsoMakerCmdSetObjPaths(pOpts, idxObj, pParsed, pszSrc);
1738}
1739
1740
1741/**
1742 * Applies filtering rules.
1743 *
1744 * @returns true if filtered out, false if included.
1745 * @param pOpts The ISO maker command instance.
1746 * @param pszSrc The source source.
1747 * @param pszName The name part (maybe different buffer from pszSrc).
1748 * @param fIsDir Set if directory, clear if not.
1749 */
1750static bool rtFsIsoMakerCmdIsFilteredOut(PRTFSISOMAKERCMDOPTS pOpts, const char *pszDir, const char *pszName, bool fIsDir)
1751{
1752 /* Ignore trans.tbl files. */
1753 if ( !fIsDir
1754 && RTStrICmp(pszName, pOpts->pszTransTbl) == 0)
1755 return true;
1756
1757 RT_NOREF(pOpts, pszDir, pszName, fIsDir);
1758 return false;
1759}
1760
1761
1762/**
1763 * Worker for rtFsIsoMakerCmdAddVfsDir that does the recursion.
1764 *
1765 * @returns IPRT status code.
1766 * @param pOpts The ISO maker command instance.
1767 * @param hVfsDir The directory to process.
1768 * @param idxDirObj The configuration index of the directory.
1769 * @param pszSrc Pointer to the source path buffer. RTPATH_MAX
1770 * in size. Okay to modify beyond @a cchSrc.
1771 * @param cchSrc Length of the path corresponding to @a hVfsDir.
1772 * @param fNamespaces Which ISO maker namespaces to add the names to.
1773 * @param cDepth Number of recursions. Used to deal with loopy
1774 * directories.
1775 * @param fFilesWithSrcPath Whether to add files using @a pszSrc or to add
1776 * as VFS handles (open first). For saving native
1777 * file descriptors.
1778 */
1779static int rtFsIsoMakerCmdAddVfsDirRecursive(PRTFSISOMAKERCMDOPTS pOpts, RTVFSDIR hVfsDir, uint32_t idxDirObj,
1780 char *pszSrc, size_t cchSrc, uint32_t fNamespaces, uint8_t cDepth,
1781 bool fFilesWithSrcPath)
1782{
1783 /*
1784 * Check that we're not in too deep.
1785 */
1786 if (cDepth >= RTFSISOMAKERCMD_MAX_DIR_RECURSIONS)
1787 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_ISOMK_IMPORT_TOO_DEEP_DIR_TREE,
1788 "Recursive (VFS) dir add too deep (depth=%u): %.*s", cDepth, cchSrc, pszSrc);
1789 /*
1790 * Enumerate the directory.
1791 */
1792 int rc;
1793 size_t cbDirEntryAlloced = sizeof(RTDIRENTRYEX);
1794 PRTDIRENTRYEX pDirEntry = (PRTDIRENTRYEX)RTMemTmpAlloc(cbDirEntryAlloced);
1795 if (pDirEntry)
1796 {
1797 for (;;)
1798 {
1799 /*
1800 * Read the next entry.
1801 */
1802 size_t cbDirEntry = cbDirEntryAlloced;
1803 rc = RTVfsDirReadEx(hVfsDir, pDirEntry, &cbDirEntry, RTFSOBJATTRADD_UNIX);
1804 if (RT_FAILURE(rc))
1805 {
1806 if (rc == VERR_NO_MORE_FILES)
1807 rc = VINF_SUCCESS;
1808 else if (rc == VERR_BUFFER_OVERFLOW)
1809 {
1810 RTMemTmpFree(pDirEntry);
1811 cbDirEntryAlloced = RT_ALIGN_Z(RT_MIN(cbDirEntry, cbDirEntryAlloced) + 64, 64);
1812 pDirEntry = (PRTDIRENTRYEX)RTMemTmpAlloc(cbDirEntryAlloced);
1813 if (pDirEntry)
1814 continue;
1815 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_NO_TMP_MEMORY, "Out of memory (direntry buffer)");
1816 }
1817 else
1818 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTVfsDirReadEx failed on %.*s: %Rrc", cchSrc, pszSrc, rc);
1819 break;
1820 }
1821
1822 /* Ignore '.' and '..' entries. */
1823 if (RTDirEntryExIsStdDotLink(pDirEntry))
1824 continue;
1825
1826 /*
1827 * Process the entry.
1828 */
1829
1830 /* Update the name. */
1831 if (cchSrc + 1 + pDirEntry->cbName < RTPATH_MAX)
1832 {
1833 pszSrc[cchSrc] = '/'; /* VFS only groks unix slashes */
1834 memcpy(&pszSrc[cchSrc + 1], pDirEntry->szName, pDirEntry->cbName);
1835 pszSrc[cchSrc + 1 + pDirEntry->cbName] = '\0';
1836 }
1837 else
1838 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_FILENAME_TOO_LONG, "Filename is too long (depth %u): '%.*s/%s'",
1839 cDepth, cchSrc, pszSrc, pDirEntry->szName);
1840
1841 /* Okay? Check name filtering. */
1842 if ( RT_SUCCESS(rc)
1843 && !rtFsIsoMakerCmdIsFilteredOut(pOpts, pszSrc, pDirEntry->szName, RTFS_IS_DIRECTORY(pDirEntry->Info.Attr.fMode)))
1844 {
1845 /* Do type specific adding. */
1846 uint32_t idxObj = UINT32_MAX;
1847 if (RTFS_IS_FILE(pDirEntry->Info.Attr.fMode))
1848 {
1849 /*
1850 * Files are either added with VFS handles or paths to the sources,
1851 * depending on what's considered more efficient. We prefer the latter
1852 * if hVfsDir maps to native handle and not a virtual one.
1853 */
1854 if (!fFilesWithSrcPath)
1855 {
1856 RTVFSFILE hVfsFileSrc;
1857 rc = RTVfsDirOpenFile(hVfsDir, pDirEntry->szName,
1858 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsFileSrc);
1859 if (RT_SUCCESS(rc))
1860 {
1861 rc = RTFsIsoMakerAddUnnamedFileWithVfsFile(pOpts->hIsoMaker, hVfsFileSrc, &idxObj);
1862 RTVfsFileRelease(hVfsFileSrc);
1863 if (RT_FAILURE(rc))
1864 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error adding file '%s' (VFS recursive, handle): %Rrc",
1865 pszSrc, rc);
1866 }
1867 else
1868 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error opening file '%s' (VFS recursive): %Rrc", pszSrc, rc);
1869 }
1870 else
1871 {
1872 /* Add file with source path: */
1873 rc = RTFsIsoMakerAddUnnamedFileWithSrcPath(pOpts->hIsoMaker, pszSrc, &idxObj);
1874 if (RT_FAILURE(rc))
1875 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error adding file '%s' (VFS recursive, path): %Rrc",
1876 pszSrc, rc);
1877 }
1878 if (RT_SUCCESS(rc))
1879 {
1880 pOpts->cItemsAdded++;
1881 rc = RTFsIsoMakerObjSetNameAndParent(pOpts->hIsoMaker, idxObj, idxDirObj, fNamespaces,
1882 pDirEntry->szName, false /*fNoNormalize*/);
1883 if (RT_FAILURE(rc))
1884 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error setting parent & name on file '%s' to '%s': %Rrc",
1885 pszSrc, pDirEntry->szName, rc);
1886 }
1887 }
1888 else if (RTFS_IS_DIRECTORY(pDirEntry->Info.Attr.fMode))
1889 {
1890 /*
1891 * Open and add the sub-directory.
1892 */
1893 RTVFSDIR hVfsSubDirSrc;
1894 rc = RTVfsDirOpenDir(hVfsDir, pDirEntry->szName, 0 /*fFlags*/, &hVfsSubDirSrc);
1895 if (RT_SUCCESS(rc))
1896 {
1897 rc = RTFsIsoMakerAddUnnamedDir(pOpts->hIsoMaker, &pDirEntry->Info, &idxObj);
1898 if (RT_SUCCESS(rc))
1899 {
1900 pOpts->cItemsAdded++;
1901 rc = RTFsIsoMakerObjSetNameAndParent(pOpts->hIsoMaker, idxObj, idxDirObj, fNamespaces,
1902 pDirEntry->szName, false /*fNoNormalize*/);
1903 if (RT_SUCCESS(rc))
1904 /* Recurse into the sub-directory. */
1905 rc = rtFsIsoMakerCmdAddVfsDirRecursive(pOpts, hVfsSubDirSrc, idxObj, pszSrc,
1906 cchSrc + 1 + pDirEntry->cbName, fNamespaces, cDepth + 1,
1907 fFilesWithSrcPath);
1908 else
1909 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc,
1910 "Error setting parent & name on directory '%s' to '%s': %Rrc",
1911 pszSrc, pDirEntry->szName, rc);
1912 }
1913 else
1914 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error adding directory '%s' (VFS recursive): %Rrc", pszSrc, rc);
1915 RTVfsDirRelease(hVfsSubDirSrc);
1916 }
1917 else
1918 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error opening directory '%s' (VFS recursive): %Rrc", pszSrc, rc);
1919 }
1920 else if (RTFS_IS_SYMLINK(pDirEntry->Info.Attr.fMode))
1921 {
1922 /*
1923 * TODO: ISO FS symlink support.
1924 */
1925 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_IMPLEMENTED,
1926 "Adding symlink '%s' failed: not yet implemented", pszSrc);
1927 }
1928 else
1929 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_IMPLEMENTED,
1930 "Adding special file '%s' failed: not implemented", pszSrc);
1931 }
1932 if (RT_FAILURE(rc))
1933 break;
1934 }
1935
1936 RTMemTmpFree(pDirEntry);
1937 }
1938 else
1939 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_NO_TMP_MEMORY, "Out of memory! (direntry buffer)");
1940 return rc;
1941}
1942
1943
1944/**
1945 * Common directory adding worker.
1946 *
1947 * @returns IPRT status code.
1948 * @param pOpts The ISO maker command instance.
1949 * @param hVfsSrcDir The directory being added.
1950 * @param pszSrc The source directory name.
1951 * @param pParsed The parsed names.
1952 * @param fFilesWithSrcPath Whether to add files using @a pszSrc
1953 * or to add as VFS handles (open first). For
1954 * saving native file descriptors.
1955 * @param pidxObj Where to return the configuration index for the
1956 * added file. Optional.
1957 */
1958static int rtFsIsoMakerCmdAddVfsDirCommon(PRTFSISOMAKERCMDOPTS pOpts, RTVFSDIR hVfsDirSrc, char *pszSrc,
1959 PCRTFSISOMKCMDPARSEDNAMES pParsed, bool fFilesWithSrcPath, PCRTFSOBJINFO pObjInfo)
1960{
1961 /*
1962 * Add the directory if it doesn't exist.
1963 */
1964 uint32_t idxObj = UINT32_MAX;
1965 for (uint32_t i = 0; i < pParsed->cNames; i++)
1966 if (pParsed->aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK)
1967 {
1968 idxObj = RTFsIsoMakerGetObjIdxForPath(pOpts->hIsoMaker,
1969 pParsed->aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK,
1970 pParsed->aNames[i].szPath);
1971 if (idxObj != UINT32_MAX)
1972 {
1973 /** @todo make sure the directory is present in the other namespace. */
1974 break;
1975 }
1976 }
1977 int rc = VINF_SUCCESS;
1978 if (idxObj == UINT32_MAX)
1979 {
1980 rc = RTFsIsoMakerAddUnnamedDir(pOpts->hIsoMaker, pObjInfo, &idxObj);
1981 if (RT_SUCCESS(rc))
1982 rc = rtFsIsoMakerCmdSetObjPaths(pOpts, idxObj, pParsed, pParsed->aNames[pParsed->cNames - 1].szPath);
1983 else
1984 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerAddUnnamedDir failed: %Rrc", rc);
1985 }
1986 if (RT_SUCCESS(rc))
1987 {
1988 /*
1989 * Add the directory content.
1990 */
1991 uint32_t fNamespaces = 0;
1992 for (uint32_t i = 0; i < pParsed->cNames; i++)
1993 fNamespaces |= pParsed->aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK;
1994 rc = rtFsIsoMakerCmdAddVfsDirRecursive(pOpts, hVfsDirSrc, idxObj, pszSrc,
1995 pParsed->aNames[pParsed->cNamesWithSrc - 1].cchPath, fNamespaces, 0 /*cDepth*/,
1996 fFilesWithSrcPath);
1997 }
1998
1999 return rc;
2000}
2001
2002
2003/**
2004 * Adds a directory, from the source VFS.
2005 *
2006 * @returns IPRT status code.
2007 * @param pOpts The ISO maker command instance.
2008 * @param pParsed The parsed names.
2009 * @param pidxObj Where to return the configuration index for the
2010 * added file. Optional.
2011 */
2012static int rtFsIsoMakerCmdAddVfsDir(PRTFSISOMAKERCMDOPTS pOpts, PCRTFSISOMKCMDPARSEDNAMES pParsed, PCRTFSOBJINFO pObjInfo)
2013{
2014 Assert(pParsed->cNames < pParsed->cNamesWithSrc);
2015 char *pszSrc = pParsed->aNames[pParsed->cNamesWithSrc - 1].szPath;
2016 RTPathChangeToUnixSlashes(pszSrc, true /*fForce*/); /* VFS currently only understand unix slashes. */
2017 RTVFSDIR hVfsDirSrc;
2018 int rc = RTVfsDirOpenDir(pOpts->aSrcStack[pOpts->iSrcStack].hSrcDir, pszSrc, 0 /*fFlags*/, &hVfsDirSrc);
2019 if (RT_SUCCESS(rc))
2020 {
2021 rc = rtFsIsoMakerCmdAddVfsDirCommon(pOpts, hVfsDirSrc, pszSrc, pParsed, false /*fFilesWithSrcPath*/, pObjInfo);
2022 RTVfsDirRelease(hVfsDirSrc);
2023 }
2024 else
2025 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error opening directory '%s' (%s '%s'): %Rrc", pszSrc,
2026 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfsOption ? "inside" : "relative to",
2027 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfs, rc);
2028 return rc;
2029}
2030
2031
2032/**
2033 * Adds a directory, from a VFS chain or real file system.
2034 *
2035 * @returns IPRT status code.
2036 * @param pOpts The ISO maker command instance.
2037 * @param pszSrc The path to the source directory.
2038 * @param pParsed The parsed names.
2039 */
2040static int rtFsIsoMakerCmdAddDir(PRTFSISOMAKERCMDOPTS pOpts, PCRTFSISOMKCMDPARSEDNAMES pParsed, PCRTFSOBJINFO pObjInfo)
2041{
2042 Assert(pParsed->cNames < pParsed->cNamesWithSrc);
2043 char *pszSrc = pParsed->aNames[pParsed->cNamesWithSrc - 1].szPath;
2044 RTERRINFOSTATIC ErrInfo;
2045 uint32_t offError;
2046 RTVFSDIR hVfsDirSrc;
2047 int rc = RTVfsChainOpenDir(pszSrc, 0 /*fOpen*/, &hVfsDirSrc, &offError, RTErrInfoInitStatic(&ErrInfo));
2048 if (RT_SUCCESS(rc))
2049 {
2050 rc = rtFsIsoMakerCmdAddVfsDirCommon(pOpts, hVfsDirSrc, pszSrc, pParsed,
2051 RTVfsDirIsStdDir(hVfsDirSrc) /*fFilesWithSrcPath*/, pObjInfo);
2052 RTVfsDirRelease(hVfsDirSrc);
2053 }
2054 else
2055 rc = rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainOpenDir", pszSrc, rc, offError, &ErrInfo.Core);
2056 return rc;
2057}
2058
2059
2060/**
2061 * Adds a file after first making sure it's a file.
2062 *
2063 * @returns IPRT status code
2064 * @param pOpts The ISO maker command instance.
2065 * @param pszSrc The path to the source file.
2066 * @param pParsed The parsed names.
2067 * @param pidxObj Where to return the configuration index for the
2068 * added file. Optional.
2069 */
2070static int rtFsIsoMakerCmdStatAndAddFile(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSrc, PCRTFSISOMKCMDPARSEDNAMES pParsed,
2071 uint32_t *pidxObj)
2072{
2073 int rc;
2074 RTFSOBJINFO ObjInfo;
2075 if (pParsed->enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_NormalSrcStack)
2076 {
2077 rc = RTVfsDirQueryPathInfo(pOpts->aSrcStack[pOpts->iSrcStack].hSrcDir, pszSrc,
2078 &ObjInfo, RTFSOBJATTRADD_UNIX, RTPATH_F_FOLLOW_LINK);
2079 if (RT_FAILURE(rc))
2080 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTVfsQueryPathInfo failed on %s (%s %s): %Rrc", pszSrc,
2081 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfsOption ? "inside" : "relative to",
2082 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfs, rc);
2083 }
2084 else
2085 {
2086 uint32_t offError;
2087 RTERRINFOSTATIC ErrInfo;
2088 rc = RTVfsChainQueryInfo(pszSrc, &ObjInfo, RTFSOBJATTRADD_UNIX,
2089 RTPATH_F_FOLLOW_LINK, &offError, RTErrInfoInitStatic(&ErrInfo));
2090 if (RT_FAILURE(rc))
2091 return rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainQueryInfo", pszSrc, rc, offError, &ErrInfo.Core);
2092 }
2093
2094 if (RTFS_IS_FILE(ObjInfo.Attr.fMode))
2095 return rtFsIsoMakerCmdAddFile(pOpts, pszSrc, pParsed, pidxObj);
2096 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_A_FILE, "Not a file: %s", pszSrc);
2097}
2098
2099
2100/**
2101 * Processes a non-option argument.
2102 *
2103 * @returns IPRT status code.
2104 * @param pOpts The ISO maker command instance.
2105 * @param pszSpec The specification of what to add.
2106 */
2107static int rtFsIsoMakerCmdAddSomething(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSpec)
2108{
2109 /*
2110 * Parse the name spec.
2111 */
2112 RTFSISOMKCMDPARSEDNAMES Parsed;
2113 int rc = rtFsIsoMakerCmdParseNameSpec(pOpts, pszSpec, true /*fWithSrc*/, &Parsed);
2114 if (RT_FAILURE(rc))
2115 return rc;
2116
2117 /*
2118 * Deal with special source filenames used to remove/change stuff.
2119 */
2120 if ( Parsed.enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_Remove
2121 || Parsed.enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_MustRemove)
2122 {
2123 uint32_t cRemoved = 0;
2124 for (uint32_t i = 0; i < pOpts->cNameSpecifiers; i++)
2125 if ( Parsed.aNames[i].cchPath > 0
2126 && (Parsed.aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK))
2127 {
2128 /* Make sure we remove all objects by this name. */
2129 for (;;)
2130 {
2131 uint32_t idxObj = RTFsIsoMakerGetObjIdxForPath(pOpts->hIsoMaker,
2132 Parsed.aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK,
2133 Parsed.aNames[i].szPath);
2134 if (idxObj == UINT32_MAX)
2135 break;
2136 rc = RTFsIsoMakerObjRemove(pOpts->hIsoMaker, idxObj);
2137 if (RT_FAILURE(rc))
2138 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to remove '%s': %Rrc", pszSpec, rc);
2139 cRemoved++;
2140 }
2141 }
2142 if ( Parsed.enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_MustRemove
2143 && cRemoved == 0)
2144 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_FOUND, "Failed to locate '%s' for removal", pszSpec);
2145 }
2146 /*
2147 * Add regular source.
2148 */
2149 else
2150 {
2151 const char *pszSrc = Parsed.aNames[Parsed.cNamesWithSrc - 1].szPath;
2152 RTFSOBJINFO ObjInfo;
2153 if (Parsed.enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_NormalSrcStack)
2154 {
2155 rc = RTVfsDirQueryPathInfo(pOpts->aSrcStack[pOpts->iSrcStack].hSrcDir, pszSrc,
2156 &ObjInfo, RTFSOBJATTRADD_UNIX, RTPATH_F_FOLLOW_LINK);
2157 if (RT_FAILURE(rc))
2158 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTVfsQueryPathInfo failed on %s (%s %s): %Rrc", pszSrc,
2159 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfsOption ? "inside" : "relative to",
2160 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfs, rc);
2161 }
2162 else
2163 {
2164 uint32_t offError;
2165 RTERRINFOSTATIC ErrInfo;
2166 rc = RTVfsChainQueryInfo(pszSrc, &ObjInfo, RTFSOBJATTRADD_UNIX,
2167 RTPATH_F_FOLLOW_LINK, &offError, RTErrInfoInitStatic(&ErrInfo));
2168 if (RT_FAILURE(rc))
2169 return rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainQueryInfo", pszSrc, rc, offError, &ErrInfo.Core);
2170 }
2171
2172 /* By type: */
2173
2174 if (RTFS_IS_FILE(ObjInfo.Attr.fMode))
2175 return rtFsIsoMakerCmdAddFile(pOpts, pszSrc, &Parsed, NULL /*pidxObj*/);
2176
2177 if (RTFS_IS_DIRECTORY(ObjInfo.Attr.fMode))
2178 {
2179 if (Parsed.enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_NormalSrcStack)
2180 return rtFsIsoMakerCmdAddVfsDir(pOpts, &Parsed, &ObjInfo);
2181 return rtFsIsoMakerCmdAddDir(pOpts, &Parsed, &ObjInfo);
2182 }
2183
2184 if (RTFS_IS_SYMLINK(ObjInfo.Attr.fMode))
2185 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_IMPLEMENTED, "Adding symlink '%s' failed: not yet implemented", pszSpec);
2186
2187 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_IMPLEMENTED, "Adding special file '%s' failed: not implemented", pszSpec);
2188 }
2189
2190 return VINF_SUCCESS;
2191}
2192
2193
2194/**
2195 * Opens an ISO and use it for subsequent file system accesses.
2196 *
2197 * This is handy for duplicating a part of an ISO in the new image.
2198 *
2199 * @returns IPRT status code.
2200 * @param pOpts The ISO maker command instance.
2201 * @param pszIsoSpec The ISO path specifier.
2202 * @param pszOption The option we're being called on.
2203 * @param fFlags RTFSISO9660_F_XXX
2204 */
2205static int rtFsIsoMakerCmdOptPushIso(PRTFSISOMAKERCMDOPTS pOpts, const char *pszIsoSpec, const char *pszOption, uint32_t fFlags)
2206{
2207 int32_t iSrcStack = pOpts->iSrcStack + 1;
2208 if ((uint32_t)iSrcStack >= RT_ELEMENTS(pOpts->aSrcStack))
2209 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_IMPLEMENTED,
2210 "Too many pushes %s %s (previous: %s %s, %s %s, %s %s, ...)",
2211 pszOption, pszIsoSpec,
2212 pOpts->aSrcStack[iSrcStack - 1].pszSrcVfsOption, pOpts->aSrcStack[iSrcStack - 1].pszSrcVfs,
2213 pOpts->aSrcStack[iSrcStack - 2].pszSrcVfsOption, pOpts->aSrcStack[iSrcStack - 2].pszSrcVfs,
2214 pOpts->aSrcStack[iSrcStack - 3].pszSrcVfsOption, pOpts->aSrcStack[iSrcStack - 3].pszSrcVfs);
2215
2216 /*
2217 * Try open the file.
2218 */
2219 int rc;
2220 RTVFSFILE hVfsFileIso = NIL_RTVFSFILE;
2221 RTERRINFOSTATIC ErrInfo;
2222 if (rtFsIsoMakerCmdUseSrcStack(pOpts, pszIsoSpec))
2223 {
2224 rc = RTVfsDirOpenFile(pOpts->aSrcStack[iSrcStack - 1].hSrcDir, pszIsoSpec,
2225 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsFileIso);
2226 if (RT_FAILURE(rc))
2227 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error opening '%s' relative to '%s'",
2228 pszIsoSpec, pOpts->aSrcStack[iSrcStack - 1].pszSrcVfs);
2229 }
2230 else
2231 {
2232 uint32_t offError;
2233 rc = RTVfsChainOpenFile(pszIsoSpec, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE,
2234 &hVfsFileIso, &offError, RTErrInfoInitStatic(&ErrInfo));
2235 if (RT_FAILURE(rc))
2236 rc = rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainOpenFile", pszIsoSpec, rc, offError, &ErrInfo.Core);
2237 }
2238 if (RT_SUCCESS(rc))
2239 {
2240 RTVFS hSrcVfs;
2241 rc = RTFsIso9660VolOpen(hVfsFileIso, fFlags, &hSrcVfs, RTErrInfoInitStatic(&ErrInfo));
2242 RTVfsFileRelease(hVfsFileIso);
2243 if (RT_SUCCESS(rc))
2244 {
2245 RTVFSDIR hVfsSrcRootDir;
2246 rc = RTVfsOpenRoot(hSrcVfs, &hVfsSrcRootDir);
2247 if (RT_SUCCESS(rc))
2248 {
2249 pOpts->aSrcStack[iSrcStack].hSrcDir = hVfsSrcRootDir;
2250 pOpts->aSrcStack[iSrcStack].hSrcVfs = hSrcVfs;
2251 pOpts->aSrcStack[iSrcStack].pszSrcVfs = pszIsoSpec;
2252 pOpts->aSrcStack[iSrcStack].pszSrcVfsOption = pszOption;
2253 pOpts->iSrcStack = iSrcStack;
2254 return VINF_SUCCESS;
2255 }
2256 RTVfsRelease(hSrcVfs);
2257 }
2258 else if (RTErrInfoIsSet(&ErrInfo.Core))
2259 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to open '%s' as ISO FS: %Rrc - %s",
2260 pszIsoSpec, rc, ErrInfo.Core.pszMsg);
2261 else
2262 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to open '%s' as ISO FS: %Rrc", pszIsoSpec, rc);
2263 }
2264 return rc;
2265}
2266
2267
2268/**
2269 * Counter part to --push-iso and friends.
2270 *
2271 * @returns IPRT status code.
2272 * @param pOpts The ISO maker command instance.
2273 */
2274static int rtFsIsoMakerCmdOptPop(PRTFSISOMAKERCMDOPTS pOpts)
2275{
2276 int32_t const iSrcStack = pOpts->iSrcStack;
2277 if ( iSrcStack >= 0
2278 && pOpts->aSrcStack[iSrcStack].pszSrcVfsOption)
2279 {
2280 RTVfsDirRelease(pOpts->aSrcStack[iSrcStack].hSrcDir);
2281 RTVfsRelease(pOpts->aSrcStack[iSrcStack].hSrcVfs);
2282 pOpts->aSrcStack[iSrcStack].hSrcDir = NIL_RTVFSDIR;
2283 pOpts->aSrcStack[iSrcStack].hSrcVfs = NIL_RTVFS;
2284 pOpts->aSrcStack[iSrcStack].pszSrcVfs = NULL;
2285 pOpts->aSrcStack[iSrcStack].pszSrcVfsOption = NULL;
2286 pOpts->iSrcStack = iSrcStack - 1;
2287 return VINF_SUCCESS;
2288 }
2289 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_FOUND, "--pop without --push-xxx");
2290}
2291
2292
2293/**
2294 * Deals with the --import-iso {iso-file-spec} options.
2295 *
2296 * @returns IPRT status code
2297 * @param pOpts The ISO maker command instance.
2298 * @param pszIsoSpec The ISO path specifier.
2299 */
2300static int rtFsIsoMakerCmdOptImportIso(PRTFSISOMAKERCMDOPTS pOpts, const char *pszIsoSpec)
2301{
2302 /*
2303 * Open the input file.
2304 */
2305 RTERRINFOSTATIC ErrInfo;
2306 RTVFSFILE hIsoFile;
2307 int rc;
2308 if (rtFsIsoMakerCmdUseSrcStack(pOpts, pszIsoSpec))
2309 {
2310 rc = RTVfsDirOpenFile(pOpts->aSrcStack[pOpts->iSrcStack].hSrcDir, pszIsoSpec,
2311 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hIsoFile);
2312 if (RT_FAILURE(rc))
2313 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to open '%s' %s %s for importing: %Rrc", pszIsoSpec,
2314 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfsOption ? "inside" : "relative to",
2315 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfs, rc);
2316 }
2317 else
2318 {
2319 uint32_t offError;
2320 rc = RTVfsChainOpenFile(pszIsoSpec, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE,
2321 &hIsoFile, &offError, RTErrInfoInitStatic(&ErrInfo));
2322 if (RT_FAILURE(rc))
2323 return rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainOpenFile", pszIsoSpec, rc, offError, &ErrInfo.Core);
2324 }
2325
2326 RTFSISOMAKERIMPORTRESULTS Results;
2327 rc = RTFsIsoMakerImport(pOpts->hIsoMaker, hIsoFile, 0 /*fFlags*/, &Results, RTErrInfoInitStatic(&ErrInfo));
2328
2329 RTVfsFileRelease(hIsoFile);
2330
2331 pOpts->cItemsAdded += Results.cAddedFiles;
2332 pOpts->cItemsAdded += Results.cAddedSymlinks;
2333 pOpts->cItemsAdded += Results.cAddedDirs;
2334 pOpts->cItemsAdded += Results.cBootCatEntries != UINT32_MAX ? Results.cBootCatEntries : 0;
2335 pOpts->cItemsAdded += Results.cbSysArea != 0 ? 1 : 0;
2336
2337 rtFsIsoMakerPrintf(pOpts, "ISO imported statistics for '%s'\n", pszIsoSpec);
2338 rtFsIsoMakerPrintf(pOpts, " cAddedNames: %'14RU32\n", Results.cAddedNames);
2339 rtFsIsoMakerPrintf(pOpts, " cAddedDirs: %'14RU32\n", Results.cAddedDirs);
2340 rtFsIsoMakerPrintf(pOpts, " cbAddedDataBlocks: %'14RU64 bytes\n", Results.cbAddedDataBlocks);
2341 rtFsIsoMakerPrintf(pOpts, " cAddedFiles: %'14RU32\n", Results.cAddedFiles);
2342 rtFsIsoMakerPrintf(pOpts, " cAddedSymlinks: %'14RU32\n", Results.cAddedSymlinks);
2343 if (Results.cBootCatEntries == UINT32_MAX)
2344 rtFsIsoMakerPrintf(pOpts, " cBootCatEntries: none\n");
2345 else
2346 rtFsIsoMakerPrintf(pOpts, " cBootCatEntries: %'14RU32\n", Results.cBootCatEntries);
2347 rtFsIsoMakerPrintf(pOpts, " cbSysArea: %'14RU32\n", Results.cbSysArea);
2348 rtFsIsoMakerPrintf(pOpts, " cErrors: %'14RU32\n", Results.cErrors);
2349
2350 if (RT_SUCCESS(rc))
2351 return rc;
2352 if (RTErrInfoIsSet(&ErrInfo.Core))
2353 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerImport failed: %Rrc - %s", rc, ErrInfo.Core.pszMsg);
2354 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerImport failed: %Rrc", rc);
2355}
2356
2357
2358/**
2359 * Deals with: --iso-level, -l
2360 *
2361 * @returns IPRT status code
2362 * @param pOpts The ISO maker command instance.
2363 * @param uLevel The new ISO level.
2364 */
2365static int rtFsIsoMakerCmdOptSetIsoLevel(PRTFSISOMAKERCMDOPTS pOpts, uint8_t uLevel)
2366{
2367 int rc = RTFsIsoMakerSetIso9660Level(pOpts->hIsoMaker, uLevel);
2368 if (RT_SUCCESS(rc))
2369 return rc;
2370 if (rc == VERR_WRONG_ORDER)
2371 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Cannot change ISO level to %d after having added files!", uLevel);
2372 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to set ISO level to %d: %Rrc", uLevel, rc);
2373}
2374
2375
2376/**
2377 * Deals with: --rock-ridge, --limited-rock-ridge, --no-rock-ridge
2378 *
2379 * @returns IPRT status code
2380 * @param pOpts The ISO maker command instance.
2381 * @param uLevel The new rock ridge level.
2382 */
2383static int rtFsIsoMakerCmdOptSetPrimaryRockLevel(PRTFSISOMAKERCMDOPTS pOpts, uint8_t uLevel)
2384{
2385 int rc = RTFsIsoMakerSetRockRidgeLevel(pOpts->hIsoMaker, uLevel);
2386 if (RT_SUCCESS(rc))
2387 return rc;
2388 if (rc == VERR_WRONG_ORDER)
2389 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Cannot change rock ridge level to %d after having added files!", uLevel);
2390 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to set rock ridge level to %d: %Rrc", uLevel, rc);
2391}
2392
2393
2394/**
2395 * Deals with: --joliet, --no-joliet, --joliet-ucs-level, --ucs-level
2396 *
2397 * @returns IPRT status code
2398 * @param pOpts The ISO maker command instance.
2399 * @param uLevel The new rock ridge level.
2400 */
2401static int rtFsIsoMakerCmdOptSetJolietUcs2Level(PRTFSISOMAKERCMDOPTS pOpts, uint8_t uLevel)
2402{
2403 int rc = RTFsIsoMakerSetJolietUcs2Level(pOpts->hIsoMaker, uLevel);
2404 if (RT_SUCCESS(rc))
2405 return rc;
2406 if (rc == VERR_WRONG_ORDER)
2407 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Cannot change joliet UCS level to %d after having added files!", uLevel);
2408 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to set joliet UCS level to %d: %Rrc", uLevel, rc);
2409}
2410
2411
2412/**
2413 * Deals with: --rational-attribs, --strict-attribs, -R, -r
2414 *
2415 * @returns IPRT status code
2416 * @param pOpts The ISO maker command instance.
2417 * @param uLevel The new rock ridge level.
2418 */
2419static int rtFsIsoMakerCmdOptSetAttribInheritStyle(PRTFSISOMAKERCMDOPTS pOpts, bool fStrict)
2420{
2421 int rc = RTFsIsoMakerSetAttribInheritStyle(pOpts->hIsoMaker, fStrict);
2422 if (RT_SUCCESS(rc))
2423 return rc;
2424 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to change attributes handling style to %s: %Rrc",
2425 fStrict ? "strict" : "rational", rc);
2426}
2427
2428
2429/**
2430 * Deals with: -G|--generic-boot {file}
2431 *
2432 * This concers content the first 16 sectors of the image. We start loading the
2433 * file at byte 0 in the image and stops at 32KB.
2434 *
2435 * @returns IPRT status code
2436 * @param pOpts The ISO maker command instance.
2437 * @param pszGenericBootImage The generic boot image source.
2438 */
2439static int rtFsIsoMakerCmdOptGenericBoot(PRTFSISOMAKERCMDOPTS pOpts, const char *pszGenericBootImage)
2440{
2441 RTERRINFOSTATIC ErrInfo;
2442 uint32_t offError;
2443 RTVFSFILE hVfsFile;
2444 int rc = RTVfsChainOpenFile(pszGenericBootImage, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsFile,
2445 &offError, RTErrInfoInitStatic(&ErrInfo));
2446 if (RT_FAILURE(rc))
2447 return rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainOpenFile", pszGenericBootImage, rc, offError, &ErrInfo.Core);
2448
2449 uint8_t abBuf[_32K];
2450 size_t cbRead;
2451 rc = RTVfsFileReadAt(hVfsFile, 0, abBuf, sizeof(abBuf), &cbRead);
2452 RTVfsFileRelease(hVfsFile);
2453 if (RT_FAILURE(rc))
2454 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error reading 32KB from generic boot image '%s': %Rrc", pszGenericBootImage, rc);
2455
2456 rc = RTFsIsoMakerSetSysAreaContent(pOpts->hIsoMaker, abBuf, cbRead, 0);
2457 if (RT_FAILURE(rc))
2458 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerSetSysAreaContent failed with a %zu bytes input: %Rrc", cbRead, rc);
2459
2460 return VINF_SUCCESS;
2461}
2462
2463
2464/**
2465 * Helper that makes sure we've got a validation boot entry.
2466 *
2467 * @returns IPRT status code
2468 * @param pOpts The ISO maker command instance.
2469 */
2470static void rtFsIsoMakerCmdOptEltoritoEnsureValidationEntry(PRTFSISOMAKERCMDOPTS pOpts)
2471{
2472 if (pOpts->cBootCatEntries == 0)
2473 {
2474 pOpts->aBootCatEntries[0].enmType = RTFSISOMKCMDELTORITOENTRY::kEntryType_Validation;
2475 pOpts->aBootCatEntries[0].u.Validation.idPlatform = ISO9660_ELTORITO_PLATFORM_ID_X86;
2476 pOpts->aBootCatEntries[0].u.Validation.pszString = NULL;
2477 pOpts->cBootCatEntries = 1;
2478 }
2479}
2480
2481
2482/**
2483 * Helper that makes sure we've got a current boot entry.
2484 *
2485 * @returns IPRT status code
2486 * @param pOpts The ISO maker command instance.
2487 * @param fForceNew Whether to force a new entry.
2488 * @param pidxBootCat Where to return the boot catalog index.
2489 */
2490static int rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(PRTFSISOMAKERCMDOPTS pOpts, bool fForceNew, uint32_t *pidxBootCat)
2491{
2492 rtFsIsoMakerCmdOptEltoritoEnsureValidationEntry(pOpts);
2493
2494 uint32_t i = pOpts->cBootCatEntries;
2495 if (i == 2 && fForceNew)
2496 {
2497 pOpts->aBootCatEntries[i].enmType = RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader;
2498 pOpts->aBootCatEntries[i].u.SectionHeader.idPlatform = pOpts->aBootCatEntries[0].u.Validation.idPlatform;
2499 pOpts->aBootCatEntries[i].u.SectionHeader.pszString = NULL;
2500 pOpts->cBootCatEntries = ++i;
2501 }
2502
2503 if ( i == 1
2504 || fForceNew
2505 || pOpts->aBootCatEntries[i - 1].enmType == RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader)
2506 {
2507 if (i >= RT_ELEMENTS(pOpts->aBootCatEntries))
2508 {
2509 *pidxBootCat = UINT32_MAX;
2510 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_BUFFER_OVERFLOW, "Too many boot catalog entries");
2511 }
2512
2513 pOpts->aBootCatEntries[i].enmType = i == 1 ? RTFSISOMKCMDELTORITOENTRY::kEntryType_Default
2514 : RTFSISOMKCMDELTORITOENTRY::kEntryType_Section;
2515 pOpts->aBootCatEntries[i].u.Section.pszImageNameInIso = NULL;
2516 pOpts->aBootCatEntries[i].u.Section.idxImageObj = UINT32_MAX;
2517 pOpts->aBootCatEntries[i].u.Section.fInsertBootInfoTable = false;
2518 pOpts->aBootCatEntries[i].u.Section.fBootable = true;
2519 pOpts->aBootCatEntries[i].u.Section.bBootMediaType = ISO9660_ELTORITO_BOOT_MEDIA_TYPE_MASK;
2520 pOpts->aBootCatEntries[i].u.Section.bSystemType = 1 /*FAT12*/;
2521 pOpts->aBootCatEntries[i].u.Section.uLoadSeg = 0x7c0;
2522 pOpts->aBootCatEntries[i].u.Section.cSectorsToLoad = 4;
2523 pOpts->cBootCatEntries = ++i;
2524 }
2525
2526 *pidxBootCat = i - 1;
2527 return VINF_SUCCESS;
2528}
2529
2530
2531/**
2532 * Deals with: --boot-catalog <path-spec>
2533 *
2534 * This enters the boot catalog into the namespaces of the image. The path-spec
2535 * is similar to what rtFsIsoMakerCmdAddSomething processes, only there isn't a
2536 * source file part.
2537 *
2538 * @returns IPRT status code
2539 * @param pOpts The ISO maker command instance.
2540 * @param pszGenericBootImage The generic boot image source.
2541 */
2542static int rtFsIsoMakerCmdOptEltoritoSetBootCatalogPath(PRTFSISOMAKERCMDOPTS pOpts, const char *pszBootCat)
2543{
2544 /* Make sure we'll fail later if no other boot options are present. */
2545 rtFsIsoMakerCmdOptEltoritoEnsureValidationEntry(pOpts);
2546
2547 /* Parse the name spec. */
2548 RTFSISOMKCMDPARSEDNAMES Parsed;
2549 int rc = rtFsIsoMakerCmdParseNameSpec(pOpts, pszBootCat, false /*fWithSrc*/, &Parsed);
2550 if (RT_SUCCESS(rc))
2551 {
2552 /* Query/create the boot catalog and enter it into the name spaces. */
2553 uint32_t idxBootCatObj;
2554 rc = RTFsIsoMakerQueryObjIdxForBootCatalog(pOpts->hIsoMaker, &idxBootCatObj);
2555 if (RT_SUCCESS(rc))
2556 rc = rtFsIsoMakerCmdSetObjPaths(pOpts, idxBootCatObj, &Parsed, "boot catalog");
2557 else
2558 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerQueryBootCatalogPathObjIdx failed: %Rrc", rc);
2559 }
2560 return rc;
2561}
2562
2563
2564/**
2565 * Deals with: --eltorito-add-image {file-spec}
2566 *
2567 * This differs from -b|--eltorito-boot in that it takes a source file
2568 * specification identical to what rtFsIsoMakerCmdAddSomething processes instead
2569 * of a reference to a file in the image.
2570 *
2571 * This operates on the current eltorito boot catalog entry.
2572 *
2573 * @returns IPRT status code
2574 * @param pOpts The ISO maker command instance.
2575 * @param pszGenericBootImage The generic boot image source.
2576 */
2577static int rtFsIsoMakerCmdOptEltoritoAddImage(PRTFSISOMAKERCMDOPTS pOpts, const char *pszBootImageSpec)
2578{
2579 /* Parse the name spec. */
2580 RTFSISOMKCMDPARSEDNAMES Parsed;
2581 int rc = rtFsIsoMakerCmdParseNameSpec(pOpts, pszBootImageSpec, true /*fWithSrc*/, &Parsed);
2582 if (RT_SUCCESS(rc))
2583 {
2584 uint32_t idxBootCat;
2585 rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
2586 if (RT_SUCCESS(rc))
2587 {
2588 if ( pOpts->aBootCatEntries[idxBootCat].u.Section.idxImageObj != UINT32_MAX
2589 || pOpts->aBootCatEntries[idxBootCat].u.Section.pszImageNameInIso != NULL)
2590 rc = rtFsIsoMakerCmdSyntaxError(pOpts, "boot image already given for current El Torito entry (%#u)", idxBootCat);
2591 else
2592 {
2593 uint32_t idxImageObj;
2594 rc = rtFsIsoMakerCmdStatAndAddFile(pOpts, Parsed.aNames[Parsed.cNamesWithSrc - 1].szPath, &Parsed, &idxImageObj);
2595 if (RT_SUCCESS(rc))
2596 pOpts->aBootCatEntries[idxBootCat].u.Section.idxImageObj = idxImageObj;
2597 }
2598 }
2599 }
2600
2601 return rc;
2602}
2603
2604
2605/**
2606 * Deals with: -b|--eltorito-boot {file-in-iso}
2607 *
2608 * This operates on the current eltorito boot catalog entry.
2609 *
2610 * @returns IPRT status code
2611 * @param pOpts The ISO maker command instance.
2612 * @param pszGenericBootImage The generic boot image source.
2613 */
2614static int rtFsIsoMakerCmdOptEltoritoBoot(PRTFSISOMAKERCMDOPTS pOpts, const char *pszBootImage)
2615{
2616 uint32_t idxBootCat;
2617 int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
2618 if (RT_SUCCESS(rc))
2619 {
2620 if ( pOpts->aBootCatEntries[idxBootCat].u.Section.idxImageObj != UINT32_MAX
2621 || pOpts->aBootCatEntries[idxBootCat].u.Section.pszImageNameInIso != NULL)
2622 return rtFsIsoMakerCmdSyntaxError(pOpts, "boot image already given for current El Torito entry (%#u)", idxBootCat);
2623
2624 uint32_t idxImageObj = RTFsIsoMakerGetObjIdxForPath(pOpts->hIsoMaker, RTFSISOMAKER_NAMESPACE_ALL, pszBootImage);
2625 if (idxImageObj == UINT32_MAX)
2626 pOpts->aBootCatEntries[idxBootCat].u.Section.pszImageNameInIso = pszBootImage;
2627 pOpts->aBootCatEntries[idxBootCat].u.Section.idxImageObj = idxImageObj;
2628 }
2629 return rc;
2630}
2631
2632
2633/**
2634 * Deals with: --eltorito-platform-id {x86|PPC|Mac|efi|number}
2635 *
2636 * Operates on the validation entry or a section header.
2637 *
2638 * @returns IPRT status code
2639 * @param pOpts The ISO maker command instance.
2640 * @param pszPlatformId The platform ID.
2641 */
2642static int rtFsIsoMakerCmdOptEltoritoPlatformId(PRTFSISOMAKERCMDOPTS pOpts, const char *pszPlatformId)
2643{
2644 /* Decode it. */
2645 uint8_t idPlatform;
2646 if (strcmp(pszPlatformId, "x86") == 0)
2647 idPlatform = ISO9660_ELTORITO_PLATFORM_ID_X86;
2648 else if (strcmp(pszPlatformId, "PPC") == 0)
2649 idPlatform = ISO9660_ELTORITO_PLATFORM_ID_PPC;
2650 else if (strcmp(pszPlatformId, "Mac") == 0)
2651 idPlatform = ISO9660_ELTORITO_PLATFORM_ID_MAC;
2652 else if (strcmp(pszPlatformId, "efi") == 0)
2653 idPlatform = ISO9660_ELTORITO_PLATFORM_ID_EFI;
2654 else
2655 {
2656 int rc = RTStrToUInt8Full(pszPlatformId, 0, &idPlatform);
2657 if (rc != VINF_SUCCESS)
2658 return rtFsIsoMakerCmdSyntaxError(pOpts, "invalid or unknown platform ID: %s", pszPlatformId);
2659 }
2660
2661 /* If this option comes before anything related to the default entry, work
2662 on the validation entry. */
2663 if (pOpts->cBootCatEntries <= 1)
2664 {
2665 rtFsIsoMakerCmdOptEltoritoEnsureValidationEntry(pOpts);
2666 pOpts->aBootCatEntries[0].u.Validation.idPlatform = idPlatform;
2667 }
2668 /* Otherwise, work on the current section header, creating a new one if necessary. */
2669 else
2670 {
2671 uint32_t idxBootCat = pOpts->cBootCatEntries - 1;
2672 if (pOpts->aBootCatEntries[idxBootCat].enmType == RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader)
2673 pOpts->aBootCatEntries[idxBootCat].u.SectionHeader.idPlatform = idPlatform;
2674 else
2675 {
2676 idxBootCat++;
2677 if (idxBootCat + 2 > RT_ELEMENTS(pOpts->aBootCatEntries))
2678 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_BUFFER_OVERFLOW, "Too many boot catalog entries");
2679
2680 pOpts->aBootCatEntries[idxBootCat].enmType = RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader;
2681 pOpts->aBootCatEntries[idxBootCat].u.SectionHeader.idPlatform = idPlatform;
2682 pOpts->aBootCatEntries[idxBootCat].u.SectionHeader.pszString = NULL;
2683 pOpts->cBootCatEntries = idxBootCat + 1;
2684 }
2685 }
2686 return VINF_SUCCESS;
2687}
2688
2689
2690/**
2691 * Deals with: -no-boot
2692 *
2693 * This operates on the current eltorito boot catalog entry.
2694 *
2695 * @returns IPRT status code
2696 * @param pOpts The ISO maker command instance.
2697 */
2698static int rtFsIsoMakerCmdOptEltoritoSetNotBootable(PRTFSISOMAKERCMDOPTS pOpts)
2699{
2700 uint32_t idxBootCat;
2701 int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
2702 if (RT_SUCCESS(rc))
2703 pOpts->aBootCatEntries[idxBootCat].u.Section.fBootable = false;
2704 return rc;
2705}
2706
2707
2708/**
2709 * Deals with: -hard-disk-boot, -no-emulation-boot, --eltorito-floppy-12,
2710 * --eltorito-floppy-144, --eltorito-floppy-288
2711 *
2712 * This operates on the current eltorito boot catalog entry.
2713 *
2714 * @returns IPRT status code
2715 * @param pOpts The ISO maker command instance.
2716 * @param bMediaType The media type.
2717 */
2718static int rtFsIsoMakerCmdOptEltoritoSetMediaType(PRTFSISOMAKERCMDOPTS pOpts, uint8_t bMediaType)
2719{
2720 uint32_t idxBootCat;
2721 int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
2722 if (RT_SUCCESS(rc))
2723 pOpts->aBootCatEntries[idxBootCat].u.Section.bBootMediaType = bMediaType;
2724 return rc;
2725}
2726
2727
2728/**
2729 * Deals with: -boot-load-seg {seg}
2730 *
2731 * This operates on the current eltorito boot catalog entry.
2732 *
2733 * @returns IPRT status code
2734 * @param pOpts The ISO maker command instance.
2735 * @param uSeg The load segment.
2736 */
2737static int rtFsIsoMakerCmdOptEltoritoSetLoadSegment(PRTFSISOMAKERCMDOPTS pOpts, uint16_t uSeg)
2738{
2739 uint32_t idxBootCat;
2740 int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
2741 if (RT_SUCCESS(rc))
2742 pOpts->aBootCatEntries[idxBootCat].u.Section.uLoadSeg = uSeg;
2743 return rc;
2744}
2745
2746
2747/**
2748 * Deals with: -boot-load-size {sectors}
2749 *
2750 * This operates on the current eltorito boot catalog entry.
2751 *
2752 * @returns IPRT status code
2753 * @param pOpts The ISO maker command instance.
2754 * @param cSectors Number of emulated sectors to load
2755 */
2756static int rtFsIsoMakerCmdOptEltoritoSetLoadSectorCount(PRTFSISOMAKERCMDOPTS pOpts, uint16_t cSectors)
2757{
2758 uint32_t idxBootCat;
2759 int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
2760 if (RT_SUCCESS(rc))
2761 pOpts->aBootCatEntries[idxBootCat].u.Section.cSectorsToLoad = cSectors;
2762 return rc;
2763}
2764
2765
2766/**
2767 * Deals with: -boot-info-table
2768 *
2769 * This operates on the current eltorito boot catalog entry.
2770 *
2771 * @returns IPRT status code
2772 * @param pOpts The ISO maker command instance.
2773 */
2774static int rtFsIsoMakerCmdOptEltoritoEnableBootInfoTablePatching(PRTFSISOMAKERCMDOPTS pOpts)
2775{
2776 uint32_t idxBootCat;
2777 int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
2778 if (RT_SUCCESS(rc))
2779 pOpts->aBootCatEntries[idxBootCat].u.Section.fInsertBootInfoTable = true;
2780 return rc;
2781}
2782
2783
2784/**
2785 * Validates and commits the boot catalog stuff.
2786 *
2787 * ASSUMING this is called after all options are parsed and there is only this
2788 * one call.
2789 *
2790 * @returns IPRT status code
2791 * @param pOpts The ISO maker command instance.
2792 */
2793static int rtFsIsoMakerCmdOptEltoritoCommitBootCatalog(PRTFSISOMAKERCMDOPTS pOpts)
2794{
2795 if (pOpts->cBootCatEntries == 0)
2796 return VINF_SUCCESS;
2797
2798 /*
2799 * Locate and configure the boot images first.
2800 */
2801 int rc;
2802 PRTFSISOMKCMDELTORITOENTRY pBootCatEntry = &pOpts->aBootCatEntries[1];
2803 for (uint32_t idxBootCat = 1; idxBootCat < pOpts->cBootCatEntries; idxBootCat++, pBootCatEntry++)
2804 if ( pBootCatEntry->enmType == RTFSISOMKCMDELTORITOENTRY::kEntryType_Default
2805 || pBootCatEntry->enmType == RTFSISOMKCMDELTORITOENTRY::kEntryType_Section)
2806 {
2807 /* Make sure we've got a boot image. */
2808 uint32_t idxImageObj = pBootCatEntry->u.Section.idxImageObj;
2809 if (idxImageObj == UINT32_MAX)
2810 {
2811 const char *pszBootImage = pBootCatEntry->u.Section.pszImageNameInIso;
2812 if (pszBootImage == NULL)
2813 return rtFsIsoMakerCmdSyntaxError(pOpts, "No image name given for boot catalog entry #%u", idxBootCat);
2814
2815 idxImageObj = RTFsIsoMakerGetObjIdxForPath(pOpts->hIsoMaker, RTFSISOMAKER_NAMESPACE_ALL, pszBootImage);
2816 if (idxImageObj == UINT32_MAX)
2817 return rtFsIsoMakerCmdSyntaxError(pOpts, "Unable to locate image for boot catalog entry #%u: %s",
2818 idxBootCat, pszBootImage);
2819 pBootCatEntry->u.Section.idxImageObj = idxImageObj;
2820 }
2821
2822 /* Enable patching it? */
2823 if (pBootCatEntry->u.Section.fInsertBootInfoTable)
2824 {
2825 rc = RTFsIsoMakerObjEnableBootInfoTablePatching(pOpts->hIsoMaker, idxImageObj, true);
2826 if (RT_FAILURE(rc))
2827 return rtFsIsoMakerCmdErrorRc(pOpts, rc,
2828 "RTFsIsoMakerObjEnableBootInfoTablePatching failed on entry #%u: %Rrc",
2829 idxBootCat, rc);
2830 }
2831
2832 /* Figure out the floppy type given the object size. */
2833 if (pBootCatEntry->u.Section.bBootMediaType == ISO9660_ELTORITO_BOOT_MEDIA_TYPE_MASK)
2834 {
2835 uint64_t cbImage;
2836 rc = RTFsIsoMakerObjQueryDataSize(pOpts->hIsoMaker, idxImageObj, &cbImage);
2837 if (RT_FAILURE(rc))
2838 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerObjGetDataSize failed on entry #%u: %Rrc",
2839 idxBootCat, rc);
2840 if (cbImage == 1228800)
2841 pBootCatEntry->u.Section.bBootMediaType = ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_1_2_MB;
2842 else if (cbImage <= 1474560)
2843 pBootCatEntry->u.Section.bBootMediaType = ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_1_44_MB;
2844 else if (cbImage <= 2949120)
2845 pBootCatEntry->u.Section.bBootMediaType = ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_2_88_MB;
2846 else
2847 pBootCatEntry->u.Section.bBootMediaType = ISO9660_ELTORITO_BOOT_MEDIA_TYPE_HARD_DISK;
2848 }
2849 }
2850
2851 /*
2852 * Add the boot catalog entries.
2853 */
2854 pBootCatEntry = &pOpts->aBootCatEntries[0];
2855 for (uint32_t idxBootCat = 0; idxBootCat < pOpts->cBootCatEntries; idxBootCat++, pBootCatEntry++)
2856 switch (pBootCatEntry->enmType)
2857 {
2858 case RTFSISOMKCMDELTORITOENTRY::kEntryType_Validation:
2859 Assert(idxBootCat == 0);
2860 rc = RTFsIsoMakerBootCatSetValidationEntry(pOpts->hIsoMaker, pBootCatEntry->u.Validation.idPlatform,
2861 pBootCatEntry->u.Validation.pszString);
2862 if (RT_FAILURE(rc))
2863 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerBootCatSetValidationEntry failed: %Rrc", rc);
2864 break;
2865
2866 case RTFSISOMKCMDELTORITOENTRY::kEntryType_Default:
2867 case RTFSISOMKCMDELTORITOENTRY::kEntryType_Section:
2868 Assert(pBootCatEntry->enmType == RTFSISOMKCMDELTORITOENTRY::kEntryType_Default ? idxBootCat == 1 : idxBootCat > 2);
2869 rc = RTFsIsoMakerBootCatSetSectionEntry(pOpts->hIsoMaker, idxBootCat,
2870 pBootCatEntry->u.Section.idxImageObj,
2871 pBootCatEntry->u.Section.bBootMediaType,
2872 pBootCatEntry->u.Section.bSystemType,
2873 pBootCatEntry->u.Section.fBootable,
2874 pBootCatEntry->u.Section.uLoadSeg,
2875 pBootCatEntry->u.Section.cSectorsToLoad,
2876 ISO9660_ELTORITO_SEL_CRIT_TYPE_NONE, NULL, 0);
2877 if (RT_FAILURE(rc))
2878 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerBootCatSetSectionEntry failed on entry #%u: %Rrc",
2879 idxBootCat, rc);
2880 break;
2881
2882 case RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader:
2883 {
2884 uint32_t cEntries = 1;
2885 while ( idxBootCat + cEntries < pOpts->cBootCatEntries
2886 && pBootCatEntry[cEntries].enmType != RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader)
2887 cEntries++;
2888 cEntries--;
2889
2890 Assert(idxBootCat > 1);
2891 rc = RTFsIsoMakerBootCatSetSectionHeaderEntry(pOpts->hIsoMaker, idxBootCat, cEntries,
2892 pBootCatEntry->u.SectionHeader.idPlatform,
2893 pBootCatEntry->u.SectionHeader.pszString);
2894 if (RT_FAILURE(rc))
2895 return rtFsIsoMakerCmdErrorRc(pOpts, rc,
2896 "RTFsIsoMakerBootCatSetSectionHeaderEntry failed on entry #%u: %Rrc",
2897 idxBootCat, rc);
2898 break;
2899 }
2900
2901 default:
2902 AssertFailedReturn(VERR_INTERNAL_ERROR_3);
2903 }
2904
2905 return VINF_SUCCESS;
2906}
2907
2908
2909/**
2910 * Deals with: --eltorito-new-entry, --eltorito-alt-boot
2911 *
2912 * This operates on the current eltorito boot catalog entry.
2913 *
2914 * @returns IPRT status code
2915 * @param pOpts The ISO maker command instance.
2916 */
2917static int rtFsIsoMakerCmdOptEltoritoNewEntry(PRTFSISOMAKERCMDOPTS pOpts)
2918{
2919 uint32_t idxBootCat;
2920 return rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, true /*fForceNew*/, &idxBootCat);
2921}
2922
2923
2924/**
2925 * Sets a string property in all namespaces.
2926 *
2927 * @returns IPRT status code.
2928 * @param pOpts The ISO maker command instance.
2929 * @param pszValue The new string value.
2930 * @param enmStringProp The string property.
2931 */
2932static int rtFsIsoMakerCmdOptSetStringProp(PRTFSISOMAKERCMDOPTS pOpts, const char *pszValue, RTFSISOMAKERSTRINGPROP enmStringProp)
2933{
2934 int rc = RTFsIsoMakerSetStringProp(pOpts->hIsoMaker, enmStringProp, pOpts->fDstNamespaces, pszValue);
2935 if (RT_FAILURE(rc))
2936 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to set string property %d to '%s': %Rrc", enmStringProp, pszValue, rc);
2937 return rc;
2938}
2939
2940
2941/**
2942 * Handles the --dir-mode and --file-mode options.
2943 *
2944 * @returns IPRT status code.
2945 * @param pOpts The ISO maker command instance.
2946 * @param fDir True if applies to dir, false if applies to
2947 * files.
2948 * @param fMode The forced mode.
2949 */
2950static int rtFsIsoMakerCmdOptSetFileOrDirMode(PRTFSISOMAKERCMDOPTS pOpts, bool fDir, RTFMODE fMode)
2951{
2952 /* Change the mode masks. */
2953 int rc;
2954 if (fDir)
2955 rc = RTFsIsoMakerSetForcedDirMode(pOpts->hIsoMaker, fMode, true /*fForced*/);
2956 else
2957 rc = RTFsIsoMakerSetForcedFileMode(pOpts->hIsoMaker, fMode, true /*fForced*/);
2958 if (RT_SUCCESS(rc))
2959 {
2960 /* Then enable rock.*/
2961 rc = RTFsIsoMakerSetRockRidgeLevel(pOpts->hIsoMaker, 2);
2962 if (RT_SUCCESS(rc))
2963 return VINF_SUCCESS;
2964 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to enable rock ridge: %Rrc", rc);
2965 }
2966 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to set %s force & default mode mask to %04o: %Rrc",
2967 fMode, fDir ? "directory" : "file", rc);
2968}
2969
2970
2971/**
2972 * Handles the --no-dir-mode and --no-file-mode options that counters
2973 * --dir-mode and --file-mode.
2974 *
2975 * @returns IPRT status code.
2976 * @param pOpts The ISO maker command instance.
2977 * @param fDir True if applies to dir, false if applies to
2978 * files.
2979 */
2980static int rtFsIsoMakerCmdOptDisableFileOrDirMode(PRTFSISOMAKERCMDOPTS pOpts, bool fDir)
2981{
2982 int rc;
2983 if (fDir)
2984 rc = RTFsIsoMakerSetForcedDirMode(pOpts->hIsoMaker, 0, false /*fForced*/);
2985 else
2986 rc = RTFsIsoMakerSetForcedFileMode(pOpts->hIsoMaker, 0, false /*fForced*/);
2987 if (RT_SUCCESS(rc))
2988 return VINF_SUCCESS;
2989 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to disable forced %s mode mask: %Rrc", fDir ? "directory" : "file", rc);
2990}
2991
2992
2993
2994/**
2995 * Handles the --new-dir-mode option.
2996 *
2997 * @returns IPRT status code.
2998 * @param pOpts The ISO maker command instance.
2999 * @param fMode The forced mode.
3000 */
3001static int rtFsIsoMakerCmdOptSetNewDirMode(PRTFSISOMAKERCMDOPTS pOpts, RTFMODE fMode)
3002{
3003 int rc = RTFsIsoMakerSetDefaultDirMode(pOpts->hIsoMaker, fMode);
3004 if (RT_SUCCESS(rc))
3005 return VINF_SUCCESS;
3006 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to set default dir mode mask to %04o: %Rrc", fMode, rc);
3007}
3008
3009
3010/**
3011 * Handles the --chmod option.
3012 *
3013 * @returns IPRT status code
3014 * @param pOpts The ISO maker command instance.
3015 * @param pszSpec The option value.
3016 */
3017static int rtFsIsoMakerCmdOptChmod(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSpec)
3018{
3019 /*
3020 * Parse the mode part.
3021 */
3022 int rc;
3023 uint32_t fUnset = 07777;
3024 uint32_t fSet = 0;
3025 const char *pszPath = pszSpec;
3026 if (RT_C_IS_DIGIT(*pszPath))
3027 {
3028 rc = RTStrToUInt32Ex(pszSpec, (char **)&pszPath, 8, &fSet);
3029 if (rc != VWRN_TRAILING_CHARS)
3030 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --chmod, octal mode parse failed: %s (%Rrc)", pszSpec, rc);
3031 if (fSet & ~07777)
3032 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --chmod, invalid mode mask: 0%o, max 07777", fSet);
3033 if (*pszPath != ':')
3034 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --chmod, expected colon after mode: %s", pszSpec);
3035 }
3036 else
3037 {
3038 pszPath = strchr(pszPath, ':');
3039 if (pszPath == NULL)
3040 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --chmod, expected colon after mode: %s", pszSpec);
3041 size_t const cchMode = pszPath - pszSpec;
3042
3043 /* We currently only matches certain patterns. Later this needs to be generalized into a RTFile or RTPath method. */
3044 fUnset = 0;
3045#define MATCH_MODE_STR(a_szMode) (cchMode == sizeof(a_szMode) - 1U && memcmp(pszSpec, a_szMode, sizeof(a_szMode) - 1) == 0)
3046 if (MATCH_MODE_STR("a+x"))
3047 fSet = 0111;
3048 else if (MATCH_MODE_STR("a+r"))
3049 fSet = 0444;
3050 else if (MATCH_MODE_STR("a+rx"))
3051 fSet = 0555;
3052 else
3053 return rtFsIsoMakerCmdSyntaxError(pOpts, "Sorry, --chmod doesn't understand complicated mode expressions: %s", pszSpec);
3054#undef MATCH_MODE_STR
3055 }
3056
3057 /*
3058 * Check that the file starts with a slash.
3059 */
3060 pszPath++;
3061 if (!RTPATH_IS_SLASH(*pszPath))
3062 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --chmod, path must start with a slash: %s", pszSpec);
3063
3064 /*
3065 * Do the job.
3066 */
3067 rc = RTFsIsoMakerSetPathMode(pOpts->hIsoMaker, pszPath, pOpts->fDstNamespaces, fSet, fUnset, 0 /*fFlags*/, NULL /*pcHits*/);
3068 if (rc == VWRN_NOT_FOUND)
3069 return rtFsIsoMakerCmdSyntaxError(pOpts, "Could not find --chmod path: %s", pszPath);
3070 if (RT_SUCCESS(rc))
3071 return VINF_SUCCESS;
3072 return rtFsIsoMakerCmdSyntaxError(pOpts, "RTFsIsoMakerSetPathMode(,%s,%#x,%o,%o,0,) failed: %Rrc",
3073 pszPath, pOpts->fDstNamespaces, fSet, fUnset, rc);
3074}
3075
3076
3077/**
3078 * Handles the --chown and --chgrp options.
3079 *
3080 * @returns IPRT status code
3081 * @param pOpts The ISO maker command instance.
3082 * @param pszSpec The option value.
3083 * @param fIsChOwn Set if 'chown', clear if 'chgrp'.
3084 */
3085static int rtFsIsoMakerCmdOptChangeOwnerGroup(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSpec, bool fIsChOwn)
3086{
3087 const char * const pszOpt = fIsChOwn ? "chown" : "chgrp";
3088
3089 /*
3090 * Parse out the ID and path .
3091 */
3092 uint32_t idValue;
3093 const char *pszPath = pszSpec;
3094 int rc = RTStrToUInt32Ex(pszSpec, (char **)&pszPath, 0, &idValue);
3095 if (rc != VWRN_TRAILING_CHARS)
3096 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --%s, numeric ID parse failed: %s (%Rrc)", pszOpt, pszSpec, rc);
3097 if (*pszPath != ':')
3098 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --%s, expected colon after ID: %s", pszOpt, pszSpec);
3099 pszPath++;
3100 if (!RTPATH_IS_SLASH(*pszPath))
3101 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --%s, path must start with a slash: %s", pszOpt, pszSpec);
3102
3103 /*
3104 * Do the job.
3105 */
3106 if (fIsChOwn)
3107 rc = RTFsIsoMakerSetPathOwnerId(pOpts->hIsoMaker, pszPath, pOpts->fDstNamespaces, idValue, NULL /*pcHits*/);
3108 else
3109 rc = RTFsIsoMakerSetPathGroupId(pOpts->hIsoMaker, pszPath, pOpts->fDstNamespaces, idValue, NULL /*pcHits*/);
3110 if (rc == VWRN_NOT_FOUND)
3111 return rtFsIsoMakerCmdSyntaxError(pOpts, "Could not find --%s path: %s", pszOpt, pszPath);
3112 if (RT_SUCCESS(rc))
3113 return VINF_SUCCESS;
3114 return rtFsIsoMakerCmdSyntaxError(pOpts, "RTFsIsoMakerSetPath%sId(,%s,%#x,%u,) failed: %Rrc",
3115 fIsChOwn ? "Owner" : "Group", pszPath, pOpts->fDstNamespaces, idValue, rc);
3116}
3117
3118
3119/**
3120 * Loads an argument file (e.g. a .iso-file) and parses it.
3121 *
3122 * @returns IPRT status code.
3123 * @param pOpts The ISO maker command instance.
3124 * @param pszFileSpec The file to parse.
3125 * @param cDepth The current nesting depth.
3126 */
3127static int rtFsIsoMakerCmdParseArgumentFile(PRTFSISOMAKERCMDOPTS pOpts, const char *pszFileSpec, unsigned cDepth)
3128{
3129 if (cDepth > 2)
3130 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_INVALID_PARAMETER, "Too many nested argument files!");
3131
3132 /*
3133 * Read the file into memory.
3134 */
3135 RTERRINFOSTATIC ErrInfo;
3136 uint32_t offError;
3137 RTVFSFILE hVfsFile;
3138 int rc = RTVfsChainOpenFile(pszFileSpec, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsFile,
3139 &offError, RTErrInfoInitStatic(&ErrInfo));
3140 if (RT_FAILURE(rc))
3141 return rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainOpenFile", pszFileSpec, rc, offError, &ErrInfo.Core);
3142
3143 uint64_t cbFile = 0;
3144 rc = RTVfsFileQuerySize(hVfsFile, &cbFile);
3145 if (RT_SUCCESS(rc))
3146 {
3147 if (cbFile < _2M)
3148 {
3149 char *pszContent = (char *)RTMemTmpAllocZ((size_t)cbFile + 1);
3150 if (pszContent)
3151 {
3152 rc = RTVfsFileRead(hVfsFile, pszContent, (size_t)cbFile, NULL);
3153 if (RT_SUCCESS(rc))
3154 {
3155 /*
3156 * Check that it's valid UTF-8 and turn it into an argument vector.
3157 */
3158 rc = RTStrValidateEncodingEx(pszContent, (size_t)cbFile + 1,
3159 RTSTR_VALIDATE_ENCODING_EXACT_LENGTH | RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED);
3160 if (RT_SUCCESS(rc))
3161 {
3162 uint32_t fGetOpt = strstr(pszContent, "--iprt-iso-maker-file-marker-ms") == NULL
3163 ? RTGETOPTARGV_CNV_QUOTE_BOURNE_SH : RTGETOPTARGV_CNV_QUOTE_MS_CRT;
3164 fGetOpt |= RTGETOPTARGV_CNV_MODIFY_INPUT;
3165 char **papszArgs;
3166 int cArgs;
3167 rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszContent, fGetOpt, NULL);
3168 if (RT_SUCCESS(rc))
3169 {
3170 /*
3171 * Parse them.
3172 */
3173 rc = rtFsIsoMakerCmdParse(pOpts, cArgs, papszArgs, cDepth + 1);
3174
3175 RTGetOptArgvFreeEx(papszArgs, fGetOpt);
3176 }
3177 else
3178 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "%s: RTGetOptArgvFromString failed: %Rrc", pszFileSpec, rc);
3179
3180 }
3181 else
3182 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "%s: invalid encoding", pszFileSpec);
3183 }
3184 else
3185 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "%s: error to read it into memory: %Rrc", pszFileSpec, rc);
3186 RTMemTmpFree(pszContent);
3187 }
3188 else
3189 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_NO_TMP_MEMORY, "%s: failed to allocte %zu bytes for reading",
3190 pszFileSpec, (size_t)cbFile + 1);
3191 }
3192 else
3193 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_FILE_TOO_BIG, "%s: file is too big: %'RU64 bytes, max 2MB", pszFileSpec, cbFile);
3194 }
3195 else
3196 rtFsIsoMakerCmdErrorRc(pOpts, rc, "%s: RTVfsFileQuerySize failed: %Rrc", pszFileSpec, rc);
3197 RTVfsFileRelease(hVfsFile);
3198 return rc;
3199}
3200
3201
3202/**
3203 * Parses the given command line options.
3204 *
3205 * @returns IPRT status code.
3206 * @retval VINF_CALLBACK_RETURN if exit successfully (help, version).
3207 * @param pOpts The ISO maker command instance.
3208 * @param cArgs Number of arguments in papszArgs.
3209 * @param papszArgs The argument vector to parse.
3210 */
3211static int rtFsIsoMakerCmdParse(PRTFSISOMAKERCMDOPTS pOpts, unsigned cArgs, char **papszArgs, unsigned cDepth)
3212{
3213 /* Setup option parsing. */
3214 RTGETOPTSTATE GetState;
3215 int rc = RTGetOptInit(&GetState, cArgs, papszArgs, g_aRtFsIsoMakerOptions, RT_ELEMENTS(g_aRtFsIsoMakerOptions),
3216 cDepth == 0 ? 1 : 0 /*iFirst*/, 0 /*fFlags*/);
3217 if (RT_FAILURE(rc))
3218 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTGetOpt failed: %Rrc", rc);
3219
3220 /*
3221 * Parse parameters. Parameters are position dependent.
3222 */
3223 RTGETOPTUNION ValueUnion;
3224 while ( RT_SUCCESS(rc)
3225 && (rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
3226 {
3227 switch (rc)
3228 {
3229 /*
3230 * Files and directories.
3231 */
3232 case VINF_GETOPT_NOT_OPTION:
3233 if ( *ValueUnion.psz != '@'
3234 || strchr(ValueUnion.psz, '='))
3235 rc = rtFsIsoMakerCmdAddSomething(pOpts, ValueUnion.psz);
3236 else
3237 rc = rtFsIsoMakerCmdParseArgumentFile(pOpts, ValueUnion.psz + 1, cDepth);
3238 break;
3239
3240
3241 /*
3242 * General options
3243 */
3244 case 'o':
3245 if (pOpts->fVirtualImageMaker)
3246 return rtFsIsoMakerCmdSyntaxError(pOpts, "The --output option is not allowed");
3247 if (pOpts->pszOutFile)
3248 return rtFsIsoMakerCmdSyntaxError(pOpts, "The --output option is specified more than once");
3249 pOpts->pszOutFile = ValueUnion.psz;
3250 break;
3251
3252 case RTFSISOMAKERCMD_OPT_NAME_SETUP:
3253 rc = rtFsIsoMakerCmdOptNameSetup(pOpts, ValueUnion.psz);
3254 break;
3255
3256 case RTFSISOMAKERCMD_OPT_NAME_SETUP_FROM_IMPORT:
3257 rc = rtFsIsoMakerCmdOptNameSetupFromImport(pOpts);
3258 break;
3259
3260 case RTFSISOMAKERCMD_OPT_PUSH_ISO:
3261 rc = rtFsIsoMakerCmdOptPushIso(pOpts, ValueUnion.psz, "--push-iso", 0);
3262 break;
3263
3264 case RTFSISOMAKERCMD_OPT_PUSH_ISO_NO_JOLIET:
3265 rc = rtFsIsoMakerCmdOptPushIso(pOpts, ValueUnion.psz, "--push-iso-no-joliet", RTFSISO9660_F_NO_JOLIET);
3266 break;
3267
3268 case RTFSISOMAKERCMD_OPT_PUSH_ISO_NO_ROCK:
3269 rc = rtFsIsoMakerCmdOptPushIso(pOpts, ValueUnion.psz, "--push-iso-no-rock", RTFSISO9660_F_NO_ROCK);
3270 break;
3271
3272 case RTFSISOMAKERCMD_OPT_PUSH_ISO_NO_ROCK_NO_JOLIET:
3273 rc = rtFsIsoMakerCmdOptPushIso(pOpts, ValueUnion.psz, "--push-iso-no-rock-no-joliet",
3274 RTFSISO9660_F_NO_ROCK | RTFSISO9660_F_NO_JOLIET);
3275 break;
3276
3277 case RTFSISOMAKERCMD_OPT_POP:
3278 rc = rtFsIsoMakerCmdOptPop(pOpts);
3279 break;
3280
3281 case RTFSISOMAKERCMD_OPT_IMPORT_ISO:
3282 rc = rtFsIsoMakerCmdOptImportIso(pOpts, ValueUnion.psz);
3283 break;
3284
3285
3286 /*
3287 * Namespace configuration.
3288 */
3289 case RTFSISOMAKERCMD_OPT_ISO_LEVEL:
3290 rc = rtFsIsoMakerCmdOptSetIsoLevel(pOpts, ValueUnion.u8);
3291 break;
3292
3293 case RTFSISOMAKERCMD_OPT_ROCK_RIDGE:
3294 rc = rtFsIsoMakerCmdOptSetPrimaryRockLevel(pOpts, 2);
3295 break;
3296
3297 case RTFSISOMAKERCMD_OPT_LIMITED_ROCK_RIDGE:
3298 rc = rtFsIsoMakerCmdOptSetPrimaryRockLevel(pOpts, 1);
3299 break;
3300
3301 case RTFSISOMAKERCMD_OPT_NO_ROCK_RIDGE:
3302 rc = rtFsIsoMakerCmdOptSetPrimaryRockLevel(pOpts, 0);
3303 break;
3304
3305 case 'J':
3306 rc = rtFsIsoMakerCmdOptSetJolietUcs2Level(pOpts, 3);
3307 break;
3308
3309 case RTFSISOMAKERCMD_OPT_NO_JOLIET:
3310 rc = rtFsIsoMakerCmdOptSetJolietUcs2Level(pOpts, 0);
3311 break;
3312
3313 case RTFSISOMAKERCMD_OPT_JOLIET_LEVEL:
3314 rc = rtFsIsoMakerCmdOptSetJolietUcs2Level(pOpts, ValueUnion.u8);
3315 break;
3316
3317
3318 /*
3319 * File attributes.
3320 */
3321 case RTFSISOMAKERCMD_OPT_RATIONAL_ATTRIBS:
3322 rc = rtFsIsoMakerCmdOptSetAttribInheritStyle(pOpts, false /*fStrict*/);
3323 break;
3324
3325 case RTFSISOMAKERCMD_OPT_STRICT_ATTRIBS:
3326 rc = rtFsIsoMakerCmdOptSetAttribInheritStyle(pOpts, true /*fStrict*/);
3327 break;
3328
3329 case RTFSISOMAKERCMD_OPT_FILE_MODE:
3330 rc = rtFsIsoMakerCmdOptSetFileOrDirMode(pOpts, false /*fDir*/, ValueUnion.u32);
3331 break;
3332
3333 case RTFSISOMAKERCMD_OPT_NO_FILE_MODE:
3334 rc = rtFsIsoMakerCmdOptDisableFileOrDirMode(pOpts, false /*fDir*/);
3335 break;
3336
3337 case RTFSISOMAKERCMD_OPT_DIR_MODE:
3338 rc = rtFsIsoMakerCmdOptSetFileOrDirMode(pOpts, true /*fDir*/, ValueUnion.u32);
3339 break;
3340
3341 case RTFSISOMAKERCMD_OPT_NO_DIR_MODE:
3342 rc = rtFsIsoMakerCmdOptDisableFileOrDirMode(pOpts, true /*fDir*/);
3343 break;
3344
3345 case RTFSISOMAKERCMD_OPT_NEW_DIR_MODE:
3346 rc = rtFsIsoMakerCmdOptSetNewDirMode(pOpts, ValueUnion.u32);
3347 break;
3348
3349 case RTFSISOMAKERCMD_OPT_CHMOD:
3350 rc = rtFsIsoMakerCmdOptChmod(pOpts, ValueUnion.psz);
3351 break;
3352
3353 case RTFSISOMAKERCMD_OPT_CHOWN:
3354 rc = rtFsIsoMakerCmdOptChangeOwnerGroup(pOpts, ValueUnion.psz, true /*fIsChOwn*/);
3355 break;
3356
3357 case RTFSISOMAKERCMD_OPT_CHGRP:
3358 rc = rtFsIsoMakerCmdOptChangeOwnerGroup(pOpts, ValueUnion.psz, false /*fIsChOwn*/);
3359 break;
3360
3361
3362 /*
3363 * Boot related options.
3364 */
3365 case 'G': /* --generic-boot <file> */
3366 rc = rtFsIsoMakerCmdOptGenericBoot(pOpts, ValueUnion.psz);
3367 break;
3368
3369 case RTFSISOMAKERCMD_OPT_ELTORITO_ADD_IMAGE:
3370 rc = rtFsIsoMakerCmdOptEltoritoAddImage(pOpts, ValueUnion.psz);
3371 break;
3372
3373 case 'b': /* --eltorito-boot <boot.img> */
3374 rc = rtFsIsoMakerCmdOptEltoritoBoot(pOpts, ValueUnion.psz);
3375 break;
3376
3377 case RTFSISOMAKERCMD_OPT_ELTORITO_NEW_ENTRY:
3378 rc = rtFsIsoMakerCmdOptEltoritoNewEntry(pOpts);
3379 break;
3380
3381 case RTFSISOMAKERCMD_OPT_ELTORITO_PLATFORM_ID:
3382 rc = rtFsIsoMakerCmdOptEltoritoPlatformId(pOpts, ValueUnion.psz);
3383 break;
3384
3385 case RTFSISOMAKERCMD_OPT_ELTORITO_NO_BOOT:
3386 rc = rtFsIsoMakerCmdOptEltoritoSetNotBootable(pOpts);
3387 break;
3388
3389 case RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_12:
3390 rc = rtFsIsoMakerCmdOptEltoritoSetMediaType(pOpts, ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_1_2_MB);
3391 break;
3392 case RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_144:
3393 rc = rtFsIsoMakerCmdOptEltoritoSetMediaType(pOpts, ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_1_44_MB);
3394 break;
3395 case RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_288:
3396 rc = rtFsIsoMakerCmdOptEltoritoSetMediaType(pOpts, ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_2_88_MB);
3397 break;
3398 case RTFSISOMAKERCMD_OPT_ELTORITO_HARD_DISK_BOOT:
3399 rc = rtFsIsoMakerCmdOptEltoritoSetMediaType(pOpts, ISO9660_ELTORITO_BOOT_MEDIA_TYPE_HARD_DISK);
3400 break;
3401 case RTFSISOMAKERCMD_OPT_ELTORITO_NO_EMULATION_BOOT:
3402 rc = rtFsIsoMakerCmdOptEltoritoSetMediaType(pOpts, ISO9660_ELTORITO_BOOT_MEDIA_TYPE_NO_EMULATION);
3403 break;
3404
3405 case RTFSISOMAKERCMD_OPT_ELTORITO_LOAD_SEG:
3406 rc = rtFsIsoMakerCmdOptEltoritoSetLoadSegment(pOpts, ValueUnion.u16);
3407 break;
3408
3409 case RTFSISOMAKERCMD_OPT_ELTORITO_LOAD_SIZE:
3410 rc = rtFsIsoMakerCmdOptEltoritoSetLoadSectorCount(pOpts, ValueUnion.u16);
3411 break;
3412
3413 case RTFSISOMAKERCMD_OPT_ELTORITO_INFO_TABLE:
3414 rc = rtFsIsoMakerCmdOptEltoritoEnableBootInfoTablePatching(pOpts);
3415 break;
3416
3417 case 'c': /* --boot-catalog <cd-path> */
3418 rc = rtFsIsoMakerCmdOptEltoritoSetBootCatalogPath(pOpts, ValueUnion.psz);
3419 break;
3420
3421
3422 /*
3423 * Image/namespace property related options.
3424 */
3425 case RTFSISOMAKERCMD_OPT_ABSTRACT_FILE_ID:
3426 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_ABSTRACT_FILE_ID);
3427 break;
3428
3429 case 'A': /* --application-id */
3430 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_APPLICATION_ID);
3431 break;
3432
3433 case RTFSISOMAKERCMD_OPT_BIBLIOGRAPHIC_FILE_ID:
3434 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_BIBLIOGRAPHIC_FILE_ID);
3435 break;
3436
3437 case RTFSISOMAKERCMD_OPT_COPYRIGHT_FILE_ID:
3438 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_COPYRIGHT_FILE_ID);
3439 break;
3440
3441 case 'P': /* -publisher */
3442 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_PUBLISHER_ID);
3443 break;
3444
3445 case 'p': /* --preparer*/
3446 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_DATA_PREPARER_ID);
3447 break;
3448
3449 case RTFSISOMAKERCMD_OPT_SYSTEM_ID:
3450 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_SYSTEM_ID);
3451 break;
3452
3453 case RTFSISOMAKERCMD_OPT_VOLUME_ID: /* (should've been '-V') */
3454 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_VOLUME_ID);
3455 break;
3456
3457 case RTFSISOMAKERCMD_OPT_VOLUME_SET_ID:
3458 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_VOLUME_SET_ID);
3459 break;
3460
3461
3462 /*
3463 * Compatibility.
3464 */
3465 case RTFSISOMAKERCMD_OPT_GRAFT_POINTS:
3466 rc = rtFsIsoMakerCmdOptNameSetup(pOpts, "iso+joliet+udf+hfs");
3467 break;
3468
3469 case 'l':
3470 if (RTFsIsoMakerGetIso9660Level(pOpts->hIsoMaker) >= 2)
3471 rc = rtFsIsoMakerCmdOptSetIsoLevel(pOpts, 2);
3472 break;
3473
3474 case 'R':
3475 rc = rtFsIsoMakerCmdOptSetPrimaryRockLevel(pOpts, 2);
3476 if (RT_SUCCESS(rc))
3477 rc = rtFsIsoMakerCmdOptSetAttribInheritStyle(pOpts, true /*fStrict*/);
3478 break;
3479
3480 case 'r':
3481 rc = rtFsIsoMakerCmdOptSetPrimaryRockLevel(pOpts, 2);
3482 if (RT_SUCCESS(rc))
3483 rc = rtFsIsoMakerCmdOptSetAttribInheritStyle(pOpts, false /*fStrict*/);
3484 break;
3485
3486 case RTFSISOMAKERCMD_OPT_PAD:
3487 rc = RTFsIsoMakerSetImagePadding(pOpts->hIsoMaker, 150);
3488 if (RT_FAILURE(rc))
3489 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerSetImagePadding failed: %Rrc", rc);
3490 break;
3491
3492 case RTFSISOMAKERCMD_OPT_NO_PAD:
3493 rc = RTFsIsoMakerSetImagePadding(pOpts->hIsoMaker, 0);
3494 if (RT_FAILURE(rc))
3495 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerSetImagePadding failed: %Rrc", rc);
3496 break;
3497
3498
3499 /*
3500 * VISO specific
3501 */
3502 case RTFSISOMAKERCMD_OPT_IPRT_ISO_MAKER_FILE_MARKER:
3503 /* ignored */
3504 break;
3505
3506
3507 /*
3508 * Testing.
3509 */
3510 case RTFSISOMAKERCMD_OPT_OUTPUT_BUFFER_SIZE: /* --output-buffer-size {cb} */
3511 pOpts->cbOutputReadBuffer = ValueUnion.u32;
3512 break;
3513
3514 case RTFSISOMAKERCMD_OPT_RANDOM_OUTPUT_BUFFER_SIZE: /* --random-output-buffer-size */
3515 pOpts->fRandomOutputReadBufferSize = true;
3516 break;
3517
3518 case RTFSISOMAKERCMD_OPT_RANDOM_ORDER_VERIFICATION: /* --random-order-verification {cb} */
3519 pOpts->cbRandomOrderVerifciationBlock = ValueUnion.u32;
3520 break;
3521
3522
3523 /*
3524 * Standard bits.
3525 */
3526 case 'h':
3527 rtFsIsoMakerCmdUsage(pOpts, papszArgs[0]);
3528 return pOpts->fVirtualImageMaker ? VERR_NOT_FOUND : VINF_CALLBACK_RETURN;
3529
3530 case 'V':
3531 rtFsIsoMakerPrintf(pOpts, "%sr%d\n", RTBldCfgVersion(), RTBldCfgRevision());
3532 return pOpts->fVirtualImageMaker ? VERR_NOT_FOUND : VINF_CALLBACK_RETURN;
3533
3534 default:
3535 if (rc > 0 && RT_C_IS_GRAPH(rc))
3536 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_GETOPT_UNKNOWN_OPTION, "Unhandled option: -%c", rc);
3537 else if (rc > 0)
3538 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_GETOPT_UNKNOWN_OPTION, "Unhandled option: %i (%#x)", rc, rc);
3539 else if (rc == VERR_GETOPT_UNKNOWN_OPTION)
3540 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Unknown option: '%s'", ValueUnion.psz);
3541 else if (ValueUnion.pDef)
3542 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "%s: %Rrs", ValueUnion.pDef->pszLong, rc);
3543 else
3544 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "%Rrs", rc);
3545 return rc;
3546 }
3547 if (RT_FAILURE(rc))
3548 return rc;
3549 }
3550 return VINF_SUCCESS;
3551}
3552
3553
3554/**
3555 * Extended ISO maker command.
3556 *
3557 * This can be used as a ISO maker command that produces a image file, or
3558 * alternatively for setting up a virtual ISO in memory.
3559 *
3560 * @returns IPRT status code
3561 * @param cArgs Number of arguments.
3562 * @param papszArgs Pointer to argument array.
3563 * @param hVfsCwd The current working directory to assume when processing
3564 * relative file/dir references. Pass NIL_RTVFSDIR to use
3565 * the current CWD of the process.
3566 * @param pszCwd Path to @a hVfsCwdDir. Use for error reporting and
3567 * optimizing the open file count if possible.
3568 * @param phVfsFile Where to return the virtual ISO. Pass NULL to for
3569 * normal operation (creates file on disk).
3570 * @param pErrInfo Where to return extended error information in the
3571 * virtual ISO mode.
3572 */
3573RTDECL(int) RTFsIsoMakerCmdEx(unsigned cArgs, char **papszArgs, RTVFSDIR hVfsCwd, const char *pszCwd,
3574 PRTVFSFILE phVfsFile, PRTERRINFO pErrInfo)
3575{
3576 if (phVfsFile)
3577 *phVfsFile = NIL_RTVFSFILE;
3578
3579 /*
3580 * Create instance.
3581 */
3582 RTFSISOMAKERCMDOPTS Opts;
3583 RT_ZERO(Opts);
3584 Opts.hIsoMaker = NIL_RTFSISOMAKER;
3585 Opts.pErrInfo = pErrInfo;
3586 Opts.fVirtualImageMaker = phVfsFile != NULL;
3587 Opts.cNameSpecifiers = 1;
3588 Opts.afNameSpecifiers[0] = RTFSISOMAKERCMDNAME_MAJOR_MASK;
3589 Opts.fDstNamespaces = RTFSISOMAKERCMDNAME_MAJOR_MASK;
3590 Opts.pszTransTbl = "TRANS.TBL"; /** @todo query this below */
3591 for (uint32_t i = 0; i < RT_ELEMENTS(Opts.aBootCatEntries); i++)
3592 Opts.aBootCatEntries[i].u.Section.idxImageObj = UINT32_MAX;
3593
3594 /* Initialize the source stack with NILs (to be on the safe size). */
3595 Opts.iSrcStack = -1;
3596 for (uint32_t i = 0; i < RT_ELEMENTS(Opts.aSrcStack); i++)
3597 {
3598 Opts.aSrcStack[i].hSrcDir = NIL_RTVFSDIR;
3599 Opts.aSrcStack[i].hSrcVfs = NIL_RTVFS;
3600 }
3601
3602 /* Push the CWD if present. */
3603 if (hVfsCwd != NIL_RTVFSDIR)
3604 {
3605 AssertReturn(pszCwd, VERR_INVALID_PARAMETER);
3606 uint32_t cRefs = RTVfsDirRetain(hVfsCwd);
3607 AssertReturn(cRefs != UINT32_MAX, VERR_INVALID_HANDLE);
3608
3609 Opts.aSrcStack[0].hSrcDir = hVfsCwd;
3610 Opts.aSrcStack[0].pszSrcVfs = pszCwd;
3611 Opts.iSrcStack = 0;
3612 }
3613
3614 /* Create the ISO creator instance. */
3615 int rc = RTFsIsoMakerCreate(&Opts.hIsoMaker);
3616 if (RT_SUCCESS(rc))
3617 {
3618 /*
3619 * Parse the command line and check for mandatory options.
3620 */
3621 rc = rtFsIsoMakerCmdParse(&Opts, cArgs, papszArgs, 0);
3622 if (RT_SUCCESS(rc) && rc != VINF_CALLBACK_RETURN)
3623 {
3624 if (!Opts.cItemsAdded)
3625 rc = rtFsIsoMakerCmdErrorRc(&Opts, VERR_NO_DATA, "Cowardly refuses to create empty ISO image");
3626 else if (!Opts.pszOutFile && !Opts.fVirtualImageMaker)
3627 rc = rtFsIsoMakerCmdErrorRc(&Opts, VERR_INVALID_PARAMETER, "No output file specified (--output <file>)");
3628
3629 /*
3630 * Final actions.
3631 */
3632 if (RT_SUCCESS(rc))
3633 rc = rtFsIsoMakerCmdOptEltoritoCommitBootCatalog(&Opts);
3634 if (RT_SUCCESS(rc))
3635 {
3636 /*
3637 * Finalize the image and get the virtual file.
3638 */
3639 rc = RTFsIsoMakerFinalize(Opts.hIsoMaker);
3640 if (RT_SUCCESS(rc))
3641 {
3642 RTVFSFILE hVfsFile;
3643 rc = RTFsIsoMakerCreateVfsOutputFile(Opts.hIsoMaker, &hVfsFile);
3644 if (RT_SUCCESS(rc))
3645 {
3646 /*
3647 * We're done now if we're only setting up a virtual image.
3648 */
3649 if (Opts.fVirtualImageMaker)
3650 *phVfsFile = hVfsFile;
3651 else
3652 {
3653 rc = rtFsIsoMakerCmdWriteImage(&Opts, hVfsFile);
3654 RTVfsFileRelease(hVfsFile);
3655 }
3656 }
3657 else
3658 rc = rtFsIsoMakerCmdErrorRc(&Opts, rc, "RTFsIsoMakerCreateVfsOutputFile failed: %Rrc", rc);
3659 }
3660 else
3661 rc = rtFsIsoMakerCmdErrorRc(&Opts, rc, "RTFsIsoMakerFinalize failed: %Rrc", rc);
3662 }
3663 }
3664 }
3665 else
3666 {
3667 rc = rtFsIsoMakerCmdErrorRc(&Opts, rc, "RTFsIsoMakerCreate failed: %Rrc", rc);
3668 Opts.hIsoMaker = NIL_RTFSISOMAKER;
3669 }
3670
3671 return rtFsIsoMakerCmdDeleteState(&Opts, rc);
3672}
3673
3674
3675/**
3676 * ISO maker command (creates image file on disk).
3677 *
3678 * @returns IPRT status code
3679 * @param cArgs Number of arguments.
3680 * @param papszArgs Pointer to argument array.
3681 */
3682RTDECL(RTEXITCODE) RTFsIsoMakerCmd(unsigned cArgs, char **papszArgs)
3683{
3684 int rc = RTFsIsoMakerCmdEx(cArgs, papszArgs, NIL_RTVFSDIR, NULL, NULL, NULL);
3685 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
3686}
3687
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette