Keep /sdcard working for shell process when isolated storage is enabled.
This is same as what we are doing as of P, symlinking
"/mnt/user/<user-id>/primary" to primary volume path.
Bug: 111890351
Test: manual
Change-Id: I3bc538401bf56fd6243ce7eca424cc4c9b585974
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
index 2b8f8d4..e744c19 100644
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -358,7 +358,24 @@
return -errno;
}
}
- return mountSandboxesForPrimaryVol(source, userId, packageNames, isPrimaryEmulated);
+ if (mountSandboxesForPrimaryVol(source, userId, packageNames, isPrimaryEmulated) != 0) {
+ return -errno;
+ }
+ // Keep /sdcard working for shell process
+ std::string primarySource(mPrimary->getPath());
+ if (isPrimaryEmulated) {
+ StringAppendF(&primarySource, "/%d", userId);
+ }
+ std::string target(StringPrintf("/mnt/user/%d/primary", userId));
+ if (TEMP_FAILURE_RETRY(unlink(target.c_str()))) {
+ if (errno != ENOENT) {
+ PLOG(WARNING) << "Failed to unlink " << target;
+ }
+ }
+ if (TEMP_FAILURE_RETRY(symlink(primarySource.c_str(), target.c_str()))) {
+ PLOG(WARNING) << "Failed to link " << primarySource << " at " << target;
+ return -errno;
+ }
} else {
std::string source(mPrimary->getPath());
if (mPrimary->getType() == android::vold::VolumeBase::Type::kEmulated) {
@@ -396,10 +413,14 @@
return -errno;
}
- std::string segment = StringPrintf("%d/package/", userId);
- std::string mntTargetRoot = prepareSubDirs("/mnt/user", segment.c_str(),
- 0700, AID_ROOT, AID_ROOT);
- if (mntTargetRoot.empty()) {
+ std::string mntTargetRoot = StringPrintf("/mnt/user/%d", userId);
+ if (fs_prepare_dir(mntTargetRoot.c_str(), 0751, AID_ROOT, AID_ROOT) != 0) {
+ PLOG(ERROR) << "fs_prepare_dir failed on " << mntTargetRoot;
+ return -errno;
+ }
+ mntTargetRoot.append("/package");
+ if (fs_prepare_dir(mntTargetRoot.c_str(), 0700, AID_ROOT, AID_ROOT) != 0) {
+ PLOG(ERROR) << "fs_prepare_dir failed on " << mntTargetRoot;
return -errno;
}