Use getvfs for block size of filesytem if available.

This commit is contained in:
Milan Broz
2017-07-26 14:32:21 +02:00
parent dbdb611bcc
commit d7a0d860b9
2 changed files with 28 additions and 3 deletions

View File

@@ -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.])])

View File

@@ -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) {