From 6e8c27a52b67e3474936113f897f309a0091910a Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Thu, 22 Dec 2016 17:55:57 -0600 Subject: Support v2 fstab format Auto detect and support both the v1 and v2 fstab formats Support putting TWRP style flags in a separate /etc/twrp.flags file twrp.flags format is the same as twrp.fstab (v1 with TWRP flags) Support using a wildcard in a block device and find all partitions: /usb-otg vfat /dev/block/sda* Support using sysfs entries (voldmanaged) and read uevents and scan for wildcard partitions from uevent data. (twvold?) May not be complete for some of the newer flags found in fstabs in newer build trees and there is a slim chance of a crash if the user removes a removable device while TWRP is performing actions. May need to add some kind of mutex to prevent the 2 threads from causing this crash. We need to start somewhere though and this change is pretty innocuous when not using a v2 fstab. Change-Id: I617d97c7db332cbe671a9d2b8ad98b3d9c4f03cc --- twrp-functions.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'twrp-functions.cpp') diff --git a/twrp-functions.cpp b/twrp-functions.cpp index d7c9c2cab..5df44c69a 100644 --- a/twrp-functions.cpp +++ b/twrp-functions.cpp @@ -97,7 +97,7 @@ int TWFunc::Exec_Cmd(const string& cmd) { } // Returns "file.name" from a full /path/to/file.name -string TWFunc::Get_Filename(string Path) { +string TWFunc::Get_Filename(const string& Path) { size_t pos = Path.find_last_of("/"); if (pos != string::npos) { string Filename; @@ -108,7 +108,7 @@ string TWFunc::Get_Filename(string Path) { } // Returns "/path/to/" from a full /path/to/file.name -string TWFunc::Get_Path(string Path) { +string TWFunc::Get_Path(const string& Path) { size_t pos = Path.find_last_of("/"); if (pos != string::npos) { string Pathonly; @@ -390,7 +390,7 @@ int32_t TWFunc::timespec_diff_ms(timespec& start, timespec& end) #ifndef BUILD_TWRPTAR_MAIN // Returns "/path" from a full /path/to/file.name -string TWFunc::Get_Root_Path(string Path) { +string TWFunc::Get_Root_Path(const string& Path) { string Local_Path = Path; // Make sure that we have a leading slash @@ -567,7 +567,7 @@ void TWFunc::Update_Log_File(void) { void TWFunc::Update_Intent_File(string Intent) { if (PartitionManager.Mount_By_Path("/cache", false) && !Intent.empty()) { - TWFunc::write_file("/cache/recovery/intent", Intent); + TWFunc::write_to_file("/cache/recovery/intent", Intent); } } @@ -759,7 +759,7 @@ int TWFunc::read_file(string fn, uint64_t& results) { return -1; } -int TWFunc::write_file(string fn, string& line) { +int TWFunc::write_to_file(const string& fn, const string& line) { FILE *file; file = fopen(fn.c_str(), "w"); if (file != NULL) { @@ -1042,11 +1042,11 @@ int TWFunc::Set_Brightness(std::string brightness_value) if (DataManager::GetIntValue("tw_has_brightnesss_file")) { LOGINFO("TWFunc::Set_Brightness: Setting brightness control to %s\n", brightness_value.c_str()); - result = TWFunc::write_file(DataManager::GetStrValue("tw_brightness_file"), brightness_value); + result = TWFunc::write_to_file(DataManager::GetStrValue("tw_brightness_file"), brightness_value); DataManager::GetValue("tw_secondary_brightness_file", secondary_brightness_file); if (!secondary_brightness_file.empty()) { LOGINFO("TWFunc::Set_Brightness: Setting secondary brightness control to %s\n", brightness_value.c_str()); - TWFunc::write_file(secondary_brightness_file, brightness_value); + TWFunc::write_to_file(secondary_brightness_file, brightness_value); } } return result; @@ -1123,7 +1123,7 @@ void TWFunc::copy_kernel_log(string curr_storage) { std::string result; Exec_Cmd(dmesgCmd, result); - write_file(dmesgDst, result); + write_to_file(dmesgDst, result); gui_msg(Msg("copy_kernel_log=Copied kernel log to {1}")(dmesgDst)); tw_set_default_metadata(dmesgDst.c_str()); } -- cgit v1.2.3