remove duplicated code, and try to cleanup parsing by using the shared code. cd9660 needs a lot of work.diff -r1.36 -r1.37 src/usr.sbin/makefs/cd9660.c
(christos)
--- src/usr.sbin/makefs/cd9660.c 2013/01/23 20:46:39 1.36
+++ src/usr.sbin/makefs/cd9660.c 2013/01/23 21:32:32 1.37
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: cd9660.c,v 1.36 2013/01/23 20:46:39 christos Exp $ */ | 1 | /* $NetBSD: cd9660.c,v 1.37 2013/01/23 21:32:32 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.36 2013/01/23 20:46:39 christos Exp $"); | 106 | __RCSID("$NetBSD: cd9660.c,v 1.37 2013/01/23 21:32:32 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 | /* | |
@@ -414,27 +414,27 @@ cd9660_parse_opts(const char *option, fs | @@ -414,27 +414,27 @@ cd9660_parse_opts(const char *option, fs | |||
414 | /* End of flag variables */ | 414 | /* End of flag variables */ | |
415 | } else if (CD9660_IS_COMMAND_ARG(var, "boot-load-segment")) { | 415 | } else if (CD9660_IS_COMMAND_ARG(var, "boot-load-segment")) { | |
416 | if (val == NULL) { | 416 | if (val == NULL) { | |
417 | warnx("Option `%s' doesn't contain a value", var); | 417 | warnx("Option `%s' doesn't contain a value", var); | |
418 | rv = 0; | 418 | rv = 0; | |
419 | } else { | 419 | } else { | |
420 | cd9660_eltorito_add_boot_option(var, val); | 420 | cd9660_eltorito_add_boot_option(var, val); | |
421 | } | 421 | } | |
422 | } else { | 422 | } else { | |
423 | if (val == NULL) { | 423 | if (val == NULL) { | |
424 | warnx("Option `%s' doesn't contain a value", var); | 424 | warnx("Option `%s' doesn't contain a value", var); | |
425 | rv = 0; | 425 | rv = 0; | |
426 | } else | 426 | } else | |
427 | rv = set_option(cd9660_options, var, val); | 427 | rv = set_option_var(cd9660_options, var, val); | |
428 | } | 428 | } | |
429 | 429 | |||
430 | if (var) | 430 | if (var) | |
431 | free(var); | 431 | free(var); | |
432 | return (rv); | 432 | return (rv); | |
433 | } | 433 | } | |
434 | 434 | |||
435 | /* | 435 | /* | |
436 | * Main function for cd9660_makefs | 436 | * Main function for cd9660_makefs | |
437 | * Builds the ISO image file | 437 | * Builds the ISO image file | |
438 | * @param const char *image The image filename to create | 438 | * @param const char *image The image filename to create | |
439 | * @param const char *dir The directory that is being read | 439 | * @param const char *dir The directory that is being read | |
440 | * @param struct fsnode *root The root node of the filesystem tree | 440 | * @param struct fsnode *root The root node of the filesystem tree |
--- src/usr.sbin/makefs/makefs.c 2013/01/23 20:46:39 1.36
+++ src/usr.sbin/makefs/makefs.c 2013/01/23 21:32:32 1.37
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: makefs.c,v 1.36 2013/01/23 20:46:39 christos Exp $ */ | 1 | /* $NetBSD: makefs.c,v 1.37 2013/01/23 21:32:32 christos Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2001-2003 Wasabi Systems, Inc. | 4 | * Copyright (c) 2001-2003 Wasabi Systems, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Written by Luke Mewburn for Wasabi Systems, Inc. | 7 | * Written by Luke Mewburn for Wasabi Systems, Inc. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -31,27 +31,27 @@ | @@ -31,27 +31,27 @@ | |||
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
35 | * POSSIBILITY OF SUCH DAMAGE. | 35 | * POSSIBILITY OF SUCH DAMAGE. | |
36 | */ | 36 | */ | |
37 | 37 | |||
38 | #if HAVE_NBTOOL_CONFIG_H | 38 | #if HAVE_NBTOOL_CONFIG_H | |
39 | #include "nbtool_config.h" | 39 | #include "nbtool_config.h" | |
40 | #endif | 40 | #endif | |
41 | 41 | |||
42 | #include <sys/cdefs.h> | 42 | #include <sys/cdefs.h> | |
43 | #if defined(__RCSID) && !defined(__lint) | 43 | #if defined(__RCSID) && !defined(__lint) | |
44 | __RCSID("$NetBSD: makefs.c,v 1.36 2013/01/23 20:46:39 christos Exp $"); | 44 | __RCSID("$NetBSD: makefs.c,v 1.37 2013/01/23 21:32:32 christos Exp $"); | |
45 | #endif /* !__lint */ | 45 | #endif /* !__lint */ | |
46 | 46 | |||
47 | #include <assert.h> | 47 | #include <assert.h> | |
48 | #include <ctype.h> | 48 | #include <ctype.h> | |
49 | #include <errno.h> | 49 | #include <errno.h> | |
50 | #include <limits.h> | 50 | #include <limits.h> | |
51 | #include <stdio.h> | 51 | #include <stdio.h> | |
52 | #include <stdlib.h> | 52 | #include <stdlib.h> | |
53 | #include <string.h> | 53 | #include <string.h> | |
54 | #include <unistd.h> | 54 | #include <unistd.h> | |
55 | #include <stdbool.h> | 55 | #include <stdbool.h> | |
56 | 56 | |||
57 | #include "makefs.h" | 57 | #include "makefs.h" | |
@@ -290,29 +290,53 @@ main(int argc, char *argv[]) | @@ -290,29 +290,53 @@ main(int argc, char *argv[]) | |||
290 | } | 290 | } | |
291 | 291 | |||
292 | /* build the file system */ | 292 | /* build the file system */ | |
293 | TIMER_START(start); | 293 | TIMER_START(start); | |
294 | fstype->make_fs(argv[0], argv[1], root, &fsoptions); | 294 | fstype->make_fs(argv[0], argv[1], root, &fsoptions); | |
295 | TIMER_RESULTS(start, "make_fs"); | 295 | TIMER_RESULTS(start, "make_fs"); | |
296 | 296 | |||
297 | free_fsnodes(root); | 297 | free_fsnodes(root); | |
298 | 298 | |||
299 | exit(0); | 299 | exit(0); | |
300 | /* NOTREACHED */ | 300 | /* NOTREACHED */ | |
301 | } | 301 | } | |
302 | 302 | |||
303 | int | |||
304 | set_option(const option_t *options, const char *option) | |||
305 | { | |||
306 | char *var, *val; | |||
307 | int retval; | |||
308 | ||||
309 | assert(option != NULL); | |||
310 | ||||
311 | if ((var = strdup(option)) == NULL) { | |||
312 | err(EXIT_FAILURE, "Allocating memory for copy of option string"); | |||
313 | } | |||
314 | retval = 0; | |||
315 | if ((val = strchr(var, '=')) == NULL) { | |||
316 | warnx("Option `%s' doesn't contain a value", var); | |||
317 | goto out; | |||
318 | } | |||
319 | *val++ = '\0'; | |||
320 | ||||
321 | retval = set_option_var(options, var, val); | |||
322 | ||||
323 | out: | |||
324 | free(var); | |||
325 | return retval; | |||
326 | } | |||
303 | 327 | |||
304 | int | 328 | int | |
305 | set_option(const option_t *options, const char *var, const char *val) | 329 | set_option_var(const option_t *options, const char *var, const char *val) | |
306 | { | 330 | { | |
307 | char *s; | 331 | char *s; | |
308 | size_t i; | 332 | size_t i; | |
309 | 333 | |||
310 | #define NUM(width) *(uint ## width ## _t *)options[i].value = \ | 334 | #define NUM(width) *(uint ## width ## _t *)options[i].value = \ | |
311 | (uint ## width ## _t)strsuftoll(options[i].desc, val, \ | 335 | (uint ## width ## _t)strsuftoll(options[i].desc, val, \ | |
312 | options[i].minimum, options[i].maximum); break | 336 | options[i].minimum, options[i].maximum); break | |
313 | 337 | |||
314 | for (i = 0; options[i].name != NULL; i++) { | 338 | for (i = 0; options[i].name != NULL; i++) { | |
315 | if (options[i].letter != var[0] || var[1] != '\0') | 339 | if (options[i].letter != var[0] || var[1] != '\0') | |
316 | continue; | 340 | continue; | |
317 | else if (strcmp(options[i].name, var) != 0) | 341 | else if (strcmp(options[i].name, var) != 0) | |
318 | continue; | 342 | continue; |
--- src/usr.sbin/makefs/chfs.c 2013/01/23 20:46:39 1.4
+++ src/usr.sbin/makefs/chfs.c 2013/01/23 21:32:32 1.5
@@ -73,48 +73,30 @@ chfs_cleanup_opts(fsinfo_t *fsopts) | @@ -73,48 +73,30 @@ chfs_cleanup_opts(fsinfo_t *fsopts) | |||
73 | int | 73 | int | |
74 | chfs_parse_opts(const char *option, fsinfo_t *fsopts) | 74 | chfs_parse_opts(const char *option, fsinfo_t *fsopts) | |
75 | { | 75 | { | |
76 | static const option_t chfs_options[] = { | 76 | static const option_t chfs_options[] = { | |
77 | { 'p', "pagesize", &chfs_opts.pagesize, OPT_INT32, | 77 | { 'p', "pagesize", &chfs_opts.pagesize, OPT_INT32, | |
78 | 1, INT_MAX, "page size" }, | 78 | 1, INT_MAX, "page size" }, | |
79 | { 'e', "eraseblock", &chfs_opts.eraseblock, OPT_INT32, | 79 | { 'e', "eraseblock", &chfs_opts.eraseblock, OPT_INT32, | |
80 | 1, INT_MAX, "eraseblock size" }, | 80 | 1, INT_MAX, "eraseblock size" }, | |
81 | { 'm', "mediatype", &chfs_opts.mediatype, OPT_INT32, | 81 | { 'm', "mediatype", &chfs_opts.mediatype, OPT_INT32, | |
82 | 0, 1, "type of the media, 0 (nor) or 1 (nand)" }, | 82 | 0, 1, "type of the media, 0 (nor) or 1 (nand)" }, | |
83 | { .name = NULL } | 83 | { .name = NULL } | |
84 | }; | 84 | }; | |
85 | 85 | |||
86 | char *var, *val; | |||
87 | int retval; | |||
88 | ||||
89 | assert(option != NULL); | 86 | assert(option != NULL); | |
90 | assert(fsopts != NULL); | 87 | assert(fsopts != NULL); | |
91 | 88 | |||
92 | if ((var = strdup(option)) == NULL) { | 89 | return set_option(chfs_options, option); | |
93 | err(EXIT_FAILURE, "Allocating memory for copy of option string"); | |||
94 | } | |||
95 | retval = 0; | |||
96 | ||||
97 | if ((val = strchr(var, '=')) == NULL) { | |||
98 | warnx("Option `%s' doesn't contain a value", var); | |||
99 | goto leave_chfs_parse_opts; | |||
100 | } | |||
101 | *val++ = '\0'; | |||
102 | ||||
103 | retval = set_option(chfs_options, var, val); | |||
104 | ||||
105 | leave_chfs_parse_opts: | |||
106 | free(var); | |||
107 | return retval; | |||
108 | } | 90 | } | |
109 | 91 | |||
110 | void | 92 | void | |
111 | chfs_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts) | 93 | chfs_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts) | |
112 | { | 94 | { | |
113 | struct timeval start; | 95 | struct timeval start; | |
114 | 96 | |||
115 | assert(image != NULL); | 97 | assert(image != NULL); | |
116 | assert(dir != NULL); | 98 | assert(dir != NULL); | |
117 | assert(root != NULL); | 99 | assert(root != NULL); | |
118 | assert(fsopts != NULL); | 100 | assert(fsopts != NULL); | |
119 | 101 | |||
120 | TIMER_START(start); | 102 | TIMER_START(start); |
--- src/usr.sbin/makefs/v7fs.c 2013/01/23 20:46:39 1.4
+++ src/usr.sbin/makefs/v7fs.c 2013/01/23 21:32:32 1.5
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: v7fs.c,v 1.4 2013/01/23 20:46:39 christos Exp $ */ | 1 | /* $NetBSD: v7fs.c,v 1.5 2013/01/23 21:32:32 christos Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by UCHIYAMA Yasushi. | 8 | * by UCHIYAMA Yasushi. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * 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. | |
@@ -25,27 +25,27 @@ | @@ -25,27 +25,27 @@ | |||
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #if HAVE_NBTOOL_CONFIG_H | 32 | #if HAVE_NBTOOL_CONFIG_H | |
33 | #include "nbtool_config.h" | 33 | #include "nbtool_config.h" | |
34 | #endif | 34 | #endif | |
35 | 35 | |||
36 | #include <sys/cdefs.h> | 36 | #include <sys/cdefs.h> | |
37 | #if defined(__RCSID) && !defined(__lint) | 37 | #if defined(__RCSID) && !defined(__lint) | |
38 | __RCSID("$NetBSD: v7fs.c,v 1.4 2013/01/23 20:46:39 christos Exp $"); | 38 | __RCSID("$NetBSD: v7fs.c,v 1.5 2013/01/23 21:32:32 christos Exp $"); | |
39 | #endif /* !__lint */ | 39 | #endif /* !__lint */ | |
40 | 40 | |||
41 | #include <stdio.h> | 41 | #include <stdio.h> | |
42 | #include <stdlib.h> | 42 | #include <stdlib.h> | |
43 | #include <unistd.h> | 43 | #include <unistd.h> | |
44 | #include <string.h> | 44 | #include <string.h> | |
45 | #include <fcntl.h> | 45 | #include <fcntl.h> | |
46 | 46 | |||
47 | #include "makefs.h" | 47 | #include "makefs.h" | |
48 | #include "v7fs.h" | 48 | #include "v7fs.h" | |
49 | #include "v7fs_impl.h" | 49 | #include "v7fs_impl.h" | |
50 | #include "v7fs_makefs.h" | 50 | #include "v7fs_makefs.h" | |
51 | #include "newfs_v7fs.h" | 51 | #include "newfs_v7fs.h" | |
@@ -72,27 +72,27 @@ v7fs_cleanup_opts(fsinfo_t *fsopts) | @@ -72,27 +72,27 @@ v7fs_cleanup_opts(fsinfo_t *fsopts) | |||
72 | } | 72 | } | |
73 | 73 | |||
74 | int | 74 | int | |
75 | v7fs_parse_opts(const char *option, fsinfo_t *fsopts) | 75 | v7fs_parse_opts(const char *option, fsinfo_t *fsopts) | |
76 | { | 76 | { | |
77 | static option_t v7fs_options[] = { | 77 | static option_t v7fs_options[] = { | |
78 | { '\0', "pdp", &v7fs_opts.pdp_endian, OPT_INT32, false, true, | 78 | { '\0', "pdp", &v7fs_opts.pdp_endian, OPT_INT32, false, true, | |
79 | "PDP endian" }, | 79 | "PDP endian" }, | |
80 | { '\0', "progress", &v7fs_opts.progress, OPT_INT32, false, true, | 80 | { '\0', "progress", &v7fs_opts.progress, OPT_INT32, false, true, | |
81 | "Progress bar" }, | 81 | "Progress bar" }, | |
82 | { .name = NULL } | 82 | { .name = NULL } | |
83 | }; | 83 | }; | |
84 | 84 | |||
85 | set_option(v7fs_options, option, "1"); | 85 | set_option_var(v7fs_options, option, "1"); | |
86 | 86 | |||
87 | return 1; | 87 | return 1; | |
88 | } | 88 | } | |
89 | 89 | |||
90 | void | 90 | void | |
91 | v7fs_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts) | 91 | v7fs_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts) | |
92 | { | 92 | { | |
93 | struct v7fs_mount_device v7fs_mount; | 93 | struct v7fs_mount_device v7fs_mount; | |
94 | int fd, endian, error = 1; | 94 | int fd, endian, error = 1; | |
95 | 95 | |||
96 | v7fs_newfs_verbose = debug; | 96 | v7fs_newfs_verbose = debug; | |
97 | #ifndef HAVE_NBTOOL_CONFIG_H | 97 | #ifndef HAVE_NBTOOL_CONFIG_H | |
98 | if ((progress_bar_enable = v7fs_opts.progress)) { | 98 | if ((progress_bar_enable = v7fs_opts.progress)) { |
--- src/usr.sbin/makefs/ffs.c 2013/01/23 20:46:39 1.50
+++ src/usr.sbin/makefs/ffs.c 2013/01/23 21:32:32 1.51
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ffs.c,v 1.50 2013/01/23 20:46:39 christos Exp $ */ | 1 | /* $NetBSD: ffs.c,v 1.51 2013/01/23 21:32:32 christos Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2001 Wasabi Systems, Inc. | 4 | * Copyright (c) 2001 Wasabi Systems, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Written by Luke Mewburn for Wasabi Systems, Inc. | 7 | * Written by Luke Mewburn for Wasabi Systems, Inc. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -61,27 +61,27 @@ | @@ -61,27 +61,27 @@ | |||
61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
63 | * SUCH DAMAGE. | 63 | * SUCH DAMAGE. | |
64 | * | 64 | * | |
65 | * @(#)ffs_alloc.c 8.19 (Berkeley) 7/13/95 | 65 | * @(#)ffs_alloc.c 8.19 (Berkeley) 7/13/95 | |
66 | */ | 66 | */ | |
67 | 67 | |||
68 | #if HAVE_NBTOOL_CONFIG_H | 68 | #if HAVE_NBTOOL_CONFIG_H | |
69 | #include "nbtool_config.h" | 69 | #include "nbtool_config.h" | |
70 | #endif | 70 | #endif | |
71 | 71 | |||
72 | #include <sys/cdefs.h> | 72 | #include <sys/cdefs.h> | |
73 | #if defined(__RCSID) && !defined(__lint) | 73 | #if defined(__RCSID) && !defined(__lint) | |
74 | __RCSID("$NetBSD: ffs.c,v 1.50 2013/01/23 20:46:39 christos Exp $"); | 74 | __RCSID("$NetBSD: ffs.c,v 1.51 2013/01/23 21:32:32 christos Exp $"); | |
75 | #endif /* !__lint */ | 75 | #endif /* !__lint */ | |
76 | 76 | |||
77 | #include <sys/param.h> | 77 | #include <sys/param.h> | |
78 | 78 | |||
79 | #if !HAVE_NBTOOL_CONFIG_H | 79 | #if !HAVE_NBTOOL_CONFIG_H | |
80 | #include <sys/mount.h> | 80 | #include <sys/mount.h> | |
81 | #endif | 81 | #endif | |
82 | 82 | |||
83 | #include <assert.h> | 83 | #include <assert.h> | |
84 | #include <errno.h> | 84 | #include <errno.h> | |
85 | #include <fcntl.h> | 85 | #include <fcntl.h> | |
86 | #include <stdarg.h> | 86 | #include <stdarg.h> | |
87 | #include <stdio.h> | 87 | #include <stdio.h> | |
@@ -176,91 +176,83 @@ ffs_prep_opts(fsinfo_t *fsopts) | @@ -176,91 +176,83 @@ ffs_prep_opts(fsinfo_t *fsopts) | |||
176 | } | 176 | } | |
177 | 177 | |||
178 | void | 178 | void | |
179 | ffs_cleanup_opts(fsinfo_t *fsopts) | 179 | ffs_cleanup_opts(fsinfo_t *fsopts) | |
180 | { | 180 | { | |
181 | if (fsopts->fs_specific) | 181 | if (fsopts->fs_specific) | |
182 | free(fsopts->fs_specific); | 182 | free(fsopts->fs_specific); | |
183 | } | 183 | } | |
184 | 184 | |||
185 | int | 185 | int | |
186 | ffs_parse_opts(const char *option, fsinfo_t *fsopts) | 186 | ffs_parse_opts(const char *option, fsinfo_t *fsopts) | |
187 | { | 187 | { | |
188 | ffs_opt_t *ffs_opts = fsopts->fs_specific; | 188 | ffs_opt_t *ffs_opts = fsopts->fs_specific; | |
189 | char optimization[24]; | |||
189 | 190 | |||
190 | option_t ffs_options[] = { | 191 | option_t ffs_options[] = { | |
191 | { '\0', "bsize", &ffs_opts->bsize, OPT_INT32, | 192 | { '\0', "bsize", &ffs_opts->bsize, OPT_INT32, | |
192 | 1, INT_MAX, "block size" }, | 193 | 1, INT_MAX, "block size" }, | |
193 | { '\0', "fsize", &ffs_opts->fsize, OPT_INT32, | 194 | { '\0', "fsize", &ffs_opts->fsize, OPT_INT32, | |
194 | 1, INT_MAX, "fragment size" }, | 195 | 1, INT_MAX, "fragment size" }, | |
195 | { '\0', "density", &ffs_opts->density, OPT_INT32, | 196 | { '\0', "density", &ffs_opts->density, OPT_INT32, | |
196 | 1, INT_MAX, "bytes per inode" }, | 197 | 1, INT_MAX, "bytes per inode" }, | |
197 | { '\0', "minfree", &ffs_opts->minfree, OPT_INT32, | 198 | { '\0', "minfree", &ffs_opts->minfree, OPT_INT32, | |
198 | 0, 99, "minfree" }, | 199 | 0, 99, "minfree" }, | |
199 | { '\0', "maxbpf", &ffs_opts->maxbpg, OPT_INT32, | 200 | { '\0', "maxbpf", &ffs_opts->maxbpg, OPT_INT32, | |
200 | 1, INT_MAX, "max blocks per file in a cg" }, | 201 | 1, INT_MAX, "max blocks per file in a cg" }, | |
201 | { '\0', "avgfilesize", &ffs_opts->avgfilesize, OPT_INT32, | 202 | { '\0', "avgfilesize", &ffs_opts->avgfilesize, OPT_INT32, | |
202 | 1, INT_MAX, "expected average file size" }, | 203 | 1, INT_MAX, "expected average file size" }, | |
203 | { '\0', "avgfpdir", &ffs_opts->avgfpdir, OPT_INT32, | 204 | { '\0', "avgfpdir", &ffs_opts->avgfpdir, OPT_INT32, | |
204 | 1, INT_MAX, "expected # of files per directory" }, | 205 | 1, INT_MAX, "expected # of files per directory" }, | |
205 | { '\0', "extent", &ffs_opts->maxbsize, OPT_INT32, | 206 | { '\0', "extent", &ffs_opts->maxbsize, OPT_INT32, | |
206 | 1, INT_MAX, "maximum # extent size" }, | 207 | 1, INT_MAX, "maximum # extent size" }, | |
207 | { '\0', "maxbpcg", &ffs_opts->maxblkspercg, OPT_INT32, | 208 | { '\0', "maxbpcg", &ffs_opts->maxblkspercg, OPT_INT32, | |
208 | 1, INT_MAX, "max # of blocks per group" }, | 209 | 1, INT_MAX, "max # of blocks per group" }, | |
209 | { '\0', "version", &ffs_opts->version, OPT_INT32, | 210 | { '\0', "version", &ffs_opts->version, OPT_INT32, | |
210 | 1, 2, "UFS version" }, | 211 | 1, 2, "UFS version" }, | |
212 | { '\0', "optimization", optimization, OPT_STRARRAY, | |||
213 | 1, sizeof(optimization), "Optimization (time|space)" }, | |||
214 | { '\0', "label", ffs_opts->label, OPT_STRARRAY, | |||
215 | 1, sizeof(ffs_opts->label), "UFS label" }, | |||
211 | { .name = NULL } | 216 | { .name = NULL } | |
212 | }; | 217 | }; | |
213 | 218 | |||
214 | char *var, *val; | 219 | int rv, i; | |
215 | int rv; | |||
216 | 220 | |||
217 | assert(option != NULL); | 221 | assert(option != NULL); | |
218 | assert(fsopts != NULL); | 222 | assert(fsopts != NULL); | |
219 | assert(ffs_opts != NULL); | 223 | assert(ffs_opts != NULL); | |
220 | 224 | |||
221 | if (debug & DEBUG_FS_PARSE_OPTS) | 225 | if (debug & DEBUG_FS_PARSE_OPTS) | |
222 | printf("ffs_parse_opts: got `%s'\n", option); | 226 | printf("ffs_parse_opts: got `%s'\n", option); | |
223 | 227 | |||
224 | if ((var = strdup(option)) == NULL) | 228 | rv = set_option(ffs_options, option); | |
225 | err(1, "Allocating memory for copy of option string"); | 229 | if (rv == 0) | |
226 | rv = 0; | 230 | return 0; | |
227 | 231 | |||
228 | if ((val = strchr(var, '=')) == NULL) { | 232 | for (i = 0; ffs_options[i].name && (1 << i) != rv; i++) | |
229 | warnx("Option `%s' doesn't contain a value", var); | 233 | continue; | |
230 | goto leave_ffs_parse_opts; | |||
231 | } | |||
232 | *val++ = '\0'; | |||
233 | 234 | |||
234 | if (strcmp(var, "optimization") == 0) { | 235 | if (strcmp(ffs_options[i].name, "optimization") == 0) { | |
235 | if (strcmp(val, "time") == 0) { | 236 | if (strcmp(optimization, "time") == 0) { | |
236 | ffs_opts->optimization = FS_OPTTIME; | 237 | ffs_opts->optimization = FS_OPTTIME; | |
237 | } else if (strcmp(val, "space") == 0) { | 238 | } else if (strcmp(optimization, "space") == 0) { | |
238 | ffs_opts->optimization = FS_OPTSPACE; | 239 | ffs_opts->optimization = FS_OPTSPACE; | |
239 | } else { | 240 | } else { | |
240 | warnx("Invalid optimization `%s'", val); | 241 | warnx("Invalid optimization `%s'", optimization); | |
241 | goto leave_ffs_parse_opts; | 242 | return 0; | |
242 | } | 243 | } | |
243 | rv = 1; | 244 | } | |
244 | } else if (strcmp(var, "label") == 0) { | 245 | return rv; | |
245 | strlcpy(ffs_opts->label, val, sizeof(ffs_opts->label)); | |||
246 | rv = 1; | |||
247 | } else | |||
248 | rv = set_option(ffs_options, var, val); | |||
249 | ||||
250 | leave_ffs_parse_opts: | |||
251 | if (var) | |||
252 | free(var); | |||
253 | return (rv); | |||
254 | } | 246 | } | |
255 | 247 | |||
256 | 248 | |||
257 | void | 249 | void | |
258 | ffs_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts) | 250 | ffs_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts) | |
259 | { | 251 | { | |
260 | struct fs *superblock; | 252 | struct fs *superblock; | |
261 | struct timeval start; | 253 | struct timeval start; | |
262 | 254 | |||
263 | assert(image != NULL); | 255 | assert(image != NULL); | |
264 | assert(dir != NULL); | 256 | assert(dir != NULL); | |
265 | assert(root != NULL); | 257 | assert(root != NULL); | |
266 | assert(fsopts != NULL); | 258 | assert(fsopts != NULL); |
--- src/usr.sbin/makefs/makefs.h 2013/01/23 20:46:39 1.28
+++ src/usr.sbin/makefs/makefs.h 2013/01/23 21:32:32 1.29
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: makefs.h,v 1.28 2013/01/23 20:46:39 christos Exp $ */ | 1 | /* $NetBSD: makefs.h,v 1.29 2013/01/23 21:32:32 christos Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2001 Wasabi Systems, Inc. | 4 | * Copyright (c) 2001 Wasabi Systems, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Written by Luke Mewburn for Wasabi Systems, Inc. | 7 | * Written by Luke Mewburn for Wasabi Systems, Inc. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -161,27 +161,28 @@ typedef struct { | @@ -161,27 +161,28 @@ typedef struct { | |||
161 | char letter; /* option letter NUL for none */ | 161 | char letter; /* option letter NUL for none */ | |
162 | const char *name; /* option name */ | 162 | const char *name; /* option name */ | |
163 | void *value; /* where to stuff the value */ | 163 | void *value; /* where to stuff the value */ | |
164 | opttype_t type; /* type of entry */ | 164 | opttype_t type; /* type of entry */ | |
165 | long long minimum; /* minimum for value */ | 165 | long long minimum; /* minimum for value */ | |
166 | long long maximum; /* maximum for value */ | 166 | long long maximum; /* maximum for value */ | |
167 | const char *desc; /* option description */ | 167 | const char *desc; /* option description */ | |
168 | } option_t; | 168 | } option_t; | |
169 | 169 | |||
170 | 170 | |||
171 | void apply_specfile(const char *, const char *, fsnode *, int); | 171 | void apply_specfile(const char *, const char *, fsnode *, int); | |
172 | void dump_fsnodes(fsnode *); | 172 | void dump_fsnodes(fsnode *); | |
173 | const char * inode_type(mode_t); | 173 | const char * inode_type(mode_t); | |
174 | int set_option(const option_t *, const char *, const char *); | 174 | int set_option(const option_t *, const char *); | |
175 | int set_option_var(const option_t *, const char *, const char *); | |||
175 | fsnode * walk_dir(const char *, const char *, fsnode *, fsnode *); | 176 | fsnode * walk_dir(const char *, const char *, fsnode *, fsnode *); | |
176 | void free_fsnodes(fsnode *); | 177 | void free_fsnodes(fsnode *); | |
177 | 178 | |||
178 | #define DECLARE_FUN(fs) \ | 179 | #define DECLARE_FUN(fs) \ | |
179 | void fs ## _prep_opts(fsinfo_t *); \ | 180 | void fs ## _prep_opts(fsinfo_t *); \ | |
180 | int fs ## _parse_opts(const char *, fsinfo_t *); \ | 181 | int fs ## _parse_opts(const char *, fsinfo_t *); \ | |
181 | void fs ## _cleanup_opts(fsinfo_t *); \ | 182 | void fs ## _cleanup_opts(fsinfo_t *); \ | |
182 | void fs ## _makefs(const char *, const char *, fsnode *, fsinfo_t *) | 183 | void fs ## _makefs(const char *, const char *, fsnode *, fsinfo_t *) | |
183 | 184 | |||
184 | DECLARE_FUN(ffs); | 185 | DECLARE_FUN(ffs); | |
185 | DECLARE_FUN(cd9660); | 186 | DECLARE_FUN(cd9660); | |
186 | DECLARE_FUN(chfs); | 187 | DECLARE_FUN(chfs); | |
187 | DECLARE_FUN(v7fs); | 188 | DECLARE_FUN(v7fs); |
--- src/usr.sbin/makefs/msdos.c 2013/01/23 20:46:39 1.1
+++ src/usr.sbin/makefs/msdos.c 2013/01/23 21:32:32 1.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: msdos.c,v 1.1 2013/01/23 20:46:39 christos Exp $ */ | 1 | /* $NetBSD: msdos.c,v 1.2 2013/01/23 21:32:32 christos Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Christos Zoulas. | 8 | * by Christos Zoulas. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * 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. | |
@@ -27,27 +27,27 @@ | @@ -27,27 +27,27 @@ | |||
27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
32 | * POSSIBILITY OF SUCH DAMAGE. | 32 | * POSSIBILITY OF SUCH DAMAGE. | |
33 | */ | 33 | */ | |
34 | #if HAVE_NBTOOL_CONFIG_H | 34 | #if HAVE_NBTOOL_CONFIG_H | |
35 | #include "nbtool_config.h" | 35 | #include "nbtool_config.h" | |
36 | #endif | 36 | #endif | |
37 | 37 | |||
38 | #include <sys/cdefs.h> | 38 | #include <sys/cdefs.h> | |
39 | #if defined(__RCSID) && !defined(__lint) | 39 | #if defined(__RCSID) && !defined(__lint) | |
40 | __RCSID("$NetBSD: msdos.c,v 1.1 2013/01/23 20:46:39 christos Exp $"); | 40 | __RCSID("$NetBSD: msdos.c,v 1.2 2013/01/23 21:32:32 christos Exp $"); | |
41 | #endif /* !__lint */ | 41 | #endif /* !__lint */ | |
42 | 42 | |||
43 | #include <sys/param.h> | 43 | #include <sys/param.h> | |
44 | 44 | |||
45 | #if !HAVE_NBTOOL_CONFIG_H | 45 | #if !HAVE_NBTOOL_CONFIG_H | |
46 | #include <sys/mount.h> | 46 | #include <sys/mount.h> | |
47 | #endif | 47 | #endif | |
48 | 48 | |||
49 | #include <assert.h> | 49 | #include <assert.h> | |
50 | #include <errno.h> | 50 | #include <errno.h> | |
51 | #include <fcntl.h> | 51 | #include <fcntl.h> | |
52 | #include <stdarg.h> | 52 | #include <stdarg.h> | |
53 | #include <stdio.h> | 53 | #include <stdio.h> | |
@@ -99,29 +99,27 @@ msdos_parse_opts(const char *option, fsi | @@ -99,29 +99,27 @@ msdos_parse_opts(const char *option, fsi | |||
99 | }, | 99 | }, | |
100 | ALLOPTS | 100 | ALLOPTS | |
101 | #undef AOPT | 101 | #undef AOPT | |
102 | { .name = NULL } | 102 | { .name = NULL } | |
103 | }; | 103 | }; | |
104 | 104 | |||
105 | assert(option != NULL); | 105 | assert(option != NULL); | |
106 | assert(fsopts != NULL); | 106 | assert(fsopts != NULL); | |
107 | assert(msdos_opt != NULL); | 107 | assert(msdos_opt != NULL); | |
108 | 108 | |||
109 | if (debug & DEBUG_FS_PARSE_OPTS) | 109 | if (debug & DEBUG_FS_PARSE_OPTS) | |
110 | printf("msdos_parse_opts: got `%s'\n", option); | 110 | printf("msdos_parse_opts: got `%s'\n", option); | |
111 | 111 | |||
112 | set_option(msdos_options, option, "1"); | 112 | return set_option(msdos_options, option); | |
113 | ||||
114 | return 1; | |||
115 | } | 113 | } | |
116 | 114 | |||
117 | 115 | |||
118 | void | 116 | void | |
119 | msdos_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts) | 117 | msdos_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts) | |
120 | { | 118 | { | |
121 | #ifdef notyet | 119 | #ifdef notyet | |
122 | struct fs *superblock; | 120 | struct fs *superblock; | |
123 | struct timeval start; | 121 | struct timeval start; | |
124 | 122 | |||
125 | assert(image != NULL); | 123 | assert(image != NULL); | |
126 | assert(dir != NULL); | 124 | assert(dir != NULL); | |
127 | assert(root != NULL); | 125 | assert(root != NULL); |