fs_mgr: errno handling in fs_mgr_overlayfs_setup()
Do not report errno if ENOENT or ENXIO as it is expected when verity
is in fact disabled or not setup on platform.
Reading the default fstab can also result in ENOENT if fstab or dt
are missing on purpose, but if we get an fstab then restore the
errno as we move on.
fs_mgr_has_shared_blocks sets errno, when all we care about is yes
or no answer (EPERM notwithstanding, which indicates do not know).
If no candidates are found to override, and not caused by EPERM,
then suppress errno.
Test: adb-remount-test.sh
Bug: 109821005
Change-Id: If7ae257cb6b738a64ba43d32805760cc292b2fae
diff --git a/fs_mgr/fs_mgr_overlayfs.cpp b/fs_mgr/fs_mgr_overlayfs.cpp
index ef043f9..8bfcd81 100644
--- a/fs_mgr/fs_mgr_overlayfs.cpp
+++ b/fs_mgr/fs_mgr_overlayfs.cpp
@@ -144,7 +144,10 @@
if (entry->fs_mgr_flags.logical) {
fs_mgr_update_logical_partition(entry);
}
- return fs_mgr_has_shared_blocks(entry->mount_point, entry->blk_device);
+ auto save_errno = errno;
+ auto has_shared_blocks = fs_mgr_has_shared_blocks(entry->mount_point, entry->blk_device);
+ errno = save_errno;
+ return has_shared_blocks;
}
bool fs_mgr_rm_all(const std::string& path, bool* change = nullptr, int level = 0) {
@@ -263,8 +266,10 @@
std::vector<std::string> fs_mgr_overlayfs_verity_enabled_list() {
std::vector<std::string> ret;
+ auto save_errno = errno;
fs_mgr_update_verity_state(
[&ret](const std::string& mount_point, int) { ret.emplace_back(mount_point); });
+ if ((errno == ENOENT) || (errno == ENXIO)) errno = save_errno;
return ret;
}
@@ -837,10 +842,12 @@
return ret;
}
+ auto save_errno = errno;
Fstab fstab;
if (!ReadDefaultFstab(&fstab)) {
return false;
}
+ errno = save_errno;
auto mounts = fs_mgr_candidate_list(&fstab, fs_mgr_mount_point(mount_point));
if (mounts.empty()) return ret;
@@ -864,7 +871,8 @@
break;
}
if (dir.empty()) {
- errno = ESRCH;
+ if (change && *change) errno = ESRCH;
+ if (errno == EPERM) errno = save_errno;
return ret;
}