Changeset View
Changeset View
Standalone View
Standalone View
head/sys/geom/eli/g_eli_ctl.c
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
g_eli_ctl_attach(struct gctl_req *req, struct g_class *mp) | g_eli_ctl_attach(struct gctl_req *req, struct g_class *mp) | ||||
{ | { | ||||
struct g_eli_metadata md; | struct g_eli_metadata md; | ||||
struct g_provider *pp; | struct g_provider *pp; | ||||
const char *name; | const char *name; | ||||
u_char *key, mkey[G_ELI_DATAIVKEYLEN]; | u_char *key, mkey[G_ELI_DATAIVKEYLEN]; | ||||
int *nargs, *detach, *readonly, *dryrun; | int *nargs, *detach, *readonly, *dryrunp; | ||||
int keysize, error, nkey; | int keysize, error, nkey, dryrun, dummy; | ||||
intmax_t *valp; | intmax_t *valp; | ||||
g_topology_assert(); | g_topology_assert(); | ||||
nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); | nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); | ||||
if (nargs == NULL) { | if (nargs == NULL) { | ||||
gctl_error(req, "No '%s' argument.", "nargs"); | gctl_error(req, "No '%s' argument.", "nargs"); | ||||
return; | return; | ||||
} | } | ||||
if (*nargs != 1) { | if (*nargs != 1) { | ||||
gctl_error(req, "Invalid number of arguments."); | gctl_error(req, "Invalid number of arguments."); | ||||
return; | return; | ||||
} | } | ||||
detach = gctl_get_paraml(req, "detach", sizeof(*detach)); | detach = gctl_get_paraml(req, "detach", sizeof(*detach)); | ||||
if (detach == NULL) { | if (detach == NULL) { | ||||
gctl_error(req, "No '%s' argument.", "detach"); | gctl_error(req, "No '%s' argument.", "detach"); | ||||
return; | return; | ||||
} | } | ||||
/* "keyno" is optional for backward compatibility */ | |||||
nkey = -1; | |||||
valp = gctl_get_param(req, "keyno", &dummy); | |||||
if (valp != NULL) { | |||||
valp = gctl_get_paraml(req, "keyno", sizeof(*valp)); | valp = gctl_get_paraml(req, "keyno", sizeof(*valp)); | ||||
if (valp == NULL) { | if (valp != NULL) | ||||
gctl_error(req, "No '%s' argument.", "keyno"); | |||||
return; | |||||
} | |||||
nkey = *valp; | nkey = *valp; | ||||
} | |||||
if (nkey < -1 || nkey >= G_ELI_MAXMKEYS) { | if (nkey < -1 || nkey >= G_ELI_MAXMKEYS) { | ||||
gctl_error(req, "Invalid '%s' argument.", "keyno"); | gctl_error(req, "Invalid '%s' argument.", "keyno"); | ||||
return; | return; | ||||
} | } | ||||
readonly = gctl_get_paraml(req, "readonly", sizeof(*readonly)); | readonly = gctl_get_paraml(req, "readonly", sizeof(*readonly)); | ||||
if (readonly == NULL) { | if (readonly == NULL) { | ||||
gctl_error(req, "No '%s' argument.", "readonly"); | gctl_error(req, "No '%s' argument.", "readonly"); | ||||
return; | return; | ||||
} | } | ||||
dryrun = gctl_get_paraml(req, "dryrun", sizeof(*dryrun)); | /* "dryrun" is optional for backward compatibility */ | ||||
if (dryrun == NULL) { | dryrun = 0; | ||||
gctl_error(req, "No '%s' argument.", "dryrun"); | dryrunp = gctl_get_param(req, "dryrun", &dummy); | ||||
return; | if (dryrunp != NULL) { | ||||
dryrunp = gctl_get_paraml(req, "dryrun", sizeof(*dryrunp)); | |||||
if (dryrunp != NULL) | |||||
dryrun = *dryrunp; | |||||
} | } | ||||
if (*detach && *readonly) { | if (*detach && *readonly) { | ||||
gctl_error(req, "Options -d and -r are mutually exclusive."); | gctl_error(req, "Options -d and -r are mutually exclusive."); | ||||
return; | return; | ||||
} | } | ||||
name = gctl_get_asciiparam(req, "arg0"); | name = gctl_get_asciiparam(req, "arg0"); | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (error == -1) { | ||||
return; | return; | ||||
} | } | ||||
G_ELI_DEBUG(1, "Using Master Key %u for %s.", nkey, pp->name); | G_ELI_DEBUG(1, "Using Master Key %u for %s.", nkey, pp->name); | ||||
if (*detach) | if (*detach) | ||||
md.md_flags |= G_ELI_FLAG_WO_DETACH; | md.md_flags |= G_ELI_FLAG_WO_DETACH; | ||||
if (*readonly) | if (*readonly) | ||||
md.md_flags |= G_ELI_FLAG_RO; | md.md_flags |= G_ELI_FLAG_RO; | ||||
if (!*dryrun) | if (!dryrun) | ||||
g_eli_create(req, mp, pp, &md, mkey, nkey); | g_eli_create(req, mp, pp, &md, mkey, nkey); | ||||
explicit_bzero(mkey, sizeof(mkey)); | explicit_bzero(mkey, sizeof(mkey)); | ||||
explicit_bzero(&md, sizeof(md)); | explicit_bzero(&md, sizeof(md)); | ||||
} | } | ||||
static struct g_eli_softc * | static struct g_eli_softc * | ||||
g_eli_find_device(struct g_class *mp, const char *prov) | g_eli_find_device(struct g_class *mp, const char *prov) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 1,014 Lines • Show Last 20 Lines |