diff --git a/extendedcommands.c b/extendedcommands.c index a96ce27..6b26d27 100644 --- a/extendedcommands.c +++ b/extendedcommands.c @@ -412,47 +412,6 @@ int confirm_selection(const char* title, const char* confirm) #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) { LOGI("Formatting unknown device.\n"); diff --git a/mmcutils/mmcutils.c b/mmcutils/mmcutils.c index de66090..7e283ef 100644 --- a/mmcutils/mmcutils.c +++ b/mmcutils/mmcutils.c @@ -318,9 +318,7 @@ run_exec_process ( char **argv) { } int -mmc_format_ext3 (MmcPartition *partition) { - char device[128]; - strcpy(device, partition->device_index); +format_ext3_device (const char *device) { // Run mke2fs char *const mke2fs[] = {MKE2FS_BIN, "-j", device, NULL}; if(run_exec_process(mke2fs)) @@ -339,6 +337,33 @@ mmc_format_ext3 (MmcPartition *partition) { return 0; } +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 +mmc_format_ext3 (MmcPartition *partition) { + char device[128]; + strcpy(device, partition->device_index); + return format_ext3_device(device); +} + int mmc_mount_partition(const MmcPartition *partition, const char *mount_point, int read_only) diff --git a/mmcutils/mmcutils.h b/mmcutils/mmcutils.h index 64e5813..5b10fdc 100644 --- a/mmcutils/mmcutils.h +++ b/mmcutils/mmcutils.h @@ -83,6 +83,9 @@ int mmc_raw_copy (const MmcPartition *partition, char *in_file); int mmc_raw_read (const MmcPartition *partition, char *data, int data_size); int mmc_raw_write (const MmcPartition *partition, char *data, int data_size); +int format_ext2_device(const char *device); +int format_ext3_device(const char *device); + #endif // MMCUTILS_H_ diff --git a/updater/install.c b/updater/install.c index 7f6a991..d23ec64 100644 --- a/updater/install.c +++ b/updater/install.c @@ -243,6 +243,24 @@ Value* FormatFn(const char* name, State* state, int argc, Expr* argv[]) { } result = location; #endif + } else if (strcmp(fs_type, "ext2") == 0) { + int status = format_ext2_device(location); + if (status != 0) { + fprintf(stderr, "%s: format_ext2_device failed (%d) on %s", + name, status, location); + result = strdup(""); + goto done; + } + result = location; + } else if (strcmp(fs_type, "ext3") == 0) { + int status = format_ext3_device(location); + if (status != 0) { + fprintf(stderr, "%s: format_ext3_device failed (%d) on %s", + name, status, location); + result = strdup(""); + goto done; + } + result = location; } else { fprintf(stderr, "%s: unsupported fs_type \"%s\" partition_type \"%s\"", name, fs_type, partition_type);