Changeset View
Changeset View
Standalone View
Standalone View
stand/common/devopen.c
Show All 23 Lines | |||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#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 <stdbool.h> | |||||
#include "bootstrap.h" | #include "bootstrap.h" | ||||
#include "disk.h" | |||||
#ifdef LOADER_GELI_SUPPORT | #ifdef LOADER_GELI_SUPPORT | ||||
#include "geliboot.h" | #include "geliboot.h" | ||||
#endif | #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; | ||||
bool is_open = false; | |||||
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_dev = dev->d_dev; | ||||
f->f_devdata = dev; | f->f_devdata = dev; | ||||
/* | |||||
* Traditinally the open of FREEBSD MBR slice means that we will | |||||
* open the first BSD slice, if that does fail, only then we will | |||||
* open the MBR slice. | |||||
* To provide backwards compatibility, we need to check if there is | |||||
* slice specified in device name, and if so, we will add partition | |||||
* name 'a' and will try to open this updated name first. | |||||
*/ | |||||
if (dev->d_dev->dv_type == DEVT_DISK) { | |||||
struct disk_devdesc *tdev; | |||||
tdev = (struct disk_devdesc *)dev; | |||||
if (tdev->d_partition == -1) { | |||||
tdev->d_partition = 0; | |||||
result = dev->d_dev->dv_open(f, dev); | result = dev->d_dev->dv_open(f, dev); | ||||
if (result != 0) { | if (result != 0) { | ||||
tdev->d_partition = -1; | |||||
} else { | |||||
is_open = true; | |||||
} | |||||
} | |||||
} | |||||
if (is_open == false) { | |||||
result = dev->d_dev->dv_open(f, dev); | |||||
if (result != 0) { | |||||
f->f_devdata = NULL; | f->f_devdata = NULL; | ||||
free(dev); | free(dev); | ||||
return (result); | return (result); | ||||
} | |||||
} | } | ||||
#ifdef LOADER_GELI_SUPPORT | #ifdef LOADER_GELI_SUPPORT | ||||
/* | /* | ||||
* If f->f_dev is geli-encrypted and we can decrypt it (will prompt for | * 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 | * 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. | * replacing f->f_dev and f_devdata with pointers to a geli_devdesc. | ||||
*/ | */ | ||||
Show All 17 Lines |