Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Mattias Nissler | 097b6bb | 2016-03-31 16:32:09 +0200 | [diff] [blame] | 17 | #include <ctype.h> |
| 18 | #include <dirent.h> |
| 19 | #include <errno.h> |
| 20 | #include <fcntl.h> |
| 21 | #include <libgen.h> |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 25 | #include <sys/ioctl.h> |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 26 | #include <sys/mount.h> |
| 27 | #include <sys/stat.h> |
Mattias Nissler | 097b6bb | 2016-03-31 16:32:09 +0200 | [diff] [blame] | 28 | #include <sys/swap.h> |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 29 | #include <sys/types.h> |
| 30 | #include <sys/wait.h> |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 31 | #include <time.h> |
Mattias Nissler | 097b6bb | 2016-03-31 16:32:09 +0200 | [diff] [blame] | 32 | #include <unistd.h> |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 33 | |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 34 | #include <android-base/unique_fd.h> |
JP Abgrall | 4bb7bba | 2014-06-19 22:12:20 -0700 | [diff] [blame] | 35 | #include <cutils/android_reboot.h> |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 36 | #include <cutils/partition_utils.h> |
| 37 | #include <cutils/properties.h> |
Tao Bao | 6d881d6 | 2016-10-05 17:53:30 -0700 | [diff] [blame] | 38 | #include <ext4_utils/ext4.h> |
| 39 | #include <ext4_utils/ext4_crypt_init_extensions.h> |
| 40 | #include <ext4_utils/ext4_sb.h> |
| 41 | #include <ext4_utils/ext4_utils.h> |
| 42 | #include <ext4_utils/wipe.h> |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 43 | #include <linux/fs.h> |
Mattias Nissler | 097b6bb | 2016-03-31 16:32:09 +0200 | [diff] [blame] | 44 | #include <linux/loop.h> |
Ken Sumrall | bf021b4 | 2013-03-19 19:38:44 -0700 | [diff] [blame] | 45 | #include <logwrap/logwrap.h> |
Mattias Nissler | 097b6bb | 2016-03-31 16:32:09 +0200 | [diff] [blame] | 46 | #include <private/android_filesystem_config.h> |
Mark Salyzyn | e528be5 | 2016-03-29 14:25:11 -0700 | [diff] [blame] | 47 | #include <private/android_logger.h> |
Geremy Condra | 3ad3d1c | 2013-02-22 18:11:41 -0800 | [diff] [blame] | 48 | |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 49 | #include "fs_mgr_priv.h" |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 50 | #include "fs_mgr_priv_avb.h" |
Geremy Condra | 3ad3d1c | 2013-02-22 18:11:41 -0800 | [diff] [blame] | 51 | #include "fs_mgr_priv_verity.h" |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 52 | |
| 53 | #define KEY_LOC_PROP "ro.crypto.keyfile.userdata" |
| 54 | #define KEY_IN_FOOTER "footer" |
| 55 | |
| 56 | #define E2FSCK_BIN "/system/bin/e2fsck" |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 57 | #define F2FS_FSCK_BIN "/system/bin/fsck.f2fs" |
Ken Sumrall | 5bc31a2 | 2013-07-08 19:11:55 -0700 | [diff] [blame] | 58 | #define MKSWAP_BIN "/system/bin/mkswap" |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 59 | #define TUNE2FS_BIN "/system/bin/tune2fs" |
Ken Sumrall | 5bc31a2 | 2013-07-08 19:11:55 -0700 | [diff] [blame] | 60 | |
Ken Sumrall | 4eaf905 | 2013-09-18 17:49:21 -0700 | [diff] [blame] | 61 | #define FSCK_LOG_FILE "/dev/fscklogs/log" |
| 62 | |
Ken Sumrall | 5bc31a2 | 2013-07-08 19:11:55 -0700 | [diff] [blame] | 63 | #define ZRAM_CONF_DEV "/sys/block/zram0/disksize" |
Peter Enderborg | 4d217f0 | 2016-08-26 15:09:35 +0200 | [diff] [blame] | 64 | #define ZRAM_CONF_MCS "/sys/block/zram0/max_comp_streams" |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 65 | |
Ken Sumrall | bf021b4 | 2013-03-19 19:38:44 -0700 | [diff] [blame] | 66 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a))) |
| 67 | |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 68 | /* |
| 69 | * gettime() - returns the time in seconds of the system's monotonic clock or |
| 70 | * zero on error. |
| 71 | */ |
| 72 | static time_t gettime(void) |
| 73 | { |
| 74 | struct timespec ts; |
| 75 | int ret; |
| 76 | |
| 77 | ret = clock_gettime(CLOCK_MONOTONIC, &ts); |
| 78 | if (ret < 0) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 79 | PERROR << "clock_gettime(CLOCK_MONOTONIC) failed"; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | return ts.tv_sec; |
| 84 | } |
| 85 | |
| 86 | static int wait_for_file(const char *filename, int timeout) |
| 87 | { |
| 88 | struct stat info; |
| 89 | time_t timeout_time = gettime() + timeout; |
| 90 | int ret = -1; |
| 91 | |
| 92 | while (gettime() < timeout_time && ((ret = stat(filename, &info)) < 0)) |
| 93 | usleep(10000); |
| 94 | |
| 95 | return ret; |
| 96 | } |
| 97 | |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 98 | static void check_fs(const char *blk_device, char *fs_type, char *target) |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 99 | { |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 100 | int status; |
Ken Sumrall | 5dc5bfe | 2012-07-23 19:34:00 -0700 | [diff] [blame] | 101 | int ret; |
| 102 | long tmpmnt_flags = MS_NOATIME | MS_NOEXEC | MS_NOSUID; |
Oreste Salerno | 6ed84c9 | 2015-05-20 17:01:39 +0000 | [diff] [blame] | 103 | char tmpmnt_opts[64] = "errors=remount-ro"; |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 104 | const char *e2fsck_argv[] = { |
Ken Sumrall | bf021b4 | 2013-03-19 19:38:44 -0700 | [diff] [blame] | 105 | E2FSCK_BIN, |
Keun-young Park | 22e8199 | 2017-01-09 16:39:49 -0800 | [diff] [blame] | 106 | #ifndef TARGET_USES_MKE2FS // "-f" only for old ext4 generation tool |
Robb Glasser | 3fb176c | 2016-04-05 18:43:37 +0000 | [diff] [blame] | 107 | "-f", |
Keun-young Park | 22e8199 | 2017-01-09 16:39:49 -0800 | [diff] [blame] | 108 | #endif |
Ken Sumrall | bf021b4 | 2013-03-19 19:38:44 -0700 | [diff] [blame] | 109 | "-y", |
| 110 | blk_device |
| 111 | }; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 112 | |
| 113 | /* Check for the types of filesystems we know how to check */ |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 114 | if (!strcmp(fs_type, "ext2") || !strcmp(fs_type, "ext3") || !strcmp(fs_type, "ext4")) { |
Ken Sumrall | 5dc5bfe | 2012-07-23 19:34:00 -0700 | [diff] [blame] | 115 | /* |
| 116 | * First try to mount and unmount the filesystem. We do this because |
| 117 | * the kernel is more efficient than e2fsck in running the journal and |
| 118 | * processing orphaned inodes, and on at least one device with a |
| 119 | * performance issue in the emmc firmware, it can take e2fsck 2.5 minutes |
| 120 | * to do what the kernel does in about a second. |
| 121 | * |
| 122 | * After mounting and unmounting the filesystem, run e2fsck, and if an |
| 123 | * error is recorded in the filesystem superblock, e2fsck will do a full |
| 124 | * check. Otherwise, it does nothing. If the kernel cannot mount the |
| 125 | * filesytsem due to an error, e2fsck is still run to do a full check |
| 126 | * fix the filesystem. |
| 127 | */ |
Elliott Hughes | 5e7dd44 | 2015-04-24 11:05:48 -0700 | [diff] [blame] | 128 | errno = 0; |
Oreste Salerno | 6ed84c9 | 2015-05-20 17:01:39 +0000 | [diff] [blame] | 129 | if (!strcmp(fs_type, "ext4")) { |
| 130 | // This option is only valid with ext4 |
| 131 | strlcat(tmpmnt_opts, ",nomblk_io_submit", sizeof(tmpmnt_opts)); |
| 132 | } |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 133 | ret = mount(blk_device, target, fs_type, tmpmnt_flags, tmpmnt_opts); |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 134 | PINFO << __FUNCTION__ << "(): mount(" << blk_device << "," << target |
| 135 | << "," << fs_type << ")=" << ret; |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 136 | if (!ret) { |
Nick Kralevich | 7294eb6 | 2015-02-05 16:02:42 -0800 | [diff] [blame] | 137 | int i; |
| 138 | for (i = 0; i < 5; i++) { |
| 139 | // Try to umount 5 times before continuing on. |
| 140 | // Should we try rebooting if all attempts fail? |
| 141 | int result = umount(target); |
| 142 | if (result == 0) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 143 | LINFO << __FUNCTION__ << "(): unmount(" << target |
| 144 | << ") succeeded"; |
Nick Kralevich | 7294eb6 | 2015-02-05 16:02:42 -0800 | [diff] [blame] | 145 | break; |
| 146 | } |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 147 | PERROR << __FUNCTION__ << "(): umount(" << target << ")=" |
| 148 | << result; |
Nick Kralevich | 7294eb6 | 2015-02-05 16:02:42 -0800 | [diff] [blame] | 149 | sleep(1); |
| 150 | } |
Ken Sumrall | 5dc5bfe | 2012-07-23 19:34:00 -0700 | [diff] [blame] | 151 | } |
| 152 | |
David 'Digit' Turner | 28483d7 | 2014-02-17 11:14:44 +0100 | [diff] [blame] | 153 | /* |
| 154 | * Some system images do not have e2fsck for licensing reasons |
| 155 | * (e.g. recent SDK system images). Detect these and skip the check. |
| 156 | */ |
| 157 | if (access(E2FSCK_BIN, X_OK)) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 158 | LINFO << "Not running " << E2FSCK_BIN << " on " << blk_device |
| 159 | << " (executable not in system image)"; |
David 'Digit' Turner | 28483d7 | 2014-02-17 11:14:44 +0100 | [diff] [blame] | 160 | } else { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 161 | LINFO << "Running " << E2FSCK_BIN << " on " << blk_device; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 162 | |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 163 | ret = android_fork_execvp_ext(ARRAY_SIZE(e2fsck_argv), |
| 164 | const_cast<char **>(e2fsck_argv), |
Yusuke Sato | d81c3c6 | 2015-08-14 01:22:53 -0700 | [diff] [blame] | 165 | &status, true, LOG_KLOG | LOG_FILE, |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 166 | true, |
| 167 | const_cast<char *>(FSCK_LOG_FILE), |
| 168 | NULL, 0); |
Ken Sumrall | bf021b4 | 2013-03-19 19:38:44 -0700 | [diff] [blame] | 169 | |
David 'Digit' Turner | 28483d7 | 2014-02-17 11:14:44 +0100 | [diff] [blame] | 170 | if (ret < 0) { |
| 171 | /* No need to check for error in fork, we can't really handle it now */ |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 172 | LERROR << "Failed trying to run " << E2FSCK_BIN; |
David 'Digit' Turner | 28483d7 | 2014-02-17 11:14:44 +0100 | [diff] [blame] | 173 | } |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 174 | } |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 175 | } else if (!strcmp(fs_type, "f2fs")) { |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 176 | const char *f2fs_fsck_argv[] = { |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 177 | F2FS_FSCK_BIN, |
Yusuke Sato | 0df0827 | 2015-07-08 14:57:07 -0700 | [diff] [blame] | 178 | "-a", |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 179 | blk_device |
| 180 | }; |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 181 | LINFO << "Running " << F2FS_FSCK_BIN << " -a " << blk_device; |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 182 | |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 183 | ret = android_fork_execvp_ext(ARRAY_SIZE(f2fs_fsck_argv), |
| 184 | const_cast<char **>(f2fs_fsck_argv), |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 185 | &status, true, LOG_KLOG | LOG_FILE, |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 186 | true, const_cast<char *>(FSCK_LOG_FILE), |
| 187 | NULL, 0); |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 188 | if (ret < 0) { |
| 189 | /* No need to check for error in fork, we can't really handle it now */ |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 190 | LERROR << "Failed trying to run " << F2FS_FSCK_BIN; |
JP Abgrall | 1235158 | 2014-06-17 17:01:14 -0700 | [diff] [blame] | 191 | } |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | return; |
| 195 | } |
| 196 | |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 197 | /* Function to read the primary superblock */ |
| 198 | static int read_super_block(int fd, struct ext4_super_block *sb) |
| 199 | { |
| 200 | off64_t ret; |
| 201 | |
| 202 | ret = lseek64(fd, 1024, SEEK_SET); |
| 203 | if (ret < 0) |
| 204 | return ret; |
| 205 | |
| 206 | ret = read(fd, sb, sizeof(*sb)); |
| 207 | if (ret < 0) |
| 208 | return ret; |
| 209 | if (ret != sizeof(*sb)) |
| 210 | return ret; |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es) |
| 216 | { |
| 217 | return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) | |
| 218 | le32_to_cpu(es->s_blocks_count_lo); |
| 219 | } |
| 220 | |
| 221 | static ext4_fsblk_t ext4_r_blocks_count(struct ext4_super_block *es) |
| 222 | { |
| 223 | return ((ext4_fsblk_t)le32_to_cpu(es->s_r_blocks_count_hi) << 32) | |
| 224 | le32_to_cpu(es->s_r_blocks_count_lo); |
| 225 | } |
| 226 | |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 227 | static int do_quota(char *blk_device, char *fs_type, struct fstab_rec *rec) |
| 228 | { |
| 229 | int force_check = 0; |
| 230 | if (!strcmp(fs_type, "ext4")) { |
| 231 | /* |
| 232 | * Some system images do not have tune2fs for licensing reasons |
| 233 | * Detect these and skip reserve blocks. |
| 234 | */ |
| 235 | if (access(TUNE2FS_BIN, X_OK)) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 236 | LERROR << "Not running " << TUNE2FS_BIN << " on " |
| 237 | << blk_device << " (executable not in system image)"; |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 238 | } else { |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 239 | const char* arg1 = nullptr; |
| 240 | const char* arg2 = nullptr; |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 241 | int status = 0; |
| 242 | int ret = 0; |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 243 | android::base::unique_fd fd( |
| 244 | TEMP_FAILURE_RETRY(open(blk_device, O_RDONLY | O_CLOEXEC))); |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 245 | if (fd >= 0) { |
| 246 | struct ext4_super_block sb; |
| 247 | ret = read_super_block(fd, &sb); |
| 248 | if (ret < 0) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 249 | PERROR << "Can't read '" << blk_device << "' super block"; |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 250 | return force_check; |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | int has_quota = (sb.s_feature_ro_compat |
| 254 | & cpu_to_le32(EXT4_FEATURE_RO_COMPAT_QUOTA)) != 0; |
| 255 | int want_quota = fs_mgr_is_quota(rec) != 0; |
| 256 | |
| 257 | if (has_quota == want_quota) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 258 | LINFO << "Requested quota status is match on " << blk_device; |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 259 | return force_check; |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 260 | } else if (want_quota) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 261 | LINFO << "Enabling quota on " << blk_device; |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 262 | arg1 = "-Oquota"; |
| 263 | arg2 = "-Qusrquota,grpquota"; |
| 264 | force_check = 1; |
| 265 | } else { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 266 | LINFO << "Disabling quota on " << blk_device; |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 267 | arg1 = "-Q^usrquota,^grpquota"; |
| 268 | arg2 = "-O^quota"; |
| 269 | } |
| 270 | } else { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 271 | PERROR << "Failed to open '" << blk_device << "'"; |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 272 | return force_check; |
| 273 | } |
| 274 | |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 275 | const char *tune2fs_argv[] = { |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 276 | TUNE2FS_BIN, |
| 277 | arg1, |
| 278 | arg2, |
| 279 | blk_device, |
| 280 | }; |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 281 | ret = android_fork_execvp_ext(ARRAY_SIZE(tune2fs_argv), |
| 282 | const_cast<char **>(tune2fs_argv), |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 283 | &status, true, LOG_KLOG | LOG_FILE, |
| 284 | true, NULL, NULL, 0); |
| 285 | if (ret < 0) { |
| 286 | /* No need to check for error in fork, we can't really handle it now */ |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 287 | LERROR << "Failed trying to run " << TUNE2FS_BIN; |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 288 | } |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | return force_check; |
| 292 | } |
| 293 | |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 294 | static void do_reserved_size(char *blk_device, char *fs_type, struct fstab_rec *rec) |
| 295 | { |
| 296 | /* Check for the types of filesystems we know how to check */ |
| 297 | if (!strcmp(fs_type, "ext2") || !strcmp(fs_type, "ext3") || !strcmp(fs_type, "ext4")) { |
| 298 | /* |
| 299 | * Some system images do not have tune2fs for licensing reasons |
| 300 | * Detect these and skip reserve blocks. |
| 301 | */ |
| 302 | if (access(TUNE2FS_BIN, X_OK)) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 303 | LERROR << "Not running " << TUNE2FS_BIN << " on " |
| 304 | << blk_device << " (executable not in system image)"; |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 305 | } else { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 306 | LINFO << "Running " << TUNE2FS_BIN << " on " << blk_device; |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 307 | |
| 308 | int status = 0; |
| 309 | int ret = 0; |
| 310 | unsigned long reserved_blocks = 0; |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 311 | android::base::unique_fd fd( |
| 312 | TEMP_FAILURE_RETRY(open(blk_device, O_RDONLY | O_CLOEXEC))); |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 313 | if (fd >= 0) { |
| 314 | struct ext4_super_block sb; |
| 315 | ret = read_super_block(fd, &sb); |
| 316 | if (ret < 0) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 317 | PERROR << "Can't read '" << blk_device << "' super block"; |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 318 | return; |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 319 | } |
| 320 | reserved_blocks = rec->reserved_size / EXT4_BLOCK_SIZE(&sb); |
| 321 | unsigned long reserved_threshold = ext4_blocks_count(&sb) * 0.02; |
| 322 | if (reserved_threshold < reserved_blocks) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 323 | LWARNING << "Reserved blocks " << reserved_blocks |
| 324 | << " is too large"; |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 325 | reserved_blocks = reserved_threshold; |
| 326 | } |
| 327 | |
| 328 | if (ext4_r_blocks_count(&sb) == reserved_blocks) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 329 | LINFO << "Have reserved same blocks"; |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 330 | return; |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 331 | } |
| 332 | } else { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 333 | PERROR << "Failed to open '" << blk_device << "'"; |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 334 | return; |
| 335 | } |
| 336 | |
| 337 | char buf[16] = {0}; |
| 338 | snprintf(buf, sizeof (buf), "-r %lu", reserved_blocks); |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 339 | const char *tune2fs_argv[] = { |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 340 | TUNE2FS_BIN, |
| 341 | buf, |
| 342 | blk_device, |
| 343 | }; |
| 344 | |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 345 | ret = android_fork_execvp_ext(ARRAY_SIZE(tune2fs_argv), |
| 346 | const_cast<char **>(tune2fs_argv), |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 347 | &status, true, LOG_KLOG | LOG_FILE, |
| 348 | true, NULL, NULL, 0); |
| 349 | |
| 350 | if (ret < 0) { |
| 351 | /* No need to check for error in fork, we can't really handle it now */ |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 352 | LERROR << "Failed trying to run " << TUNE2FS_BIN; |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 353 | } |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | } |
| 357 | |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 358 | static void remove_trailing_slashes(char *n) |
| 359 | { |
| 360 | int len; |
| 361 | |
| 362 | len = strlen(n) - 1; |
| 363 | while ((*(n + len) == '/') && len) { |
| 364 | *(n + len) = '\0'; |
| 365 | len--; |
| 366 | } |
| 367 | } |
| 368 | |
Nick Kralevich | e18c0d5 | 2013-04-16 16:41:32 -0700 | [diff] [blame] | 369 | /* |
| 370 | * Mark the given block device as read-only, using the BLKROSET ioctl. |
| 371 | * Return 0 on success, and -1 on error. |
| 372 | */ |
Sami Tolvanen | 214f33b | 2014-12-18 16:15:30 +0000 | [diff] [blame] | 373 | int fs_mgr_set_blk_ro(const char *blockdev) |
Nick Kralevich | e18c0d5 | 2013-04-16 16:41:32 -0700 | [diff] [blame] | 374 | { |
| 375 | int fd; |
Sami Tolvanen | 214f33b | 2014-12-18 16:15:30 +0000 | [diff] [blame] | 376 | int rc = -1; |
Nick Kralevich | e18c0d5 | 2013-04-16 16:41:32 -0700 | [diff] [blame] | 377 | int ON = 1; |
| 378 | |
Sami Tolvanen | 214f33b | 2014-12-18 16:15:30 +0000 | [diff] [blame] | 379 | fd = TEMP_FAILURE_RETRY(open(blockdev, O_RDONLY | O_CLOEXEC)); |
Nick Kralevich | e18c0d5 | 2013-04-16 16:41:32 -0700 | [diff] [blame] | 380 | if (fd < 0) { |
| 381 | // should never happen |
Sami Tolvanen | 214f33b | 2014-12-18 16:15:30 +0000 | [diff] [blame] | 382 | return rc; |
Nick Kralevich | e18c0d5 | 2013-04-16 16:41:32 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Sami Tolvanen | 214f33b | 2014-12-18 16:15:30 +0000 | [diff] [blame] | 385 | rc = ioctl(fd, BLKROSET, &ON); |
Elliott Hughes | 9fc8343 | 2015-05-15 19:16:40 -0700 | [diff] [blame] | 386 | close(fd); |
Sami Tolvanen | 214f33b | 2014-12-18 16:15:30 +0000 | [diff] [blame] | 387 | |
| 388 | return rc; |
Nick Kralevich | e18c0d5 | 2013-04-16 16:41:32 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /* |
| 392 | * __mount(): wrapper around the mount() system call which also |
| 393 | * sets the underlying block device to read-only if the mount is read-only. |
| 394 | * See "man 2 mount" for return values. |
| 395 | */ |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 396 | static int __mount(const char *source, const char *target, const struct fstab_rec *rec) |
Nick Kralevich | e18c0d5 | 2013-04-16 16:41:32 -0700 | [diff] [blame] | 397 | { |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 398 | unsigned long mountflags = rec->flags; |
| 399 | int ret; |
| 400 | int save_errno; |
Daniel Rosenberg | f67d6bd | 2014-06-26 14:55:04 -0700 | [diff] [blame] | 401 | |
| 402 | /* We need this because sometimes we have legacy symlinks |
| 403 | * that are lingering around and need cleaning up. |
| 404 | */ |
| 405 | struct stat info; |
| 406 | if (!lstat(target, &info)) |
| 407 | if ((info.st_mode & S_IFMT) == S_IFLNK) |
| 408 | unlink(target); |
Daniel Rosenberg | f530c93 | 2014-05-28 14:10:01 -0700 | [diff] [blame] | 409 | mkdir(target, 0755); |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 410 | ret = mount(source, target, rec->fs_type, mountflags, rec->fs_options); |
| 411 | save_errno = errno; |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 412 | LINFO << __FUNCTION__ << "(source=" << source << ",target=" |
| 413 | << target << ",type=" << rec->fs_type << ")=" << ret; |
Nick Kralevich | e18c0d5 | 2013-04-16 16:41:32 -0700 | [diff] [blame] | 414 | if ((ret == 0) && (mountflags & MS_RDONLY) != 0) { |
Sami Tolvanen | 214f33b | 2014-12-18 16:15:30 +0000 | [diff] [blame] | 415 | fs_mgr_set_blk_ro(source); |
Nick Kralevich | e18c0d5 | 2013-04-16 16:41:32 -0700 | [diff] [blame] | 416 | } |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 417 | errno = save_errno; |
Nick Kralevich | e18c0d5 | 2013-04-16 16:41:32 -0700 | [diff] [blame] | 418 | return ret; |
| 419 | } |
| 420 | |
Jin Qian | 8b7eb7b | 2016-11-03 13:36:35 -0700 | [diff] [blame] | 421 | static int fs_match(const char *in1, const char *in2) |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 422 | { |
| 423 | char *n1; |
| 424 | char *n2; |
| 425 | int ret; |
| 426 | |
| 427 | n1 = strdup(in1); |
| 428 | n2 = strdup(in2); |
| 429 | |
| 430 | remove_trailing_slashes(n1); |
| 431 | remove_trailing_slashes(n2); |
| 432 | |
| 433 | ret = !strcmp(n1, n2); |
| 434 | |
| 435 | free(n1); |
| 436 | free(n2); |
| 437 | |
| 438 | return ret; |
| 439 | } |
| 440 | |
Paul Lawrence | bbb3631 | 2014-10-09 14:22:49 +0000 | [diff] [blame] | 441 | static int device_is_secure() { |
| 442 | int ret = -1; |
| 443 | char value[PROP_VALUE_MAX]; |
| 444 | ret = __system_property_get("ro.secure", value); |
| 445 | /* If error, we want to fail secure */ |
| 446 | if (ret < 0) |
| 447 | return 1; |
| 448 | return strcmp(value, "0") ? 1 : 0; |
| 449 | } |
| 450 | |
Paul Lawrence | 703b87d | 2015-01-07 11:44:51 -0800 | [diff] [blame] | 451 | static int device_is_force_encrypted() { |
| 452 | int ret = -1; |
| 453 | char value[PROP_VALUE_MAX]; |
| 454 | ret = __system_property_get("ro.vold.forceencryption", value); |
| 455 | if (ret < 0) |
| 456 | return 0; |
| 457 | return strcmp(value, "1") ? 0 : 1; |
| 458 | } |
| 459 | |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 460 | /* |
| 461 | * Tries to mount any of the consecutive fstab entries that match |
| 462 | * the mountpoint of the one given by fstab->recs[start_idx]. |
| 463 | * |
| 464 | * end_idx: On return, will be the last rec that was looked at. |
| 465 | * attempted_idx: On return, will indicate which fstab rec |
| 466 | * succeeded. In case of failure, it will be the start_idx. |
| 467 | * Returns |
| 468 | * -1 on failure with errno set to match the 1st mount failure. |
| 469 | * 0 on success. |
| 470 | */ |
| 471 | static int mount_with_alternatives(struct fstab *fstab, int start_idx, int *end_idx, int *attempted_idx) |
JP Abgrall | 4bb7bba | 2014-06-19 22:12:20 -0700 | [diff] [blame] | 472 | { |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 473 | int i; |
| 474 | int mount_errno = 0; |
| 475 | int mounted = 0; |
| 476 | |
| 477 | if (!end_idx || !attempted_idx || start_idx >= fstab->num_entries) { |
| 478 | errno = EINVAL; |
| 479 | if (end_idx) *end_idx = start_idx; |
forfun | c5c0306 | 2016-12-14 09:47:33 -0500 | [diff] [blame] | 480 | if (attempted_idx) *attempted_idx = start_idx; |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 481 | return -1; |
JP Abgrall | 4bb7bba | 2014-06-19 22:12:20 -0700 | [diff] [blame] | 482 | } |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 483 | |
| 484 | /* Hunt down an fstab entry for the same mount point that might succeed */ |
| 485 | for (i = start_idx; |
| 486 | /* We required that fstab entries for the same mountpoint be consecutive */ |
| 487 | i < fstab->num_entries && !strcmp(fstab->recs[start_idx].mount_point, fstab->recs[i].mount_point); |
| 488 | i++) { |
| 489 | /* |
| 490 | * Don't try to mount/encrypt the same mount point again. |
| 491 | * Deal with alternate entries for the same point which are required to be all following |
| 492 | * each other. |
| 493 | */ |
| 494 | if (mounted) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 495 | LERROR << __FUNCTION__ << "(): skipping fstab dup mountpoint=" |
| 496 | << fstab->recs[i].mount_point << " rec[" << i |
| 497 | << "].fs_type=" << fstab->recs[i].fs_type |
| 498 | << " already mounted as " |
| 499 | << fstab->recs[*attempted_idx].fs_type; |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 500 | continue; |
| 501 | } |
| 502 | |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 503 | int force_check = do_quota(fstab->recs[i].blk_device, fstab->recs[i].fs_type, |
| 504 | &fstab->recs[i]); |
| 505 | |
| 506 | if ((fstab->recs[i].fs_mgr_flags & MF_CHECK) || force_check) { |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 507 | check_fs(fstab->recs[i].blk_device, fstab->recs[i].fs_type, |
| 508 | fstab->recs[i].mount_point); |
| 509 | } |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 510 | |
| 511 | if (fstab->recs[i].fs_mgr_flags & MF_RESERVEDSIZE) { |
| 512 | do_reserved_size(fstab->recs[i].blk_device, fstab->recs[i].fs_type, |
| 513 | &fstab->recs[i]); |
| 514 | } |
| 515 | |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 516 | if (!__mount(fstab->recs[i].blk_device, fstab->recs[i].mount_point, &fstab->recs[i])) { |
| 517 | *attempted_idx = i; |
| 518 | mounted = 1; |
| 519 | if (i != start_idx) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 520 | LERROR << __FUNCTION__ << "(): Mounted " |
| 521 | << fstab->recs[i].blk_device << " on " |
| 522 | << fstab->recs[i].mount_point << " with fs_type=" |
| 523 | << fstab->recs[i].fs_type << " instead of " |
| 524 | << fstab->recs[start_idx].fs_type; |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 525 | } |
| 526 | } else { |
| 527 | /* back up errno for crypto decisions */ |
| 528 | mount_errno = errno; |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | /* Adjust i for the case where it was still withing the recs[] */ |
| 533 | if (i < fstab->num_entries) --i; |
| 534 | |
| 535 | *end_idx = i; |
| 536 | if (!mounted) { |
| 537 | *attempted_idx = start_idx; |
| 538 | errno = mount_errno; |
| 539 | return -1; |
| 540 | } |
| 541 | return 0; |
JP Abgrall | 4bb7bba | 2014-06-19 22:12:20 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Christoffer Dall | 8298234 | 2014-12-17 21:26:54 +0100 | [diff] [blame] | 544 | static int translate_ext_labels(struct fstab_rec *rec) |
| 545 | { |
| 546 | DIR *blockdir = NULL; |
| 547 | struct dirent *ent; |
| 548 | char *label; |
| 549 | size_t label_len; |
| 550 | int ret = -1; |
| 551 | |
| 552 | if (strncmp(rec->blk_device, "LABEL=", 6)) |
| 553 | return 0; |
| 554 | |
| 555 | label = rec->blk_device + 6; |
| 556 | label_len = strlen(label); |
| 557 | |
| 558 | if (label_len > 16) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 559 | LERROR << "FS label is longer than allowed by filesystem"; |
Christoffer Dall | 8298234 | 2014-12-17 21:26:54 +0100 | [diff] [blame] | 560 | goto out; |
| 561 | } |
| 562 | |
| 563 | |
| 564 | blockdir = opendir("/dev/block"); |
| 565 | if (!blockdir) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 566 | LERROR << "couldn't open /dev/block"; |
Christoffer Dall | 8298234 | 2014-12-17 21:26:54 +0100 | [diff] [blame] | 567 | goto out; |
| 568 | } |
| 569 | |
| 570 | while ((ent = readdir(blockdir))) { |
| 571 | int fd; |
| 572 | char super_buf[1024]; |
| 573 | struct ext4_super_block *sb; |
| 574 | |
| 575 | if (ent->d_type != DT_BLK) |
| 576 | continue; |
| 577 | |
| 578 | fd = openat(dirfd(blockdir), ent->d_name, O_RDONLY); |
| 579 | if (fd < 0) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 580 | LERROR << "Cannot open block device /dev/block/" << ent->d_name; |
Christoffer Dall | 8298234 | 2014-12-17 21:26:54 +0100 | [diff] [blame] | 581 | goto out; |
| 582 | } |
| 583 | |
| 584 | if (TEMP_FAILURE_RETRY(lseek(fd, 1024, SEEK_SET)) < 0 || |
| 585 | TEMP_FAILURE_RETRY(read(fd, super_buf, 1024)) != 1024) { |
| 586 | /* Probably a loopback device or something else without a readable |
| 587 | * superblock. |
| 588 | */ |
| 589 | close(fd); |
| 590 | continue; |
| 591 | } |
| 592 | |
| 593 | sb = (struct ext4_super_block *)super_buf; |
| 594 | if (sb->s_magic != EXT4_SUPER_MAGIC) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 595 | LINFO << "/dev/block/" << ent->d_name << " not ext{234}"; |
Christoffer Dall | 8298234 | 2014-12-17 21:26:54 +0100 | [diff] [blame] | 596 | continue; |
| 597 | } |
| 598 | |
| 599 | if (!strncmp(label, sb->s_volume_name, label_len)) { |
| 600 | char *new_blk_device; |
| 601 | |
| 602 | if (asprintf(&new_blk_device, "/dev/block/%s", ent->d_name) < 0) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 603 | LERROR << "Could not allocate block device string"; |
Christoffer Dall | 8298234 | 2014-12-17 21:26:54 +0100 | [diff] [blame] | 604 | goto out; |
| 605 | } |
| 606 | |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 607 | LINFO << "resolved label " << rec->blk_device << " to " |
| 608 | << new_blk_device; |
Christoffer Dall | 8298234 | 2014-12-17 21:26:54 +0100 | [diff] [blame] | 609 | |
| 610 | free(rec->blk_device); |
| 611 | rec->blk_device = new_blk_device; |
| 612 | ret = 0; |
| 613 | break; |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | out: |
| 618 | closedir(blockdir); |
| 619 | return ret; |
| 620 | } |
| 621 | |
Paul Crowley | c31f1f3 | 2016-02-09 21:05:01 +0000 | [diff] [blame] | 622 | static bool needs_block_encryption(const struct fstab_rec* rec) |
| 623 | { |
| 624 | if (device_is_force_encrypted() && fs_mgr_is_encryptable(rec)) return true; |
| 625 | if (rec->fs_mgr_flags & MF_FORCECRYPT) return true; |
| 626 | if (rec->fs_mgr_flags & MF_CRYPT) { |
| 627 | /* Check for existence of convert_fde breadcrumb file */ |
| 628 | char convert_fde_name[PATH_MAX]; |
| 629 | snprintf(convert_fde_name, sizeof(convert_fde_name), |
| 630 | "%s/misc/vold/convert_fde", rec->mount_point); |
| 631 | if (access(convert_fde_name, F_OK) == 0) return true; |
| 632 | } |
| 633 | if (rec->fs_mgr_flags & MF_FORCEFDEORFBE) { |
| 634 | /* Check for absence of convert_fbe breadcrumb file */ |
| 635 | char convert_fbe_name[PATH_MAX]; |
| 636 | snprintf(convert_fbe_name, sizeof(convert_fbe_name), |
| 637 | "%s/convert_fbe", rec->mount_point); |
| 638 | if (access(convert_fbe_name, F_OK) != 0) return true; |
| 639 | } |
| 640 | return false; |
| 641 | } |
| 642 | |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 643 | // Check to see if a mountable volume has encryption requirements |
Paul Lawrence | 6908018 | 2016-02-02 10:31:30 -0800 | [diff] [blame] | 644 | static int handle_encryptable(const struct fstab_rec* rec) |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 645 | { |
| 646 | /* If this is block encryptable, need to trigger encryption */ |
Paul Crowley | c31f1f3 | 2016-02-09 21:05:01 +0000 | [diff] [blame] | 647 | if (needs_block_encryption(rec)) { |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 648 | if (umount(rec->mount_point) == 0) { |
| 649 | return FS_MGR_MNTALL_DEV_NEEDS_ENCRYPTION; |
| 650 | } else { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 651 | PWARNING << "Could not umount " << rec->mount_point |
| 652 | << " - allow continue unencrypted"; |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 653 | return FS_MGR_MNTALL_DEV_NOT_ENCRYPTED; |
| 654 | } |
Paul Crowley | c31f1f3 | 2016-02-09 21:05:01 +0000 | [diff] [blame] | 655 | } else if (rec->fs_mgr_flags & (MF_FILEENCRYPTION | MF_FORCEFDEORFBE)) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 656 | // Deal with file level encryption |
| 657 | LINFO << rec->mount_point << " is file encrypted"; |
Paul Lawrence | 6908018 | 2016-02-02 10:31:30 -0800 | [diff] [blame] | 658 | return FS_MGR_MNTALL_DEV_FILE_ENCRYPTED; |
Paul Lawrence | 1098aac | 2016-03-04 15:52:33 -0800 | [diff] [blame] | 659 | } else if (fs_mgr_is_encryptable(rec)) { |
Paul Crowley | c31f1f3 | 2016-02-09 21:05:01 +0000 | [diff] [blame] | 660 | return FS_MGR_MNTALL_DEV_NOT_ENCRYPTED; |
Paul Lawrence | 1098aac | 2016-03-04 15:52:33 -0800 | [diff] [blame] | 661 | } else { |
| 662 | return FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE; |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 663 | } |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 664 | } |
| 665 | |
bowgotsai | 3de625d | 2016-11-11 21:05:44 +0800 | [diff] [blame] | 666 | int fs_mgr_test_access(const char *device) { |
| 667 | int tries = 25; |
| 668 | while (tries--) { |
| 669 | if (!access(device, F_OK) || errno != ENOENT) { |
| 670 | return 0; |
| 671 | } |
| 672 | usleep(40 * 1000); |
| 673 | } |
| 674 | return -1; |
| 675 | } |
| 676 | |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 677 | /* When multiple fstab records share the same mount_point, it will |
| 678 | * try to mount each one in turn, and ignore any duplicates after a |
| 679 | * first successful mount. |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 680 | * Returns -1 on error, and FS_MGR_MNTALL_* otherwise. |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 681 | */ |
Wei Wang | 254f443 | 2016-08-23 11:58:09 -0700 | [diff] [blame] | 682 | int fs_mgr_mount_all(struct fstab *fstab, int mount_mode) |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 683 | { |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 684 | int i = 0; |
Paul Lawrence | 1098aac | 2016-03-04 15:52:33 -0800 | [diff] [blame] | 685 | int encryptable = FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE; |
Mohamad Ayyash | 38afe5f | 2014-03-10 15:40:29 -0700 | [diff] [blame] | 686 | int error_count = 0; |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 687 | int mret = -1; |
| 688 | int mount_errno = 0; |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 689 | int attempted_idx = -1; |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 690 | int avb_ret = FS_MGR_SETUP_AVB_FAIL; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 691 | |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 692 | if (!fstab) { |
Mohamad Ayyash | 38afe5f | 2014-03-10 15:40:29 -0700 | [diff] [blame] | 693 | return -1; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 694 | } |
| 695 | |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 696 | if (fs_mgr_is_avb_used() && |
| 697 | (avb_ret = fs_mgr_load_vbmeta_images(fstab)) == FS_MGR_SETUP_AVB_FAIL) { |
| 698 | return -1; |
| 699 | } |
| 700 | |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 701 | for (i = 0; i < fstab->num_entries; i++) { |
Wei Wang | 254f443 | 2016-08-23 11:58:09 -0700 | [diff] [blame] | 702 | /* Don't mount entries that are managed by vold or not for the mount mode*/ |
| 703 | if ((fstab->recs[i].fs_mgr_flags & (MF_VOLDMANAGED | MF_RECOVERYONLY)) || |
| 704 | ((mount_mode == MOUNT_MODE_LATE) && !fs_mgr_is_latemount(&fstab->recs[i])) || |
| 705 | ((mount_mode == MOUNT_MODE_EARLY) && fs_mgr_is_latemount(&fstab->recs[i]))) { |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 706 | continue; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 707 | } |
| 708 | |
Ken Sumrall | 5bc31a2 | 2013-07-08 19:11:55 -0700 | [diff] [blame] | 709 | /* Skip swap and raw partition entries such as boot, recovery, etc */ |
| 710 | if (!strcmp(fstab->recs[i].fs_type, "swap") || |
| 711 | !strcmp(fstab->recs[i].fs_type, "emmc") || |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 712 | !strcmp(fstab->recs[i].fs_type, "mtd")) { |
| 713 | continue; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 714 | } |
| 715 | |
Daniel Rosenberg | 31a4faf | 2015-06-29 17:33:05 -0700 | [diff] [blame] | 716 | /* Skip mounting the root partition, as it will already have been mounted */ |
| 717 | if (!strcmp(fstab->recs[i].mount_point, "/")) { |
| 718 | if ((fstab->recs[i].fs_mgr_flags & MS_RDONLY) != 0) { |
| 719 | fs_mgr_set_blk_ro(fstab->recs[i].blk_device); |
| 720 | } |
| 721 | continue; |
| 722 | } |
| 723 | |
Christoffer Dall | 8298234 | 2014-12-17 21:26:54 +0100 | [diff] [blame] | 724 | /* Translate LABEL= file system labels into block devices */ |
| 725 | if (!strcmp(fstab->recs[i].fs_type, "ext2") || |
| 726 | !strcmp(fstab->recs[i].fs_type, "ext3") || |
| 727 | !strcmp(fstab->recs[i].fs_type, "ext4")) { |
| 728 | int tret = translate_ext_labels(&fstab->recs[i]); |
| 729 | if (tret < 0) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 730 | LERROR << "Could not translate label to block device"; |
Christoffer Dall | 8298234 | 2014-12-17 21:26:54 +0100 | [diff] [blame] | 731 | continue; |
| 732 | } |
| 733 | } |
| 734 | |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 735 | if (fstab->recs[i].fs_mgr_flags & MF_WAIT) { |
| 736 | wait_for_file(fstab->recs[i].blk_device, WAIT_TIMEOUT); |
| 737 | } |
| 738 | |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 739 | if (fs_mgr_is_avb_used() && (fstab->recs[i].fs_mgr_flags & MF_AVB)) { |
| 740 | /* If HASHTREE_DISABLED is set (cf. 'adb disable-verity'), we |
| 741 | * should set up the device without using dm-verity. |
| 742 | * The actual mounting still take place in the following |
| 743 | * mount_with_alternatives(). |
| 744 | */ |
| 745 | if (avb_ret == FS_MGR_SETUP_AVB_HASHTREE_DISABLED) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 746 | LINFO << "AVB HASHTREE disabled"; |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 747 | } else if (fs_mgr_setup_avb(&fstab->recs[i]) != |
| 748 | FS_MGR_SETUP_AVB_SUCCESS) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 749 | LERROR << "Failed to set up AVB on partition: " |
| 750 | << fstab->recs[i].mount_point << ", skipping!"; |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 751 | /* Skips mounting the device. */ |
| 752 | continue; |
| 753 | } |
| 754 | } else if ((fstab->recs[i].fs_mgr_flags & MF_VERIFY) && device_is_secure()) { |
Hung-ying Tyan | ecfce13 | 2016-12-16 15:00:05 +0800 | [diff] [blame] | 755 | int rc = fs_mgr_setup_verity(&fstab->recs[i], true); |
Mark Salyzyn | e528be5 | 2016-03-29 14:25:11 -0700 | [diff] [blame] | 756 | if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 757 | LINFO << "Verity disabled"; |
Paul Lawrence | bbb3631 | 2014-10-09 14:22:49 +0000 | [diff] [blame] | 758 | } else if (rc != FS_MGR_SETUP_VERITY_SUCCESS) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 759 | LERROR << "Could not set up verified partition, skipping!"; |
Geremy Condra | 3ad3d1c | 2013-02-22 18:11:41 -0800 | [diff] [blame] | 760 | continue; |
| 761 | } |
| 762 | } |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 763 | |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 764 | int last_idx_inspected; |
Chris Fries | 79f3384 | 2013-09-05 13:19:21 -0500 | [diff] [blame] | 765 | int top_idx = i; |
| 766 | |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 767 | mret = mount_with_alternatives(fstab, i, &last_idx_inspected, &attempted_idx); |
| 768 | i = last_idx_inspected; |
| 769 | mount_errno = errno; |
JP Abgrall | f786fe5 | 2014-06-18 07:28:14 +0000 | [diff] [blame] | 770 | |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 771 | /* Deal with encryptability. */ |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 772 | if (!mret) { |
Paul Lawrence | 6908018 | 2016-02-02 10:31:30 -0800 | [diff] [blame] | 773 | int status = handle_encryptable(&fstab->recs[attempted_idx]); |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 774 | |
| 775 | if (status == FS_MGR_MNTALL_FAIL) { |
| 776 | /* Fatal error - no point continuing */ |
| 777 | return status; |
Paul Lawrence | 166fa3d | 2014-02-03 13:27:49 -0800 | [diff] [blame] | 778 | } |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 779 | |
Paul Lawrence | 1098aac | 2016-03-04 15:52:33 -0800 | [diff] [blame] | 780 | if (status != FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE) { |
| 781 | if (encryptable != FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE) { |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 782 | // Log and continue |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 783 | LERROR << "Only one encryptable/encrypted partition supported"; |
Paul Lawrence | b8c9d27 | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 784 | } |
| 785 | encryptable = status; |
| 786 | } |
| 787 | |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 788 | /* Success! Go get the next one */ |
| 789 | continue; |
| 790 | } |
| 791 | |
Chris Fries | 79f3384 | 2013-09-05 13:19:21 -0500 | [diff] [blame] | 792 | /* mount(2) returned an error, handle the encryptable/formattable case */ |
| 793 | bool wiped = partition_wiped(fstab->recs[top_idx].blk_device); |
Chuanxiao Dong | d78dff1 | 2016-03-08 15:54:55 +0100 | [diff] [blame] | 794 | bool crypt_footer = false; |
Chris Fries | 79f3384 | 2013-09-05 13:19:21 -0500 | [diff] [blame] | 795 | if (mret && mount_errno != EBUSY && mount_errno != EACCES && |
| 796 | fs_mgr_is_formattable(&fstab->recs[top_idx]) && wiped) { |
| 797 | /* top_idx and attempted_idx point at the same partition, but sometimes |
| 798 | * at two different lines in the fstab. Use the top one for formatting |
| 799 | * as that is the preferred one. |
| 800 | */ |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 801 | LERROR << __FUNCTION__ << "(): " << fstab->recs[top_idx].blk_device |
| 802 | << " is wiped and " << fstab->recs[top_idx].mount_point |
| 803 | << " " << fstab->recs[top_idx].fs_type |
| 804 | << " is formattable. Format it."; |
Chris Fries | 79f3384 | 2013-09-05 13:19:21 -0500 | [diff] [blame] | 805 | if (fs_mgr_is_encryptable(&fstab->recs[top_idx]) && |
| 806 | strcmp(fstab->recs[top_idx].key_loc, KEY_IN_FOOTER)) { |
George Burgess IV | e7aa2b2 | 2016-03-02 14:02:55 -0800 | [diff] [blame] | 807 | int fd = open(fstab->recs[top_idx].key_loc, O_WRONLY); |
Chris Fries | 79f3384 | 2013-09-05 13:19:21 -0500 | [diff] [blame] | 808 | if (fd >= 0) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 809 | LINFO << __FUNCTION__ << "(): also wipe " |
| 810 | << fstab->recs[top_idx].key_loc; |
Chris Fries | 79f3384 | 2013-09-05 13:19:21 -0500 | [diff] [blame] | 811 | wipe_block_device(fd, get_file_size(fd)); |
| 812 | close(fd); |
| 813 | } else { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 814 | PERROR << __FUNCTION__ << "(): " |
| 815 | << fstab->recs[top_idx].key_loc << " wouldn't open"; |
Chris Fries | 79f3384 | 2013-09-05 13:19:21 -0500 | [diff] [blame] | 816 | } |
Chuanxiao Dong | d78dff1 | 2016-03-08 15:54:55 +0100 | [diff] [blame] | 817 | } else if (fs_mgr_is_encryptable(&fstab->recs[top_idx]) && |
| 818 | !strcmp(fstab->recs[top_idx].key_loc, KEY_IN_FOOTER)) { |
| 819 | crypt_footer = true; |
Chris Fries | 79f3384 | 2013-09-05 13:19:21 -0500 | [diff] [blame] | 820 | } |
Chuanxiao Dong | d78dff1 | 2016-03-08 15:54:55 +0100 | [diff] [blame] | 821 | if (fs_mgr_do_format(&fstab->recs[top_idx], crypt_footer) == 0) { |
Chris Fries | 79f3384 | 2013-09-05 13:19:21 -0500 | [diff] [blame] | 822 | /* Let's replay the mount actions. */ |
| 823 | i = top_idx - 1; |
| 824 | continue; |
Matthew Bouyack | 9c59cbc | 2016-05-02 15:55:30 -0700 | [diff] [blame] | 825 | } else { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 826 | LERROR << __FUNCTION__ << "(): Format failed. " |
| 827 | << "Suggest recovery..."; |
Matthew Bouyack | 9c59cbc | 2016-05-02 15:55:30 -0700 | [diff] [blame] | 828 | encryptable = FS_MGR_MNTALL_DEV_NEEDS_RECOVERY; |
| 829 | continue; |
Chris Fries | 79f3384 | 2013-09-05 13:19:21 -0500 | [diff] [blame] | 830 | } |
| 831 | } |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 832 | if (mret && mount_errno != EBUSY && mount_errno != EACCES && |
JP Abgrall | cee2068 | 2014-07-02 14:26:54 -0700 | [diff] [blame] | 833 | fs_mgr_is_encryptable(&fstab->recs[attempted_idx])) { |
Chris Fries | 79f3384 | 2013-09-05 13:19:21 -0500 | [diff] [blame] | 834 | if (wiped) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 835 | LERROR << __FUNCTION__ << "(): " |
| 836 | << fstab->recs[attempted_idx].blk_device |
| 837 | << " is wiped and " |
| 838 | << fstab->recs[attempted_idx].mount_point << " " |
| 839 | << fstab->recs[attempted_idx].fs_type |
| 840 | << " is encryptable. Suggest recovery..."; |
JP Abgrall | cee2068 | 2014-07-02 14:26:54 -0700 | [diff] [blame] | 841 | encryptable = FS_MGR_MNTALL_DEV_NEEDS_RECOVERY; |
Mohamad Ayyash | 38afe5f | 2014-03-10 15:40:29 -0700 | [diff] [blame] | 842 | continue; |
JP Abgrall | 4bb7bba | 2014-06-19 22:12:20 -0700 | [diff] [blame] | 843 | } else { |
| 844 | /* Need to mount a tmpfs at this mountpoint for now, and set |
| 845 | * properties that vold will query later for decrypting |
| 846 | */ |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 847 | LERROR << __FUNCTION__ << "(): possibly an encryptable blkdev " |
| 848 | << fstab->recs[attempted_idx].blk_device |
| 849 | << " for mount " << fstab->recs[attempted_idx].mount_point |
| 850 | << " type " << fstab->recs[attempted_idx].fs_type; |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 851 | if (fs_mgr_do_tmpfs_mount(fstab->recs[attempted_idx].mount_point) < 0) { |
JP Abgrall | 4bb7bba | 2014-06-19 22:12:20 -0700 | [diff] [blame] | 852 | ++error_count; |
| 853 | continue; |
| 854 | } |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 855 | } |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 856 | encryptable = FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 857 | } else { |
Daniel Rosenberg | d38e3c5 | 2016-04-07 20:10:25 -0700 | [diff] [blame] | 858 | if (fs_mgr_is_nofail(&fstab->recs[attempted_idx])) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 859 | PERROR << "Ignoring failure to mount an un-encryptable or wiped partition on" |
| 860 | << fstab->recs[attempted_idx].blk_device << " at " |
| 861 | << fstab->recs[attempted_idx].mount_point << " options: " |
| 862 | << fstab->recs[attempted_idx].fs_options; |
Daniel Rosenberg | d38e3c5 | 2016-04-07 20:10:25 -0700 | [diff] [blame] | 863 | } else { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 864 | PERROR << "Failed to mount an un-encryptable or wiped partition on" |
| 865 | << fstab->recs[attempted_idx].blk_device << " at " |
| 866 | << fstab->recs[attempted_idx].mount_point << " options: " |
| 867 | << fstab->recs[attempted_idx].fs_options; |
Daniel Rosenberg | d38e3c5 | 2016-04-07 20:10:25 -0700 | [diff] [blame] | 868 | ++error_count; |
| 869 | } |
Mohamad Ayyash | 38afe5f | 2014-03-10 15:40:29 -0700 | [diff] [blame] | 870 | continue; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 871 | } |
| 872 | } |
| 873 | |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 874 | if (fs_mgr_is_avb_used()) { |
| 875 | fs_mgr_unload_vbmeta_images(); |
| 876 | } |
| 877 | |
Mohamad Ayyash | 38afe5f | 2014-03-10 15:40:29 -0700 | [diff] [blame] | 878 | if (error_count) { |
| 879 | return -1; |
Mohamad Ayyash | 38afe5f | 2014-03-10 15:40:29 -0700 | [diff] [blame] | 880 | } else { |
Paul Lawrence | 166fa3d | 2014-02-03 13:27:49 -0800 | [diff] [blame] | 881 | return encryptable; |
Mohamad Ayyash | 38afe5f | 2014-03-10 15:40:29 -0700 | [diff] [blame] | 882 | } |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 883 | } |
| 884 | |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 885 | /* If tmp_mount_point is non-null, mount the filesystem there. This is for the |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 886 | * tmp mount we do to check the user password |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 887 | * If multiple fstab entries are to be mounted on "n_name", it will try to mount each one |
| 888 | * in turn, and stop on 1st success, or no more match. |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 889 | */ |
Jin Qian | 8b7eb7b | 2016-11-03 13:36:35 -0700 | [diff] [blame] | 890 | int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device, |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 891 | char *tmp_mount_point) |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 892 | { |
| 893 | int i = 0; |
Paul Lawrence | cf234dc | 2014-09-09 10:44:51 -0700 | [diff] [blame] | 894 | int ret = FS_MGR_DOMNT_FAILED; |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 895 | int mount_errors = 0; |
| 896 | int first_mount_errno = 0; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 897 | char *m; |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 898 | int avb_ret = FS_MGR_SETUP_AVB_FAIL; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 899 | |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 900 | if (!fstab) { |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 901 | return ret; |
| 902 | } |
| 903 | |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 904 | if (fs_mgr_is_avb_used() && |
| 905 | (avb_ret = fs_mgr_load_vbmeta_images(fstab)) == FS_MGR_SETUP_AVB_FAIL) { |
| 906 | return ret; |
| 907 | } |
| 908 | |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 909 | for (i = 0; i < fstab->num_entries; i++) { |
| 910 | if (!fs_match(fstab->recs[i].mount_point, n_name)) { |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 911 | continue; |
| 912 | } |
| 913 | |
| 914 | /* We found our match */ |
Ken Sumrall | 5bc31a2 | 2013-07-08 19:11:55 -0700 | [diff] [blame] | 915 | /* If this swap or a raw partition, report an error */ |
| 916 | if (!strcmp(fstab->recs[i].fs_type, "swap") || |
| 917 | !strcmp(fstab->recs[i].fs_type, "emmc") || |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 918 | !strcmp(fstab->recs[i].fs_type, "mtd")) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 919 | LERROR << "Cannot mount filesystem of type " |
| 920 | << fstab->recs[i].fs_type << " on " << n_blk_device; |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 921 | goto out; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 922 | } |
| 923 | |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 924 | /* First check the filesystem if requested */ |
| 925 | if (fstab->recs[i].fs_mgr_flags & MF_WAIT) { |
| 926 | wait_for_file(n_blk_device, WAIT_TIMEOUT); |
| 927 | } |
| 928 | |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 929 | int force_check = do_quota(fstab->recs[i].blk_device, fstab->recs[i].fs_type, |
| 930 | &fstab->recs[i]); |
| 931 | |
| 932 | if ((fstab->recs[i].fs_mgr_flags & MF_CHECK) || force_check) { |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 933 | check_fs(n_blk_device, fstab->recs[i].fs_type, |
| 934 | fstab->recs[i].mount_point); |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 935 | } |
| 936 | |
liminghao | 9a0fd1d | 2016-07-22 11:48:14 +0800 | [diff] [blame] | 937 | if (fstab->recs[i].fs_mgr_flags & MF_RESERVEDSIZE) { |
| 938 | do_reserved_size(n_blk_device, fstab->recs[i].fs_type, &fstab->recs[i]); |
| 939 | } |
| 940 | |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 941 | if (fs_mgr_is_avb_used() && (fstab->recs[i].fs_mgr_flags & MF_AVB)) { |
| 942 | /* If HASHTREE_DISABLED is set (cf. 'adb disable-verity'), we |
| 943 | * should set up the device without using dm-verity. |
| 944 | * The actual mounting still take place in the following |
| 945 | * mount_with_alternatives(). |
| 946 | */ |
| 947 | if (avb_ret == FS_MGR_SETUP_AVB_HASHTREE_DISABLED) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 948 | LINFO << "AVB HASHTREE disabled"; |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 949 | } else if (fs_mgr_setup_avb(&fstab->recs[i]) != |
| 950 | FS_MGR_SETUP_AVB_SUCCESS) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 951 | LERROR << "Failed to set up AVB on partition: " |
| 952 | << fstab->recs[i].mount_point << ", skipping!"; |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 953 | /* Skips mounting the device. */ |
| 954 | continue; |
| 955 | } |
| 956 | } else if ((fstab->recs[i].fs_mgr_flags & MF_VERIFY) && device_is_secure()) { |
Hung-ying Tyan | ecfce13 | 2016-12-16 15:00:05 +0800 | [diff] [blame] | 957 | int rc = fs_mgr_setup_verity(&fstab->recs[i], true); |
Mark Salyzyn | e528be5 | 2016-03-29 14:25:11 -0700 | [diff] [blame] | 958 | if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 959 | LINFO << "Verity disabled"; |
Paul Lawrence | bbb3631 | 2014-10-09 14:22:49 +0000 | [diff] [blame] | 960 | } else if (rc != FS_MGR_SETUP_VERITY_SUCCESS) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 961 | LERROR << "Could not set up verified partition, skipping!"; |
Geremy Condra | 3ad3d1c | 2013-02-22 18:11:41 -0800 | [diff] [blame] | 962 | continue; |
| 963 | } |
| 964 | } |
| 965 | |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 966 | /* Now mount it where requested */ |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 967 | if (tmp_mount_point) { |
| 968 | m = tmp_mount_point; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 969 | } else { |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 970 | m = fstab->recs[i].mount_point; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 971 | } |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 972 | if (__mount(n_blk_device, m, &fstab->recs[i])) { |
| 973 | if (!first_mount_errno) first_mount_errno = errno; |
| 974 | mount_errors++; |
| 975 | continue; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 976 | } else { |
| 977 | ret = 0; |
| 978 | goto out; |
| 979 | } |
| 980 | } |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 981 | if (mount_errors) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 982 | PERROR << "Cannot mount filesystem on " << n_blk_device |
| 983 | << " at " << m; |
Paul Lawrence | cf234dc | 2014-09-09 10:44:51 -0700 | [diff] [blame] | 984 | if (first_mount_errno == EBUSY) { |
| 985 | ret = FS_MGR_DOMNT_BUSY; |
| 986 | } else { |
| 987 | ret = FS_MGR_DOMNT_FAILED; |
| 988 | } |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 989 | } else { |
| 990 | /* We didn't find a match, say so and return an error */ |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 991 | LERROR << "Cannot find mount point " << fstab->recs[i].mount_point |
| 992 | << " in fstab"; |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 993 | } |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 994 | |
| 995 | out: |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 996 | if (fs_mgr_is_avb_used()) { |
| 997 | fs_mgr_unload_vbmeta_images(); |
| 998 | } |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 999 | return ret; |
| 1000 | } |
| 1001 | |
| 1002 | /* |
| 1003 | * mount a tmpfs filesystem at the given point. |
| 1004 | * return 0 on success, non-zero on failure. |
| 1005 | */ |
| 1006 | int fs_mgr_do_tmpfs_mount(char *n_name) |
| 1007 | { |
| 1008 | int ret; |
| 1009 | |
| 1010 | ret = mount("tmpfs", n_name, "tmpfs", |
| 1011 | MS_NOATIME | MS_NOSUID | MS_NODEV, CRYPTO_TMPFS_OPTIONS); |
| 1012 | if (ret < 0) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 1013 | LERROR << "Cannot mount tmpfs filesystem at " << n_name; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1014 | return -1; |
| 1015 | } |
| 1016 | |
| 1017 | /* Success */ |
| 1018 | return 0; |
| 1019 | } |
| 1020 | |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 1021 | int fs_mgr_unmount_all(struct fstab *fstab) |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1022 | { |
| 1023 | int i = 0; |
| 1024 | int ret = 0; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1025 | |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 1026 | if (!fstab) { |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1027 | return -1; |
| 1028 | } |
| 1029 | |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 1030 | while (fstab->recs[i].blk_device) { |
| 1031 | if (umount(fstab->recs[i].mount_point)) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 1032 | LERROR << "Cannot unmount filesystem at " |
| 1033 | << fstab->recs[i].mount_point; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1034 | ret = -1; |
| 1035 | } |
| 1036 | i++; |
| 1037 | } |
| 1038 | |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1039 | return ret; |
| 1040 | } |
Ken Sumrall | 5bc31a2 | 2013-07-08 19:11:55 -0700 | [diff] [blame] | 1041 | |
| 1042 | /* This must be called after mount_all, because the mkswap command needs to be |
| 1043 | * available. |
| 1044 | */ |
| 1045 | int fs_mgr_swapon_all(struct fstab *fstab) |
| 1046 | { |
| 1047 | int i = 0; |
| 1048 | int flags = 0; |
| 1049 | int err = 0; |
| 1050 | int ret = 0; |
| 1051 | int status; |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 1052 | const char *mkswap_argv[2] = { |
Ken Sumrall | 5bc31a2 | 2013-07-08 19:11:55 -0700 | [diff] [blame] | 1053 | MKSWAP_BIN, |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 1054 | nullptr |
Ken Sumrall | 5bc31a2 | 2013-07-08 19:11:55 -0700 | [diff] [blame] | 1055 | }; |
| 1056 | |
| 1057 | if (!fstab) { |
| 1058 | return -1; |
| 1059 | } |
| 1060 | |
| 1061 | for (i = 0; i < fstab->num_entries; i++) { |
| 1062 | /* Skip non-swap entries */ |
| 1063 | if (strcmp(fstab->recs[i].fs_type, "swap")) { |
| 1064 | continue; |
| 1065 | } |
| 1066 | |
| 1067 | if (fstab->recs[i].zram_size > 0) { |
| 1068 | /* A zram_size was specified, so we need to configure the |
| 1069 | * device. There is no point in having multiple zram devices |
| 1070 | * on a system (all the memory comes from the same pool) so |
| 1071 | * we can assume the device number is 0. |
| 1072 | */ |
| 1073 | FILE *zram_fp; |
Peter Enderborg | 4d217f0 | 2016-08-26 15:09:35 +0200 | [diff] [blame] | 1074 | FILE *zram_mcs_fp; |
| 1075 | |
| 1076 | if (fstab->recs[i].max_comp_streams >= 0) { |
| 1077 | zram_mcs_fp = fopen(ZRAM_CONF_MCS, "r+"); |
| 1078 | if (zram_mcs_fp == NULL) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 1079 | LERROR << "Unable to open zram conf comp device " |
| 1080 | << ZRAM_CONF_MCS; |
Peter Enderborg | 4d217f0 | 2016-08-26 15:09:35 +0200 | [diff] [blame] | 1081 | ret = -1; |
| 1082 | continue; |
| 1083 | } |
| 1084 | fprintf(zram_mcs_fp, "%d\n", fstab->recs[i].max_comp_streams); |
| 1085 | fclose(zram_mcs_fp); |
| 1086 | } |
Ken Sumrall | 5bc31a2 | 2013-07-08 19:11:55 -0700 | [diff] [blame] | 1087 | |
| 1088 | zram_fp = fopen(ZRAM_CONF_DEV, "r+"); |
| 1089 | if (zram_fp == NULL) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 1090 | LERROR << "Unable to open zram conf device " << ZRAM_CONF_DEV; |
Ken Sumrall | 5bc31a2 | 2013-07-08 19:11:55 -0700 | [diff] [blame] | 1091 | ret = -1; |
| 1092 | continue; |
| 1093 | } |
| 1094 | fprintf(zram_fp, "%d\n", fstab->recs[i].zram_size); |
| 1095 | fclose(zram_fp); |
| 1096 | } |
| 1097 | |
| 1098 | if (fstab->recs[i].fs_mgr_flags & MF_WAIT) { |
| 1099 | wait_for_file(fstab->recs[i].blk_device, WAIT_TIMEOUT); |
| 1100 | } |
| 1101 | |
| 1102 | /* Initialize the swap area */ |
| 1103 | mkswap_argv[1] = fstab->recs[i].blk_device; |
bowgotsai | cea7ea7 | 2017-01-16 21:49:49 +0800 | [diff] [blame] | 1104 | err = android_fork_execvp_ext(ARRAY_SIZE(mkswap_argv), |
| 1105 | const_cast<char **>(mkswap_argv), |
Yusuke Sato | d81c3c6 | 2015-08-14 01:22:53 -0700 | [diff] [blame] | 1106 | &status, true, LOG_KLOG, false, NULL, |
| 1107 | NULL, 0); |
Ken Sumrall | 5bc31a2 | 2013-07-08 19:11:55 -0700 | [diff] [blame] | 1108 | if (err) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 1109 | LERROR << "mkswap failed for " << fstab->recs[i].blk_device; |
Ken Sumrall | 5bc31a2 | 2013-07-08 19:11:55 -0700 | [diff] [blame] | 1110 | ret = -1; |
| 1111 | continue; |
| 1112 | } |
| 1113 | |
| 1114 | /* If -1, then no priority was specified in fstab, so don't set |
| 1115 | * SWAP_FLAG_PREFER or encode the priority */ |
| 1116 | if (fstab->recs[i].swap_prio >= 0) { |
| 1117 | flags = (fstab->recs[i].swap_prio << SWAP_FLAG_PRIO_SHIFT) & |
| 1118 | SWAP_FLAG_PRIO_MASK; |
| 1119 | flags |= SWAP_FLAG_PREFER; |
| 1120 | } else { |
| 1121 | flags = 0; |
| 1122 | } |
| 1123 | err = swapon(fstab->recs[i].blk_device, flags); |
| 1124 | if (err) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 1125 | LERROR << "swapon failed for " << fstab->recs[i].blk_device; |
Ken Sumrall | 5bc31a2 | 2013-07-08 19:11:55 -0700 | [diff] [blame] | 1126 | ret = -1; |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | return ret; |
| 1131 | } |
| 1132 | |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1133 | /* |
| 1134 | * key_loc must be at least PROPERTY_VALUE_MAX bytes long |
| 1135 | * |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 1136 | * real_blk_device must be at least PROPERTY_VALUE_MAX bytes long |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1137 | */ |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 1138 | int fs_mgr_get_crypt_info(struct fstab *fstab, char *key_loc, char *real_blk_device, int size) |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1139 | { |
| 1140 | int i = 0; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1141 | |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 1142 | if (!fstab) { |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1143 | return -1; |
| 1144 | } |
| 1145 | /* Initialize return values to null strings */ |
| 1146 | if (key_loc) { |
| 1147 | *key_loc = '\0'; |
| 1148 | } |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 1149 | if (real_blk_device) { |
| 1150 | *real_blk_device = '\0'; |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | /* Look for the encryptable partition to find the data */ |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 1154 | for (i = 0; i < fstab->num_entries; i++) { |
| 1155 | /* Don't deal with vold managed enryptable partitions here */ |
| 1156 | if (fstab->recs[i].fs_mgr_flags & MF_VOLDMANAGED) { |
| 1157 | continue; |
| 1158 | } |
Paul Lawrence | b262d68 | 2015-10-29 10:31:02 -0700 | [diff] [blame] | 1159 | if (!(fstab->recs[i].fs_mgr_flags |
| 1160 | & (MF_CRYPT | MF_FORCECRYPT | MF_FORCEFDEORFBE))) { |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1161 | continue; |
| 1162 | } |
| 1163 | |
| 1164 | /* We found a match */ |
| 1165 | if (key_loc) { |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 1166 | strlcpy(key_loc, fstab->recs[i].key_loc, size); |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1167 | } |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 1168 | if (real_blk_device) { |
| 1169 | strlcpy(real_blk_device, fstab->recs[i].blk_device, size); |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1170 | } |
| 1171 | break; |
| 1172 | } |
| 1173 | |
Ken Sumrall | c1bf896 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 1174 | return 0; |
| 1175 | } |
Hung-ying Tyan | 99c4a8a | 2016-02-01 15:07:40 +0800 | [diff] [blame] | 1176 | |
| 1177 | int fs_mgr_early_setup_verity(struct fstab_rec *fstab_rec) |
| 1178 | { |
| 1179 | if ((fstab_rec->fs_mgr_flags & MF_VERIFY) && device_is_secure()) { |
Hung-ying Tyan | ecfce13 | 2016-12-16 15:00:05 +0800 | [diff] [blame] | 1180 | int rc = fs_mgr_setup_verity(fstab_rec, false); |
Mark Salyzyn | e528be5 | 2016-03-29 14:25:11 -0700 | [diff] [blame] | 1181 | if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 1182 | LINFO << "Verity disabled"; |
Hung-ying Tyan | 99c4a8a | 2016-02-01 15:07:40 +0800 | [diff] [blame] | 1183 | return FS_MGR_EARLY_SETUP_VERITY_NO_VERITY; |
| 1184 | } else if (rc == FS_MGR_SETUP_VERITY_SUCCESS) { |
| 1185 | return FS_MGR_EARLY_SETUP_VERITY_SUCCESS; |
| 1186 | } else { |
| 1187 | return FS_MGR_EARLY_SETUP_VERITY_FAIL; |
| 1188 | } |
| 1189 | } else if (device_is_secure()) { |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame^] | 1190 | LERROR << "Verity must be enabled for early mounted partitions on secured devices"; |
Hung-ying Tyan | 99c4a8a | 2016-02-01 15:07:40 +0800 | [diff] [blame] | 1191 | return FS_MGR_EARLY_SETUP_VERITY_FAIL; |
| 1192 | } |
| 1193 | return FS_MGR_EARLY_SETUP_VERITY_NO_VERITY; |
| 1194 | } |