Set media folder +F for adopted storage as well
We previously only set +F for /data/media, but adopted storage needs this as well. Instead we add support for adding attrs to PrepareDir. Bug: 163453310 Test: sm set-virtual-disk true follow UI setup and confirm +F on /mnt/expand/*/media Change-Id: I08f13b57a4de3538e88b38eb95b0ac115a5a5ce8 Merged-In: I08f13b57a4de3538e88b38eb95b0ac115a5a5ce8
This commit is contained in:
parent
8671044a64
commit
cc874804dd
3 changed files with 35 additions and 3 deletions
30
Utils.cpp
30
Utils.cpp
|
@ -416,7 +416,32 @@ int PrepareAppDirFromRoot(const std::string& path, const std::string& root, int
|
||||||
return OK;
|
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);
|
std::lock_guard<std::mutex> lock(kSecurityLock);
|
||||||
const char* cpath = path.c_str();
|
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);
|
freecon(secontext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (res) return -errno;
|
||||||
|
if (attrs) res = SetAttrs(path, attrs);
|
||||||
|
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
return OK;
|
return OK;
|
||||||
} else {
|
} else {
|
||||||
|
|
3
Utils.h
3
Utils.h
|
@ -67,7 +67,8 @@ int PrepareAppDirFromRoot(const std::string& path, const std::string& root, int
|
||||||
bool fixupExisting);
|
bool fixupExisting);
|
||||||
|
|
||||||
/* fs_prepare_dir wrapper that creates with SELinux context */
|
/* 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 */
|
/* Really unmounts the path, killing active processes along the way */
|
||||||
status_t ForceUnmount(const std::string& path);
|
status_t ForceUnmount(const std::string& path);
|
||||||
|
|
|
@ -166,11 +166,14 @@ status_t PrivateVolume::doMount() {
|
||||||
|
|
||||||
RestoreconRecursive(mPath);
|
RestoreconRecursive(mPath);
|
||||||
|
|
||||||
|
int attrs = 0;
|
||||||
|
if (!IsSdcardfsUsed()) attrs = FS_CASEFOLD_FL;
|
||||||
|
|
||||||
// Verify that common directories are ready to roll
|
// Verify that common directories are ready to roll
|
||||||
if (PrepareDir(mPath + "/app", 0771, AID_SYSTEM, AID_SYSTEM) ||
|
if (PrepareDir(mPath + "/app", 0771, AID_SYSTEM, AID_SYSTEM) ||
|
||||||
PrepareDir(mPath + "/user", 0711, AID_SYSTEM, AID_SYSTEM) ||
|
PrepareDir(mPath + "/user", 0711, AID_SYSTEM, AID_SYSTEM) ||
|
||||||
PrepareDir(mPath + "/user_de", 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 + "/media/0", 0770, AID_MEDIA_RW, AID_MEDIA_RW) ||
|
||||||
PrepareDir(mPath + "/local", 0751, AID_ROOT, AID_ROOT) ||
|
PrepareDir(mPath + "/local", 0751, AID_ROOT, AID_ROOT) ||
|
||||||
PrepareDir(mPath + "/local/tmp", 0771, AID_SHELL, AID_SHELL)) {
|
PrepareDir(mPath + "/local/tmp", 0771, AID_SHELL, AID_SHELL)) {
|
||||||
|
|
Loading…
Reference in a new issue