OSDN Git Service

Move enabling sdcardfs behind a property
authorDaniel Rosenberg <drosen@google.com>
Tue, 12 May 2020 05:58:42 +0000 (22:58 -0700)
committerDaniel Rosenberg <drosen@google.com>
Wed, 20 May 2020 05:11:49 +0000 (22:11 -0700)
This allows devices that have sdcardfs enabled in the kernel to not use
it. When external_storage.sdcardfs.enabled=0, sdcardfs will not be
mounted. This is treated as default true to not affect upgrading
devices. It does not use the old ro.sys.sdcardfs as that has been
repurposed over time and no longer can be relied on to turn off
sdcardfs. This is included within emulated_storage.mk

Bug: 155222498
Test: mount|grep "type sdcardfs" should find nothing after boot complete
      if external_storage.sdcardfs.enabled=0
Change-Id: I23d75fb1225aeabbcb1a035ad62fd042b6b3c7b5

Utils.cpp
Utils.h
VolumeManager.cpp
model/EmulatedVolume.cpp
model/PublicVolume.cpp

index b129990..15a5e49 100644 (file)
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -132,7 +132,7 @@ status_t DestroyDeviceNode(const std::string& path) {
 
 // Sets a default ACL on the directory.
 int SetDefaultAcl(const std::string& path, mode_t mode, uid_t uid, gid_t gid) {
-    if (IsFilesystemSupported("sdcardfs")) {
+    if (IsSdcardfsUsed()) {
         // sdcardfs magically takes care of this
         return OK;
     }
@@ -227,7 +227,7 @@ int PrepareDirWithProjectId(const std::string& path, mode_t mode, uid_t uid, gid
         return ret;
     }
 
-    if (!IsFilesystemSupported("sdcardfs")) {
+    if (!IsSdcardfsUsed()) {
         ret = SetQuotaProjectId(path, projectId);
     }
 
@@ -255,7 +255,7 @@ static int FixupAppDir(const std::string& path, mode_t mode, uid_t uid, gid_t gi
             return ret;
         }
 
-        if (!IsFilesystemSupported("sdcardfs")) {
+        if (!IsSdcardfsUsed()) {
             ret = SetQuotaProjectId(itEntry.path(), projectId);
             if (ret != 0) {
                 return ret;
@@ -271,6 +271,7 @@ int PrepareAppDirFromRoot(const std::string& path, const std::string& root, int
     long projectId;
     size_t pos;
     int ret = 0;
+    bool sdcardfsSupport = IsSdcardfsUsed();
 
     // Make sure the Android/ directories exist and are setup correctly
     ret = PrepareAndroidDirs(root);
@@ -291,17 +292,17 @@ int PrepareAppDirFromRoot(const std::string& path, const std::string& root, int
     // Check that the next part matches one of the allowed Android/ dirs
     if (StartsWith(pathFromRoot, kAppDataDir)) {
         appDir = kAppDataDir;
-        if (!IsFilesystemSupported("sdcardfs")) {
+        if (!sdcardfsSupport) {
             gid = AID_EXT_DATA_RW;
         }
     } else if (StartsWith(pathFromRoot, kAppMediaDir)) {
         appDir = kAppMediaDir;
-        if (!IsFilesystemSupported("sdcardfs")) {
+        if (!sdcardfsSupport) {
             gid = AID_MEDIA_RW;
         }
     } else if (StartsWith(pathFromRoot, kAppObbDir)) {
         appDir = kAppObbDir;
-        if (!IsFilesystemSupported("sdcardfs")) {
+        if (!sdcardfsSupport) {
             gid = AID_EXT_OBB_RW;
         }
     } else {
@@ -368,7 +369,7 @@ int PrepareAppDirFromRoot(const std::string& path, const std::string& root, int
                 return ret;
             }
 
-            if (!IsFilesystemSupported("sdcardfs")) {
+            if (!sdcardfsSupport) {
                 // Set project ID inheritance, so that future subdirectories inherit the
                 // same project ID
                 ret = SetQuotaInherit(pathToCreate);
@@ -943,6 +944,11 @@ bool IsFilesystemSupported(const std::string& fsType) {
     return supported.find(fsType + "\n") != std::string::npos;
 }
 
+bool IsSdcardfsUsed() {
+    return IsFilesystemSupported("sdcardfs") &&
+           base::GetBoolProperty(kExternalStorageSdcardfs, true);
+}
+
 status_t WipeBlockDevice(const std::string& path) {
     status_t res = -1;
     const char* c_path = path.c_str();
@@ -1426,7 +1432,7 @@ status_t MountUserFuse(userid_t user_id, const std::string& absolute_lower_path,
         return -errno;
     }
 
-    if (IsFilesystemSupported("sdcardfs")) {
+    if (IsSdcardfsUsed()) {
         std::string sdcardfs_path(
                 StringPrintf("/mnt/runtime/full/%s", relative_upper_path.c_str()));
 
@@ -1478,7 +1484,7 @@ status_t PrepareAndroidDirs(const std::string& volumeRoot) {
     std::string androidObbDir = volumeRoot + kAppObbDir;
     std::string androidMediaDir = volumeRoot + kAppMediaDir;
 
-    bool useSdcardFs = IsFilesystemSupported("sdcardfs");
+    bool useSdcardFs = IsSdcardfsUsed();
 
     // mode 0771 + sticky bit for inheriting GIDs
     mode_t mode = S_IRWXU | S_IRWXG | S_IXOTH | S_ISGID;
diff --git a/Utils.h b/Utils.h
index e04dcaa..eac3cf4 100644 (file)
--- a/Utils.h
+++ b/Utils.h
@@ -36,6 +36,7 @@ namespace vold {
 
 static const char* kPropFuse = "persist.sys.fuse";
 static const char* kVoldAppDataIsolationEnabled = "persist.sys.vold_app_data_isolation_enabled";
+static const char* kExternalStorageSdcardfs = "external_storage.sdcardfs.enabled";
 
 /* SELinux contexts used depending on the block device type */
 extern security_context_t sBlkidContext;
@@ -124,6 +125,7 @@ uint64_t GetFreeBytes(const std::string& path);
 uint64_t GetTreeBytes(const std::string& path);
 
 bool IsFilesystemSupported(const std::string& fsType);
+bool IsSdcardfsUsed();
 bool IsFuseDaemon(const pid_t pid);
 
 /* Wipes contents of block device at given path */
index f64f5f6..f42f3e7 100644 (file)
@@ -83,6 +83,7 @@ using android::vold::DeleteDirContents;
 using android::vold::DeleteDirContentsAndDir;
 using android::vold::EnsureDirExists;
 using android::vold::IsFilesystemSupported;
+using android::vold::IsSdcardfsUsed;
 using android::vold::IsVirtioBlkDevice;
 using android::vold::PrepareAndroidDirs;
 using android::vold::PrepareAppDirFromRoot;
@@ -780,7 +781,7 @@ static bool remountStorageDirs(int nsFd, const char* android_data_dir, const cha
 
 static std::string getStorageDirSrc(userid_t userId, const std::string& dirName,
         const std::string& packageName) {
-    if (IsFilesystemSupported("sdcardfs")) {
+    if (IsSdcardfsUsed()) {
         return StringPrintf("/mnt/runtime/default/emulated/%d/%s/%s",
                 userId, dirName.c_str(), packageName.c_str());
     } else {
@@ -1049,7 +1050,7 @@ int VolumeManager::setupAppDir(const std::string& path, int32_t appUid, bool fix
 }
 
 int VolumeManager::fixupAppDir(const std::string& path, int32_t appUid) {
-    if (IsFilesystemSupported("sdcardfs")) {
+    if (IsSdcardfsUsed()) {
         //sdcardfs magically does this for us
         return OK;
     }
index e7cd36e..bb5aa86 100644 (file)
@@ -49,7 +49,7 @@ EmulatedVolume::EmulatedVolume(const std::string& rawPath, int userId)
     mRawPath = rawPath;
     mLabel = "emulated";
     mFuseMounted = false;
-    mUseSdcardFs = IsFilesystemSupported("sdcardfs");
+    mUseSdcardFs = IsSdcardfsUsed();
     mAppDataIsolationEnabled = base::GetBoolProperty(kVoldAppDataIsolationEnabled, false);
 }
 
@@ -60,7 +60,7 @@ EmulatedVolume::EmulatedVolume(const std::string& rawPath, dev_t device, const s
     mRawPath = rawPath;
     mLabel = fsUuid;
     mFuseMounted = false;
-    mUseSdcardFs = IsFilesystemSupported("sdcardfs");
+    mUseSdcardFs = IsSdcardfsUsed();
     mAppDataIsolationEnabled = base::GetBoolProperty(kVoldAppDataIsolationEnabled, false);
 }
 
index a0b3227..6195482 100644 (file)
@@ -51,7 +51,7 @@ PublicVolume::PublicVolume(dev_t device) : VolumeBase(Type::kPublic), mDevice(de
     setId(StringPrintf("public:%u,%u", major(device), minor(device)));
     mDevPath = StringPrintf("/dev/block/vold/%s", getId().c_str());
     mFuseMounted = false;
-    mUseSdcardFs = IsFilesystemSupported("sdcardfs");
+    mUseSdcardFs = IsSdcardfsUsed();
 }
 
 PublicVolume::~PublicVolume() {}