From 5a0a3aeed5c522995944d50c1d944e6515fc06d3 Mon Sep 17 00:00:00 2001 From: me-cafebabe Date: Thu, 28 Jul 2022 03:45:22 +0800 Subject: [PATCH] partition: Mount partition as RO when updating size So that read-only partitions can also get mounted. For example, Super volumes are RO when setting up. Change-Id: I736a738963ba208cfdeaadc05c47d45b1bb7bf3e (cherry picked from commit b52a4815d5c3a5be1fe56968f4480c788d2eaab2) --- partition.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/partition.cpp b/partition.cpp index 4854fbee..294046b5 100755 --- a/partition.cpp +++ b/partition.cpp @@ -2982,36 +2982,39 @@ bool TWPartition::Restore_Image(PartitionSettings *part_settings) { } bool TWPartition::Update_Size(bool Display_Error) { - bool ret = false, Was_Already_Mounted = false; + bool ret = false, Was_Already_Mounted = false, ro = false; Find_Actual_Block_Device(); if (Actual_Block_Device.empty()) return false; + ro = Mount_Read_Only; + Mount_Read_Only = true; + if (!Can_Be_Mounted && !Is_Encrypted) { if (TWFunc::Path_Exists(Actual_Block_Device) && Find_Partition_Size()) { Used = Size; Backup_Size = Size; - return true; + goto success; } - return false; + goto fail; } Was_Already_Mounted = Is_Mounted(); if (Removable || Is_Encrypted) { if (!Mount(false)) - return true; + goto success; } else if (!Mount(Display_Error)) - return false; + goto fail; ret = Get_Size_Via_statfs(Display_Error); if (!ret || Size == 0) { if (!Get_Size_Via_df(Display_Error)) { if (!Was_Already_Mounted) UnMount(false); - return false; + goto fail; } } @@ -3025,7 +3028,7 @@ bool TWPartition::Update_Size(bool Display_Error) { } else { if (!Was_Already_Mounted) UnMount(false); - return false; + goto fail; } } else if (Has_Android_Secure) { if (Mount(Display_Error)) @@ -3033,12 +3036,17 @@ bool TWPartition::Update_Size(bool Display_Error) { else { if (!Was_Already_Mounted) UnMount(false); - return false; + goto fail; } } if (!Was_Already_Mounted) UnMount(false); +success: + Mount_Read_Only = ro; return true; +fail: + Mount_Read_Only = ro; + return false; } bool TWPartition::Find_Wildcard_Block_Devices(const string& Device) {