Loading fs_mgr/libfstab/boot_config.cpp +28 −1 Original line number Original line Diff line number Diff line Loading @@ -27,6 +27,33 @@ #include "fstab_priv.h" #include "fstab_priv.h" #include "logging_macros.h" #include "logging_macros.h" namespace android { namespace fs_mgr { const std::string& GetAndroidDtDir() { // Set once and saves time for subsequent calls to this function static const std::string kAndroidDtDir = [] { std::string android_dt_dir; if ((fs_mgr_get_boot_config_from_bootconfig_source("android_dt_dir", &android_dt_dir) || fs_mgr_get_boot_config_from_kernel_cmdline("android_dt_dir", &android_dt_dir)) && !android_dt_dir.empty()) { // Ensure the returned path ends with a / if (android_dt_dir.back() != '/') { android_dt_dir.push_back('/'); } } else { // Fall back to the standard procfs-based path android_dt_dir = "/proc/device-tree/firmware/android/"; } LINFO << "Using Android DT directory " << android_dt_dir; return android_dt_dir; }(); return kAndroidDtDir; } } // namespace fs_mgr } // namespace android std::vector<std::pair<std::string, std::string>> fs_mgr_parse_cmdline(const std::string& cmdline) { std::vector<std::pair<std::string, std::string>> fs_mgr_parse_cmdline(const std::string& cmdline) { static constexpr char quote = '"'; static constexpr char quote = '"'; Loading Loading @@ -145,7 +172,7 @@ bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val) { // firstly, check the device tree // firstly, check the device tree if (is_dt_compatible()) { if (is_dt_compatible()) { std::string file_name = get_android_dt_dir() + "/" + key; std::string file_name = android::fs_mgr::GetAndroidDtDir() + key; if (android::base::ReadFileToString(file_name, out_val)) { if (android::base::ReadFileToString(file_name, out_val)) { if (!out_val->empty()) { if (!out_val->empty()) { out_val->pop_back(); // Trims the trailing '\0' out. out_val->pop_back(); // Trims the trailing '\0' out. Loading fs_mgr/libfstab/fstab.cpp +5 −24 Original line number Original line Diff line number Diff line Loading @@ -51,7 +51,6 @@ namespace android { namespace fs_mgr { namespace fs_mgr { namespace { namespace { constexpr char kDefaultAndroidDtDir[] = "/proc/device-tree/firmware/android"; constexpr char kProcMountsPath[] = "/proc/mounts"; constexpr char kProcMountsPath[] = "/proc/mounts"; struct FlagList { struct FlagList { Loading Loading @@ -337,25 +336,14 @@ bool ParseFsMgrFlags(const std::string& flags, FstabEntry* entry) { return true; return true; } } std::string InitAndroidDtDir() { std::string android_dt_dir; // The platform may specify a custom Android DT path in kernel cmdline if (!fs_mgr_get_boot_config_from_bootconfig_source("android_dt_dir", &android_dt_dir) && !fs_mgr_get_boot_config_from_kernel_cmdline("android_dt_dir", &android_dt_dir)) { // Fall back to the standard procfs-based path android_dt_dir = kDefaultAndroidDtDir; } return android_dt_dir; } bool IsDtFstabCompatible() { bool IsDtFstabCompatible() { std::string dt_value; std::string dt_value; std::string file_name = get_android_dt_dir() + "/fstab/compatible"; std::string file_name = GetAndroidDtDir() + "fstab/compatible"; if (ReadDtFile(file_name, &dt_value) && dt_value == "android,fstab") { if (ReadDtFile(file_name, &dt_value) && dt_value == "android,fstab") { // If there's no status property or its set to "ok" or "okay", then we use the DT fstab. // If there's no status property or its set to "ok" or "okay", then we use the DT fstab. std::string status_value; std::string status_value; std::string status_file_name = get_android_dt_dir() + "/fstab/status"; std::string status_file_name = GetAndroidDtDir() + "fstab/status"; return !ReadDtFile(status_file_name, &status_value) || status_value == "ok" || return !ReadDtFile(status_file_name, &status_value) || status_value == "ok" || status_value == "okay"; status_value == "okay"; } } Loading @@ -368,7 +356,7 @@ std::string ReadFstabFromDt() { return {}; return {}; } } std::string fstabdir_name = get_android_dt_dir() + "/fstab"; std::string fstabdir_name = GetAndroidDtDir() + "fstab"; std::unique_ptr<DIR, int (*)(DIR*)> fstabdir(opendir(fstabdir_name.c_str()), closedir); std::unique_ptr<DIR, int (*)(DIR*)> fstabdir(opendir(fstabdir_name.c_str()), closedir); if (!fstabdir) return {}; if (!fstabdir) return {}; Loading Loading @@ -876,7 +864,7 @@ const FstabEntry* GetEntryForMountPoint(const Fstab* fstab, const std::string& p std::set<std::string> GetBootDevices() { std::set<std::string> GetBootDevices() { // First check bootconfig, then kernel commandline, then the device tree // First check bootconfig, then kernel commandline, then the device tree std::string dt_file_name = get_android_dt_dir() + "/boot_devices"; std::string dt_file_name = GetAndroidDtDir() + "boot_devices"; std::string value; std::string value; if (fs_mgr_get_boot_config_from_bootconfig_source("boot_devices", &value) || if (fs_mgr_get_boot_config_from_bootconfig_source("boot_devices", &value) || fs_mgr_get_boot_config_from_bootconfig_source("boot_device", &value)) { fs_mgr_get_boot_config_from_bootconfig_source("boot_device", &value)) { Loading Loading @@ -948,15 +936,8 @@ bool InRecovery() { } // namespace fs_mgr } // namespace fs_mgr } // namespace android } // namespace android // FIXME: The same logic is duplicated in system/core/init/ const std::string& get_android_dt_dir() { // Set once and saves time for subsequent calls to this function static const std::string kAndroidDtDir = android::fs_mgr::InitAndroidDtDir(); return kAndroidDtDir; } bool is_dt_compatible() { bool is_dt_compatible() { std::string file_name = get_android_dt_dir() + "/compatible"; std::string file_name = android::fs_mgr::GetAndroidDtDir() + "compatible"; std::string dt_value; std::string dt_value; if (android::fs_mgr::ReadDtFile(file_name, &dt_value)) { if (android::fs_mgr::ReadDtFile(file_name, &dt_value)) { if (dt_value == "android,firmware") { if (dt_value == "android,firmware") { Loading fs_mgr/libfstab/fstab_priv.h +0 −1 Original line number Original line Diff line number Diff line Loading @@ -36,7 +36,6 @@ bool fs_mgr_get_boot_config_from_bootconfig(const std::string& bootconfig, const bool fs_mgr_get_boot_config_from_bootconfig_source(const std::string& key, std::string* out_val); bool fs_mgr_get_boot_config_from_bootconfig_source(const std::string& key, std::string* out_val); bool fs_mgr_update_for_slotselect(android::fs_mgr::Fstab* fstab); bool fs_mgr_update_for_slotselect(android::fs_mgr::Fstab* fstab); const std::string& get_android_dt_dir(); bool is_dt_compatible(); bool is_dt_compatible(); namespace android { namespace android { Loading fs_mgr/libfstab/include/fstab/fstab.h +4 −0 Original line number Original line Diff line number Diff line Loading @@ -124,5 +124,9 @@ std::set<std::string> GetBootDevices(); // expected name. // expected name. std::string GetVerityDeviceName(const FstabEntry& entry); std::string GetVerityDeviceName(const FstabEntry& entry); // Returns the Android Device Tree directory as specified in the kernel bootconfig or cmdline. // If the platform does not configure a custom DT path, returns the standard one (based in procfs). const std::string& GetAndroidDtDir(); } // namespace fs_mgr } // namespace fs_mgr } // namespace android } // namespace android init/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -539,6 +539,7 @@ cc_defaults { "libprotobuf-cpp-lite", "libprotobuf-cpp-lite", ], ], static_libs: [ static_libs: [ "libfs_mgr", "libhidl-gen-utils", "libhidl-gen-utils", ], ], } } Loading Loading
fs_mgr/libfstab/boot_config.cpp +28 −1 Original line number Original line Diff line number Diff line Loading @@ -27,6 +27,33 @@ #include "fstab_priv.h" #include "fstab_priv.h" #include "logging_macros.h" #include "logging_macros.h" namespace android { namespace fs_mgr { const std::string& GetAndroidDtDir() { // Set once and saves time for subsequent calls to this function static const std::string kAndroidDtDir = [] { std::string android_dt_dir; if ((fs_mgr_get_boot_config_from_bootconfig_source("android_dt_dir", &android_dt_dir) || fs_mgr_get_boot_config_from_kernel_cmdline("android_dt_dir", &android_dt_dir)) && !android_dt_dir.empty()) { // Ensure the returned path ends with a / if (android_dt_dir.back() != '/') { android_dt_dir.push_back('/'); } } else { // Fall back to the standard procfs-based path android_dt_dir = "/proc/device-tree/firmware/android/"; } LINFO << "Using Android DT directory " << android_dt_dir; return android_dt_dir; }(); return kAndroidDtDir; } } // namespace fs_mgr } // namespace android std::vector<std::pair<std::string, std::string>> fs_mgr_parse_cmdline(const std::string& cmdline) { std::vector<std::pair<std::string, std::string>> fs_mgr_parse_cmdline(const std::string& cmdline) { static constexpr char quote = '"'; static constexpr char quote = '"'; Loading Loading @@ -145,7 +172,7 @@ bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val) { // firstly, check the device tree // firstly, check the device tree if (is_dt_compatible()) { if (is_dt_compatible()) { std::string file_name = get_android_dt_dir() + "/" + key; std::string file_name = android::fs_mgr::GetAndroidDtDir() + key; if (android::base::ReadFileToString(file_name, out_val)) { if (android::base::ReadFileToString(file_name, out_val)) { if (!out_val->empty()) { if (!out_val->empty()) { out_val->pop_back(); // Trims the trailing '\0' out. out_val->pop_back(); // Trims the trailing '\0' out. Loading
fs_mgr/libfstab/fstab.cpp +5 −24 Original line number Original line Diff line number Diff line Loading @@ -51,7 +51,6 @@ namespace android { namespace fs_mgr { namespace fs_mgr { namespace { namespace { constexpr char kDefaultAndroidDtDir[] = "/proc/device-tree/firmware/android"; constexpr char kProcMountsPath[] = "/proc/mounts"; constexpr char kProcMountsPath[] = "/proc/mounts"; struct FlagList { struct FlagList { Loading Loading @@ -337,25 +336,14 @@ bool ParseFsMgrFlags(const std::string& flags, FstabEntry* entry) { return true; return true; } } std::string InitAndroidDtDir() { std::string android_dt_dir; // The platform may specify a custom Android DT path in kernel cmdline if (!fs_mgr_get_boot_config_from_bootconfig_source("android_dt_dir", &android_dt_dir) && !fs_mgr_get_boot_config_from_kernel_cmdline("android_dt_dir", &android_dt_dir)) { // Fall back to the standard procfs-based path android_dt_dir = kDefaultAndroidDtDir; } return android_dt_dir; } bool IsDtFstabCompatible() { bool IsDtFstabCompatible() { std::string dt_value; std::string dt_value; std::string file_name = get_android_dt_dir() + "/fstab/compatible"; std::string file_name = GetAndroidDtDir() + "fstab/compatible"; if (ReadDtFile(file_name, &dt_value) && dt_value == "android,fstab") { if (ReadDtFile(file_name, &dt_value) && dt_value == "android,fstab") { // If there's no status property or its set to "ok" or "okay", then we use the DT fstab. // If there's no status property or its set to "ok" or "okay", then we use the DT fstab. std::string status_value; std::string status_value; std::string status_file_name = get_android_dt_dir() + "/fstab/status"; std::string status_file_name = GetAndroidDtDir() + "fstab/status"; return !ReadDtFile(status_file_name, &status_value) || status_value == "ok" || return !ReadDtFile(status_file_name, &status_value) || status_value == "ok" || status_value == "okay"; status_value == "okay"; } } Loading @@ -368,7 +356,7 @@ std::string ReadFstabFromDt() { return {}; return {}; } } std::string fstabdir_name = get_android_dt_dir() + "/fstab"; std::string fstabdir_name = GetAndroidDtDir() + "fstab"; std::unique_ptr<DIR, int (*)(DIR*)> fstabdir(opendir(fstabdir_name.c_str()), closedir); std::unique_ptr<DIR, int (*)(DIR*)> fstabdir(opendir(fstabdir_name.c_str()), closedir); if (!fstabdir) return {}; if (!fstabdir) return {}; Loading Loading @@ -876,7 +864,7 @@ const FstabEntry* GetEntryForMountPoint(const Fstab* fstab, const std::string& p std::set<std::string> GetBootDevices() { std::set<std::string> GetBootDevices() { // First check bootconfig, then kernel commandline, then the device tree // First check bootconfig, then kernel commandline, then the device tree std::string dt_file_name = get_android_dt_dir() + "/boot_devices"; std::string dt_file_name = GetAndroidDtDir() + "boot_devices"; std::string value; std::string value; if (fs_mgr_get_boot_config_from_bootconfig_source("boot_devices", &value) || if (fs_mgr_get_boot_config_from_bootconfig_source("boot_devices", &value) || fs_mgr_get_boot_config_from_bootconfig_source("boot_device", &value)) { fs_mgr_get_boot_config_from_bootconfig_source("boot_device", &value)) { Loading Loading @@ -948,15 +936,8 @@ bool InRecovery() { } // namespace fs_mgr } // namespace fs_mgr } // namespace android } // namespace android // FIXME: The same logic is duplicated in system/core/init/ const std::string& get_android_dt_dir() { // Set once and saves time for subsequent calls to this function static const std::string kAndroidDtDir = android::fs_mgr::InitAndroidDtDir(); return kAndroidDtDir; } bool is_dt_compatible() { bool is_dt_compatible() { std::string file_name = get_android_dt_dir() + "/compatible"; std::string file_name = android::fs_mgr::GetAndroidDtDir() + "compatible"; std::string dt_value; std::string dt_value; if (android::fs_mgr::ReadDtFile(file_name, &dt_value)) { if (android::fs_mgr::ReadDtFile(file_name, &dt_value)) { if (dt_value == "android,firmware") { if (dt_value == "android,firmware") { Loading
fs_mgr/libfstab/fstab_priv.h +0 −1 Original line number Original line Diff line number Diff line Loading @@ -36,7 +36,6 @@ bool fs_mgr_get_boot_config_from_bootconfig(const std::string& bootconfig, const bool fs_mgr_get_boot_config_from_bootconfig_source(const std::string& key, std::string* out_val); bool fs_mgr_get_boot_config_from_bootconfig_source(const std::string& key, std::string* out_val); bool fs_mgr_update_for_slotselect(android::fs_mgr::Fstab* fstab); bool fs_mgr_update_for_slotselect(android::fs_mgr::Fstab* fstab); const std::string& get_android_dt_dir(); bool is_dt_compatible(); bool is_dt_compatible(); namespace android { namespace android { Loading
fs_mgr/libfstab/include/fstab/fstab.h +4 −0 Original line number Original line Diff line number Diff line Loading @@ -124,5 +124,9 @@ std::set<std::string> GetBootDevices(); // expected name. // expected name. std::string GetVerityDeviceName(const FstabEntry& entry); std::string GetVerityDeviceName(const FstabEntry& entry); // Returns the Android Device Tree directory as specified in the kernel bootconfig or cmdline. // If the platform does not configure a custom DT path, returns the standard one (based in procfs). const std::string& GetAndroidDtDir(); } // namespace fs_mgr } // namespace fs_mgr } // namespace android } // namespace android
init/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -539,6 +539,7 @@ cc_defaults { "libprotobuf-cpp-lite", "libprotobuf-cpp-lite", ], ], static_libs: [ static_libs: [ "libfs_mgr", "libhidl-gen-utils", "libhidl-gen-utils", ], ], } } Loading