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