summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2020-10-21 22:04:11 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2020-10-21 22:04:11 +0000
commit739ca2c2980014e2131bd6494fe1551f2ae8ed81 (patch)
tree05af37a61ada01054e44283cd0e541f31d9f1e80
parent4f5e9c196f22215dfa9f7fb1d061d6da4bcad2fe (diff)
parentcc874804dd4d19686668bab08532565c90f3368d (diff)
downloadvold-739ca2c2980014e2131bd6494fe1551f2ae8ed81.tar.gz
Merge "Set media folder +F for adopted storage as well"
-rw-r--r--Utils.cpp30
-rw-r--r--Utils.h3
-rw-r--r--model/PrivateVolume.cpp5
3 files changed, 35 insertions, 3 deletions
diff --git a/Utils.cpp b/Utils.cpp
index a9b7440f..17921e8e 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -416,7 +416,32 @@ int PrepareAppDirFromRoot(const std::string& path, const std::string& root, int
return OK;
}
-status_t PrepareDir(const std::string& path, mode_t mode, uid_t uid, gid_t gid) {
+int SetAttrs(const std::string& path, unsigned int attrs) {
+ unsigned long flags;
+ android::base::unique_fd fd(
+ TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY | O_NONBLOCK | O_CLOEXEC)));
+
+ if (fd == -1) {
+ PLOG(ERROR) << "Failed to open " << path;
+ return -1;
+ }
+
+ if (ioctl(fd, FS_IOC_GETFLAGS, (void*)&flags)) {
+ PLOG(ERROR) << "Failed to get flags for " << path;
+ return -1;
+ }
+
+ if ((flags & attrs) == attrs) return 0;
+ flags |= attrs;
+ if (ioctl(fd, FS_IOC_SETFLAGS, (void*)&flags)) {
+ PLOG(ERROR) << "Failed to set flags for " << path << "(0x" << std::hex << attrs << ")";
+ return -1;
+ }
+ return 0;
+}
+
+status_t PrepareDir(const std::string& path, mode_t mode, uid_t uid, gid_t gid,
+ unsigned int attrs) {
std::lock_guard<std::mutex> lock(kSecurityLock);
const char* cpath = path.c_str();
@@ -434,6 +459,9 @@ status_t PrepareDir(const std::string& path, mode_t mode, uid_t uid, gid_t gid)
freecon(secontext);
}
+ if (res) return -errno;
+ if (attrs) res = SetAttrs(path, attrs);
+
if (res == 0) {
return OK;
} else {
diff --git a/Utils.h b/Utils.h
index 04cbac4b..5351450a 100644
--- a/Utils.h
+++ b/Utils.h
@@ -67,7 +67,8 @@ int PrepareAppDirFromRoot(const std::string& path, const std::string& root, int
bool fixupExisting);
/* fs_prepare_dir wrapper that creates with SELinux context */
-status_t PrepareDir(const std::string& path, mode_t mode, uid_t uid, gid_t gid);
+status_t PrepareDir(const std::string& path, mode_t mode, uid_t uid, gid_t gid,
+ unsigned int attrs = 0);
/* Really unmounts the path, killing active processes along the way */
status_t ForceUnmount(const std::string& path);
diff --git a/model/PrivateVolume.cpp b/model/PrivateVolume.cpp
index 39a946c1..1875b7b2 100644
--- a/model/PrivateVolume.cpp
+++ b/model/PrivateVolume.cpp
@@ -166,11 +166,14 @@ status_t PrivateVolume::doMount() {
RestoreconRecursive(mPath);
+ int attrs = 0;
+ if (!IsSdcardfsUsed()) attrs = FS_CASEFOLD_FL;
+
// Verify that common directories are ready to roll
if (PrepareDir(mPath + "/app", 0771, AID_SYSTEM, AID_SYSTEM) ||
PrepareDir(mPath + "/user", 0711, AID_SYSTEM, AID_SYSTEM) ||
PrepareDir(mPath + "/user_de", 0711, AID_SYSTEM, AID_SYSTEM) ||
- PrepareDir(mPath + "/media", 0770, AID_MEDIA_RW, AID_MEDIA_RW) ||
+ PrepareDir(mPath + "/media", 0770, AID_MEDIA_RW, AID_MEDIA_RW, attrs) ||
PrepareDir(mPath + "/media/0", 0770, AID_MEDIA_RW, AID_MEDIA_RW) ||
PrepareDir(mPath + "/local", 0751, AID_ROOT, AID_ROOT) ||
PrepareDir(mPath + "/local/tmp", 0771, AID_SHELL, AID_SHELL)) {