summaryrefslogtreecommitdiff
path: root/ext4_utils/wipe.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ext4_utils/wipe.cpp')
-rw-r--r--ext4_utils/wipe.cpp86
1 files changed, 43 insertions, 43 deletions
diff --git a/ext4_utils/wipe.cpp b/ext4_utils/wipe.cpp
index c2db3353..445c9739 100644
--- a/ext4_utils/wipe.cpp
+++ b/ext4_utils/wipe.cpp
@@ -27,60 +27,60 @@
#include <linux/fs.h>
#include <sys/ioctl.h>
+#include "helpers.h"
+
#ifndef BLKDISCARD
-#define BLKDISCARD _IO(0x12,119)
+#define BLKDISCARD _IO(0x12, 119)
#endif
#ifndef BLKSECDISCARD
-#define BLKSECDISCARD _IO(0x12,125)
+#define BLKSECDISCARD _IO(0x12, 125)
#endif
-int wipe_block_device(int fd, s64 len)
-{
- u64 range[2];
- int ret;
-
- if (!is_block_device_fd(fd)) {
- // Wiping only makes sense on a block device.
- return 0;
- }
-
- range[0] = 0;
- range[1] = len;
- ret = ioctl(fd, BLKSECDISCARD, &range);
- if (ret < 0) {
- range[0] = 0;
- range[1] = len;
- ret = ioctl(fd, BLKDISCARD, &range);
- if (ret < 0) {
- warn("Discard failed\n");
- return 1;
- } else {
- char buf[4096] = {0};
-
- if (!android::base::WriteFully(fd, buf, 4096)) {
- warn("Writing zeros failed\n");
- return 1;
- }
- fsync(fd);
- warn("Wipe via secure discard failed, used discard instead\n");
- return 0;
- }
- }
-
- return 0;
+int wipe_block_device(int fd, s64 len) {
+ u64 range[2];
+ int ret;
+
+ if (!is_block_device_fd(fd)) {
+ // Wiping only makes sense on a block device.
+ return 0;
+ }
+
+ range[0] = 0;
+ range[1] = len;
+ ret = ioctl(fd, BLKSECDISCARD, &range);
+ if (ret < 0) {
+ range[0] = 0;
+ range[1] = len;
+ ret = ioctl(fd, BLKDISCARD, &range);
+ if (ret < 0) {
+ warn("Discard failed\n");
+ return 1;
+ } else {
+ char buf[4096] = {0};
+
+ if (!android::base::WriteFully(fd, buf, 4096)) {
+ warn("Writing zeros failed\n");
+ return 1;
+ }
+ fsync(fd);
+ warn("Wipe via secure discard failed, used discard instead\n");
+ return 0;
+ }
+ }
+
+ return 0;
}
-#else /* __linux__ */
+#else /* __linux__ */
#error "Missing block device wiping implementation for this platform!"
#endif
-#else /* WIPE_IS_SUPPORTED */
+#else /* WIPE_IS_SUPPORTED */
-int wipe_block_device(int fd __attribute__((unused)), s64 len __attribute__((unused)))
-{
- /* Wiping is not supported on this platform. */
- return 1;
+int wipe_block_device(int fd __attribute__((unused)), s64 len __attribute__((unused))) {
+ /* Wiping is not supported on this platform. */
+ return 1;
}
-#endif /* WIPE_IS_SUPPORTED */
+#endif /* WIPE_IS_SUPPORTED */