diff options
author | pjd <pjd@FreeBSD.org> | 2007-01-25 11:35:27 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2007-01-25 11:35:27 +0000 |
commit | 3cd8e7b3572226079cabceefaf984b17b0669ffa (patch) | |
tree | 175d17a3e4ed80b502ea89880607a3463d493220 | |
parent | 5ecf1e982695ff237f2f1e4eba46419b85a2488e (diff) | |
download | FreeBSD-src-3cd8e7b3572226079cabceefaf984b17b0669ffa.zip FreeBSD-src-3cd8e7b3572226079cabceefaf984b17b0669ffa.tar.gz |
Implement gctl_change_param() function, which changes value of existing
parameter.
MFC after: 1 week
-rw-r--r-- | sbin/geom/misc/subr.c | 26 | ||||
-rw-r--r-- | sbin/geom/misc/subr.h | 2 |
2 files changed, 28 insertions, 0 deletions
diff --git a/sbin/geom/misc/subr.c b/sbin/geom/misc/subr.c index 1faafe5..745d919 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 865e855..4c54142 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, ...) __printflike(2, 3) int gctl_get_int(struct gctl_req *req, const char *pfmt, ...) __printflike(2, 3); intmax_t gctl_get_intmax(struct gctl_req *req, const char *pfmt, ...) __printflike(2, 3); const char *gctl_get_ascii(struct gctl_req *req, const char *pfmt, ...) __printflike(2, 3); +int gctl_change_param(struct gctl_req *req, const char *name, int len, + const void *value); #endif /* !_SUBR_H_ */ |