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