summaryrefslogtreecommitdiffstats
path: root/roots.cpp
diff options
context:
space:
mode:
authorJin Qian <jinqian@google.com>2017-07-21 21:10:22 +0200
committerandroid-build-merger <android-build-merger@google.com>2017-07-21 21:10:22 +0200
commit7cdc58497becbb1ab38f2c26ec8f5a7bb68f7d11 (patch)
treef71477d34184063bacf632e5e2df409bd7f47f64 /roots.cpp
parentMerge "Fix the android-cloexec-* warnings in bootable/recovery" am: 94a8ea1797 (diff)
parentMerge "recovery: replace make_ext4 with e2fsprogs" (diff)
downloadandroid_bootable_recovery-7cdc58497becbb1ab38f2c26ec8f5a7bb68f7d11.tar
android_bootable_recovery-7cdc58497becbb1ab38f2c26ec8f5a7bb68f7d11.tar.gz
android_bootable_recovery-7cdc58497becbb1ab38f2c26ec8f5a7bb68f7d11.tar.bz2
android_bootable_recovery-7cdc58497becbb1ab38f2c26ec8f5a7bb68f7d11.tar.lz
android_bootable_recovery-7cdc58497becbb1ab38f2c26ec8f5a7bb68f7d11.tar.xz
android_bootable_recovery-7cdc58497becbb1ab38f2c26ec8f5a7bb68f7d11.tar.zst
android_bootable_recovery-7cdc58497becbb1ab38f2c26ec8f5a7bb68f7d11.zip
Diffstat (limited to '')
-rw-r--r--roots.cpp62
1 files changed, 56 insertions, 6 deletions
diff --git a/roots.cpp b/roots.cpp
index 9b4270256..e98dfd448 100644
--- a/roots.cpp
+++ b/roots.cpp
@@ -27,7 +27,8 @@
#include <fcntl.h>
#include <android-base/logging.h>
-#include <ext4_utils/make_ext4fs.h>
+#include <android-base/properties.h>
+#include <android-base/stringprintf.h>
#include <ext4_utils/wipe.h>
#include <fs_mgr.h>
@@ -215,11 +216,60 @@ int format_volume(const char* volume, const char* directory) {
}
int result;
if (strcmp(v->fs_type, "ext4") == 0) {
- if (v->erase_blk_size != 0 && v->logical_blk_size != 0) {
- result = make_ext4fs_directory_align(v->blk_device, length, volume, sehandle,
- directory, v->erase_blk_size, v->logical_blk_size);
- } else {
- result = make_ext4fs_directory(v->blk_device, length, volume, sehandle, directory);
+ static constexpr int block_size = 4096;
+ int raid_stride = v->logical_blk_size / block_size;
+ int raid_stripe_width = v->erase_blk_size / block_size;
+
+ // stride should be the max of 8kb and logical block size
+ if (v->logical_blk_size != 0 && v->logical_blk_size < 8192) {
+ raid_stride = 8192 / block_size;
+ }
+
+ const char* mke2fs_argv[] = { "/sbin/mke2fs_static",
+ "-F",
+ "-t",
+ "ext4",
+ "-b",
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr };
+
+ int i = 5;
+ std::string block_size_str = std::to_string(block_size);
+ mke2fs_argv[i++] = block_size_str.c_str();
+
+ std::string ext_args;
+ if (v->erase_blk_size != 0 && v->logical_blk_size != 0) {
+ ext_args = android::base::StringPrintf("stride=%d,stripe-width=%d", raid_stride,
+ raid_stripe_width);
+ mke2fs_argv[i++] = "-E";
+ mke2fs_argv[i++] = ext_args.c_str();
+ }
+
+ mke2fs_argv[i++] = v->blk_device;
+
+ std::string size_str = std::to_string(length / block_size);
+ if (length != 0) {
+ mke2fs_argv[i++] = size_str.c_str();
+ }
+
+ result = exec_cmd(mke2fs_argv[0], const_cast<char**>(mke2fs_argv));
+ if (result == 0 && directory != nullptr) {
+ const char* e2fsdroid_argv[] = { "/sbin/e2fsdroid_static",
+ "-e",
+ "-S",
+ "/file_contexts",
+ "-f",
+ directory,
+ "-a",
+ volume,
+ v->blk_device,
+ nullptr };
+
+ result = exec_cmd(e2fsdroid_argv[0], const_cast<char**>(e2fsdroid_argv));
}
} else { /* Has to be f2fs because we checked earlier. */
if (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0 && length < 0) {