Merge "fs_mgr: Switch to LOG()/PLOG() defined in <android-base/logging.h>"

This commit is contained in:
Treehugger Robot 2017-01-28 01:37:21 +00:00 committed by Gerrit Code Review
commit 183ca56ce2
10 changed files with 254 additions and 233 deletions

View File

@ -76,7 +76,7 @@ static time_t gettime(void)
ret = clock_gettime(CLOCK_MONOTONIC, &ts);
if (ret < 0) {
ERROR("clock_gettime(CLOCK_MONOTONIC) failed: %s\n", strerror(errno));
PERROR << "clock_gettime(CLOCK_MONOTONIC) failed";
return 0;
}
@ -131,8 +131,8 @@ static void check_fs(const char *blk_device, char *fs_type, char *target)
strlcat(tmpmnt_opts, ",nomblk_io_submit", sizeof(tmpmnt_opts));
}
ret = mount(blk_device, target, fs_type, tmpmnt_flags, tmpmnt_opts);
INFO("%s(): mount(%s,%s,%s)=%d: %s\n",
__func__, blk_device, target, fs_type, ret, strerror(errno));
PINFO << __FUNCTION__ << "(): mount(" << blk_device << "," << target
<< "," << fs_type << ")=" << ret;
if (!ret) {
int i;
for (i = 0; i < 5; i++) {
@ -140,10 +140,12 @@ static void check_fs(const char *blk_device, char *fs_type, char *target)
// Should we try rebooting if all attempts fail?
int result = umount(target);
if (result == 0) {
INFO("%s(): unmount(%s) succeeded\n", __func__, target);
LINFO << __FUNCTION__ << "(): unmount(" << target
<< ") succeeded";
break;
}
ERROR("%s(): umount(%s)=%d: %s\n", __func__, target, result, strerror(errno));
PERROR << __FUNCTION__ << "(): umount(" << target << ")="
<< result;
sleep(1);
}
}
@ -153,10 +155,10 @@ static void check_fs(const char *blk_device, char *fs_type, char *target)
* (e.g. recent SDK system images). Detect these and skip the check.
*/
if (access(E2FSCK_BIN, X_OK)) {
INFO("Not running %s on %s (executable not in system image)\n",
E2FSCK_BIN, blk_device);
LINFO << "Not running " << E2FSCK_BIN << " on " << blk_device
<< " (executable not in system image)";
} else {
INFO("Running %s on %s\n", E2FSCK_BIN, blk_device);
LINFO << "Running " << E2FSCK_BIN << " on " << blk_device;
ret = android_fork_execvp_ext(ARRAY_SIZE(e2fsck_argv),
const_cast<char **>(e2fsck_argv),
@ -167,7 +169,7 @@ static void check_fs(const char *blk_device, char *fs_type, char *target)
if (ret < 0) {
/* No need to check for error in fork, we can't really handle it now */
ERROR("Failed trying to run %s\n", E2FSCK_BIN);
LERROR << "Failed trying to run " << E2FSCK_BIN;
}
}
} else if (!strcmp(fs_type, "f2fs")) {
@ -176,7 +178,7 @@ static void check_fs(const char *blk_device, char *fs_type, char *target)
"-a",
blk_device
};
INFO("Running %s -a %s\n", F2FS_FSCK_BIN, blk_device);
LINFO << "Running " << F2FS_FSCK_BIN << " -a " << blk_device;
ret = android_fork_execvp_ext(ARRAY_SIZE(f2fs_fsck_argv),
const_cast<char **>(f2fs_fsck_argv),
@ -185,7 +187,7 @@ static void check_fs(const char *blk_device, char *fs_type, char *target)
NULL, 0);
if (ret < 0) {
/* No need to check for error in fork, we can't really handle it now */
ERROR("Failed trying to run %s\n", F2FS_FSCK_BIN);
LERROR << "Failed trying to run " << F2FS_FSCK_BIN;
}
}
@ -231,8 +233,8 @@ static int do_quota(char *blk_device, char *fs_type, struct fstab_rec *rec)
* Detect these and skip reserve blocks.
*/
if (access(TUNE2FS_BIN, X_OK)) {
ERROR("Not running %s on %s (executable not in system image)\n",
TUNE2FS_BIN, blk_device);
LERROR << "Not running " << TUNE2FS_BIN << " on "
<< blk_device << " (executable not in system image)";
} else {
const char* arg1 = nullptr;
const char* arg2 = nullptr;
@ -244,7 +246,7 @@ static int do_quota(char *blk_device, char *fs_type, struct fstab_rec *rec)
struct ext4_super_block sb;
ret = read_super_block(fd, &sb);
if (ret < 0) {
ERROR("Can't read '%s' super block: %s\n", blk_device, strerror(errno));
PERROR << "Can't read '" << blk_device << "' super block";
return force_check;
}
@ -253,20 +255,20 @@ static int do_quota(char *blk_device, char *fs_type, struct fstab_rec *rec)
int want_quota = fs_mgr_is_quota(rec) != 0;
if (has_quota == want_quota) {
INFO("Requested quota status is match on %s\n", blk_device);
LINFO << "Requested quota status is match on " << blk_device;
return force_check;
} else if (want_quota) {
INFO("Enabling quota on %s\n", blk_device);
LINFO << "Enabling quota on " << blk_device;
arg1 = "-Oquota";
arg2 = "-Qusrquota,grpquota";
force_check = 1;
} else {
INFO("Disabling quota on %s\n", blk_device);
LINFO << "Disabling quota on " << blk_device;
arg1 = "-Q^usrquota,^grpquota";
arg2 = "-O^quota";
}
} else {
ERROR("Failed to open '%s': %s\n", blk_device, strerror(errno));
PERROR << "Failed to open '" << blk_device << "'";
return force_check;
}
@ -282,7 +284,7 @@ static int do_quota(char *blk_device, char *fs_type, struct fstab_rec *rec)
true, NULL, NULL, 0);
if (ret < 0) {
/* No need to check for error in fork, we can't really handle it now */
ERROR("Failed trying to run %s\n", TUNE2FS_BIN);
LERROR << "Failed trying to run " << TUNE2FS_BIN;
}
}
}
@ -298,10 +300,10 @@ static void do_reserved_size(char *blk_device, char *fs_type, struct fstab_rec *
* Detect these and skip reserve blocks.
*/
if (access(TUNE2FS_BIN, X_OK)) {
ERROR("Not running %s on %s (executable not in system image)\n",
TUNE2FS_BIN, blk_device);
LERROR << "Not running " << TUNE2FS_BIN << " on "
<< blk_device << " (executable not in system image)";
} else {
INFO("Running %s on %s\n", TUNE2FS_BIN, blk_device);
LINFO << "Running " << TUNE2FS_BIN << " on " << blk_device;
int status = 0;
int ret = 0;
@ -312,22 +314,23 @@ static void do_reserved_size(char *blk_device, char *fs_type, struct fstab_rec *
struct ext4_super_block sb;
ret = read_super_block(fd, &sb);
if (ret < 0) {
ERROR("Can't read '%s' super block: %s\n", blk_device, strerror(errno));
PERROR << "Can't read '" << blk_device << "' super block";
return;
}
reserved_blocks = rec->reserved_size / EXT4_BLOCK_SIZE(&sb);
unsigned long reserved_threshold = ext4_blocks_count(&sb) * 0.02;
if (reserved_threshold < reserved_blocks) {
WARNING("Reserved blocks %lu is too large\n", reserved_blocks);
LWARNING << "Reserved blocks " << reserved_blocks
<< " is too large";
reserved_blocks = reserved_threshold;
}
if (ext4_r_blocks_count(&sb) == reserved_blocks) {
INFO("Have reserved same blocks\n");
LINFO << "Have reserved same blocks";
return;
}
} else {
ERROR("Failed to open '%s': %s\n", blk_device, strerror(errno));
PERROR << "Failed to open '" << blk_device << "'";
return;
}
@ -346,7 +349,7 @@ static void do_reserved_size(char *blk_device, char *fs_type, struct fstab_rec *
if (ret < 0) {
/* No need to check for error in fork, we can't really handle it now */
ERROR("Failed trying to run %s\n", TUNE2FS_BIN);
LERROR << "Failed trying to run " << TUNE2FS_BIN;
}
}
}
@ -406,7 +409,8 @@ static int __mount(const char *source, const char *target, const struct fstab_re
mkdir(target, 0755);
ret = mount(source, target, rec->fs_type, mountflags, rec->fs_options);
save_errno = errno;
INFO("%s(source=%s,target=%s,type=%s)=%d\n", __func__, source, target, rec->fs_type, ret);
LINFO << __FUNCTION__ << "(source=" << source << ",target="
<< target << ",type=" << rec->fs_type << ")=" << ret;
if ((ret == 0) && (mountflags & MS_RDONLY) != 0) {
fs_mgr_set_blk_ro(source);
}
@ -488,8 +492,11 @@ static int mount_with_alternatives(struct fstab *fstab, int start_idx, int *end_
* each other.
*/
if (mounted) {
ERROR("%s(): skipping fstab dup mountpoint=%s rec[%d].fs_type=%s already mounted as %s.\n", __func__,
fstab->recs[i].mount_point, i, fstab->recs[i].fs_type, fstab->recs[*attempted_idx].fs_type);
LERROR << __FUNCTION__ << "(): skipping fstab dup mountpoint="
<< fstab->recs[i].mount_point << " rec[" << i
<< "].fs_type=" << fstab->recs[i].fs_type
<< " already mounted as "
<< fstab->recs[*attempted_idx].fs_type;
continue;
}
@ -510,9 +517,11 @@ static int mount_with_alternatives(struct fstab *fstab, int start_idx, int *end_
*attempted_idx = i;
mounted = 1;
if (i != start_idx) {
ERROR("%s(): Mounted %s on %s with fs_type=%s instead of %s\n", __func__,
fstab->recs[i].blk_device, fstab->recs[i].mount_point, fstab->recs[i].fs_type,
fstab->recs[start_idx].fs_type);
LERROR << __FUNCTION__ << "(): Mounted "
<< fstab->recs[i].blk_device << " on "
<< fstab->recs[i].mount_point << " with fs_type="
<< fstab->recs[i].fs_type << " instead of "
<< fstab->recs[start_idx].fs_type;
}
} else {
/* back up errno for crypto decisions */
@ -547,14 +556,14 @@ static int translate_ext_labels(struct fstab_rec *rec)
label_len = strlen(label);
if (label_len > 16) {
ERROR("FS label is longer than allowed by filesystem\n");
LERROR << "FS label is longer than allowed by filesystem";
goto out;
}
blockdir = opendir("/dev/block");
if (!blockdir) {
ERROR("couldn't open /dev/block\n");
LERROR << "couldn't open /dev/block";
goto out;
}
@ -568,7 +577,7 @@ static int translate_ext_labels(struct fstab_rec *rec)
fd = openat(dirfd(blockdir), ent->d_name, O_RDONLY);
if (fd < 0) {
ERROR("Cannot open block device /dev/block/%s\n", ent->d_name);
LERROR << "Cannot open block device /dev/block/" << ent->d_name;
goto out;
}
@ -583,7 +592,7 @@ static int translate_ext_labels(struct fstab_rec *rec)
sb = (struct ext4_super_block *)super_buf;
if (sb->s_magic != EXT4_SUPER_MAGIC) {
INFO("/dev/block/%s not ext{234}\n", ent->d_name);
LINFO << "/dev/block/" << ent->d_name << " not ext{234}";
continue;
}
@ -591,11 +600,12 @@ static int translate_ext_labels(struct fstab_rec *rec)
char *new_blk_device;
if (asprintf(&new_blk_device, "/dev/block/%s", ent->d_name) < 0) {
ERROR("Could not allocate block device string\n");
LERROR << "Could not allocate block device string";
goto out;
}
INFO("resolved label %s to %s\n", rec->blk_device, new_blk_device);
LINFO << "resolved label " << rec->blk_device << " to "
<< new_blk_device;
free(rec->blk_device);
rec->blk_device = new_blk_device;
@ -638,13 +648,13 @@ static int handle_encryptable(const struct fstab_rec* rec)
if (umount(rec->mount_point) == 0) {
return FS_MGR_MNTALL_DEV_NEEDS_ENCRYPTION;
} else {
WARNING("Could not umount %s (%s) - allow continue unencrypted\n",
rec->mount_point, strerror(errno));
PWARNING << "Could not umount " << rec->mount_point
<< " - allow continue unencrypted";
return FS_MGR_MNTALL_DEV_NOT_ENCRYPTED;
}
} else if (rec->fs_mgr_flags & (MF_FILEENCRYPTION | MF_FORCEFDEORFBE)) {
// Deal with file level encryption
INFO("%s is file encrypted\n", rec->mount_point);
// Deal with file level encryption
LINFO << rec->mount_point << " is file encrypted";
return FS_MGR_MNTALL_DEV_FILE_ENCRYPTED;
} else if (fs_mgr_is_encryptable(rec)) {
return FS_MGR_MNTALL_DEV_NOT_ENCRYPTED;
@ -717,7 +727,7 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode)
!strcmp(fstab->recs[i].fs_type, "ext4")) {
int tret = translate_ext_labels(&fstab->recs[i]);
if (tret < 0) {
ERROR("Could not translate label to block device\n");
LERROR << "Could not translate label to block device";
continue;
}
}
@ -733,20 +743,20 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode)
* mount_with_alternatives().
*/
if (avb_ret == FS_MGR_SETUP_AVB_HASHTREE_DISABLED) {
INFO("AVB HASHTREE disabled\n");
LINFO << "AVB HASHTREE disabled";
} else if (fs_mgr_setup_avb(&fstab->recs[i]) !=
FS_MGR_SETUP_AVB_SUCCESS) {
ERROR("Failed to set up AVB on partition: %s, skipping!\n",
fstab->recs[i].mount_point);
LERROR << "Failed to set up AVB on partition: "
<< fstab->recs[i].mount_point << ", skipping!";
/* Skips mounting the device. */
continue;
}
} else if ((fstab->recs[i].fs_mgr_flags & MF_VERIFY) && device_is_secure()) {
int rc = fs_mgr_setup_verity(&fstab->recs[i], true);
if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) {
INFO("Verity disabled");
LINFO << "Verity disabled";
} else if (rc != FS_MGR_SETUP_VERITY_SUCCESS) {
ERROR("Could not set up verified partition, skipping!\n");
LERROR << "Could not set up verified partition, skipping!";
continue;
}
}
@ -770,7 +780,7 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode)
if (status != FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE) {
if (encryptable != FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE) {
// Log and continue
ERROR("Only one encryptable/encrypted partition supported\n");
LERROR << "Only one encryptable/encrypted partition supported";
}
encryptable = status;
}
@ -788,19 +798,21 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode)
* at two different lines in the fstab. Use the top one for formatting
* as that is the preferred one.
*/
ERROR("%s(): %s is wiped and %s %s is formattable. Format it.\n", __func__,
fstab->recs[top_idx].blk_device, fstab->recs[top_idx].mount_point,
fstab->recs[top_idx].fs_type);
LERROR << __FUNCTION__ << "(): " << fstab->recs[top_idx].blk_device
<< " is wiped and " << fstab->recs[top_idx].mount_point
<< " " << fstab->recs[top_idx].fs_type
<< " is formattable. Format it.";
if (fs_mgr_is_encryptable(&fstab->recs[top_idx]) &&
strcmp(fstab->recs[top_idx].key_loc, KEY_IN_FOOTER)) {
int fd = open(fstab->recs[top_idx].key_loc, O_WRONLY);
if (fd >= 0) {
INFO("%s(): also wipe %s\n", __func__, fstab->recs[top_idx].key_loc);
LINFO << __FUNCTION__ << "(): also wipe "
<< fstab->recs[top_idx].key_loc;
wipe_block_device(fd, get_file_size(fd));
close(fd);
} else {
ERROR("%s(): %s wouldn't open (%s)\n", __func__,
fstab->recs[top_idx].key_loc, strerror(errno));
PERROR << __FUNCTION__ << "(): "
<< fstab->recs[top_idx].key_loc << " wouldn't open";
}
} else if (fs_mgr_is_encryptable(&fstab->recs[top_idx]) &&
!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)
i = top_idx - 1;
continue;
} else {
ERROR("%s(): Format failed. Suggest recovery...\n", __func__);
LERROR << __FUNCTION__ << "(): Format failed. "
<< "Suggest recovery...";
encryptable = FS_MGR_MNTALL_DEV_NEEDS_RECOVERY;
continue;
}
@ -819,18 +832,22 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode)
if (mret && mount_errno != EBUSY && mount_errno != EACCES &&
fs_mgr_is_encryptable(&fstab->recs[attempted_idx])) {
if (wiped) {
ERROR("%s(): %s is wiped and %s %s is encryptable. Suggest recovery...\n", __func__,
fstab->recs[attempted_idx].blk_device, fstab->recs[attempted_idx].mount_point,
fstab->recs[attempted_idx].fs_type);
LERROR << __FUNCTION__ << "(): "
<< fstab->recs[attempted_idx].blk_device
<< " is wiped and "
<< fstab->recs[attempted_idx].mount_point << " "
<< fstab->recs[attempted_idx].fs_type
<< " is encryptable. Suggest recovery...";
encryptable = FS_MGR_MNTALL_DEV_NEEDS_RECOVERY;
continue;
} else {
/* Need to mount a tmpfs at this mountpoint for now, and set
* properties that vold will query later for decrypting
*/
ERROR("%s(): possibly an encryptable blkdev %s for mount %s type %s )\n", __func__,
fstab->recs[attempted_idx].blk_device, fstab->recs[attempted_idx].mount_point,
fstab->recs[attempted_idx].fs_type);
LERROR << __FUNCTION__ << "(): possibly an encryptable blkdev "
<< fstab->recs[attempted_idx].blk_device
<< " for mount " << fstab->recs[attempted_idx].mount_point
<< " type " << fstab->recs[attempted_idx].fs_type;
if (fs_mgr_do_tmpfs_mount(fstab->recs[attempted_idx].mount_point) < 0) {
++error_count;
continue;
@ -839,15 +856,15 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode)
encryptable = FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED;
} else {
if (fs_mgr_is_nofail(&fstab->recs[attempted_idx])) {
ERROR("Ignoring failure to mount an un-encryptable or wiped partition on"
"%s at %s options: %s error: %s\n",
fstab->recs[attempted_idx].blk_device, fstab->recs[attempted_idx].mount_point,
fstab->recs[attempted_idx].fs_options, strerror(mount_errno));
PERROR << "Ignoring failure to mount an un-encryptable or wiped partition on"
<< fstab->recs[attempted_idx].blk_device << " at "
<< fstab->recs[attempted_idx].mount_point << " options: "
<< fstab->recs[attempted_idx].fs_options;
} else {
ERROR("Failed to mount an un-encryptable or wiped partition on"
"%s at %s options: %s error: %s\n",
fstab->recs[attempted_idx].blk_device, fstab->recs[attempted_idx].mount_point,
fstab->recs[attempted_idx].fs_options, strerror(mount_errno));
PERROR << "Failed to mount an un-encryptable or wiped partition on"
<< fstab->recs[attempted_idx].blk_device << " at "
<< fstab->recs[attempted_idx].mount_point << " options: "
<< fstab->recs[attempted_idx].fs_options;
++error_count;
}
continue;
@ -899,8 +916,8 @@ int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device,
if (!strcmp(fstab->recs[i].fs_type, "swap") ||
!strcmp(fstab->recs[i].fs_type, "emmc") ||
!strcmp(fstab->recs[i].fs_type, "mtd")) {
ERROR("Cannot mount filesystem of type %s on %s\n",
fstab->recs[i].fs_type, n_blk_device);
LERROR << "Cannot mount filesystem of type "
<< fstab->recs[i].fs_type << " on " << n_blk_device;
goto out;
}
@ -928,20 +945,20 @@ int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device,
* mount_with_alternatives().
*/
if (avb_ret == FS_MGR_SETUP_AVB_HASHTREE_DISABLED) {
INFO("AVB HASHTREE disabled\n");
LINFO << "AVB HASHTREE disabled";
} else if (fs_mgr_setup_avb(&fstab->recs[i]) !=
FS_MGR_SETUP_AVB_SUCCESS) {
ERROR("Failed to set up AVB on partition: %s, skipping!\n",
fstab->recs[i].mount_point);
LERROR << "Failed to set up AVB on partition: "
<< fstab->recs[i].mount_point << ", skipping!";
/* Skips mounting the device. */
continue;
}
} else if ((fstab->recs[i].fs_mgr_flags & MF_VERIFY) && device_is_secure()) {
int rc = fs_mgr_setup_verity(&fstab->recs[i], true);
if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) {
INFO("Verity disabled");
LINFO << "Verity disabled";
} else if (rc != FS_MGR_SETUP_VERITY_SUCCESS) {
ERROR("Could not set up verified partition, skipping!\n");
LERROR << "Could not set up verified partition, skipping!";
continue;
}
}
@ -962,8 +979,8 @@ int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device,
}
}
if (mount_errors) {
ERROR("Cannot mount filesystem on %s at %s. error: %s\n",
n_blk_device, m, strerror(first_mount_errno));
PERROR << "Cannot mount filesystem on " << n_blk_device
<< " at " << m;
if (first_mount_errno == EBUSY) {
ret = FS_MGR_DOMNT_BUSY;
} else {
@ -971,7 +988,8 @@ int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device,
}
} else {
/* We didn't find a match, say so and return an error */
ERROR("Cannot find mount point %s in fstab\n", fstab->recs[i].mount_point);
LERROR << "Cannot find mount point " << fstab->recs[i].mount_point
<< " in fstab";
}
out:
@ -992,7 +1010,7 @@ int fs_mgr_do_tmpfs_mount(char *n_name)
ret = mount("tmpfs", n_name, "tmpfs",
MS_NOATIME | MS_NOSUID | MS_NODEV, CRYPTO_TMPFS_OPTIONS);
if (ret < 0) {
ERROR("Cannot mount tmpfs filesystem at %s\n", n_name);
LERROR << "Cannot mount tmpfs filesystem at " << n_name;
return -1;
}
@ -1011,7 +1029,8 @@ int fs_mgr_unmount_all(struct fstab *fstab)
while (fstab->recs[i].blk_device) {
if (umount(fstab->recs[i].mount_point)) {
ERROR("Cannot unmount filesystem at %s\n", fstab->recs[i].mount_point);
LERROR << "Cannot unmount filesystem at "
<< fstab->recs[i].mount_point;
ret = -1;
}
i++;
@ -1057,7 +1076,8 @@ int fs_mgr_swapon_all(struct fstab *fstab)
if (fstab->recs[i].max_comp_streams >= 0) {
zram_mcs_fp = fopen(ZRAM_CONF_MCS, "r+");
if (zram_mcs_fp == NULL) {
ERROR("Unable to open zram conf comp device %s\n", ZRAM_CONF_MCS);
LERROR << "Unable to open zram conf comp device "
<< ZRAM_CONF_MCS;
ret = -1;
continue;
}
@ -1067,7 +1087,7 @@ int fs_mgr_swapon_all(struct fstab *fstab)
zram_fp = fopen(ZRAM_CONF_DEV, "r+");
if (zram_fp == NULL) {
ERROR("Unable to open zram conf device %s\n", ZRAM_CONF_DEV);
LERROR << "Unable to open zram conf device " << ZRAM_CONF_DEV;
ret = -1;
continue;
}
@ -1086,7 +1106,7 @@ int fs_mgr_swapon_all(struct fstab *fstab)
&status, true, LOG_KLOG, false, NULL,
NULL, 0);
if (err) {
ERROR("mkswap failed for %s\n", fstab->recs[i].blk_device);
LERROR << "mkswap failed for " << fstab->recs[i].blk_device;
ret = -1;
continue;
}
@ -1102,7 +1122,7 @@ int fs_mgr_swapon_all(struct fstab *fstab)
}
err = swapon(fstab->recs[i].blk_device, flags);
if (err) {
ERROR("swapon failed for %s\n", fstab->recs[i].blk_device);
LERROR << "swapon failed for " << fstab->recs[i].blk_device;
ret = -1;
}
}
@ -1159,7 +1179,7 @@ int fs_mgr_early_setup_verity(struct fstab_rec *fstab_rec)
if ((fstab_rec->fs_mgr_flags & MF_VERIFY) && device_is_secure()) {
int rc = fs_mgr_setup_verity(fstab_rec, false);
if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) {
INFO("Verity disabled");
LINFO << "Verity disabled";
return FS_MGR_EARLY_SETUP_VERITY_NO_VERITY;
} else if (rc == FS_MGR_SETUP_VERITY_SUCCESS) {
return FS_MGR_EARLY_SETUP_VERITY_SUCCESS;
@ -1167,7 +1187,7 @@ int fs_mgr_early_setup_verity(struct fstab_rec *fstab_rec)
return FS_MGR_EARLY_SETUP_VERITY_FAIL;
}
} else if (device_is_secure()) {
ERROR("Verity must be enabled for early mounted partitions on secured devices.\n");
LERROR << "Verity must be enabled for early mounted partitions on secured devices";
return FS_MGR_EARLY_SETUP_VERITY_FAIL;
}
return FS_MGR_EARLY_SETUP_VERITY_NO_VERITY;

