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

Commit 82b8e518 authored by Tom Cherry's avatar Tom Cherry Committed by Gerrit Code Review
Browse files

Merge "Support mounting same mount points with different fstab config"

parents 37b5edf6 01cf85bd
Loading
Loading
Loading
Loading
+43 −16
Original line number Diff line number Diff line
@@ -414,16 +414,32 @@ bool FirstStageMount::TrySwitchSystemAsRoot() {
        return entry.mount_point == "/system";
    });

    if (system_partition != fstab_.end()) {
        if (!MountPartition(&(*system_partition))) {
            return false;
        }
    if (system_partition == fstab_.end()) return true;

        SwitchRoot((*system_partition).mount_point);
    bool mounted = false;
    bool no_fail = false;
    for (auto it = system_partition; it != fstab_.end();) {
        if (it->mount_point != "/system") {
            break;
        }
        no_fail |= (it->fs_mgr_flags).no_fail;
        if (MountPartition(&(*it))) {
            mounted = true;
            SwitchRoot("/system");
            break;
        }
        it++;
    }

        fstab_.erase(system_partition);
    if (!mounted && !no_fail) {
        LOG(ERROR) << "Failed to mount /system";
        return false;
    }

    auto it = std::remove_if(fstab_.begin(), fstab_.end(),
                             [](const auto& entry) { return entry.mount_point == "/system"; });
    fstab_.erase(it, fstab_.end());

    return true;
}

@@ -444,15 +460,13 @@ bool FirstStageMount::TrySkipMountingPartitions() {
        if (skip_mount_point.empty()) {
            continue;
        }
        auto removing_entry =
                std::find_if(fstab_.begin(), fstab_.end(), [&skip_mount_point](const auto& entry) {
        auto it = std::remove_if(fstab_.begin(), fstab_.end(),
                                 [&skip_mount_point](const auto& entry) {
                                     return entry.mount_point == skip_mount_point;
                                 });
        if (removing_entry != fstab_.end()) {
            fstab_.erase(removing_entry);
        fstab_.erase(it, fstab_.end());
        LOG(INFO) << "Skip mounting partition: " << skip_mount_point;
    }
    }

    return true;
}
@@ -462,8 +476,21 @@ bool FirstStageMount::MountPartitions() {

    if (!TrySkipMountingPartitions()) return false;

    for (auto& fstab_entry : fstab_) {
        if (!MountPartition(&fstab_entry) && !fstab_entry.fs_mgr_flags.no_fail) {
    for (auto it = fstab_.begin(); it != fstab_.end();) {
        bool mounted = false;
        bool no_fail = false;
        auto start_mount_point = it->mount_point;
        do {
            no_fail |= (it->fs_mgr_flags).no_fail;
            if (!mounted)
                mounted = MountPartition(&(*it));
            else
                LOG(INFO) << "Skip already-mounted partition: " << start_mount_point;
            it++;
        } while (it != fstab_.end() && it->mount_point == start_mount_point);

        if (!mounted && !no_fail) {
            LOG(ERROR) << start_mount_point << " mounted unsuccessfully but it is required!";
            return false;
        }
    }