Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 1 | /* |
| 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 Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_PACKAGE_MANAGER |
| 18 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 19 | #include "VoldNativeService.h" |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 20 | |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 21 | #include <android-base/logging.h> |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 22 | #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 Park | 0bccae2 | 2021-10-13 16:50:10 -0700 | [diff] [blame] | 28 | #include <stdio.h> |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 29 | #include <fstream> |
| 30 | #include <thread> |
| 31 | |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 32 | #include "Benchmark.h" |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 33 | #include "Checkpoint.h" |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 34 | #include "FsCrypt.h" |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 35 | #include "IdleMaint.h" |
Seth Moore | 5a43d61 | 2021-01-19 17:51:51 +0000 | [diff] [blame] | 36 | #include "KeyStorage.h" |
Eric Biggers | d86a8ab | 2021-06-15 11:34:00 -0700 | [diff] [blame] | 37 | #include "Keystore.h" |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 38 | #include "MetadataCrypt.h" |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 39 | #include "MoveStorage.h" |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 40 | #include "VoldNativeServiceValidation.h" |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 41 | #include "VoldUtil.h" |
| 42 | #include "VolumeManager.h" |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 43 | #include "cryptfs.h" |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 44 | #include "incfs.h" |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 45 | |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 46 | using namespace std::literals; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 47 | |
| 48 | namespace android { |
| 49 | namespace vold { |
| 50 | |
| 51 | namespace { |
| 52 | |
| 53 | constexpr const char* kDump = "android.permission.DUMP"; |
Alex Buynytskyy | dcfeaa1 | 2021-04-01 13:43:14 -0700 | [diff] [blame] | 54 | constexpr auto kIncFsReadNoTimeoutMs = 100; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 55 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 56 | static binder::Status error(const std::string& msg) { |
| 57 | PLOG(ERROR) << msg; |
| 58 | return binder::Status::fromServiceSpecificError(errno, String8(msg.c_str())); |
| 59 | } |
| 60 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 61 | static binder::Status translate(int status) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 62 | if (status == 0) { |
| 63 | return binder::Status::ok(); |
| 64 | } else { |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 65 | return binder::Status::fromServiceSpecificError(status); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 69 | static 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 Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 77 | #define ENFORCE_SYSTEM_OR_ROOT \ |
| 78 | { \ |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 79 | binder::Status status = CheckUidOrRoot(AID_SYSTEM); \ |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 80 | if (!status.isOk()) { \ |
| 81 | return status; \ |
| 82 | } \ |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 83 | } |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 84 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 85 | #define CHECK_ARGUMENT_ID(id) \ |
| 86 | { \ |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 87 | binder::Status status = CheckArgumentId((id)); \ |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 88 | if (!status.isOk()) { \ |
| 89 | return status; \ |
| 90 | } \ |
| 91 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 92 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 93 | #define CHECK_ARGUMENT_PATH(path) \ |
| 94 | { \ |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 95 | binder::Status status = CheckArgumentPath((path)); \ |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 96 | if (!status.isOk()) { \ |
| 97 | return status; \ |
| 98 | } \ |
| 99 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 100 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 101 | #define CHECK_ARGUMENT_HEX(hex) \ |
| 102 | { \ |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 103 | binder::Status status = CheckArgumentHex((hex)); \ |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 104 | if (!status.isOk()) { \ |
| 105 | return status; \ |
| 106 | } \ |
| 107 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 108 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 109 | #define ACQUIRE_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 110 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \ |
| 111 | ATRACE_CALL(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 112 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 113 | #define ACQUIRE_CRYPT_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 114 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \ |
| 115 | ATRACE_CALL(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 116 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 117 | } // namespace |
| 118 | |
| 119 | status_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 Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 131 | status_t VoldNativeService::dump(int fd, const Vector<String16>& /* args */) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 132 | const binder::Status dump_permission = CheckPermission(kDump); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 133 | if (!dump_permission.isOk()) { |
Keun young Park | 0bccae2 | 2021-10-13 16:50:10 -0700 | [diff] [blame] | 134 | dprintf(fd, "%s\n", dump_permission.toString8().c_str()); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 135 | return PERMISSION_DENIED; |
| 136 | } |
| 137 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 138 | ACQUIRE_LOCK; |
Keun young Park | 0bccae2 | 2021-10-13 16:50:10 -0700 | [diff] [blame] | 139 | dprintf(fd, "vold is happy!\n"); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 140 | return NO_ERROR; |
| 141 | } |
| 142 | |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 143 | binder::Status VoldNativeService::setListener( |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 144 | const android::sp<android::os::IVoldListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 145 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 146 | ACQUIRE_LOCK; |
| 147 | |
| 148 | VolumeManager::Instance()->setListener(listener); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 149 | return Ok(); |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 150 | } |
| 151 | |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 152 | binder::Status VoldNativeService::monitor() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 153 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 154 | |
| 155 | // Simply acquire/release each lock for watchdog |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 156 | { ACQUIRE_LOCK; } |
| 157 | { ACQUIRE_CRYPT_LOCK; } |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 158 | |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 159 | return Ok(); |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 160 | } |
| 161 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 162 | binder::Status VoldNativeService::reset() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 163 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 164 | ACQUIRE_LOCK; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 165 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 166 | return translate(VolumeManager::Instance()->reset()); |
| 167 | } |
| 168 | |
| 169 | binder::Status VoldNativeService::shutdown() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 170 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 171 | ACQUIRE_LOCK; |
| 172 | |
| 173 | return translate(VolumeManager::Instance()->shutdown()); |
| 174 | } |
| 175 | |
Martijn Coenen | 23c0445 | 2020-04-29 07:49:41 +0200 | [diff] [blame] | 176 | binder::Status VoldNativeService::abortFuse() { |
| 177 | ENFORCE_SYSTEM_OR_ROOT; |
lijiazi | ffe7622 | 2021-03-17 16:51:16 +0800 | [diff] [blame] | 178 | // 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 Coenen | 23c0445 | 2020-04-29 07:49:41 +0200 | [diff] [blame] | 181 | |
| 182 | return translate(VolumeManager::Instance()->abortFuse()); |
| 183 | } |
| 184 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 185 | binder::Status VoldNativeService::onUserAdded(int32_t userId, int32_t userSerial) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 186 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 187 | ACQUIRE_LOCK; |
| 188 | |
| 189 | return translate(VolumeManager::Instance()->onUserAdded(userId, userSerial)); |
| 190 | } |
| 191 | |
| 192 | binder::Status VoldNativeService::onUserRemoved(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 193 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 194 | ACQUIRE_LOCK; |
| 195 | |
| 196 | return translate(VolumeManager::Instance()->onUserRemoved(userId)); |
| 197 | } |
| 198 | |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 199 | binder::Status VoldNativeService::onUserStarted(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 200 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 201 | ACQUIRE_LOCK; |
| 202 | |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 203 | return translate(VolumeManager::Instance()->onUserStarted(userId)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | binder::Status VoldNativeService::onUserStopped(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 207 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 208 | ACQUIRE_LOCK; |
| 209 | |
| 210 | return translate(VolumeManager::Instance()->onUserStopped(userId)); |
| 211 | } |
| 212 | |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 213 | binder::Status VoldNativeService::addAppIds(const std::vector<std::string>& packageNames, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 214 | const std::vector<int32_t>& appIds) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 215 | return Ok(); |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 218 | binder::Status VoldNativeService::addSandboxIds(const std::vector<int32_t>& appIds, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 219 | const std::vector<std::string>& sandboxIds) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 220 | return Ok(); |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Jeff Sharkey | 401b260 | 2017-12-14 22:15:20 -0700 | [diff] [blame] | 223 | binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 224 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 401b260 | 2017-12-14 22:15:20 -0700 | [diff] [blame] | 225 | ACQUIRE_LOCK; |
| 226 | |
| 227 | return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing)); |
| 228 | } |
| 229 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 230 | binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 231 | int32_t ratio) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 232 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 233 | CHECK_ARGUMENT_ID(diskId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 234 | 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 Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 241 | 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 Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 252 | binder::Status VoldNativeService::forgetPartition(const std::string& partGuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 253 | const std::string& fsUuid) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 254 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 255 | CHECK_ARGUMENT_HEX(partGuid); |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 256 | CHECK_ARGUMENT_HEX(fsUuid); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 257 | ACQUIRE_LOCK; |
| 258 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 259 | return translate(VolumeManager::Instance()->forgetPartition(partGuid, fsUuid)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 260 | } |
| 261 | |
Zim | 5048b4b | 2019-11-19 09:16:03 +0000 | [diff] [blame] | 262 | binder::Status VoldNativeService::mount( |
| 263 | const std::string& volId, int32_t mountFlags, int32_t mountUserId, |
| 264 | const android::sp<android::os::IVoldMountCallback>& callback) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 265 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 266 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 267 | 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 | |
Zim | 5048b4b | 2019-11-19 09:16:03 +0000 | [diff] [blame] | 277 | vol->setMountCallback(callback); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 278 | int res = vol->mount(); |
Zim | 5048b4b | 2019-11-19 09:16:03 +0000 | [diff] [blame] | 279 | vol->setMountCallback(nullptr); |
| 280 | |
Sudheer Shanka | 40ab674 | 2018-09-18 13:07:45 -0700 | [diff] [blame] | 281 | if (res != OK) { |
| 282 | return translate(res); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 283 | } |
Zim | 3623a21 | 2019-07-19 16:46:53 +0100 | [diff] [blame] | 284 | |
Sudheer Shanka | 40ab674 | 2018-09-18 13:07:45 -0700 | [diff] [blame] | 285 | return translate(OK); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | binder::Status VoldNativeService::unmount(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 289 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 290 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 291 | 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 | |
| 300 | binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 301 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 302 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 303 | 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 Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 312 | static binder::Status pathForVolId(const std::string& volId, std::string* path) { |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 313 | if (volId == "private" || volId == "null") { |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 314 | *path = "/data"; |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 315 | } 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 Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 326 | *path = vol->getPath(); |
| 327 | if (path->empty()) { |
| 328 | return error("Volume " + volId + " missing path"); |
| 329 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 330 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 331 | return Ok(); |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 332 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 333 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 334 | binder::Status VoldNativeService::benchmark( |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 335 | const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 336 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 337 | 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 Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 343 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 344 | std::thread([=]() { android::vold::Benchmark(path, listener); }).detach(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 345 | return Ok(); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 346 | } |
| 347 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 348 | binder::Status VoldNativeService::moveStorage( |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 349 | const std::string& fromVolId, const std::string& toVolId, |
| 350 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 351 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 352 | CHECK_ARGUMENT_ID(fromVolId); |
| 353 | CHECK_ARGUMENT_ID(toVolId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 354 | 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 Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 363 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 364 | std::thread([=]() { android::vold::MoveStorage(fromVol, toVol, listener); }).detach(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 365 | return Ok(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 369 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 370 | ACQUIRE_LOCK; |
| 371 | |
Sudheer Shanka | 817b911 | 2018-12-13 17:40:28 -0800 | [diff] [blame] | 372 | return translate(VolumeManager::Instance()->remountUid(uid, remountMode)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 373 | } |
| 374 | |
Ricky Wai | 6b12257 | 2020-02-28 16:30:47 +0000 | [diff] [blame] | 375 | binder::Status VoldNativeService::remountAppStorageDirs(int uid, int pid, |
| 376 | const std::vector<std::string>& packageNames) { |
| 377 | ENFORCE_SYSTEM_OR_ROOT; |
| 378 | ACQUIRE_LOCK; |
| 379 | |
Ricky Wai | a2ca11e | 2021-01-15 14:03:23 +0000 | [diff] [blame] | 380 | return translate(VolumeManager::Instance()->handleAppStorageDirs(uid, pid, |
| 381 | false /* doUnmount */, packageNames)); |
| 382 | } |
| 383 | |
| 384 | binder::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 Wai | 6b12257 | 2020-02-28 16:30:47 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Martijn Coenen | 8a68a07 | 2020-02-12 15:29:02 +0100 | [diff] [blame] | 393 | binder::Status VoldNativeService::setupAppDir(const std::string& path, int32_t appUid) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 394 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 395 | CHECK_ARGUMENT_PATH(path); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 396 | ACQUIRE_LOCK; |
| 397 | |
Martijn Coenen | 8a68a07 | 2020-02-12 15:29:02 +0100 | [diff] [blame] | 398 | return translate(VolumeManager::Instance()->setupAppDir(path, appUid)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 399 | } |
| 400 | |
Ricky Wai | bbfb6ea | 2020-12-03 15:32:52 +0000 | [diff] [blame] | 401 | binder::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 Coenen | 816f4d9 | 2020-02-18 15:06:37 +0100 | [diff] [blame] | 409 | binder::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 Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 417 | binder::Status VoldNativeService::createObb(const std::string& sourcePath, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 418 | const std::string& sourceKey, int32_t ownerGid, |
| 419 | std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 420 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 421 | CHECK_ARGUMENT_PATH(sourcePath); |
| 422 | CHECK_ARGUMENT_HEX(sourceKey); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 423 | ACQUIRE_LOCK; |
| 424 | |
| 425 | return translate( |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 426 | VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return)); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | binder::Status VoldNativeService::destroyObb(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 430 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 431 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 432 | ACQUIRE_LOCK; |
| 433 | |
| 434 | return translate(VolumeManager::Instance()->destroyObb(volId)); |
| 435 | } |
| 436 | |
Risan | 82e90de | 2020-02-04 16:07:21 +0900 | [diff] [blame] | 437 | binder::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 Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 443 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 444 | 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 | |
Risan | 82e90de | 2020-02-04 16:07:21 +0900 | [diff] [blame] | 451 | return translate(VolumeManager::Instance()->createStubVolume( |
| 452 | sourcePath, mountPath, fsType, fsUuid, fsLabel, flags, _aidl_return)); |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | binder::Status VoldNativeService::destroyStubVolume(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 456 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 457 | CHECK_ARGUMENT_ID(volId); |
| 458 | ACQUIRE_LOCK; |
| 459 | |
| 460 | return translate(VolumeManager::Instance()->destroyStubVolume(volId)); |
| 461 | } |
| 462 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 463 | binder::Status VoldNativeService::fstrim( |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 464 | int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 465 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 466 | ACQUIRE_LOCK; |
| 467 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 468 | std::thread([=]() { android::vold::Trim(listener); }).detach(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 469 | return Ok(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 470 | } |
| 471 | |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 472 | binder::Status VoldNativeService::runIdleMaint( |
Daeho Jeong | 999fceb | 2022-01-04 11:37:39 -0800 | [diff] [blame] | 473 | bool needGC, const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 474 | ENFORCE_SYSTEM_OR_ROOT; |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 475 | ACQUIRE_LOCK; |
| 476 | |
Daeho Jeong | 999fceb | 2022-01-04 11:37:39 -0800 | [diff] [blame] | 477 | std::thread([=]() { android::vold::RunIdleMaint(needGC, listener); }).detach(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 478 | return Ok(); |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | binder::Status VoldNativeService::abortIdleMaint( |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 482 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 483 | ENFORCE_SYSTEM_OR_ROOT; |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 484 | ACQUIRE_LOCK; |
| 485 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 486 | std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 487 | return Ok(); |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Daeho Jeong | 999fceb | 2022-01-04 11:37:39 -0800 | [diff] [blame] | 490 | binder::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 | |
| 498 | binder::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 | |
| 508 | binder::Status VoldNativeService::refreshLatestWrite() { |
| 509 | ENFORCE_SYSTEM_OR_ROOT; |
| 510 | ACQUIRE_LOCK; |
| 511 | |
| 512 | RefreshLatestWrite(); |
| 513 | return Ok(); |
| 514 | } |
| 515 | |
| 516 | binder::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 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 524 | binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t mountId, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 525 | android::base::unique_fd* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 526 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 527 | ACQUIRE_LOCK; |
| 528 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 529 | return translate(VolumeManager::Instance()->mountAppFuse(uid, mountId, _aidl_return)); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 530 | } |
| 531 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 532 | binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t mountId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 533 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 534 | ACQUIRE_LOCK; |
| 535 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 536 | return translate(VolumeManager::Instance()->unmountAppFuse(uid, mountId)); |
| 537 | } |
| 538 | |
| 539 | binder::Status VoldNativeService::openAppFuseFile(int32_t uid, int32_t mountId, int32_t fileId, |
| 540 | int32_t flags, |
| 541 | android::base::unique_fd* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 542 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 543 | 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 Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 553 | return Ok(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 554 | } |
| 555 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 556 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 557 | binder::Status VoldNativeService::fdeCheckPassword(const std::string& password) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 558 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 559 | ACQUIRE_CRYPT_LOCK; |
| 560 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 561 | SLOGE("fdeCheckPassword is no longer supported"); |
| 562 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 563 | } |
| 564 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 565 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 566 | binder::Status VoldNativeService::fdeRestart() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 567 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 568 | ACQUIRE_CRYPT_LOCK; |
| 569 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 570 | SLOGE("fdeRestart is no longer supported"); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 571 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 572 | } |
| 573 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 574 | // TODO(b/191796797) remove this once caller is removed |
| 575 | #define CRYPTO_COMPLETE_NOT_ENCRYPTED 1 |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 576 | binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 577 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 578 | ACQUIRE_CRYPT_LOCK; |
| 579 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 580 | SLOGE("fdeComplete is no longer supported"); |
| 581 | *_aidl_return = CRYPTO_COMPLETE_NOT_ENCRYPTED; |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 582 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 583 | } |
| 584 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 585 | // TODO(b/191796797) remove this once caller is removed |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 586 | binder::Status VoldNativeService::fdeEnable(int32_t passwordType, const std::string& password, |
| 587 | int32_t encryptionFlags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 588 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 589 | ACQUIRE_CRYPT_LOCK; |
| 590 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 591 | SLOGE("fdeEnable is no longer supported"); |
| 592 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 593 | } |
| 594 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 595 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 596 | binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 597 | const std::string& password) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 598 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 599 | ACQUIRE_CRYPT_LOCK; |
| 600 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 601 | SLOGE("fdeChangePassword is no longer supported"); |
| 602 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 603 | } |
| 604 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 605 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 606 | binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 607 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 608 | ACQUIRE_CRYPT_LOCK; |
| 609 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 610 | SLOGE("fdeVerifyPassword is no longer supported"); |
| 611 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 612 | } |
| 613 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 614 | // TODO(b/191796797) remove this once caller is removed |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 615 | binder::Status VoldNativeService::fdeGetField(const std::string& key, std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 616 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 617 | ACQUIRE_CRYPT_LOCK; |
| 618 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 619 | SLOGE("fdeGetField is no longer supported"); |
| 620 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 621 | } |
| 622 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 623 | // TODO(b/191796797) remove this once caller is removed |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 624 | binder::Status VoldNativeService::fdeSetField(const std::string& key, const std::string& value) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 625 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 626 | ACQUIRE_CRYPT_LOCK; |
| 627 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 628 | SLOGE("fdeSetField is no longer supported"); |
| 629 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 630 | } |
| 631 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 632 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 633 | binder::Status VoldNativeService::fdeGetPasswordType(int32_t* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 634 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 635 | ACQUIRE_CRYPT_LOCK; |
| 636 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 637 | SLOGE("fdeGetPasswordType is no longer supported"); |
| 638 | *_aidl_return = -1; |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 639 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 640 | } |
| 641 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 642 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 643 | binder::Status VoldNativeService::fdeGetPassword(std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 644 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 645 | ACQUIRE_CRYPT_LOCK; |
| 646 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 647 | SLOGE("fdeGetPassword is no longer supported"); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 648 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 649 | } |
| 650 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 651 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 652 | binder::Status VoldNativeService::fdeClearPassword() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 653 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 654 | ACQUIRE_CRYPT_LOCK; |
| 655 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 656 | SLOGE("fdeClearPassword is no longer supported"); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 657 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | binder::Status VoldNativeService::fbeEnable() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 661 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 662 | ACQUIRE_CRYPT_LOCK; |
| 663 | |
Paul Crowley | c8a3ef3 | 2019-09-11 15:00:08 -0700 | [diff] [blame] | 664 | return translateBool(fscrypt_initialize_systemwide_keys()); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 665 | } |
| 666 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 667 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 668 | binder::Status VoldNativeService::mountDefaultEncrypted() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 669 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 670 | ACQUIRE_CRYPT_LOCK; |
| 671 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 672 | SLOGE("mountDefaultEncrypted is no longer supported"); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 673 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | binder::Status VoldNativeService::initUser0() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 677 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 678 | ACQUIRE_CRYPT_LOCK; |
| 679 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 680 | return translateBool(fscrypt_init_user0()); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 681 | } |
| 682 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 683 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 684 | binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 685 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 686 | ACQUIRE_CRYPT_LOCK; |
| 687 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 688 | SLOGE("isConvertibleToFbe is no longer supported"); |
| 689 | *_aidl_return = false; |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 690 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 691 | } |
| 692 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 693 | binder::Status VoldNativeService::mountFstab(const std::string& blkDevice, |
| 694 | const std::string& mountPoint) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 695 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 696 | ACQUIRE_LOCK; |
| 697 | |
Jaegeuk Kim | 0c52c71 | 2020-12-15 09:00:49 -0800 | [diff] [blame] | 698 | return translateBool( |
| 699 | fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, false, false, "null")); |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 700 | } |
| 701 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 702 | binder::Status VoldNativeService::encryptFstab(const std::string& blkDevice, |
Jaegeuk Kim | 0c52c71 | 2020-12-15 09:00:49 -0800 | [diff] [blame] | 703 | const std::string& mountPoint, bool shouldFormat, |
| 704 | const std::string& fsType) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 705 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 706 | ACQUIRE_LOCK; |
| 707 | |
Jaegeuk Kim | 0c52c71 | 2020-12-15 09:00:49 -0800 | [diff] [blame] | 708 | return translateBool( |
| 709 | fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, true, shouldFormat, fsType)); |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 710 | } |
| 711 | |
Seth Moore | 5a43d61 | 2021-01-19 17:51:51 +0000 | [diff] [blame] | 712 | binder::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 Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 719 | binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, |
| 720 | bool ephemeral) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 721 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 722 | ACQUIRE_CRYPT_LOCK; |
| 723 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 724 | return translateBool(fscrypt_vold_create_user_key(userId, userSerial, ephemeral)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | binder::Status VoldNativeService::destroyUserKey(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 728 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 729 | ACQUIRE_CRYPT_LOCK; |
| 730 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 731 | return translateBool(fscrypt_destroy_user_key(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 732 | } |
| 733 | |
Satya Tangirala | e136171 | 2021-03-15 15:33:08 -0700 | [diff] [blame] | 734 | static bool token_empty(const std::string& token) { |
| 735 | return token.size() == 0 || token == "!"; |
| 736 | } |
| 737 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 738 | binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 739 | const std::string& token, |
| 740 | const std::string& secret) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 741 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 742 | ACQUIRE_CRYPT_LOCK; |
| 743 | |
Satya Tangirala | e136171 | 2021-03-15 15:33:08 -0700 | [diff] [blame] | 744 | 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 Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 750 | } |
| 751 | |
Barani Muthukumaran | 9ad51ad | 2019-10-31 22:59:34 -0700 | [diff] [blame] | 752 | binder::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 Tangirala | e136171 | 2021-03-15 15:33:08 -0700 | [diff] [blame] | 758 | 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 Muthukumaran | 9ad51ad | 2019-10-31 22:59:34 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 767 | binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 768 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 769 | ACQUIRE_CRYPT_LOCK; |
| 770 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 771 | return translateBool(fscrypt_fixate_newest_user_key_auth(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 772 | } |
| 773 | |
Eric Biggers | 1799deb | 2021-04-06 12:02:56 -0700 | [diff] [blame] | 774 | binder::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 Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 782 | binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 783 | const std::string& token, |
| 784 | const std::string& secret) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 785 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 786 | ACQUIRE_CRYPT_LOCK; |
| 787 | |
Satya Tangirala | e136171 | 2021-03-15 15:33:08 -0700 | [diff] [blame] | 788 | 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 Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | binder::Status VoldNativeService::lockUserKey(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 797 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 798 | ACQUIRE_CRYPT_LOCK; |
| 799 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 800 | return translateBool(fscrypt_lock_user_key(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 801 | } |
| 802 | |
Jooyung Han | 4fcb707 | 2020-01-23 13:23:26 +0900 | [diff] [blame] | 803 | binder::Status VoldNativeService::prepareUserStorage(const std::optional<std::string>& uuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 804 | int32_t userId, int32_t userSerial, |
| 805 | int32_t flags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 806 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 807 | std::string empty_string = ""; |
| 808 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 809 | CHECK_ARGUMENT_HEX(uuid_); |
| 810 | |
| 811 | ACQUIRE_CRYPT_LOCK; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 812 | return translateBool(fscrypt_prepare_user_storage(uuid_, userId, userSerial, flags)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 813 | } |
| 814 | |
Jooyung Han | 4fcb707 | 2020-01-23 13:23:26 +0900 | [diff] [blame] | 815 | binder::Status VoldNativeService::destroyUserStorage(const std::optional<std::string>& uuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 816 | int32_t userId, int32_t flags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 817 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 818 | std::string empty_string = ""; |
| 819 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 820 | CHECK_ARGUMENT_HEX(uuid_); |
| 821 | |
| 822 | ACQUIRE_CRYPT_LOCK; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 823 | return translateBool(fscrypt_destroy_user_storage(uuid_, userId, flags)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 824 | } |
| 825 | |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 826 | binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packageName, |
| 827 | int32_t appId, const std::string& sandboxId, |
| 828 | int32_t userId) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 829 | return Ok(); |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName, |
Sudheer Shanka | 69bc40f | 2018-10-25 11:06:55 -0700 | [diff] [blame] | 833 | const std::string& sandboxId, |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 834 | int32_t userId) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 835 | return Ok(); |
Sudheer Shanka | c756209 | 2018-08-24 10:20:56 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 838 | binder::Status VoldNativeService::startCheckpoint(int32_t retry) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 839 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 840 | ACQUIRE_LOCK; |
| 841 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 842 | return cp_startCheckpoint(retry); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 845 | binder::Status VoldNativeService::needsRollback(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 846 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 847 | ACQUIRE_LOCK; |
| 848 | |
| 849 | *_aidl_return = cp_needsRollback(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 850 | return Ok(); |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 851 | } |
| 852 | |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 853 | binder::Status VoldNativeService::needsCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 854 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 855 | ACQUIRE_LOCK; |
| 856 | |
| 857 | *_aidl_return = cp_needsCheckpoint(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 858 | return Ok(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 859 | } |
| 860 | |
David Anderson | 23850d3 | 2020-06-10 23:51:17 -0700 | [diff] [blame] | 861 | binder::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 Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 869 | binder::Status VoldNativeService::commitChanges() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 870 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 871 | ACQUIRE_LOCK; |
| 872 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 873 | return cp_commitChanges(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 876 | binder::Status VoldNativeService::prepareCheckpoint() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 877 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 878 | ACQUIRE_LOCK; |
| 879 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 880 | return cp_prepareCheckpoint(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 881 | } |
| 882 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 883 | binder::Status VoldNativeService::restoreCheckpoint(const std::string& mountPoint) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 884 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | 1abb2fe | 2018-09-21 10:49:57 -0700 | [diff] [blame] | 885 | CHECK_ARGUMENT_PATH(mountPoint); |
| 886 | ACQUIRE_LOCK; |
| 887 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 888 | return cp_restoreCheckpoint(mountPoint); |
Paul Lawrence | 1abb2fe | 2018-09-21 10:49:57 -0700 | [diff] [blame] | 889 | } |
| 890 | |
Daniel Rosenberg | dda5981 | 2019-03-06 17:45:17 -0800 | [diff] [blame] | 891 | binder::Status VoldNativeService::restoreCheckpointPart(const std::string& mountPoint, int count) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 892 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | dda5981 | 2019-03-06 17:45:17 -0800 | [diff] [blame] | 893 | CHECK_ARGUMENT_PATH(mountPoint); |
| 894 | ACQUIRE_LOCK; |
| 895 | |
| 896 | return cp_restoreCheckpoint(mountPoint, count); |
| 897 | } |
| 898 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 899 | binder::Status VoldNativeService::markBootAttempt() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 900 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 901 | ACQUIRE_LOCK; |
| 902 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 903 | return cp_markBootAttempt(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 904 | } |
| 905 | |
Daniel Rosenberg | a59e439 | 2019-03-20 17:02:47 -0700 | [diff] [blame] | 906 | binder::Status VoldNativeService::abortChanges(const std::string& message, bool retry) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 907 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 908 | ACQUIRE_LOCK; |
| 909 | |
Daniel Rosenberg | a59e439 | 2019-03-20 17:02:47 -0700 | [diff] [blame] | 910 | cp_abortChanges(message, retry); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 911 | return Ok(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Daniel Rosenberg | 9b667fb | 2019-01-22 17:27:25 -0800 | [diff] [blame] | 914 | binder::Status VoldNativeService::supportsCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 915 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 9b667fb | 2019-01-22 17:27:25 -0800 | [diff] [blame] | 916 | ACQUIRE_LOCK; |
| 917 | |
| 918 | return cp_supportsCheckpoint(*_aidl_return); |
| 919 | } |
| 920 | |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 921 | binder::Status VoldNativeService::supportsBlockCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 922 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 923 | ACQUIRE_LOCK; |
| 924 | |
| 925 | return cp_supportsBlockCheckpoint(*_aidl_return); |
| 926 | } |
| 927 | |
| 928 | binder::Status VoldNativeService::supportsFileCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 929 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 930 | ACQUIRE_LOCK; |
| 931 | |
| 932 | return cp_supportsFileCheckpoint(*_aidl_return); |
| 933 | } |
| 934 | |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 935 | binder::Status VoldNativeService::resetCheckpoint() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 936 | ENFORCE_SYSTEM_OR_ROOT; |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 937 | ACQUIRE_LOCK; |
| 938 | |
| 939 | cp_resetCheckpoint(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 940 | return Ok(); |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 941 | } |
| 942 | |
Alex Buynytskyy | b02e7b6 | 2021-02-11 19:09:10 -0800 | [diff] [blame] | 943 | static void initializeIncFs() { |
| 944 | // Obtaining IncFS features triggers initialization of IncFS. |
| 945 | incfs::features(); |
| 946 | } |
| 947 | |
Martijn Coenen | eed957f | 2020-11-12 10:59:13 +0100 | [diff] [blame] | 948 | binder::Status VoldNativeService::earlyBootEnded() { |
| 949 | ENFORCE_SYSTEM_OR_ROOT; |
| 950 | ACQUIRE_LOCK; |
| 951 | |
Alex Buynytskyy | b02e7b6 | 2021-02-11 19:09:10 -0800 | [diff] [blame] | 952 | initializeIncFs(); |
Eric Biggers | d86a8ab | 2021-06-15 11:34:00 -0700 | [diff] [blame] | 953 | Keystore::earlyBootEnded(); |
Martijn Coenen | eed957f | 2020-11-12 10:59:13 +0100 | [diff] [blame] | 954 | return Ok(); |
| 955 | } |
| 956 | |
Yurii Zubrytskyi | 3497cb5 | 2020-01-10 11:54:06 -0800 | [diff] [blame] | 957 | binder::Status VoldNativeService::incFsEnabled(bool* _aidl_return) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 958 | ENFORCE_SYSTEM_OR_ROOT; |
| 959 | |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 960 | *_aidl_return = incfs::enabled(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 961 | return Ok(); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | binder::Status VoldNativeService::mountIncFs( |
Yurii Zubrytskyi | 3497cb5 | 2020-01-10 11:54:06 -0800 | [diff] [blame] | 965 | const std::string& backingPath, const std::string& targetDir, int32_t flags, |
Songchun Fan | 046e68a | 2021-04-27 12:46:02 -0700 | [diff] [blame] | 966 | const std::string& sysfsName, |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 967 | ::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 968 | ENFORCE_SYSTEM_OR_ROOT; |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame^] | 969 | 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 Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 977 | |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame^] | 978 | 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 Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 988 | {.flags = IncFsMountFlags(flags), |
Alex Buynytskyy | dcfeaa1 | 2021-04-01 13:43:14 -0700 | [diff] [blame] | 989 | // Mount with read timeouts. |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 990 | .defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS, |
| 991 | // Mount with read logs disabled. |
Songchun Fan | 046e68a | 2021-04-27 12:46:02 -0700 | [diff] [blame] | 992 | .readLogBufferPages = 0, |
| 993 | .sysfsName = sysfsName.c_str()}); |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 994 | if (!control) { |
| 995 | return translate(-errno); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 996 | } |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 997 | 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 Zubrytskyi | 0c0f839 | 2020-12-08 07:33:37 -0800 | [diff] [blame] | 1002 | if (fds[BLOCKS_WRITTEN].ok()) { |
| 1003 | _aidl_return->blocksWritten.emplace(unique_fd(fds[BLOCKS_WRITTEN].release())); |
| 1004 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 1005 | return Ok(); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | binder::Status VoldNativeService::unmountIncFs(const std::string& dir) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 1009 | ENFORCE_SYSTEM_OR_ROOT; |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame^] | 1010 | if (auto status = CheckIncrementalPath(IncrementalPathKind::Any, dir); !status.isOk()) { |
| 1011 | return status; |
| 1012 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 1013 | |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame^] | 1014 | auto [fd, symLink] = OpenDirInProcfs(dir); |
| 1015 | if (!fd.ok()) { |
| 1016 | return translate(-errno); |
| 1017 | } |
| 1018 | return translate(incfs::unmount(symLink)); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 1019 | } |
| 1020 | |
Alex Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 1021 | binder::Status VoldNativeService::setIncFsMountOptions( |
| 1022 | const ::android::os::incremental::IncrementalFileSystemControlParcel& control, |
Songchun Fan | 0e53c1c | 2021-05-10 16:19:38 -0700 | [diff] [blame] | 1023 | bool enableReadLogs, bool enableReadTimeouts, const std::string& sysfsName) { |
Alex Buynytskyy | 605a44f | 2020-04-02 15:21:47 -0700 | [diff] [blame] | 1024 | ENFORCE_SYSTEM_OR_ROOT; |
Alex Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 1025 | |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 1026 | auto incfsControl = |
Yurii Zubrytskyi | 0c0f839 | 2020-12-08 07:33:37 -0800 | [diff] [blame] | 1027 | incfs::createControl(control.cmd.get(), control.pendingReads.get(), control.log.get(), |
| 1028 | control.blocksWritten ? control.blocksWritten->get() : -1); |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 1029 | 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 Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 1036 | |
Yurii Zubrytskyi | 1d7acfd | 2021-10-28 14:37:12 -0700 | [diff] [blame] | 1037 | 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 Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 1060 | return Ok(); |
Alex Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 1063 | binder::Status VoldNativeService::bindMount(const std::string& sourceDir, |
| 1064 | const std::string& targetDir) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 1065 | ENFORCE_SYSTEM_OR_ROOT; |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame^] | 1066 | 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 Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 1072 | |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame^] | 1073 | 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 Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 1082 | } |
| 1083 | |
Yo Chiang | 0af25a3 | 2020-10-07 14:20:00 +0800 | [diff] [blame] | 1084 | binder::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 Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 1091 | } // namespace vold |
| 1092 | } // namespace android |