Changeset View
Changeset View
Standalone View
Standalone View
stand/userboot/userboot/main.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 <setjmp.h> | #include <setjmp.h> | ||||
#include <sys/disk.h> | #include <sys/disk.h> | ||||
#include <sys/zfs_bootenv.h> | |||||
#include "bootstrap.h" | #include "bootstrap.h" | ||||
#include "disk.h" | #include "disk.h" | ||||
#include "libuserboot.h" | #include "libuserboot.h" | ||||
#if defined(USERBOOT_ZFS_SUPPORT) | #if defined(USERBOOT_ZFS_SUPPORT) | ||||
#include "libzfs.h" | #include "libzfs.h" | ||||
▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | #endif | ||||
if (setjmp(jb)) | if (setjmp(jb)) | ||||
return; | return; | ||||
interact(); /* doesn't return */ | interact(); /* doesn't return */ | ||||
exit(0); | exit(0); | ||||
} | } | ||||
static void | |||||
set_currdev(const char *devname) | |||||
{ | |||||
env_setenv("currdev", EV_VOLATILE, devname, | |||||
userboot_setcurrdev, env_nounset); | |||||
env_setenv("loaddev", EV_VOLATILE, devname, | |||||
env_noset, env_nounset); | |||||
} | |||||
/* | /* | ||||
* Set the 'current device' by (if possible) recovering the boot device as | * Set the 'current device' by (if possible) recovering the boot device as | ||||
* supplied by the initial bootstrap. | * supplied by the initial bootstrap. | ||||
*/ | */ | ||||
static void | static void | ||||
extract_currdev(void) | extract_currdev(void) | ||||
{ | { | ||||
struct disk_devdesc dev; | struct disk_devdesc dev; | ||||
struct devdesc *dd; | struct devdesc *dd; | ||||
#if defined(USERBOOT_ZFS_SUPPORT) | #if defined(USERBOOT_ZFS_SUPPORT) | ||||
struct zfs_devdesc zdev; | struct zfs_devdesc zdev; | ||||
char *buf = NULL; | |||||
if (userboot_zfs_found) { | if (userboot_zfs_found) { | ||||
/* Leave the pool/root guid's unassigned */ | /* Leave the pool/root guid's unassigned */ | ||||
bzero(&zdev, sizeof(zdev)); | bzero(&zdev, sizeof(zdev)); | ||||
zdev.dd.d_dev = &zfs_dev; | zdev.dd.d_dev = &zfs_dev; | ||||
init_zfs_boot_options(zfs_fmtdev(&zdev)); | init_zfs_boot_options(zfs_fmtdev(&zdev)); | ||||
Show All 16 Lines | if (userboot_disk_maxunit > 0) { | ||||
} | } | ||||
dd = &dev.dd; | dd = &dev.dd; | ||||
} else { | } else { | ||||
dev.dd.d_dev = &host_dev; | dev.dd.d_dev = &host_dev; | ||||
dev.dd.d_unit = 0; | dev.dd.d_unit = 0; | ||||
dd = &dev.dd; | dd = &dev.dd; | ||||
} | } | ||||
env_setenv("currdev", EV_VOLATILE, userboot_fmtdev(dd), | set_currdev(userboot_fmtdev(dd)); | ||||
userboot_setcurrdev, env_nounset); | |||||
env_setenv("loaddev", EV_VOLATILE, userboot_fmtdev(dd), | #if defined(USERBOOT_ZFS_SUPPORT) | ||||
env_noset, env_nounset); | if (userboot_zfs_found) { | ||||
buf = malloc(VDEV_PAD_SIZE); | |||||
if (buf != NULL) { | |||||
if (zfs_get_bootonce(&zdev, OS_BOOTONCE, buf, | |||||
VDEV_PAD_SIZE) == 0) { | |||||
printf("zfs bootonce: %s\n", buf); | |||||
set_currdev(buf); | |||||
setenv("zfs-bootonce", buf, 1); | |||||
} | |||||
free(buf); | |||||
(void) zfs_attach_nvstore(&zdev); | |||||
} | |||||
} | |||||
#endif | |||||
} | } | ||||
#if defined(USERBOOT_ZFS_SUPPORT) | #if defined(USERBOOT_ZFS_SUPPORT) | ||||
static void | static void | ||||
userboot_zfs_probe(void) | userboot_zfs_probe(void) | ||||
{ | { | ||||
char devname[32]; | char devname[32]; | ||||
uint64_t pool_guid; | uint64_t pool_guid; | ||||
Show All 35 Lines |