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

Commit 92314fef authored by Jiakai Zhang's avatar Jiakai Zhang Committed by Automerger Merge Worker
Browse files

Merge "Add a variant of ReadFstabFromFile for /proc/mounts." am: f43e20c9 am: d1c16f4d

parents b8d0423f d1c16f4d
Loading
Loading
Loading
Loading
+24 −11
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ namespace fs_mgr {
namespace {

constexpr char kDefaultAndroidDtDir[] = "/proc/device-tree/firmware/android";
constexpr char kProcMountsPath[] = "/proc/mounts";

struct FlagList {
    const char *name;
@@ -699,9 +700,7 @@ void EnableMandatoryFlags(Fstab* fstab) {
    }
}

bool ReadFstabFromFile(const std::string& path, Fstab* fstab_out) {
    const bool is_proc_mounts = (path == "/proc/mounts");

static bool ReadFstabFromFileCommon(const std::string& path, Fstab* fstab_out) {
    std::string fstab_str;
    if (!android::base::ReadFileToString(path, &fstab_str, /* follow_symlinks = */ true)) {
        PERROR << __FUNCTION__ << "(): failed to read file: '" << path << "'";
@@ -709,11 +708,22 @@ bool ReadFstabFromFile(const std::string& path, Fstab* fstab_out) {
    }

    Fstab fstab;
    if (!ParseFstabFromString(fstab_str, is_proc_mounts, &fstab)) {
    if (!ParseFstabFromString(fstab_str, path == kProcMountsPath, &fstab)) {
        LERROR << __FUNCTION__ << "(): failed to load fstab from : '" << path << "'";
        return false;
    }
    if (!is_proc_mounts) {

    EnableMandatoryFlags(&fstab);

    *fstab_out = std::move(fstab);
    return true;
}

bool ReadFstabFromFile(const std::string& path, Fstab* fstab) {
    if (!ReadFstabFromFileCommon(path, fstab)) {
        return false;
    }
    if (path != kProcMountsPath) {
        if (!access(android::gsi::kGsiBootedIndicatorFile, F_OK)) {
            std::string dsu_slot;
            if (!android::gsi::GetActiveDsu(&dsu_slot)) {
@@ -725,20 +735,23 @@ bool ReadFstabFromFile(const std::string& path, Fstab* fstab_out) {
                PERROR << __FUNCTION__ << "(): failed to read DSU LP names";
                return false;
            }
            TransformFstabForDsu(&fstab, dsu_slot, Split(lp_names, ","));
            TransformFstabForDsu(fstab, dsu_slot, Split(lp_names, ","));
        } else if (errno != ENOENT) {
            PERROR << __FUNCTION__ << "(): failed to access() DSU booted indicator";
            return false;
        }
    }

    SkipMountingPartitions(&fstab, false /* verbose */);
    EnableMandatoryFlags(&fstab);

    *fstab_out = std::move(fstab);
        SkipMountingPartitions(fstab, false /* verbose */);
    }
    return true;
}

bool ReadFstabFromProcMounts(Fstab* fstab) {
    // Don't call `ReadFstabFromFile` because the code for `path != kProcMountsPath` has an extra
    // code size cost, even if it's never executed.
    return ReadFstabFromFileCommon(kProcMountsPath, fstab);
}

// Returns fstab entries parsed from the device tree if they exist
bool ReadFstabFromDt(Fstab* fstab, bool verbose) {
    std::string fstab_buf = ReadFstabFromDt();
+1 −0
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@ std::string GetFstabPath();
bool SkipMountWithConfig(const std::string& skip_config, Fstab* fstab, bool verbose);

bool ReadFstabFromFile(const std::string& path, Fstab* fstab);
bool ReadFstabFromProcMounts(Fstab* fstab);
bool ReadFstabFromDt(Fstab* fstab, bool verbose = true);
bool ReadDefaultFstab(Fstab* fstab);
bool SkipMountingPartitions(Fstab* fstab, bool verbose = false);