Whamcloud - gitweb
tst_libext2fs: Avoid multiple definition of global variables
[tools/e2fsprogs.git] / lib / ext2fs / getsectsize.c
index b57bf56..d6bc376 100644 (file)
@@ -26,6 +26,9 @@
 #include <errno.h>
 #endif
 #include <fcntl.h>
+#ifdef HAVE_SYS_DISK_H
+#include <sys/disk.h>
+#endif
 #ifdef HAVE_LINUX_FD_H
 #include <sys/ioctl.h>
 #include <linux/fd.h>
@@ -60,6 +63,12 @@ errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize)
                return 0;
        }
 #endif
+#ifdef DIOCGSECTORSIZE
+       if (ioctl(fd, DIOCGSECTORSIZE, sectsize) >= 0) {
+               close(fd);
+               return 0;
+       }
+#endif
        *sectsize = 0;
        close(fd);
        return 0;
@@ -76,6 +85,11 @@ int ext2fs_get_dio_alignment(int fd)
        if (ioctl(fd, BLKSSZGET, &align) < 0)
                align = 0;
 #endif
+#ifdef DIOCGSECTORSIZE
+       if (align <= 0 &&
+           ioctl(fd, DIOCGSECTORSIZE, &align) < 0)
+               align = 0;
+#endif
 
 #ifdef _SC_PAGESIZE
        if (align <= 0)
@@ -108,6 +122,14 @@ errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize)
                return 0;
        }
 #endif
+#ifdef DIOCGSECTORSIZE
+       /* This isn't really the physical sector size, but FreeBSD
+        * doesn't seem to have this concept. */
+       if (ioctl(fd, DIOCGSECTORSIZE, sectsize) >= 0) {
+               close(fd);
+               return 0;
+       }
+#endif
        *sectsize = 0;
        close(fd);
        return 0;