2017-09-06 21:47:40 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 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
|
|
|
|
|
2017-09-06 21:47:40 +02:00
|
|
|
#include "VoldNativeService.h"
|
2020-02-03 21:22:03 +01:00
|
|
|
|
2020-03-04 02:58:20 +01:00
|
|
|
#include <android-base/logging.h>
|
|
|
|
#include <android-base/strings.h>
|
|
|
|
#include <fs_mgr.h>
|
|
|
|
#include <fscrypt/fscrypt.h>
|
|
|
|
#include <private/android_filesystem_config.h>
|
|
|
|
#include <utils/Trace.h>
|
|
|
|
|
2021-10-14 01:50:10 +02:00
|
|
|
#include <stdio.h>
|
2020-03-04 02:58:20 +01:00
|
|
|
#include <fstream>
|
|
|
|
#include <thread>
|
|
|
|
|
2017-10-18 00:06:32 +02:00
|
|
|
#include "Benchmark.h"
|
2020-02-03 21:22:03 +01:00
|
|
|
#include "Checkpoint.h"
|
|
|
|
#include "FsCrypt.h"
|
2017-06-15 17:59:43 +02:00
|
|
|
#include "IdleMaint.h"
|
2021-01-19 18:51:51 +01:00
|
|
|
#include "KeyStorage.h"
|
2021-06-15 20:34:00 +02:00
|
|
|
#include "Keystore.h"
|
2020-02-03 21:22:03 +01:00
|
|
|
#include "MetadataCrypt.h"
|
2017-10-18 00:06:32 +02:00
|
|
|
#include "MoveStorage.h"
|
2020-03-25 07:49:02 +01:00
|
|
|
#include "VoldNativeServiceValidation.h"
|
2020-02-03 21:22:03 +01:00
|
|
|
#include "VoldUtil.h"
|
2017-06-15 17:59:43 +02:00
|
|
|
#include "VolumeManager.h"
|
2018-09-19 00:14:18 +02:00
|
|
|
#include "cryptfs.h"
|
2020-04-23 08:23:24 +02:00
|
|
|
#include "incfs.h"
|
2017-09-13 00:30:52 +02:00
|
|
|
|
2020-03-25 07:49:02 +01:00
|
|
|
using namespace std::literals;
|
2017-09-06 21:47:40 +02:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace vold {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr const char* kDump = "android.permission.DUMP";
|
2021-04-01 22:43:14 +02:00
|
|
|
constexpr auto kIncFsReadNoTimeoutMs = 100;
|
2017-09-06 21:47:40 +02:00
|
|
|
|
2017-09-07 23:27:28 +02:00
|
|
|
static binder::Status error(const std::string& msg) {
|
|
|
|
PLOG(ERROR) << msg;
|
|
|
|
return binder::Status::fromServiceSpecificError(errno, String8(msg.c_str()));
|
|
|
|
}
|
|
|
|
|
2017-09-13 00:30:52 +02:00
|
|
|
static binder::Status translate(int status) {
|
2017-09-07 23:27:28 +02:00
|
|
|
if (status == 0) {
|
|
|
|
return binder::Status::ok();
|
|
|
|
} else {
|
2017-09-11 18:32:01 +02:00
|
|
|
return binder::Status::fromServiceSpecificError(status);
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-13 00:30:52 +02:00
|
|
|
static binder::Status translateBool(bool status) {
|
|
|
|
if (status) {
|
|
|
|
return binder::Status::ok();
|
|
|
|
} else {
|
|
|
|
return binder::Status::fromServiceSpecificError(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-23 18:19:13 +02:00
|
|
|
#define ENFORCE_SYSTEM_OR_ROOT \
|
|
|
|
{ \
|
2020-03-25 07:49:02 +01:00
|
|
|
binder::Status status = CheckUidOrRoot(AID_SYSTEM); \
|
2019-10-23 18:19:13 +02:00
|
|
|
if (!status.isOk()) { \
|
|
|
|
return status; \
|
|
|
|
} \
|
2018-09-19 00:14:18 +02:00
|
|
|
}
|
2017-09-06 21:47:40 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
#define CHECK_ARGUMENT_ID(id) \
|
|
|
|
{ \
|
2020-03-25 07:49:02 +01:00
|
|
|
binder::Status status = CheckArgumentId((id)); \
|
2018-09-19 00:14:18 +02:00
|
|
|
if (!status.isOk()) { \
|
|
|
|
return status; \
|
|
|
|
} \
|
|
|
|
}
|
2017-09-12 21:19:24 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
#define CHECK_ARGUMENT_PATH(path) \
|
|
|
|
{ \
|
2020-03-25 07:49:02 +01:00
|
|
|
binder::Status status = CheckArgumentPath((path)); \
|
2018-09-19 00:14:18 +02:00
|
|
|
if (!status.isOk()) { \
|
|
|
|
return status; \
|
|
|
|
} \
|
|
|
|
}
|
2017-09-12 21:19:24 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
#define CHECK_ARGUMENT_HEX(hex) \
|
|
|
|
{ \
|
2020-03-25 07:49:02 +01:00
|
|
|
binder::Status status = CheckArgumentHex((hex)); \
|
2018-09-19 00:14:18 +02:00
|
|
|
if (!status.isOk()) { \
|
|
|
|
return status; \
|
|
|
|
} \
|
|
|
|
}
|
2017-09-12 21:19:24 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
#define ACQUIRE_LOCK \
|
2017-09-22 01:08:43 +02:00
|
|
|
std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \
|
|
|
|
ATRACE_CALL();
|
2017-09-13 00:30:52 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
#define ACQUIRE_CRYPT_LOCK \
|
2017-09-22 01:08:43 +02:00
|
|
|
std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \
|
|
|
|
ATRACE_CALL();
|
2017-09-07 23:27:28 +02:00
|
|
|
|
2017-09-06 21:47:40 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
status_t VoldNativeService::start() {
|
|
|
|
IPCThreadState::self()->disableBackgroundScheduling(true);
|
|
|
|
status_t ret = BinderService<VoldNativeService>::publish();
|
|
|
|
if (ret != android::OK) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
sp<ProcessState> ps(ProcessState::self());
|
|
|
|
ps->startThreadPool();
|
|
|
|
ps->giveThreadPoolName();
|
|
|
|
return android::OK;
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
status_t VoldNativeService::dump(int fd, const Vector<String16>& /* args */) {
|
2020-03-25 07:49:02 +01:00
|
|
|
const binder::Status dump_permission = CheckPermission(kDump);
|
2017-09-06 21:47:40 +02:00
|
|
|
if (!dump_permission.isOk()) {
|
2021-10-14 01:50:10 +02:00
|
|
|
dprintf(fd, "%s\n", dump_permission.toString8().c_str());
|
2017-09-06 21:47:40 +02:00
|
|
|
return PERMISSION_DENIED;
|
|
|
|
}
|
|
|
|
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
2021-10-14 01:50:10 +02:00
|
|
|
dprintf(fd, "vold is happy!\n");
|
2017-09-06 21:47:40 +02:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2017-09-13 19:49:44 +02:00
|
|
|
binder::Status VoldNativeService::setListener(
|
2020-03-04 02:58:20 +01:00
|
|
|
const android::sp<android::os::IVoldListener>& listener) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 19:49:44 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
VolumeManager::Instance()->setListener(listener);
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2017-09-13 19:49:44 +02:00
|
|
|
}
|
|
|
|
|
2017-09-16 00:50:28 +02:00
|
|
|
binder::Status VoldNativeService::monitor() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-16 00:50:28 +02:00
|
|
|
|
|
|
|
// Simply acquire/release each lock for watchdog
|
2018-09-19 00:14:18 +02:00
|
|
|
{ ACQUIRE_LOCK; }
|
|
|
|
{ ACQUIRE_CRYPT_LOCK; }
|
2017-09-16 00:50:28 +02:00
|
|
|
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2017-09-16 00:50:28 +02:00
|
|
|
}
|
|
|
|
|
2017-09-06 21:47:40 +02:00
|
|
|
binder::Status VoldNativeService::reset() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->reset());
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::shutdown() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->shutdown());
|
|
|
|
}
|
|
|
|
|
2020-04-29 07:49:41 +02:00
|
|
|
binder::Status VoldNativeService::abortFuse() {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2021-03-17 09:51:16 +01:00
|
|
|
// if acquire lock, maybe lead to a deadlock if lock is held by a
|
|
|
|
// thread that is blocked on a FUSE operation.
|
|
|
|
// abort fuse doesn't need to access any state, so do not acquire lock
|
2020-04-29 07:49:41 +02:00
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->abortFuse());
|
|
|
|
}
|
|
|
|
|
Support bind mounting volumes into other volume's mountpoint.
With the way the FUSE mount point are currently setup for emulated
volumes, there can be multiple paths that serve the same files on the
lower filesystem; eg
* /mnt/user/0/emulated/0/Android
* /mnt/user/10/emulated/0/Android
both refer to the same file on the lower filesystem:
* /data/media/0/Android
this is normally not a problem, because cross-user file access is not
allowed, and so the FUSE daemon won't serve files for other users.
With clone profiles this is no longer true however, as their volumes
are accessible by each other.
So, it can happen that an app running in clone profile 10 accesses
"/mnt/user/10/emulated/0/Android", which would be served by the FUSE
daemon for the user 10 filesystem.
At the same time, an app running in the owner profile 0 accesses
"mnt/user/0/emulated/0/Android", which would be served by the FUSE
daemon for the user 0 filesystem.
This can cause page cache inconsistencies, because multiple FUSE daemons
can be running on top of the same entries in the lower filesystem.
To prevent this, use bind mounts to make sure that cross-profile
accesses actually end up in the FUSE daemon to which the volume
belongs: "/mnt/user/10/emulated/0" is bind-mounted to
"/mnt/user/0/emulated/0", and vice-versa.
Bug: 228271997
Test: manual
Change-Id: Iefcbc813670628b329a1a5d408b6126b84991e09
2022-07-12 10:11:02 +02:00
|
|
|
binder::Status VoldNativeService::onUserAdded(int32_t userId, int32_t userSerial,
|
|
|
|
int32_t sharesStorageWithUserId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
Support bind mounting volumes into other volume's mountpoint.
With the way the FUSE mount point are currently setup for emulated
volumes, there can be multiple paths that serve the same files on the
lower filesystem; eg
* /mnt/user/0/emulated/0/Android
* /mnt/user/10/emulated/0/Android
both refer to the same file on the lower filesystem:
* /data/media/0/Android
this is normally not a problem, because cross-user file access is not
allowed, and so the FUSE daemon won't serve files for other users.
With clone profiles this is no longer true however, as their volumes
are accessible by each other.
So, it can happen that an app running in clone profile 10 accesses
"/mnt/user/10/emulated/0/Android", which would be served by the FUSE
daemon for the user 10 filesystem.
At the same time, an app running in the owner profile 0 accesses
"mnt/user/0/emulated/0/Android", which would be served by the FUSE
daemon for the user 0 filesystem.
This can cause page cache inconsistencies, because multiple FUSE daemons
can be running on top of the same entries in the lower filesystem.
To prevent this, use bind mounts to make sure that cross-profile
accesses actually end up in the FUSE daemon to which the volume
belongs: "/mnt/user/10/emulated/0" is bind-mounted to
"/mnt/user/0/emulated/0", and vice-versa.
Bug: 228271997
Test: manual
Change-Id: Iefcbc813670628b329a1a5d408b6126b84991e09
2022-07-12 10:11:02 +02:00
|
|
|
return translate(
|
|
|
|
VolumeManager::Instance()->onUserAdded(userId, userSerial, sharesStorageWithUserId));
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::onUserRemoved(int32_t userId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->onUserRemoved(userId));
|
|
|
|
}
|
|
|
|
|
2019-04-29 19:46:35 +02:00
|
|
|
binder::Status VoldNativeService::onUserStarted(int32_t userId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2019-04-29 19:46:35 +02:00
|
|
|
return translate(VolumeManager::Instance()->onUserStarted(userId));
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::onUserStopped(int32_t userId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->onUserStopped(userId));
|
|
|
|
}
|
|
|
|
|
2018-07-31 19:07:34 +02:00
|
|
|
binder::Status VoldNativeService::addAppIds(const std::vector<std::string>& packageNames,
|
2018-09-19 00:14:18 +02:00
|
|
|
const std::vector<int32_t>& appIds) {
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2018-07-31 19:07:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::addSandboxIds(const std::vector<int32_t>& appIds,
|
2018-09-19 00:14:18 +02:00
|
|
|
const std::vector<std::string>& sandboxIds) {
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2018-07-31 19:07:34 +02:00
|
|
|
}
|
|
|
|
|
2017-12-15 06:15:20 +01:00
|
|
|
binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-12-15 06:15:20 +01:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing));
|
|
|
|
}
|
|
|
|
|
2017-09-11 18:32:01 +02:00
|
|
|
binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType,
|
2018-09-19 00:14:18 +02:00
|
|
|
int32_t ratio) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_ID(diskId);
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
auto disk = VolumeManager::Instance()->findDisk(diskId);
|
|
|
|
if (disk == nullptr) {
|
|
|
|
return error("Failed to find disk " + diskId);
|
|
|
|
}
|
|
|
|
switch (partitionType) {
|
2018-09-19 00:14:18 +02:00
|
|
|
case PARTITION_TYPE_PUBLIC:
|
|
|
|
return translate(disk->partitionPublic());
|
|
|
|
case PARTITION_TYPE_PRIVATE:
|
|
|
|
return translate(disk->partitionPrivate());
|
|
|
|
case PARTITION_TYPE_MIXED:
|
|
|
|
return translate(disk->partitionMixed(ratio));
|
|
|
|
default:
|
|
|
|
return error("Unknown type " + std::to_string(partitionType));
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-06 21:47:40 +02:00
|
|
|
|
2017-10-24 19:08:45 +02:00
|
|
|
binder::Status VoldNativeService::forgetPartition(const std::string& partGuid,
|
2018-09-19 00:14:18 +02:00
|
|
|
const std::string& fsUuid) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_HEX(partGuid);
|
2017-10-24 19:08:45 +02:00
|
|
|
CHECK_ARGUMENT_HEX(fsUuid);
|
2023-08-02 00:36:55 +02:00
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
{
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
success &= VolumeManager::Instance()->forgetPartition(partGuid, fsUuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
success &= fscrypt_destroy_volume_keys(fsUuid);
|
|
|
|
}
|
2017-09-07 23:27:28 +02:00
|
|
|
|
2023-08-02 00:36:55 +02:00
|
|
|
return translateBool(success);
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
|
2019-11-19 10:16:03 +01:00
|
|
|
binder::Status VoldNativeService::mount(
|
|
|
|
const std::string& volId, int32_t mountFlags, int32_t mountUserId,
|
|
|
|
const android::sp<android::os::IVoldMountCallback>& callback) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_ID(volId);
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
auto vol = VolumeManager::Instance()->findVolume(volId);
|
|
|
|
if (vol == nullptr) {
|
|
|
|
return error("Failed to find volume " + volId);
|
|
|
|
}
|
|
|
|
|
|
|
|
vol->setMountFlags(mountFlags);
|
|
|
|
vol->setMountUserId(mountUserId);
|
|
|
|
|
2019-11-19 10:16:03 +01:00
|
|
|
vol->setMountCallback(callback);
|
2017-09-07 23:27:28 +02:00
|
|
|
int res = vol->mount();
|
2019-11-19 10:16:03 +01:00
|
|
|
vol->setMountCallback(nullptr);
|
|
|
|
|
2018-09-18 22:07:45 +02:00
|
|
|
if (res != OK) {
|
|
|
|
return translate(res);
|
|
|
|
}
|
2019-07-19 17:46:53 +02:00
|
|
|
|
2018-09-18 22:07:45 +02:00
|
|
|
return translate(OK);
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::unmount(const std::string& volId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_ID(volId);
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
auto vol = VolumeManager::Instance()->findVolume(volId);
|
|
|
|
if (vol == nullptr) {
|
|
|
|
return error("Failed to find volume " + volId);
|
|
|
|
}
|
|
|
|
return translate(vol->unmount());
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_ID(volId);
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
auto vol = VolumeManager::Instance()->findVolume(volId);
|
|
|
|
if (vol == nullptr) {
|
|
|
|
return error("Failed to find volume " + volId);
|
|
|
|
}
|
|
|
|
return translate(vol->format(fsType));
|
|
|
|
}
|
|
|
|
|
2017-06-15 17:59:43 +02:00
|
|
|
static binder::Status pathForVolId(const std::string& volId, std::string* path) {
|
2017-09-15 20:57:44 +02:00
|
|
|
if (volId == "private" || volId == "null") {
|
2017-06-15 17:59:43 +02:00
|
|
|
*path = "/data";
|
2017-09-15 20:57:44 +02:00
|
|
|
} else {
|
|
|
|
auto vol = VolumeManager::Instance()->findVolume(volId);
|
|
|
|
if (vol == nullptr) {
|
|
|
|
return error("Failed to find volume " + volId);
|
|
|
|
}
|
|
|
|
if (vol->getType() != VolumeBase::Type::kPrivate) {
|
|
|
|
return error("Volume " + volId + " not private");
|
|
|
|
}
|
|
|
|
if (vol->getState() != VolumeBase::State::kMounted) {
|
|
|
|
return error("Volume " + volId + " not mounted");
|
|
|
|
}
|
2017-06-15 17:59:43 +02:00
|
|
|
*path = vol->getPath();
|
|
|
|
if (path->empty()) {
|
|
|
|
return error("Volume " + volId + " missing path");
|
|
|
|
}
|
2017-09-15 20:57:44 +02:00
|
|
|
}
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2017-06-15 17:59:43 +02:00
|
|
|
}
|
2017-09-15 20:57:44 +02:00
|
|
|
|
2017-06-15 17:59:43 +02:00
|
|
|
binder::Status VoldNativeService::benchmark(
|
2020-03-04 02:58:20 +01:00
|
|
|
const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-06-15 17:59:43 +02:00
|
|
|
CHECK_ARGUMENT_ID(volId);
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
std::string path;
|
|
|
|
auto status = pathForVolId(volId, &path);
|
|
|
|
if (!status.isOk()) return status;
|
2017-09-15 20:57:44 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
std::thread([=]() { android::vold::Benchmark(path, listener); }).detach();
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
binder::Status VoldNativeService::moveStorage(
|
2020-03-04 02:58:20 +01:00
|
|
|
const std::string& fromVolId, const std::string& toVolId,
|
|
|
|
const android::sp<android::os::IVoldTaskListener>& listener) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_ID(fromVolId);
|
|
|
|
CHECK_ARGUMENT_ID(toVolId);
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
auto fromVol = VolumeManager::Instance()->findVolume(fromVolId);
|
|
|
|
auto toVol = VolumeManager::Instance()->findVolume(toVolId);
|
|
|
|
if (fromVol == nullptr) {
|
|
|
|
return error("Failed to find volume " + fromVolId);
|
|
|
|
} else if (toVol == nullptr) {
|
|
|
|
return error("Failed to find volume " + toVolId);
|
|
|
|
}
|
2017-10-18 00:06:32 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
std::thread([=]() { android::vold::MoveStorage(fromVol, toVol, listener); }).detach();
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2017-09-06 21:47:40 +02:00
|
|
|
}
|
|
|
|
|
2017-09-07 23:27:28 +02:00
|
|
|
binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-12-14 02:40:28 +01:00
|
|
|
return translate(VolumeManager::Instance()->remountUid(uid, remountMode));
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
|
2020-02-28 17:30:47 +01:00
|
|
|
binder::Status VoldNativeService::remountAppStorageDirs(int uid, int pid,
|
|
|
|
const std::vector<std::string>& packageNames) {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2021-01-15 15:03:23 +01:00
|
|
|
return translate(VolumeManager::Instance()->handleAppStorageDirs(uid, pid,
|
|
|
|
false /* doUnmount */, packageNames));
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::unmountAppStorageDirs(int uid, int pid,
|
|
|
|
const std::vector<std::string>& packageNames) {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->handleAppStorageDirs(uid, pid,
|
|
|
|
true /* doUnmount */, packageNames));
|
2020-02-28 17:30:47 +01:00
|
|
|
}
|
|
|
|
|
2020-02-12 15:29:02 +01:00
|
|
|
binder::Status VoldNativeService::setupAppDir(const std::string& path, int32_t appUid) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_PATH(path);
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2020-02-12 15:29:02 +01:00
|
|
|
return translate(VolumeManager::Instance()->setupAppDir(path, appUid));
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
|
2020-12-03 16:32:52 +01:00
|
|
|
binder::Status VoldNativeService::ensureAppDirsCreated(const std::vector<std::string>& paths,
|
|
|
|
int32_t appUid) {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->ensureAppDirsCreated(paths, appUid));
|
|
|
|
}
|
|
|
|
|
2020-02-18 15:06:37 +01:00
|
|
|
binder::Status VoldNativeService::fixupAppDir(const std::string& path, int32_t appUid) {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
CHECK_ARGUMENT_PATH(path);
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->fixupAppDir(path, appUid));
|
|
|
|
}
|
|
|
|
|
Remove broken code for mounting encrypted OBB files
Mounting encrypted OBB files has never worked reliably across devices,
partly due to its reliance on Twofish encryption support in the kernel.
This is because Twofish support (CONFIG_CRYPTO_TWOFISH) has never been
required or even recommended for Android. It has never been enabled in
GKI, but even before GKI it wasn't required or recommended. Moreover,
this is now the only Android feature that still uses dm-crypt
(CONFIG_DM_CRYPT), and some devices don't have that enabled either.
Therefore, it appears that this feature is unused. That's perhaps not
surprising, considering that the documentation for OBBs
(https://developer.android.com/google/play/expansion-files) says that
they are deprecated, and also it explains OBBs as being app files that
are opaque to the platform; the ability of the platform to mount OBBs
that happen to be in a particular format is never mentioned. That means
that OBB mounting is probably rarely used even with unencrypted OBBs.
Finally, the usefulness of OBBs having their own encryption layer (in
addition to what the platform already provides via FBE) is not clear
either, especially with such an unusual choice of cipher.
To avoid the confusion that is being caused by having the broken code
for mounting encrypted OBBs still sitting around, let's remove it.
Test: atest StorageManagerTest # on Cuttlefish
Test: atest StorageManagerIntegrationTest # on Cuttlefish
Bug: 216475849
Change-Id: Iaef32cce90f95ea745ba2b143f89e66f533f3479
2022-03-01 22:19:18 +01:00
|
|
|
binder::Status VoldNativeService::createObb(const std::string& sourcePath, int32_t ownerGid,
|
2018-09-19 00:14:18 +02:00
|
|
|
std::string* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_PATH(sourcePath);
|
2017-09-11 18:32:01 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
Remove broken code for mounting encrypted OBB files
Mounting encrypted OBB files has never worked reliably across devices,
partly due to its reliance on Twofish encryption support in the kernel.
This is because Twofish support (CONFIG_CRYPTO_TWOFISH) has never been
required or even recommended for Android. It has never been enabled in
GKI, but even before GKI it wasn't required or recommended. Moreover,
this is now the only Android feature that still uses dm-crypt
(CONFIG_DM_CRYPT), and some devices don't have that enabled either.
Therefore, it appears that this feature is unused. That's perhaps not
surprising, considering that the documentation for OBBs
(https://developer.android.com/google/play/expansion-files) says that
they are deprecated, and also it explains OBBs as being app files that
are opaque to the platform; the ability of the platform to mount OBBs
that happen to be in a particular format is never mentioned. That means
that OBB mounting is probably rarely used even with unencrypted OBBs.
Finally, the usefulness of OBBs having their own encryption layer (in
addition to what the platform already provides via FBE) is not clear
either, especially with such an unusual choice of cipher.
To avoid the confusion that is being caused by having the broken code
for mounting encrypted OBBs still sitting around, let's remove it.
Test: atest StorageManagerTest # on Cuttlefish
Test: atest StorageManagerIntegrationTest # on Cuttlefish
Bug: 216475849
Change-Id: Iaef32cce90f95ea745ba2b143f89e66f533f3479
2022-03-01 22:19:18 +01:00
|
|
|
return translate(VolumeManager::Instance()->createObb(sourcePath, ownerGid, _aidl_return));
|
2017-09-11 18:32:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::destroyObb(const std::string& volId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_ID(volId);
|
2017-09-11 18:32:01 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->destroyObb(volId));
|
|
|
|
}
|
|
|
|
|
2020-02-04 08:07:21 +01:00
|
|
|
binder::Status VoldNativeService::createStubVolume(const std::string& sourcePath,
|
|
|
|
const std::string& mountPath,
|
|
|
|
const std::string& fsType,
|
|
|
|
const std::string& fsUuid,
|
|
|
|
const std::string& fsLabel, int32_t flags,
|
|
|
|
std::string* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-10-29 00:52:56 +01:00
|
|
|
CHECK_ARGUMENT_PATH(sourcePath);
|
|
|
|
CHECK_ARGUMENT_PATH(mountPath);
|
|
|
|
CHECK_ARGUMENT_HEX(fsUuid);
|
|
|
|
// Label limitation seems to be different between fs (including allowed characters), so checking
|
|
|
|
// is quite meaningless.
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2020-02-04 08:07:21 +01:00
|
|
|
return translate(VolumeManager::Instance()->createStubVolume(
|
|
|
|
sourcePath, mountPath, fsType, fsUuid, fsLabel, flags, _aidl_return));
|
2018-10-29 00:52:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::destroyStubVolume(const std::string& volId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-10-29 00:52:56 +01:00
|
|
|
CHECK_ARGUMENT_ID(volId);
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->destroyStubVolume(volId));
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
binder::Status VoldNativeService::fstrim(
|
2020-03-04 02:58:20 +01:00
|
|
|
int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-11 18:32:01 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
std::thread([=]() { android::vold::Trim(listener); }).detach();
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2017-09-11 18:32:01 +02:00
|
|
|
}
|
|
|
|
|
2017-10-18 00:41:45 +02:00
|
|
|
binder::Status VoldNativeService::runIdleMaint(
|
2022-01-04 20:37:39 +01:00
|
|
|
bool needGC, const android::sp<android::os::IVoldTaskListener>& listener) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-10-18 00:41:45 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2022-01-04 20:37:39 +01:00
|
|
|
std::thread([=]() { android::vold::RunIdleMaint(needGC, listener); }).detach();
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2017-10-18 00:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::abortIdleMaint(
|
2020-03-04 02:58:20 +01:00
|
|
|
const android::sp<android::os::IVoldTaskListener>& listener) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-10-18 00:41:45 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach();
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2017-10-18 00:41:45 +02:00
|
|
|
}
|
|
|
|
|
2022-01-04 20:37:39 +01:00
|
|
|
binder::Status VoldNativeService::getStorageLifeTime(int32_t* _aidl_return) {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
*_aidl_return = GetStorageLifeTime();
|
|
|
|
return Ok();
|
|
|
|
}
|
|
|
|
|
2024-01-31 19:54:33 +01:00
|
|
|
binder::Status VoldNativeService::getStorageRemainingLifetime(int32_t* _aidl_return) {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
*_aidl_return = GetStorageRemainingLifetime();
|
|
|
|
return Ok();
|
|
|
|
}
|
|
|
|
|
2022-01-04 20:37:39 +01:00
|
|
|
binder::Status VoldNativeService::setGCUrgentPace(int32_t neededSegments,
|
|
|
|
int32_t minSegmentThreshold,
|
2022-03-18 20:24:41 +01:00
|
|
|
float dirtyReclaimRate, float reclaimWeight,
|
2022-06-24 23:50:47 +02:00
|
|
|
int32_t gcPeriod, int32_t minGCSleepTime,
|
|
|
|
int32_t targetDirtyRatio) {
|
2022-01-04 20:37:39 +01:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2022-06-24 01:19:58 +02:00
|
|
|
SetGCUrgentPace(neededSegments, minSegmentThreshold, dirtyReclaimRate, reclaimWeight, gcPeriod,
|
2022-06-24 23:50:47 +02:00
|
|
|
minGCSleepTime, targetDirtyRatio);
|
2022-01-04 20:37:39 +01:00
|
|
|
return Ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::refreshLatestWrite() {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
RefreshLatestWrite();
|
|
|
|
return Ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::getWriteAmount(int32_t* _aidl_return) {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
*_aidl_return = GetWriteAmount();
|
|
|
|
return Ok();
|
|
|
|
}
|
|
|
|
|
2018-10-27 04:56:45 +02:00
|
|
|
binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t mountId,
|
2018-09-19 00:14:18 +02:00
|
|
|
android::base::unique_fd* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-11 18:32:01 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-10-27 04:56:45 +02:00
|
|
|
return translate(VolumeManager::Instance()->mountAppFuse(uid, mountId, _aidl_return));
|
2017-09-11 18:32:01 +02:00
|
|
|
}
|
|
|
|
|
2018-10-27 04:56:45 +02:00
|
|
|
binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t mountId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-11 18:32:01 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-10-27 04:56:45 +02:00
|
|
|
return translate(VolumeManager::Instance()->unmountAppFuse(uid, mountId));
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::openAppFuseFile(int32_t uid, int32_t mountId, int32_t fileId,
|
|
|
|
int32_t flags,
|
|
|
|
android::base::unique_fd* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-10-27 04:56:45 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
int fd = VolumeManager::Instance()->openAppFuseFile(uid, mountId, fileId, flags);
|
|
|
|
if (fd == -1) {
|
|
|
|
return error("Failed to open AppFuse file for uid: " + std::to_string(uid) +
|
|
|
|
" mountId: " + std::to_string(mountId) + " fileId: " + std::to_string(fileId) +
|
|
|
|
" flags: " + std::to_string(flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
*_aidl_return = android::base::unique_fd(fd);
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2017-09-11 18:32:01 +02:00
|
|
|
}
|
|
|
|
|
2017-09-13 00:30:52 +02:00
|
|
|
binder::Status VoldNativeService::fbeEnable() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2019-09-12 00:00:08 +02:00
|
|
|
return translateBool(fscrypt_initialize_systemwide_keys());
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::initUser0() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2018-10-23 22:06:55 +02:00
|
|
|
return translateBool(fscrypt_init_user0());
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
2019-06-25 23:44:33 +02:00
|
|
|
binder::Status VoldNativeService::mountFstab(const std::string& blkDevice,
|
2024-04-24 04:01:26 +02:00
|
|
|
const std::string& mountPoint, bool isZoned,
|
|
|
|
const std::vector<std::string>& userDevices) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-01-30 18:48:19 +01:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2020-12-15 18:02:29 +01:00
|
|
|
return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, false, false,
|
2024-04-24 04:01:26 +02:00
|
|
|
"null", isZoned, userDevices));
|
2018-01-30 18:48:19 +01:00
|
|
|
}
|
|
|
|
|
2019-06-25 23:44:33 +02:00
|
|
|
binder::Status VoldNativeService::encryptFstab(const std::string& blkDevice,
|
2020-12-15 18:00:49 +01:00
|
|
|
const std::string& mountPoint, bool shouldFormat,
|
2024-04-24 04:01:26 +02:00
|
|
|
const std::string& fsType, bool isZoned,
|
|
|
|
const std::vector<std::string>& userDevices) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-01-30 18:48:19 +01:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2020-12-15 18:02:29 +01:00
|
|
|
return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, true, shouldFormat,
|
2024-04-24 04:01:26 +02:00
|
|
|
fsType, isZoned, userDevices));
|
2018-01-30 18:48:19 +01:00
|
|
|
}
|
|
|
|
|
2021-01-19 18:51:51 +01:00
|
|
|
binder::Status VoldNativeService::setStorageBindingSeed(const std::vector<uint8_t>& seed) {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
|
|
|
return translateBool(setKeyStorageBindingSeed(seed));
|
|
|
|
}
|
|
|
|
|
2023-12-13 00:53:55 +01:00
|
|
|
binder::Status VoldNativeService::createUserStorageKeys(int32_t userId, bool ephemeral) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2023-12-13 00:53:55 +01:00
|
|
|
return translateBool(fscrypt_create_user_keys(userId, ephemeral));
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
2023-10-19 21:47:20 +02:00
|
|
|
binder::Status VoldNativeService::destroyUserStorageKeys(int32_t userId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2023-10-19 21:47:20 +02:00
|
|
|
return translateBool(fscrypt_destroy_user_keys(userId));
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
2023-10-19 21:47:20 +02:00
|
|
|
binder::Status VoldNativeService::setCeStorageProtection(int32_t userId,
|
|
|
|
const std::string& secret) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2023-10-19 21:47:20 +02:00
|
|
|
return translateBool(fscrypt_set_ce_key_protection(userId, secret));
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
2021-04-06 21:02:56 +02:00
|
|
|
binder::Status VoldNativeService::getUnlockedUsers(std::vector<int>* _aidl_return) {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
|
|
|
*_aidl_return = fscrypt_get_unlocked_users();
|
|
|
|
return Ok();
|
|
|
|
}
|
|
|
|
|
2023-12-13 00:53:55 +01:00
|
|
|
binder::Status VoldNativeService::unlockCeStorage(int32_t userId, const std::string& secret) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2023-12-13 00:53:55 +01:00
|
|
|
return translateBool(fscrypt_unlock_ce_storage(userId, secret));
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
2023-10-19 21:47:20 +02:00
|
|
|
binder::Status VoldNativeService::lockCeStorage(int32_t userId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2023-10-19 21:47:20 +02:00
|
|
|
return translateBool(fscrypt_lock_ce_storage(userId));
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
2020-01-23 05:23:26 +01:00
|
|
|
binder::Status VoldNativeService::prepareUserStorage(const std::optional<std::string>& uuid,
|
2023-12-13 00:53:55 +01:00
|
|
|
int32_t userId, int32_t flags) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-10-09 19:55:21 +02:00
|
|
|
std::string empty_string = "";
|
|
|
|
auto uuid_ = uuid ? *uuid : empty_string;
|
2017-10-16 19:59:51 +02:00
|
|
|
CHECK_ARGUMENT_HEX(uuid_);
|
|
|
|
|
|
|
|
ACQUIRE_CRYPT_LOCK;
|
2023-12-13 00:53:55 +01:00
|
|
|
return translateBool(fscrypt_prepare_user_storage(uuid_, userId, flags));
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
2020-01-23 05:23:26 +01:00
|
|
|
binder::Status VoldNativeService::destroyUserStorage(const std::optional<std::string>& uuid,
|
2018-09-19 00:14:18 +02:00
|
|
|
int32_t userId, int32_t flags) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-10-09 19:55:21 +02:00
|
|
|
std::string empty_string = "";
|
|
|
|
auto uuid_ = uuid ? *uuid : empty_string;
|
2017-10-16 19:59:51 +02:00
|
|
|
CHECK_ARGUMENT_HEX(uuid_);
|
|
|
|
|
|
|
|
ACQUIRE_CRYPT_LOCK;
|
2018-10-23 22:06:55 +02:00
|
|
|
return translateBool(fscrypt_destroy_user_storage(uuid_, userId, flags));
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 01:26:22 +02:00
|
|
|
binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packageName,
|
|
|
|
int32_t appId, const std::string& sandboxId,
|
|
|
|
int32_t userId) {
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2018-10-05 01:26:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName,
|
2018-10-25 20:06:55 +02:00
|
|
|
const std::string& sandboxId,
|
2018-10-05 01:26:22 +02:00
|
|
|
int32_t userId) {
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2018-08-24 19:20:56 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
binder::Status VoldNativeService::startCheckpoint(int32_t retry) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-08-28 10:58:49 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
return cp_startCheckpoint(retry);
|
2018-08-28 10:58:49 +02:00
|
|
|
}
|
|
|
|
|
2018-10-03 02:40:44 +02:00
|
|
|
binder::Status VoldNativeService::needsRollback(bool* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-10-03 02:40:44 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
*_aidl_return = cp_needsRollback();
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2018-10-03 02:40:44 +02:00
|
|
|
}
|
|
|
|
|
2018-08-28 10:58:49 +02:00
|
|
|
binder::Status VoldNativeService::needsCheckpoint(bool* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-08-28 10:58:49 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
*_aidl_return = cp_needsCheckpoint();
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2018-08-28 10:58:49 +02:00
|
|
|
}
|
|
|
|
|
2020-06-11 08:51:17 +02:00
|
|
|
binder::Status VoldNativeService::isCheckpointing(bool* _aidl_return) {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
*_aidl_return = cp_isCheckpointing();
|
|
|
|
return Ok();
|
|
|
|
}
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
binder::Status VoldNativeService::commitChanges() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-08-28 10:58:49 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
return cp_commitChanges();
|
2018-08-28 10:58:49 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
binder::Status VoldNativeService::prepareCheckpoint() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-08-28 10:58:49 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
return cp_prepareCheckpoint();
|
2018-08-28 10:58:49 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
binder::Status VoldNativeService::restoreCheckpoint(const std::string& mountPoint) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-09-21 19:49:57 +02:00
|
|
|
CHECK_ARGUMENT_PATH(mountPoint);
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
return cp_restoreCheckpoint(mountPoint);
|
2018-09-21 19:49:57 +02:00
|
|
|
}
|
|
|
|
|
2019-03-07 02:45:17 +01:00
|
|
|
binder::Status VoldNativeService::restoreCheckpointPart(const std::string& mountPoint, int count) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2019-03-07 02:45:17 +01:00
|
|
|
CHECK_ARGUMENT_PATH(mountPoint);
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return cp_restoreCheckpoint(mountPoint, count);
|
|
|
|
}
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
binder::Status VoldNativeService::markBootAttempt() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-08-28 10:58:49 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
return cp_markBootAttempt();
|
2018-08-28 10:58:49 +02:00
|
|
|
}
|
|
|
|
|
2019-03-21 01:02:47 +01:00
|
|
|
binder::Status VoldNativeService::abortChanges(const std::string& message, bool retry) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-08-28 10:58:49 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2019-03-21 01:02:47 +01:00
|
|
|
cp_abortChanges(message, retry);
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2018-08-28 10:58:49 +02:00
|
|
|
}
|
|
|
|
|
2019-01-23 02:27:25 +01:00
|
|
|
binder::Status VoldNativeService::supportsCheckpoint(bool* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2019-01-23 02:27:25 +01:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return cp_supportsCheckpoint(*_aidl_return);
|
|
|
|
}
|
|
|
|
|
2019-03-18 21:36:40 +01:00
|
|
|
binder::Status VoldNativeService::supportsBlockCheckpoint(bool* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2019-03-18 21:36:40 +01:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return cp_supportsBlockCheckpoint(*_aidl_return);
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::supportsFileCheckpoint(bool* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2019-03-18 21:36:40 +01:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return cp_supportsFileCheckpoint(*_aidl_return);
|
|
|
|
}
|
|
|
|
|
2019-10-11 17:38:21 +02:00
|
|
|
binder::Status VoldNativeService::resetCheckpoint() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2019-10-11 17:38:21 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
cp_resetCheckpoint();
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2019-10-11 17:38:21 +02:00
|
|
|
}
|
|
|
|
|
2021-02-12 04:09:10 +01:00
|
|
|
static void initializeIncFs() {
|
|
|
|
// Obtaining IncFS features triggers initialization of IncFS.
|
|
|
|
incfs::features();
|
|
|
|
}
|
|
|
|
|
2020-11-12 10:59:13 +01:00
|
|
|
binder::Status VoldNativeService::earlyBootEnded() {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2021-02-12 04:09:10 +01:00
|
|
|
initializeIncFs();
|
2021-06-15 20:34:00 +02:00
|
|
|
Keystore::earlyBootEnded();
|
2020-11-12 10:59:13 +01:00
|
|
|
return Ok();
|
|
|
|
}
|
|
|
|
|
2020-01-10 20:54:06 +01:00
|
|
|
binder::Status VoldNativeService::incFsEnabled(bool* _aidl_return) {
|
2020-03-25 07:49:02 +01:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
|
2020-04-23 08:23:24 +02:00
|
|
|
*_aidl_return = incfs::enabled();
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2019-12-02 19:50:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::mountIncFs(
|
2020-01-10 20:54:06 +01:00
|
|
|
const std::string& backingPath, const std::string& targetDir, int32_t flags,
|
2021-04-27 21:46:02 +02:00
|
|
|
const std::string& sysfsName,
|
2019-12-02 19:50:12 +01:00
|
|
|
::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) {
|
2020-03-25 07:49:02 +01:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2021-10-19 07:33:15 +02:00
|
|
|
if (auto status = CheckIncrementalPath(IncrementalPathKind::MountTarget, targetDir);
|
|
|
|
!status.isOk()) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
if (auto status = CheckIncrementalPath(IncrementalPathKind::MountSource, backingPath);
|
|
|
|
!status.isOk()) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto [backingFd, backingSymlink] = OpenDirInProcfs(backingPath);
|
|
|
|
if (!backingFd.ok()) {
|
|
|
|
return translate(-errno);
|
|
|
|
}
|
|
|
|
auto [targetFd, targetSymlink] = OpenDirInProcfs(targetDir);
|
|
|
|
if (!targetFd.ok()) {
|
|
|
|
return translate(-errno);
|
|
|
|
}
|
2020-03-25 07:49:02 +01:00
|
|
|
|
2021-10-19 07:33:15 +02:00
|
|
|
auto control = incfs::mount(backingSymlink, targetSymlink,
|
2020-04-23 08:23:24 +02:00
|
|
|
{.flags = IncFsMountFlags(flags),
|
2021-04-01 22:43:14 +02:00
|
|
|
// Mount with read timeouts.
|
2020-04-23 08:23:24 +02:00
|
|
|
.defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS,
|
|
|
|
// Mount with read logs disabled.
|
2021-04-27 21:46:02 +02:00
|
|
|
.readLogBufferPages = 0,
|
|
|
|
.sysfsName = sysfsName.c_str()});
|
2020-04-23 08:23:24 +02:00
|
|
|
if (!control) {
|
|
|
|
return translate(-errno);
|
2020-01-10 20:54:06 +01:00
|
|
|
}
|
2020-04-23 08:23:24 +02:00
|
|
|
auto fds = control.releaseFds();
|
|
|
|
using android::base::unique_fd;
|
|
|
|
_aidl_return->cmd.reset(unique_fd(fds[CMD].release()));
|
|
|
|
_aidl_return->pendingReads.reset(unique_fd(fds[PENDING_READS].release()));
|
|
|
|
_aidl_return->log.reset(unique_fd(fds[LOGS].release()));
|
2020-12-08 16:33:37 +01:00
|
|
|
if (fds[BLOCKS_WRITTEN].ok()) {
|
|
|
|
_aidl_return->blocksWritten.emplace(unique_fd(fds[BLOCKS_WRITTEN].release()));
|
|
|
|
}
|
2020-03-25 07:49:02 +01:00
|
|
|
return Ok();
|
2019-12-02 19:50:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::unmountIncFs(const std::string& dir) {
|
2020-03-25 07:49:02 +01:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2021-10-19 07:33:15 +02:00
|
|
|
if (auto status = CheckIncrementalPath(IncrementalPathKind::Any, dir); !status.isOk()) {
|
|
|
|
return status;
|
|
|
|
}
|
2020-03-25 07:49:02 +01:00
|
|
|
|
2021-10-19 07:33:15 +02:00
|
|
|
auto [fd, symLink] = OpenDirInProcfs(dir);
|
|
|
|
if (!fd.ok()) {
|
|
|
|
return translate(-errno);
|
|
|
|
}
|
|
|
|
return translate(incfs::unmount(symLink));
|
2019-12-02 19:50:12 +01:00
|
|
|
}
|
|
|
|
|
2020-03-31 23:46:25 +02:00
|
|
|
binder::Status VoldNativeService::setIncFsMountOptions(
|
|
|
|
const ::android::os::incremental::IncrementalFileSystemControlParcel& control,
|
2021-05-11 01:19:38 +02:00
|
|
|
bool enableReadLogs, bool enableReadTimeouts, const std::string& sysfsName) {
|
2020-04-03 00:21:47 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2020-03-31 23:46:25 +02:00
|
|
|
|
2020-04-23 08:23:24 +02:00
|
|
|
auto incfsControl =
|
2020-12-08 16:33:37 +01:00
|
|
|
incfs::createControl(control.cmd.get(), control.pendingReads.get(), control.log.get(),
|
|
|
|
control.blocksWritten ? control.blocksWritten->get() : -1);
|
2020-04-23 08:23:24 +02:00
|
|
|
auto cleanupFunc = [](auto incfsControl) {
|
|
|
|
for (auto& fd : incfsControl->releaseFds()) {
|
|
|
|
(void)fd.release();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
auto cleanup =
|
|
|
|
std::unique_ptr<incfs::Control, decltype(cleanupFunc)>(&incfsControl, cleanupFunc);
|
2020-03-31 23:46:25 +02:00
|
|
|
|
2021-10-28 23:37:12 +02:00
|
|
|
constexpr auto minReadLogBufferPages = INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES;
|
|
|
|
constexpr auto maxReadLogBufferPages = 8 * INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES;
|
|
|
|
auto options = incfs::MountOptions{
|
|
|
|
.defaultReadTimeoutMs =
|
|
|
|
enableReadTimeouts ? INCFS_DEFAULT_READ_TIMEOUT_MS : kIncFsReadNoTimeoutMs,
|
|
|
|
.readLogBufferPages = enableReadLogs ? maxReadLogBufferPages : 0,
|
|
|
|
.sysfsName = sysfsName.c_str()};
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
const auto error = incfs::setOptions(incfsControl, options);
|
|
|
|
if (!error) {
|
|
|
|
return Ok();
|
|
|
|
}
|
|
|
|
if (!enableReadLogs || error != -ENOMEM) {
|
|
|
|
return binder::Status::fromServiceSpecificError(error);
|
|
|
|
}
|
|
|
|
// In case of memory allocation error retry with a smaller buffer.
|
|
|
|
options.readLogBufferPages /= 2;
|
|
|
|
if (options.readLogBufferPages < minReadLogBufferPages) {
|
|
|
|
return binder::Status::fromServiceSpecificError(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// unreachable, but makes the compiler happy
|
2020-04-23 08:23:24 +02:00
|
|
|
return Ok();
|
2020-03-31 23:46:25 +02:00
|
|
|
}
|
|
|
|
|
2019-12-02 19:50:12 +01:00
|
|
|
binder::Status VoldNativeService::bindMount(const std::string& sourceDir,
|
|
|
|
const std::string& targetDir) {
|
2020-03-25 07:49:02 +01:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2021-10-19 07:33:15 +02:00
|
|
|
if (auto status = CheckIncrementalPath(IncrementalPathKind::Any, sourceDir); !status.isOk()) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
if (auto status = CheckIncrementalPath(IncrementalPathKind::Bind, targetDir); !status.isOk()) {
|
|
|
|
return status;
|
|
|
|
}
|
2020-03-25 07:49:02 +01:00
|
|
|
|
2021-10-19 07:33:15 +02:00
|
|
|
auto [sourceFd, sourceSymlink] = OpenDirInProcfs(sourceDir);
|
|
|
|
if (!sourceFd.ok()) {
|
|
|
|
return translate(-errno);
|
|
|
|
}
|
|
|
|
auto [targetFd, targetSymlink] = OpenDirInProcfs(targetDir);
|
|
|
|
if (!targetFd.ok()) {
|
|
|
|
return translate(-errno);
|
|
|
|
}
|
|
|
|
return translate(incfs::bindMount(sourceSymlink, targetSymlink));
|
2019-12-02 19:50:12 +01:00
|
|
|
}
|
|
|
|
|
2020-10-07 08:20:00 +02:00
|
|
|
binder::Status VoldNativeService::destroyDsuMetadataKey(const std::string& dsuSlot) {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translateBool(destroy_dsu_metadata_key(dsuSlot));
|
|
|
|
}
|
|
|
|
|
2023-08-11 19:27:24 +02:00
|
|
|
binder::Status VoldNativeService::getStorageSize(int64_t* storageSize) {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
return translate(GetStorageSize(storageSize));
|
|
|
|
}
|
|
|
|
|
2017-09-06 21:47:40 +02:00
|
|
|
} // namespace vold
|
|
|
|
} // namespace android
|