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 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 19 | #include <errno.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <sys/mount.h> |
| 22 | #include <sys/stat.h> |
| 23 | #include <sys/types.h> |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 24 | #include <sys/wait.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 25 | #include <unistd.h> |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 26 | #include <ctype.h> |
Doug Zongker | f39989a | 2013-12-11 15:40:28 -0800 | [diff] [blame] | 27 | #include <fcntl.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 28 | |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 29 | #include <android-base/logging.h> |
Tao Bao | de40ba5 | 2016-10-05 23:17:01 -0700 | [diff] [blame] | 30 | #include <ext4_utils/make_ext4fs.h> |
| 31 | #include <ext4_utils/wipe.h> |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 32 | #include <fs_mgr.h> |
Tao Bao | de40ba5 | 2016-10-05 23:17:01 -0700 | [diff] [blame] | 33 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 34 | #include "common.h" |
Elliott Hughes | 63a3192 | 2016-06-09 17:41:22 -0700 | [diff] [blame] | 35 | #include "mounts.h" |
Doug Zongker | f39989a | 2013-12-11 15:40:28 -0800 | [diff] [blame] | 36 | #include "cryptfs.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 37 | |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 38 | static struct fstab *fstab = NULL; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 39 | |
Kenny Root | 41dda82 | 2012-03-30 20:48:34 -0700 | [diff] [blame] | 40 | extern struct selabel_handle *sehandle; |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 41 | |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 42 | void load_volume_table() |
| 43 | { |
| 44 | int i; |
| 45 | int ret; |
Doug Zongker | 2810ced | 2011-02-17 15:55:21 -0800 | [diff] [blame] | 46 | |
Bowgo Tsai | 84a0648 | 2017-03-29 15:13:58 +0800 | [diff] [blame] | 47 | fstab = fs_mgr_read_fstab_default(); |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 48 | if (!fstab) { |
Bowgo Tsai | 84a0648 | 2017-03-29 15:13:58 +0800 | [diff] [blame] | 49 | LOG(ERROR) << "failed to read default fstab"; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 50 | return; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 51 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 52 | |
Sasha Levitskiy | 85ef47d | 2014-04-10 17:11:34 -0700 | [diff] [blame] | 53 | ret = fs_mgr_add_entry(fstab, "/tmp", "ramdisk", "ramdisk"); |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 54 | if (ret < 0 ) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 55 | LOG(ERROR) << "failed to add /tmp entry to fstab"; |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 56 | fs_mgr_free_fstab(fstab); |
| 57 | fstab = NULL; |
| 58 | return; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 59 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 60 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 61 | printf("recovery filesystem table\n"); |
| 62 | printf("=========================\n"); |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 63 | for (i = 0; i < fstab->num_entries; ++i) { |
| 64 | Volume* v = &fstab->recs[i]; |
| 65 | printf(" %d %s %s %s %lld\n", i, v->mount_point, v->fs_type, |
| 66 | v->blk_device, v->length); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 67 | } |
| 68 | printf("\n"); |
| 69 | } |
| 70 | |
| 71 | Volume* volume_for_path(const char* path) { |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 72 | return fs_mgr_get_entry_for_mount_point(fstab, path); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Tao Bao | abb8f77 | 2015-07-30 14:43:27 -0700 | [diff] [blame] | 75 | // Mount the volume specified by path at the given mount_point. |
| 76 | int ensure_path_mounted_at(const char* path, const char* mount_point) { |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 77 | Volume* v = volume_for_path(path); |
| 78 | if (v == NULL) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 79 | LOG(ERROR) << "unknown volume for path [" << path << "]"; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 80 | return -1; |
| 81 | } |
Doug Zongker | c18eeb8 | 2010-09-21 16:49:26 -0700 | [diff] [blame] | 82 | if (strcmp(v->fs_type, "ramdisk") == 0) { |
| 83 | // the ramdisk is always mounted. |
| 84 | return 0; |
| 85 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 86 | |
Elliott Hughes | 63a3192 | 2016-06-09 17:41:22 -0700 | [diff] [blame] | 87 | if (!scan_mounted_volumes()) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 88 | LOG(ERROR) << "failed to scan mounted volumes"; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 89 | return -1; |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 90 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 91 | |
Tao Bao | abb8f77 | 2015-07-30 14:43:27 -0700 | [diff] [blame] | 92 | if (!mount_point) { |
| 93 | mount_point = v->mount_point; |
| 94 | } |
| 95 | |
Elliott Hughes | 63a3192 | 2016-06-09 17:41:22 -0700 | [diff] [blame] | 96 | MountedVolume* mv = find_mounted_volume_by_mount_point(mount_point); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 97 | if (mv) { |
| 98 | // volume is already mounted |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 99 | return 0; |
| 100 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 101 | |
Tao Bao | abb8f77 | 2015-07-30 14:43:27 -0700 | [diff] [blame] | 102 | mkdir(mount_point, 0755); // in case it doesn't already exist |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 103 | |
Elliott Hughes | 63a3192 | 2016-06-09 17:41:22 -0700 | [diff] [blame] | 104 | if (strcmp(v->fs_type, "ext4") == 0 || |
Mohamad Ayyash | 522ea72 | 2015-06-29 18:57:14 -0700 | [diff] [blame] | 105 | strcmp(v->fs_type, "squashfs") == 0 || |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 106 | strcmp(v->fs_type, "vfat") == 0) { |
Johan Harvyl | 29dd6b6 | 2016-08-08 12:37:56 +0200 | [diff] [blame] | 107 | int result = mount(v->blk_device, mount_point, v->fs_type, v->flags, v->fs_options); |
| 108 | if (result == -1 && fs_mgr_is_formattable(v)) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 109 | LOG(ERROR) << "failed to mount " << mount_point << " (" << strerror(errno) |
| 110 | << ") , formatting....."; |
Johan Harvyl | 29dd6b6 | 2016-08-08 12:37:56 +0200 | [diff] [blame] | 111 | bool crypt_footer = fs_mgr_is_encryptable(v) && !strcmp(v->key_loc, "footer"); |
| 112 | if (fs_mgr_do_format(v, crypt_footer) == 0) { |
| 113 | result = mount(v->blk_device, mount_point, v->fs_type, v->flags, v->fs_options); |
| 114 | } else { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 115 | PLOG(ERROR) << "failed to format " << mount_point; |
Johan Harvyl | 29dd6b6 | 2016-08-08 12:37:56 +0200 | [diff] [blame] | 116 | return -1; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | if (result == -1) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 121 | PLOG(ERROR) << "failed to mount " << mount_point; |
Elliott Hughes | 63a3192 | 2016-06-09 17:41:22 -0700 | [diff] [blame] | 122 | return -1; |
| 123 | } |
| 124 | return 0; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 127 | LOG(ERROR) << "unknown fs_type \"" << v->fs_type << "\" for " << mount_point; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 128 | return -1; |
| 129 | } |
| 130 | |
Tao Bao | abb8f77 | 2015-07-30 14:43:27 -0700 | [diff] [blame] | 131 | int ensure_path_mounted(const char* path) { |
| 132 | // Mount at the default mount point. |
| 133 | return ensure_path_mounted_at(path, nullptr); |
| 134 | } |
| 135 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 136 | int ensure_path_unmounted(const char* path) { |
| 137 | Volume* v = volume_for_path(path); |
| 138 | if (v == NULL) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 139 | LOG(ERROR) << "unknown volume for path [" << path << "]"; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 140 | return -1; |
| 141 | } |
Doug Zongker | c18eeb8 | 2010-09-21 16:49:26 -0700 | [diff] [blame] | 142 | if (strcmp(v->fs_type, "ramdisk") == 0) { |
| 143 | // the ramdisk is always mounted; you can't unmount it. |
| 144 | return -1; |
| 145 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 146 | |
Elliott Hughes | 63a3192 | 2016-06-09 17:41:22 -0700 | [diff] [blame] | 147 | if (!scan_mounted_volumes()) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 148 | LOG(ERROR) << "failed to scan mounted volumes"; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 149 | return -1; |
| 150 | } |
| 151 | |
Elliott Hughes | 63a3192 | 2016-06-09 17:41:22 -0700 | [diff] [blame] | 152 | MountedVolume* mv = find_mounted_volume_by_mount_point(v->mount_point); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 153 | if (mv == NULL) { |
| 154 | // volume is already unmounted |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 158 | return unmount_mounted_volume(mv); |
| 159 | } |
| 160 | |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 161 | static int exec_cmd(const char* path, char* const argv[]) { |
| 162 | int status; |
| 163 | pid_t child; |
| 164 | if ((child = vfork()) == 0) { |
| 165 | execv(path, argv); |
Tao Bao | 3da8801 | 2017-02-03 13:09:23 -0800 | [diff] [blame] | 166 | _exit(EXIT_FAILURE); |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 167 | } |
| 168 | waitpid(child, &status, 0); |
| 169 | if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 170 | LOG(ERROR) << path << " failed with status " << WEXITSTATUS(status); |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 171 | } |
| 172 | return WEXITSTATUS(status); |
| 173 | } |
| 174 | |
Paul Lawrence | d0db337 | 2015-11-05 13:38:40 -0800 | [diff] [blame] | 175 | int format_volume(const char* volume, const char* directory) { |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 176 | Volume* v = volume_for_path(volume); |
| 177 | if (v == NULL) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 178 | LOG(ERROR) << "unknown volume \"" << volume << "\""; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 179 | return -1; |
| 180 | } |
Doug Zongker | c18eeb8 | 2010-09-21 16:49:26 -0700 | [diff] [blame] | 181 | if (strcmp(v->fs_type, "ramdisk") == 0) { |
| 182 | // you can't format the ramdisk. |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 183 | LOG(ERROR) << "can't format_volume \"" << volume << "\""; |
Doug Zongker | c18eeb8 | 2010-09-21 16:49:26 -0700 | [diff] [blame] | 184 | return -1; |
| 185 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 186 | if (strcmp(v->mount_point, volume) != 0) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 187 | LOG(ERROR) << "can't give path \"" << volume << "\" to format_volume"; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 188 | return -1; |
| 189 | } |
| 190 | |
| 191 | if (ensure_path_unmounted(volume) != 0) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 192 | LOG(ERROR) << "format_volume failed to unmount \"" << v->mount_point << "\""; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 193 | return -1; |
| 194 | } |
| 195 | |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 196 | if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "f2fs") == 0) { |
Doug Zongker | f39989a | 2013-12-11 15:40:28 -0800 | [diff] [blame] | 197 | // if there's a key_loc that looks like a path, it should be a |
| 198 | // block device for storing encryption metadata. wipe it too. |
| 199 | if (v->key_loc != NULL && v->key_loc[0] == '/') { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 200 | LOG(INFO) << "wiping " << v->key_loc; |
Doug Zongker | f39989a | 2013-12-11 15:40:28 -0800 | [diff] [blame] | 201 | int fd = open(v->key_loc, O_WRONLY | O_CREAT, 0644); |
| 202 | if (fd < 0) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 203 | LOG(ERROR) << "format_volume: failed to open " << v->key_loc; |
Doug Zongker | f39989a | 2013-12-11 15:40:28 -0800 | [diff] [blame] | 204 | return -1; |
| 205 | } |
| 206 | wipe_block_device(fd, get_file_size(fd)); |
| 207 | close(fd); |
| 208 | } |
| 209 | |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 210 | ssize_t length = 0; |
| 211 | if (v->length != 0) { |
| 212 | length = v->length; |
| 213 | } else if (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0) { |
| 214 | length = -CRYPT_FOOTER_OFFSET; |
| 215 | } |
| 216 | int result; |
| 217 | if (strcmp(v->fs_type, "ext4") == 0) { |
Connor O'Brien | 98a658b | 2017-01-24 17:31:14 -0800 | [diff] [blame] | 218 | if (v->erase_blk_size != 0 && v->logical_blk_size != 0) { |
| 219 | result = make_ext4fs_directory_align(v->blk_device, length, volume, sehandle, |
| 220 | directory, v->erase_blk_size, v->logical_blk_size); |
| 221 | } else { |
| 222 | result = make_ext4fs_directory(v->blk_device, length, volume, sehandle, directory); |
| 223 | } |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 224 | } else { /* Has to be f2fs because we checked earlier. */ |
| 225 | if (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0 && length < 0) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 226 | LOG(ERROR) << "format_volume: crypt footer + negative length (" << length |
| 227 | << ") not supported on " << v->fs_type; |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 228 | return -1; |
| 229 | } |
| 230 | if (length < 0) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 231 | LOG(ERROR) << "format_volume: negative length (" << length |
| 232 | << ") not supported on " << v->fs_type; |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 233 | return -1; |
| 234 | } |
Jin Qian | adeb41a | 2017-04-28 16:15:13 -0700 | [diff] [blame] | 235 | char *num_sectors = nullptr; |
| 236 | if (length >= 512 && asprintf(&num_sectors, "%zd", length / 512) <= 0) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 237 | LOG(ERROR) << "format_volume: failed to create " << v->fs_type |
| 238 | << " command for " << v->blk_device; |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 239 | return -1; |
| 240 | } |
| 241 | const char *f2fs_path = "/sbin/mkfs.f2fs"; |
Jin Qian | adeb41a | 2017-04-28 16:15:13 -0700 | [diff] [blame] | 242 | const char* const f2fs_argv[] = {"mkfs.f2fs", "-t", "-d1", v->blk_device, num_sectors, nullptr}; |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 243 | |
| 244 | result = exec_cmd(f2fs_path, (char* const*)f2fs_argv); |
| 245 | free(num_sectors); |
| 246 | } |
| 247 | if (result != 0) { |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 248 | PLOG(ERROR) << "format_volume: make " << v->fs_type << " failed on " << v->blk_device; |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 249 | return -1; |
| 250 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 251 | return 0; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 252 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 253 | |
Tianjie Xu | 7b0ad9c | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 254 | 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] | 255 | return -1; |
| 256 | } |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 257 | |
Paul Lawrence | d0db337 | 2015-11-05 13:38:40 -0800 | [diff] [blame] | 258 | int format_volume(const char* volume) { |
| 259 | return format_volume(volume, NULL); |
| 260 | } |
| 261 | |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 262 | int setup_install_mounts() { |
Tao Bao | 57130c4 | 2017-05-10 12:11:21 -0700 | [diff] [blame] | 263 | if (fstab == nullptr) { |
| 264 | LOG(ERROR) << "can't set up install mounts: no fstab loaded"; |
| 265 | return -1; |
| 266 | } |
| 267 | for (int i = 0; i < fstab->num_entries; ++i) { |
| 268 | const Volume* v = fstab->recs + i; |
| 269 | |
| 270 | // We don't want to do anything with "/". |
| 271 | if (strcmp(v->mount_point, "/") == 0) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | if (strcmp(v->mount_point, "/tmp") == 0 || strcmp(v->mount_point, "/cache") == 0) { |
| 276 | if (ensure_path_mounted(v->mount_point) != 0) { |
| 277 | LOG(ERROR) << "failed to mount " << v->mount_point; |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 278 | return -1; |
Tao Bao | 57130c4 | 2017-05-10 12:11:21 -0700 | [diff] [blame] | 279 | } |
| 280 | } else { |
| 281 | if (ensure_path_unmounted(v->mount_point) != 0) { |
| 282 | LOG(ERROR) << "failed to unmount " << v->mount_point; |
| 283 | return -1; |
| 284 | } |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 285 | } |
Tao Bao | 57130c4 | 2017-05-10 12:11:21 -0700 | [diff] [blame] | 286 | } |
| 287 | return 0; |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 288 | } |