summaryrefslogtreecommitdiffstats
path: root/sbin/geom/class/part/geom_part.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/geom/class/part/geom_part.c')
-rw-r--r--sbin/geom/class/part/geom_part.c109
1 files changed, 59 insertions, 50 deletions
diff --git a/sbin/geom/class/part/geom_part.c b/sbin/geom/class/part/geom_part.c
index 658fba6e..673d90c 100644
--- a/sbin/geom/class/part/geom_part.c
+++ b/sbin/geom/class/part/geom_part.c
@@ -58,15 +58,15 @@ __FBSDID("$FreeBSD$");
uint32_t PUBSYM(lib_version) = G_LIB_VERSION;
uint32_t PUBSYM(version) = 0;
-static char autofill[] = "*";
-static char flags[] = "C";
-
static char sstart[32];
static char ssize[32];
-static const char const bootcode_param[] = "bootcode";
-static const char const index_param[] = "index";
-static const char const partcode_param[] = "partcode";
+#define GPART_AUTOFILL "*"
+#define GPART_FLAGS "C"
+
+#define GPART_PARAM_BOOTCODE "bootcode"
+#define GPART_PARAM_INDEX "index"
+#define GPART_PARAM_PARTCODE "partcode"
static struct gclass *find_class(struct gmesh *, const char *);
static struct ggeom * find_geom(struct gclass *, const char *);
@@ -87,76 +87,81 @@ static void gpart_write_partcode_vtoc8(struct ggeom *, int, void *);
struct g_command PUBSYM(class_commands)[] = {
{ "add", 0, gpart_issue, {
- { 'b', "start", autofill, G_TYPE_STRING },
- { 's', "size", autofill, G_TYPE_STRING },
+ { 'b', "start", GPART_AUTOFILL, G_TYPE_STRING },
+ { 's', "size", GPART_AUTOFILL, G_TYPE_STRING },
{ 't', "type", NULL, G_TYPE_STRING },
- { 'i', index_param, "", G_TYPE_ASCNUM },
+ { 'i', GPART_PARAM_INDEX, "", G_TYPE_ASCNUM },
{ 'l', "label", "", G_TYPE_STRING },
- { 'f', "flags", flags, G_TYPE_STRING },
+ { 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
G_OPT_SENTINEL },
- "geom", NULL
+ "[-b start] [-s size] -t type [-i index] [-l label] [-f flags] geom"
},
{ "bootcode", 0, gpart_bootcode, {
- { 'b', bootcode_param, "", G_TYPE_STRING },
- { 'p', partcode_param, "", G_TYPE_STRING },
- { 'i', index_param, "", G_TYPE_ASCNUM },
- { 'f', "flags", flags, G_TYPE_STRING },
+ { 'b', GPART_PARAM_BOOTCODE, "", G_TYPE_STRING },
+ { 'p', GPART_PARAM_PARTCODE, "", G_TYPE_STRING },
+ { 'i', GPART_PARAM_INDEX, "", G_TYPE_ASCNUM },
+ { 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
G_OPT_SENTINEL },
- "geom", NULL
+ "bootcode [-b bootcode] [-p partcode] [-i index] [-f flags] geom"
+ },
+ { "commit", 0, gpart_issue, G_NULL_OPTS,
+ "geom"
},
- { "commit", 0, gpart_issue, G_NULL_OPTS, "geom", NULL },
{ "create", 0, gpart_issue, {
{ 's', "scheme", NULL, G_TYPE_STRING },
{ 'n', "entries", "", G_TYPE_ASCNUM },
- { 'f', "flags", flags, G_TYPE_STRING },
+ { 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
G_OPT_SENTINEL },
- "provider", NULL
+ "-s scheme [-n entries] [-f flags] provider"
},
{ "delete", 0, gpart_issue, {
- { 'i', index_param, NULL, G_TYPE_ASCNUM },
- { 'f', "flags", flags, G_TYPE_STRING },
+ { 'i', GPART_PARAM_INDEX, NULL, G_TYPE_ASCNUM },
+ { 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
G_OPT_SENTINEL },
- "geom", NULL
+ "-i index [-f flags] geom"
},
{ "destroy", 0, gpart_issue, {
- { 'f', "flags", flags, G_TYPE_STRING },
+ { 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
G_OPT_SENTINEL },
- "geom", NULL },
+ "[-f flags] geom"
+ },
{ "modify", 0, gpart_issue, {
- { 'i', index_param, NULL, G_TYPE_ASCNUM },
+ { 'i', GPART_PARAM_INDEX, NULL, G_TYPE_ASCNUM },
{ 'l', "label", "", G_TYPE_STRING },
{ 't', "type", "", G_TYPE_STRING },
- { 'f', "flags", flags, G_TYPE_STRING },
+ { 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
G_OPT_SENTINEL },
- "geom", NULL
+ "-i index [-l label] [-t type] [-f flags] geom"
},
{ "set", 0, gpart_issue, {
{ 'a', "attrib", NULL, G_TYPE_STRING },
- { 'i', index_param, NULL, G_TYPE_ASCNUM },
- { 'f', "flags", flags, G_TYPE_STRING },
+ { 'i', GPART_PARAM_INDEX, NULL, G_TYPE_ASCNUM },
+ { 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
G_OPT_SENTINEL },
- "geom", NULL
+ "-a attrib -i index [-f flags] geom"
},
{ "show", 0, gpart_show, {
{ 'l', "show_label", NULL, G_TYPE_BOOL },
{ 'r', "show_rawtype", NULL, G_TYPE_BOOL },
G_OPT_SENTINEL },
- NULL, "[-lr] [geom ...]"
+ "[-lr] [geom ...]"
+ },
+ { "undo", 0, gpart_issue, G_NULL_OPTS,
+ "geom"
},
- { "undo", 0, gpart_issue, G_NULL_OPTS, "geom", NULL },
{ "unset", 0, gpart_issue, {
{ 'a', "attrib", NULL, G_TYPE_STRING },
- { 'i', index_param, NULL, G_TYPE_ASCNUM },
- { 'f', "flags", flags, G_TYPE_STRING },
+ { 'i', GPART_PARAM_INDEX, NULL, G_TYPE_ASCNUM },
+ { 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
G_OPT_SENTINEL },
- "geom", NULL
+ "-a attrib -i index [-f flags] geom"
},
{ "resize", 0, gpart_issue, {
- { 's', "size", autofill, G_TYPE_STRING },
- { 'i', index_param, NULL, G_TYPE_ASCNUM },
- { 'f', "flags", flags, G_TYPE_STRING },
+ { 's', "size", GPART_AUTOFILL, G_TYPE_STRING },
+ { 'i', GPART_PARAM_INDEX, NULL, G_TYPE_ASCNUM },
+ { 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
G_OPT_SENTINEL },
- "geom", NULL
+ "[-s size] -i index [-f flags] geom"
},
G_CMD_SENTINEL
};
@@ -281,7 +286,7 @@ gpart_autofill_resize(struct gctl_req *req)
char *val;
int error, idx;
- s = gctl_get_ascii(req, index_param);
+ s = gctl_get_ascii(req, GPART_PARAM_INDEX);
idx = strtol(s, &val, 10);
if (idx < 1 || *s == '\0' || *val != '\0')
errx(EXIT_FAILURE, "invalid partition index");
@@ -773,11 +778,11 @@ gpart_bootcode(struct gctl_req *req, unsigned int fl)
size_t bootsize, partsize;
int error, idx, vtoc8;
- if (gctl_has_param(req, bootcode_param)) {
- s = gctl_get_ascii(req, bootcode_param);
+ if (gctl_has_param(req, GPART_PARAM_BOOTCODE)) {
+ s = gctl_get_ascii(req, GPART_PARAM_BOOTCODE);
bootsize = 800 * 1024; /* Arbitrary limit. */
bootcode = gpart_bootfile_read(s, &bootsize);
- error = gctl_change_param(req, bootcode_param, bootsize,
+ error = gctl_change_param(req, GPART_PARAM_BOOTCODE, bootsize,
bootcode);
if (error)
errc(EXIT_FAILURE, error, "internal error");
@@ -797,7 +802,7 @@ gpart_bootcode(struct gctl_req *req, unsigned int fl)
geom_deletetree(&mesh);
errx(EXIT_FAILURE, "Class %s not found.", s);
}
- s = gctl_get_ascii(req, "geom");
+ s = gctl_get_ascii(req, "arg0");
if (s == NULL)
abort();
gp = find_geom(classp, s);
@@ -808,11 +813,11 @@ gpart_bootcode(struct gctl_req *req, unsigned int fl)
if (strcmp(s, "VTOC8") == 0)
vtoc8 = 1;
- if (gctl_has_param(req, partcode_param)) {
- s = gctl_get_ascii(req, partcode_param);
+ if (gctl_has_param(req, GPART_PARAM_PARTCODE)) {
+ s = gctl_get_ascii(req, GPART_PARAM_PARTCODE);
partsize = vtoc8 != 0 ? VTOC_BOOTSIZE : bootsize * 1024;
partcode = gpart_bootfile_read(s, &partsize);
- error = gctl_delete_param(req, partcode_param);
+ error = gctl_delete_param(req, GPART_PARAM_PARTCODE);
if (error)
errc(EXIT_FAILURE, error, "internal error");
} else {
@@ -820,14 +825,14 @@ gpart_bootcode(struct gctl_req *req, unsigned int fl)
partsize = 0;
}
- if (gctl_has_param(req, index_param)) {
+ if (gctl_has_param(req, GPART_PARAM_INDEX)) {
if (partcode == NULL)
errx(EXIT_FAILURE, "-i is only valid with -p");
- s = gctl_get_ascii(req, index_param);
+ s = gctl_get_ascii(req, GPART_PARAM_INDEX);
idx = strtol(s, &sp, 10);
if (idx < 1 || *s == '\0' || *sp != '\0')
errx(EXIT_FAILURE, "invalid partition index");
- error = gctl_delete_param(req, index_param);
+ error = gctl_delete_param(req, GPART_PARAM_INDEX);
if (error)
errc(EXIT_FAILURE, error, "internal error");
} else
@@ -858,6 +863,10 @@ gpart_issue(struct gctl_req *req, unsigned int fl __unused)
const char *errstr;
int error, status;
+ if (gctl_get_int(req, "nargs") != 1)
+ errx(EXIT_FAILURE, "Invalid number of arguments.");
+ (void)gctl_delete_param(req, "nargs");
+
/* autofill parameters (if applicable). */
error = gpart_autofill(req);
if (error) {
OpenPOWER on IntegriCloud