diff options
author | pjd <pjd@FreeBSD.org> | 2010-09-13 08:56:07 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2010-09-13 08:56:07 +0000 |
commit | 6f96b7c2288e6972fad73b42080d841231294cae (patch) | |
tree | 4675ae936d21184a722c23122b0256934f486ced /sbin | |
parent | ab04d6fe3f3cad0bec4d257b1064f6959ac9d358 (diff) | |
download | FreeBSD-src-6f96b7c2288e6972fad73b42080d841231294cae.zip FreeBSD-src-6f96b7c2288e6972fad73b42080d841231294cae.tar.gz |
- Allow to specify value as const pointers.
- Make optional string values always an empty string.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/geom/class/eli/geom_eli.c | 33 | ||||
-rw-r--r-- | sbin/geom/class/mirror/geom_mirror.c | 7 | ||||
-rw-r--r-- | sbin/geom/class/part/geom_part.c | 17 | ||||
-rw-r--r-- | sbin/geom/class/sched/geom_sched.c | 10 | ||||
-rw-r--r-- | sbin/geom/core/geom.c | 32 | ||||
-rw-r--r-- | sbin/geom/core/geom.h | 2 |
6 files changed, 50 insertions, 51 deletions
diff --git a/sbin/geom/class/eli/geom_eli.c b/sbin/geom/class/eli/geom_eli.c index d772a9a..d5acc99 100644 --- a/sbin/geom/class/eli/geom_eli.c +++ b/sbin/geom/class/eli/geom_eli.c @@ -55,15 +55,12 @@ uint32_t lib_version = G_LIB_VERSION; uint32_t version = G_ELI_VERSION; #define GELI_BACKUP_DIR "/var/backups/" +#define GELI_ENC_ALGO "aes" -static char aalgo[] = "none"; -static char ealgo[] = "aes"; static intmax_t keylen = 0; static intmax_t keyno = -1; static intmax_t iterations = -1; static intmax_t sectorsize = 0; -static char keyfile[] = "", newkeyfile[] = ""; -static char backupfile[] = ""; static void eli_main(struct gctl_req *req, unsigned flags); static void eli_init(struct gctl_req *req); @@ -101,12 +98,12 @@ static int eli_backup_create(struct gctl_req *req, const char *prov, struct g_command class_commands[] = { { "init", G_FLAG_VERBOSE, eli_main, { - { 'a', "aalgo", aalgo, G_TYPE_STRING }, + { 'a', "aalgo", "", G_TYPE_STRING }, { 'b', "boot", NULL, G_TYPE_BOOL }, - { 'B', "backupfile", backupfile, G_TYPE_STRING }, - { 'e', "ealgo", ealgo, G_TYPE_STRING }, + { 'B', "backupfile", "", G_TYPE_STRING }, + { 'e', "ealgo", GELI_ENC_ALGO, G_TYPE_STRING }, { 'i', "iterations", &iterations, G_TYPE_NUMBER }, - { 'K', "newkeyfile", newkeyfile, G_TYPE_STRING }, + { 'K', "newkeyfile", "", G_TYPE_STRING }, { 'l', "keylen", &keylen, G_TYPE_NUMBER }, { 'P', "nonewpassphrase", NULL, G_TYPE_BOOL }, { 's', "sectorsize", §orsize, G_TYPE_NUMBER }, @@ -116,12 +113,12 @@ struct g_command class_commands[] = { }, { "label", G_FLAG_VERBOSE, eli_main, { - { 'a', "aalgo", aalgo, G_TYPE_STRING }, + { 'a', "aalgo", "", G_TYPE_STRING }, { 'b', "boot", NULL, G_TYPE_BOOL }, - { 'B', "backupfile", backupfile, G_TYPE_STRING }, - { 'e', "ealgo", ealgo, G_TYPE_STRING }, + { 'B', "backupfile", "", G_TYPE_STRING }, + { 'e', "ealgo", GELI_ENC_ALGO, G_TYPE_STRING }, { 'i', "iterations", &iterations, G_TYPE_NUMBER }, - { 'K', "newkeyfile", newkeyfile, G_TYPE_STRING }, + { 'K', "newkeyfile", "", G_TYPE_STRING }, { 'l', "keylen", &keylen, G_TYPE_NUMBER }, { 'P', "nonewpassphrase", NULL, G_TYPE_BOOL }, { 's', "sectorsize", §orsize, G_TYPE_NUMBER }, @@ -132,7 +129,7 @@ struct g_command class_commands[] = { { "attach", G_FLAG_VERBOSE | G_FLAG_LOADKLD, eli_main, { { 'd', "detach", NULL, G_TYPE_BOOL }, - { 'k', "keyfile", keyfile, G_TYPE_STRING }, + { 'k', "keyfile", "", G_TYPE_STRING }, { 'p', "nopassphrase", NULL, G_TYPE_BOOL }, { 'r', "readonly", NULL, G_TYPE_BOOL }, G_OPT_SENTINEL @@ -157,9 +154,9 @@ struct g_command class_commands[] = { }, { "onetime", G_FLAG_VERBOSE | G_FLAG_LOADKLD, NULL, { - { 'a', "aalgo", aalgo, G_TYPE_STRING }, + { 'a', "aalgo", "", G_TYPE_STRING }, { 'd', "detach", NULL, G_TYPE_BOOL }, - { 'e', "ealgo", ealgo, G_TYPE_STRING }, + { 'e', "ealgo", GELI_ENC_ALGO, G_TYPE_STRING }, { 'l', "keylen", &keylen, G_TYPE_NUMBER }, { 's', "sectorsize", §orsize, G_TYPE_NUMBER }, G_OPT_SENTINEL @@ -177,8 +174,8 @@ struct g_command class_commands[] = { { "setkey", G_FLAG_VERBOSE, eli_main, { { 'i', "iterations", &iterations, G_TYPE_NUMBER }, - { 'k', "keyfile", keyfile, G_TYPE_STRING }, - { 'K', "newkeyfile", newkeyfile, G_TYPE_STRING }, + { 'k', "keyfile", "", G_TYPE_STRING }, + { 'K', "newkeyfile", "", G_TYPE_STRING }, { 'n', "keyno", &keyno, G_TYPE_NUMBER }, { 'p', "nopassphrase", NULL, G_TYPE_BOOL }, { 'P', "nonewpassphrase", NULL, G_TYPE_BOOL }, @@ -551,7 +548,7 @@ eli_init(struct gctl_req *req) md.md_flags |= G_ELI_FLAG_BOOT; md.md_ealgo = CRYPTO_ALGORITHM_MIN - 1; str = gctl_get_ascii(req, "aalgo"); - if (strcmp(str, "none") != 0) { + if (*str != '\0') { md.md_aalgo = g_eli_str2aalgo(str); if (md.md_aalgo >= CRYPTO_ALGORITHM_MIN && md.md_aalgo <= CRYPTO_ALGORITHM_MAX) { diff --git a/sbin/geom/class/mirror/geom_mirror.c b/sbin/geom/class/mirror/geom_mirror.c index cf15c60..de51fb1 100644 --- a/sbin/geom/class/mirror/geom_mirror.c +++ b/sbin/geom/class/mirror/geom_mirror.c @@ -44,7 +44,8 @@ __FBSDID("$FreeBSD$"); uint32_t lib_version = G_LIB_VERSION; uint32_t version = G_MIRROR_VERSION; -static char label_balance[] = "load", configure_balance[] = "none"; +#define GMIRROR_BALANCE "load" + static intmax_t label_slice = 4096, configure_slice = -1; static intmax_t insert_priority = 0, configure_priority = -1; @@ -64,7 +65,7 @@ struct g_command class_commands[] = { { "configure", G_FLAG_VERBOSE, NULL, { { 'a', "autosync", NULL, G_TYPE_BOOL }, - { 'b', "balance", configure_balance, G_TYPE_STRING }, + { 'b', "balance", "", G_TYPE_STRING }, { 'd', "dynamic", NULL, G_TYPE_BOOL }, { 'f', "failsync", NULL, G_TYPE_BOOL }, { 'F', "nofailsync", NULL, G_TYPE_BOOL }, @@ -88,7 +89,7 @@ struct g_command class_commands[] = { }, { "label", G_FLAG_VERBOSE, mirror_main, { - { 'b', "balance", label_balance, G_TYPE_STRING }, + { 'b', "balance", GMIRROR_BALANCE, G_TYPE_STRING }, { 'F', "nofailsync", NULL, G_TYPE_BOOL }, { 'h', "hardcode", NULL, G_TYPE_BOOL }, { 'n', "noautosync", NULL, G_TYPE_BOOL }, diff --git a/sbin/geom/class/part/geom_part.c b/sbin/geom/class/part/geom_part.c index cc1145e..658fba6e 100644 --- a/sbin/geom/class/part/geom_part.c +++ b/sbin/geom/class/part/geom_part.c @@ -59,7 +59,6 @@ uint32_t PUBSYM(lib_version) = G_LIB_VERSION; uint32_t PUBSYM(version) = 0; static char autofill[] = "*"; -static char optional[] = ""; static char flags[] = "C"; static char sstart[32]; @@ -91,16 +90,16 @@ struct g_command PUBSYM(class_commands)[] = { { 'b', "start", autofill, G_TYPE_STRING }, { 's', "size", autofill, G_TYPE_STRING }, { 't', "type", NULL, G_TYPE_STRING }, - { 'i', index_param, optional, G_TYPE_ASCNUM }, - { 'l', "label", optional, G_TYPE_STRING }, + { 'i', index_param, "", G_TYPE_ASCNUM }, + { 'l', "label", "", G_TYPE_STRING }, { 'f', "flags", flags, G_TYPE_STRING }, G_OPT_SENTINEL }, "geom", NULL }, { "bootcode", 0, gpart_bootcode, { - { 'b', bootcode_param, optional, G_TYPE_STRING }, - { 'p', partcode_param, optional, G_TYPE_STRING }, - { 'i', index_param, optional, G_TYPE_ASCNUM }, + { 'b', bootcode_param, "", G_TYPE_STRING }, + { 'p', partcode_param, "", G_TYPE_STRING }, + { 'i', index_param, "", G_TYPE_ASCNUM }, { 'f', "flags", flags, G_TYPE_STRING }, G_OPT_SENTINEL }, "geom", NULL @@ -108,7 +107,7 @@ struct g_command PUBSYM(class_commands)[] = { { "commit", 0, gpart_issue, G_NULL_OPTS, "geom", NULL }, { "create", 0, gpart_issue, { { 's', "scheme", NULL, G_TYPE_STRING }, - { 'n', "entries", optional, G_TYPE_ASCNUM }, + { 'n', "entries", "", G_TYPE_ASCNUM }, { 'f', "flags", flags, G_TYPE_STRING }, G_OPT_SENTINEL }, "provider", NULL @@ -125,8 +124,8 @@ struct g_command PUBSYM(class_commands)[] = { "geom", NULL }, { "modify", 0, gpart_issue, { { 'i', index_param, NULL, G_TYPE_ASCNUM }, - { 'l', "label", optional, G_TYPE_STRING }, - { 't', "type", optional, G_TYPE_STRING }, + { 'l', "label", "", G_TYPE_STRING }, + { 't', "type", "", G_TYPE_STRING }, { 'f', "flags", flags, G_TYPE_STRING }, G_OPT_SENTINEL }, "geom", NULL diff --git a/sbin/geom/class/sched/geom_sched.c b/sbin/geom/class/sched/geom_sched.c index ca05350..eba8e49 100644 --- a/sbin/geom/class/sched/geom_sched.c +++ b/sbin/geom/class/sched/geom_sched.c @@ -54,7 +54,7 @@ uint32_t version = G_SCHED_VERSION; * storage for parameters used by this geom class. * Right now only the scheduler name is used. */ -static char algo[] = "rr"; /* default scheduler */ +#define GSCHED_ALGO "rr" /* default scheduler */ /* * Adapt to differences in geom library. @@ -76,7 +76,7 @@ gcmd_createinsert(struct gctl_req *req, unsigned flags __unused) if (gctl_has_param(req, "algo")) reqalgo = gctl_get_ascii(req, "algo"); else - reqalgo = algo; + reqalgo = GSCHED_ALGO; snprintf(name, sizeof(name), "gsched_%s", reqalgo); /* @@ -91,21 +91,21 @@ gcmd_createinsert(struct gctl_req *req, unsigned flags __unused) struct g_command class_commands[] = { { "create", G_FLAG_VERBOSE | G_FLAG_LOADKLD, gcmd_createinsert, { - { 'a', "algo", algo, G_TYPE_STRING }, + { 'a', "algo", GSCHED_ALGO, G_TYPE_STRING }, G_OPT_SENTINEL }, G_ARGNAME "[-v] [-a algorithm_name] dev ..." }, { "insert", G_FLAG_VERBOSE | G_FLAG_LOADKLD, gcmd_createinsert, { - { 'a', "algo", algo, G_TYPE_STRING }, + { 'a', "algo", GSCHED_ALGO, G_TYPE_STRING }, G_OPT_SENTINEL }, G_ARGNAME "[-v] [-a algorithm_name] dev ..." }, { "configure", G_FLAG_VERBOSE, NULL, { - { 'a', "algo", algo, G_TYPE_STRING }, + { 'a', "algo", GSCHED_ALGO, G_TYPE_STRING }, G_OPT_SENTINEL }, G_ARGNAME "[-v] [-a algorithm_name] prov ..." diff --git a/sbin/geom/core/geom.c b/sbin/geom/core/geom.c index f673aad..b891098 100644 --- a/sbin/geom/core/geom.c +++ b/sbin/geom/core/geom.c @@ -236,8 +236,8 @@ find_option(struct g_command *cmd, char ch) static void set_option(struct gctl_req *req, struct g_option *opt, const char *val) { - char *s; uint64_t number; + void *ptr; if (G_OPT_TYPE(opt) == G_TYPE_NUMBER || G_OPT_TYPE(opt) == G_TYPE_ASCNUM) { @@ -245,27 +245,29 @@ set_option(struct gctl_req *req, struct g_option *opt, const char *val) err(EXIT_FAILURE, "Invalid value for '%c' argument.", opt->go_char); } - if (G_OPT_TYPE(opt) == G_TYPE_NUMBER) - opt->go_val = malloc(sizeof(intmax_t)); - else { - asprintf(&s, "%jd", number); - opt->go_val = s; - } - if (opt->go_val == NULL) - errx(EXIT_FAILURE, "No memory."); if (G_OPT_TYPE(opt) == G_TYPE_NUMBER) { - *(intmax_t *)opt->go_val = number; + ptr = malloc(sizeof(intmax_t)); + if (ptr == NULL) + errx(EXIT_FAILURE, "No memory."); + *(intmax_t *)ptr = number; + opt->go_val = ptr; gctl_ro_param(req, opt->go_name, sizeof(intmax_t), opt->go_val); - } else + } else { + asprintf((void *)(&ptr), "%jd", number); + if (ptr == NULL) + errx(EXIT_FAILURE, "No memory."); + opt->go_val = ptr; gctl_ro_param(req, opt->go_name, -1, opt->go_val); + } } else if (G_OPT_TYPE(opt) == G_TYPE_STRING) { gctl_ro_param(req, opt->go_name, -1, val); } else if (G_OPT_TYPE(opt) == G_TYPE_BOOL) { - opt->go_val = malloc(sizeof(int)); - if (opt->go_val == NULL) + ptr = malloc(sizeof(int)); + if (ptr == NULL) errx(EXIT_FAILURE, "No memory."); - *(int *)opt->go_val = *val - '0'; + *(int *)ptr = *val - '0'; + opt->go_val = ptr; gctl_ro_param(req, opt->go_name, sizeof(int), opt->go_val); } else { assert(!"Invalid type"); @@ -354,7 +356,7 @@ parse_arguments(struct g_command *cmd, struct gctl_req *req, int *argc, G_OPT_TYPE(opt) == G_TYPE_ASCNUM) { if (cmd->gc_argname == NULL || opt->go_val == NULL || - *(char *)opt->go_val != '\0') + *(const char *)opt->go_val != '\0') gctl_ro_param(req, opt->go_name, -1, opt->go_val); } else { diff --git a/sbin/geom/core/geom.h b/sbin/geom/core/geom.h index 424695b..e2f96e9 100644 --- a/sbin/geom/core/geom.h +++ b/sbin/geom/core/geom.h @@ -54,7 +54,7 @@ struct g_option { char go_char; const char *go_name; - void *go_val; + const void *go_val; unsigned go_type; }; |