#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
+#ifdef HAVE_SYS_SYSMACROS_H
+#include <sys/sysmacros.h> /* for major, minor */
+#endif
#include "libcryptsetup.h"
#include "internal.h"
{
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);
if (!buffer)
return -ENOMEM;
- flags = O_RDWR | O_DIRECT | O_SYNC;
+ flags = O_RDWR;
/* use O_EXCL only for block devices */
if (exclusive && S_ISBLK(st.st_mode))
flags |= O_EXCL;
/* coverity[toctou] */
- devfd = open(device_path(device), flags);
+ devfd = device_open(device, flags);
if (devfd == -1) {
free(buffer);
return errno ? -errno : -EINVAL;