diff options
author | Jaegeuk Kim <jaegeuk@google.com> | 2019-02-14 16:54:46 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-02-14 16:54:46 +0000 |
commit | ac80c040c19219aa802ee7560de5f8546bb7d1e0 (patch) | |
tree | 40ddec91b8ddd81416bc74d3c5ac53e0b807ae8c /ext4_utils | |
parent | 66d0149f5e724e1d9217a2f38bc78608b576580a (diff) | |
parent | a2df793a48e7aebc45ed8cc2ef487d30203c4c40 (diff) | |
download | extras-ac80c040c19219aa802ee7560de5f8546bb7d1e0.tar.gz |
Merge changes from topic "wipe"
* changes:
wipe: guarantee zeros after wipe out partitions
ext4_utils: build by C++
Diffstat (limited to 'ext4_utils')
-rw-r--r-- | ext4_utils/Android.bp | 9 | ||||
-rw-r--r-- | ext4_utils/blk_alloc_to_base_fs.cpp (renamed from ext4_utils/blk_alloc_to_base_fs.c) | 0 | ||||
-rw-r--r-- | ext4_utils/ext4_sb.cpp (renamed from ext4_utils/ext4_sb.c) | 0 | ||||
-rw-r--r-- | ext4_utils/ext4_utils.cpp (renamed from ext4_utils/ext4_utils.c) | 12 | ||||
-rw-r--r-- | ext4_utils/wipe.cpp (renamed from ext4_utils/wipe.c) | 9 |
5 files changed, 20 insertions, 10 deletions
diff --git a/ext4_utils/Android.bp b/ext4_utils/Android.bp index 92a24e50..e9c5965f 100644 --- a/ext4_utils/Android.bp +++ b/ext4_utils/Android.bp @@ -5,9 +5,9 @@ cc_library { host_supported: true, recovery_available: true, srcs: [ - "ext4_utils.c", - "wipe.c", - "ext4_sb.c", + "ext4_utils.cpp", + "wipe.cpp", + "ext4_sb.cpp", ], // Various instances of dereferencing a type-punned pointer in extent.c cflags: [ @@ -16,6 +16,7 @@ cc_library { ], export_include_dirs: ["include"], shared_libs: [ + "libbase", "libsparse", "libz", ], @@ -80,7 +81,7 @@ prebuilt_etc { cc_binary_host { name: "blk_alloc_to_base_fs", - srcs: ["blk_alloc_to_base_fs.c"], + srcs: ["blk_alloc_to_base_fs.cpp"], shared_libs: ["libcutils"], target: { host: { diff --git a/ext4_utils/blk_alloc_to_base_fs.c b/ext4_utils/blk_alloc_to_base_fs.cpp index 664648d1..664648d1 100644 --- a/ext4_utils/blk_alloc_to_base_fs.c +++ b/ext4_utils/blk_alloc_to_base_fs.cpp diff --git a/ext4_utils/ext4_sb.c b/ext4_utils/ext4_sb.cpp index 5c3e4f3f..5c3e4f3f 100644 --- a/ext4_utils/ext4_sb.c +++ b/ext4_utils/ext4_sb.cpp diff --git a/ext4_utils/ext4_utils.c b/ext4_utils/ext4_utils.cpp index 04e2b6d9..7c411c89 100644 --- a/ext4_utils/ext4_utils.c +++ b/ext4_utils/ext4_utils.cpp @@ -140,7 +140,7 @@ void ext4_create_fs_aux_info() /* A zero-filled superblock to be written firstly to the block * device to mark the file-system as invalid */ - aux_info.sb_zero = calloc(1, info.block_size); + aux_info.sb_zero = (struct ext4_super_block *)calloc(1, info.block_size); if (!aux_info.sb_zero) critical_error_errno("calloc"); @@ -149,7 +149,7 @@ void ext4_create_fs_aux_info() * block on a system with a block size > 1K. So, we need to * deal with that here. */ - aux_info.sb_block = calloc(1, info.block_size); + aux_info.sb_block = (struct ext4_super_block *)calloc(1, info.block_size); if (!aux_info.sb_block) critical_error_errno("calloc"); @@ -159,12 +159,12 @@ void ext4_create_fs_aux_info() aux_info.sb = aux_info.sb_block; /* Alloc an array to hold the pointers to the backup superblocks */ - aux_info.backup_sb = calloc(aux_info.groups, sizeof(char *)); + aux_info.backup_sb = (struct ext4_super_block **)calloc(aux_info.groups, sizeof(char *)); if (!aux_info.sb) critical_error_errno("calloc"); - aux_info.bg_desc = calloc(info.block_size, aux_info.bg_desc_blocks); + aux_info.bg_desc = (struct ext2_group_desc *)calloc(info.block_size, aux_info.bg_desc_blocks); if (!aux_info.bg_desc) critical_error_errno("calloc"); aux_info.xattrs = NULL; @@ -289,13 +289,13 @@ int read_ext(int fd, int verbose) if (verbose) { printf("Found filesystem with parameters:\n"); - printf(" Size: %"PRIu64"\n", info.len); + printf(" Size: %" PRIu64 "\n", info.len); printf(" Block size: %d\n", info.block_size); printf(" Blocks per group: %d\n", info.blocks_per_group); printf(" Inodes per group: %d\n", info.inodes_per_group); printf(" Inode size: %d\n", info.inode_size); printf(" Label: %s\n", info.label); - printf(" Blocks: %"PRIext4u64"\n", aux_info.len_blocks); + printf(" Blocks: %" PRIext4u64 "\n", aux_info.len_blocks); printf(" Block groups: %d\n", aux_info.groups); printf(" Reserved block group size: %d\n", info.bg_desc_reserve_blocks); printf(" Used %d/%d inodes and %d/%d blocks\n", diff --git a/ext4_utils/wipe.c b/ext4_utils/wipe.cpp index 7bda71c1..c2db3353 100644 --- a/ext4_utils/wipe.c +++ b/ext4_utils/wipe.cpp @@ -18,6 +18,8 @@ #include "ext4_utils/ext4_utils.h" +#include <android-base/file.h> + #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; } |