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