Changeset View
Changeset View
Standalone View
Standalone View
sys/boot/efi/loader/devicename.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 <sys/disklabel.h> | #include <sys/disklabel.h> | ||||
#include "bootstrap.h" | #include "bootstrap.h" | ||||
#include "libzfs.h" | |||||
#include <efi.h> | #include <efi.h> | ||||
#include <efilib.h> | #include <efilib.h> | ||||
static int efi_parsedev(struct devdesc **, const char *, const char **); | static int efi_parsedev(struct devdesc **, const char *, const char **); | ||||
/* | /* | ||||
* Point (dev) at an allocated device specifier for the device matching the | * Point (dev) at an allocated device specifier for the device matching the | ||||
* path in (devspec). If it contains an explicit device specification, | * path in (devspec). If it contains an explicit device specification, | ||||
* use that. If not, use the default device. | * use that. If not, use the default device. | ||||
*/ | */ | ||||
int | int | ||||
efi_getdev(void **vdev, const char *devspec, const char **path) | efi_getdev(void **vdev, const char *devspec, const char **path) | ||||
{ | { | ||||
struct devdesc **dev = (struct devdesc **)vdev; | struct devdesc **dev = (struct devdesc **)vdev; | ||||
int rv; | int rv; | ||||
/* | /* | ||||
* If it looks like this is just a path and no device, then | * If it looks like this is just a path and no device, then | ||||
* use the current device instead. | * use the current device instead. | ||||
*/ | */ | ||||
if (devspec == NULL || *devspec == '/' || !strchr(devspec, ':')) { | if (devspec == NULL || *devspec == '/' || !strchr(devspec, ':')) { | ||||
rv = efi_parsedev(dev, getenv("currdev"), NULL); | rv = efi_parsedev(dev, getenv("currdev"), NULL); | ||||
if (rv == 0 && path != NULL) | if (rv == 0 && path != NULL) | ||||
*path = devspec; | *path = devspec; | ||||
return (rv); | return (rv); | ||||
} | } | ||||
/* Parse the device name off the beginning of the devspec. */ | /* Parse the device name off the beginning of the devspec. */ | ||||
return (efi_parsedev(dev, devspec, path)); | const int out = efi_parsedev(dev, devspec, path); | ||||
return out; | |||||
delphij: Please revert this change because it's a no-op. | |||||
} | } | ||||
/* | /* | ||||
* Point (dev) at an allocated device specifier matching the string version | * Point (dev) at an allocated device specifier matching the string version | ||||
* at the beginning of (devspec). Return a pointer to the remaining | * at the beginning of (devspec). Return a pointer to the remaining | ||||
* text in (path). | * text in (path). | ||||
* | * | ||||
* In all cases, the beginning of (devspec) is compared to the names | * In all cases, the beginning of (devspec) is compared to the names | ||||
Show All 9 Lines | |||||
{ | { | ||||
struct devdesc *idev; | struct devdesc *idev; | ||||
struct devsw *dv; | struct devsw *dv; | ||||
char *cp; | char *cp; | ||||
const char *np; | const char *np; | ||||
int i, err; | int i, err; | ||||
/* minimum length check */ | /* minimum length check */ | ||||
if (strlen(devspec) < 2) | if (strlen(devspec) < 2) { | ||||
delphijUnsubmitted Done Inline ActionsPlease revert this portion of change as it's not necessary. delphij: Please revert this portion of change as it's not necessary. | |||||
return (EINVAL); | return (EINVAL); | ||||
} | |||||
delphijUnsubmitted Done Inline Actionsand this. delphij: and this. | |||||
/* look for a device that matches */ | /* look for a device that matches */ | ||||
for (i = 0; devsw[i] != NULL; i++) { | for (i = 0; devsw[i] != NULL; i++) { | ||||
dv = devsw[i]; | dv = devsw[i]; | ||||
if (!strncmp(devspec, dv->dv_name, strlen(dv->dv_name))) | if (!strncmp(devspec, dv->dv_name, strlen(dv->dv_name))) | ||||
break; | break; | ||||
} | } | ||||
if (devsw[i] == NULL) | if (devsw[i] == NULL) { | ||||
delphijUnsubmitted Done Inline ActionsDitto. delphij: Ditto. | |||||
return (ENOENT); | return (ENOENT); | ||||
} | |||||
delphijUnsubmitted Done Inline ActionsDitto. delphij: Ditto. | |||||
np = devspec + strlen(dv->dv_name); | |||||
if (DEVT_ZFS == dv->dv_type) { | |||||
Not Done Inline ActionsDon't put constant as lval, it's not buying us anything and compiler should catch this. delphij: Don't put constant as lval, it's not buying us anything and compiler should catch this. | |||||
idev = malloc(sizeof(struct zfs_devdesc)); | |||||
int out = zfs_parsedev((struct zfs_devdesc*)idev, np, path); | |||||
Not Done Inline ActionsTest of malloc result is needed because it could be NULL. delphij: Test of malloc result is needed because it could be NULL. | |||||
if (0 == out) { | |||||
*dev = idev; | |||||
cp = strchr(np + 1, ':'); | |||||
} else { | |||||
free(idev); | |||||
return out; | |||||
} | |||||
} else { | |||||
idev = malloc(sizeof(struct devdesc)); | idev = malloc(sizeof(struct devdesc)); | ||||
if (idev == NULL) | if (idev == NULL) | ||||
return (ENOMEM); | return (ENOMEM); | ||||
idev->d_dev = dv; | idev->d_dev = dv; | ||||
idev->d_type = dv->dv_type; | idev->d_type = dv->dv_type; | ||||
idev->d_unit = -1; | idev->d_unit = -1; | ||||
err = 0; | |||||
np = devspec + strlen(dv->dv_name); | |||||
if (*np != '\0' && *np != ':') { | if (*np != '\0' && *np != ':') { | ||||
idev->d_unit = strtol(np, &cp, 0); | idev->d_unit = strtol(np, &cp, 0); | ||||
if (cp == np) { | if (cp == np) { | ||||
idev->d_unit = -1; | idev->d_unit = -1; | ||||
free(idev); | free(idev); | ||||
return (EUNIT); | return (EUNIT); | ||||
} | } | ||||
} | } | ||||
} | |||||
err = 0; | |||||
if (*cp != '\0' && *cp != ':') { | if (*cp != '\0' && *cp != ':') { | ||||
free(idev); | free(idev); | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
if (path != NULL) | if (path != NULL) | ||||
*path = (*cp == 0) ? cp : cp + 1; | *path = (*cp == 0) ? cp : cp + 1; | ||||
if (dev != NULL) | if (dev != NULL) | ||||
*dev = idev; | *dev = idev; | ||||
else | else | ||||
free(idev); | free(idev); | ||||
return (0); | return (0); | ||||
} | } | ||||
char * | char * | ||||
efi_fmtdev(void *vdev) | efi_fmtdev(void *vdev) | ||||
{ | { | ||||
struct devdesc *dev = (struct devdesc *)vdev; | struct devdesc *dev = (struct devdesc *)vdev; | ||||
static char buf[32]; /* XXX device length constant? */ | static char buf[32]; /* XXX device length constant? */ | ||||
switch(dev->d_type) { | switch(dev->d_type) { | ||||
case DEVT_ZFS: | |||||
return zfs_fmtdev(dev); | |||||
case DEVT_NONE: | case DEVT_NONE: | ||||
strcpy(buf, "(no device)"); | strcpy(buf, "(no device)"); | ||||
break; | break; | ||||
default: | default: | ||||
sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit); | sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit); | ||||
break; | break; | ||||
} | } | ||||
return(buf); | return(buf); | ||||
} | } | ||||
Show All 17 Lines |
Please revert this change because it's a no-op.