diff --git a/partition.cpp b/partition.cpp index f7fe0013..ecd5be59 100755 --- a/partition.cpp +++ b/partition.cpp @@ -1209,6 +1209,17 @@ void TWPartition::Setup_Data_Media() { wipe_exclusions.add_absolute_dir(Mount_Point + "/misc/vold"); // adopted storage keys ExcludeAll(Mount_Point + "/system/storage.xml"); } else { + int i; + string path; + for (i = 2; i <= 9; i++) { + path = "/sdcard" + TWFunc::to_string(i); + if (!TWFunc::Path_Exists(path)) { + Make_Dir(path, false); + Symlink_Mount_Point = path; + LOGINFO("'%s' data/media emulated storage symlinked to %s.\n", Mount_Point.c_str(), Symlink_Mount_Point.c_str()); + break; + } + } if (Mount(true) && TWFunc::Path_Exists(Mount_Point + "/media/0")) { Storage_Path = Mount_Point + "/media/0"; Symlink_Path = Storage_Path; @@ -3295,7 +3306,14 @@ int TWPartition::Decrypt_Adopted() { char type_guid[80]; char part_guid[80]; - if (gpt_disk_get_partition_info(fd, 2, type_guid, part_guid) == 0) { + uint32_t p_num; + size_t last_digit = Primary_Block_Device.find_last_not_of("0123456789"); + if ((last_digit != string::npos) && (last_digit != Primary_Block_Device.length()-1)) + p_num = atoi(Primary_Block_Device.substr(last_digit + 1).c_str()) + 1; + else + p_num = 2; + + if (gpt_disk_get_partition_info(fd, p_num, type_guid, part_guid) == 0) { LOGINFO("type: '%s'\n", type_guid); LOGINFO("part: '%s'\n", part_guid); Adopted_GUID = part_guid; @@ -3311,16 +3329,22 @@ int TWPartition::Decrypt_Adopted() { * to disable USB Mass Storage whenever adopted storage * is present. */ - LOGINFO("Detected adopted storage, disabling USB mass storage mode\n"); - DataManager::SetValue("tw_has_usb_storage", 0); + if (p_num == 2) { + // TODO: Properly detect mixed vs fully adopted storage. Maybe this + // should be moved to partitionmanager instead, and disable after + // checking all partitions. Also the presence of adopted storage does + // not necessarily mean it's being used as Internal Storage + LOGINFO("Detected adopted storage, disabling USB mass storage mode\n"); + DataManager::SetValue("tw_has_usb_storage", 0); + } } } } if (Is_Adopted_Storage) { - string Adopted_Block_Device = Alternate_Block_Device + "p2"; + string Adopted_Block_Device = Alternate_Block_Device + "p" + TWFunc::to_string(p_num); if (!TWFunc::Path_Exists(Adopted_Block_Device)) { - Adopted_Block_Device = Alternate_Block_Device + "2"; + Adopted_Block_Device = Alternate_Block_Device + TWFunc::to_string(p_num); if (!TWFunc::Path_Exists(Adopted_Block_Device)) { LOGINFO("Adopted block device does not exist\n"); goto exit; diff --git a/partitionmanager.cpp b/partitionmanager.cpp index b1ddb998..a4d84ecb 100755 --- a/partitionmanager.cpp +++ b/partitionmanager.cpp @@ -2157,8 +2157,12 @@ int TWPartitionManager::usb_storage_enable(void) { Mount2 = Find_Next_Storage(Mount1->Mount_Point, true); if (Mount2 && Mount2->Mount_Point != Mount1->Mount_Point) { Open_Lun_File(Mount2->Mount_Point, lun_file); + // Mimic single lun code: Mount CurrentStoragePath if it's not /data + } else if (TWFunc::Get_Root_Path(DataManager::GetCurrentStoragePath()) != "/data") { + Open_Lun_File(DataManager::GetCurrentStoragePath(), lun_file); } - } else { + // Mimic single lun code: Mount CurrentStoragePath if it's not /data + } else if (TWFunc::Get_Root_Path(DataManager::GetCurrentStoragePath()) != "/data" && !Open_Lun_File(DataManager::GetCurrentStoragePath(), lun_file)) { gui_err("unable_locate_storage=Unable to locate storage device."); goto error_handle; }