Do not use pagesize as fallback for block size.

Device must process MAX_SECTOR_SIZE as it is encryption
block size, so if it does not work with this value, it will
fail anyway.

Fixes: #943
This commit is contained in:
Milan Broz
2025-05-10 16:54:59 +02:00
parent 9484eee48a
commit a39a0d00e5

View File

@@ -48,7 +48,7 @@ struct device {
static size_t device_fs_block_size_fd(int fd) static size_t device_fs_block_size_fd(int fd)
{ {
size_t page_size = crypt_getpagesize(); size_t max_size = MAX_SECTOR_SIZE;
#if HAVE_SYS_STATVFS_H #if HAVE_SYS_STATVFS_H
struct statvfs buf; struct statvfs buf;
@@ -57,10 +57,10 @@ static size_t device_fs_block_size_fd(int fd)
* NOTE: some filesystems (NFS) returns bogus blocksize (1MB). * NOTE: some filesystems (NFS) returns bogus blocksize (1MB).
* Page-size io should always work and avoids increasing IO beyond aligned LUKS header. * Page-size io should always work and avoids increasing IO beyond aligned LUKS header.
*/ */
if (!fstatvfs(fd, &buf) && buf.f_bsize && buf.f_bsize <= page_size) if (!fstatvfs(fd, &buf) && buf.f_bsize && buf.f_bsize <= max_size)
return (size_t)buf.f_bsize; return (size_t)buf.f_bsize;
#endif #endif
return page_size; return max_size;
} }
static size_t device_block_size_fd(int fd, size_t *min_size) static size_t device_block_size_fd(int fd, size_t *min_size)
@@ -533,7 +533,7 @@ void device_topology_alignment(struct crypt_device *cd,
/* minimum io size */ /* minimum io size */
if (ioctl(fd, BLKIOMIN, &min_io_size) == -1) { if (ioctl(fd, BLKIOMIN, &min_io_size) == -1) {
log_dbg(cd, "Topology info for %s not supported, using default offset %lu bytes.", log_dbg(cd, "Topology info for %s not supported, using default alignment %lu bytes.",
device->path, default_alignment); device->path, default_alignment);
goto out; goto out;
} }