]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
blkdev: add blkdev_is_misaligned()
authorDavidlohr Bueso <dave@gnu.org>
Sat, 9 Apr 2011 00:20:49 +0000 (21:20 -0300)
committerKarel Zak <kzak@redhat.com>
Tue, 12 Apr 2011 11:08:52 +0000 (13:08 +0200)
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>
include/blkdev.h
lib/blkdev.c

index b6c46edde3e0d4d7911a50b0ab491c4e95fc38ae..6a641723f844814eeadac8fbb7b032280ca79b6e 100644 (file)
@@ -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 */
index 0c27a6df936c06233defb124e719ec4be9a5717d..fb69e88b58a8aa01810e65dbc0494008020f0269 100644 (file)
@@ -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>