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