Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/makefs - add support for parsing different types; n...
details: https://anonhg.NetBSD.org/src/rev/712fa7a6a00c
branches: trunk
changeset: 784274:712fa7a6a00c
user: christos <christos%NetBSD.org@localhost>
date: Wed Jan 23 20:46:39 2013 +0000
description:
- add support for parsing different types; not just int.
- add beginning of msdos support.
diffstat:
usr.sbin/makefs/Makefile | 5 +-
usr.sbin/makefs/cd9660.c | 29 ++----
usr.sbin/makefs/chfs.c | 10 +-
usr.sbin/makefs/ffs.c | 46 +++++-----
usr.sbin/makefs/makefs.c | 63 ++++++++++---
usr.sbin/makefs/makefs.h | 48 +++++----
usr.sbin/makefs/msdos.c | 166 +++++++++++++++++++++++++++++++++++++
usr.sbin/makefs/msdos/Makefile.inc | 9 ++
usr.sbin/makefs/v7fs.c | 9 +-
9 files changed, 297 insertions(+), 88 deletions(-)
diffs (truncated from 555 to 300 lines):
diff -r 9627b1809417 -r 712fa7a6a00c usr.sbin/makefs/Makefile
--- a/usr.sbin/makefs/Makefile Wed Jan 23 20:39:46 2013 +0000
+++ b/usr.sbin/makefs/Makefile Wed Jan 23 20:46:39 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.31 2012/04/19 17:28:25 christos Exp $
+# $NetBSD: Makefile,v 1.32 2013/01/23 20:46:39 christos Exp $
#
WARNS?= 5
@@ -6,7 +6,7 @@
.include <bsd.own.mk>
PROG= makefs
-SRCS= cd9660.c chfs.c ffs.c v7fs.c \
+SRCS= cd9660.c chfs.c ffs.c v7fs.c msdos.c \
getid.c \
makefs.c misc.c \
pack_dev.c \
@@ -24,6 +24,7 @@
.include "${.CURDIR}/chfs/Makefile.inc"
.include "${.CURDIR}/ffs/Makefile.inc"
.include "${.CURDIR}/v7fs/Makefile.inc"
+.include "${.CURDIR}/msdos/Makefile.inc"
.if !defined(HOSTPROG)
DPADD+= ${LIBUTIL}
diff -r 9627b1809417 -r 712fa7a6a00c usr.sbin/makefs/cd9660.c
--- a/usr.sbin/makefs/cd9660.c Wed Jan 23 20:39:46 2013 +0000
+++ b/usr.sbin/makefs/cd9660.c Wed Jan 23 20:46:39 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cd9660.c,v 1.35 2012/01/28 02:35:46 christos Exp $ */
+/* $NetBSD: cd9660.c,v 1.36 2013/01/23 20:46:39 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.35 2012/01/28 02:35:46 christos Exp $");
+__RCSID("$NetBSD: cd9660.c,v 1.36 2013/01/23 20:46:39 christos Exp $");
#endif /* !__lint */
#include <string.h>
@@ -304,29 +304,20 @@
int rv;
/* Set up allowed options - integer options ONLY */
option_t cd9660_options[] = {
- { "l", &diskStructure.isoLevel, 1, 3, "ISO Level" },
- { "isolevel", &diskStructure.isoLevel, 1, 3, "ISO Level" },
- { "verbose", &diskStructure.verbose_level, 0, 2,
- "Turns on verbose output" },
- { "v", &diskStructure.verbose_level, 0 , 2,
- "Turns on verbose output"},
+ { 'l', "isolevel", &diskStructure.isoLevel,
+ OPT_INT32, 1, 3, "ISO Level" },
+ { 'v', "verbose", &diskStructure.verbose_level,
+ OPT_INT32, 0, 2, "Turns on verbose output" },
+ { 'L', "Label", diskStructure.primaryDescriptor.volume_id,
+ OPT_STRARRAY, 1,
+ sizeof(diskStructure.primaryDescriptor.volume_id),
+ "Disk Label" },
{ .name = NULL }
};
if (cd9660_defaults_set == 0)
cd9660_set_defaults();
- /*
- * Todo : finish implementing this, and make a function that
- * parses them
- */
- /*
- string_option_t cd9660_string_options[] = {
- { "L", "Label", &diskStructure.primaryDescriptor.volume_id, 1, 32, "Disk Label", ISO_STRING_FILTER_DCHARS },
- { NULL }
- }
- */
-
assert(option != NULL);
if (debug & DEBUG_FS_PARSE_OPTS)
diff -r 9627b1809417 -r 712fa7a6a00c usr.sbin/makefs/chfs.c
--- a/usr.sbin/makefs/chfs.c Wed Jan 23 20:39:46 2013 +0000
+++ b/usr.sbin/makefs/chfs.c Wed Jan 23 20:46:39 2013 +0000
@@ -74,10 +74,12 @@
chfs_parse_opts(const char *option, fsinfo_t *fsopts)
{
static const option_t chfs_options[] = {
- { "pagesize", &chfs_opts.pagesize, 1, INT_MAX, "page size" },
- { "eraseblock", &chfs_opts.eraseblock, 1, INT_MAX, "eraseblock size" },
- { "mediatype", &chfs_opts.mediatype, 0, 1,
- "type of the media, 0 (nor) or 1 (nand)" },
+ { 'p', "pagesize", &chfs_opts.pagesize, OPT_INT32,
+ 1, INT_MAX, "page size" },
+ { 'e', "eraseblock", &chfs_opts.eraseblock, OPT_INT32,
+ 1, INT_MAX, "eraseblock size" },
+ { 'm', "mediatype", &chfs_opts.mediatype, OPT_INT32,
+ 0, 1, "type of the media, 0 (nor) or 1 (nand)" },
{ .name = NULL }
};
diff -r 9627b1809417 -r 712fa7a6a00c usr.sbin/makefs/ffs.c
--- a/usr.sbin/makefs/ffs.c Wed Jan 23 20:39:46 2013 +0000
+++ b/usr.sbin/makefs/ffs.c Wed Jan 23 20:46:39 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ffs.c,v 1.49 2013/01/22 09:39:19 dholland Exp $ */
+/* $NetBSD: ffs.c,v 1.50 2013/01/23 20:46:39 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.49 2013/01/22 09:39:19 dholland Exp $");
+__RCSID("$NetBSD: ffs.c,v 1.50 2013/01/23 20:46:39 christos Exp $");
#endif /* !__lint */
#include <sys/param.h>
@@ -188,27 +188,27 @@
ffs_opt_t *ffs_opts = fsopts->fs_specific;
option_t ffs_options[] = {
- { "bsize", &ffs_opts->bsize, 1, INT_MAX,
- "block size" },
- { "fsize", &ffs_opts->fsize, 1, INT_MAX,
- "fragment size" },
- { "density", &ffs_opts->density, 1, INT_MAX,
- "bytes per inode" },
- { "minfree", &ffs_opts->minfree, 0, 99,
- "minfree" },
- { "maxbpf", &ffs_opts->maxbpg, 1, INT_MAX,
- "max blocks per file in a cg" },
- { "avgfilesize", &ffs_opts->avgfilesize,1, INT_MAX,
- "expected average file size" },
- { "avgfpdir", &ffs_opts->avgfpdir, 1, INT_MAX,
- "expected # of files per directory" },
- { "extent", &ffs_opts->maxbsize, 1, INT_MAX,
- "maximum # extent size" },
- { "maxbpcg", &ffs_opts->maxblkspercg,1, INT_MAX,
- "max # of blocks per group" },
- { "version", &ffs_opts->version, 1, 2,
- "UFS version" },
- { .name = NULL }
+ { '\0', "bsize", &ffs_opts->bsize, OPT_INT32,
+ 1, INT_MAX, "block size" },
+ { '\0', "fsize", &ffs_opts->fsize, OPT_INT32,
+ 1, INT_MAX, "fragment size" },
+ { '\0', "density", &ffs_opts->density, OPT_INT32,
+ 1, INT_MAX, "bytes per inode" },
+ { '\0', "minfree", &ffs_opts->minfree, OPT_INT32,
+ 0, 99, "minfree" },
+ { '\0', "maxbpf", &ffs_opts->maxbpg, OPT_INT32,
+ 1, INT_MAX, "max blocks per file in a cg" },
+ { '\0', "avgfilesize", &ffs_opts->avgfilesize, OPT_INT32,
+ 1, INT_MAX, "expected average file size" },
+ { '\0', "avgfpdir", &ffs_opts->avgfpdir, OPT_INT32,
+ 1, INT_MAX, "expected # of files per directory" },
+ { '\0', "extent", &ffs_opts->maxbsize, OPT_INT32,
+ 1, INT_MAX, "maximum # extent size" },
+ { '\0', "maxbpcg", &ffs_opts->maxblkspercg, OPT_INT32,
+ 1, INT_MAX, "max # of blocks per group" },
+ { '\0', "version", &ffs_opts->version, OPT_INT32,
+ 1, 2, "UFS version" },
+ { .name = NULL }
};
char *var, *val;
diff -r 9627b1809417 -r 712fa7a6a00c usr.sbin/makefs/makefs.c
--- a/usr.sbin/makefs/makefs.c Wed Jan 23 20:39:46 2013 +0000
+++ b/usr.sbin/makefs/makefs.c Wed Jan 23 20:46:39 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: makefs.c,v 1.35 2012/06/22 06:15:18 sjg Exp $ */
+/* $NetBSD: makefs.c,v 1.36 2013/01/23 20:46:39 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.35 2012/06/22 06:15:18 sjg Exp $");
+__RCSID("$NetBSD: makefs.c,v 1.36 2013/01/23 20:46:39 christos Exp $");
#endif /* !__lint */
#include <assert.h>
@@ -52,6 +52,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <stdbool.h>
#include "makefs.h"
#include "mtree.h"
@@ -70,13 +71,15 @@
} fstype_t;
static fstype_t fstypes[] = {
- { "ffs", ffs_prep_opts, ffs_parse_opts, ffs_cleanup_opts, ffs_makefs },
- { "cd9660", cd9660_prep_opts, cd9660_parse_opts, cd9660_cleanup_opts,
- cd9660_makefs},
- { "chfs", chfs_prep_opts, chfs_parse_opts, chfs_cleanup_opts,
- chfs_makefs },
- { "v7fs", v7fs_prep_opts, v7fs_parse_opts, v7fs_cleanup_opts,
- v7fs_makefs },
+#define ENTRY(name) { \
+ # name, name ## _prep_opts, name ## _parse_opts, \
+ name ## _cleanup_opts, name ## _makefs \
+}
+ ENTRY(ffs),
+ ENTRY(cd9660),
+ ENTRY(chfs),
+ ENTRY(v7fs),
+ ENTRY(msdos),
{ .type = NULL },
};
@@ -301,14 +304,46 @@
int
set_option(const option_t *options, const char *var, const char *val)
{
- int i;
+ char *s;
+ size_t i;
+
+#define NUM(width) *(uint ## width ## _t *)options[i].value = \
+ (uint ## width ## _t)strsuftoll(options[i].desc, val, \
+ options[i].minimum, options[i].maximum); break
for (i = 0; options[i].name != NULL; i++) {
- if (strcmp(options[i].name, var) != 0)
+ if (options[i].letter != var[0] || var[1] != '\0')
+ continue;
+ else if (strcmp(options[i].name, var) != 0)
continue;
- *options[i].value = (int)strsuftoll(options[i].desc, val,
- options[i].minimum, options[i].maximum);
- return (1);
+ switch (options[i].type) {
+ case OPT_BOOL:
+ *(bool *)options[i].value = 1;
+ break;
+ case OPT_STRARRAY:
+ strlcpy((void *)options[i].value, val, (size_t)
+ options[i].maximum);
+ break;
+ case OPT_STRPTR:
+ if ((s = strdup(val)) == NULL)
+ err(1, NULL);
+ *(char **)options[i].value = s;
+ break;
+
+ case OPT_INT64:
+ NUM(64);
+ case OPT_INT32:
+ NUM(32);
+ case OPT_INT16:
+ NUM(16);
+ case OPT_INT8:
+ NUM(8);
+ default:
+ warnx("Unknown type %d in option %s", options[i].type,
+ val);
+ return 0;
+ }
+ return 1;
}
warnx("Unknown option `%s'", var);
return (0);
diff -r 9627b1809417 -r 712fa7a6a00c usr.sbin/makefs/makefs.h
--- a/usr.sbin/makefs/makefs.h Wed Jan 23 20:39:46 2013 +0000
+++ b/usr.sbin/makefs/makefs.h Wed Jan 23 20:46:39 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: makefs.h,v 1.27 2012/06/22 06:15:18 sjg Exp $ */
+/* $NetBSD: makefs.h,v 1.28 2013/01/23 20:46:39 christos Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -147,11 +147,23 @@
* result, and range checks for the result. Used to simplify fs specific
* option setting
*/
+typedef enum {
+ OPT_STRARRAY,
+ OPT_STRPTR,
+ OPT_BOOL,
+ OPT_INT8,
+ OPT_INT16,
+ OPT_INT32,
+ OPT_INT64
+} opttype_t;
+
typedef struct {
+ char letter; /* option letter NUL for none */
const char *name; /* option name */
- int *value; /* where to stuff the value */
- int minimum; /* minimum for value */
- int maximum; /* maximum for value */
+ void *value; /* where to stuff the value */
Home |
Main Index |
Thread Index |
Old Index