Detect unsupported zoned devices for LUKS header device.

Zoned device cannot be written with direct-io
and cannot be used for LUKS header logic without
significant changes. Do not allow to use them for LUKS header
but allow it for data device, as dm-crypt supports it.

Fixes: #877
This commit is contained in:
Milan Broz
2024-04-26 11:24:15 +02:00
parent 40e5c7d095
commit 410a586284
5 changed files with 68 additions and 0 deletions

View File

@@ -210,6 +210,23 @@ static int _path_get_uint64(const char *sysfs_path, uint64_t *value, const char
return _read_uint64(path, value);
}
static int _sysfs_get_string(int major, int minor, char *buf, size_t buf_size, const char *attr)
{
char path[PATH_MAX];
int fd, r;
if (snprintf(path, sizeof(path), "/sys/dev/block/%d:%d/%s",
major, minor, attr) < 0)
return 0;
if ((fd = open(path, O_RDONLY)) < 0)
return 0;
r = read(fd, buf, buf_size);
close(fd);
return r < 0 ? 0 : r;
}
int crypt_dev_get_partition_number(const char *dev_path)
{
uint64_t partno;
@@ -248,6 +265,16 @@ int crypt_dev_is_dax(int major, int minor)
return val ? 1 : 0;
}
int crypt_dev_is_zoned(int major, int minor)
{
char buf[32] = {};
if (!_sysfs_get_string(major, minor, buf, sizeof(buf), "queue/zoned"))
return 0; /* if failed, expect non-zoned device */
return strncmp(buf, "none", 4) ? 1 : 0;
}
int crypt_dev_is_partition(const char *dev_path)
{
uint64_t val;