summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--applypatch/applypatch.c4
-rw-r--r--partition.cpp74
-rw-r--r--partitionmanager.cpp3
3 files changed, 54 insertions, 27 deletions
diff --git a/applypatch/applypatch.c b/applypatch/applypatch.c
index 00004e9a8..488fd8c6f 100644
--- a/applypatch/applypatch.c
+++ b/applypatch/applypatch.c
@@ -324,7 +324,7 @@ static int LoadPartitionContents(const char* filename, FileContents* file) {
// Save the contents of the given FileContents object under the given
// filename. Return 0 on success.
int SaveFileContents(const char* filename, const FileContents* file) {
- int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC);
+ int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd < 0) {
printf("failed to open \"%s\" for write: %s\n",
filename, strerror(errno));
@@ -843,7 +843,7 @@ static int GenerateTarget(FileContents* source_file,
strcpy(outname, target_filename);
strcat(outname, ".patch");
- output = open(outname, O_WRONLY | O_CREAT | O_TRUNC);
+ output = open(outname, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (output < 0) {
printf("failed to open output file %s: %s\n",
outname, strerror(errno));
diff --git a/partition.cpp b/partition.cpp
index d391f9881..f5173b13d 100644
--- a/partition.cpp
+++ b/partition.cpp
@@ -214,9 +214,17 @@ bool TWPartition::Process_Fstab_Line(string Line, bool Display_Error) {
} else if (!Mount(false)) {
Is_Encrypted = true;
Is_Decrypted = false;
+ Can_Be_Mounted = false;
+ Current_File_System = "emmc";
+ Setup_Image(Display_Error);
DataManager::SetValue(TW_IS_ENCRYPTED, 1);
DataManager::SetValue(TW_CRYPTO_PASSWORD, "");
DataManager::SetValue("tw_crypto_display", "");
+ } else {
+ // Filesystem is not encrypted and the mount
+ // succeeded, so get it back to the original
+ // unmounted state
+ UnMount(false);
}
#ifdef RECOVERY_SDCARD_ON_DATA
if (!Is_Encrypted || (Is_Encrypted && Is_Decrypted))
@@ -414,12 +422,12 @@ void TWPartition::Setup_File_System(bool Display_Error) {
void TWPartition::Setup_Image(bool Display_Error) {
Display_Name = Mount_Point.substr(1, Mount_Point.size() - 1);
Backup_Name = Display_Name;
- if (Fstab_File_System == "emmc")
+ if (Current_File_System == "emmc")
Backup_Method = DD;
- else if (Fstab_File_System == "mtd" || Fstab_File_System == "bml")
+ else if (Current_File_System == "mtd" || Current_File_System == "bml")
Backup_Method = FLASH_UTILS;
else
- LOGI("Unhandled file system '%s' on image '%s'\n", Fstab_File_System.c_str(), Display_Name.c_str());
+ LOGI("Unhandled file system '%s' on image '%s'\n", Current_File_System.c_str(), Display_Name.c_str());
if (Find_Partition_Size()) {
Used = Size;
Backup_Size = Size;
@@ -733,28 +741,45 @@ bool TWPartition::Wipe(string New_File_System) {
return Wipe_Data_Without_Wiping_Media();
int check;
+ bool wiped = false;
DataManager::GetValue(TW_RM_RF_VAR, check);
- if (check)
- return Wipe_RMRF();
-
- if (New_File_System == "ext4")
- return Wipe_EXT4();
- if (New_File_System == "ext2" || New_File_System == "ext3")
- return Wipe_EXT23(New_File_System);
-
- if (New_File_System == "vfat")
- return Wipe_FAT();
-
- if (New_File_System == "yaffs2")
- return Wipe_MTD();
+ if (check)
+ wiped = Wipe_RMRF();
+ else if (New_File_System == "ext4")
+ wiped = Wipe_EXT4();
+ else if (New_File_System == "ext2" || New_File_System == "ext3")
+ wiped = Wipe_EXT23(New_File_System);
+ else if (New_File_System == "vfat")
+ wiped = Wipe_FAT();
+ else if (New_File_System == "yaffs2")
+ wiped = Wipe_MTD();
+ else {
+ LOGE("Unable to wipe '%s' -- unknown file system '%s'\n", Mount_Point.c_str(), New_File_System.c_str());
+ return false;
+ }
- LOGE("Unable to wipe '%s' -- unknown file system '%s'\n", Mount_Point.c_str(), New_File_System.c_str());
- return false;
+ if (wiped) {
+ Setup_File_System(false);
+ if (Is_Encrypted && !Is_Decrypted) {
+ // just wiped an encrypted partition back to its unencrypted state
+ Is_Encrypted = false;
+ Is_Decrypted = false;
+ Decrypted_Block_Device = "";
+ if (Mount_Point == "/data") {
+ DataManager::SetValue(TW_IS_ENCRYPTED, 0);
+ DataManager::SetValue(TW_IS_DECRYPTED, 0);
+ }
+ }
+ }
+ return wiped;
}
bool TWPartition::Wipe() {
- return Wipe(Current_File_System);
+ if (Is_File_System(Current_File_System))
+ return Wipe(Current_File_System);
+ else
+ return Wipe(Fstab_File_System);
}
bool TWPartition::Wipe_AndSec(void) {
@@ -875,12 +900,8 @@ bool TWPartition::Wipe_Encryption() {
if (!UnMount(true))
return false;
- Current_File_System = Fstab_File_System;
- Is_Encrypted = false;
- Is_Decrypted = false;
- Decrypted_Block_Device = "";
Has_Data_Media = false;
- if (Wipe()) {
+ if (Wipe(Fstab_File_System)) {
Has_Data_Media = Save_Data_Media;
if (Has_Data_Media && !Symlink_Mount_Point.empty()) {
Recreate_Media_Folder();
@@ -982,6 +1003,7 @@ bool TWPartition::Wipe_EXT23(string File_System) {
sprintf(command, "mke2fs -t %s -m 0 %s", File_System.c_str(), Actual_Block_Device.c_str());
LOGI("mke2fs command: %s\n", command);
if (system(command) == 0) {
+ Current_File_System = File_System;
Recreate_AndSec_Folder();
ui_print("Done.\n");
return true;
@@ -1015,6 +1037,7 @@ bool TWPartition::Wipe_EXT4() {
Command += " " + Actual_Block_Device;
LOGI("make_ext4fs command: %s\n", Command.c_str());
if (system(Command.c_str()) == 0) {
+ Current_File_System = "ext4";
Recreate_AndSec_Folder();
ui_print("Done.\n");
return true;
@@ -1039,6 +1062,7 @@ bool TWPartition::Wipe_FAT() {
Find_Actual_Block_Device();
sprintf(command,"mkdosfs %s", Actual_Block_Device.c_str()); // use mkdosfs to format it
if (system(command) == 0) {
+ Current_File_System = "vfat";
Recreate_AndSec_Folder();
ui_print("Done.\n");
return true;
@@ -1081,6 +1105,7 @@ bool TWPartition::Wipe_MTD() {
LOGE("Failed to close '%s'", MTD_Name.c_str());
return false;
}
+ Current_File_System = "yaffs2";
Recreate_AndSec_Folder();
ui_print("Done.\n");
return true;
@@ -1253,7 +1278,6 @@ bool TWPartition::Restore_Tar(string restore_folder, string Restore_File_System)
int index = 0;
char split_index[5];
- Current_File_System = Restore_File_System;
if (Has_Android_Secure) {
ui_print("Wiping android secure...\n");
if (!Wipe_AndSec())
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index 536e86780..95f010093 100644
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -1483,6 +1483,8 @@ void TWPartitionManager::Update_System_Details(void) {
DataManager::SetValue(TW_BACKUP_RECOVERY_VAR, 0);
} else
DataManager::SetValue(TW_HAS_RECOVERY_PARTITION, 1);
+ } else if ((*iter)->Mount_Point == "/data") {
+ data_size += (int)((*iter)->Backup_Size / 1048576LLU);
}
#ifdef SP1_NAME
if ((*iter)->Backup_Name == EXPAND(SP1_NAME)) {
@@ -1581,6 +1583,7 @@ int TWPartitionManager::Decrypt_Device(string Password) {
DataManager::SetValue(TW_IS_DECRYPTED, 1);
dat->Is_Decrypted = true;
dat->Decrypted_Block_Device = crypto_blkdev;
+ dat->Setup_File_System(false);
ui_print("Data successfully decrypted, new block device: '%s'\n", crypto_blkdev);
// Sleep for a bit so that the device will be ready
sleep(1);