Support for ext2 and ext3 update-binary.

Change-Id: Ide34392bd8ac56878aa3e992b275a39d6b6bc7cf
This commit is contained in:
Koushik Dutta 2011-01-02 22:54:31 -08:00
parent 9f52e5f23b
commit b4c5fd6305
4 changed files with 49 additions and 44 deletions

View File

@ -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");

View File

@ -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)

View File

@ -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_

View File

@ -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);