Changeset View
Changeset View
Standalone View
Standalone View
sys/geom/geom_dev.c
Context not available. | |||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include "opt_compat.h" | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
Context not available. | |||||
} | } | ||||
static int | static int | ||||
g_dev_setdumpdev(struct cdev *dev, struct thread *td) | g_dev_setdumpdev(struct cdev *dev, struct diocskerneldump_arg *kda, | ||||
struct thread *td) | |||||
{ | { | ||||
struct g_kerneldump kd; | struct g_kerneldump kd; | ||||
struct g_consumer *cp; | struct g_consumer *cp; | ||||
int error, len; | int error, len; | ||||
if (dev == NULL) | if (dev == NULL || kda == NULL) | ||||
return (set_dumper(NULL, NULL, td)); | return (set_dumper(NULL, NULL, td, 0, NULL, 0, NULL)); | ||||
cp = dev->si_drv2; | cp = dev->si_drv2; | ||||
len = sizeof(kd); | len = sizeof(kd); | ||||
kd.offset = 0; | kd.offset = 0; | ||||
kd.length = OFF_MAX; | kd.length = OFF_MAX; | ||||
error = g_io_getattr("GEOM::kerneldump", cp, &len, &kd); | error = g_io_getattr("GEOM::kerneldump", cp, &len, &kd); | ||||
if (error == 0) { | if (error != 0) | ||||
error = set_dumper(&kd.di, devtoname(dev), td); | return (error); | ||||
if (error == 0) | |||||
dev->si_flags |= SI_DUMPDEV; | error = set_dumper(&kd.di, devtoname(dev), td, kda->kda_encryption, | ||||
} | kda->kda_key, kda->kda_encryptedkeysize, kda->kda_encryptedkey); | ||||
if (error == 0) | |||||
dev->si_flags |= SI_DUMPDEV; | |||||
return (error); | return (error); | ||||
} | } | ||||
static int | static int | ||||
init_dumpdev(struct cdev *dev) | init_dumpdev(struct cdev *dev) | ||||
{ | { | ||||
struct diocskerneldump_arg kda; | |||||
struct g_consumer *cp; | struct g_consumer *cp; | ||||
const char *devprefix = "/dev/", *devname; | const char *devprefix = "/dev/", *devname; | ||||
int error; | int error; | ||||
size_t len; | size_t len; | ||||
bzero(&kda, sizeof(kda)); | |||||
kda.kda_enable = 1; | |||||
if (dumpdev == NULL) | if (dumpdev == NULL) | ||||
return (0); | return (0); | ||||
Context not available. | |||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
error = g_dev_setdumpdev(dev, curthread); | error = g_dev_setdumpdev(dev, &kda, curthread); | ||||
if (error == 0) { | if (error == 0) { | ||||
freeenv(dumpdev); | freeenv(dumpdev); | ||||
dumpdev = NULL; | dumpdev = NULL; | ||||
Context not available. | |||||
case DIOCGFRONTSTUFF: | case DIOCGFRONTSTUFF: | ||||
error = g_io_getattr("GEOM::frontstuff", cp, &i, data); | error = g_io_getattr("GEOM::frontstuff", cp, &i, data); | ||||
break; | break; | ||||
case DIOCSKERNELDUMP: | #ifdef COMPAT_FREEBSD10 | ||||
if (*(u_int *)data == 0) | case DIOCSKERNELDUMP_FREEBSD10: | ||||
jhb: I know that we use 'OLD' suffixes for other ioctls, but it might be better practice going… | |||||
Done Inline ActionsAre there existing examples of _<version> suffix for old ioctls? If not, I'd suggest _FREEBSD<version> suffix. It is more consistent with COMPAT_FREEBSD10 and more obvious than just _10. pjd: Are there existing examples of _<version> suffix for old ioctls? If not, I'd suggest… | |||||
Done Inline ActionsNo. I found a mixture of FOO_OLD, OLD_FOO, and one OFOO in some simple greps. I think _FREEBSD10 is fine. jhb: No. I found a mixture of FOO_OLD, OLD_FOO, and one OFOO in some simple greps. I think… | |||||
error = g_dev_setdumpdev(NULL, td); | { | ||||
struct diocskerneldump_arg kda; | |||||
bzero(&kda, sizeof(kda)); | |||||
kda.kda_encryption = KERNELDUMP_ENC_NONE; | |||||
kda.kda_enable = (uint8_t)*(u_int *)data; | |||||
if (kda.kda_enable == 0) | |||||
error = g_dev_setdumpdev(NULL, NULL, td); | |||||
else | else | ||||
error = g_dev_setdumpdev(dev, td); | error = g_dev_setdumpdev(dev, &kda, td); | ||||
break; | |||||
} | |||||
#endif | |||||
case DIOCSKERNELDUMP: | |||||
{ | |||||
struct diocskerneldump_arg *kda; | |||||
uint8_t *encryptedkey; | |||||
kda = (struct diocskerneldump_arg *)data; | |||||
if (kda->kda_enable == 0) { | |||||
error = g_dev_setdumpdev(NULL, NULL, td); | |||||
break; | |||||
} | |||||
if (kda->kda_encryption != KERNELDUMP_ENC_NONE) { | |||||
if (kda->kda_encryptedkeysize <= 0 || | |||||
kda->kda_encryptedkeysize > | |||||
KERNELDUMP_ENCKEY_MAX_SIZE) { | |||||
return (EINVAL); | |||||
} | |||||
encryptedkey = malloc(kda->kda_encryptedkeysize, M_TEMP, | |||||
M_WAITOK); | |||||
error = copyin(kda->kda_encryptedkey, encryptedkey, | |||||
kda->kda_encryptedkeysize); | |||||
} else { | |||||
encryptedkey = NULL; | |||||
} | |||||
if (error == 0) { | |||||
kda->kda_encryptedkey = encryptedkey; | |||||
error = g_dev_setdumpdev(dev, kda, td); | |||||
} | |||||
if (encryptedkey != NULL) { | |||||
explicit_bzero(encryptedkey, kda->kda_encryptedkeysize); | |||||
free(encryptedkey, M_TEMP); | |||||
} | |||||
explicit_bzero(kda, sizeof(*kda)); | |||||
break; | break; | ||||
} | |||||
case DIOCGFLUSH: | case DIOCGFLUSH: | ||||
error = g_io_flush(cp); | error = g_io_flush(cp); | ||||
break; | break; | ||||
Context not available. | |||||
/* Reset any dump-area set on this device */ | /* Reset any dump-area set on this device */ | ||||
if (dev->si_flags & SI_DUMPDEV) | if (dev->si_flags & SI_DUMPDEV) | ||||
(void)set_dumper(NULL, NULL, curthread); | (void)set_dumper(NULL, NULL, curthread, 0, NULL, 0, NULL); | ||||
/* Destroy the struct cdev *so we get no more requests */ | /* Destroy the struct cdev *so we get no more requests */ | ||||
destroy_dev_sched_cb(dev, g_dev_callback, cp); | destroy_dev_sched_cb(dev, g_dev_callback, cp); | ||||
Context not available. |
I know that we use 'OLD' suffixes for other ioctls, but it might be better practice going forward to use a '_10' suffix instead to match COMPAT_FREEBSD10. This removes the need for "OLDOLD" if we change the structure in the future.