View File

@ -209,21 +209,21 @@ static bool load_vbmeta_prop(androidboot_vbmeta *vbmeta_prop)
expected_digest_size = SHA512_DIGEST_LENGTH * 2;
vbmeta_prop->hash_alg = kSHA512;
} else {
ERROR("Unknown hash algorithm: %s\n", hash_alg.c_str());
LERROR << "Unknown hash algorithm: " << hash_alg.c_str();
return false;
}
// Reads digest.
if (digest.size() != expected_digest_size) {
ERROR("Unexpected digest size: %zu (expected %zu)\n", digest.size(),
expected_digest_size);
LERROR << "Unexpected digest size: " << digest.size() << " (expected: "
<< expected_digest_size << ")";
return false;
}
if (!hex_to_bytes(vbmeta_prop->digest, sizeof(vbmeta_prop->digest),
digest)) {
ERROR("Hash digest contains non-hexidecimal character: %s\n",
digest.c_str());
LERROR << "Hash digest contains non-hexidecimal character: "
<< digest.c_str();
return false;
}
@ -252,7 +252,7 @@ static bool verify_vbmeta_images(const AvbSlotVerifyData &verify_data,
const androidboot_vbmeta &vbmeta_prop)
{
if (verify_data.num_vbmeta_images == 0) {
ERROR("No vbmeta images\n");
LERROR << "No vbmeta images";
return false;
}
@ -268,13 +268,13 @@ static bool verify_vbmeta_images(const AvbSlotVerifyData &verify_data,
}
if (total_size != vbmeta_prop.vbmeta_size) {
ERROR("total vbmeta size mismatch: %zu (expected: %zu)\n", total_size,
vbmeta_prop.vbmeta_size);
LERROR << "total vbmeta size mismatch: " << total_size
<< " (expected: " << vbmeta_prop.vbmeta_size << ")";
return false;
}
if (!digest_matched) {
ERROR("vbmeta digest mismatch\n");
LERROR << "vbmeta digest mismatch";
return false;
}
@ -326,11 +326,11 @@ static bool hashtree_load_verity_table(
}
if (res < 0 || (size_t)res >= bufsize) {
ERROR("Error building verity table; insufficient buffer size?\n");
LERROR << "Error building verity table; insufficient buffer size?";
return false;
}
INFO("loading verity table: '%s'", verity_params);
LINFO << "Loading verity table: '" << verity_params << "'";
// Sets ext target boundary.
verity_params += strlen(verity_params) + 1;
@ -339,7 +339,7 @@ static bool hashtree_load_verity_table(
// Sends the ioctl to load the verity table.
if (ioctl(fd, DM_TABLE_LOAD, io)) {
ERROR("Error loading verity table (%s)\n", strerror(errno));
PERROR << "Error loading verity table";
return false;
}
@ -354,7 +354,7 @@ static bool hashtree_dm_verity_setup(struct fstab_rec *fstab_entry,
// Gets the device mapper fd.
android::base::unique_fd fd(open("/dev/device-mapper", O_RDWR));
if (fd < 0) {
ERROR("Error opening device mapper (%s)\n", strerror(errno));
PERROR << "Error opening device mapper";
return false;
}
@ -363,14 +363,14 @@ static bool hashtree_dm_verity_setup(struct fstab_rec *fstab_entry,
struct dm_ioctl *io = (struct dm_ioctl *)buffer;
const std::string mount_point(basename(fstab_entry->mount_point));
if (!fs_mgr_create_verity_device(io, mount_point, fd)) {
ERROR("Couldn't create verity device!\n");
LERROR << "Couldn't create verity device!";
return false;
}
// Gets the name of the device file.
std::string verity_blk_name;
if (!fs_mgr_get_verity_device_name(io, mount_point, fd, &verity_blk_name)) {
ERROR("Couldn't get verity device number!\n");
LERROR << "Couldn't get verity device number!";
return false;
}
@ -378,7 +378,7 @@ static bool hashtree_dm_verity_setup(struct fstab_rec *fstab_entry,
if (!hashtree_load_verity_table(io, mount_point, fd,
std::string(fstab_entry->blk_device),
hashtree_desc, salt, root_digest)) {
ERROR("Couldn't load verity table!\n");
LERROR << "Couldn't load verity table!";
return false;
}
@ -432,16 +432,16 @@ static bool get_hashtree_descriptor(const std::string &partition_name,
verify_data.vbmeta_images[i].partition_name);
if (vbmeta_partition_name != "vbmeta" &&
vbmeta_partition_name != partition_name) {
WARNING("Skip vbmeta image at %s for partition: %s\n",
verify_data.vbmeta_images[i].partition_name,
partition_name.c_str());
LWARNING << "Skip vbmeta image at "
<< verify_data.vbmeta_images[i].partition_name
<< " for partition: " << partition_name.c_str();
continue;
}
for (size_t j = 0; j < num_descriptors && !found; j++) {
AvbDescriptor desc;
if (!avb_descriptor_validate_and_byteswap(descriptors[j], &desc)) {
WARNING("Descriptor is invalid.\n");
LWARNING << "Descriptor[" << j << "] is invalid";
continue;
}
if (desc.tag == AVB_DESCRIPTOR_TAG_HASHTREE) {
@ -468,7 +468,7 @@ static bool get_hashtree_descriptor(const std::string &partition_name,
}
if (!found) {
ERROR("Partition descriptor not found: %s\n", partition_name.c_str());
LERROR << "Partition descriptor not found: " << partition_name.c_str();
return false;
}
@ -530,7 +530,7 @@ int fs_mgr_load_vbmeta_images(struct fstab *fstab)
FS_MGR_CHECK(fstab != nullptr);
if (!polling_vbmeta_blk_device(fstab)) {
ERROR("Failed to find block device of /vbmeta\n");
LERROR << "Failed to find block device of /vbmeta";
return FS_MGR_SETUP_AVB_FAIL;
}
@ -542,7 +542,7 @@ int fs_mgr_load_vbmeta_images(struct fstab *fstab)
fs_mgr_avb_ops = fs_mgr_dummy_avb_ops_new(fstab);
if (fs_mgr_avb_ops == nullptr) {
ERROR("Failed to allocate dummy avb_ops\n");
LERROR << "Failed to allocate dummy avb_ops";
return FS_MGR_SETUP_AVB_FAIL;
}
@ -562,17 +562,17 @@ int fs_mgr_load_vbmeta_images(struct fstab *fstab)
// - AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION (for UNLOCKED state).
if (verify_result == AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION) {
if (!fs_mgr_vbmeta_prop.allow_verification_error) {
ERROR("ERROR_VERIFICATION isn't allowed\n");
LERROR << "ERROR_VERIFICATION isn't allowed";
goto fail;
}
} else if (verify_result != AVB_SLOT_VERIFY_RESULT_OK) {
ERROR("avb_slot_verify failed, result: %d\n", verify_result);
LERROR << "avb_slot_verify failed, result: " << verify_result;
goto fail;
}
// Verifies vbmeta images against the digest passed from bootloader.
if (!verify_vbmeta_images(*fs_mgr_avb_verify_data, fs_mgr_vbmeta_prop)) {
ERROR("verify_vbmeta_images failed\n");
LERROR << "verify_vbmeta_images failed";
goto fail;
} else {
// Checks whether FLAGS_HASHTREE_DISABLED is set.
@ -619,8 +619,8 @@ int fs_mgr_setup_avb(struct fstab_rec *fstab_entry)
std::string partition_name(basename(fstab_entry->mount_point));
if (!avb_validate_utf8((const uint8_t *)partition_name.c_str(),
partition_name.length())) {
ERROR("Partition name: %s is not valid UTF-8.\n",
partition_name.c_str());
LERROR << "Partition name: " << partition_name.c_str()
<< " is not valid UTF-8.";
return FS_MGR_SETUP_AVB_FAIL;
}

View File

@ -66,7 +66,7 @@ static AvbIOResult read_from_partition(AvbOps *ops ATTRIBUTE_UNUSED,
fs_mgr_get_entry_for_mount_point(fs_mgr_fstab, "/misc");
if (fstab_entry == nullptr) {
ERROR("Partition (%s) not found in fstab\n", partition);
LERROR << "Partition (" << partition << ") not found in fstab";
return AVB_IO_RESULT_ERROR_IO;
}
@ -83,7 +83,7 @@ static AvbIOResult read_from_partition(AvbOps *ops ATTRIBUTE_UNUSED,
TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY | O_CLOEXEC)));
if (fd < 0) {
ERROR("Failed to open %s (%s)\n", path.c_str(), strerror(errno));
PERROR << "Failed to open " << path.c_str();
return AVB_IO_RESULT_ERROR_IO;
}
@ -92,13 +92,13 @@ static AvbIOResult read_from_partition(AvbOps *ops ATTRIBUTE_UNUSED,
if (offset < 0) {
off64_t total_size = lseek64(fd, 0, SEEK_END);
if (total_size == -1) {
ERROR("Failed to lseek64 to end of the partition\n");
LERROR << "Failed to lseek64 to end of the partition";
return AVB_IO_RESULT_ERROR_IO;
}
offset = total_size + offset;
// Repositions the offset to the beginning.
if (lseek64(fd, 0, SEEK_SET) == -1) {
ERROR("Failed to lseek64 to the beginning of the partition\n");
LERROR << "Failed to lseek64 to the beginning of the partition";
return AVB_IO_RESULT_ERROR_IO;
}
}
@ -109,8 +109,8 @@ static AvbIOResult read_from_partition(AvbOps *ops ATTRIBUTE_UNUSED,
TEMP_FAILURE_RETRY(pread64(fd, buffer, num_bytes, offset));
if (num_read < 0 || (size_t)num_read != num_bytes) {
ERROR("Failed to read %zu bytes from %s offset %" PRId64 " (%s)\n",
num_bytes, path.c_str(), offset, strerror(errno));
PERROR << "Failed to read " << num_bytes << " bytes from "
<< path.c_str() << " offset " << offset;
return AVB_IO_RESULT_ERROR_IO;
}
@ -184,7 +184,7 @@ AvbOps *fs_mgr_dummy_avb_ops_new(struct fstab *fstab)
ops = (AvbOps *)calloc(1, sizeof(AvbOps));
if (ops == nullptr) {
ERROR("Error allocating memory for AvbOps.\n");
LERROR << "Error allocating memory for AvbOps";
return nullptr;
}

View File

@ -45,7 +45,7 @@ bool fs_mgr_create_verity_device(struct dm_ioctl *io,
{
fs_mgr_verity_ioctl_init(io, name, 1);
if (ioctl(fd, DM_DEV_CREATE, io)) {
ERROR("Error creating device mapping (%s)", strerror(errno));
PERROR << "Error creating device mapping";
return false;
}
return true;
@ -57,7 +57,7 @@ bool fs_mgr_destroy_verity_device(struct dm_ioctl *io,
{
fs_mgr_verity_ioctl_init(io, name, 0);
if (ioctl(fd, DM_DEV_REMOVE, io)) {
ERROR("Error removing device mapping (%s)", strerror(errno));
PERROR << "Error removing device mapping";
return false;
}
return true;
@ -72,7 +72,7 @@ bool fs_mgr_get_verity_device_name(struct dm_ioctl *io,
fs_mgr_verity_ioctl_init(io, name, 0);
if (ioctl(fd, DM_DEV_STATUS, io)) {
ERROR("Error fetching verity device number (%s)", strerror(errno));
PERROR << "Error fetching verity device number";
return false;
}
@ -88,7 +88,7 @@ bool fs_mgr_resume_verity_table(struct dm_ioctl *io,
{
fs_mgr_verity_ioctl_init(io, name, 0);
if (ioctl(fd, DM_DEV_SUSPEND, io)) {
ERROR("Error activating verity device (%s)", strerror(errno));
PERROR << "Error activating verity device";
return false;
}
return true;

View File

@ -45,12 +45,12 @@ static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer)
int fd, rc = 0;
if ((fd = open(fs_blkdev, O_WRONLY)) < 0) {
ERROR("Cannot open block device. %s\n", strerror(errno));
PERROR << "Cannot open block device";
return -1;
}
if ((ioctl(fd, BLKGETSIZE64, &dev_sz)) == -1) {
ERROR("Cannot get block device size. %s\n", strerror(errno));
PERROR << "Cannot get block device size";
close(fd);
return -1;
}
@ -58,7 +58,7 @@ static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer)
struct selabel_handle *sehandle = selinux_android_file_context_handle();
if (!sehandle) {
/* libselinux logs specific error */
ERROR("Cannot initialize android file_contexts");
LERROR << "Cannot initialize android file_contexts";
close(fd);
return -1;
}
@ -73,7 +73,7 @@ static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer)
/* Use make_ext4fs_internal to avoid wiping an already-wiped partition. */
rc = make_ext4fs_internal(fd, NULL, NULL, fs_mnt_point, 0, 0, 0, 0, 0, 0, sehandle, 0, 0, NULL, NULL, NULL);
if (rc) {
ERROR("make_ext4fs returned %d.\n", rc);
LERROR << "make_ext4fs returned " << rc;
}
close(fd);
@ -106,19 +106,19 @@ static int format_f2fs(char *fs_blkdev)
for(;;) {
pid_t p = waitpid(pid, &rc, 0);
if (p != pid) {
ERROR("Error waiting for child process - %d\n", p);
LERROR << "Error waiting for child process - " << p;
rc = -1;
break;
}
if (WIFEXITED(rc)) {
rc = WEXITSTATUS(rc);
INFO("%s done, status %d\n", args[0], rc);
LINFO << args[0] << " done, status " << rc;
if (rc) {
rc = -1;
}
break;
}
ERROR("Still waiting for %s...\n", args[0]);
LERROR << "Still waiting for " << args[0] << "...";
}
return rc;
@ -128,14 +128,15 @@ int fs_mgr_do_format(struct fstab_rec *fstab, bool crypt_footer)
{
int rc = -EINVAL;
ERROR("%s: Format %s as '%s'.\n", __func__, fstab->blk_device, fstab->fs_type);
LERROR << __FUNCTION__ << ": Format " << fstab->blk_device
<< " as '" << fstab->fs_type << "'";
if (!strncmp(fstab->fs_type, "f2fs", 4)) {
rc = format_f2fs(fstab->blk_device);
} else if (!strncmp(fstab->fs_type, "ext4", 4)) {
rc = format_ext4(fstab->blk_device, fstab->mount_point, crypt_footer);
} else {
ERROR("File system type '%s' is not supported\n", fstab->fs_type);
LERROR << "File system type '" << fstab->fs_type << "' is not supported";
}
return rc;

View File

@ -196,7 +196,7 @@ static int parse_flags(char *flags, struct flag_list *fl,
}
}
if (flag_vals->file_encryption_mode == 0) {
ERROR("Unknown file encryption mode: %s\n", mode);
LERROR << "Unknown file encryption mode: " << mode;
}
} else if ((fl[i].flag == MF_LENGTH) && flag_vals) {
/* The length flag is followed by an = and the
@ -226,7 +226,7 @@ static int parse_flags(char *flags, struct flag_list *fl,
flag_vals->partnum = strtol(part_start, NULL, 0);
}
} else {
ERROR("Warning: voldmanaged= flag malformed\n");
LERROR << "Warning: voldmanaged= flag malformed";
}
} else if ((fl[i].flag == MF_SWAPPRIO) && flag_vals) {
flag_vals->swap_prio = strtoll(strchr(p, '=') + 1, NULL, 0);
@ -276,7 +276,7 @@ static int parse_flags(char *flags, struct flag_list *fl,
/* fs_options was not passed in, so if the flag is unknown
* it's an error.
*/
ERROR("Warning: unknown flag %s\n", p);
LERROR << "Warning: unknown flag " << p;
}
}
p = strtok_r(NULL, ",", &savep);
@ -321,7 +321,7 @@ struct fstab *fs_mgr_read_fstab_file(FILE *fstab_file)
}
if (!entries) {
ERROR("No entries found in fstab\n");
LERROR << "No entries found in fstab";
goto err;
}
@ -354,30 +354,30 @@ struct fstab *fs_mgr_read_fstab_file(FILE *fstab_file)
* between the two reads.
*/
if (cnt >= entries) {
ERROR("Tried to process more entries than counted\n");
LERROR << "Tried to process more entries than counted";
break;
}
if (!(p = strtok_r(line, delim, &save_ptr))) {
ERROR("Error parsing mount source\n");
LERROR << "Error parsing mount source";
goto err;
}
fstab->recs[cnt].blk_device = strdup(p);
if (!(p = strtok_r(NULL, delim, &save_ptr))) {
ERROR("Error parsing mount_point\n");
LERROR << "Error parsing mount_point";
goto err;
}
fstab->recs[cnt].mount_point = strdup(p);
if (!(p = strtok_r(NULL, delim, &save_ptr))) {
ERROR("Error parsing fs_type\n");
LERROR << "Error parsing fs_type";
goto err;
}
fstab->recs[cnt].fs_type = strdup(p);
if (!(p = strtok_r(NULL, delim, &save_ptr))) {
ERROR("Error parsing mount_flags\n");
LERROR << "Error parsing mount_flags";
goto err;
}
tmp_fs_options[0] = '\0';
@ -392,7 +392,7 @@ struct fstab *fs_mgr_read_fstab_file(FILE *fstab_file)
}
if (!(p = strtok_r(NULL, delim, &save_ptr))) {
ERROR("Error parsing fs_mgr_options\n");
LERROR << "Error parsing fs_mgr_options";
goto err;
}
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)
}
/* If an A/B partition, modify block device to be the real block device */
if (fs_mgr_update_for_slotselect(fstab) != 0) {
ERROR("Error updating for slotselect\n");
LERROR << "Error updating for slotselect";
goto err;
}
free(line);
@ -433,7 +433,7 @@ struct fstab *fs_mgr_read_fstab(const char *fstab_path)
fstab_file = fopen(fstab_path, "r");
if (!fstab_file) {
ERROR("Cannot open file %s\n", fstab_path);
LERROR << "Cannot open file " << fstab_path;
return NULL;
}
fstab = fs_mgr_read_fstab_file(fstab_file);

View File

@ -27,7 +27,8 @@ char *me = nullptr;
static void usage(void)
{
ERROR("%s: usage: %s <-a | -n mnt_point blk_dev | -u> <fstab_file>\n", me, me);
LERROR << me << ": usage: " << me
<< " <-a | -n mnt_point blk_dev | -u> <fstab_file>";
exit(1);
}
@ -88,7 +89,9 @@ int main(int argc, char * const argv[])
const char *fstab_file=NULL;
struct fstab *fstab=NULL;
klog_set_level(6);
setenv("ANDROID_LOG_TAGS", "*:i", 1); // Set log level to INFO
android::base::InitLogging(
const_cast<char **>(argv), &android::base::KernelLogger);
parse_options(argc, argv, &a_flag, &u_flag, &n_flag, &n_name, &n_blk_dev);
@ -104,7 +107,7 @@ int main(int argc, char * const argv[])
} else if (u_flag) {
return fs_mgr_unmount_all(fstab);
} else {
ERROR("%s: Internal error, unknown option\n", me);
LERROR << me << ": Internal error, unknown option";
exit(1);
}

View File

@ -17,11 +17,9 @@
#ifndef __CORE_FS_MGR_PRIV_H
#define __CORE_FS_MGR_PRIV_H
#include <cutils/klog.h>
#include <android-base/logging.h>
#include <fs_mgr.h>
#ifdef __cplusplus
#include <android-base/logging.h>
/* The CHECK() in logging.h will use program invocation name as the tag.
* Thus, the log will have prefix "init: " when libfs_mgr is statically
* linked in the init process. This might be opaque when debugging.
@ -29,14 +27,21 @@
* indicate the check happens in fs_mgr.
*/
#define FS_MGR_CHECK(x) CHECK(x) << "in libfs_mgr "
#endif
#define FS_MGR_TAG "[libfs_mgr]"
// Logs a message to kernel
#define LINFO LOG(INFO) << FS_MGR_TAG
#define LWARNING LOG(WARNING) << FS_MGR_TAG
#define LERROR LOG(ERROR) << FS_MGR_TAG
// Logs a message with strerror(errno) at the end
#define PINFO PLOG(INFO) << FS_MGR_TAG
#define PWARNING PLOG(WARNING) << FS_MGR_TAG
#define PERROR PLOG(ERROR) << FS_MGR_TAG
__BEGIN_DECLS
#define INFO(x...) KLOG_INFO("fs_mgr", x)
#define WARNING(x...) KLOG_WARNING("fs_mgr", x)
#define ERROR(x...) KLOG_ERROR("fs_mgr", x)
#define CRYPTO_TMPFS_OPTIONS "size=256m,mode=0771,uid=1000,gid=1000"
#define WAIT_TIMEOUT 20

View File

@ -48,9 +48,8 @@ static int get_active_slot_suffix_from_misc(struct fstab *fstab,
if (strcmp(fstab->recs[n].mount_point, "/misc") == 0) {
misc_fd = open(fstab->recs[n].blk_device, O_RDONLY);
if (misc_fd == -1) {
ERROR("Error opening misc partition \"%s\" (%s)\n",
fstab->recs[n].blk_device,
strerror(errno));
PERROR << "Error opening misc partition '"
<< fstab->recs[n].blk_device << "'";
return -1;
} else {
break;
@ -59,7 +58,7 @@ static int get_active_slot_suffix_from_misc(struct fstab *fstab,
}
if (misc_fd == -1) {
ERROR("Error finding misc partition\n");
LERROR << "Error finding misc partition";
return -1;
}
@ -67,7 +66,7 @@ static int get_active_slot_suffix_from_misc(struct fstab *fstab,
// Linux will never return partial reads when reading from block
// devices so no need to worry about them.
if (num_read != sizeof(msg)) {
ERROR("Error reading bootloader_message (%s)\n", strerror(errno));
PERROR << "Error reading bootloader_message";
close(misc_fd);
return -1;
}
@ -98,11 +97,11 @@ static int get_active_slot_suffix(struct fstab *fstab, char *out_suffix,
// If we couldn't get the suffix from the kernel cmdline, try the
// the misc partition.
if (get_active_slot_suffix_from_misc(fstab, out_suffix, suffix_len) == 0) {
INFO("Using slot suffix \"%s\" from misc\n", out_suffix);
LINFO << "Using slot suffix '" << out_suffix << "' from misc";
return 0;
}
ERROR("Error determining slot_suffix\n");
LERROR << "Error determining slot_suffix";
return -1;
}

View File

@ -94,12 +94,12 @@ static RSA *load_key(const char *path)
FILE* f = fopen(path, "r");
if (!f) {
ERROR("Can't open '%s'\n", path);
LERROR << "Can't open " << path;
return NULL;
}
if (!fread(key_data, sizeof(key_data), 1, f)) {
ERROR("Could not read key!\n");
LERROR << "Could not read key!";
fclose(f);
return NULL;
}
@ -108,7 +108,7 @@ static RSA *load_key(const char *path)
RSA* key = NULL;
if (!android_pubkey_decode(key_data, sizeof(key_data), &key)) {
ERROR("Could not parse key!\n");
LERROR << "Could not parse key!";
return NULL;
}
@ -128,14 +128,14 @@ static int verify_table(const uint8_t *signature, size_t signature_size,
// Now get the public key from the keyfile
key = load_key(VERITY_TABLE_RSA_KEY);
if (!key) {
ERROR("Couldn't load verity keys\n");
LERROR << "Couldn't load verity keys";
goto out;
}
// verify the result
if (!RSA_verify(NID_sha256, hash_buf, sizeof(hash_buf), signature,
signature_size, key)) {
ERROR("Couldn't verify table\n");
LERROR << "Couldn't verify table";
goto out;
}
@ -227,7 +227,7 @@ static bool format_verity_table(char *buf, const size_t bufsize,
}
if (res < 0 || (size_t)res >= bufsize) {
ERROR("Error building verity table; insufficient buffer size?\n");
LERROR << "Error building verity table; insufficient buffer size?";
return false;
}
@ -246,7 +246,7 @@ static bool format_legacy_verity_table(char *buf, const size_t bufsize,
}
if (res < 0 || (size_t)res >= bufsize) {
ERROR("Error building verity table; insufficient buffer size?\n");
LERROR << "Error building verity table; insufficient buffer size?";
return false;
}
@ -277,11 +277,11 @@ static int load_verity_table(struct dm_ioctl *io, const std::string &name,
bufsize = DM_BUF_SIZE - (verity_params - buffer);
if (!format(verity_params, bufsize, params)) {
ERROR("Failed to format verity parameters\n");
LERROR << "Failed to format verity parameters";
return -1;
}
INFO("loading verity table: '%s'", verity_params);
LINFO << "loading verity table: '" << verity_params << "'";
// set next target boundary
verity_params += strlen(verity_params) + 1;
@ -290,7 +290,7 @@ static int load_verity_table(struct dm_ioctl *io, const std::string &name,
// send the ioctl to load the verity table
if (ioctl(fd, DM_TABLE_LOAD, io)) {
ERROR("Error loading verity table (%s)\n", strerror(errno));
PERROR << "Error loading verity table";
return -1;
}
@ -309,13 +309,13 @@ static int check_verity_restart(const char *fname)
if (fd == -1) {
if (errno != ENOENT) {
ERROR("Failed to open %s (%s)\n", fname, strerror(errno));
PERROR << "Failed to open " << fname;
}
goto out;
}
if (fstat(fd, &s) == -1) {
ERROR("Failed to fstat %s (%s)\n", fname, strerror(errno));
PERROR << "Failed to fstat " << fname;
goto out;
}
@ -326,14 +326,12 @@ static int check_verity_restart(const char *fname)
}
if (lseek(fd, s.st_size - size, SEEK_SET) == -1) {
ERROR("Failed to lseek %jd %s (%s)\n", (intmax_t)(s.st_size - size), fname,
strerror(errno));
PERROR << "Failed to lseek " << (intmax_t)(s.st_size - size) << " " << fname;
goto out;
}
if (!android::base::ReadFully(fd, buffer, size)) {
ERROR("Failed to read %zd bytes from %s (%s)\n", size, fname,
strerror(errno));
PERROR << "Failed to read " << size << " bytes from " << fname;
goto out;
}
@ -405,14 +403,14 @@ static int metadata_find(const char *fname, const char *stag,
fp = fopen(fname, "r+");
if (!fp) {
ERROR("Failed to open %s (%s)\n", fname, strerror(errno));
PERROR << "Failed to open " << fname;
goto out;
}
/* check magic */
if (fseek(fp, start, SEEK_SET) < 0 ||
fread(&magic, sizeof(magic), 1, fp) != 1) {
ERROR("Failed to read magic from %s (%s)\n", fname, strerror(errno));
PERROR << "Failed to read magic from " << fname;
goto out;
}
@ -421,13 +419,13 @@ static int metadata_find(const char *fname, const char *stag,
if (fseek(fp, start, SEEK_SET) < 0 ||
fwrite(&magic, sizeof(magic), 1, fp) != 1) {
ERROR("Failed to write magic to %s (%s)\n", fname, strerror(errno));
PERROR << "Failed to write magic to " << fname;
goto out;
}
rc = metadata_add(fp, start + sizeof(magic), stag, slength, offset);
if (rc < 0) {
ERROR("Failed to add metadata to %s: %s\n", fname, strerror(errno));
PERROR << "Failed to add metadata to " << fname;
}
goto out;
@ -452,14 +450,13 @@ static int metadata_find(const char *fname, const char *stag,
start += length;
if (fseek(fp, length, SEEK_CUR) < 0) {
ERROR("Failed to seek %s (%s)\n", fname, strerror(errno));
PERROR << "Failed to seek " << fname;
goto out;
}
} else {
rc = metadata_add(fp, start, stag, slength, offset);
if (rc < 0) {
ERROR("Failed to write metadata to %s: %s\n", fname,
strerror(errno));
PERROR << "Failed to write metadata to " << fname;
}
goto out;
}
@ -483,13 +480,13 @@ static int write_verity_state(const char *fname, off64_t offset, int32_t mode)
fd = TEMP_FAILURE_RETRY(open(fname, O_WRONLY | O_SYNC | O_CLOEXEC));
if (fd == -1) {
ERROR("Failed to open %s (%s)\n", fname, strerror(errno));
PERROR << "Failed to open " << fname;
goto out;
}
if (TEMP_FAILURE_RETRY(pwrite64(fd, &s, sizeof(s), offset)) != sizeof(s)) {
ERROR("Failed to write %zu bytes to %s to offset %" PRIu64 " (%s)\n",
sizeof(s), fname, offset, strerror(errno));
PERROR << "Failed to write " << sizeof(s) << " bytes to " << fname
<< " to offset " << offset;
goto out;
}
@ -512,13 +509,13 @@ static int read_verity_state(const char *fname, off64_t offset, int *mode)
fd = TEMP_FAILURE_RETRY(open(fname, O_RDONLY | O_CLOEXEC));
if (fd == -1) {
ERROR("Failed to open %s (%s)\n", fname, strerror(errno));
PERROR << "Failed to open " << fname;
goto out;
}
if (TEMP_FAILURE_RETRY(pread64(fd, &s, sizeof(s), offset)) != sizeof(s)) {
ERROR("Failed to read %zu bytes from %s offset %" PRIu64 " (%s)\n",
sizeof(s), fname, offset, strerror(errno));
PERROR << "Failed to read " << sizeof(s) << " bytes from " << fname
<< " offset " << offset;
goto out;
}
@ -530,13 +527,13 @@ static int read_verity_state(const char *fname, off64_t offset, int *mode)
}
if (s.version != VERITY_STATE_VERSION) {
ERROR("Unsupported verity state version (%u)\n", s.version);
LERROR << "Unsupported verity state version (" << s.version << ")";
goto out;
}
if (s.mode < VERITY_MODE_EIO ||
s.mode > VERITY_MODE_LAST) {
ERROR("Unsupported verity mode (%u)\n", s.mode);
LERROR << "Unsupported verity mode (" << s.mode << ")";
goto out;
}
@ -558,15 +555,14 @@ static int read_partition(const char *path, uint64_t size)
android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_CLOEXEC)));
if (fd == -1) {
ERROR("Failed to open %s: %s\n", path, strerror(errno));
PERROR << "Failed to open " << path;
return -errno;
}
while (size) {
size_read = TEMP_FAILURE_RETRY(read(fd, buf, READ_BUF_SIZE));
if (size_read == -1) {
ERROR("Error in reading partition %s: %s\n", path,
strerror(errno));
PERROR << "Error in reading partition " << path;
return -errno;
}
size -= size_read;
@ -590,15 +586,13 @@ static int compare_last_signature(struct fstab_rec *fstab, int *match)
if (fec_open(&f, fstab->blk_device, O_RDONLY, FEC_VERITY_DISABLE,
FEC_DEFAULT_ROOTS) == -1) {
ERROR("Failed to open '%s' (%s)\n", fstab->blk_device,
strerror(errno));
PERROR << "Failed to open '" << fstab->blk_device << "'";
return rc;
}
// read verity metadata
if (fec_verity_get_metadata(f, &verity) == -1) {
ERROR("Failed to get verity metadata '%s' (%s)\n", fstab->blk_device,
strerror(errno));
PERROR << "Failed to get verity metadata '" << fstab->blk_device << "'";
goto out;
}
@ -606,7 +600,7 @@ static int compare_last_signature(struct fstab_rec *fstab, int *match)
if (snprintf(tag, sizeof(tag), VERITY_LASTSIG_TAG "_%s",
basename(fstab->mount_point)) >= (int)sizeof(tag)) {
ERROR("Metadata tag name too long for %s\n", fstab->mount_point);
LERROR << "Metadata tag name too long for " << fstab->mount_point;
goto out;
}
@ -618,14 +612,14 @@ static int compare_last_signature(struct fstab_rec *fstab, int *match)
fd = TEMP_FAILURE_RETRY(open(fstab->verity_loc, O_RDWR | O_SYNC | O_CLOEXEC));
if (fd == -1) {
ERROR("Failed to open %s: %s\n", fstab->verity_loc, strerror(errno));
PERROR << "Failed to open " << fstab->verity_loc;
goto out;
}
if (TEMP_FAILURE_RETRY(pread64(fd, prev, sizeof(prev),
offset)) != sizeof(prev)) {
ERROR("Failed to read %zu bytes from %s offset %" PRIu64 " (%s)\n",
sizeof(prev), fstab->verity_loc, offset, strerror(errno));
PERROR << "Failed to read " << sizeof(prev) << " bytes from "
<< fstab->verity_loc << " offset " << offset;
goto out;
}
@ -635,8 +629,8 @@ static int compare_last_signature(struct fstab_rec *fstab, int *match)
/* update current signature hash */
if (TEMP_FAILURE_RETRY(pwrite64(fd, curr, sizeof(curr),
offset)) != sizeof(curr)) {
ERROR("Failed to write %zu bytes to %s offset %" PRIu64 " (%s)\n",
sizeof(curr), fstab->verity_loc, offset, strerror(errno));
PERROR << "Failed to write " << sizeof(curr) << " bytes to "
<< fstab->verity_loc << " offset " << offset;
goto out;
}
}
@ -654,7 +648,7 @@ static int get_verity_state_offset(struct fstab_rec *fstab, off64_t *offset)
if (snprintf(tag, sizeof(tag), VERITY_STATE_TAG "_%s",
basename(fstab->mount_point)) >= (int)sizeof(tag)) {
ERROR("Metadata tag name too long for %s\n", fstab->mount_point);
LERROR << "Metadata tag name too long for " << fstab->mount_point;
return -1;
}
@ -720,7 +714,7 @@ int fs_mgr_load_verity_state(int *mode)
fstab = fs_mgr_read_fstab(fstab_filename);
if (!fstab) {
ERROR("Failed to read %s\n", fstab_filename);
LERROR << "Failed to read " << fstab_filename;
goto out;
}
@ -776,7 +770,7 @@ int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback)
fd = TEMP_FAILURE_RETRY(open("/dev/device-mapper", O_RDWR | O_CLOEXEC));
if (fd == -1) {
ERROR("Error opening device mapper (%s)\n", strerror(errno));
PERROR << "Error opening device mapper";
goto out;
}
@ -789,7 +783,7 @@ int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback)
fstab = fs_mgr_read_fstab(fstab_filename);
if (!fstab) {
ERROR("Failed to read %s\n", fstab_filename);
LERROR << "Failed to read " << fstab_filename;
goto out;
}
@ -810,8 +804,8 @@ int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback)
if (fstab->recs[i].fs_mgr_flags & MF_VERIFYATBOOT) {
status = "V";
} else {
ERROR("Failed to query DM_TABLE_STATUS for %s (%s)\n",
mount_point.c_str(), strerror(errno));
PERROR << "Failed to query DM_TABLE_STATUS for "
<< mount_point.c_str();
continue;
}
}
@ -881,22 +875,20 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab, bool verify_dev)
if (fec_open(&f, fstab->blk_device, O_RDONLY, FEC_VERITY_DISABLE,
FEC_DEFAULT_ROOTS) < 0) {
ERROR("Failed to open '%s' (%s)\n", fstab->blk_device,
strerror(errno));
PERROR << "Failed to open '" << fstab->blk_device << "'";
return retval;
}
// read verity metadata
if (fec_verity_get_metadata(f, &verity) < 0) {
ERROR("Failed to get verity metadata '%s' (%s)\n", fstab->blk_device,
strerror(errno));
PERROR << "Failed to get verity metadata '" << fstab->blk_device << "'";
goto out;
}
#ifdef ALLOW_ADBD_DISABLE_VERITY
if (verity.disabled) {
retval = FS_MGR_SETUP_VERITY_DISABLED;
INFO("Attempt to cleanly disable verity - only works in USERDEBUG\n");
LINFO << "Attempt to cleanly disable verity - only works in USERDEBUG";
goto out;
}
#endif
@ -910,19 +902,19 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab, bool verify_dev)
// get the device mapper fd
if ((fd = open("/dev/device-mapper", O_RDWR)) < 0) {
ERROR("Error opening device mapper (%s)\n", strerror(errno));
PERROR << "Error opening device mapper";
goto out;
}
// create the device
if (!fs_mgr_create_verity_device(io, mount_point, fd)) {
ERROR("Couldn't create verity device!\n");
LERROR << "Couldn't create verity device!";
goto out;
}
// get the name of the device file
if (!fs_mgr_get_verity_device_name(io, mount_point, fd, &verity_blk_name)) {
ERROR("Couldn't get verity device number!\n");
LERROR << "Couldn't get verity device number!";
goto out;
}
@ -957,8 +949,8 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab, bool verify_dev)
}
}
INFO("Enabling dm-verity for %s (mode %d)\n",
mount_point.c_str(), params.mode);
LINFO << "Enabling dm-verity for " << mount_point.c_str()
<< " (mode " << params.mode << ")";
if (fstab->fs_mgr_flags & MF_SLOTSELECT) {
// 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)
if (params.ecc.valid) {
// kernel may not support error correction, try without
INFO("Disabling error correction for %s\n", mount_point.c_str());
LINFO << "Disabling error correction for " << mount_point.c_str();
params.ecc.valid = false;
if (load_verity_table(io, mount_point, verity.data_size, fd, &params,
@ -990,7 +982,7 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab, bool verify_dev)
if (params.mode != VERITY_MODE_EIO) {
// as a last resort, EIO mode should always be supported
INFO("Falling back to EIO mode for %s\n", mount_point.c_str());
LINFO << "Falling back to EIO mode for " << mount_point.c_str();
params.mode = VERITY_MODE_EIO;
if (load_verity_table(io, mount_point, verity.data_size, fd, &params,
@ -999,7 +991,7 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab, bool verify_dev)
}
}
ERROR("Failed to load verity table for %s\n", mount_point.c_str());
LERROR << "Failed to load verity table for " << mount_point.c_str();
goto out;
loaded:
@ -1015,10 +1007,11 @@ loaded:
// Verify the entire partition in one go
// If there is an error, allow it to mount as a normal verity partition.
if (fstab->fs_mgr_flags & MF_VERIFYATBOOT) {
INFO("Verifying partition %s at boot\n", fstab->blk_device);
LINFO << "Verifying partition " << fstab->blk_device << " at boot";
int err = read_partition(verity_blk_name.c_str(), verity.data_size);
if (!err) {
INFO("Verified verity partition %s at boot\n", fstab->blk_device);
LINFO << "Verified verity partition "
<< fstab->blk_device << " at boot";
verified_at_boot = true;
}
}
@ -1028,7 +1021,7 @@ loaded:
free(fstab->blk_device);
fstab->blk_device = strdup(verity_blk_name.c_str());
} else if (!fs_mgr_destroy_verity_device(io, mount_point, fd)) {
ERROR("Failed to remove verity device %s\n", mount_point.c_str());
LERROR << "Failed to remove verity device " << mount_point.c_str();
goto out;
}