#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>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/sysmacros.h>
#include <sys/wait.h>
using android::base::StringPrintf;
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()));
"-g", "1023", // AID_MEDIA_RW
"-m",
"-w",
+ "-G",
mRawPath.c_str(),
label.c_str(),
NULL)) {
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());