VirtualBox

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

Last change on this file since 76306 was 75698, checked in by vboxsync, 6 years ago

IPRT/isomakercmd.cpp: Implemented adding regular directories to the ISO/VISO.

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

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