Skip to content

Commit

Permalink
Add settings to enable/disable f2fs forcing mode so we can switch on …
Browse files Browse the repository at this point in the history
…the fly. Force will force all wipe/format calls to use f2fs or ext4 depending on the selection. Also added code to ensure settings are re-written back to internal sd after a super wipe. Also removed fstab code to determine the mode since we now have a setting for it
  • Loading branch information
ktoonsez committed May 4, 2014
1 parent ecd4600 commit e71ab1e
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 56 deletions.
16 changes: 5 additions & 11 deletions data.cpp
Expand Up @@ -585,13 +585,8 @@ void DataManager::SetDefaultValues()
mConstValues.insert(make_pair("true", "1"));
mConstValues.insert(make_pair("false", "0"));

if (Foundf2fsInitialized)
{
if (Foundf2fs)
mConstValues.insert(make_pair(TW_VERSION_VAR, TW_VERSION_STR_F2FS));
else
mConstValues.insert(make_pair(TW_VERSION_VAR, TW_VERSION_STR_EXT4));
}
mConstValues.insert(make_pair(TW_VERSION_VAR, TW_VERSION_STR));

mValues.insert(make_pair("tw_storage_path", make_pair("/", 1)));
mValues.insert(make_pair("tw_button_vibrate", make_pair("80", 1)));
mValues.insert(make_pair("tw_keyboard_vibrate", make_pair("40", 1)));
Expand Down Expand Up @@ -926,6 +921,8 @@ void DataManager::SetDefaultValues()
mValues.insert(make_pair(TW_ZIP_QUEUE_COUNT, make_pair("0", 0)));
mValues.insert(make_pair(TW_FILENAME, make_pair("/sdcard", 0)));
mValues.insert(make_pair(TW_SIMULATE_ACTIONS, make_pair("0", 1)));
mValues.insert(make_pair(TW_FORCE_F2FS, make_pair("0", 1)));
mValues.insert(make_pair(TW_FORCE_F2FS_SYSTEM, make_pair("0", 1)));
mValues.insert(make_pair(TW_SIMULATE_FAIL, make_pair("0", 1)));
mValues.insert(make_pair(TW_IS_ENCRYPTED, make_pair("0", 0)));
mValues.insert(make_pair(TW_IS_DECRYPTED, make_pair("0", 0)));
Expand Down Expand Up @@ -1092,10 +1089,7 @@ void DataManager::Output_Version(void)
LOGERR("Unable to open '%s'.\n", Path.c_str());
return;
}
if (Foundf2fs)
strcpy(version, TW_VERSION_STR_F2FS);
else
strcpy(version, TW_VERSION_STR_EXT4);
strcpy(version, TW_VERSION_STR);

fwrite(version, sizeof(version[0]), strlen(version) / sizeof(version[0]), fp);
fclose(fp);
Expand Down
24 changes: 18 additions & 6 deletions gui/action.cpp
Expand Up @@ -832,21 +832,33 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
}
} else
ret_val = PartitionManager.Wipe_By_Path(arg);
#ifdef TW_OEM_BUILD
if (arg == DataManager::GetSettingsStoragePath()) {
//#ifdef TW_OEM_BUILD
/******* BIG monster hack to insure options get re-written after SD wipe *******/
if (arg == "DATAMEDIA") {
// If we wiped the settings storage path, recreate the TWRP folder and dump the settings
string Storage_Path = DataManager::GetSettingsStoragePath();

string Storage_Path = "/data/media/0"; //DataManager::GetSettingsStoragePath();
gui_print("Making TWRP folder and saving settings. %s - %s\n", arg.c_str(), Storage_Path.c_str());

PartitionManager.UnMount_By_Path(Storage_Path, true);
PartitionManager.Wipe_Media_From_Data();
PartitionManager.UnMount_By_Path(Storage_Path, true);
//mkdir("/data", 0777);
//mkdir("/data/media", 0777);
if (PartitionManager.Mount_By_Path(Storage_Path, true)) {
mkdir("/data/media/0", 0770);
mkdir("/data/media/0/TWRP", 0775);
PartitionManager.UnMount_By_Path(Storage_Path, true);
PartitionManager.Mount_By_Path(Storage_Path, true);
gui_print("MOUNTED - Making TWRP folder and saving settings. %s - %s\n", arg.c_str(), Storage_Path.c_str());
LOGINFO("Making TWRP folder and saving settings.\n");
Storage_Path += "/TWRP";
mkdir(Storage_Path.c_str(), 0777);
DataManager::Flush();
} else {
LOGERR("Unable to recreate TWRP folder and save settings.\n");
}
}
#endif

//#endif
}
PartitionManager.Update_System_Details();
if (ret_val)
Expand Down
44 changes: 42 additions & 2 deletions gui/devices/1080x1920/res/ui.xml
Expand Up @@ -44,6 +44,7 @@

