loader: cstyle cleanup of userboot/devicename.c
No functional changes intended. MFC after: 1 week
This commit is contained in:
parent
bed2ac27a1
commit
5d5a621664
@ -38,9 +38,10 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include "libzfs.h"
|
#include "libzfs.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int userboot_parsedev(struct disk_devdesc **dev, const char *devspec, const char **path);
|
static int userboot_parsedev(struct disk_devdesc **dev, const char *devspec,
|
||||||
|
const char **path);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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.
|
||||||
@ -48,27 +49,27 @@ static int userboot_parsedev(struct disk_devdesc **dev, const char *devspec, con
|
|||||||
int
|
int
|
||||||
userboot_getdev(void **vdev, const char *devspec, const char **path)
|
userboot_getdev(void **vdev, const char *devspec, const char **path)
|
||||||
{
|
{
|
||||||
struct disk_devdesc **dev = (struct disk_devdesc **)vdev;
|
struct disk_devdesc **dev = (struct disk_devdesc **)vdev;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
/*
|
|
||||||
* If it looks like this is just a path and no
|
|
||||||
* device, go with the current device.
|
|
||||||
*/
|
|
||||||
if ((devspec == NULL) ||
|
|
||||||
(devspec[0] == '/') ||
|
|
||||||
(strchr(devspec, ':') == NULL)) {
|
|
||||||
|
|
||||||
if (((rv = userboot_parsedev(dev, getenv("currdev"), NULL)) == 0) &&
|
/*
|
||||||
(path != NULL))
|
* If it looks like this is just a path and no
|
||||||
*path = devspec;
|
* device, go with the current device.
|
||||||
return(rv);
|
*/
|
||||||
}
|
if ((devspec == NULL) ||
|
||||||
|
(devspec[0] == '/') ||
|
||||||
/*
|
(strchr(devspec, ':') == NULL)) {
|
||||||
* Try to parse the device name off the beginning of the devspec
|
|
||||||
*/
|
rv = userboot_parsedev(dev, getenv("currdev"), NULL);
|
||||||
return(userboot_parsedev(dev, devspec, path));
|
if (rv == 0 && path != NULL)
|
||||||
|
*path = devspec;
|
||||||
|
return (rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try to parse the device name off the beginning of the devspec
|
||||||
|
*/
|
||||||
|
return (userboot_parsedev(dev, devspec, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -83,126 +84,129 @@ userboot_getdev(void **vdev, const char *devspec, const char **path)
|
|||||||
* For disk-type devices, the syntax is:
|
* For disk-type devices, the syntax is:
|
||||||
*
|
*
|
||||||
* disk<unit>[s<slice>][<partition>]:
|
* disk<unit>[s<slice>][<partition>]:
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
userboot_parsedev(struct disk_devdesc **dev, const char *devspec, const char **path)
|
userboot_parsedev(struct disk_devdesc **dev, const char *devspec,
|
||||||
|
const char **path)
|
||||||
{
|
{
|
||||||
struct disk_devdesc *idev;
|
struct disk_devdesc *idev;
|
||||||
struct devsw *dv;
|
struct devsw *dv;
|
||||||
int i, unit, err;
|
int i, unit, err;
|
||||||
const char *cp;
|
const char *cp;
|
||||||
const char *np;
|
const char *np;
|
||||||
|
|
||||||
/* minimum length check */
|
/* minimum length check */
|
||||||
if (strlen(devspec) < 2)
|
if (strlen(devspec) < 2)
|
||||||
return(EINVAL);
|
return (EINVAL);
|
||||||
|
|
||||||
/* look for a device that matches */
|
/* look for a device that matches */
|
||||||
for (i = 0, dv = NULL; devsw[i] != NULL; i++) {
|
for (i = 0, dv = NULL; devsw[i] != NULL; i++) {
|
||||||
if (!strncmp(devspec, devsw[i]->dv_name, strlen(devsw[i]->dv_name))) {
|
if (strncmp(devspec, devsw[i]->dv_name,
|
||||||
dv = devsw[i];
|
strlen(devsw[i]->dv_name)) == 0) {
|
||||||
break;
|
dv = devsw[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (dv == NULL)
|
||||||
if (dv == NULL)
|
return (ENOENT);
|
||||||
return(ENOENT);
|
idev = malloc(sizeof(struct disk_devdesc));
|
||||||
idev = malloc(sizeof(struct disk_devdesc));
|
err = 0;
|
||||||
err = 0;
|
np = (devspec + strlen(dv->dv_name));
|
||||||
np = (devspec + strlen(dv->dv_name));
|
|
||||||
|
|
||||||
switch(dv->dv_type) {
|
|
||||||
case DEVT_NONE: /* XXX what to do here? Do we care? */
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DEVT_DISK:
|
switch (dv->dv_type) {
|
||||||
err = disk_parsedev(idev, np, path);
|
case DEVT_NONE: /* XXX what to do here? Do we care? */
|
||||||
if (err != 0)
|
break;
|
||||||
goto fail;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DEVT_CD:
|
case DEVT_DISK:
|
||||||
case DEVT_NET:
|
err = disk_parsedev(idev, np, path);
|
||||||
unit = 0;
|
if (err != 0)
|
||||||
|
goto fail;
|
||||||
|
break;
|
||||||
|
|
||||||
if (*np && (*np != ':')) {
|
case DEVT_CD:
|
||||||
unit = strtol(np, (char **)&cp, 0); /* get unit number if present */
|
case DEVT_NET:
|
||||||
if (cp == np) {
|
unit = 0;
|
||||||
err = EUNIT;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cp = np;
|
|
||||||
}
|
|
||||||
if (*cp && (*cp != ':')) {
|
|
||||||
err = EINVAL;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
idev->dd.d_unit = unit;
|
if (*np && (*np != ':')) {
|
||||||
if (path != NULL)
|
/* get unit number if present */
|
||||||
*path = (*cp == 0) ? cp : cp + 1;
|
unit = strtol(np, (char **)&cp, 0);
|
||||||
break;
|
if (cp == np) {
|
||||||
|
err = EUNIT;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cp = np;
|
||||||
|
}
|
||||||
|
if (*cp && (*cp != ':')) {
|
||||||
|
err = EINVAL;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
case DEVT_ZFS:
|
idev->dd.d_unit = unit;
|
||||||
|
if (path != NULL)
|
||||||
|
*path = (*cp == 0) ? cp : cp + 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEVT_ZFS:
|
||||||
#if defined(USERBOOT_ZFS_SUPPORT)
|
#if defined(USERBOOT_ZFS_SUPPORT)
|
||||||
err = zfs_parsedev((struct zfs_devdesc *)idev, np, path);
|
err = zfs_parsedev((struct zfs_devdesc *)idev, np, path);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
break;
|
break;
|
||||||
#else
|
#else
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
err = EINVAL;
|
err = EINVAL;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
idev->dd.d_dev = dv;
|
idev->dd.d_dev = dv;
|
||||||
if (dev == NULL) {
|
if (dev == NULL) {
|
||||||
free(idev);
|
free(idev);
|
||||||
} else {
|
} else {
|
||||||
*dev = idev;
|
*dev = idev;
|
||||||
}
|
}
|
||||||
return(0);
|
return (0);
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
free(idev);
|
free(idev);
|
||||||
return(err);
|
return (err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *
|
char *
|
||||||
userboot_fmtdev(void *vdev)
|
userboot_fmtdev(void *vdev)
|
||||||
{
|
{
|
||||||
struct devdesc *dev = (struct devdesc *)vdev;
|
struct devdesc *dev = (struct devdesc *)vdev;
|
||||||
static char buf[128]; /* XXX device length constant? */
|
static char buf[128]; /* XXX device length constant? */
|
||||||
|
|
||||||
switch(dev->d_dev->dv_type) {
|
switch(dev->d_dev->dv_type) {
|
||||||
case DEVT_NONE:
|
case DEVT_NONE:
|
||||||
strcpy(buf, "(no device)");
|
strcpy(buf, "(no device)");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DEVT_CD:
|
case DEVT_CD:
|
||||||
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;
|
||||||
|
|
||||||
case DEVT_DISK:
|
case DEVT_DISK:
|
||||||
return (disk_fmtdev(vdev));
|
return (disk_fmtdev(vdev));
|
||||||
|
|
||||||
case DEVT_NET:
|
case DEVT_NET:
|
||||||
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;
|
||||||
|
|
||||||
case DEVT_ZFS:
|
case DEVT_ZFS:
|
||||||
#if defined(USERBOOT_ZFS_SUPPORT)
|
#if defined(USERBOOT_ZFS_SUPPORT)
|
||||||
return (zfs_fmtdev(vdev));
|
return (zfs_fmtdev(vdev));
|
||||||
#else
|
#else
|
||||||
sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit);
|
sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return(buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -212,12 +216,12 @@ userboot_fmtdev(void *vdev)
|
|||||||
int
|
int
|
||||||
userboot_setcurrdev(struct env_var *ev, int flags, const void *value)
|
userboot_setcurrdev(struct env_var *ev, int flags, const void *value)
|
||||||
{
|
{
|
||||||
struct disk_devdesc *ncurr;
|
struct disk_devdesc *ncurr;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
if ((rv = userboot_parsedev(&ncurr, value, NULL)) != 0)
|
if ((rv = userboot_parsedev(&ncurr, value, NULL)) != 0)
|
||||||
return(rv);
|
return (rv);
|
||||||
free(ncurr);
|
free(ncurr);
|
||||||
env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
|
env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user