From 1ebd1ed20e8bfd356317745bc0cc2a15d3080ea4 Mon Sep 17 00:00:00 2001 From: pjd Date: Sat, 3 Feb 2007 16:08:11 +0000 Subject: [PATCH] MFC: sbin/geom/misc/subr.c 1.7 sbin/geom/misc/subr.h 1.8 Implement gctl_change_param() function, which changes value of existing parameter. --- sbin/geom/misc/subr.c | 26 ++++++++++++++++++++++++++ sbin/geom/misc/subr.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/sbin/geom/misc/subr.c b/sbin/geom/misc/subr.c index 1faafe5bdd46..745d91955d3d 100644 --- a/sbin/geom/misc/subr.c +++ b/sbin/geom/misc/subr.c @@ -388,3 +388,29 @@ gctl_get_ascii(struct gctl_req *req, const char *pfmt, ...) va_end(ap); return (p); } + +int +gctl_change_param(struct gctl_req *req, const char *name, int len, + const void *value) +{ + struct gctl_req_arg *ap; + unsigned i; + + if (req == NULL || req->error != NULL) + return (EDOOFUS); + for (i = 0; i < req->narg; i++) { + ap = &req->arg[i]; + if (strcmp(ap->name, name) != 0) + continue; + ap->value = __DECONST(void *, value); + if (len >= 0) { + ap->flag &= ~GCTL_PARAM_ASCII; + ap->len = len; + } else if (len < 0) { + ap->flag |= GCTL_PARAM_ASCII; + ap->len = strlen(value) + 1; + } + return (0); + } + return (ENOENT); +} diff --git a/sbin/geom/misc/subr.h b/sbin/geom/misc/subr.h index 61f5ab0e86df..7b5120053d80 100644 --- a/sbin/geom/misc/subr.h +++ b/sbin/geom/misc/subr.h @@ -45,4 +45,6 @@ void gctl_error(struct gctl_req *req, const char *error, ...); int gctl_get_int(struct gctl_req *req, const char *pfmt, ...); intmax_t gctl_get_intmax(struct gctl_req *req, const char *pfmt, ...); const char *gctl_get_ascii(struct gctl_req *req, const char *pfmt, ...); +int gctl_change_param(struct gctl_req *req, const char *name, int len, + const void *value); #endif /* !_SUBR_H_ */