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