mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Simplify sysfs helpers.
This commit is contained in:
@@ -92,8 +92,8 @@ struct device *crypt_data_device(struct crypt_device *cd);
|
||||
int crypt_confirm(struct crypt_device *cd, const char *msg);
|
||||
|
||||
char *crypt_lookup_dev(const char *dev_id);
|
||||
int crypt_sysfs_get_rotational(int major, int minor, int *rotational);
|
||||
int crypt_sysfs_get_partition(const char *dev_path, int *partition);
|
||||
int crypt_dev_is_rotational(int major, int minor);
|
||||
int crypt_dev_is_partition(const char *dev_path);
|
||||
|
||||
ssize_t write_blockwise(int fd, int bsize, void *buf, size_t count);
|
||||
ssize_t read_blockwise(int fd, int bsize, void *_buf, size_t count);
|
||||
|
||||
@@ -565,7 +565,7 @@ int TCRYPT_read_phdr(struct crypt_device *cd,
|
||||
{
|
||||
struct device *device = crypt_metadata_device(cd);
|
||||
ssize_t hdr_size = sizeof(struct tcrypt_phdr);
|
||||
int devfd = 0, r, bs, partition;
|
||||
int devfd = 0, r, bs;
|
||||
|
||||
assert(sizeof(struct tcrypt_phdr) == 512);
|
||||
|
||||
@@ -587,9 +587,7 @@ int TCRYPT_read_phdr(struct crypt_device *cd,
|
||||
if (lseek(devfd, TCRYPT_HDR_SYSTEM_OFFSET, SEEK_SET) >= 0 &&
|
||||
read_blockwise(devfd, bs, hdr, hdr_size) == hdr_size) {
|
||||
r = TCRYPT_init_hdr(cd, hdr, params);
|
||||
if (r == -EPERM &&
|
||||
crypt_sysfs_get_partition(device_path(device), &partition) &&
|
||||
partition)
|
||||
if (r == -EPERM && crypt_dev_is_partition(device_path(device)))
|
||||
log_std(cd, _("WARNING: device %s is a partition, for TCRYPT "
|
||||
"system encryption you usually need to use "
|
||||
"whole block device path.\n"), device_path(device));
|
||||
|
||||
@@ -193,18 +193,17 @@ static int _sysfs_get_uint64(int major, int minor, uint64_t *value, const char *
|
||||
return 1;
|
||||
}
|
||||
|
||||
int crypt_sysfs_get_rotational(int major, int minor, int *rotational)
|
||||
int crypt_dev_is_rotational(int major, int minor)
|
||||
{
|
||||
uint64_t val;
|
||||
|
||||
if (!_sysfs_get_uint64(major, minor, &val, "queue/rotational"))
|
||||
return 0;
|
||||
return 1; /* if failed, expect rotational disk */
|
||||
|
||||
*rotational = val ? 1 : 0;
|
||||
return 1;
|
||||
return val ? 1 : 0;
|
||||
}
|
||||
|
||||
int crypt_sysfs_get_partition(const char *dev_path, int *partition)
|
||||
int crypt_dev_is_partition(const char *dev_path)
|
||||
{
|
||||
uint64_t val;
|
||||
struct stat st;
|
||||
@@ -219,6 +218,5 @@ int crypt_sysfs_get_partition(const char *dev_path, int *partition)
|
||||
&val, "partition"))
|
||||
return 0;
|
||||
|
||||
*partition = val ? 1 : 0;
|
||||
return 1;
|
||||
return val ? 1 : 0;
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ int crypt_wipe(struct device *device,
|
||||
{
|
||||
struct stat st;
|
||||
char *buffer;
|
||||
int devfd, flags, rotational, bsize;
|
||||
int devfd, flags, bsize;
|
||||
ssize_t written;
|
||||
|
||||
if (!size || size % SECTOR_SIZE || (size > MAXIMUM_WIPE_BYTES)) {
|
||||
@@ -139,14 +139,12 @@ int crypt_wipe(struct device *device,
|
||||
}
|
||||
|
||||
if (type == CRYPT_WIPE_DISK && S_ISBLK(st.st_mode)) {
|
||||
rotational = 0;
|
||||
if (!crypt_sysfs_get_rotational(major(st.st_rdev),
|
||||
minor(st.st_rdev),
|
||||
&rotational))
|
||||
rotational = 1;
|
||||
log_dbg("Rotational flag is %d.", rotational);
|
||||
if (!rotational)
|
||||
if (!crypt_dev_is_rotational(major(st.st_rdev),
|
||||
minor(st.st_rdev))) {
|
||||
type = CRYPT_WIPE_SSD;
|
||||
log_dbg("Non-rotational device, using SSD wipe mode.");
|
||||
} else
|
||||
log_dbg("Rotational device, using normal wipe mode.");
|
||||
}
|
||||
|
||||
bsize = device_block_size(device);
|
||||
|
||||
Reference in New Issue
Block a user