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> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 31 | |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 32 | #ifdef TW_INCLUDE_CRYPTO |
| 33 | #include "cutils/properties.h" |
| 34 | #endif |
| 35 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 36 | #include "variables.h" |
| 37 | #include "common.h" |
| 38 | #include "partitions.hpp" |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 39 | #include "data.hpp" |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 40 | #include "twrp-functions.hpp" |
Dees_Troy | 9df963c | 2012-09-26 08:58:12 -0400 | [diff] [blame] | 41 | #include "makelist.hpp" |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 42 | extern "C" { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 43 | #include "mtdutils/mtdutils.h" |
| 44 | #include "mtdutils/mounts.h" |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 45 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 46 | |
| 47 | TWPartition::TWPartition(void) { |
| 48 | Can_Be_Mounted = false; |
| 49 | Can_Be_Wiped = false; |
| 50 | Wipe_During_Factory_Reset = false; |
| 51 | Wipe_Available_in_GUI = false; |
| 52 | Is_SubPartition = false; |
Dees_Troy | 2691f9d | 2012-09-24 11:15:49 -0400 | [diff] [blame] | 53 | Has_SubPartition = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 54 | SubPartition_Of = ""; |
| 55 | Symlink_Path = ""; |
| 56 | Symlink_Mount_Point = ""; |
| 57 | Mount_Point = ""; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 58 | Backup_Path = ""; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 59 | Actual_Block_Device = ""; |
| 60 | Primary_Block_Device = ""; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 61 | Alternate_Block_Device = ""; |
| 62 | Removable = false; |
| 63 | Is_Present = false; |
| 64 | Length = 0; |
| 65 | Size = 0; |
| 66 | Used = 0; |
| 67 | Free = 0; |
| 68 | Backup_Size = 0; |
| 69 | Can_Be_Encrypted = false; |
| 70 | Is_Encrypted = false; |
| 71 | Is_Decrypted = false; |
| 72 | Decrypted_Block_Device = ""; |
| 73 | Display_Name = ""; |
| 74 | Backup_Name = ""; |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 75 | Backup_FileName = ""; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 76 | MTD_Name = ""; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 77 | Backup_Method = NONE; |
| 78 | Has_Data_Media = false; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 79 | Has_Android_Secure = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 80 | Is_Storage = false; |
| 81 | Storage_Path = ""; |
| 82 | Current_File_System = ""; |
| 83 | Fstab_File_System = ""; |
| 84 | Format_Block_Size = 0; |
| 85 | } |
| 86 | |
| 87 | TWPartition::~TWPartition(void) { |
| 88 | // Do nothing |
| 89 | } |
| 90 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 91 | bool TWPartition::Process_Fstab_Line(string Line, bool Display_Error) { |
| 92 | char full_line[MAX_FSTAB_LINE_LENGTH], item[MAX_FSTAB_LINE_LENGTH]; |
| 93 | int line_len = Line.size(), index = 0, item_index = 0; |
| 94 | char* ptr; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 95 | string Flags; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 96 | |
| 97 | strncpy(full_line, Line.c_str(), line_len); |
| 98 | |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 99 | for (index = 0; index < line_len; index++) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 100 | if (full_line[index] <= 32) |
| 101 | full_line[index] = '\0'; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 102 | } |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 103 | Mount_Point = full_line; |
| 104 | LOGI("Processing '%s'\n", Mount_Point.c_str()); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 105 | Backup_Path = Mount_Point; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 106 | index = Mount_Point.size(); |
| 107 | while (index < line_len) { |
| 108 | while (index < line_len && full_line[index] == '\0') |
| 109 | index++; |
| 110 | if (index >= line_len) |
| 111 | continue; |
| 112 | ptr = full_line + index; |
| 113 | if (item_index == 0) { |
| 114 | // File System |
| 115 | Fstab_File_System = ptr; |
| 116 | Current_File_System = ptr; |
| 117 | item_index++; |
| 118 | } else if (item_index == 1) { |
| 119 | // Primary Block Device |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 120 | if (Fstab_File_System == "mtd" || Fstab_File_System == "yaffs2") { |
Dees_Troy | 094207a | 2012-09-26 12:00:39 -0400 | [diff] [blame] | 121 | MTD_Name = ptr; |
| 122 | Find_MTD_Block_Device(MTD_Name); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 123 | } else if (*ptr != '/') { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 124 | if (Display_Error) |
| 125 | LOGE("Invalid block device on '%s', '%s', %i\n", Line.c_str(), ptr, index); |
| 126 | else |
| 127 | LOGI("Invalid block device on '%s', '%s', %i\n", Line.c_str(), ptr, index); |
| 128 | return 0; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 129 | } else { |
| 130 | Primary_Block_Device = ptr; |
| 131 | Find_Real_Block_Device(Primary_Block_Device, Display_Error); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 132 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 133 | item_index++; |
| 134 | } else if (item_index > 1) { |
| 135 | if (*ptr == '/') { |
| 136 | // Alternate Block Device |
| 137 | Alternate_Block_Device = ptr; |
| 138 | Find_Real_Block_Device(Alternate_Block_Device, Display_Error); |
| 139 | } else if (strlen(ptr) > 7 && strncmp(ptr, "length=", 7) == 0) { |
| 140 | // Partition length |
| 141 | ptr += 7; |
| 142 | Length = atoi(ptr); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 143 | } else if (strlen(ptr) > 6 && strncmp(ptr, "flags=", 6) == 0) { |
| 144 | // Custom flags, save for later so that new values aren't overwritten by defaults |
| 145 | ptr += 6; |
| 146 | Flags = ptr; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 147 | } else if (strlen(ptr) == 4 && (strncmp(ptr, "NULL", 4) == 0 || strncmp(ptr, "null", 4) == 0 || strncmp(ptr, "null", 4) == 0)) { |
| 148 | // Do nothing |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 149 | } else { |
| 150 | // Unhandled data |
Dees_Troy | ab10ee2 | 2012-09-21 14:27:30 -0400 | [diff] [blame] | 151 | LOGI("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] | 152 | } |
| 153 | } |
| 154 | while (index < line_len && full_line[index] != '\0') |
| 155 | index++; |
| 156 | } |
| 157 | |
| 158 | if (!Is_File_System(Fstab_File_System) && !Is_Image(Fstab_File_System)) { |
| 159 | if (Display_Error) |
| 160 | LOGE("Unknown File System: '%s'\n", Fstab_File_System.c_str()); |
| 161 | else |
| 162 | LOGI("Unknown File System: '%s'\n", Fstab_File_System.c_str()); |
| 163 | return 0; |
| 164 | } else if (Is_File_System(Fstab_File_System)) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 165 | Find_Actual_Block_Device(); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 166 | Setup_File_System(Display_Error); |
| 167 | if (Mount_Point == "/system") { |
| 168 | Display_Name = "System"; |
| 169 | Wipe_Available_in_GUI = true; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 170 | } else if (Mount_Point == "/data") { |
| 171 | Display_Name = "Data"; |
| 172 | Wipe_Available_in_GUI = true; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 173 | Wipe_During_Factory_Reset = true; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 174 | #ifdef RECOVERY_SDCARD_ON_DATA |
| 175 | Has_Data_Media = true; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 176 | Is_Storage = true; |
| 177 | Storage_Path = "/data/media"; |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 178 | if (strcmp(EXPAND(TW_EXTERNAL_STORAGE_PATH), "/sdcard") == 0) { |
| 179 | Make_Dir("/emmc", Display_Error); |
| 180 | Symlink_Path = "/data/media"; |
| 181 | Symlink_Mount_Point = "/emmc"; |
| 182 | } else { |
| 183 | Make_Dir("/sdcard", Display_Error); |
| 184 | Symlink_Path = "/data/media"; |
| 185 | Symlink_Mount_Point = "/sdcard"; |
| 186 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 187 | #endif |
| 188 | #ifdef TW_INCLUDE_CRYPTO |
| 189 | Can_Be_Encrypted = true; |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 190 | char crypto_blkdev[255]; |
| 191 | property_get("ro.crypto.fs_crypto_blkdev", crypto_blkdev, "error"); |
| 192 | if (strcmp(crypto_blkdev, "error") != 0) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 193 | DataManager::SetValue(TW_DATA_BLK_DEVICE, Primary_Block_Device); |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 194 | DataManager::SetValue(TW_IS_DECRYPTED, 1); |
| 195 | Is_Encrypted = true; |
| 196 | Is_Decrypted = true; |
| 197 | Decrypted_Block_Device = crypto_blkdev; |
| 198 | LOGI("Data already decrypted, new block device: '%s'\n", crypto_blkdev); |
| 199 | } else if (!Mount(false)) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 200 | Is_Encrypted = true; |
| 201 | Is_Decrypted = false; |
| 202 | DataManager::SetValue(TW_IS_ENCRYPTED, 1); |
| 203 | DataManager::SetValue(TW_CRYPTO_PASSWORD, ""); |
| 204 | DataManager::SetValue("tw_crypto_display", ""); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 205 | } |
Dees_Troy | 9b21af7 | 2012-10-01 15:51:46 -0400 | [diff] [blame] | 206 | #ifdef RECOVERY_SDCARD_ON_DATA |
| 207 | if (!Is_Encrypted || (Is_Encrypted && Is_Decrypted)) |
| 208 | Recreate_Media_Folder(); |
| 209 | #endif |
| 210 | #else |
| 211 | #ifdef RECOVERY_SDCARD_ON_DATA |
| 212 | Recreate_Media_Folder(); |
| 213 | #endif |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 214 | #endif |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 215 | } else if (Mount_Point == "/cache") { |
| 216 | Display_Name = "Cache"; |
| 217 | Wipe_Available_in_GUI = true; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 218 | Wipe_During_Factory_Reset = true; |
Dees_Troy | ce2fe77 | 2012-09-28 12:34:33 -0400 | [diff] [blame] | 219 | if (Mount(false) && !TWFunc::Path_Exists("/cache/recovery/.")) { |
| 220 | string Recreate_Command = "cd /cache && mkdir recovery"; |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 221 | LOGI("Recreating /cache/recovery folder.\n"); |
Dees_Troy | ce2fe77 | 2012-09-28 12:34:33 -0400 | [diff] [blame] | 222 | system(Recreate_Command.c_str()); |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 223 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 224 | } else if (Mount_Point == "/datadata") { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 225 | Wipe_During_Factory_Reset = true; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 226 | Display_Name = "DataData"; |
| 227 | Is_SubPartition = true; |
| 228 | SubPartition_Of = "/data"; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 229 | DataManager::SetValue(TW_HAS_DATADATA, 1); |
| 230 | } else if (Mount_Point == "/sd-ext") { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 231 | Wipe_During_Factory_Reset = true; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 232 | Display_Name = "SD-Ext"; |
| 233 | Wipe_Available_in_GUI = true; |
Dees_Troy | c51f1f9 | 2012-09-20 15:32:13 -0400 | [diff] [blame] | 234 | Removable = true; |
Dees_Troy | 2c50e18 | 2012-09-26 20:05:28 -0400 | [diff] [blame] | 235 | } else if (Mount_Point == "/boot") { |
| 236 | Display_Name = "Boot"; |
| 237 | DataManager::SetValue("tw_boot_is_mountable", 1); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 238 | } |
| 239 | #ifdef TW_EXTERNAL_STORAGE_PATH |
| 240 | if (Mount_Point == EXPAND(TW_EXTERNAL_STORAGE_PATH)) { |
| 241 | Is_Storage = true; |
| 242 | Storage_Path = EXPAND(TW_EXTERNAL_STORAGE_PATH); |
Dees_Troy | c51f1f9 | 2012-09-20 15:32:13 -0400 | [diff] [blame] | 243 | Removable = true; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 244 | } |
| 245 | #else |
| 246 | if (Mount_Point == "/sdcard") { |
| 247 | Is_Storage = true; |
| 248 | Storage_Path = "/sdcard"; |
Dees_Troy | c51f1f9 | 2012-09-20 15:32:13 -0400 | [diff] [blame] | 249 | Removable = true; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 250 | #ifndef RECOVERY_SDCARD_ON_DATA |
| 251 | Setup_AndSec(); |
| 252 | #endif |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 253 | } |
| 254 | #endif |
| 255 | #ifdef TW_INTERNAL_STORAGE_PATH |
| 256 | if (Mount_Point == EXPAND(TW_INTERNAL_STORAGE_PATH)) { |
| 257 | Is_Storage = true; |
| 258 | Storage_Path = EXPAND(TW_INTERNAL_STORAGE_PATH); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 259 | #ifndef RECOVERY_SDCARD_ON_DATA |
| 260 | Setup_AndSec(); |
| 261 | #endif |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 262 | } |
| 263 | #else |
| 264 | if (Mount_Point == "/emmc") { |
| 265 | Is_Storage = true; |
| 266 | Storage_Path = "/emmc"; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 267 | #ifndef RECOVERY_SDCARD_ON_DATA |
| 268 | Setup_AndSec(); |
| 269 | #endif |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 270 | } |
| 271 | #endif |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 272 | } else if (Is_Image(Fstab_File_System)) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 273 | Find_Actual_Block_Device(); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 274 | Setup_Image(Display_Error); |
| 275 | if (Mount_Point == "/boot") { |
| 276 | int backup_display_size = (int)(Backup_Size / 1048576LLU); |
| 277 | DataManager::SetValue(TW_BACKUP_BOOT_SIZE, backup_display_size); |
| 278 | if (Backup_Size == 0) { |
| 279 | DataManager::SetValue(TW_HAS_BOOT_PARTITION, 0); |
| 280 | DataManager::SetValue(TW_BACKUP_BOOT_VAR, 0); |
| 281 | } else |
| 282 | DataManager::SetValue(TW_HAS_BOOT_PARTITION, 1); |
| 283 | } else if (Mount_Point == "/recovery") { |
| 284 | int backup_display_size = (int)(Backup_Size / 1048576LLU); |
| 285 | DataManager::SetValue(TW_BACKUP_RECOVERY_SIZE, backup_display_size); |
| 286 | if (Backup_Size == 0) { |
| 287 | DataManager::SetValue(TW_HAS_RECOVERY_PARTITION, 0); |
| 288 | DataManager::SetValue(TW_BACKUP_RECOVERY_VAR, 0); |
| 289 | } else |
| 290 | DataManager::SetValue(TW_HAS_RECOVERY_PARTITION, 1); |
| 291 | } |
Dees_Troy | b1dab8d | 2012-09-26 12:16:41 -0400 | [diff] [blame] | 292 | #ifdef SP1_NAME |
| 293 | string SP1_Path = "/"; |
| 294 | SP1_Path += EXPAND(SP1_NAME); |
| 295 | if (Mount_Point == SP1_Path) { |
| 296 | int backup_display_size = (int)(Backup_Size / 1048576LLU); |
| 297 | DataManager::SetValue(TW_BACKUP_SP1_SIZE, backup_display_size); |
| 298 | } |
| 299 | #endif |
| 300 | #ifdef SP2_NAME |
| 301 | string SP2_Path = "/"; |
| 302 | SP2_Path += EXPAND(SP2_NAME); |
| 303 | if (Mount_Point == SP2_Path) { |
| 304 | int backup_display_size = (int)(Backup_Size / 1048576LLU); |
| 305 | DataManager::SetValue(TW_BACKUP_SP2_SIZE, backup_display_size); |
| 306 | } |
| 307 | #endif |
| 308 | #ifdef SP3_NAME |
| 309 | string SP3_Path = "/"; |
| 310 | SP3_Path += EXPAND(SP3_NAME); |
| 311 | if (Mount_Point == SP3_Path) { |
| 312 | int backup_display_size = (int)(Backup_Size / 1048576LLU); |
| 313 | DataManager::SetValue(TW_BACKUP_SP3_SIZE, backup_display_size); |
| 314 | } |
| 315 | #endif |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 316 | } |
| 317 | |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 318 | // Process any custom flags |
| 319 | if (Flags.size() > 0) |
| 320 | Process_Flags(Flags, Display_Error); |
| 321 | |
| 322 | return true; |
| 323 | } |
| 324 | |
| 325 | bool TWPartition::Process_Flags(string Flags, bool Display_Error) { |
| 326 | char flags[MAX_FSTAB_LINE_LENGTH]; |
| 327 | int flags_len, index = 0; |
| 328 | char* ptr; |
| 329 | |
| 330 | strcpy(flags, Flags.c_str()); |
| 331 | flags_len = Flags.size(); |
| 332 | for (index = 0; index < flags_len; index++) { |
| 333 | if (flags[index] == ';') |
| 334 | flags[index] = '\0'; |
| 335 | } |
| 336 | |
| 337 | index = 0; |
| 338 | while (index < flags_len) { |
| 339 | while (index < flags_len && flags[index] == '\0') |
| 340 | index++; |
| 341 | if (index >= flags_len) |
| 342 | continue; |
| 343 | ptr = flags + index; |
| 344 | if (strcmp(ptr, "removable") == 0) { |
| 345 | Removable = true; |
| 346 | } else if (strcmp(ptr, "storage") == 0) { |
| 347 | Is_Storage = true; |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 348 | } else if (strcmp(ptr, "canbewiped") == 0) { |
| 349 | Can_Be_Wiped = true; |
| 350 | } else if (strcmp(ptr, "wipeingui") == 0) { |
| 351 | Can_Be_Wiped = true; |
| 352 | Wipe_Available_in_GUI = true; |
| 353 | } else if (strcmp(ptr, "wipeduringfactoryreset") == 0) { |
| 354 | Can_Be_Wiped = true; |
| 355 | Wipe_Available_in_GUI = true; |
| 356 | Wipe_During_Factory_Reset = true; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 357 | } else if (strlen(ptr) > 15 && strncmp(ptr, "subpartitionof=", 15) == 0) { |
| 358 | ptr += 13; |
| 359 | Is_SubPartition = true; |
| 360 | SubPartition_Of = ptr; |
| 361 | } else if (strlen(ptr) > 8 && strncmp(ptr, "symlink=", 8) == 0) { |
| 362 | ptr += 8; |
| 363 | Symlink_Path = ptr; |
| 364 | } else if (strlen(ptr) > 8 && strncmp(ptr, "display=", 8) == 0) { |
| 365 | ptr += 8; |
| 366 | Display_Name = ptr; |
| 367 | } else if (strlen(ptr) > 10 && strncmp(ptr, "blocksize=", 10) == 0) { |
| 368 | ptr += 10; |
| 369 | Format_Block_Size = atoi(ptr); |
| 370 | } else if (strlen(ptr) > 7 && strncmp(ptr, "length=", 7) == 0) { |
| 371 | ptr += 7; |
| 372 | Length = atoi(ptr); |
| 373 | } else { |
| 374 | if (Display_Error) |
| 375 | LOGE("Unhandled flag: '%s'\n", ptr); |
| 376 | else |
| 377 | LOGI("Unhandled flag: '%s'\n", ptr); |
| 378 | } |
| 379 | while (index < flags_len && flags[index] != '\0') |
| 380 | index++; |
| 381 | } |
| 382 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 383 | } |
| 384 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 385 | bool TWPartition::Is_File_System(string File_System) { |
| 386 | if (File_System == "ext2" || |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 387 | File_System == "ext3" || |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 388 | File_System == "ext4" || |
| 389 | File_System == "vfat" || |
| 390 | File_System == "ntfs" || |
| 391 | File_System == "yaffs2" || |
| 392 | File_System == "auto") |
| 393 | return true; |
| 394 | else |
| 395 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 396 | } |
| 397 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 398 | bool TWPartition::Is_Image(string File_System) { |
| 399 | if (File_System == "emmc" || |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 400 | File_System == "mtd") |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 401 | return true; |
| 402 | else |
| 403 | return false; |
| 404 | } |
| 405 | |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 406 | bool TWPartition::Make_Dir(string Path, bool Display_Error) { |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 407 | if (!TWFunc::Path_Exists(Path)) { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 408 | if (mkdir(Path.c_str(), 0777) == -1) { |
| 409 | if (Display_Error) |
| 410 | LOGE("Can not create '%s' folder.\n", Path.c_str()); |
| 411 | else |
| 412 | LOGI("Can not create '%s' folder.\n", Path.c_str()); |
| 413 | return false; |
| 414 | } else { |
| 415 | LOGI("Created '%s' folder.\n", Path.c_str()); |
| 416 | return true; |
| 417 | } |
| 418 | } |
| 419 | return true; |
| 420 | } |
| 421 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 422 | void TWPartition::Setup_File_System(bool Display_Error) { |
| 423 | struct statfs st; |
| 424 | |
| 425 | Can_Be_Mounted = true; |
| 426 | Can_Be_Wiped = true; |
| 427 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 428 | // Make the mount point folder if it doesn't exist |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 429 | Make_Dir(Mount_Point, Display_Error); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 430 | Display_Name = Mount_Point.substr(1, Mount_Point.size() - 1); |
| 431 | Backup_Name = Display_Name; |
| 432 | Backup_Method = FILES; |
| 433 | } |
| 434 | |
| 435 | void TWPartition::Setup_Image(bool Display_Error) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 436 | Display_Name = Mount_Point.substr(1, Mount_Point.size() - 1); |
| 437 | Backup_Name = Display_Name; |
| 438 | if (Fstab_File_System == "emmc") |
| 439 | Backup_Method = DD; |
| 440 | else if (Fstab_File_System == "mtd") |
| 441 | Backup_Method = FLASH_UTILS; |
| 442 | else |
| 443 | LOGI("Unhandled file system '%s' on image '%s'\n", Fstab_File_System.c_str(), Display_Name.c_str()); |
| 444 | if (Find_Partition_Size()) { |
| 445 | Used = Size; |
| 446 | Backup_Size = Size; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 447 | } else { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 448 | if (Display_Error) |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 449 | LOGE("Unable to find parition size for '%s'\n", Mount_Point.c_str()); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 450 | else |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 451 | LOGI("Unable to find parition size for '%s'\n", Mount_Point.c_str()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 455 | void TWPartition::Setup_AndSec(void) { |
| 456 | Backup_Name = "and-sec"; |
| 457 | Has_Android_Secure = true; |
| 458 | Symlink_Path = Mount_Point + "/.android_secure"; |
| 459 | Symlink_Mount_Point = "/and-sec"; |
| 460 | Backup_Path = Symlink_Mount_Point; |
| 461 | Make_Dir("/and-sec", true); |
| 462 | Recreate_AndSec_Folder(); |
| 463 | } |
| 464 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 465 | void TWPartition::Find_Real_Block_Device(string& Block, bool Display_Error) { |
| 466 | char device[512], realDevice[512]; |
| 467 | |
| 468 | strcpy(device, Block.c_str()); |
| 469 | memset(realDevice, 0, sizeof(realDevice)); |
| 470 | while (readlink(device, realDevice, sizeof(realDevice)) > 0) |
| 471 | { |
| 472 | strcpy(device, realDevice); |
| 473 | memset(realDevice, 0, sizeof(realDevice)); |
| 474 | } |
| 475 | |
| 476 | if (device[0] != '/') { |
| 477 | if (Display_Error) |
| 478 | LOGE("Invalid symlink path '%s' found on block device '%s'\n", device, Block.c_str()); |
| 479 | else |
| 480 | LOGI("Invalid symlink path '%s' found on block device '%s'\n", device, Block.c_str()); |
| 481 | return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 482 | } else { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 483 | Block = device; |
| 484 | return; |
| 485 | } |
| 486 | } |
| 487 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 488 | bool TWPartition::Find_MTD_Block_Device(string MTD_Name) { |
| 489 | FILE *fp = NULL; |
| 490 | char line[255]; |
| 491 | |
| 492 | fp = fopen("/proc/mtd", "rt"); |
| 493 | if (fp == NULL) { |
| 494 | LOGE("Device does not support /proc/mtd\n"); |
| 495 | return false; |
| 496 | } |
| 497 | |
| 498 | while (fgets(line, sizeof(line), fp) != NULL) |
| 499 | { |
| 500 | char device[32], label[32]; |
| 501 | unsigned long size = 0; |
| 502 | char* fstype = NULL; |
| 503 | int deviceId; |
| 504 | |
| 505 | sscanf(line, "%s %lx %*s %*c%s", device, &size, label); |
| 506 | |
| 507 | // Skip header and blank lines |
| 508 | if ((strcmp(device, "dev:") == 0) || (strlen(line) < 8)) |
| 509 | continue; |
| 510 | |
| 511 | // Strip off the trailing " from the label |
| 512 | label[strlen(label)-1] = '\0'; |
| 513 | |
| 514 | if (strcmp(label, MTD_Name.c_str()) == 0) { |
| 515 | // We found our device |
| 516 | // Strip off the trailing : from the device |
| 517 | device[strlen(device)-1] = '\0'; |
| 518 | if (sscanf(device,"mtd%d", &deviceId) == 1) { |
| 519 | sprintf(device, "/dev/block/mtdblock%d", deviceId); |
| 520 | Primary_Block_Device = device; |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | fclose(fp); |
| 525 | |
| 526 | return false; |
| 527 | } |
| 528 | |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 529 | bool TWPartition::Get_Size_Via_statfs(bool Display_Error) { |
| 530 | struct statfs st; |
| 531 | string Local_Path = Mount_Point + "/."; |
| 532 | |
| 533 | if (!Mount(Display_Error)) |
| 534 | return false; |
| 535 | |
| 536 | if (statfs(Local_Path.c_str(), &st) != 0) { |
| 537 | if (!Removable) { |
| 538 | if (Display_Error) |
| 539 | LOGE("Unable to statfs '%s'\n", Local_Path.c_str()); |
| 540 | else |
| 541 | LOGI("Unable to statfs '%s'\n", Local_Path.c_str()); |
| 542 | } |
| 543 | return false; |
| 544 | } |
| 545 | Size = (st.f_blocks * st.f_bsize); |
| 546 | Used = ((st.f_blocks - st.f_bfree) * st.f_bsize); |
| 547 | Free = (st.f_bfree * st.f_bsize); |
| 548 | Backup_Size = Used; |
| 549 | return true; |
| 550 | } |
| 551 | |
| 552 | bool TWPartition::Get_Size_Via_df(bool Display_Error) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 553 | FILE* fp; |
| 554 | char command[255], line[512]; |
| 555 | int include_block = 1; |
| 556 | unsigned int min_len; |
| 557 | |
| 558 | if (!Mount(Display_Error)) |
| 559 | return false; |
| 560 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 561 | min_len = Actual_Block_Device.size() + 2; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 562 | sprintf(command, "df %s > /tmp/dfoutput.txt", Mount_Point.c_str()); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 563 | system(command); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 564 | fp = fopen("/tmp/dfoutput.txt", "rt"); |
| 565 | if (fp == NULL) { |
| 566 | LOGI("Unable to open /tmp/dfoutput.txt.\n"); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 567 | return false; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 568 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 569 | |
| 570 | while (fgets(line, sizeof(line), fp) != NULL) |
| 571 | { |
| 572 | unsigned long blocks, used, available; |
| 573 | char device[64]; |
| 574 | char tmpString[64]; |
| 575 | |
| 576 | if (strncmp(line, "Filesystem", 10) == 0) |
| 577 | continue; |
| 578 | if (strlen(line) < min_len) { |
| 579 | include_block = 0; |
| 580 | continue; |
| 581 | } |
| 582 | if (include_block) { |
| 583 | sscanf(line, "%s %lu %lu %lu", device, &blocks, &used, &available); |
| 584 | } else { |
| 585 | // The device block string is so long that the df information is on the next line |
| 586 | int space_count = 0; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 587 | sprintf(tmpString, "/dev/block/%s", Actual_Block_Device.c_str()); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 588 | while (tmpString[space_count] == 32) |
| 589 | space_count++; |
| 590 | sscanf(line + space_count, "%lu %lu %lu", &blocks, &used, &available); |
| 591 | } |
| 592 | |
| 593 | // Adjust block size to byte size |
| 594 | Size = blocks * 1024ULL; |
| 595 | Used = used * 1024ULL; |
| 596 | Free = available * 1024ULL; |
| 597 | Backup_Size = Used; |
| 598 | } |
| 599 | fclose(fp); |
| 600 | return true; |
| 601 | } |
| 602 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 603 | bool TWPartition::Find_Partition_Size(void) { |
| 604 | FILE* fp; |
| 605 | char line[512]; |
| 606 | string tmpdevice; |
| 607 | |
| 608 | // In this case, we'll first get the partitions we care about (with labels) |
| 609 | fp = fopen("/proc/partitions", "rt"); |
| 610 | if (fp == NULL) |
| 611 | return false; |
| 612 | |
| 613 | while (fgets(line, sizeof(line), fp) != NULL) |
| 614 | { |
| 615 | unsigned long major, minor, blocks; |
| 616 | char device[512]; |
| 617 | char tmpString[64]; |
| 618 | |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 619 | if (strlen(line) < 7 || line[0] == 'm') continue; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 620 | sscanf(line + 1, "%lu %lu %lu %s", &major, &minor, &blocks, device); |
| 621 | |
| 622 | tmpdevice = "/dev/block/"; |
| 623 | tmpdevice += device; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 624 | if (tmpdevice == Primary_Block_Device || tmpdevice == Alternate_Block_Device) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 625 | // Adjust block size to byte size |
| 626 | Size = blocks * 1024ULL; |
| 627 | fclose(fp); |
| 628 | return true; |
| 629 | } |
| 630 | } |
| 631 | fclose(fp); |
| 632 | return false; |
| 633 | } |
| 634 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 635 | bool TWPartition::Is_Mounted(void) { |
| 636 | if (!Can_Be_Mounted) |
| 637 | return false; |
| 638 | |
| 639 | struct stat st1, st2; |
| 640 | string test_path; |
| 641 | |
| 642 | // Check to see if the mount point directory exists |
| 643 | test_path = Mount_Point + "/."; |
| 644 | if (stat(test_path.c_str(), &st1) != 0) return false; |
| 645 | |
| 646 | // Check to see if the directory above the mount point exists |
| 647 | test_path = Mount_Point + "/../."; |
| 648 | if (stat(test_path.c_str(), &st2) != 0) return false; |
| 649 | |
| 650 | // Compare the device IDs -- if they match then we're (probably) using tmpfs instead of an actual device |
| 651 | int ret = (st1.st_dev != st2.st_dev) ? true : false; |
| 652 | |
| 653 | return ret; |
| 654 | } |
| 655 | |
| 656 | bool TWPartition::Mount(bool Display_Error) { |
| 657 | if (Is_Mounted()) { |
| 658 | return true; |
| 659 | } else if (!Can_Be_Mounted) { |
| 660 | return false; |
| 661 | } |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 662 | |
| 663 | Find_Actual_Block_Device(); |
| 664 | |
| 665 | // Check the current file system before mounting |
| 666 | Check_FS_Type(); |
| 667 | |
| 668 | if (mount(Actual_Block_Device.c_str(), Mount_Point.c_str(), Current_File_System.c_str(), 0, NULL) != 0) { |
| 669 | if (Display_Error) |
| 670 | LOGE("Unable to mount '%s'\n", Mount_Point.c_str()); |
| 671 | else |
| 672 | LOGI("Unable to mount '%s'\n", Mount_Point.c_str()); |
Dees_Troy | 9350b8d | 2012-09-27 12:38:38 -0400 | [diff] [blame] | 673 | LOGI("Actual block device: '%s', current file system: '%s'\n", Actual_Block_Device.c_str(), Current_File_System.c_str()); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 674 | return false; |
| 675 | } else { |
| 676 | if (Removable) |
| 677 | Update_Size(Display_Error); |
| 678 | |
| 679 | if (!Symlink_Mount_Point.empty()) { |
| 680 | string Command; |
| 681 | |
| 682 | Command = "mount " + Symlink_Path + " " + Symlink_Mount_Point; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 683 | system(Command.c_str()); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 684 | } |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 685 | return true; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 686 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 687 | return true; |
| 688 | } |
| 689 | |
| 690 | bool TWPartition::UnMount(bool Display_Error) { |
| 691 | if (Is_Mounted()) { |
| 692 | int never_unmount_system; |
| 693 | |
| 694 | DataManager::GetValue(TW_DONT_UNMOUNT_SYSTEM, never_unmount_system); |
| 695 | if (never_unmount_system == 1 && Mount_Point == "/system") |
| 696 | return true; // Never unmount system if you're not supposed to unmount it |
| 697 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 698 | if (!Symlink_Mount_Point.empty()) |
| 699 | umount(Symlink_Mount_Point.c_str()); |
| 700 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 701 | if (umount(Mount_Point.c_str()) != 0) { |
| 702 | if (Display_Error) |
| 703 | LOGE("Unable to unmount '%s'\n", Mount_Point.c_str()); |
| 704 | else |
| 705 | LOGI("Unable to unmount '%s'\n", Mount_Point.c_str()); |
| 706 | return false; |
| 707 | } else |
| 708 | return true; |
| 709 | } else { |
| 710 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | |
| 714 | bool TWPartition::Wipe() { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 715 | if (!Can_Be_Wiped) { |
| 716 | LOGE("Partition '%s' cannot be wiped.\n", Mount_Point.c_str()); |
| 717 | return false; |
| 718 | } |
| 719 | |
Dees_Troy | c51f1f9 | 2012-09-20 15:32:13 -0400 | [diff] [blame] | 720 | if (Mount_Point == "/cache") |
| 721 | tmplog_offset = 0; |
| 722 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 723 | if (Has_Data_Media) |
| 724 | return Wipe_Data_Without_Wiping_Media(); |
| 725 | |
| 726 | int check; |
| 727 | DataManager::GetValue(TW_RM_RF_VAR, check); |
| 728 | if (check) |
| 729 | return Wipe_RMRF(); |
| 730 | |
| 731 | if (Current_File_System == "ext4") |
| 732 | return Wipe_EXT4(); |
| 733 | |
| 734 | if (Current_File_System == "ext2" || Current_File_System == "ext3") |
| 735 | return Wipe_EXT23(); |
| 736 | |
| 737 | if (Current_File_System == "vfat") |
| 738 | return Wipe_FAT(); |
| 739 | |
| 740 | if (Current_File_System == "yaffs2") |
| 741 | return Wipe_MTD(); |
| 742 | |
| 743 | LOGE("Unable to wipe '%s' -- unknown file system '%s'\n", Mount_Point.c_str(), Current_File_System.c_str()); |
| 744 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 745 | } |
| 746 | |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 747 | bool TWPartition::Wipe_AndSec(void) { |
| 748 | if (!Has_Android_Secure) |
| 749 | return false; |
| 750 | |
| 751 | char cmd[512]; |
| 752 | |
| 753 | if (!Mount(true)) |
| 754 | return false; |
| 755 | |
| 756 | ui_print("Using rm -rf on .android_secure\n"); |
| 757 | sprintf(cmd, "rm -rf %s/.android_secure/* && rm -rf %s/.android_secure/.*", Mount_Point.c_str(), Mount_Point.c_str()); |
| 758 | |
| 759 | LOGI("rm -rf command is: '%s'\n", cmd); |
| 760 | system(cmd); |
| 761 | return true; |
| 762 | } |
| 763 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 764 | bool TWPartition::Backup(string backup_folder) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 765 | if (Backup_Method == FILES) |
| 766 | return Backup_Tar(backup_folder); |
| 767 | else if (Backup_Method == DD) |
| 768 | return Backup_DD(backup_folder); |
| 769 | else if (Backup_Method == FLASH_UTILS) |
| 770 | return Backup_Dump_Image(backup_folder); |
| 771 | LOGE("Unknown backup method for '%s'\n", Mount_Point.c_str()); |
| 772 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 773 | } |
| 774 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 775 | bool TWPartition::Check_MD5(string restore_folder) { |
| 776 | string Full_Filename; |
| 777 | char split_filename[512]; |
| 778 | int index = 0; |
| 779 | |
| 780 | Full_Filename = restore_folder + "/" + Backup_FileName; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 781 | if (!TWFunc::Path_Exists(Full_Filename)) { |
| 782 | // This is a split archive, we presume |
| 783 | sprintf(split_filename, "%s%03i", Full_Filename.c_str(), index); |
| 784 | while (index < 1000 && TWFunc::Path_Exists(split_filename)) { |
| 785 | if (TWFunc::Check_MD5(split_filename) == 0) { |
| 786 | LOGE("MD5 failed to match on '%s'.\n", split_filename); |
| 787 | return false; |
| 788 | } |
| 789 | index++; |
| 790 | sprintf(split_filename, "%s%03i", Full_Filename.c_str(), index); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 791 | } |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 792 | return true; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 793 | } else { |
| 794 | // Single file archive |
| 795 | if (TWFunc::Check_MD5(Full_Filename) == 0) { |
| 796 | LOGE("MD5 failed to match on '%s'.\n", split_filename); |
| 797 | return false; |
| 798 | } else |
| 799 | return true; |
| 800 | } |
| 801 | return false; |
| 802 | } |
| 803 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 804 | bool TWPartition::Restore(string restore_folder) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 805 | if (Backup_Method == FILES) |
| 806 | return Restore_Tar(restore_folder); |
| 807 | else if (Backup_Method == DD) |
| 808 | return Restore_DD(restore_folder); |
| 809 | else if (Backup_Method == FLASH_UTILS) |
| 810 | return Restore_Flash_Image(restore_folder); |
| 811 | LOGE("Unknown restore method for '%s'\n", Mount_Point.c_str()); |
| 812 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | string TWPartition::Backup_Method_By_Name() { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 816 | if (Backup_Method == NONE) |
| 817 | return "none"; |
| 818 | else if (Backup_Method == FILES) |
| 819 | return "files"; |
| 820 | else if (Backup_Method == DD) |
| 821 | return "dd"; |
| 822 | else if (Backup_Method == FLASH_UTILS) |
| 823 | return "flash_utils"; |
| 824 | else |
| 825 | return "undefined"; |
| 826 | return "ERROR!"; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | bool TWPartition::Decrypt(string Password) { |
| 830 | LOGI("STUB TWPartition::Decrypt, password: '%s'\n", Password.c_str()); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 831 | // Is this needed? |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 832 | return 1; |
| 833 | } |
| 834 | |
| 835 | bool TWPartition::Wipe_Encryption() { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 836 | bool Save_Data_Media = Has_Data_Media; |
| 837 | |
| 838 | if (!UnMount(true)) |
| 839 | return false; |
| 840 | |
| 841 | Current_File_System = Fstab_File_System; |
| 842 | Is_Encrypted = false; |
| 843 | Is_Decrypted = false; |
| 844 | Decrypted_Block_Device = ""; |
| 845 | Has_Data_Media = false; |
| 846 | if (Wipe()) { |
| 847 | Has_Data_Media = Save_Data_Media; |
| 848 | if (Has_Data_Media && !Symlink_Mount_Point.empty()) { |
| 849 | Recreate_Media_Folder(); |
| 850 | } |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 851 | ui_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] | 852 | return true; |
| 853 | } else { |
| 854 | Has_Data_Media = Save_Data_Media; |
| 855 | LOGE("Unable to format to remove encryption.\n"); |
| 856 | return false; |
| 857 | } |
| 858 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | void TWPartition::Check_FS_Type() { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 862 | FILE *fp; |
| 863 | string blkCommand; |
| 864 | char blkOutput[255]; |
| 865 | char* blk; |
| 866 | char* arg; |
| 867 | char* ptr; |
| 868 | |
| 869 | if (Fstab_File_System == "yaffs2" || Fstab_File_System == "mtd") |
| 870 | return; // Running blkid on some mtd devices causes a massive crash |
| 871 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 872 | Find_Actual_Block_Device(); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 873 | if (!Is_Present) |
| 874 | return; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 875 | |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 876 | if (TWFunc::Path_Exists("/tmp/blkidoutput.txt")) |
| 877 | system("rm /tmp/blkidoutput.txt"); |
| 878 | |
| 879 | blkCommand = "blkid " + Actual_Block_Device + " > /tmp/blkidoutput.txt"; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 880 | system(blkCommand.c_str()); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 881 | fp = fopen("/tmp/blkidoutput.txt", "rt"); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 882 | if (fp == NULL) |
| 883 | return; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 884 | while (fgets(blkOutput, sizeof(blkOutput), fp) != NULL) |
| 885 | { |
| 886 | blk = blkOutput; |
| 887 | ptr = blkOutput; |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 888 | while (*ptr > 32 && *ptr != ':') ptr++; |
| 889 | if (*ptr == 0) continue; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 890 | *ptr = 0; |
| 891 | |
| 892 | // Increment by two, but verify that we don't hit a NULL |
| 893 | ptr++; |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 894 | if (*ptr != 0) ptr++; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 895 | |
| 896 | // Now, find the TYPE field |
| 897 | while (1) |
| 898 | { |
| 899 | arg = ptr; |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 900 | while (*ptr > 32) ptr++; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 901 | if (*ptr != 0) |
| 902 | { |
| 903 | *ptr = 0; |
| 904 | ptr++; |
| 905 | } |
| 906 | |
| 907 | if (strlen(arg) > 6) |
| 908 | { |
| 909 | if (memcmp(arg, "TYPE=\"", 6) == 0) break; |
| 910 | } |
| 911 | |
| 912 | if (*ptr == 0) |
| 913 | { |
| 914 | arg = NULL; |
| 915 | break; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | if (arg && strlen(arg) > 7) |
| 920 | { |
| 921 | arg += 6; // Skip the TYPE=" portion |
| 922 | arg[strlen(arg)-1] = '\0'; // Drop the tail quote |
| 923 | } |
| 924 | else |
| 925 | continue; |
| 926 | |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 927 | if (strcmp(Current_File_System.c_str(), arg) != 0) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 928 | LOGI("'%s' was '%s' now set to '%s'\n", Mount_Point.c_str(), Current_File_System.c_str(), arg); |
| 929 | Current_File_System = arg; |
| 930 | } |
| 931 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 932 | fclose(fp); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 933 | return; |
| 934 | } |
| 935 | |
| 936 | bool TWPartition::Wipe_EXT23() { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 937 | if (!UnMount(true)) |
| 938 | return false; |
| 939 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 940 | if (TWFunc::Path_Exists("/sbin/mke2fs")) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 941 | char command[512]; |
| 942 | |
| 943 | ui_print("Formatting %s using mke2fs...\n", Display_Name.c_str()); |
| 944 | Find_Actual_Block_Device(); |
| 945 | sprintf(command, "mke2fs -t %s -m 0 %s", Current_File_System.c_str(), Actual_Block_Device.c_str()); |
| 946 | LOGI("mke2fs command: %s\n", command); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 947 | if (system(command) == 0) { |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 948 | Recreate_AndSec_Folder(); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 949 | ui_print("Done.\n"); |
| 950 | return true; |
| 951 | } else { |
| 952 | LOGE("Unable to wipe '%s'.\n", Mount_Point.c_str()); |
| 953 | return false; |
| 954 | } |
| 955 | } else |
| 956 | return Wipe_RMRF(); |
| 957 | |
| 958 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | bool TWPartition::Wipe_EXT4() { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 962 | if (!UnMount(true)) |
| 963 | return false; |
| 964 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 965 | if (TWFunc::Path_Exists("/sbin/make_ext4fs")) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 966 | string Command; |
| 967 | |
| 968 | ui_print("Formatting %s using make_ext4fs...\n", Display_Name.c_str()); |
| 969 | Find_Actual_Block_Device(); |
| 970 | Command = "make_ext4fs"; |
| 971 | if (!Is_Decrypted && Length != 0) { |
| 972 | // Only use length if we're not decrypted |
| 973 | char len[32]; |
| 974 | sprintf(len, "%i", Length); |
| 975 | Command += " -l "; |
| 976 | Command += len; |
| 977 | } |
| 978 | Command += " " + Actual_Block_Device; |
| 979 | LOGI("make_ext4fs command: %s\n", Command.c_str()); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 980 | if (system(Command.c_str()) == 0) { |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 981 | Recreate_AndSec_Folder(); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 982 | ui_print("Done.\n"); |
| 983 | return true; |
| 984 | } else { |
| 985 | LOGE("Unable to wipe '%s'.\n", Mount_Point.c_str()); |
| 986 | return false; |
| 987 | } |
| 988 | } else |
| 989 | return Wipe_EXT23(); |
| 990 | |
| 991 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | bool TWPartition::Wipe_FAT() { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 995 | char command[512]; |
| 996 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 997 | if (TWFunc::Path_Exists("/sbin/mkdosfs")) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 998 | if (!UnMount(true)) |
| 999 | return false; |
| 1000 | |
| 1001 | ui_print("Formatting %s using mkdosfs...\n", Display_Name.c_str()); |
| 1002 | Find_Actual_Block_Device(); |
| 1003 | sprintf(command,"mkdosfs %s", Actual_Block_Device.c_str()); // use mkdosfs to format it |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1004 | if (system(command) == 0) { |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1005 | Recreate_AndSec_Folder(); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1006 | ui_print("Done.\n"); |
| 1007 | return true; |
| 1008 | } else { |
| 1009 | LOGE("Unable to wipe '%s'.\n", Mount_Point.c_str()); |
| 1010 | return false; |
| 1011 | } |
| 1012 | return true; |
| 1013 | } |
| 1014 | else |
| 1015 | return Wipe_RMRF(); |
| 1016 | |
| 1017 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1018 | } |
| 1019 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1020 | bool TWPartition::Wipe_MTD() { |
| 1021 | if (!UnMount(true)) |
| 1022 | return false; |
| 1023 | |
| 1024 | ui_print("MTD Formatting \"%s\"\n", MTD_Name.c_str()); |
| 1025 | |
| 1026 | mtd_scan_partitions(); |
| 1027 | const MtdPartition* mtd = mtd_find_partition_by_name(MTD_Name.c_str()); |
| 1028 | if (mtd == NULL) { |
| 1029 | LOGE("No mtd partition named '%s'", MTD_Name.c_str()); |
| 1030 | return false; |
| 1031 | } |
| 1032 | |
| 1033 | MtdWriteContext* ctx = mtd_write_partition(mtd); |
| 1034 | if (ctx == NULL) { |
| 1035 | LOGE("Can't write '%s', failed to format.", MTD_Name.c_str()); |
| 1036 | return false; |
| 1037 | } |
| 1038 | if (mtd_erase_blocks(ctx, -1) == -1) { |
| 1039 | mtd_write_close(ctx); |
| 1040 | LOGE("Failed to format '%s'", MTD_Name.c_str()); |
| 1041 | return false; |
| 1042 | } |
| 1043 | if (mtd_write_close(ctx) != 0) { |
| 1044 | LOGE("Failed to close '%s'", MTD_Name.c_str()); |
| 1045 | return false; |
| 1046 | } |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1047 | Recreate_AndSec_Folder(); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1048 | ui_print("Done.\n"); |
| 1049 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | bool TWPartition::Wipe_RMRF() { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1053 | char cmd[512]; |
| 1054 | |
| 1055 | if (!Mount(true)) |
| 1056 | return false; |
| 1057 | |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1058 | ui_print("Using rm -rf on '%s'\n", Mount_Point.c_str()); |
| 1059 | sprintf(cmd, "rm -rf %s/* && rm -rf %s/.*", Mount_Point.c_str(), Mount_Point.c_str()); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1060 | |
| 1061 | LOGI("rm -rf command is: '%s'\n", cmd); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1062 | system(cmd); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1063 | Recreate_AndSec_Folder(); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1064 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | bool TWPartition::Wipe_Data_Without_Wiping_Media() { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1068 | char cmd[256]; |
| 1069 | |
| 1070 | // This handles wiping data on devices with "sdcard" in /data/media |
| 1071 | if (!Mount(true)) |
| 1072 | return false; |
| 1073 | |
| 1074 | ui_print("Wiping data without wiping /data/media ...\n"); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1075 | system("rm -f /data/*"); |
| 1076 | system("rm -f /data/.*"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1077 | |
| 1078 | DIR* d; |
| 1079 | d = opendir("/data"); |
| 1080 | if (d != NULL) |
| 1081 | { |
| 1082 | struct dirent* de; |
| 1083 | while ((de = readdir(d)) != NULL) { |
| 1084 | if (strcmp(de->d_name, "media") == 0) continue; |
| 1085 | |
| 1086 | sprintf(cmd, "rm -fr /data/%s", de->d_name); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1087 | system(cmd); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1088 | } |
| 1089 | closedir(d); |
| 1090 | } |
| 1091 | ui_print("Done.\n"); |
| 1092 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | bool TWPartition::Backup_Tar(string backup_folder) { |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1096 | char back_name[255], split_index[5]; |
| 1097 | string Full_FileName, Split_FileName, Tar_Args, Command; |
| 1098 | int use_compression, index, backup_count; |
| 1099 | struct stat st; |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 1100 | unsigned long long total_bsize = 0, file_size; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1101 | |
| 1102 | if (!Mount(true)) |
| 1103 | return false; |
| 1104 | |
Dees_Troy | 2c50e18 | 2012-09-26 20:05:28 -0400 | [diff] [blame] | 1105 | if (Backup_Path == "/and-sec") { |
| 1106 | TWFunc::GUI_Operation_Text(TW_BACKUP_TEXT, "Android Secure", "Backing Up"); |
| 1107 | ui_print("Backing up %s...\n", "Android Secure"); |
| 1108 | } else { |
| 1109 | TWFunc::GUI_Operation_Text(TW_BACKUP_TEXT, Display_Name, "Backing Up"); |
| 1110 | ui_print("Backing up %s...\n", Display_Name.c_str()); |
| 1111 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1112 | |
| 1113 | DataManager::GetValue(TW_USE_COMPRESSION_VAR, use_compression); |
| 1114 | if (use_compression) |
| 1115 | Tar_Args = "-cz"; |
| 1116 | else |
| 1117 | Tar_Args = "-c"; |
| 1118 | |
| 1119 | sprintf(back_name, "%s.%s.win", Backup_Name.c_str(), Current_File_System.c_str()); |
| 1120 | Backup_FileName = back_name; |
| 1121 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1122 | if (Backup_Size > MAX_ARCHIVE_SIZE) { |
| 1123 | // This backup needs to be split into multiple archives |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1124 | ui_print("Breaking backup file into multiple archives...\nGenerating file lists\n"); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1125 | sprintf(back_name, "%s", Backup_Path.c_str()); |
Dees_Troy | 9df963c | 2012-09-26 08:58:12 -0400 | [diff] [blame] | 1126 | backup_count = MakeList::Make_File_List(back_name); |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1127 | if (backup_count < 1) { |
| 1128 | LOGE("Error generating file list!\n"); |
| 1129 | return false; |
| 1130 | } |
| 1131 | for (index=0; index<backup_count; index++) { |
| 1132 | sprintf(split_index, "%03i", index); |
| 1133 | Full_FileName = backup_folder + "/" + Backup_FileName + split_index; |
| 1134 | Command = "tar " + Tar_Args + " -f '" + Full_FileName + "' -T /tmp/list/filelist" + split_index; |
| 1135 | LOGI("Backup command: '%s'\n", Command.c_str()); |
| 1136 | ui_print("Backup archive %i of %i...\n", (index + 1), backup_count); |
| 1137 | system(Command.c_str()); // sending backup command formed earlier above |
| 1138 | |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 1139 | file_size = TWFunc::Get_File_Size(Full_FileName); |
| 1140 | if (file_size == 0) { |
| 1141 | LOGE("Backup file size for '%s' is 0 bytes.\n", Full_FileName.c_str()); // oh noes! file size is 0, abort! abort! |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1142 | return false; |
| 1143 | } |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 1144 | total_bsize += file_size; |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1145 | } |
| 1146 | ui_print(" * Total size: %llu bytes.\n", total_bsize); |
| 1147 | system("cd /tmp && rm -rf list"); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1148 | } else { |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1149 | Full_FileName = backup_folder + "/" + Backup_FileName; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1150 | if (Has_Data_Media) |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1151 | Command = "cd " + Backup_Path + " && tar " + Tar_Args + " ./ --exclude='media*' -f '" + Full_FileName + "'"; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1152 | else |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1153 | Command = "cd " + Backup_Path + " && tar " + Tar_Args + " -f '" + Full_FileName + "' ./*"; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1154 | LOGI("Backup command: '%s'\n", Command.c_str()); |
| 1155 | system(Command.c_str()); |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 1156 | if (TWFunc::Get_File_Size(Full_FileName) == 0) { |
| 1157 | LOGE("Backup file size for '%s' is 0 bytes.\n", Full_FileName.c_str()); |
| 1158 | return false; |
| 1159 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1160 | } |
| 1161 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | bool TWPartition::Backup_DD(string backup_folder) { |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1165 | char back_name[255]; |
| 1166 | string Full_FileName, Command; |
| 1167 | int use_compression; |
| 1168 | |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 1169 | TWFunc::GUI_Operation_Text(TW_BACKUP_TEXT, Display_Name, "Backing Up"); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1170 | ui_print("Backing up %s...\n", Display_Name.c_str()); |
| 1171 | |
| 1172 | sprintf(back_name, "%s.%s.win", Backup_Name.c_str(), Current_File_System.c_str()); |
| 1173 | Backup_FileName = back_name; |
| 1174 | |
| 1175 | Full_FileName = backup_folder + "/" + Backup_FileName; |
| 1176 | |
| 1177 | Command = "dd if=" + Actual_Block_Device + " of='" + Full_FileName + "'"; |
| 1178 | LOGI("Backup command: '%s'\n", Command.c_str()); |
| 1179 | system(Command.c_str()); |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 1180 | if (TWFunc::Get_File_Size(Full_FileName) != Backup_Size) { |
| 1181 | LOGE("Backup file size %lu for '%s' is does not match backup size %llu.\n", TWFunc::Get_File_Size(Full_FileName), Full_FileName.c_str(), Backup_Size); |
| 1182 | return false; |
| 1183 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1184 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | bool TWPartition::Backup_Dump_Image(string backup_folder) { |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1188 | char back_name[255]; |
| 1189 | string Full_FileName, Command; |
| 1190 | int use_compression; |
| 1191 | |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 1192 | TWFunc::GUI_Operation_Text(TW_BACKUP_TEXT, Display_Name, "Backing Up"); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1193 | ui_print("Backing up %s...\n", Display_Name.c_str()); |
| 1194 | |
| 1195 | sprintf(back_name, "%s.%s.win", Backup_Name.c_str(), Current_File_System.c_str()); |
| 1196 | Backup_FileName = back_name; |
| 1197 | |
| 1198 | Full_FileName = backup_folder + "/" + Backup_FileName; |
| 1199 | |
| 1200 | Command = "dump_image " + MTD_Name + " '" + Full_FileName + "'"; |
| 1201 | LOGI("Backup command: '%s'\n", Command.c_str()); |
| 1202 | system(Command.c_str()); |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 1203 | if (TWFunc::Get_File_Size(Full_FileName) == 0) { |
| 1204 | // Actual size may not match backup size due to bad blocks on MTD devices so just check for 0 bytes |
| 1205 | LOGE("Backup file size for '%s' is 0 bytes.\n", Full_FileName.c_str()); |
| 1206 | return false; |
| 1207 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1208 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | bool TWPartition::Restore_Tar(string restore_folder) { |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1212 | size_t first_period, second_period; |
| 1213 | string Restore_File_System, Full_FileName, Command; |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1214 | int index = 0; |
| 1215 | char split_index[5]; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1216 | |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 1217 | TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Display_Name, "Restoring"); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1218 | LOGI("Restore filename is: %s\n", Backup_FileName.c_str()); |
| 1219 | |
| 1220 | // Parse backup filename to extract the file system before wiping |
| 1221 | first_period = Backup_FileName.find("."); |
| 1222 | if (first_period == string::npos) { |
| 1223 | LOGE("Unable to find file system (first period).\n"); |
| 1224 | return false; |
| 1225 | } |
| 1226 | Restore_File_System = Backup_FileName.substr(first_period + 1, Backup_FileName.size() - first_period - 1); |
| 1227 | second_period = Restore_File_System.find("."); |
| 1228 | if (second_period == string::npos) { |
| 1229 | LOGE("Unable to find file system (second period).\n"); |
| 1230 | return false; |
| 1231 | } |
| 1232 | Restore_File_System.resize(second_period); |
| 1233 | LOGI("Restore file system is: '%s'.\n", Restore_File_System.c_str()); |
| 1234 | Current_File_System = Restore_File_System; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1235 | if (Has_Android_Secure) { |
| 1236 | ui_print("Wiping android secure...\n"); |
| 1237 | if (!Wipe_AndSec()) |
| 1238 | return false; |
| 1239 | } else if (!Wipe()) { |
| 1240 | ui_print("Wiping %s...\n", Display_Name.c_str()); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1241 | return false; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1242 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1243 | |
| 1244 | if (!Mount(true)) |
| 1245 | return false; |
| 1246 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1247 | ui_print("Restoring %s...\n", Display_Name.c_str()); |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1248 | Full_FileName = restore_folder + "/" + Backup_FileName; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1249 | if (!TWFunc::Path_Exists(Full_FileName)) { |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1250 | // Backup is multiple archives |
| 1251 | LOGI("Backup is multiple archives.\n"); |
| 1252 | sprintf(split_index, "%03i", index); |
| 1253 | Full_FileName = restore_folder + "/" + Backup_FileName + split_index; |
| 1254 | while (TWFunc::Path_Exists(Full_FileName)) { |
| 1255 | ui_print("Restoring archive %i...\n", index + 1); |
Dees_Troy | 6da522d | 2012-10-12 15:19:33 -0400 | [diff] [blame^] | 1256 | Command = "tar -xf '" + Full_FileName + "'"; |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1257 | LOGI("Restore command: '%s'\n", Command.c_str()); |
| 1258 | system(Command.c_str()); |
| 1259 | index++; |
| 1260 | sprintf(split_index, "%03i", index); |
| 1261 | Full_FileName = restore_folder + "/" + Backup_FileName + split_index; |
| 1262 | } |
| 1263 | if (index == 0) { |
| 1264 | LOGE("Error locating restore file: '%s'\n", Full_FileName.c_str()); |
| 1265 | return false; |
| 1266 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1267 | } else { |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1268 | Command = "cd " + Backup_Path + " && tar -xf '" + Full_FileName + "'"; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1269 | LOGI("Restore command: '%s'\n", Command.c_str()); |
| 1270 | system(Command.c_str()); |
| 1271 | } |
| 1272 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | bool TWPartition::Restore_DD(string restore_folder) { |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1276 | string Full_FileName, Command; |
| 1277 | |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 1278 | TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Display_Name, "Restoring"); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1279 | ui_print("Restoring %s...\n", Display_Name.c_str()); |
| 1280 | Full_FileName = restore_folder + "/" + Backup_FileName; |
| 1281 | Command = "dd bs=4096 if='" + Full_FileName + "' of=" + Actual_Block_Device; |
| 1282 | LOGI("Restore command: '%s'\n", Command.c_str()); |
| 1283 | system(Command.c_str()); |
| 1284 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | bool TWPartition::Restore_Flash_Image(string restore_folder) { |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1288 | string Full_FileName, Command; |
| 1289 | |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 1290 | TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Display_Name, "Restoring"); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1291 | ui_print("Restoring %s...\n", Display_Name.c_str()); |
| 1292 | Full_FileName = restore_folder + "/" + Backup_FileName; |
| 1293 | // Sometimes flash image doesn't like to flash due to the first 2KB matching, so we erase first to ensure that it flashes |
| 1294 | Command = "erase_image " + MTD_Name; |
| 1295 | LOGI("Erase command: '%s'\n", Command.c_str()); |
| 1296 | system(Command.c_str()); |
| 1297 | Command = "flash_image " + MTD_Name + " '" + Full_FileName + "'"; |
| 1298 | LOGI("Restore command: '%s'\n", Command.c_str()); |
| 1299 | system(Command.c_str()); |
| 1300 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1301 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1302 | |
| 1303 | bool TWPartition::Update_Size(bool Display_Error) { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1304 | bool ret = false; |
| 1305 | |
Dees_Troy | ab10ee2 | 2012-09-21 14:27:30 -0400 | [diff] [blame] | 1306 | if (!Can_Be_Mounted && !Is_Encrypted) |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1307 | return false; |
| 1308 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1309 | if (Removable || Is_Encrypted) { |
| 1310 | if (!Mount(false)) |
| 1311 | return true; |
| 1312 | } else if (!Mount(Display_Error)) |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1313 | return false; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1314 | |
| 1315 | ret = Get_Size_Via_statfs(Display_Error); |
| 1316 | if (!ret || Size == 0) |
| 1317 | if (!Get_Size_Via_df(Display_Error)) |
| 1318 | return false; |
| 1319 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1320 | if (Has_Data_Media) { |
| 1321 | if (Mount(Display_Error)) { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1322 | unsigned long long data_media_used, actual_data; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1323 | Used = TWFunc::Get_Folder_Size("/data", Display_Error); |
| 1324 | data_media_used = TWFunc::Get_Folder_Size("/data/media", Display_Error); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1325 | actual_data = Used - data_media_used; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1326 | Backup_Size = actual_data; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1327 | int bak = (int)(Backup_Size / 1048576LLU); |
| 1328 | int total = (int)(Size / 1048576LLU); |
| 1329 | int us = (int)(Used / 1048576LLU); |
| 1330 | int fre = (int)(Free / 1048576LLU); |
| 1331 | int datmed = (int)(data_media_used / 1048576LLU); |
| 1332 | LOGI("Data backup size is %iMB, size: %iMB, used: %iMB, free: %iMB, in data/media: %iMB.\n", bak, total, us, fre, datmed); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1333 | } else |
| 1334 | return false; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1335 | } else if (Has_Android_Secure) { |
| 1336 | if (Mount(Display_Error)) |
| 1337 | Backup_Size = TWFunc::Get_Folder_Size(Backup_Path, Display_Error); |
| 1338 | else |
| 1339 | return false; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1340 | } |
| 1341 | return true; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1342 | } |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1343 | |
| 1344 | void TWPartition::Find_Actual_Block_Device(void) { |
| 1345 | if (Is_Decrypted) { |
| 1346 | Actual_Block_Device = Decrypted_Block_Device; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1347 | if (TWFunc::Path_Exists(Primary_Block_Device)) |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1348 | Is_Present = true; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1349 | } else if (TWFunc::Path_Exists(Primary_Block_Device)) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1350 | Is_Present = true; |
| 1351 | Actual_Block_Device = Primary_Block_Device; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1352 | } else if (!Alternate_Block_Device.empty() && TWFunc::Path_Exists(Alternate_Block_Device)) { |
Dees_Troy | 3f04d03 | 2012-10-07 18:20:09 -0400 | [diff] [blame] | 1353 | Actual_Block_Device = Alternate_Block_Device; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1354 | Is_Present = true; |
| 1355 | } else |
| 1356 | Is_Present = false; |
| 1357 | } |
| 1358 | |
| 1359 | void TWPartition::Recreate_Media_Folder(void) { |
| 1360 | string Command; |
| 1361 | |
| 1362 | if (!Mount(true)) { |
| 1363 | LOGE("Unable to recreate /data/media folder.\n"); |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 1364 | } else if (!TWFunc::Path_Exists("/data/media")) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1365 | LOGI("Recreating /data/media folder.\n"); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1366 | system("cd /data && mkdir media && chmod 755 media"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1367 | Command = "umount " + Symlink_Mount_Point; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1368 | system(Command.c_str()); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1369 | Command = "mount " + Symlink_Path + " " + Symlink_Mount_Point; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1370 | system(Command.c_str()); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1371 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1372 | } |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1373 | |
| 1374 | void TWPartition::Recreate_AndSec_Folder(void) { |
| 1375 | string Command; |
| 1376 | |
| 1377 | if (!Has_Android_Secure) |
| 1378 | return; |
| 1379 | |
| 1380 | if (!Mount(true)) { |
| 1381 | LOGE("Unable to recreate android secure folder.\n"); |
| 1382 | } else if (!TWFunc::Path_Exists(Symlink_Path)) { |
| 1383 | LOGI("Recreating android secure folder.\n"); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1384 | Command = "umount " + Symlink_Mount_Point; |
| 1385 | system(Command.c_str()); |
Dees_Troy | ce2fe77 | 2012-09-28 12:34:33 -0400 | [diff] [blame] | 1386 | Command = "cd " + Mount_Point + " && mkdir .android_secure"; |
| 1387 | system(Command.c_str()); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1388 | Command = "mount " + Symlink_Path + " " + Symlink_Mount_Point; |
| 1389 | system(Command.c_str()); |
| 1390 | } |
| 1391 | } |