summaryrefslogtreecommitdiffstats
path: root/sys/boot/common
diff options
context:
space:
mode:
authorzbb <zbb@FreeBSD.org>2015-11-27 18:17:53 +0000
committerzbb <zbb@FreeBSD.org>2015-11-27 18:17:53 +0000
commit9e87a63a97c4a65b4600f3c89cd4cf1c73444cc0 (patch)
treeadb6405eb484127779911c7e61f15fcc18820cdf /sys/boot/common
parentb8c3342a325fccdf812dc8edaff0a04730993b25 (diff)
downloadFreeBSD-src-9e87a63a97c4a65b4600f3c89cd4cf1c73444cc0.zip
FreeBSD-src-9e87a63a97c4a65b4600f3c89cd4cf1c73444cc0.tar.gz
Implement simple ops for umass_disk
The initial IOCTL implementation supports reading disk physical geometry. Two additional functions were added. They allow reading/writing raw data to the disk (default partition). Submitted by: Wojciech Macek <wma@semihalf.com> Obtained from: Semihalf Sponsored by: Juniper Networks Inc. Differential Revision: https://reviews.freebsd.org/D4143
Diffstat (limited to 'sys/boot/common')
-rw-r--r--sys/boot/common/disk.c36
-rw-r--r--sys/boot/common/disk.h10
2 files changed, 46 insertions, 0 deletions
diff --git a/sys/boot/common/disk.c b/sys/boot/common/disk.c
index a541cb0..a8801e1 100644
--- a/sys/boot/common/disk.c
+++ b/sys/boot/common/disk.c
@@ -233,6 +233,42 @@ disk_print(struct disk_devdesc *dev, char *prefix, int verbose)
}
int
+disk_read(struct disk_devdesc *dev, void *buf, off_t offset, u_int blocks)
+{
+ struct open_disk *od;
+ int ret;
+
+ od = (struct open_disk *)dev->d_opendata;
+ ret = dev->d_dev->dv_strategy(dev, F_READ, dev->d_offset + offset,
+ blocks * od->sectorsize, buf, NULL);
+
+ return (ret);
+}
+
+int
+disk_write(struct disk_devdesc *dev, void *buf, off_t offset, u_int blocks)
+{
+ struct open_disk *od;
+ int ret;
+
+ od = (struct open_disk *)dev->d_opendata;
+ ret = dev->d_dev->dv_strategy(dev, F_WRITE, dev->d_offset + offset,
+ blocks * od->sectorsize, buf, NULL);
+
+ return (ret);
+}
+
+int
+disk_ioctl(struct disk_devdesc *dev, u_long cmd, void *buf)
+{
+
+ if (dev->d_dev->dv_ioctl)
+ return ((*dev->d_dev->dv_ioctl)(dev->d_opendata, cmd, buf));
+
+ return (ENXIO);
+}
+
+int
disk_open(struct disk_devdesc *dev, off_t mediasize, u_int sectorsize,
u_int flags)
{
diff --git a/sys/boot/common/disk.h b/sys/boot/common/disk.h
index 6a78fbf..e95256d 100644
--- a/sys/boot/common/disk.h
+++ b/sys/boot/common/disk.h
@@ -89,6 +89,11 @@ struct disk_devdesc
off_t d_offset;
};
+enum disk_ioctl {
+ IOCTL_GET_BLOCKS,
+ IOCTL_GET_BLOCK_SIZE
+};
+
/*
* Parse disk metadata and initialise dev->d_offset.
*/
@@ -97,6 +102,11 @@ extern int disk_open(struct disk_devdesc *dev, off_t mediasize,
#define DISK_F_NOCACHE 0x0001 /* Do not use metadata caching */
extern int disk_close(struct disk_devdesc *dev);
extern void disk_cleanup(const struct devsw *d_dev);
+extern int disk_ioctl(struct disk_devdesc *dev, u_long cmd, void *buf);
+extern int disk_read(struct disk_devdesc *dev, void *buf, off_t offset,
+ u_int blocks);
+extern int disk_write(struct disk_devdesc *dev, void *buf, off_t offset,
+ u_int blocks);
/*
* Print information about slices on a disk.
OpenPOWER on IntegriCloud