summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavidlohr Bueso2011-04-09 02:20:49 +0200
committerKarel Zak2011-04-12 13:08:52 +0200
commitba326929706ec4dc8ab8bc0a09868bcd6fd6d75f (patch)
tree645e388dc4cfa9867db938b5fdf038718964ea70
parenthexdump: don't include err.h directly (diff)
downloadkernel-qcow2-util-linux-ba326929706ec4dc8ab8bc0a09868bcd6fd6d75f.tar.gz
kernel-qcow2-util-linux-ba326929706ec4dc8ab8bc0a09868bcd6fd6d75f.tar.xz
kernel-qcow2-util-linux-ba326929706ec4dc8ab8bc0a09868bcd6fd6d75f.zip
blkdev: add blkdev_is_misaligned()
This functions returns the status of the device's alignment. It will be 0 when aligned, otherwise return the offset. [kzak@redhat.com: - returns 0 if the ioctl failed] Signed-off-by: Davidlohr Bueso <dave@gnu.org> Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--include/blkdev.h3
-rw-r--r--lib/blkdev.c12
2 files changed, 15 insertions, 0 deletions
diff --git a/include/blkdev.h b/include/blkdev.h
index b6c46edde..6a641723f 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 0c27a6df9..fb69e88b5 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 0; /* probably kernel < 2.6.32 */
+ return aligned;
+}
+
#ifdef TEST_PROGRAM
#include <stdio.h>
#include <stdlib.h>