<variables>
<variable name="col1_x" value="10" />
<variable name="col1_x_indent" value="70" />
<variable name="col2_x" value="565" />
<variable name="col_center_x" value="288" />
<variable name="col_center_medium_x" value="414" />
Expand Down Expand Up @@ -98,6 +99,7 @@
<variable name="slider_text_y" value="1676" />
<variable name="button_text_color" value="#AAAAAA" />
<variable name="text_color" value="#FFFFFF" />
<variable name="text_color_red" value="#BB0000" />
<variable name="text_success_color" value="#33B5E5" />
<variable name="text_fail_color" value="#FF0101" />
<variable name="highlight_color" value="#90909080" />
Expand Down Expand Up @@ -209,9 +211,30 @@
</object>

<object type="text" color="%text_color%">
<condition var1="tw_force_f2fs" var2="0" />
<font resource="font" />
<placement x="180" y="15" />
<text>Team Win Recovery Project v%tw_version%</text>
<text>Team Win Recovery Project v%tw_version%EXT4</text>
</object>

<object type="text" color="%text_color_red%">
<conditions>
<condition var1="tw_force_f2fs" var2="1" />
<condition var1="tw_force_f2fs_system" var2="0" />
</conditions>
<font resource="font" />
<placement x="180" y="15" />
<text>Team Win Recovery Project v%tw_version%F2FS</text>
</object>

<object type="text" color="%text_color_red%">
<conditions>
<condition var1="tw_force_f2fs" var2="1" />
<condition var1="tw_force_f2fs_system" var2="1" />
</conditions>
<font resource="font" />
<placement x="180" y="15" />
<text>Team Win Recovery Project v%tw_version%F2FS+S</text>
</object>

<object type="text" color="%text_color%">
Expand Down Expand Up @@ -2438,14 +2461,31 @@
<object type="checkbox">
<placement x="%col1_x%" y="%row6_text_y%" />
<font resource="font" color="%text_color%" />
<text>Force data and cache wipe functions to use F2FS.</text>
<data variable="tw_force_f2fs" />
<image checked="checkbox_true" unchecked="checkbox_false" />
</object>

<object type="checkbox">
<condition var1="tw_force_f2fs" var2="1" />
<placement x="%col1_x_indent%" y="%row7_text_y%" />
<font resource="font" color="%text_color%" />
<text>Include system partition.</text>
<data variable="tw_force_f2fs_system" />
<image checked="checkbox_true" unchecked="checkbox_false" />
</object>

<object type="checkbox">
<placement x="%col1_x%" y="%row8_text_y%" />
<font resource="font" color="%text_color%" />
<text>Simulate actions for theme testing.</text>
<data variable="tw_simulate_actions" />
<image checked="checkbox_true" unchecked="checkbox_false" />
</object>

