clang-format the rest of the files
Apply clang-format to fix the remaining files not fixed by change I23cde3f0bbcac13bef555d13514e922c79d5ad48 Test: Format-only changes; treehugger suffices. Change-Id: I1bfd5c8d68d298596875d5edae26cdfe27c03489 Merged-In: I1bfd5c8d68d298596875d5edae26cdfe27c03489
This commit is contained in:
parent
a676df01e2
commit
8915d62847
9 changed files with 273 additions and 272 deletions
|
@ -24,9 +24,9 @@
|
||||||
#include "Process.h"
|
#include "Process.h"
|
||||||
#include "VolumeManager.h"
|
#include "VolumeManager.h"
|
||||||
|
|
||||||
#include "cryptfs.h"
|
|
||||||
#include "Ext4Crypt.h"
|
#include "Ext4Crypt.h"
|
||||||
#include "MetadataCrypt.h"
|
#include "MetadataCrypt.h"
|
||||||
|
#include "cryptfs.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
@ -83,11 +83,11 @@ binder::Status checkPermission(const char* permission) {
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
|
|
||||||
if (checkCallingPermission(String16(permission), reinterpret_cast<int32_t*>(&pid),
|
if (checkCallingPermission(String16(permission), reinterpret_cast<int32_t*>(&pid),
|
||||||
reinterpret_cast<int32_t*>(&uid))) {
|
reinterpret_cast<int32_t*>(&uid))) {
|
||||||
return ok();
|
return ok();
|
||||||
} else {
|
} else {
|
||||||
return exception(binder::Status::EX_SECURITY,
|
return exception(binder::Status::EX_SECURITY,
|
||||||
StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, permission));
|
StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, permission));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ binder::Status checkUid(uid_t expectedUid) {
|
||||||
return ok();
|
return ok();
|
||||||
} else {
|
} else {
|
||||||
return exception(binder::Status::EX_SECURITY,
|
return exception(binder::Status::EX_SECURITY,
|
||||||
StringPrintf("UID %d is not expected UID %d", uid, expectedUid));
|
StringPrintf("UID %d is not expected UID %d", uid, expectedUid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ binder::Status checkArgumentId(const std::string& id) {
|
||||||
for (const char& c : id) {
|
for (const char& c : id) {
|
||||||
if (!std::isalnum(c) && c != ':' && c != ',') {
|
if (!std::isalnum(c) && c != ':' && c != ',') {
|
||||||
return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
|
return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
|
||||||
StringPrintf("ID %s is malformed", id.c_str()));
|
StringPrintf("ID %s is malformed", id.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ok();
|
return ok();
|
||||||
|
@ -120,16 +120,16 @@ binder::Status checkArgumentPath(const std::string& path) {
|
||||||
}
|
}
|
||||||
if (path[0] != '/') {
|
if (path[0] != '/') {
|
||||||
return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
|
return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
|
||||||
StringPrintf("Path %s is relative", path.c_str()));
|
StringPrintf("Path %s is relative", path.c_str()));
|
||||||
}
|
}
|
||||||
if ((path + '/').find("/../") != std::string::npos) {
|
if ((path + '/').find("/../") != std::string::npos) {
|
||||||
return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
|
return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
|
||||||
StringPrintf("Path %s is shady", path.c_str()));
|
StringPrintf("Path %s is shady", path.c_str()));
|
||||||
}
|
}
|
||||||
for (const char& c : path) {
|
for (const char& c : path) {
|
||||||
if (c == '\0' || c == '\n') {
|
if (c == '\0' || c == '\n') {
|
||||||
return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
|
return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
|
||||||
StringPrintf("Path %s is malformed", path.c_str()));
|
StringPrintf("Path %s is malformed", path.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ok();
|
return ok();
|
||||||
|
@ -140,45 +140,49 @@ binder::Status checkArgumentHex(const std::string& hex) {
|
||||||
for (const char& c : hex) {
|
for (const char& c : hex) {
|
||||||
if (!std::isxdigit(c) && c != ':' && c != '-') {
|
if (!std::isxdigit(c) && c != ':' && c != '-') {
|
||||||
return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
|
return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
|
||||||
StringPrintf("Hex %s is malformed", hex.c_str()));
|
StringPrintf("Hex %s is malformed", hex.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ok();
|
return ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ENFORCE_UID(uid) { \
|
#define ENFORCE_UID(uid) \
|
||||||
binder::Status status = checkUid((uid)); \
|
{ \
|
||||||
if (!status.isOk()) { \
|
binder::Status status = checkUid((uid)); \
|
||||||
return status; \
|
if (!status.isOk()) { \
|
||||||
} \
|
return status; \
|
||||||
}
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
#define CHECK_ARGUMENT_ID(id) { \
|
#define CHECK_ARGUMENT_ID(id) \
|
||||||
binder::Status status = checkArgumentId((id)); \
|
{ \
|
||||||
if (!status.isOk()) { \
|
binder::Status status = checkArgumentId((id)); \
|
||||||
return status; \
|
if (!status.isOk()) { \
|
||||||
} \
|
return status; \
|
||||||
}
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
#define CHECK_ARGUMENT_PATH(path) { \
|
#define CHECK_ARGUMENT_PATH(path) \
|
||||||
binder::Status status = checkArgumentPath((path)); \
|
{ \
|
||||||
if (!status.isOk()) { \
|
binder::Status status = checkArgumentPath((path)); \
|
||||||
return status; \
|
if (!status.isOk()) { \
|
||||||
} \
|
return status; \
|
||||||
}
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
#define CHECK_ARGUMENT_HEX(hex) { \
|
#define CHECK_ARGUMENT_HEX(hex) \
|
||||||
binder::Status status = checkArgumentHex((hex)); \
|
{ \
|
||||||
if (!status.isOk()) { \
|
binder::Status status = checkArgumentHex((hex)); \
|
||||||
return status; \
|
if (!status.isOk()) { \
|
||||||
} \
|
return status; \
|
||||||
}
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
#define ACQUIRE_LOCK \
|
#define ACQUIRE_LOCK \
|
||||||
std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \
|
std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \
|
||||||
ATRACE_CALL();
|
ATRACE_CALL();
|
||||||
|
|
||||||
#define ACQUIRE_CRYPT_LOCK \
|
#define ACQUIRE_CRYPT_LOCK \
|
||||||
std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \
|
std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \
|
||||||
ATRACE_CALL();
|
ATRACE_CALL();
|
||||||
|
|
||||||
|
@ -196,7 +200,7 @@ status_t VoldNativeService::start() {
|
||||||
return android::OK;
|
return android::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t VoldNativeService::dump(int fd, const Vector<String16> & /* args */) {
|
status_t VoldNativeService::dump(int fd, const Vector<String16>& /* args */) {
|
||||||
auto out = std::fstream(StringPrintf("/proc/self/fd/%d", fd));
|
auto out = std::fstream(StringPrintf("/proc/self/fd/%d", fd));
|
||||||
const binder::Status dump_permission = checkPermission(kDump);
|
const binder::Status dump_permission = checkPermission(kDump);
|
||||||
if (!dump_permission.isOk()) {
|
if (!dump_permission.isOk()) {
|
||||||
|
@ -211,7 +215,7 @@ status_t VoldNativeService::dump(int fd, const Vector<String16> & /* args */) {
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::setListener(
|
binder::Status VoldNativeService::setListener(
|
||||||
const android::sp<android::os::IVoldListener>& listener) {
|
const android::sp<android::os::IVoldListener>& listener) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
ACQUIRE_LOCK;
|
ACQUIRE_LOCK;
|
||||||
|
|
||||||
|
@ -223,12 +227,8 @@ binder::Status VoldNativeService::monitor() {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
|
|
||||||
// Simply acquire/release each lock for watchdog
|
// Simply acquire/release each lock for watchdog
|
||||||
{
|
{ ACQUIRE_LOCK; }
|
||||||
ACQUIRE_LOCK;
|
{ ACQUIRE_CRYPT_LOCK; }
|
||||||
}
|
|
||||||
{
|
|
||||||
ACQUIRE_CRYPT_LOCK;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ok();
|
return ok();
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) {
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType,
|
binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType,
|
||||||
int32_t ratio) {
|
int32_t ratio) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
CHECK_ARGUMENT_ID(diskId);
|
CHECK_ARGUMENT_ID(diskId);
|
||||||
ACQUIRE_LOCK;
|
ACQUIRE_LOCK;
|
||||||
|
@ -293,15 +293,19 @@ binder::Status VoldNativeService::partition(const std::string& diskId, int32_t p
|
||||||
return error("Failed to find disk " + diskId);
|
return error("Failed to find disk " + diskId);
|
||||||
}
|
}
|
||||||
switch (partitionType) {
|
switch (partitionType) {
|
||||||
case PARTITION_TYPE_PUBLIC: return translate(disk->partitionPublic());
|
case PARTITION_TYPE_PUBLIC:
|
||||||
case PARTITION_TYPE_PRIVATE: return translate(disk->partitionPrivate());
|
return translate(disk->partitionPublic());
|
||||||
case PARTITION_TYPE_MIXED: return translate(disk->partitionMixed(ratio));
|
case PARTITION_TYPE_PRIVATE:
|
||||||
default: return error("Unknown type " + std::to_string(partitionType));
|
return translate(disk->partitionPrivate());
|
||||||
|
case PARTITION_TYPE_MIXED:
|
||||||
|
return translate(disk->partitionMixed(ratio));
|
||||||
|
default:
|
||||||
|
return error("Unknown type " + std::to_string(partitionType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::forgetPartition(const std::string& partGuid,
|
binder::Status VoldNativeService::forgetPartition(const std::string& partGuid,
|
||||||
const std::string& fsUuid) {
|
const std::string& fsUuid) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
CHECK_ARGUMENT_HEX(partGuid);
|
CHECK_ARGUMENT_HEX(partGuid);
|
||||||
CHECK_ARGUMENT_HEX(fsUuid);
|
CHECK_ARGUMENT_HEX(fsUuid);
|
||||||
|
@ -311,7 +315,7 @@ binder::Status VoldNativeService::forgetPartition(const std::string& partGuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::mount(const std::string& volId, int32_t mountFlags,
|
binder::Status VoldNativeService::mount(const std::string& volId, int32_t mountFlags,
|
||||||
int32_t mountUserId) {
|
int32_t mountUserId) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
CHECK_ARGUMENT_ID(volId);
|
CHECK_ARGUMENT_ID(volId);
|
||||||
ACQUIRE_LOCK;
|
ACQUIRE_LOCK;
|
||||||
|
@ -387,9 +391,7 @@ binder::Status VoldNativeService::benchmark(
|
||||||
auto status = pathForVolId(volId, &path);
|
auto status = pathForVolId(volId, &path);
|
||||||
if (!status.isOk()) return status;
|
if (!status.isOk()) return status;
|
||||||
|
|
||||||
std::thread([=]() {
|
std::thread([=]() { android::vold::Benchmark(path, listener); }).detach();
|
||||||
android::vold::Benchmark(path, listener);
|
|
||||||
}).detach();
|
|
||||||
return ok();
|
return ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,8 +406,9 @@ binder::Status VoldNativeService::checkEncryption(const std::string& volId) {
|
||||||
return translate(android::vold::CheckEncryption(path));
|
return translate(android::vold::CheckEncryption(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::moveStorage(const std::string& fromVolId,
|
binder::Status VoldNativeService::moveStorage(
|
||||||
const std::string& toVolId, const android::sp<android::os::IVoldTaskListener>& listener) {
|
const std::string& fromVolId, const std::string& toVolId,
|
||||||
|
const android::sp<android::os::IVoldTaskListener>& listener) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
CHECK_ARGUMENT_ID(fromVolId);
|
CHECK_ARGUMENT_ID(fromVolId);
|
||||||
CHECK_ARGUMENT_ID(toVolId);
|
CHECK_ARGUMENT_ID(toVolId);
|
||||||
|
@ -419,9 +422,7 @@ binder::Status VoldNativeService::moveStorage(const std::string& fromVolId,
|
||||||
return error("Failed to find volume " + toVolId);
|
return error("Failed to find volume " + toVolId);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::thread([=]() {
|
std::thread([=]() { android::vold::MoveStorage(fromVol, toVol, listener); }).detach();
|
||||||
android::vold::MoveStorage(fromVol, toVol, listener);
|
|
||||||
}).detach();
|
|
||||||
return ok();
|
return ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,11 +432,20 @@ binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) {
|
||||||
|
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
switch (remountMode) {
|
switch (remountMode) {
|
||||||
case REMOUNT_MODE_NONE: tmp = "none"; break;
|
case REMOUNT_MODE_NONE:
|
||||||
case REMOUNT_MODE_DEFAULT: tmp = "default"; break;
|
tmp = "none";
|
||||||
case REMOUNT_MODE_READ: tmp = "read"; break;
|
break;
|
||||||
case REMOUNT_MODE_WRITE: tmp = "write"; break;
|
case REMOUNT_MODE_DEFAULT:
|
||||||
default: return error("Unknown mode " + std::to_string(remountMode));
|
tmp = "default";
|
||||||
|
break;
|
||||||
|
case REMOUNT_MODE_READ:
|
||||||
|
tmp = "read";
|
||||||
|
break;
|
||||||
|
case REMOUNT_MODE_WRITE:
|
||||||
|
tmp = "write";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return error("Unknown mode " + std::to_string(remountMode));
|
||||||
}
|
}
|
||||||
return translate(VolumeManager::Instance()->remountUid(uid, tmp));
|
return translate(VolumeManager::Instance()->remountUid(uid, tmp));
|
||||||
}
|
}
|
||||||
|
@ -449,14 +459,15 @@ binder::Status VoldNativeService::mkdirs(const std::string& path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::createObb(const std::string& sourcePath,
|
binder::Status VoldNativeService::createObb(const std::string& sourcePath,
|
||||||
const std::string& sourceKey, int32_t ownerGid, std::string* _aidl_return) {
|
const std::string& sourceKey, int32_t ownerGid,
|
||||||
|
std::string* _aidl_return) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
CHECK_ARGUMENT_PATH(sourcePath);
|
CHECK_ARGUMENT_PATH(sourcePath);
|
||||||
CHECK_ARGUMENT_HEX(sourceKey);
|
CHECK_ARGUMENT_HEX(sourceKey);
|
||||||
ACQUIRE_LOCK;
|
ACQUIRE_LOCK;
|
||||||
|
|
||||||
return translate(
|
return translate(
|
||||||
VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return));
|
VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return));
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::destroyObb(const std::string& volId) {
|
binder::Status VoldNativeService::destroyObb(const std::string& volId) {
|
||||||
|
@ -467,41 +478,35 @@ binder::Status VoldNativeService::destroyObb(const std::string& volId) {
|
||||||
return translate(VolumeManager::Instance()->destroyObb(volId));
|
return translate(VolumeManager::Instance()->destroyObb(volId));
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::fstrim(int32_t fstrimFlags,
|
binder::Status VoldNativeService::fstrim(
|
||||||
const android::sp<android::os::IVoldTaskListener>& listener) {
|
int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
ACQUIRE_LOCK;
|
ACQUIRE_LOCK;
|
||||||
|
|
||||||
std::thread([=]() {
|
std::thread([=]() { android::vold::Trim(listener); }).detach();
|
||||||
android::vold::Trim(listener);
|
|
||||||
}).detach();
|
|
||||||
return ok();
|
return ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::runIdleMaint(
|
binder::Status VoldNativeService::runIdleMaint(
|
||||||
const android::sp<android::os::IVoldTaskListener>& listener) {
|
const android::sp<android::os::IVoldTaskListener>& listener) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
ACQUIRE_LOCK;
|
ACQUIRE_LOCK;
|
||||||
|
|
||||||
std::thread([=]() {
|
std::thread([=]() { android::vold::RunIdleMaint(listener); }).detach();
|
||||||
android::vold::RunIdleMaint(listener);
|
|
||||||
}).detach();
|
|
||||||
return ok();
|
return ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::abortIdleMaint(
|
binder::Status VoldNativeService::abortIdleMaint(
|
||||||
const android::sp<android::os::IVoldTaskListener>& listener) {
|
const android::sp<android::os::IVoldTaskListener>& listener) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
ACQUIRE_LOCK;
|
ACQUIRE_LOCK;
|
||||||
|
|
||||||
std::thread([=]() {
|
std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach();
|
||||||
android::vold::AbortIdleMaint(listener);
|
|
||||||
}).detach();
|
|
||||||
return ok();
|
return ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t pid, int32_t mountId,
|
binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t pid, int32_t mountId,
|
||||||
android::base::unique_fd* _aidl_return) {
|
android::base::unique_fd* _aidl_return) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
ACQUIRE_LOCK;
|
ACQUIRE_LOCK;
|
||||||
|
|
||||||
|
@ -541,7 +546,7 @@ binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fdeEnableInternal(int32_t passwordType, const std::string& password,
|
static int fdeEnableInternal(int32_t passwordType, const std::string& password,
|
||||||
int32_t encryptionFlags) {
|
int32_t encryptionFlags) {
|
||||||
bool noUi = (encryptionFlags & VoldNativeService::ENCRYPTION_FLAG_NO_UI) != 0;
|
bool noUi = (encryptionFlags & VoldNativeService::ENCRYPTION_FLAG_NO_UI) != 0;
|
||||||
|
|
||||||
for (int tries = 0; tries < 2; ++tries) {
|
for (int tries = 0; tries < 2; ++tries) {
|
||||||
|
@ -562,8 +567,8 @@ static int fdeEnableInternal(int32_t passwordType, const std::string& password,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::fdeEnable(int32_t passwordType,
|
binder::Status VoldNativeService::fdeEnable(int32_t passwordType, const std::string& password,
|
||||||
const std::string& password, int32_t encryptionFlags) {
|
int32_t encryptionFlags) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
ACQUIRE_CRYPT_LOCK;
|
ACQUIRE_CRYPT_LOCK;
|
||||||
|
|
||||||
|
@ -581,7 +586,7 @@ binder::Status VoldNativeService::fdeEnable(int32_t passwordType,
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType,
|
binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType,
|
||||||
const std::string& password) {
|
const std::string& password) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
ACQUIRE_CRYPT_LOCK;
|
ACQUIRE_CRYPT_LOCK;
|
||||||
|
|
||||||
|
@ -595,8 +600,7 @@ binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password)
|
||||||
return translate(cryptfs_verify_passwd(password.c_str()));
|
return translate(cryptfs_verify_passwd(password.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::fdeGetField(const std::string& key,
|
binder::Status VoldNativeService::fdeGetField(const std::string& key, std::string* _aidl_return) {
|
||||||
std::string* _aidl_return) {
|
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
ACQUIRE_CRYPT_LOCK;
|
ACQUIRE_CRYPT_LOCK;
|
||||||
|
|
||||||
|
@ -609,8 +613,7 @@ binder::Status VoldNativeService::fdeGetField(const std::string& key,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::fdeSetField(const std::string& key,
|
binder::Status VoldNativeService::fdeSetField(const std::string& key, const std::string& value) {
|
||||||
const std::string& value) {
|
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
ACQUIRE_CRYPT_LOCK;
|
ACQUIRE_CRYPT_LOCK;
|
||||||
|
|
||||||
|
@ -692,8 +695,7 @@ binder::Status VoldNativeService::encryptFstab(const std::string& mountPoint) {
|
||||||
return translateBool(e4crypt_mount_metadata_encrypted(mountPoint, true));
|
return translateBool(e4crypt_mount_metadata_encrypted(mountPoint, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial,
|
binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, bool ephemeral) {
|
||||||
bool ephemeral) {
|
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
ACQUIRE_CRYPT_LOCK;
|
ACQUIRE_CRYPT_LOCK;
|
||||||
|
|
||||||
|
@ -708,7 +710,8 @@ binder::Status VoldNativeService::destroyUserKey(int32_t userId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial,
|
binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial,
|
||||||
const std::string& token, const std::string& secret) {
|
const std::string& token,
|
||||||
|
const std::string& secret) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
ACQUIRE_CRYPT_LOCK;
|
ACQUIRE_CRYPT_LOCK;
|
||||||
|
|
||||||
|
@ -723,7 +726,8 @@ binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial,
|
binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial,
|
||||||
const std::string& token, const std::string& secret) {
|
const std::string& token,
|
||||||
|
const std::string& secret) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
ACQUIRE_CRYPT_LOCK;
|
ACQUIRE_CRYPT_LOCK;
|
||||||
|
|
||||||
|
@ -738,7 +742,8 @@ binder::Status VoldNativeService::lockUserKey(int32_t userId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::prepareUserStorage(const std::unique_ptr<std::string>& uuid,
|
binder::Status VoldNativeService::prepareUserStorage(const std::unique_ptr<std::string>& uuid,
|
||||||
int32_t userId, int32_t userSerial, int32_t flags) {
|
int32_t userId, int32_t userSerial,
|
||||||
|
int32_t flags) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
std::string empty_string = "";
|
std::string empty_string = "";
|
||||||
auto uuid_ = uuid ? *uuid : empty_string;
|
auto uuid_ = uuid ? *uuid : empty_string;
|
||||||
|
@ -749,7 +754,7 @@ binder::Status VoldNativeService::prepareUserStorage(const std::unique_ptr<std::
|
||||||
}
|
}
|
||||||
|
|
||||||
binder::Status VoldNativeService::destroyUserStorage(const std::unique_ptr<std::string>& uuid,
|
binder::Status VoldNativeService::destroyUserStorage(const std::unique_ptr<std::string>& uuid,
|
||||||
int32_t userId, int32_t flags) {
|
int32_t userId, int32_t flags) {
|
||||||
ENFORCE_UID(AID_SYSTEM);
|
ENFORCE_UID(AID_SYSTEM);
|
||||||
std::string empty_string = "";
|
std::string empty_string = "";
|
||||||
auto uuid_ = uuid ? *uuid : empty_string;
|
auto uuid_ = uuid ? *uuid : empty_string;
|
||||||
|
|
|
@ -26,10 +26,10 @@ namespace android {
|
||||||
namespace vold {
|
namespace vold {
|
||||||
|
|
||||||
class VoldNativeService : public BinderService<VoldNativeService>, public os::BnVold {
|
class VoldNativeService : public BinderService<VoldNativeService>, public os::BnVold {
|
||||||
public:
|
public:
|
||||||
static status_t start();
|
static status_t start();
|
||||||
static char const* getServiceName() { return "vold"; }
|
static char const* getServiceName() { return "vold"; }
|
||||||
virtual status_t dump(int fd, const Vector<String16> &args) override;
|
virtual status_t dump(int fd, const Vector<String16>& args) override;
|
||||||
|
|
||||||
binder::Status setListener(const android::sp<android::os::IVoldListener>& listener);
|
binder::Status setListener(const android::sp<android::os::IVoldListener>& listener);
|
||||||
|
|
||||||
|
@ -51,38 +51,35 @@ public:
|
||||||
binder::Status unmount(const std::string& volId);
|
binder::Status unmount(const std::string& volId);
|
||||||
binder::Status format(const std::string& volId, const std::string& fsType);
|
binder::Status format(const std::string& volId, const std::string& fsType);
|
||||||
binder::Status benchmark(const std::string& volId,
|
binder::Status benchmark(const std::string& volId,
|
||||||
const android::sp<android::os::IVoldTaskListener>& listener);
|
const android::sp<android::os::IVoldTaskListener>& listener);
|
||||||
binder::Status checkEncryption(const std::string& volId);
|
binder::Status checkEncryption(const std::string& volId);
|
||||||
|
|
||||||
binder::Status moveStorage(const std::string& fromVolId, const std::string& toVolId,
|
binder::Status moveStorage(const std::string& fromVolId, const std::string& toVolId,
|
||||||
const android::sp<android::os::IVoldTaskListener>& listener);
|
const android::sp<android::os::IVoldTaskListener>& listener);
|
||||||
|
|
||||||
binder::Status remountUid(int32_t uid, int32_t remountMode);
|
binder::Status remountUid(int32_t uid, int32_t remountMode);
|
||||||
|
|
||||||
binder::Status mkdirs(const std::string& path);
|
binder::Status mkdirs(const std::string& path);
|
||||||
|
|
||||||
binder::Status createObb(const std::string& sourcePath, const std::string& sourceKey,
|
binder::Status createObb(const std::string& sourcePath, const std::string& sourceKey,
|
||||||
int32_t ownerGid, std::string* _aidl_return);
|
int32_t ownerGid, std::string* _aidl_return);
|
||||||
binder::Status destroyObb(const std::string& volId);
|
binder::Status destroyObb(const std::string& volId);
|
||||||
|
|
||||||
binder::Status fstrim(int32_t fstrimFlags,
|
binder::Status fstrim(int32_t fstrimFlags,
|
||||||
const android::sp<android::os::IVoldTaskListener>& listener);
|
const android::sp<android::os::IVoldTaskListener>& listener);
|
||||||
binder::Status runIdleMaint(
|
binder::Status runIdleMaint(const android::sp<android::os::IVoldTaskListener>& listener);
|
||||||
const android::sp<android::os::IVoldTaskListener>& listener);
|
binder::Status abortIdleMaint(const android::sp<android::os::IVoldTaskListener>& listener);
|
||||||
binder::Status abortIdleMaint(
|
|
||||||
const android::sp<android::os::IVoldTaskListener>& listener);
|
|
||||||
|
|
||||||
binder::Status mountAppFuse(int32_t uid, int32_t pid, int32_t mountId,
|
binder::Status mountAppFuse(int32_t uid, int32_t pid, int32_t mountId,
|
||||||
android::base::unique_fd* _aidl_return);
|
android::base::unique_fd* _aidl_return);
|
||||||
binder::Status unmountAppFuse(int32_t uid, int32_t pid, int32_t mountId);
|
binder::Status unmountAppFuse(int32_t uid, int32_t pid, int32_t mountId);
|
||||||
|
|
||||||
binder::Status fdeCheckPassword(const std::string& password);
|
binder::Status fdeCheckPassword(const std::string& password);
|
||||||
binder::Status fdeRestart();
|
binder::Status fdeRestart();
|
||||||
binder::Status fdeComplete(int32_t* _aidl_return);
|
binder::Status fdeComplete(int32_t* _aidl_return);
|
||||||
binder::Status fdeEnable(int32_t passwordType,
|
binder::Status fdeEnable(int32_t passwordType, const std::string& password,
|
||||||
const std::string& password, int32_t encryptionFlags);
|
int32_t encryptionFlags);
|
||||||
binder::Status fdeChangePassword(int32_t passwordType,
|
binder::Status fdeChangePassword(int32_t passwordType, const std::string& password);
|
||||||
const std::string& password);
|
|
||||||
binder::Status fdeVerifyPassword(const std::string& password);
|
binder::Status fdeVerifyPassword(const std::string& password);
|
||||||
binder::Status fdeGetField(const std::string& key, std::string* _aidl_return);
|
binder::Status fdeGetField(const std::string& key, std::string* _aidl_return);
|
||||||
binder::Status fdeSetField(const std::string& key, const std::string& value);
|
binder::Status fdeSetField(const std::string& key, const std::string& value);
|
||||||
|
@ -101,18 +98,18 @@ public:
|
||||||
binder::Status createUserKey(int32_t userId, int32_t userSerial, bool ephemeral);
|
binder::Status createUserKey(int32_t userId, int32_t userSerial, bool ephemeral);
|
||||||
binder::Status destroyUserKey(int32_t userId);
|
binder::Status destroyUserKey(int32_t userId);
|
||||||
|
|
||||||
binder::Status addUserKeyAuth(int32_t userId, int32_t userSerial,
|
binder::Status addUserKeyAuth(int32_t userId, int32_t userSerial, const std::string& token,
|
||||||
const std::string& token, const std::string& secret);
|
const std::string& secret);
|
||||||
binder::Status fixateNewestUserKeyAuth(int32_t userId);
|
binder::Status fixateNewestUserKeyAuth(int32_t userId);
|
||||||
|
|
||||||
binder::Status unlockUserKey(int32_t userId, int32_t userSerial,
|
binder::Status unlockUserKey(int32_t userId, int32_t userSerial, const std::string& token,
|
||||||
const std::string& token, const std::string& secret);
|
const std::string& secret);
|
||||||
binder::Status lockUserKey(int32_t userId);
|
binder::Status lockUserKey(int32_t userId);
|
||||||
|
|
||||||
binder::Status prepareUserStorage(const std::unique_ptr<std::string>& uuid,
|
binder::Status prepareUserStorage(const std::unique_ptr<std::string>& uuid, int32_t userId,
|
||||||
int32_t userId, int32_t userSerial, int32_t flags);
|
int32_t userSerial, int32_t flags);
|
||||||
binder::Status destroyUserStorage(const std::unique_ptr<std::string>& uuid,
|
binder::Status destroyUserStorage(const std::unique_ptr<std::string>& uuid, int32_t userId,
|
||||||
int32_t userId, int32_t flags);
|
int32_t flags);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace vold
|
} // namespace vold
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/sysmacros.h>
|
#include <sys/sysmacros.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -79,11 +79,10 @@ static const unsigned int kMajorBlockMmc = 179;
|
||||||
static const unsigned int kMajorBlockExperimentalMin = 240;
|
static const unsigned int kMajorBlockExperimentalMin = 240;
|
||||||
static const unsigned int kMajorBlockExperimentalMax = 254;
|
static const unsigned int kMajorBlockExperimentalMax = 254;
|
||||||
|
|
||||||
VolumeManager *VolumeManager::sInstance = NULL;
|
VolumeManager* VolumeManager::sInstance = NULL;
|
||||||
|
|
||||||
VolumeManager *VolumeManager::Instance() {
|
VolumeManager* VolumeManager::Instance() {
|
||||||
if (!sInstance)
|
if (!sInstance) sInstance = new VolumeManager();
|
||||||
sInstance = new VolumeManager();
|
|
||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,8 +94,7 @@ VolumeManager::VolumeManager() {
|
||||||
mSecureKeyguardShowing = true;
|
mSecureKeyguardShowing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
VolumeManager::~VolumeManager() {
|
VolumeManager::~VolumeManager() {}
|
||||||
}
|
|
||||||
|
|
||||||
int VolumeManager::updateVirtualDisk() {
|
int VolumeManager::updateVirtualDisk() {
|
||||||
ATRACE_NAME("VolumeManager::updateVirtualDisk");
|
ATRACE_NAME("VolumeManager::updateVirtualDisk");
|
||||||
|
@ -117,8 +115,9 @@ int VolumeManager::updateVirtualDisk() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto disk = new android::vold::Disk("virtual", buf.st_rdev, "virtual",
|
auto disk = new android::vold::Disk(
|
||||||
android::vold::Disk::Flags::kAdoptable | android::vold::Disk::Flags::kSd);
|
"virtual", buf.st_rdev, "virtual",
|
||||||
|
android::vold::Disk::Flags::kAdoptable | android::vold::Disk::Flags::kSd);
|
||||||
mVirtualDisk = std::shared_ptr<android::vold::Disk>(disk);
|
mVirtualDisk = std::shared_ptr<android::vold::Disk>(disk);
|
||||||
handleDiskAdded(mVirtualDisk);
|
handleDiskAdded(mVirtualDisk);
|
||||||
}
|
}
|
||||||
|
@ -157,7 +156,7 @@ int VolumeManager::start() {
|
||||||
// storage; the framework will decide if it should be mounted.
|
// storage; the framework will decide if it should be mounted.
|
||||||
CHECK(mInternalEmulated == nullptr);
|
CHECK(mInternalEmulated == nullptr);
|
||||||
mInternalEmulated = std::shared_ptr<android::vold::VolumeBase>(
|
mInternalEmulated = std::shared_ptr<android::vold::VolumeBase>(
|
||||||
new android::vold::EmulatedVolume("/data/media"));
|
new android::vold::EmulatedVolume("/data/media"));
|
||||||
mInternalEmulated->create();
|
mInternalEmulated->create();
|
||||||
|
|
||||||
// Consider creating a virtual disk
|
// Consider creating a virtual disk
|
||||||
|
@ -173,17 +172,17 @@ int VolumeManager::stop() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VolumeManager::handleBlockEvent(NetlinkEvent *evt) {
|
void VolumeManager::handleBlockEvent(NetlinkEvent* evt) {
|
||||||
std::lock_guard<std::mutex> lock(mLock);
|
std::lock_guard<std::mutex> lock(mLock);
|
||||||
|
|
||||||
if (mDebug) {
|
if (mDebug) {
|
||||||
LOG(VERBOSE) << "----------------";
|
LOG(VERBOSE) << "----------------";
|
||||||
LOG(VERBOSE) << "handleBlockEvent with action " << (int) evt->getAction();
|
LOG(VERBOSE) << "handleBlockEvent with action " << (int)evt->getAction();
|
||||||
evt->dump();
|
evt->dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string eventPath(evt->findParam("DEVPATH")?evt->findParam("DEVPATH"):"");
|
std::string eventPath(evt->findParam("DEVPATH") ? evt->findParam("DEVPATH") : "");
|
||||||
std::string devType(evt->findParam("DEVTYPE")?evt->findParam("DEVTYPE"):"");
|
std::string devType(evt->findParam("DEVTYPE") ? evt->findParam("DEVTYPE") : "");
|
||||||
|
|
||||||
if (devType != "disk") return;
|
if (devType != "disk") return;
|
||||||
|
|
||||||
|
@ -192,43 +191,42 @@ void VolumeManager::handleBlockEvent(NetlinkEvent *evt) {
|
||||||
dev_t device = makedev(major, minor);
|
dev_t device = makedev(major, minor);
|
||||||
|
|
||||||
switch (evt->getAction()) {
|
switch (evt->getAction()) {
|
||||||
case NetlinkEvent::Action::kAdd: {
|
case NetlinkEvent::Action::kAdd: {
|
||||||
for (const auto& source : mDiskSources) {
|
for (const auto& source : mDiskSources) {
|
||||||
if (source->matches(eventPath)) {
|
if (source->matches(eventPath)) {
|
||||||
// For now, assume that MMC and virtio-blk (the latter is
|
// For now, assume that MMC and virtio-blk (the latter is
|
||||||
// emulator-specific; see Disk.cpp for details) devices are SD,
|
// emulator-specific; see Disk.cpp for details) devices are SD,
|
||||||
// and that everything else is USB
|
// and that everything else is USB
|
||||||
int flags = source->getFlags();
|
int flags = source->getFlags();
|
||||||
if (major == kMajorBlockMmc
|
if (major == kMajorBlockMmc || (android::vold::IsRunningInEmulator() &&
|
||||||
|| (android::vold::IsRunningInEmulator()
|
major >= (int)kMajorBlockExperimentalMin &&
|
||||||
&& major >= (int) kMajorBlockExperimentalMin
|
major <= (int)kMajorBlockExperimentalMax)) {
|
||||||
&& major <= (int) kMajorBlockExperimentalMax)) {
|
flags |= android::vold::Disk::Flags::kSd;
|
||||||
flags |= android::vold::Disk::Flags::kSd;
|
} else {
|
||||||
} else {
|
flags |= android::vold::Disk::Flags::kUsb;
|
||||||
flags |= android::vold::Disk::Flags::kUsb;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
auto disk = new android::vold::Disk(eventPath, device,
|
auto disk =
|
||||||
source->getNickname(), flags);
|
new android::vold::Disk(eventPath, device, source->getNickname(), flags);
|
||||||
handleDiskAdded(std::shared_ptr<android::vold::Disk>(disk));
|
handleDiskAdded(std::shared_ptr<android::vold::Disk>(disk));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +235,7 @@ void VolumeManager::handleDiskAdded(const std::shared_ptr<android::vold::Disk>&
|
||||||
// until the user unlocks the device to actually touch it
|
// until the user unlocks the device to actually touch it
|
||||||
if (mSecureKeyguardShowing) {
|
if (mSecureKeyguardShowing) {
|
||||||
LOG(INFO) << "Found disk at " << disk->getEventPath()
|
LOG(INFO) << "Found disk at " << disk->getEventPath()
|
||||||
<< " but delaying scan due to secure keyguard";
|
<< " but delaying scan due to secure keyguard";
|
||||||
mPendingDisks.push_back(disk);
|
mPendingDisks.push_back(disk);
|
||||||
} else {
|
} else {
|
||||||
disk->create();
|
disk->create();
|
||||||
|
@ -312,8 +310,7 @@ std::shared_ptr<android::vold::VolumeBase> VolumeManager::findVolume(const std::
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VolumeManager::listVolumes(android::vold::VolumeBase::Type type,
|
void VolumeManager::listVolumes(android::vold::VolumeBase::Type type, std::list<std::string>& list) {
|
||||||
std::list<std::string>& list) {
|
|
||||||
list.clear();
|
list.clear();
|
||||||
for (const auto& disk : mDisks) {
|
for (const auto& disk : mDisks) {
|
||||||
disk->listVolumes(type, list);
|
disk->listVolumes(type, list);
|
||||||
|
@ -497,7 +494,7 @@ int VolumeManager::remountUid(uid_t uid, const std::string& mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// We purposefully leave the namespace open across the fork
|
// We purposefully leave the namespace open across the fork
|
||||||
nsFd = openat(pidFd, "ns/mnt", O_RDONLY); // not O_CLOEXEC
|
nsFd = openat(pidFd, "ns/mnt", O_RDONLY); // not O_CLOEXEC
|
||||||
if (nsFd < 0) {
|
if (nsFd < 0) {
|
||||||
PLOG(WARNING) << "Failed to open namespace for " << de->d_name;
|
PLOG(WARNING) << "Failed to open namespace for " << de->d_name;
|
||||||
goto next;
|
goto next;
|
||||||
|
@ -522,26 +519,22 @@ int VolumeManager::remountUid(uid_t uid, const std::string& mode) {
|
||||||
// Sane default of no storage visible
|
// Sane default of no storage visible
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
if (TEMP_FAILURE_RETRY(mount(storageSource.c_str(), "/storage",
|
if (TEMP_FAILURE_RETRY(
|
||||||
NULL, MS_BIND | MS_REC, NULL)) == -1) {
|
mount(storageSource.c_str(), "/storage", NULL, MS_BIND | MS_REC, NULL)) == -1) {
|
||||||
PLOG(ERROR) << "Failed to mount " << storageSource << " for "
|
PLOG(ERROR) << "Failed to mount " << storageSource << " for " << de->d_name;
|
||||||
<< de->d_name;
|
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
if (TEMP_FAILURE_RETRY(mount(NULL, "/storage", NULL,
|
if (TEMP_FAILURE_RETRY(mount(NULL, "/storage", NULL, MS_REC | MS_SLAVE, NULL)) == -1) {
|
||||||
MS_REC | MS_SLAVE, NULL)) == -1) {
|
PLOG(ERROR) << "Failed to set MS_SLAVE to /storage for " << de->d_name;
|
||||||
PLOG(ERROR) << "Failed to set MS_SLAVE to /storage for "
|
|
||||||
<< de->d_name;
|
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mount user-specific symlink helper into place
|
// Mount user-specific symlink helper into place
|
||||||
userid_t user_id = multiuser_get_user_id(uid);
|
userid_t user_id = multiuser_get_user_id(uid);
|
||||||
std::string userSource(StringPrintf("/mnt/user/%d", user_id));
|
std::string userSource(StringPrintf("/mnt/user/%d", user_id));
|
||||||
if (TEMP_FAILURE_RETRY(mount(userSource.c_str(), "/storage/self",
|
if (TEMP_FAILURE_RETRY(
|
||||||
NULL, MS_BIND, NULL)) == -1) {
|
mount(userSource.c_str(), "/storage/self", NULL, MS_BIND, NULL)) == -1) {
|
||||||
PLOG(ERROR) << "Failed to mount " << userSource << " for "
|
PLOG(ERROR) << "Failed to mount " << userSource << " for " << de->d_name;
|
||||||
<< de->d_name;
|
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -555,7 +548,7 @@ int VolumeManager::remountUid(uid_t uid, const std::string& mode) {
|
||||||
TEMP_FAILURE_RETRY(waitpid(child, nullptr, 0));
|
TEMP_FAILURE_RETRY(waitpid(child, nullptr, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
next:
|
next:
|
||||||
close(nsFd);
|
close(nsFd);
|
||||||
close(pidFd);
|
close(pidFd);
|
||||||
}
|
}
|
||||||
|
@ -583,7 +576,7 @@ int VolumeManager::reset() {
|
||||||
// Can be called twice (sequentially) during shutdown. should be safe for that.
|
// Can be called twice (sequentially) during shutdown. should be safe for that.
|
||||||
int VolumeManager::shutdown() {
|
int VolumeManager::shutdown() {
|
||||||
if (mInternalEmulated == nullptr) {
|
if (mInternalEmulated == nullptr) {
|
||||||
return 0; // already shutdown
|
return 0; // already shutdown
|
||||||
}
|
}
|
||||||
android::vold::sSleepOnUnmount = false;
|
android::vold::sSleepOnUnmount = false;
|
||||||
mInternalEmulated->destroy();
|
mInternalEmulated->destroy();
|
||||||
|
@ -673,20 +666,18 @@ static android::status_t mountInNamespace(uid_t uid, int device_fd, const std::s
|
||||||
android::vold::ForceUnmount(path);
|
android::vold::ForceUnmount(path);
|
||||||
|
|
||||||
const auto opts = android::base::StringPrintf(
|
const auto opts = android::base::StringPrintf(
|
||||||
"fd=%i,"
|
"fd=%i,"
|
||||||
"rootmode=40000,"
|
"rootmode=40000,"
|
||||||
"default_permissions,"
|
"default_permissions,"
|
||||||
"allow_other,"
|
"allow_other,"
|
||||||
"user_id=%d,group_id=%d,"
|
"user_id=%d,group_id=%d,"
|
||||||
"context=\"u:object_r:app_fuse_file:s0\","
|
"context=\"u:object_r:app_fuse_file:s0\","
|
||||||
"fscontext=u:object_r:app_fusefs:s0",
|
"fscontext=u:object_r:app_fusefs:s0",
|
||||||
device_fd,
|
device_fd, uid, uid);
|
||||||
uid,
|
|
||||||
uid);
|
|
||||||
|
|
||||||
const int result = TEMP_FAILURE_RETRY(mount(
|
const int result =
|
||||||
"/dev/fuse", path.c_str(), "fuse",
|
TEMP_FAILURE_RETRY(mount("/dev/fuse", path.c_str(), "fuse",
|
||||||
MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts.c_str()));
|
MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts.c_str()));
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
PLOG(ERROR) << "Failed to mount " << path;
|
PLOG(ERROR) << "Failed to mount " << path;
|
||||||
return -errno;
|
return -errno;
|
||||||
|
@ -695,11 +686,8 @@ static android::status_t mountInNamespace(uid_t uid, int device_fd, const std::s
|
||||||
return android::OK;
|
return android::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static android::status_t runCommandInNamespace(const std::string& command,
|
static android::status_t runCommandInNamespace(const std::string& command, uid_t uid, pid_t pid,
|
||||||
uid_t uid,
|
const std::string& path, int device_fd) {
|
||||||
pid_t pid,
|
|
||||||
const std::string& path,
|
|
||||||
int device_fd) {
|
|
||||||
if (DEBUG_APPFUSE) {
|
if (DEBUG_APPFUSE) {
|
||||||
LOG(DEBUG) << "Run app fuse command " << command << " for the path " << path
|
LOG(DEBUG) << "Run app fuse command " << command << " for the path " << path
|
||||||
<< " in namespace " << uid;
|
<< " in namespace " << uid;
|
||||||
|
@ -713,8 +701,7 @@ static android::status_t runCommandInNamespace(const std::string& command,
|
||||||
|
|
||||||
// Obtains process file descriptor.
|
// Obtains process file descriptor.
|
||||||
const std::string pid_str = android::base::StringPrintf("%d", pid);
|
const std::string pid_str = android::base::StringPrintf("%d", pid);
|
||||||
const unique_fd pid_fd(
|
const unique_fd pid_fd(openat(dir.get(), pid_str.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC));
|
||||||
openat(dir.get(), pid_str.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC));
|
|
||||||
if (pid_fd.get() == -1) {
|
if (pid_fd.get() == -1) {
|
||||||
PLOG(ERROR) << "Failed to open /proc/" << pid;
|
PLOG(ERROR) << "Failed to open /proc/" << pid;
|
||||||
return -errno;
|
return -errno;
|
||||||
|
@ -730,7 +717,7 @@ static android::status_t runCommandInNamespace(const std::string& command,
|
||||||
}
|
}
|
||||||
if (sb.st_uid != AID_SYSTEM) {
|
if (sb.st_uid != AID_SYSTEM) {
|
||||||
LOG(ERROR) << "Only system can mount appfuse. UID expected=" << AID_SYSTEM
|
LOG(ERROR) << "Only system can mount appfuse. UID expected=" << AID_SYSTEM
|
||||||
<< ", actual=" << sb.st_uid;
|
<< ", actual=" << sb.st_uid;
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -739,8 +726,8 @@ static android::status_t runCommandInNamespace(const std::string& command,
|
||||||
{
|
{
|
||||||
std::string rootName;
|
std::string rootName;
|
||||||
std::string pidName;
|
std::string pidName;
|
||||||
if (!android::vold::Readlinkat(dir.get(), "1/ns/mnt", &rootName)
|
if (!android::vold::Readlinkat(dir.get(), "1/ns/mnt", &rootName) ||
|
||||||
|| !android::vold::Readlinkat(pid_fd.get(), "ns/mnt", &pidName)) {
|
!android::vold::Readlinkat(pid_fd.get(), "ns/mnt", &pidName)) {
|
||||||
PLOG(ERROR) << "Failed to read namespaces";
|
PLOG(ERROR) << "Failed to read namespaces";
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
}
|
}
|
||||||
|
@ -751,7 +738,7 @@ static android::status_t runCommandInNamespace(const std::string& command,
|
||||||
}
|
}
|
||||||
|
|
||||||
// We purposefully leave the namespace open across the fork
|
// We purposefully leave the namespace open across the fork
|
||||||
unique_fd ns_fd(openat(pid_fd.get(), "ns/mnt", O_RDONLY)); // not O_CLOEXEC
|
unique_fd ns_fd(openat(pid_fd.get(), "ns/mnt", O_RDONLY)); // not O_CLOEXEC
|
||||||
if (ns_fd.get() < 0) {
|
if (ns_fd.get() < 0) {
|
||||||
PLOG(ERROR) << "Failed to open namespace for /proc/" << pid << "/ns/mnt";
|
PLOG(ERROR) << "Failed to open namespace for /proc/" << pid << "/ns/mnt";
|
||||||
return -errno;
|
return -errno;
|
||||||
|
@ -769,8 +756,8 @@ static android::status_t runCommandInNamespace(const std::string& command,
|
||||||
} else if (command == "unmount") {
|
} else if (command == "unmount") {
|
||||||
// If it's just after all FD opened on mount point are closed, umount2 can fail with
|
// 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.
|
// EBUSY. To avoid the case, specify MNT_DETACH.
|
||||||
if (umount2(path.c_str(), UMOUNT_NOFOLLOW | MNT_DETACH) != 0 &&
|
if (umount2(path.c_str(), UMOUNT_NOFOLLOW | MNT_DETACH) != 0 && errno != EINVAL &&
|
||||||
errno != EINVAL && errno != ENOENT) {
|
errno != ENOENT) {
|
||||||
PLOG(ERROR) << "Failed to unmount directory.";
|
PLOG(ERROR) << "Failed to unmount directory.";
|
||||||
_exit(-errno);
|
_exit(-errno);
|
||||||
}
|
}
|
||||||
|
@ -797,11 +784,11 @@ static android::status_t runCommandInNamespace(const std::string& command,
|
||||||
}
|
}
|
||||||
|
|
||||||
int VolumeManager::createObb(const std::string& sourcePath, const std::string& sourceKey,
|
int VolumeManager::createObb(const std::string& sourcePath, const std::string& sourceKey,
|
||||||
int32_t ownerGid, std::string* outVolId) {
|
int32_t ownerGid, std::string* outVolId) {
|
||||||
int id = mNextObbId++;
|
int id = mNextObbId++;
|
||||||
|
|
||||||
auto vol = std::shared_ptr<android::vold::VolumeBase>(
|
auto vol = std::shared_ptr<android::vold::VolumeBase>(
|
||||||
new android::vold::ObbVolume(id, sourcePath, sourceKey, ownerGid));
|
new android::vold::ObbVolume(id, sourcePath, sourceKey, ownerGid));
|
||||||
vol->create();
|
vol->create();
|
||||||
|
|
||||||
mObbVolumes.push_back(vol);
|
mObbVolumes.push_back(vol);
|
||||||
|
@ -823,7 +810,7 @@ int VolumeManager::destroyObb(const std::string& volId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int VolumeManager::mountAppFuse(uid_t uid, pid_t pid, int mountId,
|
int VolumeManager::mountAppFuse(uid_t uid, pid_t pid, int mountId,
|
||||||
android::base::unique_fd* device_fd) {
|
android::base::unique_fd* device_fd) {
|
||||||
std::string name = std::to_string(mountId);
|
std::string name = std::to_string(mountId);
|
||||||
|
|
||||||
// Check mount point name.
|
// Check mount point name.
|
||||||
|
@ -841,7 +828,7 @@ int VolumeManager::mountAppFuse(uid_t uid, pid_t pid, int mountId,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open device FD.
|
// Open device FD.
|
||||||
device_fd->reset(open("/dev/fuse", O_RDWR)); // not O_CLOEXEC
|
device_fd->reset(open("/dev/fuse", O_RDWR)); // not O_CLOEXEC
|
||||||
if (device_fd->get() == -1) {
|
if (device_fd->get() == -1) {
|
||||||
PLOG(ERROR) << "Failed to open /dev/fuse";
|
PLOG(ERROR) << "Failed to open /dev/fuse";
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
#ifndef ANDROID_VOLD_VOLUME_MANAGER_H
|
#ifndef ANDROID_VOLD_VOLUME_MANAGER_H
|
||||||
#define ANDROID_VOLD_VOLUME_MANAGER_H
|
#define ANDROID_VOLD_VOLUME_MANAGER_H
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
|
#include <pthread.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
@ -29,9 +29,9 @@
|
||||||
|
|
||||||
#include <android-base/unique_fd.h>
|
#include <android-base/unique_fd.h>
|
||||||
#include <cutils/multiuser.h>
|
#include <cutils/multiuser.h>
|
||||||
|
#include <sysutils/NetlinkEvent.h>
|
||||||
#include <utils/List.h>
|
#include <utils/List.h>
|
||||||
#include <utils/Timers.h>
|
#include <utils/Timers.h>
|
||||||
#include <sysutils/NetlinkEvent.h>
|
|
||||||
|
|
||||||
#include "android/os/IVoldListener.h"
|
#include "android/os/IVoldListener.h"
|
||||||
|
|
||||||
|
@ -41,12 +41,12 @@
|
||||||
#define DEBUG_APPFUSE 0
|
#define DEBUG_APPFUSE 0
|
||||||
|
|
||||||
class VolumeManager {
|
class VolumeManager {
|
||||||
private:
|
private:
|
||||||
static VolumeManager *sInstance;
|
static VolumeManager* sInstance;
|
||||||
|
|
||||||
bool mDebug;
|
bool mDebug;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~VolumeManager();
|
virtual ~VolumeManager();
|
||||||
|
|
||||||
// TODO: pipe all requests through VM to avoid exposing this lock
|
// TODO: pipe all requests through VM to avoid exposing this lock
|
||||||
|
@ -59,13 +59,12 @@ public:
|
||||||
int start();
|
int start();
|
||||||
int stop();
|
int stop();
|
||||||
|
|
||||||
void handleBlockEvent(NetlinkEvent *evt);
|
void handleBlockEvent(NetlinkEvent* evt);
|
||||||
|
|
||||||
class DiskSource {
|
class DiskSource {
|
||||||
public:
|
public:
|
||||||
DiskSource(const std::string& sysPattern, const std::string& nickname, int flags) :
|
DiskSource(const std::string& sysPattern, const std::string& nickname, int flags)
|
||||||
mSysPattern(sysPattern), mNickname(nickname), mFlags(flags) {
|
: mSysPattern(sysPattern), mNickname(nickname), mFlags(flags) {}
|
||||||
}
|
|
||||||
|
|
||||||
bool matches(const std::string& sysPath) {
|
bool matches(const std::string& sysPath) {
|
||||||
return !fnmatch(mSysPattern.c_str(), sysPath.c_str(), 0);
|
return !fnmatch(mSysPattern.c_str(), sysPath.c_str(), 0);
|
||||||
|
@ -74,7 +73,7 @@ public:
|
||||||
const std::string& getNickname() { return mNickname; }
|
const std::string& getNickname() { return mNickname; }
|
||||||
int getFlags() { return mFlags; }
|
int getFlags() { return mFlags; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string mSysPattern;
|
std::string mSysPattern;
|
||||||
std::string mNickname;
|
std::string mNickname;
|
||||||
int mFlags;
|
int mFlags;
|
||||||
|
@ -110,7 +109,7 @@ public:
|
||||||
int updateVirtualDisk();
|
int updateVirtualDisk();
|
||||||
int setDebug(bool enable);
|
int setDebug(bool enable);
|
||||||
|
|
||||||
static VolumeManager *Instance();
|
static VolumeManager* Instance();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ensure that all directories along given path exist, creating parent
|
* Ensure that all directories along given path exist, creating parent
|
||||||
|
@ -122,13 +121,13 @@ public:
|
||||||
int mkdirs(const std::string& path);
|
int mkdirs(const std::string& path);
|
||||||
|
|
||||||
int createObb(const std::string& path, const std::string& key, int32_t ownerGid,
|
int createObb(const std::string& path, const std::string& key, int32_t ownerGid,
|
||||||
std::string* outVolId);
|
std::string* outVolId);
|
||||||
int destroyObb(const std::string& volId);
|
int destroyObb(const std::string& volId);
|
||||||
|
|
||||||
int mountAppFuse(uid_t uid, pid_t pid, int mountId, android::base::unique_fd* device_fd);
|
int mountAppFuse(uid_t uid, pid_t pid, int mountId, android::base::unique_fd* device_fd);
|
||||||
int unmountAppFuse(uid_t uid, pid_t pid, int mountId);
|
int unmountAppFuse(uid_t uid, pid_t pid, int mountId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VolumeManager();
|
VolumeManager();
|
||||||
void readInitialState();
|
void readInitialState();
|
||||||
|
|
||||||
|
|
|
@ -44,14 +44,14 @@ interface IVold {
|
||||||
void checkEncryption(@utf8InCpp String volId);
|
void checkEncryption(@utf8InCpp String volId);
|
||||||
|
|
||||||
void moveStorage(@utf8InCpp String fromVolId, @utf8InCpp String toVolId,
|
void moveStorage(@utf8InCpp String fromVolId, @utf8InCpp String toVolId,
|
||||||
IVoldTaskListener listener);
|
IVoldTaskListener listener);
|
||||||
|
|
||||||
void remountUid(int uid, int remountMode);
|
void remountUid(int uid, int remountMode);
|
||||||
|
|
||||||
void mkdirs(@utf8InCpp String path);
|
void mkdirs(@utf8InCpp String path);
|
||||||
|
|
||||||
@utf8InCpp String createObb(@utf8InCpp String sourcePath,
|
@utf8InCpp String createObb(@utf8InCpp String sourcePath, @utf8InCpp String sourceKey,
|
||||||
@utf8InCpp String sourceKey, int ownerGid);
|
int ownerGid);
|
||||||
void destroyObb(@utf8InCpp String volId);
|
void destroyObb(@utf8InCpp String volId);
|
||||||
|
|
||||||
void fstrim(int fstrimFlags, IVoldTaskListener listener);
|
void fstrim(int fstrimFlags, IVoldTaskListener listener);
|
||||||
|
@ -84,13 +84,16 @@ interface IVold {
|
||||||
void createUserKey(int userId, int userSerial, boolean ephemeral);
|
void createUserKey(int userId, int userSerial, boolean ephemeral);
|
||||||
void destroyUserKey(int userId);
|
void destroyUserKey(int userId);
|
||||||
|
|
||||||
void addUserKeyAuth(int userId, int userSerial, @utf8InCpp String token, @utf8InCpp String secret);
|
void addUserKeyAuth(int userId, int userSerial, @utf8InCpp String token,
|
||||||
|
@utf8InCpp String secret);
|
||||||
void fixateNewestUserKeyAuth(int userId);
|
void fixateNewestUserKeyAuth(int userId);
|
||||||
|
|
||||||
void unlockUserKey(int userId, int userSerial, @utf8InCpp String token, @utf8InCpp String secret);
|
void unlockUserKey(int userId, int userSerial, @utf8InCpp String token,
|
||||||
|
@utf8InCpp String secret);
|
||||||
void lockUserKey(int userId);
|
void lockUserKey(int userId);
|
||||||
|
|
||||||
void prepareUserStorage(@nullable @utf8InCpp String uuid, int userId, int userSerial, int storageFlags);
|
void prepareUserStorage(@nullable @utf8InCpp String uuid, int userId, int userSerial,
|
||||||
|
int storageFlags);
|
||||||
void destroyUserStorage(@nullable @utf8InCpp String uuid, int userId, int storageFlags);
|
void destroyUserStorage(@nullable @utf8InCpp String uuid, int userId, int storageFlags);
|
||||||
|
|
||||||
const int ENCRYPTION_FLAG_NO_UI = 4;
|
const int ENCRYPTION_FLAG_NO_UI = 4;
|
||||||
|
|
|
@ -27,8 +27,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/sysmacros.h>
|
#include <sys/sysmacros.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
using android::base::StringPrintf;
|
using android::base::StringPrintf;
|
||||||
|
@ -38,22 +38,21 @@ namespace vold {
|
||||||
|
|
||||||
static const char* kFusePath = "/system/bin/sdcard";
|
static const char* kFusePath = "/system/bin/sdcard";
|
||||||
|
|
||||||
EmulatedVolume::EmulatedVolume(const std::string& rawPath) :
|
EmulatedVolume::EmulatedVolume(const std::string& rawPath)
|
||||||
VolumeBase(Type::kEmulated), mFusePid(0) {
|
: VolumeBase(Type::kEmulated), mFusePid(0) {
|
||||||
setId("emulated");
|
setId("emulated");
|
||||||
mRawPath = rawPath;
|
mRawPath = rawPath;
|
||||||
mLabel = "emulated";
|
mLabel = "emulated";
|
||||||
}
|
}
|
||||||
|
|
||||||
EmulatedVolume::EmulatedVolume(const std::string& rawPath, dev_t device,
|
EmulatedVolume::EmulatedVolume(const std::string& rawPath, dev_t device, const std::string& fsUuid)
|
||||||
const std::string& fsUuid) : VolumeBase(Type::kEmulated), mFusePid(0) {
|
: VolumeBase(Type::kEmulated), mFusePid(0) {
|
||||||
setId(StringPrintf("emulated:%u,%u", major(device), minor(device)));
|
setId(StringPrintf("emulated:%u,%u", major(device), minor(device)));
|
||||||
mRawPath = rawPath;
|
mRawPath = rawPath;
|
||||||
mLabel = fsUuid;
|
mLabel = fsUuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
EmulatedVolume::~EmulatedVolume() {
|
EmulatedVolume::~EmulatedVolume() {}
|
||||||
}
|
|
||||||
|
|
||||||
status_t EmulatedVolume::doMount() {
|
status_t EmulatedVolume::doMount() {
|
||||||
// We could have migrated storage to an adopted private volume, so always
|
// We could have migrated storage to an adopted private volume, so always
|
||||||
|
@ -71,8 +70,8 @@ status_t EmulatedVolume::doMount() {
|
||||||
setPath(StringPrintf("/storage/%s", label.c_str()));
|
setPath(StringPrintf("/storage/%s", label.c_str()));
|
||||||
|
|
||||||
if (fs_prepare_dir(mFuseDefault.c_str(), 0700, AID_ROOT, AID_ROOT) ||
|
if (fs_prepare_dir(mFuseDefault.c_str(), 0700, AID_ROOT, AID_ROOT) ||
|
||||||
fs_prepare_dir(mFuseRead.c_str(), 0700, AID_ROOT, AID_ROOT) ||
|
fs_prepare_dir(mFuseRead.c_str(), 0700, AID_ROOT, AID_ROOT) ||
|
||||||
fs_prepare_dir(mFuseWrite.c_str(), 0700, AID_ROOT, AID_ROOT)) {
|
fs_prepare_dir(mFuseWrite.c_str(), 0700, AID_ROOT, AID_ROOT)) {
|
||||||
PLOG(ERROR) << getId() << " failed to create mount points";
|
PLOG(ERROR) << getId() << " failed to create mount points";
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
@ -80,6 +79,7 @@ status_t EmulatedVolume::doMount() {
|
||||||
dev_t before = GetDevice(mFuseWrite);
|
dev_t before = GetDevice(mFuseWrite);
|
||||||
|
|
||||||
if (!(mFusePid = fork())) {
|
if (!(mFusePid = fork())) {
|
||||||
|
// clang-format off
|
||||||
if (execl(kFusePath, kFusePath,
|
if (execl(kFusePath, kFusePath,
|
||||||
"-u", "1023", // AID_MEDIA_RW
|
"-u", "1023", // AID_MEDIA_RW
|
||||||
"-g", "1023", // AID_MEDIA_RW
|
"-g", "1023", // AID_MEDIA_RW
|
||||||
|
@ -90,6 +90,7 @@ status_t EmulatedVolume::doMount() {
|
||||||
mRawPath.c_str(),
|
mRawPath.c_str(),
|
||||||
label.c_str(),
|
label.c_str(),
|
||||||
NULL)) {
|
NULL)) {
|
||||||
|
// clang-format on
|
||||||
PLOG(ERROR) << "Failed to exec";
|
PLOG(ERROR) << "Failed to exec";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +106,7 @@ status_t EmulatedVolume::doMount() {
|
||||||
nsecs_t start = systemTime(SYSTEM_TIME_BOOTTIME);
|
nsecs_t start = systemTime(SYSTEM_TIME_BOOTTIME);
|
||||||
while (before == GetDevice(mFuseWrite)) {
|
while (before == GetDevice(mFuseWrite)) {
|
||||||
LOG(VERBOSE) << "Waiting for FUSE to spin up...";
|
LOG(VERBOSE) << "Waiting for FUSE to spin up...";
|
||||||
usleep(50000); // 50ms
|
usleep(50000); // 50ms
|
||||||
|
|
||||||
nsecs_t now = systemTime(SYSTEM_TIME_BOOTTIME);
|
nsecs_t now = systemTime(SYSTEM_TIME_BOOTTIME);
|
||||||
if (nanoseconds_to_milliseconds(now - start) > 5000) {
|
if (nanoseconds_to_milliseconds(now - start) > 5000) {
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
#include "fs/Exfat.h"
|
#include "fs/Exfat.h"
|
||||||
#include "fs/Vfat.h"
|
#include "fs/Vfat.h"
|
||||||
|
|
||||||
#include <android-base/stringprintf.h>
|
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
|
#include <android-base/stringprintf.h>
|
||||||
#include <cutils/fs.h>
|
#include <cutils/fs.h>
|
||||||
#include <private/android_filesystem_config.h>
|
#include <private/android_filesystem_config.h>
|
||||||
#include <utils/Timers.h>
|
#include <utils/Timers.h>
|
||||||
|
@ -30,8 +30,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/sysmacros.h>
|
#include <sys/sysmacros.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
using android::base::StringPrintf;
|
using android::base::StringPrintf;
|
||||||
|
@ -43,14 +43,12 @@ static const char* kFusePath = "/system/bin/sdcard";
|
||||||
|
|
||||||
static const char* kAsecPath = "/mnt/secure/asec";
|
static const char* kAsecPath = "/mnt/secure/asec";
|
||||||
|
|
||||||
PublicVolume::PublicVolume(dev_t device) :
|
PublicVolume::PublicVolume(dev_t device) : VolumeBase(Type::kPublic), mDevice(device), mFusePid(0) {
|
||||||
VolumeBase(Type::kPublic), mDevice(device), mFusePid(0) {
|
|
||||||
setId(StringPrintf("public:%u,%u", major(device), minor(device)));
|
setId(StringPrintf("public:%u,%u", major(device), minor(device)));
|
||||||
mDevPath = StringPrintf("/dev/block/vold/%s", getId().c_str());
|
mDevPath = StringPrintf("/dev/block/vold/%s", getId().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
PublicVolume::~PublicVolume() {
|
PublicVolume::~PublicVolume() {}
|
||||||
}
|
|
||||||
|
|
||||||
status_t PublicVolume::readMetadata() {
|
status_t PublicVolume::readMetadata() {
|
||||||
status_t res = ReadMetadataUntrusted(mDevPath, &mFsType, &mFsUuid, &mFsLabel);
|
status_t res = ReadMetadataUntrusted(mDevPath, &mFsType, &mFsUuid, &mFsLabel);
|
||||||
|
@ -66,8 +64,7 @@ status_t PublicVolume::initAsecStage() {
|
||||||
std::string securePath(mRawPath + "/.android_secure");
|
std::string securePath(mRawPath + "/.android_secure");
|
||||||
|
|
||||||
// Recover legacy secure path
|
// Recover legacy secure path
|
||||||
if (!access(legacyPath.c_str(), R_OK | X_OK)
|
if (!access(legacyPath.c_str(), R_OK | X_OK) && access(securePath.c_str(), R_OK | X_OK)) {
|
||||||
&& access(securePath.c_str(), R_OK | X_OK)) {
|
|
||||||
if (rename(legacyPath.c_str(), securePath.c_str())) {
|
if (rename(legacyPath.c_str(), securePath.c_str())) {
|
||||||
PLOG(WARNING) << getId() << " failed to rename legacy ASEC dir";
|
PLOG(WARNING) << getId() << " failed to rename legacy ASEC dir";
|
||||||
}
|
}
|
||||||
|
@ -158,8 +155,8 @@ status_t PublicVolume::doMount() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs_prepare_dir(mFuseDefault.c_str(), 0700, AID_ROOT, AID_ROOT) ||
|
if (fs_prepare_dir(mFuseDefault.c_str(), 0700, AID_ROOT, AID_ROOT) ||
|
||||||
fs_prepare_dir(mFuseRead.c_str(), 0700, AID_ROOT, AID_ROOT) ||
|
fs_prepare_dir(mFuseRead.c_str(), 0700, AID_ROOT, AID_ROOT) ||
|
||||||
fs_prepare_dir(mFuseWrite.c_str(), 0700, AID_ROOT, AID_ROOT)) {
|
fs_prepare_dir(mFuseWrite.c_str(), 0700, AID_ROOT, AID_ROOT)) {
|
||||||
PLOG(ERROR) << getId() << " failed to create FUSE mount points";
|
PLOG(ERROR) << getId() << " failed to create FUSE mount points";
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
@ -168,6 +165,7 @@ status_t PublicVolume::doMount() {
|
||||||
|
|
||||||
if (!(mFusePid = fork())) {
|
if (!(mFusePid = fork())) {
|
||||||
if (getMountFlags() & MountFlags::kPrimary) {
|
if (getMountFlags() & MountFlags::kPrimary) {
|
||||||
|
// clang-format off
|
||||||
if (execl(kFusePath, kFusePath,
|
if (execl(kFusePath, kFusePath,
|
||||||
"-u", "1023", // AID_MEDIA_RW
|
"-u", "1023", // AID_MEDIA_RW
|
||||||
"-g", "1023", // AID_MEDIA_RW
|
"-g", "1023", // AID_MEDIA_RW
|
||||||
|
@ -176,9 +174,11 @@ status_t PublicVolume::doMount() {
|
||||||
mRawPath.c_str(),
|
mRawPath.c_str(),
|
||||||
stableName.c_str(),
|
stableName.c_str(),
|
||||||
NULL)) {
|
NULL)) {
|
||||||
|
// clang-format on
|
||||||
PLOG(ERROR) << "Failed to exec";
|
PLOG(ERROR) << "Failed to exec";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// clang-format off
|
||||||
if (execl(kFusePath, kFusePath,
|
if (execl(kFusePath, kFusePath,
|
||||||
"-u", "1023", // AID_MEDIA_RW
|
"-u", "1023", // AID_MEDIA_RW
|
||||||
"-g", "1023", // AID_MEDIA_RW
|
"-g", "1023", // AID_MEDIA_RW
|
||||||
|
@ -186,6 +186,7 @@ status_t PublicVolume::doMount() {
|
||||||
mRawPath.c_str(),
|
mRawPath.c_str(),
|
||||||
stableName.c_str(),
|
stableName.c_str(),
|
||||||
NULL)) {
|
NULL)) {
|
||||||
|
// clang-format on
|
||||||
PLOG(ERROR) << "Failed to exec";
|
PLOG(ERROR) << "Failed to exec";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,7 +203,7 @@ status_t PublicVolume::doMount() {
|
||||||
nsecs_t start = systemTime(SYSTEM_TIME_BOOTTIME);
|
nsecs_t start = systemTime(SYSTEM_TIME_BOOTTIME);
|
||||||
while (before == GetDevice(mFuseWrite)) {
|
while (before == GetDevice(mFuseWrite)) {
|
||||||
LOG(VERBOSE) << "Waiting for FUSE to spin up...";
|
LOG(VERBOSE) << "Waiting for FUSE to spin up...";
|
||||||
usleep(50000); // 50ms
|
usleep(50000); // 50ms
|
||||||
|
|
||||||
nsecs_t now = systemTime(SYSTEM_TIME_BOOTTIME);
|
nsecs_t now = systemTime(SYSTEM_TIME_BOOTTIME);
|
||||||
if (nanoseconds_to_milliseconds(now - start) > 5000) {
|
if (nanoseconds_to_milliseconds(now - start) > 5000) {
|
||||||
|
|
|
@ -14,12 +14,12 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Utils.h"
|
|
||||||
#include "VolumeBase.h"
|
#include "VolumeBase.h"
|
||||||
|
#include "Utils.h"
|
||||||
#include "VolumeManager.h"
|
#include "VolumeManager.h"
|
||||||
|
|
||||||
#include <android-base/stringprintf.h>
|
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
|
#include <android-base/stringprintf.h>
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -32,10 +32,13 @@ using android::base::StringPrintf;
|
||||||
namespace android {
|
namespace android {
|
||||||
namespace vold {
|
namespace vold {
|
||||||
|
|
||||||
VolumeBase::VolumeBase(Type type) :
|
VolumeBase::VolumeBase(Type type)
|
||||||
mType(type), mMountFlags(0), mMountUserId(-1), mCreated(false), mState(
|
: mType(type),
|
||||||
State::kUnmounted), mSilent(false) {
|
mMountFlags(0),
|
||||||
}
|
mMountUserId(-1),
|
||||||
|
mCreated(false),
|
||||||
|
mState(State::kUnmounted),
|
||||||
|
mSilent(false) {}
|
||||||
|
|
||||||
VolumeBase::~VolumeBase() {
|
VolumeBase::~VolumeBase() {
|
||||||
CHECK(!mCreated);
|
CHECK(!mCreated);
|
||||||
|
@ -45,7 +48,9 @@ void VolumeBase::setState(State state) {
|
||||||
mState = state;
|
mState = state;
|
||||||
|
|
||||||
auto listener = getListener();
|
auto listener = getListener();
|
||||||
if (listener) listener->onVolumeStateChanged(getId(), static_cast<int32_t>(mState));
|
if (listener) {
|
||||||
|
listener->onVolumeStateChanged(getId(), static_cast<int32_t>(mState));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t VolumeBase::setDiskId(const std::string& diskId) {
|
status_t VolumeBase::setDiskId(const std::string& diskId) {
|
||||||
|
@ -131,7 +136,9 @@ status_t VolumeBase::setInternalPath(const std::string& internalPath) {
|
||||||
mInternalPath = internalPath;
|
mInternalPath = internalPath;
|
||||||
|
|
||||||
auto listener = getListener();
|
auto listener = getListener();
|
||||||
if (listener) listener->onVolumeInternalPathChanged(getId(), mInternalPath);
|
if (listener) {
|
||||||
|
listener->onVolumeInternalPathChanged(getId(), mInternalPath);
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
@ -168,8 +175,9 @@ status_t VolumeBase::create() {
|
||||||
status_t res = doCreate();
|
status_t res = doCreate();
|
||||||
|
|
||||||
auto listener = getListener();
|
auto listener = getListener();
|
||||||
if (listener) listener->onVolumeCreated(getId(),
|
if (listener) {
|
||||||
static_cast<int32_t>(mType), mDiskId, mPartGuid);
|
listener->onVolumeCreated(getId(), static_cast<int32_t>(mType), mDiskId, mPartGuid);
|
||||||
|
}
|
||||||
|
|
||||||
setState(State::kUnmounted);
|
setState(State::kUnmounted);
|
||||||
return res;
|
return res;
|
||||||
|
@ -189,9 +197,10 @@ status_t VolumeBase::destroy() {
|
||||||
setState(State::kRemoved);
|
setState(State::kRemoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
auto listener = getListener();
|
auto listener = getListener();
|
||||||
if (listener) listener->onVolumeDestroyed(getId());
|
if (listener) {
|
||||||
|
listener->onVolumeDestroyed(getId());
|
||||||
|
}
|
||||||
|
|
||||||
status_t res = doDestroy();
|
status_t res = doDestroy();
|
||||||
mCreated = false;
|
mCreated = false;
|
||||||
|
@ -228,8 +237,7 @@ status_t VolumeBase::unmount() {
|
||||||
setState(State::kEjecting);
|
setState(State::kEjecting);
|
||||||
for (const auto& vol : mVolumes) {
|
for (const auto& vol : mVolumes) {
|
||||||
if (vol->destroy()) {
|
if (vol->destroy()) {
|
||||||
LOG(WARNING) << getId() << " failed to destroy " << vol->getId()
|
LOG(WARNING) << getId() << " failed to destroy " << vol->getId() << " stacked above";
|
||||||
<< " stacked above";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mVolumes.clear();
|
mVolumes.clear();
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
#ifndef ANDROID_VOLD_VOLUME_BASE_H
|
#ifndef ANDROID_VOLD_VOLUME_BASE_H
|
||||||
#define ANDROID_VOLD_VOLUME_BASE_H
|
#define ANDROID_VOLD_VOLUME_BASE_H
|
||||||
|
|
||||||
#include "android/os/IVoldListener.h"
|
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
#include "android/os/IVoldListener.h"
|
||||||
|
|
||||||
#include <cutils/multiuser.h>
|
#include <cutils/multiuser.h>
|
||||||
#include <utils/Errors.h>
|
#include <utils/Errors.h>
|
||||||
|
@ -45,7 +45,7 @@ namespace vold {
|
||||||
* volumes and removes any bind mounts before finally unmounting itself.
|
* volumes and removes any bind mounts before finally unmounting itself.
|
||||||
*/
|
*/
|
||||||
class VolumeBase {
|
class VolumeBase {
|
||||||
public:
|
public:
|
||||||
virtual ~VolumeBase();
|
virtual ~VolumeBase();
|
||||||
|
|
||||||
enum class Type {
|
enum class Type {
|
||||||
|
@ -102,7 +102,7 @@ public:
|
||||||
status_t unmount();
|
status_t unmount();
|
||||||
status_t format(const std::string& fsType);
|
status_t format(const std::string& fsType);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit VolumeBase(Type type);
|
explicit VolumeBase(Type type);
|
||||||
|
|
||||||
virtual status_t doCreate();
|
virtual status_t doCreate();
|
||||||
|
@ -117,7 +117,7 @@ protected:
|
||||||
|
|
||||||
android::sp<android::os::IVoldListener> getListener();
|
android::sp<android::os::IVoldListener> getListener();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* ID that uniquely references volume while alive */
|
/* ID that uniquely references volume while alive */
|
||||||
std::string mId;
|
std::string mId;
|
||||||
/* ID that uniquely references parent disk while alive */
|
/* ID that uniquely references parent disk while alive */
|
||||||
|
|
Loading…
Reference in a new issue