Dees Troy | 3be70a8 | 2013-10-22 14:25:12 +0000 | [diff] [blame] | 1 | /* |
bigbiff bigbiff | 56cf564 | 2016-08-19 17:43:45 -0400 | [diff] [blame] | 2 | Copyright 2013 to 2017 TeamWin |
Dees Troy | 3be70a8 | 2013-10-22 14:25:12 +0000 | [diff] [blame] | 3 | This file is part of TWRP/TeamWin Recovery Project. |
| 4 | |
| 5 | TWRP is free software: you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation, either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | TWRP is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with TWRP. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
| 22 | #include <sys/stat.h> |
| 23 | #include <sys/vfs.h> |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 24 | #include <sys/mount.h> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 25 | #include <unistd.h> |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 26 | #include <dirent.h> |
that | f54e539 | 2016-01-29 22:04:43 +0100 | [diff] [blame] | 27 | #include <libgen.h> |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 28 | #include <zlib.h> |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 29 | #include <iostream> |
| 30 | #include <sstream> |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 31 | #include <sys/param.h> |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 32 | #include <fcntl.h> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 33 | |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 34 | #ifdef TW_INCLUDE_CRYPTO |
| 35 | #include "cutils/properties.h" |
| 36 | #endif |
| 37 | |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 38 | #include "libblkid/include/blkid.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 39 | #include "variables.h" |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 40 | #include "twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 41 | #include "partitions.hpp" |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 42 | #include "data.hpp" |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 43 | #include "twrp-functions.hpp" |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 44 | #include "twrpTar.hpp" |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 45 | #include "exclude.hpp" |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 46 | #include "infomanager.hpp" |
Ethan Yonker | 4b94cfd | 2014-12-11 10:00:45 -0600 | [diff] [blame] | 47 | #include "set_metadata.h" |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 48 | #include "gui/gui.hpp" |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 49 | #include "adbbu/libtwadbbu.hpp" |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 50 | extern "C" { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 51 | #include "mtdutils/mtdutils.h" |
| 52 | #include "mtdutils/mounts.h" |
Dees_Troy | a95f55c | 2013-08-17 13:14:43 +0000 | [diff] [blame] | 53 | #ifdef USE_EXT4 |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame^] | 54 | // #include "make_ext4fs.h" TODO need ifdef for android8 |
| 55 | #include <ext4_utils/make_ext4fs.h> |
Dees_Troy | a95f55c | 2013-08-17 13:14:43 +0000 | [diff] [blame] | 56 | #endif |
Ethan Yonker | 71413f4 | 2014-02-26 13:36:08 -0600 | [diff] [blame] | 57 | |
| 58 | #ifdef TW_INCLUDE_CRYPTO |
Ethan Yonker | 253368a | 2014-11-25 15:00:52 -0600 | [diff] [blame] | 59 | #include "crypto/lollipop/cryptfs.h" |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 60 | #include "gpt/gpt.h" |
Ethan Yonker | bd7492d | 2016-12-07 13:55:01 -0600 | [diff] [blame] | 61 | #ifdef TW_INCLUDE_FBE |
| 62 | #include "crypto/ext4crypt/Decrypt.h" |
Ethan Yonker | bd7492d | 2016-12-07 13:55:01 -0600 | [diff] [blame] | 63 | #endif |
Ethan Yonker | bc85b63 | 2015-08-09 12:48:14 -0500 | [diff] [blame] | 64 | #else |
| 65 | #define CRYPT_FOOTER_OFFSET 0x4000 |
Ethan Yonker | 71413f4 | 2014-02-26 13:36:08 -0600 | [diff] [blame] | 66 | #endif |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 67 | } |
Matt Mower | 8741364 | 2017-01-17 21:14:46 -0600 | [diff] [blame] | 68 | #include <selinux/selinux.h> |
Ethan Yonker | f27497f | 2014-02-09 11:48:33 -0600 | [diff] [blame] | 69 | #include <selinux/label.h> |
Dees Troy | 4159aed | 2014-02-28 17:24:43 +0000 | [diff] [blame] | 70 | #ifdef HAVE_CAPABILITIES |
| 71 | #include <sys/capability.h> |
| 72 | #include <sys/xattr.h> |
| 73 | #include <linux/xattr.h> |
| 74 | #endif |
HashBang | ed974bb | 2016-01-30 14:20:09 -0500 | [diff] [blame] | 75 | #include <sparse_format.h> |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 76 | #include "progresstracking.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 77 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 78 | using namespace std; |
| 79 | |
Dees_Troy | a95f55c | 2013-08-17 13:14:43 +0000 | [diff] [blame] | 80 | extern struct selabel_handle *selinux_handle; |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 81 | extern bool datamedia; |
Dees_Troy | a95f55c | 2013-08-17 13:14:43 +0000 | [diff] [blame] | 82 | |
Hashcode | 62bd9e0 | 2013-11-19 21:59:42 -0800 | [diff] [blame] | 83 | struct flag_list { |
| 84 | const char *name; |
| 85 | unsigned flag; |
| 86 | }; |
| 87 | |
Matt Mower | 4ab42b1 | 2016-04-21 13:52:18 -0500 | [diff] [blame] | 88 | const struct flag_list mount_flags[] = { |
Hashcode | 62bd9e0 | 2013-11-19 21:59:42 -0800 | [diff] [blame] | 89 | { "noatime", MS_NOATIME }, |
| 90 | { "noexec", MS_NOEXEC }, |
| 91 | { "nosuid", MS_NOSUID }, |
| 92 | { "nodev", MS_NODEV }, |
| 93 | { "nodiratime", MS_NODIRATIME }, |
| 94 | { "ro", MS_RDONLY }, |
| 95 | { "rw", 0 }, |
| 96 | { "remount", MS_REMOUNT }, |
| 97 | { "bind", MS_BIND }, |
| 98 | { "rec", MS_REC }, |
Dees Troy | c4bc30e | 2014-02-03 15:04:19 +0000 | [diff] [blame] | 99 | #ifdef MS_UNBINDABLE |
Hashcode | 62bd9e0 | 2013-11-19 21:59:42 -0800 | [diff] [blame] | 100 | { "unbindable", MS_UNBINDABLE }, |
Dees Troy | c4bc30e | 2014-02-03 15:04:19 +0000 | [diff] [blame] | 101 | #endif |
| 102 | #ifdef MS_PRIVATE |
Hashcode | 62bd9e0 | 2013-11-19 21:59:42 -0800 | [diff] [blame] | 103 | { "private", MS_PRIVATE }, |
Dees Troy | c4bc30e | 2014-02-03 15:04:19 +0000 | [diff] [blame] | 104 | #endif |
| 105 | #ifdef MS_SLAVE |
Hashcode | 62bd9e0 | 2013-11-19 21:59:42 -0800 | [diff] [blame] | 106 | { "slave", MS_SLAVE }, |
Dees Troy | c4bc30e | 2014-02-03 15:04:19 +0000 | [diff] [blame] | 107 | #endif |
| 108 | #ifdef MS_SHARED |
Hashcode | 62bd9e0 | 2013-11-19 21:59:42 -0800 | [diff] [blame] | 109 | { "shared", MS_SHARED }, |
Dees Troy | c4bc30e | 2014-02-03 15:04:19 +0000 | [diff] [blame] | 110 | #endif |
Hashcode | 62bd9e0 | 2013-11-19 21:59:42 -0800 | [diff] [blame] | 111 | { "sync", MS_SYNCHRONOUS }, |
| 112 | { "defaults", 0 }, |
| 113 | { 0, 0 }, |
| 114 | }; |
| 115 | |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 116 | enum TW_FSTAB_FLAGS { |
| 117 | TWFLAG_DEFAULTS, // Retain position |
| 118 | TWFLAG_ANDSEC, |
| 119 | TWFLAG_BACKUP, |
| 120 | TWFLAG_BACKUPNAME, |
| 121 | TWFLAG_BLOCKSIZE, |
| 122 | TWFLAG_CANBEWIPED, |
| 123 | TWFLAG_CANENCRYPTBACKUP, |
| 124 | TWFLAG_DISPLAY, |
| 125 | TWFLAG_ENCRYPTABLE, |
| 126 | TWFLAG_FLASHIMG, |
| 127 | TWFLAG_FORCEENCRYPT, |
| 128 | TWFLAG_FSFLAGS, |
| 129 | TWFLAG_IGNOREBLKID, |
| 130 | TWFLAG_LENGTH, |
| 131 | TWFLAG_MOUNTTODECRYPT, |
| 132 | TWFLAG_REMOVABLE, |
| 133 | TWFLAG_RETAINLAYOUTVERSION, |
| 134 | TWFLAG_SETTINGSSTORAGE, |
| 135 | TWFLAG_STORAGE, |
| 136 | TWFLAG_STORAGENAME, |
| 137 | TWFLAG_SUBPARTITIONOF, |
| 138 | TWFLAG_SYMLINK, |
| 139 | TWFLAG_USERDATAENCRYPTBACKUP, |
| 140 | TWFLAG_USERMRF, |
| 141 | TWFLAG_WIPEDURINGFACTORYRESET, |
| 142 | TWFLAG_WIPEINGUI, |
Ethan Yonker | 1b19016 | 2016-12-05 15:25:19 -0600 | [diff] [blame] | 143 | TWFLAG_SLOTSELECT, |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | /* Flags without a trailing '=' are considered dual format flags and can be |
| 147 | * written as either 'flagname' or 'flagname=', where the character following |
| 148 | * the '=' is Y,y,1 for true and false otherwise. |
| 149 | */ |
| 150 | const struct flag_list tw_flags[] = { |
| 151 | { "andsec", TWFLAG_ANDSEC }, |
| 152 | { "backup", TWFLAG_BACKUP }, |
| 153 | { "backupname=", TWFLAG_BACKUPNAME }, |
| 154 | { "blocksize=", TWFLAG_BLOCKSIZE }, |
| 155 | { "canbewiped", TWFLAG_CANBEWIPED }, |
| 156 | { "canencryptbackup", TWFLAG_CANENCRYPTBACKUP }, |
| 157 | { "defaults", TWFLAG_DEFAULTS }, |
| 158 | { "display=", TWFLAG_DISPLAY }, |
| 159 | { "encryptable=", TWFLAG_ENCRYPTABLE }, |
| 160 | { "flashimg", TWFLAG_FLASHIMG }, |
| 161 | { "forceencrypt=", TWFLAG_FORCEENCRYPT }, |
| 162 | { "fsflags=", TWFLAG_FSFLAGS }, |
| 163 | { "ignoreblkid", TWFLAG_IGNOREBLKID }, |
| 164 | { "length=", TWFLAG_LENGTH }, |
| 165 | { "mounttodecrypt", TWFLAG_MOUNTTODECRYPT }, |
| 166 | { "removable", TWFLAG_REMOVABLE }, |
| 167 | { "retainlayoutversion", TWFLAG_RETAINLAYOUTVERSION }, |
| 168 | { "settingsstorage", TWFLAG_SETTINGSSTORAGE }, |
| 169 | { "storage", TWFLAG_STORAGE }, |
| 170 | { "storagename=", TWFLAG_STORAGENAME }, |
| 171 | { "subpartitionof=", TWFLAG_SUBPARTITIONOF }, |
| 172 | { "symlink=", TWFLAG_SYMLINK }, |
| 173 | { "userdataencryptbackup", TWFLAG_USERDATAENCRYPTBACKUP }, |
| 174 | { "usermrf", TWFLAG_USERMRF }, |
| 175 | { "wipeduringfactoryreset", TWFLAG_WIPEDURINGFACTORYRESET }, |
| 176 | { "wipeingui", TWFLAG_WIPEINGUI }, |
Ethan Yonker | 1b19016 | 2016-12-05 15:25:19 -0600 | [diff] [blame] | 177 | { "slotselect", TWFLAG_SLOTSELECT }, |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 178 | { 0, 0 }, |
| 179 | }; |
| 180 | |
that | 9e0593e | 2014-10-08 00:01:24 +0200 | [diff] [blame] | 181 | TWPartition::TWPartition() { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 182 | Can_Be_Mounted = false; |
| 183 | Can_Be_Wiped = false; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 184 | Can_Be_Backed_Up = false; |
Vojtech Bocek | 1dc3098 | 2013-08-30 21:49:30 +0200 | [diff] [blame] | 185 | Use_Rm_Rf = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 186 | Wipe_During_Factory_Reset = false; |
| 187 | Wipe_Available_in_GUI = false; |
| 188 | Is_SubPartition = false; |
Dees_Troy | 2691f9d | 2012-09-24 11:15:49 -0400 | [diff] [blame] | 189 | Has_SubPartition = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 190 | SubPartition_Of = ""; |
| 191 | Symlink_Path = ""; |
| 192 | Symlink_Mount_Point = ""; |
| 193 | Mount_Point = ""; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 194 | Backup_Path = ""; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 195 | Actual_Block_Device = ""; |
| 196 | Primary_Block_Device = ""; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 197 | Alternate_Block_Device = ""; |
| 198 | Removable = false; |
| 199 | Is_Present = false; |
| 200 | Length = 0; |
| 201 | Size = 0; |
| 202 | Used = 0; |
| 203 | Free = 0; |
| 204 | Backup_Size = 0; |
| 205 | Can_Be_Encrypted = false; |
| 206 | Is_Encrypted = false; |
| 207 | Is_Decrypted = false; |
Ethan Yonker | bd7492d | 2016-12-07 13:55:01 -0600 | [diff] [blame] | 208 | Is_FBE = false; |
Ethan Yonker | 253368a | 2014-11-25 15:00:52 -0600 | [diff] [blame] | 209 | Mount_To_Decrypt = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 210 | Decrypted_Block_Device = ""; |
| 211 | Display_Name = ""; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 212 | Backup_Display_Name = ""; |
| 213 | Storage_Name = ""; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 214 | Backup_Name = ""; |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 215 | Backup_FileName = ""; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 216 | MTD_Name = ""; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 217 | Backup_Method = BM_NONE; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 218 | Can_Encrypt_Backup = false; |
| 219 | Use_Userdata_Encryption = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 220 | Has_Data_Media = false; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 221 | Has_Android_Secure = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 222 | Is_Storage = false; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 223 | Is_Settings_Storage = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 224 | Storage_Path = ""; |
| 225 | Current_File_System = ""; |
| 226 | Fstab_File_System = ""; |
Hashcode | 62bd9e0 | 2013-11-19 21:59:42 -0800 | [diff] [blame] | 227 | Mount_Flags = 0; |
| 228 | Mount_Options = ""; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 229 | Format_Block_Size = 0; |
Dees_Troy | 68cab49 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 230 | Ignore_Blkid = false; |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 231 | Retain_Layout_Version = false; |
Ethan Yonker | 253368a | 2014-11-25 15:00:52 -0600 | [diff] [blame] | 232 | Crypto_Key_Location = "footer"; |
Ethan Yonker | 726a020 | 2014-12-16 20:01:38 -0600 | [diff] [blame] | 233 | MTP_Storage_ID = 0; |
Ethan Yonker | 96af84a | 2015-01-05 14:58:36 -0600 | [diff] [blame] | 234 | Can_Flash_Img = false; |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 235 | Mount_Read_Only = false; |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 236 | Is_Adopted_Storage = false; |
| 237 | Adopted_GUID = ""; |
Ethan Yonker | 1b19016 | 2016-12-05 15:25:19 -0600 | [diff] [blame] | 238 | SlotSelect = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | TWPartition::~TWPartition(void) { |
| 242 | // Do nothing |
| 243 | } |
| 244 | |
Matt Mower | 2b2dd15 | 2016-04-26 11:24:08 -0500 | [diff] [blame] | 245 | bool TWPartition::Process_Fstab_Line(const char *fstab_line, bool Display_Error) { |
| 246 | char full_line[MAX_FSTAB_LINE_LENGTH]; |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 247 | char twflags[MAX_FSTAB_LINE_LENGTH] = ""; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 248 | char* ptr; |
Matt Mower | 2b2dd15 | 2016-04-26 11:24:08 -0500 | [diff] [blame] | 249 | int line_len = strlen(fstab_line), index = 0, item_index = 0; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 250 | bool skip = false; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 251 | |
Matt Mower | 2b2dd15 | 2016-04-26 11:24:08 -0500 | [diff] [blame] | 252 | strlcpy(full_line, fstab_line, sizeof(full_line)); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 253 | for (index = 0; index < line_len; index++) { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 254 | if (full_line[index] == 34) |
| 255 | skip = !skip; |
| 256 | if (!skip && full_line[index] <= 32) |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 257 | full_line[index] = '\0'; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 258 | } |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 259 | Mount_Point = full_line; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 260 | LOGINFO("Processing '%s'\n", Mount_Point.c_str()); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 261 | Backup_Path = Mount_Point; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 262 | Storage_Path = Mount_Point; |
Dees_Troy | 70737fa | 2013-04-08 13:19:20 +0000 | [diff] [blame] | 263 | Display_Name = full_line + 1; |
| 264 | Backup_Display_Name = Display_Name; |
| 265 | Storage_Name = Display_Name; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 266 | index = Mount_Point.size(); |
| 267 | while (index < line_len) { |
| 268 | while (index < line_len && full_line[index] == '\0') |
| 269 | index++; |
| 270 | if (index >= line_len) |
| 271 | continue; |
| 272 | ptr = full_line + index; |
| 273 | if (item_index == 0) { |
| 274 | // File System |
| 275 | Fstab_File_System = ptr; |
| 276 | Current_File_System = ptr; |
| 277 | item_index++; |
| 278 | } else if (item_index == 1) { |
| 279 | // Primary Block Device |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 280 | if (Fstab_File_System == "mtd" || Fstab_File_System == "yaffs2") { |
Dees_Troy | 094207a | 2012-09-26 12:00:39 -0400 | [diff] [blame] | 281 | MTD_Name = ptr; |
| 282 | Find_MTD_Block_Device(MTD_Name); |
Dees_Troy | 5fcd8f9 | 2012-10-16 12:22:05 -0400 | [diff] [blame] | 283 | } else if (Fstab_File_System == "bml") { |
| 284 | if (Mount_Point == "/boot") |
| 285 | MTD_Name = "boot"; |
| 286 | else if (Mount_Point == "/recovery") |
| 287 | MTD_Name = "recovery"; |
| 288 | Primary_Block_Device = ptr; |
| 289 | if (*ptr != '/') |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 290 | LOGERR("Until we get better BML support, you will have to find and provide the full block device path to the BML devices e.g. /dev/block/bml9 instead of the partition name\n"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 291 | } else if (*ptr != '/') { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 292 | if (Display_Error) |
Matt Mower | 2b2dd15 | 2016-04-26 11:24:08 -0500 | [diff] [blame] | 293 | LOGERR("Invalid block device '%s' in fstab line '%s'", ptr, fstab_line); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 294 | else |
Matt Mower | 2b2dd15 | 2016-04-26 11:24:08 -0500 | [diff] [blame] | 295 | LOGINFO("Invalid block device '%s' in fstab line '%s'", ptr, fstab_line); |
Matt Mower | 72c87ce | 2016-04-26 14:34:56 -0500 | [diff] [blame] | 296 | return false; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 297 | } else { |
| 298 | Primary_Block_Device = ptr; |
| 299 | Find_Real_Block_Device(Primary_Block_Device, Display_Error); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 300 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 301 | item_index++; |
| 302 | } else if (item_index > 1) { |
| 303 | if (*ptr == '/') { |
| 304 | // Alternate Block Device |
| 305 | Alternate_Block_Device = ptr; |
| 306 | Find_Real_Block_Device(Alternate_Block_Device, Display_Error); |
| 307 | } else if (strlen(ptr) > 7 && strncmp(ptr, "length=", 7) == 0) { |
| 308 | // Partition length |
| 309 | ptr += 7; |
| 310 | Length = atoi(ptr); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 311 | } else if (strlen(ptr) > 6 && strncmp(ptr, "flags=", 6) == 0) { |
| 312 | // Custom flags, save for later so that new values aren't overwritten by defaults |
| 313 | ptr += 6; |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 314 | strlcpy(twflags, ptr, sizeof(twflags)); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 315 | } else if (strlen(ptr) == 4 && (strncmp(ptr, "NULL", 4) == 0 || strncmp(ptr, "null", 4) == 0 || strncmp(ptr, "null", 4) == 0)) { |
| 316 | // Do nothing |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 317 | } else { |
| 318 | // Unhandled data |
Matt Mower | 2b2dd15 | 2016-04-26 11:24:08 -0500 | [diff] [blame] | 319 | LOGINFO("Unhandled fstab information '%s' in fstab line '%s'\n", ptr, fstab_line); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | while (index < line_len && full_line[index] != '\0') |
| 323 | index++; |
| 324 | } |
| 325 | |
| 326 | if (!Is_File_System(Fstab_File_System) && !Is_Image(Fstab_File_System)) { |
| 327 | if (Display_Error) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 328 | LOGERR("Unknown File System: '%s'\n", Fstab_File_System.c_str()); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 329 | else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 330 | LOGINFO("Unknown File System: '%s'\n", Fstab_File_System.c_str()); |
Matt Mower | 72c87ce | 2016-04-26 14:34:56 -0500 | [diff] [blame] | 331 | return false; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 332 | } else if (Is_File_System(Fstab_File_System)) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 333 | Find_Actual_Block_Device(); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 334 | Setup_File_System(Display_Error); |
| 335 | if (Mount_Point == "/system") { |
| 336 | Display_Name = "System"; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 337 | Backup_Display_Name = Display_Name; |
| 338 | Storage_Name = Display_Name; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 339 | Wipe_Available_in_GUI = true; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 340 | Can_Be_Backed_Up = true; |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 341 | Mount_Read_Only = true; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 342 | } else if (Mount_Point == "/data") { |
| 343 | Display_Name = "Data"; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 344 | Backup_Display_Name = Display_Name; |
| 345 | Storage_Name = Display_Name; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 346 | Wipe_Available_in_GUI = true; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 347 | Wipe_During_Factory_Reset = true; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 348 | Can_Be_Backed_Up = true; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 349 | Can_Encrypt_Backup = true; |
| 350 | Use_Userdata_Encryption = true; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 351 | } else if (Mount_Point == "/cache") { |
| 352 | Display_Name = "Cache"; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 353 | Backup_Display_Name = Display_Name; |
| 354 | Storage_Name = Display_Name; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 355 | Wipe_Available_in_GUI = true; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 356 | Wipe_During_Factory_Reset = true; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 357 | Can_Be_Backed_Up = true; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 358 | } else if (Mount_Point == "/datadata") { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 359 | Wipe_During_Factory_Reset = true; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 360 | Display_Name = "DataData"; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 361 | Backup_Display_Name = Display_Name; |
| 362 | Storage_Name = Display_Name; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 363 | Is_SubPartition = true; |
| 364 | SubPartition_Of = "/data"; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 365 | DataManager::SetValue(TW_HAS_DATADATA, 1); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 366 | Can_Be_Backed_Up = true; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 367 | Can_Encrypt_Backup = true; |
| 368 | Use_Userdata_Encryption = false; // This whole partition should be encrypted |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 369 | } else if (Mount_Point == "/sd-ext") { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 370 | Wipe_During_Factory_Reset = true; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 371 | Display_Name = "SD-Ext"; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 372 | Backup_Display_Name = Display_Name; |
| 373 | Storage_Name = Display_Name; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 374 | Wipe_Available_in_GUI = true; |
Dees_Troy | c51f1f9 | 2012-09-20 15:32:13 -0400 | [diff] [blame] | 375 | Removable = true; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 376 | Can_Be_Backed_Up = true; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 377 | Can_Encrypt_Backup = true; |
| 378 | Use_Userdata_Encryption = true; |
Dees_Troy | 2c50e18 | 2012-09-26 20:05:28 -0400 | [diff] [blame] | 379 | } else if (Mount_Point == "/boot") { |
| 380 | Display_Name = "Boot"; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 381 | Backup_Display_Name = Display_Name; |
Dees_Troy | 2c50e18 | 2012-09-26 20:05:28 -0400 | [diff] [blame] | 382 | DataManager::SetValue("tw_boot_is_mountable", 1); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 383 | Can_Be_Backed_Up = true; |
Ethan Yonker | 1673e3d | 2015-10-26 21:51:58 -0500 | [diff] [blame] | 384 | } else if (Mount_Point == "/vendor") { |
| 385 | Display_Name = "Vendor"; |
| 386 | Backup_Display_Name = Display_Name; |
| 387 | Storage_Name = Display_Name; |
| 388 | Mount_Read_Only = true; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 389 | } |
| 390 | #ifdef TW_EXTERNAL_STORAGE_PATH |
| 391 | if (Mount_Point == EXPAND(TW_EXTERNAL_STORAGE_PATH)) { |
| 392 | Is_Storage = true; |
| 393 | Storage_Path = EXPAND(TW_EXTERNAL_STORAGE_PATH); |
Dees_Troy | c51f1f9 | 2012-09-20 15:32:13 -0400 | [diff] [blame] | 394 | Removable = true; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 395 | Wipe_Available_in_GUI = true; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 396 | #else |
Dees_Troy | 70737fa | 2013-04-08 13:19:20 +0000 | [diff] [blame] | 397 | if (Mount_Point == "/sdcard" || Mount_Point == "/external_sd" || Mount_Point == "/external_sdcard") { |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 398 | Is_Storage = true; |
Dees_Troy | c51f1f9 | 2012-09-20 15:32:13 -0400 | [diff] [blame] | 399 | Removable = true; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 400 | Wipe_Available_in_GUI = true; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 401 | #endif |
Dees_Troy | b05ddee | 2013-01-28 20:24:50 +0000 | [diff] [blame] | 402 | } |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 403 | #ifdef TW_INTERNAL_STORAGE_PATH |
| 404 | if (Mount_Point == EXPAND(TW_INTERNAL_STORAGE_PATH)) { |
| 405 | Is_Storage = true; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 406 | Is_Settings_Storage = true; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 407 | Storage_Path = EXPAND(TW_INTERNAL_STORAGE_PATH); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 408 | Wipe_Available_in_GUI = true; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 409 | } |
| 410 | #else |
Dees_Troy | 70737fa | 2013-04-08 13:19:20 +0000 | [diff] [blame] | 411 | if (Mount_Point == "/emmc" || Mount_Point == "/internal_sd" || Mount_Point == "/internal_sdcard") { |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 412 | Is_Storage = true; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 413 | Is_Settings_Storage = true; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 414 | Wipe_Available_in_GUI = true; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 415 | } |
| 416 | #endif |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 417 | } else if (Is_Image(Fstab_File_System)) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 418 | Find_Actual_Block_Device(); |
Ethan Yonker | 1b19016 | 2016-12-05 15:25:19 -0600 | [diff] [blame] | 419 | Setup_Image(); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 420 | if (Mount_Point == "/boot") { |
| 421 | Display_Name = "Boot"; |
| 422 | Backup_Display_Name = Display_Name; |
| 423 | Can_Be_Backed_Up = true; |
Ethan Yonker | 96af84a | 2015-01-05 14:58:36 -0600 | [diff] [blame] | 424 | Can_Flash_Img = true; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 425 | } else if (Mount_Point == "/recovery") { |
| 426 | Display_Name = "Recovery"; |
| 427 | Backup_Display_Name = Display_Name; |
Ethan Yonker | 96af84a | 2015-01-05 14:58:36 -0600 | [diff] [blame] | 428 | Can_Flash_Img = true; |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 429 | } else if (Mount_Point == "/system_image") { |
| 430 | Display_Name = "System Image"; |
| 431 | Backup_Display_Name = Display_Name; |
HashBang | ed974bb | 2016-01-30 14:20:09 -0500 | [diff] [blame] | 432 | Can_Flash_Img = true; |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 433 | Can_Be_Backed_Up = true; |
Ethan Yonker | 1673e3d | 2015-10-26 21:51:58 -0500 | [diff] [blame] | 434 | } else if (Mount_Point == "/vendor_image") { |
| 435 | Display_Name = "Vendor Image"; |
| 436 | Backup_Display_Name = Display_Name; |
HashBang | ed974bb | 2016-01-30 14:20:09 -0500 | [diff] [blame] | 437 | Can_Flash_Img = true; |
Ethan Yonker | 1673e3d | 2015-10-26 21:51:58 -0500 | [diff] [blame] | 438 | Can_Be_Backed_Up = true; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 439 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 440 | } |
| 441 | |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 442 | // Process TWRP fstab flags |
| 443 | if (strlen(twflags) > 0) { |
| 444 | string Prev_Display_Name = Display_Name; |
| 445 | string Prev_Storage_Name = Storage_Name; |
| 446 | string Prev_Backup_Display_Name = Backup_Display_Name; |
| 447 | Display_Name = ""; |
| 448 | Storage_Name = ""; |
| 449 | Backup_Display_Name = ""; |
| 450 | |
| 451 | Process_TW_Flags(twflags, Display_Error); |
| 452 | |
| 453 | bool has_display_name = !Display_Name.empty(); |
| 454 | bool has_storage_name = !Storage_Name.empty(); |
| 455 | bool has_backup_name = !Backup_Display_Name.empty(); |
| 456 | if (!has_display_name) Display_Name = Prev_Display_Name; |
| 457 | if (!has_storage_name) Storage_Name = Prev_Storage_Name; |
| 458 | if (!has_backup_name) Backup_Display_Name = Prev_Backup_Display_Name; |
| 459 | |
| 460 | if (has_display_name && !has_storage_name) |
| 461 | Storage_Name = Display_Name; |
| 462 | if (!has_display_name && has_storage_name) |
| 463 | Display_Name = Storage_Name; |
| 464 | if (has_display_name && !has_backup_name && Backup_Display_Name != "Android Secure") |
| 465 | Backup_Display_Name = Display_Name; |
| 466 | if (!has_display_name && has_backup_name) |
| 467 | Display_Name = Backup_Display_Name; |
| 468 | } |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 469 | return true; |
| 470 | } |
| 471 | |
Matt Mower | 72c87ce | 2016-04-26 14:34:56 -0500 | [diff] [blame] | 472 | void TWPartition::Partition_Post_Processing(bool Display_Error) { |
| 473 | if (Mount_Point == "/data") |
| 474 | Setup_Data_Partition(Display_Error); |
| 475 | else if (Mount_Point == "/cache") |
| 476 | Setup_Cache_Partition(Display_Error); |
| 477 | } |
| 478 | |
Ethan Yonker | bd7492d | 2016-12-07 13:55:01 -0600 | [diff] [blame] | 479 | void TWPartition::ExcludeAll(const string& path) { |
| 480 | backup_exclusions.add_absolute_dir(path); |
| 481 | wipe_exclusions.add_absolute_dir(path); |
| 482 | } |
| 483 | |
Matt Mower | 72c87ce | 2016-04-26 14:34:56 -0500 | [diff] [blame] | 484 | void TWPartition::Setup_Data_Partition(bool Display_Error) { |
| 485 | if (Mount_Point != "/data") |
| 486 | return; |
| 487 | |
| 488 | // Ensure /data is not mounted as tmpfs for qcom hardware decrypt |
| 489 | UnMount(false); |
| 490 | |
| 491 | #ifdef TW_INCLUDE_CRYPTO |
| 492 | if (datamedia) |
| 493 | Setup_Data_Media(); |
| 494 | Can_Be_Encrypted = true; |
| 495 | char crypto_blkdev[255]; |
| 496 | property_get("ro.crypto.fs_crypto_blkdev", crypto_blkdev, "error"); |
| 497 | if (strcmp(crypto_blkdev, "error") != 0) { |
| 498 | DataManager::SetValue(TW_IS_DECRYPTED, 1); |
| 499 | Is_Encrypted = true; |
| 500 | Is_Decrypted = true; |
Ethan Yonker | bd7492d | 2016-12-07 13:55:01 -0600 | [diff] [blame] | 501 | Is_FBE = false; |
| 502 | DataManager::SetValue(TW_IS_FBE, 0); |
Matt Mower | 72c87ce | 2016-04-26 14:34:56 -0500 | [diff] [blame] | 503 | Decrypted_Block_Device = crypto_blkdev; |
| 504 | LOGINFO("Data already decrypted, new block device: '%s'\n", crypto_blkdev); |
| 505 | } else if (!Mount(false)) { |
| 506 | if (Is_Present) { |
| 507 | set_partition_data(Actual_Block_Device.c_str(), Crypto_Key_Location.c_str(), Fstab_File_System.c_str()); |
| 508 | if (cryptfs_check_footer() == 0) { |
| 509 | Is_Encrypted = true; |
| 510 | Is_Decrypted = false; |
| 511 | Can_Be_Mounted = false; |
| 512 | Current_File_System = "emmc"; |
Ethan Yonker | 1b19016 | 2016-12-05 15:25:19 -0600 | [diff] [blame] | 513 | Setup_Image(); |
Matt Mower | 72c87ce | 2016-04-26 14:34:56 -0500 | [diff] [blame] | 514 | DataManager::SetValue(TW_IS_ENCRYPTED, 1); |
| 515 | DataManager::SetValue(TW_CRYPTO_PWTYPE, cryptfs_get_password_type()); |
| 516 | DataManager::SetValue(TW_CRYPTO_PASSWORD, ""); |
| 517 | DataManager::SetValue("tw_crypto_display", ""); |
| 518 | } else { |
| 519 | gui_err("mount_data_footer=Could not mount /data and unable to find crypto footer."); |
| 520 | } |
| 521 | } else { |
| 522 | LOGERR("Primary block device '%s' for mount point '%s' is not present!\n", Primary_Block_Device.c_str(), Mount_Point.c_str()); |
| 523 | } |
| 524 | } else { |
Ethan Yonker | bd7492d | 2016-12-07 13:55:01 -0600 | [diff] [blame] | 525 | if (TWFunc::Path_Exists("/data/unencrypted/key/version")) { |
| 526 | LOGINFO("File Based Encryption is present\n"); |
| 527 | #ifdef TW_INCLUDE_FBE |
| 528 | ExcludeAll(Mount_Point + "/convert_fbe"); |
| 529 | ExcludeAll(Mount_Point + "/unencrypted"); |
| 530 | //ExcludeAll(Mount_Point + "/system/users/0"); // we WILL need to retain some of this if multiple users are present or we just need to delete more folders for the extra users somewhere else |
| 531 | ExcludeAll(Mount_Point + "/misc/vold/user_keys"); |
Ethan Yonker | 79f88bd | 2016-12-09 14:52:12 -0600 | [diff] [blame] | 532 | //ExcludeAll(Mount_Point + "/system_ce"); |
| 533 | //ExcludeAll(Mount_Point + "/system_de"); |
| 534 | //ExcludeAll(Mount_Point + "/misc_ce"); |
| 535 | //ExcludeAll(Mount_Point + "/misc_de"); |
Ethan Yonker | bd7492d | 2016-12-07 13:55:01 -0600 | [diff] [blame] | 536 | ExcludeAll(Mount_Point + "/system/gatekeeper.password.key"); |
| 537 | ExcludeAll(Mount_Point + "/system/gatekeeper.pattern.key"); |
| 538 | ExcludeAll(Mount_Point + "/system/locksettings.db"); |
| 539 | //ExcludeAll(Mount_Point + "/system/locksettings.db-shm"); // don't seem to need this one, but the other 2 are needed |
| 540 | ExcludeAll(Mount_Point + "/system/locksettings.db-wal"); |
Ethan Yonker | 79f88bd | 2016-12-09 14:52:12 -0600 | [diff] [blame] | 541 | //ExcludeAll(Mount_Point + "/user_de"); |
Ethan Yonker | bd7492d | 2016-12-07 13:55:01 -0600 | [diff] [blame] | 542 | //ExcludeAll(Mount_Point + "/misc/profiles/cur/0"); // might be important later |
| 543 | ExcludeAll(Mount_Point + "/misc/gatekeeper"); |
| 544 | ExcludeAll(Mount_Point + "/drm/kek.dat"); |
| 545 | int retry_count = 3; |
| 546 | while (!Decrypt_DE() && --retry_count) |
| 547 | usleep(2000); |
| 548 | if (retry_count > 0) { |
| 549 | property_set("ro.crypto.state", "encrypted"); |
| 550 | Is_Encrypted = true; |
| 551 | Is_Decrypted = false; |
| 552 | Is_FBE = true; |
| 553 | DataManager::SetValue(TW_IS_FBE, 1); |
| 554 | DataManager::SetValue(TW_IS_ENCRYPTED, 1); |
| 555 | string filename; |
| 556 | DataManager::SetValue(TW_CRYPTO_PWTYPE, Get_Password_Type(0, filename)); |
| 557 | DataManager::SetValue(TW_CRYPTO_PASSWORD, ""); |
| 558 | DataManager::SetValue("tw_crypto_display", ""); |
| 559 | } |
| 560 | #else |
| 561 | LOGERR("FBE found but FBE support not present in TWRP\n"); |
| 562 | #endif |
| 563 | } else { |
| 564 | // Filesystem is not encrypted and the mount succeeded, so return to |
| 565 | // the original unmounted state |
| 566 | UnMount(false); |
| 567 | } |
Matt Mower | 72c87ce | 2016-04-26 14:34:56 -0500 | [diff] [blame] | 568 | } |
| 569 | if (datamedia && (!Is_Encrypted || (Is_Encrypted && Is_Decrypted))) { |
| 570 | Setup_Data_Media(); |
| 571 | Recreate_Media_Folder(); |
| 572 | } |
| 573 | #else |
| 574 | if (datamedia) { |
| 575 | Setup_Data_Media(); |
| 576 | Recreate_Media_Folder(); |
| 577 | } |
| 578 | #endif |
| 579 | } |
| 580 | |
| 581 | void TWPartition::Setup_Cache_Partition(bool Display_Error __unused) { |
| 582 | if (Mount_Point != "/cache") |
| 583 | return; |
| 584 | |
| 585 | if (!Mount(true)) |
| 586 | return; |
| 587 | |
| 588 | if (!TWFunc::Path_Exists("/cache/recovery/.")) { |
| 589 | LOGINFO("Recreating /cache/recovery folder\n"); |
| 590 | if (mkdir("/cache/recovery", S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP) != 0) |
| 591 | LOGERR("Could not create /cache/recovery\n"); |
| 592 | } |
| 593 | } |
| 594 | |
Matt Mower | 4ab42b1 | 2016-04-21 13:52:18 -0500 | [diff] [blame] | 595 | void TWPartition::Process_FS_Flags(const char *str) { |
| 596 | char *options = strdup(str); |
| 597 | char *ptr, *savep; |
Hashcode | 62bd9e0 | 2013-11-19 21:59:42 -0800 | [diff] [blame] | 598 | |
Matt Mower | 4ab42b1 | 2016-04-21 13:52:18 -0500 | [diff] [blame] | 599 | Mount_Options = ""; |
Hashcode | 62bd9e0 | 2013-11-19 21:59:42 -0800 | [diff] [blame] | 600 | |
Matt Mower | 4ab42b1 | 2016-04-21 13:52:18 -0500 | [diff] [blame] | 601 | // Avoid issues with potentially nested strtok by using strtok_r |
| 602 | ptr = strtok_r(options, ",", &savep); |
| 603 | while (ptr) { |
| 604 | const struct flag_list* mount_flag = mount_flags; |
| 605 | |
| 606 | for (; mount_flag->name; mount_flag++) { |
| 607 | // mount_flags are never postfixed by '=', |
| 608 | // so only match identical strings (including length) |
| 609 | if (strcmp(ptr, mount_flag->name) == 0) { |
| 610 | Mount_Flags |= mount_flag->flag; |
Hashcode | 62bd9e0 | 2013-11-19 21:59:42 -0800 | [diff] [blame] | 611 | break; |
| 612 | } |
| 613 | } |
| 614 | |
Matt Mower | 4ab42b1 | 2016-04-21 13:52:18 -0500 | [diff] [blame] | 615 | if (mount_flag->flag == MS_RDONLY) |
| 616 | Mount_Read_Only = true; |
Hashcode | 62bd9e0 | 2013-11-19 21:59:42 -0800 | [diff] [blame] | 617 | |
Matt Mower | 4ab42b1 | 2016-04-21 13:52:18 -0500 | [diff] [blame] | 618 | if (mount_flag->name != 0) { |
| 619 | if (!Mount_Options.empty()) |
| 620 | Mount_Options += ","; |
| 621 | Mount_Options += mount_flag->name; |
| 622 | } else { |
| 623 | LOGINFO("Unhandled mount flag: '%s'\n", ptr); |
| 624 | } |
| 625 | |
| 626 | ptr = strtok_r(NULL, ",", &savep); |
| 627 | } |
| 628 | free(options); |
Hashcode | 62bd9e0 | 2013-11-19 21:59:42 -0800 | [diff] [blame] | 629 | } |
| 630 | |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 631 | void TWPartition::Apply_TW_Flag(const unsigned flag, const char* str, const bool val) { |
| 632 | switch (flag) { |
| 633 | case TWFLAG_ANDSEC: |
| 634 | Has_Android_Secure = val; |
| 635 | break; |
| 636 | case TWFLAG_BACKUP: |
| 637 | Can_Be_Backed_Up = val; |
| 638 | break; |
| 639 | case TWFLAG_BACKUPNAME: |
| 640 | Backup_Display_Name = str; |
| 641 | break; |
| 642 | case TWFLAG_BLOCKSIZE: |
| 643 | Format_Block_Size = (unsigned long)(atol(str)); |
| 644 | break; |
| 645 | case TWFLAG_CANBEWIPED: |
| 646 | Can_Be_Wiped = val; |
| 647 | break; |
| 648 | case TWFLAG_CANENCRYPTBACKUP: |
| 649 | Can_Encrypt_Backup = val; |
| 650 | break; |
| 651 | case TWFLAG_DEFAULTS: |
| 652 | // Do nothing |
| 653 | break; |
| 654 | case TWFLAG_DISPLAY: |
| 655 | Display_Name = str; |
| 656 | break; |
| 657 | case TWFLAG_ENCRYPTABLE: |
| 658 | case TWFLAG_FORCEENCRYPT: |
| 659 | Crypto_Key_Location = str; |
| 660 | break; |
| 661 | case TWFLAG_FLASHIMG: |
| 662 | Can_Flash_Img = val; |
| 663 | break; |
| 664 | case TWFLAG_FSFLAGS: |
Matt Mower | 4ab42b1 | 2016-04-21 13:52:18 -0500 | [diff] [blame] | 665 | Process_FS_Flags(str); |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 666 | break; |
| 667 | case TWFLAG_IGNOREBLKID: |
| 668 | Ignore_Blkid = val; |
| 669 | break; |
| 670 | case TWFLAG_LENGTH: |
| 671 | Length = atoi(str); |
| 672 | break; |
| 673 | case TWFLAG_MOUNTTODECRYPT: |
| 674 | Mount_To_Decrypt = val; |
| 675 | break; |
| 676 | case TWFLAG_REMOVABLE: |
| 677 | Removable = val; |
| 678 | break; |
| 679 | case TWFLAG_RETAINLAYOUTVERSION: |
| 680 | Retain_Layout_Version = val; |
| 681 | break; |
| 682 | case TWFLAG_SETTINGSSTORAGE: |
| 683 | Is_Settings_Storage = val; |
| 684 | if (Is_Settings_Storage) |
| 685 | Is_Storage = true; |
| 686 | break; |
| 687 | case TWFLAG_STORAGE: |
| 688 | Is_Storage = val; |
| 689 | break; |
| 690 | case TWFLAG_STORAGENAME: |
| 691 | Storage_Name = str; |
| 692 | break; |
| 693 | case TWFLAG_SUBPARTITIONOF: |
| 694 | Is_SubPartition = true; |
| 695 | SubPartition_Of = str; |
| 696 | break; |
| 697 | case TWFLAG_SYMLINK: |
| 698 | Symlink_Path = str; |
| 699 | break; |
| 700 | case TWFLAG_USERDATAENCRYPTBACKUP: |
| 701 | Use_Userdata_Encryption = val; |
| 702 | if (Use_Userdata_Encryption) |
| 703 | Can_Encrypt_Backup = true; |
| 704 | break; |
| 705 | case TWFLAG_USERMRF: |
| 706 | Use_Rm_Rf = val; |
| 707 | break; |
| 708 | case TWFLAG_WIPEDURINGFACTORYRESET: |
| 709 | Wipe_During_Factory_Reset = val; |
| 710 | if (Wipe_During_Factory_Reset) { |
| 711 | Can_Be_Wiped = true; |
| 712 | Wipe_Available_in_GUI = true; |
| 713 | } |
| 714 | break; |
| 715 | case TWFLAG_WIPEINGUI: |
| 716 | Wipe_Available_in_GUI = val; |
| 717 | if (Wipe_Available_in_GUI) |
| 718 | Can_Be_Wiped = true; |
| 719 | break; |
Ethan Yonker | 1b19016 | 2016-12-05 15:25:19 -0600 | [diff] [blame] | 720 | case TWFLAG_SLOTSELECT: |
| 721 | SlotSelect = true; |
| 722 | break; |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 723 | default: |
| 724 | // Should not get here |
| 725 | LOGINFO("Flag identified for processing, but later unmatched: %i\n", flag); |
| 726 | break; |
| 727 | } |
| 728 | } |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 729 | |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 730 | void TWPartition::Process_TW_Flags(char *flags, bool Display_Error) { |
| 731 | char separator[2] = {'\n', 0}; |
| 732 | char *ptr, *savep; |
| 733 | |
| 734 | // Semicolons within double-quotes are not forbidden, so replace |
| 735 | // only the semicolons intended as separators with '\n' for strtok |
| 736 | for (unsigned i = 0, skip = 0; i < strlen(flags); i++) { |
| 737 | if (flags[i] == '\"') |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 738 | skip = !skip; |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 739 | if (!skip && flags[i] == ';') |
| 740 | flags[i] = separator[0]; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 741 | } |
| 742 | |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 743 | // Avoid issues with potentially nested strtok by using strtok_r |
| 744 | ptr = strtok_r(flags, separator, &savep); |
| 745 | while (ptr) { |
| 746 | int ptr_len = strlen(ptr); |
| 747 | const struct flag_list* tw_flag = tw_flags; |
Hashcode | 62bd9e0 | 2013-11-19 21:59:42 -0800 | [diff] [blame] | 748 | |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 749 | for (; tw_flag->name; tw_flag++) { |
| 750 | int flag_len = strlen(tw_flag->name); |
| 751 | |
| 752 | if (strncmp(ptr, tw_flag->name, flag_len) == 0) { |
| 753 | bool flag_val = false; |
| 754 | |
| 755 | if (ptr_len > flag_len && (tw_flag->name)[flag_len-1] != '=' |
| 756 | && ptr[flag_len] != '=') { |
| 757 | // Handle flags with same starting string |
| 758 | // (e.g. backup and backupname) |
| 759 | continue; |
| 760 | } else if (ptr_len > flag_len && ptr[flag_len] == '=') { |
| 761 | // Handle flags with dual format: Part 1 |
| 762 | // (e.g. backup and backup=y. backup=y handled here) |
| 763 | ptr += flag_len + 1; |
| 764 | TWFunc::Strip_Quotes(ptr); |
| 765 | // Skip flags with empty argument |
| 766 | // (e.g. backup=) |
| 767 | if (strlen(ptr) == 0) { |
| 768 | LOGINFO("Flag missing argument or should not include '=': %s=\n", tw_flag->name); |
| 769 | break; |
| 770 | } |
| 771 | flag_val = strchr("yY1", *ptr) != NULL; |
| 772 | } else if (ptr_len == flag_len |
| 773 | && (tw_flag->name)[flag_len-1] == '=') { |
| 774 | // Skip flags missing argument after = |
| 775 | // (e.g. backupname=) |
| 776 | LOGINFO("Flag missing argument: %s\n", tw_flag->name); |
| 777 | break; |
| 778 | } else if (ptr_len > flag_len |
| 779 | && (tw_flag->name)[flag_len-1] == '=') { |
| 780 | // Handle arguments to flags |
| 781 | // (e.g. backupname="My Stuff") |
| 782 | ptr += flag_len; |
| 783 | TWFunc::Strip_Quotes(ptr); |
| 784 | // Skip flags with empty argument |
| 785 | // (e.g. backupname="") |
| 786 | if (strlen(ptr) == 0) { |
| 787 | LOGINFO("Flag missing argument: %s\n", tw_flag->name); |
| 788 | break; |
| 789 | } |
| 790 | } else if (ptr_len == flag_len) { |
| 791 | // Handle flags with dual format: Part 2 |
| 792 | // (e.g. backup and backup=y. backup handled here) |
| 793 | flag_val = true; |
Ethan Yonker | 96af84a | 2015-01-05 14:58:36 -0600 | [diff] [blame] | 794 | } else { |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 795 | LOGINFO("Flag matched, but could not be processed: %s\n", ptr); |
| 796 | break; |
Ethan Yonker | 96af84a | 2015-01-05 14:58:36 -0600 | [diff] [blame] | 797 | } |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 798 | |
| 799 | Apply_TW_Flag(tw_flag->flag, ptr, flag_val); |
| 800 | break; |
Ethan Yonker | 96af84a | 2015-01-05 14:58:36 -0600 | [diff] [blame] | 801 | } |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 802 | } |
| 803 | if (tw_flag->name == 0) { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 804 | if (Display_Error) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 805 | LOGERR("Unhandled flag: '%s'\n", ptr); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 806 | else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 807 | LOGINFO("Unhandled flag: '%s'\n", ptr); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 808 | } |
Matt Mower | 2416a50 | 2016-04-12 19:54:46 -0500 | [diff] [blame] | 809 | ptr = strtok_r(NULL, separator, &savep); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 810 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 811 | } |
| 812 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 813 | bool TWPartition::Is_File_System(string File_System) { |
| 814 | if (File_System == "ext2" || |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 815 | File_System == "ext3" || |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 816 | File_System == "ext4" || |
| 817 | File_System == "vfat" || |
| 818 | File_System == "ntfs" || |
| 819 | File_System == "yaffs2" || |
bigbiff bigbiff | 3e14652 | 2012-11-14 14:32:59 -0500 | [diff] [blame] | 820 | File_System == "exfat" || |
Dees_Troy | e501704 | 2013-08-29 16:38:55 +0000 | [diff] [blame] | 821 | File_System == "f2fs" || |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 822 | File_System == "auto") |
| 823 | return true; |
| 824 | else |
| 825 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 826 | } |
| 827 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 828 | bool TWPartition::Is_Image(string File_System) { |
Dees_Troy | 5fcd8f9 | 2012-10-16 12:22:05 -0400 | [diff] [blame] | 829 | if (File_System == "emmc" || File_System == "mtd" || File_System == "bml") |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 830 | return true; |
| 831 | else |
| 832 | return false; |
| 833 | } |
| 834 | |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 835 | bool TWPartition::Make_Dir(string Path, bool Display_Error) { |
Ethan Yonker | 93ac7a0 | 2016-11-07 22:05:58 -0600 | [diff] [blame] | 836 | if (TWFunc::Get_D_Type_From_Stat(Path) != S_IFDIR) |
| 837 | unlink(Path.c_str()); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 838 | if (!TWFunc::Path_Exists(Path)) { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 839 | if (mkdir(Path.c_str(), 0777) == -1) { |
| 840 | if (Display_Error) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 841 | gui_msg(Msg(msg::kError, "create_folder_strerr=Can not create '{1}' folder ({2}).")(Path)(strerror(errno))); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 842 | else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 843 | LOGINFO("Can not create '%s' folder.\n", Path.c_str()); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 844 | return false; |
| 845 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 846 | LOGINFO("Created '%s' folder.\n", Path.c_str()); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 847 | return true; |
| 848 | } |
| 849 | } |
| 850 | return true; |
| 851 | } |
| 852 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 853 | void TWPartition::Setup_File_System(bool Display_Error) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 854 | Can_Be_Mounted = true; |
| 855 | Can_Be_Wiped = true; |
| 856 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 857 | // Make the mount point folder if it doesn't exist |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 858 | Make_Dir(Mount_Point, Display_Error); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 859 | Display_Name = Mount_Point.substr(1, Mount_Point.size() - 1); |
| 860 | Backup_Name = Display_Name; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 861 | Backup_Method = BM_FILES; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 862 | } |
| 863 | |
Ethan Yonker | 1b19016 | 2016-12-05 15:25:19 -0600 | [diff] [blame] | 864 | void TWPartition::Setup_Image() { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 865 | Display_Name = Mount_Point.substr(1, Mount_Point.size() - 1); |
| 866 | Backup_Name = Display_Name; |
Gary Peck | 82599a8 | 2012-11-21 16:23:12 -0800 | [diff] [blame] | 867 | if (Current_File_System == "emmc") |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 868 | Backup_Method = BM_DD; |
Gary Peck | 82599a8 | 2012-11-21 16:23:12 -0800 | [diff] [blame] | 869 | else if (Current_File_System == "mtd" || Current_File_System == "bml") |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 870 | Backup_Method = BM_FLASH_UTILS; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 871 | else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 872 | LOGINFO("Unhandled file system '%s' on image '%s'\n", Current_File_System.c_str(), Display_Name.c_str()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 873 | } |
| 874 | |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 875 | void TWPartition::Setup_AndSec(void) { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 876 | Backup_Display_Name = "Android Secure"; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 877 | Backup_Name = "and-sec"; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 878 | Can_Be_Backed_Up = true; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 879 | Has_Android_Secure = true; |
| 880 | Symlink_Path = Mount_Point + "/.android_secure"; |
| 881 | Symlink_Mount_Point = "/and-sec"; |
| 882 | Backup_Path = Symlink_Mount_Point; |
| 883 | Make_Dir("/and-sec", true); |
| 884 | Recreate_AndSec_Folder(); |
Kjell Braden | 3126a11 | 2016-06-19 16:58:15 +0000 | [diff] [blame] | 885 | Mount_Storage_Retry(true); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 886 | } |
| 887 | |
that | 9e0593e | 2014-10-08 00:01:24 +0200 | [diff] [blame] | 888 | void TWPartition::Setup_Data_Media() { |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 889 | LOGINFO("Setting up '%s' as data/media emulated storage.\n", Mount_Point.c_str()); |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 890 | if (Storage_Name.empty() || Storage_Name == "Data") |
| 891 | Storage_Name = "Internal Storage"; |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 892 | Has_Data_Media = true; |
| 893 | Is_Storage = true; |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 894 | Storage_Path = Mount_Point + "/media"; |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 895 | Symlink_Path = Storage_Path; |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 896 | if (Mount_Point == "/data") { |
| 897 | Is_Settings_Storage = true; |
| 898 | if (strcmp(EXPAND(TW_EXTERNAL_STORAGE_PATH), "/sdcard") == 0) { |
| 899 | Make_Dir("/emmc", false); |
| 900 | Symlink_Mount_Point = "/emmc"; |
| 901 | } else { |
| 902 | Make_Dir("/sdcard", false); |
| 903 | Symlink_Mount_Point = "/sdcard"; |
| 904 | } |
| 905 | if (Mount(false) && TWFunc::Path_Exists(Mount_Point + "/media/0")) { |
| 906 | Storage_Path = Mount_Point + "/media/0"; |
| 907 | Symlink_Path = Storage_Path; |
| 908 | DataManager::SetValue(TW_INTERNAL_PATH, Mount_Point + "/media/0"); |
| 909 | UnMount(true); |
| 910 | } |
| 911 | DataManager::SetValue("tw_has_internal", 1); |
| 912 | DataManager::SetValue("tw_has_data_media", 1); |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 913 | backup_exclusions.add_absolute_dir("/data/data/com.google.android.music/files"); |
Ethan Yonker | 6355b56 | 2017-05-01 09:42:17 -0500 | [diff] [blame] | 914 | wipe_exclusions.add_absolute_dir(Mount_Point + "/misc/vold"); // adopted storage keys |
Ethan Yonker | 79f88bd | 2016-12-09 14:52:12 -0600 | [diff] [blame] | 915 | ExcludeAll(Mount_Point + "/.layout_version"); |
| 916 | ExcludeAll(Mount_Point + "/system/storage.xml"); |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 917 | } else { |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 918 | if (Mount(true) && TWFunc::Path_Exists(Mount_Point + "/media/0")) { |
| 919 | Storage_Path = Mount_Point + "/media/0"; |
| 920 | Symlink_Path = Storage_Path; |
| 921 | UnMount(true); |
| 922 | } |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 923 | } |
Ethan Yonker | 79f88bd | 2016-12-09 14:52:12 -0600 | [diff] [blame] | 924 | ExcludeAll(Mount_Point + "/media"); |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 925 | } |
| 926 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 927 | void TWPartition::Find_Real_Block_Device(string& Block, bool Display_Error) { |
| 928 | char device[512], realDevice[512]; |
| 929 | |
| 930 | strcpy(device, Block.c_str()); |
| 931 | memset(realDevice, 0, sizeof(realDevice)); |
| 932 | while (readlink(device, realDevice, sizeof(realDevice)) > 0) |
| 933 | { |
| 934 | strcpy(device, realDevice); |
| 935 | memset(realDevice, 0, sizeof(realDevice)); |
| 936 | } |
| 937 | |
| 938 | if (device[0] != '/') { |
| 939 | if (Display_Error) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 940 | LOGERR("Invalid symlink path '%s' found on block device '%s'\n", device, Block.c_str()); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 941 | else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 942 | LOGINFO("Invalid symlink path '%s' found on block device '%s'\n", device, Block.c_str()); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 943 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 944 | } else { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 945 | Block = device; |
| 946 | return; |
| 947 | } |
| 948 | } |
| 949 | |
Kjell Braden | 3126a11 | 2016-06-19 16:58:15 +0000 | [diff] [blame] | 950 | bool TWPartition::Mount_Storage_Retry(bool Display_Error) { |
Dees_Troy | 8e337f3 | 2012-10-13 22:07:49 -0400 | [diff] [blame] | 951 | // On some devices, storage doesn't want to mount right away, retry and sleep |
Kjell Braden | 3126a11 | 2016-06-19 16:58:15 +0000 | [diff] [blame] | 952 | if (!Mount(Display_Error)) { |
Dees_Troy | 8e337f3 | 2012-10-13 22:07:49 -0400 | [diff] [blame] | 953 | int retry_count = 5; |
| 954 | while (retry_count > 0 && !Mount(false)) { |
| 955 | usleep(500000); |
| 956 | retry_count--; |
| 957 | } |
Kjell Braden | 3126a11 | 2016-06-19 16:58:15 +0000 | [diff] [blame] | 958 | return Mount(Display_Error); |
Dees_Troy | 8e337f3 | 2012-10-13 22:07:49 -0400 | [diff] [blame] | 959 | } |
Kjell Braden | 3126a11 | 2016-06-19 16:58:15 +0000 | [diff] [blame] | 960 | return true; |
Dees_Troy | 8e337f3 | 2012-10-13 22:07:49 -0400 | [diff] [blame] | 961 | } |
| 962 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 963 | bool TWPartition::Find_MTD_Block_Device(string MTD_Name) { |
| 964 | FILE *fp = NULL; |
| 965 | char line[255]; |
| 966 | |
| 967 | fp = fopen("/proc/mtd", "rt"); |
| 968 | if (fp == NULL) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 969 | LOGERR("Device does not support /proc/mtd\n"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 970 | return false; |
| 971 | } |
| 972 | |
| 973 | while (fgets(line, sizeof(line), fp) != NULL) |
| 974 | { |
| 975 | char device[32], label[32]; |
| 976 | unsigned long size = 0; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 977 | int deviceId; |
| 978 | |
| 979 | sscanf(line, "%s %lx %*s %*c%s", device, &size, label); |
| 980 | |
| 981 | // Skip header and blank lines |
| 982 | if ((strcmp(device, "dev:") == 0) || (strlen(line) < 8)) |
| 983 | continue; |
| 984 | |
| 985 | // Strip off the trailing " from the label |
| 986 | label[strlen(label)-1] = '\0'; |
| 987 | |
| 988 | if (strcmp(label, MTD_Name.c_str()) == 0) { |
| 989 | // We found our device |
| 990 | // Strip off the trailing : from the device |
| 991 | device[strlen(device)-1] = '\0'; |
| 992 | if (sscanf(device,"mtd%d", &deviceId) == 1) { |
| 993 | sprintf(device, "/dev/block/mtdblock%d", deviceId); |
| 994 | Primary_Block_Device = device; |
Dees_Troy | 76543db | 2013-06-19 16:24:30 +0000 | [diff] [blame] | 995 | fclose(fp); |
| 996 | return true; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 997 | } |
| 998 | } |
| 999 | } |
| 1000 | fclose(fp); |
| 1001 | |
| 1002 | return false; |
| 1003 | } |
| 1004 | |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1005 | bool TWPartition::Get_Size_Via_statfs(bool Display_Error) { |
| 1006 | struct statfs st; |
| 1007 | string Local_Path = Mount_Point + "/."; |
| 1008 | |
| 1009 | if (!Mount(Display_Error)) |
| 1010 | return false; |
| 1011 | |
| 1012 | if (statfs(Local_Path.c_str(), &st) != 0) { |
| 1013 | if (!Removable) { |
| 1014 | if (Display_Error) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1015 | LOGERR("Unable to statfs '%s'\n", Local_Path.c_str()); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1016 | else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1017 | LOGINFO("Unable to statfs '%s'\n", Local_Path.c_str()); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1018 | } |
| 1019 | return false; |
| 1020 | } |
| 1021 | Size = (st.f_blocks * st.f_bsize); |
| 1022 | Used = ((st.f_blocks - st.f_bfree) * st.f_bsize); |
| 1023 | Free = (st.f_bfree * st.f_bsize); |
| 1024 | Backup_Size = Used; |
| 1025 | return true; |
| 1026 | } |
| 1027 | |
| 1028 | bool TWPartition::Get_Size_Via_df(bool Display_Error) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1029 | FILE* fp; |
| 1030 | char command[255], line[512]; |
| 1031 | int include_block = 1; |
| 1032 | unsigned int min_len; |
| 1033 | |
| 1034 | if (!Mount(Display_Error)) |
| 1035 | return false; |
| 1036 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1037 | min_len = Actual_Block_Device.size() + 2; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1038 | sprintf(command, "df %s > /tmp/dfoutput.txt", Mount_Point.c_str()); |
Vojtech Bocek | 0553420 | 2013-09-11 08:11:56 +0200 | [diff] [blame] | 1039 | TWFunc::Exec_Cmd(command); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1040 | fp = fopen("/tmp/dfoutput.txt", "rt"); |
| 1041 | if (fp == NULL) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1042 | LOGINFO("Unable to open /tmp/dfoutput.txt.\n"); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1043 | return false; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1044 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1045 | |
| 1046 | while (fgets(line, sizeof(line), fp) != NULL) |
| 1047 | { |
| 1048 | unsigned long blocks, used, available; |
| 1049 | char device[64]; |
| 1050 | char tmpString[64]; |
| 1051 | |
| 1052 | if (strncmp(line, "Filesystem", 10) == 0) |
| 1053 | continue; |
| 1054 | if (strlen(line) < min_len) { |
| 1055 | include_block = 0; |
| 1056 | continue; |
| 1057 | } |
| 1058 | if (include_block) { |
| 1059 | sscanf(line, "%s %lu %lu %lu", device, &blocks, &used, &available); |
| 1060 | } else { |
| 1061 | // The device block string is so long that the df information is on the next line |
| 1062 | int space_count = 0; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1063 | sprintf(tmpString, "/dev/block/%s", Actual_Block_Device.c_str()); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1064 | while (tmpString[space_count] == 32) |
| 1065 | space_count++; |
| 1066 | sscanf(line + space_count, "%lu %lu %lu", &blocks, &used, &available); |
| 1067 | } |
| 1068 | |
| 1069 | // Adjust block size to byte size |
| 1070 | Size = blocks * 1024ULL; |
| 1071 | Used = used * 1024ULL; |
| 1072 | Free = available * 1024ULL; |
| 1073 | Backup_Size = Used; |
| 1074 | } |
| 1075 | fclose(fp); |
| 1076 | return true; |
| 1077 | } |
| 1078 | |
Ethan Yonker | d18a821 | 2015-12-14 10:17:00 -0600 | [diff] [blame] | 1079 | unsigned long long TWPartition::IOCTL_Get_Block_Size() { |
Ethan Yonker | d18a821 | 2015-12-14 10:17:00 -0600 | [diff] [blame] | 1080 | Find_Actual_Block_Device(); |
Ethan Yonker | 483e9f4 | 2016-01-11 22:21:18 -0600 | [diff] [blame] | 1081 | |
| 1082 | return TWFunc::IOCTL_Get_Block_Size(Actual_Block_Device.c_str()); |
Ethan Yonker | d18a821 | 2015-12-14 10:17:00 -0600 | [diff] [blame] | 1083 | } |
| 1084 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1085 | bool TWPartition::Find_Partition_Size(void) { |
| 1086 | FILE* fp; |
| 1087 | char line[512]; |
| 1088 | string tmpdevice; |
| 1089 | |
igoriok | 87e3d93 | 2013-01-31 21:03:53 +0200 | [diff] [blame] | 1090 | fp = fopen("/proc/dumchar_info", "rt"); |
| 1091 | if (fp != NULL) { |
| 1092 | while (fgets(line, sizeof(line), fp) != NULL) |
| 1093 | { |
| 1094 | char label[32], device[32]; |
| 1095 | unsigned long size = 0; |
| 1096 | |
that | d43bf2d | 2014-09-21 23:13:02 +0200 | [diff] [blame] | 1097 | sscanf(line, "%s %lx %*x %*u %s", label, &size, device); |
igoriok | 87e3d93 | 2013-01-31 21:03:53 +0200 | [diff] [blame] | 1098 | |
bigbiff bigbiff | 34684ff | 2013-12-01 21:03:45 -0500 | [diff] [blame] | 1099 | // Skip header, annotation and blank lines |
igoriok | 87e3d93 | 2013-01-31 21:03:53 +0200 | [diff] [blame] | 1100 | if ((strncmp(device, "/dev/", 5) != 0) || (strlen(line) < 8)) |
| 1101 | continue; |
| 1102 | |
| 1103 | tmpdevice = "/dev/"; |
| 1104 | tmpdevice += label; |
| 1105 | if (tmpdevice == Primary_Block_Device || tmpdevice == Alternate_Block_Device) { |
| 1106 | Size = size; |
| 1107 | fclose(fp); |
| 1108 | return true; |
| 1109 | } |
| 1110 | } |
| 1111 | } |
| 1112 | |
Ethan Yonker | d18a821 | 2015-12-14 10:17:00 -0600 | [diff] [blame] | 1113 | unsigned long long ioctl_size = IOCTL_Get_Block_Size(); |
| 1114 | if (ioctl_size) { |
| 1115 | Size = ioctl_size; |
| 1116 | return true; |
| 1117 | } |
| 1118 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1119 | // In this case, we'll first get the partitions we care about (with labels) |
| 1120 | fp = fopen("/proc/partitions", "rt"); |
| 1121 | if (fp == NULL) |
| 1122 | return false; |
| 1123 | |
| 1124 | while (fgets(line, sizeof(line), fp) != NULL) |
| 1125 | { |
| 1126 | unsigned long major, minor, blocks; |
| 1127 | char device[512]; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1128 | |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 1129 | if (strlen(line) < 7 || line[0] == 'm') continue; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1130 | sscanf(line + 1, "%lu %lu %lu %s", &major, &minor, &blocks, device); |
| 1131 | |
| 1132 | tmpdevice = "/dev/block/"; |
| 1133 | tmpdevice += device; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1134 | if (tmpdevice == Primary_Block_Device || tmpdevice == Alternate_Block_Device) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1135 | // Adjust block size to byte size |
| 1136 | Size = blocks * 1024ULL; |
| 1137 | fclose(fp); |
| 1138 | return true; |
| 1139 | } |
| 1140 | } |
| 1141 | fclose(fp); |
| 1142 | return false; |
| 1143 | } |
| 1144 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1145 | bool TWPartition::Is_Mounted(void) { |
| 1146 | if (!Can_Be_Mounted) |
| 1147 | return false; |
| 1148 | |
| 1149 | struct stat st1, st2; |
| 1150 | string test_path; |
| 1151 | |
| 1152 | // Check to see if the mount point directory exists |
| 1153 | test_path = Mount_Point + "/."; |
| 1154 | if (stat(test_path.c_str(), &st1) != 0) return false; |
| 1155 | |
| 1156 | // Check to see if the directory above the mount point exists |
| 1157 | test_path = Mount_Point + "/../."; |
| 1158 | if (stat(test_path.c_str(), &st2) != 0) return false; |
| 1159 | |
| 1160 | // Compare the device IDs -- if they match then we're (probably) using tmpfs instead of an actual device |
| 1161 | int ret = (st1.st_dev != st2.st_dev) ? true : false; |
| 1162 | |
| 1163 | return ret; |
| 1164 | } |
| 1165 | |
James Christopher Adduono | d6f94ac | 2016-02-29 04:26:04 -0500 | [diff] [blame] | 1166 | bool TWPartition::Is_File_System_Writable(void) { |
| 1167 | if (!Is_File_System(Current_File_System) || !Is_Mounted()) |
| 1168 | return false; |
| 1169 | |
| 1170 | string test_path = Mount_Point + "/."; |
| 1171 | return (access(test_path.c_str(), W_OK) == 0); |
| 1172 | } |
| 1173 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1174 | bool TWPartition::Mount(bool Display_Error) { |
Dees_Troy | 3f5c4e8 | 2013-02-01 15:16:59 +0000 | [diff] [blame] | 1175 | int exfat_mounted = 0; |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 1176 | unsigned long flags = Mount_Flags; |
Dees_Troy | 3f5c4e8 | 2013-02-01 15:16:59 +0000 | [diff] [blame] | 1177 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1178 | if (Is_Mounted()) { |
| 1179 | return true; |
| 1180 | } else if (!Can_Be_Mounted) { |
| 1181 | return false; |
| 1182 | } |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1183 | |
| 1184 | Find_Actual_Block_Device(); |
| 1185 | |
| 1186 | // Check the current file system before mounting |
| 1187 | Check_FS_Type(); |
Dees_Troy | 3f5c4e8 | 2013-02-01 15:16:59 +0000 | [diff] [blame] | 1188 | if (Current_File_System == "exfat" && TWFunc::Path_Exists("/sbin/exfat-fuse")) { |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 1189 | string cmd = "/sbin/exfat-fuse -o big_writes,max_read=131072,max_write=131072 " + Actual_Block_Device + " " + Mount_Point; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1190 | LOGINFO("cmd: %s\n", cmd.c_str()); |
Dees_Troy | 3f5c4e8 | 2013-02-01 15:16:59 +0000 | [diff] [blame] | 1191 | string result; |
| 1192 | if (TWFunc::Exec_Cmd(cmd, result) != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1193 | LOGINFO("exfat-fuse failed to mount with result '%s', trying vfat\n", result.c_str()); |
Dees_Troy | 3f5c4e8 | 2013-02-01 15:16:59 +0000 | [diff] [blame] | 1194 | Current_File_System = "vfat"; |
| 1195 | } else { |
| 1196 | #ifdef TW_NO_EXFAT_FUSE |
| 1197 | UnMount(false); |
| 1198 | // We'll let the kernel handle it but using exfat-fuse to detect if the file system is actually exfat |
| 1199 | // Some kernels let us mount vfat as exfat which doesn't work out too well |
| 1200 | #else |
| 1201 | exfat_mounted = 1; |
| 1202 | #endif |
| 1203 | } |
| 1204 | } |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 1205 | |
Greg Wallace | b39e6c6 | 2015-12-29 00:55:26 -0500 | [diff] [blame] | 1206 | if (Current_File_System == "ntfs" && (TWFunc::Path_Exists("/sbin/ntfs-3g") || TWFunc::Path_Exists("/sbin/mount.ntfs"))) { |
Ethan Yonker | b81d905 | 2015-07-09 13:20:53 -0500 | [diff] [blame] | 1207 | string cmd; |
Greg Wallace | b39e6c6 | 2015-12-29 00:55:26 -0500 | [diff] [blame] | 1208 | string Ntfsmount_Binary = ""; |
| 1209 | |
| 1210 | if (TWFunc::Path_Exists("/sbin/ntfs-3g")) |
| 1211 | Ntfsmount_Binary = "ntfs-3g"; |
| 1212 | else if (TWFunc::Path_Exists("/sbin/mount.ntfs")) |
| 1213 | Ntfsmount_Binary = "mount.ntfs"; |
| 1214 | |
Ethan Yonker | b81d905 | 2015-07-09 13:20:53 -0500 | [diff] [blame] | 1215 | if (Mount_Read_Only) |
Greg Wallace | b39e6c6 | 2015-12-29 00:55:26 -0500 | [diff] [blame] | 1216 | cmd = "/sbin/" + Ntfsmount_Binary + " -o ro " + Actual_Block_Device + " " + Mount_Point; |
Ethan Yonker | b81d905 | 2015-07-09 13:20:53 -0500 | [diff] [blame] | 1217 | else |
Greg Wallace | b39e6c6 | 2015-12-29 00:55:26 -0500 | [diff] [blame] | 1218 | cmd = "/sbin/" + Ntfsmount_Binary + " " + Actual_Block_Device + " " + Mount_Point; |
Ethan Yonker | b81d905 | 2015-07-09 13:20:53 -0500 | [diff] [blame] | 1219 | LOGINFO("cmd: '%s'\n", cmd.c_str()); |
Greg Wallace | b39e6c6 | 2015-12-29 00:55:26 -0500 | [diff] [blame] | 1220 | |
Ethan Yonker | b81d905 | 2015-07-09 13:20:53 -0500 | [diff] [blame] | 1221 | if (TWFunc::Exec_Cmd(cmd) == 0) { |
| 1222 | return true; |
| 1223 | } else { |
| 1224 | LOGINFO("ntfs-3g failed to mount, trying regular mount method.\n"); |
| 1225 | } |
| 1226 | } |
| 1227 | |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 1228 | if (Mount_Read_Only) |
| 1229 | flags |= MS_RDONLY; |
| 1230 | |
Dees_Troy | 2204203 | 2012-12-18 21:23:08 +0000 | [diff] [blame] | 1231 | if (Fstab_File_System == "yaffs2") { |
| 1232 | // mount an MTD partition as a YAFFS2 filesystem. |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 1233 | flags = MS_NOATIME | MS_NODEV | MS_NODIRATIME; |
| 1234 | if (Mount_Read_Only) |
| 1235 | flags |= MS_RDONLY; |
Dees_Troy | 76543db | 2013-06-19 16:24:30 +0000 | [diff] [blame] | 1236 | if (mount(Actual_Block_Device.c_str(), Mount_Point.c_str(), Fstab_File_System.c_str(), flags, NULL) < 0) { |
| 1237 | if (mount(Actual_Block_Device.c_str(), Mount_Point.c_str(), Fstab_File_System.c_str(), flags | MS_RDONLY, NULL) < 0) { |
| 1238 | if (Display_Error) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1239 | gui_msg(Msg(msg::kError, "fail_mount=Failed to mount '{1}' ({2})")(Mount_Point)(strerror(errno))); |
Dees_Troy | 76543db | 2013-06-19 16:24:30 +0000 | [diff] [blame] | 1240 | else |
| 1241 | LOGINFO("Failed to mount '%s' (MTD)\n", Mount_Point.c_str()); |
| 1242 | return false; |
| 1243 | } else { |
| 1244 | LOGINFO("Mounted '%s' (MTD) as RO\n", Mount_Point.c_str()); |
| 1245 | return true; |
| 1246 | } |
| 1247 | } else { |
| 1248 | struct stat st; |
| 1249 | string test_path = Mount_Point; |
| 1250 | if (stat(test_path.c_str(), &st) < 0) { |
| 1251 | if (Display_Error) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1252 | gui_msg(Msg(msg::kError, "fail_mount=Failed to mount '{1}' ({2})")(Mount_Point)(strerror(errno))); |
Dees_Troy | 76543db | 2013-06-19 16:24:30 +0000 | [diff] [blame] | 1253 | else |
| 1254 | LOGINFO("Failed to mount '%s' (MTD)\n", Mount_Point.c_str()); |
| 1255 | return false; |
| 1256 | } |
| 1257 | mode_t new_mode = st.st_mode | S_IXUSR | S_IXGRP | S_IXOTH; |
| 1258 | if (new_mode != st.st_mode) { |
| 1259 | LOGINFO("Fixing execute permissions for %s\n", Mount_Point.c_str()); |
| 1260 | if (chmod(Mount_Point.c_str(), new_mode) < 0) { |
| 1261 | if (Display_Error) |
| 1262 | LOGERR("Couldn't fix permissions for %s: %s\n", Mount_Point.c_str(), strerror(errno)); |
| 1263 | else |
| 1264 | LOGINFO("Couldn't fix permissions for %s: %s\n", Mount_Point.c_str(), strerror(errno)); |
| 1265 | return false; |
| 1266 | } |
| 1267 | } |
Dees_Troy | 2204203 | 2012-12-18 21:23:08 +0000 | [diff] [blame] | 1268 | return true; |
Dees_Troy | 76543db | 2013-06-19 16:24:30 +0000 | [diff] [blame] | 1269 | } |
that | c7572eb | 2015-03-31 18:55:30 +0200 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | string mount_fs = Current_File_System; |
| 1273 | if (Current_File_System == "exfat" && TWFunc::Path_Exists("/sys/module/texfat")) |
| 1274 | mount_fs = "texfat"; |
| 1275 | |
| 1276 | if (!exfat_mounted && |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 1277 | mount(Actual_Block_Device.c_str(), Mount_Point.c_str(), mount_fs.c_str(), flags, Mount_Options.c_str()) != 0 && |
| 1278 | mount(Actual_Block_Device.c_str(), Mount_Point.c_str(), mount_fs.c_str(), flags, NULL) != 0) { |
Dees_Troy | 3f5c4e8 | 2013-02-01 15:16:59 +0000 | [diff] [blame] | 1279 | #ifdef TW_NO_EXFAT_FUSE |
| 1280 | if (Current_File_System == "exfat") { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1281 | LOGINFO("Mounting exfat failed, trying vfat...\n"); |
Dees_Troy | 3f5c4e8 | 2013-02-01 15:16:59 +0000 | [diff] [blame] | 1282 | if (mount(Actual_Block_Device.c_str(), Mount_Point.c_str(), "vfat", 0, NULL) != 0) { |
Dees_Troy | 85f44ed | 2013-01-09 18:42:36 +0000 | [diff] [blame] | 1283 | if (Display_Error) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1284 | gui_msg(Msg(msg::kError, "fail_mount=Failed to mount '{1}' ({2})")(Mount_Point)(strerror(errno))); |
Dees_Troy | 85f44ed | 2013-01-09 18:42:36 +0000 | [diff] [blame] | 1285 | else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1286 | LOGINFO("Unable to mount '%s'\n", Mount_Point.c_str()); |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 1287 | LOGINFO("Actual block device: '%s', current file system: '%s', flags: 0x%8x, options: '%s'\n", Actual_Block_Device.c_str(), Current_File_System.c_str(), flags, Mount_Options.c_str()); |
Dees_Troy | 3f5c4e8 | 2013-02-01 15:16:59 +0000 | [diff] [blame] | 1288 | return false; |
Dees_Troy | 85f44ed | 2013-01-09 18:42:36 +0000 | [diff] [blame] | 1289 | } |
Dees_Troy | b05ddee | 2013-01-28 20:24:50 +0000 | [diff] [blame] | 1290 | } else { |
Dees_Troy | 3f5c4e8 | 2013-02-01 15:16:59 +0000 | [diff] [blame] | 1291 | #endif |
bigbiff bigbiff | 26774a0 | 2014-03-29 18:22:00 -0400 | [diff] [blame] | 1292 | if (!Removable && Display_Error) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1293 | gui_msg(Msg(msg::kError, "fail_mount=Failed to mount '{1}' ({2})")(Mount_Point)(strerror(errno))); |
Dees_Troy | 3f5c4e8 | 2013-02-01 15:16:59 +0000 | [diff] [blame] | 1294 | else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1295 | LOGINFO("Unable to mount '%s'\n", Mount_Point.c_str()); |
| 1296 | LOGINFO("Actual block device: '%s', current file system: '%s'\n", Actual_Block_Device.c_str(), Current_File_System.c_str()); |
Dees_Troy | 3f5c4e8 | 2013-02-01 15:16:59 +0000 | [diff] [blame] | 1297 | return false; |
| 1298 | #ifdef TW_NO_EXFAT_FUSE |
Dees_Troy | 85f44ed | 2013-01-09 18:42:36 +0000 | [diff] [blame] | 1299 | } |
| 1300 | #endif |
Dees_Troy | 3f5c4e8 | 2013-02-01 15:16:59 +0000 | [diff] [blame] | 1301 | } |
Ethan Yonker | 253368a | 2014-11-25 15:00:52 -0600 | [diff] [blame] | 1302 | |
Dees_Troy | 3f5c4e8 | 2013-02-01 15:16:59 +0000 | [diff] [blame] | 1303 | if (Removable) |
| 1304 | Update_Size(Display_Error); |
| 1305 | |
xiaolu | 9416f4f | 2015-06-04 08:22:23 +0800 | [diff] [blame] | 1306 | if (!Symlink_Mount_Point.empty() && TWFunc::Path_Exists(Symlink_Path)) { |
codelover | 2a3d4ce | 2015-03-14 20:26:49 +0800 | [diff] [blame] | 1307 | string Command = "mount -o bind '" + Symlink_Path + "' '" + Symlink_Mount_Point + "'"; |
Vojtech Bocek | 0553420 | 2013-09-11 08:11:56 +0200 | [diff] [blame] | 1308 | TWFunc::Exec_Cmd(Command); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1309 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1310 | return true; |
| 1311 | } |
| 1312 | |
| 1313 | bool TWPartition::UnMount(bool Display_Error) { |
| 1314 | if (Is_Mounted()) { |
| 1315 | int never_unmount_system; |
| 1316 | |
| 1317 | DataManager::GetValue(TW_DONT_UNMOUNT_SYSTEM, never_unmount_system); |
| 1318 | if (never_unmount_system == 1 && Mount_Point == "/system") |
| 1319 | return true; // Never unmount system if you're not supposed to unmount it |
| 1320 | |
Matt Mower | a8e6d83 | 2017-02-14 20:20:59 -0600 | [diff] [blame] | 1321 | if (Is_Storage && MTP_Storage_ID > 0) |
Ethan Yonker | 726a020 | 2014-12-16 20:01:38 -0600 | [diff] [blame] | 1322 | PartitionManager.Remove_MTP_Storage(MTP_Storage_ID); |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 1323 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1324 | if (!Symlink_Mount_Point.empty()) |
| 1325 | umount(Symlink_Mount_Point.c_str()); |
| 1326 | |
Dees_Troy | b05ddee | 2013-01-28 20:24:50 +0000 | [diff] [blame] | 1327 | umount(Mount_Point.c_str()); |
| 1328 | if (Is_Mounted()) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1329 | if (Display_Error) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1330 | gui_msg(Msg(msg::kError, "fail_unmount=Failed to unmount '{1}' ({2})")(Mount_Point)(strerror(errno))); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1331 | else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1332 | LOGINFO("Unable to unmount '%s'\n", Mount_Point.c_str()); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1333 | return false; |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 1334 | } else { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1335 | return true; |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 1336 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1337 | } else { |
| 1338 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1339 | } |
| 1340 | } |
| 1341 | |
James Christopher Adduono | d6f94ac | 2016-02-29 04:26:04 -0500 | [diff] [blame] | 1342 | bool TWPartition::ReMount(bool Display_Error) { |
| 1343 | if (UnMount(Display_Error)) |
| 1344 | return Mount(Display_Error); |
| 1345 | return false; |
| 1346 | } |
| 1347 | |
| 1348 | bool TWPartition::ReMount_RW(bool Display_Error) { |
| 1349 | // No need to remount if already mounted rw |
| 1350 | if (Is_File_System_Writable()) |
| 1351 | return true; |
| 1352 | |
| 1353 | bool ro = Mount_Read_Only; |
| 1354 | int flags = Mount_Flags; |
| 1355 | |
| 1356 | Mount_Read_Only = false; |
| 1357 | Mount_Flags &= ~MS_RDONLY; |
| 1358 | |
| 1359 | bool ret = ReMount(Display_Error); |
| 1360 | |
| 1361 | Mount_Read_Only = ro; |
| 1362 | Mount_Flags = flags; |
| 1363 | |
| 1364 | return ret; |
| 1365 | } |
| 1366 | |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 1367 | bool TWPartition::Wipe(string New_File_System) { |
Ethan Yonker | 726a020 | 2014-12-16 20:01:38 -0600 | [diff] [blame] | 1368 | bool wiped = false, update_crypt = false, recreate_media = true; |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 1369 | int check; |
| 1370 | string Layout_Filename = Mount_Point + "/.layout_version"; |
| 1371 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1372 | if (!Can_Be_Wiped) { |
Matt Mower | 3c36697 | 2015-12-25 19:28:31 -0600 | [diff] [blame] | 1373 | gui_msg(Msg(msg::kError, "cannot_wipe=Partition {1} cannot be wiped.")(Display_Name)); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1374 | return false; |
| 1375 | } |
| 1376 | |
Dees_Troy | c51f1f9 | 2012-09-20 15:32:13 -0400 | [diff] [blame] | 1377 | if (Mount_Point == "/cache") |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1378 | Log_Offset = 0; |
Dees_Troy | c51f1f9 | 2012-09-20 15:32:13 -0400 | [diff] [blame] | 1379 | |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 1380 | if (Retain_Layout_Version && Mount(false) && TWFunc::Path_Exists(Layout_Filename)) |
| 1381 | TWFunc::copy_file(Layout_Filename, "/.layout_version", 0600); |
| 1382 | else |
| 1383 | unlink("/.layout_version"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1384 | |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1385 | if (Has_Data_Media && Current_File_System == New_File_System) { |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 1386 | wiped = Wipe_Data_Without_Wiping_Media(); |
Ethan Yonker | 5eac222 | 2014-06-11 12:22:55 -0500 | [diff] [blame] | 1387 | recreate_media = false; |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 1388 | } else { |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 1389 | DataManager::GetValue(TW_RM_RF_VAR, check); |
| 1390 | |
Hashcode | dabfd49 | 2013-08-29 22:45:30 -0700 | [diff] [blame] | 1391 | if (check || Use_Rm_Rf) |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 1392 | wiped = Wipe_RMRF(); |
| 1393 | else if (New_File_System == "ext4") |
| 1394 | wiped = Wipe_EXT4(); |
| 1395 | else if (New_File_System == "ext2" || New_File_System == "ext3") |
| 1396 | wiped = Wipe_EXT23(New_File_System); |
| 1397 | else if (New_File_System == "vfat") |
| 1398 | wiped = Wipe_FAT(); |
| 1399 | else if (New_File_System == "exfat") |
| 1400 | wiped = Wipe_EXFAT(); |
| 1401 | else if (New_File_System == "yaffs2") |
| 1402 | wiped = Wipe_MTD(); |
Dees_Troy | e501704 | 2013-08-29 16:38:55 +0000 | [diff] [blame] | 1403 | else if (New_File_System == "f2fs") |
| 1404 | wiped = Wipe_F2FS(); |
Ethan Yonker | b81d905 | 2015-07-09 13:20:53 -0500 | [diff] [blame] | 1405 | else if (New_File_System == "ntfs") |
| 1406 | wiped = Wipe_NTFS(); |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 1407 | else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1408 | LOGERR("Unable to wipe '%s' -- unknown file system '%s'\n", Mount_Point.c_str(), New_File_System.c_str()); |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 1409 | unlink("/.layout_version"); |
| 1410 | return false; |
| 1411 | } |
| 1412 | update_crypt = wiped; |
Gary Peck | e8bc5d7 | 2012-12-21 06:45:25 -0800 | [diff] [blame] | 1413 | } |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1414 | |
Gary Peck | e8bc5d7 | 2012-12-21 06:45:25 -0800 | [diff] [blame] | 1415 | if (wiped) { |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 1416 | if (Mount_Point == "/cache") |
| 1417 | DataManager::Output_Version(); |
| 1418 | |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 1419 | if (TWFunc::Path_Exists("/.layout_version") && Mount(false)) |
| 1420 | TWFunc::copy_file("/.layout_version", Layout_Filename, 0600); |
| 1421 | |
| 1422 | if (update_crypt) { |
| 1423 | Setup_File_System(false); |
| 1424 | if (Is_Encrypted && !Is_Decrypted) { |
| 1425 | // just wiped an encrypted partition back to its unencrypted state |
| 1426 | Is_Encrypted = false; |
| 1427 | Is_Decrypted = false; |
| 1428 | Decrypted_Block_Device = ""; |
| 1429 | if (Mount_Point == "/data") { |
| 1430 | DataManager::SetValue(TW_IS_ENCRYPTED, 0); |
| 1431 | DataManager::SetValue(TW_IS_DECRYPTED, 0); |
| 1432 | } |
Gary Peck | e8bc5d7 | 2012-12-21 06:45:25 -0800 | [diff] [blame] | 1433 | } |
| 1434 | } |
Ethan Yonker | 5eac222 | 2014-06-11 12:22:55 -0500 | [diff] [blame] | 1435 | |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 1436 | if (Has_Data_Media && recreate_media) { |
Ethan Yonker | 5eac222 | 2014-06-11 12:22:55 -0500 | [diff] [blame] | 1437 | Recreate_Media_Folder(); |
| 1438 | } |
Matt Mower | 209c963 | 2016-01-20 12:08:35 -0600 | [diff] [blame] | 1439 | if (Is_Storage && Mount(false)) |
| 1440 | PartitionManager.Add_MTP_Storage(MTP_Storage_ID); |
Gary Peck | e8bc5d7 | 2012-12-21 06:45:25 -0800 | [diff] [blame] | 1441 | } |
Matt Mower | 209c963 | 2016-01-20 12:08:35 -0600 | [diff] [blame] | 1442 | |
Gary Peck | e8bc5d7 | 2012-12-21 06:45:25 -0800 | [diff] [blame] | 1443 | return wiped; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1444 | } |
| 1445 | |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 1446 | bool TWPartition::Wipe() { |
Gary Peck | 82599a8 | 2012-11-21 16:23:12 -0800 | [diff] [blame] | 1447 | if (Is_File_System(Current_File_System)) |
| 1448 | return Wipe(Current_File_System); |
| 1449 | else |
| 1450 | return Wipe(Fstab_File_System); |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 1451 | } |
| 1452 | |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1453 | bool TWPartition::Wipe_AndSec(void) { |
| 1454 | if (!Has_Android_Secure) |
| 1455 | return false; |
| 1456 | |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1457 | if (!Mount(true)) |
| 1458 | return false; |
| 1459 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1460 | gui_msg(Msg("wiping=Wiping {1}")(Backup_Display_Name)); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1461 | TWFunc::removeDir(Mount_Point + "/.android_secure/", true); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1462 | return true; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1463 | } |
| 1464 | |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1465 | bool TWPartition::Can_Repair() { |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 1466 | if (Mount_Read_Only) |
| 1467 | return false; |
Matt Mower | 18794c8 | 2015-11-11 16:22:45 -0600 | [diff] [blame] | 1468 | if (Current_File_System == "vfat" && TWFunc::Path_Exists("/sbin/fsck.fat")) |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1469 | return true; |
| 1470 | else if ((Current_File_System == "ext2" || Current_File_System == "ext3" || Current_File_System == "ext4") && TWFunc::Path_Exists("/sbin/e2fsck")) |
| 1471 | return true; |
| 1472 | else if (Current_File_System == "exfat" && TWFunc::Path_Exists("/sbin/fsck.exfat")) |
| 1473 | return true; |
| 1474 | else if (Current_File_System == "f2fs" && TWFunc::Path_Exists("/sbin/fsck.f2fs")) |
| 1475 | return true; |
Greg Wallace | b39e6c6 | 2015-12-29 00:55:26 -0500 | [diff] [blame] | 1476 | else if (Current_File_System == "ntfs" && (TWFunc::Path_Exists("/sbin/ntfsfix") || TWFunc::Path_Exists("/sbin/fsck.ntfs"))) |
Ethan Yonker | b81d905 | 2015-07-09 13:20:53 -0500 | [diff] [blame] | 1477 | return true; |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1478 | return false; |
| 1479 | } |
| 1480 | |
| 1481 | bool TWPartition::Repair() { |
| 1482 | string command; |
| 1483 | |
| 1484 | if (Current_File_System == "vfat") { |
Matt Mower | 18794c8 | 2015-11-11 16:22:45 -0600 | [diff] [blame] | 1485 | if (!TWFunc::Path_Exists("/sbin/fsck.fat")) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1486 | gui_msg(Msg(msg::kError, "repair_not_exist={1} does not exist! Cannot repair!")("fsck.fat")); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1487 | return false; |
| 1488 | } |
| 1489 | if (!UnMount(true)) |
| 1490 | return false; |
Greg Wallace | 2d65340 | 2015-12-29 14:19:21 -0500 | [diff] [blame] | 1491 | gui_msg(Msg("repairing_using=Repairing {1} using {2}...")(Display_Name)("fsck.fat")); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1492 | Find_Actual_Block_Device(); |
Matt Mower | 18794c8 | 2015-11-11 16:22:45 -0600 | [diff] [blame] | 1493 | command = "/sbin/fsck.fat -y " + Actual_Block_Device; |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1494 | LOGINFO("Repair command: %s\n", command.c_str()); |
| 1495 | if (TWFunc::Exec_Cmd(command) == 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1496 | gui_msg("done=Done."); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1497 | return true; |
| 1498 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1499 | gui_msg(Msg(msg::kError, "unable_repair=Unable to repair {1}.")(Display_Name)); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1500 | return false; |
| 1501 | } |
| 1502 | } |
| 1503 | if (Current_File_System == "ext2" || Current_File_System == "ext3" || Current_File_System == "ext4") { |
| 1504 | if (!TWFunc::Path_Exists("/sbin/e2fsck")) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1505 | gui_msg(Msg(msg::kError, "repair_not_exist={1} does not exist! Cannot repair!")("e2fsck")); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1506 | return false; |
| 1507 | } |
| 1508 | if (!UnMount(true)) |
| 1509 | return false; |
Greg Wallace | 2d65340 | 2015-12-29 14:19:21 -0500 | [diff] [blame] | 1510 | gui_msg(Msg("repairing_using=Repairing {1} using {2}...")(Display_Name)("e2fsck")); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1511 | Find_Actual_Block_Device(); |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 1512 | command = "/sbin/e2fsck -fp " + Actual_Block_Device; |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1513 | LOGINFO("Repair command: %s\n", command.c_str()); |
| 1514 | if (TWFunc::Exec_Cmd(command) == 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1515 | gui_msg("done=Done."); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1516 | return true; |
| 1517 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1518 | gui_msg(Msg(msg::kError, "unable_repair=Unable to repair {1}.")(Display_Name)); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1519 | return false; |
| 1520 | } |
| 1521 | } |
| 1522 | if (Current_File_System == "exfat") { |
| 1523 | if (!TWFunc::Path_Exists("/sbin/fsck.exfat")) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1524 | gui_msg(Msg(msg::kError, "repair_not_exist={1} does not exist! Cannot repair!")("fsck.exfat")); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1525 | return false; |
| 1526 | } |
| 1527 | if (!UnMount(true)) |
| 1528 | return false; |
Greg Wallace | 2d65340 | 2015-12-29 14:19:21 -0500 | [diff] [blame] | 1529 | gui_msg(Msg("repairing_using=Repairing {1} using {2}...")(Display_Name)("fsck.exfat")); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1530 | Find_Actual_Block_Device(); |
| 1531 | command = "/sbin/fsck.exfat " + Actual_Block_Device; |
| 1532 | LOGINFO("Repair command: %s\n", command.c_str()); |
| 1533 | if (TWFunc::Exec_Cmd(command) == 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1534 | gui_msg("done=Done."); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1535 | return true; |
| 1536 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1537 | gui_msg(Msg(msg::kError, "unable_repair=Unable to repair {1}.")(Display_Name)); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1538 | return false; |
| 1539 | } |
| 1540 | } |
| 1541 | if (Current_File_System == "f2fs") { |
| 1542 | if (!TWFunc::Path_Exists("/sbin/fsck.f2fs")) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1543 | gui_msg(Msg(msg::kError, "repair_not_exist={1} does not exist! Cannot repair!")("fsck.f2fs")); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1544 | return false; |
| 1545 | } |
| 1546 | if (!UnMount(true)) |
| 1547 | return false; |
Greg Wallace | 2d65340 | 2015-12-29 14:19:21 -0500 | [diff] [blame] | 1548 | gui_msg(Msg("repairing_using=Repairing {1} using {2}...")(Display_Name)("fsck.f2fs")); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1549 | Find_Actual_Block_Device(); |
| 1550 | command = "/sbin/fsck.f2fs " + Actual_Block_Device; |
| 1551 | LOGINFO("Repair command: %s\n", command.c_str()); |
| 1552 | if (TWFunc::Exec_Cmd(command) == 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1553 | gui_msg("done=Done."); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1554 | return true; |
| 1555 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1556 | gui_msg(Msg(msg::kError, "unable_repair=Unable to repair {1}.")(Display_Name)); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1557 | return false; |
| 1558 | } |
| 1559 | } |
Ethan Yonker | b81d905 | 2015-07-09 13:20:53 -0500 | [diff] [blame] | 1560 | if (Current_File_System == "ntfs") { |
Greg Wallace | b39e6c6 | 2015-12-29 00:55:26 -0500 | [diff] [blame] | 1561 | string Ntfsfix_Binary; |
| 1562 | if (TWFunc::Path_Exists("/sbin/ntfsfix")) |
| 1563 | Ntfsfix_Binary = "ntfsfix"; |
| 1564 | else if (TWFunc::Path_Exists("/sbin/fsck.ntfs")) |
| 1565 | Ntfsfix_Binary = "fsck.ntfs"; |
| 1566 | else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1567 | gui_msg(Msg(msg::kError, "repair_not_exist={1} does not exist! Cannot repair!")("ntfsfix")); |
Ethan Yonker | b81d905 | 2015-07-09 13:20:53 -0500 | [diff] [blame] | 1568 | return false; |
| 1569 | } |
| 1570 | if (!UnMount(true)) |
| 1571 | return false; |
Greg Wallace | 2d65340 | 2015-12-29 14:19:21 -0500 | [diff] [blame] | 1572 | gui_msg(Msg("repairing_using=Repairing {1} using {2}...")(Display_Name)(Ntfsfix_Binary)); |
Ethan Yonker | b81d905 | 2015-07-09 13:20:53 -0500 | [diff] [blame] | 1573 | Find_Actual_Block_Device(); |
Greg Wallace | b39e6c6 | 2015-12-29 00:55:26 -0500 | [diff] [blame] | 1574 | command = "/sbin/" + Ntfsfix_Binary + " " + Actual_Block_Device; |
Ethan Yonker | b81d905 | 2015-07-09 13:20:53 -0500 | [diff] [blame] | 1575 | LOGINFO("Repair command: %s\n", command.c_str()); |
| 1576 | if (TWFunc::Exec_Cmd(command) == 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1577 | gui_msg("done=Done."); |
Ethan Yonker | b81d905 | 2015-07-09 13:20:53 -0500 | [diff] [blame] | 1578 | return true; |
| 1579 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1580 | gui_msg(Msg(msg::kError, "unable_repair=Unable to repair {1}.")(Display_Name)); |
Ethan Yonker | b81d905 | 2015-07-09 13:20:53 -0500 | [diff] [blame] | 1581 | return false; |
| 1582 | } |
| 1583 | } |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1584 | return false; |
| 1585 | } |
| 1586 | |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 1587 | bool TWPartition::Can_Resize() { |
| 1588 | if (Mount_Read_Only) |
| 1589 | return false; |
| 1590 | if ((Current_File_System == "ext2" || Current_File_System == "ext3" || Current_File_System == "ext4") && TWFunc::Path_Exists("/sbin/resize2fs")) |
| 1591 | return true; |
| 1592 | return false; |
| 1593 | } |
| 1594 | |
| 1595 | bool TWPartition::Resize() { |
| 1596 | string command; |
| 1597 | |
| 1598 | if (Current_File_System == "ext2" || Current_File_System == "ext3" || Current_File_System == "ext4") { |
| 1599 | if (!Can_Repair()) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1600 | LOGINFO("Cannot resize %s because %s cannot be repaired before resizing.\n", Display_Name.c_str(), Display_Name.c_str()); |
| 1601 | gui_msg(Msg(msg::kError, "cannot_resize=Cannot resize {1}.")(Display_Name)); |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 1602 | return false; |
| 1603 | } |
| 1604 | if (!TWFunc::Path_Exists("/sbin/resize2fs")) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1605 | LOGINFO("resize2fs does not exist! Cannot resize!\n"); |
| 1606 | gui_msg(Msg(msg::kError, "cannot_resize=Cannot resize {1}.")(Display_Name)); |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 1607 | return false; |
| 1608 | } |
| 1609 | // Repair will unmount so no need to do it twice |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1610 | gui_msg(Msg("repair_resize=Repairing {1} before resizing.")( Display_Name)); |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 1611 | if (!Repair()) |
| 1612 | return false; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1613 | gui_msg(Msg("resizing=Resizing {1} using {2}...")(Display_Name)("resize2fs")); |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 1614 | Find_Actual_Block_Device(); |
| 1615 | command = "/sbin/resize2fs " + Actual_Block_Device; |
| 1616 | if (Length != 0) { |
Ethan Yonker | d18a821 | 2015-12-14 10:17:00 -0600 | [diff] [blame] | 1617 | unsigned long long Actual_Size = IOCTL_Get_Block_Size(); |
| 1618 | if (Actual_Size == 0) |
| 1619 | return false; |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 1620 | |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 1621 | unsigned long long Block_Count; |
| 1622 | if (Length < 0) { |
| 1623 | // Reduce overall size by this length |
| 1624 | Block_Count = (Actual_Size / 1024LLU) - ((unsigned long long)(Length * -1) / 1024LLU); |
| 1625 | } else { |
| 1626 | // This is the size, not a size reduction |
| 1627 | Block_Count = ((unsigned long long)(Length) / 1024LLU); |
| 1628 | } |
| 1629 | char temp[256]; |
| 1630 | sprintf(temp, "%llu", Block_Count); |
| 1631 | command += " "; |
| 1632 | command += temp; |
| 1633 | command += "K"; |
| 1634 | } |
| 1635 | LOGINFO("Resize command: %s\n", command.c_str()); |
| 1636 | if (TWFunc::Exec_Cmd(command) == 0) { |
| 1637 | Update_Size(true); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1638 | gui_msg("done=Done."); |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 1639 | return true; |
| 1640 | } else { |
| 1641 | Update_Size(true); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1642 | gui_msg(Msg(msg::kError, "unable_resize=Unable to resize {1}.")(Display_Name)); |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 1643 | return false; |
| 1644 | } |
| 1645 | } |
| 1646 | return false; |
| 1647 | } |
| 1648 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1649 | bool TWPartition::Backup(PartitionSettings *part_settings, pid_t *tar_fork_pid) { |
| 1650 | if (Backup_Method == BM_FILES) |
| 1651 | return Backup_Tar(part_settings, tar_fork_pid); |
| 1652 | else if (Backup_Method == BM_DD) |
| 1653 | return Backup_Image(part_settings); |
| 1654 | else if (Backup_Method == BM_FLASH_UTILS) |
| 1655 | return Backup_Dump_Image(part_settings); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1656 | LOGERR("Unknown backup method for '%s'\n", Mount_Point.c_str()); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1657 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1658 | } |
| 1659 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1660 | bool TWPartition::Restore(PartitionSettings *part_settings) { |
Matt Mower | 3c36697 | 2015-12-25 19:28:31 -0600 | [diff] [blame] | 1661 | TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Display_Name, gui_parse_text("{@restoring_hdr}")); |
Ethan Yonker | e080c1f | 2016-09-19 13:50:25 -0500 | [diff] [blame] | 1662 | LOGINFO("Restore filename is: %s/%s\n", part_settings->Backup_Folder.c_str(), Backup_FileName.c_str()); |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 1663 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1664 | string Restore_File_System = Get_Restore_File_System(part_settings); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1665 | |
| 1666 | if (Is_File_System(Restore_File_System)) |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1667 | return Restore_Tar(part_settings); |
| 1668 | else if (Is_Image(Restore_File_System)) |
| 1669 | return Restore_Image(part_settings); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1670 | |
| 1671 | LOGERR("Unknown restore method for '%s'\n", Mount_Point.c_str()); |
| 1672 | return false; |
| 1673 | } |
| 1674 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1675 | string TWPartition::Get_Restore_File_System(PartitionSettings *part_settings) { |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1676 | size_t first_period, second_period; |
| 1677 | string Restore_File_System; |
| 1678 | |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 1679 | // Parse backup filename to extract the file system before wiping |
Ethan Yonker | dcf2b67 | 2016-09-13 14:41:53 -0500 | [diff] [blame] | 1680 | first_period = Backup_FileName.find("."); |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 1681 | if (first_period == string::npos) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1682 | LOGERR("Unable to find file system (first period).\n"); |
that | d43bf2d | 2014-09-21 23:13:02 +0200 | [diff] [blame] | 1683 | return string(); |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 1684 | } |
Ethan Yonker | dcf2b67 | 2016-09-13 14:41:53 -0500 | [diff] [blame] | 1685 | Restore_File_System = Backup_FileName.substr(first_period + 1, Backup_FileName.size() - first_period - 1); |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 1686 | second_period = Restore_File_System.find("."); |
| 1687 | if (second_period == string::npos) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1688 | LOGERR("Unable to find file system (second period).\n"); |
that | d43bf2d | 2014-09-21 23:13:02 +0200 | [diff] [blame] | 1689 | return string(); |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 1690 | } |
| 1691 | Restore_File_System.resize(second_period); |
Matt Mower | a0cd91d | 2016-12-30 18:21:42 -0600 | [diff] [blame] | 1692 | LOGINFO("Restore file system is: '%s'.\n", Restore_File_System.c_str()); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1693 | return Restore_File_System; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | string TWPartition::Backup_Method_By_Name() { |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1697 | if (Backup_Method == BM_NONE) |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1698 | return "none"; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1699 | else if (Backup_Method == BM_FILES) |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1700 | return "files"; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1701 | else if (Backup_Method == BM_DD) |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1702 | return "dd"; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1703 | else if (Backup_Method == BM_FLASH_UTILS) |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1704 | return "flash_utils"; |
| 1705 | else |
| 1706 | return "undefined"; |
| 1707 | return "ERROR!"; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | bool TWPartition::Decrypt(string Password) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1711 | LOGINFO("STUB TWPartition::Decrypt, password: '%s'\n", Password.c_str()); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1712 | // Is this needed? |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1713 | return 1; |
| 1714 | } |
| 1715 | |
| 1716 | bool TWPartition::Wipe_Encryption() { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1717 | bool Save_Data_Media = Has_Data_Media; |
| 1718 | |
| 1719 | if (!UnMount(true)) |
| 1720 | return false; |
| 1721 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1722 | Has_Data_Media = false; |
Dees_Troy | 74fb2e9 | 2013-04-15 14:35:47 +0000 | [diff] [blame] | 1723 | Decrypted_Block_Device = ""; |
Ethan Yonker | d79d9bc | 2014-12-20 15:38:29 -0600 | [diff] [blame] | 1724 | #ifdef TW_INCLUDE_CRYPTO |
Ethan Yonker | 1b19016 | 2016-12-05 15:25:19 -0600 | [diff] [blame] | 1725 | if (Is_Decrypted && !Decrypted_Block_Device.empty()) { |
Ethan Yonker | d79d9bc | 2014-12-20 15:38:29 -0600 | [diff] [blame] | 1726 | if (!UnMount(true)) |
| 1727 | return false; |
Matt Mower | 2b18a53 | 2015-02-20 16:58:05 -0600 | [diff] [blame] | 1728 | if (delete_crypto_blk_dev((char*)("userdata")) != 0) { |
Ethan Yonker | d79d9bc | 2014-12-20 15:38:29 -0600 | [diff] [blame] | 1729 | LOGERR("Error deleting crypto block device, continuing anyway.\n"); |
| 1730 | } |
| 1731 | } |
| 1732 | #endif |
Dees_Troy | 74fb2e9 | 2013-04-15 14:35:47 +0000 | [diff] [blame] | 1733 | Is_Decrypted = false; |
|