blob: 291a0d9f43bb77ca40b6c84b72ed50a58916d676 [file] [log] [blame]
Jeff Sharkey068c6be2017-09-06 13:47:40 -06001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jeff Sharkey67b8c492017-09-21 17:08:43 -060017#define ATRACE_TAG ATRACE_TAG_PACKAGE_MANAGER
18
Jeff Sharkey068c6be2017-09-06 13:47:40 -060019#include "VoldNativeService.h"
Paul Crowley73be12d2020-02-03 12:22:03 -080020
Songchun Fan01c4e912020-03-03 17:58:20 -080021#include <android-base/logging.h>
22#include <android-base/stringprintf.h>
23#include <android-base/strings.h>
24#include <fs_mgr.h>
25#include <fscrypt/fscrypt.h>
26#include <private/android_filesystem_config.h>
27#include <utils/Trace.h>
28
Keun young Park0bccae22021-10-13 16:50:10 -070029#include <stdio.h>
Eric Biggers4859e0c2021-06-24 11:13:24 -070030#include <sys/vfs.h>
Songchun Fan01c4e912020-03-03 17:58:20 -080031#include <fstream>
32#include <thread>
33
Jeff Sharkey01a0e7f2017-10-17 16:06:32 -060034#include "Benchmark.h"
Daniel Rosenberg4f684712018-08-28 01:58:49 -070035#include "Checkpoint.h"
Eric Biggersa701c452018-10-23 13:06:55 -070036#include "FsCrypt.h"
Paul Crowley73be12d2020-02-03 12:22:03 -080037#include "IdleMaint.h"
Seth Moore5a43d612021-01-19 17:51:51 +000038#include "KeyStorage.h"
Eric Biggersd86a8ab2021-06-15 11:34:00 -070039#include "Keystore.h"
Jeff Sharkey83b559c2017-09-12 16:30:52 -060040#include "MetadataCrypt.h"
Paul Crowley73be12d2020-02-03 12:22:03 -080041#include "MoveStorage.h"
42#include "Process.h"
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -070043#include "VoldNativeServiceValidation.h"
Paul Crowley73be12d2020-02-03 12:22:03 -080044#include "VoldUtil.h"
45#include "VolumeManager.h"
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070046#include "cryptfs.h"
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -070047#include "incfs.h"
Jeff Sharkey83b559c2017-09-12 16:30:52 -060048
Jeff Sharkey068c6be2017-09-06 13:47:40 -060049using android::base::StringPrintf;
50using std::endl;
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -070051using namespace std::literals;
Jeff Sharkey068c6be2017-09-06 13:47:40 -060052
53namespace android {
54namespace vold {
55
56namespace {
57
58constexpr const char* kDump = "android.permission.DUMP";
Alex Buynytskyydcfeaa12021-04-01 13:43:14 -070059constexpr auto kIncFsReadNoTimeoutMs = 100;
Jeff Sharkey068c6be2017-09-06 13:47:40 -060060
Jeff Sharkey9462bdd2017-09-07 15:27:28 -060061static binder::Status error(const std::string& msg) {
62 PLOG(ERROR) << msg;
63 return binder::Status::fromServiceSpecificError(errno, String8(msg.c_str()));
64}
65
Jeff Sharkey83b559c2017-09-12 16:30:52 -060066static binder::Status translate(int status) {
Jeff Sharkey9462bdd2017-09-07 15:27:28 -060067 if (status == 0) {
68 return binder::Status::ok();
69 } else {
Jeff Sharkey11c2d382017-09-11 10:32:01 -060070 return binder::Status::fromServiceSpecificError(status);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -060071 }
72}
73
Jeff Sharkey83b559c2017-09-12 16:30:52 -060074static binder::Status translateBool(bool status) {
75 if (status) {
76 return binder::Status::ok();
77 } else {
78 return binder::Status::fromServiceSpecificError(status);
79 }
80}
81
Nikita Ioffe5d85bf32019-10-23 17:19:13 +010082#define ENFORCE_SYSTEM_OR_ROOT \
83 { \
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -070084 binder::Status status = CheckUidOrRoot(AID_SYSTEM); \
Nikita Ioffe5d85bf32019-10-23 17:19:13 +010085 if (!status.isOk()) { \
86 return status; \
87 } \
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070088 }
Jeff Sharkey068c6be2017-09-06 13:47:40 -060089
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070090#define CHECK_ARGUMENT_ID(id) \
91 { \
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -070092 binder::Status status = CheckArgumentId((id)); \
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070093 if (!status.isOk()) { \
94 return status; \
95 } \
96 }
Jeff Sharkeyec4fda22017-09-12 13:19:24 -060097
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070098#define CHECK_ARGUMENT_PATH(path) \
99 { \
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700100 binder::Status status = CheckArgumentPath((path)); \
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700101 if (!status.isOk()) { \
102 return status; \
103 } \
104 }
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600105
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700106#define CHECK_ARGUMENT_HEX(hex) \
107 { \
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700108 binder::Status status = CheckArgumentHex((hex)); \
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700109 if (!status.isOk()) { \
110 return status; \
111 } \
112 }
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600113
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700114#define ACQUIRE_LOCK \
Jeff Sharkey67b8c492017-09-21 17:08:43 -0600115 std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \
116 ATRACE_CALL();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600117
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700118#define ACQUIRE_CRYPT_LOCK \
Jeff Sharkey67b8c492017-09-21 17:08:43 -0600119 std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \
120 ATRACE_CALL();
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600121
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600122} // namespace
123
124status_t VoldNativeService::start() {
125 IPCThreadState::self()->disableBackgroundScheduling(true);
126 status_t ret = BinderService<VoldNativeService>::publish();
127 if (ret != android::OK) {
128 return ret;
129 }
130 sp<ProcessState> ps(ProcessState::self());
131 ps->startThreadPool();
132 ps->giveThreadPoolName();
133 return android::OK;
134}
135
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700136status_t VoldNativeService::dump(int fd, const Vector<String16>& /* args */) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700137 const binder::Status dump_permission = CheckPermission(kDump);
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600138 if (!dump_permission.isOk()) {
Keun young Park0bccae22021-10-13 16:50:10 -0700139 dprintf(fd, "%s\n", dump_permission.toString8().c_str());
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600140 return PERMISSION_DENIED;
141 }
142
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600143 ACQUIRE_LOCK;
Keun young Park0bccae22021-10-13 16:50:10 -0700144 dprintf(fd, "vold is happy!\n");
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600145 return NO_ERROR;
146}
147
Jeff Sharkey814e9d32017-09-13 11:49:44 -0600148binder::Status VoldNativeService::setListener(
Songchun Fan01c4e912020-03-03 17:58:20 -0800149 const android::sp<android::os::IVoldListener>& listener) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100150 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey814e9d32017-09-13 11:49:44 -0600151 ACQUIRE_LOCK;
152
153 VolumeManager::Instance()->setListener(listener);
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700154 return Ok();
Jeff Sharkey814e9d32017-09-13 11:49:44 -0600155}
156
Jeff Sharkeycbe69fc2017-09-15 16:50:28 -0600157binder::Status VoldNativeService::monitor() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100158 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeycbe69fc2017-09-15 16:50:28 -0600159
160 // Simply acquire/release each lock for watchdog
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700161 { ACQUIRE_LOCK; }
162 { ACQUIRE_CRYPT_LOCK; }
Jeff Sharkeycbe69fc2017-09-15 16:50:28 -0600163
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700164 return Ok();
Jeff Sharkeycbe69fc2017-09-15 16:50:28 -0600165}
166
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600167binder::Status VoldNativeService::reset() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100168 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600169 ACQUIRE_LOCK;
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600170
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600171 return translate(VolumeManager::Instance()->reset());
172}
173
174binder::Status VoldNativeService::shutdown() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100175 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600176 ACQUIRE_LOCK;
177
178 return translate(VolumeManager::Instance()->shutdown());
179}
180
Martijn Coenen23c04452020-04-29 07:49:41 +0200181binder::Status VoldNativeService::abortFuse() {
182 ENFORCE_SYSTEM_OR_ROOT;
lijiaziffe76222021-03-17 16:51:16 +0800183 // if acquire lock, maybe lead to a deadlock if lock is held by a
184 // thread that is blocked on a FUSE operation.
185 // abort fuse doesn't need to access any state, so do not acquire lock
Martijn Coenen23c04452020-04-29 07:49:41 +0200186
187 return translate(VolumeManager::Instance()->abortFuse());
188}
189
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600190binder::Status VoldNativeService::onUserAdded(int32_t userId, int32_t userSerial) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100191 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600192 ACQUIRE_LOCK;
193
194 return translate(VolumeManager::Instance()->onUserAdded(userId, userSerial));
195}
196
197binder::Status VoldNativeService::onUserRemoved(int32_t userId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100198 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600199 ACQUIRE_LOCK;
200
201 return translate(VolumeManager::Instance()->onUserRemoved(userId));
202}
203
Sudheer Shanka5fceb482019-04-29 10:46:35 -0700204binder::Status VoldNativeService::onUserStarted(int32_t userId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100205 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600206 ACQUIRE_LOCK;
207
Sudheer Shanka5fceb482019-04-29 10:46:35 -0700208 return translate(VolumeManager::Instance()->onUserStarted(userId));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600209}
210
211binder::Status VoldNativeService::onUserStopped(int32_t userId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100212 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600213 ACQUIRE_LOCK;
214
215 return translate(VolumeManager::Instance()->onUserStopped(userId));
216}
217
Sudheer Shankad484aa92018-07-31 10:07:34 -0700218binder::Status VoldNativeService::addAppIds(const std::vector<std::string>& packageNames,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700219 const std::vector<int32_t>& appIds) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700220 return Ok();
Sudheer Shankad484aa92018-07-31 10:07:34 -0700221}
222
Sudheer Shankad484aa92018-07-31 10:07:34 -0700223binder::Status VoldNativeService::addSandboxIds(const std::vector<int32_t>& appIds,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700224 const std::vector<std::string>& sandboxIds) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700225 return Ok();
Sudheer Shankad484aa92018-07-31 10:07:34 -0700226}
227
Jeff Sharkey401b2602017-12-14 22:15:20 -0700228binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100229 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey401b2602017-12-14 22:15:20 -0700230 ACQUIRE_LOCK;
231
232 return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing));
233}
234
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600235binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700236 int32_t ratio) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100237 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600238 CHECK_ARGUMENT_ID(diskId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600239 ACQUIRE_LOCK;
240
241 auto disk = VolumeManager::Instance()->findDisk(diskId);
242 if (disk == nullptr) {
243 return error("Failed to find disk " + diskId);
244 }
245 switch (partitionType) {
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700246 case PARTITION_TYPE_PUBLIC:
247 return translate(disk->partitionPublic());
248 case PARTITION_TYPE_PRIVATE:
249 return translate(disk->partitionPrivate());
250 case PARTITION_TYPE_MIXED:
251 return translate(disk->partitionMixed(ratio));
252 default:
253 return error("Unknown type " + std::to_string(partitionType));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600254 }
255}
256
Jeff Sharkey3ce18252017-10-24 11:08:45 -0600257binder::Status VoldNativeService::forgetPartition(const std::string& partGuid,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700258 const std::string& fsUuid) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100259 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600260 CHECK_ARGUMENT_HEX(partGuid);
Jeff Sharkey3ce18252017-10-24 11:08:45 -0600261 CHECK_ARGUMENT_HEX(fsUuid);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600262 ACQUIRE_LOCK;
263
Jeff Sharkey3ce18252017-10-24 11:08:45 -0600264 return translate(VolumeManager::Instance()->forgetPartition(partGuid, fsUuid));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600265}
266
Zim5048b4b2019-11-19 09:16:03 +0000267binder::Status VoldNativeService::mount(
268 const std::string& volId, int32_t mountFlags, int32_t mountUserId,
269 const android::sp<android::os::IVoldMountCallback>& callback) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100270 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600271 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600272 ACQUIRE_LOCK;
273
274 auto vol = VolumeManager::Instance()->findVolume(volId);
275 if (vol == nullptr) {
276 return error("Failed to find volume " + volId);
277 }
278
279 vol->setMountFlags(mountFlags);
280 vol->setMountUserId(mountUserId);
281
Zim5048b4b2019-11-19 09:16:03 +0000282 vol->setMountCallback(callback);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600283 int res = vol->mount();
Zim5048b4b2019-11-19 09:16:03 +0000284 vol->setMountCallback(nullptr);
285
Sudheer Shanka40ab6742018-09-18 13:07:45 -0700286 if (res != OK) {
287 return translate(res);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600288 }
Zim3623a212019-07-19 16:46:53 +0100289
Sudheer Shanka40ab6742018-09-18 13:07:45 -0700290 return translate(OK);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600291}
292
293binder::Status VoldNativeService::unmount(const std::string& volId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100294 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600295 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600296 ACQUIRE_LOCK;
297
298 auto vol = VolumeManager::Instance()->findVolume(volId);
299 if (vol == nullptr) {
300 return error("Failed to find volume " + volId);
301 }
302 return translate(vol->unmount());
303}
304
305binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100306 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600307 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600308 ACQUIRE_LOCK;
309
310 auto vol = VolumeManager::Instance()->findVolume(volId);
311 if (vol == nullptr) {
312 return error("Failed to find volume " + volId);
313 }
314 return translate(vol->format(fsType));
315}
316
Jeff Sharkey2048a282017-06-15 09:59:43 -0600317static binder::Status pathForVolId(const std::string& volId, std::string* path) {
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600318 if (volId == "private" || volId == "null") {
Jeff Sharkey2048a282017-06-15 09:59:43 -0600319 *path = "/data";
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600320 } else {
321 auto vol = VolumeManager::Instance()->findVolume(volId);
322 if (vol == nullptr) {
323 return error("Failed to find volume " + volId);
324 }
325 if (vol->getType() != VolumeBase::Type::kPrivate) {
326 return error("Volume " + volId + " not private");
327 }
328 if (vol->getState() != VolumeBase::State::kMounted) {
329 return error("Volume " + volId + " not mounted");
330 }
Jeff Sharkey2048a282017-06-15 09:59:43 -0600331 *path = vol->getPath();
332 if (path->empty()) {
333 return error("Volume " + volId + " missing path");
334 }
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600335 }
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700336 return Ok();
Jeff Sharkey2048a282017-06-15 09:59:43 -0600337}
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600338
Jeff Sharkey2048a282017-06-15 09:59:43 -0600339binder::Status VoldNativeService::benchmark(
Songchun Fan01c4e912020-03-03 17:58:20 -0800340 const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100341 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey2048a282017-06-15 09:59:43 -0600342 CHECK_ARGUMENT_ID(volId);
343 ACQUIRE_LOCK;
344
345 std::string path;
346 auto status = pathForVolId(volId, &path);
347 if (!status.isOk()) return status;
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600348
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700349 std::thread([=]() { android::vold::Benchmark(path, listener); }).detach();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700350 return Ok();
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600351}
352
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700353binder::Status VoldNativeService::moveStorage(
Songchun Fan01c4e912020-03-03 17:58:20 -0800354 const std::string& fromVolId, const std::string& toVolId,
355 const android::sp<android::os::IVoldTaskListener>& listener) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100356 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600357 CHECK_ARGUMENT_ID(fromVolId);
358 CHECK_ARGUMENT_ID(toVolId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600359 ACQUIRE_LOCK;
360
361 auto fromVol = VolumeManager::Instance()->findVolume(fromVolId);
362 auto toVol = VolumeManager::Instance()->findVolume(toVolId);
363 if (fromVol == nullptr) {
364 return error("Failed to find volume " + fromVolId);
365 } else if (toVol == nullptr) {
366 return error("Failed to find volume " + toVolId);
367 }
Jeff Sharkey01a0e7f2017-10-17 16:06:32 -0600368
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700369 std::thread([=]() { android::vold::MoveStorage(fromVol, toVol, listener); }).detach();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700370 return Ok();
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600371}
372
373binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100374 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600375 ACQUIRE_LOCK;
376
Sudheer Shanka817b9112018-12-13 17:40:28 -0800377 return translate(VolumeManager::Instance()->remountUid(uid, remountMode));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600378}
379
Ricky Wai6b122572020-02-28 16:30:47 +0000380binder::Status VoldNativeService::remountAppStorageDirs(int uid, int pid,
381 const std::vector<std::string>& packageNames) {
382 ENFORCE_SYSTEM_OR_ROOT;
383 ACQUIRE_LOCK;
384
Ricky Waia2ca11e2021-01-15 14:03:23 +0000385 return translate(VolumeManager::Instance()->handleAppStorageDirs(uid, pid,
386 false /* doUnmount */, packageNames));
387}
388
389binder::Status VoldNativeService::unmountAppStorageDirs(int uid, int pid,
390 const std::vector<std::string>& packageNames) {
391 ENFORCE_SYSTEM_OR_ROOT;
392 ACQUIRE_LOCK;
393
394 return translate(VolumeManager::Instance()->handleAppStorageDirs(uid, pid,
395 true /* doUnmount */, packageNames));
Ricky Wai6b122572020-02-28 16:30:47 +0000396}
397
Martijn Coenen8a68a072020-02-12 15:29:02 +0100398binder::Status VoldNativeService::setupAppDir(const std::string& path, int32_t appUid) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100399 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600400 CHECK_ARGUMENT_PATH(path);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600401 ACQUIRE_LOCK;
402
Martijn Coenen8a68a072020-02-12 15:29:02 +0100403 return translate(VolumeManager::Instance()->setupAppDir(path, appUid));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600404}
405
Ricky Waibbfb6ea2020-12-03 15:32:52 +0000406binder::Status VoldNativeService::ensureAppDirsCreated(const std::vector<std::string>& paths,
407 int32_t appUid) {
408 ENFORCE_SYSTEM_OR_ROOT;
409 ACQUIRE_LOCK;
410
411 return translate(VolumeManager::Instance()->ensureAppDirsCreated(paths, appUid));
412}
413
Martijn Coenen816f4d92020-02-18 15:06:37 +0100414binder::Status VoldNativeService::fixupAppDir(const std::string& path, int32_t appUid) {
415 ENFORCE_SYSTEM_OR_ROOT;
416 CHECK_ARGUMENT_PATH(path);
417 ACQUIRE_LOCK;
418
419 return translate(VolumeManager::Instance()->fixupAppDir(path, appUid));
420}
421
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600422binder::Status VoldNativeService::createObb(const std::string& sourcePath,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700423 const std::string& sourceKey, int32_t ownerGid,
424 std::string* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100425 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600426 CHECK_ARGUMENT_PATH(sourcePath);
427 CHECK_ARGUMENT_HEX(sourceKey);
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600428 ACQUIRE_LOCK;
429
430 return translate(
Songchun Fan01c4e912020-03-03 17:58:20 -0800431 VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return));
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600432}
433
434binder::Status VoldNativeService::destroyObb(const std::string& volId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100435 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600436 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600437 ACQUIRE_LOCK;
438
439 return translate(VolumeManager::Instance()->destroyObb(volId));
440}
441
Risan82e90de2020-02-04 16:07:21 +0900442binder::Status VoldNativeService::createStubVolume(const std::string& sourcePath,
443 const std::string& mountPath,
444 const std::string& fsType,
445 const std::string& fsUuid,
446 const std::string& fsLabel, int32_t flags,
447 std::string* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100448 ENFORCE_SYSTEM_OR_ROOT;
Risan8c9f3322018-10-29 08:52:56 +0900449 CHECK_ARGUMENT_PATH(sourcePath);
450 CHECK_ARGUMENT_PATH(mountPath);
451 CHECK_ARGUMENT_HEX(fsUuid);
452 // Label limitation seems to be different between fs (including allowed characters), so checking
453 // is quite meaningless.
454 ACQUIRE_LOCK;
455
Risan82e90de2020-02-04 16:07:21 +0900456 return translate(VolumeManager::Instance()->createStubVolume(
457 sourcePath, mountPath, fsType, fsUuid, fsLabel, flags, _aidl_return));
Risan8c9f3322018-10-29 08:52:56 +0900458}
459
460binder::Status VoldNativeService::destroyStubVolume(const std::string& volId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100461 ENFORCE_SYSTEM_OR_ROOT;
Risan8c9f3322018-10-29 08:52:56 +0900462 CHECK_ARGUMENT_ID(volId);
463 ACQUIRE_LOCK;
464
465 return translate(VolumeManager::Instance()->destroyStubVolume(volId));
466}
467
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700468binder::Status VoldNativeService::fstrim(
Songchun Fan01c4e912020-03-03 17:58:20 -0800469 int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100470 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600471 ACQUIRE_LOCK;
472
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700473 std::thread([=]() { android::vold::Trim(listener); }).detach();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700474 return Ok();
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600475}
476
Jin Qiana370c142017-10-17 15:41:45 -0700477binder::Status VoldNativeService::runIdleMaint(
Songchun Fan01c4e912020-03-03 17:58:20 -0800478 const android::sp<android::os::IVoldTaskListener>& listener) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100479 ENFORCE_SYSTEM_OR_ROOT;
Jin Qiana370c142017-10-17 15:41:45 -0700480 ACQUIRE_LOCK;
481
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700482 std::thread([=]() { android::vold::RunIdleMaint(listener); }).detach();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700483 return Ok();
Jin Qiana370c142017-10-17 15:41:45 -0700484}
485
486binder::Status VoldNativeService::abortIdleMaint(
Songchun Fan01c4e912020-03-03 17:58:20 -0800487 const android::sp<android::os::IVoldTaskListener>& listener) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100488 ENFORCE_SYSTEM_OR_ROOT;
Jin Qiana370c142017-10-17 15:41:45 -0700489 ACQUIRE_LOCK;
490
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700491 std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700492 return Ok();
Jin Qiana370c142017-10-17 15:41:45 -0700493}
494
Risan8f6198d2018-10-26 20:56:45 -0600495binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t mountId,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700496 android::base::unique_fd* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100497 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600498 ACQUIRE_LOCK;
499
Risan8f6198d2018-10-26 20:56:45 -0600500 return translate(VolumeManager::Instance()->mountAppFuse(uid, mountId, _aidl_return));
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600501}
502
Risan8f6198d2018-10-26 20:56:45 -0600503binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t mountId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100504 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600505 ACQUIRE_LOCK;
506
Risan8f6198d2018-10-26 20:56:45 -0600507 return translate(VolumeManager::Instance()->unmountAppFuse(uid, mountId));
508}
509
510binder::Status VoldNativeService::openAppFuseFile(int32_t uid, int32_t mountId, int32_t fileId,
511 int32_t flags,
512 android::base::unique_fd* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100513 ENFORCE_SYSTEM_OR_ROOT;
Risan8f6198d2018-10-26 20:56:45 -0600514 ACQUIRE_LOCK;
515
516 int fd = VolumeManager::Instance()->openAppFuseFile(uid, mountId, fileId, flags);
517 if (fd == -1) {
518 return error("Failed to open AppFuse file for uid: " + std::to_string(uid) +
519 " mountId: " + std::to_string(mountId) + " fileId: " + std::to_string(fileId) +
520 " flags: " + std::to_string(flags));
521 }
522
523 *_aidl_return = android::base::unique_fd(fd);
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700524 return Ok();
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600525}
526
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600527binder::Status VoldNativeService::fdeCheckPassword(const std::string& password) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100528 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600529 ACQUIRE_CRYPT_LOCK;
530
531 return translate(cryptfs_check_passwd(password.c_str()));
532}
533
534binder::Status VoldNativeService::fdeRestart() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100535 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600536 ACQUIRE_CRYPT_LOCK;
537
538 // Spawn as thread so init can issue commands back to vold without
539 // causing deadlock, usually as a result of prep_data_fs.
540 std::thread(&cryptfs_restart).detach();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700541 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600542}
543
544binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100545 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600546 ACQUIRE_CRYPT_LOCK;
547
548 *_aidl_return = cryptfs_crypto_complete();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700549 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600550}
551
552static int fdeEnableInternal(int32_t passwordType, const std::string& password,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700553 int32_t encryptionFlags) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600554 bool noUi = (encryptionFlags & VoldNativeService::ENCRYPTION_FLAG_NO_UI) != 0;
555
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600556 for (int tries = 0; tries < 2; ++tries) {
557 int rc;
558 if (passwordType == VoldNativeService::PASSWORD_TYPE_DEFAULT) {
Paul Lawrence7ee87cf2017-12-22 10:12:06 -0800559 rc = cryptfs_enable_default(noUi);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600560 } else {
Paul Lawrence7ee87cf2017-12-22 10:12:06 -0800561 rc = cryptfs_enable(passwordType, password.c_str(), noUi);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600562 }
563
564 if (rc == 0) {
565 return 0;
566 } else if (tries == 0) {
Jeff Sharkey3472e522017-10-06 18:02:53 -0600567 KillProcessesWithOpenFiles(DATA_MNT_POINT, SIGKILL);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600568 }
569 }
570
571 return -1;
572}
573
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700574binder::Status VoldNativeService::fdeEnable(int32_t passwordType, const std::string& password,
575 int32_t encryptionFlags) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100576 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600577 ACQUIRE_CRYPT_LOCK;
578
Paul Crowley0fd26262018-01-30 09:48:19 -0800579 LOG(DEBUG) << "fdeEnable(" << passwordType << ", *, " << encryptionFlags << ")";
Eric Biggersa701c452018-10-23 13:06:55 -0700580 if (fscrypt_is_native()) {
581 LOG(ERROR) << "fscrypt_is_native, fdeEnable invalid";
582 return error("fscrypt_is_native, fdeEnable invalid");
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600583 }
Eric Biggersa701c452018-10-23 13:06:55 -0700584 LOG(DEBUG) << "!fscrypt_is_native, spawning fdeEnableInternal";
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600585
586 // Spawn as thread so init can issue commands back to vold without
587 // causing deadlock, usually as a result of prep_data_fs.
588 std::thread(&fdeEnableInternal, passwordType, password, encryptionFlags).detach();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700589 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600590}
591
592binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700593 const std::string& password) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100594 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600595 ACQUIRE_CRYPT_LOCK;
596
597 return translate(cryptfs_changepw(passwordType, password.c_str()));
598}
599
600binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100601 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600602 ACQUIRE_CRYPT_LOCK;
603
604 return translate(cryptfs_verify_passwd(password.c_str()));
605}
606
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700607binder::Status VoldNativeService::fdeGetField(const std::string& key, std::string* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100608 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600609 ACQUIRE_CRYPT_LOCK;
610
611 char buf[PROPERTY_VALUE_MAX];
612 if (cryptfs_getfield(key.c_str(), buf, sizeof(buf)) != CRYPTO_GETFIELD_OK) {
613 return error(StringPrintf("Failed to read field %s", key.c_str()));
614 } else {
615 *_aidl_return = buf;
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700616 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600617 }
618}
619
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700620binder::Status VoldNativeService::fdeSetField(const std::string& key, const std::string& value) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100621 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600622 ACQUIRE_CRYPT_LOCK;
623
624 return translate(cryptfs_setfield(key.c_str(), value.c_str()));
625}
626
627binder::Status VoldNativeService::fdeGetPasswordType(int32_t* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100628 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600629 ACQUIRE_CRYPT_LOCK;
630
631 *_aidl_return = cryptfs_get_password_type();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700632 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600633}
634
635binder::Status VoldNativeService::fdeGetPassword(std::string* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100636 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600637 ACQUIRE_CRYPT_LOCK;
638
639 const char* res = cryptfs_get_password();
640 if (res != nullptr) {
641 *_aidl_return = res;
642 }
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700643 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600644}
645
646binder::Status VoldNativeService::fdeClearPassword() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100647 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600648 ACQUIRE_CRYPT_LOCK;
649
650 cryptfs_clear_password();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700651 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600652}
653
654binder::Status VoldNativeService::fbeEnable() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100655 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600656 ACQUIRE_CRYPT_LOCK;
657
Paul Crowleyc8a3ef32019-09-11 15:00:08 -0700658 return translateBool(fscrypt_initialize_systemwide_keys());
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600659}
660
661binder::Status VoldNativeService::mountDefaultEncrypted() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100662 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600663 ACQUIRE_CRYPT_LOCK;
664
Eric Biggersa701c452018-10-23 13:06:55 -0700665 if (!fscrypt_is_native()) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600666 // Spawn as thread so init can issue commands back to vold without
667 // causing deadlock, usually as a result of prep_data_fs.
668 std::thread(&cryptfs_mount_default_encrypted).detach();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600669 }
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700670 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600671}
672
673binder::Status VoldNativeService::initUser0() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100674 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600675 ACQUIRE_CRYPT_LOCK;
676
Eric Biggersa701c452018-10-23 13:06:55 -0700677 return translateBool(fscrypt_init_user0());
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600678}
679
680binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100681 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600682 ACQUIRE_CRYPT_LOCK;
683
684 *_aidl_return = cryptfs_isConvertibleToFBE() != 0;
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700685 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600686}
687
Paul Lawrence236e5e82019-06-25 14:44:33 -0700688binder::Status VoldNativeService::mountFstab(const std::string& blkDevice,
689 const std::string& mountPoint) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100690 ENFORCE_SYSTEM_OR_ROOT;
Paul Crowley0fd26262018-01-30 09:48:19 -0800691 ACQUIRE_LOCK;
692
Jaegeuk Kim0c52c712020-12-15 09:00:49 -0800693 return translateBool(
694 fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, false, false, "null"));
Paul Crowley0fd26262018-01-30 09:48:19 -0800695}
696
Paul Lawrence236e5e82019-06-25 14:44:33 -0700697binder::Status VoldNativeService::encryptFstab(const std::string& blkDevice,
Jaegeuk Kim0c52c712020-12-15 09:00:49 -0800698 const std::string& mountPoint, bool shouldFormat,
699 const std::string& fsType) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100700 ENFORCE_SYSTEM_OR_ROOT;
Paul Crowley0fd26262018-01-30 09:48:19 -0800701 ACQUIRE_LOCK;
702
Jaegeuk Kim0c52c712020-12-15 09:00:49 -0800703 return translateBool(
704 fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, true, shouldFormat, fsType));
Paul Crowley0fd26262018-01-30 09:48:19 -0800705}
706
Seth Moore5a43d612021-01-19 17:51:51 +0000707binder::Status VoldNativeService::setStorageBindingSeed(const std::vector<uint8_t>& seed) {
708 ENFORCE_SYSTEM_OR_ROOT;
709 ACQUIRE_CRYPT_LOCK;
710
711 return translateBool(setKeyStorageBindingSeed(seed));
712}
713
Songchun Fan01c4e912020-03-03 17:58:20 -0800714binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial,
715 bool ephemeral) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100716 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600717 ACQUIRE_CRYPT_LOCK;
718
Eric Biggersa701c452018-10-23 13:06:55 -0700719 return translateBool(fscrypt_vold_create_user_key(userId, userSerial, ephemeral));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600720}
721
722binder::Status VoldNativeService::destroyUserKey(int32_t userId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100723 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600724 ACQUIRE_CRYPT_LOCK;
725
Eric Biggersa701c452018-10-23 13:06:55 -0700726 return translateBool(fscrypt_destroy_user_key(userId));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600727}
728
Satya Tangiralae1361712021-03-15 15:33:08 -0700729static bool token_empty(const std::string& token) {
730 return token.size() == 0 || token == "!";
731}
732
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600733binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700734 const std::string& token,
735 const std::string& secret) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100736 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600737 ACQUIRE_CRYPT_LOCK;
738
Satya Tangiralae1361712021-03-15 15:33:08 -0700739 if (!token_empty(token)) {
740 LOG(ERROR) << "Vold doesn't use auth tokens, but non-empty token passed to addUserKeyAuth.";
741 return binder::Status::fromServiceSpecificError(-EINVAL);
742 }
743
744 return translateBool(fscrypt_add_user_key_auth(userId, userSerial, secret));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600745}
746
Barani Muthukumaran9ad51ad2019-10-31 22:59:34 -0700747binder::Status VoldNativeService::clearUserKeyAuth(int32_t userId, int32_t userSerial,
748 const std::string& token,
749 const std::string& secret) {
750 ENFORCE_SYSTEM_OR_ROOT;
751 ACQUIRE_CRYPT_LOCK;
752
Satya Tangiralae1361712021-03-15 15:33:08 -0700753 if (!token_empty(token)) {
754 LOG(ERROR)
755 << "Vold doesn't use auth tokens, but non-empty token passed to clearUserKeyAuth.";
756 return binder::Status::fromServiceSpecificError(-EINVAL);
757 }
758
759 return translateBool(fscrypt_clear_user_key_auth(userId, userSerial, secret));
Barani Muthukumaran9ad51ad2019-10-31 22:59:34 -0700760}
761
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600762binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100763 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600764 ACQUIRE_CRYPT_LOCK;
765
Eric Biggersa701c452018-10-23 13:06:55 -0700766 return translateBool(fscrypt_fixate_newest_user_key_auth(userId));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600767}
768
Eric Biggers1799deb2021-04-06 12:02:56 -0700769binder::Status VoldNativeService::getUnlockedUsers(std::vector<int>* _aidl_return) {
770 ENFORCE_SYSTEM_OR_ROOT;
771 ACQUIRE_CRYPT_LOCK;
772
773 *_aidl_return = fscrypt_get_unlocked_users();
774 return Ok();
775}
776
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600777binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700778 const std::string& token,
779 const std::string& secret) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100780 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600781 ACQUIRE_CRYPT_LOCK;
782
Satya Tangiralae1361712021-03-15 15:33:08 -0700783 if (!token_empty(token)) {
784 LOG(ERROR) << "Vold doesn't use auth tokens, but non-empty token passed to unlockUserKey.";
785 return binder::Status::fromServiceSpecificError(-EINVAL);
786 }
787
788 return translateBool(fscrypt_unlock_user_key(userId, userSerial, secret));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600789}
790
791binder::Status VoldNativeService::lockUserKey(int32_t userId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100792 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600793 ACQUIRE_CRYPT_LOCK;
794
Eric Biggersa701c452018-10-23 13:06:55 -0700795 return translateBool(fscrypt_lock_user_key(userId));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600796}
797
Jooyung Han4fcb7072020-01-23 13:23:26 +0900798binder::Status VoldNativeService::prepareUserStorage(const std::optional<std::string>& uuid,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700799 int32_t userId, int32_t userSerial,
800 int32_t flags) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100801 ENFORCE_SYSTEM_OR_ROOT;
Paul Crowley3b71fc52017-10-09 10:55:21 -0700802 std::string empty_string = "";
803 auto uuid_ = uuid ? *uuid : empty_string;
Paul Crowley06f762d2017-10-16 10:59:51 -0700804 CHECK_ARGUMENT_HEX(uuid_);
805
806 ACQUIRE_CRYPT_LOCK;
Eric Biggersa701c452018-10-23 13:06:55 -0700807 return translateBool(fscrypt_prepare_user_storage(uuid_, userId, userSerial, flags));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600808}
809
Jooyung Han4fcb7072020-01-23 13:23:26 +0900810binder::Status VoldNativeService::destroyUserStorage(const std::optional<std::string>& uuid,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700811 int32_t userId, int32_t flags) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100812 ENFORCE_SYSTEM_OR_ROOT;
Paul Crowley3b71fc52017-10-09 10:55:21 -0700813 std::string empty_string = "";
814 auto uuid_ = uuid ? *uuid : empty_string;
Paul Crowley06f762d2017-10-16 10:59:51 -0700815 CHECK_ARGUMENT_HEX(uuid_);
816
817 ACQUIRE_CRYPT_LOCK;
Eric Biggersa701c452018-10-23 13:06:55 -0700818 return translateBool(fscrypt_destroy_user_storage(uuid_, userId, flags));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600819}
820
Sudheer Shankafa6a1742018-10-04 16:26:22 -0700821binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packageName,
822 int32_t appId, const std::string& sandboxId,
823 int32_t userId) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700824 return Ok();
Sudheer Shankafa6a1742018-10-04 16:26:22 -0700825}
826
827binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName,
Sudheer Shanka69bc40f2018-10-25 11:06:55 -0700828 const std::string& sandboxId,
Sudheer Shankafa6a1742018-10-04 16:26:22 -0700829 int32_t userId) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700830 return Ok();
Sudheer Shankac7562092018-08-24 10:20:56 -0700831}
832
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700833binder::Status VoldNativeService::startCheckpoint(int32_t retry) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100834 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700835 ACQUIRE_LOCK;
836
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700837 return cp_startCheckpoint(retry);
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700838}
839
Daniel Rosenbergd3992492018-10-02 17:40:44 -0700840binder::Status VoldNativeService::needsRollback(bool* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100841 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenbergd3992492018-10-02 17:40:44 -0700842 ACQUIRE_LOCK;
843
844 *_aidl_return = cp_needsRollback();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700845 return Ok();
Daniel Rosenbergd3992492018-10-02 17:40:44 -0700846}
847
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700848binder::Status VoldNativeService::needsCheckpoint(bool* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100849 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700850 ACQUIRE_LOCK;
851
852 *_aidl_return = cp_needsCheckpoint();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700853 return Ok();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700854}
855
David Anderson23850d32020-06-10 23:51:17 -0700856binder::Status VoldNativeService::isCheckpointing(bool* _aidl_return) {
857 ENFORCE_SYSTEM_OR_ROOT;
858 ACQUIRE_LOCK;
859
860 *_aidl_return = cp_isCheckpointing();
861 return Ok();
862}
863
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700864binder::Status VoldNativeService::commitChanges() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100865 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700866 ACQUIRE_LOCK;
867
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700868 return cp_commitChanges();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700869}
870
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700871binder::Status VoldNativeService::prepareCheckpoint() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100872 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700873 ACQUIRE_LOCK;
874
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700875 return cp_prepareCheckpoint();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700876}
877
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700878binder::Status VoldNativeService::restoreCheckpoint(const std::string& mountPoint) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100879 ENFORCE_SYSTEM_OR_ROOT;
Paul Lawrence1abb2fe2018-09-21 10:49:57 -0700880 CHECK_ARGUMENT_PATH(mountPoint);
881 ACQUIRE_LOCK;
882
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700883 return cp_restoreCheckpoint(mountPoint);
Paul Lawrence1abb2fe2018-09-21 10:49:57 -0700884}
885
Daniel Rosenbergdda59812019-03-06 17:45:17 -0800886binder::Status VoldNativeService::restoreCheckpointPart(const std::string& mountPoint, int count) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100887 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenbergdda59812019-03-06 17:45:17 -0800888 CHECK_ARGUMENT_PATH(mountPoint);
889 ACQUIRE_LOCK;
890
891 return cp_restoreCheckpoint(mountPoint, count);
892}
893
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700894binder::Status VoldNativeService::markBootAttempt() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100895 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700896 ACQUIRE_LOCK;
897
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700898 return cp_markBootAttempt();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700899}
900
Daniel Rosenberga59e4392019-03-20 17:02:47 -0700901binder::Status VoldNativeService::abortChanges(const std::string& message, bool retry) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100902 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700903 ACQUIRE_LOCK;
904
Daniel Rosenberga59e4392019-03-20 17:02:47 -0700905 cp_abortChanges(message, retry);
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700906 return Ok();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700907}
908
Daniel Rosenberg9b667fb2019-01-22 17:27:25 -0800909binder::Status VoldNativeService::supportsCheckpoint(bool* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100910 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg9b667fb2019-01-22 17:27:25 -0800911 ACQUIRE_LOCK;
912
913 return cp_supportsCheckpoint(*_aidl_return);
914}
915
Paul Lawrencec5c79c52019-03-18 13:36:40 -0700916binder::Status VoldNativeService::supportsBlockCheckpoint(bool* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100917 ENFORCE_SYSTEM_OR_ROOT;
Paul Lawrencec5c79c52019-03-18 13:36:40 -0700918 ACQUIRE_LOCK;
919
920 return cp_supportsBlockCheckpoint(*_aidl_return);
921}
922
923binder::Status VoldNativeService::supportsFileCheckpoint(bool* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100924 ENFORCE_SYSTEM_OR_ROOT;
Paul Lawrencec5c79c52019-03-18 13:36:40 -0700925 ACQUIRE_LOCK;
926
927 return cp_supportsFileCheckpoint(*_aidl_return);
928}
929
Nikita Ioffea5798fc2019-10-11 16:38:21 +0100930binder::Status VoldNativeService::resetCheckpoint() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100931 ENFORCE_SYSTEM_OR_ROOT;
Nikita Ioffea5798fc2019-10-11 16:38:21 +0100932 ACQUIRE_LOCK;
933
934 cp_resetCheckpoint();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700935 return Ok();
Nikita Ioffea5798fc2019-10-11 16:38:21 +0100936}
937
Alex Buynytskyyb02e7b62021-02-11 19:09:10 -0800938static void initializeIncFs() {
939 // Obtaining IncFS features triggers initialization of IncFS.
940 incfs::features();
941}
942
Eric Biggers4859e0c2021-06-24 11:13:24 -0700943// This is missing from the kernel UAPI headers.
944#define ST_RDONLY 0x0001
945
946// FDE devices run the post-fs-data trigger (and hence also earlyBootEnded)
947// multiple times, sometimes prior to the real /data being mounted. That causes
948// keystore2 to try to open a file in /data, causing it to panic or have to be
949// killed by vold later, causing problems (vold failing to connect to keystore2,
950// or keystore2 operations erroring out later). As a workaround to keep FDE
951// working, ignore these too-early calls to earlyBootEnded.
952//
953// This can be removed when support for FDE is removed.
954static bool IgnoreEarlyBootEnded() {
955 // The statfs("/data") below should be sufficient by itself, but to be safe
956 // we also explicitly return false on FBE devices. (This really should be
957 // ro.crypto.type != "block" for "non-FDE devices", but on FDE devices this
958 // is sometimes called before ro.crypto.type gets set.)
959 if (fscrypt_is_native()) return false;
960
961 struct statfs buf;
962 if (statfs(DATA_MNT_POINT, &buf) != 0) {
963 PLOG(ERROR) << "statfs(\"/data\") failed";
964 return false;
965 }
966 if (buf.f_type == TMPFS_MAGIC || (buf.f_flags & ST_RDONLY)) {
967 LOG(INFO) << "Ignoring earlyBootEnded since real /data isn't mounted yet";
968 return true;
969 }
970 return false;
971}
972
Martijn Coeneneed957f2020-11-12 10:59:13 +0100973binder::Status VoldNativeService::earlyBootEnded() {
974 ENFORCE_SYSTEM_OR_ROOT;
975 ACQUIRE_LOCK;
976
Eric Biggers4859e0c2021-06-24 11:13:24 -0700977 if (IgnoreEarlyBootEnded()) return Ok();
978
Alex Buynytskyyb02e7b62021-02-11 19:09:10 -0800979 initializeIncFs();
Eric Biggersd86a8ab2021-06-15 11:34:00 -0700980 Keystore::earlyBootEnded();
Martijn Coeneneed957f2020-11-12 10:59:13 +0100981 return Ok();
982}
983
Yurii Zubrytskyi3497cb52020-01-10 11:54:06 -0800984binder::Status VoldNativeService::incFsEnabled(bool* _aidl_return) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700985 ENFORCE_SYSTEM_OR_ROOT;
986
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -0700987 *_aidl_return = incfs::enabled();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700988 return Ok();
Songchun Fanab55cec2019-12-02 10:50:12 -0800989}
990
991binder::Status VoldNativeService::mountIncFs(
Yurii Zubrytskyi3497cb52020-01-10 11:54:06 -0800992 const std::string& backingPath, const std::string& targetDir, int32_t flags,
Songchun Fan046e68a2021-04-27 12:46:02 -0700993 const std::string& sysfsName,
Songchun Fanab55cec2019-12-02 10:50:12 -0800994 ::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700995 ENFORCE_SYSTEM_OR_ROOT;
996 CHECK_ARGUMENT_PATH(backingPath);
997 CHECK_ARGUMENT_PATH(targetDir);
998
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -0700999 auto control = incfs::mount(backingPath, targetDir,
1000 {.flags = IncFsMountFlags(flags),
Alex Buynytskyydcfeaa12021-04-01 13:43:14 -07001001 // Mount with read timeouts.
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -07001002 .defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS,
1003 // Mount with read logs disabled.
Songchun Fan046e68a2021-04-27 12:46:02 -07001004 .readLogBufferPages = 0,
1005 .sysfsName = sysfsName.c_str()});
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -07001006 if (!control) {
1007 return translate(-errno);
Songchun Fanab55cec2019-12-02 10:50:12 -08001008 }
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -07001009 auto fds = control.releaseFds();
1010 using android::base::unique_fd;
1011 _aidl_return->cmd.reset(unique_fd(fds[CMD].release()));
1012 _aidl_return->pendingReads.reset(unique_fd(fds[PENDING_READS].release()));
1013 _aidl_return->log.reset(unique_fd(fds[LOGS].release()));
Yurii Zubrytskyi0c0f8392020-12-08 07:33:37 -08001014 if (fds[BLOCKS_WRITTEN].ok()) {
1015 _aidl_return->blocksWritten.emplace(unique_fd(fds[BLOCKS_WRITTEN].release()));
1016 }
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -07001017 return Ok();
Songchun Fanab55cec2019-12-02 10:50:12 -08001018}
1019
1020binder::Status VoldNativeService::unmountIncFs(const std::string& dir) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -07001021 ENFORCE_SYSTEM_OR_ROOT;
1022 CHECK_ARGUMENT_PATH(dir);
1023
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -07001024 return translate(incfs::unmount(dir));
Songchun Fanab55cec2019-12-02 10:50:12 -08001025}
1026
Alex Buynytskyy91e0bf42020-03-31 14:46:25 -07001027binder::Status VoldNativeService::setIncFsMountOptions(
1028 const ::android::os::incremental::IncrementalFileSystemControlParcel& control,
Songchun Fan0e53c1c2021-05-10 16:19:38 -07001029 bool enableReadLogs, bool enableReadTimeouts, const std::string& sysfsName) {
Alex Buynytskyy605a44f2020-04-02 15:21:47 -07001030 ENFORCE_SYSTEM_OR_ROOT;
Alex Buynytskyy91e0bf42020-03-31 14:46:25 -07001031
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -07001032 auto incfsControl =
Yurii Zubrytskyi0c0f8392020-12-08 07:33:37 -08001033 incfs::createControl(control.cmd.get(), control.pendingReads.get(), control.log.get(),
1034 control.blocksWritten ? control.blocksWritten->get() : -1);
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -07001035 auto cleanupFunc = [](auto incfsControl) {
1036 for (auto& fd : incfsControl->releaseFds()) {
1037 (void)fd.release();
1038 }
1039 };
1040 auto cleanup =
1041 std::unique_ptr<incfs::Control, decltype(cleanupFunc)>(&incfsControl, cleanupFunc);
Alex Buynytskyy91e0bf42020-03-31 14:46:25 -07001042
Yurii Zubrytskyi1d7acfd2021-10-28 14:37:12 -07001043 constexpr auto minReadLogBufferPages = INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES;
1044 constexpr auto maxReadLogBufferPages = 8 * INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES;
1045 auto options = incfs::MountOptions{
1046 .defaultReadTimeoutMs =
1047 enableReadTimeouts ? INCFS_DEFAULT_READ_TIMEOUT_MS : kIncFsReadNoTimeoutMs,
1048 .readLogBufferPages = enableReadLogs ? maxReadLogBufferPages : 0,
1049 .sysfsName = sysfsName.c_str()};
1050
1051 for (;;) {
1052 const auto error = incfs::setOptions(incfsControl, options);
1053 if (!error) {
1054 return Ok();
1055 }
1056 if (!enableReadLogs || error != -ENOMEM) {
1057 return binder::Status::fromServiceSpecificError(error);
1058 }
1059 // In case of memory allocation error retry with a smaller buffer.
1060 options.readLogBufferPages /= 2;
1061 if (options.readLogBufferPages < minReadLogBufferPages) {
1062 return binder::Status::fromServiceSpecificError(error);
1063 }
1064 }
1065 // unreachable, but makes the compiler happy
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -07001066 return Ok();
Alex Buynytskyy91e0bf42020-03-31 14:46:25 -07001067}
1068
Songchun Fanab55cec2019-12-02 10:50:12 -08001069binder::Status VoldNativeService::bindMount(const std::string& sourceDir,
1070 const std::string& targetDir) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -07001071 ENFORCE_SYSTEM_OR_ROOT;
1072 CHECK_ARGUMENT_PATH(sourceDir);
1073 CHECK_ARGUMENT_PATH(targetDir);
1074
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -07001075 return translate(incfs::bindMount(sourceDir, targetDir));
Songchun Fanab55cec2019-12-02 10:50:12 -08001076}
1077
Yo Chiang0af25a32020-10-07 14:20:00 +08001078binder::Status VoldNativeService::destroyDsuMetadataKey(const std::string& dsuSlot) {
1079 ENFORCE_SYSTEM_OR_ROOT;
1080 ACQUIRE_LOCK;
1081
1082 return translateBool(destroy_dsu_metadata_key(dsuSlot));
1083}
1084
Jeff Sharkey068c6be2017-09-06 13:47:40 -06001085} // namespace vold
1086} // namespace android