San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
Eric Biggers | fb48666 | 2022-03-22 00:33:52 +0000 | [diff] [blame^] | 19 | #include "FsCrypt.h" |
David Anderson | 156d9d2 | 2021-09-21 17:21:57 -0700 | [diff] [blame] | 20 | #include "MetadataCrypt.h" |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 21 | #include "NetlinkManager.h" |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 22 | #include "VoldNativeService.h" |
Paul Crowley | e2ee152 | 2017-09-26 14:05:26 -0700 | [diff] [blame] | 23 | #include "VoldUtil.h" |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 24 | #include "VolumeManager.h" |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 25 | #include "model/Disk.h" |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 26 | #include "sehandle.h" |
| 27 | |
Elliott Hughes | 7e128fb | 2015-12-04 15:50:53 -0800 | [diff] [blame] | 28 | #include <android-base/logging.h> |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 29 | #include <android-base/properties.h> |
Elliott Hughes | 7e128fb | 2015-12-04 15:50:53 -0800 | [diff] [blame] | 30 | #include <android-base/stringprintf.h> |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 31 | #include <cutils/klog.h> |
Yifan Hong | 024a124 | 2018-08-10 13:50:46 -0700 | [diff] [blame] | 32 | #include <hidl/HidlTransportSupport.h> |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 33 | #include <utils/Trace.h> |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 34 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 35 | #include <dirent.h> |
| 36 | #include <errno.h> |
| 37 | #include <fcntl.h> |
| 38 | #include <fs_mgr.h> |
| 39 | #include <getopt.h> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 40 | #include <stdio.h> |
| 41 | #include <stdlib.h> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 42 | #include <string.h> |
San Mehat | 3578c41 | 2009-10-12 14:51:52 -0700 | [diff] [blame] | 43 | #include <sys/stat.h> |
| 44 | #include <sys/types.h> |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 45 | |
Jaegeuk Kim | c52f672 | 2020-04-06 15:58:41 -0700 | [diff] [blame] | 46 | typedef struct vold_configs { |
| 47 | bool has_adoptable : 1; |
| 48 | bool has_quota : 1; |
| 49 | bool has_reserved : 1; |
| 50 | bool has_compress : 1; |
| 51 | } VoldConfigs; |
| 52 | |
| 53 | static int process_config(VolumeManager* vm, VoldConfigs* configs); |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 54 | static void coldboot(const char* path); |
Jeff Sharkey | 95c87cc | 2015-04-01 11:54:32 -0700 | [diff] [blame] | 55 | static void parse_args(int argc, char** argv); |
David Anderson | 52de78e | 2021-11-05 19:26:56 -0700 | [diff] [blame] | 56 | static void VoldLogger(android::base::LogId log_buffer_id, android::base::LogSeverity severity, |
| 57 | const char* tag, const char* file, unsigned int line, const char* message); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 58 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 59 | struct selabel_handle* sehandle; |
David Anderson | 52de78e | 2021-11-05 19:26:56 -0700 | [diff] [blame] | 60 | android::base::LogdLogger logd_logger(android::base::SYSTEM); |
Stephen Smalley | 684e662 | 2014-09-30 10:29:24 -0400 | [diff] [blame] | 61 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 62 | using android::base::StringPrintf; |
Tom Cherry | 4c5bde2 | 2019-01-29 14:34:01 -0800 | [diff] [blame] | 63 | using android::fs_mgr::ReadDefaultFstab; |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 64 | |
Jeff Sharkey | 95c87cc | 2015-04-01 11:54:32 -0700 | [diff] [blame] | 65 | int main(int argc, char** argv) { |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 66 | atrace_set_tracing_enabled(false); |
Sudheer Shanka | 40ab674 | 2018-09-18 13:07:45 -0700 | [diff] [blame] | 67 | setenv("ANDROID_LOG_TAGS", "*:d", 1); // Do not submit with verbose logs enabled |
David Anderson | 52de78e | 2021-11-05 19:26:56 -0700 | [diff] [blame] | 68 | android::base::InitLogging(argv, &VoldLogger); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 69 | |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 70 | LOG(INFO) << "Vold 3.0 (the awakening) firing up"; |
| 71 | |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 72 | ATRACE_BEGIN("main"); |
| 73 | |
Sudheer Shanka | 4b6ca4e | 2018-09-21 10:54:54 -0700 | [diff] [blame] | 74 | LOG(DEBUG) << "Detected support for:" |
| 75 | << (android::vold::IsFilesystemSupported("ext4") ? " ext4" : "") |
| 76 | << (android::vold::IsFilesystemSupported("f2fs") ? " f2fs" : "") |
| 77 | << (android::vold::IsFilesystemSupported("vfat") ? " vfat" : ""); |
Jeff Sharkey | d0640f6 | 2015-05-21 22:35:42 -0700 | [diff] [blame] | 78 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 79 | VolumeManager* vm; |
| 80 | NetlinkManager* nm; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 81 | |
Jeff Sharkey | 95c87cc | 2015-04-01 11:54:32 -0700 | [diff] [blame] | 82 | parse_args(argc, argv); |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 83 | |
Stephen Smalley | 684e662 | 2014-09-30 10:29:24 -0400 | [diff] [blame] | 84 | sehandle = selinux_android_file_context_handle(); |
Jeff Sharkey | 95c87cc | 2015-04-01 11:54:32 -0700 | [diff] [blame] | 85 | if (sehandle) { |
Stephen Smalley | 684e662 | 2014-09-30 10:29:24 -0400 | [diff] [blame] | 86 | selinux_android_set_sehandle(sehandle); |
Jeff Sharkey | 95c87cc | 2015-04-01 11:54:32 -0700 | [diff] [blame] | 87 | } |
Stephen Smalley | 684e662 | 2014-09-30 10:29:24 -0400 | [diff] [blame] | 88 | |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 89 | mkdir("/dev/block/vold", 0755); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 90 | |
Ken Sumrall | b9738ea | 2013-03-19 19:42:30 -0700 | [diff] [blame] | 91 | /* For when cryptfs checks and mounts an encrypted filesystem */ |
| 92 | klog_set_level(6); |
| 93 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 94 | /* Create our singleton managers */ |
| 95 | if (!(vm = VolumeManager::Instance())) { |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 96 | LOG(ERROR) << "Unable to create VolumeManager"; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 97 | exit(1); |
Jeff Sharkey | 95c87cc | 2015-04-01 11:54:32 -0700 | [diff] [blame] | 98 | } |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 99 | |
| 100 | if (!(nm = NetlinkManager::Instance())) { |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 101 | LOG(ERROR) << "Unable to create NetlinkManager"; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 102 | exit(1); |
Jeff Sharkey | 95c87cc | 2015-04-01 11:54:32 -0700 | [diff] [blame] | 103 | } |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 104 | |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 105 | if (android::base::GetBoolProperty("vold.debug", false)) { |
Jeff Sharkey | b066787 | 2015-04-29 08:57:18 -0700 | [diff] [blame] | 106 | vm->setDebug(true); |
| 107 | } |
| 108 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 109 | if (vm->start()) { |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 110 | PLOG(ERROR) << "Unable to start VolumeManager"; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 111 | exit(1); |
| 112 | } |
| 113 | |
Jaegeuk Kim | c52f672 | 2020-04-06 15:58:41 -0700 | [diff] [blame] | 114 | VoldConfigs configs = {}; |
| 115 | if (process_config(vm, &configs)) { |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 116 | PLOG(ERROR) << "Error reading configuration... continuing anyways"; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Yifan Hong | 024a124 | 2018-08-10 13:50:46 -0700 | [diff] [blame] | 119 | android::hardware::configureRpcThreadpool(1, false /* callerWillJoin */); |
| 120 | |
Paul Crowley | 3188805 | 2017-09-27 10:56:54 -0700 | [diff] [blame] | 121 | ATRACE_BEGIN("VoldNativeService::start"); |
| 122 | if (android::vold::VoldNativeService::start() != android::OK) { |
| 123 | LOG(ERROR) << "Unable to start VoldNativeService"; |
| 124 | exit(1); |
| 125 | } |
| 126 | ATRACE_END(); |
| 127 | |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 128 | LOG(DEBUG) << "VoldNativeService::start() completed OK"; |
| 129 | |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 130 | ATRACE_BEGIN("NetlinkManager::start"); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 131 | if (nm->start()) { |
Jeff Sharkey | 9f18fe7 | 2015-04-01 23:32:18 -0700 | [diff] [blame] | 132 | PLOG(ERROR) << "Unable to start NetlinkManager"; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 133 | exit(1); |
| 134 | } |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 135 | ATRACE_END(); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 136 | |
Dimitry Ivanov | c976e73 | 2017-01-19 12:48:27 -0800 | [diff] [blame] | 137 | // This call should go after listeners are started to avoid |
| 138 | // a deadlock between vold and init (see b/34278978 for details) |
Jaegeuk Kim | 4ea573a | 2020-04-23 13:43:12 -0700 | [diff] [blame] | 139 | android::base::SetProperty("vold.has_adoptable", configs.has_adoptable ? "1" : "0"); |
Jaegeuk Kim | c52f672 | 2020-04-06 15:58:41 -0700 | [diff] [blame] | 140 | android::base::SetProperty("vold.has_quota", configs.has_quota ? "1" : "0"); |
| 141 | android::base::SetProperty("vold.has_reserved", configs.has_reserved ? "1" : "0"); |
| 142 | android::base::SetProperty("vold.has_compress", configs.has_compress ? "1" : "0"); |
Dimitry Ivanov | c976e73 | 2017-01-19 12:48:27 -0800 | [diff] [blame] | 143 | |
Wei Wang | 2edbe28 | 2017-03-06 17:27:05 -0800 | [diff] [blame] | 144 | // Do coldboot here so it won't block booting, |
| 145 | // also the cold boot is needed in case we have flash drive |
| 146 | // connected before Vold launched |
| 147 | coldboot("/sys/block"); |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 148 | |
| 149 | ATRACE_END(); |
| 150 | |
Jeff Sharkey | 93396c1 | 2017-10-18 16:52:48 -0600 | [diff] [blame] | 151 | android::IPCThreadState::self()->joinThreadPool(); |
| 152 | LOG(INFO) << "vold shutting down"; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 153 | |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 154 | exit(0); |
| 155 | } |
| 156 | |
Jeff Sharkey | 95c87cc | 2015-04-01 11:54:32 -0700 | [diff] [blame] | 157 | static void parse_args(int argc, char** argv) { |
| 158 | static struct option opts[] = { |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 159 | {"blkid_context", required_argument, 0, 'b'}, |
| 160 | {"blkid_untrusted_context", required_argument, 0, 'B'}, |
| 161 | {"fsck_context", required_argument, 0, 'f'}, |
| 162 | {"fsck_untrusted_context", required_argument, 0, 'F'}, |
Eric Biggers | f5ef40d | 2019-04-03 16:32:24 -0700 | [diff] [blame] | 163 | {nullptr, 0, nullptr, 0}, |
Jeff Sharkey | 95c87cc | 2015-04-01 11:54:32 -0700 | [diff] [blame] | 164 | }; |
| 165 | |
| 166 | int c; |
| 167 | while ((c = getopt_long(argc, argv, "", opts, nullptr)) != -1) { |
| 168 | switch (c) { |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 169 | // clang-format off |
Jeff Sharkey | 95c87cc | 2015-04-01 11:54:32 -0700 | [diff] [blame] | 170 | case 'b': android::vold::sBlkidContext = optarg; break; |
| 171 | case 'B': android::vold::sBlkidUntrustedContext = optarg; break; |
| 172 | case 'f': android::vold::sFsckContext = optarg; break; |
| 173 | case 'F': android::vold::sFsckUntrustedContext = optarg; break; |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 174 | // clang-format on |
Jeff Sharkey | 95c87cc | 2015-04-01 11:54:32 -0700 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
| 178 | CHECK(android::vold::sBlkidContext != nullptr); |
| 179 | CHECK(android::vold::sBlkidUntrustedContext != nullptr); |
| 180 | CHECK(android::vold::sFsckContext != nullptr); |
| 181 | CHECK(android::vold::sFsckUntrustedContext != nullptr); |
| 182 | } |
| 183 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 184 | static void do_coldboot(DIR* d, int lvl) { |
| 185 | struct dirent* de; |
Wei Wang | 2edbe28 | 2017-03-06 17:27:05 -0800 | [diff] [blame] | 186 | int dfd, fd; |
| 187 | |
| 188 | dfd = dirfd(d); |
| 189 | |
| 190 | fd = openat(dfd, "uevent", O_WRONLY | O_CLOEXEC); |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 191 | if (fd >= 0) { |
Wei Wang | 2edbe28 | 2017-03-06 17:27:05 -0800 | [diff] [blame] | 192 | write(fd, "add\n", 4); |
| 193 | close(fd); |
| 194 | } |
| 195 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 196 | while ((de = readdir(d))) { |
| 197 | DIR* d2; |
Wei Wang | 2edbe28 | 2017-03-06 17:27:05 -0800 | [diff] [blame] | 198 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 199 | if (de->d_name[0] == '.') continue; |
Wei Wang | 2edbe28 | 2017-03-06 17:27:05 -0800 | [diff] [blame] | 200 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 201 | if (de->d_type != DT_DIR && lvl > 0) continue; |
Wei Wang | 2edbe28 | 2017-03-06 17:27:05 -0800 | [diff] [blame] | 202 | |
Jeff Sharkey | fd3dc3c | 2017-03-27 10:49:21 -0600 | [diff] [blame] | 203 | fd = openat(dfd, de->d_name, O_RDONLY | O_DIRECTORY | O_CLOEXEC); |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 204 | if (fd < 0) continue; |
Wei Wang | 2edbe28 | 2017-03-06 17:27:05 -0800 | [diff] [blame] | 205 | |
| 206 | d2 = fdopendir(fd); |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 207 | if (d2 == 0) |
Wei Wang | 2edbe28 | 2017-03-06 17:27:05 -0800 | [diff] [blame] | 208 | close(fd); |
| 209 | else { |
| 210 | do_coldboot(d2, lvl + 1); |
| 211 | closedir(d2); |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 216 | static void coldboot(const char* path) { |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 217 | ATRACE_NAME("coldboot"); |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 218 | DIR* d = opendir(path); |
| 219 | if (d) { |
Wei Wang | 2edbe28 | 2017-03-06 17:27:05 -0800 | [diff] [blame] | 220 | do_coldboot(d, 0); |
| 221 | closedir(d); |
| 222 | } |
| 223 | } |
| 224 | |
Jaegeuk Kim | c52f672 | 2020-04-06 15:58:41 -0700 | [diff] [blame] | 225 | static int process_config(VolumeManager* vm, VoldConfigs* configs) { |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 226 | ATRACE_NAME("process_config"); |
| 227 | |
Tom Cherry | 4c5bde2 | 2019-01-29 14:34:01 -0800 | [diff] [blame] | 228 | if (!ReadDefaultFstab(&fstab_default)) { |
Bowgo Tsai | e8fb6c3 | 2017-03-09 23:11:33 +0800 | [diff] [blame] | 229 | PLOG(ERROR) << "Failed to open default fstab"; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 230 | return -1; |
| 231 | } |
| 232 | |
Ken Sumrall | 56ad03c | 2013-02-13 13:00:19 -0800 | [diff] [blame] | 233 | /* Loop through entries looking for ones that vold manages */ |
Jaegeuk Kim | c52f672 | 2020-04-06 15:58:41 -0700 | [diff] [blame] | 234 | configs->has_adoptable = false; |
| 235 | configs->has_quota = false; |
| 236 | configs->has_reserved = false; |
| 237 | configs->has_compress = false; |
David Anderson | 0d71c4b | 2019-02-05 17:32:05 -0800 | [diff] [blame] | 238 | for (auto& entry : fstab_default) { |
Tom Cherry | 4c5bde2 | 2019-01-29 14:34:01 -0800 | [diff] [blame] | 239 | if (entry.fs_mgr_flags.quota) { |
Jaegeuk Kim | c52f672 | 2020-04-06 15:58:41 -0700 | [diff] [blame] | 240 | configs->has_quota = true; |
Jeff Sharkey | 95a92f9 | 2017-07-17 13:57:18 -0600 | [diff] [blame] | 241 | } |
Tom Cherry | 4c5bde2 | 2019-01-29 14:34:01 -0800 | [diff] [blame] | 242 | if (entry.reserved_size > 0) { |
Jaegeuk Kim | c52f672 | 2020-04-06 15:58:41 -0700 | [diff] [blame] | 243 | configs->has_reserved = true; |
Jeff Sharkey | 53d5d7c | 2018-01-08 10:43:00 -0700 | [diff] [blame] | 244 | } |
Jaegeuk Kim | f64d30a | 2020-01-14 11:22:26 -0800 | [diff] [blame] | 245 | if (entry.fs_mgr_flags.fs_compress) { |
Jaegeuk Kim | c52f672 | 2020-04-06 15:58:41 -0700 | [diff] [blame] | 246 | configs->has_compress = true; |
Jaegeuk Kim | f64d30a | 2020-01-14 11:22:26 -0800 | [diff] [blame] | 247 | } |
Jeff Sharkey | 95a92f9 | 2017-07-17 13:57:18 -0600 | [diff] [blame] | 248 | |
David Anderson | 0d71c4b | 2019-02-05 17:32:05 -0800 | [diff] [blame] | 249 | /* Make sure logical partitions have an updated blk_device. */ |
P.Adarsh Reddy | 167c2a6 | 2020-04-16 21:46:08 +0530 | [diff] [blame] | 250 | if (entry.fs_mgr_flags.logical && !fs_mgr_update_logical_partition(&entry) && |
| 251 | !entry.fs_mgr_flags.no_fail) { |
David Anderson | 0d71c4b | 2019-02-05 17:32:05 -0800 | [diff] [blame] | 252 | PLOG(FATAL) << "could not find logical partition " << entry.blk_device; |
| 253 | } |
| 254 | |
Eric Biggers | f14f862 | 2022-03-17 23:06:45 +0000 | [diff] [blame] | 255 | if (entry.mount_point == "/data" && !entry.metadata_key_dir.empty()) { |
David Anderson | 156d9d2 | 2021-09-21 17:21:57 -0700 | [diff] [blame] | 256 | // Pre-populate userdata dm-devices since the uevents are asynchronous (b/198405417). |
| 257 | android::vold::defaultkey_precreate_dm_device(); |
| 258 | } |
| 259 | |
Tom Cherry | 4c5bde2 | 2019-01-29 14:34:01 -0800 | [diff] [blame] | 260 | if (entry.fs_mgr_flags.vold_managed) { |
| 261 | if (entry.fs_mgr_flags.nonremovable) { |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 262 | LOG(WARNING) << "nonremovable no longer supported; ignoring volume"; |
| 263 | continue; |
San Mehat | a2677e4 | 2009-12-13 10:40:18 -0800 | [diff] [blame] | 264 | } |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 265 | |
Tom Cherry | 4c5bde2 | 2019-01-29 14:34:01 -0800 | [diff] [blame] | 266 | std::string sysPattern(entry.blk_device); |
| 267 | std::string nickname(entry.label); |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 268 | int flags = 0; |
| 269 | |
Tom Cherry | 4c5bde2 | 2019-01-29 14:34:01 -0800 | [diff] [blame] | 270 | if (entry.is_encryptable()) { |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 271 | flags |= android::vold::Disk::Flags::kAdoptable; |
Jaegeuk Kim | c52f672 | 2020-04-06 15:58:41 -0700 | [diff] [blame] | 272 | configs->has_adoptable = true; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 273 | } |
Tom Cherry | 4c5bde2 | 2019-01-29 14:34:01 -0800 | [diff] [blame] | 274 | if (entry.fs_mgr_flags.no_emulated_sd || |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 275 | android::base::GetBoolProperty("vold.debug.default_primary", false)) { |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 276 | flags |= android::vold::Disk::Flags::kDefaultPrimary; |
Jeff Sharkey | ba6ae8d | 2013-07-15 18:14:25 -0700 | [diff] [blame] | 277 | } |
Ken Sumrall | 29d8da8 | 2011-05-18 17:20:07 -0700 | [diff] [blame] | 278 | |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 279 | vm->addDiskSource(std::shared_ptr<VolumeManager::DiskSource>( |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 280 | new VolumeManager::DiskSource(sysPattern, nickname, flags))); |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 281 | } |
| 282 | } |
Jeff Sharkey | 36801cc | 2015-03-13 16:09:20 -0700 | [diff] [blame] | 283 | return 0; |
San Mehat | f1b736b | 2009-10-10 17:22:08 -0700 | [diff] [blame] | 284 | } |
David Anderson | 52de78e | 2021-11-05 19:26:56 -0700 | [diff] [blame] | 285 | |
| 286 | static void VoldLogger(android::base::LogId log_buffer_id, android::base::LogSeverity severity, |
| 287 | const char* tag, const char* file, unsigned int line, const char* message) { |
| 288 | logd_logger(log_buffer_id, severity, tag, file, line, message); |
| 289 | |
Eric Biggers | fb48666 | 2022-03-22 00:33:52 +0000 | [diff] [blame^] | 290 | if (severity >= android::base::WARNING) { |
| 291 | static bool early_boot_done = false; |
David Anderson | 52de78e | 2021-11-05 19:26:56 -0700 | [diff] [blame] | 292 | |
Eric Biggers | fb48666 | 2022-03-22 00:33:52 +0000 | [diff] [blame^] | 293 | // If metadata encryption setup (fscrypt_mount_metadata_encrypted) or |
| 294 | // basic FBE setup (fscrypt_init_user0) fails, then the boot will fail |
| 295 | // before adb can be started, so logcat won't be available. To allow |
| 296 | // debugging these early boot failures, log early errors and warnings to |
| 297 | // the kernel log. This allows diagnosing failures via the serial log, |
| 298 | // or via last dmesg/"fastboot oem dmesg" on devices that support it. |
David Anderson | 52de78e | 2021-11-05 19:26:56 -0700 | [diff] [blame] | 299 | // |
Eric Biggers | fb48666 | 2022-03-22 00:33:52 +0000 | [diff] [blame^] | 300 | // As a very quick-and-dirty test for whether /data has been mounted, |
| 301 | // check whether /data/misc/vold exists. |
| 302 | if (!early_boot_done) { |
| 303 | if (access("/data/misc/vold", F_OK) == 0 && fscrypt_init_user0_done) { |
| 304 | early_boot_done = true; |
| 305 | return; |
| 306 | } |
| 307 | android::base::KernelLogger(log_buffer_id, severity, tag, file, line, message); |
David Anderson | 52de78e | 2021-11-05 19:26:56 -0700 | [diff] [blame] | 308 | } |
David Anderson | 52de78e | 2021-11-05 19:26:56 -0700 | [diff] [blame] | 309 | } |
| 310 | } |