aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKoushik Dutta <koushd@gmail.com>2012-06-17 20:22:22 -0700
committerKoushik Dutta <koushd@gmail.com>2012-06-17 20:23:11 -0700
commit407183abda027c35b35d4ac7ac43745e70ed1ffa (patch)
tree41973bfe4aed2edf5a787fced019de2463acb6dc
parente491f80accc0ddb2c925df18d2b796968e48bb71 (diff)
downloadbootable_recovery-407183abda027c35b35d4ac7ac43745e70ed1ffa.zip
bootable_recovery-407183abda027c35b35d4ac7ac43745e70ed1ffa.tar.gz
bootable_recovery-407183abda027c35b35d4ac7ac43745e70ed1ffa.tar.bz2
support datamedia on any one volume
Change-Id: I198e789ee01e8a5b10eee33ed59a2d828cfb096a
-rw-r--r--extendedcommands.c11
-rw-r--r--nandroid.c21
-rw-r--r--roots.c67
-rw-r--r--roots.h1
4 files changed, 57 insertions, 43 deletions
diff --git a/extendedcommands.c b/extendedcommands.c
index 845626a..220c976 100644
--- a/extendedcommands.c
+++ b/extendedcommands.c
@@ -444,17 +444,16 @@ int confirm_selection(const char* title, const char* confirm)
int format_device(const char *device, const char *path, const char *fs_type) {
Volume* v = volume_for_path(path);
if (v == NULL) {
- // no /sdcard? let's assume /data/media
- if (strstr(path, "/sdcard") == path && is_data_media()) {
- return format_unknown_device(NULL, path, NULL);
- }
// silent failure for sd-ext
if (strcmp(path, "/sd-ext") == 0)
return -1;
LOGE("unknown volume \"%s\"\n", path);
return -1;
}
- if (strstr(path, "/data") == path && volume_for_path("/sdcard") == NULL && is_data_media()) {
+ if (is_data_media_volume_path(path)) {
+ return format_unknown_device(NULL, path, NULL);
+ }
+ if (strstr(path, "/data") == path && is_data_media()) {
return format_unknown_device(NULL, path, NULL);
}
if (strcmp(fs_type, "ramdisk") == 0) {
@@ -834,7 +833,7 @@ void show_nandroid_menu()
NULL
};
- if (volume_for_path("/emmc") == NULL || volume_for_path("/sdcard") == NULL && is_data_media())
+ if (volume_for_path("/emmc") == NULL)
list[3] = NULL;
int chosen_item = get_menu_selection(headers, list, 0, 0);
diff --git a/nandroid.c b/nandroid.c
index d986457..eb46025 100644
--- a/nandroid.c
+++ b/nandroid.c
@@ -264,12 +264,10 @@ int nandroid_backup(const char* backup_path)
}
Volume* volume = volume_for_path(backup_path);
- if (NULL == volume) {
- if (strstr(backup_path, "/sdcard") == backup_path && is_data_media())
- volume = volume_for_path("/data");
- else
- return print_and_error("Unable to find volume for backup path.\n");
- }
+ if (NULL == volume)
+ return print_and_error("Unable to find volume for backup path.\n");
+ if (is_data_media_volume_path(volume->mount_point))
+ volume = volume_for_path("/data");
int ret;
struct statfs s;
if (NULL != volume) {
@@ -471,22 +469,19 @@ int nandroid_restore_partition_extended(const char* backup_path, const char* mou
}
// If the fs_type of this volume is "auto" or mount_point is /data
- // and is_data_media (redundantly, and vol for /sdcard is NULL), let's revert
+ // and is_data_media, let's revert
// to using a rm -rf, rather than trying to do a
// ext3/ext4/whatever format.
// This is because some phones (like DroidX) will freak out if you
// reformat the /system or /data partitions, and not boot due to
// a locked bootloader.
// Other devices, like the Galaxy Nexus, XOOM, and Galaxy Tab 10.1
- // have a /sdcard symlinked to /data/media. /data is set to "auto"
- // so that when the format occurs, /data/media is not erased.
- // The "auto" fs type preserves the file system, and does not
- // trigger that lock.
+ // have a /sdcard symlinked to /data/media.
// Or of volume does not exist (.android_secure), just rm -rf.
if (vol == NULL || 0 == strcmp(vol->fs_type, "auto"))
backup_filesystem = NULL;
- else if (0 == strcmp(vol->mount_point, "/data") && volume_for_path("/sdcard") == NULL && is_data_media())
- backup_filesystem = NULL;
+ if (0 == strcmp(vol->mount_point, "/data") && is_data_media())
+ backup_filesystem = NULL;
}
ensure_directory(mount_point);
diff --git a/roots.c b/roots.c
index ea97c7a..917af0b 100644
--- a/roots.c
+++ b/roots.c
@@ -196,14 +196,36 @@ int try_mount(const char* device, const char* mount_point, const char* fs_type,
}
int is_data_media() {
- Volume *data = volume_for_path("/data");
- return data != NULL && strcmp(data->fs_type, "auto") == 0 || volume_for_path("/sdcard") == NULL;
+ int i;
+ for (i = 0; i < num_volumes; i++) {
+ Volume* vol = device_volumes + i;
+ if (strcmp(vol->fs_type, "datamedia") == 0)
+ return 1;
+ }
+ return 0;
}
void setup_data_media() {
- rmdir("/sdcard");
- mkdir("/data/media", 0755);
- symlink("/data/media", "/sdcard");
+ int i;
+ for (i = 0; i < num_volumes; i++) {
+ Volume* vol = device_volumes + i;
+ if (strcmp(vol->fs_type, "datamedia") == 0) {
+ rmdir(vol->mount_point);
+ mkdir("/data/media", 0755);
+ symlink("/data/media", vol->mount_point);
+ return;
+ }
+ }
+}
+
+int is_data_media_volume_path(const char* path) {
+ int i;
+ for (i = 0; i < num_volumes; i++) {
+ Volume* vol = device_volumes + i;
+ if (strcmp(vol->fs_type, "datamedia") == 0 && strstr(vol->mount_point, path) == vol->mount_point)
+ return 1;
+ }
+ return 0;
}
int ensure_path_mounted(const char* path) {
@@ -213,18 +235,17 @@ int ensure_path_mounted(const char* path) {
int ensure_path_mounted_at_mount_point(const char* path, const char* mount_point) {
Volume* v = volume_for_path(path);
if (v == NULL) {
- // no /sdcard? let's assume /data/media
- if (strstr(path, "/sdcard") == path && is_data_media()) {
- LOGI("using /data/media, no /sdcard found.\n");
- int ret;
- if (0 != (ret = ensure_path_mounted("/data")))
- return ret;
- setup_data_media();
- return 0;
- }
LOGE("unknown volume for path [%s]\n", path);
return -1;
}
+ if (is_data_media_volume_path(path)) {
+ LOGI("using /data/media for %s.\n", path);
+ int ret;
+ if (0 != (ret = ensure_path_mounted("/data")))
+ return ret;
+ setup_data_media();
+ return 0;
+ }
if (strcmp(v->fs_type, "ramdisk") == 0) {
// the ramdisk is always mounted.
return 0;
@@ -286,19 +307,18 @@ int ensure_path_mounted_at_mount_point(const char* path, const char* mount_point
int ensure_path_unmounted(const char* path) {
// if we are using /data/media, do not ever unmount volumes /data or /sdcard
- if (volume_for_path("/sdcard") == NULL && (strstr(path, "/sdcard") == path || strstr(path, "/data") == path)) {
+ if (strstr(path, "/data") == path && is_data_media()) {
return 0;
}
Volume* v = volume_for_path(path);
if (v == NULL) {
- // no /sdcard? let's assume /data/media
- if (strstr(path, "/sdcard") == path && is_data_media()) {
- return ensure_path_unmounted("/data");
- }
LOGE("unknown volume for path [%s]\n", path);
return -1;
}
+ if (is_data_media_volume_path(path)) {
+ return ensure_path_unmounted("/data");
+ }
if (strcmp(v->fs_type, "ramdisk") == 0) {
// the ramdisk is always mounted; you can't unmount it.
return -1;
@@ -324,19 +344,18 @@ int ensure_path_unmounted(const char* path) {
int format_volume(const char* volume) {
Volume* v = volume_for_path(volume);
if (v == NULL) {
- // no /sdcard? let's assume /data/media
- if (strstr(volume, "/sdcard") == volume && is_data_media()) {
- return format_unknown_device(NULL, volume, NULL);
- }
// silent failure for sd-ext
if (strcmp(volume, "/sd-ext") == 0)
return -1;
LOGE("unknown volume \"%s\"\n", volume);
return -1;
}
+ if (is_data_media_volume_path(volume)) {
+ return format_unknown_device(NULL, volume, NULL);
+ }
// check to see if /data is being formatted, and if it is /data/media
// Note: the /sdcard check is redundant probably, just being safe.
- if (strstr(volume, "/data") == volume && volume_for_path("/sdcard") == NULL && is_data_media()) {
+ if (strstr(volume, "/data") == volume && is_data_media()) {
return format_unknown_device(NULL, volume, NULL);
}
if (strcmp(v->fs_type, "ramdisk") == 0) {
diff --git a/roots.h b/roots.h
index af82280..63aa98f 100644
--- a/roots.h
+++ b/roots.h
@@ -45,5 +45,6 @@ Volume* get_device_volumes();
int is_data_media();
void setup_data_media();
+int is_data_media_volume_path(const char* path);
#endif // RECOVERY_ROOTS_H_