Skip to content

Commit

Permalink
sdcard: only bind mount sdcard after successful preparation of data
Browse files Browse the repository at this point in the history
Change-Id: I589f48a019f90a60ad48f93c5f5555aae4b8a5c9
  • Loading branch information
bigbiff committed Feb 8, 2022
1 parent 2a8dc0d commit cda1588
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
16 changes: 12 additions & 4 deletions partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,15 +658,15 @@ void TWPartition::Setup_Data_Partition(bool Display_Error) {
UnMount(false);

#ifdef TW_INCLUDE_CRYPTO
if (datamedia)
Setup_Data_Media();
Can_Be_Encrypted = true;
char crypto_blkdev[255];
property_get("ro.crypto.fs_crypto_blkdev", crypto_blkdev, "error");
if (strcmp(crypto_blkdev, "error") != 0) {
Set_FBE_Status();
Decrypted_Block_Device = crypto_blkdev;
LOGINFO("Data already decrypted, new block device: '%s'\n", crypto_blkdev);
if (datamedia)
Setup_Data_Media();
DataManager::SetValue(TW_IS_ENCRYPTED, 0);
} else if (!Mount(false)) {
if (Is_Present) {
Expand All @@ -683,6 +683,8 @@ void TWPartition::Setup_Data_Partition(bool Display_Error) {
DataManager::SetValue("tw_crypto_pwtype_0", cryptfs_get_password_type());
DataManager::SetValue(TW_CRYPTO_PASSWORD, "");
DataManager::SetValue("tw_crypto_display", "");
if (datamedia)
Setup_Data_Media();
} else {
gui_err("mount_data_footer=Could not mount /data and unable to find crypto footer.");
}
Expand All @@ -695,6 +697,8 @@ void TWPartition::Setup_Data_Partition(bool Display_Error) {
Primary_Block_Device.c_str(), Mount_Point.c_str());
}
} else {
if (Is_Mounted())
UnMount(true);
Set_FBE_Status();
int is_device_fbe;
DataManager::GetValue(TW_IS_FBE, is_device_fbe);
Expand All @@ -705,6 +709,9 @@ void TWPartition::Setup_Data_Partition(bool Display_Error) {
LOGERR("Unable to decrypt FBE device\n");
} else {
DataManager::SetValue(TW_IS_ENCRYPTED, 0);
if (datamedia)
Setup_Data_Media();

}
}
if (datamedia && (!Is_Encrypted || (Is_Encrypted && Is_Decrypted))) {
Expand Down Expand Up @@ -1194,7 +1201,8 @@ void TWPartition::Setup_Data_Media() {
Make_Dir("/sdcard", false);
Symlink_Mount_Point = "/sdcard";
}
if (Mount(false) && TWFunc::Path_Exists(Mount_Point + "/media/0")) {
Mount(false);
if (TWFunc::Path_Exists(Mount_Point + "/media/0")) {
Storage_Path = Mount_Point + "/media/0";
Symlink_Path = Storage_Path;
DataManager::SetValue(TW_INTERNAL_PATH, Mount_Point + "/media/0");
Expand Down Expand Up @@ -1605,7 +1613,7 @@ bool TWPartition::Mount(bool Display_Error) {
if (Removable)
Update_Size(Display_Error);

if (!Symlink_Mount_Point.empty() && Symlink_Mount_Point != "/sdcard") {
if (!Symlink_Mount_Point.empty()) {
if (!Bind_Mount(false))
return false;
}
Expand Down
17 changes: 11 additions & 6 deletions partitionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,12 @@ void TWPartitionManager::Decrypt_Data() {
TWPartition* Decrypt_Data = Find_Partition_By_Path("/data");
if (Decrypt_Data && Decrypt_Data->Is_Encrypted && !Decrypt_Data->Is_Decrypted) {
Set_Crypto_State();
if (!Decrypt_Data->Key_Directory.empty() && Mount_By_Path(Decrypt_Data->Key_Directory, false)) {
Set_Crypto_Type("file");
TWPartition* Key_Directory_Partition = Find_Partition_By_Path(Decrypt_Data->Key_Directory);
if (Key_Directory_Partition != nullptr)
if (!Key_Directory_Partition->Is_Mounted())
Mount_By_Path(Decrypt_Data->Key_Directory, false);
if (!Decrypt_Data->Key_Directory.empty()) {
Set_Crypto_Type("file");
#ifdef TW_INCLUDE_FBE_METADATA_DECRYPT
#ifdef USE_FSCRYPT
if (fscrypt_mount_metadata_encrypted(Decrypt_Data->Actual_Block_Device, Decrypt_Data->Mount_Point, false)) {
Expand Down Expand Up @@ -477,8 +481,7 @@ void TWPartitionManager::Decrypt_Data() {
}
}
}
if (Decrypt_Data && (!Decrypt_Data->Is_Encrypted || Decrypt_Data->Is_Decrypted) &&
Decrypt_Data->Mount(false)) {
if (Decrypt_Data && (!Decrypt_Data->Is_Encrypted || Decrypt_Data->Is_Decrypted)) {
Decrypt_Adopted();
}
#endif
Expand Down Expand Up @@ -1817,8 +1820,10 @@ void TWPartitionManager::Post_Decrypt(const string& Block_Device) {
DataManager::LoadTWRPFolderInfo();
Update_System_Details();
Output_Partition(dat);
if (!dat->Bind_Mount(false))
LOGERR("Unable to bind mount /sdcard to %s\n", dat->Storage_Path.c_str());
if (!android::base::StartsWith(dat->Actual_Block_Device, "/dev/block/mmcblk")) {
if (!dat->Bind_Mount(false))
LOGERR("Unable to bind mount /sdcard to %s\n", dat->Storage_Path.c_str());
}
} else
LOGERR("Unable to locate data partition.\n");
}
Expand Down

0 comments on commit cda1588

Please sign in to comment.