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);
{
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);
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));
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;
&val, "partition"))
return 0;
- *partition = val ? 1 : 0;
- return 1;
+ return val ? 1 : 0;
}
{
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)) {
}
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);