From Nathan Whitehorn (nwhitehorn at freebsd dot org): Add code to generate bootable ISOs on Powermac and CHRP systems. Synthesize some partition maps (APM and MBR, respectively) pointing to (a) the whole disk, and (b) relevant El Torito boot images that have been added by other code. These partition maps are a little bit funny looking, but they seem to work. FreeBSD has been using this successfully in their release generation on powerpc, as well as generating all non-SPARC install media. SPARC support could probably be added as an extension of this patch.diff -r1.28 -r1.29 src/usr.sbin/makefs/cd9660.c
(christos)
--- src/usr.sbin/makefs/cd9660.c 2010/11/19 15:47:32 1.28
+++ src/usr.sbin/makefs/cd9660.c 2011/05/22 21:51:39 1.29
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: cd9660.c,v 1.28 2010/11/19 15:47:32 tsutsui Exp $ */ | 1 | /* $NetBSD: cd9660.c,v 1.29 2011/05/22 21:51:39 christos Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan | 4 | * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan | |
5 | * Perez-Rathke and Ram Vedam. All rights reserved. | 5 | * Perez-Rathke and Ram Vedam. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys, | 7 | * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys, | |
8 | * Alan Perez-Rathke and Ram Vedam. | 8 | * Alan Perez-Rathke and Ram Vedam. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or | 10 | * Redistribution and use in source and binary forms, with or | |
11 | * without modification, are permitted provided that the following | 11 | * without modification, are permitted provided that the following | |
12 | * conditions are met: | 12 | * conditions are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -93,27 +93,27 @@ | @@ -93,27 +93,27 @@ | |||
93 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 93 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
94 | * SUCH DAMAGE. | 94 | * SUCH DAMAGE. | |
95 | * | 95 | * | |
96 | */ | 96 | */ | |
97 | 97 | |||
98 | #if HAVE_NBTOOL_CONFIG_H | 98 | #if HAVE_NBTOOL_CONFIG_H | |
99 | #include "nbtool_config.h" | 99 | #include "nbtool_config.h" | |
100 | #else | 100 | #else | |
101 | #include <sys/mount.h> | 101 | #include <sys/mount.h> | |
102 | #endif | 102 | #endif | |
103 | 103 | |||
104 | #include <sys/cdefs.h> | 104 | #include <sys/cdefs.h> | |
105 | #if defined(__RCSID) && !defined(__lint) | 105 | #if defined(__RCSID) && !defined(__lint) | |
106 | __RCSID("$NetBSD: cd9660.c,v 1.28 2010/11/19 15:47:32 tsutsui Exp $"); | 106 | __RCSID("$NetBSD: cd9660.c,v 1.29 2011/05/22 21:51:39 christos Exp $"); | |
107 | #endif /* !__lint */ | 107 | #endif /* !__lint */ | |
108 | 108 | |||
109 | #include <string.h> | 109 | #include <string.h> | |
110 | #include <ctype.h> | 110 | #include <ctype.h> | |
111 | #include <sys/param.h> | 111 | #include <sys/param.h> | |
112 | #include <sys/queue.h> | 112 | #include <sys/queue.h> | |
113 | 113 | |||
114 | #include "makefs.h" | 114 | #include "makefs.h" | |
115 | #include "cd9660.h" | 115 | #include "cd9660.h" | |
116 | #include "cd9660/iso9660_rrip.h" | 116 | #include "cd9660/iso9660_rrip.h" | |
117 | #include "cd9660/cd9660_archimedes.h" | 117 | #include "cd9660/cd9660_archimedes.h" | |
118 | 118 | |||
119 | /* | 119 | /* | |
@@ -205,26 +205,27 @@ cd9660_set_defaults(void) | @@ -205,26 +205,27 @@ cd9660_set_defaults(void) | |||
205 | 205 | |||
206 | /* Set up defaults in our own structure */ | 206 | /* Set up defaults in our own structure */ | |
207 | diskStructure.verbose_level = 0; | 207 | diskStructure.verbose_level = 0; | |
208 | diskStructure.keep_bad_images = 0; | 208 | diskStructure.keep_bad_images = 0; | |
209 | diskStructure.follow_sym_links = 0; | 209 | diskStructure.follow_sym_links = 0; | |
210 | diskStructure.isoLevel = 2; | 210 | diskStructure.isoLevel = 2; | |
211 | 211 | |||
212 | diskStructure.rock_ridge_enabled = 0; | 212 | diskStructure.rock_ridge_enabled = 0; | |
213 | diskStructure.rock_ridge_renamed_dir_name = 0; | 213 | diskStructure.rock_ridge_renamed_dir_name = 0; | |
214 | diskStructure.rock_ridge_move_count = 0; | 214 | diskStructure.rock_ridge_move_count = 0; | |
215 | diskStructure.rr_moved_dir = 0; | 215 | diskStructure.rr_moved_dir = 0; | |
216 | 216 | |||
217 | diskStructure.archimedes_enabled = 0; | 217 | diskStructure.archimedes_enabled = 0; | |
218 | diskStructure.chrp_boot = 0; | |||
218 | 219 | |||
219 | diskStructure.include_padding_areas = 1; | 220 | diskStructure.include_padding_areas = 1; | |
220 | 221 | |||
221 | /* Spec breaking functionality */ | 222 | /* Spec breaking functionality */ | |
222 | diskStructure.allow_deep_trees = | 223 | diskStructure.allow_deep_trees = | |
223 | diskStructure.allow_start_dot = | 224 | diskStructure.allow_start_dot = | |
224 | diskStructure.allow_max_name = | 225 | diskStructure.allow_max_name = | |
225 | diskStructure.allow_illegal_chars = | 226 | diskStructure.allow_illegal_chars = | |
226 | diskStructure.allow_lowercase = | 227 | diskStructure.allow_lowercase = | |
227 | diskStructure.allow_multidot = | 228 | diskStructure.allow_multidot = | |
228 | diskStructure.omit_trailing_period = 0; | 229 | diskStructure.omit_trailing_period = 0; | |
229 | 230 | |||
230 | /* Make sure the PVD is clear */ | 231 | /* Make sure the PVD is clear */ | |
@@ -389,26 +390,28 @@ cd9660_parse_opts(const char *option, fs | @@ -389,26 +390,28 @@ cd9660_parse_opts(const char *option, fs | |||
389 | } | 390 | } | |
390 | } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "G", "generic-bootimage")) { | 391 | } else if (CD9660_IS_COMMAND_ARG_DUAL(var, "G", "generic-bootimage")) { | |
391 | if (val == NULL) | 392 | if (val == NULL) | |
392 | warnx("error: The Boot Image parameter requires a valid boot information string"); | 393 | warnx("error: The Boot Image parameter requires a valid boot information string"); | |
393 | else | 394 | else | |
394 | rv = cd9660_add_generic_bootimage(val); | 395 | rv = cd9660_add_generic_bootimage(val); | |
395 | } else if (CD9660_IS_COMMAND_ARG(var, "no-trailing-padding")) | 396 | } else if (CD9660_IS_COMMAND_ARG(var, "no-trailing-padding")) | |
396 | diskStructure.include_padding_areas = 0; | 397 | diskStructure.include_padding_areas = 0; | |
397 | /* RRIP */ | 398 | /* RRIP */ | |
398 | else if (CD9660_IS_COMMAND_ARG_DUAL(var, "R", "rockridge")) | 399 | else if (CD9660_IS_COMMAND_ARG_DUAL(var, "R", "rockridge")) | |
399 | diskStructure.rock_ridge_enabled = 1; | 400 | diskStructure.rock_ridge_enabled = 1; | |
400 | else if (CD9660_IS_COMMAND_ARG_DUAL(var, "A", "archimedes")) | 401 | else if (CD9660_IS_COMMAND_ARG_DUAL(var, "A", "archimedes")) | |
401 | diskStructure.archimedes_enabled = 1; | 402 | diskStructure.archimedes_enabled = 1; | |
403 | else if (CD9660_IS_COMMAND_ARG(var, "chrp-boot")) | |||
404 | diskStructure.chrp_boot = 1; | |||
402 | else if (CD9660_IS_COMMAND_ARG_DUAL(var, "K", "keep-bad-images")) | 405 | else if (CD9660_IS_COMMAND_ARG_DUAL(var, "K", "keep-bad-images")) | |
403 | diskStructure.keep_bad_images = 1; | 406 | diskStructure.keep_bad_images = 1; | |
404 | else if (CD9660_IS_COMMAND_ARG(var, "allow-deep-trees")) | 407 | else if (CD9660_IS_COMMAND_ARG(var, "allow-deep-trees")) | |
405 | diskStructure.allow_deep_trees = 1; | 408 | diskStructure.allow_deep_trees = 1; | |
406 | else if (CD9660_IS_COMMAND_ARG(var, "allow-max-name")) | 409 | else if (CD9660_IS_COMMAND_ARG(var, "allow-max-name")) | |
407 | diskStructure.allow_max_name = 1; | 410 | diskStructure.allow_max_name = 1; | |
408 | else if (CD9660_IS_COMMAND_ARG(var, "allow-illegal-chars")) | 411 | else if (CD9660_IS_COMMAND_ARG(var, "allow-illegal-chars")) | |
409 | diskStructure.allow_illegal_chars = 1; | 412 | diskStructure.allow_illegal_chars = 1; | |
410 | else if (CD9660_IS_COMMAND_ARG(var, "allow-lowercase")) | 413 | else if (CD9660_IS_COMMAND_ARG(var, "allow-lowercase")) | |
411 | diskStructure.allow_lowercase = 1; | 414 | diskStructure.allow_lowercase = 1; | |
412 | else if (CD9660_IS_COMMAND_ARG(var,"allow-multidot")) | 415 | else if (CD9660_IS_COMMAND_ARG(var,"allow-multidot")) | |
413 | diskStructure.allow_multidot = 1; | 416 | diskStructure.allow_multidot = 1; | |
414 | else if (CD9660_IS_COMMAND_ARG(var, "omit-trailing-period")) | 417 | else if (CD9660_IS_COMMAND_ARG(var, "omit-trailing-period")) |
--- src/usr.sbin/makefs/cd9660.h 2010/10/27 18:51:34 1.15
+++ src/usr.sbin/makefs/cd9660.h 2011/05/22 21:51:39 1.16
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: cd9660.h,v 1.15 2010/10/27 18:51:34 christos Exp $ */ | 1 | /* $NetBSD: cd9660.h,v 1.16 2011/05/22 21:51:39 christos Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan | 4 | * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan | |
5 | * Perez-Rathke and Ram Vedam. All rights reserved. | 5 | * Perez-Rathke and Ram Vedam. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys, | 7 | * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys, | |
8 | * Alan Perez-Rathke and Ram Vedam. | 8 | * Alan Perez-Rathke and Ram Vedam. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or | 10 | * Redistribution and use in source and binary forms, with or | |
11 | * without modification, are permitted provided that the following | 11 | * without modification, are permitted provided that the following | |
12 | * conditions are met: | 12 | * conditions are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -276,26 +276,27 @@ typedef struct _iso9660_disk { | @@ -276,26 +276,27 @@ typedef struct _iso9660_disk { | |||
276 | 276 | |||
277 | /* SUSP options and variables */ | 277 | /* SUSP options and variables */ | |
278 | int64_t susp_continuation_area_start_sector; | 278 | int64_t susp_continuation_area_start_sector; | |
279 | int64_t susp_continuation_area_size; | 279 | int64_t susp_continuation_area_size; | |
280 | int64_t susp_continuation_area_current_free; | 280 | int64_t susp_continuation_area_current_free; | |
281 | 281 | |||
282 | int rock_ridge_enabled; | 282 | int rock_ridge_enabled; | |
283 | /* Other Rock Ridge Variables */ | 283 | /* Other Rock Ridge Variables */ | |
284 | char *rock_ridge_renamed_dir_name; | 284 | char *rock_ridge_renamed_dir_name; | |
285 | int rock_ridge_move_count; | 285 | int rock_ridge_move_count; | |
286 | cd9660node *rr_moved_dir; | 286 | cd9660node *rr_moved_dir; | |
287 | 287 | |||
288 | int archimedes_enabled; | 288 | int archimedes_enabled; | |
289 | int chrp_boot; | |||
289 | 290 | |||
290 | /* Spec breaking options */ | 291 | /* Spec breaking options */ | |
291 | u_char allow_deep_trees; | 292 | u_char allow_deep_trees; | |
292 | u_char allow_start_dot; | 293 | u_char allow_start_dot; | |
293 | u_char allow_max_name; /* Allow 37 char filenames*/ | 294 | u_char allow_max_name; /* Allow 37 char filenames*/ | |
294 | u_char allow_illegal_chars; /* ~, !, # */ | 295 | u_char allow_illegal_chars; /* ~, !, # */ | |
295 | u_char allow_lowercase; | 296 | u_char allow_lowercase; | |
296 | u_char allow_multidot; | 297 | u_char allow_multidot; | |
297 | u_char omit_trailing_period; | 298 | u_char omit_trailing_period; | |
298 | 299 | |||
299 | /* BOOT INFORMATION HERE */ | 300 | /* BOOT INFORMATION HERE */ | |
300 | int has_generic_bootimage; /* Default to 0 */ | 301 | int has_generic_bootimage; /* Default to 0 */ | |
301 | char *generic_bootimage; | 302 | char *generic_bootimage; |
--- src/usr.sbin/makefs/makefs.8 2009/01/20 20:47:25 1.32
+++ src/usr.sbin/makefs/makefs.8 2011/05/22 21:51:39 1.33
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | .\" $NetBSD: makefs.8,v 1.32 2009/01/20 20:47:25 bjh21 Exp $ | 1 | .\" $NetBSD: makefs.8,v 1.33 2011/05/22 21:51:39 christos Exp $ | |
2 | .\" | 2 | .\" | |
3 | .\" Copyright (c) 2001-2003 Wasabi Systems, Inc. | 3 | .\" Copyright (c) 2001-2003 Wasabi Systems, Inc. | |
4 | .\" All rights reserved. | 4 | .\" All rights reserved. | |
5 | .\" | 5 | .\" | |
6 | .\" Written by Luke Mewburn for Wasabi Systems, Inc. | 6 | .\" Written by Luke Mewburn for Wasabi Systems, Inc. | |
7 | .\" | 7 | .\" | |
8 | .\" Redistribution and use in source and binary forms, with or without | 8 | .\" Redistribution and use in source and binary forms, with or without | |
9 | .\" modification, are permitted provided that the following conditions | 9 | .\" modification, are permitted provided that the following conditions | |
10 | .\" are met: | 10 | .\" are met: | |
11 | .\" 1. Redistributions of source code must retain the above copyright | 11 | .\" 1. Redistributions of source code must retain the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer. | 12 | .\" notice, this list of conditions and the following disclaimer. | |
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
14 | .\" notice, this list of conditions and the following disclaimer in the | 14 | .\" notice, this list of conditions and the following disclaimer in the | |
@@ -23,27 +23,27 @@ | @@ -23,27 +23,27 @@ | |||
23 | .\" | 23 | .\" | |
24 | .\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND | 24 | .\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND | |
25 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 25 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
26 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 26 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
27 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC | 27 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC | |
28 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 28 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
29 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 29 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
30 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 30 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
31 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 31 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
32 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 32 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
33 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 33 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
34 | .\" POSSIBILITY OF SUCH DAMAGE. | 34 | .\" POSSIBILITY OF SUCH DAMAGE. | |
35 | .\" | 35 | .\" | |
36 | .Dd January 10, 2009 | 36 | .Dd May 22, 2011 | |
37 | .Dt MAKEFS 8 | 37 | .Dt MAKEFS 8 | |
38 | .Os | 38 | .Os | |
39 | .Sh NAME | 39 | .Sh NAME | |
40 | .Nm makefs | 40 | .Nm makefs | |
41 | .Nd create a file system image from a directory tree | 41 | .Nd create a file system image from a directory tree | |
42 | .Sh SYNOPSIS | 42 | .Sh SYNOPSIS | |
43 | .Nm | 43 | .Nm | |
44 | .Op Fl x | 44 | .Op Fl x | |
45 | .Op Fl B Ar byte-order | 45 | .Op Fl B Ar byte-order | |
46 | .Op Fl b Ar free-blocks | 46 | .Op Fl b Ar free-blocks | |
47 | .Op Fl d Ar debug-mask | 47 | .Op Fl d Ar debug-mask | |
48 | .Op Fl F Ar specfile | 48 | .Op Fl F Ar specfile | |
49 | .Op Fl f Ar free-files | 49 | .Op Fl f Ar free-files | |
@@ -273,26 +273,29 @@ the spec. | @@ -273,26 +273,29 @@ the spec. | |||
273 | .It Sy allow-max-name | 273 | .It Sy allow-max-name | |
274 | Allow 37 instead of 33 characters for filenames by omitting the | 274 | Allow 37 instead of 33 characters for filenames by omitting the | |
275 | version id. | 275 | version id. | |
276 | .It Sy allow-multidot | 276 | .It Sy allow-multidot | |
277 | Allow multiple dots in a filename. | 277 | Allow multiple dots in a filename. | |
278 | .It Sy applicationid | 278 | .It Sy applicationid | |
279 | Application ID of the image. | 279 | Application ID of the image. | |
280 | .It Sy archimedes | 280 | .It Sy archimedes | |
281 | Use the | 281 | Use the | |
282 | .Ql ARCHIMEDES | 282 | .Ql ARCHIMEDES | |
283 | extension to encode | 283 | extension to encode | |
284 | .Tn RISC OS | 284 | .Tn RISC OS | |
285 | metadata. | 285 | metadata. | |
286 | .It Sy chrp-boot | |||
287 | Write an MBR partition table to the image to allow older CHRP hardware to | |||
288 | boot. | |||
286 | .It Sy boot-load-segment | 289 | .It Sy boot-load-segment | |
287 | Set load segment for the boot image. | 290 | Set load segment for the boot image. | |
288 | .It Sy bootimage | 291 | .It Sy bootimage | |
289 | Filename of a boot image in the format | 292 | Filename of a boot image in the format | |
290 | .Dq sysid;filename , | 293 | .Dq sysid;filename , | |
291 | where | 294 | where | |
292 | .Dq sysid | 295 | .Dq sysid | |
293 | is one of | 296 | is one of | |
294 | .Ql i386 , | 297 | .Ql i386 , | |
295 | .Ql mac68k , | 298 | .Ql mac68k , | |
296 | .Ql macppc , | 299 | .Ql macppc , | |
297 | or | 300 | or | |
298 | .Ql powerpc . | 301 | .Ql powerpc . |
--- src/usr.sbin/makefs/cd9660/cd9660_eltorito.c 2010/10/27 18:51:35 1.14
+++ src/usr.sbin/makefs/cd9660/cd9660_eltorito.c 2011/05/22 21:51:39 1.15
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: cd9660_eltorito.c,v 1.14 2010/10/27 18:51:35 christos Exp $ */ | 1 | /* $NetBSD: cd9660_eltorito.c,v 1.15 2011/05/22 21:51:39 christos Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan | 4 | * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan | |
5 | * Perez-Rathke and Ram Vedam. All rights reserved. | 5 | * Perez-Rathke and Ram Vedam. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys, | 7 | * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys, | |
8 | * Alan Perez-Rathke and Ram Vedam. | 8 | * Alan Perez-Rathke and Ram Vedam. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or | 10 | * Redistribution and use in source and binary forms, with or | |
11 | * without modification, are permitted provided that the following | 11 | * without modification, are permitted provided that the following | |
12 | * conditions are met: | 12 | * conditions are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -21,32 +21,35 @@ | @@ -21,32 +21,35 @@ | |||
21 | * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR | 21 | * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR | |
22 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 22 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
23 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 23 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
24 | * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN | 24 | * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN | |
25 | * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT, | 25 | * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT, | |
26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | 27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |
28 | * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 28 | * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 29 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
32 | * OF SUCH DAMAGE. | 32 | * OF SUCH DAMAGE. | |
33 | */ | 33 | */ | |
34 | ||||
35 | #include <sys/endian.h> | |||
36 | ||||
34 | #include "cd9660.h" | 37 | #include "cd9660.h" | |
35 | #include "cd9660_eltorito.h" | 38 | #include "cd9660_eltorito.h" | |
36 | 39 | |||
37 | #include <sys/cdefs.h> | 40 | #include <sys/cdefs.h> | |
38 | #if defined(__RCSID) && !defined(__lint) | 41 | #if defined(__RCSID) && !defined(__lint) | |
39 | __RCSID("$NetBSD: cd9660_eltorito.c,v 1.14 2010/10/27 18:51:35 christos Exp $"); | 42 | __RCSID("$NetBSD: cd9660_eltorito.c,v 1.15 2011/05/22 21:51:39 christos Exp $"); | |
40 | #endif /* !__lint */ | 43 | #endif /* !__lint */ | |
41 | 44 | |||
42 | #ifdef DEBUG | 45 | #ifdef DEBUG | |
43 | #define ELTORITO_DPRINTF(__x) printf __x | 46 | #define ELTORITO_DPRINTF(__x) printf __x | |
44 | #else | 47 | #else | |
45 | #define ELTORITO_DPRINTF(__x) | 48 | #define ELTORITO_DPRINTF(__x) | |
46 | #endif | 49 | #endif | |
47 | 50 | |||
48 | static struct boot_catalog_entry *cd9660_init_boot_catalog_entry(void); | 51 | static struct boot_catalog_entry *cd9660_init_boot_catalog_entry(void); | |
49 | static struct boot_catalog_entry *cd9660_boot_setup_validation_entry(char); | 52 | static struct boot_catalog_entry *cd9660_boot_setup_validation_entry(char); | |
50 | static struct boot_catalog_entry *cd9660_boot_setup_default_entry( | 53 | static struct boot_catalog_entry *cd9660_boot_setup_default_entry( | |
51 | struct cd9660_boot_image *); | 54 | struct cd9660_boot_image *); | |
52 | static struct boot_catalog_entry *cd9660_boot_setup_section_head(char); | 55 | static struct boot_catalog_entry *cd9660_boot_setup_section_head(char); | |
@@ -489,31 +492,101 @@ cd9660_setup_boot_volume_descriptor(volu | @@ -489,31 +492,101 @@ cd9660_setup_boot_volume_descriptor(volu | |||
489 | boot_volume_descriptor *bvdData = | 492 | boot_volume_descriptor *bvdData = | |
490 | (boot_volume_descriptor*)bvd->volumeDescriptorData; | 493 | (boot_volume_descriptor*)bvd->volumeDescriptorData; | |
491 | 494 | |||
492 | bvdData->boot_record_indicator[0] = ISO_VOLUME_DESCRIPTOR_BOOT; | 495 | bvdData->boot_record_indicator[0] = ISO_VOLUME_DESCRIPTOR_BOOT; | |
493 | memcpy(bvdData->identifier, ISO_VOLUME_DESCRIPTOR_STANDARD_ID, 5); | 496 | memcpy(bvdData->identifier, ISO_VOLUME_DESCRIPTOR_STANDARD_ID, 5); | |
494 | bvdData->version[0] = 1; | 497 | bvdData->version[0] = 1; | |
495 | memcpy(bvdData->boot_system_identifier, ET_ID, 23); | 498 | memcpy(bvdData->boot_system_identifier, ET_ID, 23); | |
496 | memcpy(bvdData->identifier, ISO_VOLUME_DESCRIPTOR_STANDARD_ID, 5); | 499 | memcpy(bvdData->identifier, ISO_VOLUME_DESCRIPTOR_STANDARD_ID, 5); | |
497 | diskStructure.boot_descriptor = | 500 | diskStructure.boot_descriptor = | |
498 | (boot_volume_descriptor*) bvd->volumeDescriptorData; | 501 | (boot_volume_descriptor*) bvd->volumeDescriptorData; | |
499 | return 1; | 502 | return 1; | |
500 | } | 503 | } | |
501 | 504 | |||
505 | static int | |||
506 | cd9660_write_mbr_partition_entry(FILE *fd, int idx, off_t sector_start, | |||
507 | off_t nsectors, int type) | |||
508 | { | |||
509 | uint8_t val; | |||
510 | uint32_t lba; | |||
511 | ||||
512 | if (fseeko(fd, (off_t)(idx) * 16 + 0x1be, SEEK_SET) == -1) | |||
513 | err(1, "fseeko"); | |||
514 | ||||
515 | val = 0x80; /* Bootable */ | |||
516 | fwrite(&val, sizeof(val), 1, fd); | |||
517 | ||||
518 | val = 0xff; /* CHS begin */ | |||
519 | fwrite(&val, sizeof(val), 1, fd); | |||
520 | fwrite(&val, sizeof(val), 1, fd); | |||
521 | fwrite(&val, sizeof(val), 1, fd); | |||
522 | ||||
523 | val = type; /* Part type */ | |||
524 | fwrite(&val, sizeof(val), 1, fd); | |||
525 | ||||
526 | val = 0xff; /* CHS end */ | |||
527 | fwrite(&val, sizeof(val), 1, fd); | |||
528 | fwrite(&val, sizeof(val), 1, fd); | |||
529 | fwrite(&val, sizeof(val), 1, fd); | |||
530 | ||||
531 | /* LBA extent */ | |||
532 | lba = htole32(sector_start); | |||
533 | fwrite(&lba, sizeof(lba), 1, fd); | |||
534 | lba = htole32(nsectors); | |||
535 | fwrite(&lba, sizeof(lba), 1, fd); | |||
536 | ||||
537 | return 0; | |||
538 | } | |||
539 | ||||
540 | static int | |||
541 | cd9660_write_apm_partition_entry(FILE *fd, int idx, int total_partitions, | |||
542 | off_t sector_start, off_t nsectors, off_t sector_size, | |||
543 | const char *part_name, const char *part_type) | |||
544 | { | |||
545 | uint32_t apm32; | |||
546 | uint16_t apm16; | |||
547 | ||||
548 | if (fseeko(fd, (off_t)(idx + 1) * sector_size, SEEK_SET) == -1) | |||
549 | err(1, "fseeko"); | |||
550 | ||||
551 | /* Signature */ | |||
552 | apm16 = htobe16(0x504d); | |||
553 | fwrite(&apm16, sizeof(apm16), 1, fd); | |||
554 | apm16 = 0; | |||
555 | fwrite(&apm16, sizeof(apm16), 1, fd); | |||
556 | ||||
557 | /* Total number of partitions */ | |||
558 | apm32 = htobe32(total_partitions); | |||
559 | fwrite(&apm32, sizeof(apm32), 1, fd); | |||
560 | /* Bounds */ | |||
561 | apm32 = htobe32(sector_start); | |||
562 | fwrite(&apm32, sizeof(apm32), 1, fd); | |||
563 | apm32 = htobe32(nsectors); | |||
564 | fwrite(&apm32, sizeof(apm32), 1, fd); | |||
565 | ||||
566 | fwrite(part_name, strlen(part_name) + 1, 1, fd); | |||
567 | fseek(fd, 32 - strlen(part_name) - 1, SEEK_CUR); | |||
568 | fwrite(part_type, strlen(part_type) + 1, 1, fd); | |||
569 | ||||
570 | return 0; | |||
571 | } | |||
572 | ||||
502 | int | 573 | int | |
503 | cd9660_write_boot(FILE *fd) | 574 | cd9660_write_boot(FILE *fd) | |
504 | { | 575 | { | |
505 | struct boot_catalog_entry *e; | 576 | struct boot_catalog_entry *e; | |
506 | struct cd9660_boot_image *t; | 577 | struct cd9660_boot_image *t; | |
578 | int apm_partitions = 0; | |||
579 | int mbr_partitions = 0; | |||
507 | 580 | |||
508 | /* write boot catalog */ | 581 | /* write boot catalog */ | |
509 | if (fseeko(fd, (off_t)diskStructure.boot_catalog_sector * | 582 | if (fseeko(fd, (off_t)diskStructure.boot_catalog_sector * | |
510 | diskStructure.sectorSize, SEEK_SET) == -1) | 583 | diskStructure.sectorSize, SEEK_SET) == -1) | |
511 | err(1, "fseeko"); | 584 | err(1, "fseeko"); | |
512 | 585 | |||
513 | if (diskStructure.verbose_level > 0) { | 586 | if (diskStructure.verbose_level > 0) { | |
514 | printf("Writing boot catalog to sector %" PRId64 "\n", | 587 | printf("Writing boot catalog to sector %" PRId64 "\n", | |
515 | diskStructure.boot_catalog_sector); | 588 | diskStructure.boot_catalog_sector); | |
516 | } | 589 | } | |
517 | LIST_FOREACH(e, &diskStructure.boot_entries, ll_struct) { | 590 | LIST_FOREACH(e, &diskStructure.boot_entries, ll_struct) { | |
518 | if (diskStructure.verbose_level > 0) { | 591 | if (diskStructure.verbose_level > 0) { | |
519 | printf("Writing catalog entry of type %d\n", | 592 | printf("Writing catalog entry of type %d\n", | |
@@ -525,17 +598,98 @@ cd9660_write_boot(FILE *fd) | @@ -525,17 +598,98 @@ cd9660_write_boot(FILE *fd) | |||
525 | */ | 598 | */ | |
526 | fwrite(&(e->entry_data.VE), 1, 32, fd); | 599 | fwrite(&(e->entry_data.VE), 1, 32, fd); | |
527 | } | 600 | } | |
528 | if (diskStructure.verbose_level > 0) | 601 | if (diskStructure.verbose_level > 0) | |
529 | printf("Finished writing boot catalog\n"); | 602 | printf("Finished writing boot catalog\n"); | |
530 | 603 | |||
531 | /* copy boot images */ | 604 | /* copy boot images */ | |
532 | TAILQ_FOREACH(t, &diskStructure.boot_images, image_list) { | 605 | TAILQ_FOREACH(t, &diskStructure.boot_images, image_list) { | |
533 | if (diskStructure.verbose_level > 0) { | 606 | if (diskStructure.verbose_level > 0) { | |
534 | printf("Writing boot image from %s to sectors %d\n", | 607 | printf("Writing boot image from %s to sectors %d\n", | |
535 | t->filename, t->sector); | 608 | t->filename, t->sector); | |
536 | } | 609 | } | |
537 | cd9660_copy_file(fd, t->sector, t->filename); | 610 | cd9660_copy_file(fd, t->sector, t->filename); | |
611 | ||||
612 | if (t->system == ET_SYS_MAC) | |||
613 | apm_partitions++; | |||
614 | if (t->system == ET_SYS_PPC) | |||
615 | mbr_partitions++; | |||
616 | } | |||
617 | ||||
618 | /* some systems need partition tables as well */ | |||
619 | if (mbr_partitions > 0 || diskStructure.chrp_boot) { | |||
620 | uint16_t sig; | |||
621 | ||||
622 | fseek(fd, 0x1fe, SEEK_SET); | |||
623 | sig = htole16(0xaa55); | |||
624 | fwrite(&sig, sizeof(sig), 1, fd); | |||
625 | ||||
626 | mbr_partitions = 0; | |||
627 | ||||
628 | /* Write ISO9660 descriptor, enclosing the whole disk */ | |||
629 | if (diskStructure.chrp_boot) | |||
630 | cd9660_write_mbr_partition_entry(fd, mbr_partitions++, | |||
631 | 0, diskStructure.totalSectors * | |||
632 | (diskStructure.sectorSize / 512), 0x96); | |||
633 | ||||
634 | /* Write all partition entries */ | |||
635 | TAILQ_FOREACH(t, &diskStructure.boot_images, image_list) { | |||
636 | if (t->system != ET_SYS_PPC) | |||
637 | continue; | |||
638 | cd9660_write_mbr_partition_entry(fd, mbr_partitions++, | |||
639 | t->sector * (diskStructure.sectorSize / 512), | |||
640 | t->num_sectors * (diskStructure.sectorSize / 512), | |||
641 | 0x41 /* PReP Boot */); | |||
642 | } | |||
643 | } | |||
644 | ||||
645 | if (apm_partitions > 0) { | |||
646 | /* Write DDR and global APM info */ | |||
647 | uint32_t apm32; | |||
648 | uint16_t apm16; | |||
649 | int total_parts; | |||
650 | ||||
651 | fseek(fd, 0, SEEK_SET); | |||
652 | apm16 = htobe16(0x4552); | |||
653 | fwrite(&apm16, sizeof(apm16), 1, fd); | |||
654 | /* Device block size */ | |||
655 | apm16 = htobe16(512); | |||
656 | fwrite(&apm16, sizeof(apm16), 1, fd); | |||
657 | /* Device block count */ | |||
658 | apm32 = htobe32(diskStructure.totalSectors * | |||
659 | (diskStructure.sectorSize / 512)); | |||
660 | fwrite(&apm32, sizeof(apm32), 1, fd); | |||
661 | /* Device type/id */ | |||
662 | apm16 = htobe16(1); | |||
663 | fwrite(&apm16, sizeof(apm16), 1, fd); | |||
664 | fwrite(&apm16, sizeof(apm16), 1, fd); | |||
665 | ||||
666 | /* Count total needed entries */ | |||
667 | total_parts = 2 + apm_partitions; /* Self + ISO9660 */ | |||
668 | ||||
669 | /* Write self-descriptor */ | |||
670 | cd9660_write_apm_partition_entry(fd, 0, total_parts, 1, | |||
671 | total_parts, 512, "Apple", "Apple_partition_map"); | |||
672 | ||||
673 | /* Write ISO9660 descriptor, enclosing the whole disk */ | |||
674 | cd9660_write_apm_partition_entry(fd, 1, total_parts, 0, | |||
675 | diskStructure.totalSectors * | |||
676 | (diskStructure.sectorSize / 512), 512, "ISO9660", | |||
677 | "CD_ROM_Mode_1"); | |||
678 | ||||
679 | /* Write all partition entries */ | |||
680 | apm_partitions = 0; | |||
681 | TAILQ_FOREACH(t, &diskStructure.boot_images, image_list) { | |||
682 | if (t->system != ET_SYS_MAC) | |||
683 | continue; | |||
684 | ||||
685 | cd9660_write_apm_partition_entry(fd, | |||
686 | 2 + apm_partitions++, total_parts, | |||
687 | t->sector * (diskStructure.sectorSize / 512), | |||
688 | t->num_sectors * (diskStructure.sectorSize / 512), | |||
689 | 512, "CD Boot", "Apple_Bootstrap"); | |||
690 | } | |||
538 | } | 691 | } | |
539 | 692 | |||
540 | return 0; | 693 | return 0; | |
541 | } | 694 | } | |
695 |