diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2019-08-14 04:10:11 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2019-08-14 04:10:11 +0000 |
commit | 69412e592d8c5ffd5c0c9327013c7713d7192284 (patch) | |
tree | 1f0b16ac55633a568e697ddcdb1322db054792eb | |
parent | 6225390356ca09449da9d65d0306b1f43099fa62 (diff) | |
parent | 1cbe5b87d3e97459ead43de2d3a66cf13dcb9a87 (diff) | |
download | f2fs-tools-android10-c2f2-release.tar.gz |
Snap for 5800080 from 1cbe5b87d3e97459ead43de2d3a66cf13dcb9a87 to qt-c2f2-releaseandroid-10.0.0_r9android-10.0.0_r8android-10.0.0_r7android-10.0.0_r14android-10.0.0_r13android-10.0.0_r12android10-c2f2-s2-releaseandroid10-c2f2-s1-releaseandroid10-c2f2-release
Change-Id: I2716e59b20d925ad440d773c1ff3ab4629a412aa
-rw-r--r-- | mkfs/f2fs_format_utils.c | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/mkfs/f2fs_format_utils.c b/mkfs/f2fs_format_utils.c index 8bf128c..f2d55ad 100644 --- a/mkfs/f2fs_format_utils.c +++ b/mkfs/f2fs_format_utils.c @@ -25,6 +25,7 @@ #include <stdio.h> #include <unistd.h> #include <stdlib.h> +#include <stdbool.h> #ifndef ANDROID_WINDOWS_HOST #include <sys/ioctl.h> #endif @@ -110,13 +111,61 @@ static int trim_device(int i) return 0; } +static bool is_wiped_device(int i) +{ +#ifdef WITH_ANDROID + struct device_info *dev = c.devices + i; + int fd = dev->fd; + char *buf, *zero_buf; + bool wiped = true; + int nblocks = 4096; /* 16MB size */ + int j; + + buf = malloc(F2FS_BLKSIZE); + if (buf == NULL) { + MSG(1, "\tError: Malloc Failed for buf!!!\n"); + return false; + } + zero_buf = calloc(1, F2FS_BLKSIZE); + if (zero_buf == NULL) { + MSG(1, "\tError: Calloc Failed for zero buf!!!\n"); + free(buf); + return false; + } + + if (lseek(fd, 0, SEEK_SET) < 0) { + free(zero_buf); + free(buf); + return false; + } + + /* check first n blocks */ + for (j = 0; j < nblocks; j++) { + if (read(fd, buf, F2FS_BLKSIZE) != F2FS_BLKSIZE || + memcmp(buf, zero_buf, F2FS_BLKSIZE)) { + wiped = false; + break; + } + } + free(zero_buf); + free(buf); + + if (wiped) + MSG(0, "Info: Found all zeros in first %d blocks\n", nblocks); + return wiped; +#else + return false; +#endif +} + int f2fs_trim_devices(void) { int i; - for (i = 0; i < c.ndevs; i++) - if (trim_device(i)) + for (i = 0; i < c.ndevs; i++) { + if (!is_wiped_device(i) && trim_device(i)) return -1; + } c.trimmed = 1; return 0; } |