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

Commit c89e97f6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "vts_fs_test: checks AVB 1.0 isn't used"

parents f4753d1c 80cb505f
Loading
Loading
Loading
Loading
+28 −28
Original line number Diff line number Diff line
@@ -439,34 +439,6 @@ std::string ReadFstabFromDt() {
    return fstab_result;
}

// Return the path to the fstab file.  There may be multiple fstab files; the
// one that is returned will be the first that exists of fstab.<fstab_suffix>,
// fstab.<hardware>, and fstab.<hardware.platform>.  The fstab is searched for
// in /odm/etc/ and /vendor/etc/, as well as in the locations where it may be in
// the first stage ramdisk during early boot.  Previously, the first stage
// ramdisk's copy of the fstab had to be located in the root directory, but now
// the system/etc directory is supported too and is the preferred location.
std::string GetFstabPath() {
    for (const char* prop : {"fstab_suffix", "hardware", "hardware.platform"}) {
        std::string suffix;

        if (!fs_mgr_get_boot_config(prop, &suffix)) continue;

        for (const char* prefix : {// late-boot/post-boot locations
                                   "/odm/etc/fstab.", "/vendor/etc/fstab.",
                                   // early boot locations
                                   "/system/etc/fstab.", "/first_stage_ramdisk/system/etc/fstab.",
                                   "/fstab.", "/first_stage_ramdisk/fstab."}) {
            std::string fstab_path = prefix + suffix;
            if (access(fstab_path.c_str(), F_OK) == 0) {
                return fstab_path;
            }
        }
    }

    return "";
}

/* Extracts <device>s from the by-name symlinks specified in a fstab:
 *   /dev/block/<type>/<device>/by-name/<partition>
 *
@@ -526,6 +498,34 @@ std::vector<FstabEntry*> GetEntriesByPred(Fstab* fstab, const Pred& pred) {

}  // namespace

// Return the path to the fstab file.  There may be multiple fstab files; the
// one that is returned will be the first that exists of fstab.<fstab_suffix>,
// fstab.<hardware>, and fstab.<hardware.platform>.  The fstab is searched for
// in /odm/etc/ and /vendor/etc/, as well as in the locations where it may be in
// the first stage ramdisk during early boot.  Previously, the first stage
// ramdisk's copy of the fstab had to be located in the root directory, but now
// the system/etc directory is supported too and is the preferred location.
std::string GetFstabPath() {
    for (const char* prop : {"fstab_suffix", "hardware", "hardware.platform"}) {
        std::string suffix;

        if (!fs_mgr_get_boot_config(prop, &suffix)) continue;

        for (const char* prefix : {// late-boot/post-boot locations
                                   "/odm/etc/fstab.", "/vendor/etc/fstab.",
                                   // early boot locations
                                   "/system/etc/fstab.", "/first_stage_ramdisk/system/etc/fstab.",
                                   "/fstab.", "/first_stage_ramdisk/fstab."}) {
            std::string fstab_path = prefix + suffix;
            if (access(fstab_path.c_str(), F_OK) == 0) {
                return fstab_path;
            }
        }
    }

    return "";
}

bool ParseFstabFromString(const std::string& fstab_str, bool proc_mounts, Fstab* fstab_out) {
    const int expected_fields = proc_mounts ? 4 : 5;

+2 −0
Original line number Diff line number Diff line
@@ -95,6 +95,8 @@ using Fstab = std::vector<FstabEntry>;

// Exported for testability. Regular users should use ReadFstabFromFile().
bool ParseFstabFromString(const std::string& fstab_str, bool proc_mounts, Fstab* fstab_out);
// Exported for testability. Regular users should use ReadDefaultFstab().
std::string GetFstabPath();

bool ReadFstabFromFile(const std::string& path, Fstab* fstab);
bool ReadFstabFromDt(Fstab* fstab, bool verbose = true);
+30 −0
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@
#include <gtest/gtest.h>
#include <libdm/dm.h>

using testing::Contains;
using testing::Not;

static int GetVsrLevel() {
    return android::base::GetIntProperty("ro.vendor.api_level", -1);
}
@@ -117,3 +120,30 @@ TEST(fs, NoDtFstab) {
    android::fs_mgr::Fstab fstab;
    EXPECT_FALSE(android::fs_mgr::ReadFstabFromDt(&fstab, false));
}

TEST(fs, NoLegacyVerifiedBoot) {
    if (GetVsrLevel() < __ANDROID_API_T__) {
        GTEST_SKIP();
    }

    const auto& default_fstab_path = android::fs_mgr::GetFstabPath();
    EXPECT_FALSE(default_fstab_path.empty());

    std::string fstab_str;
    EXPECT_TRUE(android::base::ReadFileToString(default_fstab_path, &fstab_str,
                                                /* follow_symlinks = */ true));

    for (const auto& line : android::base::Split(fstab_str, "\n")) {
        auto fields = android::base::Tokenize(line, " \t");
        // Ignores empty lines and comments.
        if (fields.empty() || android::base::StartsWith(fields.front(), '#')) {
            continue;
        }
        // Each line in a fstab should have at least five entries.
        //   <src> <mnt_point> <type> <mnt_flags and options> <fs_mgr_flags>
        ASSERT_GE(fields.size(), 5);
        EXPECT_THAT(android::base::Split(fields[4], ","), Not(Contains("verify")))
                << "AVB 1.0 isn't supported now, but the 'verify' flag is found:\n"
                << "  " << line;
    }
}