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>
This commit is contained in:
Davidlohr Bueso 2011-04-08 21:20:49 -03:00 committed by Karel Zak
parent 0a0803460c
commit ba32692970
2 changed files with 15 additions and 0 deletions

View 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>