Include 'sys/sysmacros.h' for GCC-9
[platform/upstream/cryptsetup.git] / lib / utils_wipe.c
index 858964c..c70d632 100644 (file)
@@ -30,6 +30,9 @@
 #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"
@@ -124,7 +127,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 +142,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);
@@ -157,14 +158,14 @@ int crypt_wipe(struct device *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;