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 | |
Eric Biggers | 7e79a43 | 2022-03-01 21:19:18 +0000 | [diff] [blame] | 417 | binder::Status VoldNativeService::createObb(const std::string& sourcePath, int32_t ownerGid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 418 | std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 419 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 420 | CHECK_ARGUMENT_PATH(sourcePath); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 421 | ACQUIRE_LOCK; |
| 422 | |
Eric Biggers | 7e79a43 | 2022-03-01 21:19:18 +0000 | [diff] [blame] | 423 | return translate(VolumeManager::Instance()->createObb(sourcePath, ownerGid, _aidl_return)); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | binder::Status VoldNativeService::destroyObb(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 427 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 428 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 429 | ACQUIRE_LOCK; |
| 430 | |
| 431 | return translate(VolumeManager::Instance()->destroyObb(volId)); |
| 432 | } |
| 433 | |
Risan | 82e90de | 2020-02-04 16:07:21 +0900 | [diff] [blame] | 434 | binder::Status VoldNativeService::createStubVolume(const std::string& sourcePath, |
| 435 | const std::string& mountPath, |
| 436 | const std::string& fsType, |
| 437 | const std::string& fsUuid, |
| 438 | const std::string& fsLabel, int32_t flags, |
| 439 | std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 440 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 441 | CHECK_ARGUMENT_PATH(sourcePath); |
| 442 | CHECK_ARGUMENT_PATH(mountPath); |
| 443 | CHECK_ARGUMENT_HEX(fsUuid); |
| 444 | // Label limitation seems to be different between fs (including allowed characters), so checking |
| 445 | // is quite meaningless. |
| 446 | ACQUIRE_LOCK; |
| 447 | |
Risan | 82e90de | 2020-02-04 16:07:21 +0900 | [diff] [blame] | 448 | return translate(VolumeManager::Instance()->createStubVolume( |
| 449 | sourcePath, mountPath, fsType, fsUuid, fsLabel, flags, _aidl_return)); |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | binder::Status VoldNativeService::destroyStubVolume(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 453 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 454 | CHECK_ARGUMENT_ID(volId); |
| 455 | ACQUIRE_LOCK; |
| 456 | |
| 457 | return translate(VolumeManager::Instance()->destroyStubVolume(volId)); |
| 458 | } |
| 459 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 460 | binder::Status VoldNativeService::fstrim( |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 461 | int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 462 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 463 | ACQUIRE_LOCK; |
| 464 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 465 | std::thread([=]() { android::vold::Trim(listener); }).detach(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 466 | return Ok(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 467 | } |
| 468 | |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 469 | binder::Status VoldNativeService::runIdleMaint( |
Daeho Jeong | 999fceb | 2022-01-04 11:37:39 -0800 | [diff] [blame] | 470 | bool needGC, const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 471 | ENFORCE_SYSTEM_OR_ROOT; |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 472 | ACQUIRE_LOCK; |
| 473 | |
Daeho Jeong | 999fceb | 2022-01-04 11:37:39 -0800 | [diff] [blame] | 474 | std::thread([=]() { android::vold::RunIdleMaint(needGC, listener); }).detach(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 475 | return Ok(); |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | binder::Status VoldNativeService::abortIdleMaint( |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 479 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 480 | ENFORCE_SYSTEM_OR_ROOT; |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 481 | ACQUIRE_LOCK; |
| 482 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 483 | std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 484 | return Ok(); |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Daeho Jeong | 999fceb | 2022-01-04 11:37:39 -0800 | [diff] [blame] | 487 | binder::Status VoldNativeService::getStorageLifeTime(int32_t* _aidl_return) { |
| 488 | ENFORCE_SYSTEM_OR_ROOT; |
| 489 | ACQUIRE_LOCK; |
| 490 | |
| 491 | *_aidl_return = GetStorageLifeTime(); |
| 492 | return Ok(); |
| 493 | } |
| 494 | |
| 495 | binder::Status VoldNativeService::setGCUrgentPace(int32_t neededSegments, |
| 496 | int32_t minSegmentThreshold, |
| 497 | float dirtyReclaimRate, float reclaimWeight) { |
| 498 | ENFORCE_SYSTEM_OR_ROOT; |
| 499 | ACQUIRE_LOCK; |
| 500 | |
| 501 | SetGCUrgentPace(neededSegments, minSegmentThreshold, dirtyReclaimRate, reclaimWeight); |
| 502 | return Ok(); |
| 503 | } |
| 504 | |
| 505 | binder::Status VoldNativeService::refreshLatestWrite() { |
| 506 | ENFORCE_SYSTEM_OR_ROOT; |
| 507 | ACQUIRE_LOCK; |
| 508 | |
| 509 | RefreshLatestWrite(); |
| 510 | return Ok(); |
| 511 | } |
| 512 | |
| 513 | binder::Status VoldNativeService::getWriteAmount(int32_t* _aidl_return) { |
| 514 | ENFORCE_SYSTEM_OR_ROOT; |
| 515 | ACQUIRE_LOCK; |
| 516 | |
| 517 | *_aidl_return = GetWriteAmount(); |
| 518 | return Ok(); |
| 519 | } |
| 520 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 521 | binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t mountId, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 522 | android::base::unique_fd* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 523 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 524 | ACQUIRE_LOCK; |
| 525 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 526 | return translate(VolumeManager::Instance()->mountAppFuse(uid, mountId, _aidl_return)); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 527 | } |
| 528 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 529 | binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t mountId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 530 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 531 | ACQUIRE_LOCK; |
| 532 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 533 | return translate(VolumeManager::Instance()->unmountAppFuse(uid, mountId)); |
| 534 | } |
| 535 | |
| 536 | binder::Status VoldNativeService::openAppFuseFile(int32_t uid, int32_t mountId, int32_t fileId, |
| 537 | int32_t flags, |
| 538 | android::base::unique_fd* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 539 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 540 | ACQUIRE_LOCK; |
| 541 | |
| 542 | int fd = VolumeManager::Instance()->openAppFuseFile(uid, mountId, fileId, flags); |
| 543 | if (fd == -1) { |
| 544 | return error("Failed to open AppFuse file for uid: " + std::to_string(uid) + |
| 545 | " mountId: " + std::to_string(mountId) + " fileId: " + std::to_string(fileId) + |
| 546 | " flags: " + std::to_string(flags)); |
| 547 | } |
| 548 | |
| 549 | *_aidl_return = android::base::unique_fd(fd); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 550 | return Ok(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 551 | } |
| 552 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 553 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 554 | binder::Status VoldNativeService::fdeCheckPassword(const std::string& password) { |
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("fdeCheckPassword 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::fdeRestart() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 564 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 565 | ACQUIRE_CRYPT_LOCK; |
| 566 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 567 | SLOGE("fdeRestart is no longer supported"); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 568 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 569 | } |
| 570 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 571 | // TODO(b/191796797) remove this once caller is removed |
| 572 | #define CRYPTO_COMPLETE_NOT_ENCRYPTED 1 |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 573 | binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) { |
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("fdeComplete is no longer supported"); |
| 578 | *_aidl_return = CRYPTO_COMPLETE_NOT_ENCRYPTED; |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 579 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 580 | } |
| 581 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 582 | // TODO(b/191796797) remove this once caller is removed |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 583 | binder::Status VoldNativeService::fdeEnable(int32_t passwordType, const std::string& password, |
| 584 | int32_t encryptionFlags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 585 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 586 | ACQUIRE_CRYPT_LOCK; |
| 587 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 588 | SLOGE("fdeEnable is no longer supported"); |
| 589 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 590 | } |
| 591 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 592 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 593 | binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 594 | const std::string& password) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 595 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 596 | ACQUIRE_CRYPT_LOCK; |
| 597 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 598 | SLOGE("fdeChangePassword is no longer supported"); |
| 599 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 600 | } |
| 601 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 602 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 603 | binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 604 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 605 | ACQUIRE_CRYPT_LOCK; |
| 606 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 607 | SLOGE("fdeVerifyPassword is no longer supported"); |
| 608 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 609 | } |
| 610 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 611 | // TODO(b/191796797) remove this once caller is removed |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 612 | binder::Status VoldNativeService::fdeGetField(const std::string& key, std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 613 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 614 | ACQUIRE_CRYPT_LOCK; |
| 615 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 616 | SLOGE("fdeGetField is no longer supported"); |
| 617 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 618 | } |
| 619 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 620 | // TODO(b/191796797) remove this once caller is removed |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 621 | binder::Status VoldNativeService::fdeSetField(const std::string& key, const std::string& value) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 622 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 623 | ACQUIRE_CRYPT_LOCK; |
| 624 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 625 | SLOGE("fdeSetField is no longer supported"); |
| 626 | return translate(-1); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 627 | } |
| 628 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 629 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 630 | binder::Status VoldNativeService::fdeGetPasswordType(int32_t* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 631 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 632 | ACQUIRE_CRYPT_LOCK; |
| 633 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 634 | SLOGE("fdeGetPasswordType is no longer supported"); |
| 635 | *_aidl_return = -1; |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 636 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 637 | } |
| 638 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 639 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 640 | binder::Status VoldNativeService::fdeGetPassword(std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 641 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 642 | ACQUIRE_CRYPT_LOCK; |
| 643 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 644 | SLOGE("fdeGetPassword is no longer supported"); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 645 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 646 | } |
| 647 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 648 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 649 | binder::Status VoldNativeService::fdeClearPassword() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 650 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 651 | ACQUIRE_CRYPT_LOCK; |
| 652 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 653 | SLOGE("fdeClearPassword is no longer supported"); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 654 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | binder::Status VoldNativeService::fbeEnable() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 658 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 659 | ACQUIRE_CRYPT_LOCK; |
| 660 | |
Paul Crowley | c8a3ef3 | 2019-09-11 15:00:08 -0700 | [diff] [blame] | 661 | return translateBool(fscrypt_initialize_systemwide_keys()); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 662 | } |
| 663 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 664 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 665 | binder::Status VoldNativeService::mountDefaultEncrypted() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 666 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 667 | ACQUIRE_CRYPT_LOCK; |
| 668 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 669 | SLOGE("mountDefaultEncrypted is no longer supported"); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 670 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | binder::Status VoldNativeService::initUser0() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 674 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 675 | ACQUIRE_CRYPT_LOCK; |
| 676 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 677 | return translateBool(fscrypt_init_user0()); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 678 | } |
| 679 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 680 | // TODO(b/191796797) remove this once caller is removed |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 681 | binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 682 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 683 | ACQUIRE_CRYPT_LOCK; |
| 684 | |
Eric Biggers | 0803ba0 | 2021-11-08 16:45:58 -0800 | [diff] [blame] | 685 | SLOGE("isConvertibleToFbe is no longer supported"); |
| 686 | *_aidl_return = false; |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 687 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 688 | } |
| 689 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 690 | binder::Status VoldNativeService::mountFstab(const std::string& blkDevice, |
| 691 | const std::string& mountPoint) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 692 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 693 | ACQUIRE_LOCK; |
| 694 | |
Jaegeuk Kim | 0c52c71 | 2020-12-15 09:00:49 -0800 | [diff] [blame] | 695 | return translateBool( |
| 696 | fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, false, false, "null")); |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 697 | } |
| 698 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 699 | binder::Status VoldNativeService::encryptFstab(const std::string& blkDevice, |
Jaegeuk Kim | 0c52c71 | 2020-12-15 09:00:49 -0800 | [diff] [blame] | 700 | const std::string& mountPoint, bool shouldFormat, |
| 701 | const std::string& fsType) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 702 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 703 | ACQUIRE_LOCK; |
| 704 | |
Jaegeuk Kim | 0c52c71 | 2020-12-15 09:00:49 -0800 | [diff] [blame] | 705 | return translateBool( |
| 706 | fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, true, shouldFormat, fsType)); |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 707 | } |
| 708 | |
Seth Moore | 5a43d61 | 2021-01-19 17:51:51 +0000 | [diff] [blame] | 709 | binder::Status VoldNativeService::setStorageBindingSeed(const std::vector<uint8_t>& seed) { |
| 710 | ENFORCE_SYSTEM_OR_ROOT; |
| 711 | ACQUIRE_CRYPT_LOCK; |
| 712 | |
| 713 | return translateBool(setKeyStorageBindingSeed(seed)); |
| 714 | } |
| 715 | |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 716 | binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, |
| 717 | bool ephemeral) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 718 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 719 | ACQUIRE_CRYPT_LOCK; |
| 720 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 721 | return translateBool(fscrypt_vold_create_user_key(userId, userSerial, ephemeral)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | binder::Status VoldNativeService::destroyUserKey(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 725 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 726 | ACQUIRE_CRYPT_LOCK; |
| 727 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 728 | return translateBool(fscrypt_destroy_user_key(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 729 | } |
| 730 | |
Satya Tangirala | e136171 | 2021-03-15 15:33:08 -0700 | [diff] [blame] | 731 | static bool token_empty(const std::string& token) { |
| 732 | return token.size() == 0 || token == "!"; |
| 733 | } |
| 734 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 735 | binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 736 | const std::string& token, |
| 737 | const std::string& secret) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 738 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 739 | ACQUIRE_CRYPT_LOCK; |
| 740 | |
Satya Tangirala | e136171 | 2021-03-15 15:33:08 -0700 | [diff] [blame] | 741 | if (!token_empty(token)) { |
| 742 | LOG(ERROR) << "Vold doesn't use auth tokens, but non-empty token passed to addUserKeyAuth."; |
| 743 | return binder::Status::fromServiceSpecificError(-EINVAL); |
| 744 | } |
| 745 | |
| 746 | return translateBool(fscrypt_add_user_key_auth(userId, userSerial, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 747 | } |
| 748 | |
Barani Muthukumaran | 9ad51ad | 2019-10-31 22:59:34 -0700 | [diff] [blame] | 749 | binder::Status VoldNativeService::clearUserKeyAuth(int32_t userId, int32_t userSerial, |
| 750 | const std::string& token, |
| 751 | const std::string& secret) { |
| 752 | ENFORCE_SYSTEM_OR_ROOT; |
| 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) |
| 757 | << "Vold doesn't use auth tokens, but non-empty token passed to clearUserKeyAuth."; |
| 758 | return binder::Status::fromServiceSpecificError(-EINVAL); |
| 759 | } |
| 760 | |
| 761 | return translateBool(fscrypt_clear_user_key_auth(userId, userSerial, secret)); |
Barani Muthukumaran | 9ad51ad | 2019-10-31 22:59:34 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 764 | binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 765 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 766 | ACQUIRE_CRYPT_LOCK; |
| 767 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 768 | return translateBool(fscrypt_fixate_newest_user_key_auth(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 769 | } |
| 770 | |
Eric Biggers | 1799deb | 2021-04-06 12:02:56 -0700 | [diff] [blame] | 771 | binder::Status VoldNativeService::getUnlockedUsers(std::vector<int>* _aidl_return) { |
| 772 | ENFORCE_SYSTEM_OR_ROOT; |
| 773 | ACQUIRE_CRYPT_LOCK; |
| 774 | |
| 775 | *_aidl_return = fscrypt_get_unlocked_users(); |
| 776 | return Ok(); |
| 777 | } |
| 778 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 779 | binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 780 | const std::string& token, |
| 781 | const std::string& secret) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 782 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 783 | ACQUIRE_CRYPT_LOCK; |
| 784 | |
Satya Tangirala | e136171 | 2021-03-15 15:33:08 -0700 | [diff] [blame] | 785 | if (!token_empty(token)) { |
| 786 | LOG(ERROR) << "Vold doesn't use auth tokens, but non-empty token passed to unlockUserKey."; |
| 787 | return binder::Status::fromServiceSpecificError(-EINVAL); |
| 788 | } |
| 789 | |
| 790 | return translateBool(fscrypt_unlock_user_key(userId, userSerial, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | binder::Status VoldNativeService::lockUserKey(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 794 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 795 | ACQUIRE_CRYPT_LOCK; |
| 796 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 797 | return translateBool(fscrypt_lock_user_key(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 798 | } |
| 799 | |
Jooyung Han | 4fcb707 | 2020-01-23 13:23:26 +0900 | [diff] [blame] | 800 | binder::Status VoldNativeService::prepareUserStorage(const std::optional<std::string>& uuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 801 | int32_t userId, int32_t userSerial, |
| 802 | int32_t flags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 803 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 804 | std::string empty_string = ""; |
| 805 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 806 | CHECK_ARGUMENT_HEX(uuid_); |
| 807 | |
| 808 | ACQUIRE_CRYPT_LOCK; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 809 | return translateBool(fscrypt_prepare_user_storage(uuid_, userId, userSerial, flags)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 810 | } |
| 811 | |
Jooyung Han | 4fcb707 | 2020-01-23 13:23:26 +0900 | [diff] [blame] | 812 | binder::Status VoldNativeService::destroyUserStorage(const std::optional<std::string>& uuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 813 | int32_t userId, int32_t flags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 814 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 815 | std::string empty_string = ""; |
| 816 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 817 | CHECK_ARGUMENT_HEX(uuid_); |
| 818 | |
| 819 | ACQUIRE_CRYPT_LOCK; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 820 | return translateBool(fscrypt_destroy_user_storage(uuid_, userId, flags)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 821 | } |
| 822 | |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 823 | binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packageName, |
| 824 | int32_t appId, const std::string& sandboxId, |
| 825 | int32_t userId) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 826 | return Ok(); |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName, |
Sudheer Shanka | 69bc40f | 2018-10-25 11:06:55 -0700 | [diff] [blame] | 830 | const std::string& sandboxId, |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 831 | int32_t userId) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 832 | return Ok(); |
Sudheer Shanka | c756209 | 2018-08-24 10:20:56 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 835 | binder::Status VoldNativeService::startCheckpoint(int32_t retry) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 836 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 837 | ACQUIRE_LOCK; |
| 838 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 839 | return cp_startCheckpoint(retry); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 842 | binder::Status VoldNativeService::needsRollback(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 843 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 844 | ACQUIRE_LOCK; |
| 845 | |
| 846 | *_aidl_return = cp_needsRollback(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 847 | return Ok(); |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 848 | } |
| 849 | |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 850 | binder::Status VoldNativeService::needsCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 851 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 852 | ACQUIRE_LOCK; |
| 853 | |
| 854 | *_aidl_return = cp_needsCheckpoint(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 855 | return Ok(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 856 | } |
| 857 | |
David Anderson | 23850d3 | 2020-06-10 23:51:17 -0700 | [diff] [blame] | 858 | binder::Status VoldNativeService::isCheckpointing(bool* _aidl_return) { |
| 859 | ENFORCE_SYSTEM_OR_ROOT; |
| 860 | ACQUIRE_LOCK; |
| 861 | |
| 862 | *_aidl_return = cp_isCheckpointing(); |
| 863 | return Ok(); |
| 864 | } |
| 865 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 866 | binder::Status VoldNativeService::commitChanges() { |
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_commitChanges(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 871 | } |
| 872 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 873 | binder::Status VoldNativeService::prepareCheckpoint() { |
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 | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 877 | return cp_prepareCheckpoint(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 880 | binder::Status VoldNativeService::restoreCheckpoint(const std::string& mountPoint) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 881 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | 1abb2fe | 2018-09-21 10:49:57 -0700 | [diff] [blame] | 882 | CHECK_ARGUMENT_PATH(mountPoint); |
| 883 | ACQUIRE_LOCK; |
| 884 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 885 | return cp_restoreCheckpoint(mountPoint); |
Paul Lawrence | 1abb2fe | 2018-09-21 10:49:57 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Daniel Rosenberg | dda5981 | 2019-03-06 17:45:17 -0800 | [diff] [blame] | 888 | binder::Status VoldNativeService::restoreCheckpointPart(const std::string& mountPoint, int count) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 889 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | dda5981 | 2019-03-06 17:45:17 -0800 | [diff] [blame] | 890 | CHECK_ARGUMENT_PATH(mountPoint); |
| 891 | ACQUIRE_LOCK; |
| 892 | |
| 893 | return cp_restoreCheckpoint(mountPoint, count); |
| 894 | } |
| 895 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 896 | binder::Status VoldNativeService::markBootAttempt() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 897 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 898 | ACQUIRE_LOCK; |
| 899 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 900 | return cp_markBootAttempt(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 901 | } |
| 902 | |
Daniel Rosenberg | a59e439 | 2019-03-20 17:02:47 -0700 | [diff] [blame] | 903 | binder::Status VoldNativeService::abortChanges(const std::string& message, bool retry) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 904 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 905 | ACQUIRE_LOCK; |
| 906 | |
Daniel Rosenberg | a59e439 | 2019-03-20 17:02:47 -0700 | [diff] [blame] | 907 | cp_abortChanges(message, retry); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 908 | return Ok(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Daniel Rosenberg | 9b667fb | 2019-01-22 17:27:25 -0800 | [diff] [blame] | 911 | binder::Status VoldNativeService::supportsCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 912 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 9b667fb | 2019-01-22 17:27:25 -0800 | [diff] [blame] | 913 | ACQUIRE_LOCK; |
| 914 | |
| 915 | return cp_supportsCheckpoint(*_aidl_return); |
| 916 | } |
| 917 | |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 918 | binder::Status VoldNativeService::supportsBlockCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 919 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 920 | ACQUIRE_LOCK; |
| 921 | |
| 922 | return cp_supportsBlockCheckpoint(*_aidl_return); |
| 923 | } |
| 924 | |
| 925 | binder::Status VoldNativeService::supportsFileCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 926 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 927 | ACQUIRE_LOCK; |
| 928 | |
| 929 | return cp_supportsFileCheckpoint(*_aidl_return); |
| 930 | } |
| 931 | |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 932 | binder::Status VoldNativeService::resetCheckpoint() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 933 | ENFORCE_SYSTEM_OR_ROOT; |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 934 | ACQUIRE_LOCK; |
| 935 | |
| 936 | cp_resetCheckpoint(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 937 | return Ok(); |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 938 | } |
| 939 | |
Alex Buynytskyy | b02e7b6 | 2021-02-11 19:09:10 -0800 | [diff] [blame] | 940 | static void initializeIncFs() { |
| 941 | // Obtaining IncFS features triggers initialization of IncFS. |
| 942 | incfs::features(); |
| 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 | |
Alex Buynytskyy | b02e7b6 | 2021-02-11 19:09:10 -0800 | [diff] [blame] | 949 | initializeIncFs(); |
Eric Biggers | d86a8ab | 2021-06-15 11:34:00 -0700 | [diff] [blame] | 950 | Keystore::earlyBootEnded(); |
Martijn Coenen | eed957f | 2020-11-12 10:59:13 +0100 | [diff] [blame] | 951 | return Ok(); |
| 952 | } |
| 953 | |
Yurii Zubrytskyi | 3497cb5 | 2020-01-10 11:54:06 -0800 | [diff] [blame] | 954 | binder::Status VoldNativeService::incFsEnabled(bool* _aidl_return) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 955 | ENFORCE_SYSTEM_OR_ROOT; |
| 956 | |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 957 | *_aidl_return = incfs::enabled(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 958 | return Ok(); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | binder::Status VoldNativeService::mountIncFs( |
Yurii Zubrytskyi | 3497cb5 | 2020-01-10 11:54:06 -0800 | [diff] [blame] | 962 | const std::string& backingPath, const std::string& targetDir, int32_t flags, |
Songchun Fan | 046e68a | 2021-04-27 12:46:02 -0700 | [diff] [blame] | 963 | const std::string& sysfsName, |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 964 | ::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 965 | ENFORCE_SYSTEM_OR_ROOT; |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 966 | if (auto status = CheckIncrementalPath(IncrementalPathKind::MountTarget, targetDir); |
| 967 | !status.isOk()) { |
| 968 | return status; |
| 969 | } |
| 970 | if (auto status = CheckIncrementalPath(IncrementalPathKind::MountSource, backingPath); |
| 971 | !status.isOk()) { |
| 972 | return status; |
| 973 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 974 | |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 975 | auto [backingFd, backingSymlink] = OpenDirInProcfs(backingPath); |
| 976 | if (!backingFd.ok()) { |
| 977 | return translate(-errno); |
| 978 | } |
| 979 | auto [targetFd, targetSymlink] = OpenDirInProcfs(targetDir); |
| 980 | if (!targetFd.ok()) { |
| 981 | return translate(-errno); |
| 982 | } |
| 983 | |
| 984 | auto control = incfs::mount(backingSymlink, targetSymlink, |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 985 | {.flags = IncFsMountFlags(flags), |
Alex Buynytskyy | dcfeaa1 | 2021-04-01 13:43:14 -0700 | [diff] [blame] | 986 | // Mount with read timeouts. |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 987 | .defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS, |
| 988 | // Mount with read logs disabled. |
Songchun Fan | 046e68a | 2021-04-27 12:46:02 -0700 | [diff] [blame] | 989 | .readLogBufferPages = 0, |
| 990 | .sysfsName = sysfsName.c_str()}); |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 991 | if (!control) { |
| 992 | return translate(-errno); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 993 | } |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 994 | auto fds = control.releaseFds(); |
| 995 | using android::base::unique_fd; |
| 996 | _aidl_return->cmd.reset(unique_fd(fds[CMD].release())); |
| 997 | _aidl_return->pendingReads.reset(unique_fd(fds[PENDING_READS].release())); |
| 998 | _aidl_return->log.reset(unique_fd(fds[LOGS].release())); |
Yurii Zubrytskyi | 0c0f839 | 2020-12-08 07:33:37 -0800 | [diff] [blame] | 999 | if (fds[BLOCKS_WRITTEN].ok()) { |
| 1000 | _aidl_return->blocksWritten.emplace(unique_fd(fds[BLOCKS_WRITTEN].release())); |
| 1001 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 1002 | return Ok(); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | binder::Status VoldNativeService::unmountIncFs(const std::string& dir) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 1006 | ENFORCE_SYSTEM_OR_ROOT; |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 1007 | if (auto status = CheckIncrementalPath(IncrementalPathKind::Any, dir); !status.isOk()) { |
| 1008 | return status; |
| 1009 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 1010 | |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 1011 | auto [fd, symLink] = OpenDirInProcfs(dir); |
| 1012 | if (!fd.ok()) { |
| 1013 | return translate(-errno); |
| 1014 | } |
| 1015 | return translate(incfs::unmount(symLink)); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 1016 | } |
| 1017 | |
Alex Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 1018 | binder::Status VoldNativeService::setIncFsMountOptions( |
| 1019 | const ::android::os::incremental::IncrementalFileSystemControlParcel& control, |
Songchun Fan | 0e53c1c | 2021-05-10 16:19:38 -0700 | [diff] [blame] | 1020 | bool enableReadLogs, bool enableReadTimeouts, const std::string& sysfsName) { |
Alex Buynytskyy | 605a44f | 2020-04-02 15:21:47 -0700 | [diff] [blame] | 1021 | ENFORCE_SYSTEM_OR_ROOT; |
Alex Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 1022 | |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 1023 | auto incfsControl = |
Yurii Zubrytskyi | 0c0f839 | 2020-12-08 07:33:37 -0800 | [diff] [blame] | 1024 | incfs::createControl(control.cmd.get(), control.pendingReads.get(), control.log.get(), |
| 1025 | control.blocksWritten ? control.blocksWritten->get() : -1); |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 1026 | auto cleanupFunc = [](auto incfsControl) { |
| 1027 | for (auto& fd : incfsControl->releaseFds()) { |
| 1028 | (void)fd.release(); |
| 1029 | } |
| 1030 | }; |
| 1031 | auto cleanup = |
| 1032 | std::unique_ptr<incfs::Control, decltype(cleanupFunc)>(&incfsControl, cleanupFunc); |
Alex Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 1033 | |
Yurii Zubrytskyi | 1d7acfd | 2021-10-28 14:37:12 -0700 | [diff] [blame] | 1034 | constexpr auto minReadLogBufferPages = INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES; |
| 1035 | constexpr auto maxReadLogBufferPages = 8 * INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES; |
| 1036 | auto options = incfs::MountOptions{ |
| 1037 | .defaultReadTimeoutMs = |
| 1038 | enableReadTimeouts ? INCFS_DEFAULT_READ_TIMEOUT_MS : kIncFsReadNoTimeoutMs, |
| 1039 | .readLogBufferPages = enableReadLogs ? maxReadLogBufferPages : 0, |
| 1040 | .sysfsName = sysfsName.c_str()}; |
| 1041 | |
| 1042 | for (;;) { |
| 1043 | const auto error = incfs::setOptions(incfsControl, options); |
| 1044 | if (!error) { |
| 1045 | return Ok(); |
| 1046 | } |
| 1047 | if (!enableReadLogs || error != -ENOMEM) { |
| 1048 | return binder::Status::fromServiceSpecificError(error); |
| 1049 | } |
| 1050 | // In case of memory allocation error retry with a smaller buffer. |
| 1051 | options.readLogBufferPages /= 2; |
| 1052 | if (options.readLogBufferPages < minReadLogBufferPages) { |
| 1053 | return binder::Status::fromServiceSpecificError(error); |
| 1054 | } |
| 1055 | } |
| 1056 | // unreachable, but makes the compiler happy |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 1057 | return Ok(); |
Alex Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 1060 | binder::Status VoldNativeService::bindMount(const std::string& sourceDir, |
| 1061 | const std::string& targetDir) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 1062 | ENFORCE_SYSTEM_OR_ROOT; |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 1063 | if (auto status = CheckIncrementalPath(IncrementalPathKind::Any, sourceDir); !status.isOk()) { |
| 1064 | return status; |
| 1065 | } |
| 1066 | if (auto status = CheckIncrementalPath(IncrementalPathKind::Bind, targetDir); !status.isOk()) { |
| 1067 | return status; |
| 1068 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 1069 | |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 1070 | auto [sourceFd, sourceSymlink] = OpenDirInProcfs(sourceDir); |
| 1071 | if (!sourceFd.ok()) { |
| 1072 | return translate(-errno); |
| 1073 | } |
| 1074 | auto [targetFd, targetSymlink] = OpenDirInProcfs(targetDir); |
| 1075 | if (!targetFd.ok()) { |
| 1076 | return translate(-errno); |
| 1077 | } |
| 1078 | return translate(incfs::bindMount(sourceSymlink, targetSymlink)); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 1079 | } |
| 1080 | |
Yo Chiang | 0af25a3 | 2020-10-07 14:20:00 +0800 | [diff] [blame] | 1081 | binder::Status VoldNativeService::destroyDsuMetadataKey(const std::string& dsuSlot) { |
| 1082 | ENFORCE_SYSTEM_OR_ROOT; |
| 1083 | ACQUIRE_LOCK; |
| 1084 | |
| 1085 | return translateBool(destroy_dsu_metadata_key(dsuSlot)); |
| 1086 | } |
| 1087 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 1088 | } // namespace vold |
| 1089 | } // namespace android |