diff options
author | Martijn Coenen <maco@google.com> | 2020-11-19 10:49:45 +0100 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2020-11-19 15:27:55 +0000 |
commit | d6a612ac209d810ae421628564f1aa83e9c1016a (patch) | |
tree | 887ed035fb5f1276f30103dcd6652b06dcc7e97b | |
parent | dfd36fe6b6958c0351d56a100c52d2a69f91036e (diff) | |
download | vold-d6a612ac209d810ae421628564f1aa83e9c1016a.tar.gz |
Convert to lower fs path for createObb().
Since /storage/emulated/userId isn't accessible for users != userId,
and vold should anyway try to avoid accessing the FUSE filesystem itself.
Bug: 172078780
Test: atest StorageManagerTest --user-type secondary_user
Change-Id: I98222bf844a6b7d8ec0d9873eddc71f61aa68c90
-rw-r--r-- | VolumeManager.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/VolumeManager.cpp b/VolumeManager.cpp index fb88fa45..f0fc3887 100644 --- a/VolumeManager.cpp +++ b/VolumeManager.cpp @@ -1056,8 +1056,42 @@ int VolumeManager::createObb(const std::string& sourcePath, const std::string& s int32_t ownerGid, std::string* outVolId) { int id = mNextObbId++; + std::string lowerSourcePath; + + // Convert to lower filesystem path + if (StartsWith(sourcePath, "/storage/")) { + auto filter_fn = [&](const VolumeBase& vol) { + if (vol.getState() != VolumeBase::State::kMounted) { + // The volume must be mounted + return false; + } + if ((vol.getMountFlags() & VolumeBase::MountFlags::kVisible) == 0) { + // and visible + return false; + } + if (vol.getInternalPath().empty()) { + return false; + } + if (!sourcePath.empty() && StartsWith(sourcePath, vol.getPath())) { + return true; + } + + return false; + }; + auto volume = findVolumeWithFilter(filter_fn); + if (volume == nullptr) { + LOG(ERROR) << "Failed to find mounted volume for " << sourcePath; + return -EINVAL; + } else { + lowerSourcePath = + volume->getInternalPath() + sourcePath.substr(volume->getPath().length()); + } + } else { + lowerSourcePath = sourcePath; + } + auto vol = std::shared_ptr<android::vold::VolumeBase>( - new android::vold::ObbVolume(id, sourcePath, sourceKey, ownerGid)); + new android::vold::ObbVolume(id, lowerSourcePath, sourceKey, ownerGid)); vol->create(); mObbVolumes.push_back(vol); |