Skip to content

Instantly share code, notes, and snippets.

@kmanna
Created August 22, 2014 22:04
Show Gist options
  • Save kmanna/547bb09ef06801ea8d67 to your computer and use it in GitHub Desktop.
Save kmanna/547bb09ef06801ea8d67 to your computer and use it in GitHub Desktop.
From 8f073c7661197cefe8fbfaa723b96a522420c672 Mon Sep 17 00:00:00 2001
From: Kyle Manna <kmanna@fanhattan.com>
Date: Fri, 22 Aug 2014 15:04:20 -0700
Subject: [PATCH] HACK: wipe: Add timing parameters
* Add timing parameters
Change-Id: If82f1777355e56ccc4ea3c6722d0bf1771e1e630
---
ext4_utils/Android.mk | 9 +++++++++
ext4_utils/wipe.c | 33 +++++++++++++++++++++++++++++++--
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/ext4_utils/Android.mk b/ext4_utils/Android.mk
index 674cd47..a9911d0 100644
--- a/ext4_utils/Android.mk
+++ b/ext4_utils/Android.mk
@@ -23,6 +23,7 @@ LOCAL_MODULE := libext4_utils
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES += external/zlib
LOCAL_SHARED_LIBRARIES := libz
+LOCAL_LDLIBS += -lrt
include $(BUILD_SHARED_LIBRARY)
@@ -34,6 +35,7 @@ LOCAL_MODULE := libext4_utils
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES += external/zlib
LOCAL_STATIC_LIBRARIES := libz
+LOCAL_LDLIBS += -lrt
include $(BUILD_STATIC_LIBRARY)
@@ -44,6 +46,7 @@ LOCAL_SRC_FILES := $(libext4_utils_src_files)
LOCAL_MODULE := libext4_utils
LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := libz
+LOCAL_LDLIBS += -lrt
include $(BUILD_HOST_STATIC_LIBRARY)
@@ -53,6 +56,7 @@ LOCAL_SRC_FILES := make_ext4fs_main.c
LOCAL_MODULE := make_ext4fs
LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES += libext4_utils libz
+LOCAL_LDLIBS += -lrt
include $(BUILD_EXECUTABLE)
@@ -61,6 +65,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := make_ext4fs_main.c
LOCAL_MODULE := make_ext4fs
LOCAL_STATIC_LIBRARIES += libext4_utils libz
+LOCAL_LDLIBS += -lrt
include $(BUILD_HOST_EXECUTABLE)
@@ -70,6 +75,7 @@ LOCAL_SRC_FILES := ext2simg.c
LOCAL_MODULE := ext2simg
LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES += libext4_utils libz
+LOCAL_LDLIBS += -lrt
include $(BUILD_EXECUTABLE)
@@ -79,6 +85,7 @@ LOCAL_SRC_FILES := ext2simg.c
LOCAL_MODULE := ext2simg
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_LIBRARIES += libext4_utils libz
+LOCAL_LDLIBS += -lrt
include $(BUILD_HOST_EXECUTABLE)
@@ -111,6 +118,7 @@ LOCAL_SRC_FILES := ext4fixup_main.c
LOCAL_MODULE := ext4fixup
LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES += libext4_utils libz
+LOCAL_LDLIBS += -lrt
include $(BUILD_EXECUTABLE)
@@ -120,6 +128,7 @@ LOCAL_SRC_FILES := ext4fixup_main.c
LOCAL_MODULE := ext4fixup
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_LIBRARIES += libext4_utils libz
+LOCAL_LDLIBS += -lrt
include $(BUILD_HOST_EXECUTABLE)
diff --git a/ext4_utils/wipe.c b/ext4_utils/wipe.c
index 3bd33e5..8d6fbc5 100644
--- a/ext4_utils/wipe.c
+++ b/ext4_utils/wipe.c
@@ -30,6 +30,30 @@
#define BLKSECDISCARD _IO(0x12,125)
#endif
+#include <stdarg.h>
+#include <time.h>
+
+static inline double clock_get_dbl()
+{
+ struct timespec ts;
+ if (0 == clock_gettime(CLOCK_MONOTONIC, &ts))
+ return ts.tv_sec + ts.tv_nsec / 1000000000.0;
+
+ return 0.0;
+}
+
+static inline int write_log(const char *format, ...)
+{
+ int ret;
+ va_list args;
+
+ printf("%f: ", clock_get_dbl());
+ va_start(args, format);
+ ret = vprintf(format, args);
+ va_end(args);
+ return ret;
+}
+
int wipe_block_device(int fd, s64 len)
{
u64 range[2];
@@ -37,20 +61,25 @@ int wipe_block_device(int fd, s64 len)
range[0] = 0;
range[1] = len;
+ write_log("Attempting ioctl(fd, BLKSECDISCARD, &range)\n");
+ write_log("range[0] = %llu, range[1] = %llu\n", range[0], range[1]);
ret = ioctl(fd, BLKSECDISCARD, &range);
if (ret < 0) {
range[0] = 0;
range[1] = len;
+ write_log("Attempting ioctl(fd, BLKDISCARD, &range)\n");
+ write_log("range[0] = %llu, range[1] = %llu\n", range[0], range[1]);
ret = ioctl(fd, BLKDISCARD, &range);
if (ret < 0) {
- warn("Discard failed\n");
+ write_log("Discard failed\n");
return 1;
} else {
- warn("Wipe via secure discard failed, used discard instead\n");
+ write_log("Wipe via secure discard failed, used discard instead\n");
return 0;
}
}
+ write_log("Wipe via secure discard succeeded\n");
return 0;
}
#else
--
2.1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment