Changeset View
Changeset View
Standalone View
Standalone View
head/stand/common/devopen.c
Show All 26 Lines | |||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <stand.h> | #include <stand.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "bootstrap.h" | #include "bootstrap.h" | ||||
#ifdef LOADER_GELI_SUPPORT | |||||
#include "geliboot.h" | |||||
#endif | |||||
int | int | ||||
devopen(struct open_file *f, const char *fname, const char **file) | devopen(struct open_file *f, const char *fname, const char **file) | ||||
{ | { | ||||
struct devdesc *dev; | struct devdesc *dev; | ||||
int result; | int result; | ||||
result = archsw.arch_getdev((void **)&dev, fname, file); | result = archsw.arch_getdev((void **)&dev, fname, file); | ||||
if (result) | if (result) | ||||
return (result); | return (result); | ||||
/* point to device-specific data so that device open can use it */ | /* point to device-specific data so that device open can use it */ | ||||
f->f_dev = dev->d_dev; | |||||
f->f_devdata = dev; | f->f_devdata = dev; | ||||
result = dev->d_dev->dv_open(f, dev); | result = dev->d_dev->dv_open(f, dev); | ||||
if (result != 0) { | if (result != 0) { | ||||
f->f_devdata = NULL; | f->f_devdata = NULL; | ||||
free(dev); | free(dev); | ||||
return (result); | return (result); | ||||
} | } | ||||
/* reference the devsw entry from the open_file structure */ | #ifdef LOADER_GELI_SUPPORT | ||||
f->f_dev = dev->d_dev; | /* | ||||
* If f->f_dev is geli-encrypted and we can decrypt it (will prompt for | |||||
* pw if needed), this will attach the geli code to the open_file by | |||||
* replacing f->f_dev and f_devdata with pointers to a geli_devdesc. | |||||
*/ | |||||
if (f->f_dev->dv_type == DEVT_DISK) { | |||||
geli_probe_and_attach(f); | |||||
} | |||||
#endif | |||||
return (0); | return (0); | ||||
} | } | ||||
int | int | ||||
devclose(struct open_file *f) | devclose(struct open_file *f) | ||||
{ | { | ||||
if (f->f_devdata != NULL) { | if (f->f_devdata != NULL) { | ||||
free(f->f_devdata); | free(f->f_devdata); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } |