From 5268131918bc9ffdcd2f82de12778247bf86782e Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Wed, 31 Aug 2011 23:26:45 -0700 Subject: [PATCH] allow explicitly provided mount locations Change-Id: I3930b2abeb81c09c25c1750f0545c233c0d5a4a2 --- roots.c | 25 ++++++++++++++++--------- roots.h | 1 + 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/roots.c b/roots.c index 527fc59..ba1786b 100644 --- a/roots.c +++ b/roots.c @@ -176,6 +176,10 @@ void setup_data_media() { } int ensure_path_mounted(const char* path) { + return ensure_path_mounted_at_mount_point(path, NULL); +} + +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 @@ -202,14 +206,17 @@ int ensure_path_mounted(const char* path) { return -1; } + if (NULL == mount_point) + mount_point = v->mount_point; + const MountedVolume* mv = - find_mounted_volume_by_mount_point(v->mount_point); + find_mounted_volume_by_mount_point(mount_point); if (mv) { // volume is already mounted return 0; } - mkdir(v->mount_point, 0755); // in case it doesn't already exist + mkdir(mount_point, 0755); // in case it doesn't already exist if (strcmp(v->fs_type, "yaffs2") == 0) { // mount an MTD partition as a YAFFS2 filesystem. @@ -218,21 +225,21 @@ int ensure_path_mounted(const char* path) { partition = mtd_find_partition_by_name(v->device); if (partition == NULL) { LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", - v->device, v->mount_point); + v->device, mount_point); return -1; } - return mtd_mount_partition(partition, v->mount_point, v->fs_type, 0); + return mtd_mount_partition(partition, mount_point, v->fs_type, 0); } else if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "ext3") == 0 || strcmp(v->fs_type, "rfs") == 0 || strcmp(v->fs_type, "vfat") == 0) { - if ((result = try_mount(v->device, v->mount_point, v->fs_type, v->fs_options)) == 0) + if ((result = try_mount(v->device, mount_point, v->fs_type, v->fs_options)) == 0) return 0; - if ((result = try_mount(v->device2, v->mount_point, v->fs_type, v->fs_options)) == 0) + if ((result = try_mount(v->device2, mount_point, v->fs_type, v->fs_options)) == 0) return 0; - if ((result = try_mount(v->device, v->mount_point, v->fs_type2, v->fs_options2)) == 0) + if ((result = try_mount(v->device, mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; - if ((result = try_mount(v->device2, v->mount_point, v->fs_type2, v->fs_options2)) == 0) + if ((result = try_mount(v->device2, mount_point, v->fs_type2, v->fs_options2)) == 0) return 0; return result; } else { @@ -242,7 +249,7 @@ int ensure_path_mounted(const char* path) { return __system(mount_cmd); } - LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, v->mount_point); + LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, mount_point); return -1; } diff --git a/roots.h b/roots.h index 7914307..af82280 100644 --- a/roots.h +++ b/roots.h @@ -28,6 +28,7 @@ Volume* volume_for_path(const char* path); // Make sure that the volume 'path' is on is mounted. Returns 0 on // success (volume is mounted). int ensure_path_mounted(const char* path); +int ensure_path_mounted_at_mount_point(const char* path, const char* mount_point); // Make sure that the volume 'path' is on is mounted. Returns 0 on // success (volume is unmounted);