[PATCH 1/2] blkdev: add blkdev_is_misaligned()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This functions returns the status of the device's alignment. It will be 0 when aligned, otherwise return the offset.

Signed-off-by: Davidlohr Bueso <dave@xxxxxxx>
---
 include/blkdev.h |    3 +++
 lib/blkdev.c     |   12 ++++++++++++
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/include/blkdev.h b/include/blkdev.h
index b6c46ed..6a64172 100644
--- a/include/blkdev.h
+++ b/include/blkdev.h
@@ -92,4 +92,7 @@ int blkdev_get_sectors(int fd, unsigned long long *sectors);
 /* get hardware sector size */
 int blkdev_get_sector_size(int fd, int *sector_size);
 
+/* specifies whether or not the device is misaligned */
+int blkdev_is_misaligned(int fd);
+
 #endif /* BLKDEV_H */
diff --git a/lib/blkdev.c b/lib/blkdev.c
index 0c27a6d..9059ebf 100644
--- a/lib/blkdev.c
+++ b/lib/blkdev.c
@@ -205,6 +205,18 @@ blkdev_get_sector_size(int fd, int *sector_size)
 }
 

+/*
+ * Return the alignment status of a device
+ */
+int blkdev_is_misaligned(int fd)
+{
+	int aligned;
+
+	if (ioctl(fd, BLKALIGNOFF, &aligned) < 0)
+		return -1;
+	return aligned;
+}
+
 #ifdef TEST_PROGRAM
 #include <stdio.h>
 #include <stdlib.h>
-- 
1.7.1




--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux