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