mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Print a warning if system encryption is used and device is a partition.
System encryption hav metadata in space located ouside of partition itself. Ideally the check should be automatic but for virtualized systems (where a partition could be "whole device" for another sustem this can be dangerous.
This commit is contained in:
@@ -170,13 +170,13 @@ char *crypt_lookup_dev(const char *dev_id)
|
||||
return devpath;
|
||||
}
|
||||
|
||||
int crypt_sysfs_get_rotational(int major, int minor, int *rotational)
|
||||
static int _sysfs_get_int(int major, int minor, int *value, const char *attr)
|
||||
{
|
||||
char path[PATH_MAX], tmp[64] = {0};
|
||||
int fd, r;
|
||||
|
||||
if (snprintf(path, sizeof(path), "/sys/dev/block/%d:%d/queue/rotational",
|
||||
major, minor) < 0)
|
||||
if (snprintf(path, sizeof(path), "/sys/dev/block/%d:%d/%s",
|
||||
major, minor, attr) < 0)
|
||||
return 0;
|
||||
|
||||
if ((fd = open(path, O_RDONLY)) < 0)
|
||||
@@ -187,8 +187,27 @@ int crypt_sysfs_get_rotational(int major, int minor, int *rotational)
|
||||
if (r <= 0)
|
||||
return 0;
|
||||
|
||||
if (sscanf(tmp, "%d", rotational) != 1)
|
||||
if (sscanf(tmp, "%d", value) != 1)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int crypt_sysfs_get_rotational(int major, int minor, int *rotational)
|
||||
{
|
||||
return _sysfs_get_int(major, minor, rotational, "queue/rotational");
|
||||
}
|
||||
|
||||
int crypt_sysfs_get_partition(const char *dev_path, int *partition)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(dev_path, &st) < 0)
|
||||
return 0;
|
||||
|
||||
if (!S_ISBLK(st.st_mode))
|
||||
return 0;
|
||||
|
||||
return _sysfs_get_int(major(st.st_rdev), minor(st.st_rdev),
|
||||
partition, "partition");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user