summaryrefslogtreecommitdiffstats
path: root/sbin/geom/class/concat
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/concat
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/concat')
-rw-r--r--sbin/geom/class/concat/geom_concat.c77
1 files changed, 22 insertions, 55 deletions
diff --git a/sbin/geom/class/concat/geom_concat.c b/sbin/geom/class/concat/geom_concat.c
index 20b5b89..bf4687e 100644
--- a/sbin/geom/class/concat/geom_concat.c
+++ b/sbin/geom/class/concat/geom_concat.c
@@ -94,7 +94,7 @@ concat_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;
@@ -115,32 +115,20 @@ concat_label(struct gctl_req *req)
struct g_concat_metadata md;
u_char sector[512];
const char *name;
- char param[16];
- unsigned i;
- int *hardcode, *nargs, error;
+ int error, i, hardcode, 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, "Too few arguments.");
return;
}
- hardcode = gctl_get_paraml(req, "hardcode", sizeof(*hardcode));
- if (hardcode == NULL) {
- gctl_error(req, "No '%s' argument.", "hardcode");
- return;
- }
+ hardcode = gctl_get_int(req, "hardcode");
/*
* Clear last sector first to spoil all components if device exists.
*/
- for (i = 1; i < (unsigned)*nargs; i++) {
- snprintf(param, sizeof(param), "arg%u", i);
- name = gctl_get_asciiparam(req, param);
-
+ for (i = 1; i < nargs; i++) {
+ name = gctl_get_ascii(req, "arg%d", i);
error = g_metadata_clear(name, NULL);
if (error != 0) {
gctl_error(req, "Can't store metadata on %s: %s.", name,
@@ -151,24 +139,18 @@ concat_label(struct gctl_req *req)
strlcpy(md.md_magic, G_CONCAT_MAGIC, sizeof(md.md_magic));
md.md_version = G_CONCAT_VERSION;
- name = gctl_get_asciiparam(req, "arg0");
- if (name == NULL) {
- gctl_error(req, "No 'arg%u' argument.", 0);
- return;
- }
+ name = gctl_get_ascii(req, "arg0");
strlcpy(md.md_name, name, sizeof(md.md_name));
md.md_id = arc4random();
- md.md_all = *nargs - 1;
+ md.md_all = nargs - 1;
/*
* Ok, store metadata.
*/
- for (i = 1; i < (unsigned)*nargs; i++) {
- snprintf(param, sizeof(param), "arg%u", i);
- name = gctl_get_asciiparam(req, param);
-
+ for (i = 1; i < nargs; i++) {
+ name = gctl_get_ascii(req, "arg%d", i);
md.md_no = i - 1;
- if (!*hardcode)
+ if (!hardcode)
bzero(md.md_provider, sizeof(md.md_provider));
else {
if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
@@ -199,24 +181,16 @@ static void
concat_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_CONCAT_MAGIC);
if (error != 0) {
fprintf(stderr, "Can't clear metadata on %s: %s.\n",
@@ -247,23 +221,16 @@ concat_dump(struct gctl_req *req)
{
struct g_concat_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_CONCAT_MAGIC);
if (error != 0) {
OpenPOWER on IntegriCloud