summaryrefslogtreecommitdiffstats
path: root/sbin/geom/core
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2007-05-15 20:25:18 +0000
committermarcel <marcel@FreeBSD.org>2007-05-15 20:25:18 +0000
commit40656d08513a31c921315a57a9bbd86878c991fa (patch)
treede4581799ddcced445b8a47904084798e54bf914 /sbin/geom/core
parent8ea441aed588aa6eb59168cf5f54cf2931aaf6e1 (diff)
downloadFreeBSD-src-40656d08513a31c921315a57a9bbd86878c991fa.zip
FreeBSD-src-40656d08513a31c921315a57a9bbd86878c991fa.tar.gz
Add gpart(8).
In order to support gpart(8), geom(8) needs to support a named argument. Also, optional string parameters are a requirement. Both have been added to the infrastructure. The former required all existing classes to be adjusted.
Diffstat (limited to 'sbin/geom/core')
-rw-r--r--sbin/geom/core/geom.c41
-rw-r--r--sbin/geom/core/geom.h3
2 files changed, 28 insertions, 16 deletions
diff --git a/sbin/geom/core/geom.c b/sbin/geom/core/geom.c
index d375ba3..7547f50 100644
--- a/sbin/geom/core/geom.c
+++ b/sbin/geom/core/geom.c
@@ -69,8 +69,8 @@ static void std_load(struct gctl_req *req, unsigned flags);
static void std_unload(struct gctl_req *req, unsigned flags);
struct g_command std_commands[] = {
- { "help", 0, std_help, G_NULL_OPTS, NULL },
- { "list", 0, std_list, G_NULL_OPTS,
+ { "help", 0, std_help, G_NULL_OPTS, NULL, NULL },
+ { "list", 0, std_list, G_NULL_OPTS, NULL,
"[name ...]"
},
{ "status", 0, std_status,
@@ -78,10 +78,11 @@ struct g_command std_commands[] = {
{ 's', "script", NULL, G_TYPE_BOOL },
G_OPT_SENTINEL
},
- "[-s] [name ...]"
+ NULL, "[-s] [name ...]"
},
- { "load", G_FLAG_VERBOSE | G_FLAG_LOADKLD, std_load, G_NULL_OPTS, NULL },
- { "unload", G_FLAG_VERBOSE, std_unload, G_NULL_OPTS, NULL },
+ { "load", G_FLAG_VERBOSE | G_FLAG_LOADKLD, std_load, G_NULL_OPTS,
+ NULL, NULL },
+ { "unload", G_FLAG_VERBOSE, std_unload, G_NULL_OPTS, NULL, NULL },
G_CMD_SENTINEL
};
@@ -112,6 +113,8 @@ usage_command(struct g_command *cmd, const char *prefix)
if (opt->go_val != NULL || G_OPT_TYPE(opt) == G_TYPE_BOOL)
fprintf(stderr, "]");
}
+ if (cmd->gc_argname)
+ fprintf(stderr, " %s", cmd->gc_argname);
fprintf(stderr, "\n");
}
@@ -327,23 +330,31 @@ parse_arguments(struct g_command *cmd, struct gctl_req *req, int *argc,
gctl_ro_param(req, opt->go_name,
sizeof(intmax_t), opt->go_val);
} else if (G_OPT_TYPE(opt) == G_TYPE_STRING) {
- gctl_ro_param(req, opt->go_name, -1,
- opt->go_val);
+ if (*(char *)opt->go_val != '\0')
+ gctl_ro_param(req, opt->go_name,
+ -1, opt->go_val);
} else {
assert(!"Invalid type");
}
}
}
}
- /*
- * Add rest of given arguments.
- */
- gctl_ro_param(req, "nargs", sizeof(int), argc);
- for (i = 0; i < (unsigned)*argc; i++) {
- char argname[16];
- snprintf(argname, sizeof(argname), "arg%u", i);
- gctl_ro_param(req, argname, -1, (*argv)[i]);
+ if (cmd->gc_argname == NULL) {
+ /*
+ * Add rest of given arguments.
+ */
+ gctl_ro_param(req, "nargs", sizeof(int), argc);
+ for (i = 0; i < (unsigned)*argc; i++) {
+ char argname[16];
+
+ snprintf(argname, sizeof(argname), "arg%u", i);
+ gctl_ro_param(req, argname, -1, (*argv)[i]);
+ }
+ } else {
+ if (*argc != 1)
+ usage();
+ gctl_ro_param(req, cmd->gc_argname, -1, (*argv)[0]);
}
}
diff --git a/sbin/geom/core/geom.h b/sbin/geom/core/geom.h
index 5368b56..ecca7b6 100644
--- a/sbin/geom/core/geom.h
+++ b/sbin/geom/core/geom.h
@@ -48,7 +48,7 @@
#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 }
+#define G_CMD_SENTINEL { NULL, 0, NULL, G_NULL_OPTS, NULL, NULL }
struct g_option {
char go_char;
@@ -62,6 +62,7 @@ struct g_command {
unsigned gc_flags;
void (*gc_func)(struct gctl_req *, unsigned);
struct g_option gc_options[G_OPT_MAX];
+ const char *gc_argname;
const char *gc_usage;
};
#endif /* !_GEOM_H_ */
OpenPOWER on IntegriCloud