summaryrefslogtreecommitdiffstats
path: root/sbin/geom/class/label
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2005-12-07 01:38:27 +0000
committerpjd <pjd@FreeBSD.org>2005-12-07 01:38:27 +0000
commit03a6ffac1f9a8616d4b74a4d631d27f024966a76 (patch)
treeb5b01ee00715a779cd75c12e2ae3797f95f5124c /sbin/geom/class/label
parent4ed0dcf09fd85f4fd2c1e14c2a25a1904bd7df42 (diff)
downloadFreeBSD-src-03a6ffac1f9a8616d4b74a4d631d27f024966a76.zip
FreeBSD-src-03a6ffac1f9a8616d4b74a4d631d27f024966a76.tar.gz
- The geom(8) utility only uses three types of arguments: string (char *),
value (intmax_t) and boolean (int). Based on that provide three functions: - gctl_get_ascii() - gctl_get_int() - gctl_get_intmax() - Hide gctl_get_param() function, as it is only used internally in subr.c. - Allow to provide argument name as (fmt, ...). - Assert geom(8) bugs (missing argument is a geom(8) bug). - Clean-up and simplify the code by using new functions and assumtions (no more checking for missing argument). Tested by: regression tests
Diffstat (limited to 'sbin/geom/class/label')
-rw-r--r--sbin/geom/class/label/geom_label.c59
1 files changed, 16 insertions, 43 deletions
diff --git a/sbin/geom/class/label/geom_label.c b/sbin/geom/class/label/geom_label.c
index 83c713b..24b452e 100644
--- a/sbin/geom/class/label/geom_label.c
+++ b/sbin/geom/class/label/geom_label.c
@@ -89,7 +89,7 @@ label_main(struct gctl_req *req, unsigned flags)
if ((flags & G_FLAG_VERBOSE) != 0)
verbose = 1;
- name = gctl_get_asciiparam(req, "verb");
+ name = gctl_get_ascii(req, "verb");
if (name == NULL) {
gctl_error(req, "No '%s' argument.", "verb");
return;
@@ -110,14 +110,10 @@ label_label(struct gctl_req *req)
struct g_label_metadata md;
const char *name, *label;
u_char sector[512];
- int *nargs, error;
+ int error, nargs;
- nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
- if (nargs == NULL) {
- gctl_error(req, "No '%s' argument.", "nargs");
- return;
- }
- if (*nargs != 2) {
+ nargs = gctl_get_int(req, "nargs");
+ if (nargs != 2) {
gctl_error(req, "Invalid number of arguments.");
return;
}
@@ -125,11 +121,7 @@ label_label(struct gctl_req *req)
/*
* Clear last sector first to spoil all components if device exists.
*/
- name = gctl_get_asciiparam(req, "arg1");
- if (name == NULL) {
- gctl_error(req, "No 'arg%u' argument.", 1);
- return;
- }
+ name = gctl_get_ascii(req, "arg1");
error = g_metadata_clear(name, NULL);
if (error != 0) {
gctl_error(req, "Can't store metadata on %s: %s.", name,
@@ -139,11 +131,7 @@ label_label(struct gctl_req *req)
strlcpy(md.md_magic, G_LABEL_MAGIC, sizeof(md.md_magic));
md.md_version = G_LABEL_VERSION;
- label = gctl_get_asciiparam(req, "arg0");
- if (label == NULL) {
- gctl_error(req, "No 'arg%u' argument.", 0);
- return;
- }
+ label = gctl_get_ascii(req, "arg0");
strlcpy(md.md_label, label, sizeof(md.md_label));
md.md_provsize = g_get_mediasize(name);
if (md.md_provsize == 0) {
@@ -170,24 +158,16 @@ static void
label_clear(struct gctl_req *req)
{
const char *name;
- char param[16];
- unsigned i;
- int *nargs, error;
+ int error, i, nargs;
- nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
- if (nargs == NULL) {
- gctl_error(req, "No '%s' argument.", "nargs");
- return;
- }
- if (*nargs < 1) {
+ nargs = gctl_get_int(req, "nargs");
+ if (nargs < 1) {
gctl_error(req, "Too few arguments.");
return;
}
- for (i = 0; i < (unsigned)*nargs; i++) {
- snprintf(param, sizeof(param), "arg%u", i);
- name = gctl_get_asciiparam(req, param);
-
+ for (i = 0; i < nargs; i++) {
+ name = gctl_get_ascii(req, "arg%d", i);
error = g_metadata_clear(name, G_LABEL_MAGIC);
if (error != 0) {
fprintf(stderr, "Can't clear metadata on %s: %s.\n",
@@ -214,23 +194,16 @@ label_dump(struct gctl_req *req)
{
struct g_label_metadata md, tmpmd;
const char *name;
- char param[16];
- int *nargs, error, i;
+ int error, i, nargs;
- nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
- if (nargs == NULL) {
- gctl_error(req, "No '%s' argument.", "nargs");
- return;
- }
- if (*nargs < 1) {
+ nargs = gctl_get_int(req, "nargs");
+ if (nargs < 1) {
gctl_error(req, "Too few arguments.");
return;
}
- for (i = 0; i < *nargs; i++) {
- snprintf(param, sizeof(param), "arg%u", i);
- name = gctl_get_asciiparam(req, param);
-
+ for (i = 0; i < nargs; i++) {
+ name = gctl_get_ascii(req, "arg%d", i);
error = g_metadata_read(name, (u_char *)&tmpmd, sizeof(tmpmd),
G_LABEL_MAGIC);
if (error != 0) {
OpenPOWER on IntegriCloud