aboutsummaryrefslogtreecommitdiffstats
path: root/roots.c
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 /roots.c
parente491f80accc0ddb2c925df18d2b796968e48bb71 (diff)
downloadandroid_bootable_recovery-407183abda027c35b35d4ac7ac43745e70ed1ffa.tar.gz
android_bootable_recovery-407183abda027c35b35d4ac7ac43745e70ed1ffa.tar.bz2
android_bootable_recovery-407183abda027c35b35d4ac7ac43745e70ed1ffa.zip
support datamedia on any one volume
Change-Id: I198e789ee01e8a5b10eee33ed59a2d828cfb096a
Diffstat (limited to 'roots.c')
-rw-r--r--roots.c67
1 files changed, 43 insertions, 24 deletions
diff --git a/roots.c b/roots.c
index ea97c7a0..917af0b0 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) {