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

Commit e24c57b3 authored by Dan Pasanen's avatar Dan Pasanen Committed by Alessandro Astone
Browse files

fs_mgr: autodetect filesystem type

* Multiple fstab lines (supported in android) cause recovery to fail
  to mount partitions if the fs type is not the same as the first
  fstab entry. So when we attempt to find an fstab entry, check it
  against blkid's determination of what filesystem type it is.

* If blkid fails, or if no entry matches the detected fs type,
  return the first found.

[yodevil: revamped for Q]
Change-Id: I7b720b534185fc7cb3860833aa49f748e02e3f6c
parent 052679ba
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -105,6 +105,10 @@ cc_library_static {
        "fs_mgr_boot_config.cpp",
        "fs_mgr_slotselect.cpp",
    ],
    whole_static_libs: [
        "libext2_blkid",
        "libext2_uuid",
    ],
    target: {
        darwin: {
            enabled: false,
+23 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include <android-base/parseint.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <blkid/blkid.h>
#include <libgsi/libgsi.h>

#include "fs_mgr_priv.h"
@@ -770,6 +771,28 @@ FstabEntry* GetEntryForMountPoint(Fstab* fstab, const std::string& path) {
    return nullptr;
}

FstabEntry* GetEntryForMountPointTryDetectFs(Fstab* fstab, const std::string& path) {
    if (fstab == nullptr) {
        return nullptr;
    }
    FstabEntry* found = GetEntryForMountPoint(fstab, path);
    if (found == nullptr) {
        return nullptr;
    }

    if (char* detected_fs_type = blkid_get_tag_value(nullptr, "TYPE", found->blk_device.c_str())) {
        for (auto& entry : *fstab) {
            if (entry.mount_point == path && entry.fs_type == detected_fs_type) {
                found = &entry;
                break;
            }
        }
        free(detected_fs_type);
    }

    return found;
}

std::set<std::string> GetBootDevices() {
    // First check the kernel commandline, then try the device tree otherwise
    std::string dt_file_name = get_android_dt_dir() + "/boot_devices";
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ FstabEntry* GetEntryForPath(Fstab* fstab, const std::string& path) {
    if (path.empty()) return nullptr;
    std::string str(path);
    while (true) {
        auto entry = GetEntryForMountPoint(fstab, str);
        auto entry = GetEntryForMountPointTryDetectFs(fstab, str);
        if (entry != nullptr) return entry;
        if (str == "/") break;
        auto slash = str.find_last_of('/');
+1 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ bool ReadDefaultFstab(Fstab* fstab);
bool SkipMountingPartitions(Fstab* fstab);

FstabEntry* GetEntryForMountPoint(Fstab* fstab, const std::string& path);
FstabEntry* GetEntryForMountPointTryDetectFs(Fstab* fstab, const std::string& path);

// Helper method to build a GSI fstab entry for mounting /system.
FstabEntry BuildGsiSystemFstabEntry();