-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmakehybrid.go
361 lines (238 loc) · 16 KB
/
makehybrid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
// Copyright 2017 The go-darwin Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package hdiutil
import "os/exec"
// makehybridFlag implements a hdiutil makehybrid command flag interface.
type makehybridFlag interface {
makehybridFlag() []string
}
type makehybridHFS bool
func (m makehybridHFS) makehybridFlag() []string { return boolFlag("hfs", bool(m)) }
type makehybridISO bool
func (m makehybridISO) makehybridFlag() []string { return boolFlag("iso", bool(m)) }
type makehybridJoliet bool
func (m makehybridJoliet) makehybridFlag() []string { return boolFlag("joliet", bool(m)) }
type makehybridUDF bool
func (m makehybridUDF) makehybridFlag() []string { return boolFlag("udf", bool(m)) }
type makehybridHFSBlessedDirectory bool
func (m makehybridHFSBlessedDirectory) makehybridFlag() []string {
return boolFlag("hfs-blessed-directory", bool(m))
}
type makehybridHFSOpenfolder bool
func (m makehybridHFSOpenfolder) makehybridFlag() []string { return boolFlag("hfs-openfolder", bool(m)) }
type makehybridHFSStartupfileSize bool
func (m makehybridHFSStartupfileSize) makehybridFlag() []string {
return boolFlag("hfs-startupfile-size", bool(m))
}
type makehybridAbstractFile bool
func (m makehybridAbstractFile) makehybridFlag() []string { return boolFlag("abstract-file", bool(m)) }
type makehybridBibliographyFile bool
func (m makehybridBibliographyFile) makehybridFlag() []string {
return boolFlag("bibliography-file", bool(m))
}
type makehybridCopyrightFile bool
func (m makehybridCopyrightFile) makehybridFlag() []string { return boolFlag("copyright-file", bool(m)) }
type makehybridApplication bool
func (m makehybridApplication) makehybridFlag() []string { return boolFlag("application", bool(m)) }
type makehybridPreparer bool
func (m makehybridPreparer) makehybridFlag() []string { return boolFlag("preparer", bool(m)) }
type makehybridPublisher bool
func (m makehybridPublisher) makehybridFlag() []string { return boolFlag("publisher", bool(m)) }
type makehybridSystemID bool
func (m makehybridSystemID) makehybridFlag() []string { return boolFlag("system-id", bool(m)) }
type makehybridKeepMacSpecific bool
func (m makehybridKeepMacSpecific) makehybridFlag() []string {
return boolFlag("keep-mac-specific", bool(m))
}
type makehybridEltoritoBoot bool
func (m makehybridEltoritoBoot) makehybridFlag() []string { return boolFlag("eltorito-boot", bool(m)) }
type makehybridHardDiskBoot bool
func (m makehybridHardDiskBoot) makehybridFlag() []string { return boolFlag("hard-disk-boot", bool(m)) }
type makehybridNoEmulBoot bool
func (m makehybridNoEmulBoot) makehybridFlag() []string { return boolFlag("no-emul-boot", bool(m)) }
type makehybridNoBoot bool
func (m makehybridNoBoot) makehybridFlag() []string { return boolFlag("no-boot", bool(m)) }
type makehybridBootLoadSeg bool
func (m makehybridBootLoadSeg) makehybridFlag() []string { return boolFlag("boot-load-seg", bool(m)) }
type makehybridBootLoadSize bool
func (m makehybridBootLoadSize) makehybridFlag() []string { return boolFlag("boot-load-seg", bool(m)) }
type makehybridEltoritoPlatform bool
func (m makehybridEltoritoPlatform) makehybridFlag() []string {
return boolFlag("eltorito-platform", bool(m))
}
type makehybridEltoritoSpecification bool
func (m makehybridEltoritoSpecification) makehybridFlag() []string {
return boolFlag("eltorito-specification", bool(m))
}
type makehybridUDFVersion bool
func (m makehybridUDFVersion) makehybridFlag() []string { return boolFlag("udf-version", bool(m)) }
type makehybridDefaultVolumeName bool
func (m makehybridDefaultVolumeName) makehybridFlag() []string {
return boolFlag("default-volume-name", bool(m))
}
type makehybridHFSVolumeName bool
func (m makehybridHFSVolumeName) makehybridFlag() []string {
return boolFlag("hfs-volume-name", bool(m))
}
type makehybridISOVolumeName bool
func (m makehybridISOVolumeName) makehybridFlag() []string {
return boolFlag("iso-volume-name", bool(m))
}
type makehybridJolietVolumeName bool
func (m makehybridJolietVolumeName) makehybridFlag() []string {
return boolFlag("joliet-volume-name", bool(m))
}
type makehybridUDFVolumeName bool
func (m makehybridUDFVolumeName) makehybridFlag() []string {
return boolFlag("udf-volume-name", bool(m))
}
type makehybridHideAll bool
func (m makehybridHideAll) makehybridFlag() []string { return boolFlag("hide-all", bool(m)) }
type makehybridHideHFS bool
func (m makehybridHideHFS) makehybridFlag() []string { return boolFlag("hide-hfs", bool(m)) }
type makehybridHideISO bool
func (m makehybridHideISO) makehybridFlag() []string { return boolFlag("hide-iso", bool(m)) }
type makehybridHideJoliet bool
func (m makehybridHideJoliet) makehybridFlag() []string { return boolFlag("hide-joliet", bool(m)) }
type makehybridHideUDF bool
func (m makehybridHideUDF) makehybridFlag() []string { return boolFlag("hide-udf", bool(m)) }
type makehybridOnlyUDF bool
func (m makehybridOnlyUDF) makehybridFlag() []string { return boolFlag("only-udf", bool(m)) }
type makehybridOnlyISO bool
func (m makehybridOnlyISO) makehybridFlag() []string { return boolFlag("only-iso", bool(m)) }
type makehybridOnlyJoliet bool
func (m makehybridOnlyJoliet) makehybridFlag() []string { return boolFlag("only-joliet", bool(m)) }
type makehybridPrintSize bool
func (m makehybridPrintSize) makehybridFlag() []string { return boolFlag("print-size", bool(m)) }
type makehybridPlistin bool
func (m makehybridPlistin) makehybridFlag() []string { return boolFlag("plistin", bool(m)) }
const (
// MakehybridHFS generate an HFS+ filesystem.
//
// This filesystem can be present on an image simultaneously with an ISO9660 or Joliet or UDF filesystem.
// On operating systems that understand HFS+ as well as ISO9660 and UDF, like Mac OS 9 or OS X, HFS+ is usually the preferred filesystem for hybrid images.
MakehybridHFS makehybridHFS = true
// MakehybridISO generate an ISO9660 Level 2 filesystem with Rock Ridge extensions.
//
// This filesystem can be present on an image simultaneously with an HFS+ or Joliet or UDF filesystem.
// ISO9660 is the standard cross-platform interchange format for CDs and some DVDs, and is understood by virtually all operating systems.
//
// If an ISO9660 or Joliet filesystem is present on a disk image or CD, but not HFS+, OS X will use the ISO9660 (or Joliet) filesystem.
MakehybridISO makehybridISO = true
// MakeHybridJoliet generate joliet extensions to ISO9660.
//
// This view of the filesystem can be present on an image simultaneously with HFS+, and requires the presence of an ISO9660 filesystem.
// Joliet supports Unicode filenames, but is only supported on some operating systems.
//
// If both an ISO9660 and Joliet filesystem are present on a disk image or CD, but not HFS+, OS X will prefer the Joliet filesystem.
MakeHybridJoliet makehybridJoliet = true
// MakeHybridUDF generate a UDF filesystem.
//
// This filesystem can be present on an image simultaneously with HFS+, ISO9660, and Joliet.
// UDF is the standard interchange format for DVDs, although operating system support varies based on OS version and UDF version.
MakeHybridUDF makehybridUDF = true
// MakehybridHFSBlessedDirectory path to directory which should be "blessed" for OS X booting on the generated filesystem.
//
// This assumes the directory has been otherwise prepared, for example with bless -bootinfo to create a valid BootX file. (HFS+ only).
MakehybridHFSBlessedDirectory makehybridHFSBlessedDirectory = true
// MakehybridHFSOpenfolder path to a directory that will be opened by the Finder automatically. See also the -openfolder option in bless(8) (HFS+ only).
MakehybridHFSOpenfolder makehybridHFSOpenfolder = true
// MakehybridHFSStartupfileSize allocate an empty HFS+ Startup File of the specified size, in bytes (HFS+ only).
MakehybridHFSStartupfileSize makehybridHFSStartupfileSize = true
// MakehybridAbstractFile path to a file in the source directory (and thus the root of the generated filesystem) for use as the ISO9660/Joliet Abstract file (ISO9660/Joliet).
MakehybridAbstractFile makehybridAbstractFile = true
// MakehybridBibliographyFile path to a file in the source directory (and thus the root of the generated filesystem) for use as the ISO9660/Joliet Bibliography file (ISO9660/Joliet).
MakehybridBibliographyFile makehybridBibliographyFile = true
// MakehybridCopyrightFile path to a file in the source directory (and thus the root of the generated filesystem) for use as the ISO9660/Joliet Copyright file (ISO9660/Joliet).
MakehybridCopyrightFile makehybridCopyrightFile = true
// MakehybridApplication Application string (ISO9660/Joliet).
MakehybridApplication makehybridApplication = true
// MakehybridPreparer preparer string (ISO9660/Joliet).
MakehybridPreparer makehybridPreparer = true
// MakehybridPublisher publisher string (ISO9660/Joliet).
MakehybridPublisher makehybridPublisher = true
// MakehybridSystemID system Identification string (ISO9660/Joliet).
MakehybridSystemID makehybridSystemID = true
// MakehybridKeepMacSpecific Expose Macintosh-specific files (such as .DS_Store) in non-HFS+ filesystems (ISO9660/Joliet).
MakehybridKeepMacSpecific makehybridKeepMacSpecific = true
// MakehybridEltoritoBoot path to an El Torito boot image within the source directory. By default, floppy drive emulation is used, so the image must be one of 1200KB, 1440KB, or 2880KB. If the image has a different size, either -no-emul-boot or
// -hard-disk-boot must be used to enable "No Emulation" or "Hard Disk Emulation" mode, respectively (ISO9660/Joliet).
MakehybridEltoritoBoot makehybridEltoritoBoot = true
// MakehybridHardDiskBoot use El Torito Hard Disk Emulation mode. The image must represent a virtual device with an MBR partition map and a single partition.
MakehybridHardDiskBoot makehybridHardDiskBoot = true
// MakehybridNoEmulBoot use El Torito No Emulation mode. The system firmware will load the number of sectors specified by -boot-load-size and execute it, without emulating any devices (ISO9660/Joliet).
MakehybridNoEmulBoot makehybridNoEmulBoot = true
// MakehybridNoBoot mark the El Torito image as non-bootable. The system firmware may still create a virtual device backed by this data. This option is not recommended (ISO9660/Joliet).
MakehybridNoBoot makehybridNoBoot = true
// MakehybridBootLoadSeg for a No Emulation boot image, load the data at the specified segment address. This options is not recommended, so that the system firmware can use its default address (ISO9660/Joliet)
MakehybridBootLoadSeg makehybridBootLoadSeg = true
// MakehybridBootLoadSize for a No Emulation boot image, load the specified number of 512-byte emulated sectors into memory and execute it. By default, 4 sectors (2KB) will be loaded (ISO9660/Joliet).
MakehybridBootLoadSize makehybridBootLoadSize = true
// MakehybridEltoritoPlatform use the specified numeric platform ID in the El Torito Boot Catalog Validation Entry or Section Header. Defaults to 0 to identify x86 hardware (ISO/Joliet).
MakehybridEltoritoPlatform makehybridEltoritoPlatform = true
// MakehybridEltoritoSpecification for complex layouts involving multiple boot images, a plist-formatted string can be provided, using either OpenStep-style syntax or XML syntax, representing an array of dictionaries.
//
// Any of the El Torito options can be set in the sub-dictionaries and will apply to that boot image only.
// If -eltorito-specification is provided in addition to the normal El Torito command-line options, the specification will be used to populate secondary non-default boot entries.
MakehybridEltoritoSpecification makehybridEltoritoSpecification = true
// MakehybridUDFVersion version of UDF filesystem to generate. This can be either "1.02" or "1.50". If not specified, it defaults to "1.50" (UDF).
MakehybridUDFVersion makehybridUDFVersion = true
// MakehybridDefaultVolumeName default volume name for all filesystems, unless overridden.
//
// If not specified, defaults to the last path component of source.
MakehybridDefaultVolumeName makehybridDefaultVolumeName = true
// MakehybridHFSVolumeName volume name for just the HFS+ filesystem if it should be different (HFS+ only).
MakehybridHFSVolumeName makehybridHFSVolumeName = true
// MakehybridISOVolumeName volume name for just the ISO9660 filesystem if it should be different (ISO9660 only).
MakehybridISOVolumeName makehybridISOVolumeName = true
// MakehybridJolietVolumeName volume name for just the Joliet filesystem if it should be different (Joliet only).
MakehybridJolietVolumeName makehybridJolietVolumeName = true
// MakehybridUDFVolumeName volume name for just the UDF filesystem if it should be different (UDF only).
MakehybridUDFVolumeName makehybridUDFVolumeName = true
// MakehybridHideAll a glob expression of files and directories that should not be exposed in the generated filesystems.
//
// The string may need to be quoted to avoid shell expansion, and will be passed to glob(3) for evaluation.
// Although this option can not be used multiple times, an arbitrarily complex glob expression can be used.
MakehybridHideAll makehybridHideAll = true
// MakehybridHideHFS a glob expression of files and directories that should not be exposed via the HFS+ filesystem, although the data may still be present for use by other filesystems (HFS+ only).
MakehybridHideHFS makehybridHideHFS = true
// MakehybridHideISO a glob expression of files and directories that should not be exposed via the ISO filesystem, although the data may still be present for use by other filesystems (ISO9660 only).
//
// Per above, the Joliet hierarchy will supersede the ISO hierarchy when the hybrid is mounted as an ISO 9660 filesystem on OS X.
// Therefore, if Joliet is being generated (the default) -hide-joliet will also be needed to hide the file from mount_cd9660(8).
MakehybridHideISO makehybridHideISO = true
// MakehybridHideJoliet a glob expression of files and directories that should not be exposed via the Joliet filesystem, although the data may still be present for use by other filesystems (Joliet only).
//
// Because OS X's ISO 9660 filesystem uses the Joliet catalog if it is available, -hide-joliet effectively supersedes -hide-iso when the resulting filesystem is mounted as ISO on OS X.
MakehybridHideJoliet makehybridHideJoliet = true
// MakehybridHideUDF a glob expression of files and directories that should not be exposed via the UDF filesystem, although the data may still be present for use by other filesystems (UDF only).
MakehybridHideUDF makehybridHideUDF = true
// MakehybridOnlyUDF a glob expression of objects that should only be exposed in UDF.
MakehybridOnlyUDF makehybridOnlyUDF = true
// MakehybridOnlyISO a glob expression of objects that should only be exposed in ISO.
MakehybridOnlyISO makehybridOnlyISO = true
// MakehybridOnlyJoliet a glob expression of objects that should only be exposed in Joleit.
MakehybridOnlyJoliet makehybridOnlyJoliet = true
// MakehybridPrintSize preflight the data and calculate an upper bound on the size of the image. The actual size of the generated image is guaranteed to be less than or equal to this estimate.
MakehybridPrintSize makehybridPrintSize = true
// MakehybridPlistin instead of using command-line parameters, use a standard plist from standard input to specific the parameters of the hybrid image generation.
//
// Each command-line option should be a key in the dictionary, without the leading "-", and the value should be a string for path and string arguments, a number for number arguments, and a boolean for toggle options.
// The source argument should use a key of "source" and the image should use a key of "output".
MakehybridPlistin makehybridPlistin = true
)
// Makehybrid generate a potentially-hybrid filesystem in a read-only disk image using the DiscRecording framework's content creation system.
func Makehybrid(image, source string, flags ...makehybridFlag) error {
cmd := exec.Command(hdiutilPath, "makehybrid", image, source)
if len(flags) > 0 {
for _, flag := range flags {
cmd.Args = append(cmd.Args, flag.makehybridFlag()...)
}
}
err := cmd.Run()
if err != nil {
return err
}
return nil
}