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