blob: 1033af93d6166160ceee2f7169dc633a87730ded [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>
Songchun Fan01c4e912020-03-03 17:58:20 -080022#include <android-base/strings.h>
23#include <fs_mgr.h>
24#include <fscrypt/fscrypt.h>
25#include <private/android_filesystem_config.h>
26#include <utils/Trace.h>
27
Keun young Park0bccae22021-10-13 16:50:10 -070028#include <stdio.h>
Songchun Fan01c4e912020-03-03 17:58:20 -080029#include <fstream>
30#include <thread>
31
Jeff Sharkey01a0e7f2017-10-17 16:06:32 -060032#include "Benchmark.h"
Daniel Rosenberg4f684712018-08-28 01:58:49 -070033#include "Checkpoint.h"
Eric Biggersa701c452018-10-23 13:06:55 -070034#include "FsCrypt.h"
Paul Crowley73be12d2020-02-03 12:22:03 -080035#include "IdleMaint.h"
Seth Moore5a43d612021-01-19 17:51:51 +000036#include "KeyStorage.h"
Eric Biggersd86a8ab2021-06-15 11:34:00 -070037#include "Keystore.h"
Jeff Sharkey83b559c2017-09-12 16:30:52 -060038#include "MetadataCrypt.h"
Paul Crowley73be12d2020-02-03 12:22:03 -080039#include "MoveStorage.h"
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -070040#include "VoldNativeServiceValidation.h"
Paul Crowley73be12d2020-02-03 12:22:03 -080041#include "VoldUtil.h"
42#include "VolumeManager.h"
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070043#include "cryptfs.h"
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -070044#include "incfs.h"
Jeff Sharkey83b559c2017-09-12 16:30:52 -060045
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -070046using namespace std::literals;
Jeff Sharkey068c6be2017-09-06 13:47:40 -060047
48namespace android {
49namespace vold {
50
51namespace {
52
53constexpr const char* kDump = "android.permission.DUMP";
Alex Buynytskyydcfeaa12021-04-01 13:43:14 -070054constexpr auto kIncFsReadNoTimeoutMs = 100;
Jeff Sharkey068c6be2017-09-06 13:47:40 -060055
Jeff Sharkey9462bdd2017-09-07 15:27:28 -060056static binder::Status error(const std::string& msg) {
57 PLOG(ERROR) << msg;
58 return binder::Status::fromServiceSpecificError(errno, String8(msg.c_str()));
59}
60
Jeff Sharkey83b559c2017-09-12 16:30:52 -060061static binder::Status translate(int status) {
Jeff Sharkey9462bdd2017-09-07 15:27:28 -060062 if (status == 0) {
63 return binder::Status::ok();
64 } else {
Jeff Sharkey11c2d382017-09-11 10:32:01 -060065 return binder::Status::fromServiceSpecificError(status);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -060066 }
67}
68
Jeff Sharkey83b559c2017-09-12 16:30:52 -060069static binder::Status translateBool(bool status) {
70 if (status) {
71 return binder::Status::ok();
72 } else {
73 return binder::Status::fromServiceSpecificError(status);
74 }
75}
76
Nikita Ioffe5d85bf32019-10-23 17:19:13 +010077#define ENFORCE_SYSTEM_OR_ROOT \
78 { \
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -070079 binder::Status status = CheckUidOrRoot(AID_SYSTEM); \
Nikita Ioffe5d85bf32019-10-23 17:19:13 +010080 if (!status.isOk()) { \
81 return status; \
82 } \
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070083 }
Jeff Sharkey068c6be2017-09-06 13:47:40 -060084
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070085#define CHECK_ARGUMENT_ID(id) \
86 { \
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -070087 binder::Status status = CheckArgumentId((id)); \
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070088 if (!status.isOk()) { \
89 return status; \
90 } \
91 }
Jeff Sharkeyec4fda22017-09-12 13:19:24 -060092
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070093#define CHECK_ARGUMENT_PATH(path) \
94 { \
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -070095 binder::Status status = CheckArgumentPath((path)); \
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070096 if (!status.isOk()) { \
97 return status; \
98 } \
99 }
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600100
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700101#define CHECK_ARGUMENT_HEX(hex) \
102 { \
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700103 binder::Status status = CheckArgumentHex((hex)); \
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700104 if (!status.isOk()) { \
105 return status; \
106 } \
107 }
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600108
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700109#define ACQUIRE_LOCK \
Jeff Sharkey67b8c492017-09-21 17:08:43 -0600110 std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \
111 ATRACE_CALL();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600112
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700113#define ACQUIRE_CRYPT_LOCK \
Jeff Sharkey67b8c492017-09-21 17:08:43 -0600114 std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \
115 ATRACE_CALL();
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600116
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600117} // namespace
118
119status_t VoldNativeService::start() {
120 IPCThreadState::self()->disableBackgroundScheduling(true);
121 status_t ret = BinderService<VoldNativeService>::publish();
122 if (ret != android::OK) {
123 return ret;
124 }
125 sp<ProcessState> ps(ProcessState::self());
126 ps->startThreadPool();
127 ps->giveThreadPoolName();
128 return android::OK;
129}
130
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700131status_t VoldNativeService::dump(int fd, const Vector<String16>& /* args */) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700132 const binder::Status dump_permission = CheckPermission(kDump);
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600133 if (!dump_permission.isOk()) {
Keun young Park0bccae22021-10-13 16:50:10 -0700134 dprintf(fd, "%s\n", dump_permission.toString8().c_str());
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600135 return PERMISSION_DENIED;
136 }
137
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600138 ACQUIRE_LOCK;
Keun young Park0bccae22021-10-13 16:50:10 -0700139 dprintf(fd, "vold is happy!\n");
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600140 return NO_ERROR;
141}
142
Jeff Sharkey814e9d32017-09-13 11:49:44 -0600143binder::Status VoldNativeService::setListener(
Songchun Fan01c4e912020-03-03 17:58:20 -0800144 const android::sp<android::os::IVoldListener>& listener) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100145 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey814e9d32017-09-13 11:49:44 -0600146 ACQUIRE_LOCK;
147
148 VolumeManager::Instance()->setListener(listener);
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700149 return Ok();
Jeff Sharkey814e9d32017-09-13 11:49:44 -0600150}
151
Jeff Sharkeycbe69fc2017-09-15 16:50:28 -0600152binder::Status VoldNativeService::monitor() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100153 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeycbe69fc2017-09-15 16:50:28 -0600154
155 // Simply acquire/release each lock for watchdog
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700156 { ACQUIRE_LOCK; }
157 { ACQUIRE_CRYPT_LOCK; }
Jeff Sharkeycbe69fc2017-09-15 16:50:28 -0600158
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700159 return Ok();
Jeff Sharkeycbe69fc2017-09-15 16:50:28 -0600160}
161
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600162binder::Status VoldNativeService::reset() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100163 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600164 ACQUIRE_LOCK;
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600165
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600166 return translate(VolumeManager::Instance()->reset());
167}
168
169binder::Status VoldNativeService::shutdown() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100170 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600171 ACQUIRE_LOCK;
172
173 return translate(VolumeManager::Instance()->shutdown());
174}
175
Martijn Coenen23c04452020-04-29 07:49:41 +0200176binder::Status VoldNativeService::abortFuse() {
177 ENFORCE_SYSTEM_OR_ROOT;
lijiaziffe76222021-03-17 16:51:16 +0800178 // if acquire lock, maybe lead to a deadlock if lock is held by a
179 // thread that is blocked on a FUSE operation.
180 // abort fuse doesn't need to access any state, so do not acquire lock
Martijn Coenen23c04452020-04-29 07:49:41 +0200181
182 return translate(VolumeManager::Instance()->abortFuse());
183}
184
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600185binder::Status VoldNativeService::onUserAdded(int32_t userId, int32_t userSerial) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100186 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600187 ACQUIRE_LOCK;
188
189 return translate(VolumeManager::Instance()->onUserAdded(userId, userSerial));
190}
191
192binder::Status VoldNativeService::onUserRemoved(int32_t userId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100193 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600194 ACQUIRE_LOCK;
195
196 return translate(VolumeManager::Instance()->onUserRemoved(userId));
197}
198
Sudheer Shanka5fceb482019-04-29 10:46:35 -0700199binder::Status VoldNativeService::onUserStarted(int32_t userId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100200 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600201 ACQUIRE_LOCK;
202
Sudheer Shanka5fceb482019-04-29 10:46:35 -0700203 return translate(VolumeManager::Instance()->onUserStarted(userId));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600204}
205
206binder::Status VoldNativeService::onUserStopped(int32_t userId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100207 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600208 ACQUIRE_LOCK;
209
210 return translate(VolumeManager::Instance()->onUserStopped(userId));
211}
212
Sudheer Shankad484aa92018-07-31 10:07:34 -0700213binder::Status VoldNativeService::addAppIds(const std::vector<std::string>& packageNames,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700214 const std::vector<int32_t>& appIds) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700215 return Ok();
Sudheer Shankad484aa92018-07-31 10:07:34 -0700216}
217
Sudheer Shankad484aa92018-07-31 10:07:34 -0700218binder::Status VoldNativeService::addSandboxIds(const std::vector<int32_t>& appIds,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700219 const std::vector<std::string>& sandboxIds) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700220 return Ok();
Sudheer Shankad484aa92018-07-31 10:07:34 -0700221}
222
Jeff Sharkey401b2602017-12-14 22:15:20 -0700223binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100224 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey401b2602017-12-14 22:15:20 -0700225 ACQUIRE_LOCK;
226
227 return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing));
228}
229
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600230binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700231 int32_t ratio) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100232 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600233 CHECK_ARGUMENT_ID(diskId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600234 ACQUIRE_LOCK;
235
236 auto disk = VolumeManager::Instance()->findDisk(diskId);
237 if (disk == nullptr) {
238 return error("Failed to find disk " + diskId);
239 }
240 switch (partitionType) {
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700241 case PARTITION_TYPE_PUBLIC:
242 return translate(disk->partitionPublic());
243 case PARTITION_TYPE_PRIVATE:
244 return translate(disk->partitionPrivate());
245 case PARTITION_TYPE_MIXED:
246 return translate(disk->partitionMixed(ratio));
247 default:
248 return error("Unknown type " + std::to_string(partitionType));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600249 }
250}
251
Jeff Sharkey3ce18252017-10-24 11:08:45 -0600252binder::Status VoldNativeService::forgetPartition(const std::string& partGuid,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700253 const std::string& fsUuid) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100254 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600255 CHECK_ARGUMENT_HEX(partGuid);
Jeff Sharkey3ce18252017-10-24 11:08:45 -0600256 CHECK_ARGUMENT_HEX(fsUuid);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600257 ACQUIRE_LOCK;
258
Jeff Sharkey3ce18252017-10-24 11:08:45 -0600259 return translate(VolumeManager::Instance()->forgetPartition(partGuid, fsUuid));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600260}
261
Zim5048b4b2019-11-19 09:16:03 +0000262binder::Status VoldNativeService::mount(
263 const std::string& volId, int32_t mountFlags, int32_t mountUserId,
264 const android::sp<android::os::IVoldMountCallback>& callback) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100265 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600266 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600267 ACQUIRE_LOCK;
268
269 auto vol = VolumeManager::Instance()->findVolume(volId);
270 if (vol == nullptr) {
271 return error("Failed to find volume " + volId);
272 }
273
274 vol->setMountFlags(mountFlags);
275 vol->setMountUserId(mountUserId);
276
Zim5048b4b2019-11-19 09:16:03 +0000277 vol->setMountCallback(callback);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600278 int res = vol->mount();
Zim5048b4b2019-11-19 09:16:03 +0000279 vol->setMountCallback(nullptr);
280
Sudheer Shanka40ab6742018-09-18 13:07:45 -0700281 if (res != OK) {
282 return translate(res);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600283 }
Zim3623a212019-07-19 16:46:53 +0100284
Sudheer Shanka40ab6742018-09-18 13:07:45 -0700285 return translate(OK);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600286}
287
288binder::Status VoldNativeService::unmount(const std::string& volId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100289 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600290 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600291 ACQUIRE_LOCK;
292
293 auto vol = VolumeManager::Instance()->findVolume(volId);
294 if (vol == nullptr) {
295 return error("Failed to find volume " + volId);
296 }
297 return translate(vol->unmount());
298}
299
300binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100301 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600302 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600303 ACQUIRE_LOCK;
304
305 auto vol = VolumeManager::Instance()->findVolume(volId);
306 if (vol == nullptr) {
307 return error("Failed to find volume " + volId);
308 }
309 return translate(vol->format(fsType));
310}
311
Jeff Sharkey2048a282017-06-15 09:59:43 -0600312static binder::Status pathForVolId(const std::string& volId, std::string* path) {
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600313 if (volId == "private" || volId == "null") {
Jeff Sharkey2048a282017-06-15 09:59:43 -0600314 *path = "/data";
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600315 } else {
316 auto vol = VolumeManager::Instance()->findVolume(volId);
317 if (vol == nullptr) {
318 return error("Failed to find volume " + volId);
319 }
320 if (vol->getType() != VolumeBase::Type::kPrivate) {
321 return error("Volume " + volId + " not private");
322 }
323 if (vol->getState() != VolumeBase::State::kMounted) {
324 return error("Volume " + volId + " not mounted");
325 }
Jeff Sharkey2048a282017-06-15 09:59:43 -0600326 *path = vol->getPath();
327 if (path->empty()) {
328 return error("Volume " + volId + " missing path");
329 }
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600330 }
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700331 return Ok();
Jeff Sharkey2048a282017-06-15 09:59:43 -0600332}
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600333
Jeff Sharkey2048a282017-06-15 09:59:43 -0600334binder::Status VoldNativeService::benchmark(
Songchun Fan01c4e912020-03-03 17:58:20 -0800335 const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100336 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey2048a282017-06-15 09:59:43 -0600337 CHECK_ARGUMENT_ID(volId);
338 ACQUIRE_LOCK;
339
340 std::string path;
341 auto status = pathForVolId(volId, &path);
342 if (!status.isOk()) return status;
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600343
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700344 std::thread([=]() { android::vold::Benchmark(path, listener); }).detach();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700345 return Ok();
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600346}
347
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700348binder::Status VoldNativeService::moveStorage(
Songchun Fan01c4e912020-03-03 17:58:20 -0800349 const std::string& fromVolId, const std::string& toVolId,
350 const android::sp<android::os::IVoldTaskListener>& listener) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100351 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600352 CHECK_ARGUMENT_ID(fromVolId);
353 CHECK_ARGUMENT_ID(toVolId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600354 ACQUIRE_LOCK;
355
356 auto fromVol = VolumeManager::Instance()->findVolume(fromVolId);
357 auto toVol = VolumeManager::Instance()->findVolume(toVolId);
358 if (fromVol == nullptr) {
359 return error("Failed to find volume " + fromVolId);
360 } else if (toVol == nullptr) {
361 return error("Failed to find volume " + toVolId);
362 }
Jeff Sharkey01a0e7f2017-10-17 16:06:32 -0600363
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700364 std::thread([=]() { android::vold::MoveStorage(fromVol, toVol, listener); }).detach();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700365 return Ok();
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600366}
367
368binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100369 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600370 ACQUIRE_LOCK;
371
Sudheer Shanka817b9112018-12-13 17:40:28 -0800372 return translate(VolumeManager::Instance()->remountUid(uid, remountMode));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600373}
374
Ricky Wai6b122572020-02-28 16:30:47 +0000375binder::Status VoldNativeService::remountAppStorageDirs(int uid, int pid,
376 const std::vector<std::string>& packageNames) {
377 ENFORCE_SYSTEM_OR_ROOT;
378 ACQUIRE_LOCK;
379
Ricky Waia2ca11e2021-01-15 14:03:23 +0000380 return translate(VolumeManager::Instance()->handleAppStorageDirs(uid, pid,
381 false /* doUnmount */, packageNames));
382}
383
384binder::Status VoldNativeService::unmountAppStorageDirs(int uid, int pid,
385 const std::vector<std::string>& packageNames) {
386 ENFORCE_SYSTEM_OR_ROOT;
387 ACQUIRE_LOCK;
388
389 return translate(VolumeManager::Instance()->handleAppStorageDirs(uid, pid,
390 true /* doUnmount */, packageNames));
Ricky Wai6b122572020-02-28 16:30:47 +0000391}
392
Martijn Coenen8a68a072020-02-12 15:29:02 +0100393binder::Status VoldNativeService::setupAppDir(const std::string& path, int32_t appUid) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100394 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600395 CHECK_ARGUMENT_PATH(path);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600396 ACQUIRE_LOCK;
397
Martijn Coenen8a68a072020-02-12 15:29:02 +0100398 return translate(VolumeManager::Instance()->setupAppDir(path, appUid));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600399}
400
Ricky Waibbfb6ea2020-12-03 15:32:52 +0000401binder::Status VoldNativeService::ensureAppDirsCreated(const std::vector<std::string>& paths,
402 int32_t appUid) {
403 ENFORCE_SYSTEM_OR_ROOT;
404 ACQUIRE_LOCK;
405
406 return translate(VolumeManager::Instance()->ensureAppDirsCreated(paths, appUid));
407}
408
Martijn Coenen816f4d92020-02-18 15:06:37 +0100409binder::Status VoldNativeService::fixupAppDir(const std::string& path, int32_t appUid) {
410 ENFORCE_SYSTEM_OR_ROOT;
411 CHECK_ARGUMENT_PATH(path);
412 ACQUIRE_LOCK;
413
414 return translate(VolumeManager::Instance()->fixupAppDir(path, appUid));
415}
416
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600417binder::Status VoldNativeService::createObb(const std::string& sourcePath,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700418 const std::string& sourceKey, int32_t ownerGid,
419 std::string* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100420 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600421 CHECK_ARGUMENT_PATH(sourcePath);
422 CHECK_ARGUMENT_HEX(sourceKey);
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600423 ACQUIRE_LOCK;
424
425 return translate(
Songchun Fan01c4e912020-03-03 17:58:20 -0800426 VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return));
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600427}
428
429binder::Status VoldNativeService::destroyObb(const std::string& volId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100430 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600431 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600432 ACQUIRE_LOCK;
433
434 return translate(VolumeManager::Instance()->destroyObb(volId));
435}
436
Risan82e90de2020-02-04 16:07:21 +0900437binder::Status VoldNativeService::createStubVolume(const std::string& sourcePath,
438 const std::string& mountPath,
439 const std::string& fsType,
440 const std::string& fsUuid,
441 const std::string& fsLabel, int32_t flags,
442 std::string* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100443 ENFORCE_SYSTEM_OR_ROOT;
Risan8c9f3322018-10-29 08:52:56 +0900444 CHECK_ARGUMENT_PATH(sourcePath);
445 CHECK_ARGUMENT_PATH(mountPath);
446 CHECK_ARGUMENT_HEX(fsUuid);
447 // Label limitation seems to be different between fs (including allowed characters), so checking
448 // is quite meaningless.
449 ACQUIRE_LOCK;
450
Risan82e90de2020-02-04 16:07:21 +0900451 return translate(VolumeManager::Instance()->createStubVolume(
452 sourcePath, mountPath, fsType, fsUuid, fsLabel, flags, _aidl_return));
Risan8c9f3322018-10-29 08:52:56 +0900453}
454
455binder::Status VoldNativeService::destroyStubVolume(const std::string& volId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100456 ENFORCE_SYSTEM_OR_ROOT;
Risan8c9f3322018-10-29 08:52:56 +0900457 CHECK_ARGUMENT_ID(volId);
458 ACQUIRE_LOCK;
459
460 return translate(VolumeManager::Instance()->destroyStubVolume(volId));
461}
462
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700463binder::Status VoldNativeService::fstrim(
Songchun Fan01c4e912020-03-03 17:58:20 -0800464 int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100465 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600466 ACQUIRE_LOCK;
467
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700468 std::thread([=]() { android::vold::Trim(listener); }).detach();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700469 return Ok();
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600470}
471
Jin Qiana370c142017-10-17 15:41:45 -0700472binder::Status VoldNativeService::runIdleMaint(
Daeho Jeong999fceb2022-01-04 11:37:39 -0800473 bool needGC, const android::sp<android::os::IVoldTaskListener>& listener) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100474 ENFORCE_SYSTEM_OR_ROOT;
Jin Qiana370c142017-10-17 15:41:45 -0700475 ACQUIRE_LOCK;
476
Daeho Jeong999fceb2022-01-04 11:37:39 -0800477 std::thread([=]() { android::vold::RunIdleMaint(needGC, listener); }).detach();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700478 return Ok();
Jin Qiana370c142017-10-17 15:41:45 -0700479}
480
481binder::Status VoldNativeService::abortIdleMaint(
Songchun Fan01c4e912020-03-03 17:58:20 -0800482 const android::sp<android::os::IVoldTaskListener>& listener) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100483 ENFORCE_SYSTEM_OR_ROOT;
Jin Qiana370c142017-10-17 15:41:45 -0700484 ACQUIRE_LOCK;
485
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700486 std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700487 return Ok();
Jin Qiana370c142017-10-17 15:41:45 -0700488}
489
Daeho Jeong999fceb2022-01-04 11:37:39 -0800490binder::Status VoldNativeService::getStorageLifeTime(int32_t* _aidl_return) {
491 ENFORCE_SYSTEM_OR_ROOT;
492 ACQUIRE_LOCK;
493
494 *_aidl_return = GetStorageLifeTime();
495 return Ok();
496}
497
498binder::Status VoldNativeService::setGCUrgentPace(int32_t neededSegments,
499 int32_t minSegmentThreshold,
500 float dirtyReclaimRate, float reclaimWeight) {
501 ENFORCE_SYSTEM_OR_ROOT;
502 ACQUIRE_LOCK;
503
504 SetGCUrgentPace(neededSegments, minSegmentThreshold, dirtyReclaimRate, reclaimWeight);
505 return Ok();
506}
507
508binder::Status VoldNativeService::refreshLatestWrite() {
509 ENFORCE_SYSTEM_OR_ROOT;
510 ACQUIRE_LOCK;
511
512 RefreshLatestWrite();
513 return Ok();
514}
515
516binder::Status VoldNativeService::getWriteAmount(int32_t* _aidl_return) {
517 ENFORCE_SYSTEM_OR_ROOT;
518 ACQUIRE_LOCK;
519
520 *_aidl_return = GetWriteAmount();
521 return Ok();
522}
523
Risan8f6198d2018-10-26 20:56:45 -0600524binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t mountId,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700525 android::base::unique_fd* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100526 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600527 ACQUIRE_LOCK;
528
Risan8f6198d2018-10-26 20:56:45 -0600529 return translate(VolumeManager::Instance()->mountAppFuse(uid, mountId, _aidl_return));
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600530}
531
Risan8f6198d2018-10-26 20:56:45 -0600532binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t mountId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100533 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600534 ACQUIRE_LOCK;
535
Risan8f6198d2018-10-26 20:56:45 -0600536 return translate(VolumeManager::Instance()->unmountAppFuse(uid, mountId));
537}
538
539binder::Status VoldNativeService::openAppFuseFile(int32_t uid, int32_t mountId, int32_t fileId,
540 int32_t flags,
541 android::base::unique_fd* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100542 ENFORCE_SYSTEM_OR_ROOT;
Risan8f6198d2018-10-26 20:56:45 -0600543 ACQUIRE_LOCK;
544
545 int fd = VolumeManager::Instance()->openAppFuseFile(uid, mountId, fileId, flags);
546 if (fd == -1) {
547 return error("Failed to open AppFuse file for uid: " + std::to_string(uid) +
548 " mountId: " + std::to_string(mountId) + " fileId: " + std::to_string(fileId) +
549 " flags: " + std::to_string(flags));
550 }
551
552 *_aidl_return = android::base::unique_fd(fd);
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700553 return Ok();
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600554}
555
Eric Biggers0803ba02021-11-08 16:45:58 -0800556// TODO(b/191796797) remove this once caller is removed
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600557binder::Status VoldNativeService::fdeCheckPassword(const std::string& password) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100558 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600559 ACQUIRE_CRYPT_LOCK;
560
Eric Biggers0803ba02021-11-08 16:45:58 -0800561 SLOGE("fdeCheckPassword is no longer supported");
562 return translate(-1);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600563}
564
Eric Biggers0803ba02021-11-08 16:45:58 -0800565// TODO(b/191796797) remove this once caller is removed
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600566binder::Status VoldNativeService::fdeRestart() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100567 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600568 ACQUIRE_CRYPT_LOCK;
569
Eric Biggers0803ba02021-11-08 16:45:58 -0800570 SLOGE("fdeRestart is no longer supported");
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700571 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600572}
573
Eric Biggers0803ba02021-11-08 16:45:58 -0800574// TODO(b/191796797) remove this once caller is removed
575#define CRYPTO_COMPLETE_NOT_ENCRYPTED 1
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600576binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100577 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600578 ACQUIRE_CRYPT_LOCK;
579
Eric Biggers0803ba02021-11-08 16:45:58 -0800580 SLOGE("fdeComplete is no longer supported");
581 *_aidl_return = CRYPTO_COMPLETE_NOT_ENCRYPTED;
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700582 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600583}
584
Eric Biggers0803ba02021-11-08 16:45:58 -0800585// TODO(b/191796797) remove this once caller is removed
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700586binder::Status VoldNativeService::fdeEnable(int32_t passwordType, const std::string& password,
587 int32_t encryptionFlags) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100588 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600589 ACQUIRE_CRYPT_LOCK;
590
Eric Biggers0803ba02021-11-08 16:45:58 -0800591 SLOGE("fdeEnable is no longer supported");
592 return translate(-1);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600593}
594
Eric Biggers0803ba02021-11-08 16:45:58 -0800595// TODO(b/191796797) remove this once caller is removed
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600596binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700597 const std::string& password) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100598 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600599 ACQUIRE_CRYPT_LOCK;
600
Eric Biggers0803ba02021-11-08 16:45:58 -0800601 SLOGE("fdeChangePassword is no longer supported");
602 return translate(-1);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600603}
604
Eric Biggers0803ba02021-11-08 16:45:58 -0800605// TODO(b/191796797) remove this once caller is removed
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600606binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100607 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600608 ACQUIRE_CRYPT_LOCK;
609
Eric Biggers0803ba02021-11-08 16:45:58 -0800610 SLOGE("fdeVerifyPassword is no longer supported");
611 return translate(-1);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600612}
613
Eric Biggers0803ba02021-11-08 16:45:58 -0800614// TODO(b/191796797) remove this once caller is removed
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700615binder::Status VoldNativeService::fdeGetField(const std::string& key, std::string* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100616 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600617 ACQUIRE_CRYPT_LOCK;
618
Eric Biggers0803ba02021-11-08 16:45:58 -0800619 SLOGE("fdeGetField is no longer supported");
620 return translate(-1);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600621}
622
Eric Biggers0803ba02021-11-08 16:45:58 -0800623// TODO(b/191796797) remove this once caller is removed
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700624binder::Status VoldNativeService::fdeSetField(const std::string& key, const std::string& value) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100625 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600626 ACQUIRE_CRYPT_LOCK;
627
Eric Biggers0803ba02021-11-08 16:45:58 -0800628 SLOGE("fdeSetField is no longer supported");
629 return translate(-1);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600630}
631
Eric Biggers0803ba02021-11-08 16:45:58 -0800632// TODO(b/191796797) remove this once caller is removed
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600633binder::Status VoldNativeService::fdeGetPasswordType(int32_t* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100634 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600635 ACQUIRE_CRYPT_LOCK;
636
Eric Biggers0803ba02021-11-08 16:45:58 -0800637 SLOGE("fdeGetPasswordType is no longer supported");
638 *_aidl_return = -1;
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700639 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600640}
641
Eric Biggers0803ba02021-11-08 16:45:58 -0800642// TODO(b/191796797) remove this once caller is removed
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600643binder::Status VoldNativeService::fdeGetPassword(std::string* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100644 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600645 ACQUIRE_CRYPT_LOCK;
646
Eric Biggers0803ba02021-11-08 16:45:58 -0800647 SLOGE("fdeGetPassword is no longer supported");
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700648 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600649}
650
Eric Biggers0803ba02021-11-08 16:45:58 -0800651// TODO(b/191796797) remove this once caller is removed
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600652binder::Status VoldNativeService::fdeClearPassword() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100653 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600654 ACQUIRE_CRYPT_LOCK;
655
Eric Biggers0803ba02021-11-08 16:45:58 -0800656 SLOGE("fdeClearPassword is no longer supported");
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700657 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600658}
659
660binder::Status VoldNativeService::fbeEnable() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100661 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600662 ACQUIRE_CRYPT_LOCK;
663
Paul Crowleyc8a3ef32019-09-11 15:00:08 -0700664 return translateBool(fscrypt_initialize_systemwide_keys());
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600665}
666
Eric Biggers0803ba02021-11-08 16:45:58 -0800667// TODO(b/191796797) remove this once caller is removed
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600668binder::Status VoldNativeService::mountDefaultEncrypted() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100669 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600670 ACQUIRE_CRYPT_LOCK;
671
Eric Biggers0803ba02021-11-08 16:45:58 -0800672 SLOGE("mountDefaultEncrypted is no longer supported");
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700673 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600674}
675
676binder::Status VoldNativeService::initUser0() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100677 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600678 ACQUIRE_CRYPT_LOCK;
679
Eric Biggersa701c452018-10-23 13:06:55 -0700680 return translateBool(fscrypt_init_user0());
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600681}
682
Eric Biggers0803ba02021-11-08 16:45:58 -0800683// TODO(b/191796797) remove this once caller is removed
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600684binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100685 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600686 ACQUIRE_CRYPT_LOCK;
687
Eric Biggers0803ba02021-11-08 16:45:58 -0800688 SLOGE("isConvertibleToFbe is no longer supported");
689 *_aidl_return = false;
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700690 return Ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600691}
692
Paul Lawrence236e5e82019-06-25 14:44:33 -0700693binder::Status VoldNativeService::mountFstab(const std::string& blkDevice,
694 const std::string& mountPoint) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100695 ENFORCE_SYSTEM_OR_ROOT;
Paul Crowley0fd26262018-01-30 09:48:19 -0800696 ACQUIRE_LOCK;
697
Jaegeuk Kim0c52c712020-12-15 09:00:49 -0800698 return translateBool(
699 fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, false, false, "null"));
Paul Crowley0fd26262018-01-30 09:48:19 -0800700}
701
Paul Lawrence236e5e82019-06-25 14:44:33 -0700702binder::Status VoldNativeService::encryptFstab(const std::string& blkDevice,
Jaegeuk Kim0c52c712020-12-15 09:00:49 -0800703 const std::string& mountPoint, bool shouldFormat,
704 const std::string& fsType) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100705 ENFORCE_SYSTEM_OR_ROOT;
Paul Crowley0fd26262018-01-30 09:48:19 -0800706 ACQUIRE_LOCK;
707
Jaegeuk Kim0c52c712020-12-15 09:00:49 -0800708 return translateBool(
709 fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, true, shouldFormat, fsType));
Paul Crowley0fd26262018-01-30 09:48:19 -0800710}
711
Seth Moore5a43d612021-01-19 17:51:51 +0000712binder::Status VoldNativeService::setStorageBindingSeed(const std::vector<uint8_t>& seed) {
713 ENFORCE_SYSTEM_OR_ROOT;
714 ACQUIRE_CRYPT_LOCK;
715
716 return translateBool(setKeyStorageBindingSeed(seed));
717}
718
Songchun Fan01c4e912020-03-03 17:58:20 -0800719binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial,
720 bool ephemeral) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100721 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600722 ACQUIRE_CRYPT_LOCK;
723
Eric Biggersa701c452018-10-23 13:06:55 -0700724 return translateBool(fscrypt_vold_create_user_key(userId, userSerial, ephemeral));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600725}
726
727binder::Status VoldNativeService::destroyUserKey(int32_t userId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100728 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600729 ACQUIRE_CRYPT_LOCK;
730
Eric Biggersa701c452018-10-23 13:06:55 -0700731 return translateBool(fscrypt_destroy_user_key(userId));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600732}
733
Satya Tangiralae1361712021-03-15 15:33:08 -0700734static bool token_empty(const std::string& token) {
735 return token.size() == 0 || token == "!";
736}
737
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600738binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700739 const std::string& token,
740 const std::string& secret) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100741 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600742 ACQUIRE_CRYPT_LOCK;
743
Satya Tangiralae1361712021-03-15 15:33:08 -0700744 if (!token_empty(token)) {
745 LOG(ERROR) << "Vold doesn't use auth tokens, but non-empty token passed to addUserKeyAuth.";
746 return binder::Status::fromServiceSpecificError(-EINVAL);
747 }
748
749 return translateBool(fscrypt_add_user_key_auth(userId, userSerial, secret));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600750}
751
Barani Muthukumaran9ad51ad2019-10-31 22:59:34 -0700752binder::Status VoldNativeService::clearUserKeyAuth(int32_t userId, int32_t userSerial,
753 const std::string& token,
754 const std::string& secret) {
755 ENFORCE_SYSTEM_OR_ROOT;
756 ACQUIRE_CRYPT_LOCK;
757
Satya Tangiralae1361712021-03-15 15:33:08 -0700758 if (!token_empty(token)) {
759 LOG(ERROR)
760 << "Vold doesn't use auth tokens, but non-empty token passed to clearUserKeyAuth.";
761 return binder::Status::fromServiceSpecificError(-EINVAL);
762 }
763
764 return translateBool(fscrypt_clear_user_key_auth(userId, userSerial, secret));
Barani Muthukumaran9ad51ad2019-10-31 22:59:34 -0700765}
766
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600767binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100768 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600769 ACQUIRE_CRYPT_LOCK;
770
Eric Biggersa701c452018-10-23 13:06:55 -0700771 return translateBool(fscrypt_fixate_newest_user_key_auth(userId));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600772}
773
Eric Biggers1799deb2021-04-06 12:02:56 -0700774binder::Status VoldNativeService::getUnlockedUsers(std::vector<int>* _aidl_return) {
775 ENFORCE_SYSTEM_OR_ROOT;
776 ACQUIRE_CRYPT_LOCK;
777
778 *_aidl_return = fscrypt_get_unlocked_users();
779 return Ok();
780}
781
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600782binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700783 const std::string& token,
784 const std::string& secret) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100785 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600786 ACQUIRE_CRYPT_LOCK;
787
Satya Tangiralae1361712021-03-15 15:33:08 -0700788 if (!token_empty(token)) {
789 LOG(ERROR) << "Vold doesn't use auth tokens, but non-empty token passed to unlockUserKey.";
790 return binder::Status::fromServiceSpecificError(-EINVAL);
791 }
792
793 return translateBool(fscrypt_unlock_user_key(userId, userSerial, secret));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600794}
795
796binder::Status VoldNativeService::lockUserKey(int32_t userId) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100797 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600798 ACQUIRE_CRYPT_LOCK;
799
Eric Biggersa701c452018-10-23 13:06:55 -0700800 return translateBool(fscrypt_lock_user_key(userId));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600801}
802
Jooyung Han4fcb7072020-01-23 13:23:26 +0900803binder::Status VoldNativeService::prepareUserStorage(const std::optional<std::string>& uuid,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700804 int32_t userId, int32_t userSerial,
805 int32_t flags) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100806 ENFORCE_SYSTEM_OR_ROOT;
Paul Crowley3b71fc52017-10-09 10:55:21 -0700807 std::string empty_string = "";
808 auto uuid_ = uuid ? *uuid : empty_string;
Paul Crowley06f762d2017-10-16 10:59:51 -0700809 CHECK_ARGUMENT_HEX(uuid_);
810
811 ACQUIRE_CRYPT_LOCK;
Eric Biggersa701c452018-10-23 13:06:55 -0700812 return translateBool(fscrypt_prepare_user_storage(uuid_, userId, userSerial, flags));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600813}
814
Jooyung Han4fcb7072020-01-23 13:23:26 +0900815binder::Status VoldNativeService::destroyUserStorage(const std::optional<std::string>& uuid,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700816 int32_t userId, int32_t flags) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100817 ENFORCE_SYSTEM_OR_ROOT;
Paul Crowley3b71fc52017-10-09 10:55:21 -0700818 std::string empty_string = "";
819 auto uuid_ = uuid ? *uuid : empty_string;
Paul Crowley06f762d2017-10-16 10:59:51 -0700820 CHECK_ARGUMENT_HEX(uuid_);
821
822 ACQUIRE_CRYPT_LOCK;
Eric Biggersa701c452018-10-23 13:06:55 -0700823 return translateBool(fscrypt_destroy_user_storage(uuid_, userId, flags));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600824}
825
Sudheer Shankafa6a1742018-10-04 16:26:22 -0700826binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packageName,
827 int32_t appId, const std::string& sandboxId,
828 int32_t userId) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700829 return Ok();
Sudheer Shankafa6a1742018-10-04 16:26:22 -0700830}
831
832binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName,
Sudheer Shanka69bc40f2018-10-25 11:06:55 -0700833 const std::string& sandboxId,
Sudheer Shankafa6a1742018-10-04 16:26:22 -0700834 int32_t userId) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700835 return Ok();
Sudheer Shankac7562092018-08-24 10:20:56 -0700836}
837
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700838binder::Status VoldNativeService::startCheckpoint(int32_t retry) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100839 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700840 ACQUIRE_LOCK;
841
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700842 return cp_startCheckpoint(retry);
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700843}
844
Daniel Rosenbergd3992492018-10-02 17:40:44 -0700845binder::Status VoldNativeService::needsRollback(bool* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100846 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenbergd3992492018-10-02 17:40:44 -0700847 ACQUIRE_LOCK;
848
849 *_aidl_return = cp_needsRollback();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700850 return Ok();
Daniel Rosenbergd3992492018-10-02 17:40:44 -0700851}
852
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700853binder::Status VoldNativeService::needsCheckpoint(bool* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100854 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700855 ACQUIRE_LOCK;
856
857 *_aidl_return = cp_needsCheckpoint();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700858 return Ok();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700859}
860
David Anderson23850d32020-06-10 23:51:17 -0700861binder::Status VoldNativeService::isCheckpointing(bool* _aidl_return) {
862 ENFORCE_SYSTEM_OR_ROOT;
863 ACQUIRE_LOCK;
864
865 *_aidl_return = cp_isCheckpointing();
866 return Ok();
867}
868
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700869binder::Status VoldNativeService::commitChanges() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100870 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700871 ACQUIRE_LOCK;
872
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700873 return cp_commitChanges();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700874}
875
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700876binder::Status VoldNativeService::prepareCheckpoint() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100877 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700878 ACQUIRE_LOCK;
879
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700880 return cp_prepareCheckpoint();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700881}
882
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700883binder::Status VoldNativeService::restoreCheckpoint(const std::string& mountPoint) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100884 ENFORCE_SYSTEM_OR_ROOT;
Paul Lawrence1abb2fe2018-09-21 10:49:57 -0700885 CHECK_ARGUMENT_PATH(mountPoint);
886 ACQUIRE_LOCK;
887
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700888 return cp_restoreCheckpoint(mountPoint);
Paul Lawrence1abb2fe2018-09-21 10:49:57 -0700889}
890
Daniel Rosenbergdda59812019-03-06 17:45:17 -0800891binder::Status VoldNativeService::restoreCheckpointPart(const std::string& mountPoint, int count) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100892 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenbergdda59812019-03-06 17:45:17 -0800893 CHECK_ARGUMENT_PATH(mountPoint);
894 ACQUIRE_LOCK;
895
896 return cp_restoreCheckpoint(mountPoint, count);
897}
898
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700899binder::Status VoldNativeService::markBootAttempt() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100900 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700901 ACQUIRE_LOCK;
902
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700903 return cp_markBootAttempt();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700904}
905
Daniel Rosenberga59e4392019-03-20 17:02:47 -0700906binder::Status VoldNativeService::abortChanges(const std::string& message, bool retry) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100907 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700908 ACQUIRE_LOCK;
909
Daniel Rosenberga59e4392019-03-20 17:02:47 -0700910 cp_abortChanges(message, retry);
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700911 return Ok();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700912}
913
Daniel Rosenberg9b667fb2019-01-22 17:27:25 -0800914binder::Status VoldNativeService::supportsCheckpoint(bool* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100915 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg9b667fb2019-01-22 17:27:25 -0800916 ACQUIRE_LOCK;
917
918 return cp_supportsCheckpoint(*_aidl_return);
919}
920
Paul Lawrencec5c79c52019-03-18 13:36:40 -0700921binder::Status VoldNativeService::supportsBlockCheckpoint(bool* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100922 ENFORCE_SYSTEM_OR_ROOT;
Paul Lawrencec5c79c52019-03-18 13:36:40 -0700923 ACQUIRE_LOCK;
924
925 return cp_supportsBlockCheckpoint(*_aidl_return);
926}
927
928binder::Status VoldNativeService::supportsFileCheckpoint(bool* _aidl_return) {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100929 ENFORCE_SYSTEM_OR_ROOT;
Paul Lawrencec5c79c52019-03-18 13:36:40 -0700930 ACQUIRE_LOCK;
931
932 return cp_supportsFileCheckpoint(*_aidl_return);
933}
934
Nikita Ioffea5798fc2019-10-11 16:38:21 +0100935binder::Status VoldNativeService::resetCheckpoint() {
Nikita Ioffe5d85bf32019-10-23 17:19:13 +0100936 ENFORCE_SYSTEM_OR_ROOT;
Nikita Ioffea5798fc2019-10-11 16:38:21 +0100937 ACQUIRE_LOCK;
938
939 cp_resetCheckpoint();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700940 return Ok();
Nikita Ioffea5798fc2019-10-11 16:38:21 +0100941}
942
Alex Buynytskyyb02e7b62021-02-11 19:09:10 -0800943static void initializeIncFs() {
944 // Obtaining IncFS features triggers initialization of IncFS.
945 incfs::features();
946}
947
Martijn Coeneneed957f2020-11-12 10:59:13 +0100948binder::Status VoldNativeService::earlyBootEnded() {
949 ENFORCE_SYSTEM_OR_ROOT;
950 ACQUIRE_LOCK;
951
Alex Buynytskyyb02e7b62021-02-11 19:09:10 -0800952 initializeIncFs();
Eric Biggersd86a8ab2021-06-15 11:34:00 -0700953 Keystore::earlyBootEnded();
Martijn Coeneneed957f2020-11-12 10:59:13 +0100954 return Ok();
955}
956
Yurii Zubrytskyi3497cb52020-01-10 11:54:06 -0800957binder::Status VoldNativeService::incFsEnabled(bool* _aidl_return) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700958 ENFORCE_SYSTEM_OR_ROOT;
959
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -0700960 *_aidl_return = incfs::enabled();
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700961 return Ok();
Songchun Fanab55cec2019-12-02 10:50:12 -0800962}
963
964binder::Status VoldNativeService::mountIncFs(
Yurii Zubrytskyi3497cb52020-01-10 11:54:06 -0800965 const std::string& backingPath, const std::string& targetDir, int32_t flags,
Songchun Fan046e68a2021-04-27 12:46:02 -0700966 const std::string& sysfsName,
Songchun Fanab55cec2019-12-02 10:50:12 -0800967 ::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700968 ENFORCE_SYSTEM_OR_ROOT;
Yurii Zubrytskyi18eb8772021-10-18 22:33:15 -0700969 if (auto status = CheckIncrementalPath(IncrementalPathKind::MountTarget, targetDir);
970 !status.isOk()) {
971 return status;
972 }
973 if (auto status = CheckIncrementalPath(IncrementalPathKind::MountSource, backingPath);
974 !status.isOk()) {
975 return status;
976 }
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -0700977
Yurii Zubrytskyi18eb8772021-10-18 22:33:15 -0700978 auto [backingFd, backingSymlink] = OpenDirInProcfs(backingPath);
979 if (!backingFd.ok()) {
980 return translate(-errno);
981 }
982 auto [targetFd, targetSymlink] = OpenDirInProcfs(targetDir);
983 if (!targetFd.ok()) {
984 return translate(-errno);
985 }
986
987 auto control = incfs::mount(backingSymlink, targetSymlink,
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -0700988 {.flags = IncFsMountFlags(flags),
Alex Buynytskyydcfeaa12021-04-01 13:43:14 -0700989 // Mount with read timeouts.
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -0700990 .defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS,
991 // Mount with read logs disabled.
Songchun Fan046e68a2021-04-27 12:46:02 -0700992 .readLogBufferPages = 0,
993 .sysfsName = sysfsName.c_str()});
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -0700994 if (!control) {
995 return translate(-errno);
Songchun Fanab55cec2019-12-02 10:50:12 -0800996 }
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -0700997 auto fds = control.releaseFds();
998 using android::base::unique_fd;
999 _aidl_return->cmd.reset(unique_fd(fds[CMD].release()));
1000 _aidl_return->pendingReads.reset(unique_fd(fds[PENDING_READS].release()));
1001 _aidl_return->log.reset(unique_fd(fds[LOGS].release()));
Yurii Zubrytskyi0c0f8392020-12-08 07:33:37 -08001002 if (fds[BLOCKS_WRITTEN].ok()) {
1003 _aidl_return->blocksWritten.emplace(unique_fd(fds[BLOCKS_WRITTEN].release()));
1004 }
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -07001005 return Ok();
Songchun Fanab55cec2019-12-02 10:50:12 -08001006}
1007
1008binder::Status VoldNativeService::unmountIncFs(const std::string& dir) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -07001009 ENFORCE_SYSTEM_OR_ROOT;
Yurii Zubrytskyi18eb8772021-10-18 22:33:15 -07001010 if (auto status = CheckIncrementalPath(IncrementalPathKind::Any, dir); !status.isOk()) {
1011 return status;
1012 }
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -07001013
Yurii Zubrytskyi18eb8772021-10-18 22:33:15 -07001014 auto [fd, symLink] = OpenDirInProcfs(dir);
1015 if (!fd.ok()) {
1016 return translate(-errno);
1017 }
1018 return translate(incfs::unmount(symLink));
Songchun Fanab55cec2019-12-02 10:50:12 -08001019}
1020
Alex Buynytskyy91e0bf42020-03-31 14:46:25 -07001021binder::Status VoldNativeService::setIncFsMountOptions(
1022 const ::android::os::incremental::IncrementalFileSystemControlParcel& control,
Songchun Fan0e53c1c2021-05-10 16:19:38 -07001023 bool enableReadLogs, bool enableReadTimeouts, const std::string& sysfsName) {
Alex Buynytskyy605a44f2020-04-02 15:21:47 -07001024 ENFORCE_SYSTEM_OR_ROOT;
Alex Buynytskyy91e0bf42020-03-31 14:46:25 -07001025
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -07001026 auto incfsControl =
Yurii Zubrytskyi0c0f8392020-12-08 07:33:37 -08001027 incfs::createControl(control.cmd.get(), control.pendingReads.get(), control.log.get(),
1028 control.blocksWritten ? control.blocksWritten->get() : -1);
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -07001029 auto cleanupFunc = [](auto incfsControl) {
1030 for (auto& fd : incfsControl->releaseFds()) {
1031 (void)fd.release();
1032 }
1033 };
1034 auto cleanup =
1035 std::unique_ptr<incfs::Control, decltype(cleanupFunc)>(&incfsControl, cleanupFunc);
Alex Buynytskyy91e0bf42020-03-31 14:46:25 -07001036
Yurii Zubrytskyi1d7acfd2021-10-28 14:37:12 -07001037 constexpr auto minReadLogBufferPages = INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES;
1038 constexpr auto maxReadLogBufferPages = 8 * INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES;
1039 auto options = incfs::MountOptions{
1040 .defaultReadTimeoutMs =
1041 enableReadTimeouts ? INCFS_DEFAULT_READ_TIMEOUT_MS : kIncFsReadNoTimeoutMs,
1042 .readLogBufferPages = enableReadLogs ? maxReadLogBufferPages : 0,
1043 .sysfsName = sysfsName.c_str()};
1044
1045 for (;;) {
1046 const auto error = incfs::setOptions(incfsControl, options);
1047 if (!error) {
1048 return Ok();
1049 }
1050 if (!enableReadLogs || error != -ENOMEM) {
1051 return binder::Status::fromServiceSpecificError(error);
1052 }
1053 // In case of memory allocation error retry with a smaller buffer.
1054 options.readLogBufferPages /= 2;
1055 if (options.readLogBufferPages < minReadLogBufferPages) {
1056 return binder::Status::fromServiceSpecificError(error);
1057 }
1058 }
1059 // unreachable, but makes the compiler happy
Yurii Zubrytskyifc7b6692020-04-22 23:23:24 -07001060 return Ok();
Alex Buynytskyy91e0bf42020-03-31 14:46:25 -07001061}
1062
Songchun Fanab55cec2019-12-02 10:50:12 -08001063binder::Status VoldNativeService::bindMount(const std::string& sourceDir,
1064 const std::string& targetDir) {
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -07001065 ENFORCE_SYSTEM_OR_ROOT;
Yurii Zubrytskyi18eb8772021-10-18 22:33:15 -07001066 if (auto status = CheckIncrementalPath(IncrementalPathKind::Any, sourceDir); !status.isOk()) {
1067 return status;
1068 }
1069 if (auto status = CheckIncrementalPath(IncrementalPathKind::Bind, targetDir); !status.isOk()) {
1070 return status;
1071 }
Yurii Zubrytskyi131365a2020-03-24 23:49:02 -07001072
Yurii Zubrytskyi18eb8772021-10-18 22:33:15 -07001073 auto [sourceFd, sourceSymlink] = OpenDirInProcfs(sourceDir);
1074 if (!sourceFd.ok()) {
1075 return translate(-errno);
1076 }
1077 auto [targetFd, targetSymlink] = OpenDirInProcfs(targetDir);
1078 if (!targetFd.ok()) {
1079 return translate(-errno);
1080 }
1081 return translate(incfs::bindMount(sourceSymlink, targetSymlink));
Songchun Fanab55cec2019-12-02 10:50:12 -08001082}
1083
Yo Chiang0af25a32020-10-07 14:20:00 +08001084binder::Status VoldNativeService::destroyDsuMetadataKey(const std::string& dsuSlot) {
1085 ENFORCE_SYSTEM_OR_ROOT;
1086 ACQUIRE_LOCK;
1087
1088 return translateBool(destroy_dsu_metadata_key(dsuSlot));
1089}
1090
Jeff Sharkey068c6be2017-09-06 13:47:40 -06001091} // namespace vold
1092} // namespace android