diff options
author | Koushik Dutta <koushd@gmail.com> | 2011-11-16 16:00:35 -0800 |
---|---|---|
committer | Koushik Dutta <koushd@gmail.com> | 2011-11-16 16:00:35 -0800 |
commit | 0df56f4db49c1fde314e1e0b02b32cfc6ceca1dd (patch) | |
tree | b14e75085d72d8a1f8aa2727c847b35dc7910526 /roots.c | |
parent | 88a233d5faa82e51050bdfacfebaf9624b073797 (diff) | |
parent | 441031dadc4f5e8c1487468229781702bc08fb14 (diff) | |
download | android_bootable_recovery-0df56f4db49c1fde314e1e0b02b32cfc6ceca1dd.tar.gz android_bootable_recovery-0df56f4db49c1fde314e1e0b02b32cfc6ceca1dd.tar.bz2 android_bootable_recovery-0df56f4db49c1fde314e1e0b02b32cfc6ceca1dd.zip |
wip
Diffstat (limited to 'roots.c')
-rw-r--r-- | roots.c | 61 |
1 files changed, 43 insertions, 18 deletions
@@ -56,6 +56,28 @@ static char* dupe_string(const char* sz) { return strdup(sz); } +static int parse_options(char* options, Volume* volume) { + char* option; + while (option = strtok(options, ",")) { + options = NULL; + + if (strncmp(option, "length=", 7) == 0) { + volume->length = strtoll(option+7, NULL, 10); + } else if (strncmp(option, "fstype2=", 8) == 0) { + volume->fs_type2 = volume->fs_type; + volume->fs_type = strdup(option); + } else if (strncmp(option, "fs_options=", 11) == 0) { + volume->fs_options = strdup(option); + } else if (strncmp(option, "fs_options2=", 12) == 0) { + volume->fs_options2 = strdup(option); + } else { + LOGE("bad option \"%s\"\n", option); + return -1; + } + } + return 0; +} + void load_volume_table() { int alloc = 2; device_volumes = malloc(alloc * sizeof(Volume)); @@ -65,8 +87,10 @@ void load_volume_table() { device_volumes[0].fs_type = "ramdisk"; device_volumes[0].device = NULL; device_volumes[0].device2 = NULL; + device_volumes[0].fs_type2 = NULL; device_volumes[0].fs_options = NULL; device_volumes[0].fs_options2 = NULL; + device_volumes[0].length = 0; num_volumes = 1; FILE* fstab = fopen("/etc/recovery.fstab", "r"); @@ -88,10 +112,16 @@ void load_volume_table() { char* device = strtok(NULL, " \t\n"); // lines may optionally have a second device, to use if // mounting the first one fails. + char* options = NULL; char* device2 = strtok(NULL, " \t\n"); - char* fs_type2 = strtok(NULL, " \t\n"); - char* fs_options = strtok(NULL, " \t\n"); - char* fs_options2 = strtok(NULL, " \t\n"); + if (device2) { + if (device2[0] == '/') { + options = strtok(NULL, " \t\n"); + } else { + options = device2; + device2 = NULL; + } + } if (mount_point && fs_type && device) { while (num_volumes >= alloc) { @@ -99,21 +129,17 @@ void load_volume_table() { device_volumes = realloc(device_volumes, alloc*sizeof(Volume)); } device_volumes[num_volumes].mount_point = strdup(mount_point); - device_volumes[num_volumes].fs_type = !is_null(fs_type2) ? strdup(fs_type2) : strdup(fs_type); + device_volumes[num_volumes].fs_type = strdup(fs_type); device_volumes[num_volumes].device = strdup(device); device_volumes[num_volumes].device2 = - !is_null(device2) ? strdup(device2) : NULL; - device_volumes[num_volumes].fs_type2 = !is_null(fs_type2) ? strdup(fs_type) : NULL; + device2 ? strdup(device2) : NULL; - if (!is_null(fs_type2)) { - device_volumes[num_volumes].fs_options2 = dupe_string(fs_options); - device_volumes[num_volumes].fs_options = dupe_string(fs_options2); - } - else { - device_volumes[num_volumes].fs_options2 = NULL; - device_volumes[num_volumes].fs_options = dupe_string(fs_options); + device_volumes[num_volumes].length = 0; + if (parse_options(options, device_volumes + num_volumes) != 0) { + LOGE("skipping malformed recovery.fstab line: %s\n", original); + } else { + ++num_volumes; } - ++num_volumes; } else { LOGE("skipping malformed recovery.fstab line: %s\n", original); } @@ -126,8 +152,8 @@ void load_volume_table() { printf("=========================\n"); for (i = 0; i < num_volumes; ++i) { Volume* v = &device_volumes[i]; - printf(" %d %s %s %s %s\n", i, v->mount_point, v->fs_type, - v->device, v->device2); + printf(" %d %s %s %s %s %lld\n", i, v->mount_point, v->fs_type, + v->device, v->device2, v->length); } printf("\n"); } @@ -345,8 +371,7 @@ int format_volume(const char* volume) { } if (strcmp(v->fs_type, "ext4") == 0) { - reset_ext4fs_info(); - int result = make_ext4fs(v->device, NULL, NULL, 0, 0, 0); + int result = make_ext4fs(v->device, v->length); if (result != 0) { LOGE("format_volume: make_extf4fs failed on %s\n", v->device); return -1; |