Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libbe/be.c
Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | be_locate_rootfs(libbe_handle_t *lbh) | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Initializes the libbe context to operate in the root boot environment | * Initializes the libbe context to operate in the root boot environment | ||||
* dataset, for example, zroot/ROOT. | * dataset, for example, zroot/ROOT. | ||||
*/ | */ | ||||
libbe_handle_t * | libbe_handle_t * | ||||
libbe_init(void) | libbe_init(const char *root) | ||||
{ | { | ||||
libbe_handle_t *lbh; | libbe_handle_t *lbh; | ||||
char *poolname, *pos; | char *poolname, *pos; | ||||
int pnamelen; | int pnamelen; | ||||
lbh = NULL; | lbh = NULL; | ||||
poolname = pos = NULL; | poolname = pos = NULL; | ||||
if ((lbh = calloc(1, sizeof(libbe_handle_t))) == NULL) | if ((lbh = calloc(1, sizeof(libbe_handle_t))) == NULL) | ||||
goto err; | goto err; | ||||
if ((lbh->lzh = libzfs_init()) == NULL) | if ((lbh->lzh = libzfs_init()) == NULL) | ||||
goto err; | goto err; | ||||
/* Grab rootfs, we'll work backwards from there */ | /* | ||||
* Grab rootfs, we'll work backwards from there if an optional BE root | |||||
* has not been passed in. | |||||
*/ | |||||
if (be_locate_rootfs(lbh) != 0) | if (be_locate_rootfs(lbh) != 0) | ||||
goto err; | goto err; | ||||
if (root == NULL) { | |||||
/* Strip off the final slash from the rootfs to get the be root */ | /* Strip off the final slash from rootfs to get the be root */ | ||||
strlcpy(lbh->root, lbh->rootfs, sizeof(lbh->root)); | strlcpy(lbh->root, lbh->rootfs, sizeof(lbh->root)); | ||||
pos = strrchr(lbh->root, '/'); | pos = strrchr(lbh->root, '/'); | ||||
if (pos == NULL) | if (pos == NULL) | ||||
goto err; | goto err; | ||||
*pos = '\0'; | *pos = '\0'; | ||||
} else | |||||
strlcpy(lbh->root, root, sizeof(lbh->root)); | |||||
if ((pos = strchr(lbh->root, '/')) == NULL) | if ((pos = strchr(lbh->root, '/')) == NULL) | ||||
goto err; | goto err; | ||||
pnamelen = pos - lbh->root; | pnamelen = pos - lbh->root; | ||||
poolname = malloc(pnamelen + 1); | poolname = malloc(pnamelen + 1); | ||||
if (poolname == NULL) | if (poolname == NULL) | ||||
goto err; | goto err; | ||||
▲ Show 20 Lines • Show All 840 Lines • Show Last 20 Lines |