From da32b54f85065fd9d68e234571f1208369069463 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sat, 1 Jan 2011 17:55:22 -0800 Subject: [PATCH] readd ext2/ext3 format support. Change-Id: I58652abaea8f7a52b70bc1b14aec5b530fe70382 --- extendedcommands.c | 63 ++++++++++++++++++++++++++++++++++++++++++++- extendedcommands.h | 3 +-- mmcutils/mmcutils.c | 2 +- roots.c | 3 ++- 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/extendedcommands.c b/extendedcommands.c index d9589a4..a6db1d5 100644 --- a/extendedcommands.c +++ b/extendedcommands.c @@ -390,8 +390,69 @@ int confirm_selection(const char* title, const char* confirm) return chosen_item == 7; } -int format_unknown_device(const char* path) +#define MKE2FS_BIN "/sbin/mke2fs" +#define TUNE2FS_BIN "/sbin/tune2fs" +#define E2FSCK_BIN "/sbin/e2fsck" + +static int +format_ext3_device (const char *device) { + // Run mke2fs + char *const mke2fs[] = {MKE2FS_BIN, "-j", device, NULL}; + if(run_exec_process(mke2fs)) + return -1; + + // Run tune2fs + char *const tune2fs[] = {TUNE2FS_BIN, "-j", "-C", "1", device, NULL}; + if(run_exec_process(tune2fs)) + return -1; + + // Run e2fsck + char *const e2fsck[] = {E2FSCK_BIN, "-fy", device, NULL}; + if(run_exec_process(e2fsck)) + return -1; + + return 0; +} + +static int +format_ext2_device (const char *device) { + // Run mke2fs + char *const mke2fs[] = {MKE2FS_BIN, device, NULL}; + if(run_exec_process(mke2fs)) + return -1; + + // Run tune2fs + char *const tune2fs[] = {TUNE2FS_BIN, "-C", "1", device, NULL}; + if(run_exec_process(tune2fs)) + return -1; + + // Run e2fsck + char *const e2fsck[] = {E2FSCK_BIN, "-fy", device, NULL}; + if(run_exec_process(e2fsck)) + return -1; + + return 0; +} + + +int format_unknown_device(const char *device, const char* path, const char *fs_type) { + // device may simply be a name, like "system" + if (device[0] != '/') + return erase_partition(device, fs_type); + + if (strcmp("ext3", device) == 0) { + if (0 != ensure_path_unmounted(path)) + return -11; + return format_ext3_device(device); + } + + if (strcmp("ext2", device) == 0) { + if (0 != ensure_path_unmounted(path)) + return -12; + return format_ext2_device(device); + } + // if this is SDEXT:, don't worry about it. if (0 == strcmp(path, "/sd-ext")) { diff --git a/extendedcommands.h b/extendedcommands.h index e9d7cc4..9297f83 100644 --- a/extendedcommands.h +++ b/extendedcommands.h @@ -37,8 +37,7 @@ __system(const char *command); void show_advanced_menu(); -int -format_unknown_device(const char* root); +int format_unknown_device(const char *device, const char* path, const char *fs_type); void wipe_battery_stats(); diff --git a/mmcutils/mmcutils.c b/mmcutils/mmcutils.c index 44fdcf2..de66090 100644 --- a/mmcutils/mmcutils.c +++ b/mmcutils/mmcutils.c @@ -299,7 +299,7 @@ mmc_find_partition_by_name(const char *name) #define TUNE2FS_BIN "/sbin/tune2fs" #define E2FSCK_BIN "/sbin/e2fsck" -static int +int run_exec_process ( char **argv) { pid_t pid; int status; diff --git a/roots.c b/roots.c index 45e0727..61c7498 100644 --- a/roots.c +++ b/roots.c @@ -217,7 +217,8 @@ int format_volume(const char* volume) { LOGE("can't give path \"%s\" to format_volume\n", volume); return -1; #endif - return format_unknown_device(volume); + printf("Formatting volume %s of fs type %s\n", volume, v->fs_type); + return format_unknown_device(v->device, volume, v->fs_type); } if (ensure_path_unmounted(volume) != 0) {