2009-10-11 02:22:08 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-09-22 01:08:43 +02:00
|
|
|
#define ATRACE_TAG ATRACE_TAG_PACKAGE_MANAGER
|
|
|
|
|
2015-01-02 22:28:28 +01:00
|
|
|
#include <dirent.h>
|
2009-10-11 02:22:08 +02:00
|
|
|
#include <errno.h>
|
2009-12-13 19:40:18 +01:00
|
|
|
#include <fcntl.h>
|
2015-01-02 22:28:28 +01:00
|
|
|
#include <mntent.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mount.h>
|
2010-01-06 19:33:53 +01:00
|
|
|
#include <sys/stat.h>
|
2017-05-18 18:08:24 +02:00
|
|
|
#include <sys/sysmacros.h>
|
2018-09-19 00:14:18 +02:00
|
|
|
#include <sys/types.h>
|
2015-06-24 20:49:24 +02:00
|
|
|
#include <sys/wait.h>
|
2015-01-02 22:28:28 +01:00
|
|
|
#include <unistd.h>
|
2010-01-06 19:33:53 +01:00
|
|
|
|
2009-12-13 19:40:18 +01:00
|
|
|
#include <linux/kdev_t.h>
|
2009-10-11 02:22:08 +02:00
|
|
|
|
2015-12-05 00:50:53 +01:00
|
|
|
#include <android-base/logging.h>
|
2017-10-24 02:12:31 +02:00
|
|
|
#include <android-base/parseint.h>
|
2017-10-07 02:02:53 +02:00
|
|
|
#include <android-base/properties.h>
|
2015-12-05 00:50:53 +01:00
|
|
|
#include <android-base/stringprintf.h>
|
2017-10-24 02:12:31 +02:00
|
|
|
#include <android-base/strings.h>
|
|
|
|
|
2013-09-18 02:24:38 +02:00
|
|
|
#include <cutils/fs.h>
|
2017-09-22 01:08:43 +02:00
|
|
|
#include <utils/Trace.h>
|
2009-10-11 02:22:08 +02:00
|
|
|
|
2014-02-04 16:53:00 +01:00
|
|
|
#include <selinux/android.h>
|
|
|
|
|
2009-10-12 20:32:47 +02:00
|
|
|
#include <sysutils/NetlinkEvent.h>
|
|
|
|
|
2012-04-04 02:23:01 +02:00
|
|
|
#include <private/android_filesystem_config.h>
|
|
|
|
|
2018-10-23 22:06:55 +02:00
|
|
|
#include <fscrypt/fscrypt.h>
|
2017-10-24 23:54:43 +02:00
|
|
|
|
2010-01-10 22:02:12 +01:00
|
|
|
#include "Devmapper.h"
|
2018-10-23 22:06:55 +02:00
|
|
|
#include "FsCrypt.h"
|
2017-10-24 23:54:43 +02:00
|
|
|
#include "Loop.h"
|
|
|
|
#include "NetlinkManager.h"
|
2010-02-17 02:12:00 +01:00
|
|
|
#include "Process.h"
|
2017-10-24 23:54:43 +02:00
|
|
|
#include "Utils.h"
|
2015-02-04 05:29:15 +01:00
|
|
|
#include "VoldUtil.h"
|
2017-10-24 23:54:43 +02:00
|
|
|
#include "VolumeManager.h"
|
2011-05-19 02:20:07 +02:00
|
|
|
#include "cryptfs.h"
|
2017-10-24 23:54:43 +02:00
|
|
|
#include "fs/Ext4.h"
|
|
|
|
#include "fs/Vfat.h"
|
|
|
|
#include "model/EmulatedVolume.h"
|
|
|
|
#include "model/ObbVolume.h"
|
2018-10-29 00:52:56 +01:00
|
|
|
#include "model/StubVolume.h"
|
2010-01-09 16:08:06 +01:00
|
|
|
|
2018-09-20 19:09:27 +02:00
|
|
|
using android::base::StartsWith;
|
2015-03-14 00:09:20 +01:00
|
|
|
using android::base::StringPrintf;
|
2017-09-11 18:32:01 +02:00
|
|
|
using android::base::unique_fd;
|
2015-03-14 00:09:20 +01:00
|
|
|
|
2017-03-26 06:49:13 +02:00
|
|
|
static const char* kPathUserMount = "/mnt/user";
|
|
|
|
static const char* kPathVirtualDisk = "/data/misc/vold/virtual_disk";
|
|
|
|
|
|
|
|
static const char* kPropVirtualDisk = "persist.sys.virtual_disk";
|
|
|
|
|
|
|
|
/* 512MiB is large enough for testing purposes */
|
|
|
|
static const unsigned int kSizeVirtualDisk = 536870912;
|
2015-03-14 00:09:20 +01:00
|
|
|
|
|
|
|
static const unsigned int kMajorBlockMmc = 179;
|
2016-01-08 10:36:47 +01:00
|
|
|
static const unsigned int kMajorBlockExperimentalMin = 240;
|
|
|
|
static const unsigned int kMajorBlockExperimentalMax = 254;
|
2015-03-14 00:09:20 +01:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
VolumeManager* VolumeManager::sInstance = NULL;
|
2009-10-11 02:22:08 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
VolumeManager* VolumeManager::Instance() {
|
|
|
|
if (!sInstance) sInstance = new VolumeManager();
|
2009-10-11 02:22:08 +02:00
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
VolumeManager::VolumeManager() {
|
2010-03-12 22:32:47 +01:00
|
|
|
mDebug = false;
|
2017-09-11 18:32:01 +02:00
|
|
|
mNextObbId = 0;
|
2018-10-29 00:52:56 +01:00
|
|
|
mNextStubVolumeId = 0;
|
2017-12-15 06:15:20 +01:00
|
|
|
// For security reasons, assume that a secure keyguard is
|
|
|
|
// showing until we hear otherwise
|
|
|
|
mSecureKeyguardShowing = true;
|
2009-10-11 02:22:08 +02:00
|
|
|
}
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
VolumeManager::~VolumeManager() {}
|
2010-03-12 22:32:47 +01:00
|
|
|
|
2017-03-26 06:49:13 +02:00
|
|
|
int VolumeManager::updateVirtualDisk() {
|
2017-09-22 01:08:43 +02:00
|
|
|
ATRACE_NAME("VolumeManager::updateVirtualDisk");
|
2017-10-07 02:02:53 +02:00
|
|
|
if (android::base::GetBoolProperty(kPropVirtualDisk, false)) {
|
2017-03-26 06:49:13 +02:00
|
|
|
if (access(kPathVirtualDisk, F_OK) != 0) {
|
|
|
|
Loop::createImageFile(kPathVirtualDisk, kSizeVirtualDisk / 512);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mVirtualDisk == nullptr) {
|
|
|
|
if (Loop::create(kPathVirtualDisk, mVirtualDiskPath) != 0) {
|
|
|
|
LOG(ERROR) << "Failed to create virtual disk";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct stat buf;
|
|
|
|
if (stat(mVirtualDiskPath.c_str(), &buf) < 0) {
|
|
|
|
PLOG(ERROR) << "Failed to stat " << mVirtualDiskPath;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
auto disk = new android::vold::Disk(
|
|
|
|
"virtual", buf.st_rdev, "virtual",
|
|
|
|
android::vold::Disk::Flags::kAdoptable | android::vold::Disk::Flags::kSd);
|
2017-03-26 06:49:13 +02:00
|
|
|
mVirtualDisk = std::shared_ptr<android::vold::Disk>(disk);
|
2017-12-15 06:15:20 +01:00
|
|
|
handleDiskAdded(mVirtualDisk);
|
2017-03-26 06:49:13 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (mVirtualDisk != nullptr) {
|
|
|
|
dev_t device = mVirtualDisk->getDevice();
|
2017-12-15 06:15:20 +01:00
|
|
|
handleDiskRemoved(device);
|
2017-03-26 06:49:13 +02:00
|
|
|
|
|
|
|
Loop::destroyByDevice(mVirtualDiskPath.c_str());
|
|
|
|
mVirtualDisk = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (access(kPathVirtualDisk, F_OK) == 0) {
|
|
|
|
unlink(kPathVirtualDisk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-18 02:35:20 +02:00
|
|
|
int VolumeManager::setDebug(bool enable) {
|
2010-03-12 22:32:47 +01:00
|
|
|
mDebug = enable;
|
2015-04-18 02:35:20 +02:00
|
|
|
return 0;
|
2010-03-12 22:32:47 +01:00
|
|
|
}
|
|
|
|
|
2009-10-11 02:22:08 +02:00
|
|
|
int VolumeManager::start() {
|
2017-09-22 01:08:43 +02:00
|
|
|
ATRACE_NAME("VolumeManager::start");
|
|
|
|
|
2015-03-14 00:09:20 +01:00
|
|
|
// Always start from a clean slate by unmounting everything in
|
|
|
|
// directories that we own, in case we crashed.
|
2015-03-31 19:35:33 +02:00
|
|
|
unmountAll();
|
2015-03-14 00:09:20 +01:00
|
|
|
|
2017-09-11 18:32:01 +02:00
|
|
|
Devmapper::destroyAll();
|
|
|
|
Loop::destroyAll();
|
|
|
|
|
2015-03-14 00:09:20 +01:00
|
|
|
// Assume that we always have an emulated volume on internal
|
|
|
|
// storage; the framework will decide if it should be mounted.
|
2015-04-21 21:14:17 +02:00
|
|
|
CHECK(mInternalEmulated == nullptr);
|
2015-03-14 00:09:20 +01:00
|
|
|
mInternalEmulated = std::shared_ptr<android::vold::VolumeBase>(
|
2018-09-19 00:14:18 +02:00
|
|
|
new android::vold::EmulatedVolume("/data/media"));
|
2015-03-14 00:09:20 +01:00
|
|
|
mInternalEmulated->create();
|
|
|
|
|
2017-03-26 06:49:13 +02:00
|
|
|
// Consider creating a virtual disk
|
|
|
|
updateVirtualDisk();
|
|
|
|
|
2009-10-11 02:22:08 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int VolumeManager::stop() {
|
2015-04-21 21:14:17 +02:00
|
|
|
CHECK(mInternalEmulated != nullptr);
|
2015-03-14 00:09:20 +01:00
|
|
|
mInternalEmulated->destroy();
|
|
|
|
mInternalEmulated = nullptr;
|
2009-10-11 02:22:08 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
void VolumeManager::handleBlockEvent(NetlinkEvent* evt) {
|
2015-04-21 21:14:17 +02:00
|
|
|
std::lock_guard<std::mutex> lock(mLock);
|
|
|
|
|
2015-04-18 02:35:20 +02:00
|
|
|
if (mDebug) {
|
2018-09-21 19:54:54 +02:00
|
|
|
LOG(DEBUG) << "----------------";
|
|
|
|
LOG(DEBUG) << "handleBlockEvent with action " << (int)evt->getAction();
|
2015-04-18 02:35:20 +02:00
|
|
|
evt->dump();
|
|
|
|
}
|
2009-10-11 02:22:08 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
std::string eventPath(evt->findParam("DEVPATH") ? evt->findParam("DEVPATH") : "");
|
|
|
|
std::string devType(evt->findParam("DEVTYPE") ? evt->findParam("DEVTYPE") : "");
|
2015-03-14 00:09:20 +01:00
|
|
|
|
|
|
|
if (devType != "disk") return;
|
|
|
|
|
2017-09-19 02:19:28 +02:00
|
|
|
int major = std::stoi(evt->findParam("MAJOR"));
|
|
|
|
int minor = std::stoi(evt->findParam("MINOR"));
|
2015-03-14 00:09:20 +01:00
|
|
|
dev_t device = makedev(major, minor);
|
|
|
|
|
|
|
|
switch (evt->getAction()) {
|
2018-09-19 00:14:18 +02:00
|
|
|
case NetlinkEvent::Action::kAdd: {
|
|
|
|
for (const auto& source : mDiskSources) {
|
|
|
|
if (source->matches(eventPath)) {
|
|
|
|
// For now, assume that MMC and virtio-blk (the latter is
|
|
|
|
// 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)) {
|
|
|
|
flags |= android::vold::Disk::Flags::kSd;
|
|
|
|
} else {
|
|
|
|
flags |= android::vold::Disk::Flags::kUsb;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto disk =
|
|
|
|
new android::vold::Disk(eventPath, device, source->getNickname(), flags);
|
|
|
|
handleDiskAdded(std::shared_ptr<android::vold::Disk>(disk));
|
|
|
|
break;
|
2015-03-14 00:09:20 +01:00
|
|
|
}
|
|
|
|
}
|
2018-09-19 00:14:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NetlinkEvent::Action::kChange: {
|
|
|
|
LOG(DEBUG) << "Disk at " << major << ":" << minor << " changed";
|
|
|
|
handleDiskChanged(device);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NetlinkEvent::Action::kRemove: {
|
|
|
|
handleDiskRemoved(device);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
LOG(WARNING) << "Unexpected block event action " << (int)evt->getAction();
|
|
|
|
break;
|
2015-03-14 00:09:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-11 02:22:08 +02:00
|
|
|
|
2017-12-15 06:15:20 +01:00
|
|
|
void VolumeManager::handleDiskAdded(const std::shared_ptr<android::vold::Disk>& disk) {
|
|
|
|
// For security reasons, if secure keyguard is showing, wait
|
|
|
|
// until the user unlocks the device to actually touch it
|
|
|
|
if (mSecureKeyguardShowing) {
|
|
|
|
LOG(INFO) << "Found disk at " << disk->getEventPath()
|
2018-09-19 00:14:18 +02:00
|
|
|
<< " but delaying scan due to secure keyguard";
|
2017-12-15 06:15:20 +01:00
|
|
|
mPendingDisks.push_back(disk);
|
|
|
|
} else {
|
|
|
|
disk->create();
|
|
|
|
mDisks.push_back(disk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeManager::handleDiskChanged(dev_t device) {
|
|
|
|
for (const auto& disk : mDisks) {
|
|
|
|
if (disk->getDevice() == device) {
|
|
|
|
disk->readMetadata();
|
|
|
|
disk->readPartitions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For security reasons, we ignore all pending disks, since
|
|
|
|
// we'll scan them once the device is unlocked
|
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeManager::handleDiskRemoved(dev_t device) {
|
|
|
|
auto i = mDisks.begin();
|
|
|
|
while (i != mDisks.end()) {
|
|
|
|
if ((*i)->getDevice() == device) {
|
|
|
|
(*i)->destroy();
|
|
|
|
i = mDisks.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto j = mPendingDisks.begin();
|
|
|
|
while (j != mPendingDisks.end()) {
|
|
|
|
if ((*j)->getDevice() == device) {
|
|
|
|
j = mPendingDisks.erase(j);
|
|
|
|
} else {
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-14 00:09:20 +01:00
|
|
|
void VolumeManager::addDiskSource(const std::shared_ptr<DiskSource>& diskSource) {
|
2017-01-20 20:52:33 +01:00
|
|
|
std::lock_guard<std::mutex> lock(mLock);
|
2015-03-14 00:09:20 +01:00
|
|
|
mDiskSources.push_back(diskSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<android::vold::Disk> VolumeManager::findDisk(const std::string& id) {
|
|
|
|
for (auto disk : mDisks) {
|
|
|
|
if (disk->getId() == id) {
|
|
|
|
return disk;
|
|
|
|
}
|
2009-10-11 02:22:08 +02:00
|
|
|
}
|
2015-03-14 00:09:20 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<android::vold::VolumeBase> VolumeManager::findVolume(const std::string& id) {
|
2017-08-14 05:32:13 +02:00
|
|
|
// Vold could receive "mount" after "shutdown" command in the extreme case.
|
|
|
|
// If this happens, mInternalEmulated will equal nullptr and
|
|
|
|
// we need to deal with it in order to avoid null pointer crash.
|
|
|
|
if (mInternalEmulated != nullptr && mInternalEmulated->getId() == id) {
|
2015-03-14 00:09:20 +01:00
|
|
|
return mInternalEmulated;
|
|
|
|
}
|
2016-07-27 23:11:02 +02:00
|
|
|
for (const auto& disk : mDisks) {
|
2015-03-14 00:09:20 +01:00
|
|
|
auto vol = disk->findVolume(id);
|
|
|
|
if (vol != nullptr) {
|
|
|
|
return vol;
|
|
|
|
}
|
|
|
|
}
|
2018-10-29 00:52:56 +01:00
|
|
|
for (const auto& vol : mStubVolumes) {
|
|
|
|
if (vol->getId() == id) {
|
|
|
|
return vol;
|
|
|
|
}
|
|
|
|
}
|
2017-09-11 18:32:01 +02:00
|
|
|
for (const auto& vol : mObbVolumes) {
|
|
|
|
if (vol->getId() == id) {
|
|
|
|
return vol;
|
|
|
|
}
|
|
|
|
}
|
2015-03-14 00:09:20 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
void VolumeManager::listVolumes(android::vold::VolumeBase::Type type, std::list<std::string>& list) {
|
2015-06-26 23:02:09 +02:00
|
|
|
list.clear();
|
2016-07-27 23:11:02 +02:00
|
|
|
for (const auto& disk : mDisks) {
|
2015-06-26 23:02:09 +02:00
|
|
|
disk->listVolumes(type, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-24 19:08:45 +02:00
|
|
|
int VolumeManager::forgetPartition(const std::string& partGuid, const std::string& fsUuid) {
|
2015-06-18 23:25:08 +02:00
|
|
|
std::string normalizedGuid;
|
|
|
|
if (android::vold::NormalizeHex(partGuid, normalizedGuid)) {
|
|
|
|
LOG(WARNING) << "Invalid GUID " << partGuid;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-10-24 23:54:43 +02:00
|
|
|
bool success = true;
|
2015-06-18 23:25:08 +02:00
|
|
|
std::string keyPath = android::vold::BuildKeyPath(normalizedGuid);
|
|
|
|
if (unlink(keyPath.c_str()) != 0) {
|
|
|
|
LOG(ERROR) << "Failed to unlink " << keyPath;
|
2017-10-24 23:54:43 +02:00
|
|
|
success = false;
|
2015-06-18 23:25:08 +02:00
|
|
|
}
|
2018-10-23 22:06:55 +02:00
|
|
|
if (fscrypt_is_native()) {
|
|
|
|
if (!fscrypt_destroy_volume_keys(fsUuid)) {
|
2017-10-24 23:54:43 +02:00
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return success ? 0 : -1;
|
2015-06-18 23:25:08 +02:00
|
|
|
}
|
|
|
|
|
2015-03-14 00:09:20 +01:00
|
|
|
int VolumeManager::linkPrimary(userid_t userId) {
|
|
|
|
std::string source(mPrimary->getPath());
|
|
|
|
if (mPrimary->getType() == android::vold::VolumeBase::Type::kEmulated) {
|
|
|
|
source = StringPrintf("%s/%d", source.c_str(), userId);
|
2015-07-21 23:22:01 +02:00
|
|
|
fs_prepare_dir(source.c_str(), 0755, AID_ROOT, AID_ROOT);
|
2015-03-14 00:09:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string target(StringPrintf("/mnt/user/%d/primary", userId));
|
|
|
|
if (TEMP_FAILURE_RETRY(unlink(target.c_str()))) {
|
|
|
|
if (errno != ENOENT) {
|
2017-10-07 02:02:53 +02:00
|
|
|
PLOG(WARNING) << "Failed to unlink " << target;
|
2015-03-14 00:09:20 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-30 00:22:23 +02:00
|
|
|
LOG(DEBUG) << "Linking " << source << " to " << target;
|
2015-03-14 00:09:20 +01:00
|
|
|
if (TEMP_FAILURE_RETRY(symlink(source.c_str(), target.c_str()))) {
|
2017-10-07 02:02:53 +02:00
|
|
|
PLOG(WARNING) << "Failed to link";
|
2015-03-14 00:09:20 +01:00
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-10 18:42:01 +02:00
|
|
|
int VolumeManager::onUserAdded(userid_t userId, int userSerialNumber) {
|
|
|
|
mAddedUsers[userId] = userSerialNumber;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int VolumeManager::onUserRemoved(userid_t userId) {
|
|
|
|
mAddedUsers.erase(userId);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int VolumeManager::onUserStarted(userid_t userId) {
|
2015-03-14 00:09:20 +01:00
|
|
|
// Note that sometimes the system will spin up processes from Zygote
|
|
|
|
// before actually starting the user, so we're okay if Zygote
|
|
|
|
// already created this directory.
|
2017-03-26 06:49:13 +02:00
|
|
|
std::string path(StringPrintf("%s/%d", kPathUserMount, userId));
|
2015-03-14 00:09:20 +01:00
|
|
|
fs_prepare_dir(path.c_str(), 0755, AID_ROOT, AID_ROOT);
|
|
|
|
|
2015-06-10 18:42:01 +02:00
|
|
|
mStartedUsers.insert(userId);
|
2015-03-14 00:09:20 +01:00
|
|
|
if (mPrimary) {
|
|
|
|
linkPrimary(userId);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-10 18:42:01 +02:00
|
|
|
int VolumeManager::onUserStopped(userid_t userId) {
|
|
|
|
mStartedUsers.erase(userId);
|
2015-03-14 00:09:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-15 06:15:20 +01:00
|
|
|
int VolumeManager::onSecureKeyguardStateChanged(bool isShowing) {
|
|
|
|
mSecureKeyguardShowing = isShowing;
|
|
|
|
if (!mSecureKeyguardShowing) {
|
|
|
|
// Now that secure keyguard has been dismissed, process
|
|
|
|
// any pending disks
|
|
|
|
for (const auto& disk : mPendingDisks) {
|
|
|
|
disk->create();
|
|
|
|
mDisks.push_back(disk);
|
|
|
|
}
|
|
|
|
mPendingDisks.clear();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-14 00:09:20 +01:00
|
|
|
int VolumeManager::setPrimary(const std::shared_ptr<android::vold::VolumeBase>& vol) {
|
|
|
|
mPrimary = vol;
|
2015-06-10 18:42:01 +02:00
|
|
|
for (userid_t userId : mStartedUsers) {
|
2015-03-14 00:09:20 +01:00
|
|
|
linkPrimary(userId);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-24 20:49:24 +02:00
|
|
|
int VolumeManager::remountUid(uid_t uid, const std::string& mode) {
|
|
|
|
LOG(DEBUG) << "Remounting " << uid << " as mode " << mode;
|
|
|
|
|
|
|
|
DIR* dir;
|
|
|
|
struct dirent* de;
|
2017-10-07 02:02:53 +02:00
|
|
|
std::string rootName;
|
|
|
|
std::string pidName;
|
2015-06-24 20:49:24 +02:00
|
|
|
int pidFd;
|
|
|
|
int nsFd;
|
|
|
|
struct stat sb;
|
|
|
|
pid_t child;
|
|
|
|
|
|
|
|
if (!(dir = opendir("/proc"))) {
|
|
|
|
PLOG(ERROR) << "Failed to opendir";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Figure out root namespace to compare against below
|
2017-10-07 02:02:53 +02:00
|
|
|
if (!android::vold::Readlinkat(dirfd(dir), "1/ns/mnt", &rootName)) {
|
|
|
|
PLOG(ERROR) << "Failed to read root namespace";
|
2015-06-24 20:49:24 +02:00
|
|
|
closedir(dir);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Poke through all running PIDs look for apps running as UID
|
|
|
|
while ((de = readdir(dir))) {
|
2017-10-24 02:12:31 +02:00
|
|
|
pid_t pid;
|
|
|
|
if (de->d_type != DT_DIR) continue;
|
|
|
|
if (!android::base::ParseInt(de->d_name, &pid)) continue;
|
|
|
|
|
2015-06-24 20:49:24 +02:00
|
|
|
pidFd = -1;
|
|
|
|
nsFd = -1;
|
|
|
|
|
|
|
|
pidFd = openat(dirfd(dir), de->d_name, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
|
|
|
|
if (pidFd < 0) {
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
if (fstat(pidFd, &sb) != 0) {
|
|
|
|
PLOG(WARNING) << "Failed to stat " << de->d_name;
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
if (sb.st_uid != uid) {
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Matches so far, but refuse to touch if in root namespace
|
|
|
|
LOG(DEBUG) << "Found matching PID " << de->d_name;
|
2017-10-07 02:02:53 +02:00
|
|
|
if (!android::vold::Readlinkat(pidFd, "ns/mnt", &pidName)) {
|
2015-06-24 20:49:24 +02:00
|
|
|
PLOG(WARNING) << "Failed to read namespace for " << de->d_name;
|
|
|
|
goto next;
|
|
|
|
}
|
2017-10-07 02:02:53 +02:00
|
|
|
if (rootName == pidName) {
|
2015-06-24 20:49:24 +02:00
|
|
|
LOG(WARNING) << "Skipping due to root namespace";
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We purposefully leave the namespace open across the fork
|
2018-09-19 00:14:18 +02:00
|
|
|
nsFd = openat(pidFd, "ns/mnt", O_RDONLY); // not O_CLOEXEC
|
2015-06-24 20:49:24 +02:00
|
|
|
if (nsFd < 0) {
|
2015-07-01 00:54:17 +02:00
|
|
|
PLOG(WARNING) << "Failed to open namespace for " << de->d_name;
|
2015-06-24 20:49:24 +02:00
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(child = fork())) {
|
|
|
|
if (setns(nsFd, CLONE_NEWNS) != 0) {
|
2015-07-01 00:54:17 +02:00
|
|
|
PLOG(ERROR) << "Failed to setns for " << de->d_name;
|
2015-06-24 20:49:24 +02:00
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
|
2018-09-27 23:53:51 +02:00
|
|
|
android::vold::UnmountTree("/storage/");
|
2015-06-24 20:49:24 +02:00
|
|
|
|
|
|
|
std::string storageSource;
|
|
|
|
if (mode == "default") {
|
2015-08-06 20:40:00 +02:00
|
|
|
storageSource = "/mnt/runtime/default";
|
2015-06-24 20:49:24 +02:00
|
|
|
} else if (mode == "read") {
|
2015-08-06 20:40:00 +02:00
|
|
|
storageSource = "/mnt/runtime/read";
|
2015-06-24 20:49:24 +02:00
|
|
|
} else if (mode == "write") {
|
2015-08-06 20:40:00 +02:00
|
|
|
storageSource = "/mnt/runtime/write";
|
2015-06-24 20:49:24 +02:00
|
|
|
} else {
|
|
|
|
// Sane default of no storage visible
|
|
|
|
_exit(0);
|
|
|
|
}
|
2018-09-19 00:14:18 +02:00
|
|
|
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;
|
2015-07-01 00:54:17 +02:00
|
|
|
_exit(1);
|
2015-06-24 20:49:24 +02:00
|
|
|
}
|
2018-09-19 00:14:18 +02:00
|
|
|
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;
|
2016-03-09 08:42:10 +01:00
|
|
|
_exit(1);
|
|
|
|
}
|
2015-07-01 00:54:17 +02:00
|
|
|
|
|
|
|
// 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));
|
2018-09-19 00:14:18 +02:00
|
|
|
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;
|
2015-07-01 00:54:17 +02:00
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
|
2015-06-24 20:49:24 +02:00
|
|
|
_exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child == -1) {
|
|
|
|
PLOG(ERROR) << "Failed to fork";
|
|
|
|
goto next;
|
|
|
|
} else {
|
|
|
|
TEMP_FAILURE_RETRY(waitpid(child, nullptr, 0));
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
next:
|
2015-06-24 20:49:24 +02:00
|
|
|
close(nsFd);
|
|
|
|
close(pidFd);
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-14 00:09:20 +01:00
|
|
|
int VolumeManager::reset() {
|
|
|
|
// Tear down all existing disks/volumes and start from a blank slate so
|
|
|
|
// newly connected framework hears all events.
|
2017-08-14 05:32:13 +02:00
|
|
|
if (mInternalEmulated != nullptr) {
|
|
|
|
mInternalEmulated->destroy();
|
|
|
|
mInternalEmulated->create();
|
|
|
|
}
|
2016-07-27 23:11:02 +02:00
|
|
|
for (const auto& disk : mDisks) {
|
2015-03-14 00:09:20 +01:00
|
|
|
disk->destroy();
|
|
|
|
disk->create();
|
|
|
|
}
|
2017-03-26 06:49:13 +02:00
|
|
|
updateVirtualDisk();
|
2015-06-10 18:42:01 +02:00
|
|
|
mAddedUsers.clear();
|
|
|
|
mStartedUsers.clear();
|
2015-03-14 00:09:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-14 02:02:50 +01:00
|
|
|
// Can be called twice (sequentially) during shutdown. should be safe for that.
|
2015-03-14 00:09:20 +01:00
|
|
|
int VolumeManager::shutdown() {
|
2017-03-14 02:02:50 +01:00
|
|
|
if (mInternalEmulated == nullptr) {
|
2018-09-19 00:14:18 +02:00
|
|
|
return 0; // already shutdown
|
2017-03-14 02:02:50 +01:00
|
|
|
}
|
2017-10-20 17:07:53 +02:00
|
|
|
android::vold::sSleepOnUnmount = false;
|
2015-03-31 19:35:33 +02:00
|
|
|
mInternalEmulated->destroy();
|
2017-03-14 02:02:50 +01:00
|
|
|
mInternalEmulated = nullptr;
|
2016-07-27 23:11:02 +02:00
|
|
|
for (const auto& disk : mDisks) {
|
2015-03-14 00:09:20 +01:00
|
|
|
disk->destroy();
|
|
|
|
}
|
2018-10-29 00:52:56 +01:00
|
|
|
mStubVolumes.clear();
|
2015-03-14 00:09:20 +01:00
|
|
|
mDisks.clear();
|
2017-12-15 06:15:20 +01:00
|
|
|
mPendingDisks.clear();
|
2017-10-20 17:07:53 +02:00
|
|
|
android::vold::sSleepOnUnmount = true;
|
2015-03-14 00:09:20 +01:00
|
|
|
return 0;
|
2009-10-11 02:22:08 +02:00
|
|
|
}
|
|
|
|
|
2015-03-31 19:35:33 +02:00
|
|
|
int VolumeManager::unmountAll() {
|
2015-04-21 21:14:17 +02:00
|
|
|
std::lock_guard<std::mutex> lock(mLock);
|
2017-09-22 01:08:43 +02:00
|
|
|
ATRACE_NAME("VolumeManager::unmountAll()");
|
2015-04-21 21:14:17 +02:00
|
|
|
|
2015-03-31 19:35:33 +02:00
|
|
|
// First, try gracefully unmounting all known devices
|
|
|
|
if (mInternalEmulated != nullptr) {
|
|
|
|
mInternalEmulated->unmount();
|
|
|
|
}
|
2018-10-29 00:52:56 +01:00
|
|
|
for (const auto& stub : mStubVolumes) {
|
|
|
|
stub->unmount();
|
|
|
|
}
|
2016-07-27 23:11:02 +02:00
|
|
|
for (const auto& disk : mDisks) {
|
2015-03-31 19:35:33 +02:00
|
|
|
disk->unmountAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Worst case we might have some stale mounts lurking around, so
|
|
|
|
// force unmount those just to be safe.
|
|
|
|
FILE* fp = setmntent("/proc/mounts", "r");
|
|
|
|
if (fp == NULL) {
|
2017-10-07 02:02:53 +02:00
|
|
|
PLOG(ERROR) << "Failed to open /proc/mounts";
|
2015-03-31 19:35:33 +02:00
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some volumes can be stacked on each other, so force unmount in
|
|
|
|
// reverse order to give us the best chance of success.
|
|
|
|
std::list<std::string> toUnmount;
|
|
|
|
mntent* mentry;
|
|
|
|
while ((mentry = getmntent(fp)) != NULL) {
|
2017-10-07 02:02:53 +02:00
|
|
|
auto test = std::string(mentry->mnt_dir);
|
2018-09-20 19:09:27 +02:00
|
|
|
if ((StartsWith(test, "/mnt/") &&
|
|
|
|
#ifdef __ANDROID_DEBUGGABLE__
|
|
|
|
!StartsWith(test, "/mnt/scratch") &&
|
|
|
|
#endif
|
|
|
|
!StartsWith(test, "/mnt/vendor") && !StartsWith(test, "/mnt/product")) ||
|
|
|
|
StartsWith(test, "/storage/")) {
|
2017-10-07 02:02:53 +02:00
|
|
|
toUnmount.push_front(test);
|
2015-03-31 19:35:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
endmntent(fp);
|
|
|
|
|
2016-07-27 23:11:02 +02:00
|
|
|
for (const auto& path : toUnmount) {
|
2017-09-11 18:32:01 +02:00
|
|
|
LOG(DEBUG) << "Tearing down stale mount " << path;
|
2015-03-31 19:35:33 +02:00
|
|
|
android::vold::ForceUnmount(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-07 02:02:53 +02:00
|
|
|
int VolumeManager::mkdirs(const std::string& path) {
|
2015-03-14 00:09:20 +01:00
|
|
|
// Only offer to create directories for paths managed by vold
|
2018-09-20 19:09:27 +02:00
|
|
|
if (StartsWith(path, "/storage/")) {
|
2015-03-14 00:09:20 +01:00
|
|
|
// fs_mkdirs() does symlink checking and relative path enforcement
|
2017-10-07 02:02:53 +02:00
|
|
|
return fs_mkdirs(path.c_str(), 0700);
|
2013-09-18 02:24:38 +02:00
|
|
|
} else {
|
2017-10-07 02:02:53 +02:00
|
|
|
LOG(ERROR) << "Failed to find mounted volume for " << path;
|
2013-09-18 02:24:38 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2017-09-11 18:32:01 +02:00
|
|
|
|
|
|
|
static size_t kAppFuseMaxMountPointName = 32;
|
|
|
|
|
|
|
|
static android::status_t getMountPath(uid_t uid, const std::string& name, std::string* path) {
|
|
|
|
if (name.size() > kAppFuseMaxMountPointName) {
|
|
|
|
LOG(ERROR) << "AppFuse mount name is too long.";
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < name.size(); i++) {
|
|
|
|
if (!isalnum(name[i])) {
|
|
|
|
LOG(ERROR) << "AppFuse mount name contains invalid character.";
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2018-09-20 19:09:27 +02:00
|
|
|
*path = StringPrintf("/mnt/appfuse/%d_%s", uid, name.c_str());
|
2017-09-11 18:32:01 +02:00
|
|
|
return android::OK;
|
|
|
|
}
|
|
|
|
|
2018-10-27 04:56:45 +02:00
|
|
|
static android::status_t mount(int device_fd, const std::string& path) {
|
2017-09-11 18:32:01 +02:00
|
|
|
// Remove existing mount.
|
|
|
|
android::vold::ForceUnmount(path);
|
|
|
|
|
2018-09-20 19:09:27 +02:00
|
|
|
const auto opts = StringPrintf(
|
2018-09-19 00:14:18 +02:00
|
|
|
"fd=%i,"
|
|
|
|
"rootmode=40000,"
|
|
|
|
"default_permissions,"
|
|
|
|
"allow_other,"
|
2018-10-27 04:56:45 +02:00
|
|
|
"user_id=0,group_id=0,"
|
2018-09-19 00:14:18 +02:00
|
|
|
"context=\"u:object_r:app_fuse_file:s0\","
|
|
|
|
"fscontext=u:object_r:app_fusefs:s0",
|
2018-10-27 04:56:45 +02:00
|
|
|
device_fd);
|
2018-09-19 00:14:18 +02:00
|
|
|
|
|
|
|
const int result =
|
|
|
|
TEMP_FAILURE_RETRY(mount("/dev/fuse", path.c_str(), "fuse",
|
|
|
|
MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts.c_str()));
|
2017-09-11 18:32:01 +02:00
|
|
|
if (result != 0) {
|
|
|
|
PLOG(ERROR) << "Failed to mount " << path;
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
return android::OK;
|
|
|
|
}
|
|
|
|
|
2018-10-27 04:56:45 +02:00
|
|
|
static android::status_t runCommand(const std::string& command, uid_t uid, const std::string& path,
|
|
|
|
int device_fd) {
|
2017-09-11 18:32:01 +02:00
|
|
|
if (DEBUG_APPFUSE) {
|
2018-10-27 04:56:45 +02:00
|
|
|
LOG(DEBUG) << "Run app fuse command " << command << " for the path " << path << " and uid "
|
|
|
|
<< uid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command == "mount") {
|
|
|
|
return mount(device_fd, path);
|
|
|
|
} 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) {
|
|
|
|
PLOG(ERROR) << "Failed to unmount directory.";
|
2017-09-11 18:32:01 +02:00
|
|
|
return -errno;
|
|
|
|
}
|
2018-10-27 04:56:45 +02:00
|
|
|
if (rmdir(path.c_str()) != 0) {
|
|
|
|
PLOG(ERROR) << "Failed to remove the mount directory.";
|
|
|
|
return -errno;
|
2017-09-11 18:32:01 +02:00
|
|
|
}
|
2018-10-27 04:56:45 +02:00
|
|
|
return android::OK;
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Unknown appfuse command " << command;
|
|
|
|
return -EPERM;
|
2017-09-11 18:32:01 +02:00
|
|
|
}
|
|
|
|
|
2018-10-27 04:56:45 +02:00
|
|
|
return android::OK;
|
2017-09-11 18:32:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int VolumeManager::createObb(const std::string& sourcePath, const std::string& sourceKey,
|
2018-09-19 00:14:18 +02:00
|
|
|
int32_t ownerGid, std::string* outVolId) {
|
2017-09-11 18:32:01 +02:00
|
|
|
int id = mNextObbId++;
|
|
|
|
|
|
|
|
auto vol = std::shared_ptr<android::vold::VolumeBase>(
|
2018-09-19 00:14:18 +02:00
|
|
|
new android::vold::ObbVolume(id, sourcePath, sourceKey, ownerGid));
|
2017-09-11 18:32:01 +02:00
|
|
|
vol->create();
|
|
|
|
|
|
|
|
mObbVolumes.push_back(vol);
|
|
|
|
*outVolId = vol->getId();
|
|
|
|
return android::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int VolumeManager::destroyObb(const std::string& volId) {
|
|
|
|
auto i = mObbVolumes.begin();
|
|
|
|
while (i != mObbVolumes.end()) {
|
|
|
|
if ((*i)->getId() == volId) {
|
|
|
|
(*i)->destroy();
|
|
|
|
i = mObbVolumes.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return android::OK;
|
|
|
|
}
|
|
|
|
|
2018-10-29 00:52:56 +01:00
|
|
|
int VolumeManager::createStubVolume(const std::string& sourcePath, const std::string& mountPath,
|
|
|
|
const std::string& fsType, const std::string& fsUuid,
|
|
|
|
const std::string& fsLabel, std::string* outVolId) {
|
|
|
|
int id = mNextStubVolumeId++;
|
|
|
|
auto vol = std::shared_ptr<android::vold::VolumeBase>(
|
|
|
|
new android::vold::StubVolume(id, sourcePath, mountPath, fsType, fsUuid, fsLabel));
|
|
|
|
vol->create();
|
|
|
|
|
|
|
|
mStubVolumes.push_back(vol);
|
|
|
|
*outVolId = vol->getId();
|
|
|
|
return android::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int VolumeManager::destroyStubVolume(const std::string& volId) {
|
|
|
|
auto i = mStubVolumes.begin();
|
|
|
|
while (i != mStubVolumes.end()) {
|
|
|
|
if ((*i)->getId() == volId) {
|
|
|
|
(*i)->destroy();
|
|
|
|
i = mStubVolumes.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return android::OK;
|
|
|
|
}
|
|
|
|
|
2018-10-27 04:56:45 +02:00
|
|
|
int VolumeManager::mountAppFuse(uid_t uid, int mountId, unique_fd* device_fd) {
|
2017-09-11 18:32:01 +02:00
|
|
|
std::string name = std::to_string(mountId);
|
|
|
|
|
|
|
|
// Check mount point name.
|
|
|
|
std::string path;
|
|
|
|
if (getMountPath(uid, name, &path) != android::OK) {
|
|
|
|
LOG(ERROR) << "Invalid mount point name";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create directories.
|
|
|
|
const android::status_t result = android::vold::PrepareDir(path, 0700, 0, 0);
|
|
|
|
if (result != android::OK) {
|
|
|
|
PLOG(ERROR) << "Failed to prepare directory " << path;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open device FD.
|
2018-09-19 00:14:18 +02:00
|
|
|
device_fd->reset(open("/dev/fuse", O_RDWR)); // not O_CLOEXEC
|
2017-09-11 18:32:01 +02:00
|
|
|
if (device_fd->get() == -1) {
|
|
|
|
PLOG(ERROR) << "Failed to open /dev/fuse";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mount.
|
2018-10-27 04:56:45 +02:00
|
|
|
return runCommand("mount", uid, path, device_fd->get());
|
2017-09-11 18:32:01 +02:00
|
|
|
}
|
|
|
|
|
2018-10-27 04:56:45 +02:00
|
|
|
int VolumeManager::unmountAppFuse(uid_t uid, int mountId) {
|
2017-09-11 18:32:01 +02:00
|
|
|
std::string name = std::to_string(mountId);
|
|
|
|
|
|
|
|
// Check mount point name.
|
|
|
|
std::string path;
|
|
|
|
if (getMountPath(uid, name, &path) != android::OK) {
|
|
|
|
LOG(ERROR) << "Invalid mount point name";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-10-27 04:56:45 +02:00
|
|
|
return runCommand("unmount", uid, path, -1 /* device_fd */);
|
|
|
|
}
|
|
|
|
|
|
|
|
int VolumeManager::openAppFuseFile(uid_t uid, int mountId, int fileId, int flags) {
|
|
|
|
std::string name = std::to_string(mountId);
|
|
|
|
|
|
|
|
// Check mount point name.
|
|
|
|
std::string mountPoint;
|
|
|
|
if (getMountPath(uid, name, &mountPoint) != android::OK) {
|
|
|
|
LOG(ERROR) << "Invalid mount point name";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string path = StringPrintf("%s/%d", mountPoint.c_str(), fileId);
|
|
|
|
return TEMP_FAILURE_RETRY(open(path.c_str(), flags));
|
2017-09-11 18:32:01 +02:00
|
|
|
}
|