Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cf10e209 authored by Yi-yo Chiang's avatar Yi-yo Chiang Committed by Gerrit Code Review
Browse files

Merge "Replacing fs_mgr_dir_is_writable(work) with fs_mgr_rw_access(work) to...

Merge "Replacing fs_mgr_dir_is_writable(work) with fs_mgr_rw_access(work) to check whether the scratch partition is writable."
parents aa9eb7c8 301adfcc
Loading
Loading
Loading
Loading
+4 −13
Original line number Diff line number Diff line
@@ -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 {