Skip to contentSkip to conversation

NVMe: Add getgeo to block ops

PATCH New Keith Busch 1 participant 1 message Apr 2, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NVMe: Add getgeo to block ops

Some programs require HDIO_GETGEO work, which requires we implement getgeo.

Signed-off-by Keith Busch <keith.busch at intel.com>

---
For example, fdisk -l doesn't automatically list the nvme drivers without this. There are other programs that require this as well.

We have to pick some values for this. I just copied the ones used by default from virtio-blk... Are these okay?

 drivers/block/nvme-core.c |   11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/block/nvme-core.c +11 -0
index 625259d..a113e10 100644
@@ -25,6 +25,7 @@
 #include <linux/errno.h>
 #include <linux/fs.h>
 #include <linux/genhd.h>
+#include <linux/hdreg.h>
 #include <linux/idr.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
@@ -1708,12 +1709,22 @@ static void nvme_release(struct gendisk *disk, fmode_t mode)
 	kref_put(&dev->kref, nvme_free_dev);
 }
 
+static int nvme_getgeo(struct block_device *bd, struct hd_geometry *geo)
+{
+	/* some standard values */
+	geo->heads = 1 << 6;
+	geo->sectors = 1 << 5;
+	geo->cylinders = get_capacity(bd->bd_disk) >> 11;
+	return 0;
+}
+
 static const struct block_device_operations nvme_fops = {
 	.owner		= THIS_MODULE,
 	.ioctl		= nvme_ioctl,
 	.compat_ioctl	= nvme_compat_ioctl,
 	.open		= nvme_open,
 	.release	= nvme_release,
+	.getgeo		= nvme_getgeo,
 };
 
 static void nvme_resubmit_bios(struct nvme_queue *nvmeq)
Signature · 1 line
1.7.10.4