Commit d7a0d860 authored by Milan Broz's avatar Milan Broz

Use getvfs for block size of filesytem if available.

parent dbdb611b
......@@ -37,7 +37,7 @@ PKG_PROG_PKG_CONFIG
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h malloc.h inttypes.h sys/ioctl.h sys/mman.h \
sys/sysmacros.h ctype.h unistd.h locale.h byteswap.h endian.h)
sys/sysmacros.h sys/statvfs.h ctype.h unistd.h locale.h byteswap.h endian.h)
AC_CHECK_HEADERS(uuid/uuid.h,,[AC_MSG_ERROR([You need the uuid library.])])
AC_CHECK_HEADER(libdevmapper.h,,[AC_MSG_ERROR([You need the device-mapper library.])])
......
......@@ -33,6 +33,9 @@
#ifdef HAVE_SYS_SYSMACROS_H
# include <sys/sysmacros.h> /* for major, minor */
#endif
#ifdef HAVE_SYS_STATVFS_H
# include <sys/statvfs.h>
#endif
#include "internal.h"
struct device {
......@@ -49,6 +52,28 @@ struct device {
size_t block_size;
};
static size_t device_fs_block_size(const char *path)
{
#ifdef HAVE_SYS_STATVFS_H
struct statvfs buf;
if (!statvfs(path, &buf) && buf.f_bsize)
return (size_t)buf.f_bsize;
#endif
return crypt_getpagesize();
}
static size_t device_fs_block_size_fd(int fd)
{
#ifdef HAVE_SYS_STATVFS_H
struct statvfs buf;
if (!fstatvfs(fd, &buf) && buf.f_bsize)
return (size_t)buf.f_bsize;
#endif
return crypt_getpagesize();
}
static size_t device_block_size_fd(int fd, size_t *min_size)
{
struct stat st;
......@@ -59,7 +84,7 @@ static size_t device_block_size_fd(int fd, size_t *min_size)
return 0;
if (S_ISREG(st.st_mode))
bsize = crypt_getpagesize();
bsize = device_fs_block_size_fd(fd);
else {
if (ioctl(fd, BLKSSZGET, &arg) < 0)
bsize = crypt_getpagesize();
......@@ -338,7 +363,7 @@ size_t device_block_size(struct device *device)
return device->block_size;
if (device->file_path)
device->block_size = crypt_getpagesize();
device->block_size = device_fs_block_size(device->file_path);
else {
fd = open(device->path, O_RDONLY);
if (fd >= 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment