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 | |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 21 | #include "Benchmark.h" |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 22 | #include "CheckEncryption.h" |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 23 | #include "Checkpoint.h" |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 24 | #include "FsCrypt.h" |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 25 | #include "IdleMaint.h" |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 26 | #include "MetadataCrypt.h" |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 27 | #include "MoveStorage.h" |
| 28 | #include "Process.h" |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 29 | #include "VoldNativeServiceValidation.h" |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 30 | #include "VoldUtil.h" |
| 31 | #include "VolumeManager.h" |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 32 | #include "cryptfs.h" |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 33 | |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 34 | #include "incfs_ndk.h" |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 35 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 36 | #include <fstream> |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 37 | #include <thread> |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 38 | |
| 39 | #include <android-base/logging.h> |
| 40 | #include <android-base/stringprintf.h> |
| 41 | #include <android-base/strings.h> |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 42 | #include <fs_mgr.h> |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 43 | #include <fscrypt/fscrypt.h> |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 44 | #include <private/android_filesystem_config.h> |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 45 | #include <utils/Trace.h> |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 46 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 47 | using android::base::StringPrintf; |
| 48 | using std::endl; |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 49 | using namespace std::literals; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 50 | |
| 51 | namespace android { |
| 52 | namespace vold { |
| 53 | |
| 54 | namespace { |
| 55 | |
| 56 | constexpr const char* kDump = "android.permission.DUMP"; |
| 57 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 58 | static binder::Status error(const std::string& msg) { |
| 59 | PLOG(ERROR) << msg; |
| 60 | return binder::Status::fromServiceSpecificError(errno, String8(msg.c_str())); |
| 61 | } |
| 62 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 63 | static binder::Status translate(int status) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 64 | if (status == 0) { |
| 65 | return binder::Status::ok(); |
| 66 | } else { |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 67 | return binder::Status::fromServiceSpecificError(status); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 71 | static binder::Status translateBool(bool status) { |
| 72 | if (status) { |
| 73 | return binder::Status::ok(); |
| 74 | } else { |
| 75 | return binder::Status::fromServiceSpecificError(status); |
| 76 | } |
| 77 | } |
| 78 | |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 79 | #define ENFORCE_SYSTEM_OR_ROOT \ |
| 80 | { \ |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 81 | binder::Status status = CheckUidOrRoot(AID_SYSTEM); \ |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 82 | if (!status.isOk()) { \ |
| 83 | return status; \ |
| 84 | } \ |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 85 | } |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 86 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 87 | #define CHECK_ARGUMENT_ID(id) \ |
| 88 | { \ |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 89 | binder::Status status = CheckArgumentId((id)); \ |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 90 | if (!status.isOk()) { \ |
| 91 | return status; \ |
| 92 | } \ |
| 93 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 94 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 95 | #define CHECK_ARGUMENT_PATH(path) \ |
| 96 | { \ |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 97 | binder::Status status = CheckArgumentPath((path)); \ |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 98 | if (!status.isOk()) { \ |
| 99 | return status; \ |
| 100 | } \ |
| 101 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 102 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 103 | #define CHECK_ARGUMENT_HEX(hex) \ |
| 104 | { \ |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 105 | binder::Status status = CheckArgumentHex((hex)); \ |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 106 | if (!status.isOk()) { \ |
| 107 | return status; \ |
| 108 | } \ |
| 109 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 110 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 111 | #define ACQUIRE_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 112 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \ |
| 113 | ATRACE_CALL(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 114 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 115 | #define ACQUIRE_CRYPT_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 116 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \ |
| 117 | ATRACE_CALL(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 118 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 119 | } // namespace |
| 120 | |
| 121 | status_t VoldNativeService::start() { |
| 122 | IPCThreadState::self()->disableBackgroundScheduling(true); |
| 123 | status_t ret = BinderService<VoldNativeService>::publish(); |
| 124 | if (ret != android::OK) { |
| 125 | return ret; |
| 126 | } |
| 127 | sp<ProcessState> ps(ProcessState::self()); |
| 128 | ps->startThreadPool(); |
| 129 | ps->giveThreadPoolName(); |
| 130 | return android::OK; |
| 131 | } |
| 132 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 133 | status_t VoldNativeService::dump(int fd, const Vector<String16>& /* args */) { |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 134 | auto out = std::fstream(StringPrintf("/proc/self/fd/%d", fd)); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 135 | const binder::Status dump_permission = CheckPermission(kDump); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 136 | if (!dump_permission.isOk()) { |
| 137 | out << dump_permission.toString8() << endl; |
| 138 | return PERMISSION_DENIED; |
| 139 | } |
| 140 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 141 | ACQUIRE_LOCK; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 142 | out << "vold is happy!" << endl; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 143 | return NO_ERROR; |
| 144 | } |
| 145 | |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 146 | binder::Status VoldNativeService::setListener( |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 147 | const android::sp<android::os::IVoldListener>& listener) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 148 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 149 | ACQUIRE_LOCK; |
| 150 | |
| 151 | VolumeManager::Instance()->setListener(listener); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 152 | return Ok(); |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 153 | } |
| 154 | |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 155 | binder::Status VoldNativeService::monitor() { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 156 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 157 | |
| 158 | // Simply acquire/release each lock for watchdog |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 159 | { ACQUIRE_LOCK; } |
| 160 | { ACQUIRE_CRYPT_LOCK; } |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 161 | |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 162 | return Ok(); |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 163 | } |
| 164 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 165 | binder::Status VoldNativeService::reset() { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 166 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 167 | ACQUIRE_LOCK; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 168 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 169 | return translate(VolumeManager::Instance()->reset()); |
| 170 | } |
| 171 | |
| 172 | binder::Status VoldNativeService::shutdown() { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 173 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 174 | ACQUIRE_LOCK; |
| 175 | |
| 176 | return translate(VolumeManager::Instance()->shutdown()); |
| 177 | } |
| 178 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 179 | binder::Status VoldNativeService::onUserAdded(int32_t userId, int32_t userSerial) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 180 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 181 | ACQUIRE_LOCK; |
| 182 | |
| 183 | return translate(VolumeManager::Instance()->onUserAdded(userId, userSerial)); |
| 184 | } |
| 185 | |
| 186 | binder::Status VoldNativeService::onUserRemoved(int32_t userId) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 187 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 188 | ACQUIRE_LOCK; |
| 189 | |
| 190 | return translate(VolumeManager::Instance()->onUserRemoved(userId)); |
| 191 | } |
| 192 | |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 193 | binder::Status VoldNativeService::onUserStarted(int32_t userId) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 194 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 195 | ACQUIRE_LOCK; |
| 196 | |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 197 | return translate(VolumeManager::Instance()->onUserStarted(userId)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | binder::Status VoldNativeService::onUserStopped(int32_t userId) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 201 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 202 | ACQUIRE_LOCK; |
| 203 | |
| 204 | return translate(VolumeManager::Instance()->onUserStopped(userId)); |
| 205 | } |
| 206 | |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 207 | binder::Status VoldNativeService::addAppIds(const std::vector<std::string>& packageNames, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 208 | const std::vector<int32_t>& appIds) { |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 209 | return Ok(); |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 212 | binder::Status VoldNativeService::addSandboxIds(const std::vector<int32_t>& appIds, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 213 | const std::vector<std::string>& sandboxIds) { |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 214 | return Ok(); |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Jeff Sharkey | 401b260 | 2017-12-14 22:15:20 -0700 | [diff] [blame] | 217 | binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 218 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 401b260 | 2017-12-14 22:15:20 -0700 | [diff] [blame] | 219 | ACQUIRE_LOCK; |
| 220 | |
| 221 | return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing)); |
| 222 | } |
| 223 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 224 | binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 225 | int32_t ratio) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 226 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 227 | CHECK_ARGUMENT_ID(diskId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 228 | ACQUIRE_LOCK; |
| 229 | |
| 230 | auto disk = VolumeManager::Instance()->findDisk(diskId); |
| 231 | if (disk == nullptr) { |
| 232 | return error("Failed to find disk " + diskId); |
| 233 | } |
| 234 | switch (partitionType) { |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 235 | case PARTITION_TYPE_PUBLIC: |
| 236 | return translate(disk->partitionPublic()); |
| 237 | case PARTITION_TYPE_PRIVATE: |
| 238 | return translate(disk->partitionPrivate()); |
| 239 | case PARTITION_TYPE_MIXED: |
| 240 | return translate(disk->partitionMixed(ratio)); |
| 241 | default: |
| 242 | return error("Unknown type " + std::to_string(partitionType)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 246 | binder::Status VoldNativeService::forgetPartition(const std::string& partGuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 247 | const std::string& fsUuid) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 248 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 249 | CHECK_ARGUMENT_HEX(partGuid); |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 250 | CHECK_ARGUMENT_HEX(fsUuid); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 251 | ACQUIRE_LOCK; |
| 252 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 253 | return translate(VolumeManager::Instance()->forgetPartition(partGuid, fsUuid)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 254 | } |
| 255 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 256 | binder::Status VoldNativeService::mount(const std::string& volId, int32_t mountFlags, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 257 | int32_t mountUserId) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 258 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 259 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 260 | ACQUIRE_LOCK; |
| 261 | |
| 262 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 263 | if (vol == nullptr) { |
| 264 | return error("Failed to find volume " + volId); |
| 265 | } |
| 266 | |
| 267 | vol->setMountFlags(mountFlags); |
| 268 | vol->setMountUserId(mountUserId); |
| 269 | |
| 270 | int res = vol->mount(); |
Sudheer Shanka | 40ab674 | 2018-09-18 13:07:45 -0700 | [diff] [blame] | 271 | if (res != OK) { |
| 272 | return translate(res); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 273 | } |
Sudheer Shanka | 40ab674 | 2018-09-18 13:07:45 -0700 | [diff] [blame] | 274 | if ((mountFlags & MOUNT_FLAG_PRIMARY) != 0) { |
| 275 | res = VolumeManager::Instance()->setPrimary(vol); |
| 276 | if (res != OK) { |
| 277 | return translate(res); |
| 278 | } |
| 279 | } |
| 280 | return translate(OK); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | binder::Status VoldNativeService::unmount(const std::string& volId) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 284 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 285 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 286 | ACQUIRE_LOCK; |
| 287 | |
| 288 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 289 | if (vol == nullptr) { |
| 290 | return error("Failed to find volume " + volId); |
| 291 | } |
| 292 | return translate(vol->unmount()); |
| 293 | } |
| 294 | |
| 295 | binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 296 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 297 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 298 | ACQUIRE_LOCK; |
| 299 | |
| 300 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 301 | if (vol == nullptr) { |
| 302 | return error("Failed to find volume " + volId); |
| 303 | } |
| 304 | return translate(vol->format(fsType)); |
| 305 | } |
| 306 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 307 | static binder::Status pathForVolId(const std::string& volId, std::string* path) { |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 308 | if (volId == "private" || volId == "null") { |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 309 | *path = "/data"; |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 310 | } else { |
| 311 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 312 | if (vol == nullptr) { |
| 313 | return error("Failed to find volume " + volId); |
| 314 | } |
| 315 | if (vol->getType() != VolumeBase::Type::kPrivate) { |
| 316 | return error("Volume " + volId + " not private"); |
| 317 | } |
| 318 | if (vol->getState() != VolumeBase::State::kMounted) { |
| 319 | return error("Volume " + volId + " not mounted"); |
| 320 | } |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 321 | *path = vol->getPath(); |
| 322 | if (path->empty()) { |
| 323 | return error("Volume " + volId + " missing path"); |
| 324 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 325 | } |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 326 | return Ok(); |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 327 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 328 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 329 | binder::Status VoldNativeService::benchmark( |
| 330 | const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 331 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 332 | CHECK_ARGUMENT_ID(volId); |
| 333 | ACQUIRE_LOCK; |
| 334 | |
| 335 | std::string path; |
| 336 | auto status = pathForVolId(volId, &path); |
| 337 | if (!status.isOk()) return status; |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 338 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 339 | std::thread([=]() { android::vold::Benchmark(path, listener); }).detach(); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 340 | return Ok(); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 341 | } |
| 342 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 343 | binder::Status VoldNativeService::checkEncryption(const std::string& volId) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 344 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 345 | CHECK_ARGUMENT_ID(volId); |
| 346 | ACQUIRE_LOCK; |
| 347 | |
| 348 | std::string path; |
| 349 | auto status = pathForVolId(volId, &path); |
| 350 | if (!status.isOk()) return status; |
| 351 | return translate(android::vold::CheckEncryption(path)); |
| 352 | } |
| 353 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 354 | binder::Status VoldNativeService::moveStorage( |
| 355 | const std::string& fromVolId, const std::string& toVolId, |
| 356 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 357 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 358 | CHECK_ARGUMENT_ID(fromVolId); |
| 359 | CHECK_ARGUMENT_ID(toVolId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 360 | ACQUIRE_LOCK; |
| 361 | |
| 362 | auto fromVol = VolumeManager::Instance()->findVolume(fromVolId); |
| 363 | auto toVol = VolumeManager::Instance()->findVolume(toVolId); |
| 364 | if (fromVol == nullptr) { |
| 365 | return error("Failed to find volume " + fromVolId); |
| 366 | } else if (toVol == nullptr) { |
| 367 | return error("Failed to find volume " + toVolId); |
| 368 | } |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 369 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 370 | std::thread([=]() { android::vold::MoveStorage(fromVol, toVol, listener); }).detach(); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 371 | return Ok(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 375 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 376 | ACQUIRE_LOCK; |
| 377 | |
Sudheer Shanka | 817b911 | 2018-12-13 17:40:28 -0800 | [diff] [blame] | 378 | return translate(VolumeManager::Instance()->remountUid(uid, remountMode)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | binder::Status VoldNativeService::mkdirs(const std::string& path) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 382 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 383 | CHECK_ARGUMENT_PATH(path); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 384 | ACQUIRE_LOCK; |
| 385 | |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 386 | return translate(VolumeManager::Instance()->mkdirs(path)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 387 | } |
| 388 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 389 | binder::Status VoldNativeService::createObb(const std::string& sourcePath, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 390 | const std::string& sourceKey, int32_t ownerGid, |
| 391 | std::string* _aidl_return) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 392 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 393 | CHECK_ARGUMENT_PATH(sourcePath); |
| 394 | CHECK_ARGUMENT_HEX(sourceKey); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 395 | ACQUIRE_LOCK; |
| 396 | |
| 397 | return translate( |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 398 | VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return)); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | binder::Status VoldNativeService::destroyObb(const std::string& volId) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 402 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 403 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 404 | ACQUIRE_LOCK; |
| 405 | |
| 406 | return translate(VolumeManager::Instance()->destroyObb(volId)); |
| 407 | } |
| 408 | |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 409 | binder::Status VoldNativeService::createStubVolume( |
| 410 | const std::string& sourcePath, const std::string& mountPath, const std::string& fsType, |
| 411 | const std::string& fsUuid, const std::string& fsLabel, std::string* _aidl_return) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 412 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 413 | CHECK_ARGUMENT_PATH(sourcePath); |
| 414 | CHECK_ARGUMENT_PATH(mountPath); |
| 415 | CHECK_ARGUMENT_HEX(fsUuid); |
| 416 | // Label limitation seems to be different between fs (including allowed characters), so checking |
| 417 | // is quite meaningless. |
| 418 | ACQUIRE_LOCK; |
| 419 | |
| 420 | return translate(VolumeManager::Instance()->createStubVolume(sourcePath, mountPath, fsType, |
| 421 | fsUuid, fsLabel, _aidl_return)); |
| 422 | } |
| 423 | |
| 424 | binder::Status VoldNativeService::destroyStubVolume(const std::string& volId) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 425 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 426 | CHECK_ARGUMENT_ID(volId); |
| 427 | ACQUIRE_LOCK; |
| 428 | |
| 429 | return translate(VolumeManager::Instance()->destroyStubVolume(volId)); |
| 430 | } |
| 431 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 432 | binder::Status VoldNativeService::fstrim( |
| 433 | int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 434 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 435 | ACQUIRE_LOCK; |
| 436 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 437 | std::thread([=]() { android::vold::Trim(listener); }).detach(); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 438 | return Ok(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 439 | } |
| 440 | |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 441 | binder::Status VoldNativeService::runIdleMaint( |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 442 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 443 | ENFORCE_SYSTEM_OR_ROOT; |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 444 | ACQUIRE_LOCK; |
| 445 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 446 | std::thread([=]() { android::vold::RunIdleMaint(listener); }).detach(); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 447 | return Ok(); |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | binder::Status VoldNativeService::abortIdleMaint( |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 451 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 452 | ENFORCE_SYSTEM_OR_ROOT; |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 453 | ACQUIRE_LOCK; |
| 454 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 455 | std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach(); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 456 | return Ok(); |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 459 | binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t mountId, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 460 | android::base::unique_fd* _aidl_return) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 461 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 462 | ACQUIRE_LOCK; |
| 463 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 464 | return translate(VolumeManager::Instance()->mountAppFuse(uid, mountId, _aidl_return)); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 465 | } |
| 466 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 467 | binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t mountId) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 468 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 469 | ACQUIRE_LOCK; |
| 470 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 471 | return translate(VolumeManager::Instance()->unmountAppFuse(uid, mountId)); |
| 472 | } |
| 473 | |
| 474 | binder::Status VoldNativeService::openAppFuseFile(int32_t uid, int32_t mountId, int32_t fileId, |
| 475 | int32_t flags, |
| 476 | android::base::unique_fd* _aidl_return) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 477 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 478 | ACQUIRE_LOCK; |
| 479 | |
| 480 | int fd = VolumeManager::Instance()->openAppFuseFile(uid, mountId, fileId, flags); |
| 481 | if (fd == -1) { |
| 482 | return error("Failed to open AppFuse file for uid: " + std::to_string(uid) + |
| 483 | " mountId: " + std::to_string(mountId) + " fileId: " + std::to_string(fileId) + |
| 484 | " flags: " + std::to_string(flags)); |
| 485 | } |
| 486 | |
| 487 | *_aidl_return = android::base::unique_fd(fd); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 488 | return Ok(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 489 | } |
| 490 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 491 | binder::Status VoldNativeService::fdeCheckPassword(const std::string& password) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 492 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 493 | ACQUIRE_CRYPT_LOCK; |
| 494 | |
| 495 | return translate(cryptfs_check_passwd(password.c_str())); |
| 496 | } |
| 497 | |
| 498 | binder::Status VoldNativeService::fdeRestart() { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 499 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 500 | ACQUIRE_CRYPT_LOCK; |
| 501 | |
| 502 | // Spawn as thread so init can issue commands back to vold without |
| 503 | // causing deadlock, usually as a result of prep_data_fs. |
| 504 | std::thread(&cryptfs_restart).detach(); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 505 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 509 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 510 | ACQUIRE_CRYPT_LOCK; |
| 511 | |
| 512 | *_aidl_return = cryptfs_crypto_complete(); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 513 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | static int fdeEnableInternal(int32_t passwordType, const std::string& password, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 517 | int32_t encryptionFlags) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 518 | bool noUi = (encryptionFlags & VoldNativeService::ENCRYPTION_FLAG_NO_UI) != 0; |
| 519 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 520 | for (int tries = 0; tries < 2; ++tries) { |
| 521 | int rc; |
| 522 | if (passwordType == VoldNativeService::PASSWORD_TYPE_DEFAULT) { |
Paul Lawrence | 7ee87cf | 2017-12-22 10:12:06 -0800 | [diff] [blame] | 523 | rc = cryptfs_enable_default(noUi); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 524 | } else { |
Paul Lawrence | 7ee87cf | 2017-12-22 10:12:06 -0800 | [diff] [blame] | 525 | rc = cryptfs_enable(passwordType, password.c_str(), noUi); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | if (rc == 0) { |
| 529 | return 0; |
| 530 | } else if (tries == 0) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 531 | KillProcessesWithOpenFiles(DATA_MNT_POINT, SIGKILL); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | |
| 535 | return -1; |
| 536 | } |
| 537 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 538 | binder::Status VoldNativeService::fdeEnable(int32_t passwordType, const std::string& password, |
| 539 | int32_t encryptionFlags) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 540 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 541 | ACQUIRE_CRYPT_LOCK; |
| 542 | |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 543 | LOG(DEBUG) << "fdeEnable(" << passwordType << ", *, " << encryptionFlags << ")"; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 544 | if (fscrypt_is_native()) { |
| 545 | LOG(ERROR) << "fscrypt_is_native, fdeEnable invalid"; |
| 546 | return error("fscrypt_is_native, fdeEnable invalid"); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 547 | } |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 548 | LOG(DEBUG) << "!fscrypt_is_native, spawning fdeEnableInternal"; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 549 | |
| 550 | // Spawn as thread so init can issue commands back to vold without |
| 551 | // causing deadlock, usually as a result of prep_data_fs. |
| 552 | std::thread(&fdeEnableInternal, passwordType, password, encryptionFlags).detach(); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 553 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 557 | const std::string& password) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 558 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 559 | ACQUIRE_CRYPT_LOCK; |
| 560 | |
| 561 | return translate(cryptfs_changepw(passwordType, password.c_str())); |
| 562 | } |
| 563 | |
| 564 | binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 565 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 566 | ACQUIRE_CRYPT_LOCK; |
| 567 | |
| 568 | return translate(cryptfs_verify_passwd(password.c_str())); |
| 569 | } |
| 570 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 571 | binder::Status VoldNativeService::fdeGetField(const std::string& key, std::string* _aidl_return) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 572 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 573 | ACQUIRE_CRYPT_LOCK; |
| 574 | |
| 575 | char buf[PROPERTY_VALUE_MAX]; |
| 576 | if (cryptfs_getfield(key.c_str(), buf, sizeof(buf)) != CRYPTO_GETFIELD_OK) { |
| 577 | return error(StringPrintf("Failed to read field %s", key.c_str())); |
| 578 | } else { |
| 579 | *_aidl_return = buf; |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 580 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 584 | binder::Status VoldNativeService::fdeSetField(const std::string& key, const std::string& value) { |
Nikita Ioffe | e1fd489 | 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 | |
| 588 | return translate(cryptfs_setfield(key.c_str(), value.c_str())); |
| 589 | } |
| 590 | |
| 591 | binder::Status VoldNativeService::fdeGetPasswordType(int32_t* _aidl_return) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 592 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 593 | ACQUIRE_CRYPT_LOCK; |
| 594 | |
| 595 | *_aidl_return = cryptfs_get_password_type(); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 596 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | binder::Status VoldNativeService::fdeGetPassword(std::string* _aidl_return) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 600 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 601 | ACQUIRE_CRYPT_LOCK; |
| 602 | |
| 603 | const char* res = cryptfs_get_password(); |
| 604 | if (res != nullptr) { |
| 605 | *_aidl_return = res; |
| 606 | } |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 607 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | binder::Status VoldNativeService::fdeClearPassword() { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 611 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 612 | ACQUIRE_CRYPT_LOCK; |
| 613 | |
| 614 | cryptfs_clear_password(); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 615 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | binder::Status VoldNativeService::fbeEnable() { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 619 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 620 | ACQUIRE_CRYPT_LOCK; |
| 621 | |
Paul Crowley | c8a3ef3 | 2019-09-11 15:00:08 -0700 | [diff] [blame] | 622 | return translateBool(fscrypt_initialize_systemwide_keys()); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | binder::Status VoldNativeService::mountDefaultEncrypted() { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 626 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 627 | ACQUIRE_CRYPT_LOCK; |
| 628 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 629 | if (!fscrypt_is_native()) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 630 | // Spawn as thread so init can issue commands back to vold without |
| 631 | // causing deadlock, usually as a result of prep_data_fs. |
| 632 | std::thread(&cryptfs_mount_default_encrypted).detach(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 633 | } |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 634 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | binder::Status VoldNativeService::initUser0() { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 638 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 639 | ACQUIRE_CRYPT_LOCK; |
| 640 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 641 | return translateBool(fscrypt_init_user0()); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 645 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 646 | ACQUIRE_CRYPT_LOCK; |
| 647 | |
| 648 | *_aidl_return = cryptfs_isConvertibleToFBE() != 0; |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 649 | return Ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 650 | } |
| 651 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 652 | binder::Status VoldNativeService::mountFstab(const std::string& blkDevice, |
| 653 | const std::string& mountPoint) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 654 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 655 | ACQUIRE_LOCK; |
| 656 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 657 | return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, false)); |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 658 | } |
| 659 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 660 | binder::Status VoldNativeService::encryptFstab(const std::string& blkDevice, |
| 661 | const std::string& mountPoint) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 662 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 663 | ACQUIRE_LOCK; |
| 664 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 665 | return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, true)); |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 666 | } |
| 667 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 668 | binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, bool ephemeral) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 669 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 670 | ACQUIRE_CRYPT_LOCK; |
| 671 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 672 | return translateBool(fscrypt_vold_create_user_key(userId, userSerial, ephemeral)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | binder::Status VoldNativeService::destroyUserKey(int32_t userId) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 676 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 677 | ACQUIRE_CRYPT_LOCK; |
| 678 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 679 | return translateBool(fscrypt_destroy_user_key(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 683 | const std::string& token, |
| 684 | const std::string& secret) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 685 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 686 | ACQUIRE_CRYPT_LOCK; |
| 687 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 688 | return translateBool(fscrypt_add_user_key_auth(userId, userSerial, token, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 689 | } |
| 690 | |
Barani Muthukumaran | b1927c2 | 2019-10-31 22:59:34 -0700 | [diff] [blame] | 691 | binder::Status VoldNativeService::clearUserKeyAuth(int32_t userId, int32_t userSerial, |
| 692 | const std::string& token, |
| 693 | const std::string& secret) { |
| 694 | ENFORCE_SYSTEM_OR_ROOT; |
| 695 | ACQUIRE_CRYPT_LOCK; |
| 696 | |
| 697 | return translateBool(fscrypt_clear_user_key_auth(userId, userSerial, token, secret)); |
| 698 | } |
| 699 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 700 | binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 701 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 702 | ACQUIRE_CRYPT_LOCK; |
| 703 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 704 | return translateBool(fscrypt_fixate_newest_user_key_auth(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 708 | const std::string& token, |
| 709 | const std::string& secret) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 710 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 711 | ACQUIRE_CRYPT_LOCK; |
| 712 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 713 | return translateBool(fscrypt_unlock_user_key(userId, userSerial, token, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | binder::Status VoldNativeService::lockUserKey(int32_t userId) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 717 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 718 | ACQUIRE_CRYPT_LOCK; |
| 719 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 720 | return translateBool(fscrypt_lock_user_key(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 721 | } |
| 722 | |
Jooyung Han | d75a10a | 2020-01-23 13:23:26 +0900 | [diff] [blame] | 723 | binder::Status VoldNativeService::prepareUserStorage(const std::optional<std::string>& uuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 724 | int32_t userId, int32_t userSerial, |
| 725 | int32_t flags) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 726 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 727 | std::string empty_string = ""; |
| 728 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 729 | CHECK_ARGUMENT_HEX(uuid_); |
| 730 | |
| 731 | ACQUIRE_CRYPT_LOCK; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 732 | return translateBool(fscrypt_prepare_user_storage(uuid_, userId, userSerial, flags)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 733 | } |
| 734 | |
Jooyung Han | d75a10a | 2020-01-23 13:23:26 +0900 | [diff] [blame] | 735 | binder::Status VoldNativeService::destroyUserStorage(const std::optional<std::string>& uuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 736 | int32_t userId, int32_t flags) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 737 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 738 | std::string empty_string = ""; |
| 739 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 740 | CHECK_ARGUMENT_HEX(uuid_); |
| 741 | |
| 742 | ACQUIRE_CRYPT_LOCK; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 743 | return translateBool(fscrypt_destroy_user_storage(uuid_, userId, flags)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 744 | } |
| 745 | |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 746 | binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packageName, |
| 747 | int32_t appId, const std::string& sandboxId, |
| 748 | int32_t userId) { |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 749 | return Ok(); |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName, |
Sudheer Shanka | 69bc40f | 2018-10-25 11:06:55 -0700 | [diff] [blame] | 753 | const std::string& sandboxId, |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 754 | int32_t userId) { |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 755 | return Ok(); |
Sudheer Shanka | c756209 | 2018-08-24 10:20:56 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 758 | binder::Status VoldNativeService::startCheckpoint(int32_t retry) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 759 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 760 | ACQUIRE_LOCK; |
| 761 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 762 | return cp_startCheckpoint(retry); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 765 | binder::Status VoldNativeService::needsRollback(bool* _aidl_return) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 766 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 767 | ACQUIRE_LOCK; |
| 768 | |
| 769 | *_aidl_return = cp_needsRollback(); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 770 | return Ok(); |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 773 | binder::Status VoldNativeService::needsCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 774 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 775 | ACQUIRE_LOCK; |
| 776 | |
| 777 | *_aidl_return = cp_needsCheckpoint(); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 778 | return Ok(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 779 | } |
| 780 | |
David Anderson | 23850d3 | 2020-06-10 23:51:17 -0700 | [diff] [blame] | 781 | binder::Status VoldNativeService::isCheckpointing(bool* _aidl_return) { |
| 782 | ENFORCE_SYSTEM_OR_ROOT; |
| 783 | ACQUIRE_LOCK; |
| 784 | |
| 785 | *_aidl_return = cp_isCheckpointing(); |
| 786 | return Ok(); |
| 787 | } |
| 788 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 789 | binder::Status VoldNativeService::commitChanges() { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 790 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 791 | ACQUIRE_LOCK; |
| 792 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 793 | return cp_commitChanges(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 794 | } |
| 795 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 796 | binder::Status VoldNativeService::prepareCheckpoint() { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 797 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 798 | ACQUIRE_LOCK; |
| 799 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 800 | return cp_prepareCheckpoint(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 803 | binder::Status VoldNativeService::restoreCheckpoint(const std::string& mountPoint) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 804 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | 1abb2fe | 2018-09-21 10:49:57 -0700 | [diff] [blame] | 805 | CHECK_ARGUMENT_PATH(mountPoint); |
| 806 | ACQUIRE_LOCK; |
| 807 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 808 | return cp_restoreCheckpoint(mountPoint); |
Paul Lawrence | 1abb2fe | 2018-09-21 10:49:57 -0700 | [diff] [blame] | 809 | } |
| 810 | |
Daniel Rosenberg | dda5981 | 2019-03-06 17:45:17 -0800 | [diff] [blame] | 811 | binder::Status VoldNativeService::restoreCheckpointPart(const std::string& mountPoint, int count) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 812 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | dda5981 | 2019-03-06 17:45:17 -0800 | [diff] [blame] | 813 | CHECK_ARGUMENT_PATH(mountPoint); |
| 814 | ACQUIRE_LOCK; |
| 815 | |
| 816 | return cp_restoreCheckpoint(mountPoint, count); |
| 817 | } |
| 818 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 819 | binder::Status VoldNativeService::markBootAttempt() { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 820 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 821 | ACQUIRE_LOCK; |
| 822 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 823 | return cp_markBootAttempt(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 824 | } |
| 825 | |
Daniel Rosenberg | a59e439 | 2019-03-20 17:02:47 -0700 | [diff] [blame] | 826 | binder::Status VoldNativeService::abortChanges(const std::string& message, bool retry) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 827 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 828 | ACQUIRE_LOCK; |
| 829 | |
Daniel Rosenberg | a59e439 | 2019-03-20 17:02:47 -0700 | [diff] [blame] | 830 | cp_abortChanges(message, retry); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 831 | return Ok(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 832 | } |
| 833 | |
Daniel Rosenberg | 9b667fb | 2019-01-22 17:27:25 -0800 | [diff] [blame] | 834 | binder::Status VoldNativeService::supportsCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 835 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 9b667fb | 2019-01-22 17:27:25 -0800 | [diff] [blame] | 836 | ACQUIRE_LOCK; |
| 837 | |
| 838 | return cp_supportsCheckpoint(*_aidl_return); |
| 839 | } |
| 840 | |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 841 | binder::Status VoldNativeService::supportsBlockCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 842 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 843 | ACQUIRE_LOCK; |
| 844 | |
| 845 | return cp_supportsBlockCheckpoint(*_aidl_return); |
| 846 | } |
| 847 | |
| 848 | binder::Status VoldNativeService::supportsFileCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 849 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 850 | ACQUIRE_LOCK; |
| 851 | |
| 852 | return cp_supportsFileCheckpoint(*_aidl_return); |
| 853 | } |
| 854 | |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 855 | binder::Status VoldNativeService::resetCheckpoint() { |
Nikita Ioffe | e1fd489 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 856 | ENFORCE_SYSTEM_OR_ROOT; |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 857 | ACQUIRE_LOCK; |
| 858 | |
| 859 | cp_resetCheckpoint(); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 860 | return Ok(); |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 861 | } |
| 862 | |
Yurii Zubrytskyi | d05bcc8 | 2020-01-10 11:54:06 -0800 | [diff] [blame] | 863 | binder::Status VoldNativeService::incFsEnabled(bool* _aidl_return) { |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 864 | ENFORCE_SYSTEM_OR_ROOT; |
| 865 | |
Yurii Zubrytskyi | d05bcc8 | 2020-01-10 11:54:06 -0800 | [diff] [blame] | 866 | *_aidl_return = IncFs_IsEnabled(); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 867 | return Ok(); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | binder::Status VoldNativeService::mountIncFs( |
Yurii Zubrytskyi | d05bcc8 | 2020-01-10 11:54:06 -0800 | [diff] [blame] | 871 | const std::string& backingPath, const std::string& targetDir, int32_t flags, |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 872 | ::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) { |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 873 | ENFORCE_SYSTEM_OR_ROOT; |
| 874 | CHECK_ARGUMENT_PATH(backingPath); |
| 875 | CHECK_ARGUMENT_PATH(targetDir); |
| 876 | |
Songchun Fan | 2781933 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 877 | auto control = IncFs_Mount(backingPath.c_str(), targetDir.c_str(), |
| 878 | {.flags = IncFsMountFlags(flags), |
| 879 | .defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS, |
| 880 | .readLogBufferPages = 4}); |
| 881 | if (control == nullptr) { |
| 882 | return translate(-1); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 883 | } |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 884 | using unique_fd = ::android::base::unique_fd; |
Songchun Fan | 2781933 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 885 | _aidl_return->cmd.emplace(unique_fd(dup(IncFs_GetControlFd(control, CMD)))); |
| 886 | _aidl_return->pendingReads.emplace(unique_fd(dup(IncFs_GetControlFd(control, PENDING_READS)))); |
| 887 | auto logsFd = IncFs_GetControlFd(control, LOGS); |
| 888 | if (logsFd >= 0) { |
| 889 | _aidl_return->log.emplace(unique_fd(dup(logsFd))); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 890 | } |
Songchun Fan | 2781933 | 2020-03-03 17:58:20 -0800 | [diff] [blame] | 891 | IncFs_DeleteControl(control); |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 892 | return Ok(); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | binder::Status VoldNativeService::unmountIncFs(const std::string& dir) { |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 896 | ENFORCE_SYSTEM_OR_ROOT; |
| 897 | CHECK_ARGUMENT_PATH(dir); |
| 898 | |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 899 | return translate(IncFs_Unmount(dir.c_str())); |
| 900 | } |
| 901 | |
| 902 | binder::Status VoldNativeService::bindMount(const std::string& sourceDir, |
| 903 | const std::string& targetDir) { |
Yurii Zubrytskyi | 9e7482e | 2020-03-24 16:23:51 -0700 | [diff] [blame] | 904 | ENFORCE_SYSTEM_OR_ROOT; |
| 905 | CHECK_ARGUMENT_PATH(sourceDir); |
| 906 | CHECK_ARGUMENT_PATH(targetDir); |
| 907 | |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 908 | return translate(IncFs_BindMount(sourceDir.c_str(), targetDir.c_str())); |
| 909 | } |
| 910 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 911 | } // namespace vold |
| 912 | } // namespace android |