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

Commit b127c35a authored by Mark Salyzyn's avatar Mark Salyzyn Committed by Gerrit Code Review
Browse files

Merge changes Ie03f3895,Id4d9ee61

* changes:
  fs_mgr: add fs_mgr_access() as no-errno access(,F_OK) wrapper
  fs_mgr: candidate list check mount_point
parents 6cc230f5 aace4864
Loading
Loading
Loading
Loading
+16 −15
Original line number Diff line number Diff line
@@ -177,9 +177,16 @@ const char* fs_mgr_mount_point(const fstab* fstab, const char* mount_point) {
    return "/system";
}

bool fs_mgr_access(const std::string& path) {
    auto save_errno = errno;
    auto ret = access(path.c_str(), F_OK) == 0;
    errno = save_errno;
    return ret;
}

// return true if system supports overlayfs
bool fs_mgr_wants_overlayfs() {
    // This will return empty on init first_stage_mount, so speculative
    // Properties will return empty on init first_stage_mount, so speculative
    // determination, empty (unset) _or_ "1" is true which differs from the
    // official ro.debuggable policy.  ALLOW_ADBD_DISABLE_VERITY == 0 should
    // protect us from false in any case, so this is insurance.
@@ -187,13 +194,7 @@ bool fs_mgr_wants_overlayfs() {
    if (debuggable != "1") return false;

    // Overlayfs available in the kernel, and patched for override_creds?
    static signed char overlayfs_in_kernel = -1;  // cache for constant condition
    if (overlayfs_in_kernel == -1) {
        auto save_errno = errno;
        overlayfs_in_kernel = !access("/sys/module/overlay/parameters/override_creds", F_OK);
        errno = save_errno;
    }
    return overlayfs_in_kernel;
    return fs_mgr_access("/sys/module/overlay/parameters/override_creds");
}

bool fs_mgr_overlayfs_already_mounted(const std::string& mount_point) {
@@ -373,15 +374,14 @@ bool fs_mgr_overlayfs_setup_one(const std::string& overlay, const std::string& m
bool fs_mgr_overlayfs_teardown_one(const std::string& overlay, const std::string& mount_point,
                                   bool* change) {
    const auto top = overlay + kOverlayTopDir;
    auto save_errno = errno;
    auto missing = access(top.c_str(), F_OK);
    errno = save_errno;
    if (missing) return false;

    const auto oldpath = top + (mount_point.empty() ? "" : ("/"s + mount_point));
    if (!fs_mgr_access(top)) return false;

    auto cleanup_all = mount_point.empty();
    const auto oldpath = top + (cleanup_all ? "" : ("/"s + mount_point));
    const auto newpath = oldpath + ".teardown";
    auto ret = fs_mgr_rm_all(newpath);
    save_errno = errno;
    auto save_errno = errno;
    if (!rename(oldpath.c_str(), newpath.c_str())) {
        if (change) *change = true;
    } else if (errno != ENOENT) {
@@ -400,7 +400,7 @@ bool fs_mgr_overlayfs_teardown_one(const std::string& overlay, const std::string
    } else {
        errno = save_errno;
    }
    if (!mount_point.empty()) {
    if (!cleanup_all) {
        save_errno = errno;
        if (!rmdir(top.c_str())) {
            if (change) *change = true;
@@ -471,6 +471,7 @@ std::vector<std::string> fs_mgr_candidate_list(const fstab* fstab,
    if ((std::find(mounts.begin(), mounts.end(), "/system") == mounts.end()) &&
        !fs_mgr_get_entry_for_mount_point(const_cast<struct fstab*>(fstab), "/") &&
        !fs_mgr_get_entry_for_mount_point(const_cast<struct fstab*>(fstab), "/system") &&
        (!mount_point || ("/system"s == mount_point)) &&
        !fs_mgr_overlayfs_verity_enabled("system")) {
        mounts.emplace_back("/system");
    }