diff options
author | Jin Qian | 2017-04-21 16:36:12 -0500 |
---|---|---|
committer | Jin Qian | 2017-07-20 13:42:17 -0500 |
commit | ded2dac082fd703f1cd7a5c3de59450cd3dc2530 (patch) | |
tree | 26e825f0e507b95edb92f3926eb911620fe7a242 /roots.cpp | |
parent | 8155a8ba74bce27626f3ce3f088951298c44776d (diff) | |
download | platform-bootable-recovery-ded2dac082fd703f1cd7a5c3de59450cd3dc2530.tar.gz platform-bootable-recovery-ded2dac082fd703f1cd7a5c3de59450cd3dc2530.tar.xz platform-bootable-recovery-ded2dac082fd703f1cd7a5c3de59450cd3dc2530.zip |
recovery: replace make_ext4 with e2fsprogs
Execute mke2fs to create empty ext4 filesystem.
Execute e2fsdroid to add files to filesystem.
Test: enter recovery mode and wipe data
Bug: 35219933
Change-Id: I10a9f4c1f4754ad864b2df45b1f879180ab33876
(cherry picked from commit ac31808cd37cfb98755e5821dbb2efb5fe5cb12a)
Diffstat (limited to 'roots.cpp')
-rw-r--r-- | roots.cpp | 62 |
1 files changed, 56 insertions, 6 deletions
@@ -27,7 +27,8 @@ | |||
27 | #include <fcntl.h> | 27 | #include <fcntl.h> |
28 | 28 | ||
29 | #include <android-base/logging.h> | 29 | #include <android-base/logging.h> |
30 | #include <ext4_utils/make_ext4fs.h> | 30 | #include <android-base/properties.h> |
31 | #include <android-base/stringprintf.h> | ||
31 | #include <ext4_utils/wipe.h> | 32 | #include <ext4_utils/wipe.h> |
32 | #include <fs_mgr.h> | 33 | #include <fs_mgr.h> |
33 | 34 | ||
@@ -215,11 +216,60 @@ int format_volume(const char* volume, const char* directory) { | |||
215 | } | 216 | } |
216 | int result; | 217 | int result; |
217 | if (strcmp(v->fs_type, "ext4") == 0) { | 218 | if (strcmp(v->fs_type, "ext4") == 0) { |
218 | if (v->erase_blk_size != 0 && v->logical_blk_size != 0) { | 219 | static constexpr int block_size = 4096; |
219 | result = make_ext4fs_directory_align(v->blk_device, length, volume, sehandle, | 220 | int raid_stride = v->logical_blk_size / block_size; |
220 | directory, v->erase_blk_size, v->logical_blk_size); | 221 | int raid_stripe_width = v->erase_blk_size / block_size; |
221 | } else { | 222 | |
222 | result = make_ext4fs_directory(v->blk_device, length, volume, sehandle, directory); | 223 | // stride should be the max of 8kb and logical block size |
224 | if (v->logical_blk_size != 0 && v->logical_blk_size < 8192) { | ||
225 | raid_stride = 8192 / block_size; | ||
226 | } | ||
227 | |||
228 | const char* mke2fs_argv[] = { "/sbin/mke2fs_static", | ||
229 | "-F", | ||
230 | "-t", | ||
231 | "ext4", | ||
232 | "-b", | ||
233 | nullptr, | ||
234 | nullptr, | ||
235 | nullptr, | ||
236 | nullptr, | ||
237 | nullptr, | ||
238 | nullptr }; | ||
239 | |||
240 | int i = 5; | ||
241 | std::string block_size_str = std::to_string(block_size); | ||
242 | mke2fs_argv[i++] = block_size_str.c_str(); | ||
243 | |||
244 | std::string ext_args; | ||
245 | if (v->erase_blk_size != 0 && v->logical_blk_size != 0) { | ||
246 | ext_args = android::base::StringPrintf("stride=%d,stripe-width=%d", raid_stride, | ||
247 | raid_stripe_width); | ||
248 | mke2fs_argv[i++] = "-E"; | ||
249 | mke2fs_argv[i++] = ext_args.c_str(); | ||
250 | } | ||
251 | |||
252 | mke2fs_argv[i++] = v->blk_device; | ||
253 | |||
254 | std::string size_str = std::to_string(length / block_size); | ||
255 | if (length != 0) { | ||
256 | mke2fs_argv[i++] = size_str.c_str(); | ||
257 | } | ||
258 | |||
259 | result = exec_cmd(mke2fs_argv[0], const_cast<char**>(mke2fs_argv)); | ||
260 | if (result == 0 && directory != nullptr) { | ||
261 | const char* e2fsdroid_argv[] = { "/sbin/e2fsdroid_static", | ||
262 | "-e", | ||
263 | "-S", | ||
264 | "/file_contexts", | ||
265 | "-f", | ||
266 | directory, | ||
267 | "-a", | ||
268 | volume, | ||
269 | v->blk_device, | ||
270 | nullptr }; | ||
271 | |||
272 | result = exec_cmd(e2fsdroid_argv[0], const_cast<char**>(e2fsdroid_argv)); | ||
223 | } | 273 | } |
224 | } else { /* Has to be f2fs because we checked earlier. */ | 274 | } else { /* Has to be f2fs because we checked earlier. */ |
225 | if (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0 && length < 0) { | 275 | if (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0 && length < 0) { |