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, |
Daeho Jeong | 7c788fc | 2022-03-18 12:24:41 -0700 | [diff] [blame] | 497 | float dirtyReclaimRate, float reclaimWeight, |
Daeho Jeong | 3f8e855 | 2022-06-24 14:50:47 -0700 | [diff] [blame] | 498 | int32_t gcPeriod, int32_t minGCSleepTime, |
| 499 | int32_t targetDirtyRatio) { |
Daeho Jeong | 999fceb | 2022-01-04 11:37:39 -0800 | [diff] [blame] | 500 | ENFORCE_SYSTEM_OR_ROOT; |
| 501 | ACQUIRE_LOCK; |
| 502 | |
Daeho Jeong | a26a56a | 2022-06-23 16:19:58 -0700 | [diff] [blame] | 503 | SetGCUrgentPace(neededSegments, minSegmentThreshold, dirtyReclaimRate, reclaimWeight, gcPeriod, |
Daeho Jeong | 3f8e855 | 2022-06-24 14:50:47 -0700 | [diff] [blame] | 504 | minGCSleepTime, targetDirtyRatio); |
Daeho Jeong | 999fceb | 2022-01-04 11:37:39 -0800 | [diff] [blame] | 505 | return Ok(); |
| 506 | } |
| 507 | |
| 508 | binder::Status VoldNativeService::refreshLatestWrite() { |
| 509 | ENFORCE_SYSTEM_OR_ROOT; |
| 510 | ACQUIRE_LOCK; |
| 511 | |
| 512 | RefreshLatestWrite(); |
| 513 | return Ok(); |
| 514 | } |
| 515 | |
| 516 | binder::Status VoldNativeService::getWriteAmount(int32_t* _aidl_return) { |
| 517 | ENFORCE_SYSTEM_OR_ROOT; |
| 518 | ACQUIRE_LOCK; |
| 519 | |
| 520 | *_aidl_return = GetWriteAmount(); |
| 521 | return Ok(); |
| 522 | } |
| 523 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 524 | binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t mountId, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 525 | android::base::unique_fd* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 526 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 527 | ACQUIRE_LOCK; |
| 528 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 529 | return translate(VolumeManager::Instance()->mountAppFuse(uid, mountId, _aidl_return)); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 530 | } |
| 531 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 532 | binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t mountId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 533 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 534 | ACQUIRE_LOCK; |
| 535 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 536 | return translate(VolumeManager::Instance()->unmountAppFuse(uid, mountId)); |
| 537 | } |
| 538 | |
| 539 | binder::Status VoldNativeService::openAppFuseFile(int32_t uid, int32_t mountId, int32_t fileId, |
| 540 | int32_t flags, |
| 541 | android::base::unique_fd* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 542 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 543 | ACQUIRE_LOCK; |
| 544 | |
| 545 | int fd = VolumeManager::Instance()->openAppFuseFile(uid, mountId, fileId, flags); |
| 546 | if (fd == -1) { |
| 547 | return error("Failed to open AppFuse file for uid: " + std::to_string(uid) + |
| 548 | " mountId: " + std::to_string(mountId) + " fileId: " + std::to_string(fileId) + |
| 549 | " flags: " + std::to_string(flags)); |
| 550 | } |
| 551 | |
| 552 | *_aidl_return = android::base::unique_fd(fd); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 553 | return Ok(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 554 | } |
| 555 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 556 | binder::Status VoldNativeService::fbeEnable() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 557 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 558 | ACQUIRE_CRYPT_LOCK; |
| 559 | |
Paul Crowley | c8a3ef3 | 2019-09-11 15:00:08 -0700 | [diff] [blame] | 560 | return translateBool(fscrypt_initialize_systemwide_keys()); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 561 | } |
| 562 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 563 | binder::Status VoldNativeService::initUser0() { |
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 | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 567 | return translateBool(fscrypt_init_user0()); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 568 | } |
| 569 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 570 | binder::Status VoldNativeService::mountFstab(const std::string& blkDevice, |
| 571 | const std::string& mountPoint) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 572 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 573 | ACQUIRE_LOCK; |
| 574 | |
Jaegeuk Kim | 0c52c71 | 2020-12-15 09:00:49 -0800 | [diff] [blame] | 575 | return translateBool( |
| 576 | fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, false, false, "null")); |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 577 | } |
| 578 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 579 | binder::Status VoldNativeService::encryptFstab(const std::string& blkDevice, |
Jaegeuk Kim | 0c52c71 | 2020-12-15 09:00:49 -0800 | [diff] [blame] | 580 | const std::string& mountPoint, bool shouldFormat, |
| 581 | const std::string& fsType) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 582 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 583 | ACQUIRE_LOCK; |
| 584 | |
Jaegeuk Kim | 0c52c71 | 2020-12-15 09:00:49 -0800 | [diff] [blame] | 585 | return translateBool( |
| 586 | fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, true, shouldFormat, fsType)); |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 587 | } |
| 588 | |
Seth Moore | 5a43d61 | 2021-01-19 17:51:51 +0000 | [diff] [blame] | 589 | binder::Status VoldNativeService::setStorageBindingSeed(const std::vector<uint8_t>& seed) { |
| 590 | ENFORCE_SYSTEM_OR_ROOT; |
| 591 | ACQUIRE_CRYPT_LOCK; |
| 592 | |
| 593 | return translateBool(setKeyStorageBindingSeed(seed)); |
| 594 | } |
| 595 | |
Songchun Fan | 01c4e91 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 596 | binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, |
| 597 | bool ephemeral) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 598 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 599 | ACQUIRE_CRYPT_LOCK; |
| 600 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 601 | return translateBool(fscrypt_vold_create_user_key(userId, userSerial, ephemeral)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | binder::Status VoldNativeService::destroyUserKey(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 605 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 606 | ACQUIRE_CRYPT_LOCK; |
| 607 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 608 | return translateBool(fscrypt_destroy_user_key(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 612 | const std::string& secret) { |
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 | |
Satya Tangirala | e136171 | 2021-03-15 15:33:08 -0700 | [diff] [blame] | 616 | return translateBool(fscrypt_add_user_key_auth(userId, userSerial, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 617 | } |
| 618 | |
Barani Muthukumaran | 9ad51ad | 2019-10-31 22:59:34 -0700 | [diff] [blame] | 619 | binder::Status VoldNativeService::clearUserKeyAuth(int32_t userId, int32_t userSerial, |
Barani Muthukumaran | 9ad51ad | 2019-10-31 22:59:34 -0700 | [diff] [blame] | 620 | const std::string& secret) { |
| 621 | ENFORCE_SYSTEM_OR_ROOT; |
| 622 | ACQUIRE_CRYPT_LOCK; |
| 623 | |
Satya Tangirala | e136171 | 2021-03-15 15:33:08 -0700 | [diff] [blame] | 624 | return translateBool(fscrypt_clear_user_key_auth(userId, userSerial, secret)); |
Barani Muthukumaran | 9ad51ad | 2019-10-31 22:59:34 -0700 | [diff] [blame] | 625 | } |
| 626 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 627 | binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) { |
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 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 631 | return translateBool(fscrypt_fixate_newest_user_key_auth(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 632 | } |
| 633 | |
Eric Biggers | 1799deb | 2021-04-06 12:02:56 -0700 | [diff] [blame] | 634 | binder::Status VoldNativeService::getUnlockedUsers(std::vector<int>* _aidl_return) { |
| 635 | ENFORCE_SYSTEM_OR_ROOT; |
| 636 | ACQUIRE_CRYPT_LOCK; |
| 637 | |
| 638 | *_aidl_return = fscrypt_get_unlocked_users(); |
| 639 | return Ok(); |
| 640 | } |
| 641 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 642 | binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 643 | const std::string& secret) { |
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 | |
Satya Tangirala | e136171 | 2021-03-15 15:33:08 -0700 | [diff] [blame] | 647 | return translateBool(fscrypt_unlock_user_key(userId, userSerial, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | binder::Status VoldNativeService::lockUserKey(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 651 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 652 | ACQUIRE_CRYPT_LOCK; |
| 653 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 654 | return translateBool(fscrypt_lock_user_key(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 655 | } |
| 656 | |
Jooyung Han | 4fcb707 | 2020-01-23 13:23:26 +0900 | [diff] [blame] | 657 | binder::Status VoldNativeService::prepareUserStorage(const std::optional<std::string>& uuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 658 | int32_t userId, int32_t userSerial, |
| 659 | int32_t flags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 660 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 661 | std::string empty_string = ""; |
| 662 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 663 | CHECK_ARGUMENT_HEX(uuid_); |
| 664 | |
| 665 | ACQUIRE_CRYPT_LOCK; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 666 | return translateBool(fscrypt_prepare_user_storage(uuid_, userId, userSerial, flags)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 667 | } |
| 668 | |
Jooyung Han | 4fcb707 | 2020-01-23 13:23:26 +0900 | [diff] [blame] | 669 | binder::Status VoldNativeService::destroyUserStorage(const std::optional<std::string>& uuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 670 | int32_t userId, int32_t flags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 671 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 672 | std::string empty_string = ""; |
| 673 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 674 | CHECK_ARGUMENT_HEX(uuid_); |
| 675 | |
| 676 | ACQUIRE_CRYPT_LOCK; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 677 | return translateBool(fscrypt_destroy_user_storage(uuid_, userId, flags)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 678 | } |
| 679 | |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 680 | binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packageName, |
| 681 | int32_t appId, const std::string& sandboxId, |
| 682 | int32_t userId) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 683 | return Ok(); |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName, |
Sudheer Shanka | 69bc40f | 2018-10-25 11:06:55 -0700 | [diff] [blame] | 687 | const std::string& sandboxId, |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 688 | int32_t userId) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 689 | return Ok(); |
Sudheer Shanka | c756209 | 2018-08-24 10:20:56 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 692 | binder::Status VoldNativeService::startCheckpoint(int32_t retry) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 693 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 694 | ACQUIRE_LOCK; |
| 695 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 696 | return cp_startCheckpoint(retry); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 699 | binder::Status VoldNativeService::needsRollback(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 700 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 701 | ACQUIRE_LOCK; |
| 702 | |
| 703 | *_aidl_return = cp_needsRollback(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 704 | return Ok(); |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 707 | binder::Status VoldNativeService::needsCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 708 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 709 | ACQUIRE_LOCK; |
| 710 | |
| 711 | *_aidl_return = cp_needsCheckpoint(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 712 | return Ok(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 713 | } |
| 714 | |
David Anderson | 23850d3 | 2020-06-10 23:51:17 -0700 | [diff] [blame] | 715 | binder::Status VoldNativeService::isCheckpointing(bool* _aidl_return) { |
| 716 | ENFORCE_SYSTEM_OR_ROOT; |
| 717 | ACQUIRE_LOCK; |
| 718 | |
| 719 | *_aidl_return = cp_isCheckpointing(); |
| 720 | return Ok(); |
| 721 | } |
| 722 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 723 | binder::Status VoldNativeService::commitChanges() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 724 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 725 | ACQUIRE_LOCK; |
| 726 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 727 | return cp_commitChanges(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 730 | binder::Status VoldNativeService::prepareCheckpoint() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 731 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 732 | ACQUIRE_LOCK; |
| 733 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 734 | return cp_prepareCheckpoint(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 737 | binder::Status VoldNativeService::restoreCheckpoint(const std::string& mountPoint) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 738 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | 1abb2fe | 2018-09-21 10:49:57 -0700 | [diff] [blame] | 739 | CHECK_ARGUMENT_PATH(mountPoint); |
| 740 | ACQUIRE_LOCK; |
| 741 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 742 | return cp_restoreCheckpoint(mountPoint); |
Paul Lawrence | 1abb2fe | 2018-09-21 10:49:57 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Daniel Rosenberg | dda5981 | 2019-03-06 17:45:17 -0800 | [diff] [blame] | 745 | binder::Status VoldNativeService::restoreCheckpointPart(const std::string& mountPoint, int count) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 746 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | dda5981 | 2019-03-06 17:45:17 -0800 | [diff] [blame] | 747 | CHECK_ARGUMENT_PATH(mountPoint); |
| 748 | ACQUIRE_LOCK; |
| 749 | |
| 750 | return cp_restoreCheckpoint(mountPoint, count); |
| 751 | } |
| 752 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 753 | binder::Status VoldNativeService::markBootAttempt() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 754 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 755 | ACQUIRE_LOCK; |
| 756 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 757 | return cp_markBootAttempt(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Daniel Rosenberg | a59e439 | 2019-03-20 17:02:47 -0700 | [diff] [blame] | 760 | binder::Status VoldNativeService::abortChanges(const std::string& message, bool retry) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 761 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 762 | ACQUIRE_LOCK; |
| 763 | |
Daniel Rosenberg | a59e439 | 2019-03-20 17:02:47 -0700 | [diff] [blame] | 764 | cp_abortChanges(message, retry); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 765 | return Ok(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Daniel Rosenberg | 9b667fb | 2019-01-22 17:27:25 -0800 | [diff] [blame] | 768 | binder::Status VoldNativeService::supportsCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 769 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 9b667fb | 2019-01-22 17:27:25 -0800 | [diff] [blame] | 770 | ACQUIRE_LOCK; |
| 771 | |
| 772 | return cp_supportsCheckpoint(*_aidl_return); |
| 773 | } |
| 774 | |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 775 | binder::Status VoldNativeService::supportsBlockCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 776 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 777 | ACQUIRE_LOCK; |
| 778 | |
| 779 | return cp_supportsBlockCheckpoint(*_aidl_return); |
| 780 | } |
| 781 | |
| 782 | binder::Status VoldNativeService::supportsFileCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 783 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 784 | ACQUIRE_LOCK; |
| 785 | |
| 786 | return cp_supportsFileCheckpoint(*_aidl_return); |
| 787 | } |
| 788 | |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 789 | binder::Status VoldNativeService::resetCheckpoint() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 790 | ENFORCE_SYSTEM_OR_ROOT; |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 791 | ACQUIRE_LOCK; |
| 792 | |
| 793 | cp_resetCheckpoint(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 794 | return Ok(); |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 795 | } |
| 796 | |
Alex Buynytskyy | b02e7b6 | 2021-02-11 19:09:10 -0800 | [diff] [blame] | 797 | static void initializeIncFs() { |
| 798 | // Obtaining IncFS features triggers initialization of IncFS. |
| 799 | incfs::features(); |
| 800 | } |
| 801 | |
Martijn Coenen | eed957f | 2020-11-12 10:59:13 +0100 | [diff] [blame] | 802 | binder::Status VoldNativeService::earlyBootEnded() { |
| 803 | ENFORCE_SYSTEM_OR_ROOT; |
| 804 | ACQUIRE_LOCK; |
| 805 | |
Alex Buynytskyy | b02e7b6 | 2021-02-11 19:09:10 -0800 | [diff] [blame] | 806 | initializeIncFs(); |
Eric Biggers | d86a8ab | 2021-06-15 11:34:00 -0700 | [diff] [blame] | 807 | Keystore::earlyBootEnded(); |
Martijn Coenen | eed957f | 2020-11-12 10:59:13 +0100 | [diff] [blame] | 808 | return Ok(); |
| 809 | } |
| 810 | |
Yurii Zubrytskyi | 3497cb5 | 2020-01-10 11:54:06 -0800 | [diff] [blame] | 811 | binder::Status VoldNativeService::incFsEnabled(bool* _aidl_return) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 812 | ENFORCE_SYSTEM_OR_ROOT; |
| 813 | |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 814 | *_aidl_return = incfs::enabled(); |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 815 | return Ok(); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | binder::Status VoldNativeService::mountIncFs( |
Yurii Zubrytskyi | 3497cb5 | 2020-01-10 11:54:06 -0800 | [diff] [blame] | 819 | const std::string& backingPath, const std::string& targetDir, int32_t flags, |
Songchun Fan | 046e68a | 2021-04-27 12:46:02 -0700 | [diff] [blame] | 820 | const std::string& sysfsName, |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 821 | ::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 822 | ENFORCE_SYSTEM_OR_ROOT; |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 823 | if (auto status = CheckIncrementalPath(IncrementalPathKind::MountTarget, targetDir); |
| 824 | !status.isOk()) { |
| 825 | return status; |
| 826 | } |
| 827 | if (auto status = CheckIncrementalPath(IncrementalPathKind::MountSource, backingPath); |
| 828 | !status.isOk()) { |
| 829 | return status; |
| 830 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 831 | |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 832 | auto [backingFd, backingSymlink] = OpenDirInProcfs(backingPath); |
| 833 | if (!backingFd.ok()) { |
| 834 | return translate(-errno); |
| 835 | } |
| 836 | auto [targetFd, targetSymlink] = OpenDirInProcfs(targetDir); |
| 837 | if (!targetFd.ok()) { |
| 838 | return translate(-errno); |
| 839 | } |
| 840 | |
| 841 | auto control = incfs::mount(backingSymlink, targetSymlink, |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 842 | {.flags = IncFsMountFlags(flags), |
Alex Buynytskyy | dcfeaa1 | 2021-04-01 13:43:14 -0700 | [diff] [blame] | 843 | // Mount with read timeouts. |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 844 | .defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS, |
| 845 | // Mount with read logs disabled. |
Songchun Fan | 046e68a | 2021-04-27 12:46:02 -0700 | [diff] [blame] | 846 | .readLogBufferPages = 0, |
| 847 | .sysfsName = sysfsName.c_str()}); |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 848 | if (!control) { |
| 849 | return translate(-errno); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 850 | } |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 851 | auto fds = control.releaseFds(); |
| 852 | using android::base::unique_fd; |
| 853 | _aidl_return->cmd.reset(unique_fd(fds[CMD].release())); |
| 854 | _aidl_return->pendingReads.reset(unique_fd(fds[PENDING_READS].release())); |
| 855 | _aidl_return->log.reset(unique_fd(fds[LOGS].release())); |
Yurii Zubrytskyi | 0c0f839 | 2020-12-08 07:33:37 -0800 | [diff] [blame] | 856 | if (fds[BLOCKS_WRITTEN].ok()) { |
| 857 | _aidl_return->blocksWritten.emplace(unique_fd(fds[BLOCKS_WRITTEN].release())); |
| 858 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 859 | return Ok(); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | binder::Status VoldNativeService::unmountIncFs(const std::string& dir) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 863 | ENFORCE_SYSTEM_OR_ROOT; |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 864 | if (auto status = CheckIncrementalPath(IncrementalPathKind::Any, dir); !status.isOk()) { |
| 865 | return status; |
| 866 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 867 | |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 868 | auto [fd, symLink] = OpenDirInProcfs(dir); |
| 869 | if (!fd.ok()) { |
| 870 | return translate(-errno); |
| 871 | } |
| 872 | return translate(incfs::unmount(symLink)); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 873 | } |
| 874 | |
Alex Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 875 | binder::Status VoldNativeService::setIncFsMountOptions( |
| 876 | const ::android::os::incremental::IncrementalFileSystemControlParcel& control, |
Songchun Fan | 0e53c1c | 2021-05-10 16:19:38 -0700 | [diff] [blame] | 877 | bool enableReadLogs, bool enableReadTimeouts, const std::string& sysfsName) { |
Alex Buynytskyy | 605a44f | 2020-04-02 15:21:47 -0700 | [diff] [blame] | 878 | ENFORCE_SYSTEM_OR_ROOT; |
Alex Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 879 | |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 880 | auto incfsControl = |
Yurii Zubrytskyi | 0c0f839 | 2020-12-08 07:33:37 -0800 | [diff] [blame] | 881 | incfs::createControl(control.cmd.get(), control.pendingReads.get(), control.log.get(), |
| 882 | control.blocksWritten ? control.blocksWritten->get() : -1); |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 883 | auto cleanupFunc = [](auto incfsControl) { |
| 884 | for (auto& fd : incfsControl->releaseFds()) { |
| 885 | (void)fd.release(); |
| 886 | } |
| 887 | }; |
| 888 | auto cleanup = |
| 889 | std::unique_ptr<incfs::Control, decltype(cleanupFunc)>(&incfsControl, cleanupFunc); |
Alex Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 890 | |
Yurii Zubrytskyi | 1d7acfd | 2021-10-28 14:37:12 -0700 | [diff] [blame] | 891 | constexpr auto minReadLogBufferPages = INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES; |
| 892 | constexpr auto maxReadLogBufferPages = 8 * INCFS_DEFAULT_PAGE_READ_BUFFER_PAGES; |
| 893 | auto options = incfs::MountOptions{ |
| 894 | .defaultReadTimeoutMs = |
| 895 | enableReadTimeouts ? INCFS_DEFAULT_READ_TIMEOUT_MS : kIncFsReadNoTimeoutMs, |
| 896 | .readLogBufferPages = enableReadLogs ? maxReadLogBufferPages : 0, |
| 897 | .sysfsName = sysfsName.c_str()}; |
| 898 | |
| 899 | for (;;) { |
| 900 | const auto error = incfs::setOptions(incfsControl, options); |
| 901 | if (!error) { |
| 902 | return Ok(); |
| 903 | } |
| 904 | if (!enableReadLogs || error != -ENOMEM) { |
| 905 | return binder::Status::fromServiceSpecificError(error); |
| 906 | } |
| 907 | // In case of memory allocation error retry with a smaller buffer. |
| 908 | options.readLogBufferPages /= 2; |
| 909 | if (options.readLogBufferPages < minReadLogBufferPages) { |
| 910 | return binder::Status::fromServiceSpecificError(error); |
| 911 | } |
| 912 | } |
| 913 | // unreachable, but makes the compiler happy |
Yurii Zubrytskyi | fc7b669 | 2020-04-22 23:23:24 -0700 | [diff] [blame] | 914 | return Ok(); |
Alex Buynytskyy | 91e0bf4 | 2020-03-31 14:46:25 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 917 | binder::Status VoldNativeService::bindMount(const std::string& sourceDir, |
| 918 | const std::string& targetDir) { |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 919 | ENFORCE_SYSTEM_OR_ROOT; |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 920 | if (auto status = CheckIncrementalPath(IncrementalPathKind::Any, sourceDir); !status.isOk()) { |
| 921 | return status; |
| 922 | } |
| 923 | if (auto status = CheckIncrementalPath(IncrementalPathKind::Bind, targetDir); !status.isOk()) { |
| 924 | return status; |
| 925 | } |
Yurii Zubrytskyi | 131365a | 2020-03-24 23:49:02 -0700 | [diff] [blame] | 926 | |
Yurii Zubrytskyi | 18eb877 | 2021-10-18 22:33:15 -0700 | [diff] [blame] | 927 | auto [sourceFd, sourceSymlink] = OpenDirInProcfs(sourceDir); |
| 928 | if (!sourceFd.ok()) { |
| 929 | return translate(-errno); |
| 930 | } |
| 931 | auto [targetFd, targetSymlink] = OpenDirInProcfs(targetDir); |
| 932 | if (!targetFd.ok()) { |
| 933 | return translate(-errno); |
| 934 | } |
| 935 | return translate(incfs::bindMount(sourceSymlink, targetSymlink)); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 936 | } |
| 937 | |
Yo Chiang | 0af25a3 | 2020-10-07 14:20:00 +0800 | [diff] [blame] | 938 | binder::Status VoldNativeService::destroyDsuMetadataKey(const std::string& dsuSlot) { |
| 939 | ENFORCE_SYSTEM_OR_ROOT; |
| 940 | ACQUIRE_LOCK; |
| 941 | |
| 942 | return translateBool(destroy_dsu_metadata_key(dsuSlot)); |
| 943 | } |
| 944 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 945 | } // namespace vold |
| 946 | } // namespace android |