diff options
author | James Christopher Adduono <jc@adduono.com> | 2016-02-29 10:26:04 +0100 |
---|---|---|
committer | Dees Troy <dees_troy@teamw.in> | 2016-03-29 20:38:02 +0200 |
commit | d6f94acc9ad6f60675969bbe20e37717ea795bca (patch) | |
tree | ad707f70a1b307b4592cd5691b8c7f3fb5568162 /partition.cpp | |
parent | Fix RELINK of toybox for twrp (diff) | |
download | android_bootable_recovery-d6f94acc9ad6f60675969bbe20e37717ea795bca.tar android_bootable_recovery-d6f94acc9ad6f60675969bbe20e37717ea795bca.tar.gz android_bootable_recovery-d6f94acc9ad6f60675969bbe20e37717ea795bca.tar.bz2 android_bootable_recovery-d6f94acc9ad6f60675969bbe20e37717ea795bca.tar.lz android_bootable_recovery-d6f94acc9ad6f60675969bbe20e37717ea795bca.tar.xz android_bootable_recovery-d6f94acc9ad6f60675969bbe20e37717ea795bca.tar.zst android_bootable_recovery-d6f94acc9ad6f60675969bbe20e37717ea795bca.zip |
Diffstat (limited to 'partition.cpp')
-rw-r--r-- | partition.cpp | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/partition.cpp b/partition.cpp index 979272a44..fe2843cae 100644 --- a/partition.cpp +++ b/partition.cpp @@ -984,6 +984,14 @@ bool TWPartition::Is_Mounted(void) { return ret; } +bool TWPartition::Is_File_System_Writable(void) { + if (!Is_File_System(Current_File_System) || !Is_Mounted()) + return false; + + string test_path = Mount_Point + "/."; + return (access(test_path.c_str(), W_OK) == 0); +} + bool TWPartition::Mount(bool Display_Error) { int exfat_mounted = 0; unsigned long flags = Mount_Flags; @@ -1152,6 +1160,31 @@ bool TWPartition::UnMount(bool Display_Error) { } } +bool TWPartition::ReMount(bool Display_Error) { + if (UnMount(Display_Error)) + return Mount(Display_Error); + return false; +} + +bool TWPartition::ReMount_RW(bool Display_Error) { + // No need to remount if already mounted rw + if (Is_File_System_Writable()) + return true; + + bool ro = Mount_Read_Only; + int flags = Mount_Flags; + + Mount_Read_Only = false; + Mount_Flags &= ~MS_RDONLY; + + bool ret = ReMount(Display_Error); + + Mount_Read_Only = ro; + Mount_Flags = flags; + + return ret; +} + bool TWPartition::Wipe(string New_File_System) { bool wiped = false, update_crypt = false, recreate_media = true; int check; @@ -2141,7 +2174,8 @@ bool TWPartition::Restore_Tar(string restore_folder, string Restore_File_System, TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Backup_Display_Name, gui_parse_text("{@restoring_hdr}")); gui_msg(Msg("restoring=Restoring {1}...")(Backup_Display_Name)); - if (!Mount(true)) + // Remount as read/write as needed so we can restore the backup + if (!ReMount_RW(true)) return false; Full_FileName = restore_folder + "/" + Backup_FileName; @@ -2178,6 +2212,10 @@ bool TWPartition::Restore_Tar(string restore_folder, string Restore_File_System, } } #endif + if (Mount_Read_Only || Mount_Flags & MS_RDONLY) + // Remount as read only when restoration is complete + ReMount(true); + return ret; } |