From a2df793a48e7aebc45ed8cc2ef487d30203c4c40 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Wed, 13 Feb 2019 15:24:01 -0800 Subject: [PATCH] wipe: guarantee zeros after wipe out partitions Stale data in the partition can bypass formatting by fs_mgr and cause filesystem unmountable. Bug: 122989894 Change-Id: Id2aa4baefeb8308ce14eeaa7790a1aab35e522aa Signed-off-by: Jaegeuk Kim --- ext4_utils/Android.bp | 1 + ext4_utils/wipe.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/ext4_utils/Android.bp b/ext4_utils/Android.bp index f8bb310e..e9c5965f 100644 --- a/ext4_utils/Android.bp +++ b/ext4_utils/Android.bp @@ -16,6 +16,7 @@ cc_library { ], export_include_dirs: ["include"], shared_libs: [ + "libbase", "libsparse", "libz", ], diff --git a/ext4_utils/wipe.cpp b/ext4_utils/wipe.cpp index 7bda71c1..c2db3353 100644 --- a/ext4_utils/wipe.cpp +++ b/ext4_utils/wipe.cpp @@ -18,6 +18,8 @@ #include "ext4_utils/ext4_utils.h" +#include + #if WIPE_IS_SUPPORTED #if defined(__linux__) @@ -54,6 +56,13 @@ int wipe_block_device(int fd, s64 len) 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; } -- 2.11.0