aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--volume_manager/EmulatedVolume.cpp27
-rw-r--r--volume_manager/EmulatedVolume.h1
-rw-r--r--volume_manager/VolumeManager.cpp2
3 files changed, 23 insertions, 7 deletions
diff --git a/volume_manager/EmulatedVolume.cpp b/volume_manager/EmulatedVolume.cpp
index 63e5ca39..96011306 100644
--- a/volume_manager/EmulatedVolume.cpp
+++ b/volume_manager/EmulatedVolume.cpp
@@ -40,7 +40,7 @@ using android::base::StringPrintf;
namespace android {
namespace volmgr {
-static const std::string kStagingPath = "/mnt/staging/emulated";
+static const std::string kStagingPath = "/mnt/staging/emulated/0";
EmulatedVolume::EmulatedVolume(fstab_rec* rec, const std::string& subdir)
: VolumeBase(Type::kEmulated),
@@ -51,18 +51,16 @@ EmulatedVolume::EmulatedVolume(fstab_rec* rec, const std::string& subdir)
mFsOptions(rec->fs_options) {
setId("emulated");
setPartLabel("emulated");
- setPath("/storage/emulated");
+ setPath("/storage/emulated/0");
}
EmulatedVolume::~EmulatedVolume() {}
status_t EmulatedVolume::doMount() {
- if (fs_prepare_dir(kStagingPath.c_str(), 0700, AID_ROOT, AID_ROOT)) {
- PLOG(ERROR) << getId() << " failed to create mount points";
+ if (createMountPointRecursive(kStagingPath, 0700, AID_ROOT, AID_ROOT)) {
return -errno;
}
- if (fs_prepare_dir(getPath().c_str(), 0700, AID_ROOT, AID_ROOT)) {
- PLOG(ERROR) << getId() << " failed to create mount points";
+ if (createMountPointRecursive(getPath(), 0700, AID_ROOT, AID_ROOT)) {
return -errno;
}
@@ -92,5 +90,22 @@ status_t EmulatedVolume::doUnmount(bool detach /* = false */) {
return OK;
}
+int EmulatedVolume::createMountPointRecursive(const std::string& path, mode_t mode, uid_t uid,
+ gid_t gid) {
+ auto pos = path.find("/", 1);
+ while (pos != std::string::npos) {
+ std::string tmp = path.substr(0, pos);
+ mkdir(tmp.c_str(), mode);
+ pos = path.find("/", pos + 1);
+ }
+
+ if (fs_prepare_dir(path.c_str(), mode, uid, gid)) {
+ PLOG(ERROR) << getId() << " failed to create mount point " << path.c_str();
+ return -1;
+ }
+
+ return 0;
+}
+
} // namespace volmgr
} // namespace android
diff --git a/volume_manager/EmulatedVolume.h b/volume_manager/EmulatedVolume.h
index 938db19a..cece26b4 100644
--- a/volume_manager/EmulatedVolume.h
+++ b/volume_manager/EmulatedVolume.h
@@ -46,6 +46,7 @@ class EmulatedVolume : public VolumeBase {
protected:
status_t doMount() override;
status_t doUnmount(bool detach = false) override;
+ int createMountPointRecursive(const std::string&, mode_t, uid_t, gid_t);
private:
std::string mSubdir;
diff --git a/volume_manager/VolumeManager.cpp b/volume_manager/VolumeManager.cpp
index 9351396a..10a3cda4 100644
--- a/volume_manager/VolumeManager.cpp
+++ b/volume_manager/VolumeManager.cpp
@@ -176,7 +176,7 @@ bool VolumeManager::start(VolumeWatcher* watcher) {
}
if (data_rec) {
- mInternalEmulated = new EmulatedVolume(data_rec, "media");
+ mInternalEmulated = new EmulatedVolume(data_rec, "media/0");
mInternalEmulated->create();
}