Module Name: src Committed By: christos Date: Thu Jan 24 01:10:48 UTC 2013
Modified Files: src/usr.sbin/makefs: cd9660.c chfs.c ffs.c makefs.c msdos.c v7fs.c Log Message: - Fix single letter option parsing. - Instead of returning 1 << index and 0 on error, return just index and -1 on error for the set_option*() routines. To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 src/usr.sbin/makefs/cd9660.c cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/makefs/chfs.c \ src/usr.sbin/makefs/v7fs.c cvs rdiff -u -r1.52 -r1.53 src/usr.sbin/makefs/ffs.c cvs rdiff -u -r1.38 -r1.39 src/usr.sbin/makefs/makefs.c cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/makefs/msdos.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/makefs/cd9660.c diff -u src/usr.sbin/makefs/cd9660.c:1.37 src/usr.sbin/makefs/cd9660.c:1.38 --- src/usr.sbin/makefs/cd9660.c:1.37 Wed Jan 23 16:32:32 2013 +++ src/usr.sbin/makefs/cd9660.c Wed Jan 23 20:10:47 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: cd9660.c,v 1.37 2013/01/23 21:32:32 christos Exp $ */ +/* $NetBSD: cd9660.c,v 1.38 2013/01/24 01:10:47 christos Exp $ */ /* * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan @@ -103,7 +103,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(__lint) -__RCSID("$NetBSD: cd9660.c,v 1.37 2013/01/23 21:32:32 christos Exp $"); +__RCSID("$NetBSD: cd9660.c,v 1.38 2013/01/24 01:10:47 christos Exp $"); #endif /* !__lint */ #include <string.h> @@ -424,7 +424,7 @@ cd9660_parse_opts(const char *option, fs warnx("Option `%s' doesn't contain a value", var); rv = 0; } else - rv = set_option_var(cd9660_options, var, val); + rv = set_option_var(cd9660_options, var, val) != -1; } if (var) Index: src/usr.sbin/makefs/chfs.c diff -u src/usr.sbin/makefs/chfs.c:1.5 src/usr.sbin/makefs/chfs.c:1.6 --- src/usr.sbin/makefs/chfs.c:1.5 Wed Jan 23 16:32:32 2013 +++ src/usr.sbin/makefs/chfs.c Wed Jan 23 20:10:47 2013 @@ -86,7 +86,7 @@ chfs_parse_opts(const char *option, fsin assert(option != NULL); assert(fsopts != NULL); - return set_option(chfs_options, option); + return set_option(chfs_options, option) != -1; } void Index: src/usr.sbin/makefs/v7fs.c diff -u src/usr.sbin/makefs/v7fs.c:1.5 src/usr.sbin/makefs/v7fs.c:1.6 --- src/usr.sbin/makefs/v7fs.c:1.5 Wed Jan 23 16:32:32 2013 +++ src/usr.sbin/makefs/v7fs.c Wed Jan 23 20:10:47 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: v7fs.c,v 1.5 2013/01/23 21:32:32 christos Exp $ */ +/* $NetBSD: v7fs.c,v 1.6 2013/01/24 01:10:47 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(__lint) -__RCSID("$NetBSD: v7fs.c,v 1.5 2013/01/23 21:32:32 christos Exp $"); +__RCSID("$NetBSD: v7fs.c,v 1.6 2013/01/24 01:10:47 christos Exp $"); #endif /* !__lint */ #include <stdio.h> @@ -82,9 +82,7 @@ v7fs_parse_opts(const char *option, fsin { .name = NULL } }; - set_option_var(v7fs_options, option, "1"); - - return 1; + return set_option_var(v7fs_options, option, "1") != -1; } void Index: src/usr.sbin/makefs/ffs.c diff -u src/usr.sbin/makefs/ffs.c:1.52 src/usr.sbin/makefs/ffs.c:1.53 --- src/usr.sbin/makefs/ffs.c:1.52 Wed Jan 23 16:42:22 2013 +++ src/usr.sbin/makefs/ffs.c Wed Jan 23 20:10:47 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ffs.c,v 1.52 2013/01/23 21:42:22 christos Exp $ */ +/* $NetBSD: ffs.c,v 1.53 2013/01/24 01:10:47 christos Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -71,7 +71,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(__lint) -__RCSID("$NetBSD: ffs.c,v 1.52 2013/01/23 21:42:22 christos Exp $"); +__RCSID("$NetBSD: ffs.c,v 1.53 2013/01/24 01:10:47 christos Exp $"); #endif /* !__lint */ #include <sys/param.h> @@ -216,7 +216,7 @@ ffs_parse_opts(const char *option, fsinf { .name = NULL } }; - int rv, i; + int rv; assert(option != NULL); assert(fsopts != NULL); @@ -226,16 +226,13 @@ ffs_parse_opts(const char *option, fsinf printf("ffs_parse_opts: got `%s'\n", option); rv = set_option(ffs_options, option); - if (rv == 0) + if (rv == -1) return 0; - for (i = 0; ffs_options[i].name && (1 << i) != rv; i++) - continue; - - if (ffs_options[i].name == NULL) + if (ffs_options[rv].name == NULL) abort(); - if (strcmp(ffs_options[i].name, "optimization") == 0) { + if (strcmp(ffs_options[rv].name, "optimization") == 0) { if (strcmp(optimization, "time") == 0) { ffs_opts->optimization = FS_OPTTIME; } else if (strcmp(optimization, "space") == 0) { @@ -245,7 +242,7 @@ ffs_parse_opts(const char *option, fsinf return 0; } } - return rv; + return 1; } Index: src/usr.sbin/makefs/makefs.c diff -u src/usr.sbin/makefs/makefs.c:1.38 src/usr.sbin/makefs/makefs.c:1.39 --- src/usr.sbin/makefs/makefs.c:1.38 Wed Jan 23 16:42:22 2013 +++ src/usr.sbin/makefs/makefs.c Wed Jan 23 20:10:47 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: makefs.c,v 1.38 2013/01/23 21:42:22 christos Exp $ */ +/* $NetBSD: makefs.c,v 1.39 2013/01/24 01:10:47 christos Exp $ */ /* * Copyright (c) 2001-2003 Wasabi Systems, Inc. @@ -41,7 +41,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(__lint) -__RCSID("$NetBSD: makefs.c,v 1.38 2013/01/23 21:42:22 christos Exp $"); +__RCSID("$NetBSD: makefs.c,v 1.39 2013/01/24 01:10:47 christos Exp $"); #endif /* !__lint */ #include <assert.h> @@ -311,7 +311,7 @@ set_option(const option_t *options, cons if ((var = strdup(option)) == NULL) { err(EXIT_FAILURE, "Allocating memory for copy of option string"); } - retval = 0; + retval = -1; if ((val = strchr(var, '=')) == NULL) { warnx("Option `%s' doesn't contain a value", var); goto out; @@ -336,7 +336,7 @@ set_option_var(const option_t *options, options[i].minimum, options[i].maximum); break for (i = 0; options[i].name != NULL; i++) { - if (options[i].letter != var[0] || var[1] != '\0') + if (options[i].letter != var[0] && var[1] == '\0') continue; else if (strcmp(options[i].name, var) != 0) continue; @@ -367,10 +367,10 @@ set_option_var(const option_t *options, val); return 0; } - return 1 << i; + return i; } warnx("Unknown option `%s'", var); - return (0); + return -1; } Index: src/usr.sbin/makefs/msdos.c diff -u src/usr.sbin/makefs/msdos.c:1.4 src/usr.sbin/makefs/msdos.c:1.5 --- src/usr.sbin/makefs/msdos.c:1.4 Wed Jan 23 17:47:18 2013 +++ src/usr.sbin/makefs/msdos.c Wed Jan 23 20:10:47 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: msdos.c,v 1.4 2013/01/23 22:47:18 christos Exp $ */ +/* $NetBSD: msdos.c,v 1.5 2013/01/24 01:10:47 christos Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(__lint) -__RCSID("$NetBSD: msdos.c,v 1.4 2013/01/23 22:47:18 christos Exp $"); +__RCSID("$NetBSD: msdos.c,v 1.5 2013/01/24 01:10:47 christos Exp $"); #endif /* !__lint */ #include <sys/param.h> @@ -101,7 +101,7 @@ ALLOPTS #undef AOPT { .name = NULL } }; - int i, rv; + int rv; assert(option != NULL); assert(fsopts != NULL); @@ -111,21 +111,16 @@ ALLOPTS printf("msdos_parse_opts: got `%s'\n", option); rv = set_option(msdos_options, option); - if (rv == 0) + if (rv == -1) return rv; - for (i = 0; msdos_options[i].name != NULL && (1 << i) != rv; i++) - break; - if (msdos_options[i].name == NULL) - abort(); - - if (strcmp(msdos_options[i].name, "volume_id") == 0) + if (strcmp(msdos_options[rv].name, "volume_id") == 0) msdos_opt->volume_id_set = 1; - else if (strcmp(msdos_options[i].name, "media_descriptor") == 0) + else if (strcmp(msdos_options[rv].name, "media_descriptor") == 0) msdos_opt->media_descriptor_set = 1; - else if (strcmp(msdos_options[i].name, "hidden_sectors") == 0) + else if (strcmp(msdos_options[rv].name, "hidden_sectors") == 0) msdos_opt->hidden_sectors_set = 1; - return rv; + return 1; }