Merge "Replacing fs_mgr_dir_is_writable(work) with fs_mgr_rw_access(work) to check whether the scratch partition is writable."

This commit is contained in:
Yi-yo Chiang 2022-10-12 10:06:48 +00:00 committed by Gerrit Code Review
commit cf10e2097d

View file

@ -120,13 +120,9 @@ bool fs_mgr_is_dir(const std::string& path) {
return !stat(path.c_str(), &st) && S_ISDIR(st.st_mode);
}
// Similar test as overlayfs workdir= validation in the kernel for read-write
// validation, except we use fs_mgr_work. Covers space and storage issues.
bool fs_mgr_dir_is_writable(const std::string& path) {
auto test_directory = path + "/fs_mgr_work";
rmdir(test_directory.c_str());
auto ret = !mkdir(test_directory.c_str(), 0700);
return ret | !rmdir(test_directory.c_str());
bool fs_mgr_rw_access(const std::string& path) {
if (path.empty()) return false;
return access(path.c_str(), R_OK | W_OK) == 0;
}
// At less than 1% or 8MB of free space return value of false,
@ -280,7 +276,7 @@ std::string fs_mgr_get_overlayfs_candidate(const std::string& mount_point) {
if (!fs_mgr_is_dir(upper)) continue;
auto work = dir + kWorkName;
if (!fs_mgr_is_dir(work)) continue;
if (!fs_mgr_dir_is_writable(work)) continue;
if (!fs_mgr_rw_access(work)) continue;
return dir;
}
return "";
@ -317,11 +313,6 @@ const std::string fs_mgr_mount_point(const std::string& mount_point) {
return "/system";
}
bool fs_mgr_rw_access(const std::string& path) {
if (path.empty()) return false;
return access(path.c_str(), R_OK | W_OK) == 0;
}
constexpr char kOverlayfsFileContext[] = "u:object_r:overlayfs_file:s0";
class AutoSetFsCreateCon final {