Skip to contentSkip to conversation

blkdev: add blkdev_get_physector_size()

PATCH In review Davidlohr Bueso 2 participants 2 messages Jun 21, 2011 – Jun 27, 2011

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

PATCH 1/1 blkdev: add blkdev_get_physector_size()

From: Davidlohr Bueso <[email protected]>
Date: Mon, 20 Jun 2011 22:51:47 -0400

This function uses the BLKPBSZGET ioctl to get the physical block size of the device.

---
 include/blkdev.h |    3 +++
 lib/blkdev.c     |   14 ++++++++++++++
 2 files changed, 17 insertions(+), 0 deletions(-)
include/blkdev.h +3 -0
index 6a64172..0024897 100644
@@ -95,4 +95,7 @@ int blkdev_get_sector_size(int fd, int *sector_size);
 /* specifies whether or not the device is misaligned */
 int blkdev_is_misaligned(int fd);
 
+/* get physical block device size */
+int blkdev_get_physector_size(int fd);
+
 #endif /* BLKDEV_H */
lib/blkdev.c +14 -0
index 5cb6554..94df803 100644
@@ -221,6 +221,20 @@ int blkdev_is_misaligned(int fd)
 #endif
 }
 
+/* get physical block device size */
+int blkdev_get_physector_size(int fd)
+{
+#ifdef BLKPBSZGET
+	int bsz;
+
+	if (ioctl(fd, BLKPBSZGET, &bsz) < 0)
+		return 0;
+	return bsz;
+#else
+	return 0;
+#endif
+}
+
 #ifdef TEST_PROGRAM
 #include <stdio.h>
 #include <stdlib.h>
Signature · 1 line
1.7.5.4
maintainer
#1 lore raw
Quoted 3 lines · Davidlohr Bueso
 include/blkdev.h |    3 +++
 lib/blkdev.c     |   14 ++++++++++++++
 2 files changed, 17 insertions(+), 0 deletions(-)

Applied with minor changes, thanks.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com