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