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

Commit fac6b4e6 authored by Bowgo Tsai's avatar Bowgo Tsai Committed by android-build-merger
Browse files

Merge "Allow init to skip mounting /product and /product_services" am: 8fe0eb46 am: 8d464e75

am: d3dc311f

Change-Id: Ib33b129bea815a87ebf9ce8c9029537d1a4ba9b3
parents 0f785bcb d3dc311f
Loading
Loading
Loading
Loading
+45 −4
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@
#include "uevent_listener.h"
#include "util.h"

using android::base::ReadFileToString;
using android::base::Split;
using android::base::Timer;
using android::fs_mgr::AvbHandle;
@@ -73,6 +74,8 @@ class FirstStageMount {
    bool CreateLogicalPartitions();
    bool MountPartition(FstabEntry* fstab_entry);
    bool MountPartitions();
    bool TrySwitchSystemAsRoot();
    bool TrySkipMountingPartitions();
    bool IsDmLinearEnabled();
    bool GetDmLinearMetadataDevice();
    bool InitDmLinearBackingDevices(const android::fs_mgr::LpMetadata& metadata);
@@ -398,10 +401,10 @@ bool FirstStageMount::MountPartition(FstabEntry* fstab_entry) {
    return true;
}

bool FirstStageMount::MountPartitions() {
// If system is in the fstab then we're not a system-as-root device, and in
// this case, we mount system first then pivot to it.  From that point on,
// we are effectively identical to a system-as-root device.
bool FirstStageMount::TrySwitchSystemAsRoot() {
    auto system_partition = std::find_if(fstab_.begin(), fstab_.end(), [](const auto& entry) {
        return entry.mount_point == "/system";
    });
@@ -416,6 +419,44 @@ bool FirstStageMount::MountPartitions() {
        fstab_.erase(system_partition);
    }

    return true;
}

// For GSI to skip mounting /product and /product_services, until there are
// well-defined interfaces between them and /system. Otherwise, the GSI flashed
// on /system might not be able to work with /product and /product_services.
// When they're skipped here, /system/product and /system/product_services in
// GSI will be used.
bool FirstStageMount::TrySkipMountingPartitions() {
    constexpr const char kSkipMountConfig[] = "/system/etc/init/config/skip_mount.cfg";

    std::string skip_config;
    if (!ReadFileToString(kSkipMountConfig, &skip_config)) {
        return true;
    }

    for (const auto& skip_mount_point : Split(skip_config, "\n")) {
        if (skip_mount_point.empty()) {
            continue;
        }
        auto removing_entry =
                std::find_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);
            LOG(INFO) << "Skip mounting partition: " << skip_mount_point;
        }
    }

    return true;
}

bool FirstStageMount::MountPartitions() {
    if (!TrySwitchSystemAsRoot()) return false;

    if (!TrySkipMountingPartitions()) return false;

    for (auto& fstab_entry : fstab_) {
        if (!MountPartition(&fstab_entry) && !fstab_entry.fs_mgr_flags.no_fail) {
            return false;