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

Commit 71db89b1 authored by Yo Chiang's avatar Yo Chiang Committed by Gerrit Code Review
Browse files

Merge "fs_mgr_overlayfs: Polish fs_mgr_overlayfs_mount_fstab_entry()"

parents b440fc9c dcf1c1f4
Loading
Loading
Loading
Loading
+21 −7
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ bool fs_mgr_overlayfs_mount_all(Fstab*) {
    return false;
}

bool fs_mgr_overlayfs_mount_fstab_entry(const std::string&, const std::string&) {
bool fs_mgr_overlayfs_mount_fstab_entry(const android::fs_mgr::FstabEntry&) {
    return false;
}

@@ -1299,17 +1299,31 @@ static void TryMountScratch() {
    }
}

bool fs_mgr_overlayfs_mount_fstab_entry(const std::string& lowers,
                                        const std::string& mount_point) {
bool fs_mgr_overlayfs_mount_fstab_entry(const android::fs_mgr::FstabEntry& entry) {
    if (fs_mgr_overlayfs_invalid()) return false;

    std::string aux = "lowerdir=" + lowers + ",override_creds=off";
    auto rc = mount("overlay", mount_point.c_str(), "overlay", MS_RDONLY | MS_NOATIME, aux.c_str());
    // Create the mount point in case it doesn't exist.
    mkdir(entry.mount_point.c_str(), 0755);

    if (rc == 0) return true;
    auto options = kLowerdirOption + entry.lowerdir;
    if (fs_mgr_overlayfs_valid() == OverlayfsValidResult::kOverrideCredsRequired) {
        options += ",override_creds=off";
    }

    // Use .blk_device as the mount() source for debugging purposes.
    // Overlayfs is pseudo filesystem, so the source device is a symbolic value and isn't used to
    // back the filesystem. /proc/mounts would show the source as the device name of the mount.
    auto report = "__mount(source=" + entry.blk_device + ",target=" + entry.mount_point +
                  ",type=overlay," + options + ")=";
    auto ret = mount(entry.blk_device.c_str(), entry.mount_point.c_str(), "overlay",
                     MS_RDONLY | MS_NOATIME, options.c_str());
    if (ret) {
        PERROR << report << ret;
        return false;
    }
    LINFO << report << ret;
    return true;
}

bool fs_mgr_overlayfs_mount_all(Fstab* fstab) {
    auto ret = false;
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@
android::fs_mgr::Fstab fs_mgr_overlayfs_candidate_list(const android::fs_mgr::Fstab& fstab);

bool fs_mgr_overlayfs_mount_all(android::fs_mgr::Fstab* fstab);
bool fs_mgr_overlayfs_mount_fstab_entry (const std::string& lowers, const std::string& mount_point);
bool fs_mgr_overlayfs_mount_fstab_entry(const android::fs_mgr::FstabEntry& entry);
std::vector<std::string> fs_mgr_overlayfs_required_devices(android::fs_mgr::Fstab* fstab);
bool fs_mgr_overlayfs_setup(const char* backing = nullptr, const char* mount_point = nullptr,
                            bool* change = nullptr, bool force = true);
+7 −7
Original line number Diff line number Diff line
@@ -542,6 +542,7 @@ bool FirstStageMount::MountPartitions() {
            continue;
        }

        // Handle overlayfs entries later.
        if (current->fs_type == "overlay") {
            ++current;
            continue;
@@ -571,6 +572,12 @@ bool FirstStageMount::MountPartitions() {
        current = end;
    }

    for (const auto& entry : fstab_) {
        if (entry.fs_type == "overlay") {
            fs_mgr_overlayfs_mount_fstab_entry(entry);
        }
    }

    // If we don't see /system or / in the fstab, then we need to create an root entry for
    // overlayfs.
    if (!GetEntryForMountPoint(&fstab_, "/system") && !GetEntryForMountPoint(&fstab_, "/")) {
@@ -596,13 +603,6 @@ bool FirstStageMount::MountPartitions() {
    };
    MapScratchPartitionIfNeeded(&fstab_, init_devices);

    for (auto current = fstab_.begin(); current != fstab_.end(); ) {
        if (current->fs_type == "overlay") {
            fs_mgr_overlayfs_mount_fstab_entry(current->lowerdir, current->mount_point);
        }
        ++current;
    }

    fs_mgr_overlayfs_mount_all(&fstab_);

    return true;