Merge "fs_mgr: code clean up"
This commit is contained in:
commit
0914d2bdff
4 changed files with 21 additions and 28 deletions
|
|
@ -807,7 +807,7 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode)
|
||||||
FsManagerAvbUniquePtr avb_handle(nullptr);
|
FsManagerAvbUniquePtr avb_handle(nullptr);
|
||||||
|
|
||||||
if (!fstab) {
|
if (!fstab) {
|
||||||
return -1;
|
return FS_MGR_MNTALL_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < fstab->num_entries; i++) {
|
for (i = 0; i < fstab->num_entries; i++) {
|
||||||
|
|
@ -853,7 +853,7 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode)
|
||||||
avb_handle = FsManagerAvbHandle::Open(extract_by_name_prefix(fstab));
|
avb_handle = FsManagerAvbHandle::Open(extract_by_name_prefix(fstab));
|
||||||
if (!avb_handle) {
|
if (!avb_handle) {
|
||||||
LERROR << "Failed to open FsManagerAvbHandle";
|
LERROR << "Failed to open FsManagerAvbHandle";
|
||||||
return -1;
|
return FS_MGR_MNTALL_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!avb_handle->SetUpAvb(&fstab->recs[i], true /* wait_for_verity_dev */)) {
|
if (!avb_handle->SetUpAvb(&fstab->recs[i], true /* wait_for_verity_dev */)) {
|
||||||
|
|
@ -983,7 +983,7 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error_count) {
|
if (error_count) {
|
||||||
return -1;
|
return FS_MGR_MNTALL_FAIL;
|
||||||
} else {
|
} else {
|
||||||
return encryptable;
|
return encryptable;
|
||||||
}
|
}
|
||||||
|
|
@ -1016,14 +1016,13 @@ int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device,
|
||||||
char *tmp_mount_point)
|
char *tmp_mount_point)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int ret = FS_MGR_DOMNT_FAILED;
|
|
||||||
int mount_errors = 0;
|
int mount_errors = 0;
|
||||||
int first_mount_errno = 0;
|
int first_mount_errno = 0;
|
||||||
char *m;
|
char* mount_point;
|
||||||
FsManagerAvbUniquePtr avb_handle(nullptr);
|
FsManagerAvbUniquePtr avb_handle(nullptr);
|
||||||
|
|
||||||
if (!fstab) {
|
if (!fstab) {
|
||||||
return ret;
|
return FS_MGR_DOMNT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < fstab->num_entries; i++) {
|
for (i = 0; i < fstab->num_entries; i++) {
|
||||||
|
|
@ -1038,7 +1037,7 @@ int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device,
|
||||||
!strcmp(fstab->recs[i].fs_type, "mtd")) {
|
!strcmp(fstab->recs[i].fs_type, "mtd")) {
|
||||||
LERROR << "Cannot mount filesystem of type "
|
LERROR << "Cannot mount filesystem of type "
|
||||||
<< fstab->recs[i].fs_type << " on " << n_blk_device;
|
<< fstab->recs[i].fs_type << " on " << n_blk_device;
|
||||||
goto out;
|
return FS_MGR_DOMNT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* First check the filesystem if requested */
|
/* First check the filesystem if requested */
|
||||||
|
|
@ -1065,7 +1064,7 @@ int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device,
|
||||||
avb_handle = FsManagerAvbHandle::Open(extract_by_name_prefix(fstab));
|
avb_handle = FsManagerAvbHandle::Open(extract_by_name_prefix(fstab));
|
||||||
if (!avb_handle) {
|
if (!avb_handle) {
|
||||||
LERROR << "Failed to open FsManagerAvbHandle";
|
LERROR << "Failed to open FsManagerAvbHandle";
|
||||||
return -1;
|
return FS_MGR_DOMNT_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!avb_handle->SetUpAvb(&fstab->recs[i], true /* wait_for_verity_dev */)) {
|
if (!avb_handle->SetUpAvb(&fstab->recs[i], true /* wait_for_verity_dev */)) {
|
||||||
|
|
@ -1086,16 +1085,15 @@ int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device,
|
||||||
|
|
||||||
/* Now mount it where requested */
|
/* Now mount it where requested */
|
||||||
if (tmp_mount_point) {
|
if (tmp_mount_point) {
|
||||||
m = tmp_mount_point;
|
mount_point = tmp_mount_point;
|
||||||
} else {
|
} else {
|
||||||
m = fstab->recs[i].mount_point;
|
mount_point = fstab->recs[i].mount_point;
|
||||||
}
|
}
|
||||||
int retry_count = 2;
|
int retry_count = 2;
|
||||||
while (retry_count-- > 0) {
|
while (retry_count-- > 0) {
|
||||||
if (!__mount(n_blk_device, m, &fstab->recs[i])) {
|
if (!__mount(n_blk_device, mount_point, &fstab->recs[i])) {
|
||||||
ret = 0;
|
|
||||||
fs_stat &= ~FS_STAT_FULL_MOUNT_FAILED;
|
fs_stat &= ~FS_STAT_FULL_MOUNT_FAILED;
|
||||||
goto out;
|
return FS_MGR_DOMNT_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
if (retry_count <= 0) break; // run check_fs only once
|
if (retry_count <= 0) break; // run check_fs only once
|
||||||
if (!first_mount_errno) first_mount_errno = errno;
|
if (!first_mount_errno) first_mount_errno = errno;
|
||||||
|
|
@ -1107,22 +1105,16 @@ int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device,
|
||||||
}
|
}
|
||||||
log_fs_stat(fstab->recs[i].blk_device, fs_stat);
|
log_fs_stat(fstab->recs[i].blk_device, fs_stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reach here means the mount attempt fails.
|
||||||
if (mount_errors) {
|
if (mount_errors) {
|
||||||
PERROR << "Cannot mount filesystem on " << n_blk_device
|
PERROR << "Cannot mount filesystem on " << n_blk_device << " at " << mount_point;
|
||||||
<< " at " << m;
|
if (first_mount_errno == EBUSY) return FS_MGR_DOMNT_BUSY;
|
||||||
if (first_mount_errno == EBUSY) {
|
|
||||||
ret = FS_MGR_DOMNT_BUSY;
|
|
||||||
} else {
|
|
||||||
ret = FS_MGR_DOMNT_FAILED;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* We didn't find a match, say so and return an error */
|
/* We didn't find a match, say so and return an error */
|
||||||
LERROR << "Cannot find mount point " << fstab->recs[i].mount_point
|
LERROR << "Cannot find mount point " << n_name << " in fstab";
|
||||||
<< " in fstab";
|
|
||||||
}
|
}
|
||||||
|
return FS_MGR_DOMNT_FAILED;
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ class FsManagerAvbVerifier {
|
||||||
std::unique_ptr<FsManagerAvbVerifier> FsManagerAvbVerifier::Create() {
|
std::unique_ptr<FsManagerAvbVerifier> FsManagerAvbVerifier::Create() {
|
||||||
std::string cmdline;
|
std::string cmdline;
|
||||||
if (!android::base::ReadFileToString("/proc/cmdline", &cmdline)) {
|
if (!android::base::ReadFileToString("/proc/cmdline", &cmdline)) {
|
||||||
LERROR << "Failed to read /proc/cmdline";
|
PERROR << "Failed to read /proc/cmdline";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,13 +133,13 @@ AvbIOResult FsManagerAvbOps::ReadFromPartition(const char* partition, int64_t of
|
||||||
if (offset < 0) {
|
if (offset < 0) {
|
||||||
off64_t total_size = lseek64(fd, 0, SEEK_END);
|
off64_t total_size = lseek64(fd, 0, SEEK_END);
|
||||||
if (total_size == -1) {
|
if (total_size == -1) {
|
||||||
LERROR << "Failed to lseek64 to end of the partition";
|
PERROR << "Failed to lseek64 to end of the partition";
|
||||||
return AVB_IO_RESULT_ERROR_IO;
|
return AVB_IO_RESULT_ERROR_IO;
|
||||||
}
|
}
|
||||||
offset = total_size + offset;
|
offset = total_size + offset;
|
||||||
// Repositions the offset to the beginning.
|
// Repositions the offset to the beginning.
|
||||||
if (lseek64(fd, 0, SEEK_SET) == -1) {
|
if (lseek64(fd, 0, SEEK_SET) == -1) {
|
||||||
LERROR << "Failed to lseek64 to the beginning of the partition";
|
PERROR << "Failed to lseek64 to the beginning of the partition";
|
||||||
return AVB_IO_RESULT_ERROR_IO;
|
return AVB_IO_RESULT_ERROR_IO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,7 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode);
|
||||||
|
|
||||||
#define FS_MGR_DOMNT_FAILED (-1)
|
#define FS_MGR_DOMNT_FAILED (-1)
|
||||||
#define FS_MGR_DOMNT_BUSY (-2)
|
#define FS_MGR_DOMNT_BUSY (-2)
|
||||||
|
#define FS_MGR_DOMNT_SUCCESS 0
|
||||||
|
|
||||||
int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device,
|
int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device,
|
||||||
char *tmp_mount_point);
|
char *tmp_mount_point);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue