The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
Elliott Hughes | 63a3192 | 2016-06-09 17:41:22 -0700 | [diff] [blame] | 17 | #include "roots.h" |
| 18 | |
Tao Bao | bb10e58 | 2017-07-22 16:30:34 -0700 | [diff] [blame] | 19 | #include <ctype.h> |
| 20 | #include <fcntl.h> |
Tom Cherry | 45e505a | 2018-11-29 13:33:07 -0800 | [diff] [blame] | 21 | #include <inttypes.h> |
Abhishek Arpure | 4fec8e9 | 2017-08-24 15:27:16 +0530 | [diff] [blame] | 22 | #include <stdint.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 23 | #include <stdlib.h> |
Tao Bao | ad774b2 | 2017-09-29 10:39:08 -0700 | [diff] [blame] | 24 | #include <string.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 25 | #include <sys/mount.h> |
| 26 | #include <sys/stat.h> |
| 27 | #include <sys/types.h> |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 28 | #include <sys/wait.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 29 | #include <unistd.h> |
| 30 | |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 31 | #include <algorithm> |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 32 | #include <iostream> |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 33 | #include <string> |
| 34 | #include <vector> |
| 35 | |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 36 | #include <android-base/logging.h> |
Jin Qian | ded2dac | 2017-04-21 14:36:12 -0700 | [diff] [blame] | 37 | #include <android-base/properties.h> |
| 38 | #include <android-base/stringprintf.h> |
Jin Qian | f3ccad5 | 2017-07-24 10:34:35 -0700 | [diff] [blame] | 39 | #include <android-base/unique_fd.h> |
Tao Bao | bb10e58 | 2017-07-22 16:30:34 -0700 | [diff] [blame] | 40 | #include <cryptfs.h> |
Tao Bao | de40ba5 | 2016-10-05 23:17:01 -0700 | [diff] [blame] | 41 | #include <ext4_utils/wipe.h> |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 42 | #include <fs_mgr.h> |
Yifan Hong | 0f339e2 | 2018-12-03 13:44:01 -0800 | [diff] [blame] | 43 | #include <fs_mgr/roots.h> |
David Anderson | 2b2f423 | 2018-10-29 18:48:56 -0700 | [diff] [blame] | 44 | #include <fs_mgr_dm_linear.h> |
Tao Bao | de40ba5 | 2016-10-05 23:17:01 -0700 | [diff] [blame] | 45 | |
Tao Bao | 9a319f0 | 2018-01-04 13:19:11 -0800 | [diff] [blame] | 46 | #include "otautil/mounts.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 47 | |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 48 | static Fstab fstab; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 49 | |
Tao Bao | bb10e58 | 2017-07-22 16:30:34 -0700 | [diff] [blame] | 50 | extern struct selabel_handle* sehandle; |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 51 | |
Tao Bao | bb10e58 | 2017-07-22 16:30:34 -0700 | [diff] [blame] | 52 | void load_volume_table() { |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 53 | if (!ReadDefaultFstab(&fstab)) { |
Tao Bao | bb10e58 | 2017-07-22 16:30:34 -0700 | [diff] [blame] | 54 | LOG(ERROR) << "Failed to read default fstab"; |
| 55 | return; |
| 56 | } |
Doug Zongker | 2810ced | 2011-02-17 15:55:21 -0800 | [diff] [blame] | 57 | |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 58 | fstab.emplace_back(FstabEntry{ |
| 59 | .mount_point = "/tmp", .fs_type = "ramdisk", .blk_device = "ramdisk", .length = 0 }); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 60 | |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 61 | std::cout << "recovery filesystem table" << std::endl << "=========================" << std::endl; |
| 62 | for (size_t i = 0; i < fstab.size(); ++i) { |
| 63 | const auto& entry = fstab[i]; |
| 64 | std::cout << " " << i << " " << entry.mount_point << " " |
| 65 | << " " << entry.fs_type << " " << entry.blk_device << " " << entry.length |
| 66 | << std::endl; |
Tao Bao | bb10e58 | 2017-07-22 16:30:34 -0700 | [diff] [blame] | 67 | } |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 68 | std::cout << std::endl; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Tao Bao | 3e18f2b | 2017-09-29 17:11:13 -0700 | [diff] [blame] | 71 | Volume* volume_for_mount_point(const std::string& mount_point) { |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 72 | auto it = std::find_if(fstab.begin(), fstab.end(), [&mount_point](const auto& entry) { |
| 73 | return entry.mount_point == mount_point; |
| 74 | }); |
| 75 | return it == fstab.end() ? nullptr : &*it; |
Tao Bao | 3e18f2b | 2017-09-29 17:11:13 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Tao Bao | abb8f77 | 2015-07-30 14:43:27 -0700 | [diff] [blame] | 78 | // Mount the volume specified by path at the given mount_point. |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 79 | int ensure_path_mounted_at(const std::string& path, const std::string& mount_point) { |
| 80 | return android::fs_mgr::EnsurePathMounted(&fstab, path, mount_point) ? 0 : -1; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 83 | int ensure_path_mounted(const std::string& path) { |
Tao Bao | bb10e58 | 2017-07-22 16:30:34 -0700 | [diff] [blame] | 84 | // Mount at the default mount point. |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 85 | return android::fs_mgr::EnsurePathMounted(&fstab, path) ? 0 : -1; |
Tao Bao | abb8f77 | 2015-07-30 14:43:27 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 88 | int ensure_path_unmounted(const std::string& path) { |
| 89 | return android::fs_mgr::EnsurePathUnmounted(&fstab, path) ? 0 : -1; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 92 | static int exec_cmd(const std::vector<std::string>& args) { |
| 93 | CHECK_NE(static_cast<size_t>(0), args.size()); |
| 94 | |
| 95 | std::vector<char*> argv(args.size()); |
| 96 | std::transform(args.cbegin(), args.cend(), argv.begin(), |
| 97 | [](const std::string& arg) { return const_cast<char*>(arg.c_str()); }); |
| 98 | argv.push_back(nullptr); |
| 99 | |
| 100 | pid_t child; |
George Burgess IV | 1cfb361 | 2018-02-17 17:48:45 -0800 | [diff] [blame] | 101 | if ((child = fork()) == 0) { |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 102 | execv(argv[0], argv.data()); |
| 103 | _exit(EXIT_FAILURE); |
| 104 | } |
| 105 | |
| 106 | int status; |
| 107 | waitpid(child, &status, 0); |
| 108 | if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { |
| 109 | LOG(ERROR) << args[0] << " failed with status " << WEXITSTATUS(status); |
| 110 | } |
| 111 | return WEXITSTATUS(status); |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Abhishek Arpure | 4fec8e9 | 2017-08-24 15:27:16 +0530 | [diff] [blame] | 114 | static int64_t get_file_size(int fd, uint64_t reserve_len) { |
Jin Qian | f3ccad5 | 2017-07-24 10:34:35 -0700 | [diff] [blame] | 115 | struct stat buf; |
| 116 | int ret = fstat(fd, &buf); |
| 117 | if (ret) return 0; |
| 118 | |
Abhishek Arpure | 4fec8e9 | 2017-08-24 15:27:16 +0530 | [diff] [blame] | 119 | int64_t computed_size; |
Jin Qian | f3ccad5 | 2017-07-24 10:34:35 -0700 | [diff] [blame] | 120 | if (S_ISREG(buf.st_mode)) { |
| 121 | computed_size = buf.st_size - reserve_len; |
| 122 | } else if (S_ISBLK(buf.st_mode)) { |
Abhishek Arpure | 4fec8e9 | 2017-08-24 15:27:16 +0530 | [diff] [blame] | 123 | uint64_t block_device_size = get_block_device_size(fd); |
| 124 | if (block_device_size < reserve_len || |
| 125 | block_device_size > std::numeric_limits<int64_t>::max()) { |
| 126 | computed_size = 0; |
| 127 | } else { |
| 128 | computed_size = block_device_size - reserve_len; |
| 129 | } |
Jin Qian | f3ccad5 | 2017-07-24 10:34:35 -0700 | [diff] [blame] | 130 | } else { |
| 131 | computed_size = 0; |
| 132 | } |
| 133 | |
| 134 | return computed_size; |
| 135 | } |
| 136 | |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 137 | int format_volume(const std::string& volume, const std::string& directory) { |
| 138 | const FstabEntry* v = android::fs_mgr::GetEntryForPath(&fstab, volume); |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 139 | if (v == nullptr) { |
| 140 | LOG(ERROR) << "unknown volume \"" << volume << "\""; |
| 141 | return -1; |
| 142 | } |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 143 | if (v->fs_type == "ramdisk") { |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 144 | LOG(ERROR) << "can't format_volume \"" << volume << "\""; |
| 145 | return -1; |
| 146 | } |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 147 | if (v->mount_point != volume) { |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 148 | LOG(ERROR) << "can't give path \"" << volume << "\" to format_volume"; |
| 149 | return -1; |
| 150 | } |
| 151 | if (ensure_path_unmounted(volume) != 0) { |
| 152 | LOG(ERROR) << "format_volume: Failed to unmount \"" << v->mount_point << "\""; |
| 153 | return -1; |
| 154 | } |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 155 | if (v->fs_type != "ext4" && v->fs_type != "f2fs") { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 156 | LOG(ERROR) << "format_volume: fs_type \"" << v->fs_type << "\" unsupported"; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 157 | return -1; |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | // If there's a key_loc that looks like a path, it should be a block device for storing encryption |
| 161 | // metadata. Wipe it too. |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 162 | if (!v->key_loc.empty() && v->key_loc[0] == '/') { |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 163 | LOG(INFO) << "Wiping " << v->key_loc; |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 164 | int fd = open(v->key_loc.c_str(), O_WRONLY | O_CREAT, 0644); |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 165 | if (fd == -1) { |
| 166 | PLOG(ERROR) << "format_volume: Failed to open " << v->key_loc; |
| 167 | return -1; |
| 168 | } |
| 169 | wipe_block_device(fd, get_file_size(fd)); |
| 170 | close(fd); |
| 171 | } |
| 172 | |
Abhishek Arpure | 4fec8e9 | 2017-08-24 15:27:16 +0530 | [diff] [blame] | 173 | int64_t length = 0; |
Jin Qian | cc10008 | 2017-11-17 23:53:22 -0800 | [diff] [blame] | 174 | if (v->length > 0) { |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 175 | length = v->length; |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 176 | } else if (v->length < 0 || v->key_loc == "footer") { |
| 177 | android::base::unique_fd fd(open(v->blk_device.c_str(), O_RDONLY)); |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 178 | if (fd == -1) { |
Abhishek Arpure | 4fec8e9 | 2017-08-24 15:27:16 +0530 | [diff] [blame] | 179 | PLOG(ERROR) << "format_volume: failed to open " << v->blk_device; |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 180 | return -1; |
| 181 | } |
Jin Qian | cc10008 | 2017-11-17 23:53:22 -0800 | [diff] [blame] | 182 | length = |
| 183 | get_file_size(fd.get(), v->length ? -v->length : CRYPT_FOOTER_OFFSET); |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 184 | if (length <= 0) { |
Jin Qian | cc10008 | 2017-11-17 23:53:22 -0800 | [diff] [blame] | 185 | LOG(ERROR) << "get_file_size: invalid size " << length << " for " |
| 186 | << v->blk_device; |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 187 | return -1; |
| 188 | } |
| 189 | } |
| 190 | |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 191 | if (v->fs_type == "ext4") { |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 192 | static constexpr int kBlockSize = 4096; |
| 193 | std::vector<std::string> mke2fs_args = { |
Jiyong Park | 69364fe | 2018-06-20 14:18:18 +0900 | [diff] [blame] | 194 | "/system/bin/mke2fs", "-F", "-t", "ext4", "-b", std::to_string(kBlockSize), |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | int raid_stride = v->logical_blk_size / kBlockSize; |
| 198 | int raid_stripe_width = v->erase_blk_size / kBlockSize; |
| 199 | // stride should be the max of 8KB and logical block size |
| 200 | if (v->logical_blk_size != 0 && v->logical_blk_size < 8192) { |
| 201 | raid_stride = 8192 / kBlockSize; |
| 202 | } |
| 203 | if (v->erase_blk_size != 0 && v->logical_blk_size != 0) { |
| 204 | mke2fs_args.push_back("-E"); |
| 205 | mke2fs_args.push_back( |
| 206 | android::base::StringPrintf("stride=%d,stripe-width=%d", raid_stride, raid_stripe_width)); |
| 207 | } |
| 208 | mke2fs_args.push_back(v->blk_device); |
| 209 | if (length != 0) { |
| 210 | mke2fs_args.push_back(std::to_string(length / kBlockSize)); |
| 211 | } |
| 212 | |
| 213 | int result = exec_cmd(mke2fs_args); |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 214 | if (result == 0 && !directory.empty()) { |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 215 | std::vector<std::string> e2fsdroid_args = { |
Jiyong Park | 69364fe | 2018-06-20 14:18:18 +0900 | [diff] [blame] | 216 | "/system/bin/e2fsdroid", "-e", "-f", directory, "-a", volume, v->blk_device, |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 217 | }; |
| 218 | result = exec_cmd(e2fsdroid_args); |
| 219 | } |
| 220 | |
| 221 | if (result != 0) { |
| 222 | PLOG(ERROR) << "format_volume: Failed to make ext4 on " << v->blk_device; |
| 223 | return -1; |
| 224 | } |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | // Has to be f2fs because we checked earlier. |
Jaegeuk Kim | 4358262 | 2018-04-02 13:37:35 -0700 | [diff] [blame] | 229 | static constexpr int kSectorSize = 4096; |
Jaegeuk Kim | c1c7311 | 2017-11-28 19:48:05 -0800 | [diff] [blame] | 230 | std::string cmd("/sbin/mkfs.f2fs"); |
Jaegeuk Kim | 4358262 | 2018-04-02 13:37:35 -0700 | [diff] [blame] | 231 | // clang-format off |
| 232 | std::vector<std::string> make_f2fs_cmd = { |
| 233 | cmd, |
Jaegeuk Kim | 91e631d | 2018-11-21 11:12:54 -0800 | [diff] [blame] | 234 | "-g", "android", |
Jaegeuk Kim | 4358262 | 2018-04-02 13:37:35 -0700 | [diff] [blame] | 235 | v->blk_device, |
| 236 | }; |
| 237 | // clang-format on |
| 238 | if (length >= kSectorSize) { |
| 239 | make_f2fs_cmd.push_back(std::to_string(length / kSectorSize)); |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Jaegeuk Kim | c1c7311 | 2017-11-28 19:48:05 -0800 | [diff] [blame] | 242 | int result = exec_cmd(make_f2fs_cmd); |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 243 | if (result == 0 && !directory.empty()) { |
Jaegeuk Kim | c1c7311 | 2017-11-28 19:48:05 -0800 | [diff] [blame] | 244 | cmd = "/sbin/sload.f2fs"; |
Jaegeuk Kim | 4358262 | 2018-04-02 13:37:35 -0700 | [diff] [blame] | 245 | // clang-format off |
Jaegeuk Kim | c1c7311 | 2017-11-28 19:48:05 -0800 | [diff] [blame] | 246 | std::vector<std::string> sload_f2fs_cmd = { |
Jaegeuk Kim | 4358262 | 2018-04-02 13:37:35 -0700 | [diff] [blame] | 247 | cmd, |
| 248 | "-f", directory, |
| 249 | "-t", volume, |
| 250 | v->blk_device, |
Jaegeuk Kim | c1c7311 | 2017-11-28 19:48:05 -0800 | [diff] [blame] | 251 | }; |
Jaegeuk Kim | 4358262 | 2018-04-02 13:37:35 -0700 | [diff] [blame] | 252 | // clang-format on |
Jaegeuk Kim | c1c7311 | 2017-11-28 19:48:05 -0800 | [diff] [blame] | 253 | result = exec_cmd(sload_f2fs_cmd); |
| 254 | } |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 255 | if (result != 0) { |
Jaegeuk Kim | c1c7311 | 2017-11-28 19:48:05 -0800 | [diff] [blame] | 256 | PLOG(ERROR) << "format_volume: Failed " << cmd << " on " << v->blk_device; |
Tao Bao | 3c00fac | 2017-07-22 16:46:54 -0700 | [diff] [blame] | 257 | return -1; |
| 258 | } |
| 259 | return 0; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 260 | } |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 261 | |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 262 | int format_volume(const std::string& volume) { |
| 263 | return format_volume(volume, ""); |
Paul Lawrence | d0db337 | 2015-11-05 13:38:40 -0800 | [diff] [blame] | 264 | } |
| 265 | |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 266 | int setup_install_mounts() { |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 267 | if (fstab.empty()) { |
Tao Bao | 57130c4 | 2017-05-10 12:11:21 -0700 | [diff] [blame] | 268 | LOG(ERROR) << "can't set up install mounts: no fstab loaded"; |
| 269 | return -1; |
| 270 | } |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 271 | for (const FstabEntry& entry : fstab) { |
Tao Bao | 57130c4 | 2017-05-10 12:11:21 -0700 | [diff] [blame] | 272 | // We don't want to do anything with "/". |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 273 | if (entry.mount_point == "/") { |
Tao Bao | 57130c4 | 2017-05-10 12:11:21 -0700 | [diff] [blame] | 274 | continue; |
| 275 | } |
| 276 | |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 277 | if (entry.mount_point == "/tmp" || entry.mount_point == "/cache") { |
| 278 | if (ensure_path_mounted(entry.mount_point) != 0) { |
| 279 | LOG(ERROR) << "Failed to mount " << entry.mount_point; |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 280 | return -1; |
Tao Bao | 57130c4 | 2017-05-10 12:11:21 -0700 | [diff] [blame] | 281 | } |
| 282 | } else { |
Yifan Hong | d81b8e3 | 2018-12-17 14:29:06 -0800 | [diff] [blame] | 283 | if (ensure_path_unmounted(entry.mount_point) != 0) { |
| 284 | LOG(ERROR) << "Failed to unmount " << entry.mount_point; |
Tao Bao | 57130c4 | 2017-05-10 12:11:21 -0700 | [diff] [blame] | 285 | return -1; |
| 286 | } |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 287 | } |
Tao Bao | 57130c4 | 2017-05-10 12:11:21 -0700 | [diff] [blame] | 288 | } |
| 289 | return 0; |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 290 | } |
David Anderson | 2b2f423 | 2018-10-29 18:48:56 -0700 | [diff] [blame] | 291 | |
| 292 | bool logical_partitions_mapped() { |
Yifan Hong | 0f339e2 | 2018-12-03 13:44:01 -0800 | [diff] [blame] | 293 | return android::fs_mgr::LogicalPartitionsMapped(); |
David Anderson | 2b2f423 | 2018-10-29 18:48:56 -0700 | [diff] [blame] | 294 | } |
Yifan Hong | 4932780 | 2018-11-26 14:59:09 -0800 | [diff] [blame] | 295 | |
| 296 | std::string get_system_root() { |
Yifan Hong | 0f339e2 | 2018-12-03 13:44:01 -0800 | [diff] [blame] | 297 | return android::fs_mgr::GetSystemRoot(); |
Yifan Hong | 4932780 | 2018-11-26 14:59:09 -0800 | [diff] [blame] | 298 | } |