|
|
|
@ -26,8 +26,8 @@
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/sysmacros.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
@ -79,11 +79,10 @@ static const unsigned int kMajorBlockMmc = 179;
|
|
|
|
|
static const unsigned int kMajorBlockExperimentalMin = 240;
|
|
|
|
|
static const unsigned int kMajorBlockExperimentalMax = 254;
|
|
|
|
|
|
|
|
|
|
VolumeManager *VolumeManager::sInstance = NULL;
|
|
|
|
|
VolumeManager* VolumeManager::sInstance = NULL;
|
|
|
|
|
|
|
|
|
|
VolumeManager *VolumeManager::Instance() {
|
|
|
|
|
if (!sInstance)
|
|
|
|
|
sInstance = new VolumeManager();
|
|
|
|
|
VolumeManager* VolumeManager::Instance() {
|
|
|
|
|
if (!sInstance) sInstance = new VolumeManager();
|
|
|
|
|
return sInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -95,8 +94,7 @@ VolumeManager::VolumeManager() {
|
|
|
|
|
mSecureKeyguardShowing = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VolumeManager::~VolumeManager() {
|
|
|
|
|
}
|
|
|
|
|
VolumeManager::~VolumeManager() {}
|
|
|
|
|
|
|
|
|
|
int VolumeManager::updateVirtualDisk() {
|
|
|
|
|
ATRACE_NAME("VolumeManager::updateVirtualDisk");
|
|
|
|
@ -117,7 +115,8 @@ int VolumeManager::updateVirtualDisk() {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto disk = new android::vold::Disk("virtual", buf.st_rdev, "virtual",
|
|
|
|
|
auto disk = new android::vold::Disk(
|
|
|
|
|
"virtual", buf.st_rdev, "virtual",
|
|
|
|
|
android::vold::Disk::Flags::kAdoptable | android::vold::Disk::Flags::kSd);
|
|
|
|
|
mVirtualDisk = std::shared_ptr<android::vold::Disk>(disk);
|
|
|
|
|
handleDiskAdded(mVirtualDisk);
|
|
|
|
@ -173,17 +172,17 @@ int VolumeManager::stop() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VolumeManager::handleBlockEvent(NetlinkEvent *evt) {
|
|
|
|
|
void VolumeManager::handleBlockEvent(NetlinkEvent* evt) {
|
|
|
|
|
std::lock_guard<std::mutex> lock(mLock);
|
|
|
|
|
|
|
|
|
|
if (mDebug) {
|
|
|
|
|
LOG(VERBOSE) << "----------------";
|
|
|
|
|
LOG(VERBOSE) << "handleBlockEvent with action " << (int) evt->getAction();
|
|
|
|
|
LOG(VERBOSE) << "handleBlockEvent with action " << (int)evt->getAction();
|
|
|
|
|
evt->dump();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string eventPath(evt->findParam("DEVPATH")?evt->findParam("DEVPATH"):"");
|
|
|
|
|
std::string devType(evt->findParam("DEVTYPE")?evt->findParam("DEVTYPE"):"");
|
|
|
|
|
std::string eventPath(evt->findParam("DEVPATH") ? evt->findParam("DEVPATH") : "");
|
|
|
|
|
std::string devType(evt->findParam("DEVTYPE") ? evt->findParam("DEVTYPE") : "");
|
|
|
|
|
|
|
|
|
|
if (devType != "disk") return;
|
|
|
|
|
|
|
|
|
@ -199,17 +198,16 @@ void VolumeManager::handleBlockEvent(NetlinkEvent *evt) {
|
|
|
|
|
// emulator-specific; see Disk.cpp for details) devices are SD,
|
|
|
|
|
// and that everything else is USB
|
|
|
|
|
int flags = source->getFlags();
|
|
|
|
|
if (major == kMajorBlockMmc
|
|
|
|
|
|| (android::vold::IsRunningInEmulator()
|
|
|
|
|
&& major >= (int) kMajorBlockExperimentalMin
|
|
|
|
|
&& major <= (int) kMajorBlockExperimentalMax)) {
|
|
|
|
|
if (major == kMajorBlockMmc || (android::vold::IsRunningInEmulator() &&
|
|
|
|
|
major >= (int)kMajorBlockExperimentalMin &&
|
|
|
|
|
major <= (int)kMajorBlockExperimentalMax)) {
|
|
|
|
|
flags |= android::vold::Disk::Flags::kSd;
|
|
|
|
|
} else {
|
|
|
|
|
flags |= android::vold::Disk::Flags::kUsb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto disk = new android::vold::Disk(eventPath, device,
|
|
|
|
|
source->getNickname(), flags);
|
|
|
|
|
auto disk =
|
|
|
|
|
new android::vold::Disk(eventPath, device, source->getNickname(), flags);
|
|
|
|
|
handleDiskAdded(std::shared_ptr<android::vold::Disk>(disk));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -226,7 +224,7 @@ void VolumeManager::handleBlockEvent(NetlinkEvent *evt) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
LOG(WARNING) << "Unexpected block event action " << (int) evt->getAction();
|
|
|
|
|
LOG(WARNING) << "Unexpected block event action " << (int)evt->getAction();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -312,8 +310,7 @@ std::shared_ptr<android::vold::VolumeBase> VolumeManager::findVolume(const std::
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VolumeManager::listVolumes(android::vold::VolumeBase::Type type,
|
|
|
|
|
std::list<std::string>& list) {
|
|
|
|
|
void VolumeManager::listVolumes(android::vold::VolumeBase::Type type, std::list<std::string>& list) {
|
|
|
|
|
list.clear();
|
|
|
|
|
for (const auto& disk : mDisks) {
|
|
|
|
|
disk->listVolumes(type, list);
|
|
|
|
@ -522,26 +519,22 @@ int VolumeManager::remountUid(uid_t uid, const std::string& mode) {
|
|
|
|
|
// Sane default of no storage visible
|
|
|
|
|
_exit(0);
|
|
|
|
|
}
|
|
|
|
|
if (TEMP_FAILURE_RETRY(mount(storageSource.c_str(), "/storage",
|
|
|
|
|
NULL, MS_BIND | MS_REC, NULL)) == -1) {
|
|
|
|
|
PLOG(ERROR) << "Failed to mount " << storageSource << " for "
|
|
|
|
|
<< de->d_name;
|
|
|
|
|
if (TEMP_FAILURE_RETRY(
|
|
|
|
|
mount(storageSource.c_str(), "/storage", NULL, MS_BIND | MS_REC, NULL)) == -1) {
|
|
|
|
|
PLOG(ERROR) << "Failed to mount " << storageSource << " for " << de->d_name;
|
|
|
|
|
_exit(1);
|
|
|
|
|
}
|
|
|
|
|
if (TEMP_FAILURE_RETRY(mount(NULL, "/storage", NULL,
|
|
|
|
|
MS_REC | MS_SLAVE, NULL)) == -1) {
|
|
|
|
|
PLOG(ERROR) << "Failed to set MS_SLAVE to /storage for "
|
|
|
|
|
<< de->d_name;
|
|
|
|
|
if (TEMP_FAILURE_RETRY(mount(NULL, "/storage", NULL, MS_REC | MS_SLAVE, NULL)) == -1) {
|
|
|
|
|
PLOG(ERROR) << "Failed to set MS_SLAVE to /storage for " << de->d_name;
|
|
|
|
|
_exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mount user-specific symlink helper into place
|
|
|
|
|
userid_t user_id = multiuser_get_user_id(uid);
|
|
|
|
|
std::string userSource(StringPrintf("/mnt/user/%d", user_id));
|
|
|
|
|
if (TEMP_FAILURE_RETRY(mount(userSource.c_str(), "/storage/self",
|
|
|
|
|
NULL, MS_BIND, NULL)) == -1) {
|
|
|
|
|
PLOG(ERROR) << "Failed to mount " << userSource << " for "
|
|
|
|
|
<< de->d_name;
|
|
|
|
|
if (TEMP_FAILURE_RETRY(
|
|
|
|
|
mount(userSource.c_str(), "/storage/self", NULL, MS_BIND, NULL)) == -1) {
|
|
|
|
|
PLOG(ERROR) << "Failed to mount " << userSource << " for " << de->d_name;
|
|
|
|
|
_exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -555,7 +548,7 @@ int VolumeManager::remountUid(uid_t uid, const std::string& mode) {
|
|
|
|
|
TEMP_FAILURE_RETRY(waitpid(child, nullptr, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
next:
|
|
|
|
|
next:
|
|
|
|
|
close(nsFd);
|
|
|
|
|
close(pidFd);
|
|
|
|
|
}
|
|
|
|
@ -680,12 +673,10 @@ static android::status_t mountInNamespace(uid_t uid, int device_fd, const std::s
|
|
|
|
|
"user_id=%d,group_id=%d,"
|
|
|
|
|
"context=\"u:object_r:app_fuse_file:s0\","
|
|
|
|
|
"fscontext=u:object_r:app_fusefs:s0",
|
|
|
|
|
device_fd,
|
|
|
|
|
uid,
|
|
|
|
|
uid);
|
|
|
|
|
device_fd, uid, uid);
|
|
|
|
|
|
|
|
|
|
const int result = TEMP_FAILURE_RETRY(mount(
|
|
|
|
|
"/dev/fuse", path.c_str(), "fuse",
|
|
|
|
|
const int result =
|
|
|
|
|
TEMP_FAILURE_RETRY(mount("/dev/fuse", path.c_str(), "fuse",
|
|
|
|
|
MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts.c_str()));
|
|
|
|
|
if (result != 0) {
|
|
|
|
|
PLOG(ERROR) << "Failed to mount " << path;
|
|
|
|
@ -695,11 +686,8 @@ static android::status_t mountInNamespace(uid_t uid, int device_fd, const std::s
|
|
|
|
|
return android::OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static android::status_t runCommandInNamespace(const std::string& command,
|
|
|
|
|
uid_t uid,
|
|
|
|
|
pid_t pid,
|
|
|
|
|
const std::string& path,
|
|
|
|
|
int device_fd) {
|
|
|
|
|
static android::status_t runCommandInNamespace(const std::string& command, uid_t uid, pid_t pid,
|
|
|
|
|
const std::string& path, int device_fd) {
|
|
|
|
|
if (DEBUG_APPFUSE) {
|
|
|
|
|
LOG(DEBUG) << "Run app fuse command " << command << " for the path " << path
|
|
|
|
|
<< " in namespace " << uid;
|
|
|
|
@ -713,8 +701,7 @@ static android::status_t runCommandInNamespace(const std::string& command,
|
|
|
|
|
|
|
|
|
|
// Obtains process file descriptor.
|
|
|
|
|
const std::string pid_str = android::base::StringPrintf("%d", pid);
|
|
|
|
|
const unique_fd pid_fd(
|
|
|
|
|
openat(dir.get(), pid_str.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC));
|
|
|
|
|
const unique_fd pid_fd(openat(dir.get(), pid_str.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC));
|
|
|
|
|
if (pid_fd.get() == -1) {
|
|
|
|
|
PLOG(ERROR) << "Failed to open /proc/" << pid;
|
|
|
|
|
return -errno;
|
|
|
|
@ -739,8 +726,8 @@ static android::status_t runCommandInNamespace(const std::string& command,
|
|
|
|
|
{
|
|
|
|
|
std::string rootName;
|
|
|
|
|
std::string pidName;
|
|
|
|
|
if (!android::vold::Readlinkat(dir.get(), "1/ns/mnt", &rootName)
|
|
|
|
|
|| !android::vold::Readlinkat(pid_fd.get(), "ns/mnt", &pidName)) {
|
|
|
|
|
if (!android::vold::Readlinkat(dir.get(), "1/ns/mnt", &rootName) ||
|
|
|
|
|
!android::vold::Readlinkat(pid_fd.get(), "ns/mnt", &pidName)) {
|
|
|
|
|
PLOG(ERROR) << "Failed to read namespaces";
|
|
|
|
|
return -EPERM;
|
|
|
|
|
}
|
|
|
|
@ -769,8 +756,8 @@ static android::status_t runCommandInNamespace(const std::string& command,
|
|
|
|
|
} else if (command == "unmount") {
|
|
|
|
|
// If it's just after all FD opened on mount point are closed, umount2 can fail with
|
|
|
|
|
// EBUSY. To avoid the case, specify MNT_DETACH.
|
|
|
|
|
if (umount2(path.c_str(), UMOUNT_NOFOLLOW | MNT_DETACH) != 0 &&
|
|
|
|
|
errno != EINVAL && errno != ENOENT) {
|
|
|
|
|
if (umount2(path.c_str(), UMOUNT_NOFOLLOW | MNT_DETACH) != 0 && errno != EINVAL &&
|
|
|
|
|
errno != ENOENT) {
|
|
|
|
|
PLOG(ERROR) << "Failed to unmount directory.";
|
|
|
|
|
_exit(-errno);
|
|
|
|
|
}
|
|
|
|
|