mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 04:43:53 +00:00
ofw/disk: Add parsedev support
Add a parsedev support for OpenFirmware disks. We must look at characteristics of the OFW node to know if we match this device (so supply a match routine) or not. Add a parsing routine to allocate devdesc for OpenFirmware disks as well. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D37558
This commit is contained in:
parent
b8ff248f65
commit
88a8c68298
|
@ -50,7 +50,8 @@ static int ofwd_close(struct open_file *f);
|
|||
static int ofwd_ioctl(struct open_file *f, u_long cmd, void *data);
|
||||
static int ofwd_print(int verbose);
|
||||
static char * ofwd_fmtdev(struct devdesc *);
|
||||
|
||||
static int ofwd_parsedev(struct devdesc **, const char *, const char **);
|
||||
static bool ofwd_match(struct devsw *, const char *);
|
||||
|
||||
struct devsw ofwdisk = {
|
||||
.dv_name = "block",
|
||||
|
@ -62,7 +63,9 @@ struct devsw ofwdisk = {
|
|||
.dv_ioctl = ofwd_ioctl,
|
||||
.dv_print = ofwd_print,
|
||||
.dv_cleanup = nullsys,
|
||||
.dv_match = ofwd_match,
|
||||
.dv_fmtdev = ofwd_fmtdev,
|
||||
.dv_parsedev = ofwd_parsedev,
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -210,6 +213,16 @@ ofwd_print(int verbose __unused)
|
|||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
ofwd_match(struct devsw *devsw, const char *devspec)
|
||||
{
|
||||
const char *path;
|
||||
|
||||
return (ofw_path_to_handle(devspec, devsw->dv_name, &path) != -1);
|
||||
}
|
||||
|
||||
static char *
|
||||
ofwd_fmtdev(struct devdesc *idev)
|
||||
{
|
||||
|
@ -217,3 +230,25 @@ ofwd_fmtdev(struct devdesc *idev)
|
|||
|
||||
return (dev->d_path);
|
||||
}
|
||||
|
||||
static int
|
||||
ofwd_parsedev(struct devdesc **dev, const char *devspec, const char **path)
|
||||
{
|
||||
const char *rem_path;
|
||||
struct ofw_devdesc *idev;
|
||||
|
||||
if (ofw_path_to_handle(devspec, ofwdisk.dv_name, &rem_path) == -1)
|
||||
return (ENOENT);
|
||||
idev = malloc(sizeof(struct ofw_devdesc));
|
||||
if (idev == NULL) {
|
||||
printf("ofw_parsedev: malloc failed\n");
|
||||
return ENOMEM;
|
||||
};
|
||||
strlcpy(idev->d_path, devspec, min(rem_path - devspec + 1,
|
||||
sizeof(idev->d_path)));
|
||||
if (dev != NULL)
|
||||
*dev = &idev->dd;
|
||||
if (path != NULL)
|
||||
*path = rem_path;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue