svn commit: r212606 - in head/sbin/geom: class/part core

Pawel Jakub Dawidek pjd at FreeBSD.org
Tue Sep 14 11:13:47 UTC 2010


Author: pjd
Date: Tue Sep 14 11:13:46 2010
New Revision: 212606
URL: http://svn.freebsd.org/changeset/base/212606

Log:
  Introduce special G_VAL_OPTIONAL define, which when given in value field
  tells geom(8) to ignore it when it is not given and don't try to obtain
  default value.

Modified:
  head/sbin/geom/class/part/geom_part.c
  head/sbin/geom/core/geom.c
  head/sbin/geom/core/geom.h

Modified: head/sbin/geom/class/part/geom_part.c
==============================================================================
--- head/sbin/geom/class/part/geom_part.c	Tue Sep 14 10:27:32 2010	(r212605)
+++ head/sbin/geom/class/part/geom_part.c	Tue Sep 14 11:13:46 2010	(r212606)
@@ -90,16 +90,16 @@ struct g_command PUBSYM(class_commands)[
 		{ 'b', "start", GPART_AUTOFILL, G_TYPE_STRING },
 		{ 's', "size", GPART_AUTOFILL, G_TYPE_STRING },
 		{ 't', "type", NULL, G_TYPE_STRING },
-		{ 'i', GPART_PARAM_INDEX, "", G_TYPE_ASCNUM },
-		{ 'l', "label", "", G_TYPE_STRING },
+		{ 'i', GPART_PARAM_INDEX, G_VAL_OPTIONAL, G_TYPE_ASCNUM },
+		{ 'l', "label", G_VAL_OPTIONAL, G_TYPE_STRING },
 		{ 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
 		G_OPT_SENTINEL },
 	    "[-b start] [-s size] -t type [-i index] [-l label] [-f flags] geom"
 	},
 	{ "bootcode", 0, gpart_bootcode, {
-		{ 'b', GPART_PARAM_BOOTCODE, "", G_TYPE_STRING },
-		{ 'p', GPART_PARAM_PARTCODE, "", G_TYPE_STRING },
-		{ 'i', GPART_PARAM_INDEX, "", G_TYPE_ASCNUM },
+		{ 'b', GPART_PARAM_BOOTCODE, G_VAL_OPTIONAL, G_TYPE_STRING },
+		{ 'p', GPART_PARAM_PARTCODE, G_VAL_OPTIONAL, G_TYPE_STRING },
+		{ 'i', GPART_PARAM_INDEX, G_VAL_OPTIONAL, G_TYPE_ASCNUM },
 		{ 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
 		G_OPT_SENTINEL },
 	    "bootcode [-b bootcode] [-p partcode] [-i index] [-f flags] geom"
@@ -109,7 +109,7 @@ struct g_command PUBSYM(class_commands)[
 	},
 	{ "create", 0, gpart_issue, {
 		{ 's', "scheme", NULL, G_TYPE_STRING },
-		{ 'n', "entries", "", G_TYPE_ASCNUM },
+		{ 'n', "entries", G_VAL_OPTIONAL, G_TYPE_ASCNUM },
 		{ 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
 		G_OPT_SENTINEL },
 	    "-s scheme [-n entries] [-f flags] provider"
@@ -127,8 +127,8 @@ struct g_command PUBSYM(class_commands)[
 	},
 	{ "modify", 0, gpart_issue, {
 		{ 'i', GPART_PARAM_INDEX, NULL, G_TYPE_ASCNUM },
-		{ 'l', "label", "", G_TYPE_STRING },
-		{ 't', "type", "", G_TYPE_STRING },
+		{ 'l', "label", G_VAL_OPTIONAL, G_TYPE_STRING },
+		{ 't', "type", G_VAL_OPTIONAL, G_TYPE_STRING },
 		{ 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
 		G_OPT_SENTINEL },
 	    "-i index [-l label] [-t type] [-f flags] geom"

Modified: head/sbin/geom/core/geom.c
==============================================================================
--- head/sbin/geom/core/geom.c	Tue Sep 14 10:27:32 2010	(r212605)
+++ head/sbin/geom/core/geom.c	Tue Sep 14 11:13:46 2010	(r212606)
@@ -374,9 +374,8 @@ parse_arguments(struct g_command *cmd, s
 				warnx("Option '%c' not specified.",
 				    opt->go_char);
 				usage();
-			} else if (G_OPT_TYPE(opt) == G_TYPE_ASCNUM &&
-			    *(const char *)opt->go_val == '\0') {
-			    	;	/* add nothing. */
+			} else if (opt->go_val == G_VAL_OPTIONAL) {
+				/* add nothing. */
 			} else {
 				set_option(req, opt, opt->go_val);
 			}

Modified: head/sbin/geom/core/geom.h
==============================================================================
--- head/sbin/geom/core/geom.h	Tue Sep 14 10:27:32 2010	(r212605)
+++ head/sbin/geom/core/geom.h	Tue Sep 14 11:13:46 2010	(r212606)
@@ -53,6 +53,8 @@
 #define	G_OPT_NUM(opt)		(((opt)->go_type & G_TYPE_NUMMASK) >> G_TYPE_NUMSHIFT)
 #define	G_OPT_NUMINC(opt)	((opt)->go_type += (1 << G_TYPE_NUMSHIFT))
 
+#define	G_VAL_OPTIONAL	((void *)-1)
+
 #define G_OPT_SENTINEL	{ '\0', NULL, NULL, G_TYPE_NONE }
 #define G_NULL_OPTS	{ G_OPT_SENTINEL }
 #define	G_CMD_SENTINEL	{ NULL, 0, NULL, G_NULL_OPTS, NULL }


More information about the svn-src-head mailing list