Commit 6e8c27a5 authored by Ethan Yonker's avatar Ethan Yonker Committed by Dees Troy

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
parent adcb4d8c
/*update
/*
Copyright 2013 bigbiff/Dees_Troy TeamWin
This file is part of TWRP/TeamWin Recovery Project.
......
......@@ -33,7 +33,6 @@
#include <sys/mount.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
extern "C"
{
......@@ -79,6 +78,8 @@ int gGuiRunning = 0;
int g_pty_fd = -1; // set by terminal on init
void terminal_pty_read();
int select_fd = 0;
static int gRecorder = -1;
extern "C" void gr_write_frame_to_file(int fd);
......@@ -395,9 +396,18 @@ void InputHandler::handleDrag()
}
}
void set_select_fd() {
select_fd = ors_read_fd + 1;
if (g_pty_fd >= select_fd)
select_fd = g_pty_fd + 1;
if (PartitionManager.uevent_pfd.fd >= select_fd)
select_fd = PartitionManager.uevent_pfd.fd + 1;
}
static void setup_ors_command()
{
ors_read_fd = -1;
set_select_fd();
unlink(ORS_INPUT_FILE);
if (mkfifo(ORS_INPUT_FILE, 06660) != 0) {
......@@ -417,6 +427,7 @@ static void setup_ors_command()
unlink(ORS_INPUT_FILE);
unlink(ORS_OUTPUT_FILE);
}
set_select_fd();
}
// callback called after a CLI command was executed
......@@ -448,6 +459,7 @@ static void ors_command_read()
if (!orsout) {
close(ors_read_fd);
ors_read_fd = -1;
set_select_fd();
LOGINFO("Unable to fopen %s\n", ORS_OUTPUT_FILE);
unlink(ORS_INPUT_FILE);
unlink(ORS_OUTPUT_FILE);
......@@ -554,29 +566,30 @@ static int runPages(const char *page_name, const int stop_on_page_done)
for (;;)
{
loopTimer(input_timeout_ms);
FD_ZERO(&fdset);
timeout.tv_sec = 0;
timeout.tv_usec = 1;
if (g_pty_fd > 0) {
// TODO: this is not nice, we should have one central select for input, pty, and ors
FD_ZERO(&fdset);
FD_SET(g_pty_fd, &fdset);
timeout.tv_sec = 0;
timeout.tv_usec = 1;
has_data = select(g_pty_fd+1, &fdset, NULL, NULL, &timeout);
if (has_data > 0) {
terminal_pty_read();
}
}
if (PartitionManager.uevent_pfd.fd > 0) {
FD_SET(PartitionManager.uevent_pfd.fd, &fdset);
}
#ifndef TW_OEM_BUILD
if (ors_read_fd > 0 && !orsout) { // orsout is non-NULL if a command is still running
FD_ZERO(&fdset);
FD_SET(ors_read_fd, &fdset);
timeout.tv_sec = 0;
timeout.tv_usec = 1;
has_data = select(ors_read_fd+1, &fdset, NULL, NULL, &timeout);
if (has_data > 0) {
ors_command_read();
}
}
#endif
// TODO: combine this select with the poll done by input handling
has_data = select(select_fd, &fdset, NULL, NULL, &timeout);
if (has_data > 0) {
if (g_pty_fd > 0 && FD_ISSET(g_pty_fd, &fdset))
terminal_pty_read();
if (PartitionManager.uevent_pfd.fd > 0 && FD_ISSET(PartitionManager.uevent_pfd.fd, &fdset))
PartitionManager.read_uevent();
if (ors_read_fd > 0 && !orsout && FD_ISSET(ors_read_fd, &fdset))
ors_command_read();
}
if (!gForceRender.get_value())
{
......@@ -636,6 +649,7 @@ static int runPages(const char *page_name, const int stop_on_page_done)
if (ors_read_fd > 0)
close(ors_read_fd);
ors_read_fd = -1;
set_select_fd();
gGuiRunning = 0;
return 0;
}
......
......@@ -21,6 +21,8 @@
#include "twmsg.h"
void set_select_fd();
void gui_msg(const char* text);
void gui_warn(const char* text);
void gui_err(const char* text);
......
......@@ -34,6 +34,7 @@ extern "C" {
#include "../twcommon.h"
}
#include "../minuitwrp/minui.h"
#include "gui.hpp"
#include "rapidxml.hpp"
#include "objects.hpp"
......@@ -83,6 +84,7 @@ public:
// and write it to the terminal
// this currently works through gui.cpp calling terminal_pty_read below
g_pty_fd = fdMaster;
set_select_fd();
return true;
}
else {
......@@ -174,6 +176,7 @@ public:
}
close(fdMaster);
g_pty_fd = fdMaster = -1;
set_select_fd();
int status;
waitpid(pid, &status, WNOHANG); // avoid zombies but don't hang if the child is still alive and we got here due to some error
pid = 0;
......
......@@ -30,6 +30,7 @@
<string name="sdext">SD-EXT</string>
<string name="adopted_data">Adopted Data</string>
<string name="adopted_storage">Adopted Storage</string>
<string name="autostorage">Storage</string>
<!-- GUI XML strings -->
<string name="twrp_header">Team Win Recovery Project</string>
......
......@@ -25,8 +25,8 @@
struct mtpmsg {
int message_type; // 1 is add, 2 is remove, see above
unsigned int storage_id;
const char* display;
const char* path;
char display[1024];
char path[1024];
uint64_t maxFileSize;
};
......
......@@ -170,7 +170,7 @@ int twmtp_MtpServer::mtppipe_thread(void)
if (mtp_message.storage_id) {
long reserveSpace = 1;
bool removable = false;
MtpStorage* storage = new MtpStorage(mtp_message.storage_id, mtp_message.path, mtp_message.display, reserveSpace, removable, mtp_message.maxFileSize, refserver);
MtpStorage* storage = new MtpStorage(mtp_message.storage_id, &mtp_message.path[0], &mtp_message.display[0], reserveSpace, removable, mtp_message.maxFileSize, refserver);
server->addStorage(storage);
MTPD("mtppipe done adding storage\n");
} else {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -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());
}
......
......@@ -47,9 +47,9 @@ enum Archive_Type {
class TWFunc
{
public:
static string Get_Root_Path(string Path); // Trims any trailing folders or filenames from the path, also adds a leading / if not present
static string Get_Path(string Path); // Trims everything after the last / in the string
static string Get_Filename(string Path); // Trims the path off of a filename
static string Get_Root_Path(const string& Path); // Trims any trailing folders or filenames from the path, also adds a leading / if not present
static string Get_Path(const string& Path); // Trims everything after the last / in the string
static string Get_Filename(const string& Path); // Trims the path off of a filename
static int Exec_Cmd(const string& cmd, string &result); //execute a command and return the result as a string by reference
static int Exec_Cmd(const string& cmd); //execute a command
......@@ -82,7 +82,7 @@ public:
static int read_file(string fn, vector<string>& results); //read from file
static int read_file(string fn, string& results); //read from file
static int read_file(string fn, uint64_t& results); //read from file
static int write_file(string fn, string& line); //write from file
static int write_to_file(const string& fn, const string& line); //write to file
static bool Install_SuperSU(void); // Installs su binary and apk and sets proper permissions
static bool Try_Decrypting_Backup(string Restore_Path, string Password); // true for success, false for failed to decrypt
static string System_Property_Get(string Prop_Name); // Returns value of Prop_Name from reading /system/build.prop
......
......@@ -157,7 +157,7 @@ bool twrpDigestDriver::Write_Digest(string Full_Filename) {
digest_str = digest_str + " " + TWFunc::Get_Filename(Full_Filename) + "\n";
LOGINFO("digest_filename: %s\n", digest_filename.c_str());
if (TWFunc::write_file(digest_filename, digest_str) == 0) {
if (TWFunc::write_to_file(digest_filename, digest_str) == 0) {
tw_set_default_metadata(digest_filename.c_str());
gui_msg("digest_created= * Digest Created.");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment