VirtualBox

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

Last change on this file since 68817 was 68817, checked in by vboxsync, 8 years ago

IPRT/isomaker: Added default 16 sector image padding (allegedly a workaround for various read ahead bugs) and a bunch of other things.

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

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