diff options
author | Treehugger Robot | 2017-01-27 19:37:21 -0600 |
---|---|---|
committer | Gerrit Code Review | 2017-01-27 19:37:22 -0600 |
commit | 183ca56ce22fa59d8b1a1372051b28984d1ab91c (patch) | |
tree | d0059b61f0686a34eb1a597b3abf68c0707de1fa | |
parent | d0ff90afefcce82d7b70373da7bf749210e71dc1 (diff) | |
parent | 47878de7d12c7e438fcc584183b44893e91b4a28 (diff) | |
download | platform-system-core-183ca56ce22fa59d8b1a1372051b28984d1ab91c.tar.gz platform-system-core-183ca56ce22fa59d8b1a1372051b28984d1ab91c.tar.xz platform-system-core-183ca56ce22fa59d8b1a1372051b28984d1ab91c.zip |
Merge "fs_mgr: Switch to LOG()/PLOG() defined in <android-base/logging.h>"
-rw-r--r-- | fs_mgr/fs_mgr.cpp | 198 | ||||
-rw-r--r-- | fs_mgr/fs_mgr_avb.cpp | 56 | ||||
-rw-r--r-- | fs_mgr/fs_mgr_avb_ops.cpp | 14 | ||||
-rw-r--r-- | fs_mgr/fs_mgr_dm_ioctl.cpp | 8 | ||||
-rw-r--r-- | fs_mgr/fs_mgr_format.cpp | 19 | ||||
-rw-r--r-- | fs_mgr/fs_mgr_fstab.cpp | 24 | ||||
-rw-r--r-- | fs_mgr/fs_mgr_main.cpp | 9 | ||||
-rw-r--r-- | fs_mgr/fs_mgr_priv.h | 21 | ||||
-rw-r--r-- | fs_mgr/fs_mgr_slotselect.cpp | 13 | ||||
-rw-r--r-- | fs_mgr/fs_mgr_verity.cpp | 125 |
10 files changed, 254 insertions, 233 deletions
diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp index 207f42b53..be84e8a51 100644 --- a/fs_mgr/fs_mgr.cpp +++ b/fs_mgr/fs_mgr.cpp | |||
@@ -76,7 +76,7 @@ static time_t gettime(void) | |||
76 | 76 | ||
77 | ret = clock_gettime(CLOCK_MONOTONIC, &ts); | 77 | ret = clock_gettime(CLOCK_MONOTONIC, &ts); |
78 | if (ret < 0) { | 78 | if (ret < 0) { |
79 | ERROR("clock_gettime(CLOCK_MONOTONIC) failed: %s\n", strerror(errno)); | 79 | PERROR << "clock_gettime(CLOCK_MONOTONIC) failed"; |
80 | return 0; | 80 | return 0; |
81 | } | 81 | } |
82 | 82 | ||
@@ -131,8 +131,8 @@ static void check_fs(const char *blk_device, char *fs_type, char *target) | |||
131 | strlcat(tmpmnt_opts, ",nomblk_io_submit", sizeof(tmpmnt_opts)); | 131 | strlcat(tmpmnt_opts, ",nomblk_io_submit", sizeof(tmpmnt_opts)); |
132 | } | 132 | } |
133 | ret = mount(blk_device, target, fs_type, tmpmnt_flags, tmpmnt_opts); | 133 | ret = mount(blk_device, target, fs_type, tmpmnt_flags, tmpmnt_opts); |
134 | INFO("%s(): mount(%s,%s,%s)=%d: %s\n", | 134 | PINFO << __FUNCTION__ << "(): mount(" << blk_device << "," << target |
135 | __func__, blk_device, target, fs_type, ret, strerror(errno)); | 135 | << "," << fs_type << ")=" << ret; |
136 | if (!ret) { | 136 | if (!ret) { |
137 | int i; | 137 | int i; |
138 | for (i = 0; i < 5; i++) { | 138 | for (i = 0; i < 5; i++) { |
@@ -140,10 +140,12 @@ static void check_fs(const char *blk_device, char *fs_type, char *target) | |||
140 | // Should we try rebooting if all attempts fail? | 140 | // Should we try rebooting if all attempts fail? |
141 | int result = umount(target); | 141 | int result = umount(target); |
142 | if (result == 0) { | 142 | if (result == 0) { |
143 | INFO("%s(): unmount(%s) succeeded\n", __func__, target); | 143 | LINFO << __FUNCTION__ << "(): unmount(" << target |
144 | << ") succeeded"; | ||
144 | break; | 145 | break; |
145 | } | 146 | } |
146 | ERROR("%s(): umount(%s)=%d: %s\n", __func__, target, result, strerror(errno)); | 147 | PERROR << __FUNCTION__ << "(): umount(" << target << ")=" |
148 | << result; | ||
147 | sleep(1); | 149 | sleep(1); |
148 | } | 150 | } |
149 | } | 151 | } |
@@ -153,10 +155,10 @@ static void check_fs(const char *blk_device, char *fs_type, char *target) | |||
153 | * (e.g. recent SDK system images). Detect these and skip the check. | 155 | * (e.g. recent SDK system images). Detect these and skip the check. |
154 | */ | 156 | */ |
155 | if (access(E2FSCK_BIN, X_OK)) { | 157 | if (access(E2FSCK_BIN, X_OK)) { |
156 | INFO("Not running %s on %s (executable not in system image)\n", | 158 | LINFO << "Not running " << E2FSCK_BIN << " on " << blk_device |
157 | E2FSCK_BIN, blk_device); | 159 | << " (executable not in system image)"; |
158 | } else { | 160 | } else { |
159 | INFO("Running %s on %s\n", E2FSCK_BIN, blk_device); | 161 | LINFO << "Running " << E2FSCK_BIN << " on " << blk_device; |
160 | 162 | ||
161 | ret = android_fork_execvp_ext(ARRAY_SIZE(e2fsck_argv), | 163 | ret = android_fork_execvp_ext(ARRAY_SIZE(e2fsck_argv), |
162 | const_cast<char **>(e2fsck_argv), | 164 | const_cast<char **>(e2fsck_argv), |
@@ -167,7 +169,7 @@ static void check_fs(const char *blk_device, char *fs_type, char *target) | |||
167 | 169 | ||
168 | if (ret < 0) { | 170 | if (ret < 0) { |
169 | /* No need to check for error in fork, we can't really handle it now */ | 171 | /* No need to check for error in fork, we can't really handle it now */ |
170 | ERROR("Failed trying to run %s\n", E2FSCK_BIN); | 172 | LERROR << "Failed trying to run " << E2FSCK_BIN; |
171 | } | 173 | } |
172 | } | 174 | } |
173 | } else if (!strcmp(fs_type, "f2fs")) { | 175 | } else if (!strcmp(fs_type, "f2fs")) { |
@@ -176,7 +178,7 @@ static void check_fs(const char *blk_device, char *fs_type, char *target) | |||
176 | "-a", | 178 | "-a", |
177 | blk_device | 179 | blk_device |
178 | }; | 180 | }; |
179 | INFO("Running %s -a %s\n", F2FS_FSCK_BIN, blk_device); | 181 | LINFO << "Running " << F2FS_FSCK_BIN << " -a " << blk_device; |
180 | 182 | ||
181 | ret = android_fork_execvp_ext(ARRAY_SIZE(f2fs_fsck_argv), | 183 | ret = android_fork_execvp_ext(ARRAY_SIZE(f2fs_fsck_argv), |
182 | const_cast<char **>(f2fs_fsck_argv), | 184 | const_cast<char **>(f2fs_fsck_argv), |
@@ -185,7 +187,7 @@ static void check_fs(const char *blk_device, char *fs_type, char *target) | |||
185 | NULL, 0); | 187 | NULL, 0); |
186 | if (ret < 0) { | 188 | if (ret < 0) { |
187 | /* No need to check for error in fork, we can't really handle it now */ | 189 | /* No need to check for error in fork, we can't really handle it now */ |
188 | ERROR("Failed trying to run %s\n", F2FS_FSCK_BIN); | 190 | LERROR << "Failed trying to run " << F2FS_FSCK_BIN; |
189 | } | 191 | } |
190 | } | 192 | } |
191 | 193 | ||
@@ -231,8 +233,8 @@ static int do_quota(char *blk_device, char *fs_type, struct fstab_rec *rec) | |||
231 | * Detect these and skip reserve blocks. | 233 | * Detect these and skip reserve blocks. |
232 | */ | 234 | */ |
233 | if (access(TUNE2FS_BIN, X_OK)) { | 235 | if (access(TUNE2FS_BIN, X_OK)) { |
234 | ERROR("Not running %s on %s (executable not in system image)\n", | 236 | LERROR << "Not running " << TUNE2FS_BIN << " on " |
235 | TUNE2FS_BIN, blk_device); | 237 | << blk_device << " (executable not in system image)"; |
236 | } else { | 238 | } else { |
237 | const char* arg1 = nullptr; | 239 | const char* arg1 = nullptr; |
238 | const char* arg2 = nullptr; | 240 | const char* arg2 = nullptr; |
@@ -244,7 +246,7 @@ static int do_quota(char *blk_device, char *fs_type, struct fstab_rec *rec) | |||
244 | struct ext4_super_block sb; | 246 | struct ext4_super_block sb; |
245 | ret = read_super_block(fd, &sb); | 247 | ret = read_super_block(fd, &sb); |
246 | if (ret < 0) { | 248 | if (ret < 0) { |
247 | ERROR("Can't read '%s' super block: %s\n", blk_device, strerror(errno)); | 249 | PERROR << "Can't read '" << blk_device << "' super block"; |
248 | return force_check; | 250 | return force_check; |
249 | } | 251 | } |
250 | 252 | ||
@@ -253,20 +255,20 @@ static int do_quota(char *blk_device, char *fs_type, struct fstab_rec *rec) | |||
253 | int want_quota = fs_mgr_is_quota(rec) != 0; | 255 | int want_quota = fs_mgr_is_quota(rec) != 0; |
254 | 256 | ||
255 | if (has_quota == want_quota) { | 257 | if (has_quota == want_quota) { |
256 | INFO("Requested quota status is match on %s\n", blk_device); | 258 | LINFO << "Requested quota status is match on " << blk_device; |
257 | return force_check; | 259 | return force_check; |
258 | } else if (want_quota) { | 260 | } else if (want_quota) { |
259 | INFO("Enabling quota on %s\n", blk_device); | 261 | LINFO << "Enabling quota on " << blk_device; |
260 | arg1 = "-Oquota"; | 262 | arg1 = "-Oquota"; |
261 | arg2 = "-Qusrquota,grpquota"; | 263 | arg2 = "-Qusrquota,grpquota"; |
262 | force_check = 1; | 264 | force_check = 1; |
263 | } else { | 265 | } else { |
264 | INFO("Disabling quota on %s\n", blk_device); | 266 | LINFO << "Disabling quota on " << blk_device; |
265 | arg1 = "-Q^usrquota,^grpquota"; | 267 | arg1 = "-Q^usrquota,^grpquota"; |
266 | arg2 = "-O^quota"; | 268 | arg2 = "-O^quota"; |
267 | } | 269 | } |
268 | } else { | 270 | } else { |
269 | ERROR("Failed to open '%s': %s\n", blk_device, strerror(errno)); | 271 | PERROR << "Failed to open '" << blk_device << "'"; |
270 | return force_check; | 272 | return force_check; |
271 | } | 273 | } |
272 | 274 | ||
@@ -282,7 +284,7 @@ static int do_quota(char *blk_device, char *fs_type, struct fstab_rec *rec) | |||
282 | true, NULL, NULL, 0); | 284 | true, NULL, NULL, 0); |
283 | if (ret < 0) { | 285 | if (ret < 0) { |
284 | /* No need to check for error in fork, we can't really handle it now */ | 286 | /* No need to check for error in fork, we can't really handle it now */ |
285 | ERROR("Failed trying to run %s\n", TUNE2FS_BIN); | 287 | LERROR << "Failed trying to run " << TUNE2FS_BIN; |
286 | } | 288 | } |
287 | } | 289 | } |
288 | } | 290 | } |
@@ -298,10 +300,10 @@ static void do_reserved_size(char *blk_device, char *fs_type, struct fstab_rec * | |||
298 | * Detect these and skip reserve blocks. | 300 | * Detect these and skip reserve blocks. |
299 | */ | 301 | */ |
300 | if (access(TUNE2FS_BIN, X_OK)) { | 302 | if (access(TUNE2FS_BIN, X_OK)) { |
301 | ERROR("Not running %s on %s (executable not in system image)\n", | 303 | LERROR << "Not running " << TUNE2FS_BIN << " on " |
302 | TUNE2FS_BIN, blk_device); | 304 | << blk_device << " (executable not in system image)"; |
303 | } else { | 305 | } else { |
304 | INFO("Running %s on %s\n", TUNE2FS_BIN, blk_device); | 306 | LINFO << "Running " << TUNE2FS_BIN << " on " << blk_device; |
305 | 307 | ||
306 | int status = 0; | 308 | int status = 0; |
307 | int ret = 0; | 309 | int ret = 0; |
@@ -312,22 +314,23 @@ static void do_reserved_size(char *blk_device, char *fs_type, struct fstab_rec * | |||
312 | struct ext4_super_block sb; | 314 | struct ext4_super_block sb; |
313 | ret = read_super_block(fd, &sb); | 315 | ret = read_super_block(fd, &sb); |
314 | if (ret < 0) { | 316 | if (ret < 0) { |
315 | ERROR("Can't read '%s' super block: %s\n", blk_device, strerror(errno)); | 317 | PERROR << "Can't read '" << blk_device << "' super block"; |
316 | return; | 318 | return; |
317 | } | 319 | } |
318 | reserved_blocks = rec->reserved_size / EXT4_BLOCK_SIZE(&sb); | 320 | reserved_blocks = rec->reserved_size / EXT4_BLOCK_SIZE(&sb); |
319 | unsigned long reserved_threshold = ext4_blocks_count(&sb) * 0.02; | 321 | unsigned long reserved_threshold = ext4_blocks_count(&sb) * 0.02; |
320 | if (reserved_threshold < reserved_blocks) { | 322 | if (reserved_threshold < reserved_blocks) { |
321 | WARNING("Reserved blocks %lu is too large\n", reserved_blocks); | 323 | LWARNING << "Reserved blocks " << reserved_blocks |
324 | << " is too large"; | ||
322 | reserved_blocks = reserved_threshold; | 325 | reserved_blocks = reserved_threshold; |
323 | } | 326 | } |
324 | 327 | ||
325 | if (ext4_r_blocks_count(&sb) == reserved_blocks) { | 328 | if (ext4_r_blocks_count(&sb) == reserved_blocks) { |
326 | INFO("Have reserved same blocks\n"); | 329 | LINFO << "Have reserved same blocks"; |
327 | return; | 330 | return; |
328 | } | 331 | } |
329 | } else { | 332 | } else { |
330 | ERROR("Failed to open '%s': %s\n", blk_device, strerror(errno)); | 333 | PERROR << "Failed to open '" << blk_device << "'"; |
331 | return; | 334 | return; |
332 | } | 335 | } |
333 | 336 | ||
@@ -346,7 +349,7 @@ static void do_reserved_size(char *blk_device, char *fs_type, struct fstab_rec * | |||
346 | 349 | ||
347 | if (ret < 0) { | 350 | if (ret < 0) { |
348 | /* No need to check for error in fork, we can't really handle it now */ | 351 | /* No need to check for error in fork, we can't really handle it now */ |
349 | ERROR("Failed trying to run %s\n", TUNE2FS_BIN); | 352 | LERROR << "Failed trying to run " << TUNE2FS_BIN; |
350 | } | 353 | } |
351 | } | 354 | } |
352 | } | 355 | } |
@@ -406,7 +409,8 @@ static int __mount(const char *source, const char *target, const struct fstab_re | |||
406 | mkdir(target, 0755); | 409 | mkdir(target, 0755); |
407 | ret = mount(source, target, rec->fs_type, mountflags, rec->fs_options); | 410 | ret = mount(source, target, rec->fs_type, mountflags, rec->fs_options); |
408 | save_errno = errno; | 411 | save_errno = errno; |
409 | INFO("%s(source=%s,target=%s,type=%s)=%d\n", __func__, source, target, rec->fs_type, ret); | 412 | LINFO << __FUNCTION__ << "(source=" << source << ",target=" |
413 | << target << ",type=" << rec->fs_type << ")=" << ret; | ||
410 | if ((ret == 0) && (mountflags & MS_RDONLY) != 0) { | 414 | if ((ret == 0) && (mountflags & MS_RDONLY) != 0) { |
411 | fs_mgr_set_blk_ro(source); | 415 | fs_mgr_set_blk_ro(source); |
412 | } | 416 | } |
@@ -488,8 +492,11 @@ static int mount_with_alternatives(struct fstab *fstab, int start_idx, int *end_ | |||
488 | * each other. | 492 | * each other. |
489 | */ | 493 | */ |
490 | if (mounted) { | 494 | if (mounted) { |
491 | ERROR("%s(): skipping fstab dup mountpoint=%s rec[%d].fs_type=%s already mounted as %s.\n", __func__, | 495 | LERROR << __FUNCTION__ << "(): skipping fstab dup mountpoint=" |
492 | fstab->recs[i].mount_point, i, fstab->recs[i].fs_type, fstab->recs[*attempted_idx].fs_type); | 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; | ||
493 | continue; | 500 | continue; |
494 | } | 501 | } |
495 | 502 | ||
@@ -510,9 +517,11 @@ static int mount_with_alternatives(struct fstab *fstab, int start_idx, int *end_ | |||
510 | *attempted_idx = i; | 517 | *attempted_idx = i; |
511 | mounted = 1; | 518 | mounted = 1; |
512 | if (i != start_idx) { | 519 | if (i != start_idx) { |
513 | ERROR("%s(): Mounted %s on %s with fs_type=%s instead of %s\n", __func__, | 520 | LERROR << __FUNCTION__ << "(): Mounted " |
514 | fstab->recs[i].blk_device, fstab->recs[i].mount_point, fstab->recs[i].fs_type, | 521 | << fstab->recs[i].blk_device << " on " |
515 | fstab->recs[start_idx].fs_type); | 522 | << fstab->recs[i].mount_point << " with fs_type=" |
523 | << fstab->recs[i].fs_type << " instead of " | ||
524 | << fstab->recs[start_idx].fs_type; | ||
516 | } | 525 | } |
517 | } else { | 526 | } else { |
518 | /* back up errno for crypto decisions */ | 527 | /* back up errno for crypto decisions */ |
@@ -547,14 +556,14 @@ static int translate_ext_labels(struct fstab_rec *rec) | |||
547 | label_len = strlen(label); | 556 | label_len = strlen(label); |
548 | 557 | ||
549 | if (label_len > 16) { | 558 | if (label_len > 16) { |
550 | ERROR("FS label is longer than allowed by filesystem\n"); | 559 | LERROR << "FS label is longer than allowed by filesystem"; |
551 | goto out; | 560 | goto out; |
552 | } | 561 | } |
553 | 562 | ||
554 | 563 | ||
555 | blockdir = opendir("/dev/block"); | 564 | blockdir = opendir("/dev/block"); |
556 | if (!blockdir) { | 565 | if (!blockdir) { |
557 | ERROR("couldn't open /dev/block\n"); | 566 | LERROR << "couldn't open /dev/block"; |
558 | goto out; | 567 | goto out; |
559 | } | 568 | } |
560 | 569 | ||
@@ -568,7 +577,7 @@ static int translate_ext_labels(struct fstab_rec *rec) | |||
568 | 577 | ||
569 | fd = openat(dirfd(blockdir), ent->d_name, O_RDONLY); | 578 | fd = openat(dirfd(blockdir), ent->d_name, O_RDONLY); |
570 | if (fd < 0) { | 579 | if (fd < 0) { |
571 | ERROR("Cannot open block device /dev/block/%s\n", ent->d_name); | 580 | LERROR << "Cannot open block device /dev/block/" << ent->d_name; |
572 | goto out; | 581 | goto out; |
573 | } | 582 | } |
574 | 583 | ||
@@ -583,7 +592,7 @@ static int translate_ext_labels(struct fstab_rec *rec) | |||
583 | 592 | ||
584 | sb = (struct ext4_super_block *)super_buf; | 593 | sb = (struct ext4_super_block *)super_buf; |
585 | if (sb->s_magic != EXT4_SUPER_MAGIC) { | 594 | if (sb->s_magic != EXT4_SUPER_MAGIC) { |
586 | INFO("/dev/block/%s not ext{234}\n", ent->d_name); | 595 | LINFO << "/dev/block/" << ent->d_name << " not ext{234}"; |
587 | continue; | 596 | continue; |
588 | } | 597 | } |
589 | 598 | ||
@@ -591,11 +600,12 @@ static int translate_ext_labels(struct fstab_rec *rec) | |||
591 | char *new_blk_device; | 600 | char *new_blk_device; |
592 | 601 | ||
593 | if (asprintf(&new_blk_device, "/dev/block/%s", ent->d_name) < 0) { | 602 | if (asprintf(&new_blk_device, "/dev/block/%s", ent->d_name) < 0) { |
594 | ERROR("Could not allocate block device string\n"); | 603 | LERROR << "Could not allocate block device string"; |
595 | goto out; | 604 | goto out; |
596 | } | 605 | } |
597 | 606 | ||
598 | INFO("resolved label %s to %s\n", rec->blk_device, new_blk_device); | 607 | LINFO << "resolved label " << rec->blk_device << " to " |
608 | << new_blk_device; | ||
599 | 609 | ||
600 | free(rec->blk_device); | 610 | free(rec->blk_device); |
601 | rec->blk_device = new_blk_device; | 611 | rec->blk_device = new_blk_device; |
@@ -638,13 +648,13 @@ static int handle_encryptable(const struct fstab_rec* rec) | |||
638 | if (umount(rec->mount_point) == 0) { | 648 | if (umount(rec->mount_point) == 0) { |
639 | return FS_MGR_MNTALL_DEV_NEEDS_ENCRYPTION; | 649 | return FS_MGR_MNTALL_DEV_NEEDS_ENCRYPTION; |
640 | } else { | 650 | } else { |
641 | WARNING("Could not umount %s (%s) - allow continue unencrypted\n", | 651 | PWARNING << "Could not umount " << rec->mount_point |
642 | rec->mount_point, strerror(errno)); | 652 | << " - allow continue unencrypted"; |
643 | return FS_MGR_MNTALL_DEV_NOT_ENCRYPTED; | 653 | return FS_MGR_MNTALL_DEV_NOT_ENCRYPTED; |
644 | } | 654 | } |
645 | } else if (rec->fs_mgr_flags & (MF_FILEENCRYPTION | MF_FORCEFDEORFBE)) { | 655 | } else if (rec->fs_mgr_flags & (MF_FILEENCRYPTION | MF_FORCEFDEORFBE)) { |
646 | // Deal with file level encryption | 656 | // Deal with file level encryption |
647 | INFO("%s is file encrypted\n", rec->mount_point); | 657 | LINFO << rec->mount_point << " is file encrypted"; |
648 | return FS_MGR_MNTALL_DEV_FILE_ENCRYPTED; | 658 | return FS_MGR_MNTALL_DEV_FILE_ENCRYPTED; |
649 | } else if (fs_mgr_is_encryptable(rec)) { | 659 | } else if (fs_mgr_is_encryptable(rec)) { |
650 | return FS_MGR_MNTALL_DEV_NOT_ENCRYPTED; | 660 | return FS_MGR_MNTALL_DEV_NOT_ENCRYPTED; |
@@ -717,7 +727,7 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode) | |||
717 | !strcmp(fstab->recs[i].fs_type, "ext4")) { | 727 | !strcmp(fstab->recs[i].fs_type, "ext4")) { |
718 | int tret = translate_ext_labels(&fstab->recs[i]); | 728 | int tret = translate_ext_labels(&fstab->recs[i]); |
719 | if (tret < 0) { | 729 | if (tret < 0) { |
720 | ERROR("Could not translate label to block device\n"); | 730 | LERROR << "Could not translate label to block device"; |
721 | continue; | 731 | continue; |
722 | } | 732 | } |
723 | } | 733 | } |
@@ -733,20 +743,20 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode) | |||
733 | * mount_with_alternatives(). | 743 | * mount_with_alternatives(). |
734 | */ | 744 | */ |
735 | if (avb_ret == FS_MGR_SETUP_AVB_HASHTREE_DISABLED) { | 745 | if (avb_ret == FS_MGR_SETUP_AVB_HASHTREE_DISABLED) { |
736 | INFO("AVB HASHTREE disabled\n"); | 746 | LINFO << "AVB HASHTREE disabled"; |
737 | } else if (fs_mgr_setup_avb(&fstab->recs[i]) != | 747 | } else if (fs_mgr_setup_avb(&fstab->recs[i]) != |
738 | FS_MGR_SETUP_AVB_SUCCESS) { | 748 | FS_MGR_SETUP_AVB_SUCCESS) { |
739 | ERROR("Failed to set up AVB on partition: %s, skipping!\n", | 749 | LERROR << "Failed to set up AVB on partition: " |
740 | fstab->recs[i].mount_point); | 750 | << fstab->recs[i].mount_point << ", skipping!"; |
741 | /* Skips mounting the device. */ | 751 | /* Skips mounting the device. */ |
742 | continue; | 752 | continue; |
743 | } | 753 | } |
744 | } else if ((fstab->recs[i].fs_mgr_flags & MF_VERIFY) && device_is_secure()) { | 754 | } else if ((fstab->recs[i].fs_mgr_flags & MF_VERIFY) && device_is_secure()) { |
745 | int rc = fs_mgr_setup_verity(&fstab->recs[i], true); | 755 | int rc = fs_mgr_setup_verity(&fstab->recs[i], true); |
746 | if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) { | 756 | if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) { |
747 | INFO("Verity disabled"); | 757 | LINFO << "Verity disabled"; |
748 | } else if (rc != FS_MGR_SETUP_VERITY_SUCCESS) { | 758 | } else if (rc != FS_MGR_SETUP_VERITY_SUCCESS) { |
749 | ERROR("Could not set up verified partition, skipping!\n"); | 759 | LERROR << "Could not set up verified partition, skipping!"; |
750 | continue; | 760 | continue; |
751 | } | 761 | } |
752 | } | 762 | } |
@@ -770,7 +780,7 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode) | |||
770 | if (status != FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE) { | 780 | if (status != FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE) { |
771 | if (encryptable != FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE) { | 781 | if (encryptable != FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE) { |
772 | // Log and continue | 782 | // Log and continue |
773 | ERROR("Only one encryptable/encrypted partition supported\n"); | 783 | LERROR << "Only one encryptable/encrypted partition supported"; |
774 | } | 784 | } |
775 | encryptable = status; | 785 | encryptable = status; |
776 | } | 786 | } |
@@ -788,19 +798,21 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode) | |||
788 | * at two different lines in the fstab. Use the top one for formatting | 798 | * at two different lines in the fstab. Use the top one for formatting |
789 | * as that is the preferred one. | 799 | * as that is the preferred one. |
790 | */ | 800 | */ |
791 | ERROR("%s(): %s is wiped and %s %s is formattable. Format it.\n", __func__, | 801 | LERROR << __FUNCTION__ << "(): " << fstab->recs[top_idx].blk_device |
792 | fstab->recs[top_idx].blk_device, fstab->recs[top_idx].mount_point, | 802 | << " is wiped and " << fstab->recs[top_idx].mount_point |
793 | fstab->recs[top_idx].fs_type); | 803 | << " " << fstab->recs[top_idx].fs_type |
804 | << " is formattable. Format it."; | ||
794 | if (fs_mgr_is_encryptable(&fstab->recs[top_idx]) && | 805 | if (fs_mgr_is_encryptable(&fstab->recs[top_idx]) && |
795 | strcmp(fstab->recs[top_idx].key_loc, KEY_IN_FOOTER)) { | 806 | strcmp(fstab->recs[top_idx].key_loc, KEY_IN_FOOTER)) { |
796 | int fd = open(fstab->recs[top_idx].key_loc, O_WRONLY); | 807 | int fd = open(fstab->recs[top_idx].key_loc, O_WRONLY); |
797 | if (fd >= 0) { | 808 | if (fd >= 0) { |
798 | INFO("%s(): also wipe %s\n", __func__, fstab->recs[top_idx].key_loc); | 809 | LINFO << __FUNCTION__ << "(): also wipe " |
810 | << fstab->recs[top_idx].key_loc; | ||
799 | wipe_block_device(fd, get_file_size(fd)); | 811 | wipe_block_device(fd, get_file_size(fd)); |
800 | close(fd); | 812 | close(fd); |
801 | } else { | 813 | } else { |
802 | ERROR("%s(): %s wouldn't open (%s)\n", __func__, | 814 | PERROR << __FUNCTION__ << "(): " |
803 | fstab->recs[top_idx].key_loc, strerror(errno)); | 815 | << fstab->recs[top_idx].key_loc << " wouldn't open"; |
804 | } | 816 | } |
805 | } else if (fs_mgr_is_encryptable(&fstab->recs[top_idx]) && | 817 | } else if (fs_mgr_is_encryptable(&fstab->recs[top_idx]) && |
806 | !strcmp(fstab->recs[top_idx].key_loc, KEY_IN_FOOTER)) { | 818 | !strcmp(fstab->recs[top_idx].key_loc, KEY_IN_FOOTER)) { |
@@ -811,7 +823,8 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode) | |||
811 | i = top_idx - 1; | 823 | i = top_idx - 1; |
812 | continue; | 824 | continue; |
813 | } else { | 825 | } else { |
814 | ERROR("%s(): Format failed. Suggest recovery...\n", __func__); | 826 | LERROR << __FUNCTION__ << "(): Format failed. " |
827 | << "Suggest recovery..."; | ||
815 | encryptable = FS_MGR_MNTALL_DEV_NEEDS_RECOVERY; | 828 | encryptable = FS_MGR_MNTALL_DEV_NEEDS_RECOVERY; |
816 | continue; | 829 | continue; |
817 | } | 830 | } |
@@ -819,18 +832,22 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode) | |||
819 | if (mret && mount_errno != EBUSY && mount_errno != EACCES && | 832 | if (mret && mount_errno != EBUSY && mount_errno != EACCES && |
820 | fs_mgr_is_encryptable(&fstab->recs[attempted_idx])) { | 833 | fs_mgr_is_encryptable(&fstab->recs[attempted_idx])) { |
821 | if (wiped) { | 834 | if (wiped) { |
822 | ERROR("%s(): %s is wiped and %s %s is encryptable. Suggest recovery...\n", __func__, | 835 | LERROR << __FUNCTION__ << "(): " |
823 | fstab->recs[attempted_idx].blk_device, fstab->recs[attempted_idx].mount_point, | 836 | << fstab->recs[attempted_idx].blk_device |
824 | fstab->recs[attempted_idx].fs_type); | 837 | << " is wiped and " |
838 | << fstab->recs[attempted_idx].mount_point << " " | ||
839 | << fstab->recs[attempted_idx].fs_type | ||
840 | << " is encryptable. Suggest recovery..."; | ||
825 | encryptable = FS_MGR_MNTALL_DEV_NEEDS_RECOVERY; | 841 | encryptable = FS_MGR_MNTALL_DEV_NEEDS_RECOVERY; |
826 | continue; | 842 | continue; |
827 | } else { | 843 | } else { |
828 | /* Need to mount a tmpfs at this mountpoint for now, and set | 844 | /* Need to mount a tmpfs at this mountpoint for now, and set |
829 | * properties that vold will query later for decrypting | 845 | * properties that vold will query later for decrypting |
830 | */ | 846 | */ |
831 | ERROR("%s(): possibly an encryptable blkdev %s for mount %s type %s )\n", __func__, | 847 | LERROR << __FUNCTION__ << "(): possibly an encryptable blkdev " |
832 | fstab->recs[attempted_idx].blk_device, fstab->recs[attempted_idx].mount_point, | 848 | << fstab->recs[attempted_idx].blk_device |
833 | fstab->recs[attempted_idx].fs_type); | 849 | << " for mount " << fstab->recs[attempted_idx].mount_point |
850 | << " type " << fstab->recs[attempted_idx].fs_type; | ||
834 | if (fs_mgr_do_tmpfs_mount(fstab->recs[attempted_idx].mount_point) < 0) { | 851 | if (fs_mgr_do_tmpfs_mount(fstab->recs[attempted_idx].mount_point) < 0) { |
835 | ++error_count; | 852 | ++error_count; |
836 | continue; | 853 | continue; |
@@ -839,15 +856,15 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode) | |||
839 | encryptable = FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED; | 856 | encryptable = FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED; |
840 | } else { | 857 | } else { |
841 | if (fs_mgr_is_nofail(&fstab->recs[attempted_idx])) { | 858 | if (fs_mgr_is_nofail(&fstab->recs[attempted_idx])) { |
842 | ERROR("Ignoring failure to mount an un-encryptable or wiped partition on" | 859 | PERROR << "Ignoring failure to mount an un-encryptable or wiped partition on" |
843 | "%s at %s options: %s error: %s\n", | 860 | << fstab->recs[attempted_idx].blk_device << " at " |
844 | fstab->recs[attempted_idx].blk_device, fstab->recs[attempted_idx].mount_point, | 861 | << fstab->recs[attempted_idx].mount_point << " options: " |
845 | fstab->recs[attempted_idx].fs_options, strerror(mount_errno)); | 862 | << fstab->recs[attempted_idx].fs_options; |
846 | } else { | 863 | } else { |
847 | ERROR("Failed to mount an un-encryptable or wiped partition on" | 864 | PERROR << "Failed to mount an un-encryptable or wiped partition on" |
848 | "%s at %s options: %s error: %s\n", | 865 | << fstab->recs[attempted_idx].blk_device << " at " |
849 | fstab->recs[attempted_idx].blk_device, fstab->recs[attempted_idx].mount_point, | 866 | << fstab->recs[attempted_idx].mount_point << " options: " |
850 | fstab->recs[attempted_idx].fs_options, strerror(mount_errno)); | 867 | << fstab->recs[attempted_idx].fs_options; |
851 | ++error_count; | 868 | ++error_count; |
852 | } | 869 | } |
853 | continue; | 870 | continue; |
@@ -899,8 +916,8 @@ int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device, | |||
899 | if (!strcmp(fstab->recs[i].fs_type, "swap") || | 916 | if (!strcmp(fstab->recs[i].fs_type, "swap") || |
900 | !strcmp(fstab->recs[i].fs_type, "emmc") || | 917 | !strcmp(fstab->recs[i].fs_type, "emmc") || |
901 | !strcmp(fstab->recs[i].fs_type, "mtd")) { | 918 | !strcmp(fstab->recs[i].fs_type, "mtd")) { |
902 | ERROR("Cannot mount filesystem of type %s on %s\n", | 919 | LERROR << "Cannot mount filesystem of type " |
903 | fstab->recs[i].fs_type, n_blk_device); | 920 | << fstab->recs[i].fs_type << " on " << n_blk_device; |
904 | goto out; | 921 | goto out; |
905 | } | 922 | } |
906 | 923 | ||
@@ -928,20 +945,20 @@ int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device, | |||
928 | * mount_with_alternatives(). | 945 | * mount_with_alternatives(). |
929 | */ | 946 | */ |
930 | if (avb_ret == FS_MGR_SETUP_AVB_HASHTREE_DISABLED) { | 947 | if (avb_ret == FS_MGR_SETUP_AVB_HASHTREE_DISABLED) { |
931 | INFO("AVB HASHTREE disabled\n"); | 948 | LINFO << "AVB HASHTREE disabled"; |
932 | } else if (fs_mgr_setup_avb(&fstab->recs[i]) != | 949 | } else if (fs_mgr_setup_avb(&fstab->recs[i]) != |
933 | FS_MGR_SETUP_AVB_SUCCESS) { | 950 | FS_MGR_SETUP_AVB_SUCCESS) { |
934 | ERROR("Failed to set up AVB on partition: %s, skipping!\n", | 951 | LERROR << "Failed to set up AVB on partition: " |
935 | fstab->recs[i].mount_point); | 952 | << fstab->recs[i].mount_point << ", skipping!"; |
936 | /* Skips mounting the device. */ | 953 | /* Skips mounting the device. */ |
937 | continue; | 954 | continue; |
938 | } | 955 | } |
939 | } else if ((fstab->recs[i].fs_mgr_flags & MF_VERIFY) && device_is_secure()) { | 956 | } else if ((fstab->recs[i].fs_mgr_flags & MF_VERIFY) && device_is_secure()) { |
940 | int rc = fs_mgr_setup_verity(&fstab->recs[i], true); | 957 | int rc = fs_mgr_setup_verity(&fstab->recs[i], true); |
941 | if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) { | 958 | if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) { |
942 | INFO("Verity disabled"); | 959 | LINFO << "Verity disabled"; |
943 | } else if (rc != FS_MGR_SETUP_VERITY_SUCCESS) { | 960 | } else if (rc != FS_MGR_SETUP_VERITY_SUCCESS) { |
944 | ERROR("Could not set up verified partition, skipping!\n"); | 961 | LERROR << "Could not set up verified partition, skipping!"; |
945 | continue; | 962 | continue; |
946 | } | 963 | } |
947 | } | 964 | } |
@@ -962,8 +979,8 @@ int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device, | |||
962 | } | 979 | } |
963 | } | 980 | } |
964 | if (mount_errors) { | 981 | if (mount_errors) { |
965 | ERROR("Cannot mount filesystem on %s at %s. error: %s\n", | 982 | PERROR << "Cannot mount filesystem on " << n_blk_device |
966 | n_blk_device, m, strerror(first_mount_errno)); | 983 | << " at " << m; |
967 | if (first_mount_errno == EBUSY) { | 984 | if (first_mount_errno == EBUSY) { |
968 | ret = FS_MGR_DOMNT_BUSY; | 985 | ret = FS_MGR_DOMNT_BUSY; |
969 | } else { | 986 | } else { |
@@ -971,7 +988,8 @@ int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device, | |||
971 | } | 988 | } |
972 | } else { | 989 | } else { |
973 | /* We didn't find a match, say so and return an error */ | 990 | /* We didn't find a match, say so and return an error */ |
974 | ERROR("Cannot find mount point %s in fstab\n", fstab->recs[i].mount_point); | 991 | LERROR << "Cannot find mount point " << fstab->recs[i].mount_point |
992 | << " in fstab"; | ||
975 | } | 993 | } |
976 | 994 | ||
977 | out: | 995 | out: |
@@ -992,7 +1010,7 @@ int fs_mgr_do_tmpfs_mount(char *n_name) | |||
992 | ret = mount("tmpfs", n_name, "tmpfs", | 1010 | ret = mount("tmpfs", n_name, "tmpfs", |
993 | MS_NOATIME | MS_NOSUID | MS_NODEV, CRYPTO_TMPFS_OPTIONS); | 1011 | MS_NOATIME | MS_NOSUID | MS_NODEV, CRYPTO_TMPFS_OPTIONS); |
994 | if (ret < 0) { | 1012 | if (ret < 0) { |
995 | ERROR("Cannot mount tmpfs filesystem at %s\n", n_name); | 1013 | LERROR << "Cannot mount tmpfs filesystem at " << n_name; |
996 | return -1; | 1014 | return -1; |
997 | } | 1015 | } |
998 | 1016 | ||
@@ -1011,7 +1029,8 @@ int fs_mgr_unmount_all(struct fstab *fstab) | |||
1011 | 1029 | ||
1012 | while (fstab->recs[i].blk_device) { | 1030 | while (fstab->recs[i].blk_device) { |
1013 | if (umount(fstab->recs[i].mount_point)) { | 1031 | if (umount(fstab->recs[i].mount_point)) { |
1014 | ERROR("Cannot unmount filesystem at %s\n", fstab->recs[i].mount_point); | 1032 | LERROR << "Cannot unmount filesystem at " |
1033 | << fstab->recs[i].mount_point; | ||
1015 | ret = -1; | 1034 | ret = -1; |
1016 | } | 1035 | } |
1017 | i++; | 1036 | i++; |
@@ -1057,7 +1076,8 @@ int fs_mgr_swapon_all(struct fstab *fstab) | |||
1057 | if (fstab->recs[i].max_comp_streams >= 0) { | 1076 | if (fstab->recs[i].max_comp_streams >= 0) { |
1058 | zram_mcs_fp = fopen(ZRAM_CONF_MCS, "r+"); | 1077 | zram_mcs_fp = fopen(ZRAM_CONF_MCS, "r+"); |
1059 | if (zram_mcs_fp == NULL) { | 1078 | if (zram_mcs_fp == NULL) { |
1060 | ERROR("Unable to open zram conf comp device %s\n", ZRAM_CONF_MCS); | 1079 | LERROR << "Unable to open zram conf comp device " |
1080 | << ZRAM_CONF_MCS; | ||
1061 | ret = -1; | 1081 | ret = -1; |
1062 | continue; | 1082 | continue; |
1063 | } | 1083 | } |
@@ -1067,7 +1087,7 @@ int fs_mgr_swapon_all(struct fstab *fstab) | |||
1067 | 1087 | ||
1068 | zram_fp = fopen(ZRAM_CONF_DEV, "r+"); | 1088 | zram_fp = fopen(ZRAM_CONF_DEV, "r+"); |
1069 | if (zram_fp == NULL) { | 1089 | if (zram_fp == NULL) { |
1070 | ERROR("Unable to open zram conf device %s\n", ZRAM_CONF_DEV); | 1090 | LERROR << "Unable to open zram conf device " << ZRAM_CONF_DEV; |
1071 | ret = -1; | 1091 | ret = -1; |
1072 | continue; | 1092 | continue; |
1073 | } | 1093 | } |
@@ -1086,7 +1106,7 @@ int fs_mgr_swapon_all(struct fstab *fstab) | |||
1086 | &status, true, LOG_KLOG, false, NULL, | 1106 | &status, true, LOG_KLOG, false, NULL, |
1087 | NULL, 0); | 1107 | NULL, 0); |
1088 | if (err) { | 1108 | if (err) { |
1089 | ERROR("mkswap failed for %s\n", fstab->recs[i].blk_device); | 1109 | LERROR << "mkswap failed for " << fstab->recs[i].blk_device; |
1090 | ret = -1; | 1110 | ret = -1; |
1091 | continue; | 1111 | continue; |
1092 | } | 1112 | } |
@@ -1102,7 +1122,7 @@ int fs_mgr_swapon_all(struct fstab *fstab) | |||
1102 | } | 1122 | } |
1103 | err = swapon(fstab->recs[i].blk_device, flags); | 1123 | err = swapon(fstab->recs[i].blk_device, flags); |
1104 | if (err) { | 1124 | if (err) { |
1105 | ERROR("swapon failed for %s\n", fstab->recs[i].blk_device); | 1125 | LERROR << "swapon failed for " << fstab->recs[i].blk_device; |
1106 | ret = -1; | 1126 | ret = -1; |
1107 | } | 1127 | } |
1108 | } | 1128 | } |
@@ -1159,7 +1179,7 @@ int fs_mgr_early_setup_verity(struct fstab_rec *fstab_rec) | |||
1159 | if ((fstab_rec->fs_mgr_flags & MF_VERIFY) && device_is_secure()) { | 1179 | if ((fstab_rec->fs_mgr_flags & MF_VERIFY) && device_is_secure()) { |
1160 | int rc = fs_mgr_setup_verity(fstab_rec, false); | 1180 | int rc = fs_mgr_setup_verity(fstab_rec, false); |
1161 | if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) { | 1181 | if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) { |
1162 | INFO("Verity disabled"); | 1182 | LINFO << "Verity disabled"; |
1163 | return FS_MGR_EARLY_SETUP_VERITY_NO_VERITY; | 1183 | return FS_MGR_EARLY_SETUP_VERITY_NO_VERITY; |
1164 | } else if (rc == FS_MGR_SETUP_VERITY_SUCCESS) { | 1184 | } else if (rc == FS_MGR_SETUP_VERITY_SUCCESS) { |
1165 | return FS_MGR_EARLY_SETUP_VERITY_SUCCESS; | 1185 | return FS_MGR_EARLY_SETUP_VERITY_SUCCESS; |
@@ -1167,7 +1187,7 @@ int fs_mgr_early_setup_verity(struct fstab_rec *fstab_rec) | |||
1167 | return FS_MGR_EARLY_SETUP_VERITY_FAIL; | 1187 | return FS_MGR_EARLY_SETUP_VERITY_FAIL; |
1168 | } | 1188 | } |
1169 | } else if (device_is_secure()) { | 1189 | } else if (device_is_secure()) { |
1170 | ERROR("Verity must be enabled for early mounted partitions on secured devices.\n"); | 1190 | LERROR << "Verity must be enabled for early mounted partitions on secured devices"; |
1171 | return FS_MGR_EARLY_SETUP_VERITY_FAIL; | 1191 | return FS_MGR_EARLY_SETUP_VERITY_FAIL; |
1172 | } | 1192 | } |
1173 | return FS_MGR_EARLY_SETUP_VERITY_NO_VERITY; | 1193 | return FS_MGR_EARLY_SETUP_VERITY_NO_VERITY; |
diff --git a/fs_mgr/fs_mgr_avb.cpp b/fs_mgr/fs_mgr_avb.cpp index 51632cf39..70140d828 100644 --- a/fs_mgr/fs_mgr_avb.cpp +++ b/fs_mgr/fs_mgr_avb.cpp | |||
@@ -209,21 +209,21 @@ static bool load_vbmeta_prop(androidboot_vbmeta *vbmeta_prop) | |||
209 | expected_digest_size = SHA512_DIGEST_LENGTH * 2; | 209 | expected_digest_size = SHA512_DIGEST_LENGTH * 2; |
210 | vbmeta_prop->hash_alg = kSHA512; | 210 | vbmeta_prop->hash_alg = kSHA512; |
211 | } else { | 211 | } else { |
212 | ERROR("Unknown hash algorithm: %s\n", hash_alg.c_str()); | 212 | LERROR << "Unknown hash algorithm: " << hash_alg.c_str(); |
213 | return false; | 213 | return false; |
214 | } | 214 | } |
215 | 215 | ||
216 | // Reads digest. | 216 | // Reads digest. |
217 | if (digest.size() != expected_digest_size) { | 217 | if (digest.size() != expected_digest_size) { |
218 | ERROR("Unexpected digest size: %zu (expected %zu)\n", digest.size(), | 218 | LERROR << "Unexpected digest size: " << digest.size() << " (expected: " |
219 | expected_digest_size); | 219 | << expected_digest_size << ")"; |
220 | return false; | 220 | return false; |
221 | } | 221 | } |
222 | 222 | ||
223 | if (!hex_to_bytes(vbmeta_prop->digest, sizeof(vbmeta_prop->digest), | 223 | if (!hex_to_bytes(vbmeta_prop->digest, sizeof(vbmeta_prop->digest), |
224 | digest)) { | 224 | digest)) { |
225 | ERROR("Hash digest contains non-hexidecimal character: %s\n", | 225 | LERROR << "Hash digest contains non-hexidecimal character: " |
226 | digest.c_str()); | 226 | << digest.c_str(); |
227 | return false; | 227 | return false; |
228 | } | 228 | } |
229 | 229 | ||
@@ -252,7 +252,7 @@ static bool verify_vbmeta_images(const AvbSlotVerifyData &verify_data, | |||
252 | const androidboot_vbmeta &vbmeta_prop) | 252 | const androidboot_vbmeta &vbmeta_prop) |
253 | { | 253 | { |
254 | if (verify_data.num_vbmeta_images == 0) { | 254 | if (verify_data.num_vbmeta_images == 0) { |
255 | ERROR("No vbmeta images\n"); | 255 | LERROR << "No vbmeta images"; |
256 | return false; | 256 | return false; |
257 | } | 257 | } |
258 | 258 | ||
@@ -268,13 +268,13 @@ static bool verify_vbmeta_images(const AvbSlotVerifyData &verify_data, | |||
268 | } | 268 | } |
269 | 269 | ||
270 | if (total_size != vbmeta_prop.vbmeta_size) { | 270 | if (total_size != vbmeta_prop.vbmeta_size) { |
271 | ERROR("total vbmeta size mismatch: %zu (expected: %zu)\n", total_size, | 271 | LERROR << "total vbmeta size mismatch: " << total_size |
272 | vbmeta_prop.vbmeta_size); | 272 | << " (expected: " << vbmeta_prop.vbmeta_size << ")"; |
273 | return false; | 273 | return false; |
274 | } | 274 | } |
275 | 275 | ||
276 | if (!digest_matched) { | 276 | if (!digest_matched) { |
277 | ERROR("vbmeta digest mismatch\n"); | 277 | LERROR << "vbmeta digest mismatch"; |
278 | return false; | 278 | return false; |
279 | } | 279 | } |
280 | 280 | ||
@@ -326,11 +326,11 @@ static bool hashtree_load_verity_table( | |||
326 | } | 326 | } |
327 | 327 | ||
328 | if (res < 0 || (size_t)res >= bufsize) { | 328 | if (res < 0 || (size_t)res >= bufsize) { |
329 | ERROR("Error building verity table; insufficient buffer size?\n"); | 329 | LERROR << "Error building verity table; insufficient buffer size?"; |
330 | return false; | 330 | return false; |
331 | } | 331 | } |
332 | 332 | ||
333 | INFO("loading verity table: '%s'", verity_params); | 333 | LINFO << "Loading verity table: '" << verity_params << "'"; |
334 | 334 | ||
335 | // Sets ext target boundary. | 335 | // Sets ext target boundary. |
336 | verity_params += strlen(verity_params) + 1; | 336 | verity_params += strlen(verity_params) + 1; |
@@ -339,7 +339,7 @@ static bool hashtree_load_verity_table( | |||
339 | 339 | ||
340 | // Sends the ioctl to load the verity table. | 340 | // Sends the ioctl to load the verity table. |
341 | if (ioctl(fd, DM_TABLE_LOAD, io)) { | 341 | if (ioctl(fd, DM_TABLE_LOAD, io)) { |
342 | ERROR("Error loading verity table (%s)\n", strerror(errno)); | 342 | PERROR << "Error loading verity table"; |
343 | return false; | 343 | return false; |
344 | } | 344 | } |
345 | 345 | ||
@@ -354,7 +354,7 @@ static bool hashtree_dm_verity_setup(struct fstab_rec *fstab_entry, | |||
354 | // Gets the device mapper fd. | 354 | // Gets the device mapper fd. |
355 | android::base::unique_fd fd(open("/dev/device-mapper", O_RDWR)); | 355 | android::base::unique_fd fd(open("/dev/device-mapper", O_RDWR)); |
356 | if (fd < 0) { | 356 | if (fd < 0) { |
357 | ERROR("Error opening device mapper (%s)\n", strerror(errno)); | 357 | PERROR << "Error opening device mapper"; |
358 | return false; | 358 | return false; |
359 | } | 359 | } |
360 | 360 | ||
@@ -363,14 +363,14 @@ static bool hashtree_dm_verity_setup(struct fstab_rec *fstab_entry, | |||
363 | struct dm_ioctl *io = (struct dm_ioctl *)buffer; | 363 | struct dm_ioctl *io = (struct dm_ioctl *)buffer; |
364 | const std::string mount_point(basename(fstab_entry->mount_point)); | 364 | const std::string mount_point(basename(fstab_entry->mount_point)); |
365 | if (!fs_mgr_create_verity_device(io, mount_point, fd)) { | 365 | if (!fs_mgr_create_verity_device(io, mount_point, fd)) { |
366 | ERROR("Couldn't create verity device!\n"); | 366 | LERROR << "Couldn't create verity device!"; |
367 | return false; | 367 | return false; |
368 | } | 368 | } |
369 | 369 | ||
370 | // Gets the name of the device file. | 370 | // Gets the name of the device file. |
371 | std::string verity_blk_name; | 371 | std::string verity_blk_name; |
372 | if (!fs_mgr_get_verity_device_name(io, mount_point, fd, &verity_blk_name)) { | 372 | if (!fs_mgr_get_verity_device_name(io, mount_point, fd, &verity_blk_name)) { |
373 | ERROR("Couldn't get verity device number!\n"); | 373 | LERROR << "Couldn't get verity device number!"; |
374 | return false; | 374 | return false; |
375 | } | 375 | } |
376 | 376 | ||
@@ -378,7 +378,7 @@ static bool hashtree_dm_verity_setup(struct fstab_rec *fstab_entry, | |||
378 | if (!hashtree_load_verity_table(io, mount_point, fd, | 378 | if (!hashtree_load_verity_table(io, mount_point, fd, |
379 | std::string(fstab_entry->blk_device), | 379 | std::string(fstab_entry->blk_device), |
380 | hashtree_desc, salt, root_digest)) { | 380 | hashtree_desc, salt, root_digest)) { |
381 | ERROR("Couldn't load verity table!\n"); | 381 | LERROR << "Couldn't load verity table!"; |
382 | return false; | 382 | return false; |
383 | } | 383 | } |
384 | 384 | ||
@@ -432,16 +432,16 @@ static bool get_hashtree_descriptor(const std::string &partition_name, | |||
432 | verify_data.vbmeta_images[i].partition_name); | 432 | verify_data.vbmeta_images[i].partition_name); |
433 | if (vbmeta_partition_name != "vbmeta" && | 433 | if (vbmeta_partition_name != "vbmeta" && |
434 | vbmeta_partition_name != partition_name) { | 434 | vbmeta_partition_name != partition_name) { |
435 | WARNING("Skip vbmeta image at %s for partition: %s\n", | 435 | LWARNING << "Skip vbmeta image at " |
436 | verify_data.vbmeta_images[i].partition_name, | 436 | << verify_data.vbmeta_images[i].partition_name |
437 | partition_name.c_str()); | 437 | << " for partition: " << partition_name.c_str(); |
438 | continue; | 438 | continue; |
439 | } | 439 | } |
440 | 440 | ||
441 | for (size_t j = 0; j < num_descriptors && !found; j++) { | 441 | for (size_t j = 0; j < num_descriptors && !found; j++) { |
442 | AvbDescriptor desc; | 442 | AvbDescriptor desc; |
443 | if (!avb_descriptor_validate_and_byteswap(descriptors[j], &desc)) { | 443 | if (!avb_descriptor_validate_and_byteswap(descriptors[j], &desc)) { |
444 | WARNING("Descriptor is invalid.\n"); | 444 | LWARNING << "Descriptor[" << j << "] is invalid"; |
445 | continue; | 445 | continue; |
446 | } | 446 | } |
447 | if (desc.tag == AVB_DESCRIPTOR_TAG_HASHTREE) { | 447 | if (desc.tag == AVB_DESCRIPTOR_TAG_HASHTREE) { |
@@ -468,7 +468,7 @@ static bool get_hashtree_descriptor(const std::string &partition_name, | |||
468 | } | 468 | } |
469 | 469 | ||
470 | if (!found) { | 470 | if (!found) { |
471 | ERROR("Partition descriptor not found: %s\n", partition_name.c_str()); | 471 | LERROR << "Partition descriptor not found: " << partition_name.c_str(); |
472 | return false; | 472 | return false; |
473 | } | 473 | } |
474 | 474 | ||
@@ -530,7 +530,7 @@ int fs_mgr_load_vbmeta_images(struct fstab *fstab) | |||
530 | FS_MGR_CHECK(fstab != nullptr); | 530 | FS_MGR_CHECK(fstab != nullptr); |
531 | 531 | ||
532 | if (!polling_vbmeta_blk_device(fstab)) { | 532 | if (!polling_vbmeta_blk_device(fstab)) { |
533 | ERROR("Failed to find block device of /vbmeta\n"); | 533 | LERROR << "Failed to find block device of /vbmeta"; |
534 | return FS_MGR_SETUP_AVB_FAIL; | 534 | return FS_MGR_SETUP_AVB_FAIL; |
535 | } | 535 | } |
536 | 536 | ||
@@ -542,7 +542,7 @@ int fs_mgr_load_vbmeta_images(struct fstab *fstab) | |||
542 | 542 | ||
543 | fs_mgr_avb_ops = fs_mgr_dummy_avb_ops_new(fstab); | 543 | fs_mgr_avb_ops = fs_mgr_dummy_avb_ops_new(fstab); |
544 | if (fs_mgr_avb_ops == nullptr) { | 544 | if (fs_mgr_avb_ops == nullptr) { |
545 | ERROR("Failed to allocate dummy avb_ops\n"); | 545 | LERROR << "Failed to allocate dummy avb_ops"; |
546 | return FS_MGR_SETUP_AVB_FAIL; | 546 | return FS_MGR_SETUP_AVB_FAIL; |
547 | } | 547 | } |
548 | 548 | ||
@@ -562,17 +562,17 @@ int fs_mgr_load_vbmeta_images(struct fstab *fstab) | |||
562 | // - AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION (for UNLOCKED state). | 562 | // - AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION (for UNLOCKED state). |
563 | if (verify_result == AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION) { | 563 | if (verify_result == AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION) { |
564 | if (!fs_mgr_vbmeta_prop.allow_verification_error) { | 564 | if (!fs_mgr_vbmeta_prop.allow_verification_error) { |
565 | ERROR("ERROR_VERIFICATION isn't allowed\n"); | 565 | LERROR << "ERROR_VERIFICATION isn't allowed"; |
566 | goto fail; | 566 | goto fail; |
567 | } | 567 | } |
568 | } else if (verify_result != AVB_SLOT_VERIFY_RESULT_OK) { | 568 | } else if (verify_result != AVB_SLOT_VERIFY_RESULT_OK) { |
569 | ERROR("avb_slot_verify failed, result: %d\n", verify_result); | 569 | LERROR << "avb_slot_verify failed, result: " << verify_result; |
570 | goto fail; | 570 | goto fail; |
571 | } | 571 | } |
572 | 572 | ||
573 | // Verifies vbmeta images against the digest passed from bootloader. | 573 | // Verifies vbmeta images against the digest passed from bootloader. |
574 | if (!verify_vbmeta_images(*fs_mgr_avb_verify_data, fs_mgr_vbmeta_prop)) { | 574 | if (!verify_vbmeta_images(*fs_mgr_avb_verify_data, fs_mgr_vbmeta_prop)) { |
575 | ERROR("verify_vbmeta_images failed\n"); | 575 | LERROR << "verify_vbmeta_images failed"; |
576 | goto fail; | 576 | goto fail; |
577 | } else { | 577 | } else { |
578 | // Checks whether FLAGS_HASHTREE_DISABLED is set. | 578 | // Checks whether FLAGS_HASHTREE_DISABLED is set. |
@@ -619,8 +619,8 @@ int fs_mgr_setup_avb(struct fstab_rec *fstab_entry) | |||
619 | std::string partition_name(basename(fstab_entry->mount_point)); | 619 | std::string partition_name(basename(fstab_entry->mount_point)); |
620 | if (!avb_validate_utf8((const uint8_t *)partition_name.c_str(), | 620 | if (!avb_validate_utf8((const uint8_t *)partition_name.c_str(), |
621 | partition_name.length())) { | 621 | partition_name.length())) { |
622 | ERROR("Partition name: %s is not valid UTF-8.\n", | 622 | LERROR << "Partition name: " << partition_name.c_str() |
623 | partition_name.c_str()); | 623 | << " is not valid UTF-8."; |
624 | return FS_MGR_SETUP_AVB_FAIL; | 624 | return FS_MGR_SETUP_AVB_FAIL; |
625 | } | 625 | } |
626 | 626 | ||
diff --git a/fs_mgr/fs_mgr_avb_ops.cpp b/fs_mgr/fs_mgr_avb_ops.cpp index f3030eb96..7683166d8 100644 --- a/fs_mgr/fs_mgr_avb_ops.cpp +++ b/fs_mgr/fs_mgr_avb_ops.cpp | |||
@@ -66,7 +66,7 @@ static AvbIOResult read_from_partition(AvbOps *ops ATTRIBUTE_UNUSED, | |||
66 | fs_mgr_get_entry_for_mount_point(fs_mgr_fstab, "/misc"); | 66 | fs_mgr_get_entry_for_mount_point(fs_mgr_fstab, "/misc"); |
67 | 67 | ||
68 | if (fstab_entry == nullptr) { | 68 | if (fstab_entry == nullptr) { |
69 | ERROR("Partition (%s) not found in fstab\n", partition); | 69 | LERROR << "Partition (" << partition << ") not found in fstab"; |
70 | return AVB_IO_RESULT_ERROR_IO; | 70 | return AVB_IO_RESULT_ERROR_IO; |
71 | } | 71 | } |
72 | 72 | ||
@@ -83,7 +83,7 @@ static AvbIOResult read_from_partition(AvbOps *ops ATTRIBUTE_UNUSED, | |||
83 | TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY | O_CLOEXEC))); | 83 | TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY | O_CLOEXEC))); |
84 | 84 | ||
85 | if (fd < 0) { | 85 | if (fd < 0) { |
86 | ERROR("Failed to open %s (%s)\n", path.c_str(), strerror(errno)); | 86 | PERROR << "Failed to open " << path.c_str(); |
87 | return AVB_IO_RESULT_ERROR_IO; | 87 | return AVB_IO_RESULT_ERROR_IO; |
88 | } | 88 | } |
89 | 89 | ||
@@ -92,13 +92,13 @@ static AvbIOResult read_from_partition(AvbOps *ops ATTRIBUTE_UNUSED, | |||
92 | if (offset < 0) { | 92 | if (offset < 0) { |
93 | off64_t total_size = lseek64(fd, 0, SEEK_END); | 93 | off64_t total_size = lseek64(fd, 0, SEEK_END); |
94 | if (total_size == -1) { | 94 | if (total_size == -1) { |
95 | ERROR("Failed to lseek64 to end of the partition\n"); | 95 | LERROR << "Failed to lseek64 to end of the partition"; |
96 | return AVB_IO_RESULT_ERROR_IO; | 96 | return AVB_IO_RESULT_ERROR_IO; |
97 | } | 97 | } |
98 | offset = total_size + offset; | 98 | offset = total_size + offset; |
99 | // Repositions the offset to the beginning. | 99 | // Repositions the offset to the beginning. |
100 | if (lseek64(fd, 0, SEEK_SET) == -1) { | 100 | if (lseek64(fd, 0, SEEK_SET) == -1) { |
101 | ERROR("Failed to lseek64 to the beginning of the partition\n"); | 101 | LERROR << "Failed to lseek64 to the beginning of the partition"; |
102 | return AVB_IO_RESULT_ERROR_IO; | 102 | return AVB_IO_RESULT_ERROR_IO; |
103 | } | 103 | } |
104 | } | 104 | } |
@@ -109,8 +109,8 @@ static AvbIOResult read_from_partition(AvbOps *ops ATTRIBUTE_UNUSED, | |||
109 | TEMP_FAILURE_RETRY(pread64(fd, buffer, num_bytes, offset)); | 109 | TEMP_FAILURE_RETRY(pread64(fd, buffer, num_bytes, offset)); |
110 | 110 | ||
111 | if (num_read < 0 || (size_t)num_read != num_bytes) { | 111 | if (num_read < 0 || (size_t)num_read != num_bytes) { |
112 | ERROR("Failed to read %zu bytes from %s offset %" PRId64 " (%s)\n", | 112 | PERROR << "Failed to read " << num_bytes << " bytes from " |
113 | num_bytes, path.c_str(), offset, strerror(errno)); | 113 | << path.c_str() << " offset " << offset; |
114 | return AVB_IO_RESULT_ERROR_IO; | 114 | return AVB_IO_RESULT_ERROR_IO; |
115 | } | 115 | } |
116 | 116 | ||
@@ -184,7 +184,7 @@ AvbOps *fs_mgr_dummy_avb_ops_new(struct fstab *fstab) | |||
184 | 184 | ||
185 | ops = (AvbOps *)calloc(1, sizeof(AvbOps)); | 185 | ops = (AvbOps *)calloc(1, sizeof(AvbOps)); |
186 | if (ops == nullptr) { | 186 | if (ops == nullptr) { |
187 | ERROR("Error allocating memory for AvbOps.\n"); | 187 | LERROR << "Error allocating memory for AvbOps"; |
188 | return nullptr; | 188 | return nullptr; |
189 | } | 189 | } |
190 | 190 | ||
diff --git a/fs_mgr/fs_mgr_dm_ioctl.cpp b/fs_mgr/fs_mgr_dm_ioctl.cpp index 939657e54..6012a39d4 100644 --- a/fs_mgr/fs_mgr_dm_ioctl.cpp +++ b/fs_mgr/fs_mgr_dm_ioctl.cpp | |||
@@ -45,7 +45,7 @@ bool fs_mgr_create_verity_device(struct dm_ioctl *io, | |||
45 | { | 45 | { |
46 | fs_mgr_verity_ioctl_init(io, name, 1); | 46 | fs_mgr_verity_ioctl_init(io, name, 1); |
47 | if (ioctl(fd, DM_DEV_CREATE, io)) { | 47 | if (ioctl(fd, DM_DEV_CREATE, io)) { |
48 | ERROR("Error creating device mapping (%s)", strerror(errno)); | 48 | PERROR << "Error creating device mapping"; |
49 | return false; | 49 | return false; |
50 | } | 50 | } |
51 | return true; | 51 | return true; |
@@ -57,7 +57,7 @@ bool fs_mgr_destroy_verity_device(struct dm_ioctl *io, | |||
57 | { | 57 | { |
58 | fs_mgr_verity_ioctl_init(io, name, 0); | 58 | fs_mgr_verity_ioctl_init(io, name, 0); |
59 | if (ioctl(fd, DM_DEV_REMOVE, io)) { | 59 | if (ioctl(fd, DM_DEV_REMOVE, io)) { |
60 | ERROR("Error removing device mapping (%s)", strerror(errno)); | 60 | PERROR << "Error removing device mapping"; |
61 | return false; | 61 | return false; |
62 | } | 62 | } |
63 | return true; | 63 | return true; |
@@ -72,7 +72,7 @@ bool fs_mgr_get_verity_device_name(struct dm_ioctl *io, | |||
72 | 72 | ||
73 | fs_mgr_verity_ioctl_init(io, name, 0); | 73 | fs_mgr_verity_ioctl_init(io, name, 0); |
74 | if (ioctl(fd, DM_DEV_STATUS, io)) { | 74 | if (ioctl(fd, DM_DEV_STATUS, io)) { |
75 | ERROR("Error fetching verity device number (%s)", strerror(errno)); | 75 | PERROR << "Error fetching verity device number"; |
76 | return false; | 76 | return false; |
77 | } | 77 | } |
78 | 78 | ||
@@ -88,7 +88,7 @@ bool fs_mgr_resume_verity_table(struct dm_ioctl *io, | |||
88 | { | 88 | { |
89 | fs_mgr_verity_ioctl_init(io, name, 0); | 89 | fs_mgr_verity_ioctl_init(io, name, 0); |
90 | if (ioctl(fd, DM_DEV_SUSPEND, io)) { | 90 | if (ioctl(fd, DM_DEV_SUSPEND, io)) { |
91 | ERROR("Error activating verity device (%s)", strerror(errno)); | 91 | PERROR << "Error activating verity device"; |
92 | return false; | 92 | return false; |
93 | } | 93 | } |
94 | return true; | 94 | return true; |
diff --git a/fs_mgr/fs_mgr_format.cpp b/fs_mgr/fs_mgr_format.cpp index 45298b399..5705f937f 100644 --- a/fs_mgr/fs_mgr_format.cpp +++ b/fs_mgr/fs_mgr_format.cpp | |||
@@ -45,12 +45,12 @@ static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer) | |||
45 | int fd, rc = 0; | 45 | int fd, rc = 0; |
46 | 46 | ||
47 | if ((fd = open(fs_blkdev, O_WRONLY)) < 0) { | 47 | if ((fd = open(fs_blkdev, O_WRONLY)) < 0) { |
48 | ERROR("Cannot open block device. %s\n", strerror(errno)); | 48 | PERROR << "Cannot open block device"; |
49 | return -1; | 49 | return -1; |
50 | } | 50 | } |
51 | 51 | ||
52 | if ((ioctl(fd, BLKGETSIZE64, &dev_sz)) == -1) { | 52 | if ((ioctl(fd, BLKGETSIZE64, &dev_sz)) == -1) { |
53 | ERROR("Cannot get block device size. %s\n", strerror(errno)); | 53 | PERROR << "Cannot get block device size"; |
54 | close(fd); | 54 | close(fd); |
55 | return -1; | 55 | return -1; |
56 | } | 56 | } |
@@ -58,7 +58,7 @@ static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer) | |||
58 | struct selabel_handle *sehandle = selinux_android_file_context_handle(); | 58 | struct selabel_handle *sehandle = selinux_android_file_context_handle(); |
59 | if (!sehandle) { | 59 | if (!sehandle) { |
60 | /* libselinux logs specific error */ | 60 | /* libselinux logs specific error */ |
61 | ERROR("Cannot initialize android file_contexts"); | 61 | LERROR << "Cannot initialize android file_contexts"; |
62 | close(fd); | 62 | close(fd); |
63 | return -1; | 63 | return -1; |
64 | } | 64 | } |
@@ -73,7 +73,7 @@ static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer) | |||
73 | /* Use make_ext4fs_internal to avoid wiping an already-wiped partition. */ | 73 | /* Use make_ext4fs_internal to avoid wiping an already-wiped partition. */ |
74 | rc = make_ext4fs_internal(fd, NULL, NULL, fs_mnt_point, 0, 0, 0, 0, 0, 0, sehandle, 0, 0, NULL, NULL, NULL); | 74 | rc = make_ext4fs_internal(fd, NULL, NULL, fs_mnt_point, 0, 0, 0, 0, 0, 0, sehandle, 0, 0, NULL, NULL, NULL); |
75 | if (rc) { | 75 | if (rc) { |
76 | ERROR("make_ext4fs returned %d.\n", rc); | 76 | LERROR << "make_ext4fs returned " << rc; |
77 | } | 77 | } |
78 | close(fd); | 78 | close(fd); |
79 | 79 | ||
@@ -106,19 +106,19 @@ static int format_f2fs(char *fs_blkdev) | |||
106 | for(;;) { | 106 | for(;;) { |
107 | pid_t p = waitpid(pid, &rc, 0); | 107 | pid_t p = waitpid(pid, &rc, 0); |
108 | if (p != pid) { | 108 | if (p != pid) { |
109 | ERROR("Error waiting for child process - %d\n", p); | 109 | LERROR << "Error waiting for child process - " << p; |
110 | rc = -1; | 110 | rc = -1; |
111 | break; | 111 | break; |
112 | } | 112 | } |
113 | if (WIFEXITED(rc)) { | 113 | if (WIFEXITED(rc)) { |
114 | rc = WEXITSTATUS(rc); | 114 | rc = WEXITSTATUS(rc); |
115 | INFO("%s done, status %d\n", args[0], rc); | 115 | LINFO << args[0] << " done, status " << rc; |
116 | if (rc) { | 116 | if (rc) { |
117 | rc = -1; | 117 | rc = -1; |
118 | } | 118 | } |
119 | break; | 119 | break; |
120 | } | 120 | } |
121 | ERROR("Still waiting for %s...\n", args[0]); | 121 | LERROR << "Still waiting for " << args[0] << "..."; |
122 | } | 122 | } |
123 | 123 | ||
124 | return rc; | 124 | return rc; |
@@ -128,14 +128,15 @@ int fs_mgr_do_format(struct fstab_rec *fstab, bool crypt_footer) | |||
128 | { | 128 | { |
129 | int rc = -EINVAL; | 129 | int rc = -EINVAL; |
130 | 130 | ||
131 | ERROR("%s: Format %s as '%s'.\n", __func__, fstab->blk_device, fstab->fs_type); | 131 | LERROR << __FUNCTION__ << ": Format " << fstab->blk_device |
132 | << " as '" << fstab->fs_type << "'"; | ||
132 | 133 | ||
133 | if (!strncmp(fstab->fs_type, "f2fs", 4)) { | 134 | if (!strncmp(fstab->fs_type, "f2fs", 4)) { |
134 | rc = format_f2fs(fstab->blk_device); | 135 | rc = format_f2fs(fstab->blk_device); |
135 | } else if (!strncmp(fstab->fs_type, "ext4", 4)) { | 136 | } else if (!strncmp(fstab->fs_type, "ext4", 4)) { |
136 | rc = format_ext4(fstab->blk_device, fstab->mount_point, crypt_footer); | 137 | rc = format_ext4(fstab->blk_device, fstab->mount_point, crypt_footer); |
137 | } else { | 138 | } else { |
138 | ERROR("File system type '%s' is not supported\n", fstab->fs_type); | 139 | LERROR << "File system type '" << fstab->fs_type << "' is not supported"; |
139 | } | 140 | } |
140 | 141 | ||
141 | return rc; | 142 | return rc; |
diff --git a/fs_mgr/fs_mgr_fstab.cpp b/fs_mgr/fs_mgr_fstab.cpp index 23059dff3..48ddf29e8 100644 --- a/fs_mgr/fs_mgr_fstab.cpp +++ b/fs_mgr/fs_mgr_fstab.cpp | |||
@@ -196,7 +196,7 @@ static int parse_flags(char *flags, struct flag_list *fl, | |||
196 | } | 196 | } |
197 | } | 197 | } |
198 | if (flag_vals->file_encryption_mode == 0) { | 198 | if (flag_vals->file_encryption_mode == 0) { |
199 | ERROR("Unknown file encryption mode: %s\n", mode); | 199 | LERROR << "Unknown file encryption mode: " << mode; |
200 | } | 200 | } |
201 | } else if ((fl[i].flag == MF_LENGTH) && flag_vals) { | 201 | } else if ((fl[i].flag == MF_LENGTH) && flag_vals) { |
202 | /* The length flag is followed by an = and the | 202 | /* The length flag is followed by an = and the |
@@ -226,7 +226,7 @@ static int parse_flags(char *flags, struct flag_list *fl, | |||
226 | flag_vals->partnum = strtol(part_start, NULL, 0); | 226 | flag_vals->partnum = strtol(part_start, NULL, 0); |
227 | } | 227 | } |
228 | } else { | 228 | } else { |
229 | ERROR("Warning: voldmanaged= flag malformed\n"); | 229 | LERROR << "Warning: voldmanaged= flag malformed"; |
230 | } | 230 | } |
231 | } else if ((fl[i].flag == MF_SWAPPRIO) && flag_vals) { | 231 | } else if ((fl[i].flag == MF_SWAPPRIO) && flag_vals) { |
232 | flag_vals->swap_prio = strtoll(strchr(p, '=') + 1, NULL, 0); | 232 | flag_vals->swap_prio = strtoll(strchr(p, '=') + 1, NULL, 0); |
@@ -276,7 +276,7 @@ static int parse_flags(char *flags, struct flag_list *fl, | |||
276 | /* fs_options was not passed in, so if the flag is unknown | 276 | /* fs_options was not passed in, so if the flag is unknown |
277 | * it's an error. | 277 | * it's an error. |
278 | */ | 278 | */ |
279 | ERROR("Warning: unknown flag %s\n", p); | 279 | LERROR << "Warning: unknown flag " << p; |
280 | } | 280 | } |
281 | } | 281 | } |
282 | p = strtok_r(NULL, ",", &savep); | 282 | p = strtok_r(NULL, ",", &savep); |
@@ -321,7 +321,7 @@ struct fstab *fs_mgr_read_fstab_file(FILE *fstab_file) | |||
321 | } | 321 | } |
322 | 322 | ||
323 | if (!entries) { | 323 | if (!entries) { |
324 | ERROR("No entries found in fstab\n"); | 324 | LERROR << "No entries found in fstab"; |
325 | goto err; | 325 | goto err; |
326 | } | 326 | } |
327 | 327 | ||
@@ -354,30 +354,30 @@ struct fstab *fs_mgr_read_fstab_file(FILE *fstab_file) | |||
354 | * between the two reads. | 354 | * between the two reads. |
355 | */ | 355 | */ |
356 | if (cnt >= entries) { | 356 | if (cnt >= entries) { |
357 | ERROR("Tried to process more entries than counted\n"); | 357 | LERROR << "Tried to process more entries than counted"; |
358 | break; | 358 | break; |
359 | } | 359 | } |
360 | 360 | ||
361 | if (!(p = strtok_r(line, delim, &save_ptr))) { | 361 | if (!(p = strtok_r(line, delim, &save_ptr))) { |
362 | ERROR("Error parsing mount source\n"); | 362 | LERROR << "Error parsing mount source"; |
363 | goto err; | 363 | goto err; |
364 | } | 364 | } |
365 | fstab->recs[cnt].blk_device = strdup(p); | 365 | fstab->recs[cnt].blk_device = strdup(p); |
366 | 366 | ||
367 | if (!(p = strtok_r(NULL, delim, &save_ptr))) { | 367 | if (!(p = strtok_r(NULL, delim, &save_ptr))) { |
368 | ERROR("Error parsing mount_point\n"); | 368 | LERROR << "Error parsing mount_point"; |
369 | goto err; | 369 | goto err; |
370 | } | 370 | } |
371 | fstab->recs[cnt].mount_point = strdup(p); | 371 | fstab->recs[cnt].mount_point = strdup(p); |
372 | 372 | ||
373 | if (!(p = strtok_r(NULL, delim, &save_ptr))) { | 373 | if (!(p = strtok_r(NULL, delim, &save_ptr))) { |
374 | ERROR("Error parsing fs_type\n"); | 374 | LERROR << "Error parsing fs_type"; |
375 | goto err; | 375 | goto err; |
376 | } | 376 | } |
377 | fstab->recs[cnt].fs_type = strdup(p); | 377 | fstab->recs[cnt].fs_type = strdup(p); |
378 | 378 | ||
379 | if (!(p = strtok_r(NULL, delim, &save_ptr))) { | 379 | if (!(p = strtok_r(NULL, delim, &save_ptr))) { |
380 | ERROR("Error parsing mount_flags\n"); | 380 | LERROR << "Error parsing mount_flags"; |
381 | goto err; | 381 | goto err; |
382 | } | 382 | } |
383 | tmp_fs_options[0] = '\0'; | 383 | tmp_fs_options[0] = '\0'; |
@@ -392,7 +392,7 @@ struct fstab *fs_mgr_read_fstab_file(FILE *fstab_file) | |||
392 | } | 392 | } |
393 | 393 | ||
394 | if (!(p = strtok_r(NULL, delim, &save_ptr))) { | 394 | if (!(p = strtok_r(NULL, delim, &save_ptr))) { |
395 | ERROR("Error parsing fs_mgr_options\n"); | 395 | LERROR << "Error parsing fs_mgr_options"; |
396 | goto err; | 396 | goto err; |
397 | } | 397 | } |
398 | fstab->recs[cnt].fs_mgr_flags = parse_flags(p, fs_mgr_flags, | 398 | fstab->recs[cnt].fs_mgr_flags = parse_flags(p, fs_mgr_flags, |
@@ -413,7 +413,7 @@ struct fstab *fs_mgr_read_fstab_file(FILE *fstab_file) | |||
413 | } | 413 | } |
414 | /* If an A/B partition, modify block device to be the real block device */ | 414 | /* If an A/B partition, modify block device to be the real block device */ |
415 | if (fs_mgr_update_for_slotselect(fstab) != 0) { | 415 | if (fs_mgr_update_for_slotselect(fstab) != 0) { |
416 | ERROR("Error updating for slotselect\n"); | 416 | LERROR << "Error updating for slotselect"; |
417 | goto err; | 417 | goto err; |
418 | } | 418 | } |
419 | free(line); | 419 | free(line); |
@@ -433,7 +433,7 @@ struct fstab *fs_mgr_read_fstab(const char *fstab_path) | |||
433 | 433 | ||
434 | fstab_file = fopen(fstab_path, "r"); | 434 | fstab_file = fopen(fstab_path, "r"); |
435 | if (!fstab_file) { | 435 | if (!fstab_file) { |
436 | ERROR("Cannot open file %s\n", fstab_path); | 436 | LERROR << "Cannot open file " << fstab_path; |
437 | return NULL; | 437 | return NULL; |
438 | } | 438 | } |
439 | fstab = fs_mgr_read_fstab_file(fstab_file); | 439 | fstab = fs_mgr_read_fstab_file(fstab_file); |
diff --git a/fs_mgr/fs_mgr_main.cpp b/fs_mgr/fs_mgr_main.cpp index f2901f325..f3919d9d9 100644 --- a/fs_mgr/fs_mgr_main.cpp +++ b/fs_mgr/fs_mgr_main.cpp | |||
@@ -27,7 +27,8 @@ char *me = nullptr; | |||
27 | 27 | ||
28 | static void usage(void) | 28 | static void usage(void) |
29 | { | 29 | { |
30 | ERROR("%s: usage: %s <-a | -n mnt_point blk_dev | -u> <fstab_file>\n", me, me); | 30 | LERROR << me << ": usage: " << me |
31 | << " <-a | -n mnt_point blk_dev | -u> <fstab_file>"; | ||
31 | exit(1); | 32 | exit(1); |
32 | } | 33 | } |
33 | 34 | ||
@@ -88,7 +89,9 @@ int main(int argc, char * const argv[]) | |||
88 | const char *fstab_file=NULL; | 89 | const char *fstab_file=NULL; |
89 | struct fstab *fstab=NULL; | 90 | struct fstab *fstab=NULL; |
90 | 91 | ||
91 | klog_set_level(6); | 92 | setenv("ANDROID_LOG_TAGS", "*:i", 1); // Set log level to INFO |
93 | android::base::InitLogging( | ||
94 | const_cast<char **>(argv), &android::base::KernelLogger); | ||
92 | 95 | ||
93 | parse_options(argc, argv, &a_flag, &u_flag, &n_flag, &n_name, &n_blk_dev); | 96 | parse_options(argc, argv, &a_flag, &u_flag, &n_flag, &n_name, &n_blk_dev); |
94 | 97 | ||
@@ -104,7 +107,7 @@ int main(int argc, char * const argv[]) | |||
104 | } else if (u_flag) { | 107 | } else if (u_flag) { |
105 | return fs_mgr_unmount_all(fstab); | 108 | return fs_mgr_unmount_all(fstab); |
106 | } else { | 109 | } else { |
107 | ERROR("%s: Internal error, unknown option\n", me); | 110 | LERROR << me << ": Internal error, unknown option"; |
108 | exit(1); | 111 | exit(1); |
109 | } | 112 | } |
110 | 113 | ||
diff --git a/fs_mgr/fs_mgr_priv.h b/fs_mgr/fs_mgr_priv.h index 0a27c7a3f..79c27c425 100644 --- a/fs_mgr/fs_mgr_priv.h +++ b/fs_mgr/fs_mgr_priv.h | |||
@@ -17,11 +17,9 @@ | |||
17 | #ifndef __CORE_FS_MGR_PRIV_H | 17 | #ifndef __CORE_FS_MGR_PRIV_H |
18 | #define __CORE_FS_MGR_PRIV_H | 18 | #define __CORE_FS_MGR_PRIV_H |
19 | 19 | ||
20 | #include <cutils/klog.h> | 20 | #include <android-base/logging.h> |
21 | #include <fs_mgr.h> | 21 | #include <fs_mgr.h> |
22 | 22 | ||
23 | #ifdef __cplusplus | ||
24 | #include <android-base/logging.h> | ||
25 | /* The CHECK() in logging.h will use program invocation name as the tag. | 23 | /* The CHECK() in logging.h will use program invocation name as the tag. |
26 | * Thus, the log will have prefix "init: " when libfs_mgr is statically | 24 | * Thus, the log will have prefix "init: " when libfs_mgr is statically |
27 | * linked in the init process. This might be opaque when debugging. | 25 | * linked in the init process. This might be opaque when debugging. |
@@ -29,13 +27,20 @@ | |||
29 | * indicate the check happens in fs_mgr. | 27 | * indicate the check happens in fs_mgr. |
30 | */ | 28 | */ |
31 | #define FS_MGR_CHECK(x) CHECK(x) << "in libfs_mgr " | 29 | #define FS_MGR_CHECK(x) CHECK(x) << "in libfs_mgr " |
32 | #endif | ||
33 | 30 | ||
34 | __BEGIN_DECLS | 31 | #define FS_MGR_TAG "[libfs_mgr]" |
35 | 32 | ||
36 | #define INFO(x...) KLOG_INFO("fs_mgr", x) | 33 | // Logs a message to kernel |
37 | #define WARNING(x...) KLOG_WARNING("fs_mgr", x) | 34 | #define LINFO LOG(INFO) << FS_MGR_TAG |
38 | #define ERROR(x...) KLOG_ERROR("fs_mgr", x) | 35 | #define LWARNING LOG(WARNING) << FS_MGR_TAG |
36 | #define LERROR LOG(ERROR) << FS_MGR_TAG | ||
37 | |||
38 | // Logs a message with strerror(errno) at the end | ||
39 | #define PINFO PLOG(INFO) << FS_MGR_TAG | ||
40 | #define PWARNING PLOG(WARNING) << FS_MGR_TAG | ||
41 | #define PERROR PLOG(ERROR) << FS_MGR_TAG | ||
42 | |||
43 | __BEGIN_DECLS | ||
39 | 44 | ||
40 | #define CRYPTO_TMPFS_OPTIONS "size=256m,mode=0771,uid=1000,gid=1000" | 45 | #define CRYPTO_TMPFS_OPTIONS "size=256m,mode=0771,uid=1000,gid=1000" |
41 | 46 | ||
diff --git a/fs_mgr/fs_mgr_slotselect.cpp b/fs_mgr/fs_mgr_slotselect.cpp index 0f59115f3..94b43e4f8 100644 --- a/fs_mgr/fs_mgr_slotselect.cpp +++ b/fs_mgr/fs_mgr_slotselect.cpp | |||
@@ -48,9 +48,8 @@ static int get_active_slot_suffix_from_misc(struct fstab *fstab, | |||
48 | if (strcmp(fstab->recs[n].mount_point, "/misc") == 0) { | 48 | if (strcmp(fstab->recs[n].mount_point, "/misc") == 0) { |
49 | misc_fd = open(fstab->recs[n].blk_device, O_RDONLY); | 49 | misc_fd = open(fstab->recs[n].blk_device, O_RDONLY); |
50 | if (misc_fd == -1) { | 50 | if (misc_fd == -1) { |
51 | ERROR("Error opening misc partition \"%s\" (%s)\n", | 51 | PERROR << "Error opening misc partition '" |
52 | fstab->recs[n].blk_device, | 52 | << fstab->recs[n].blk_device << "'"; |
53 | strerror(errno)); | ||
54 | return -1; | 53 | return -1; |
55 | } else { | 54 | } else { |
56 | break; | 55 | break; |
@@ -59,7 +58,7 @@ static int get_active_slot_suffix_from_misc(struct fstab *fstab, | |||
59 | } | 58 | } |
60 | 59 | ||
61 | if (misc_fd == -1) { | 60 | if (misc_fd == -1) { |
62 | ERROR("Error finding misc partition\n"); | 61 | LERROR << "Error finding misc partition"; |
63 | return -1; | 62 | return -1; |
64 | } | 63 | } |
65 | 64 | ||
@@ -67,7 +66,7 @@ static int get_active_slot_suffix_from_misc(struct fstab *fstab, | |||
67 | // Linux will never return partial reads when reading from block | 66 | // Linux will never return partial reads when reading from block |
68 | // devices so no need to worry about them. | 67 | // devices so no need to worry about them. |
69 | if (num_read != sizeof(msg)) { | 68 | if (num_read != sizeof(msg)) { |
70 | ERROR("Error reading bootloader_message (%s)\n", strerror(errno)); | 69 | PERROR << "Error reading bootloader_message"; |
71 | close(misc_fd); | 70 | close(misc_fd); |
72 | return -1; | 71 | return -1; |
73 | } | 72 | } |
@@ -98,11 +97,11 @@ static int get_active_slot_suffix(struct fstab *fstab, char *out_suffix, | |||
98 | // If we couldn't get the suffix from the kernel cmdline, try the | 97 | // If we couldn't get the suffix from the kernel cmdline, try the |
99 | // the misc partition. | 98 | // the misc partition. |
100 | if (get_active_slot_suffix_from_misc(fstab, out_suffix, suffix_len) == 0) { | 99 | if (get_active_slot_suffix_from_misc(fstab, out_suffix, suffix_len) == 0) { |
101 | INFO("Using slot suffix \"%s\" from misc\n", out_suffix); | 100 | LINFO << "Using slot suffix '" << out_suffix << "' from misc"; |
102 | return 0; | 101 | return 0; |
103 | } | 102 | } |
104 | 103 | ||
105 | ERROR("Error determining slot_suffix\n"); | 104 | LERROR << "Error determining slot_suffix"; |
106 | 105 | ||
107 | return -1; | 106 | return -1; |
108 | } | 107 | } |
diff --git a/fs_mgr/fs_mgr_verity.cpp b/fs_mgr/fs_mgr_verity.cpp index f6a14da3d..1ec454072 100644 --- a/fs_mgr/fs_mgr_verity.cpp +++ b/fs_mgr/fs_mgr_verity.cpp | |||
@@ -94,12 +94,12 @@ static RSA *load_key(const char *path) | |||
94 | 94 | ||
95 | FILE* f = fopen(path, "r"); | 95 | FILE* f = fopen(path, "r"); |
96 | if (!f) { | 96 | if (!f) { |
97 | ERROR("Can't open '%s'\n", path); | 97 | LERROR << "Can't open " << path; |
98 | return NULL; | 98 | return NULL; |
99 | } | 99 | } |
100 | 100 | ||
101 | if (!fread(key_data, sizeof(key_data), 1, f)) { | 101 | if (!fread(key_data, sizeof(key_data), 1, f)) { |
102 | ERROR("Could not read key!\n"); | 102 | LERROR << "Could not read key!"; |
103 | fclose(f); | 103 | fclose(f); |
104 | return NULL; | 104 | return NULL; |
105 | } | 105 | } |
@@ -108,7 +108,7 @@ static RSA *load_key(const char *path) | |||
108 | 108 | ||
109 | RSA* key = NULL; | 109 | RSA* key = NULL; |
110 | if (!android_pubkey_decode(key_data, sizeof(key_data), &key)) { | 110 | if (!android_pubkey_decode(key_data, sizeof(key_data), &key)) { |
111 | ERROR("Could not parse key!\n"); | 111 | LERROR << "Could not parse key!"; |
112 | return NULL; | 112 | return NULL; |
113 | } | 113 | } |
114 | 114 | ||
@@ -128,14 +128,14 @@ static int verify_table(const uint8_t *signature, size_t signature_size, | |||
128 | // Now get the public key from the keyfile | 128 | // Now get the public key from the keyfile |
129 | key = load_key(VERITY_TABLE_RSA_KEY); | 129 | key = load_key(VERITY_TABLE_RSA_KEY); |
130 | if (!key) { | 130 | if (!key) { |
131 | ERROR("Couldn't load verity keys\n"); | 131 | LERROR << "Couldn't load verity keys"; |
132 | goto out; | 132 | goto out; |
133 | } | 133 | } |
134 | 134 | ||
135 | // verify the result | 135 | // verify the result |
136 | if (!RSA_verify(NID_sha256, hash_buf, sizeof(hash_buf), signature, | 136 | if (!RSA_verify(NID_sha256, hash_buf, sizeof(hash_buf), signature, |
137 | signature_size, key)) { | 137 | signature_size, key)) { |
138 | ERROR("Couldn't verify table\n"); | 138 | LERROR << "Couldn't verify table"; |
139 | goto out; | 139 | goto out; |
140 | } | 140 | } |
141 | 141 | ||
@@ -227,7 +227,7 @@ static bool format_verity_table(char *buf, const size_t bufsize, | |||
227 | } | 227 | } |
228 | 228 | ||
229 | if (res < 0 || (size_t)res >= bufsize) { | 229 | if (res < 0 || (size_t)res >= bufsize) { |
230 | ERROR("Error building verity table; insufficient buffer size?\n"); | 230 | LERROR << "Error building verity table; insufficient buffer size?"; |
231 | return false; | 231 | return false; |
232 | } | 232 | } |
233 | 233 | ||
@@ -246,7 +246,7 @@ static bool format_legacy_verity_table(char *buf, const size_t bufsize, | |||
246 | } | 246 | } |
247 | 247 | ||
248 | if (res < 0 || (size_t)res >= bufsize) { | 248 | if (res < 0 || (size_t)res >= bufsize) { |
249 | ERROR("Error building verity table; insufficient buffer size?\n"); | 249 | LERROR << "Error building verity table; insufficient buffer size?"; |
250 | return false; | 250 | return false; |
251 | } | 251 | } |
252 | 252 | ||
@@ -277,11 +277,11 @@ static int load_verity_table(struct dm_ioctl *io, const std::string &name, | |||
277 | bufsize = DM_BUF_SIZE - (verity_params - buffer); | 277 | bufsize = DM_BUF_SIZE - (verity_params - buffer); |
278 | 278 | ||
279 | if (!format(verity_params, bufsize, params)) { | 279 | if (!format(verity_params, bufsize, params)) { |
280 | ERROR("Failed to format verity parameters\n"); | 280 | LERROR << "Failed to format verity parameters"; |
281 | return -1; | 281 | return -1; |
282 | } | 282 | } |
283 | 283 | ||
284 | INFO("loading verity table: '%s'", verity_params); | 284 | LINFO << "loading verity table: '" << verity_params << "'"; |
285 | 285 | ||
286 | // set next target boundary | 286 | // set next target boundary |
287 | verity_params += strlen(verity_params) + 1; | 287 | verity_params += strlen(verity_params) + 1; |
@@ -290,7 +290,7 @@ static int load_verity_table(struct dm_ioctl *io, const std::string &name, | |||
290 | 290 | ||
291 | // send the ioctl to load the verity table | 291 | // send the ioctl to load the verity table |
292 | if (ioctl(fd, DM_TABLE_LOAD, io)) { | 292 | if (ioctl(fd, DM_TABLE_LOAD, io)) { |
293 | ERROR("Error loading verity table (%s)\n", strerror(errno)); | 293 | PERROR << "Error loading verity table"; |
294 | return -1; | 294 | return -1; |
295 | } | 295 | } |
296 | 296 | ||
@@ -309,13 +309,13 @@ static int check_verity_restart(const char *fname) | |||
309 | 309 | ||
310 | if (fd == -1) { | 310 | if (fd == -1) { |
311 | if (errno != ENOENT) { | 311 | if (errno != ENOENT) { |
312 | ERROR("Failed to open %s (%s)\n", fname, strerror(errno)); | 312 | PERROR << "Failed to open " << fname; |
313 | } | 313 | } |
314 | goto out; | 314 | goto out; |
315 | } | 315 | } |
316 | 316 | ||
317 | if (fstat(fd, &s) == -1) { | 317 | if (fstat(fd, &s) == -1) { |
318 | ERROR("Failed to fstat %s (%s)\n", fname, strerror(errno)); | 318 | PERROR << "Failed to fstat " << fname; |
319 | goto out; | 319 | goto out; |
320 | } | 320 | } |
321 | 321 | ||
@@ -326,14 +326,12 @@ static int check_verity_restart(const char *fname) | |||
326 | } | 326 | } |
327 | 327 | ||
328 | if (lseek(fd, s.st_size - size, SEEK_SET) == -1) { | 328 | if (lseek(fd, s.st_size - size, SEEK_SET) == -1) { |
329 | ERROR("Failed to lseek %jd %s (%s)\n", (intmax_t)(s.st_size - size), fname, | 329 | PERROR << "Failed to lseek " << (intmax_t)(s.st_size - size) << " " << fname; |
330 | strerror(errno)); | ||
331 | goto out; | 330 | goto out; |
332 | } | 331 | } |
333 | 332 | ||
334 | if (!android::base::ReadFully(fd, buffer, size)) { | 333 | if (!android::base::ReadFully(fd, buffer, size)) { |
335 | ERROR("Failed to read %zd bytes from %s (%s)\n", size, fname, | 334 | PERROR << "Failed to read " << size << " bytes from " << fname; |
336 | strerror(errno)); | ||
337 | goto out; | 335 | goto out; |
338 | } | 336 | } |
339 | 337 | ||
@@ -405,14 +403,14 @@ static int metadata_find(const char *fname, const char *stag, | |||
405 | fp = fopen(fname, "r+"); | 403 | fp = fopen(fname, "r+"); |
406 | 404 | ||
407 | if (!fp) { | 405 | if (!fp) { |
408 | ERROR("Failed to open %s (%s)\n", fname, strerror(errno)); | 406 | PERROR << "Failed to open " << fname; |
409 | goto out; | 407 | goto out; |
410 | } | 408 | } |
411 | 409 | ||
412 | /* check magic */ | 410 | /* check magic */ |
413 | if (fseek(fp, start, SEEK_SET) < 0 || | 411 | if (fseek(fp, start, SEEK_SET) < 0 || |
414 | fread(&magic, sizeof(magic), 1, fp) != 1) { | 412 | fread(&magic, sizeof(magic), 1, fp) != 1) { |
415 | ERROR("Failed to read magic from %s (%s)\n", fname, strerror(errno)); | 413 | PERROR << "Failed to read magic from " << fname; |
416 | goto out; | 414 | goto out; |
417 | } | 415 | } |
418 | 416 | ||
@@ -421,13 +419,13 @@ static int metadata_find(const char *fname, const char *stag, | |||
421 | 419 | ||
422 | if (fseek(fp, start, SEEK_SET) < 0 || | 420 | if (fseek(fp, start, SEEK_SET) < 0 || |
423 | fwrite(&magic, sizeof(magic), 1, fp) != 1) { | 421 | fwrite(&magic, sizeof(magic), 1, fp) != 1) { |
424 | ERROR("Failed to write magic to %s (%s)\n", fname, strerror(errno)); | 422 | PERROR << "Failed to write magic to " << fname; |
425 | goto out; | 423 | goto out; |
426 | } | 424 | } |
427 | 425 | ||
428 | rc = metadata_add(fp, start + sizeof(magic), stag, slength, offset); | 426 | rc = metadata_add(fp, start + sizeof(magic), stag, slength, offset); |
429 | if (rc < 0) { | 427 | if (rc < 0) { |
430 | ERROR("Failed to add metadata to %s: %s\n", fname, strerror(errno)); | 428 | PERROR << "Failed to add metadata to " << fname; |
431 | } | 429 | } |
432 | 430 | ||
433 | goto out; | 431 | goto out; |
@@ -452,14 +450,13 @@ static int metadata_find(const char *fname, const char *stag, | |||
452 | start += length; | 450 | start += length; |
453 | 451 | ||
454 | if (fseek(fp, length, SEEK_CUR) < 0) { | 452 | if (fseek(fp, length, SEEK_CUR) < 0) { |
455 | ERROR("Failed to seek %s (%s)\n", fname, strerror(errno)); | 453 | PERROR << "Failed to seek " << fname; |
456 | goto out; | 454 | goto out; |
457 | } | 455 | } |
458 | } else { | 456 | } else { |
459 | rc = metadata_add(fp, start, stag, slength, offset); | 457 | rc = metadata_add(fp, start, stag, slength, offset); |
460 | if (rc < 0) { | 458 | if (rc < 0) { |
461 | ERROR("Failed to write metadata to %s: %s\n", fname, | 459 | PERROR << "Failed to write metadata to " << fname; |
462 | strerror(errno)); | ||
463 | } | 460 | } |
464 | goto out; | 461 | goto out; |
465 | } | 462 | } |
@@ -483,13 +480,13 @@ static int write_verity_state(const char *fname, off64_t offset, int32_t mode) | |||
483 | fd = TEMP_FAILURE_RETRY(open(fname, O_WRONLY | O_SYNC | O_CLOEXEC)); | 480 | fd = TEMP_FAILURE_RETRY(open(fname, O_WRONLY | O_SYNC | O_CLOEXEC)); |
484 | 481 | ||
485 | if (fd == -1) { | 482 | if (fd == -1) { |
486 | ERROR("Failed to open %s (%s)\n", fname, strerror(errno)); | 483 | PERROR << "Failed to open " << fname; |
487 | goto out; | 484 | goto out; |
488 | } | 485 | } |
489 | 486 | ||
490 | if (TEMP_FAILURE_RETRY(pwrite64(fd, &s, sizeof(s), offset)) != sizeof(s)) { | 487 | if (TEMP_FAILURE_RETRY(pwrite64(fd, &s, sizeof(s), offset)) != sizeof(s)) { |
491 | ERROR("Failed to write %zu bytes to %s to offset %" PRIu64 " (%s)\n", | 488 | PERROR << "Failed to write " << sizeof(s) << " bytes to " << fname |
492 | sizeof(s), fname, offset, strerror(errno)); | 489 | << " to offset " << offset; |
493 | goto out; | 490 | goto out; |
494 | } | 491 | } |
495 | 492 | ||
@@ -512,13 +509,13 @@ static int read_verity_state(const char *fname, off64_t offset, int *mode) | |||
512 | fd = TEMP_FAILURE_RETRY(open(fname, O_RDONLY | O_CLOEXEC)); | 509 | fd = TEMP_FAILURE_RETRY(open(fname, O_RDONLY | O_CLOEXEC)); |
513 | 510 | ||
514 | if (fd == -1) { | 511 | if (fd == -1) { |
515 | ERROR("Failed to open %s (%s)\n", fname, strerror(errno)); | 512 | PERROR << "Failed to open " << fname; |
516 | goto out; | 513 | goto out; |
517 | } | 514 | } |
518 | 515 | ||
519 | if (TEMP_FAILURE_RETRY(pread64(fd, &s, sizeof(s), offset)) != sizeof(s)) { | 516 | if (TEMP_FAILURE_RETRY(pread64(fd, &s, sizeof(s), offset)) != sizeof(s)) { |
520 | ERROR("Failed to read %zu bytes from %s offset %" PRIu64 " (%s)\n", | 517 | PERROR << "Failed to read " << sizeof(s) << " bytes from " << fname |
521 | sizeof(s), fname, offset, strerror(errno)); | 518 | << " offset " << offset; |
522 | goto out; | 519 | goto out; |
523 | } | 520 | } |
524 | 521 | ||
@@ -530,13 +527,13 @@ static int read_verity_state(const char *fname, off64_t offset, int *mode) | |||
530 | } | 527 | } |
531 | 528 | ||
532 | if (s.version != VERITY_STATE_VERSION) { | 529 | if (s.version != VERITY_STATE_VERSION) { |
533 | ERROR("Unsupported verity state version (%u)\n", s.version); | 530 | LERROR << "Unsupported verity state version (" << s.version << ")"; |
534 | goto out; | 531 | goto out; |
535 | } | 532 | } |
536 | 533 | ||
537 | if (s.mode < VERITY_MODE_EIO || | 534 | if (s.mode < VERITY_MODE_EIO || |
538 | s.mode > VERITY_MODE_LAST) { | 535 | s.mode > VERITY_MODE_LAST) { |
539 | ERROR("Unsupported verity mode (%u)\n", s.mode); | 536 | LERROR << "Unsupported verity mode (" << s.mode << ")"; |
540 | goto out; | 537 | goto out; |
541 | } | 538 | } |
542 | 539 | ||
@@ -558,15 +555,14 @@ static int read_partition(const char *path, uint64_t size) | |||
558 | android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC))); | 555 | android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC))); |
559 | 556 | ||
560 | if (fd == -1) { | 557 | if (fd == -1) { |
561 | ERROR("Failed to open %s: %s\n", path, strerror(errno)); | 558 | PERROR << "Failed to open " << path; |
562 | return -errno; | 559 | return -errno; |
563 | } | 560 | } |
564 | 561 | ||
565 | while (size) { | 562 | while (size) { |
566 | size_read = TEMP_FAILURE_RETRY(read(fd, buf, READ_BUF_SIZE)); | 563 | size_read = TEMP_FAILURE_RETRY(read(fd, buf, READ_BUF_SIZE)); |
567 | if (size_read == -1) { | 564 | if (size_read == -1) { |
568 | ERROR("Error in reading partition %s: %s\n", path, | 565 | PERROR << "Error in reading partition " << path; |
569 | strerror(errno)); | ||
570 | return -errno; | 566 | return -errno; |
571 | } | 567 | } |
572 | size -= size_read; | 568 | size -= size_read; |
@@ -590,15 +586,13 @@ static int compare_last_signature(struct fstab_rec *fstab, int *match) | |||
590 | 586 | ||
591 | if (fec_open(&f, fstab->blk_device, O_RDONLY, FEC_VERITY_DISABLE, | 587 | if (fec_open(&f, fstab->blk_device, O_RDONLY, FEC_VERITY_DISABLE, |
592 | FEC_DEFAULT_ROOTS) == -1) { | 588 | FEC_DEFAULT_ROOTS) == -1) { |
593 | ERROR("Failed to open '%s' (%s)\n", fstab->blk_device, | 589 | PERROR << "Failed to open '" << fstab->blk_device << "'"; |
594 | strerror(errno)); | ||
595 | return rc; | 590 | return rc; |
596 | } | 591 | } |
597 | 592 | ||
598 | // read verity metadata | 593 | // read verity metadata |
599 | if (fec_verity_get_metadata(f, &verity) == -1) { | 594 | if (fec_verity_get_metadata(f, &verity) == -1) { |
600 | ERROR("Failed to get verity metadata '%s' (%s)\n", fstab->blk_device, | 595 | PERROR << "Failed to get verity metadata '" << fstab->blk_device << "'"; |
601 | strerror(errno)); | ||
602 | goto out; | 596 | goto out; |
603 | } | 597 | } |
604 | 598 | ||
@@ -606,7 +600,7 @@ static int compare_last_signature(struct fstab_rec *fstab, int *match) | |||
606 | 600 | ||
607 | if (snprintf(tag, sizeof(tag), VERITY_LASTSIG_TAG "_%s", | 601 | if (snprintf(tag, sizeof(tag), VERITY_LASTSIG_TAG "_%s", |
608 | basename(fstab->mount_point)) >= (int)sizeof(tag)) { | 602 | basename(fstab->mount_point)) >= (int)sizeof(tag)) { |
609 | ERROR("Metadata tag name too long for %s\n", fstab->mount_point); | 603 | LERROR << "Metadata tag name too long for " << fstab->mount_point; |
610 | goto out; | 604 | goto out; |
611 | } | 605 | } |
612 | 606 | ||
@@ -618,14 +612,14 @@ static int compare_last_signature(struct fstab_rec *fstab, int *match) | |||
618 | fd = TEMP_FAILURE_RETRY(open(fstab->verity_loc, O_RDWR | O_SYNC | O_CLOEXEC)); | 612 | fd = TEMP_FAILURE_RETRY(open(fstab->verity_loc, O_RDWR | O_SYNC | O_CLOEXEC)); |
619 | 613 | ||
620 | if (fd == -1) { | 614 | if (fd == -1) { |
621 | ERROR("Failed to open %s: %s\n", fstab->verity_loc, strerror(errno)); | 615 | PERROR << "Failed to open " << fstab->verity_loc; |
622 | goto out; | 616 | goto out; |
623 | } | 617 | } |
624 | 618 | ||
625 | if (TEMP_FAILURE_RETRY(pread64(fd, prev, sizeof(prev), | 619 | if (TEMP_FAILURE_RETRY(pread64(fd, prev, sizeof(prev), |
626 | offset)) != sizeof(prev)) { | 620 | offset)) != sizeof(prev)) { |
627 | ERROR("Failed to read %zu bytes from %s offset %" PRIu64 " (%s)\n", | 621 | PERROR << "Failed to read " << sizeof(prev) << " bytes from " |
628 | sizeof(prev), fstab->verity_loc, offset, strerror(errno)); | 622 | << fstab->verity_loc << " offset " << offset; |
629 | goto out; | 623 | goto out; |
630 | } | 624 | } |
631 | 625 | ||
@@ -635,8 +629,8 @@ static int compare_last_signature(struct fstab_rec *fstab, int *match) | |||
635 | /* update current signature hash */ | 629 | /* update current signature hash */ |
636 | if (TEMP_FAILURE_RETRY(pwrite64(fd, curr, sizeof(curr), | 630 | if (TEMP_FAILURE_RETRY(pwrite64(fd, curr, sizeof(curr), |
637 | offset)) != sizeof(curr)) { | 631 | offset)) != sizeof(curr)) { |
638 | ERROR("Failed to write %zu bytes to %s offset %" PRIu64 " (%s)\n", | 632 | PERROR << "Failed to write " << sizeof(curr) << " bytes to " |
639 | sizeof(curr), fstab->verity_loc, offset, strerror(errno)); | 633 | << fstab->verity_loc << " offset " << offset; |
640 | goto out; | 634 | goto out; |
641 | } | 635 | } |
642 | } | 636 | } |
@@ -654,7 +648,7 @@ static int get_verity_state_offset(struct fstab_rec *fstab, off64_t *offset) | |||
654 | 648 | ||
655 | if (snprintf(tag, sizeof(tag), VERITY_STATE_TAG "_%s", | 649 | if (snprintf(tag, sizeof(tag), VERITY_STATE_TAG "_%s", |
656 | basename(fstab->mount_point)) >= (int)sizeof(tag)) { | 650 | basename(fstab->mount_point)) >= (int)sizeof(tag)) { |
657 | ERROR("Metadata tag name too long for %s\n", fstab->mount_point); | 651 | LERROR << "Metadata tag name too long for " << fstab->mount_point; |
658 | return -1; | 652 | return -1; |
659 | } | 653 | } |
660 | 654 | ||
@@ -720,7 +714,7 @@ int fs_mgr_load_verity_state(int *mode) | |||
720 | fstab = fs_mgr_read_fstab(fstab_filename); | 714 | fstab = fs_mgr_read_fstab(fstab_filename); |
721 | 715 | ||
722 | if (!fstab) { | 716 | if (!fstab) { |
723 | ERROR("Failed to read %s\n", fstab_filename); | 717 | LERROR << "Failed to read " << fstab_filename; |
724 | goto out; | 718 | goto out; |
725 | } | 719 | } |
726 | 720 | ||
@@ -776,7 +770,7 @@ int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback) | |||
776 | fd = TEMP_FAILURE_RETRY(open("/dev/device-mapper", O_RDWR | O_CLOEXEC)); | 770 | fd = TEMP_FAILURE_RETRY(open("/dev/device-mapper", O_RDWR | O_CLOEXEC)); |
777 | 771 | ||
778 | if (fd == -1) { | 772 | if (fd == -1) { |
779 | ERROR("Error opening device mapper (%s)\n", strerror(errno)); | 773 | PERROR << "Error opening device mapper"; |
780 | goto out; | 774 | goto out; |
781 | } | 775 | } |
782 | 776 | ||
@@ -789,7 +783,7 @@ int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback) | |||
789 | fstab = fs_mgr_read_fstab(fstab_filename); | 783 | fstab = fs_mgr_read_fstab(fstab_filename); |
790 | 784 | ||
791 | if (!fstab) { | 785 | if (!fstab) { |
792 | ERROR("Failed to read %s\n", fstab_filename); | 786 | LERROR << "Failed to read " << fstab_filename; |
793 | goto out; | 787 | goto out; |
794 | } | 788 | } |
795 | 789 | ||
@@ -810,8 +804,8 @@ int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback) | |||
810 | if (fstab->recs[i].fs_mgr_flags & MF_VERIFYATBOOT) { | 804 | if (fstab->recs[i].fs_mgr_flags & MF_VERIFYATBOOT) { |
811 | status = "V"; | 805 | status = "V"; |
812 | } else { | 806 | } else { |
813 | ERROR("Failed to query DM_TABLE_STATUS for %s (%s)\n", | 807 | PERROR << "Failed to query DM_TABLE_STATUS for " |
814 | mount_point.c_str(), strerror(errno)); | 808 | << mount_point.c_str(); |
815 | continue; | 809 | continue; |
816 | } | 810 | } |
817 | } | 811 | } |
@@ -881,22 +875,20 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab, bool verify_dev) | |||
881 | 875 | ||
882 | if (fec_open(&f, fstab->blk_device, O_RDONLY, FEC_VERITY_DISABLE, | 876 | if (fec_open(&f, fstab->blk_device, O_RDONLY, FEC_VERITY_DISABLE, |
883 | FEC_DEFAULT_ROOTS) < 0) { | 877 | FEC_DEFAULT_ROOTS) < 0) { |
884 | ERROR("Failed to open '%s' (%s)\n", fstab->blk_device, | 878 | PERROR << "Failed to open '" << fstab->blk_device << "'"; |
885 | strerror(errno)); | ||
886 | return retval; | 879 | return retval; |
887 | } | 880 | } |
888 | 881 | ||
889 | // read verity metadata | 882 | // read verity metadata |
890 | if (fec_verity_get_metadata(f, &verity) < 0) { | 883 | if (fec_verity_get_metadata(f, &verity) < 0) { |
891 | ERROR("Failed to get verity metadata '%s' (%s)\n", fstab->blk_device, | 884 | PERROR << "Failed to get verity metadata '" << fstab->blk_device << "'"; |
892 | strerror(errno)); | ||
893 | goto out; | 885 | goto out; |
894 | } | 886 | } |
895 | 887 | ||
896 | #ifdef ALLOW_ADBD_DISABLE_VERITY | 888 | #ifdef ALLOW_ADBD_DISABLE_VERITY |
897 | if (verity.disabled) { | 889 | if (verity.disabled) { |
898 | retval = FS_MGR_SETUP_VERITY_DISABLED; | 890 | retval = FS_MGR_SETUP_VERITY_DISABLED; |
899 | INFO("Attempt to cleanly disable verity - only works in USERDEBUG\n"); | 891 | LINFO << "Attempt to cleanly disable verity - only works in USERDEBUG"; |
900 | goto out; | 892 | goto out; |
901 | } | 893 | } |
902 | #endif | 894 | #endif |
@@ -910,19 +902,19 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab, bool verify_dev) | |||
910 | 902 | ||
911 | // get the device mapper fd | 903 | // get the device mapper fd |
912 | if ((fd = open("/dev/device-mapper", O_RDWR)) < 0) { | 904 | if ((fd = open("/dev/device-mapper", O_RDWR)) < 0) { |
913 | ERROR("Error opening device mapper (%s)\n", strerror(errno)); | 905 | PERROR << "Error opening device mapper"; |
914 | goto out; | 906 | goto out; |
915 | } | 907 | } |
916 | 908 | ||
917 | // create the device | 909 | // create the device |
918 | if (!fs_mgr_create_verity_device(io, mount_point, fd)) { | 910 | if (!fs_mgr_create_verity_device(io, mount_point, fd)) { |
919 | ERROR("Couldn't create verity device!\n"); | 911 | LERROR << "Couldn't create verity device!"; |
920 | goto out; | 912 | goto out; |
921 | } | 913 | } |
922 | 914 | ||
923 | // get the name of the device file | 915 | // get the name of the device file |
924 | if (!fs_mgr_get_verity_device_name(io, mount_point, fd, &verity_blk_name)) { | 916 | if (!fs_mgr_get_verity_device_name(io, mount_point, fd, &verity_blk_name)) { |
925 | ERROR("Couldn't get verity device number!\n"); | 917 | LERROR << "Couldn't get verity device number!"; |
926 | goto out; | 918 | goto out; |
927 | } | 919 | } |
928 | 920 | ||
@@ -957,8 +949,8 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab, bool verify_dev) | |||
957 | } | 949 | } |
958 | } | 950 | } |
959 | 951 | ||
960 | INFO("Enabling dm-verity for %s (mode %d)\n", | 952 | LINFO << "Enabling dm-verity for " << mount_point.c_str() |
961 | mount_point.c_str(), params.mode); | 953 | << " (mode " << params.mode << ")"; |
962 | 954 | ||
963 | if (fstab->fs_mgr_flags & MF_SLOTSELECT) { | 955 | if (fstab->fs_mgr_flags & MF_SLOTSELECT) { |
964 | // Update the verity params using the actual block device path | 956 | // Update the verity params using the actual block device path |
@@ -973,7 +965,7 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab, bool verify_dev) | |||
973 | 965 | ||
974 | if (params.ecc.valid) { | 966 | if (params.ecc.valid) { |
975 | // kernel may not support error correction, try without | 967 | // kernel may not support error correction, try without |
976 | INFO("Disabling error correction for %s\n", mount_point.c_str()); | 968 | LINFO << "Disabling error correction for " << mount_point.c_str(); |
977 | params.ecc.valid = false; | 969 | params.ecc.valid = false; |
978 | 970 | ||
979 | if (load_verity_table(io, mount_point, verity.data_size, fd, ¶ms, | 971 | if (load_verity_table(io, mount_point, verity.data_size, fd, ¶ms, |
@@ -990,7 +982,7 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab, bool verify_dev) | |||
990 | 982 | ||
991 | if (params.mode != VERITY_MODE_EIO) { | 983 | if (params.mode != VERITY_MODE_EIO) { |
992 | // as a last resort, EIO mode should always be supported | 984 | // as a last resort, EIO mode should always be supported |
993 | INFO("Falling back to EIO mode for %s\n", mount_point.c_str()); | 985 | LINFO << "Falling back to EIO mode for " << mount_point.c_str(); |
994 | params.mode = VERITY_MODE_EIO; | 986 | params.mode = VERITY_MODE_EIO; |
995 | 987 | ||
996 | if (load_verity_table(io, mount_point, verity.data_size, fd, ¶ms, | 988 | if (load_verity_table(io, mount_point, verity.data_size, fd, ¶ms, |
@@ -999,7 +991,7 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab, bool verify_dev) | |||
999 | } | 991 | } |
1000 | } | 992 | } |
1001 | 993 | ||
1002 | ERROR("Failed to load verity table for %s\n", mount_point.c_str()); | 994 | LERROR << "Failed to load verity table for " << mount_point.c_str(); |
1003 | goto out; | 995 | goto out; |
1004 | 996 | ||
1005 | loaded: | 997 | loaded: |
@@ -1015,10 +1007,11 @@ loaded: | |||
1015 | // Verify the entire partition in one go | 1007 | // Verify the entire partition in one go |
1016 | // If there is an error, allow it to mount as a normal verity partition. | 1008 | // If there is an error, allow it to mount as a normal verity partition. |
1017 | if (fstab->fs_mgr_flags & MF_VERIFYATBOOT) { | 1009 | if (fstab->fs_mgr_flags & MF_VERIFYATBOOT) { |
1018 | INFO("Verifying partition %s at boot\n", fstab->blk_device); | 1010 | LINFO << "Verifying partition " << fstab->blk_device << " at boot"; |
1019 | int err = read_partition(verity_blk_name.c_str(), verity.data_size); | 1011 | int err = read_partition(verity_blk_name.c_str(), verity.data_size); |
1020 | if (!err) { | 1012 | if (!err) { |
1021 | INFO("Verified verity partition %s at boot\n", fstab->blk_device); | 1013 | LINFO << "Verified verity partition " |
1014 | << fstab->blk_device << " at boot"; | ||
1022 | verified_at_boot = true; | 1015 | verified_at_boot = true; |
1023 | } | 1016 | } |
1024 | } | 1017 | } |
@@ -1028,7 +1021,7 @@ loaded: | |||
1028 | free(fstab->blk_device); | 1021 | free(fstab->blk_device); |
1029 | fstab->blk_device = strdup(verity_blk_name.c_str()); | 1022 | fstab->blk_device = strdup(verity_blk_name.c_str()); |
1030 | } else if (!fs_mgr_destroy_verity_device(io, mount_point, fd)) { | 1023 | } else if (!fs_mgr_destroy_verity_device(io, mount_point, fd)) { |
1031 | ERROR("Failed to remove verity device %s\n", mount_point.c_str()); | 1024 | LERROR << "Failed to remove verity device " << mount_point.c_str(); |
1032 | goto out; | 1025 | goto out; |
1033 | } | 1026 | } |
1034 | 1027 | ||