Index: class/journal/geom_journal.c =================================================================== RCS file: /alt/ncvs/src/sbin/geom/class/journal/geom_journal.c,v retrieving revision 1.2 diff -u -r1.2 geom_journal.c --- class/journal/geom_journal.c 1 Nov 2006 09:22:33 -0000 1.2 +++ class/journal/geom_journal.c 3 Apr 2007 04:49:28 -0000 @@ -66,7 +66,7 @@ { 'c', "checksum", NULL, G_TYPE_BOOL }, { 'f', "force", NULL, G_TYPE_BOOL }, { 'h', "hardcode", NULL, G_TYPE_BOOL }, - { 's', "jsize", &default_jsize, G_TYPE_NUMBER }, + { 's', "jsize", &default_jsize, G_TYPE_STRING }, G_OPT_SENTINEL }, "[-cfhv] [-s jsize] dataprov [jprov]" @@ -174,7 +174,7 @@ } data = gctl_get_ascii(req, "arg0"); - jsize = gctl_get_intmax(req, "jsize"); + jsize = gctl_get_numexpr(req, "jsize"); journal = NULL; switch (nargs) { case 1: Index: misc/subr.c =================================================================== RCS file: /alt/ncvs/src/sbin/geom/misc/subr.c,v retrieving revision 1.7 diff -u -r1.7 subr.c --- misc/subr.c 25 Jan 2007 11:35:27 -0000 1.7 +++ misc/subr.c 3 Apr 2007 04:50:44 -0000 @@ -377,6 +377,70 @@ return (*p); } +/* + * Convert an expression of the following forms to a uintmax_t. + * 1) A positive decimal number. + * 2) A positive decimal number followed by a 'b' or 'B' (mult by 512). + * 3) A positive decimal number followed by a 'k' or 'K' (mult by 1 << 10). + * 4) A positive decimal number followed by a 'm' or 'M' (mult by 1 << 20). + * 5) A positive decimal number followed by a 'g' or 'G' (mult by 1 << 30). + * 5) A positive decimal number followed by a 'w' or 'W' (mult by sizeof int). + */ +intmax_t +gctl_get_numexpr(struct gctl_req *req, const char *pfmt, ...) +{ + const char *val; + va_list ap; + uintmax_t num, mult, prevnum; + char *expr; + + va_start(ap, pfmt); + val = gctl_get_param(req, 0, pfmt, ap); + + num = strtouq(val, &expr, 0); + + if (expr == val) /* No valid digits. */ + printf("illegal numeric value\n"); + + mult = 0; + switch (*expr) { + case 'B': + case 'b': + mult = 512; + break; + case 'K': + case 'k': + mult = 1 << 10; + break; + case 'M': + case 'm': + mult = 1 << 20; + break; + case 'G': + case 'g': + mult = 1 << 30; + break; + case 'W': + case 'w': + mult = sizeof(int); + break; + default: + ; + } + + if (mult != 0) { + prevnum = num; + num *= mult; + /* Check for overflow. */ + if (num / mult != prevnum) + printf("overflow in argument\n"); + expr++; + } + + va_end(ap); + return (num); +} + const char * gctl_get_ascii(struct gctl_req *req, const char *pfmt, ...) { Index: misc/subr.h =================================================================== RCS file: /alt/ncvs/src/sbin/geom/misc/subr.h,v retrieving revision 1.8 diff -u -r1.8 subr.h --- misc/subr.h 25 Jan 2007 11:35:27 -0000 1.8 +++ misc/subr.h 3 Apr 2007 04:21:36 -0000 @@ -44,6 +44,7 @@ void gctl_error(struct gctl_req *req, const char *error, ...) __printflike(2, 3); int gctl_get_int(struct gctl_req *req, const char *pfmt, ...) __printflike(2, 3); intmax_t gctl_get_intmax(struct gctl_req *req, const char *pfmt, ...) __printflike(2, 3); +intmax_t gctl_get_numexpr(struct gctl_req *req, const char *pfmt, ...) __printflike(2, 3); const char *gctl_get_ascii(struct gctl_req *req, const char *pfmt, ...) __printflike(2, 3); int gctl_change_param(struct gctl_req *req, const char *name, int len, const void *value);