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 | |
| 17 | #include <errno.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <sys/mount.h> |
| 20 | #include <sys/stat.h> |
| 21 | #include <sys/types.h> |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 22 | #include <sys/wait.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 23 | #include <unistd.h> |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 24 | #include <ctype.h> |
Doug Zongker | f39989a | 2013-12-11 15:40:28 -0800 | [diff] [blame] | 25 | #include <fcntl.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 26 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 27 | extern "C" { |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 28 | #include <fs_mgr.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 29 | #include "mtdutils/mtdutils.h" |
| 30 | #include "mtdutils/mounts.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 31 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 32 | #include "roots.h" |
| 33 | #include "common.h" |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 34 | #include "make_ext4fs.h" |
Doug Zongker | f39989a | 2013-12-11 15:40:28 -0800 | [diff] [blame] | 35 | extern "C" { |
| 36 | #include "wipe.h" |
| 37 | #include "cryptfs.h" |
| 38 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 39 | |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 40 | static struct fstab *fstab = NULL; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 41 | |
Kenny Root | 41dda82 | 2012-03-30 20:48:34 -0700 | [diff] [blame] | 42 | extern struct selabel_handle *sehandle; |
Stephen Smalley | 779701d | 2012-02-09 14:13:23 -0500 | [diff] [blame] | 43 | |
Andres Morales | ee19387 | 2014-08-05 19:49:09 -0700 | [diff] [blame] | 44 | static const char* PERSISTENT_PATH = "/persistent"; |
| 45 | |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 46 | void load_volume_table() |
| 47 | { |
| 48 | int i; |
| 49 | int ret; |
Doug Zongker | 2810ced | 2011-02-17 15:55:21 -0800 | [diff] [blame] | 50 | |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 51 | fstab = fs_mgr_read_fstab("/etc/recovery.fstab"); |
| 52 | if (!fstab) { |
| 53 | LOGE("failed to read /etc/recovery.fstab\n"); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 54 | return; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 55 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 56 | |
Sasha Levitskiy | 85ef47d | 2014-04-10 17:11:34 -0700 | [diff] [blame] | 57 | ret = fs_mgr_add_entry(fstab, "/tmp", "ramdisk", "ramdisk"); |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 58 | if (ret < 0 ) { |
| 59 | LOGE("failed to add /tmp entry to fstab\n"); |
| 60 | fs_mgr_free_fstab(fstab); |
| 61 | fstab = NULL; |
| 62 | return; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 63 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 64 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 65 | printf("recovery filesystem table\n"); |
| 66 | printf("=========================\n"); |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 67 | for (i = 0; i < fstab->num_entries; ++i) { |
| 68 | Volume* v = &fstab->recs[i]; |
| 69 | printf(" %d %s %s %s %lld\n", i, v->mount_point, v->fs_type, |
| 70 | v->blk_device, v->length); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 71 | } |
| 72 | printf("\n"); |
| 73 | } |
| 74 | |
| 75 | Volume* volume_for_path(const char* path) { |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 76 | 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] | 77 | } |
| 78 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 79 | int ensure_path_mounted(const char* path) { |
Dees_Troy | c51f1f9 | 2012-09-20 15:32:13 -0400 | [diff] [blame] | 80 | if (PartitionManager.Mount_By_Path(path, true)) |
| 81 | return 0; |
| 82 | else |
| 83 | return -1; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 84 | Volume* v = volume_for_path(path); |
| 85 | if (v == NULL) { |
| 86 | LOGE("unknown volume for path [%s]\n", path); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 87 | return -1; |
| 88 | } |
Doug Zongker | c18eeb8 | 2010-09-21 16:49:26 -0700 | [diff] [blame] | 89 | if (strcmp(v->fs_type, "ramdisk") == 0) { |
| 90 | // the ramdisk is always mounted. |
| 91 | return 0; |
| 92 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 93 | |
| 94 | int result; |
| 95 | result = scan_mounted_volumes(); |
| 96 | if (result < 0) { |
| 97 | LOGE("failed to scan mounted volumes\n"); |
| 98 | return -1; |
Doug Zongker | 23ceeea | 2010-07-08 17:27:55 -0700 | [diff] [blame] | 99 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 100 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 101 | const MountedVolume* mv = |
| 102 | find_mounted_volume_by_mount_point(v->mount_point); |
| 103 | if (mv) { |
| 104 | // volume is already mounted |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 105 | return 0; |
| 106 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 107 | |
| 108 | mkdir(v->mount_point, 0755); // in case it doesn't already exist |
| 109 | |
| 110 | if (strcmp(v->fs_type, "yaffs2") == 0) { |
| 111 | // mount an MTD partition as a YAFFS2 filesystem. |
| 112 | mtd_scan_partitions(); |
| 113 | const MtdPartition* partition; |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 114 | partition = mtd_find_partition_by_name(v->blk_device); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 115 | if (partition == NULL) { |
| 116 | LOGE("failed to find \"%s\" partition to mount at \"%s\"\n", |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 117 | v->blk_device, v->mount_point); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 118 | return -1; |
| 119 | } |
| 120 | return mtd_mount_partition(partition, v->mount_point, v->fs_type, 0); |
| 121 | } else if (strcmp(v->fs_type, "ext4") == 0 || |
| 122 | strcmp(v->fs_type, "vfat") == 0) { |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 123 | result = mount(v->blk_device, v->mount_point, v->fs_type, |
Doug Zongker | 469243e | 2011-04-12 09:28:10 -0700 | [diff] [blame] | 124 | MS_NOATIME | MS_NODEV | MS_NODIRATIME, ""); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 125 | if (result == 0) return 0; |
| 126 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 127 | LOGE("failed to mount %s (%s)\n", v->mount_point, strerror(errno)); |
| 128 | return -1; |
| 129 | } |
| 130 | |
| 131 | LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, v->mount_point); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 132 | return -1; |
| 133 | } |
| 134 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 135 | int ensure_path_unmounted(const char* path) { |
Dees_Troy | c51f1f9 | 2012-09-20 15:32:13 -0400 | [diff] [blame] | 136 | if (PartitionManager.UnMount_By_Path(path, true)) |
| 137 | return 0; |
| 138 | else |
| 139 | return -1; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 140 | Volume* v = volume_for_path(path); |
| 141 | if (v == NULL) { |
| 142 | LOGE("unknown volume for path [%s]\n", path); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 143 | return -1; |
| 144 | } |
Doug Zongker | c18eeb8 | 2010-09-21 16:49:26 -0700 | [diff] [blame] | 145 | if (strcmp(v->fs_type, "ramdisk") == 0) { |
| 146 | // the ramdisk is always mounted; you can't unmount it. |
| 147 | return -1; |
| 148 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 149 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 150 | int result; |
| 151 | result = scan_mounted_volumes(); |
| 152 | if (result < 0) { |
| 153 | LOGE("failed to scan mounted volumes\n"); |
| 154 | return -1; |
| 155 | } |
| 156 | |
| 157 | const MountedVolume* mv = |
| 158 | find_mounted_volume_by_mount_point(v->mount_point); |
| 159 | if (mv == NULL) { |
| 160 | // volume is already unmounted |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 161 | return 0; |
| 162 | } |
| 163 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 164 | return unmount_mounted_volume(mv); |
| 165 | } |
| 166 | |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 167 | static int exec_cmd(const char* path, char* const argv[]) { |
| 168 | int status; |
| 169 | pid_t child; |
| 170 | if ((child = vfork()) == 0) { |
| 171 | execv(path, argv); |
| 172 | _exit(-1); |
| 173 | } |
| 174 | waitpid(child, &status, 0); |
| 175 | if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { |
| 176 | LOGE("%s failed with status %d\n", path, WEXITSTATUS(status)); |
| 177 | } |
| 178 | return WEXITSTATUS(status); |
| 179 | } |
| 180 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 181 | int format_volume(const char* volume) { |
Dees_Troy | c51f1f9 | 2012-09-20 15:32:13 -0400 | [diff] [blame] | 182 | if (PartitionManager.Wipe_By_Path(volume)) |
| 183 | return 0; |
| 184 | else |
| 185 | return -1; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 186 | Volume* v = volume_for_path(volume); |
| 187 | if (v == NULL) { |
| 188 | LOGE("unknown volume \"%s\"\n", volume); |
| 189 | return -1; |
| 190 | } |
Doug Zongker | c18eeb8 | 2010-09-21 16:49:26 -0700 | [diff] [blame] | 191 | if (strcmp(v->fs_type, "ramdisk") == 0) { |
| 192 | // you can't format the ramdisk. |
| 193 | LOGE("can't format_volume \"%s\"", volume); |
| 194 | return -1; |
| 195 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 196 | if (strcmp(v->mount_point, volume) != 0) { |
| 197 | LOGE("can't give path \"%s\" to format_volume\n", volume); |
| 198 | return -1; |
| 199 | } |
| 200 | |
| 201 | if (ensure_path_unmounted(volume) != 0) { |
| 202 | LOGE("format_volume failed to unmount \"%s\"\n", v->mount_point); |
| 203 | return -1; |
| 204 | } |
| 205 | |
| 206 | if (strcmp(v->fs_type, "yaffs2") == 0 || strcmp(v->fs_type, "mtd") == 0) { |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 207 | mtd_scan_partitions(); |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 208 | const MtdPartition* partition = mtd_find_partition_by_name(v->blk_device); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 209 | if (partition == NULL) { |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 210 | LOGE("format_volume: no MTD partition \"%s\"\n", v->blk_device); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 211 | return -1; |
| 212 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 213 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 214 | MtdWriteContext *write = mtd_write_partition(partition); |
| 215 | if (write == NULL) { |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 216 | LOGW("format_volume: can't open MTD \"%s\"\n", v->blk_device); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 217 | return -1; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 218 | } else if (mtd_erase_blocks(write, -1) == (off_t) -1) { |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 219 | LOGW("format_volume: can't erase MTD \"%s\"\n", v->blk_device); |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 220 | mtd_write_close(write); |
| 221 | return -1; |
| 222 | } else if (mtd_write_close(write)) { |
Ken Sumrall | f35d1ce | 2013-02-13 12:59:35 -0800 | [diff] [blame] | 223 | LOGW("format_volume: can't close MTD \"%s\"\n", v->blk_device); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 224 | return -1; |
| 225 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 229 | 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] | 230 | // if there's a key_loc that looks like a path, it should be a |
| 231 | // block device for storing encryption metadata. wipe it too. |
| 232 | if (v->key_loc != NULL && v->key_loc[0] == '/') { |
| 233 | LOGI("wiping %s\n", v->key_loc); |
| 234 | int fd = open(v->key_loc, O_WRONLY | O_CREAT, 0644); |
| 235 | if (fd < 0) { |
| 236 | LOGE("format_volume: failed to open %s\n", v->key_loc); |
| 237 | return -1; |
| 238 | } |
| 239 | wipe_block_device(fd, get_file_size(fd)); |
| 240 | close(fd); |
| 241 | } |
| 242 | |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 243 | ssize_t length = 0; |
| 244 | if (v->length != 0) { |
| 245 | length = v->length; |
| 246 | } else if (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0) { |
| 247 | length = -CRYPT_FOOTER_OFFSET; |
| 248 | } |
| 249 | int result; |
| 250 | if (strcmp(v->fs_type, "ext4") == 0) { |
| 251 | result = make_ext4fs(v->blk_device, length, volume, sehandle); |
| 252 | } else { /* Has to be f2fs because we checked earlier. */ |
| 253 | if (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0 && length < 0) { |
JP Abgrall | 78d458c | 2014-08-04 16:44:33 -0700 | [diff] [blame] | 254 | LOGE("format_volume: crypt footer + negative length (%zd) not supported on %s\n", length, v->fs_type); |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 255 | return -1; |
| 256 | } |
| 257 | if (length < 0) { |
JP Abgrall | 78d458c | 2014-08-04 16:44:33 -0700 | [diff] [blame] | 258 | LOGE("format_volume: negative length (%zd) not supported on %s\n", length, v->fs_type); |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 259 | return -1; |
| 260 | } |
| 261 | char *num_sectors; |
JP Abgrall | 78d458c | 2014-08-04 16:44:33 -0700 | [diff] [blame] | 262 | if (asprintf(&num_sectors, "%zd", length / 512) <= 0) { |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 263 | LOGE("format_volume: failed to create %s command for %s\n", v->fs_type, v->blk_device); |
| 264 | return -1; |
| 265 | } |
| 266 | const char *f2fs_path = "/sbin/mkfs.f2fs"; |
| 267 | const char* const f2fs_argv[] = {"mkfs.f2fs", "-t", "-d1", v->blk_device, num_sectors, NULL}; |
| 268 | |
| 269 | result = exec_cmd(f2fs_path, (char* const*)f2fs_argv); |
| 270 | free(num_sectors); |
| 271 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 272 | if (result != 0) { |
JP Abgrall | 37aedb3 | 2014-06-16 19:07:39 -0700 | [diff] [blame] | 273 | LOGE("format_volume: make %s failed on %s with %d(%s)\n", v->fs_type, v->blk_device, result, strerror(errno)); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 274 | return -1; |
| 275 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 276 | return 0; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 277 | } |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 278 | |
| 279 | LOGE("format_volume: fs_type \"%s\" unsupported\n", v->fs_type); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 280 | return -1; |
| 281 | } |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 282 | |
Andres Morales | ee19387 | 2014-08-05 19:49:09 -0700 | [diff] [blame] | 283 | int erase_persistent_partition() { |
| 284 | Volume *v = volume_for_path(PERSISTENT_PATH); |
| 285 | if (v == NULL) { |
| 286 | // most devices won't have /persistent, so this is not an error. |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | int fd = open(v->blk_device, O_RDWR); |
| 291 | uint64_t size = get_file_size(fd); |
| 292 | if (size == 0) { |
| 293 | LOGE("failed to stat size of /persistent\n"); |
| 294 | close(fd); |
| 295 | return -1; |
| 296 | } |
| 297 | |
| 298 | char oem_unlock_enabled; |
| 299 | lseek(fd, size - 1, SEEK_SET); |
| 300 | read(fd, &oem_unlock_enabled, 1); |
| 301 | |
| 302 | if (oem_unlock_enabled) { |
| 303 | if (wipe_block_device(fd, size)) { |
| 304 | LOGE("error wiping /persistent: %s\n", strerror(errno)); |
| 305 | close(fd); |
| 306 | return -1; |
| 307 | } |
| 308 | |
| 309 | lseek(fd, size - 1, SEEK_SET); |
| 310 | write(fd, &oem_unlock_enabled, 1); |
| 311 | } |
| 312 | |
| 313 | close(fd); |
| 314 | |
| 315 | return (int) oem_unlock_enabled; |
| 316 | } |
| 317 | |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 318 | int setup_install_mounts() { |
| 319 | if (fstab == NULL) { |
| 320 | LOGE("can't set up install mounts: no fstab loaded\n"); |
| 321 | return -1; |
| 322 | } |
| 323 | for (int i = 0; i < fstab->num_entries; ++i) { |
| 324 | Volume* v = fstab->recs + i; |
| 325 | |
| 326 | if (strcmp(v->mount_point, "/tmp") == 0 || |
| 327 | strcmp(v->mount_point, "/cache") == 0) { |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 328 | if (ensure_path_mounted(v->mount_point) != 0) { |
| 329 | LOGE("failed to mount %s\n", v->mount_point); |
| 330 | return -1; |
| 331 | } |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 332 | |
| 333 | } else { |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 334 | if (ensure_path_unmounted(v->mount_point) != 0) { |
| 335 | LOGE("failed to unmount %s\n", v->mount_point); |
| 336 | return -1; |
| 337 | } |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | return 0; |
| 341 | } |