VirtualBox

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

Last change on this file since 70398 was 70398, checked in by vboxsync, 7 years ago

IPRT/VISO: Pass a the directory of a VISO file to the ISO maker to allow for relative file/dir specification from it. Nested push-iso now possible. Tweak importer code to handle NT 3.1 iso where the big endian volume sequence number wasn't set. [build ifx]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 157.5 KB
Line 
1/* $Id: isomakercmd.cpp 70398 2018-01-01 12:29:24Z 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 * Adds a directory, from a VFS chain or real file system.
1695 *
1696 * @returns IPRT status code.
1697 * @param pOpts The ISO maker command instance.
1698 * @param pszSrc The path to the source directory.
1699 * @param pParsed The parsed names.
1700 */
1701static int rtFsIsoMakerCmdAddDir(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSrc, PCRTFSISOMKCMDPARSEDNAMES pParsed)
1702{
1703 RT_NOREF(pParsed);
1704 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_IMPLEMENTED, "Adding directory '%s' failed: not implemented", pszSrc);
1705}
1706
1707
1708/**
1709 * Worker for rtFsIsoMakerCmdAddVfsDir that does the recursion.
1710 *
1711 * @returns IPRT status code.
1712 * @param pOpts The ISO maker command instance.
1713 * @param hVfsDir The directory to process.
1714 * @param idxDirObj The configuration index of the directory.
1715 * @param pszSrc Pointer to the source path buffer. RTPATH_MAX
1716 * in size. Okay to modify beyond @a cchSrc.
1717 * @param cchSrc Length of the path corresponding to @a hVfsDir.
1718 * @param fNamespaces Which ISO maker namespaces to add the names to.
1719 * @param cDepth Number of recursions. Used to deal with loopy
1720 * directories.
1721 */
1722static int rtFsIsoMakerCmdAddVfsDirRecursive(PRTFSISOMAKERCMDOPTS pOpts, RTVFSDIR hVfsDir, uint32_t idxDirObj,
1723 char *pszSrc, size_t cchSrc, uint32_t fNamespaces, uint8_t cDepth)
1724{
1725 /*
1726 * Check that we're not in too deep.
1727 */
1728 if (cDepth >= RTFSISOMAKERCMD_MAX_DIR_RECURSIONS)
1729 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_ISOMK_IMPORT_TOO_DEEP_DIR_TREE,
1730 "Recursive (VFS) dir add too deep (depth=%u): %.*s", cDepth, cchSrc, pszSrc);
1731 /*
1732 * Enumerate the directory.
1733 */
1734 int rc;
1735 size_t cbDirEntryAlloced = sizeof(RTDIRENTRYEX);
1736 PRTDIRENTRYEX pDirEntry = (PRTDIRENTRYEX)RTMemTmpAlloc(cbDirEntryAlloced);
1737 if (pDirEntry)
1738 {
1739 for (;;)
1740 {
1741 /*
1742 * Read the next entry.
1743 */
1744 size_t cbDirEntry = cbDirEntryAlloced;
1745 rc = RTVfsDirReadEx(hVfsDir, pDirEntry, &cbDirEntry, RTFSOBJATTRADD_UNIX);
1746 if (RT_FAILURE(rc))
1747 {
1748 if (rc == VERR_NO_MORE_FILES)
1749 rc = VINF_SUCCESS;
1750 else if (rc == VERR_BUFFER_OVERFLOW)
1751 {
1752 RTMemTmpFree(pDirEntry);
1753 cbDirEntryAlloced = RT_ALIGN_Z(RT_MIN(cbDirEntry, cbDirEntryAlloced) + 64, 64);
1754 pDirEntry = (PRTDIRENTRYEX)RTMemTmpAlloc(cbDirEntryAlloced);
1755 if (pDirEntry)
1756 continue;
1757 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_NO_TMP_MEMORY, "Out of memory (direntry buffer)");
1758 }
1759 else
1760 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTVfsDirReadEx failed on %.*s: %Rrc", cchSrc, pszSrc, rc);
1761 break;
1762 }
1763
1764 /* Ignore '.' and '..' entries. */
1765 if (RTDirEntryExIsStdDotLink(pDirEntry))
1766 continue;
1767
1768 /*
1769 * Process the entry.
1770 */
1771
1772 /* Update the name. */
1773 if (cchSrc + 1 + pDirEntry->cbName < RTPATH_MAX)
1774 {
1775 pszSrc[cchSrc] = '/'; /* VFS only groks unix slashes */
1776 memcpy(&pszSrc[cchSrc + 1], pDirEntry->szName, pDirEntry->cbName);
1777 pszSrc[cchSrc + 1 + pDirEntry->cbName] = '\0';
1778 }
1779 else
1780 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_FILENAME_TOO_LONG, "Filename is too long (depth %u): '%.*s/%s'",
1781 cDepth, cchSrc, pszSrc, pDirEntry->szName);
1782
1783 /* Okay? Check name filtering. */
1784 if ( RT_SUCCESS(rc)
1785 && !rtFsIsoMakerCmdIsFilteredOut(pOpts, pszSrc, pDirEntry->szName, RTFS_IS_DIRECTORY(pDirEntry->Info.Attr.fMode)))
1786 {
1787 /* Do type specific adding. */
1788 uint32_t idxObj = UINT32_MAX;
1789 if (RTFS_IS_FILE(pDirEntry->Info.Attr.fMode))
1790 {
1791 /*
1792 * Files are added with VFS file sources.
1793 * The ASSUMPTION is that we're working with a virtual file system
1794 * here and won't be wasting native file descriptors.
1795 */
1796 RTVFSFILE hVfsFileSrc;
1797 rc = RTVfsDirOpenFile(hVfsDir, pDirEntry->szName,
1798 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsFileSrc);
1799 if (RT_SUCCESS(rc))
1800 {
1801 rc = RTFsIsoMakerAddUnnamedFileWithVfsFile(pOpts->hIsoMaker, hVfsFileSrc, &idxObj);
1802 RTVfsFileRelease(hVfsFileSrc);
1803 if (RT_SUCCESS(rc))
1804 {
1805 pOpts->cItemsAdded++;
1806 rc = RTFsIsoMakerObjSetNameAndParent(pOpts->hIsoMaker, idxObj, idxDirObj, fNamespaces,
1807 pDirEntry->szName);
1808 if (RT_FAILURE(rc))
1809 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error setting parent & name on file '%s' to '%s': %Rrc",
1810 pszSrc, pDirEntry->szName, rc);
1811 }
1812 else
1813 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error adding file '%s' (VFS recursive): %Rrc", pszSrc, rc);
1814 }
1815 else
1816 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error opening file '%s' (VFS recursive): %Rrc", pszSrc, rc);
1817 }
1818 else if (RTFS_IS_DIRECTORY(pDirEntry->Info.Attr.fMode))
1819 {
1820 /*
1821 * Open and add the sub-directory.
1822 */
1823 RTVFSDIR hVfsSubDirSrc;
1824 rc = RTVfsDirOpenDir(hVfsDir, pDirEntry->szName, 0 /*fFlags*/, &hVfsSubDirSrc);
1825 if (RT_SUCCESS(rc))
1826 {
1827 rc = RTFsIsoMakerAddUnnamedDir(pOpts->hIsoMaker, &pDirEntry->Info, &idxObj);
1828 if (RT_SUCCESS(rc))
1829 {
1830 pOpts->cItemsAdded++;
1831 rc = RTFsIsoMakerObjSetNameAndParent(pOpts->hIsoMaker, idxObj, idxDirObj, fNamespaces,
1832 pDirEntry->szName);
1833 if (RT_SUCCESS(rc))
1834 /* Recurse into the sub-directory. */
1835 rc = rtFsIsoMakerCmdAddVfsDirRecursive(pOpts, hVfsSubDirSrc, idxObj, pszSrc,
1836 cchSrc + 1 + pDirEntry->cbName, fNamespaces, cDepth + 1);
1837 else
1838 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc,
1839 "Error setting parent & name on directory '%s' to '%s': %Rrc",
1840 pszSrc, pDirEntry->szName, rc);
1841 }
1842 else
1843 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error adding directory '%s' (VFS recursive): %Rrc", pszSrc, rc);
1844 RTVfsDirRelease(hVfsSubDirSrc);
1845 }
1846 else
1847 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error opening directory '%s' (VFS recursive): %Rrc", pszSrc, rc);
1848 }
1849 else if (RTFS_IS_SYMLINK(pDirEntry->Info.Attr.fMode))
1850 {
1851 /*
1852 * TODO: ISO FS symlink support.
1853 */
1854 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_IMPLEMENTED,
1855 "Adding symlink '%s' failed: not yet implemented", pszSrc);
1856 }
1857 else
1858 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_IMPLEMENTED,
1859 "Adding special file '%s' failed: not implemented", pszSrc);
1860 }
1861 if (RT_FAILURE(rc))
1862 break;
1863 }
1864
1865 RTMemTmpFree(pDirEntry);
1866 }
1867 else
1868 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_NO_TMP_MEMORY, "Out of memory! (direntry buffer)");
1869 return rc;
1870}
1871
1872
1873/**
1874 * Adds a directory, from the source VFS.
1875 *
1876 * @returns IPRT status code.
1877 * @param pOpts The ISO maker command instance.
1878 * @param pParsed The parsed names.
1879 * @param pidxObj Where to return the configuration index for the
1880 * added file. Optional.
1881 */
1882static int rtFsIsoMakerCmdAddVfsDir(PRTFSISOMAKERCMDOPTS pOpts, PCRTFSISOMKCMDPARSEDNAMES pParsed, PCRTFSOBJINFO pObjInfo)
1883{
1884 Assert(pParsed->cNames < pParsed->cNamesWithSrc);
1885
1886 /*
1887 * Open the directory.
1888 */
1889 char *pszDir = pParsed->aNames[pParsed->cNamesWithSrc - 1].szPath;
1890 RTPathChangeToUnixSlashes(pszDir, true /*fForce*/); /* VFS currently only understand unix slashes. */
1891 RTVFSDIR hVfsDirSrc;
1892 int rc = RTVfsDirOpenDir(pOpts->aSrcStack[pOpts->iSrcStack].hSrcDir, pszDir, 0 /*fFlags*/, &hVfsDirSrc);
1893 if (RT_FAILURE(rc))
1894 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error opening directory '%s' (%s '%s'): %Rrc", pszDir,
1895 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfsOption ? "inside" : "relative to",
1896 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfs, rc);
1897
1898 /*
1899 * Add the directory if it doesn't exist.
1900 */
1901 uint32_t idxObj = UINT32_MAX;
1902 for (uint32_t i = 0; i < pParsed->cNames; i++)
1903 if (pParsed->aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK)
1904 {
1905 idxObj = RTFsIsoMakerGetObjIdxForPath(pOpts->hIsoMaker,
1906 pParsed->aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK,
1907 pParsed->aNames[i].szPath);
1908 if (idxObj != UINT32_MAX)
1909 {
1910 /** @todo make sure the directory is present in the other namespace. */
1911 break;
1912 }
1913 }
1914 if (idxObj == UINT32_MAX)
1915 {
1916 rc = RTFsIsoMakerAddUnnamedDir(pOpts->hIsoMaker, pObjInfo, &idxObj);
1917 if (RT_SUCCESS(rc))
1918 rc = rtFsIsoMakerCmdSetObjPaths(pOpts, idxObj, pParsed, pParsed->aNames[pParsed->cNames - 1].szPath);
1919 else
1920 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerAddUnnamedDir failed: %Rrc", rc);
1921 }
1922 if (RT_SUCCESS(rc))
1923 {
1924 /*
1925 * Add the directory content.
1926 */
1927 uint32_t fNamespaces = 0;
1928 for (uint32_t i = 0; i < pParsed->cNames; i++)
1929 fNamespaces |= pParsed->aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK;
1930 rc = rtFsIsoMakerCmdAddVfsDirRecursive(pOpts, hVfsDirSrc, idxObj, pszDir,
1931 pParsed->aNames[pParsed->cNamesWithSrc - 1].cchPath, fNamespaces, 0 /*cDepth*/);
1932 }
1933 RTVfsDirRelease(hVfsDirSrc);
1934 return rc;
1935}
1936
1937
1938
1939
1940/**
1941 * Adds a file after first making sure it's a file.
1942 *
1943 * @returns IPRT status code
1944 * @param pOpts The ISO maker command instance.
1945 * @param pszSrc The path to the source file.
1946 * @param pParsed The parsed names.
1947 * @param pidxObj Where to return the configuration index for the
1948 * added file. Optional.
1949 */
1950static int rtFsIsoMakerCmdStatAndAddFile(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSrc, PCRTFSISOMKCMDPARSEDNAMES pParsed,
1951 uint32_t *pidxObj)
1952{
1953 int rc;
1954 RTFSOBJINFO ObjInfo;
1955 if (pParsed->enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_NormalSrcStack)
1956 {
1957 rc = RTVfsDirQueryPathInfo(pOpts->aSrcStack[pOpts->iSrcStack].hSrcDir, pszSrc,
1958 &ObjInfo, RTFSOBJATTRADD_UNIX, RTPATH_F_FOLLOW_LINK);
1959 if (RT_FAILURE(rc))
1960 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTVfsQueryPathInfo failed on %s (%s %s): %Rrc", pszSrc,
1961 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfsOption ? "inside" : "relative to",
1962 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfs, rc);
1963 }
1964 else
1965 {
1966 uint32_t offError;
1967 RTERRINFOSTATIC ErrInfo;
1968 rc = RTVfsChainQueryInfo(pszSrc, &ObjInfo, RTFSOBJATTRADD_UNIX,
1969 RTPATH_F_FOLLOW_LINK, &offError, RTErrInfoInitStatic(&ErrInfo));
1970 if (RT_FAILURE(rc))
1971 return rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainQueryInfo", pszSrc, rc, offError, &ErrInfo.Core);
1972 }
1973
1974 if (RTFS_IS_FILE(ObjInfo.Attr.fMode))
1975 return rtFsIsoMakerCmdAddFile(pOpts, pszSrc, pParsed, pidxObj);
1976 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_A_FILE, "Not a file: %s", pszSrc);
1977}
1978
1979
1980/**
1981 * Processes a non-option argument.
1982 *
1983 * @returns IPRT status code.
1984 * @param pOpts The ISO maker command instance.
1985 * @param pszSpec The specification of what to add.
1986 */
1987static int rtFsIsoMakerCmdAddSomething(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSpec)
1988{
1989 /*
1990 * Parse the name spec.
1991 */
1992 RTFSISOMKCMDPARSEDNAMES Parsed;
1993 int rc = rtFsIsoMakerCmdParseNameSpec(pOpts, pszSpec, true /*fWithSrc*/, &Parsed);
1994 if (RT_FAILURE(rc))
1995 return rc;
1996
1997 /*
1998 * Deal with special source filenames used to remove/change stuff.
1999 */
2000 if ( Parsed.enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_Remove
2001 || Parsed.enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_MustRemove)
2002 {
2003 const char *pszFirstNm = NULL;
2004 uint32_t cRemoved = 0;
2005 for (uint32_t i = 0; i < pOpts->cNameSpecifiers; i++)
2006 if ( Parsed.aNames[i].cchPath > 0
2007 && (Parsed.aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK))
2008 {
2009 pszFirstNm = Parsed.aNames[i].szPath;
2010 uint32_t idxObj = RTFsIsoMakerGetObjIdxForPath(pOpts->hIsoMaker,
2011 Parsed.aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK,
2012 Parsed.aNames[i].szPath);
2013 if (idxObj != UINT32_MAX)
2014 {
2015 rc = RTFsIsoMakerObjRemove(pOpts->hIsoMaker, idxObj);
2016 if (RT_FAILURE(rc))
2017 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to remove '%s': %Rrc", pszSpec, rc);
2018 cRemoved++;
2019 }
2020 }
2021 if ( Parsed.enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_MustRemove
2022 && cRemoved == 0)
2023 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_FOUND, "Failed to locate '%s' for removal", pszSpec);
2024 }
2025 /*
2026 * Add regular source.
2027 */
2028 else
2029 {
2030 const char *pszSrc = Parsed.aNames[Parsed.cNamesWithSrc - 1].szPath;
2031 RTFSOBJINFO ObjInfo;
2032 if (Parsed.enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_NormalSrcStack)
2033 {
2034 rc = RTVfsDirQueryPathInfo(pOpts->aSrcStack[pOpts->iSrcStack].hSrcDir, pszSrc,
2035 &ObjInfo, RTFSOBJATTRADD_UNIX, RTPATH_F_FOLLOW_LINK);
2036 if (RT_FAILURE(rc))
2037 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTVfsQueryPathInfo failed on %s (%s %s): %Rrc", pszSrc,
2038 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfsOption ? "inside" : "relative to",
2039 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfs, rc);
2040 }
2041 else
2042 {
2043 uint32_t offError;
2044 RTERRINFOSTATIC ErrInfo;
2045 rc = RTVfsChainQueryInfo(pszSrc, &ObjInfo, RTFSOBJATTRADD_UNIX,
2046 RTPATH_F_FOLLOW_LINK, &offError, RTErrInfoInitStatic(&ErrInfo));
2047 if (RT_FAILURE(rc))
2048 return rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainQueryInfo", pszSrc, rc, offError, &ErrInfo.Core);
2049 }
2050
2051 /* By type: */
2052
2053 if (RTFS_IS_FILE(ObjInfo.Attr.fMode))
2054 return rtFsIsoMakerCmdAddFile(pOpts, pszSrc, &Parsed, NULL /*pidxObj*/);
2055
2056 if (RTFS_IS_DIRECTORY(ObjInfo.Attr.fMode))
2057 {
2058 if (Parsed.enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_NormalSrcStack)
2059 return rtFsIsoMakerCmdAddVfsDir(pOpts, &Parsed, &ObjInfo);
2060 return rtFsIsoMakerCmdAddDir(pOpts, pszSrc, &Parsed);
2061 }
2062
2063 if (RTFS_IS_SYMLINK(ObjInfo.Attr.fMode))
2064 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_IMPLEMENTED, "Adding symlink '%s' failed: not yet implemented", pszSpec);
2065
2066 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_IMPLEMENTED, "Adding special file '%s' failed: not implemented", pszSpec);
2067 }
2068
2069 return VINF_SUCCESS;
2070}
2071
2072
2073/**
2074 * Opens an ISO and use it for subsequent file system accesses.
2075 *
2076 * This is handy for duplicating a part of an ISO in the new image.
2077 *
2078 * @returns IPRT status code.
2079 * @param pOpts The ISO maker command instance.
2080 * @param pszIsoSpec The ISO path specifier.
2081 * @param pszOption The option we're being called on.
2082 * @param fFlags RTFSISO9660_F_XXX
2083 */
2084static int rtFsIsoMakerCmdOptPushIso(PRTFSISOMAKERCMDOPTS pOpts, const char *pszIsoSpec, const char *pszOption, uint32_t fFlags)
2085{
2086 int32_t iSrcStack = pOpts->iSrcStack + 1;
2087 if ((uint32_t)iSrcStack >= RT_ELEMENTS(pOpts->aSrcStack))
2088 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_IMPLEMENTED,
2089 "Too many pushes %s %s (previous: %s %s, %s %s, %s %s, ...)",
2090 pszOption, pszIsoSpec,
2091 pOpts->aSrcStack[iSrcStack - 1].pszSrcVfsOption, pOpts->aSrcStack[iSrcStack - 1].pszSrcVfs,
2092 pOpts->aSrcStack[iSrcStack - 2].pszSrcVfsOption, pOpts->aSrcStack[iSrcStack - 2].pszSrcVfs,
2093 pOpts->aSrcStack[iSrcStack - 3].pszSrcVfsOption, pOpts->aSrcStack[iSrcStack - 3].pszSrcVfs);
2094
2095 /*
2096 * Try open the file.
2097 */
2098 int rc;
2099 RTVFSFILE hVfsFileIso = NIL_RTVFSFILE;
2100 RTERRINFOSTATIC ErrInfo;
2101 if (rtFsIsoMakerCmdUseSrcStack(pOpts, pszIsoSpec))
2102 {
2103 rc = RTVfsDirOpenFile(pOpts->aSrcStack[iSrcStack - 1].hSrcDir, pszIsoSpec,
2104 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsFileIso);
2105 if (RT_FAILURE(rc))
2106 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error opening '%s' relative to '%s'",
2107 pszIsoSpec, pOpts->aSrcStack[iSrcStack - 1].pszSrcVfs);
2108 }
2109 else
2110 {
2111 uint32_t offError;
2112 rc = RTVfsChainOpenFile(pszIsoSpec, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE,
2113 &hVfsFileIso, &offError, RTErrInfoInitStatic(&ErrInfo));
2114 if (RT_FAILURE(rc))
2115 rc = rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainOpenFile", pszIsoSpec, rc, offError, &ErrInfo.Core);
2116 }
2117 if (RT_SUCCESS(rc))
2118 {
2119 RTVFS hSrcVfs;
2120 rc = RTFsIso9660VolOpen(hVfsFileIso, fFlags, &hSrcVfs, RTErrInfoInitStatic(&ErrInfo));
2121 RTVfsFileRelease(hVfsFileIso);
2122 if (RT_SUCCESS(rc))
2123 {
2124 RTVFSDIR hVfsSrcRootDir;
2125 rc = RTVfsOpenRoot(hSrcVfs, &hVfsSrcRootDir);
2126 if (RT_SUCCESS(rc))
2127 {
2128 pOpts->aSrcStack[iSrcStack].hSrcDir = hVfsSrcRootDir;
2129 pOpts->aSrcStack[iSrcStack].hSrcVfs = hSrcVfs;
2130 pOpts->aSrcStack[iSrcStack].pszSrcVfs = pszIsoSpec;
2131 pOpts->aSrcStack[iSrcStack].pszSrcVfsOption = pszOption;
2132 pOpts->iSrcStack = iSrcStack;
2133 return VINF_SUCCESS;
2134 }
2135 RTVfsRelease(hSrcVfs);
2136 }
2137 else if (RTErrInfoIsSet(&ErrInfo.Core))
2138 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to open '%s' as ISO FS: %Rrc - %s",
2139 pszIsoSpec, rc, ErrInfo.Core.pszMsg);
2140 else
2141 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to open '%s' as ISO FS: %Rrc", pszIsoSpec, rc);
2142 }
2143 return rc;
2144}
2145
2146
2147/**
2148 * Counter part to --push-iso and friends.
2149 *
2150 * @returns IPRT status code.
2151 * @param pOpts The ISO maker command instance.
2152 */
2153static int rtFsIsoMakerCmdOptPop(PRTFSISOMAKERCMDOPTS pOpts)
2154{
2155 int32_t const iSrcStack = pOpts->iSrcStack;
2156 if ( iSrcStack >= 0
2157 && pOpts->aSrcStack[iSrcStack].pszSrcVfsOption)
2158 {
2159 RTVfsDirRelease(pOpts->aSrcStack[iSrcStack].hSrcDir);
2160 RTVfsRelease(pOpts->aSrcStack[iSrcStack].hSrcVfs);
2161 pOpts->aSrcStack[iSrcStack].hSrcDir = NIL_RTVFSDIR;
2162 pOpts->aSrcStack[iSrcStack].hSrcVfs = NIL_RTVFS;
2163 pOpts->aSrcStack[iSrcStack].pszSrcVfs = NULL;
2164 pOpts->aSrcStack[iSrcStack].pszSrcVfsOption = NULL;
2165 pOpts->iSrcStack = iSrcStack - 1;
2166 return VINF_SUCCESS;
2167 }
2168 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_FOUND, "--pop without --push-xxx");
2169}
2170
2171
2172/**
2173 * Deals with the --import-iso {iso-file-spec} options.
2174 *
2175 * @returns IPRT status code
2176 * @param pOpts The ISO maker command instance.
2177 * @param pszIsoSpec The ISO path specifier.
2178 */
2179static int rtFsIsoMakerCmdOptImportIso(PRTFSISOMAKERCMDOPTS pOpts, const char *pszIsoSpec)
2180{
2181 /*
2182 * Open the input file.
2183 */
2184 RTERRINFOSTATIC ErrInfo;
2185 RTVFSFILE hIsoFile;
2186 int rc;
2187 if (rtFsIsoMakerCmdUseSrcStack(pOpts, pszIsoSpec))
2188 {
2189 rc = RTVfsDirOpenFile(pOpts->aSrcStack[pOpts->iSrcStack].hSrcDir, pszIsoSpec,
2190 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hIsoFile);
2191 if (RT_FAILURE(rc))
2192 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to open '%s' %s %s for importing: %Rrc", pszIsoSpec,
2193 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfsOption ? "inside" : "relative to",
2194 pOpts->aSrcStack[pOpts->iSrcStack].pszSrcVfs, rc);
2195 }
2196 else
2197 {
2198 uint32_t offError;
2199 rc = RTVfsChainOpenFile(pszIsoSpec, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE,
2200 &hIsoFile, &offError, RTErrInfoInitStatic(&ErrInfo));
2201 if (RT_FAILURE(rc))
2202 return rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainOpenFile", pszIsoSpec, rc, offError, &ErrInfo.Core);
2203 }
2204
2205 RTFSISOMAKERIMPORTRESULTS Results;
2206 rc = RTFsIsoMakerImport(pOpts->hIsoMaker, hIsoFile, 0 /*fFlags*/, &Results, RTErrInfoInitStatic(&ErrInfo));
2207
2208 RTVfsFileRelease(hIsoFile);
2209
2210 pOpts->cItemsAdded += Results.cAddedFiles;
2211 pOpts->cItemsAdded += Results.cAddedSymlinks;
2212 pOpts->cItemsAdded += Results.cAddedDirs;
2213 pOpts->cItemsAdded += Results.cBootCatEntries != UINT32_MAX ? Results.cBootCatEntries : 0;
2214 pOpts->cItemsAdded += Results.cbSysArea != 0 ? 1 : 0;
2215
2216 rtFsIsoMakerPrintf(pOpts, "ISO imported statistics for '%s'\n", pszIsoSpec);
2217 rtFsIsoMakerPrintf(pOpts, " cAddedNames: %'14RU32\n", Results.cAddedNames);
2218 rtFsIsoMakerPrintf(pOpts, " cAddedDirs: %'14RU32\n", Results.cAddedDirs);
2219 rtFsIsoMakerPrintf(pOpts, " cbAddedDataBlocks: %'14RU64 bytes\n", Results.cbAddedDataBlocks);
2220 rtFsIsoMakerPrintf(pOpts, " cAddedFiles: %'14RU32\n", Results.cAddedFiles);
2221 rtFsIsoMakerPrintf(pOpts, " cAddedSymlinks: %'14RU32\n", Results.cAddedSymlinks);
2222 if (Results.cBootCatEntries == UINT32_MAX)
2223 rtFsIsoMakerPrintf(pOpts, " cBootCatEntries: none\n");
2224 else
2225 rtFsIsoMakerPrintf(pOpts, " cBootCatEntries: %'14RU32\n", Results.cBootCatEntries);
2226 rtFsIsoMakerPrintf(pOpts, " cbSysArea: %'14RU32\n", Results.cbSysArea);
2227 rtFsIsoMakerPrintf(pOpts, " cErrors: %'14RU32\n", Results.cErrors);
2228
2229 if (RT_SUCCESS(rc))
2230 return rc;
2231 if (RTErrInfoIsSet(&ErrInfo.Core))
2232 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerImport failed: %Rrc - %s", rc, ErrInfo.Core.pszMsg);
2233 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerImport failed: %Rrc", rc);
2234}
2235
2236
2237/**
2238 * Deals with: --iso-level, -l
2239 *
2240 * @returns IPRT status code
2241 * @param pOpts The ISO maker command instance.
2242 * @param uLevel The new ISO level.
2243 */
2244static int rtFsIsoMakerCmdOptSetIsoLevel(PRTFSISOMAKERCMDOPTS pOpts, uint8_t uLevel)
2245{
2246 int rc = RTFsIsoMakerSetIso9660Level(pOpts->hIsoMaker, uLevel);
2247 if (RT_SUCCESS(rc))
2248 return rc;
2249 if (rc == VERR_WRONG_ORDER)
2250 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Cannot change ISO level to %d after having added files!", uLevel);
2251 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to set ISO level to %d: %Rrc", uLevel, rc);
2252}
2253
2254
2255/**
2256 * Deals with: --rock-ridge, --limited-rock-ridge, --no-rock-ridge
2257 *
2258 * @returns IPRT status code
2259 * @param pOpts The ISO maker command instance.
2260 * @param uLevel The new rock ridge level.
2261 */
2262static int rtFsIsoMakerCmdOptSetPrimaryRockLevel(PRTFSISOMAKERCMDOPTS pOpts, uint8_t uLevel)
2263{
2264 int rc = RTFsIsoMakerSetRockRidgeLevel(pOpts->hIsoMaker, uLevel);
2265 if (RT_SUCCESS(rc))
2266 return rc;
2267 if (rc == VERR_WRONG_ORDER)
2268 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Cannot change rock ridge level to %d after having added files!", uLevel);
2269 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to set rock ridge level to %d: %Rrc", uLevel, rc);
2270}
2271
2272
2273/**
2274 * Deals with: --joliet, --no-joliet, --joliet-ucs-level, --ucs-level
2275 *
2276 * @returns IPRT status code
2277 * @param pOpts The ISO maker command instance.
2278 * @param uLevel The new rock ridge level.
2279 */
2280static int rtFsIsoMakerCmdOptSetJolietUcs2Level(PRTFSISOMAKERCMDOPTS pOpts, uint8_t uLevel)
2281{
2282 int rc = RTFsIsoMakerSetJolietUcs2Level(pOpts->hIsoMaker, uLevel);
2283 if (RT_SUCCESS(rc))
2284 return rc;
2285 if (rc == VERR_WRONG_ORDER)
2286 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Cannot change joliet UCS level to %d after having added files!", uLevel);
2287 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to set joliet UCS level to %d: %Rrc", uLevel, rc);
2288}
2289
2290
2291/**
2292 * Deals with: --rational-attribs, --strict-attribs, -R, -r
2293 *
2294 * @returns IPRT status code
2295 * @param pOpts The ISO maker command instance.
2296 * @param uLevel The new rock ridge level.
2297 */
2298static int rtFsIsoMakerCmdOptSetAttribInheritStyle(PRTFSISOMAKERCMDOPTS pOpts, bool fStrict)
2299{
2300 int rc = RTFsIsoMakerSetAttribInheritStyle(pOpts->hIsoMaker, fStrict);
2301 if (RT_SUCCESS(rc))
2302 return rc;
2303 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to change attributes handling style to %s: %Rrc",
2304 fStrict ? "strict" : "rational", rc);
2305}
2306
2307
2308/**
2309 * Deals with: -G|--generic-boot {file}
2310 *
2311 * This concers content the first 16 sectors of the image. We start loading the
2312 * file at byte 0 in the image and stops at 32KB.
2313 *
2314 * @returns IPRT status code
2315 * @param pOpts The ISO maker command instance.
2316 * @param pszGenericBootImage The generic boot image source.
2317 */
2318static int rtFsIsoMakerCmdOptGenericBoot(PRTFSISOMAKERCMDOPTS pOpts, const char *pszGenericBootImage)
2319{
2320 RTERRINFOSTATIC ErrInfo;
2321 uint32_t offError;
2322 RTVFSFILE hVfsFile;
2323 int rc = RTVfsChainOpenFile(pszGenericBootImage, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsFile,
2324 &offError, RTErrInfoInitStatic(&ErrInfo));
2325 if (RT_FAILURE(rc))
2326 return rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainOpenFile", pszGenericBootImage, rc, offError, &ErrInfo.Core);
2327
2328 uint8_t abBuf[_32K];
2329 size_t cbRead;
2330 rc = RTVfsFileReadAt(hVfsFile, 0, abBuf, sizeof(abBuf), &cbRead);
2331 RTVfsFileRelease(hVfsFile);
2332 if (RT_FAILURE(rc))
2333 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error reading 32KB from generic boot image '%s': %Rrc", pszGenericBootImage, rc);
2334
2335 rc = RTFsIsoMakerSetSysAreaContent(pOpts->hIsoMaker, abBuf, cbRead, 0);
2336 if (RT_FAILURE(rc))
2337 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerSetSysAreaContent failed with a %zu bytes input: %Rrc", cbRead, rc);
2338
2339 return VINF_SUCCESS;
2340}
2341
2342
2343/**
2344 * Helper that makes sure we've got a validation boot entry.
2345 *
2346 * @returns IPRT status code
2347 * @param pOpts The ISO maker command instance.
2348 */
2349static void rtFsIsoMakerCmdOptEltoritoEnsureValidationEntry(PRTFSISOMAKERCMDOPTS pOpts)
2350{
2351 if (pOpts->cBootCatEntries == 0)
2352 {
2353 pOpts->aBootCatEntries[0].enmType = RTFSISOMKCMDELTORITOENTRY::kEntryType_Validation;
2354 pOpts->aBootCatEntries[0].u.Validation.idPlatform = ISO9660_ELTORITO_PLATFORM_ID_X86;
2355 pOpts->aBootCatEntries[0].u.Validation.pszString = NULL;
2356 pOpts->cBootCatEntries = 1;
2357 }
2358}
2359
2360
2361/**
2362 * Helper that makes sure we've got a current boot entry.
2363 *
2364 * @returns IPRT status code
2365 * @param pOpts The ISO maker command instance.
2366 * @param fForceNew Whether to force a new entry.
2367 * @param pidxBootCat Where to return the boot catalog index.
2368 */
2369static int rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(PRTFSISOMAKERCMDOPTS pOpts, bool fForceNew, uint32_t *pidxBootCat)
2370{
2371 rtFsIsoMakerCmdOptEltoritoEnsureValidationEntry(pOpts);
2372
2373 uint32_t i = pOpts->cBootCatEntries;
2374 if (i == 2 && fForceNew)
2375 {
2376 pOpts->aBootCatEntries[i].enmType = RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader;
2377 pOpts->aBootCatEntries[i].u.SectionHeader.idPlatform = pOpts->aBootCatEntries[0].u.Validation.idPlatform;
2378 pOpts->aBootCatEntries[i].u.SectionHeader.pszString = NULL;
2379 pOpts->cBootCatEntries = ++i;
2380 }
2381
2382 if ( i == 1
2383 || fForceNew
2384 || pOpts->aBootCatEntries[i - 1].enmType == RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader)
2385 {
2386 if (i >= RT_ELEMENTS(pOpts->aBootCatEntries))
2387 {
2388 *pidxBootCat = UINT32_MAX;
2389 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_BUFFER_OVERFLOW, "Too many boot catalog entries");
2390 }
2391
2392 pOpts->aBootCatEntries[i].enmType = i == 1 ? RTFSISOMKCMDELTORITOENTRY::kEntryType_Default
2393 : RTFSISOMKCMDELTORITOENTRY::kEntryType_Section;
2394 pOpts->aBootCatEntries[i].u.Section.pszImageNameInIso = NULL;
2395 pOpts->aBootCatEntries[i].u.Section.idxImageObj = UINT32_MAX;
2396 pOpts->aBootCatEntries[i].u.Section.fInsertBootInfoTable = false;
2397 pOpts->aBootCatEntries[i].u.Section.fBootable = true;
2398 pOpts->aBootCatEntries[i].u.Section.bBootMediaType = ISO9660_ELTORITO_BOOT_MEDIA_TYPE_MASK;
2399 pOpts->aBootCatEntries[i].u.Section.bSystemType = 1 /*FAT12*/;
2400 pOpts->aBootCatEntries[i].u.Section.uLoadSeg = 0x7c0;
2401 pOpts->aBootCatEntries[i].u.Section.cSectorsToLoad = 4;
2402 pOpts->cBootCatEntries = ++i;
2403 }
2404
2405 *pidxBootCat = i - 1;
2406 return VINF_SUCCESS;
2407}
2408
2409
2410/**
2411 * Deals with: --boot-catalog <path-spec>
2412 *
2413 * This enters the boot catalog into the namespaces of the image. The path-spec
2414 * is similar to what rtFsIsoMakerCmdAddSomething processes, only there isn't a
2415 * source file part.
2416 *
2417 * @returns IPRT status code
2418 * @param pOpts The ISO maker command instance.
2419 * @param pszGenericBootImage The generic boot image source.
2420 */
2421static int rtFsIsoMakerCmdOptEltoritoSetBootCatalogPath(PRTFSISOMAKERCMDOPTS pOpts, const char *pszBootCat)
2422{
2423 /* Make sure we'll fail later if no other boot options are present. */
2424 rtFsIsoMakerCmdOptEltoritoEnsureValidationEntry(pOpts);
2425
2426 /* Parse the name spec. */
2427 RTFSISOMKCMDPARSEDNAMES Parsed;
2428 int rc = rtFsIsoMakerCmdParseNameSpec(pOpts, pszBootCat, false /*fWithSrc*/, &Parsed);
2429 if (RT_SUCCESS(rc))
2430 {
2431 /* Query/create the boot catalog and enter it into the name spaces. */
2432 uint32_t idxBootCatObj;
2433 rc = RTFsIsoMakerQueryObjIdxForBootCatalog(pOpts->hIsoMaker, &idxBootCatObj);
2434 if (RT_SUCCESS(rc))
2435 rc = rtFsIsoMakerCmdSetObjPaths(pOpts, idxBootCatObj, &Parsed, "boot catalog");
2436 else
2437 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerQueryBootCatalogPathObjIdx failed: %Rrc", rc);
2438 }
2439 return rc;
2440}
2441
2442
2443/**
2444 * Deals with: --eltorito-add-image {file-spec}
2445 *
2446 * This differs from -b|--eltorito-boot in that it takes a source file
2447 * specification identical to what rtFsIsoMakerCmdAddSomething processes instead
2448 * of a reference to a file in the image.
2449 *
2450 * This operates on the current eltorito boot catalog entry.
2451 *
2452 * @returns IPRT status code
2453 * @param pOpts The ISO maker command instance.
2454 * @param pszGenericBootImage The generic boot image source.
2455 */
2456static int rtFsIsoMakerCmdOptEltoritoAddImage(PRTFSISOMAKERCMDOPTS pOpts, const char *pszBootImageSpec)
2457{
2458 /* Parse the name spec. */
2459 RTFSISOMKCMDPARSEDNAMES Parsed;
2460 int rc = rtFsIsoMakerCmdParseNameSpec(pOpts, pszBootImageSpec, true /*fWithSrc*/, &Parsed);
2461 if (RT_SUCCESS(rc))
2462 {
2463 uint32_t idxBootCat;
2464 rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
2465 if (RT_SUCCESS(rc))
2466 {
2467 if ( pOpts->aBootCatEntries[idxBootCat].u.Section.idxImageObj != UINT32_MAX
2468 || pOpts->aBootCatEntries[idxBootCat].u.Section.pszImageNameInIso != NULL)
2469 rc = rtFsIsoMakerCmdSyntaxError(pOpts, "boot image already given for current El Torito entry (%#u)", idxBootCat);
2470 else
2471 {
2472 uint32_t idxImageObj;
2473 rc = rtFsIsoMakerCmdStatAndAddFile(pOpts, Parsed.aNames[Parsed.cNamesWithSrc - 1].szPath, &Parsed, &idxImageObj);
2474 if (RT_SUCCESS(rc))
2475 pOpts->aBootCatEntries[idxBootCat].u.Section.idxImageObj = idxImageObj;
2476 }
2477 }
2478 }
2479
2480 return rc;
2481}
2482
2483
2484/**
2485 * Deals with: -b|--eltorito-boot {file-in-iso}
2486 *
2487 * This operates on the current eltorito boot catalog entry.
2488 *
2489 * @returns IPRT status code
2490 * @param pOpts The ISO maker command instance.
2491 * @param pszGenericBootImage The generic boot image source.
2492 */
2493static int rtFsIsoMakerCmdOptEltoritoBoot(PRTFSISOMAKERCMDOPTS pOpts, const char *pszBootImage)
2494{
2495 uint32_t idxBootCat;
2496 int 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 return rtFsIsoMakerCmdSyntaxError(pOpts, "boot image already given for current El Torito entry (%#u)", idxBootCat);
2502
2503 uint32_t idxImageObj = RTFsIsoMakerGetObjIdxForPath(pOpts->hIsoMaker, RTFSISOMAKER_NAMESPACE_ALL, pszBootImage);
2504 if (idxImageObj == UINT32_MAX)
2505 pOpts->aBootCatEntries[idxBootCat].u.Section.pszImageNameInIso = pszBootImage;
2506 pOpts->aBootCatEntries[idxBootCat].u.Section.idxImageObj = idxImageObj;
2507 }
2508 return rc;
2509}
2510
2511
2512/**
2513 * Deals with: --eltorito-platform-id {x86|PPC|Mac|efi|number}
2514 *
2515 * Operates on the validation entry or a section header.
2516 *
2517 * @returns IPRT status code
2518 * @param pOpts The ISO maker command instance.
2519 * @param pszPlatformId The platform ID.
2520 */
2521static int rtFsIsoMakerCmdOptEltoritoPlatformId(PRTFSISOMAKERCMDOPTS pOpts, const char *pszPlatformId)
2522{
2523 /* Decode it. */
2524 uint8_t idPlatform;
2525 if (strcmp(pszPlatformId, "x86") == 0)
2526 idPlatform = ISO9660_ELTORITO_PLATFORM_ID_X86;
2527 else if (strcmp(pszPlatformId, "PPC") == 0)
2528 idPlatform = ISO9660_ELTORITO_PLATFORM_ID_PPC;
2529 else if (strcmp(pszPlatformId, "Mac") == 0)
2530 idPlatform = ISO9660_ELTORITO_PLATFORM_ID_MAC;
2531 else if (strcmp(pszPlatformId, "efi") == 0)
2532 idPlatform = ISO9660_ELTORITO_PLATFORM_ID_EFI;
2533 else
2534 {
2535 int rc = RTStrToUInt8Full(pszPlatformId, 0, &idPlatform);
2536 if (rc != VINF_SUCCESS)
2537 return rtFsIsoMakerCmdSyntaxError(pOpts, "invalid or unknown platform ID: %s", pszPlatformId);
2538 }
2539
2540 /* If this option comes before anything related to the default entry, work
2541 on the validation entry. */
2542 if (pOpts->cBootCatEntries <= 1)
2543 {
2544 rtFsIsoMakerCmdOptEltoritoEnsureValidationEntry(pOpts);
2545 pOpts->aBootCatEntries[0].u.Validation.idPlatform = idPlatform;
2546 }
2547 /* Otherwise, work on the current section header, creating a new one if necessary. */
2548 else
2549 {
2550 uint32_t idxBootCat = pOpts->cBootCatEntries - 1;
2551 if (pOpts->aBootCatEntries[idxBootCat].enmType == RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader)
2552 pOpts->aBootCatEntries[idxBootCat].u.SectionHeader.idPlatform = idPlatform;
2553 else
2554 {
2555 idxBootCat++;
2556 if (idxBootCat + 2 > RT_ELEMENTS(pOpts->aBootCatEntries))
2557 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_BUFFER_OVERFLOW, "Too many boot catalog entries");
2558
2559 pOpts->aBootCatEntries[idxBootCat].enmType = RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader;
2560 pOpts->aBootCatEntries[idxBootCat].u.SectionHeader.idPlatform = idPlatform;
2561 pOpts->aBootCatEntries[idxBootCat].u.SectionHeader.pszString = NULL;
2562 pOpts->cBootCatEntries = idxBootCat + 1;
2563 }
2564 }
2565 return VINF_SUCCESS;
2566}
2567
2568
2569/**
2570 * Deals with: -no-boot
2571 *
2572 * This operates on the current eltorito boot catalog entry.
2573 *
2574 * @returns IPRT status code
2575 * @param pOpts The ISO maker command instance.
2576 */
2577static int rtFsIsoMakerCmdOptEltoritoSetNotBootable(PRTFSISOMAKERCMDOPTS pOpts)
2578{
2579 uint32_t idxBootCat;
2580 int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
2581 if (RT_SUCCESS(rc))
2582 pOpts->aBootCatEntries[idxBootCat].u.Section.fBootable = false;
2583 return rc;
2584}
2585
2586
2587/**
2588 * Deals with: -hard-disk-boot, -no-emulation-boot, --eltorito-floppy-12,
2589 * --eltorito-floppy-144, --eltorito-floppy-288
2590 *
2591 * This operates on the current eltorito boot catalog entry.
2592 *
2593 * @returns IPRT status code
2594 * @param pOpts The ISO maker command instance.
2595 * @param bMediaType The media type.
2596 */
2597static int rtFsIsoMakerCmdOptEltoritoSetMediaType(PRTFSISOMAKERCMDOPTS pOpts, uint8_t bMediaType)
2598{
2599 uint32_t idxBootCat;
2600 int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
2601 if (RT_SUCCESS(rc))
2602 pOpts->aBootCatEntries[idxBootCat].u.Section.bBootMediaType = bMediaType;
2603 return rc;
2604}
2605
2606
2607/**
2608 * Deals with: -boot-load-seg {seg}
2609 *
2610 * This operates on the current eltorito boot catalog entry.
2611 *
2612 * @returns IPRT status code
2613 * @param pOpts The ISO maker command instance.
2614 * @param uSeg The load segment.
2615 */
2616static int rtFsIsoMakerCmdOptEltoritoSetLoadSegment(PRTFSISOMAKERCMDOPTS pOpts, uint16_t uSeg)
2617{
2618 uint32_t idxBootCat;
2619 int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
2620 if (RT_SUCCESS(rc))
2621 pOpts->aBootCatEntries[idxBootCat].u.Section.uLoadSeg = uSeg;
2622 return rc;
2623}
2624
2625
2626/**
2627 * Deals with: -boot-load-size {sectors}
2628 *
2629 * This operates on the current eltorito boot catalog entry.
2630 *
2631 * @returns IPRT status code
2632 * @param pOpts The ISO maker command instance.
2633 * @param cSectors Number of emulated sectors to load
2634 */
2635static int rtFsIsoMakerCmdOptEltoritoSetLoadSectorCount(PRTFSISOMAKERCMDOPTS pOpts, uint16_t cSectors)
2636{
2637 uint32_t idxBootCat;
2638 int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
2639 if (RT_SUCCESS(rc))
2640 pOpts->aBootCatEntries[idxBootCat].u.Section.cSectorsToLoad = cSectors;
2641 return rc;
2642}
2643
2644
2645/**
2646 * Deals with: -boot-info-table
2647 *
2648 * This operates on the current eltorito boot catalog entry.
2649 *
2650 * @returns IPRT status code
2651 * @param pOpts The ISO maker command instance.
2652 */
2653static int rtFsIsoMakerCmdOptEltoritoEnableBootInfoTablePatching(PRTFSISOMAKERCMDOPTS pOpts)
2654{
2655 uint32_t idxBootCat;
2656 int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
2657 if (RT_SUCCESS(rc))
2658 pOpts->aBootCatEntries[idxBootCat].u.Section.fInsertBootInfoTable = true;
2659 return rc;
2660}
2661
2662
2663/**
2664 * Validates and commits the boot catalog stuff.
2665 *
2666 * ASSUMING this is called after all options are parsed and there is only this
2667 * one call.
2668 *
2669 * @returns IPRT status code
2670 * @param pOpts The ISO maker command instance.
2671 */
2672static int rtFsIsoMakerCmdOptEltoritoCommitBootCatalog(PRTFSISOMAKERCMDOPTS pOpts)
2673{
2674 if (pOpts->cBootCatEntries == 0)
2675 return VINF_SUCCESS;
2676
2677 /*
2678 * Locate and configure the boot images first.
2679 */
2680 int rc;
2681 PRTFSISOMKCMDELTORITOENTRY pBootCatEntry = &pOpts->aBootCatEntries[1];
2682 for (uint32_t idxBootCat = 1; idxBootCat < pOpts->cBootCatEntries; idxBootCat++, pBootCatEntry++)
2683 if ( pBootCatEntry->enmType == RTFSISOMKCMDELTORITOENTRY::kEntryType_Default
2684 || pBootCatEntry->enmType == RTFSISOMKCMDELTORITOENTRY::kEntryType_Section)
2685 {
2686 /* Make sure we've got a boot image. */
2687 uint32_t idxImageObj = pBootCatEntry->u.Section.idxImageObj;
2688 if (idxImageObj == UINT32_MAX)
2689 {
2690 const char *pszBootImage = pBootCatEntry->u.Section.pszImageNameInIso;
2691 if (pszBootImage == NULL)
2692 return rtFsIsoMakerCmdSyntaxError(pOpts, "No image name given for boot catalog entry #%u", idxBootCat);
2693
2694 idxImageObj = RTFsIsoMakerGetObjIdxForPath(pOpts->hIsoMaker, RTFSISOMAKER_NAMESPACE_ALL, pszBootImage);
2695 if (idxImageObj == UINT32_MAX)
2696 return rtFsIsoMakerCmdSyntaxError(pOpts, "Unable to locate image for boot catalog entry #%u: %s",
2697 idxBootCat, pszBootImage);
2698 pBootCatEntry->u.Section.idxImageObj = idxImageObj;
2699 }
2700
2701 /* Enable patching it? */
2702 if (pBootCatEntry->u.Section.fInsertBootInfoTable)
2703 {
2704 rc = RTFsIsoMakerObjEnableBootInfoTablePatching(pOpts->hIsoMaker, idxImageObj, true);
2705 if (RT_FAILURE(rc))
2706 return rtFsIsoMakerCmdErrorRc(pOpts, rc,
2707 "RTFsIsoMakerObjEnableBootInfoTablePatching failed on entry #%u: %Rrc",
2708 idxBootCat, rc);
2709 }
2710
2711 /* Figure out the floppy type given the object size. */
2712 if (pBootCatEntry->u.Section.bBootMediaType == ISO9660_ELTORITO_BOOT_MEDIA_TYPE_MASK)
2713 {
2714 uint64_t cbImage;
2715 rc = RTFsIsoMakerObjQueryDataSize(pOpts->hIsoMaker, idxImageObj, &cbImage);
2716 if (RT_FAILURE(rc))
2717 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerObjGetDataSize failed on entry #%u: %Rrc",
2718 idxBootCat, rc);
2719 if (cbImage == 1228800)
2720 pBootCatEntry->u.Section.bBootMediaType = ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_1_2_MB;
2721 else if (cbImage <= 1474560)
2722 pBootCatEntry->u.Section.bBootMediaType = ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_1_44_MB;
2723 else if (cbImage <= 2949120)
2724 pBootCatEntry->u.Section.bBootMediaType = ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_2_88_MB;
2725 else
2726 pBootCatEntry->u.Section.bBootMediaType = ISO9660_ELTORITO_BOOT_MEDIA_TYPE_HARD_DISK;
2727 }
2728 }
2729
2730 /*
2731 * Add the boot catalog entries.
2732 */
2733 pBootCatEntry = &pOpts->aBootCatEntries[0];
2734 for (uint32_t idxBootCat = 0; idxBootCat < pOpts->cBootCatEntries; idxBootCat++, pBootCatEntry++)
2735 switch (pBootCatEntry->enmType)
2736 {
2737 case RTFSISOMKCMDELTORITOENTRY::kEntryType_Validation:
2738 Assert(idxBootCat == 0);
2739 rc = RTFsIsoMakerBootCatSetValidationEntry(pOpts->hIsoMaker, pBootCatEntry->u.Validation.idPlatform,
2740 pBootCatEntry->u.Validation.pszString);
2741 if (RT_FAILURE(rc))
2742 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerBootCatSetValidationEntry failed: %Rrc", rc);
2743 break;
2744
2745 case RTFSISOMKCMDELTORITOENTRY::kEntryType_Default:
2746 case RTFSISOMKCMDELTORITOENTRY::kEntryType_Section:
2747 Assert(pBootCatEntry->enmType == RTFSISOMKCMDELTORITOENTRY::kEntryType_Default ? idxBootCat == 1 : idxBootCat > 2);
2748 rc = RTFsIsoMakerBootCatSetSectionEntry(pOpts->hIsoMaker, idxBootCat,
2749 pBootCatEntry->u.Section.idxImageObj,
2750 pBootCatEntry->u.Section.bBootMediaType,
2751 pBootCatEntry->u.Section.bSystemType,
2752 pBootCatEntry->u.Section.fBootable,
2753 pBootCatEntry->u.Section.uLoadSeg,
2754 pBootCatEntry->u.Section.cSectorsToLoad,
2755 ISO9660_ELTORITO_SEL_CRIT_TYPE_NONE, NULL, 0);
2756 if (RT_FAILURE(rc))
2757 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerBootCatSetSectionEntry failed on entry #%u: %Rrc",
2758 idxBootCat, rc);
2759 break;
2760
2761 case RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader:
2762 {
2763 uint32_t cEntries = 1;
2764 while ( idxBootCat + cEntries < pOpts->cBootCatEntries
2765 && pBootCatEntry[cEntries].enmType != RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader)
2766 cEntries++;
2767 cEntries--;
2768
2769 Assert(idxBootCat > 1);
2770 rc = RTFsIsoMakerBootCatSetSectionHeaderEntry(pOpts->hIsoMaker, idxBootCat, cEntries,
2771 pBootCatEntry->u.SectionHeader.idPlatform,
2772 pBootCatEntry->u.SectionHeader.pszString);
2773 if (RT_FAILURE(rc))
2774 return rtFsIsoMakerCmdErrorRc(pOpts, rc,
2775 "RTFsIsoMakerBootCatSetSectionHeaderEntry failed on entry #%u: %Rrc",
2776 idxBootCat, rc);
2777 break;
2778 }
2779
2780 default:
2781 AssertFailedReturn(VERR_INTERNAL_ERROR_3);
2782 }
2783
2784 return VINF_SUCCESS;
2785}
2786
2787
2788/**
2789 * Deals with: --eltorito-new-entry, --eltorito-alt-boot
2790 *
2791 * This operates on the current eltorito boot catalog entry.
2792 *
2793 * @returns IPRT status code
2794 * @param pOpts The ISO maker command instance.
2795 */
2796static int rtFsIsoMakerCmdOptEltoritoNewEntry(PRTFSISOMAKERCMDOPTS pOpts)
2797{
2798 uint32_t idxBootCat;
2799 return rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, true /*fForceNew*/, &idxBootCat);
2800}
2801
2802
2803/**
2804 * Sets a string property in all namespaces.
2805 *
2806 * @returns IPRT status code.
2807 * @param pOpts The ISO maker command instance.
2808 * @param pszValue The new string value.
2809 * @param enmStringProp The string property.
2810 */
2811static int rtFsIsoMakerCmdOptSetStringProp(PRTFSISOMAKERCMDOPTS pOpts, const char *pszValue, RTFSISOMAKERSTRINGPROP enmStringProp)
2812{
2813 int rc = RTFsIsoMakerSetStringProp(pOpts->hIsoMaker, enmStringProp, pOpts->fDstNamespaces, pszValue);
2814 if (RT_FAILURE(rc))
2815 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to set string property %d to '%s': %Rrc", enmStringProp, pszValue, rc);
2816 return rc;
2817}
2818
2819
2820/**
2821 * Handles the --dir-mode and --file-mode options.
2822 *
2823 * @returns IPRT status code.
2824 * @param pOpts The ISO maker command instance.
2825 * @param fDir True if applies to dir, false if applies to
2826 * files.
2827 * @param fMode The forced mode.
2828 */
2829static int rtFsIsoMakerCmdOptSetFileOrDirMode(PRTFSISOMAKERCMDOPTS pOpts, bool fDir, RTFMODE fMode)
2830{
2831 /* Change the mode masks. */
2832 int rc;
2833 if (fDir)
2834 rc = RTFsIsoMakerSetForcedDirMode(pOpts->hIsoMaker, fMode, true /*fForced*/);
2835 else
2836 rc = RTFsIsoMakerSetForcedFileMode(pOpts->hIsoMaker, fMode, true /*fForced*/);
2837 if (RT_SUCCESS(rc))
2838 {
2839 /* Then enable rock.*/
2840 rc = RTFsIsoMakerSetRockRidgeLevel(pOpts->hIsoMaker, 2);
2841 if (RT_SUCCESS(rc))
2842 return VINF_SUCCESS;
2843 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to enable rock ridge: %Rrc", rc);
2844 }
2845 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to set %s force & default mode mask to %04o: %Rrc",
2846 fMode, fDir ? "directory" : "file", rc);
2847}
2848
2849
2850/**
2851 * Handles the --no-dir-mode and --no-file-mode options that counters
2852 * --dir-mode and --file-mode.
2853 *
2854 * @returns IPRT status code.
2855 * @param pOpts The ISO maker command instance.
2856 * @param fDir True if applies to dir, false if applies to
2857 * files.
2858 */
2859static int rtFsIsoMakerCmdOptDisableFileOrDirMode(PRTFSISOMAKERCMDOPTS pOpts, bool fDir)
2860{
2861 int rc;
2862 if (fDir)
2863 rc = RTFsIsoMakerSetForcedDirMode(pOpts->hIsoMaker, 0, false /*fForced*/);
2864 else
2865 rc = RTFsIsoMakerSetForcedFileMode(pOpts->hIsoMaker, 0, true /*fForced*/);
2866 if (RT_SUCCESS(rc))
2867 return VINF_SUCCESS;
2868 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to disable forced %s mode mask: %Rrc", fDir ? "directory" : "file", rc);
2869}
2870
2871
2872
2873/**
2874 * Handles the --new-dir-mode option.
2875 *
2876 * @returns IPRT status code.
2877 * @param pOpts The ISO maker command instance.
2878 * @param fMode The forced mode.
2879 */
2880static int rtFsIsoMakerCmdOptSetNewDirMode(PRTFSISOMAKERCMDOPTS pOpts, RTFMODE fMode)
2881{
2882 int rc = RTFsIsoMakerSetDefaultDirMode(pOpts->hIsoMaker, fMode);
2883 if (RT_SUCCESS(rc))
2884 return VINF_SUCCESS;
2885 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to set default dir mode mask to %04o: %Rrc", fMode, rc);
2886}
2887
2888
2889/**
2890 * Handles the --chmod option.
2891 *
2892 * @returns IPRT status code
2893 * @param pOpts The ISO maker command instance.
2894 * @param pszSpec The option value.
2895 */
2896static int rtFsIsoMakerCmdOptChmod(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSpec)
2897{
2898 /*
2899 * Parse the mode part.
2900 */
2901 int rc;
2902 uint32_t fUnset = 07777;
2903 uint32_t fSet = 0;
2904 const char *pszPath = pszSpec;
2905 if (RT_C_IS_DIGIT(*pszPath))
2906 {
2907 rc = RTStrToUInt32Ex(pszSpec, (char **)&pszPath, 8, &fSet);
2908 if (rc != VWRN_TRAILING_CHARS)
2909 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --chmod, octal mode parse failed: %s (%Rrc)", pszSpec, rc);
2910 if (fSet & ~07777)
2911 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --chmod, invalid mode mask: 0%o, max 07777", fSet);
2912 if (*pszPath != ':')
2913 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --chmod, expected colon after mode: %s", pszSpec);
2914 }
2915 else
2916 {
2917 pszPath = strchr(pszPath, ':');
2918 if (pszPath == NULL)
2919 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --chmod, expected colon after mode: %s", pszSpec);
2920 size_t const cchMode = pszPath - pszSpec;
2921
2922 /* We currently only matches certain patterns. Later this needs to be generalized into a RTFile or RTPath method. */
2923 fUnset = 0;
2924#define MATCH_MODE_STR(a_szMode) (cchMode == sizeof(a_szMode) - 1U && memcmp(pszSpec, a_szMode, sizeof(a_szMode) - 1) == 0)
2925 if (MATCH_MODE_STR("a+x"))
2926 fSet = 0111;
2927 else if (MATCH_MODE_STR("a+r"))
2928 fSet = 0444;
2929 else if (MATCH_MODE_STR("a+rx"))
2930 fSet = 0555;
2931 else
2932 return rtFsIsoMakerCmdSyntaxError(pOpts, "Sorry, --chmod doesn't understand complicated mode expressions: %s", pszSpec);
2933#undef MATCH_MODE_STR
2934 }
2935
2936 /*
2937 * Check that the file starts with a slash.
2938 */
2939 pszPath++;
2940 if (!RTPATH_IS_SLASH(*pszPath))
2941 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --chmod, path must start with a slash: %s", pszSpec);
2942
2943 /*
2944 * Do the job.
2945 */
2946 rc = RTFsIsoMakerSetPathMode(pOpts->hIsoMaker, pszPath, pOpts->fDstNamespaces, fSet, fUnset, 0 /*fFlags*/, NULL /*pcHits*/);
2947 if (rc == VWRN_NOT_FOUND)
2948 return rtFsIsoMakerCmdSyntaxError(pOpts, "Could not find --chmod path: %s", pszPath);
2949 if (RT_SUCCESS(rc))
2950 return VINF_SUCCESS;
2951 return rtFsIsoMakerCmdSyntaxError(pOpts, "RTFsIsoMakerSetPathMode(,%s,%#x,%o,%o,0,) failed: %Rrc",
2952 pszPath, pOpts->fDstNamespaces, fSet, fUnset, rc);
2953}
2954
2955
2956/**
2957 * Handles the --chown and --chgrp options.
2958 *
2959 * @returns IPRT status code
2960 * @param pOpts The ISO maker command instance.
2961 * @param pszSpec The option value.
2962 * @param fIsChOwn Set if 'chown', clear if 'chgrp'.
2963 */
2964static int rtFsIsoMakerCmdOptChangeOwnerGroup(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSpec, bool fIsChOwn)
2965{
2966 const char * const pszOpt = fIsChOwn ? "chown" : "chgrp";
2967
2968 /*
2969 * Parse out the ID and path .
2970 */
2971 uint32_t idValue;
2972 const char *pszPath = pszSpec;
2973 int rc = RTStrToUInt32Ex(pszSpec, (char **)&pszPath, 0, &idValue);
2974 if (rc != VWRN_TRAILING_CHARS)
2975 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --%s, numeric ID parse failed: %s (%Rrc)", pszOpt, pszSpec, rc);
2976 if (*pszPath != ':')
2977 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --%s, expected colon after ID: %s", pszOpt, pszSpec);
2978 pszPath++;
2979 if (!RTPATH_IS_SLASH(*pszPath))
2980 return rtFsIsoMakerCmdSyntaxError(pOpts, "Malformed --%s, path must start with a slash: %s", pszOpt, pszSpec);
2981
2982 /*
2983 * Do the job.
2984 */
2985 if (fIsChOwn)
2986 rc = RTFsIsoMakerSetPathOwnerId(pOpts->hIsoMaker, pszPath, pOpts->fDstNamespaces, idValue, NULL /*pcHits*/);
2987 else
2988 rc = RTFsIsoMakerSetPathGroupId(pOpts->hIsoMaker, pszPath, pOpts->fDstNamespaces, idValue, NULL /*pcHits*/);
2989 if (rc == VWRN_NOT_FOUND)
2990 return rtFsIsoMakerCmdSyntaxError(pOpts, "Could not find --%s path: %s", pszOpt, pszPath);
2991 if (RT_SUCCESS(rc))
2992 return VINF_SUCCESS;
2993 return rtFsIsoMakerCmdSyntaxError(pOpts, "RTFsIsoMakerSetPath%sId(,%s,%#x,%u,) failed: %Rrc",
2994 fIsChOwn ? "Owner" : "Group", pszPath, pOpts->fDstNamespaces, idValue, rc);
2995}
2996
2997
2998/**
2999 * Loads an argument file (e.g. a .iso-file) and parses it.
3000 *
3001 * @returns IPRT status code.
3002 * @param pOpts The ISO maker command instance.
3003 * @param pszFileSpec The file to parse.
3004 * @param cDepth The current nesting depth.
3005 */
3006static int rtFsIsoMakerCmdParseArgumentFile(PRTFSISOMAKERCMDOPTS pOpts, const char *pszFileSpec, unsigned cDepth)
3007{
3008 if (cDepth > 2)
3009 return rtFsIsoMakerCmdErrorRc(pOpts, VERR_INVALID_PARAMETER, "Too many nested argument files!");
3010
3011 /*
3012 * Read the file into memory.
3013 */
3014 RTERRINFOSTATIC ErrInfo;
3015 uint32_t offError;
3016 RTVFSFILE hVfsFile;
3017 int rc = RTVfsChainOpenFile(pszFileSpec, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsFile,
3018 &offError, RTErrInfoInitStatic(&ErrInfo));
3019 if (RT_FAILURE(rc))
3020 return rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainOpenFile", pszFileSpec, rc, offError, &ErrInfo.Core);
3021
3022 uint64_t cbFile = 0;
3023 rc = RTVfsFileGetSize(hVfsFile, &cbFile);
3024 if (RT_SUCCESS(rc))
3025 {
3026 if (cbFile < _2M)
3027 {
3028 char *pszContent = (char *)RTMemTmpAllocZ((size_t)cbFile + 1);
3029 if (pszContent)
3030 {
3031 rc = RTVfsFileRead(hVfsFile, pszContent, (size_t)cbFile, NULL);
3032 if (RT_SUCCESS(rc))
3033 {
3034 /*
3035 * Check that it's valid UTF-8 and turn it into an argument vector.
3036 */
3037 rc = RTStrValidateEncodingEx(pszContent, (size_t)cbFile + 1,
3038 RTSTR_VALIDATE_ENCODING_EXACT_LENGTH | RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED);
3039 if (RT_SUCCESS(rc))
3040 {
3041 uint32_t fGetOpt = strstr(pszContent, "--iprt-iso-maker-file-marker-ms") == NULL
3042 ? RTGETOPTARGV_CNV_QUOTE_BOURNE_SH : RTGETOPTARGV_CNV_QUOTE_MS_CRT;
3043 fGetOpt |= RTGETOPTARGV_CNV_MODIFY_INPUT;
3044 char **papszArgs;
3045 int cArgs;
3046 rc = RTGetOptArgvFromString(&papszArgs, &cArgs, pszContent, fGetOpt, NULL);
3047 if (RT_SUCCESS(rc))
3048 {
3049 /*
3050 * Parse them.
3051 */
3052 rc = rtFsIsoMakerCmdParse(pOpts, cArgs, papszArgs, cDepth + 1);
3053
3054 RTGetOptArgvFreeEx(papszArgs, fGetOpt);
3055 }
3056 else
3057 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "%s: RTGetOptArgvFromString failed: %Rrc", pszFileSpec, rc);
3058
3059 }
3060 else
3061 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "%s: invalid encoding", pszFileSpec);
3062 }
3063 else
3064 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "%s: error to read it into memory: %Rrc", pszFileSpec, rc);
3065 RTMemTmpFree(pszContent);
3066 }
3067 else
3068 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_NO_TMP_MEMORY, "%s: failed to allocte %zu bytes for reading",
3069 pszFileSpec, (size_t)cbFile + 1);
3070 }
3071 else
3072 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_FILE_TOO_BIG, "%s: file is too big: %'RU64 bytes, max 2MB", pszFileSpec, cbFile);
3073 }
3074 else
3075 rtFsIsoMakerCmdErrorRc(pOpts, rc, "%s: RTVfsFileGetSize failed: %Rrc", pszFileSpec, rc);
3076 RTVfsFileRelease(hVfsFile);
3077 return rc;
3078}
3079
3080
3081/**
3082 * Parses the given command line options.
3083 *
3084 * @returns IPRT status code.
3085 * @retval VINF_CALLBACK_RETURN if exit successfully (help, version).
3086 * @param pOpts The ISO maker command instance.
3087 * @param cArgs Number of arguments in papszArgs.
3088 * @param papszArgs The argument vector to parse.
3089 */
3090static int rtFsIsoMakerCmdParse(PRTFSISOMAKERCMDOPTS pOpts, unsigned cArgs, char **papszArgs, unsigned cDepth)
3091{
3092 /* Setup option parsing. */
3093 RTGETOPTSTATE GetState;
3094 int rc = RTGetOptInit(&GetState, cArgs, papszArgs, g_aRtFsIsoMakerOptions, RT_ELEMENTS(g_aRtFsIsoMakerOptions),
3095 cDepth == 0 ? 1 : 0 /*iFirst*/, 0 /*fFlags*/);
3096 if (RT_FAILURE(rc))
3097 return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTGetOpt failed: %Rrc", rc);
3098
3099 /*
3100 * Parse parameters. Parameters are position dependent.
3101 */
3102 RTGETOPTUNION ValueUnion;
3103 while ( RT_SUCCESS(rc)
3104 && (rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
3105 {
3106 switch (rc)
3107 {
3108 /*
3109 * Files and directories.
3110 */
3111 case VINF_GETOPT_NOT_OPTION:
3112 if ( *ValueUnion.psz != '@'
3113 || strchr(ValueUnion.psz, '='))
3114 rc = rtFsIsoMakerCmdAddSomething(pOpts, ValueUnion.psz);
3115 else
3116 rc = rtFsIsoMakerCmdParseArgumentFile(pOpts, ValueUnion.psz + 1, cDepth);
3117 break;
3118
3119
3120 /*
3121 * General options
3122 */
3123 case 'o':
3124 if (pOpts->fVirtualImageMaker)
3125 return rtFsIsoMakerCmdSyntaxError(pOpts, "The --output option is not allowed");
3126 if (pOpts->pszOutFile)
3127 return rtFsIsoMakerCmdSyntaxError(pOpts, "The --output option is specified more than once");
3128 pOpts->pszOutFile = ValueUnion.psz;
3129 break;
3130
3131 case RTFSISOMAKERCMD_OPT_NAME_SETUP:
3132 rc = rtFsIsoMakerCmdOptNameSetup(pOpts, ValueUnion.psz);
3133 break;
3134
3135 case RTFSISOMAKERCMD_OPT_PUSH_ISO:
3136 rc = rtFsIsoMakerCmdOptPushIso(pOpts, ValueUnion.psz, "--push-iso", 0);
3137 break;
3138
3139 case RTFSISOMAKERCMD_OPT_PUSH_ISO_NO_JOLIET:
3140 rc = rtFsIsoMakerCmdOptPushIso(pOpts, ValueUnion.psz, "--push-iso-no-joliet", RTFSISO9660_F_NO_JOLIET);
3141 break;
3142
3143 case RTFSISOMAKERCMD_OPT_PUSH_ISO_NO_ROCK:
3144 rc = rtFsIsoMakerCmdOptPushIso(pOpts, ValueUnion.psz, "--push-iso-no-rock", RTFSISO9660_F_NO_ROCK);
3145 break;
3146
3147 case RTFSISOMAKERCMD_OPT_PUSH_ISO_NO_ROCK_NO_JOLIET:
3148 rc = rtFsIsoMakerCmdOptPushIso(pOpts, ValueUnion.psz, "--push-iso-no-rock-no-joliet",
3149 RTFSISO9660_F_NO_ROCK | RTFSISO9660_F_NO_JOLIET);
3150 break;
3151
3152 case RTFSISOMAKERCMD_OPT_POP:
3153 rc = rtFsIsoMakerCmdOptPop(pOpts);
3154 break;
3155
3156 case RTFSISOMAKERCMD_OPT_IMPORT_ISO:
3157 rc = rtFsIsoMakerCmdOptImportIso(pOpts, ValueUnion.psz);
3158 break;
3159
3160
3161 /*
3162 * Namespace configuration.
3163 */
3164 case RTFSISOMAKERCMD_OPT_ISO_LEVEL:
3165 rc = rtFsIsoMakerCmdOptSetIsoLevel(pOpts, ValueUnion.u8);
3166 break;
3167
3168 case RTFSISOMAKERCMD_OPT_ROCK_RIDGE:
3169 rc = rtFsIsoMakerCmdOptSetPrimaryRockLevel(pOpts, 2);
3170 break;
3171
3172 case RTFSISOMAKERCMD_OPT_LIMITED_ROCK_RIDGE:
3173 rc = rtFsIsoMakerCmdOptSetPrimaryRockLevel(pOpts, 1);
3174 break;
3175
3176 case RTFSISOMAKERCMD_OPT_NO_ROCK_RIDGE:
3177 rc = rtFsIsoMakerCmdOptSetPrimaryRockLevel(pOpts, 0);
3178 break;
3179
3180 case 'J':
3181 rc = rtFsIsoMakerCmdOptSetJolietUcs2Level(pOpts, 3);
3182 break;
3183
3184 case RTFSISOMAKERCMD_OPT_NO_JOLIET:
3185 rc = rtFsIsoMakerCmdOptSetJolietUcs2Level(pOpts, 0);
3186 break;
3187
3188 case RTFSISOMAKERCMD_OPT_JOLIET_LEVEL:
3189 rc = rtFsIsoMakerCmdOptSetJolietUcs2Level(pOpts, ValueUnion.u8);
3190 break;
3191
3192
3193 /*
3194 * File attributes.
3195 */
3196 case RTFSISOMAKERCMD_OPT_RATIONAL_ATTRIBS:
3197 rc = rtFsIsoMakerCmdOptSetAttribInheritStyle(pOpts, false /*fStrict*/);
3198 break;
3199
3200 case RTFSISOMAKERCMD_OPT_STRICT_ATTRIBS:
3201 rc = rtFsIsoMakerCmdOptSetAttribInheritStyle(pOpts, true /*fStrict*/);
3202 break;
3203
3204 case RTFSISOMAKERCMD_OPT_FILE_MODE:
3205 rc = rtFsIsoMakerCmdOptSetFileOrDirMode(pOpts, false /*fDir*/, ValueUnion.u32);
3206 break;
3207
3208 case RTFSISOMAKERCMD_OPT_NO_FILE_MODE:
3209 rc = rtFsIsoMakerCmdOptDisableFileOrDirMode(pOpts, false /*fDir*/);
3210 break;
3211
3212 case RTFSISOMAKERCMD_OPT_DIR_MODE:
3213 rc = rtFsIsoMakerCmdOptSetFileOrDirMode(pOpts, true /*fDir*/, ValueUnion.u32);
3214 break;
3215
3216 case RTFSISOMAKERCMD_OPT_NO_DIR_MODE:
3217 rc = rtFsIsoMakerCmdOptDisableFileOrDirMode(pOpts, true /*fDir*/);
3218 break;
3219
3220 case RTFSISOMAKERCMD_OPT_NEW_DIR_MODE:
3221 rc = rtFsIsoMakerCmdOptSetNewDirMode(pOpts, ValueUnion.u32);
3222 break;
3223
3224 case RTFSISOMAKERCMD_OPT_CHMOD:
3225 rc = rtFsIsoMakerCmdOptChmod(pOpts, ValueUnion.psz);
3226 break;
3227
3228 case RTFSISOMAKERCMD_OPT_CHOWN:
3229 rc = rtFsIsoMakerCmdOptChangeOwnerGroup(pOpts, ValueUnion.psz, true /*fIsChOwn*/);
3230 break;
3231
3232 case RTFSISOMAKERCMD_OPT_CHGRP:
3233 rc = rtFsIsoMakerCmdOptChangeOwnerGroup(pOpts, ValueUnion.psz, false /*fIsChOwn*/);
3234 break;
3235
3236
3237 /*
3238 * Boot related options.
3239 */
3240 case 'G': /* --generic-boot <file> */
3241 rc = rtFsIsoMakerCmdOptGenericBoot(pOpts, ValueUnion.psz);
3242 break;
3243
3244 case RTFSISOMAKERCMD_OPT_ELTORITO_ADD_IMAGE:
3245 rc = rtFsIsoMakerCmdOptEltoritoAddImage(pOpts, ValueUnion.psz);
3246 break;
3247
3248 case 'b': /* --eltorito-boot <boot.img> */
3249 rc = rtFsIsoMakerCmdOptEltoritoBoot(pOpts, ValueUnion.psz);
3250 break;
3251
3252 case RTFSISOMAKERCMD_OPT_ELTORITO_NEW_ENTRY:
3253 rc = rtFsIsoMakerCmdOptEltoritoNewEntry(pOpts);
3254 break;
3255
3256 case RTFSISOMAKERCMD_OPT_ELTORITO_PLATFORM_ID:
3257 rc = rtFsIsoMakerCmdOptEltoritoPlatformId(pOpts, ValueUnion.psz);
3258 break;
3259
3260 case RTFSISOMAKERCMD_OPT_ELTORITO_NO_BOOT:
3261 rc = rtFsIsoMakerCmdOptEltoritoSetNotBootable(pOpts);
3262 break;
3263
3264 case RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_12:
3265 rc = rtFsIsoMakerCmdOptEltoritoSetMediaType(pOpts, ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_1_2_MB);
3266 break;
3267 case RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_144:
3268 rc = rtFsIsoMakerCmdOptEltoritoSetMediaType(pOpts, ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_1_44_MB);
3269 break;
3270 case RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_288:
3271 rc = rtFsIsoMakerCmdOptEltoritoSetMediaType(pOpts, ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_2_88_MB);
3272 break;
3273 case RTFSISOMAKERCMD_OPT_ELTORITO_HARD_DISK_BOOT:
3274 rc = rtFsIsoMakerCmdOptEltoritoSetMediaType(pOpts, ISO9660_ELTORITO_BOOT_MEDIA_TYPE_HARD_DISK);
3275 break;
3276 case RTFSISOMAKERCMD_OPT_ELTORITO_NO_EMULATION_BOOT:
3277 rc = rtFsIsoMakerCmdOptEltoritoSetMediaType(pOpts, ISO9660_ELTORITO_BOOT_MEDIA_TYPE_NO_EMULATION);
3278 break;
3279
3280 case RTFSISOMAKERCMD_OPT_ELTORITO_LOAD_SEG:
3281 rc = rtFsIsoMakerCmdOptEltoritoSetLoadSegment(pOpts, ValueUnion.u16);
3282 break;
3283
3284 case RTFSISOMAKERCMD_OPT_ELTORITO_LOAD_SIZE:
3285 rc = rtFsIsoMakerCmdOptEltoritoSetLoadSectorCount(pOpts, ValueUnion.u16);
3286 break;
3287
3288 case RTFSISOMAKERCMD_OPT_ELTORITO_INFO_TABLE:
3289 rc = rtFsIsoMakerCmdOptEltoritoEnableBootInfoTablePatching(pOpts);
3290 break;
3291
3292 case 'c': /* --boot-catalog <cd-path> */
3293 rc = rtFsIsoMakerCmdOptEltoritoSetBootCatalogPath(pOpts, ValueUnion.psz);
3294 break;
3295
3296
3297 /*
3298 * Image/namespace property related options.
3299 */
3300 case RTFSISOMAKERCMD_OPT_ABSTRACT_FILE_ID:
3301 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_ABSTRACT_FILE_ID);
3302 break;
3303
3304 case 'A': /* --application-id */
3305 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_APPLICATION_ID);
3306 break;
3307
3308 case RTFSISOMAKERCMD_OPT_BIBLIOGRAPHIC_FILE_ID:
3309 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_BIBLIOGRAPHIC_FILE_ID);
3310 break;
3311
3312 case RTFSISOMAKERCMD_OPT_COPYRIGHT_FILE_ID:
3313 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_COPYRIGHT_FILE_ID);
3314 break;
3315
3316 case 'P': /* -publisher */
3317 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_PUBLISHER_ID);
3318 break;
3319
3320 case 'p': /* --preparer*/
3321 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_DATA_PREPARER_ID);
3322 break;
3323
3324 case RTFSISOMAKERCMD_OPT_SYSTEM_ID:
3325 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_SYSTEM_ID);
3326 break;
3327
3328 case RTFSISOMAKERCMD_OPT_VOLUME_ID: /* (should've been '-V') */
3329 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_VOLUME_ID);
3330 break;
3331
3332 case RTFSISOMAKERCMD_OPT_VOLUME_SET_ID:
3333 rc = rtFsIsoMakerCmdOptSetStringProp(pOpts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_VOLUME_SET_ID);
3334 break;
3335
3336
3337 /*
3338 * Compatibility.
3339 */
3340 case RTFSISOMAKERCMD_OPT_GRAFT_POINTS:
3341 rc = rtFsIsoMakerCmdOptNameSetup(pOpts, "iso+joliet+udf+hfs");
3342 break;
3343
3344 case 'l':
3345 if (RTFsIsoMakerGetIso9660Level(pOpts->hIsoMaker) >= 2)
3346 rc = rtFsIsoMakerCmdOptSetIsoLevel(pOpts, 2);
3347 break;
3348
3349 case 'R':
3350 rc = rtFsIsoMakerCmdOptSetPrimaryRockLevel(pOpts, 2);
3351 if (RT_SUCCESS(rc))
3352 rc = rtFsIsoMakerCmdOptSetAttribInheritStyle(pOpts, true /*fStrict*/);
3353 break;
3354
3355 case 'r':
3356 rc = rtFsIsoMakerCmdOptSetPrimaryRockLevel(pOpts, 2);
3357 if (RT_SUCCESS(rc))
3358 rc = rtFsIsoMakerCmdOptSetAttribInheritStyle(pOpts, false /*fStrict*/);
3359 break;
3360
3361 case RTFSISOMAKERCMD_OPT_PAD:
3362 rc = RTFsIsoMakerSetImagePadding(pOpts->hIsoMaker, 150);
3363 if (RT_FAILURE(rc))
3364 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerSetImagePadding failed: %Rrc", rc);
3365 break;
3366
3367 case RTFSISOMAKERCMD_OPT_NO_PAD:
3368 rc = RTFsIsoMakerSetImagePadding(pOpts->hIsoMaker, 0);
3369 if (RT_FAILURE(rc))
3370 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerSetImagePadding failed: %Rrc", rc);
3371 break;
3372
3373
3374 /*
3375 * VISO specific
3376 */
3377 case RTFSISOMAKERCMD_OPT_IPRT_ISO_MAKER_FILE_MARKER:
3378 /* ignored */
3379 break;
3380
3381
3382 /*
3383 * Testing.
3384 */
3385 case RTFSISOMAKERCMD_OPT_OUTPUT_BUFFER_SIZE: /* --output-buffer-size {cb} */
3386 pOpts->cbOutputReadBuffer = ValueUnion.u32;
3387 break;
3388
3389 case RTFSISOMAKERCMD_OPT_RANDOM_OUTPUT_BUFFER_SIZE: /* --random-output-buffer-size */
3390 pOpts->fRandomOutputReadBufferSize = true;
3391 break;
3392
3393 case RTFSISOMAKERCMD_OPT_RANDOM_ORDER_VERIFICATION: /* --random-order-verification {cb} */
3394 pOpts->cbRandomOrderVerifciationBlock = ValueUnion.u32;
3395 break;
3396
3397
3398 /*
3399 * Standard bits.
3400 */
3401 case 'h':
3402 rtFsIsoMakerCmdUsage(pOpts, papszArgs[0]);
3403 return pOpts->fVirtualImageMaker ? VERR_NOT_FOUND : VINF_CALLBACK_RETURN;
3404
3405 case 'V':
3406 rtFsIsoMakerPrintf(pOpts, "%sr%d\n", RTBldCfgVersion(), RTBldCfgRevision());
3407 return pOpts->fVirtualImageMaker ? VERR_NOT_FOUND : VINF_CALLBACK_RETURN;
3408
3409 default:
3410 if (rc > 0 && RT_C_IS_GRAPH(rc))
3411 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_GETOPT_UNKNOWN_OPTION, "Unhandled option: -%c", rc);
3412 else if (rc > 0)
3413 rc = rtFsIsoMakerCmdErrorRc(pOpts, VERR_GETOPT_UNKNOWN_OPTION, "Unhandled option: %i (%#x)", rc, rc);
3414 else if (rc == VERR_GETOPT_UNKNOWN_OPTION)
3415 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Unknown option: '%s'", ValueUnion.psz);
3416 else if (ValueUnion.pDef)
3417 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "%s: %Rrs", ValueUnion.pDef->pszLong, rc);
3418 else
3419 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "%Rrs", rc);
3420 return rc;
3421 }
3422 if (RT_FAILURE(rc))
3423 return rc;
3424 }
3425 return VINF_SUCCESS;
3426}
3427
3428
3429/**
3430 * Extended ISO maker command.
3431 *
3432 * This can be used as a ISO maker command that produces a image file, or
3433 * alternatively for setting up a virtual ISO in memory.
3434 *
3435 * @returns IPRT status code
3436 * @param cArgs Number of arguments.
3437 * @param papszArgs Pointer to argument array.
3438 * @param hVfsCwd The current working directory to assume when processing
3439 * relative file/dir references. Pass NIL_RTVFSDIR to use
3440 * the current CWD of the process.
3441 * @param pszCwd Path to @a hVfsCwdDir. Use for error reporting and
3442 * optimizing the open file count if possible.
3443 * @param phVfsFile Where to return the virtual ISO. Pass NULL to for
3444 * normal operation (creates file on disk).
3445 * @param pErrInfo Where to return extended error information in the
3446 * virtual ISO mode.
3447 */
3448RTDECL(int) RTFsIsoMakerCmdEx(unsigned cArgs, char **papszArgs, RTVFSDIR hVfsCwd, const char *pszCwd,
3449 PRTVFSFILE phVfsFile, PRTERRINFO pErrInfo)
3450{
3451 if (phVfsFile)
3452 *phVfsFile = NIL_RTVFSFILE;
3453
3454 /*
3455 * Create instance.
3456 */
3457 RTFSISOMAKERCMDOPTS Opts;
3458 RT_ZERO(Opts);
3459 Opts.hIsoMaker = NIL_RTFSISOMAKER;
3460 Opts.pErrInfo = pErrInfo;
3461 Opts.fVirtualImageMaker = phVfsFile != NULL;
3462 Opts.cNameSpecifiers = 1;
3463 Opts.afNameSpecifiers[0] = RTFSISOMAKERCMDNAME_MAJOR_MASK;
3464 Opts.fDstNamespaces = RTFSISOMAKERCMDNAME_MAJOR_MASK;
3465 Opts.pszTransTbl = "TRANS.TBL"; /** @todo query this below */
3466 for (uint32_t i = 0; i < RT_ELEMENTS(Opts.aBootCatEntries); i++)
3467 Opts.aBootCatEntries[i].u.Section.idxImageObj = UINT32_MAX;
3468
3469 /* Initialize the source stack with NILs (to be on the safe size). */
3470 Opts.iSrcStack = -1;
3471 for (uint32_t i = 0; i < RT_ELEMENTS(Opts.aSrcStack); i++)
3472 {
3473 Opts.aSrcStack[i].hSrcDir = NIL_RTVFSDIR;
3474 Opts.aSrcStack[i].hSrcVfs = NIL_RTVFS;
3475 }
3476
3477 /* Push the CWD if present. */
3478 if (hVfsCwd != NIL_RTVFSDIR)
3479 {
3480 AssertReturn(pszCwd, VERR_INVALID_PARAMETER);
3481 uint32_t cRefs = RTVfsDirRetain(hVfsCwd);
3482 AssertReturn(cRefs != UINT32_MAX, VERR_INVALID_HANDLE);
3483
3484 Opts.aSrcStack[0].hSrcDir = hVfsCwd;
3485 Opts.aSrcStack[0].pszSrcVfs = pszCwd;
3486 Opts.iSrcStack = 0;
3487 }
3488
3489 /* Create the ISO creator instance. */
3490 int rc = RTFsIsoMakerCreate(&Opts.hIsoMaker);
3491 if (RT_SUCCESS(rc))
3492 {
3493 /*
3494 * Parse the command line and check for mandatory options.
3495 */
3496 rc = rtFsIsoMakerCmdParse(&Opts, cArgs, papszArgs, 0);
3497 if (RT_SUCCESS(rc) && rc != VINF_CALLBACK_RETURN)
3498 {
3499 if (!Opts.cItemsAdded)
3500 rc = rtFsIsoMakerCmdErrorRc(&Opts, VERR_NO_DATA, "Cowardly refuses to create empty ISO image");
3501 else if (!Opts.pszOutFile && !Opts.fVirtualImageMaker)
3502 rc = rtFsIsoMakerCmdErrorRc(&Opts, VERR_INVALID_PARAMETER, "No output file specified (--output <file>)");
3503
3504 /*
3505 * Final actions.
3506 */
3507 if (RT_SUCCESS(rc))
3508 rc = rtFsIsoMakerCmdOptEltoritoCommitBootCatalog(&Opts);
3509 if (RT_SUCCESS(rc))
3510 {
3511 /*
3512 * Finalize the image and get the virtual file.
3513 */
3514 rc = RTFsIsoMakerFinalize(Opts.hIsoMaker);
3515 if (RT_SUCCESS(rc))
3516 {
3517 RTVFSFILE hVfsFile;
3518 rc = RTFsIsoMakerCreateVfsOutputFile(Opts.hIsoMaker, &hVfsFile);
3519 if (RT_SUCCESS(rc))
3520 {
3521 /*
3522 * We're done now if we're only setting up a virtual image.
3523 */
3524 if (Opts.fVirtualImageMaker)
3525 *phVfsFile = hVfsFile;
3526 else
3527 {
3528 rc = rtFsIsoMakerCmdWriteImage(&Opts, hVfsFile);
3529 RTVfsFileRelease(hVfsFile);
3530 }
3531 }
3532 else
3533 rc = rtFsIsoMakerCmdErrorRc(&Opts, rc, "RTFsIsoMakerCreateVfsOutputFile failed: %Rrc", rc);
3534 }
3535 else
3536 rc = rtFsIsoMakerCmdErrorRc(&Opts, rc, "RTFsIsoMakerFinalize failed: %Rrc", rc);
3537 }
3538 }
3539 }
3540 else
3541 {
3542 rc = rtFsIsoMakerCmdErrorRc(&Opts, rc, "RTFsIsoMakerCreate failed: %Rrc", rc);
3543 Opts.hIsoMaker = NIL_RTFSISOMAKER;
3544 }
3545
3546 return rtFsIsoMakerCmdDeleteState(&Opts, rc);
3547}
3548
3549
3550/**
3551 * ISO maker command (creates image file on disk).
3552 *
3553 * @returns IPRT status code
3554 * @param cArgs Number of arguments.
3555 * @param papszArgs Pointer to argument array.
3556 */
3557RTDECL(RTEXITCODE) RTFsIsoMakerCmd(unsigned cArgs, char **papszArgs)
3558{
3559 int rc = RTFsIsoMakerCmdEx(cArgs, papszArgs, NIL_RTVFSDIR, NULL, NULL, NULL);
3560 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
3561}
3562
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