<object type="checkbox">
<condition var1="tw_simulate_actions" var2="1" />
<placement x="%col1_x%" y="%row7_text_y%" />
<placement x="%col1_x%" y="%row9_text_y%" />
<font resource="font" color="%text_color%" />
<text>Simulate failure for actions.</text>
<data variable="tw_simulate_fail" />
Expand Down
22 changes: 5 additions & 17 deletions gui/gui.cpp
Expand Up @@ -670,26 +670,14 @@ std::string gui_parse_text(string inText)
extern "C" int gui_init(void)
{
int fd;

gr_init();

if (Foundf2fs)
if (res_create_surface("/res/images/curtain.f2fs.jpg", &gCurtain))
{
if (res_create_surface("/res/images/curtain.f2fs.jpg", &gCurtain))
{
printf
("Unable to locate '/res/images/curtain.f2fs.jpg'\nDid you set a DEVICE_RESOLUTION in your config files?\n");
return -1;
}
}
else
{
if (res_create_surface("/res/images/curtain.ext4.jpg", &gCurtain))
{
printf
("Unable to locate '/res/images/curtain.ext4.jpg'\nDid you set a DEVICE_RESOLUTION in your config files?\n");
return -1;
}
printf
("Unable to locate '/res/images/curtain.f2fs.jpg'\nDid you set a DEVICE_RESOLUTION in your config files?\n");
return -1;
}

curtainSet();
Expand Down
29 changes: 29 additions & 0 deletions partition.cpp
Expand Up @@ -1083,6 +1083,8 @@ bool TWPartition::UnMount(bool Display_Error) {
bool TWPartition::Wipe(string New_File_System) {
bool wiped = false, update_crypt = false;
int check;
int forcef2fs;
int forcef2fs_sys;
string Layout_Filename = Mount_Point + "/.layout_version";

if (!Can_Be_Wiped) {
Expand All @@ -1100,6 +1102,33 @@ bool TWPartition::Wipe(string New_File_System) {
}
#endif

DataManager::GetValue(TW_FORCE_F2FS, forcef2fs);
DataManager::GetValue(TW_FORCE_F2FS_SYSTEM, forcef2fs_sys);
if (forcef2fs)
{
if ((Mount_Point == "/system" && forcef2fs_sys) || Mount_Point == "/cache" || Mount_Point == "/data")
{
gui_print("Forcing f2fs wipe!\n");
LOGINFO("Forcing f2fs wipe on '%s'!\n", Display_Name.c_str());
New_File_System = "f2fs";
}
else if (Mount_Point == "/system" && !forcef2fs_sys)
{
gui_print("Forcing ext4 wipe!\n");
LOGINFO("Forcing ext4 wipe on '%s'!\n", Display_Name.c_str());
New_File_System = "ext4";
}
}
else
{
if (Mount_Point == "/system" || Mount_Point == "/cache" || Mount_Point == "/data")
{
gui_print("Forcing ext4 wipe!\n");
LOGINFO("Forcing ext4 wipe on '%s'!\n", Display_Name.c_str());
New_File_System = "ext4";
}
}

if (Retain_Layout_Version && Mount(false) && TWFunc::Path_Exists(Layout_Filename))
TWFunc::copy_file(Layout_Filename, "/.layout_version", 0600);
else
Expand Down
5 changes: 0 additions & 5 deletions partitionmanager.cpp
Expand Up @@ -267,11 +267,6 @@ void TWPartitionManager::Output_Partition(TWPartition* Part) {
if (Part->Mount_Flags || !Part->Mount_Options.empty())
printf(" Mount_Flags=0x%8x, Mount_Options=%s\n", Part->Mount_Flags, Part->Mount_Options.c_str());

if (!Part->Fstab_File_System.empty())
{
if (strncmp(Part->Fstab_File_System.c_str(), "f2fs", 4) == 0 && !Foundf2fs)
Foundf2fs = true;
}
}

int TWPartitionManager::Mount_By_Path(string Path, bool Display_Error) {
Expand Down
27 changes: 14 additions & 13 deletions twrp.cpp
Expand Up @@ -51,9 +51,6 @@ extern "C" {
struct selabel_handle *selinux_handle;
#endif

bool Foundf2fs = false;
bool Foundf2fsInitialized = false;

TWPartitionManager PartitionManager;
int Log_Offset;
twrpDU du;
Expand All @@ -65,6 +62,8 @@ static void Print_Prop(const char *key, const char *name, void *cookie) {
int main(int argc, char **argv) {
// Recovery needs to install world-readable files, so clear umask
// set by init
int forcef2fs;
int forcef2fs_sys;
umask(0);

Log_Offset = 0;
Expand All @@ -83,6 +82,11 @@ int main(int argc, char **argv) {

time_t StartupTime = time(NULL);

DataManager::SetDefaultValues();
printf("Starting the UI...");
printf("=> Linking mtab\n");
gui_init();

// Load default values to set DataManager constants and handle ifdefs
symlink("/proc/mounts", "/etc/mtab");
if (TWFunc::Path_Exists("/etc/twrp.fstab")) {
Expand All @@ -100,17 +104,8 @@ int main(int argc, char **argv) {
}

PartitionManager.Output_Partition_Logging();
Foundf2fsInitialized = true;

if (Foundf2fs)
printf("Starting TWRP %s on %s", TW_VERSION_STR_F2FS, ctime(&StartupTime));
else
printf("Starting TWRP %s on %s", TW_VERSION_STR_EXT4, ctime(&StartupTime));

DataManager::SetDefaultValues();
printf("Starting the UI...");
printf("=> Linking mtab\n");
gui_init();
printf("Starting TWRP %s on %s", TW_VERSION_STR, ctime(&StartupTime));

// Load up all the resources
gui_loadResources();
Expand Down Expand Up @@ -275,6 +270,12 @@ int main(int argc, char **argv) {

// Read the settings file
DataManager::ReadSettingsFile();
DataManager::GetValue(TW_FORCE_F2FS, forcef2fs);
DataManager::GetValue(TW_FORCE_F2FS_SYSTEM, forcef2fs_sys);
if (forcef2fs && forcef2fs_sys)
gui_print("F2FS mode for data, cache and system is enabled!\n");
else if (forcef2fs && !forcef2fs_sys)
gui_print("F2FS mode for data and cache is enabled!\n");

// Fixup the RTC clock on devices which require it
TWFunc::Fixup_Time_On_Boot();
Expand Down
5 changes: 3 additions & 2 deletions variables.h
Expand Up @@ -17,8 +17,7 @@
#ifndef _VARIABLES_HEADER_
#define _VARIABLES_HEADER_

#define TW_VERSION_STR_EXT4 "2.7.0.1.EXT4"
#define TW_VERSION_STR_F2FS "2.7.0.1.F2FS"
#define TW_VERSION_STR "2.7.0.5."

#define TW_USE_COMPRESSION_VAR "tw_use_compression"
#define TW_FILENAME "tw_filename"
Expand Down Expand Up @@ -133,6 +132,8 @@
#define TW_NO_BATTERY_PERCENT "tw_no_battery_percent"
#define TW_POWER_BUTTON "tw_power_button"
#define TW_SIMULATE_ACTIONS "tw_simulate_actions"
#define TW_FORCE_F2FS "tw_force_f2fs"
#define TW_FORCE_F2FS_SYSTEM "tw_force_f2fs_system"
#define TW_SIMULATE_FAIL "tw_simulate_fail"
#define TW_DONT_UNMOUNT_SYSTEM "tw_dont_unmount_system"
// #define TW_ALWAYS_RMRF "tw_always_rmrf"
Expand Down

0 comments on commit e71ab1e

Please sign in to comment.