Support for ext2 and ext3 update-binary.
Change-Id: Ide34392bd8ac56878aa3e992b275a39d6b6bc7cf
diff --git a/extendedcommands.c b/extendedcommands.c
index a96ce27..6b26d27 100644
--- a/extendedcommands.c
+++ b/extendedcommands.c
@@ -412,47 +412,6 @@
#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 @@
}
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))
@@ -340,6 +338,33 @@
}
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_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 @@
}
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);