OSDN Git Service

Fix building errors on Android 8.1
[android-x86/system-vold.git] / EmulatedVolume.cpp
index f1ca97b..21b290a 100644 (file)
@@ -17,8 +17,8 @@
 #include "EmulatedVolume.h"
 #include "Utils.h"
 
-#include <base/stringprintf.h>
-#include <base/logging.h>
+#include <android-base/stringprintf.h>
+#include <android-base/logging.h>
 #include <cutils/fs.h>
 #include <private/android_filesystem_config.h>
 
@@ -27,6 +27,7 @@
 #include <sys/mount.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/sysmacros.h>
 #include <sys/wait.h>
 
 using android::base::StringPrintf;
@@ -61,9 +62,9 @@ status_t EmulatedVolume::doMount() {
         label = "emulated";
     }
 
-    mFuseDefault = StringPrintf("/mnt/runtime_default/%s", label.c_str());
-    mFuseRead = StringPrintf("/mnt/runtime_read/%s", label.c_str());
-    mFuseWrite = StringPrintf("/mnt/runtime_write/%s", label.c_str());
+    mFuseDefault = StringPrintf("/mnt/runtime/default/%s", label.c_str());
+    mFuseRead = StringPrintf("/mnt/runtime/read/%s", label.c_str());
+    mFuseWrite = StringPrintf("/mnt/runtime/write/%s", label.c_str());
 
     setInternalPath(mRawPath);
     setPath(StringPrintf("/storage/%s", label.c_str()));
@@ -83,6 +84,7 @@ status_t EmulatedVolume::doMount() {
                 "-g", "1023", // AID_MEDIA_RW
                 "-m",
                 "-w",
+                "-G",
                 mRawPath.c_str(),
                 label.c_str(),
                 NULL)) {
@@ -102,21 +104,28 @@ status_t EmulatedVolume::doMount() {
         LOG(VERBOSE) << "Waiting for FUSE to spin up...";
         usleep(50000); // 50ms
     }
+    /* sdcardfs will have exited already. FUSE will still be running */
+    TEMP_FAILURE_RETRY(waitpid(mFusePid, nullptr, WNOHANG));
 
     return OK;
 }
 
 status_t EmulatedVolume::doUnmount() {
+    // Unmount the storage before we kill the FUSE process. If we kill
+    // the FUSE process first, most file system operations will return
+    // ENOTCONN until the unmount completes. This is an exotic and unusual
+    // error code and might cause broken behaviour in applications.
+    KillProcessesUsingPath(getPath());
+    ForceUnmount(mFuseDefault);
+    ForceUnmount(mFuseRead);
+    ForceUnmount(mFuseWrite);
+
     if (mFusePid > 0) {
         kill(mFusePid, SIGTERM);
         TEMP_FAILURE_RETRY(waitpid(mFusePid, nullptr, 0));
         mFusePid = 0;
     }
 
-    ForceUnmount(mFuseDefault);
-    ForceUnmount(mFuseRead);
-    ForceUnmount(mFuseWrite);
-
     rmdir(mFuseDefault.c_str());
     rmdir(mFuseRead.c_str());
     rmdir(mFuseWrite.c_str());