Changeset View
Changeset View
Standalone View
Standalone View
sys/cam/ctl/ctl_backend.c
Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | if (strcmp(be_tmp->name, backend_name) == 0) { | ||||
return (be_tmp); | return (be_tmp); | ||||
} | } | ||||
} | } | ||||
mtx_unlock(&softc->ctl_lock); | mtx_unlock(&softc->ctl_lock); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
void | |||||
ctl_init_opts(ctl_options_t *opts, int num_args, struct ctl_be_arg *args) | |||||
{ | |||||
struct ctl_option *opt; | |||||
int i; | |||||
STAILQ_INIT(opts); | |||||
for (i = 0; i < num_args; i++) { | |||||
if ((args[i].flags & CTL_BEARG_RD) == 0) | |||||
continue; | |||||
if ((args[i].flags & CTL_BEARG_ASCII) == 0) | |||||
continue; | |||||
opt = malloc(sizeof(*opt), M_CTL, M_WAITOK); | |||||
opt->name = strdup(args[i].kname, M_CTL); | |||||
opt->value = strdup(args[i].kvalue, M_CTL); | |||||
STAILQ_INSERT_TAIL(opts, opt, links); | |||||
} | |||||
} | |||||
void | |||||
ctl_update_opts(ctl_options_t *opts, int num_args, struct ctl_be_arg *args) | |||||
{ | |||||
struct ctl_option *opt; | |||||
int i; | |||||
for (i = 0; i < num_args; i++) { | |||||
if ((args[i].flags & CTL_BEARG_RD) == 0) | |||||
continue; | |||||
if ((args[i].flags & CTL_BEARG_ASCII) == 0) | |||||
continue; | |||||
STAILQ_FOREACH(opt, opts, links) { | |||||
if (strcmp(opt->name, args[i].kname) == 0) | |||||
break; | |||||
} | |||||
if (args[i].kvalue != NULL && | |||||
((char *)args[i].kvalue)[0] != 0) { | |||||
if (opt) { | |||||
free(opt->value, M_CTL); | |||||
opt->value = strdup(args[i].kvalue, M_CTL); | |||||
} else { | |||||
opt = malloc(sizeof(*opt), M_CTL, M_WAITOK); | |||||
opt->name = strdup(args[i].kname, M_CTL); | |||||
opt->value = strdup(args[i].kvalue, M_CTL); | |||||
STAILQ_INSERT_TAIL(opts, opt, links); | |||||
} | |||||
} else if (opt) { | |||||
STAILQ_REMOVE(opts, opt, ctl_option, links); | |||||
free(opt->name, M_CTL); | |||||
free(opt->value, M_CTL); | |||||
free(opt, M_CTL); | |||||
} | |||||
} | |||||
} | |||||
void | |||||
ctl_free_opts(ctl_options_t *opts) | |||||
{ | |||||
struct ctl_option *opt; | |||||
while ((opt = STAILQ_FIRST(opts)) != NULL) { | |||||
STAILQ_REMOVE_HEAD(opts, links); | |||||
free(opt->name, M_CTL); | |||||
free(opt->value, M_CTL); | |||||
free(opt, M_CTL); | |||||
} | |||||
} | |||||
char * | |||||
ctl_get_opt(ctl_options_t *opts, const char *name) | |||||
{ | |||||
struct ctl_option *opt; | |||||
STAILQ_FOREACH(opt, opts, links) { | |||||
if (strcmp(opt->name, name) == 0) { | |||||
return (opt->value); | |||||
} | |||||
} | |||||
return (NULL); | |||||
} | |||||
int | |||||
ctl_get_opt_number(ctl_options_t *opts, const char *name, uint64_t *val) | |||||
{ | |||||
const char *value; | |||||
value = ctl_get_opt(opts, name); | |||||
if (value == NULL) | |||||
return (-2); | |||||
return (ctl_expand_number(value, val)); | |||||
} |