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> |
Eric Biggers | 4859e0c | 2021-06-24 11:13:24 -0700 | [diff] [blame] | 29 | #include <sys/vfs.h> |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 30 | #include <fstream> |
| 31 | #include <thread> |
| 32 | |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 33 | #include "Benchmark.h" |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 34 | #include "Checkpoint.h" |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 35 | #include "FsCrypt.h" |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 36 | #include "IdleMaint.h" |
Seth Moore | 5a43d61 | 2021-01-19 17:51:51 +0000 | [diff] [blame] | 37 | #include "KeyStorage.h" |
Eric Biggers | d86a8ab | 2021-06-15 11:34:00 -0700 | [diff] [blame] | 38 | #include "Keystore.h" |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 39 | #include "MetadataCrypt.h" |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 40 | #include "MoveStorage.h" |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 41 | #include "VoldNativeServiceValidation.h" |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 42 | #include "VoldUtil.h" |
| 43 | #include "VolumeManager.h" |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 44 | #include "cryptfs.h" |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 45 | #include "incfs.h" |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 46 | |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 47 | using namespace std::literals; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 48 | |
| 49 | namespace android { |
| 50 | namespace vold { |
| 51 | |
| 52 | namespace { |
| 53 | |
| 54 | constexpr const char* kDump = "android.permission.DUMP"; |
Alex Buynytskyy | dcfeaa1 | 2021-04-01 13:43:14 -0700 | [diff] [blame] | 55 | constexpr auto kIncFsReadNoTimeoutMs = 100; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 56 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 57 | static binder::Status error(const std::string& msg) { |
| 58 | PLOG(ERROR) << msg; |
| 59 | return binder::Status::fromServiceSpecificError(errno, String8(msg.c_str())); |
| 60 | } |
| 61 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 62 | static binder::Status translate(int status) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 63 | if (status == 0) { |
| 64 | return binder::Status::ok(); |
| 65 | } else { |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 66 | return binder::Status::fromServiceSpecificError(status); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 70 | static binder::Status translateBool(bool status) { |
| 71 | if (status) { |
| 72 | return binder::Status::ok(); |
| 73 | } else { |
| 74 | return binder::Status::fromServiceSpecificError(status); |
| 75 | } |
| 76 | } |
| 77 | |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 78 | #define ENFORCE_SYSTEM_OR_ROOT \ |
| 79 | { \ |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 80 | binder::Status status = CheckUidOrRoot(AID_SYSTEM); \ |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 81 | if (!status.isOk()) { \ |
| 82 | return status; \ |
| 83 | } \ |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 84 | } |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 85 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 86 | #define CHECK_ARGUMENT_ID(id) \ |
| 87 | { \ |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 88 | binder::Status status = CheckArgumentId((id)); \ |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 89 | if (!status.isOk()) { \ |
| 90 | return status; \ |
| 91 | } \ |
| 92 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 93 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 94 | #define CHECK_ARGUMENT_PATH(path) \ |
| 95 | { \ |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 96 | binder::Status status = CheckArgumentPath((path)); \ |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 97 | if (!status.isOk()) { \ |
| 98 | return status; \ |
| 99 | } \ |
| 100 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 101 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 102 | #define CHECK_ARGUMENT_HEX(hex) \ |
| 103 | { \ |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 104 | binder::Status status = CheckArgumentHex((hex)); \ |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 105 | if (!status.isOk()) { \ |
| 106 | return status; \ |
| 107 | } \ |
| 108 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 109 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 110 | #define ACQUIRE_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 111 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \ |
| 112 | ATRACE_CALL(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 113 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 114 | #define ACQUIRE_CRYPT_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 115 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \ |
| 116 | ATRACE_CALL(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 117 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 118 | } // namespace |
| 119 | |
| 120 | status_t VoldNativeService::start() { |
| 121 | IPCThreadState::self()->disableBackgroundScheduling(true); |
| 122 | status_t ret = BinderService<VoldNativeService>::publish(); |
| 123 | if (ret != android::OK) { |
| 124 | return ret; |
| 125 | } |
| 126 | sp<ProcessState> ps(ProcessState::self()); |
| 127 | ps->startThreadPool(); |
| 128 | ps->giveThreadPoolName(); |
| 129 | return android::OK; |
| 130 | } |
| 131 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 132 | status_t VoldNativeService::dump(int fd, const Vector<String16>& /* args */) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 133 | const binder::Status dump_permission = CheckPermission(kDump); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 134 | if (!dump_permission.isOk()) { |
Keun young Park | 0bccae2 | 2021-10-13 16:50:10 -0700 | [diff] [blame] | 135 | dprintf(fd, "%s\n", dump_permission.toString8().c_str()); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 136 | return PERMISSION_DENIED; |
| 137 | } |
| 138 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 139 | ACQUIRE_LOCK; |
Keun young Park | 0bccae2 | 2021-10-13 16:50:10 -0700 | [diff] [blame] | 140 | dprintf(fd, "vold is happy!\n"); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 141 | return NO_ERROR; |
| 142 | } |
| 143 | |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 144 | binder::Status VoldNativeService::setListener( |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 145 | const android::sp<android::os::IVoldListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 146 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 147 | ACQUIRE_LOCK; |
| 148 | |
| 149 | VolumeManager::Instance()->setListener(listener); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 150 | return Ok(); |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 151 | } |
| 152 | |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 153 | binder::Status VoldNativeService::monitor() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 154 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 155 | |
| 156 | // Simply acquire/release each lock for watchdog |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 157 | { ACQUIRE_LOCK; } |
| 158 | { ACQUIRE_CRYPT_LOCK; } |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 159 | |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 160 | return Ok(); |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 161 | } |
| 162 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 163 | binder::Status VoldNativeService::reset() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 164 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 165 | ACQUIRE_LOCK; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 166 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 167 | return translate(VolumeManager::Instance()->reset()); |
| 168 | } |
| 169 | |
| 170 | binder::Status VoldNativeService::shutdown() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 171 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 172 | ACQUIRE_LOCK; |
| 173 | |
| 174 | return translate(VolumeManager::Instance()->shutdown()); |
| 175 | } |
| 176 | |
Martijn Coenen | 23c0445 | 2020-04-29 07:49:41 +0200 | [diff] [blame] | 177 | binder::Status VoldNativeService::abortFuse() { |
| 178 | ENFORCE_SYSTEM_OR_ROOT; |
lijiazi | ffe7622 | 2021-03-17 16:51:16 +0800 | [diff] [blame] | 179 | // if acquire lock, maybe lead to a deadlock if lock is held by a |
| 180 | // thread that is blocked on a FUSE operation. |
| 181 | // 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] | 182 | |
| 183 | return translate(VolumeManager::Instance()->abortFuse()); |
| 184 | } |
| 185 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 186 | binder::Status VoldNativeService::onUserAdded(int32_t userId, int32_t userSerial) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 187 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 188 | ACQUIRE_LOCK; |
| 189 | |
| 190 | return translate(VolumeManager::Instance()->onUserAdded(userId, userSerial)); |
| 191 | } |
| 192 | |
| 193 | binder::Status VoldNativeService::onUserRemoved(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 194 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 195 | ACQUIRE_LOCK; |
| 196 | |
| 197 | return translate(VolumeManager::Instance()->onUserRemoved(userId)); |
| 198 | } |
| 199 | |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 200 | binder::Status VoldNativeService::onUserStarted(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 201 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 202 | ACQUIRE_LOCK; |
| 203 | |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 204 | return translate(VolumeManager::Instance()->onUserStarted(userId)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | binder::Status VoldNativeService::onUserStopped(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 208 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 209 | ACQUIRE_LOCK; |
| 210 | |
| 211 | return translate(VolumeManager::Instance()->onUserStopped(userId)); |
| 212 | } |
| 213 | |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 214 | binder::Status VoldNativeService::addAppIds(const std::vector<std::string>& packageNames, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 215 | const std::vector<int32_t>& appIds) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 216 | return Ok(); |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 219 | binder::Status VoldNativeService::addSandboxIds(const std::vector<int32_t>& appIds, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 220 | const std::vector<std::string>& sandboxIds) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 221 | return Ok(); |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Jeff Sharkey | 401b260 | 2017-12-14 22:15:20 -0700 | [diff] [blame] | 224 | binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 225 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 401b260 | 2017-12-14 22:15:20 -0700 | [diff] [blame] | 226 | ACQUIRE_LOCK; |
| 227 | |
| 228 | return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing)); |
| 229 | } |
| 230 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 231 | binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 232 | int32_t ratio) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 233 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 234 | CHECK_ARGUMENT_ID(diskId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 235 | ACQUIRE_LOCK; |
| 236 | |
| 237 | auto disk = VolumeManager::Instance()->findDisk(diskId); |
| 238 | if (disk == nullptr) { |
| 239 | return error("Failed to find disk " + diskId); |
| 240 | } |
| 241 | switch (partitionType) { |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 242 | case PARTITION_TYPE_PUBLIC: |
| 243 | return translate(disk->partitionPublic()); |
| 244 | case PARTITION_TYPE_PRIVATE: |
| 245 | return translate(disk->partitionPrivate()); |
| 246 | case PARTITION_TYPE_MIXED: |
| 247 | return translate(disk->partitionMixed(ratio)); |
| 248 | default: |
| 249 | return error("Unknown type " + std::to_string(partitionType)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 253 | binder::Status VoldNativeService::forgetPartition(const std::string& partGuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 254 | const std::string& fsUuid) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 255 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 256 | CHECK_ARGUMENT_HEX(partGuid); |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 257 | CHECK_ARGUMENT_HEX(fsUuid); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 258 | ACQUIRE_LOCK; |
| 259 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 260 | return translate(VolumeManager::Instance()->forgetPartition(partGuid, fsUuid)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 261 | } |
| 262 | |
Zim | 5048b4b | 2019-11-19 09:16:03 +0000 | [diff] [blame] | 263 | binder::Status VoldNativeService::mount( |
| 264 | const std::string& volId, int32_t mountFlags, int32_t mountUserId, |
| 265 | const android::sp<android::os::IVoldMountCallback>& callback) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 266 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 267 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 268 | ACQUIRE_LOCK; |
| 269 | |
| 270 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 271 | if (vol == nullptr) { |
| 272 | return error("Failed to find volume " + volId); |
| 273 | } |
| 274 | |
| 275 | vol->setMountFlags(mountFlags); |
| 276 | vol->setMountUserId(mountUserId); |
| 277 | |
Zim | 5048b4b | 2019-11-19 09:16:03 +0000 | [diff] [blame] | 278 | vol->setMountCallback(callback); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 279 | int res = vol->mount(); |
Zim | 5048b4b | 2019-11-19 09:16:03 +0000 | [diff] [blame] | 280 | vol->setMountCallback(nullptr); |
| 281 | |
Sudheer Shanka | 40ab674 | 2018-09-18 13:07:45 -0700 | [diff] [blame] | 282 | if (res != OK) { |
| 283 | return translate(res); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 284 | } |
Zim | 3623a21 | 2019-07-19 16:46:53 +0100 | [diff] [blame] | 285 | |
Sudheer Shanka | 40ab674 | 2018-09-18 13:07:45 -0700 | [diff] [blame] | 286 | return translate(OK); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | binder::Status VoldNativeService::unmount(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 290 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 291 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 292 | ACQUIRE_LOCK; |
| 293 | |
| 294 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 295 | if (vol == nullptr) { |
| 296 | return error("Failed to find volume " + volId); |
| 297 | } |
| 298 | return translate(vol->unmount()); |
| 299 | } |
| 300 | |
| 301 | binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 302 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 303 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 304 | ACQUIRE_LOCK; |
| 305 | |
| 306 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 307 | if (vol == nullptr) { |
| 308 | return error("Failed to find volume " + volId); |
| 309 | } |
| 310 | return translate(vol->format(fsType)); |
| 311 | } |
| 312 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 313 | static binder::Status pathForVolId(const std::string& volId, std::string* path) { |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 314 | if (volId == "private" || volId == "null") { |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 315 | *path = "/data"; |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 316 | } else { |
| 317 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 318 | if (vol == nullptr) { |
| 319 | return error("Failed to find volume " + volId); |
| 320 | } |
| 321 | if (vol->getType() != VolumeBase::Type::kPrivate) { |
| 322 | return error("Volume " + volId + " not private"); |
| 323 | } |
| 324 | if (vol->getState() != VolumeBase::State::kMounted) { |
| 325 | return error("Volume " + volId + " not mounted"); |
| 326 | } |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 327 | *path = vol->getPath(); |
| 328 | if (path->empty()) { |
| 329 | return error("Volume " + volId + " missing path"); |
| 330 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 331 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 332 | return Ok(); |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 333 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 334 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 335 | binder::Status VoldNativeService::benchmark( |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 336 | const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 337 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 338 | CHECK_ARGUMENT_ID(volId); |
| 339 | ACQUIRE_LOCK; |
| 340 | |
| 341 | std::string path; |
| 342 | auto status = pathForVolId(volId, &path); |
| 343 | if (!status.isOk()) return status; |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 344 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 345 | std::thread([=]() { android::vold::Benchmark(path, listener); }).detach(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 346 | return Ok(); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 347 | } |
| 348 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 349 | binder::Status VoldNativeService::moveStorage( |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 350 | const std::string& fromVolId, const std::string& toVolId, |
| 351 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 352 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 353 | CHECK_ARGUMENT_ID(fromVolId); |
| 354 | CHECK_ARGUMENT_ID(toVolId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 355 | ACQUIRE_LOCK; |
| 356 | |
| 357 | auto fromVol = VolumeManager::Instance()->findVolume(fromVolId); |
| 358 | auto toVol = VolumeManager::Instance()->findVolume(toVolId); |
| 359 | if (fromVol == nullptr) { |
| 360 | return error("Failed to find volume " + fromVolId); |
| 361 | } else if (toVol == nullptr) { |
| 362 | return error("Failed to find volume " + toVolId); |
| 363 | } |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 364 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 365 | std::thread([=]() { android::vold::MoveStorage(fromVol, toVol, listener); }).detach(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 366 | return Ok(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 370 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 371 | ACQUIRE_LOCK; |
| 372 | |
Sudheer Shanka | 817b911 | 2018-12-13 17:40:28 -0800 | [diff] [blame] | 373 | return translate(VolumeManager::Instance()->remountUid(uid, remountMode)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 374 | } |
| 375 | |
Ricky Wai | 6b12257 | 2020-02-28 16:30:47 +0000 | [diff] [blame] | 376 | binder::Status VoldNativeService::remountAppStorageDirs(int uid, int pid, |
| 377 | const std::vector<std::string>& packageNames) { |
| 378 | ENFORCE_SYSTEM_OR_ROOT; |
| 379 | ACQUIRE_LOCK; |
| 380 | |
Ricky Wai | a2ca11e | 2021-01-15 14:03:23 +0000 | [diff] [blame] | 381 | return translate(VolumeManager::Instance()->handleAppStorageDirs(uid, pid, |
| 382 | false /* doUnmount */, packageNames)); |
| 383 | } |
| 384 | |
| 385 | binder::Status VoldNativeService::unmountAppStorageDirs(int uid, int pid, |
| 386 | const std::vector<std::string>& packageNames) { |
| 387 | ENFORCE_SYSTEM_OR_ROOT; |
| 388 | ACQUIRE_LOCK; |
| 389 | |
| 390 | return translate(VolumeManager::Instance()->handleAppStorageDirs(uid, pid, |
| 391 | true /* doUnmount */, packageNames)); |
Ricky Wai | 6b12257 | 2020-02-28 16:30:47 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Martijn Coenen | 8a68a07 | 2020-02-12 15:29:02 +0100 | [diff] [blame] | 394 | binder::Status VoldNativeService::setupAppDir(const std::string& path, int32_t appUid) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 395 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 396 | CHECK_ARGUMENT_PATH(path); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 397 | ACQUIRE_LOCK; |
| 398 | |
Martijn Coenen | 8a68a07 | 2020-02-12 15:29:02 +0100 | [diff] [blame] | 399 | return translate(VolumeManager::Instance()->setupAppDir(path, appUid)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 400 | } |
| 401 | |
Ricky Wai | bbfb6ea | 2020-12-03 15:32:52 +0000 | [diff] [blame] | 402 | binder::Status VoldNativeService::ensureAppDirsCreated(const std::vector<std::string>& paths, |
| 403 | int32_t appUid) { |
| 404 | ENFORCE_SYSTEM_OR_ROOT; |
| 405 | ACQUIRE_LOCK; |
| 406 | |
| 407 | return translate(VolumeManager::Instance()->ensureAppDirsCreated(paths, appUid)); |
| 408 | } |
| 409 | |
Martijn Coenen | 816f4d9 | 2020-02-18 15:06:37 +0100 | [diff] [blame] | 410 | binder::Status VoldNativeService::fixupAppDir(const std::string& path, int32_t appUid) { |
| 411 | ENFORCE_SYSTEM_OR_ROOT; |
| 412 | CHECK_ARGUMENT_PATH(path); |
| 413 | ACQUIRE_LOCK; |
| 414 | |
| 415 | return translate(VolumeManager::Instance()->fixupAppDir(path, appUid)); |
| 416 | } |
| 417 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 418 | binder::Status VoldNativeService::createObb(const std::string& sourcePath, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 419 | const std::string& sourceKey, int32_t ownerGid, |
| 420 | std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 421 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 422 | CHECK_ARGUMENT_PATH(sourcePath); |
| 423 | CHECK_ARGUMENT_HEX(sourceKey); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 424 | ACQUIRE_LOCK; |
| 425 | |
| 426 | return translate( |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 427 | VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return)); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | binder::Status VoldNativeService::destroyObb(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 431 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 432 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 433 | ACQUIRE_LOCK; |
| 434 | |
| 435 | return translate(VolumeManager::Instance()->destroyObb(volId)); |
| 436 | } |
| 437 | |
Risan | 82e90de | 2020-02-04 16:07:21 +0900 | [diff] [blame] | 438 | binder::Status VoldNativeService::createStubVolume(const std::string& sourcePath, |
| 439 | const std::string& mountPath, |
| 440 | const std::string& fsType, |
| 441 | const std::string& fsUuid, |
| 442 | const std::string& fsLabel, int32_t flags, |
| 443 | std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 444 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 445 | CHECK_ARGUMENT_PATH(sourcePath); |
| 446 | CHECK_ARGUMENT_PATH(mountPath); |
| 447 | CHECK_ARGUMENT_HEX(fsUuid); |
| 448 | // Label limitation seems to be different between fs (including allowed characters), so checking |
| 449 | // is quite meaningless. |
| 450 | ACQUIRE_LOCK; |
| 451 | |
Risan | 82e90de | 2020-02-04 16:07:21 +0900 | [diff] [blame] | 452 | return translate(VolumeManager::Instance()->createStubVolume( |
| 453 | sourcePath, mountPath, fsType, fsUuid, fsLabel, flags, _aidl_return)); |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | binder::Status VoldNativeService::destroyStubVolume(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 457 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 458 | CHECK_ARGUMENT_ID(volId); |
| 459 | ACQUIRE_LOCK; |
| 460 | |
| 461 | return translate(VolumeManager::Instance()->destroyStubVolume(volId)); |
| 462 | } |
| 463 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 464 | binder::Status VoldNativeService::fstrim( |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 465 | int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 466 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 467 | ACQUIRE_LOCK; |
| 468 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 469 | std::thread([=]() { android::vold::Trim(listener); }).detach(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 470 | return Ok(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 471 | } |
| 472 | |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 473 | binder::Status VoldNativeService::runIdleMaint( |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 474 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 475 | ENFORCE_SYSTEM_OR_ROOT; |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 476 | ACQUIRE_LOCK; |
| 477 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 478 | std::thread([=]() { android::vold::RunIdleMaint(listener); }).detach(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 479 | return Ok(); |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | binder::Status VoldNativeService::abortIdleMaint( |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 483 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 484 | ENFORCE_SYSTEM_OR_ROOT; |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 485 | ACQUIRE_LOCK; |
| 486 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 487 | std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 488 | return Ok(); |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 491 | binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t mountId, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 492 | android::base::unique_fd* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 493 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 494 | ACQUIRE_LOCK; |
| 495 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 496 | return translate(VolumeManager::Instance()->mountAppFuse(uid, mountId, _aidl_return)); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 497 | } |
| 498 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 499 | binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t mountId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 500 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 501 | ACQUIRE_LOCK; |
| 502 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 503 | return translate(VolumeManager::Instance()->unmountAppFuse(uid, mountId)); |
| 504 | } |
| 505 | |
| 506 | binder::Status VoldNativeService::openAppFuseFile(int32_t uid, int32_t mountId, int32_t fileId, |
| 507 | int32_t flags, |
| 508 | android::base::unique_fd* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 509 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 510 | ACQUIRE_LOCK; |
| 511 | |
| 512 | int fd = VolumeManager::Instance()->openAppFuseFile(uid, mountId, fileId, flags); |
| 513 | if (fd == -1) { |
| 514 | return error("Failed to open AppFuse file for uid: " + std::to_string(uid) + |
| 515 | " mountId: " + std::to_string(mountId) + " fileId: " + std::to_string(fileId) + |
| 516 | " flags: " + std::to_string(flags)); |
| 517 | } |
| 518 | |
| 519 | *_aidl_return = android::base::unique_fd(fd); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 520 | return Ok(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 521 | } |
| 522 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 523 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 524 | binder::Status VoldNativeService::fdeCheckPassword(const std::string& password) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 525 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 526 | ACQUIRE_CRYPT_LOCK; |
| 527 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 528 | SLOGE("fdeCheckPassword is no longer supported"); |
| 529 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 530 | } |
| 531 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 532 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 533 | binder::Status VoldNativeService::fdeRestart() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 534 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 535 | ACQUIRE_CRYPT_LOCK; |
| 536 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 537 | SLOGE("fdeRestart is no longer supported"); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 538 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 539 | } |
| 540 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 541 | // TODO(b/191796797) remove this once caller is removed |
| 542 | #define CRYPTO_COMPLETE_NOT_ENCRYPTED 1 |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 543 | binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 544 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 545 | ACQUIRE_CRYPT_LOCK; |
| 546 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 547 | SLOGE("fdeComplete is no longer supported"); |
| 548 | *_aidl_return = CRYPTO_COMPLETE_NOT_ENCRYPTED; |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 549 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 550 | } |
| 551 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 552 | // TODO(b/191796797) remove this once caller is removed |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 553 | binder::Status VoldNativeService::fdeEnable(int32_t passwordType, const std::string& password, |
| 554 | int32_t encryptionFlags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 555 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 556 | ACQUIRE_CRYPT_LOCK; |
| 557 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 558 | SLOGE("fdeEnable is no longer supported"); |
| 559 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 560 | } |
| 561 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 562 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 563 | binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 564 | const std::string& password) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 565 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 566 | ACQUIRE_CRYPT_LOCK; |
| 567 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 568 | SLOGE("fdeChangePassword is no longer supported"); |
| 569 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 570 | } |
| 571 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 572 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 573 | binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 574 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 575 | ACQUIRE_CRYPT_LOCK; |
| 576 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 577 | SLOGE("fdeVerifyPassword is no longer supported"); |
| 578 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 579 | } |
| 580 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 581 | // TODO(b/191796797) remove this once caller is removed |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 582 | binder::Status VoldNativeService::fdeGetField(const std::string& key, std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 583 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 584 | ACQUIRE_CRYPT_LOCK; |
| 585 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 586 | SLOGE("fdeGetField is no longer supported"); |
| 587 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 588 | } |
| 589 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 590 | // TODO(b/191796797) remove this once caller is removed |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 591 | binder::Status VoldNativeService::fdeSetField(const std::string& key, const std::string& value) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 592 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 593 | ACQUIRE_CRYPT_LOCK; |
| 594 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 595 | SLOGE("fdeSetField is no longer supported"); |
| 596 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 597 | } |
| 598 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 599 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 600 | binder::Status VoldNativeService::fdeGetPasswordType(int32_t* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 601 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 602 | ACQUIRE_CRYPT_LOCK; |
| 603 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 604 | SLOGE("fdeGetPasswordType is no longer supported"); |
| 605 | *_aidl_return = -1; |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 606 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 607 | } |
| 608 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 609 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 610 | binder::Status VoldNativeService::fdeGetPassword(std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 611 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 612 | ACQUIRE_CRYPT_LOCK; |
| 613 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 614 | SLOGE("fdeGetPassword is no longer supported"); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 615 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 616 | } |
| 617 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 618 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 619 | binder::Status VoldNativeService::fdeClearPassword() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 620 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 621 | ACQUIRE_CRYPT_LOCK; |
| 622 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 623 | SLOGE("fdeClearPassword is no longer supported"); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 624 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | binder::Status VoldNativeService::fbeEnable() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 628 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 629 | ACQUIRE_CRYPT_LOCK; |
| 630 | |
Paul Crowley | c8a3ef3 | 2019-09-11 15:00:08 -0700 | [diff] [blame] | 631 | return translateBool(fscrypt_initialize_systemwide_keys()); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 632 | } |
| 633 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 634 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 635 | binder::Status VoldNativeService::mountDefaultEncrypted() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 636 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 637 | ACQUIRE_CRYPT_LOCK; |
| 638 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 639 | SLOGE("mountDefaultEncrypted is no longer supported"); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 640 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | binder::Status VoldNativeService::initUser0() { |
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 | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 647 | return translateBool(fscrypt_init_user0()); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 648 | } |
| 649 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 650 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 651 | binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 652 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 653 | ACQUIRE_CRYPT_LOCK; |
| 654 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 655 | SLOGE("isConvertibleToFbe is no longer supported"); |
| 656 | *_aidl_return = false; |
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 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 660 | binder::Status VoldNativeService::mountFstab(const std::string& blkDevice, |
| 661 | const std::string& mountPoint) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 662 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 663 | ACQUIRE_LOCK; |
| 664 | |
Jaegeuk Kim | 0c52c71 | 2020-12-15 09:00:49 -0800 | [diff] [blame] | 665 | return translateBool( |
| 666 | fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, false, false, "null")); |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 667 | } |
| 668 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 669 | binder::Status VoldNativeService::encryptFstab(const std::string& blkDevice, |
Jaegeuk Kim | 0c52c71 | 2020-12-15 09:00:49 -0800 | [diff] [blame] | 670 | const std::string& mountPoint, bool shouldFormat, |
| 671 | const std::string& fsType) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 672 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 673 | ACQUIRE_LOCK; |
| 674 | |
Jaegeuk Kim | 0c52c71 | 2020-12-15 09:00:49 -0800 | [diff] [blame] | 675 | return translateBool( |
| 676 | fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, true, shouldFormat, fsType)); |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 677 | } |
| 678 | |
Seth Moore | 5a43d61 | 2021-01-19 17:51:51 +0000 | [diff] [blame] | 679 | binder::Status VoldNativeService::setStorageBindingSeed(const std::vector<uint8_t>& seed) { |
| 680 | ENFORCE_SYSTEM_OR_ROOT; |
| 681 | ACQUIRE_CRYPT_LOCK; |
| 682 | |
| 683 | return translateBool(setKeyStorageBindingSeed(seed)); |
| 684 | } |
| 685 | |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 686 | binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, |
| 687 | bool ephemeral) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 688 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 689 | ACQUIRE_CRYPT_LOCK; |
| 690 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 691 | return translateBool(fscrypt_vold_create_user_key(userId, userSerial, ephemeral)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | binder::Status VoldNativeService::destroyUserKey(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 695 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 696 | ACQUIRE_CRYPT_LOCK; |
| 697 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 698 | return translateBool(fscrypt_destroy_user_key(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 699 | } |
| 700 | |
Satya Tangirala | e136171 | 2021-03-15 15:33:08 -0700 | [diff] [blame] | 701 | static bool token_empty(const std::string& token) { |
| 702 | return token.size() == 0 || token == "!"; |
| 703 | } |
| 704 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 705 | binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 706 | const std::string& token, |
| 707 | const std::string& secret) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 708 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 709 | ACQUIRE_CRYPT_LOCK; |
| 710 | |
Satya Tangirala | e136171 | 2021-03-15 15:33:08 -0700 | [diff] [blame] | 711 | if (!token_empty(token)) { |
| 712 | LOG(ERROR) << "Vold doesn't use auth tokens, but non-empty token passed to addUserKeyAuth."; |
| 713 | return binder::Status::fromServiceSpecificError(-EINVAL); |
| 714 | } |
| 715 | |
| 716 | return translateBool(fscrypt_add_user_key_auth(userId, userSerial, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 717 | } |
| 718 | |
Barani Muthukumaran | 9ad51ad | 2019-10-31 22:59:34 -0700 | [diff] [blame] | 719 | binder::Status VoldNativeService::clearUserKeyAuth(int32_t userId, int32_t userSerial, |
| 720 | const std::string& token, |
| 721 | const std::string& secret) { |
| 722 | ENFORCE_SYSTEM_OR_ROOT; |
| 723 | ACQUIRE_CRYPT_LOCK; |
| 724 | |
Satya Tangirala | e136171 | 2021-03-15 15:33:08 -0700 | [diff] [blame] | 725 | if (!token_empty(token)) { |
| 726 | LOG(ERROR) |
| 727 | << "Vold doesn't use auth tokens, but non-empty token passed to clearUserKeyAuth."; |
| 728 | return binder::Status::fromServiceSpecificError(-EINVAL); |
| 729 | } |
| 730 | |
| 731 | return translateBool(fscrypt_clear_user_key_auth(userId, userSerial, secret)); |
Barani Muthukumaran | 9ad51ad | 2019-10-31 22:59:34 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 734 | binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 735 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 736 | ACQUIRE_CRYPT_LOCK; |
| 737 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 738 | return translateBool(fscrypt_fixate_newest_user_key_auth(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 739 | } |
| 740 | |
Eric Biggers | 1799deb | 2021-04-06 12:02:56 -0700 | [diff] [blame] | 741 | binder::Status VoldNativeService::getUnlockedUsers(std::vector<int>* _aidl_return) { |
| 742 | ENFORCE_SYSTEM_OR_ROOT; |
| 743 | ACQUIRE_CRYPT_LOCK; |
| 744 | |
| 745 | *_aidl_return = fscrypt_get_unlocked_users(); |
| 746 | return Ok(); |
| 747 | } |
| 748 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 749 | binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 750 | const std::string& token, |
| 751 | const std::string& secret) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 752 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 753 | ACQUIRE_CRYPT_LOCK; |
| 754 | |
Satya Tangirala | e136171 | 2021-03-15 15:33:08 -0700 | [diff] [blame] | 755 | if (!token_empty(token)) { |
| 756 | LOG(ERROR) << "Vold doesn't use auth tokens, but non-empty token passed to unlockUserKey."; |
| 757 | return binder::Status::fromServiceSpecificError(-EINVAL); |
| 758 | } |
| 759 | |
| 760 | return translateBool(fscrypt_unlock_user_key(userId, userSerial, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | binder::Status VoldNativeService::lockUserKey(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 764 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 765 | ACQUIRE_CRYPT_LOCK; |
| 766 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 767 | return translateBool(fscrypt_lock_user_key(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 768 | } |
| 769 | |
Jooyung Han | 4fcb707 | 2020-01-23 13:23:26 +0900 | [diff] [blame] | 770 | binder::Status VoldNativeService::prepareUserStorage(const std::optional<std::string>& uuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 771 | int32_t userId, int32_t userSerial, |
| 772 | int32_t flags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 773 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 774 | std::string empty_string = ""; |
| 775 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 776 | CHECK_ARGUMENT_HEX(uuid_); |
| 777 | |
| 778 | ACQUIRE_CRYPT_LOCK; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 779 | return translateBool(fscrypt_prepare_user_storage(uuid_, userId, userSerial, flags)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 780 | } |
| 781 | |
Jooyung Han | 4fcb707 | 2020-01-23 13:23:26 +0900 | [diff] [blame] | 782 | binder::Status VoldNativeService::destroyUserStorage(const std::optional<std::string>& uuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 783 | int32_t userId, int32_t flags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 784 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 785 | std::string empty_string = ""; |
| 786 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 787 | CHECK_ARGUMENT_HEX(uuid_); |
| 788 | |
| 789 | ACQUIRE_CRYPT_LOCK; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 790 | return translateBool(fscrypt_destroy_user_storage(uuid_, userId, flags)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 791 | } |
| 792 | |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 793 | binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packageName, |
| 794 | int32_t appId, const std::string& sandboxId, |
| 795 | int32_t userId) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 796 | return Ok(); |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName, |
Sudheer Shanka | 69bc40f | 2018-10-25 11:06:55 -0700 | [diff] [blame] | 800 | const std::string& sandboxId, |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 801 | int32_t userId) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 802 | return Ok(); |
Sudheer Shanka | c756209 | 2018-08-24 10:20:56 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 805 | binder::Status VoldNativeService::startCheckpoint(int32_t retry) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 806 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 807 | ACQUIRE_LOCK; |
| 808 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 809 | return cp_startCheckpoint(retry); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 812 | binder::Status VoldNativeService::needsRollback(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 813 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 814 | ACQUIRE_LOCK; |
| 815 | |
| 816 | *_aidl_return = cp_needsRollback(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 817 | return Ok(); |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 820 | binder::Status VoldNativeService::needsCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 821 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 822 | ACQUIRE_LOCK; |
| 823 | |
| 824 | *_aidl_return = cp_needsCheckpoint(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 825 | return Ok(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 826 | } |
| 827 | |
David Anderson | 23850d3 | 2020-06-10 23:51:17 -0700 | [diff] [blame] | 828 | binder::Status VoldNativeService::isCheckpointing(bool* _aidl_return) { |
| 829 | ENFORCE_SYSTEM_OR_ROOT; |
| 830 | ACQUIRE_LOCK; |
| 831 | |
| 832 | *_aidl_return = cp_isCheckpointing(); |
| 833 | return Ok(); |
| 834 | } |
| 835 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 836 | binder::Status VoldNativeService::commitChanges() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 837 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 838 | ACQUIRE_LOCK; |
| 839 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 840 | return cp_commitChanges(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 841 | } |
| 842 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 843 | binder::Status VoldNativeService::prepareCheckpoint() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 844 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 845 | ACQUIRE_LOCK; |
| 846 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 847 | return cp_prepareCheckpoint(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 848 | } |
| 849 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 850 | binder::Status VoldNativeService::restoreCheckpoint(const std::string& mountPoint) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 851 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | 1abb2fe | 2018-09-21 10:49:57 -0700 | [diff] [blame] | 852 | CHECK_ARGUMENT_PATH(mountPoint); |
| 853 | ACQUIRE_LOCK; |
| 854 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 855 | return cp_restoreCheckpoint(mountPoint); |
Paul Lawrence | 1abb2fe | 2018-09-21 10:49:57 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Daniel Rosenberg | dda5981 | 2019-03-06 17:45:17 -0800 | [diff] [blame] | 858 | binder::Status VoldNativeService::restoreCheckpointPart(const std::string& mountPoint, int count) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 859 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | dda5981 | 2019-03-06 17:45:17 -0800 | [diff] [blame] | 860 | CHECK_ARGUMENT_PATH(mountPoint); |
| 861 | ACQUIRE_LOCK; |
| 862 | |
| 863 | return cp_restoreCheckpoint(mountPoint, count); |
| 864 | } |
| 865 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 866 | binder::Status VoldNativeService::markBootAttempt() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 867 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 868 | ACQUIRE_LOCK; |
| 869 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 870 | return cp_markBootAttempt(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 871 | } |
| 872 | |
Daniel Rosenberg | a59e439 | 2019-03-20 17:02:47 -0700 | [diff] [blame] | 873 | binder::Status VoldNativeService::abortChanges(const std::string& message, bool retry) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 874 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 875 | ACQUIRE_LOCK; |
| 876 | |
Daniel Rosenberg | a59e439 | 2019-03-20 17:02:47 -0700 | [diff] [blame] | 877 | cp_abortChanges(message, retry); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 878 | return Ok(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Daniel Rosenberg | 9b667fb | 2019-01-22 17:27:25 -0800 | [diff] [blame] | 881 | binder::Status VoldNativeService::supportsCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 882 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 9b667fb | 2019-01-22 17:27:25 -0800 | [diff] [blame] | 883 | ACQUIRE_LOCK; |
| 884 | |
| 885 | return cp_supportsCheckpoint(*_aidl_return); |
| 886 | } |
| 887 | |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 888 | binder::Status VoldNativeService::supportsBlockCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 889 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 890 | ACQUIRE_LOCK; |
| 891 | |
| 892 | return cp_supportsBlockCheckpoint(*_aidl_return); |
| 893 | } |
| 894 | |
| 895 | binder::Status VoldNativeService::supportsFileCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 896 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 897 | ACQUIRE_LOCK; |
| 898 | |
| 899 | return cp_supportsFileCheckpoint(*_aidl_return); |
| 900 | } |
| 901 | |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 902 | binder::Status VoldNativeService::resetCheckpoint() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 903 | ENFORCE_SYSTEM_OR_ROOT; |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 904 | ACQUIRE_LOCK; |
| 905 | |
| 906 | cp_resetCheckpoint(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 907 | return Ok(); |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 908 | } |
| 909 | |
Alex Buynytskyy | b02e7b6 | 2021-02-11 19:09:10 -0800 | [diff] [blame] | 910 | static void initializeIncFs() { |
| 911 | // Obtaining IncFS features triggers initialization of IncFS. |
| 912 | incfs::features(); |
| 913 | } |
| 914 | |
Eric Biggers | 4859e0c | 2021-06-24 11:13:24 -0700 | [diff] [blame] | 915 | // This is missing from the kernel UAPI headers. |
| 916 | #define ST_RDONLY 0x0001 |
| 917 | |
| 918 | // FDE devices run the post-fs-data trigger (and hence also earlyBootEnded) |
| 919 | // multiple times, sometimes prior to the real /data being mounted. That causes |
| 920 | // keystore2 to try to open a file in /data, causing it to panic or have to be |
| 921 | // killed by vold later, causing problems (vold failing to connect to keystore2, |
| 922 | // or keystore2 operations erroring out later). As a workaround to keep FDE |
| 923 | // working, ignore these too-early calls to earlyBootEnded. |
| 924 | // |
| 925 | // This can be removed when support for FDE is removed. |
| 926 | static bool IgnoreEarlyBootEnded() { |
| 927 | // The statfs("/data") below should be sufficient by itself, but to be safe |
| 928 | // we also explicitly return false on FBE devices. (This really should be |
| 929 | // ro.crypto.type != "block" for "non-FDE devices", but on FDE devices this |
| 930 | // is sometimes called before ro.crypto.type gets set.) |
| 931 | if (fscrypt_is_native()) return false; |
| 932 | |
| 933 | struct statfs buf; |
| 934 | if (statfs(DATA_MNT_POINT, &buf) != 0) { |
| 935 | PLOG(ERROR) << "statfs(\"/data\") failed"; |
| 936 | return false; |
| 937 | } |
| 938 | if (buf.f_type == TMPFS_MAGIC || (buf.f_flags & ST_RDONLY)) { |
| 939 | LOG(INFO) << "Ignoring earlyBootEnded since real /data isn't mounted yet"; |
| 940 | return true; |
| 941 | } |
| 942 | return false; |
| 943 | } |
| 944 | |
Martijn Coenen | eed957f | 2020-11-12 10:59:13 +0100 | [diff] [blame] | 945 | binder::Status VoldNativeService::earlyBootEnded() { |
| 946 | ENFORCE_SYSTEM_OR_ROOT; |
| 947 | ACQUIRE_LOCK; |
| 948 | |
Eric Biggers | 4859e0c | 2021-06-24 11:13:24 -0700 | [diff] [blame] | 949 | if (IgnoreEarlyBootEnded()) return Ok(); |
| 950 | |
Alex Buynytskyy | b02e7b6 | 2021-02-11 19:09:10 -0800 | [diff] [blame] | 951 | initializeIncFs(); |
Eric Biggers | d86a8ab | 2021-06-15 11:34:00 -0700 | [diff] [blame] | 952 | Keystore::earlyBootEnded(); |
Martijn Coenen | eed957f | 2020-11-12 10:59:13 +0100 | [diff] [blame] | 953 | return Ok(); |
| 954 | } |
| 955 | |
Yurii Zubrytskyi | 3497cb5 | 2020-01-10 11:54:06 -0800 | [diff] [blame] | 956 | binder::Status VoldNativeService::incFsEnabled(bool* _aidl_return) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 957 | ENFORCE_SYSTEM_OR_ROOT; |
| 958 | |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 959 | *_aidl_return = incfs::enabled(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 960 | return Ok(); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | binder::Status VoldNativeService::mountIncFs( |
Yurii Zubrytskyi | 3497cb5 | 2020-01-10 11:54:06 -0800 | [diff] [blame] | 964 | const std::string& backingPath, const std::string& targetDir, int32_t flags, |
Songchun Fan | 046e68a | 2021-04-27 12:46:02 -0700 | [diff] [blame] | 965 | const std::string& sysfsName, |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 966 | ::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 967 | ENFORCE_SYSTEM_OR_ROOT; |
Yurii Zubrytskyi | 4038982 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 968 | if (auto status = CheckIncrementalPath(IncrementalPathKind::MountTarget, targetDir); |
| 969 | !status.isOk()) { |
| 970 | return status; |
| 971 | } |
| 972 | if (auto status = CheckIncrementalPath(IncrementalPathKind::MountSource, backingPath); |
| 973 | !status.isOk()) { |
| 974 | return status; |
| 975 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 976 | |
Yurii Zubrytskyi | 4038982 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 977 | auto [backingFd, backingSymlink] = OpenDirInProcfs(backingPath); |
| 978 | if (!backingFd.ok()) { |
| 979 | return translate(-errno); |
| 980 | } |
| 981 | auto [targetFd, targetSymlink] = OpenDirInProcfs(targetDir); |
| 982 | if (!targetFd.ok()) { |
| 983 | return translate(-errno); |
| 984 | } |
| 985 | |
| 986 | auto control = incfs::mount(backingSymlink, targetSymlink, |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 987 | {.flags = IncFsMountFlags(flags), |
Alex Buynytskyy | dcfeaa1 | 2021-04-01 13:43:14 -0700 | [diff] [blame] | 988 | // Mount with read timeouts. |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 989 | .defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS, |
| 990 | // Mount with read logs disabled. |
Songchun Fan | 046e68a | 2021-04-27 12:46:02 -0700 | [diff] [blame] | 991 | .readLogBufferPages = 0, |
| 992 | .sysfsName = sysfsName.c_str()}); |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 993 | if (!control) { |
| 994 | return translate(-errno); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 995 | } |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 996 | auto fds = control.releaseFds(); |
| 997 | using android::base::unique_fd; |
| 998 | _aidl_return->cmd.reset(unique_fd(fds[CMD].release())); |
| 999 | _aidl_return->pendingReads.reset(unique_fd(fds[PENDING_READS].release())); |
| 1000 | _aidl_return->log.reset(unique_fd(fds[LOGS].release())); |
Yurii Zubrytskyi | 0c0f839 | 2020-12-08 07:33:37 -0800 | [diff] [blame] | 1001 | if (fds[BLOCKS_WRITTEN].ok()) { |
| 1002 | _aidl_return->blocksWritten.emplace(unique_fd(fds[BLOCKS_WRITTEN].release())); |
| 1003 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 1004 | return Ok(); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | binder::Status VoldNativeService::unmountIncFs(const std::string& dir) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 1008 | ENFORCE_SYSTEM_OR_ROOT; |
Yurii Zubrytskyi | 4038982 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 1009 | if (auto status = CheckIncrementalPath(IncrementalPathKind::Any, dir); !status.isOk()) { |
| 1010 | return status; |
| 1011 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 1012 | |
Yurii Zubrytskyi | 4038982 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 1013 | auto [fd, symLink] = OpenDirInProcfs(dir); |
| 1014 | if (!fd.ok()) { |
| 1015 | return translate(-errno); |
| 1016 | } |
| 1017 | return translate(incfs::unmount(symLink)); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 1018 | } |
| 1019 | |
Alex Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 1020 | binder::Status VoldNativeService::setIncFsMountOptions( |
| 1021 | const ::android::os::incremental::IncrementalFileSystemControlParcel& control, |
Songchun Fan | 0e53c1c | 2021-05-10 16:19:38 -0700 | [diff] [blame] | 1022 | bool enableReadLogs, bool enableReadTimeouts, const std::string& sysfsName) { |
Alex Buynytskyy | 605a44f | 2020-04-02 15:21:47 -0700 | [diff] [blame] | 1023 | ENFORCE_SYSTEM_OR_ROOT; |
Alex Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 1024 | |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 1025 | auto incfsControl = |
Yurii Zubrytskyi | 0c0f839 | 2020-12-08 07:33:37 -0800 | [diff] [blame] | 1026 | incfs::createControl(control.cmd.get(), control.pendingReads.get(), control.log.get(), |
| 1027 | control.blocksWritten ? control.blocksWritten->get() : -1); |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 1028 | auto cleanupFunc = [](auto incfsControl) { |
| 1029 | for (auto& fd : incfsControl->releaseFds()) { |
| 1030 | (void)fd.release(); |
| 1031 | } |
| 1032 | }; |
| 1033 | auto cleanup = |
| 1034 | std::unique_ptr<incfs::Control, decltype(cleanupFunc)>(&incfsControl, cleanupFunc); |
Alex Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 1035 | |
Yurii Zubrytskyi | 1d7acfd | 2021-10-28 14:37:12 -0700 | [diff] [blame] | 1036 | constexpr auto minReadLogBufferPages = INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES; |
| 1037 | constexpr auto maxReadLogBufferPages = 8 * INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES; |
| 1038 | auto options = incfs::MountOptions{ |
| 1039 | .defaultReadTimeoutMs = |
| 1040 | enableReadTimeouts ? INCFS_DEFAULT_READ_TIMEOUT_MS : kIncFsReadNoTimeoutMs, |
| 1041 | .readLogBufferPages = enableReadLogs ? maxReadLogBufferPages : 0, |
| 1042 | .sysfsName = sysfsName.c_str()}; |
| 1043 | |
| 1044 | for (;;) { |
| 1045 | const auto error = incfs::setOptions(incfsControl, options); |
| 1046 | if (!error) { |
| 1047 | return Ok(); |
| 1048 | } |
| 1049 | if (!enableReadLogs || error != -ENOMEM) { |
| 1050 | return binder::Status::fromServiceSpecificError(error); |
| 1051 | } |
| 1052 | // In case of memory allocation error retry with a smaller buffer. |
| 1053 | options.readLogBufferPages /= 2; |
| 1054 | if (options.readLogBufferPages < minReadLogBufferPages) { |
| 1055 | return binder::Status::fromServiceSpecificError(error); |
| 1056 | } |
| 1057 | } |
| 1058 | // unreachable, but makes the compiler happy |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 1059 | return Ok(); |
Alex Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 1062 | binder::Status VoldNativeService::bindMount(const std::string& sourceDir, |
| 1063 | const std::string& targetDir) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 1064 | ENFORCE_SYSTEM_OR_ROOT; |
Yurii Zubrytskyi | 4038982 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 1065 | if (auto status = CheckIncrementalPath(IncrementalPathKind::Any, sourceDir); !status.isOk()) { |
| 1066 | return status; |
| 1067 | } |
| 1068 | if (auto status = CheckIncrementalPath(IncrementalPathKind::Bind, targetDir); !status.isOk()) { |
| 1069 | return status; |
| 1070 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 1071 | |
Yurii Zubrytskyi | 4038982 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 1072 | auto [sourceFd, sourceSymlink] = OpenDirInProcfs(sourceDir); |
| 1073 | if (!sourceFd.ok()) { |
| 1074 | return translate(-errno); |
| 1075 | } |
| 1076 | auto [targetFd, targetSymlink] = OpenDirInProcfs(targetDir); |
| 1077 | if (!targetFd.ok()) { |
| 1078 | return translate(-errno); |
| 1079 | } |
| 1080 | return translate(incfs::bindMount(sourceSymlink, targetSymlink)); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 1081 | } |
| 1082 | |
Yo Chiang | 0af25a3 | 2020-10-07 14:20:00 +0800 | [diff] [blame] | 1083 | binder::Status VoldNativeService::destroyDsuMetadataKey(const std::string& dsuSlot) { |
| 1084 | ENFORCE_SYSTEM_OR_ROOT; |
| 1085 | ACQUIRE_LOCK; |
| 1086 | |
| 1087 | return translateBool(destroy_dsu_metadata_key(dsuSlot)); |
| 1088 | } |
| 1089 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 1090 | } // namespace vold |
| 1091 | } // namespace android |