1 | /* $Id: isomakercmd.cpp 67549 2017-06-21 23:45:48Z 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/assert.h>
|
---|
36 | #include <iprt/buildconfig.h>
|
---|
37 | #include <iprt/ctype.h>
|
---|
38 | #include <iprt/file.h>
|
---|
39 | #include <iprt/err.h>
|
---|
40 | #include <iprt/getopt.h>
|
---|
41 | #include <iprt/log.h>
|
---|
42 | #include <iprt/mem.h>
|
---|
43 | #include <iprt/message.h>
|
---|
44 | #include <iprt/path.h>
|
---|
45 | #include <iprt/rand.h>
|
---|
46 | #include <iprt/stream.h>
|
---|
47 | #include <iprt/string.h>
|
---|
48 | #include <iprt/vfs.h>
|
---|
49 | #include <iprt/formats/iso9660.h>
|
---|
50 |
|
---|
51 |
|
---|
52 | /*********************************************************************************************************************************
|
---|
53 | * Defined Constants And Macros *
|
---|
54 | *********************************************************************************************************************************/
|
---|
55 | /** Maximum number of name specifiers we allow. */
|
---|
56 | #define RTFSISOMAKERCMD_MAX_NAMES 8
|
---|
57 |
|
---|
58 | /** @name Name specifiers
|
---|
59 | * @{ */
|
---|
60 | #define RTFSISOMAKERCMDNAME_PRIMARY_ISO RTFSISOMAKER_NAMESPACE_ISO_9660
|
---|
61 | #define RTFSISOMAKERCMDNAME_JOLIET RTFSISOMAKER_NAMESPACE_JOLIET
|
---|
62 | #define RTFSISOMAKERCMDNAME_UDF RTFSISOMAKER_NAMESPACE_UDF
|
---|
63 | #define RTFSISOMAKERCMDNAME_HFS RTFSISOMAKER_NAMESPACE_HFS
|
---|
64 |
|
---|
65 | #define RTFSISOMAKERCMDNAME_PRIMARY_ISO_ROCK_RIDGE RT_BIT_32(16)
|
---|
66 | #define RTFSISOMAKERCMDNAME_JOLIET_ROCK_RIDGE RT_BIT_32(17)
|
---|
67 |
|
---|
68 | #define RTFSISOMAKERCMDNAME_JOLIET_TRANS_TBL RT_BIT_32(20)
|
---|
69 | #define RTFSISOMAKERCMDNAME_PRIMARY_ISO_TRANS_TBL RT_BIT_32(21)
|
---|
70 | #define RTFSISOMAKERCMDNAME_UDF_TRANS_TBL RT_BIT_32(22)
|
---|
71 | #define RTFSISOMAKERCMDNAME_HFS_TRANS_TBL RT_BIT_32(23)
|
---|
72 |
|
---|
73 | #define RTFSISOMAKERCMDNAME_MAJOR_MASK \
|
---|
74 | (RTFSISOMAKERCMDNAME_PRIMARY_ISO | RTFSISOMAKERCMDNAME_JOLIET | RTFSISOMAKERCMDNAME_UDF | RTFSISOMAKERCMDNAME_HFS)
|
---|
75 |
|
---|
76 | #define RTFSISOMAKERCMDNAME_MINOR_MASK \
|
---|
77 | ( RTFSISOMAKERCMDNAME_PRIMARY_ISO_ROCK_RIDGE | RTFSISOMAKERCMDNAME_PRIMARY_ISO_TRANS_TBL \
|
---|
78 | | RTFSISOMAKERCMDNAME_JOLIET_ROCK_RIDGE | RTFSISOMAKERCMDNAME_JOLIET_TRANS_TBL \
|
---|
79 | | RTFSISOMAKERCMDNAME_UDF_TRANS_TBL \
|
---|
80 | | RTFSISOMAKERCMDNAME_HFS_TRANS_TBL)
|
---|
81 | AssertCompile((RTFSISOMAKERCMDNAME_MAJOR_MASK & RTFSISOMAKERCMDNAME_MINOR_MASK) == 0);
|
---|
82 | /** @} */
|
---|
83 |
|
---|
84 |
|
---|
85 | /*********************************************************************************************************************************
|
---|
86 | * Structures and Typedefs *
|
---|
87 | *********************************************************************************************************************************/
|
---|
88 | typedef enum RTFSISOMAKERCMDOPT
|
---|
89 | {
|
---|
90 | RTFSISOMAKERCMD_OPT_FIRST = 1000,
|
---|
91 |
|
---|
92 | RTFSISOMAKERCMD_OPT_IPRT_ISO_MAKER_FILE_MARKER,
|
---|
93 | RTFSISOMAKERCMD_OPT_OUTPUT_BUFFER_SIZE,
|
---|
94 | RTFSISOMAKERCMD_OPT_RANDOM_OUTPUT_BUFFER_SIZE,
|
---|
95 | RTFSISOMAKERCMD_OPT_NAME_SETUP,
|
---|
96 | RTFSISOMAKERCMD_OPT_NO_JOLIET,
|
---|
97 | RTFSISOMAKERCMD_OPT_IMPORT_ISO,
|
---|
98 |
|
---|
99 | RTFSISOMAKERCMD_OPT_ELTORITO_NEW_ENTRY,
|
---|
100 | RTFSISOMAKERCMD_OPT_ELTORITO_ADD_IMAGE,
|
---|
101 | RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_12,
|
---|
102 | RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_144,
|
---|
103 | RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_288,
|
---|
104 |
|
---|
105 | /*
|
---|
106 | * Compatibility options:
|
---|
107 | */
|
---|
108 | RTFSISOMAKERCMD_OPT_ABSTRACT_FILE_ID,
|
---|
109 | RTFSISOMAKERCMD_OPT_ALLOW_LEADING_DOTS,
|
---|
110 | RTFSISOMAKERCMD_OPT_ALLOW_LIMITED_SIZE,
|
---|
111 | RTFSISOMAKERCMD_OPT_ALLOW_LOWERCASE,
|
---|
112 | RTFSISOMAKERCMD_OPT_ALLOW_MULTI_DOT,
|
---|
113 | RTFSISOMAKERCMD_OPT_ALPHA_BOOT,
|
---|
114 | RTFSISOMAKERCMD_OPT_APPLE,
|
---|
115 | RTFSISOMAKERCMD_OPT_BIBLIOGRAPHIC_FILE_ID,
|
---|
116 | RTFSISOMAKERCMD_OPT_CHECK_OLD_NAMES,
|
---|
117 | RTFSISOMAKERCMD_OPT_CHECK_SESSION,
|
---|
118 | RTFSISOMAKERCMD_OPT_COPYRIGHT_FILE_ID,
|
---|
119 | RTFSISOMAKERCMD_OPT_DETECT_HARDLINKS,
|
---|
120 | RTFSISOMAKERCMD_OPT_DIR_MODE,
|
---|
121 | RTFSISOMAKERCMD_OPT_DVD_VIDEO,
|
---|
122 | RTFSISOMAKERCMD_OPT_ELTORITO_PLATFORM_ID,
|
---|
123 | RTFSISOMAKERCMD_OPT_ELTORITO_HARD_DISK_BOOT,
|
---|
124 | RTFSISOMAKERCMD_OPT_ELTORITO_INFO_TABLE,
|
---|
125 | RTFSISOMAKERCMD_OPT_ELTORITO_LOAD_SEG,
|
---|
126 | RTFSISOMAKERCMD_OPT_ELTORITO_LOAD_SIZE,
|
---|
127 | RTFSISOMAKERCMD_OPT_ELTORITO_NO_BOOT,
|
---|
128 | RTFSISOMAKERCMD_OPT_ELTORITO_NO_EMULATION_BOOT,
|
---|
129 | RTFSISOMAKERCMD_OPT_EXCLUDE_LIST,
|
---|
130 | RTFSISOMAKERCMD_OPT_FILE_MODE,
|
---|
131 | RTFSISOMAKERCMD_OPT_FORCE_RR,
|
---|
132 | RTFSISOMAKERCMD_OPT_GID,
|
---|
133 | RTFSISOMAKERCMD_OPT_GRAFT_POINTS,
|
---|
134 | RTFSISOMAKERCMD_OPT_GUI,
|
---|
135 | RTFSISOMAKERCMD_OPT_HFS_AUTO,
|
---|
136 | RTFSISOMAKERCMD_OPT_HFS_BLESS,
|
---|
137 | RTFSISOMAKERCMD_OPT_HFS_BOOT_FILE,
|
---|
138 | RTFSISOMAKERCMD_OPT_HFS_CAP,
|
---|
139 | RTFSISOMAKERCMD_OPT_HFS_CHRP_BOOT,
|
---|
140 | RTFSISOMAKERCMD_OPT_HFS_CLUSTER_SIZE,
|
---|
141 | RTFSISOMAKERCMD_OPT_HFS_CREATOR,
|
---|
142 | RTFSISOMAKERCMD_OPT_HFS_DAVE,
|
---|
143 | RTFSISOMAKERCMD_OPT_HFS_DOUBLE,
|
---|
144 | RTFSISOMAKERCMD_OPT_HFS_ENABLE,
|
---|
145 | RTFSISOMAKERCMD_OPT_HFS_ETHERSHARE,
|
---|
146 | RTFSISOMAKERCMD_OPT_HFS_EXCHANGE,
|
---|
147 | RTFSISOMAKERCMD_OPT_HFS_HIDE,
|
---|
148 | RTFSISOMAKERCMD_OPT_HFS_HIDE_LIST,
|
---|
149 | RTFSISOMAKERCMD_OPT_HFS_ICON_POSITION,
|
---|
150 | RTFSISOMAKERCMD_OPT_HFS_INPUT_CHARSET,
|
---|
151 | RTFSISOMAKERCMD_OPT_HFS_MAC_NAME,
|
---|
152 | RTFSISOMAKERCMD_OPT_HFS_MACBIN,
|
---|
153 | RTFSISOMAKERCMD_OPT_HFS_MAGIC,
|
---|
154 | RTFSISOMAKERCMD_OPT_HFS_MAP,
|
---|
155 | RTFSISOMAKERCMD_OPT_HFS_NETATALK,
|
---|
156 | RTFSISOMAKERCMD_OPT_HFS_NO_DESKTOP,
|
---|
157 | RTFSISOMAKERCMD_OPT_HFS_OSX_DOUBLE,
|
---|
158 | RTFSISOMAKERCMD_OPT_HFS_OSX_HFS,
|
---|
159 | RTFSISOMAKERCMD_OPT_HFS_OUTPUT_CHARSET,
|
---|
160 | RTFSISOMAKERCMD_OPT_HFS_PARMS,
|
---|
161 | RTFSISOMAKERCMD_OPT_HFS_PART,
|
---|
162 | RTFSISOMAKERCMD_OPT_HFS_PREP_BOOT,
|
---|
163 | RTFSISOMAKERCMD_OPT_HFS_PROBE,
|
---|
164 | RTFSISOMAKERCMD_OPT_HFS_ROOT_INFO,
|
---|
165 | RTFSISOMAKERCMD_OPT_HFS_SFM,
|
---|
166 | RTFSISOMAKERCMD_OPT_HFS_SGI,
|
---|
167 | RTFSISOMAKERCMD_OPT_HFS_SINGLE,
|
---|
168 | RTFSISOMAKERCMD_OPT_HFS_TYPE,
|
---|
169 | RTFSISOMAKERCMD_OPT_HFS_UNLOCK,
|
---|
170 | RTFSISOMAKERCMD_OPT_HFS_USHARE,
|
---|
171 | RTFSISOMAKERCMD_OPT_HFS_VOL_ID,
|
---|
172 | RTFSISOMAKERCMD_OPT_HFS_XINET,
|
---|
173 | RTFSISOMAKERCMD_OPT_HIDDEN,
|
---|
174 | RTFSISOMAKERCMD_OPT_HIDDEN_LIST,
|
---|
175 | RTFSISOMAKERCMD_OPT_HIDE,
|
---|
176 | RTFSISOMAKERCMD_OPT_HIDE_JOLIET,
|
---|
177 | RTFSISOMAKERCMD_OPT_HIDE_JOLIET_LIST,
|
---|
178 | RTFSISOMAKERCMD_OPT_HIDE_JOLIET_TRANS_TBL,
|
---|
179 | RTFSISOMAKERCMD_OPT_HIDE_LIST,
|
---|
180 | RTFSISOMAKERCMD_OPT_HIDE_RR_MOVED,
|
---|
181 | RTFSISOMAKERCMD_OPT_HPPA_BOOTLOADER,
|
---|
182 | RTFSISOMAKERCMD_OPT_HPPA_CMDLINE,
|
---|
183 | RTFSISOMAKERCMD_OPT_HPPA_KERNEL_32,
|
---|
184 | RTFSISOMAKERCMD_OPT_HPPA_KERNEL_64,
|
---|
185 | RTFSISOMAKERCMD_OPT_HPPA_RAMDISK,
|
---|
186 | RTFSISOMAKERCMD_OPT_INPUT_CHARSET,
|
---|
187 | RTFSISOMAKERCMD_OPT_ISO_LEVEL,
|
---|
188 | RTFSISOMAKERCMD_OPT_JIGDO_COMPRESS,
|
---|
189 | RTFSISOMAKERCMD_OPT_JIGDO_EXCLUDE,
|
---|
190 | RTFSISOMAKERCMD_OPT_JIGDO_FORCE_MD5,
|
---|
191 | RTFSISOMAKERCMD_OPT_JIGDO_JIGDO,
|
---|
192 | RTFSISOMAKERCMD_OPT_JIGDO_MAP,
|
---|
193 | RTFSISOMAKERCMD_OPT_JIGDO_MD5_LIST,
|
---|
194 | RTFSISOMAKERCMD_OPT_JIGDO_MIN_FILE_SIZE,
|
---|
195 | RTFSISOMAKERCMD_OPT_JIGDO_TEMPLATE,
|
---|
196 | RTFSISOMAKERCMD_OPT_JOLIET_CHARSET,
|
---|
197 | RTFSISOMAKERCMD_OPT_JOLIET_LEVEL,
|
---|
198 | RTFSISOMAKERCMD_OPT_JOLIET_LONG,
|
---|
199 | RTFSISOMAKERCMD_OPT_LOG_FILE,
|
---|
200 | RTFSISOMAKERCMD_OPT_MAX_ISO9660_FILENAMES,
|
---|
201 | RTFSISOMAKERCMD_OPT_MIPS_BOOT,
|
---|
202 | RTFSISOMAKERCMD_OPT_MIPSEL_BOOT,
|
---|
203 | RTFSISOMAKERCMD_OPT_NEW_DIR_MODE,
|
---|
204 | RTFSISOMAKERCMD_OPT_NO_BACKUP_FILES,
|
---|
205 | RTFSISOMAKERCMD_OPT_NO_DETECT_HARDLINKS,
|
---|
206 | RTFSISOMAKERCMD_OPT_NO_ISO_TRANSLATE,
|
---|
207 | RTFSISOMAKERCMD_OPT_NO_PAD,
|
---|
208 | RTFSISOMAKERCMD_OPT_NO_RR,
|
---|
209 | RTFSISOMAKERCMD_OPT_NO_SPLIT_SYMLINK_COMPONENTS,
|
---|
210 | RTFSISOMAKERCMD_OPT_NO_SPLIT_SYMLINK_FIELDS,
|
---|
211 | RTFSISOMAKERCMD_OPT_OLD_ROOT,
|
---|
212 | RTFSISOMAKERCMD_OPT_OUTPUT_CHARSET,
|
---|
213 | RTFSISOMAKERCMD_OPT_PAD,
|
---|
214 | RTFSISOMAKERCMD_OPT_PATH_LIST,
|
---|
215 | RTFSISOMAKERCMD_OPT_PRINT_SIZE,
|
---|
216 | RTFSISOMAKERCMD_OPT_QUIET,
|
---|
217 | RTFSISOMAKERCMD_OPT_RELAXED_FILENAMES,
|
---|
218 | RTFSISOMAKERCMD_OPT_ROOT,
|
---|
219 | RTFSISOMAKERCMD_OPT_SORT,
|
---|
220 | RTFSISOMAKERCMD_OPT_SPARC_BOOT,
|
---|
221 | RTFSISOMAKERCMD_OPT_SPARC_LABEL,
|
---|
222 | RTFSISOMAKERCMD_OPT_SPLIT_OUTPUT,
|
---|
223 | RTFSISOMAKERCMD_OPT_STREAM_FILE_NAME,
|
---|
224 | RTFSISOMAKERCMD_OPT_STREAM_MEDIA_SIZE,
|
---|
225 | RTFSISOMAKERCMD_OPT_SUNX86_BOOT,
|
---|
226 | RTFSISOMAKERCMD_OPT_SUNX86_LABEL,
|
---|
227 | RTFSISOMAKERCMD_OPT_SYSTEM_ID,
|
---|
228 | RTFSISOMAKERCMD_OPT_TRANS_TBL_NAME,
|
---|
229 | RTFSISOMAKERCMD_OPT_UDF,
|
---|
230 | RTFSISOMAKERCMD_OPT_UID,
|
---|
231 | RTFSISOMAKERCMD_OPT_USE_FILE_VERSION,
|
---|
232 | RTFSISOMAKERCMD_OPT_VOLUME_ID,
|
---|
233 | RTFSISOMAKERCMD_OPT_VOLUME_SET_ID,
|
---|
234 | RTFSISOMAKERCMD_OPT_VOLUME_SET_SEQ_NO,
|
---|
235 | RTFSISOMAKERCMD_OPT_VOLUME_SET_SIZE,
|
---|
236 | RTFSISOMAKERCMD_OPT_END
|
---|
237 | } RTFSISOMAKERCMDOPT;
|
---|
238 |
|
---|
239 |
|
---|
240 | /**
|
---|
241 | * El Torito boot entry.
|
---|
242 | */
|
---|
243 | typedef struct RTFSISOMKCMDELTORITOENTRY
|
---|
244 | {
|
---|
245 | /** The type of this entry. */
|
---|
246 | enum
|
---|
247 | {
|
---|
248 | kEntryType_Invalid = 0,
|
---|
249 | kEntryType_Validation, /**< Same as kEntryType_SectionHeader, just hardcoded #0. */
|
---|
250 | kEntryType_SectionHeader,
|
---|
251 | kEntryType_Default, /**< Same as kEntryType_Section, just hardcoded #1. */
|
---|
252 | kEntryType_Section
|
---|
253 | } enmType;
|
---|
254 | /** Type specific data. */
|
---|
255 | union
|
---|
256 | {
|
---|
257 | struct
|
---|
258 | {
|
---|
259 | /** The platform ID (ISO9660_ELTORITO_PLATFORM_ID_XXX). */
|
---|
260 | uint8_t idPlatform;
|
---|
261 | /** Some string for the header. */
|
---|
262 | const char *pszString;
|
---|
263 | } Validation,
|
---|
264 | SectionHeader;
|
---|
265 | struct
|
---|
266 | {
|
---|
267 | /** The name of the boot image wihtin the ISO (-b option). */
|
---|
268 | const char *pszImageNameInIso;
|
---|
269 | /** The object ID of the image in the ISO. This is set to UINT32_MAX when
|
---|
270 | * pszImageNameInIso is used (i.e. -b option) and we've delayed everything
|
---|
271 | * boot related till after all files have been added to the image. */
|
---|
272 | uint32_t idxImageObj;
|
---|
273 | /** Whether to insert boot info table into the image. */
|
---|
274 | bool fInsertBootInfoTable;
|
---|
275 | /** Bootble or not. Possible to make BIOS set up emulation w/o booting it. */
|
---|
276 | bool fBootable;
|
---|
277 | /** The media type (ISO9660_ELTORITO_BOOT_MEDIA_TYPE_XXX). */
|
---|
278 | uint8_t bBootMediaType;
|
---|
279 | /** File system / partition type. */
|
---|
280 | uint8_t bSystemType;
|
---|
281 | /** Load address divided by 0x10. */
|
---|
282 | uint16_t uLoadSeg;
|
---|
283 | /** Number of sectors (512) to load. */
|
---|
284 | uint16_t cSectorsToLoad;
|
---|
285 | } Section,
|
---|
286 | Default;
|
---|
287 | } u;
|
---|
288 | } RTFSISOMKCMDELTORITOENTRY;
|
---|
289 | /** Pointer to an el torito boot entry. */
|
---|
290 | typedef RTFSISOMKCMDELTORITOENTRY *PRTFSISOMKCMDELTORITOENTRY;
|
---|
291 |
|
---|
292 | /**
|
---|
293 | * ISO maker command options & state.
|
---|
294 | */
|
---|
295 | typedef struct RTFSISOMAKERCMDOPTS
|
---|
296 | {
|
---|
297 | /** The handle to the ISO maker. */
|
---|
298 | RTFSISOMAKER hIsoMaker;
|
---|
299 | /** Set if we're creating a virtual image maker, i.e. producing something
|
---|
300 | * that is going to be read from only and not written to disk. */
|
---|
301 | bool fVirtualImageMaker;
|
---|
302 | /** Extended error info. This is a stderr alternative for the
|
---|
303 | * fVirtualImageMaker case (stdout goes to LogRel). */
|
---|
304 | PRTERRINFO pErrInfo;
|
---|
305 |
|
---|
306 | /** The output file.
|
---|
307 | * This is NULL when fVirtualImageMaker is set. */
|
---|
308 | const char *pszOutFile;
|
---|
309 | /** Special buffer size to use for testing the ISO maker code reading. */
|
---|
310 | uint32_t cbOutputReadBuffer;
|
---|
311 | /** Use random output read buffer size. cbOutputReadBuffer works as maximum
|
---|
312 | * when this is enabled. */
|
---|
313 | bool fRandomOutputReadBufferSize;
|
---|
314 |
|
---|
315 | /** @name Processing of inputs
|
---|
316 | * @{ */
|
---|
317 | /** The namespaces (RTFSISOMAKER_NAMESPACE_XXX) we're currently adding
|
---|
318 | * input to. */
|
---|
319 | uint32_t fDstNamespaces;
|
---|
320 | /** The number of name specifiers we're currently operating with. */
|
---|
321 | uint32_t cNameSpecifiers;
|
---|
322 | /** Name specifier configurations.
|
---|
323 | * For instance given "name0=name1=name2=name3=source-file" we will add
|
---|
324 | * source-file to the image with name0 as the name in the namespace and
|
---|
325 | * sub-name specified by aNameSpecifiers[0], name1 in aNameSpecifiers[1],
|
---|
326 | * and so on. This allows exact control over which names a file will
|
---|
327 | * have in each namespace (primary-iso, joliet, udf, hfs) and sub-namespace
|
---|
328 | * (rock-ridge, trans.tbl).
|
---|
329 | */
|
---|
330 | uint32_t afNameSpecifiers[RTFSISOMAKERCMD_MAX_NAMES];
|
---|
331 | /** @} */
|
---|
332 |
|
---|
333 | /** @name Booting related options and state.
|
---|
334 | * @{ */
|
---|
335 | /** Number of boot catalog entries (aBootCatEntries). */
|
---|
336 | uint32_t cBootCatEntries;
|
---|
337 | /** Boot catalog entries. */
|
---|
338 | RTFSISOMKCMDELTORITOENTRY aBootCatEntries[64];
|
---|
339 | /** @} */
|
---|
340 |
|
---|
341 | /** Number of items (files, directories, images, whatever) we've added. */
|
---|
342 | uint32_t cItemsAdded;
|
---|
343 | } RTFSISOMAKERCMDOPTS;
|
---|
344 | typedef RTFSISOMAKERCMDOPTS *PRTFSISOMAKERCMDOPTS;
|
---|
345 | typedef RTFSISOMAKERCMDOPTS const *PCRTFSISOMAKERCMDOPTS;
|
---|
346 |
|
---|
347 |
|
---|
348 | /**
|
---|
349 | * One parsed name.
|
---|
350 | */
|
---|
351 | typedef struct RTFSISOMKCMDPARSEDNAME
|
---|
352 | {
|
---|
353 | /** Copy of the corresponding RTFSISOMAKERCMDOPTS::afNameSpecifiers
|
---|
354 | * value. */
|
---|
355 | uint32_t fNameSpecifiers;
|
---|
356 | /** The length of the specified path. */
|
---|
357 | uint32_t cchPath;
|
---|
358 | /** Specified path. */
|
---|
359 | char szPath[RTPATH_MAX];
|
---|
360 | } RTFSISOMKCMDPARSEDNAME;
|
---|
361 | /** Pointer to a parsed name. */
|
---|
362 | typedef RTFSISOMKCMDPARSEDNAME *PRTFSISOMKCMDPARSEDNAME;
|
---|
363 | /** Pointer to a const parsed name. */
|
---|
364 | typedef RTFSISOMKCMDPARSEDNAME const *PCRTFSISOMKCMDPARSEDNAME;
|
---|
365 |
|
---|
366 |
|
---|
367 | /**
|
---|
368 | * Parsed names.
|
---|
369 | */
|
---|
370 | typedef struct RTFSISOMKCMDPARSEDNAMES
|
---|
371 | {
|
---|
372 | /** Number of names. */
|
---|
373 | uint32_t cNames;
|
---|
374 | /** Number of names with the source. */
|
---|
375 | uint32_t cNamesWithSrc;
|
---|
376 | /** Special source types.
|
---|
377 | * Used for conveying commands to do on names intead of adding a source.
|
---|
378 | * Only used when adding generic stuff w/o any options involved. */
|
---|
379 | enum
|
---|
380 | {
|
---|
381 | kSrcType_None,
|
---|
382 | kSrcType_Normal,
|
---|
383 | kSrcType_Remove,
|
---|
384 | kSrcType_MustRemove
|
---|
385 | } enmSrcType;
|
---|
386 | /** The parsed names. */
|
---|
387 | RTFSISOMKCMDPARSEDNAME aNames[RTFSISOMAKERCMD_MAX_NAMES + 1];
|
---|
388 | } RTFSISOMKCMDPARSEDNAMES;
|
---|
389 | /** Pointer to parsed names. */
|
---|
390 | typedef RTFSISOMKCMDPARSEDNAMES *PRTFSISOMKCMDPARSEDNAMES;
|
---|
391 | /** Pointer to const parsed names. */
|
---|
392 | typedef RTFSISOMKCMDPARSEDNAMES *PCRTFSISOMKCMDPARSEDNAMES;
|
---|
393 |
|
---|
394 |
|
---|
395 |
|
---|
396 | /*********************************************************************************************************************************
|
---|
397 | * Global Variables *
|
---|
398 | *********************************************************************************************************************************/
|
---|
399 | /*
|
---|
400 | * Parse the command line. This is similar to genisoimage and mkisofs,
|
---|
401 | * thus the single dash long name aliases.
|
---|
402 | */
|
---|
403 | static const RTGETOPTDEF g_aRtFsIsoMakerOptions[] =
|
---|
404 | {
|
---|
405 | /*
|
---|
406 | * Unquie IPRT ISO maker options.
|
---|
407 | */
|
---|
408 | { "--iprt-iso-maker-file-marker", RTFSISOMAKERCMD_OPT_IPRT_ISO_MAKER_FILE_MARKER, RTGETOPT_REQ_STRING },
|
---|
409 | { "--iprt-iso-maker-file-marker-ms", RTFSISOMAKERCMD_OPT_IPRT_ISO_MAKER_FILE_MARKER, RTGETOPT_REQ_STRING },
|
---|
410 | { "--iprt-iso-maker-file-marker-ms-crt", RTFSISOMAKERCMD_OPT_IPRT_ISO_MAKER_FILE_MARKER, RTGETOPT_REQ_STRING },
|
---|
411 | { "--iprt-iso-maker-file-marker-bourne", RTFSISOMAKERCMD_OPT_IPRT_ISO_MAKER_FILE_MARKER, RTGETOPT_REQ_STRING },
|
---|
412 | { "--iprt-iso-maker-file-marker-bourne-sh", RTFSISOMAKERCMD_OPT_IPRT_ISO_MAKER_FILE_MARKER, RTGETOPT_REQ_STRING },
|
---|
413 |
|
---|
414 | { "--output-buffer-size", RTFSISOMAKERCMD_OPT_OUTPUT_BUFFER_SIZE, RTGETOPT_REQ_UINT32 },
|
---|
415 | { "--random-output-buffer-size", RTFSISOMAKERCMD_OPT_RANDOM_OUTPUT_BUFFER_SIZE, RTGETOPT_REQ_NOTHING },
|
---|
416 | { "--name-setup", RTFSISOMAKERCMD_OPT_NAME_SETUP, RTGETOPT_REQ_STRING },
|
---|
417 | { "--no-joliet", RTFSISOMAKERCMD_OPT_NO_JOLIET, RTGETOPT_REQ_NOTHING },
|
---|
418 | { "--import-iso", RTFSISOMAKERCMD_OPT_IMPORT_ISO, RTGETOPT_REQ_STRING },
|
---|
419 |
|
---|
420 | { "--eltorito-new-entry", RTFSISOMAKERCMD_OPT_ELTORITO_NEW_ENTRY, RTGETOPT_REQ_NOTHING },
|
---|
421 | { "--eltorito-add-image", RTFSISOMAKERCMD_OPT_ELTORITO_ADD_IMAGE, RTGETOPT_REQ_NOTHING },
|
---|
422 | { "--eltorito-floppy-12", RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_12, RTGETOPT_REQ_NOTHING },
|
---|
423 | { "--eltorito-floppy-144", RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_144, RTGETOPT_REQ_NOTHING },
|
---|
424 | { "--eltorito-floppy-288", RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_288, RTGETOPT_REQ_NOTHING },
|
---|
425 |
|
---|
426 | #define DD(a_szLong, a_chShort, a_fFlags) { a_szLong, a_chShort, a_fFlags }, { "-" a_szLong, a_chShort, a_fFlags }
|
---|
427 |
|
---|
428 | /*
|
---|
429 | * genisoimage/mkisofs compatibility options we've implemented:
|
---|
430 | */
|
---|
431 | /* booting: */
|
---|
432 | { "--generic-boot", 'G', RTGETOPT_REQ_STRING },
|
---|
433 | DD("-eltorito-boot", 'b', RTGETOPT_REQ_STRING ),
|
---|
434 | DD("-eltorito-alt-boot", RTFSISOMAKERCMD_OPT_ELTORITO_NEW_ENTRY, RTGETOPT_REQ_NOTHING ),
|
---|
435 | DD("-eltorito-platform-id", RTFSISOMAKERCMD_OPT_ELTORITO_PLATFORM_ID, RTGETOPT_REQ_STRING ),
|
---|
436 | DD("-hard-disk-boot", RTFSISOMAKERCMD_OPT_ELTORITO_HARD_DISK_BOOT, RTGETOPT_REQ_NOTHING ),
|
---|
437 | DD("-no-emulation-boot", RTFSISOMAKERCMD_OPT_ELTORITO_NO_EMULATION_BOOT, RTGETOPT_REQ_NOTHING ),
|
---|
438 | DD("-no-boot", RTFSISOMAKERCMD_OPT_ELTORITO_NO_BOOT, RTGETOPT_REQ_NOTHING ),
|
---|
439 | DD("-boot-load-seg", RTFSISOMAKERCMD_OPT_ELTORITO_LOAD_SEG, RTGETOPT_REQ_UINT16 ),
|
---|
440 | DD("-boot-load-size", RTFSISOMAKERCMD_OPT_ELTORITO_LOAD_SIZE, RTGETOPT_REQ_UINT16 ),
|
---|
441 | DD("-boot-info-table", RTFSISOMAKERCMD_OPT_ELTORITO_INFO_TABLE, RTGETOPT_REQ_STRING ),
|
---|
442 | { "--boot-catalog", 'c', RTGETOPT_REQ_STRING },
|
---|
443 |
|
---|
444 | /* String props: */
|
---|
445 | DD("-abstract", RTFSISOMAKERCMD_OPT_ABSTRACT_FILE_ID, RTGETOPT_REQ_STRING ),
|
---|
446 | { "--application-id", 'A', RTGETOPT_REQ_STRING },
|
---|
447 | DD("-biblio", RTFSISOMAKERCMD_OPT_BIBLIOGRAPHIC_FILE_ID, RTGETOPT_REQ_STRING ),
|
---|
448 | DD("-copyright", RTFSISOMAKERCMD_OPT_COPYRIGHT_FILE_ID, RTGETOPT_REQ_STRING ),
|
---|
449 | DD("-publisher", 'P', RTGETOPT_REQ_STRING ),
|
---|
450 | { "--preparer", 'p', RTGETOPT_REQ_STRING },
|
---|
451 | DD("-sysid", RTFSISOMAKERCMD_OPT_SYSTEM_ID, RTGETOPT_REQ_STRING ),
|
---|
452 | { "--volume-id", RTFSISOMAKERCMD_OPT_VOLUME_ID, RTGETOPT_REQ_STRING }, /* should've been '-V' */
|
---|
453 | DD("-volset", RTFSISOMAKERCMD_OPT_VOLUME_SET_ID, RTGETOPT_REQ_STRING ),
|
---|
454 |
|
---|
455 | /*
|
---|
456 | * genisoimage/mkisofs compatibility:
|
---|
457 | */
|
---|
458 | DD("-allow-limited-size", RTFSISOMAKERCMD_OPT_ALLOW_LIMITED_SIZE, RTGETOPT_REQ_NOTHING ),
|
---|
459 | DD("-allow-leading-dots", RTFSISOMAKERCMD_OPT_ALLOW_LEADING_DOTS, RTGETOPT_REQ_NOTHING ),
|
---|
460 | DD("-ldots", RTFSISOMAKERCMD_OPT_ALLOW_LEADING_DOTS, RTGETOPT_REQ_NOTHING ),
|
---|
461 | DD("-allow-lowercase", RTFSISOMAKERCMD_OPT_ALLOW_LOWERCASE, RTGETOPT_REQ_NOTHING ),
|
---|
462 | DD("-allow-multidot", RTFSISOMAKERCMD_OPT_ALLOW_MULTI_DOT, RTGETOPT_REQ_NOTHING ),
|
---|
463 | DD("-cache-inodes", RTFSISOMAKERCMD_OPT_DETECT_HARDLINKS, RTGETOPT_REQ_NOTHING ),
|
---|
464 | DD("-no-cache-inodes", RTFSISOMAKERCMD_OPT_NO_DETECT_HARDLINKS, RTGETOPT_REQ_NOTHING ),
|
---|
465 | DD("-alpha-boot", RTFSISOMAKERCMD_OPT_ALPHA_BOOT, RTGETOPT_REQ_STRING ),
|
---|
466 | DD("-hppa-bootloader", RTFSISOMAKERCMD_OPT_HPPA_BOOTLOADER, RTGETOPT_REQ_STRING ),
|
---|
467 | DD("-hppa-cmdline", RTFSISOMAKERCMD_OPT_HPPA_CMDLINE, RTGETOPT_REQ_STRING ),
|
---|
468 | DD("-hppa-kernel-32", RTFSISOMAKERCMD_OPT_HPPA_KERNEL_32, RTGETOPT_REQ_STRING ),
|
---|
469 | DD("-hppa-kernel-64", RTFSISOMAKERCMD_OPT_HPPA_KERNEL_64, RTGETOPT_REQ_STRING ),
|
---|
470 | DD("-hppa-ramdisk", RTFSISOMAKERCMD_OPT_HPPA_RAMDISK, RTGETOPT_REQ_STRING ),
|
---|
471 | DD("-mips-boot", RTFSISOMAKERCMD_OPT_MIPS_BOOT, RTGETOPT_REQ_STRING ),
|
---|
472 | DD("-mipsel-boot", RTFSISOMAKERCMD_OPT_MIPSEL_BOOT, RTGETOPT_REQ_STRING ),
|
---|
473 | DD("-sparc-boot", 'B', RTGETOPT_REQ_STRING ),
|
---|
474 | { "--cd-extra", 'C', RTGETOPT_REQ_STRING },
|
---|
475 | DD("-check-oldnames", RTFSISOMAKERCMD_OPT_CHECK_OLD_NAMES, RTGETOPT_REQ_NOTHING ),
|
---|
476 | DD("-check-session", RTFSISOMAKERCMD_OPT_CHECK_SESSION, RTGETOPT_REQ_STRING ),
|
---|
477 | { "--dont-append-dot", 'd', RTGETOPT_REQ_NOTHING },
|
---|
478 | { "--deep-directories", 'D', RTGETOPT_REQ_NOTHING },
|
---|
479 | DD("-dir-mode", RTFSISOMAKERCMD_OPT_DIR_MODE, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_OCT ),
|
---|
480 | DD("-dvd-video", RTFSISOMAKERCMD_OPT_DVD_VIDEO, RTGETOPT_REQ_NOTHING ),
|
---|
481 | DD("-follow-symlinks", 'f', RTGETOPT_REQ_NOTHING ),
|
---|
482 | DD("-file-mode", RTFSISOMAKERCMD_OPT_FILE_MODE, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_OCT ),
|
---|
483 | DD("-gid", RTFSISOMAKERCMD_OPT_GID, RTGETOPT_REQ_UINT32 ),
|
---|
484 | DD("-gui", RTFSISOMAKERCMD_OPT_GUI, RTGETOPT_REQ_NOTHING ),
|
---|
485 | DD("-graft-points", RTFSISOMAKERCMD_OPT_GRAFT_POINTS, RTGETOPT_REQ_NOTHING ),
|
---|
486 | DD("-hide", RTFSISOMAKERCMD_OPT_HIDE, RTGETOPT_REQ_STRING ),
|
---|
487 | DD("-hide-list", RTFSISOMAKERCMD_OPT_HIDE_LIST, RTGETOPT_REQ_STRING ),
|
---|
488 | DD("-hidden", RTFSISOMAKERCMD_OPT_HIDDEN, RTGETOPT_REQ_STRING ),
|
---|
489 | DD("-hidden-list", RTFSISOMAKERCMD_OPT_HIDDEN_LIST, RTGETOPT_REQ_STRING ),
|
---|
490 | DD("-hide-joliet", RTFSISOMAKERCMD_OPT_HIDE_JOLIET, RTGETOPT_REQ_STRING ),
|
---|
491 | DD("-hide-joliet-list", RTFSISOMAKERCMD_OPT_HIDE_JOLIET_LIST, RTGETOPT_REQ_STRING ),
|
---|
492 | DD("-hide-joliet-trans-tbl", RTFSISOMAKERCMD_OPT_HIDE_JOLIET_TRANS_TBL, RTGETOPT_REQ_NOTHING ),
|
---|
493 | DD("-hide-rr-moved", RTFSISOMAKERCMD_OPT_HIDE_RR_MOVED, RTGETOPT_REQ_NOTHING ),
|
---|
494 | DD("-input-charset", RTFSISOMAKERCMD_OPT_INPUT_CHARSET, RTGETOPT_REQ_STRING ),
|
---|
495 | DD("-output-charset", RTFSISOMAKERCMD_OPT_OUTPUT_CHARSET, RTGETOPT_REQ_STRING ),
|
---|
496 | { "--iso-level", RTFSISOMAKERCMD_OPT_ISO_LEVEL, RTGETOPT_REQ_UINT8 },
|
---|
497 | { "--joliet", 'J', RTGETOPT_REQ_NOTHING },
|
---|
498 | DD("-joliet-long", RTFSISOMAKERCMD_OPT_JOLIET_LONG, RTGETOPT_REQ_NOTHING ),
|
---|
499 | DD("-jcharset", RTFSISOMAKERCMD_OPT_JOLIET_CHARSET, RTGETOPT_REQ_STRING ),
|
---|
500 | { "--long-names", 'l', RTGETOPT_REQ_NOTHING },
|
---|
501 | { "--leading-dot", 'L', RTGETOPT_REQ_NOTHING },
|
---|
502 | DD("-jigdo-jigdo", RTFSISOMAKERCMD_OPT_JIGDO_JIGDO, RTGETOPT_REQ_STRING ),
|
---|
503 | DD("-jigdo-template", RTFSISOMAKERCMD_OPT_JIGDO_TEMPLATE, RTGETOPT_REQ_STRING ),
|
---|
504 | DD("-jigdo-min-file-size", RTFSISOMAKERCMD_OPT_JIGDO_MIN_FILE_SIZE, RTGETOPT_REQ_UINT64 ),
|
---|
505 | DD("-jigdo-force-md5", RTFSISOMAKERCMD_OPT_JIGDO_FORCE_MD5, RTGETOPT_REQ_STRING ),
|
---|
506 | DD("-jigdo-exclude", RTFSISOMAKERCMD_OPT_JIGDO_EXCLUDE, RTGETOPT_REQ_STRING ),
|
---|
507 | DD("-jigdo-map", RTFSISOMAKERCMD_OPT_JIGDO_MAP, RTGETOPT_REQ_STRING ),
|
---|
508 | DD("-md5-list", RTFSISOMAKERCMD_OPT_JIGDO_MD5_LIST, RTGETOPT_REQ_STRING ),
|
---|
509 | DD("-jigdo-template-compress", RTFSISOMAKERCMD_OPT_JIGDO_COMPRESS, RTGETOPT_REQ_STRING ),
|
---|
510 | DD("-log-file", RTFSISOMAKERCMD_OPT_LOG_FILE, RTGETOPT_REQ_STRING ),
|
---|
511 | { "--exclude", 'm', RTGETOPT_REQ_STRING },
|
---|
512 | { "--exclude", 'x', RTGETOPT_REQ_STRING },
|
---|
513 | DD("-exclude-list", RTFSISOMAKERCMD_OPT_EXCLUDE_LIST, RTGETOPT_REQ_STRING ),
|
---|
514 | DD("-max-iso9660-filenames", RTFSISOMAKERCMD_OPT_MAX_ISO9660_FILENAMES, RTGETOPT_REQ_NOTHING ),
|
---|
515 | { "--merge", 'M', RTGETOPT_REQ_STRING },
|
---|
516 | DD("-dev", 'M', RTGETOPT_REQ_STRING ),
|
---|
517 | { "--omit-version-numbers", 'N', RTGETOPT_REQ_NOTHING },
|
---|
518 | DD("-new-dir-mode", RTFSISOMAKERCMD_OPT_NEW_DIR_MODE, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_OCT ),
|
---|
519 | DD("-nobak", RTFSISOMAKERCMD_OPT_NO_BACKUP_FILES, RTGETOPT_REQ_NOTHING ),
|
---|
520 | DD("-no-bak", RTFSISOMAKERCMD_OPT_NO_BACKUP_FILES, RTGETOPT_REQ_NOTHING ),
|
---|
521 | DD("-force-rr", RTFSISOMAKERCMD_OPT_FORCE_RR, RTGETOPT_REQ_NOTHING ),
|
---|
522 | DD("-no-rr", RTFSISOMAKERCMD_OPT_NO_RR, RTGETOPT_REQ_NOTHING ),
|
---|
523 | DD("-no-split-symlink-components", RTFSISOMAKERCMD_OPT_NO_SPLIT_SYMLINK_COMPONENTS, RTGETOPT_REQ_NOTHING ),
|
---|
524 | DD("-no-split-symlink-fields", RTFSISOMAKERCMD_OPT_NO_SPLIT_SYMLINK_FIELDS, RTGETOPT_REQ_NOTHING ),
|
---|
525 | { "--output", 'o', RTGETOPT_REQ_STRING },
|
---|
526 | DD("-pad", RTFSISOMAKERCMD_OPT_PAD, RTGETOPT_REQ_NOTHING ),
|
---|
527 | DD("-no-pad", RTFSISOMAKERCMD_OPT_NO_PAD, RTGETOPT_REQ_NOTHING ),
|
---|
528 | DD("-path-list", RTFSISOMAKERCMD_OPT_PATH_LIST, RTGETOPT_REQ_STRING ),
|
---|
529 | DD("-print-size", RTFSISOMAKERCMD_OPT_PRINT_SIZE, RTGETOPT_REQ_NOTHING ),
|
---|
530 | DD("-quiet", RTFSISOMAKERCMD_OPT_QUIET, RTGETOPT_REQ_NOTHING ),
|
---|
531 | { "--rock-ridge", 'R', RTGETOPT_REQ_NOTHING },
|
---|
532 | { "--rock-ridge-relaxed", 'r', RTGETOPT_REQ_NOTHING },
|
---|
533 | DD("-relaxed-filenames", RTFSISOMAKERCMD_OPT_RELAXED_FILENAMES, RTGETOPT_REQ_NOTHING ),
|
---|
534 | DD("-root", RTFSISOMAKERCMD_OPT_ROOT, RTGETOPT_REQ_STRING ),
|
---|
535 | DD("-old-root", RTFSISOMAKERCMD_OPT_OLD_ROOT, RTGETOPT_REQ_STRING ),
|
---|
536 | DD("-sort", RTFSISOMAKERCMD_OPT_SORT, RTGETOPT_REQ_STRING ),
|
---|
537 | DD("-sparc-boot", RTFSISOMAKERCMD_OPT_SPARC_BOOT, RTGETOPT_REQ_STRING ),
|
---|
538 | DD("-sparc-label", RTFSISOMAKERCMD_OPT_SPARC_LABEL, RTGETOPT_REQ_STRING ),
|
---|
539 | DD("-split-output", RTFSISOMAKERCMD_OPT_SPLIT_OUTPUT, RTGETOPT_REQ_NOTHING ),
|
---|
540 | DD("-stream-media-size", RTFSISOMAKERCMD_OPT_STREAM_MEDIA_SIZE, RTGETOPT_REQ_UINT64 ),
|
---|
541 | DD("-stream-file-name", RTFSISOMAKERCMD_OPT_STREAM_FILE_NAME, RTGETOPT_REQ_STRING ),
|
---|
542 | DD("-sunx86-boot", RTFSISOMAKERCMD_OPT_SUNX86_BOOT, RTGETOPT_REQ_STRING ),
|
---|
543 | DD("-sunx86-label", RTFSISOMAKERCMD_OPT_SUNX86_LABEL, RTGETOPT_REQ_STRING ),
|
---|
544 | { "--trans-tbl", 'T', RTGETOPT_REQ_NOTHING },
|
---|
545 | DD("-table-name", RTFSISOMAKERCMD_OPT_TRANS_TBL_NAME, RTGETOPT_REQ_STRING ),
|
---|
546 | DD("-ucs-level", RTFSISOMAKERCMD_OPT_JOLIET_LEVEL, RTGETOPT_REQ_UINT8 ),
|
---|
547 | DD("-udf", RTFSISOMAKERCMD_OPT_UDF, RTGETOPT_REQ_NOTHING ),
|
---|
548 | DD("-uid", RTFSISOMAKERCMD_OPT_UID, RTGETOPT_REQ_UINT32 ),
|
---|
549 | DD("-use-fileversion", RTFSISOMAKERCMD_OPT_USE_FILE_VERSION, RTGETOPT_REQ_NOTHING ),
|
---|
550 | { "--untranslated-filenames", 'U', RTGETOPT_REQ_NOTHING },
|
---|
551 | DD("-no-iso-translate", RTFSISOMAKERCMD_OPT_NO_ISO_TRANSLATE, RTGETOPT_REQ_NOTHING ),
|
---|
552 | DD("-volset-size", RTFSISOMAKERCMD_OPT_VOLUME_SET_SIZE, RTGETOPT_REQ_UINT32 ),
|
---|
553 | DD("-volset-seqno", RTFSISOMAKERCMD_OPT_VOLUME_SET_SEQ_NO, RTGETOPT_REQ_UINT32 ),
|
---|
554 | { "--transpared-compression", 'z', RTGETOPT_REQ_NOTHING },
|
---|
555 |
|
---|
556 | /* HFS and ISO-9660 apple extensions. */
|
---|
557 | DD("-hfs", RTFSISOMAKERCMD_OPT_HFS_ENABLE, RTGETOPT_REQ_NOTHING ),
|
---|
558 | DD("-apple", RTFSISOMAKERCMD_OPT_APPLE, RTGETOPT_REQ_NOTHING ),
|
---|
559 | DD("-map", RTFSISOMAKERCMD_OPT_HFS_MAP, RTGETOPT_REQ_STRING ),
|
---|
560 | DD("-magic", RTFSISOMAKERCMD_OPT_HFS_MAGIC, RTGETOPT_REQ_STRING ),
|
---|
561 | DD("-hfs-creator", RTFSISOMAKERCMD_OPT_HFS_CREATOR, RTGETOPT_REQ_STRING ),
|
---|
562 | DD("-hfs-type", RTFSISOMAKERCMD_OPT_HFS_TYPE, RTGETOPT_REQ_STRING ),
|
---|
563 | DD("-probe", RTFSISOMAKERCMD_OPT_HFS_PROBE, RTGETOPT_REQ_NOTHING ),
|
---|
564 | DD("-no-desktop", RTFSISOMAKERCMD_OPT_HFS_NO_DESKTOP, RTGETOPT_REQ_NOTHING ),
|
---|
565 | DD("-mac-name", RTFSISOMAKERCMD_OPT_HFS_MAC_NAME, RTGETOPT_REQ_NOTHING ),
|
---|
566 | DD("-boot-hfs-file", RTFSISOMAKERCMD_OPT_HFS_BOOT_FILE, RTGETOPT_REQ_STRING ),
|
---|
567 | DD("-part", RTFSISOMAKERCMD_OPT_HFS_PART, RTGETOPT_REQ_NOTHING ),
|
---|
568 | DD("-auto", RTFSISOMAKERCMD_OPT_HFS_AUTO, RTGETOPT_REQ_STRING ),
|
---|
569 | DD("-cluster-size", RTFSISOMAKERCMD_OPT_HFS_CLUSTER_SIZE, RTGETOPT_REQ_UINT32 ),
|
---|
570 | DD("-hide-hfs", RTFSISOMAKERCMD_OPT_HFS_HIDE, RTGETOPT_REQ_STRING ),
|
---|
571 | DD("-hide-hfs-list", RTFSISOMAKERCMD_OPT_HFS_HIDE_LIST, RTGETOPT_REQ_STRING ),
|
---|
572 | DD("-hfs-volid", RTFSISOMAKERCMD_OPT_HFS_VOL_ID, RTGETOPT_REQ_STRING ),
|
---|
573 | DD("-icon-position", RTFSISOMAKERCMD_OPT_HFS_ICON_POSITION, RTGETOPT_REQ_NOTHING ),
|
---|
574 | DD("-root-info", RTFSISOMAKERCMD_OPT_HFS_ROOT_INFO, RTGETOPT_REQ_STRING ),
|
---|
575 | DD("-prep-boot", RTFSISOMAKERCMD_OPT_HFS_PREP_BOOT, RTGETOPT_REQ_STRING ),
|
---|
576 | DD("-chrp-boot", RTFSISOMAKERCMD_OPT_HFS_CHRP_BOOT, RTGETOPT_REQ_NOTHING ),
|
---|
577 | DD("-input-hfs-charset", RTFSISOMAKERCMD_OPT_HFS_INPUT_CHARSET, RTGETOPT_REQ_STRING ),
|
---|
578 | DD("-output-hfs-charset", RTFSISOMAKERCMD_OPT_HFS_OUTPUT_CHARSET, RTGETOPT_REQ_STRING ),
|
---|
579 | DD("-hfs-unlock", RTFSISOMAKERCMD_OPT_HFS_UNLOCK, RTGETOPT_REQ_NOTHING ),
|
---|
580 | DD("-hfs-bless", RTFSISOMAKERCMD_OPT_HFS_BLESS, RTGETOPT_REQ_STRING ),
|
---|
581 | DD("-hfs-parms", RTFSISOMAKERCMD_OPT_HFS_PARMS, RTGETOPT_REQ_STRING ),
|
---|
582 | { "--cap", RTFSISOMAKERCMD_OPT_HFS_CAP, RTGETOPT_REQ_NOTHING },
|
---|
583 | { "--netatalk", RTFSISOMAKERCMD_OPT_HFS_NETATALK, RTGETOPT_REQ_NOTHING },
|
---|
584 | { "--double", RTFSISOMAKERCMD_OPT_HFS_DOUBLE, RTGETOPT_REQ_NOTHING },
|
---|
585 | { "--ethershare", RTFSISOMAKERCMD_OPT_HFS_ETHERSHARE, RTGETOPT_REQ_NOTHING },
|
---|
586 | { "--ushare", RTFSISOMAKERCMD_OPT_HFS_USHARE, RTGETOPT_REQ_NOTHING },
|
---|
587 | { "--exchange", RTFSISOMAKERCMD_OPT_HFS_EXCHANGE, RTGETOPT_REQ_NOTHING },
|
---|
588 | { "--sgi", RTFSISOMAKERCMD_OPT_HFS_SGI, RTGETOPT_REQ_NOTHING },
|
---|
589 | { "--xinet", RTFSISOMAKERCMD_OPT_HFS_XINET, RTGETOPT_REQ_NOTHING },
|
---|
590 | { "--macbin", RTFSISOMAKERCMD_OPT_HFS_MACBIN, RTGETOPT_REQ_NOTHING },
|
---|
591 | { "--single", RTFSISOMAKERCMD_OPT_HFS_SINGLE, RTGETOPT_REQ_NOTHING },
|
---|
592 | { "--dave", RTFSISOMAKERCMD_OPT_HFS_DAVE, RTGETOPT_REQ_NOTHING },
|
---|
593 | { "--sfm", RTFSISOMAKERCMD_OPT_HFS_SFM, RTGETOPT_REQ_NOTHING },
|
---|
594 | { "--osx-double", RTFSISOMAKERCMD_OPT_HFS_OSX_DOUBLE, RTGETOPT_REQ_NOTHING },
|
---|
595 | { "--osx-hfs", RTFSISOMAKERCMD_OPT_HFS_OSX_HFS, RTGETOPT_REQ_NOTHING },
|
---|
596 | #undef DD
|
---|
597 | };
|
---|
598 |
|
---|
599 |
|
---|
600 | /**
|
---|
601 | * Wrapper around RTErrInfoSetV / RTMsgErrorV.
|
---|
602 | *
|
---|
603 | * @returns @a rc
|
---|
604 | * @param pOpts The ISO maker command instance.
|
---|
605 | * @param rc The return code.
|
---|
606 | * @param pszFormat The message format.
|
---|
607 | * @param ... The message format arguments.
|
---|
608 | */
|
---|
609 | static int rtFsIsoMakerCmdErrorRc(PRTFSISOMAKERCMDOPTS pOpts, int rc, const char *pszFormat, ...)
|
---|
610 | {
|
---|
611 | va_list va;
|
---|
612 | va_start(va, pszFormat);
|
---|
613 | if (pOpts->pErrInfo)
|
---|
614 | RTErrInfoSetV(pOpts->pErrInfo, rc, pszFormat, va);
|
---|
615 | else
|
---|
616 | RTMsgErrorV(pszFormat, va);
|
---|
617 | va_end(va);
|
---|
618 | return rc;
|
---|
619 | }
|
---|
620 |
|
---|
621 |
|
---|
622 | /**
|
---|
623 | * Wrapper around RTErrInfoSetV / RTMsgErrorV for doing the job of
|
---|
624 | * RTVfsChainMsgError.
|
---|
625 | *
|
---|
626 | * @returns @a rc
|
---|
627 | * @param pOpts The ISO maker command instance.
|
---|
628 | * @param pszFunction The API called.
|
---|
629 | * @param pszSpec The VFS chain specification or file path passed to the.
|
---|
630 | * @param rc The return code.
|
---|
631 | * @param offError The error offset value returned (0 if not captured).
|
---|
632 | * @param pErrInfo Additional error information. Optional.
|
---|
633 | */
|
---|
634 | static int rtFsIsoMakerCmdChainError(PRTFSISOMAKERCMDOPTS pOpts, const char *pszFunction, const char *pszSpec, int rc,
|
---|
635 | uint32_t offError, PRTERRINFO pErrInfo)
|
---|
636 | {
|
---|
637 | if (RTErrInfoIsSet(pErrInfo))
|
---|
638 | {
|
---|
639 | if (offError > 0)
|
---|
640 | rc = rtFsIsoMakerCmdErrorRc(pOpts, rc,
|
---|
641 | "%s failed with rc=%Rrc: %s\n"
|
---|
642 | " '%s'\n"
|
---|
643 | " %*s^",
|
---|
644 | pszFunction, rc, pErrInfo->pszMsg, pszSpec, offError, "");
|
---|
645 | else
|
---|
646 | rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "%s failed to open '%s': %Rrc: %s",
|
---|
647 | pszFunction, pszSpec, rc, pErrInfo->pszMsg);
|
---|
648 | }
|
---|
649 | else
|
---|
650 | {
|
---|
651 | if (offError > 0)
|
---|
652 | rc = rtFsIsoMakerCmdErrorRc(pOpts, rc,
|
---|
653 | "%s failed with rc=%Rrc:\n"
|
---|
654 | " '%s'\n"
|
---|
655 | " %*s^",
|
---|
656 | pszFunction, rc, pszSpec, offError, "");
|
---|
657 | else
|
---|
658 | rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "%s failed to open '%s': %Rrc", pszFunction, pszSpec, rc);
|
---|
659 | }
|
---|
660 | return rc;
|
---|
661 | }
|
---|
662 |
|
---|
663 |
|
---|
664 | /**
|
---|
665 | * Wrapper around RTErrInfoSetV / RTMsgErrorV for displaying syntax errors.
|
---|
666 | *
|
---|
667 | * @returns VERR_INVALID_PARAMETER
|
---|
668 | * @param pOpts The ISO maker command instance.
|
---|
669 | * @param pszFormat The message format.
|
---|
670 | * @param ... The message format arguments.
|
---|
671 | */
|
---|
672 | static int rtFsIsoMakerCmdSyntaxError(PRTFSISOMAKERCMDOPTS pOpts, const char *pszFormat, ...)
|
---|
673 | {
|
---|
674 | va_list va;
|
---|
675 | va_start(va, pszFormat);
|
---|
676 | if (pOpts->pErrInfo)
|
---|
677 | RTErrInfoSetV(pOpts->pErrInfo, VERR_INVALID_PARAMETER, pszFormat, va);
|
---|
678 | else
|
---|
679 | RTMsgErrorV(pszFormat, va);
|
---|
680 | va_end(va);
|
---|
681 | return VERR_INVALID_PARAMETER;
|
---|
682 | }
|
---|
683 |
|
---|
684 |
|
---|
685 | /**
|
---|
686 | * Wrapper around RTPrintfV / RTLogRelPrintfV.
|
---|
687 | *
|
---|
688 | * @param pOpts The ISO maker command instance.
|
---|
689 | * @param pszFormat The message format.
|
---|
690 | * @param ... The message format arguments.
|
---|
691 | */
|
---|
692 | static void rtFsIsoMakerPrintf(PRTFSISOMAKERCMDOPTS pOpts, const char *pszFormat, ...)
|
---|
693 | {
|
---|
694 | va_list va;
|
---|
695 | va_start(va, pszFormat);
|
---|
696 | if (pOpts->pErrInfo)
|
---|
697 | RTLogRelPrintfV(pszFormat, va);
|
---|
698 | else
|
---|
699 | RTPrintfV(pszFormat, va);
|
---|
700 | va_end(va);
|
---|
701 | }
|
---|
702 |
|
---|
703 | /**
|
---|
704 | * Deletes the state and returns @a rc.
|
---|
705 | *
|
---|
706 | * @returns @a rc.
|
---|
707 | * @param pOpts The ISO maker command instance to delete.
|
---|
708 | * @param rc The status code to return.
|
---|
709 | */
|
---|
710 | static int rtFsIsoMakerCmdDeleteState(PRTFSISOMAKERCMDOPTS pOpts, int rc)
|
---|
711 | {
|
---|
712 | if (pOpts->hIsoMaker != NIL_RTFSISOMAKER)
|
---|
713 | {
|
---|
714 | RTFsIsoMakerRelease(pOpts->hIsoMaker);
|
---|
715 | pOpts->hIsoMaker = NIL_RTFSISOMAKER;
|
---|
716 | }
|
---|
717 |
|
---|
718 | return rc;
|
---|
719 | }
|
---|
720 |
|
---|
721 |
|
---|
722 | static void rtFsIsoMakerCmdUsage(PRTFSISOMAKERCMDOPTS pOpts, const char *pszProgName)
|
---|
723 | {
|
---|
724 | rtFsIsoMakerPrintf(pOpts, "usage: %s [options] <file>=<cdfile>\n", pszProgName);
|
---|
725 | }
|
---|
726 |
|
---|
727 |
|
---|
728 | /**
|
---|
729 | * Writes the image to file.
|
---|
730 | *
|
---|
731 | * @returns IPRT status code.
|
---|
732 | * @param pOpts The ISO maker command instance.
|
---|
733 | * @param hVfsSrcFile The source file from the ISO maker.
|
---|
734 | */
|
---|
735 | static int rtFsIsoMakerCmdWriteImage(PRTFSISOMAKERCMDOPTS pOpts, RTVFSFILE hVfsSrcFile)
|
---|
736 | {
|
---|
737 | /*
|
---|
738 | * Get the image size and setup the copy buffer.
|
---|
739 | */
|
---|
740 | uint64_t cbImage;
|
---|
741 | int rc = RTVfsFileGetSize(hVfsSrcFile, &cbImage);
|
---|
742 | if (RT_SUCCESS(rc))
|
---|
743 | {
|
---|
744 | rtFsIsoMakerPrintf(pOpts, "Image size: %'RU64 (%#RX64) bytes\n", cbImage, cbImage);
|
---|
745 |
|
---|
746 | uint32_t cbBuf = pOpts->cbOutputReadBuffer == 0 ? _1M : pOpts->cbOutputReadBuffer;
|
---|
747 | void *pvBuf = RTMemTmpAlloc(cbBuf);
|
---|
748 | if (pvBuf)
|
---|
749 | {
|
---|
750 | /*
|
---|
751 | * Open the output file.
|
---|
752 | */
|
---|
753 | RTVFSFILE hVfsDstFile;
|
---|
754 | uint32_t offError;
|
---|
755 | RTERRINFOSTATIC ErrInfo;
|
---|
756 | rc = RTVfsChainOpenFile(pOpts->pszOutFile, RTFILE_O_WRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_WRITE,
|
---|
757 | &hVfsDstFile, &offError, RTErrInfoInitStatic(&ErrInfo));
|
---|
758 | if (RT_SUCCESS(rc))
|
---|
759 | {
|
---|
760 | /*
|
---|
761 | * Copy the virtual image bits to the destination file.
|
---|
762 | */
|
---|
763 | uint64_t offImage = 0;
|
---|
764 | while (offImage < cbImage)
|
---|
765 | {
|
---|
766 | /* Figure out how much to copy this time. */
|
---|
767 | size_t cbToCopy = cbBuf;
|
---|
768 | if (pOpts->fRandomOutputReadBufferSize)
|
---|
769 | cbToCopy = RTRandU32Ex(1, (uint32_t)cbBuf - 1);
|
---|
770 | if (offImage + cbToCopy < cbImage)
|
---|
771 | { /* likely */ }
|
---|
772 | else
|
---|
773 | cbToCopy = (size_t)(cbImage - offImage);
|
---|
774 |
|
---|
775 | /* Do the copying. */
|
---|
776 | rc = RTVfsFileReadAt(hVfsSrcFile, offImage, pvBuf, cbToCopy, NULL);
|
---|
777 | if (RT_SUCCESS(rc))
|
---|
778 | {
|
---|
779 | rc = RTVfsFileWriteAt(hVfsDstFile, offImage, pvBuf, cbToCopy, NULL);
|
---|
780 | if (RT_SUCCESS(rc))
|
---|
781 | offImage += cbToCopy;
|
---|
782 | else
|
---|
783 | {
|
---|
784 | rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error %Rrc writing %#zx bytes at offset %#RX64 to '%s'",
|
---|
785 | rc, cbToCopy, offImage, pOpts->pszOutFile);
|
---|
786 | break;
|
---|
787 | }
|
---|
788 | }
|
---|
789 | else
|
---|
790 | {
|
---|
791 | rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error %Rrc read %#zx bytes at offset %#RX64", rc, cbToCopy, offImage);
|
---|
792 | break;
|
---|
793 | }
|
---|
794 | }
|
---|
795 |
|
---|
796 | /*
|
---|
797 | * Flush the output file before releasing it.
|
---|
798 | */
|
---|
799 | if (RT_SUCCESS(rc))
|
---|
800 | {
|
---|
801 | rc = RTVfsFileFlush(hVfsDstFile);
|
---|
802 | if (RT_FAILURE(rc))
|
---|
803 | rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTVfsFileFlush failed on '%s': %Rrc", pOpts->pszOutFile, rc);
|
---|
804 | }
|
---|
805 |
|
---|
806 | RTVfsFileRelease(hVfsDstFile);
|
---|
807 | }
|
---|
808 | else
|
---|
809 | rc = rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainOpenFile", pOpts->pszOutFile, rc, offError, &ErrInfo.Core);
|
---|
810 |
|
---|
811 | RTMemTmpFree(pvBuf);
|
---|
812 | }
|
---|
813 | else
|
---|
814 | rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTMemTmpAlloc(%zu) failed: %Rrc", pOpts->cbOutputReadBuffer, rc);
|
---|
815 | }
|
---|
816 | else
|
---|
817 | rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTVfsFileGetSize failed: %Rrc", rc);
|
---|
818 | return rc;
|
---|
819 | }
|
---|
820 |
|
---|
821 |
|
---|
822 | /**
|
---|
823 | * Formats @a fNameSpecifiers into a '+' separated list of names.
|
---|
824 | *
|
---|
825 | * @returns pszDst
|
---|
826 | * @param fNameSpecifiers The name specifiers.
|
---|
827 | * @param pszDst The destination bufer.
|
---|
828 | * @param cbDst The size of the destination buffer.
|
---|
829 | */
|
---|
830 | static char *rtFsIsoMakerCmdNameSpecifiersToString(uint32_t fNameSpecifiers, char *pszDst, size_t cbDst)
|
---|
831 | {
|
---|
832 | static struct { const char *pszName; uint32_t cchName; uint32_t fSpec; } const s_aSpecs[] =
|
---|
833 | {
|
---|
834 | { RT_STR_TUPLE("primary"), RTFSISOMAKERCMDNAME_PRIMARY_ISO },
|
---|
835 | { RT_STR_TUPLE("primary-rock"), RTFSISOMAKERCMDNAME_PRIMARY_ISO_ROCK_RIDGE },
|
---|
836 | { RT_STR_TUPLE("primary-trans-tbl"), RTFSISOMAKERCMDNAME_PRIMARY_ISO_TRANS_TBL },
|
---|
837 | { RT_STR_TUPLE("joliet"), RTFSISOMAKERCMDNAME_JOLIET },
|
---|
838 | { RT_STR_TUPLE("joliet-rock"), RTFSISOMAKERCMDNAME_JOLIET_ROCK_RIDGE },
|
---|
839 | { RT_STR_TUPLE("joliet-trans-tbl"), RTFSISOMAKERCMDNAME_JOLIET_TRANS_TBL },
|
---|
840 | { RT_STR_TUPLE("udf"), RTFSISOMAKERCMDNAME_UDF },
|
---|
841 | { RT_STR_TUPLE("udf-trans-tbl"), RTFSISOMAKERCMDNAME_UDF_TRANS_TBL },
|
---|
842 | { RT_STR_TUPLE("hfs"), RTFSISOMAKERCMDNAME_HFS },
|
---|
843 | { RT_STR_TUPLE("hfs-trans-tbl"), RTFSISOMAKERCMDNAME_HFS_TRANS_TBL },
|
---|
844 | };
|
---|
845 |
|
---|
846 | Assert(cbDst > 0);
|
---|
847 | char *pszRet = pszDst;
|
---|
848 | for (uint32_t i = 0; i < RT_ELEMENTS(s_aSpecs); i++)
|
---|
849 | if (s_aSpecs[i].fSpec & fNameSpecifiers)
|
---|
850 | {
|
---|
851 | if (pszDst != pszRet && cbDst > 1)
|
---|
852 | {
|
---|
853 | *pszDst++ = '+';
|
---|
854 | cbDst--;
|
---|
855 | }
|
---|
856 | if (cbDst > s_aSpecs[i].cchName)
|
---|
857 | {
|
---|
858 | memcpy(pszDst, s_aSpecs[i].pszName, s_aSpecs[i].cchName);
|
---|
859 | cbDst -= s_aSpecs[i].cchName;
|
---|
860 | pszDst += s_aSpecs[i].cchName;
|
---|
861 | }
|
---|
862 | else if (cbDst > 1)
|
---|
863 | {
|
---|
864 | memcpy(pszDst, s_aSpecs[i].pszName, cbDst - 1);
|
---|
865 | pszDst += cbDst - 1;
|
---|
866 | cbDst = 1;
|
---|
867 | }
|
---|
868 |
|
---|
869 | fNameSpecifiers &= ~s_aSpecs[i].fSpec;
|
---|
870 | if (!fNameSpecifiers)
|
---|
871 | break;
|
---|
872 | }
|
---|
873 | *pszDst = '\0';
|
---|
874 | return pszRet;
|
---|
875 | }
|
---|
876 |
|
---|
877 |
|
---|
878 | /**
|
---|
879 | * Parses the --name-setup option.
|
---|
880 | *
|
---|
881 | * @returns IPRT status code.
|
---|
882 | * @param pOpts The ISO maker command instance.
|
---|
883 | * @param pszSpec The name setup specification.
|
---|
884 | */
|
---|
885 | static int rtFsIsoMakerCmdOptNameSetup(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSpec)
|
---|
886 | {
|
---|
887 | /*
|
---|
888 | * Comma separated list of one or more specifiers.
|
---|
889 | */
|
---|
890 | uint32_t fNamespaces = 0;
|
---|
891 | uint32_t fPrevMajor = 0;
|
---|
892 | uint32_t iNameSpecifier = 0;
|
---|
893 | uint32_t offSpec = 0;
|
---|
894 | do
|
---|
895 | {
|
---|
896 | /*
|
---|
897 | * Parse up to the next colon or end of string.
|
---|
898 | */
|
---|
899 | uint32_t fNameSpecifier = 0;
|
---|
900 | char ch;
|
---|
901 | while ( (ch = pszSpec[offSpec]) != '\0'
|
---|
902 | && ch != ',')
|
---|
903 | {
|
---|
904 | if (RT_C_IS_SPACE(ch) || ch == '+' || ch == '|') /* space, '+' and '|' are allowed as name separators. */
|
---|
905 | offSpec++;
|
---|
906 | else
|
---|
907 | {
|
---|
908 | /* Find the end of the name. */
|
---|
909 | uint32_t offEndSpec = offSpec + 1;
|
---|
910 | while ( (ch = pszSpec[offEndSpec]) != '\0'
|
---|
911 | && ch != ','
|
---|
912 | && ch != '+'
|
---|
913 | && ch != '|'
|
---|
914 | && !RT_C_IS_SPACE(ch))
|
---|
915 | offEndSpec++;
|
---|
916 |
|
---|
917 | #define IS_EQUAL(a_sz) (cchName == sizeof(a_sz) - 1U && strncmp(pchName, a_sz, sizeof(a_sz) - 1U) == 0)
|
---|
918 | const char * const pchName = &pszSpec[offSpec];
|
---|
919 | uint32_t const cchName = offEndSpec - offSpec;
|
---|
920 | /* major namespaces */
|
---|
921 | if ( IS_EQUAL("iso")
|
---|
922 | || IS_EQUAL("primary")
|
---|
923 | || IS_EQUAL("iso9660")
|
---|
924 | || IS_EQUAL("iso-9660")
|
---|
925 | || IS_EQUAL("primary-iso")
|
---|
926 | || IS_EQUAL("iso-primary") )
|
---|
927 | {
|
---|
928 | fNameSpecifier |= RTFSISOMAKERCMDNAME_PRIMARY_ISO;
|
---|
929 | fNamespaces |= fPrevMajor = RTFSISOMAKER_NAMESPACE_ISO_9660;
|
---|
930 | }
|
---|
931 | else if (IS_EQUAL("joliet"))
|
---|
932 | {
|
---|
933 | fNameSpecifier |= RTFSISOMAKERCMDNAME_JOLIET;
|
---|
934 | fNamespaces |= fPrevMajor = RTFSISOMAKER_NAMESPACE_JOLIET;
|
---|
935 | }
|
---|
936 | else if (IS_EQUAL("udf"))
|
---|
937 | {
|
---|
938 | #if 0
|
---|
939 | fNameSpecifier |= RTFSISOMAKERCMDNAME_UDF;
|
---|
940 | fNamespaces |= fPrevMajor = RTFSISOMAKER_NAMESPACE_UDF;
|
---|
941 | #else
|
---|
942 | return rtFsIsoMakerCmdSyntaxError(pOpts, "UDF support is currently not implemented");
|
---|
943 | #endif
|
---|
944 | }
|
---|
945 | else if (IS_EQUAL("hfs") || IS_EQUAL("hfsplus"))
|
---|
946 | {
|
---|
947 | #if 0
|
---|
948 | fNameSpecifier |= RTFSISOMAKERCMDNAME_HFS;
|
---|
949 | fNamespaces |= fPrevMajor = RTFSISOMAKER_NAMESPACE_HFS;
|
---|
950 | #else
|
---|
951 | return rtFsIsoMakerCmdSyntaxError(pOpts, "Hybrid HFS+ support is currently not implemented");
|
---|
952 | #endif
|
---|
953 | }
|
---|
954 | /* rock ridge */
|
---|
955 | else if ( IS_EQUAL("rr")
|
---|
956 | || IS_EQUAL("rock")
|
---|
957 | || IS_EQUAL("rock-ridge"))
|
---|
958 | {
|
---|
959 | if (fPrevMajor == RTFSISOMAKERCMDNAME_PRIMARY_ISO)
|
---|
960 | fNameSpecifier |= RTFSISOMAKERCMDNAME_PRIMARY_ISO_ROCK_RIDGE;
|
---|
961 | else if (fPrevMajor == RTFSISOMAKERCMDNAME_JOLIET)
|
---|
962 | fNameSpecifier |= RTFSISOMAKERCMDNAME_JOLIET_ROCK_RIDGE;
|
---|
963 | else
|
---|
964 | return rtFsIsoMakerCmdSyntaxError(pOpts, "unqualified rock-ridge name specifier");
|
---|
965 | }
|
---|
966 | else if ( IS_EQUAL("iso-rr") || IS_EQUAL("iso-rock") || IS_EQUAL("iso-rock-ridge")
|
---|
967 | || IS_EQUAL("primary-rr") || IS_EQUAL("primary-rock") || IS_EQUAL("primary-rock-ridge")
|
---|
968 | || IS_EQUAL("iso9660-rr") || IS_EQUAL("iso9660-rock") || IS_EQUAL("iso9660-rock-ridge")
|
---|
969 | || IS_EQUAL("iso-9660-rr") || IS_EQUAL("iso-9660-rock") || IS_EQUAL("iso-9660-rock-ridge")
|
---|
970 | || IS_EQUAL("primaryiso-rr") || IS_EQUAL("primaryiso-rock") || IS_EQUAL("primaryiso-rock-ridge")
|
---|
971 | || IS_EQUAL("primary-iso-rr") || IS_EQUAL("primary-iso-rock") || IS_EQUAL("primary-iso-rock-ridge") )
|
---|
972 | {
|
---|
973 | fNameSpecifier |= RTFSISOMAKERCMDNAME_PRIMARY_ISO_ROCK_RIDGE;
|
---|
974 | if (!(fNamespaces & RTFSISOMAKERCMDNAME_PRIMARY_ISO))
|
---|
975 | return rtFsIsoMakerCmdSyntaxError(pOpts, "iso-9660-rock-ridge must come after the iso-9660 name specifier");
|
---|
976 | }
|
---|
977 | else if (IS_EQUAL("joliet-rr") || IS_EQUAL("joliet-rock") || IS_EQUAL("joliet-rock-ridge"))
|
---|
978 | {
|
---|
979 | fNameSpecifier |= RTFSISOMAKERCMDNAME_JOLIET_ROCK_RIDGE;
|
---|
980 | if (!(fNamespaces & RTFSISOMAKERCMDNAME_JOLIET))
|
---|
981 | return rtFsIsoMakerCmdSyntaxError(pOpts, "joliet-rock-ridge must come after the joliet name specifier");
|
---|
982 | }
|
---|
983 | /* trans.tbl */
|
---|
984 | else if (IS_EQUAL("trans") || IS_EQUAL("trans-tbl"))
|
---|
985 | {
|
---|
986 | if (fPrevMajor == RTFSISOMAKERCMDNAME_PRIMARY_ISO)
|
---|
987 | fNameSpecifier |= RTFSISOMAKERCMDNAME_PRIMARY_ISO_TRANS_TBL;
|
---|
988 | else if (fPrevMajor == RTFSISOMAKERCMDNAME_JOLIET)
|
---|
989 | fNameSpecifier |= RTFSISOMAKERCMDNAME_JOLIET_TRANS_TBL;
|
---|
990 | else
|
---|
991 | return rtFsIsoMakerCmdSyntaxError(pOpts, "unqualified trans-tbl name specifier");
|
---|
992 | }
|
---|
993 | else if ( IS_EQUAL("iso-trans") || IS_EQUAL("iso-trans-tbl")
|
---|
994 | || IS_EQUAL("primary-trans") || IS_EQUAL("primary-trans-tbl")
|
---|
995 | || IS_EQUAL("iso9660-trans") || IS_EQUAL("iso9660-trans-tbl")
|
---|
996 | || IS_EQUAL("iso-9660-trans") || IS_EQUAL("iso-9660-trans-tbl")
|
---|
997 | || IS_EQUAL("primaryiso-trans") || IS_EQUAL("primaryiso-trans-tbl")
|
---|
998 | || IS_EQUAL("primary-iso-trans") || IS_EQUAL("primary-iso-trans-tbl") )
|
---|
999 | {
|
---|
1000 | fNameSpecifier |= RTFSISOMAKERCMDNAME_PRIMARY_ISO_TRANS_TBL;
|
---|
1001 | if (!(fNamespaces & RTFSISOMAKERCMDNAME_PRIMARY_ISO))
|
---|
1002 | return rtFsIsoMakerCmdSyntaxError(pOpts, "iso-9660-trans-tbl must come after the iso-9660 name specifier");
|
---|
1003 | }
|
---|
1004 | else if (IS_EQUAL("joliet-trans") || IS_EQUAL("joliet-trans-tbl"))
|
---|
1005 | {
|
---|
1006 | fNameSpecifier |= RTFSISOMAKERCMDNAME_JOLIET_TRANS_TBL;
|
---|
1007 | if (!(fNamespaces & RTFSISOMAKERCMDNAME_JOLIET))
|
---|
1008 | return rtFsIsoMakerCmdSyntaxError(pOpts, "joliet-trans-tbl must come after the joliet name specifier");
|
---|
1009 | }
|
---|
1010 | else if (IS_EQUAL("udf-trans") || IS_EQUAL("udf-trans-tbl"))
|
---|
1011 | {
|
---|
1012 | fNameSpecifier |= RTFSISOMAKERCMDNAME_UDF_TRANS_TBL;
|
---|
1013 | if (!(fNamespaces & RTFSISOMAKERCMDNAME_UDF))
|
---|
1014 | return rtFsIsoMakerCmdSyntaxError(pOpts, "udf-trans-tbl must come after the udf name specifier");
|
---|
1015 | }
|
---|
1016 | else if (IS_EQUAL("hfs-trans") || IS_EQUAL("hfs-trans-tbl"))
|
---|
1017 | {
|
---|
1018 | fNameSpecifier |= RTFSISOMAKERCMDNAME_HFS_TRANS_TBL;
|
---|
1019 | if (!(fNamespaces & RTFSISOMAKERCMDNAME_HFS))
|
---|
1020 | return rtFsIsoMakerCmdSyntaxError(pOpts, "hfs-trans-tbl must come after the hfs name specifier");
|
---|
1021 | }
|
---|
1022 | else
|
---|
1023 | return rtFsIsoMakerCmdSyntaxError(pOpts, "unknown name specifier '%.*s'", cchName, pchName);
|
---|
1024 | #undef IS_EQUAL
|
---|
1025 | offSpec = offEndSpec;
|
---|
1026 | }
|
---|
1027 | } /* while same specifier */
|
---|
1028 |
|
---|
1029 | /*
|
---|
1030 | * Check that it wasn't empty.
|
---|
1031 | */
|
---|
1032 | if (fNameSpecifier == 0)
|
---|
1033 | return rtFsIsoMakerCmdSyntaxError(pOpts, "name specifier #%u (0-based) is empty ", iNameSpecifier);
|
---|
1034 |
|
---|
1035 | /*
|
---|
1036 | * Complain if a major namespace name is duplicated. The rock-ridge and
|
---|
1037 | * trans.tbl names are simple to replace, the others affect the two former
|
---|
1038 | * names and are therefore not allowed twice in the list.
|
---|
1039 | */
|
---|
1040 | uint32_t i = iNameSpecifier;
|
---|
1041 | while (i-- > 0)
|
---|
1042 | {
|
---|
1043 | uint32_t fRepeated = (fNameSpecifier & RTFSISOMAKERCMDNAME_MAJOR_MASK)
|
---|
1044 | & (pOpts->afNameSpecifiers[i] & RTFSISOMAKERCMDNAME_MAJOR_MASK);
|
---|
1045 | if (fRepeated)
|
---|
1046 | {
|
---|
1047 | char szTmp[128];
|
---|
1048 | return rtFsIsoMakerCmdSyntaxError(pOpts, "repeating name specifier%s: %s", RT_IS_POWER_OF_TWO(fRepeated) ? "" : "s",
|
---|
1049 | rtFsIsoMakerCmdNameSpecifiersToString(fRepeated, szTmp, sizeof(szTmp)));
|
---|
1050 | }
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | /*
|
---|
1054 | * Add it.
|
---|
1055 | */
|
---|
1056 | if (iNameSpecifier >= RT_ELEMENTS(pOpts->afNameSpecifiers))
|
---|
1057 | return rtFsIsoMakerCmdSyntaxError(pOpts, "too many name specifiers (max %d)", RT_ELEMENTS(pOpts->afNameSpecifiers));
|
---|
1058 | pOpts->afNameSpecifiers[iNameSpecifier] = fNameSpecifier;
|
---|
1059 | iNameSpecifier++;
|
---|
1060 |
|
---|
1061 | /*
|
---|
1062 | * Next, if any.
|
---|
1063 | */
|
---|
1064 | if (pszSpec[offSpec] == ',')
|
---|
1065 | offSpec++;
|
---|
1066 | } while (pszSpec[offSpec] != '\0');
|
---|
1067 |
|
---|
1068 | pOpts->cNameSpecifiers = iNameSpecifier;
|
---|
1069 | pOpts->fDstNamespaces = fNamespaces;
|
---|
1070 |
|
---|
1071 | return VINF_SUCCESS;
|
---|
1072 | }
|
---|
1073 |
|
---|
1074 |
|
---|
1075 | /**
|
---|
1076 | * Processes a non-option argument.
|
---|
1077 | *
|
---|
1078 | * @returns IPRT status code.
|
---|
1079 | * @param pOpts The ISO maker command instance.
|
---|
1080 | * @param pszSpec The specification of what to add.
|
---|
1081 | * @param fWithSrc Whether the specification includes a source path
|
---|
1082 | * or not.
|
---|
1083 | * @param pParsed Where to return the parsed name specification.
|
---|
1084 | */
|
---|
1085 | static int rtFsIsoMakerCmdParseNameSpec(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSpec, bool fWithSrc,
|
---|
1086 | PRTFSISOMKCMDPARSEDNAMES pParsed)
|
---|
1087 | {
|
---|
1088 | const char * const pszSpecIn = pszSpec;
|
---|
1089 | uint32_t const cMaxNames = pOpts->cNameSpecifiers + fWithSrc;
|
---|
1090 |
|
---|
1091 | /*
|
---|
1092 | * Split it up by '='.
|
---|
1093 | */
|
---|
1094 | pParsed->cNames = 0;
|
---|
1095 | pParsed->cNamesWithSrc = 0;
|
---|
1096 | pParsed->enmSrcType = fWithSrc ? RTFSISOMKCMDPARSEDNAMES::kSrcType_Normal : RTFSISOMKCMDPARSEDNAMES::kSrcType_None;
|
---|
1097 | for (;;)
|
---|
1098 | {
|
---|
1099 | const char *pszEqual = strchr(pszSpec, '=');
|
---|
1100 | size_t cchName = pszEqual ? pszEqual - pszSpec : strlen(pszSpec);
|
---|
1101 | bool fNeedSlash = (pszEqual || !fWithSrc) && !RTPATH_IS_SLASH(*pszSpec) && cchName > 0;
|
---|
1102 | if (cchName + fNeedSlash >= sizeof(pParsed->aNames[pParsed->cNamesWithSrc].szPath))
|
---|
1103 | return rtFsIsoMakerCmdSyntaxError(pOpts, "name #%u (0-based) is too long: %s", pParsed->cNamesWithSrc, pszSpecIn);
|
---|
1104 | if (pParsed->cNamesWithSrc >= cMaxNames)
|
---|
1105 | return rtFsIsoMakerCmdSyntaxError(pOpts, "too many names specified (max %u%s): %s",
|
---|
1106 | pOpts->cNameSpecifiers, fWithSrc ? " + source" : "", pszSpecIn);
|
---|
1107 | if (!fNeedSlash)
|
---|
1108 | memcpy(pParsed->aNames[pParsed->cNamesWithSrc].szPath, pszSpec, cchName);
|
---|
1109 | else
|
---|
1110 | {
|
---|
1111 | memcpy(&pParsed->aNames[pParsed->cNamesWithSrc].szPath[1], pszSpec, cchName);
|
---|
1112 | pParsed->aNames[pParsed->cNamesWithSrc].szPath[0] = RTPATH_SLASH;
|
---|
1113 | cchName++;
|
---|
1114 | }
|
---|
1115 | pParsed->aNames[pParsed->cNamesWithSrc].szPath[cchName] = '\0';
|
---|
1116 | pParsed->aNames[pParsed->cNamesWithSrc].cchPath = (uint32_t)cchName;
|
---|
1117 | pParsed->cNamesWithSrc++;
|
---|
1118 |
|
---|
1119 | if (!pszEqual)
|
---|
1120 | {
|
---|
1121 | if (fWithSrc)
|
---|
1122 | {
|
---|
1123 | if (!cchName)
|
---|
1124 | return rtFsIsoMakerCmdSyntaxError(pOpts, "empty source file name: %s", pszSpecIn);
|
---|
1125 | if (cchName == 8 && strcmp(pszSpec, ":remove:") == 0)
|
---|
1126 | pParsed->enmSrcType = RTFSISOMKCMDPARSEDNAMES::kSrcType_Remove;
|
---|
1127 | else if (cchName == 13 && strcmp(pszSpec, ":must-remove:") == 0)
|
---|
1128 | pParsed->enmSrcType = RTFSISOMKCMDPARSEDNAMES::kSrcType_MustRemove;
|
---|
1129 | }
|
---|
1130 | break;
|
---|
1131 | }
|
---|
1132 | pszSpec = pszEqual + 1;
|
---|
1133 | }
|
---|
1134 |
|
---|
1135 | /*
|
---|
1136 | * If there are too few names specified, move the source and repeat the
|
---|
1137 | * last non-source name. If only source, convert source into a name spec.
|
---|
1138 | */
|
---|
1139 | if (pParsed->cNamesWithSrc < cMaxNames)
|
---|
1140 | {
|
---|
1141 | uint32_t iSrc;
|
---|
1142 | if (!fWithSrc)
|
---|
1143 | iSrc = pParsed->cNamesWithSrc - 1;
|
---|
1144 | else
|
---|
1145 | {
|
---|
1146 | pParsed->aNames[pOpts->cNameSpecifiers] = pParsed->aNames[pParsed->cNamesWithSrc - 1];
|
---|
1147 | iSrc = pParsed->cNamesWithSrc >= 2 ? pParsed->cNamesWithSrc - 2 : 0;
|
---|
1148 | }
|
---|
1149 |
|
---|
1150 | /* If the source is a input file name specifier, reduce it to something that starts with a slash. */
|
---|
1151 | if (pParsed->cNamesWithSrc == 1 && fWithSrc)
|
---|
1152 | {
|
---|
1153 | if (RTVfsChainIsSpec(pParsed->aNames[iSrc].szPath))
|
---|
1154 | {
|
---|
1155 | uint32_t offError;
|
---|
1156 | char *pszFinalPath;
|
---|
1157 | int rc = RTVfsChainQueryFinalPath(pParsed->aNames[iSrc].szPath, &pszFinalPath, &offError);
|
---|
1158 | if (RT_FAILURE(rc))
|
---|
1159 | return rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainQueryFinalPath",
|
---|
1160 | pParsed->aNames[iSrc].szPath, rc, offError, NULL);
|
---|
1161 | pParsed->aNames[iSrc].cchPath = (uint32_t)strlen(pszFinalPath);
|
---|
1162 | if (RTPATH_IS_SLASH(*pszFinalPath))
|
---|
1163 | memcpy(pParsed->aNames[iSrc].szPath, pszFinalPath, pParsed->aNames[iSrc].cchPath + 1);
|
---|
1164 | else
|
---|
1165 | {
|
---|
1166 | memcpy(&pParsed->aNames[iSrc].szPath[1], pszFinalPath, pParsed->aNames[iSrc].cchPath + 1);
|
---|
1167 | pParsed->aNames[iSrc].szPath[0] = RTPATH_SLASH;
|
---|
1168 | pParsed->aNames[iSrc].cchPath++;
|
---|
1169 | }
|
---|
1170 | RTStrFree(pszFinalPath);
|
---|
1171 | }
|
---|
1172 | #if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
|
---|
1173 | else if ( RTPATH_IS_VOLSEP(pParsed->aNames[iSrc].szPath[1])
|
---|
1174 | && RT_C_IS_ALPHA(pParsed->aNames[iSrc].szPath[0]))
|
---|
1175 | {
|
---|
1176 | if (RTPATH_IS_SLASH(pParsed->aNames[iSrc].szPath[2]))
|
---|
1177 | {
|
---|
1178 | memmove(&pParsed->aNames[iSrc].szPath[0], &pParsed->aNames[iSrc].szPath[2], pParsed->aNames[iSrc].cchPath - 1);
|
---|
1179 | pParsed->aNames[iSrc].cchPath -= 2;
|
---|
1180 | }
|
---|
1181 | else
|
---|
1182 | {
|
---|
1183 | memmove(&pParsed->aNames[iSrc].szPath[1], &pParsed->aNames[iSrc].szPath[2], pParsed->aNames[iSrc].cchPath - 1);
|
---|
1184 | pParsed->aNames[iSrc].szPath[0] = RTPATH_SLASH;
|
---|
1185 | pParsed->aNames[iSrc].cchPath -= 1;
|
---|
1186 | }
|
---|
1187 | }
|
---|
1188 | #endif
|
---|
1189 | else if (!RTPATH_IS_SLASH(pParsed->aNames[iSrc].szPath[0]))
|
---|
1190 | {
|
---|
1191 | if (pParsed->aNames[iSrc].cchPath + 2 > sizeof(pParsed->aNames[iSrc].szPath))
|
---|
1192 | return rtFsIsoMakerCmdSyntaxError(pOpts, "name too long: %s", pszSpecIn);
|
---|
1193 | memmove(&pParsed->aNames[iSrc].szPath[1], &pParsed->aNames[iSrc].szPath[0], pParsed->aNames[iSrc].cchPath + 1);
|
---|
1194 | pParsed->aNames[iSrc].szPath[0] = RTPATH_SLASH;
|
---|
1195 | pParsed->aNames[iSrc].cchPath++;
|
---|
1196 | }
|
---|
1197 | }
|
---|
1198 |
|
---|
1199 | for (uint32_t iDst = iSrc + 1; iDst < pOpts->cNameSpecifiers; iDst++)
|
---|
1200 | pParsed->aNames[iDst] = pParsed->aNames[iSrc];
|
---|
1201 |
|
---|
1202 | pParsed->cNamesWithSrc = cMaxNames;
|
---|
1203 | }
|
---|
1204 | pParsed->cNames = pOpts->cNameSpecifiers;
|
---|
1205 |
|
---|
1206 | /*
|
---|
1207 | * Copy the specifier flags and check that the paths all starts with slashes.
|
---|
1208 | */
|
---|
1209 | for (uint32_t i = 0; i < pOpts->cNameSpecifiers; i++)
|
---|
1210 | {
|
---|
1211 | pParsed->aNames[i].fNameSpecifiers = pOpts->afNameSpecifiers[i];
|
---|
1212 | Assert( pParsed->aNames[i].cchPath == 0
|
---|
1213 | || RTPATH_IS_SLASH(pParsed->aNames[i].szPath[0]));
|
---|
1214 | }
|
---|
1215 |
|
---|
1216 | return VINF_SUCCESS;
|
---|
1217 | }
|
---|
1218 |
|
---|
1219 |
|
---|
1220 | /**
|
---|
1221 | * Enteres an object into the namespace by full paths.
|
---|
1222 | *
|
---|
1223 | * This is used by rtFsIsoMakerCmdOptEltoritoSetBootCatalogPath and
|
---|
1224 | * rtFsIsoMakerCmdAddFile.
|
---|
1225 | *
|
---|
1226 | * @returns IPRT status code.
|
---|
1227 | * @param pOpts The ISO maker command instance.
|
---|
1228 | * @param idxObj The configuration index of the object to be named.
|
---|
1229 | * @param pParsed The parsed names.
|
---|
1230 | * @param pszSrcOrName Source file or name.
|
---|
1231 | */
|
---|
1232 | static int rtFsIsoMakerCmdSetObjPaths(PRTFSISOMAKERCMDOPTS pOpts, uint32_t idxObj, PCRTFSISOMKCMDPARSEDNAMES pParsed,
|
---|
1233 | const char *pszSrcOrName)
|
---|
1234 | {
|
---|
1235 | int rc = VINF_SUCCESS;
|
---|
1236 | for (uint32_t i = 0; i < pParsed->cNames; i++)
|
---|
1237 | if (pParsed->aNames[i].cchPath > 0)
|
---|
1238 | {
|
---|
1239 | if (pParsed->aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK)
|
---|
1240 | {
|
---|
1241 | rc = RTFsIsoMakerObjSetPath(pOpts->hIsoMaker, idxObj,
|
---|
1242 | pParsed->aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK,
|
---|
1243 | pParsed->aNames[i].szPath);
|
---|
1244 | if (RT_FAILURE(rc))
|
---|
1245 | {
|
---|
1246 | rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error setting name '%s' on '%s': %Rrc",
|
---|
1247 | pParsed->aNames[i].szPath, pszSrcOrName, rc);
|
---|
1248 | break;
|
---|
1249 | }
|
---|
1250 | }
|
---|
1251 | if (pParsed->aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MINOR_MASK)
|
---|
1252 | {
|
---|
1253 | /** @todo add APIs for this. */
|
---|
1254 | }
|
---|
1255 | }
|
---|
1256 | return rc;
|
---|
1257 | }
|
---|
1258 |
|
---|
1259 |
|
---|
1260 | /**
|
---|
1261 | * Adds a file.
|
---|
1262 | *
|
---|
1263 | * @returns IPRT status code.
|
---|
1264 | * @param pOpts The ISO maker command instance.
|
---|
1265 | * @param pszSrc The path to the source file.
|
---|
1266 | * @param pParsed The parsed names.
|
---|
1267 | * @param pidxObj Where to return the configuration index for the
|
---|
1268 | * added file. Optional.
|
---|
1269 | */
|
---|
1270 | static int rtFsIsoMakerCmdAddFile(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSrc, PCRTFSISOMKCMDPARSEDNAMES pParsed,
|
---|
1271 | uint32_t *pidxObj)
|
---|
1272 | {
|
---|
1273 | uint32_t idxObj;
|
---|
1274 | int rc = RTFsIsoMakerAddUnnamedFileWithSrcPath(pOpts->hIsoMaker, pszSrc, &idxObj);
|
---|
1275 | if (RT_SUCCESS(rc))
|
---|
1276 | {
|
---|
1277 | pOpts->cItemsAdded++;
|
---|
1278 | if (pidxObj)
|
---|
1279 | *pidxObj = idxObj;
|
---|
1280 |
|
---|
1281 | rc = rtFsIsoMakerCmdSetObjPaths(pOpts, idxObj, pParsed, pszSrc);
|
---|
1282 | }
|
---|
1283 | else
|
---|
1284 | rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error adding '%s': %Rrc", pszSrc, rc);
|
---|
1285 | return rc;
|
---|
1286 | }
|
---|
1287 |
|
---|
1288 |
|
---|
1289 | /**
|
---|
1290 | * Adds a file after first making sure it's a file.
|
---|
1291 | *
|
---|
1292 | * @returns IPRT status code
|
---|
1293 | * @param pOpts The ISO maker command instance.
|
---|
1294 | * @param pszSrc The path to the source file.
|
---|
1295 | * @param pParsed The parsed names.
|
---|
1296 | * @param pidxObj Where to return the configuration index for the
|
---|
1297 | * added file. Optional.
|
---|
1298 | */
|
---|
1299 | static int rtFsIsoMakerCmdStatAndAddFile(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSrc, PCRTFSISOMKCMDPARSEDNAMES pParsed,
|
---|
1300 | uint32_t *pidxObj)
|
---|
1301 | {
|
---|
1302 | RTFSOBJINFO ObjInfo;
|
---|
1303 | uint32_t offError;
|
---|
1304 | RTERRINFOSTATIC ErrInfo;
|
---|
1305 | int rc = RTVfsChainQueryInfo(pszSrc, &ObjInfo, RTFSOBJATTRADD_UNIX,
|
---|
1306 | RTPATH_F_FOLLOW_LINK, &offError, RTErrInfoInitStatic(&ErrInfo));
|
---|
1307 | if (RT_FAILURE(rc))
|
---|
1308 | return rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainQueryInfo", pszSrc, rc, offError, &ErrInfo.Core);
|
---|
1309 |
|
---|
1310 | if (RTFS_IS_FILE(ObjInfo.Attr.fMode))
|
---|
1311 | return rtFsIsoMakerCmdAddFile(pOpts, pszSrc, pParsed, pidxObj);
|
---|
1312 | return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_A_FILE, "Not a file: %s", pszSrc);
|
---|
1313 | }
|
---|
1314 |
|
---|
1315 |
|
---|
1316 | /**
|
---|
1317 | * Processes a non-option argument.
|
---|
1318 | *
|
---|
1319 | * @returns IPRT status code.
|
---|
1320 | * @param pOpts The ISO maker command instance.
|
---|
1321 | * @param pszSpec The specification of what to add.
|
---|
1322 | */
|
---|
1323 | static int rtFsIsoMakerCmdAddSomething(PRTFSISOMAKERCMDOPTS pOpts, const char *pszSpec)
|
---|
1324 | {
|
---|
1325 | /*
|
---|
1326 | * Parse the name spec.
|
---|
1327 | */
|
---|
1328 | RTFSISOMKCMDPARSEDNAMES Parsed;
|
---|
1329 | int rc = rtFsIsoMakerCmdParseNameSpec(pOpts, pszSpec, true /*fWithSrc*/, &Parsed);
|
---|
1330 | if (RT_FAILURE(rc))
|
---|
1331 | return rc;
|
---|
1332 |
|
---|
1333 | /*
|
---|
1334 | * Deal with special source filenames used to remove/change stuff.
|
---|
1335 | */
|
---|
1336 | if ( Parsed.enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_Remove
|
---|
1337 | || Parsed.enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_MustRemove)
|
---|
1338 | {
|
---|
1339 | const char *pszFirstNm = NULL;
|
---|
1340 | uint32_t cRemoved = 0;
|
---|
1341 | for (uint32_t i = 0; i < pOpts->cNameSpecifiers; i++)
|
---|
1342 | if ( Parsed.aNames[i].cchPath > 0
|
---|
1343 | && (Parsed.aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK))
|
---|
1344 | {
|
---|
1345 | pszFirstNm = Parsed.aNames[i].szPath;
|
---|
1346 | uint32_t idxObj = RTFsIsoMakerGetObjIdxForPath(pOpts->hIsoMaker,
|
---|
1347 | Parsed.aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK,
|
---|
1348 | Parsed.aNames[i].szPath);
|
---|
1349 | if (idxObj != UINT32_MAX)
|
---|
1350 | {
|
---|
1351 | rc = RTFsIsoMakerObjRemove(pOpts->hIsoMaker, idxObj);
|
---|
1352 | if (RT_FAILURE(rc))
|
---|
1353 | return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to remove '%s': %Rrc", pszSpec, rc);
|
---|
1354 | cRemoved++;
|
---|
1355 | }
|
---|
1356 | }
|
---|
1357 | if ( Parsed.enmSrcType == RTFSISOMKCMDPARSEDNAMES::kSrcType_MustRemove
|
---|
1358 | && cRemoved == 0)
|
---|
1359 | return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_FOUND, "Failed to locate '%s' for removal", pszSpec);
|
---|
1360 | }
|
---|
1361 | /*
|
---|
1362 | * Add regular source.
|
---|
1363 | */
|
---|
1364 | else
|
---|
1365 | {
|
---|
1366 | const char *pszSrc = Parsed.aNames[Parsed.cNamesWithSrc - 1].szPath;
|
---|
1367 | RTFSOBJINFO ObjInfo;
|
---|
1368 | uint32_t offError;
|
---|
1369 | RTERRINFOSTATIC ErrInfo;
|
---|
1370 | rc = RTVfsChainQueryInfo(pszSrc, &ObjInfo, RTFSOBJATTRADD_UNIX,
|
---|
1371 | RTPATH_F_FOLLOW_LINK, &offError, RTErrInfoInitStatic(&ErrInfo));
|
---|
1372 | if (RT_FAILURE(rc))
|
---|
1373 | return rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainQueryInfo", pszSrc, rc, offError, &ErrInfo.Core);
|
---|
1374 |
|
---|
1375 | if (RTFS_IS_FILE(ObjInfo.Attr.fMode))
|
---|
1376 | return rtFsIsoMakerCmdAddFile(pOpts, pszSrc, &Parsed, NULL /*pidxObj*/);
|
---|
1377 |
|
---|
1378 | if (RTFS_IS_DIRECTORY(ObjInfo.Attr.fMode))
|
---|
1379 | return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_IMPLEMENTED, "Adding directory '%s' failed: not implemented", pszSpec);
|
---|
1380 |
|
---|
1381 | if (RTFS_IS_SYMLINK(ObjInfo.Attr.fMode))
|
---|
1382 | return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_IMPLEMENTED, "Adding symlink '%s' failed: not implemented", pszSpec);
|
---|
1383 |
|
---|
1384 | return rtFsIsoMakerCmdErrorRc(pOpts, VERR_NOT_IMPLEMENTED, "Adding special file '%s' failed: not implemented", pszSpec);
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 | return VINF_SUCCESS;
|
---|
1388 | }
|
---|
1389 |
|
---|
1390 |
|
---|
1391 | /**
|
---|
1392 | * Deals with the --import-iso {iso-file-spec} options.
|
---|
1393 | *
|
---|
1394 | * @returns IPRT status code
|
---|
1395 | * @param pOpts The ISO maker command instance.
|
---|
1396 | * @param pszIsoSpec The ISO path specifier.
|
---|
1397 | */
|
---|
1398 | static int rtFsIsoMakerCmdOptImportIso(PRTFSISOMAKERCMDOPTS pOpts, const char *pszIsoSpec)
|
---|
1399 | {
|
---|
1400 | RTFSISOMAKERIMPORTRESULTS Results;
|
---|
1401 | RTERRINFOSTATIC ErrInfo;
|
---|
1402 | int rc = RTFsIsoMakerImport(pOpts->hIsoMaker, pszIsoSpec, 0 /*fFlags*/, &Results, RTErrInfoInitStatic(&ErrInfo));
|
---|
1403 |
|
---|
1404 | pOpts->cItemsAdded += Results.cAddedFiles;
|
---|
1405 | pOpts->cItemsAdded += Results.cAddedDirs;
|
---|
1406 | pOpts->cItemsAdded += Results.cBootCatEntries;
|
---|
1407 | pOpts->cItemsAdded += Results.cbSysArea != 0 ? 1 : 0;
|
---|
1408 |
|
---|
1409 | rtFsIsoMakerPrintf(pOpts, "ISO imported statistics for '%s'\n", pszIsoSpec);
|
---|
1410 | rtFsIsoMakerPrintf(pOpts, " cAddedNames: %'14RU32\n", Results.cAddedNames);
|
---|
1411 | rtFsIsoMakerPrintf(pOpts, " cAddedDirs: %'14RU32\n", Results.cAddedDirs);
|
---|
1412 | rtFsIsoMakerPrintf(pOpts, " cbAddedDataBlocks: %'14RU64 bytes\n", Results.cbAddedDataBlocks);
|
---|
1413 | rtFsIsoMakerPrintf(pOpts, " cAddedFiles: %'14RU32\n", Results.cAddedFiles);
|
---|
1414 | if (Results.cBootCatEntries == UINT32_MAX)
|
---|
1415 | rtFsIsoMakerPrintf(pOpts, " cBootCatEntries: none\n");
|
---|
1416 | else
|
---|
1417 | rtFsIsoMakerPrintf(pOpts, " cBootCatEntries: %'14RU32\n", Results.cBootCatEntries);
|
---|
1418 | rtFsIsoMakerPrintf(pOpts, " cbSysArea: %'14RU32\n", Results.cbSysArea);
|
---|
1419 | rtFsIsoMakerPrintf(pOpts, " cErrors: %'14RU32\n", Results.cErrors);
|
---|
1420 |
|
---|
1421 | if (RT_SUCCESS(rc))
|
---|
1422 | return rc;
|
---|
1423 | if (Results.offError != UINT32_MAX)
|
---|
1424 | return rtFsIsoMakerCmdChainError(pOpts, "RTFsIsoMakerImport", pszIsoSpec, rc, Results.offError, &ErrInfo.Core);
|
---|
1425 | if (RTErrInfoIsSet(&ErrInfo.Core))
|
---|
1426 | return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerImport failed: %Rrc - %s", rc, ErrInfo.Core.pszMsg);
|
---|
1427 | return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerImport failed: %Rrc", rc);
|
---|
1428 | }
|
---|
1429 |
|
---|
1430 |
|
---|
1431 | /**
|
---|
1432 | * Deals with: -G|--generic-boot {file}
|
---|
1433 | *
|
---|
1434 | * This concers content the first 16 sectors of the image. We start loading the
|
---|
1435 | * file at byte 0 in the image and stops at 32KB.
|
---|
1436 | *
|
---|
1437 | * @returns IPRT status code
|
---|
1438 | * @param pOpts The ISO maker command instance.
|
---|
1439 | * @param pszGenericBootImage The generic boot image source.
|
---|
1440 | */
|
---|
1441 | static int rtFsIsoMakerCmdOptGenericBoot(PRTFSISOMAKERCMDOPTS pOpts, const char *pszGenericBootImage)
|
---|
1442 | {
|
---|
1443 | RTERRINFOSTATIC ErrInfo;
|
---|
1444 | uint32_t offError;
|
---|
1445 | RTVFSFILE hVfsFile;
|
---|
1446 | int rc = RTVfsChainOpenFile(pszGenericBootImage, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsFile,
|
---|
1447 | &offError, RTErrInfoInitStatic(&ErrInfo));
|
---|
1448 | if (RT_FAILURE(rc))
|
---|
1449 | return rtFsIsoMakerCmdChainError(pOpts, "RTVfsChainOpenFile", pszGenericBootImage, rc, offError, &ErrInfo.Core);
|
---|
1450 |
|
---|
1451 | uint8_t abBuf[_32K];
|
---|
1452 | size_t cbRead;
|
---|
1453 | rc = RTVfsFileReadAt(hVfsFile, 0, abBuf, sizeof(abBuf), &cbRead);
|
---|
1454 | RTVfsFileRelease(hVfsFile);
|
---|
1455 | if (RT_FAILURE(rc))
|
---|
1456 | return rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error reading 32KB from generic boot image '%s': %Rrc", pszGenericBootImage, rc);
|
---|
1457 |
|
---|
1458 | rc = RTFsIsoMakerSetSysAreaContent(pOpts->hIsoMaker, abBuf, cbRead, 0);
|
---|
1459 | if (RT_FAILURE(rc))
|
---|
1460 | return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerSetSysAreaContent failed with a %zu bytes input: %Rrc", cbRead, rc);
|
---|
1461 |
|
---|
1462 | return VINF_SUCCESS;
|
---|
1463 | }
|
---|
1464 |
|
---|
1465 |
|
---|
1466 | /**
|
---|
1467 | * Helper that makes sure we've got a validation boot entry.
|
---|
1468 | *
|
---|
1469 | * @returns IPRT status code
|
---|
1470 | * @param pOpts The ISO maker command instance.
|
---|
1471 | */
|
---|
1472 | static void rtFsIsoMakerCmdOptEltoritoEnsureValidationEntry(PRTFSISOMAKERCMDOPTS pOpts)
|
---|
1473 | {
|
---|
1474 | if (pOpts->cBootCatEntries == 0)
|
---|
1475 | {
|
---|
1476 | pOpts->aBootCatEntries[0].enmType = RTFSISOMKCMDELTORITOENTRY::kEntryType_Validation;
|
---|
1477 | pOpts->aBootCatEntries[0].u.Validation.idPlatform = ISO9660_ELTORITO_PLATFORM_ID_X86;
|
---|
1478 | pOpts->aBootCatEntries[0].u.Validation.pszString = NULL;
|
---|
1479 | pOpts->cBootCatEntries = 1;
|
---|
1480 | }
|
---|
1481 | }
|
---|
1482 |
|
---|
1483 |
|
---|
1484 | /**
|
---|
1485 | * Helper that makes sure we've got a current boot entry.
|
---|
1486 | *
|
---|
1487 | * @returns IPRT status code
|
---|
1488 | * @param pOpts The ISO maker command instance.
|
---|
1489 | * @param fForceNew Whether to force a new entry.
|
---|
1490 | * @param pidxBootCat Where to return the boot catalog index.
|
---|
1491 | */
|
---|
1492 | static int rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(PRTFSISOMAKERCMDOPTS pOpts, bool fForceNew, uint32_t *pidxBootCat)
|
---|
1493 | {
|
---|
1494 | rtFsIsoMakerCmdOptEltoritoEnsureValidationEntry(pOpts);
|
---|
1495 |
|
---|
1496 | uint32_t i = pOpts->cBootCatEntries;
|
---|
1497 | if (i == 2 && fForceNew)
|
---|
1498 | {
|
---|
1499 | pOpts->aBootCatEntries[i].enmType = RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader;
|
---|
1500 | pOpts->aBootCatEntries[i].u.SectionHeader.idPlatform = pOpts->aBootCatEntries[0].u.Validation.idPlatform;
|
---|
1501 | pOpts->aBootCatEntries[i].u.SectionHeader.pszString = NULL;
|
---|
1502 | pOpts->cBootCatEntries = ++i;
|
---|
1503 | }
|
---|
1504 |
|
---|
1505 | if ( i == 1
|
---|
1506 | || fForceNew
|
---|
1507 | || pOpts->aBootCatEntries[i - 1].enmType == RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader)
|
---|
1508 | {
|
---|
1509 | if (i >= RT_ELEMENTS(pOpts->aBootCatEntries))
|
---|
1510 | {
|
---|
1511 | *pidxBootCat = UINT32_MAX;
|
---|
1512 | return rtFsIsoMakerCmdErrorRc(pOpts, VERR_BUFFER_OVERFLOW, "Too many boot catalog entries");
|
---|
1513 | }
|
---|
1514 |
|
---|
1515 | pOpts->aBootCatEntries[i].enmType = i == 1 ? RTFSISOMKCMDELTORITOENTRY::kEntryType_Default
|
---|
1516 | : RTFSISOMKCMDELTORITOENTRY::kEntryType_Section;
|
---|
1517 | pOpts->aBootCatEntries[i].u.Section.pszImageNameInIso = NULL;
|
---|
1518 | pOpts->aBootCatEntries[i].u.Section.idxImageObj = UINT32_MAX;
|
---|
1519 | pOpts->aBootCatEntries[i].u.Section.fInsertBootInfoTable = false;
|
---|
1520 | pOpts->aBootCatEntries[i].u.Section.fBootable = true;
|
---|
1521 | pOpts->aBootCatEntries[i].u.Section.bBootMediaType = ISO9660_ELTORITO_BOOT_MEDIA_TYPE_MASK;
|
---|
1522 | pOpts->aBootCatEntries[i].u.Section.bSystemType = 1 /*FAT12*/;
|
---|
1523 | pOpts->aBootCatEntries[i].u.Section.uLoadSeg = 0x7c0;
|
---|
1524 | pOpts->aBootCatEntries[i].u.Section.cSectorsToLoad = 4;
|
---|
1525 | pOpts->cBootCatEntries = ++i;
|
---|
1526 | }
|
---|
1527 |
|
---|
1528 | *pidxBootCat = i - 1;
|
---|
1529 | return VINF_SUCCESS;
|
---|
1530 | }
|
---|
1531 |
|
---|
1532 |
|
---|
1533 | /**
|
---|
1534 | * Deals with: --boot-catalog <path-spec>
|
---|
1535 | *
|
---|
1536 | * This enters the boot catalog into the namespaces of the image. The path-spec
|
---|
1537 | * is similar to what rtFsIsoMakerCmdAddSomething processes, only there isn't a
|
---|
1538 | * source file part.
|
---|
1539 | *
|
---|
1540 | * @returns IPRT status code
|
---|
1541 | * @param pOpts The ISO maker command instance.
|
---|
1542 | * @param pszGenericBootImage The generic boot image source.
|
---|
1543 | */
|
---|
1544 | static int rtFsIsoMakerCmdOptEltoritoSetBootCatalogPath(PRTFSISOMAKERCMDOPTS pOpts, const char *pszBootCat)
|
---|
1545 | {
|
---|
1546 | /* Make sure we'll fail later if no other boot options are present. */
|
---|
1547 | rtFsIsoMakerCmdOptEltoritoEnsureValidationEntry(pOpts);
|
---|
1548 |
|
---|
1549 | /* Parse the name spec. */
|
---|
1550 | RTFSISOMKCMDPARSEDNAMES Parsed;
|
---|
1551 | int rc = rtFsIsoMakerCmdParseNameSpec(pOpts, pszBootCat, false /*fWithSrc*/, &Parsed);
|
---|
1552 | if (RT_SUCCESS(rc))
|
---|
1553 | {
|
---|
1554 | /* Query/create the boot catalog and enter it into the name spaces. */
|
---|
1555 | uint32_t idxBootCatObj;
|
---|
1556 | rc = RTFsIsoMakerQueryObjIdxForBootCatalog(pOpts->hIsoMaker, &idxBootCatObj);
|
---|
1557 | if (RT_SUCCESS(rc))
|
---|
1558 | rc = rtFsIsoMakerCmdSetObjPaths(pOpts, idxBootCatObj, &Parsed, "boot catalog");
|
---|
1559 | else
|
---|
1560 | rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerQueryBootCatalogPathObjIdx failed: %Rrc", rc);
|
---|
1561 | }
|
---|
1562 | return rc;
|
---|
1563 | }
|
---|
1564 |
|
---|
1565 |
|
---|
1566 | /**
|
---|
1567 | * Deals with: --eltorito-add-image {file-spec}
|
---|
1568 | *
|
---|
1569 | * This differs from -b|--eltorito-boot in that it takes a source file
|
---|
1570 | * specification identical to what rtFsIsoMakerCmdAddSomething processes instead
|
---|
1571 | * of a reference to a file in the image.
|
---|
1572 | *
|
---|
1573 | * This operates on the current eltorito boot catalog entry.
|
---|
1574 | *
|
---|
1575 | * @returns IPRT status code
|
---|
1576 | * @param pOpts The ISO maker command instance.
|
---|
1577 | * @param pszGenericBootImage The generic boot image source.
|
---|
1578 | */
|
---|
1579 | static int rtFsIsoMakerCmdOptEltoritoAddImage(PRTFSISOMAKERCMDOPTS pOpts, const char *pszBootImageSpec)
|
---|
1580 | {
|
---|
1581 | /* Parse the name spec. */
|
---|
1582 | RTFSISOMKCMDPARSEDNAMES Parsed;
|
---|
1583 | int rc = rtFsIsoMakerCmdParseNameSpec(pOpts, pszBootImageSpec, true /*fWithSrc*/, &Parsed);
|
---|
1584 | if (RT_SUCCESS(rc))
|
---|
1585 | {
|
---|
1586 | uint32_t idxBootCat;
|
---|
1587 | rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
|
---|
1588 | if (RT_SUCCESS(rc))
|
---|
1589 | {
|
---|
1590 | if ( pOpts->aBootCatEntries[idxBootCat].u.Section.idxImageObj != UINT32_MAX
|
---|
1591 | || pOpts->aBootCatEntries[idxBootCat].u.Section.pszImageNameInIso != NULL)
|
---|
1592 | rc = rtFsIsoMakerCmdSyntaxError(pOpts, "boot image already given for current El Torito entry (%#u)", idxBootCat);
|
---|
1593 | else
|
---|
1594 | {
|
---|
1595 | uint32_t idxImageObj;
|
---|
1596 | rc = rtFsIsoMakerCmdStatAndAddFile(pOpts, Parsed.aNames[Parsed.cNamesWithSrc - 1].szPath, &Parsed, &idxImageObj);
|
---|
1597 | if (RT_SUCCESS(rc))
|
---|
1598 | pOpts->aBootCatEntries[idxBootCat].u.Section.idxImageObj = idxImageObj;
|
---|
1599 | }
|
---|
1600 | }
|
---|
1601 | }
|
---|
1602 |
|
---|
1603 | return rc;
|
---|
1604 | }
|
---|
1605 |
|
---|
1606 |
|
---|
1607 | /**
|
---|
1608 | * Deals with: -b|--eltorito-boot {file-in-iso}
|
---|
1609 | *
|
---|
1610 | * This operates on the current eltorito boot catalog entry.
|
---|
1611 | *
|
---|
1612 | * @returns IPRT status code
|
---|
1613 | * @param pOpts The ISO maker command instance.
|
---|
1614 | * @param pszGenericBootImage The generic boot image source.
|
---|
1615 | */
|
---|
1616 | static int rtFsIsoMakerCmdOptEltoritoBoot(PRTFSISOMAKERCMDOPTS pOpts, const char *pszBootImage)
|
---|
1617 | {
|
---|
1618 | uint32_t idxBootCat;
|
---|
1619 | int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
|
---|
1620 | if (RT_SUCCESS(rc))
|
---|
1621 | {
|
---|
1622 | if ( pOpts->aBootCatEntries[idxBootCat].u.Section.idxImageObj != UINT32_MAX
|
---|
1623 | || pOpts->aBootCatEntries[idxBootCat].u.Section.pszImageNameInIso != NULL)
|
---|
1624 | return rtFsIsoMakerCmdSyntaxError(pOpts, "boot image already given for current El Torito entry (%#u)", idxBootCat);
|
---|
1625 |
|
---|
1626 | uint32_t idxImageObj = RTFsIsoMakerGetObjIdxForPath(pOpts->hIsoMaker, RTFSISOMAKER_NAMESPACE_ALL, pszBootImage);
|
---|
1627 | if (idxImageObj == UINT32_MAX)
|
---|
1628 | pOpts->aBootCatEntries[idxBootCat].u.Section.pszImageNameInIso = pszBootImage;
|
---|
1629 | pOpts->aBootCatEntries[idxBootCat].u.Section.idxImageObj = idxImageObj;
|
---|
1630 | }
|
---|
1631 | return rc;
|
---|
1632 | }
|
---|
1633 |
|
---|
1634 |
|
---|
1635 | /**
|
---|
1636 | * Deals with: --eltorito-platform-id {x86|PPC|Mac|efi|number}
|
---|
1637 | *
|
---|
1638 | * Operates on the validation entry or a section header.
|
---|
1639 | *
|
---|
1640 | * @returns IPRT status code
|
---|
1641 | * @param pOpts The ISO maker command instance.
|
---|
1642 | * @param pszPlatformId The platform ID.
|
---|
1643 | */
|
---|
1644 | static int rtFsIsoMakerCmdOptEltoritoPlatformId(PRTFSISOMAKERCMDOPTS pOpts, const char *pszPlatformId)
|
---|
1645 | {
|
---|
1646 | /* Decode it. */
|
---|
1647 | uint8_t idPlatform;
|
---|
1648 | if (strcmp(pszPlatformId, "x86") == 0)
|
---|
1649 | idPlatform = ISO9660_ELTORITO_PLATFORM_ID_X86;
|
---|
1650 | else if (strcmp(pszPlatformId, "PPC") == 0)
|
---|
1651 | idPlatform = ISO9660_ELTORITO_PLATFORM_ID_PPC;
|
---|
1652 | else if (strcmp(pszPlatformId, "Mac") == 0)
|
---|
1653 | idPlatform = ISO9660_ELTORITO_PLATFORM_ID_MAC;
|
---|
1654 | else if (strcmp(pszPlatformId, "efi") == 0)
|
---|
1655 | idPlatform = ISO9660_ELTORITO_PLATFORM_ID_EFI;
|
---|
1656 | else
|
---|
1657 | {
|
---|
1658 | int rc = RTStrToUInt8Full(pszPlatformId, 0, &idPlatform);
|
---|
1659 | if (rc != VINF_SUCCESS)
|
---|
1660 | return rtFsIsoMakerCmdSyntaxError(pOpts, "invalid or unknown platform ID: %s", pszPlatformId);
|
---|
1661 | }
|
---|
1662 |
|
---|
1663 | /* If this option comes before anything related to the default entry, work
|
---|
1664 | on the validation entry. */
|
---|
1665 | if (pOpts->cBootCatEntries <= 1)
|
---|
1666 | {
|
---|
1667 | rtFsIsoMakerCmdOptEltoritoEnsureValidationEntry(pOpts);
|
---|
1668 | pOpts->aBootCatEntries[0].u.Validation.idPlatform = idPlatform;
|
---|
1669 | }
|
---|
1670 | /* Otherwise, work on the current section header, creating a new one if necessary. */
|
---|
1671 | else
|
---|
1672 | {
|
---|
1673 | uint32_t idxBootCat = pOpts->cBootCatEntries - 1;
|
---|
1674 | if (pOpts->aBootCatEntries[idxBootCat].enmType == RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader)
|
---|
1675 | pOpts->aBootCatEntries[idxBootCat].u.SectionHeader.idPlatform = idPlatform;
|
---|
1676 | else
|
---|
1677 | {
|
---|
1678 | idxBootCat++;
|
---|
1679 | if (idxBootCat + 2 > RT_ELEMENTS(pOpts->aBootCatEntries))
|
---|
1680 | return rtFsIsoMakerCmdErrorRc(pOpts, VERR_BUFFER_OVERFLOW, "Too many boot catalog entries");
|
---|
1681 |
|
---|
1682 | pOpts->aBootCatEntries[idxBootCat].enmType = RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader;
|
---|
1683 | pOpts->aBootCatEntries[idxBootCat].u.SectionHeader.idPlatform = idPlatform;
|
---|
1684 | pOpts->aBootCatEntries[idxBootCat].u.SectionHeader.pszString = NULL;
|
---|
1685 | pOpts->cBootCatEntries = idxBootCat + 1;
|
---|
1686 | }
|
---|
1687 | }
|
---|
1688 | return VINF_SUCCESS;
|
---|
1689 | }
|
---|
1690 |
|
---|
1691 |
|
---|
1692 | /**
|
---|
1693 | * Deals with: -no-boot
|
---|
1694 | *
|
---|
1695 | * This operates on the current eltorito boot catalog entry.
|
---|
1696 | *
|
---|
1697 | * @returns IPRT status code
|
---|
1698 | * @param pOpts The ISO maker command instance.
|
---|
1699 | */
|
---|
1700 | static int rtFsIsoMakerCmdOptEltoritoSetNotBootable(PRTFSISOMAKERCMDOPTS pOpts)
|
---|
1701 | {
|
---|
1702 | uint32_t idxBootCat;
|
---|
1703 | int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
|
---|
1704 | if (RT_SUCCESS(rc))
|
---|
1705 | pOpts->aBootCatEntries[idxBootCat].u.Section.fBootable = false;
|
---|
1706 | return rc;
|
---|
1707 | }
|
---|
1708 |
|
---|
1709 |
|
---|
1710 | /**
|
---|
1711 | * Deals with: -hard-disk-boot, -no-emulation-boot, --eltorito-floppy-12,
|
---|
1712 | * --eltorito-floppy-144, --eltorito-floppy-288
|
---|
1713 | *
|
---|
1714 | * This operates on the current eltorito boot catalog entry.
|
---|
1715 | *
|
---|
1716 | * @returns IPRT status code
|
---|
1717 | * @param pOpts The ISO maker command instance.
|
---|
1718 | * @param bMediaType The media type.
|
---|
1719 | */
|
---|
1720 | static int rtFsIsoMakerCmdOptEltoritoSetMediaType(PRTFSISOMAKERCMDOPTS pOpts, uint8_t bMediaType)
|
---|
1721 | {
|
---|
1722 | uint32_t idxBootCat;
|
---|
1723 | int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
|
---|
1724 | if (RT_SUCCESS(rc))
|
---|
1725 | pOpts->aBootCatEntries[idxBootCat].u.Section.bBootMediaType = bMediaType;
|
---|
1726 | return rc;
|
---|
1727 | }
|
---|
1728 |
|
---|
1729 |
|
---|
1730 | /**
|
---|
1731 | * Deals with: -boot-load-seg {seg}
|
---|
1732 | *
|
---|
1733 | * This operates on the current eltorito boot catalog entry.
|
---|
1734 | *
|
---|
1735 | * @returns IPRT status code
|
---|
1736 | * @param pOpts The ISO maker command instance.
|
---|
1737 | * @param uSeg The load segment.
|
---|
1738 | */
|
---|
1739 | static int rtFsIsoMakerCmdOptEltoritoSetLoadSegment(PRTFSISOMAKERCMDOPTS pOpts, uint16_t uSeg)
|
---|
1740 | {
|
---|
1741 | uint32_t idxBootCat;
|
---|
1742 | int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
|
---|
1743 | if (RT_SUCCESS(rc))
|
---|
1744 | pOpts->aBootCatEntries[idxBootCat].u.Section.uLoadSeg = uSeg;
|
---|
1745 | return rc;
|
---|
1746 | }
|
---|
1747 |
|
---|
1748 |
|
---|
1749 | /**
|
---|
1750 | * Deals with: -boot-load-size {sectors}
|
---|
1751 | *
|
---|
1752 | * This operates on the current eltorito boot catalog entry.
|
---|
1753 | *
|
---|
1754 | * @returns IPRT status code
|
---|
1755 | * @param pOpts The ISO maker command instance.
|
---|
1756 | * @param cSectors Number of emulated sectors to load
|
---|
1757 | */
|
---|
1758 | static int rtFsIsoMakerCmdOptEltoritoSetLoadSectorCount(PRTFSISOMAKERCMDOPTS pOpts, uint16_t cSectors)
|
---|
1759 | {
|
---|
1760 | uint32_t idxBootCat;
|
---|
1761 | int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
|
---|
1762 | if (RT_SUCCESS(rc))
|
---|
1763 | pOpts->aBootCatEntries[idxBootCat].u.Section.cSectorsToLoad = cSectors;
|
---|
1764 | return rc;
|
---|
1765 | }
|
---|
1766 |
|
---|
1767 |
|
---|
1768 | /**
|
---|
1769 | * Deals with: -boot-info-table
|
---|
1770 | *
|
---|
1771 | * This operates on the current eltorito boot catalog entry.
|
---|
1772 | *
|
---|
1773 | * @returns IPRT status code
|
---|
1774 | * @param pOpts The ISO maker command instance.
|
---|
1775 | */
|
---|
1776 | static int rtFsIsoMakerCmdOptEltoritoEnableBootInfoTablePatching(PRTFSISOMAKERCMDOPTS pOpts)
|
---|
1777 | {
|
---|
1778 | uint32_t idxBootCat;
|
---|
1779 | int rc = rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, false /*fForceNew*/, &idxBootCat);
|
---|
1780 | if (RT_SUCCESS(rc))
|
---|
1781 | pOpts->aBootCatEntries[idxBootCat].u.Section.fInsertBootInfoTable = true;
|
---|
1782 | return rc;
|
---|
1783 | }
|
---|
1784 |
|
---|
1785 |
|
---|
1786 | /**
|
---|
1787 | * Validates and commits the boot catalog stuff.
|
---|
1788 | *
|
---|
1789 | * ASSUMING this is called after all options are parsed and there is only this
|
---|
1790 | * one call.
|
---|
1791 | *
|
---|
1792 | * @returns IPRT status code
|
---|
1793 | * @param pOpts The ISO maker command instance.
|
---|
1794 | */
|
---|
1795 | static int rtFsIsoMakerCmdOptEltoritoCommitBootCatalog(PRTFSISOMAKERCMDOPTS pOpts)
|
---|
1796 | {
|
---|
1797 | if (pOpts->cBootCatEntries == 0)
|
---|
1798 | return VINF_SUCCESS;
|
---|
1799 |
|
---|
1800 | /*
|
---|
1801 | * Locate and configure the boot images first.
|
---|
1802 | */
|
---|
1803 | int rc;
|
---|
1804 | PRTFSISOMKCMDELTORITOENTRY pBootCatEntry = &pOpts->aBootCatEntries[1];
|
---|
1805 | for (uint32_t idxBootCat = 1; idxBootCat < pOpts->cBootCatEntries; idxBootCat++, pBootCatEntry++)
|
---|
1806 | if ( pBootCatEntry->enmType == RTFSISOMKCMDELTORITOENTRY::kEntryType_Default
|
---|
1807 | || pBootCatEntry->enmType == RTFSISOMKCMDELTORITOENTRY::kEntryType_Section)
|
---|
1808 | {
|
---|
1809 | /* Make sure we've got a boot image. */
|
---|
1810 | uint32_t idxImageObj = pBootCatEntry->u.Section.idxImageObj;
|
---|
1811 | if (idxImageObj == UINT32_MAX)
|
---|
1812 | {
|
---|
1813 | const char *pszBootImage = pBootCatEntry->u.Section.pszImageNameInIso;
|
---|
1814 | if (pszBootImage == NULL)
|
---|
1815 | return rtFsIsoMakerCmdSyntaxError(pOpts, "No image name given for boot catalog entry #%u", idxBootCat);
|
---|
1816 |
|
---|
1817 | idxImageObj = RTFsIsoMakerGetObjIdxForPath(pOpts->hIsoMaker, RTFSISOMAKER_NAMESPACE_ALL, pszBootImage);
|
---|
1818 | if (idxImageObj == UINT32_MAX)
|
---|
1819 | return rtFsIsoMakerCmdSyntaxError(pOpts, "Unable to locate image for boot catalog entry #%u: %s",
|
---|
1820 | idxBootCat, pszBootImage);
|
---|
1821 | pBootCatEntry->u.Section.idxImageObj = idxImageObj;
|
---|
1822 | }
|
---|
1823 |
|
---|
1824 | /* Enable patching it? */
|
---|
1825 | if (pBootCatEntry->u.Section.fInsertBootInfoTable)
|
---|
1826 | {
|
---|
1827 | rc = RTFsIsoMakerObjEnableBootInfoTablePatching(pOpts->hIsoMaker, idxImageObj, true);
|
---|
1828 | if (RT_FAILURE(rc))
|
---|
1829 | return rtFsIsoMakerCmdErrorRc(pOpts, rc,
|
---|
1830 | "RTFsIsoMakerObjEnableBootInfoTablePatching failed on entry #%u: %Rrc",
|
---|
1831 | idxBootCat, rc);
|
---|
1832 | }
|
---|
1833 |
|
---|
1834 | /* Figure out the floppy type given the object size. */
|
---|
1835 | if (pBootCatEntry->u.Section.bBootMediaType == ISO9660_ELTORITO_BOOT_MEDIA_TYPE_MASK)
|
---|
1836 | {
|
---|
1837 | uint64_t cbImage;
|
---|
1838 | rc = RTFsIsoMakerObjQueryDataSize(pOpts->hIsoMaker, idxImageObj, &cbImage);
|
---|
1839 | if (RT_FAILURE(rc))
|
---|
1840 | return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerObjGetDataSize failed on entry #%u: %Rrc",
|
---|
1841 | idxBootCat, rc);
|
---|
1842 | if (cbImage == 1228800)
|
---|
1843 | pBootCatEntry->u.Section.bBootMediaType = ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_1_2_MB;
|
---|
1844 | else if (cbImage <= 1474560)
|
---|
1845 | pBootCatEntry->u.Section.bBootMediaType = ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_1_44_MB;
|
---|
1846 | else if (cbImage <= 2949120)
|
---|
1847 | pBootCatEntry->u.Section.bBootMediaType = ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_2_88_MB;
|
---|
1848 | else
|
---|
1849 | pBootCatEntry->u.Section.bBootMediaType = ISO9660_ELTORITO_BOOT_MEDIA_TYPE_HARD_DISK;
|
---|
1850 | }
|
---|
1851 | }
|
---|
1852 |
|
---|
1853 | /*
|
---|
1854 | * Add the boot catalog entries.
|
---|
1855 | */
|
---|
1856 | pBootCatEntry = &pOpts->aBootCatEntries[0];
|
---|
1857 | for (uint32_t idxBootCat = 0; idxBootCat < pOpts->cBootCatEntries; idxBootCat++, pBootCatEntry++)
|
---|
1858 | switch (pBootCatEntry->enmType)
|
---|
1859 | {
|
---|
1860 | case RTFSISOMKCMDELTORITOENTRY::kEntryType_Validation:
|
---|
1861 | Assert(idxBootCat == 0);
|
---|
1862 | rc = RTFsIsoMakerBootCatSetValidationEntry(pOpts->hIsoMaker, pBootCatEntry->u.Validation.idPlatform,
|
---|
1863 | pBootCatEntry->u.Validation.pszString);
|
---|
1864 | if (RT_FAILURE(rc))
|
---|
1865 | return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerBootCatSetValidationEntry failed: %Rrc", rc);
|
---|
1866 | break;
|
---|
1867 |
|
---|
1868 | case RTFSISOMKCMDELTORITOENTRY::kEntryType_Default:
|
---|
1869 | case RTFSISOMKCMDELTORITOENTRY::kEntryType_Section:
|
---|
1870 | Assert(pBootCatEntry->enmType == RTFSISOMKCMDELTORITOENTRY::kEntryType_Default ? idxBootCat == 1 : idxBootCat > 2);
|
---|
1871 | rc = RTFsIsoMakerBootCatSetSectionEntry(pOpts->hIsoMaker, idxBootCat,
|
---|
1872 | pBootCatEntry->u.Section.idxImageObj,
|
---|
1873 | pBootCatEntry->u.Section.bBootMediaType,
|
---|
1874 | pBootCatEntry->u.Section.bSystemType,
|
---|
1875 | pBootCatEntry->u.Section.fBootable,
|
---|
1876 | pBootCatEntry->u.Section.uLoadSeg,
|
---|
1877 | pBootCatEntry->u.Section.cSectorsToLoad,
|
---|
1878 | ISO9660_ELTORITO_SEL_CRIT_TYPE_NONE, NULL, 0);
|
---|
1879 | if (RT_FAILURE(rc))
|
---|
1880 | return rtFsIsoMakerCmdErrorRc(pOpts, rc, "RTFsIsoMakerBootCatSetSectionEntry failed on entry #%u: %Rrc",
|
---|
1881 | idxBootCat, rc);
|
---|
1882 | break;
|
---|
1883 |
|
---|
1884 | case RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader:
|
---|
1885 | {
|
---|
1886 | uint32_t cEntries = 1;
|
---|
1887 | while ( idxBootCat + cEntries < pOpts->cBootCatEntries
|
---|
1888 | && pBootCatEntry[cEntries].enmType != RTFSISOMKCMDELTORITOENTRY::kEntryType_SectionHeader)
|
---|
1889 | cEntries++;
|
---|
1890 | cEntries--;
|
---|
1891 |
|
---|
1892 | Assert(idxBootCat > 1);
|
---|
1893 | rc = RTFsIsoMakerBootCatSetSectionHeaderEntry(pOpts->hIsoMaker, idxBootCat, cEntries,
|
---|
1894 | pBootCatEntry->u.SectionHeader.idPlatform,
|
---|
1895 | pBootCatEntry->u.SectionHeader.pszString);
|
---|
1896 | if (RT_FAILURE(rc))
|
---|
1897 | return rtFsIsoMakerCmdErrorRc(pOpts, rc,
|
---|
1898 | "RTFsIsoMakerBootCatSetSectionHeaderEntry failed on entry #%u: %Rrc",
|
---|
1899 | idxBootCat, rc);
|
---|
1900 | break;
|
---|
1901 | }
|
---|
1902 |
|
---|
1903 | default:
|
---|
1904 | AssertFailedReturn(VERR_INTERNAL_ERROR_3);
|
---|
1905 | }
|
---|
1906 |
|
---|
1907 | return VINF_SUCCESS;
|
---|
1908 | }
|
---|
1909 |
|
---|
1910 |
|
---|
1911 | /**
|
---|
1912 | * Deals with: --eltorito-new-entry, --eltorito-alt-boot
|
---|
1913 | *
|
---|
1914 | * This operates on the current eltorito boot catalog entry.
|
---|
1915 | *
|
---|
1916 | * @returns IPRT status code
|
---|
1917 | * @param pOpts The ISO maker command instance.
|
---|
1918 | */
|
---|
1919 | static int rtFsIsoMakerCmdOptEltoritoNewEntry(PRTFSISOMAKERCMDOPTS pOpts)
|
---|
1920 | {
|
---|
1921 | uint32_t idxBootCat;
|
---|
1922 | return rtFsIsoMakerCmdOptEltoritoEnsureSectionEntry(pOpts, true /*fForceNew*/, &idxBootCat);
|
---|
1923 | }
|
---|
1924 |
|
---|
1925 |
|
---|
1926 | /**
|
---|
1927 | * Sets a string property in all namespaces.
|
---|
1928 | *
|
---|
1929 | * @returns IPRT status code.
|
---|
1930 | * @param pOpts The ISO maker command instance.
|
---|
1931 | * @param pszValue The new string value.
|
---|
1932 | * @param enmStringProp The string property.
|
---|
1933 | */
|
---|
1934 | static int rtFsIsoMakerCmdOptSetStringProp(PRTFSISOMAKERCMDOPTS pOpts, const char *pszValue, RTFSISOMAKERSTRINGPROP enmStringProp)
|
---|
1935 | {
|
---|
1936 | int rc = RTFsIsoMakerSetStringProp(pOpts->hIsoMaker, enmStringProp, RTFSISOMAKER_NAMESPACE_ALL, pszValue);
|
---|
1937 | if (RT_FAILURE(rc))
|
---|
1938 | rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Failed to set string property %d to '%s': %Rrc", enmStringProp, pszValue, rc);
|
---|
1939 | return rc;
|
---|
1940 | }
|
---|
1941 |
|
---|
1942 |
|
---|
1943 | /**
|
---|
1944 | * Extended ISO maker command.
|
---|
1945 | *
|
---|
1946 | * This can be used as a ISO maker command that produces a image file, or
|
---|
1947 | * alternatively for setting up a virtual ISO in memory.
|
---|
1948 | *
|
---|
1949 | * @returns IPRT status code
|
---|
1950 | * @param cArgs Number of arguments.
|
---|
1951 | * @param papszArgs Pointer to argument array.
|
---|
1952 | * @param phVfsFile Where to return the virtual ISO. Pass NULL to
|
---|
1953 | * for normal operation (creates file on disk).
|
---|
1954 | * @param pErrInfo Where to return extended error information in
|
---|
1955 | * the virtual ISO mode.
|
---|
1956 | */
|
---|
1957 | RTDECL(int) RTFsIsoMakerCmdEx(unsigned cArgs, char **papszArgs, PRTVFSFILE phVfsFile, PRTERRINFO pErrInfo)
|
---|
1958 | {
|
---|
1959 | /*
|
---|
1960 | * Create instance.
|
---|
1961 | */
|
---|
1962 | RTFSISOMAKERCMDOPTS Opts;
|
---|
1963 | RT_ZERO(Opts);
|
---|
1964 | Opts.hIsoMaker = NIL_RTFSISOMAKER;
|
---|
1965 | Opts.pErrInfo = pErrInfo;
|
---|
1966 | Opts.fVirtualImageMaker = phVfsFile != NULL;
|
---|
1967 | Opts.cNameSpecifiers = 1;
|
---|
1968 | Opts.afNameSpecifiers[0] = RTFSISOMAKERCMDNAME_MAJOR_MASK;
|
---|
1969 | Opts.fDstNamespaces = RTFSISOMAKERCMDNAME_MAJOR_MASK;
|
---|
1970 | if (phVfsFile)
|
---|
1971 | *phVfsFile = NIL_RTVFSFILE;
|
---|
1972 | for (uint32_t i = 0; i < RT_ELEMENTS(Opts.aBootCatEntries); i++)
|
---|
1973 | Opts.aBootCatEntries[i].u.Section.idxImageObj = UINT32_MAX;
|
---|
1974 |
|
---|
1975 | /* Setup option parsing. */
|
---|
1976 | RTGETOPTSTATE GetState;
|
---|
1977 | int rc = RTGetOptInit(&GetState, cArgs, papszArgs, g_aRtFsIsoMakerOptions, RT_ELEMENTS(g_aRtFsIsoMakerOptions),
|
---|
1978 | 1 /*iFirst*/, 0 /*fFlags*/);
|
---|
1979 | if (RT_FAILURE(rc))
|
---|
1980 | return rtFsIsoMakerCmdErrorRc(&Opts, rc, "RTGetOpt failed: %Rrc", rc);
|
---|
1981 |
|
---|
1982 | /* Create the ISO creator instance. */
|
---|
1983 | rc = RTFsIsoMakerCreate(&Opts.hIsoMaker);
|
---|
1984 | if (RT_FAILURE(rc))
|
---|
1985 | return rtFsIsoMakerCmdErrorRc(&Opts, rc, "RTFsIsoMakerCreate failed: %Rrc", rc);
|
---|
1986 |
|
---|
1987 | /*
|
---|
1988 | * Parse parameters. Parameters are position dependent.
|
---|
1989 | */
|
---|
1990 | RTGETOPTUNION ValueUnion;
|
---|
1991 | while ( RT_SUCCESS(rc)
|
---|
1992 | && (rc = RTGetOpt(&GetState, &ValueUnion)) != 0)
|
---|
1993 | {
|
---|
1994 | switch (rc)
|
---|
1995 | {
|
---|
1996 | /*
|
---|
1997 | * Files and directories.
|
---|
1998 | */
|
---|
1999 | case VINF_GETOPT_NOT_OPTION:
|
---|
2000 | rc = rtFsIsoMakerCmdAddSomething(&Opts, ValueUnion.psz);
|
---|
2001 | break;
|
---|
2002 |
|
---|
2003 | /*
|
---|
2004 | * Options specific to our ISO maker.
|
---|
2005 | */
|
---|
2006 | case RTFSISOMAKERCMD_OPT_NAME_SETUP:
|
---|
2007 | rc = rtFsIsoMakerCmdOptNameSetup(&Opts, ValueUnion.psz);
|
---|
2008 | break;
|
---|
2009 |
|
---|
2010 | case RTFSISOMAKERCMD_OPT_IPRT_ISO_MAKER_FILE_MARKER:
|
---|
2011 | /* ignored */
|
---|
2012 | break;
|
---|
2013 |
|
---|
2014 | case RTFSISOMAKERCMD_OPT_IMPORT_ISO:
|
---|
2015 | rc = rtFsIsoMakerCmdOptImportIso(&Opts, ValueUnion.psz);
|
---|
2016 | break;
|
---|
2017 |
|
---|
2018 | /*
|
---|
2019 | * Joliet related options.
|
---|
2020 | */
|
---|
2021 | case RTFSISOMAKERCMD_OPT_NO_JOLIET:
|
---|
2022 | rc = RTFsIsoMakerSetJolietUcs2Level(Opts.hIsoMaker, 0);
|
---|
2023 | if (RT_FAILURE(rc))
|
---|
2024 | rc = rtFsIsoMakerCmdErrorRc(&Opts, rc, "Failed to disable joliet: %Rrc", rc);
|
---|
2025 | break;
|
---|
2026 |
|
---|
2027 |
|
---|
2028 | /*
|
---|
2029 | * Boot related options.
|
---|
2030 | */
|
---|
2031 | case 'G': /* --generic-boot <file> */
|
---|
2032 | rc = rtFsIsoMakerCmdOptGenericBoot(&Opts, ValueUnion.psz);
|
---|
2033 | break;
|
---|
2034 |
|
---|
2035 | case RTFSISOMAKERCMD_OPT_ELTORITO_ADD_IMAGE:
|
---|
2036 | rc = rtFsIsoMakerCmdOptEltoritoAddImage(&Opts, ValueUnion.psz);
|
---|
2037 | break;
|
---|
2038 |
|
---|
2039 | case 'b': /* --eltorito-boot <boot.img> */
|
---|
2040 | rc = rtFsIsoMakerCmdOptEltoritoBoot(&Opts, ValueUnion.psz);
|
---|
2041 | break;
|
---|
2042 |
|
---|
2043 | case RTFSISOMAKERCMD_OPT_ELTORITO_NEW_ENTRY:
|
---|
2044 | rc = rtFsIsoMakerCmdOptEltoritoNewEntry(&Opts);
|
---|
2045 | break;
|
---|
2046 |
|
---|
2047 | case RTFSISOMAKERCMD_OPT_ELTORITO_PLATFORM_ID:
|
---|
2048 | rc = rtFsIsoMakerCmdOptEltoritoPlatformId(&Opts, ValueUnion.psz);
|
---|
2049 | break;
|
---|
2050 |
|
---|
2051 | case RTFSISOMAKERCMD_OPT_ELTORITO_NO_BOOT:
|
---|
2052 | rc = rtFsIsoMakerCmdOptEltoritoSetNotBootable(&Opts);
|
---|
2053 | break;
|
---|
2054 |
|
---|
2055 | case RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_12:
|
---|
2056 | rc = rtFsIsoMakerCmdOptEltoritoSetMediaType(&Opts, ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_1_2_MB);
|
---|
2057 | break;
|
---|
2058 | case RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_144:
|
---|
2059 | rc = rtFsIsoMakerCmdOptEltoritoSetMediaType(&Opts, ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_1_44_MB);
|
---|
2060 | break;
|
---|
2061 | case RTFSISOMAKERCMD_OPT_ELTORITO_FLOPPY_288:
|
---|
2062 | rc = rtFsIsoMakerCmdOptEltoritoSetMediaType(&Opts, ISO9660_ELTORITO_BOOT_MEDIA_TYPE_FLOPPY_2_88_MB);
|
---|
2063 | break;
|
---|
2064 | case RTFSISOMAKERCMD_OPT_ELTORITO_HARD_DISK_BOOT:
|
---|
2065 | rc = rtFsIsoMakerCmdOptEltoritoSetMediaType(&Opts, ISO9660_ELTORITO_BOOT_MEDIA_TYPE_HARD_DISK);
|
---|
2066 | break;
|
---|
2067 | case RTFSISOMAKERCMD_OPT_ELTORITO_NO_EMULATION_BOOT:
|
---|
2068 | rc = rtFsIsoMakerCmdOptEltoritoSetMediaType(&Opts, ISO9660_ELTORITO_BOOT_MEDIA_TYPE_NO_EMULATION);
|
---|
2069 | break;
|
---|
2070 |
|
---|
2071 | case RTFSISOMAKERCMD_OPT_ELTORITO_LOAD_SEG:
|
---|
2072 | rc = rtFsIsoMakerCmdOptEltoritoSetLoadSegment(&Opts, ValueUnion.u16);
|
---|
2073 | break;
|
---|
2074 |
|
---|
2075 | case RTFSISOMAKERCMD_OPT_ELTORITO_LOAD_SIZE:
|
---|
2076 | rc = rtFsIsoMakerCmdOptEltoritoSetLoadSectorCount(&Opts, ValueUnion.u16);
|
---|
2077 | break;
|
---|
2078 |
|
---|
2079 | case RTFSISOMAKERCMD_OPT_ELTORITO_INFO_TABLE:
|
---|
2080 | rc = rtFsIsoMakerCmdOptEltoritoEnableBootInfoTablePatching(&Opts);
|
---|
2081 | break;
|
---|
2082 |
|
---|
2083 | case 'c': /* --boot-catalog <cd-path> */
|
---|
2084 | rc = rtFsIsoMakerCmdOptEltoritoSetBootCatalogPath(&Opts, ValueUnion.psz);
|
---|
2085 | break;
|
---|
2086 |
|
---|
2087 | /*
|
---|
2088 | * Image/namespace property related options.
|
---|
2089 | */
|
---|
2090 | case RTFSISOMAKERCMD_OPT_ABSTRACT_FILE_ID:
|
---|
2091 | rc = rtFsIsoMakerCmdOptSetStringProp(&Opts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_ABSTRACT_FILE_ID);
|
---|
2092 | break;
|
---|
2093 |
|
---|
2094 | case 'A': /* --application-id */
|
---|
2095 | rc = rtFsIsoMakerCmdOptSetStringProp(&Opts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_APPLICATION_ID);
|
---|
2096 | break;
|
---|
2097 |
|
---|
2098 | case RTFSISOMAKERCMD_OPT_BIBLIOGRAPHIC_FILE_ID:
|
---|
2099 | rc = rtFsIsoMakerCmdOptSetStringProp(&Opts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_BIBLIOGRAPHIC_FILE_ID);
|
---|
2100 | break;
|
---|
2101 |
|
---|
2102 | case RTFSISOMAKERCMD_OPT_COPYRIGHT_FILE_ID:
|
---|
2103 | rc = rtFsIsoMakerCmdOptSetStringProp(&Opts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_COPYRIGHT_FILE_ID);
|
---|
2104 | break;
|
---|
2105 |
|
---|
2106 | case 'P': /* -publisher */
|
---|
2107 | rc = rtFsIsoMakerCmdOptSetStringProp(&Opts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_PUBLISHER_ID);
|
---|
2108 | break;
|
---|
2109 |
|
---|
2110 | case 'p': /* --preparer*/
|
---|
2111 | rc = rtFsIsoMakerCmdOptSetStringProp(&Opts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_DATA_PREPARER_ID);
|
---|
2112 | break;
|
---|
2113 |
|
---|
2114 | case RTFSISOMAKERCMD_OPT_SYSTEM_ID:
|
---|
2115 | rc = rtFsIsoMakerCmdOptSetStringProp(&Opts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_SYSTEM_ID);
|
---|
2116 | break;
|
---|
2117 |
|
---|
2118 | case RTFSISOMAKERCMD_OPT_VOLUME_ID: /* (should've been '-V') */
|
---|
2119 | rc = rtFsIsoMakerCmdOptSetStringProp(&Opts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_VOLUME_ID);
|
---|
2120 | break;
|
---|
2121 |
|
---|
2122 | case RTFSISOMAKERCMD_OPT_VOLUME_SET_ID:
|
---|
2123 | rc = rtFsIsoMakerCmdOptSetStringProp(&Opts, ValueUnion.psz, RTFSISOMAKERSTRINGPROP_VOLUME_SET_ID);
|
---|
2124 | break;
|
---|
2125 |
|
---|
2126 | /*
|
---|
2127 | * Options compatible with other ISO makers.
|
---|
2128 | */
|
---|
2129 | case 'o':
|
---|
2130 | if (Opts.fVirtualImageMaker)
|
---|
2131 | return rtFsIsoMakerCmdSyntaxError(&Opts, "The --output option is not allowed");
|
---|
2132 | if (Opts.pszOutFile)
|
---|
2133 | return rtFsIsoMakerCmdSyntaxError(&Opts, "The --output option is specified more than once");
|
---|
2134 | Opts.pszOutFile = ValueUnion.psz;
|
---|
2135 | break;
|
---|
2136 |
|
---|
2137 | /*
|
---|
2138 | * Standard bits.
|
---|
2139 | */
|
---|
2140 | case 'h':
|
---|
2141 | rtFsIsoMakerCmdUsage(&Opts, papszArgs[0]);
|
---|
2142 | return rtFsIsoMakerCmdDeleteState(&Opts, Opts.fVirtualImageMaker ? VERR_NOT_FOUND : VINF_SUCCESS);
|
---|
2143 |
|
---|
2144 | case 'V':
|
---|
2145 | rtFsIsoMakerPrintf(&Opts, "%sr%d\n", RTBldCfgVersion(), RTBldCfgRevision());
|
---|
2146 | return rtFsIsoMakerCmdDeleteState(&Opts, Opts.fVirtualImageMaker ? VERR_NOT_FOUND : VINF_SUCCESS);
|
---|
2147 |
|
---|
2148 | default:
|
---|
2149 | if (rc > 0 && RT_C_IS_GRAPH(rc))
|
---|
2150 | rc = rtFsIsoMakerCmdErrorRc(&Opts, VERR_GETOPT_UNKNOWN_OPTION, "Unhandled option: -%c", rc);
|
---|
2151 | else if (rc > 0)
|
---|
2152 | rc = rtFsIsoMakerCmdErrorRc(&Opts, VERR_GETOPT_UNKNOWN_OPTION, "Unhandled option: %i (%#x)", rc, rc);
|
---|
2153 | else if (rc == VERR_GETOPT_UNKNOWN_OPTION)
|
---|
2154 | rc = rtFsIsoMakerCmdErrorRc(&Opts, rc, "Unknown option: '%s'", ValueUnion.psz);
|
---|
2155 | else if (ValueUnion.pDef)
|
---|
2156 | rc = rtFsIsoMakerCmdErrorRc(&Opts, rc, "%s: %Rrs", ValueUnion.pDef->pszLong, rc);
|
---|
2157 | else
|
---|
2158 | rc = rtFsIsoMakerCmdErrorRc(&Opts, rc, "%Rrs", rc);
|
---|
2159 | return rtFsIsoMakerCmdDeleteState(&Opts, rc);
|
---|
2160 | }
|
---|
2161 | }
|
---|
2162 |
|
---|
2163 | /*
|
---|
2164 | * Check for mandatory options.
|
---|
2165 | */
|
---|
2166 | if (RT_SUCCESS(rc))
|
---|
2167 | {
|
---|
2168 | if (!Opts.cItemsAdded)
|
---|
2169 | rc = rtFsIsoMakerCmdErrorRc(&Opts, VERR_NO_DATA, "Cowardly refuses to create empty ISO image");
|
---|
2170 | else if (!Opts.pszOutFile && !Opts.fVirtualImageMaker)
|
---|
2171 | rc = rtFsIsoMakerCmdErrorRc(&Opts, VERR_INVALID_PARAMETER, "No output file specified (--output <file>)");
|
---|
2172 | }
|
---|
2173 |
|
---|
2174 | /*
|
---|
2175 | * Final actions.
|
---|
2176 | */
|
---|
2177 | if (RT_SUCCESS(rc))
|
---|
2178 | rc = rtFsIsoMakerCmdOptEltoritoCommitBootCatalog(&Opts);
|
---|
2179 | if (RT_SUCCESS(rc))
|
---|
2180 | {
|
---|
2181 | /*
|
---|
2182 | * Finalize the image and get the virtual file.
|
---|
2183 | */
|
---|
2184 | rc = RTFsIsoMakerFinalize(Opts.hIsoMaker);
|
---|
2185 | if (RT_SUCCESS(rc))
|
---|
2186 | {
|
---|
2187 | RTVFSFILE hVfsFile;
|
---|
2188 | rc = RTFsIsoMakerCreateVfsOutputFile(Opts.hIsoMaker, &hVfsFile);
|
---|
2189 | if (RT_SUCCESS(rc))
|
---|
2190 | {
|
---|
2191 | /*
|
---|
2192 | * We're done now if we're only setting up a virtual image.
|
---|
2193 | */
|
---|
2194 | if (Opts.fVirtualImageMaker)
|
---|
2195 | *phVfsFile = hVfsFile;
|
---|
2196 | else
|
---|
2197 | {
|
---|
2198 | rc = rtFsIsoMakerCmdWriteImage(&Opts, hVfsFile);
|
---|
2199 | RTVfsFileRelease(hVfsFile);
|
---|
2200 | }
|
---|
2201 | }
|
---|
2202 | else
|
---|
2203 | rc = rtFsIsoMakerCmdErrorRc(&Opts, rc, "RTFsIsoMakerCreateVfsOutputFile failed: %Rrc", rc);
|
---|
2204 | }
|
---|
2205 | else
|
---|
2206 | rc = rtFsIsoMakerCmdErrorRc(&Opts, rc, "RTFsIsoMakerFinalize failed: %Rrc", rc);
|
---|
2207 | }
|
---|
2208 |
|
---|
2209 | return rtFsIsoMakerCmdDeleteState(&Opts, rc);
|
---|
2210 | }
|
---|
2211 |
|
---|
2212 |
|
---|
2213 | /**
|
---|
2214 | * ISO maker command (creates image file on disk).
|
---|
2215 | *
|
---|
2216 | * @returns IPRT status code
|
---|
2217 | * @param cArgs Number of arguments.
|
---|
2218 | * @param papszArgs Pointer to argument array.
|
---|
2219 | */
|
---|
2220 | RTDECL(RTEXITCODE) RTFsIsoMakerCmd(unsigned cArgs, char **papszArgs)
|
---|
2221 | {
|
---|
2222 | int rc = RTFsIsoMakerCmdEx(cArgs, papszArgs, NULL, NULL);
|
---|
2223 | return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
|
---|
2224 | }
|
---|
2225 |
|
---|