Changeset View
Changeset View
Standalone View
Standalone View
stand/libofw/ofw_disk.c
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
static int ofwd_init(void); | static int ofwd_init(void); | ||||
static int ofwd_strategy(void *devdata, int flag, daddr_t dblk, | static int ofwd_strategy(void *devdata, int flag, daddr_t dblk, | ||||
size_t size, char *buf, size_t *rsize); | size_t size, char *buf, size_t *rsize); | ||||
static int ofwd_open(struct open_file *f, ...); | static int ofwd_open(struct open_file *f, ...); | ||||
static int ofwd_close(struct open_file *f); | static int ofwd_close(struct open_file *f); | ||||
static int ofwd_ioctl(struct open_file *f, u_long cmd, void *data); | static int ofwd_ioctl(struct open_file *f, u_long cmd, void *data); | ||||
static int ofwd_print(int verbose); | static int ofwd_print(int verbose); | ||||
static char * ofwd_fmtdev(struct devdesc *); | 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 = { | struct devsw ofwdisk = { | ||||
.dv_name = "block", | .dv_name = "block", | ||||
.dv_type = DEVT_OFDISK, | .dv_type = DEVT_OFDISK, | ||||
.dv_init = ofwd_init, | .dv_init = ofwd_init, | ||||
.dv_strategy = ofwd_strategy, | .dv_strategy = ofwd_strategy, | ||||
.dv_open = ofwd_open, | .dv_open = ofwd_open, | ||||
.dv_close = ofwd_close, | .dv_close = ofwd_close, | ||||
.dv_ioctl = ofwd_ioctl, | .dv_ioctl = ofwd_ioctl, | ||||
.dv_print = ofwd_print, | .dv_print = ofwd_print, | ||||
.dv_cleanup = nullsys, | .dv_cleanup = nullsys, | ||||
.dv_match = ofwd_match, | |||||
.dv_fmtdev = ofwd_fmtdev, | .dv_fmtdev = ofwd_fmtdev, | ||||
.dv_parsedev = ofwd_parsedev, | |||||
}; | }; | ||||
/* | /* | ||||
* We're not guaranteed to be able to open a device more than once and there | * We're not guaranteed to be able to open a device more than once and there | ||||
* is no OFW standard method to determine whether a device is already opened. | * is no OFW standard method to determine whether a device is already opened. | ||||
* Opening a device multiple times simultaneously happens to work with most | * Opening a device multiple times simultaneously happens to work with most | ||||
* OFW block device drivers but triggers a trap with at least the driver for | * OFW block device drivers but triggers a trap with at least the driver for | ||||
* the on-board controllers of Sun Fire V100 and Ultra 1. Upper layers and MI | * the on-board controllers of Sun Fire V100 and Ultra 1. Upper layers and MI | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | if ((ret = pager_output(line)) != 0) | ||||
return (ret); | return (ret); | ||||
} else { | } else { | ||||
if ((ret = pager_output(" none are open, so no info\n")) != 0) | if ((ret = pager_output(" none are open, so no info\n")) != 0) | ||||
return (ret); | return (ret); | ||||
} | } | ||||
return (0); | 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 * | static char * | ||||
ofwd_fmtdev(struct devdesc *idev) | ofwd_fmtdev(struct devdesc *idev) | ||||
{ | { | ||||
struct ofw_devdesc *dev = (struct ofw_devdesc *)idev; | struct ofw_devdesc *dev = (struct ofw_devdesc *)idev; | ||||
return (dev->d_path); | 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; | |||||
} | } |