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 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 38 | #include "variables.h" |
| 39 | #include "common.h" |
| 40 | #include "partitions.hpp" |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 41 | #include "data.hpp" |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 42 | #include "twrp-functions.hpp" |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 43 | #include "twrpTar.hpp" |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 44 | extern "C" { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 45 | #include "mtdutils/mtdutils.h" |
| 46 | #include "mtdutils/mounts.h" |
Dees_Troy | 85f44ed | 2013-01-09 18:42:36 +0000 | [diff] [blame] | 47 | #ifdef TW_INCLUDE_CRYPTO_SAMSUNG |
| 48 | #include "crypto/libcrypt_samsung/include/libcrypt_samsung.h" |
| 49 | #endif |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 50 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 51 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 52 | using namespace std; |
| 53 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 54 | TWPartition::TWPartition(void) { |
| 55 | Can_Be_Mounted = false; |
| 56 | Can_Be_Wiped = false; |
| 57 | Wipe_During_Factory_Reset = false; |
| 58 | Wipe_Available_in_GUI = false; |
| 59 | Is_SubPartition = false; |
Dees_Troy | 2691f9d | 2012-09-24 11:15:49 -0400 | [diff] [blame] | 60 | Has_SubPartition = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 61 | SubPartition_Of = ""; |
| 62 | Symlink_Path = ""; |
| 63 | Symlink_Mount_Point = ""; |
| 64 | Mount_Point = ""; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 65 | Backup_Path = ""; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 66 | Actual_Block_Device = ""; |
| 67 | Primary_Block_Device = ""; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 68 | Alternate_Block_Device = ""; |
| 69 | Removable = false; |
| 70 | Is_Present = false; |
| 71 | Length = 0; |
| 72 | Size = 0; |
| 73 | Used = 0; |
| 74 | Free = 0; |
| 75 | Backup_Size = 0; |
| 76 | Can_Be_Encrypted = false; |
| 77 | Is_Encrypted = false; |
| 78 | Is_Decrypted = false; |
| 79 | Decrypted_Block_Device = ""; |
| 80 | Display_Name = ""; |
| 81 | Backup_Name = ""; |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 82 | Backup_FileName = ""; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 83 | MTD_Name = ""; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 84 | Backup_Method = NONE; |
| 85 | Has_Data_Media = false; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 86 | Has_Android_Secure = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 87 | Is_Storage = false; |
| 88 | Storage_Path = ""; |
| 89 | Current_File_System = ""; |
| 90 | Fstab_File_System = ""; |
| 91 | Format_Block_Size = 0; |
Dees_Troy | 68cab49 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 92 | Ignore_Blkid = false; |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 93 | Retain_Layout_Version = false; |
Dees_Troy | 85f44ed | 2013-01-09 18:42:36 +0000 | [diff] [blame] | 94 | #ifdef TW_INCLUDE_CRYPTO_SAMSUNG |
| 95 | EcryptFS_Password = ""; |
| 96 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | TWPartition::~TWPartition(void) { |
| 100 | // Do nothing |
| 101 | } |
| 102 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 103 | bool TWPartition::Process_Fstab_Line(string Line, bool Display_Error) { |
| 104 | char full_line[MAX_FSTAB_LINE_LENGTH], item[MAX_FSTAB_LINE_LENGTH]; |
| 105 | int line_len = Line.size(), index = 0, item_index = 0; |
| 106 | char* ptr; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 107 | string Flags; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 108 | strncpy(full_line, Line.c_str(), line_len); |
| 109 | |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 110 | for (index = 0; index < line_len; index++) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 111 | if (full_line[index] <= 32) |
| 112 | full_line[index] = '\0'; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 113 | } |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 114 | Mount_Point = full_line; |
| 115 | LOGI("Processing '%s'\n", Mount_Point.c_str()); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 116 | Backup_Path = Mount_Point; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 117 | index = Mount_Point.size(); |
| 118 | while (index < line_len) { |
| 119 | while (index < line_len && full_line[index] == '\0') |
| 120 | index++; |
| 121 | if (index >= line_len) |
| 122 | continue; |
| 123 | ptr = full_line + index; |
| 124 | if (item_index == 0) { |
| 125 | // File System |
| 126 | Fstab_File_System = ptr; |
| 127 | Current_File_System = ptr; |
| 128 | item_index++; |
| 129 | } else if (item_index == 1) { |
| 130 | // Primary Block Device |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 131 | if (Fstab_File_System == "mtd" || Fstab_File_System == "yaffs2") { |
Dees_Troy | 094207a | 2012-09-26 12:00:39 -0400 | [diff] [blame] | 132 | MTD_Name = ptr; |
| 133 | Find_MTD_Block_Device(MTD_Name); |
Dees_Troy | 5fcd8f9 | 2012-10-16 12:22:05 -0400 | [diff] [blame] | 134 | } else if (Fstab_File_System == "bml") { |
| 135 | if (Mount_Point == "/boot") |
| 136 | MTD_Name = "boot"; |
| 137 | else if (Mount_Point == "/recovery") |
| 138 | MTD_Name = "recovery"; |
| 139 | Primary_Block_Device = ptr; |
| 140 | if (*ptr != '/') |
| 141 | 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] | 142 | } else if (*ptr != '/') { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 143 | if (Display_Error) |
| 144 | LOGE("Invalid block device on '%s', '%s', %i\n", Line.c_str(), ptr, index); |
| 145 | else |
| 146 | LOGI("Invalid block device on '%s', '%s', %i\n", Line.c_str(), ptr, index); |
| 147 | return 0; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 148 | } else { |
| 149 | Primary_Block_Device = ptr; |
| 150 | Find_Real_Block_Device(Primary_Block_Device, Display_Error); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 151 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 152 | item_index++; |
| 153 | } else if (item_index > 1) { |
| 154 | if (*ptr == '/') { |
| 155 | // Alternate Block Device |
| 156 | Alternate_Block_Device = ptr; |
| 157 | Find_Real_Block_Device(Alternate_Block_Device, Display_Error); |
| 158 | } else if (strlen(ptr) > 7 && strncmp(ptr, "length=", 7) == 0) { |
| 159 | // Partition length |
| 160 | ptr += 7; |
| 161 | Length = atoi(ptr); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 162 | } else if (strlen(ptr) > 6 && strncmp(ptr, "flags=", 6) == 0) { |
| 163 | // Custom flags, save for later so that new values aren't overwritten by defaults |
| 164 | ptr += 6; |
| 165 | Flags = ptr; |
Dees_Troy | 68cab49 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 166 | Process_Flags(Flags, Display_Error); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 167 | } else if (strlen(ptr) == 4 && (strncmp(ptr, "NULL", 4) == 0 || strncmp(ptr, "null", 4) == 0 || strncmp(ptr, "null", 4) == 0)) { |
| 168 | // Do nothing |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 169 | } else { |
| 170 | // Unhandled data |
Dees_Troy | ab10ee2 | 2012-09-21 14:27:30 -0400 | [diff] [blame] | 171 | 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] | 172 | } |
| 173 | } |
| 174 | while (index < line_len && full_line[index] != '\0') |
| 175 | index++; |
| 176 | } |
| 177 | |
| 178 | if (!Is_File_System(Fstab_File_System) && !Is_Image(Fstab_File_System)) { |
| 179 | if (Display_Error) |
| 180 | LOGE("Unknown File System: '%s'\n", Fstab_File_System.c_str()); |
| 181 | else |
| 182 | LOGI("Unknown File System: '%s'\n", Fstab_File_System.c_str()); |
| 183 | return 0; |
| 184 | } else if (Is_File_System(Fstab_File_System)) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 185 | Find_Actual_Block_Device(); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 186 | Setup_File_System(Display_Error); |
| 187 | if (Mount_Point == "/system") { |
| 188 | Display_Name = "System"; |
| 189 | Wipe_Available_in_GUI = true; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 190 | } else if (Mount_Point == "/data") { |
| 191 | Display_Name = "Data"; |
| 192 | Wipe_Available_in_GUI = true; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 193 | Wipe_During_Factory_Reset = true; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 194 | #ifdef RECOVERY_SDCARD_ON_DATA |
| 195 | Has_Data_Media = true; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 196 | Is_Storage = true; |
| 197 | Storage_Path = "/data/media"; |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 198 | Symlink_Path = Storage_Path; |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 199 | if (strcmp(EXPAND(TW_EXTERNAL_STORAGE_PATH), "/sdcard") == 0) { |
| 200 | Make_Dir("/emmc", Display_Error); |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 201 | Symlink_Mount_Point = "/emmc"; |
| 202 | } else { |
| 203 | Make_Dir("/sdcard", Display_Error); |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 204 | Symlink_Mount_Point = "/sdcard"; |
| 205 | } |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 206 | if (Mount(false) && TWFunc::Path_Exists("/data/media/0")) { |
| 207 | Storage_Path = "/data/media/0"; |
| 208 | Symlink_Path = Storage_Path; |
| 209 | DataManager::SetValue(TW_INTERNAL_PATH, "/data/media/0"); |
| 210 | UnMount(true); |
| 211 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 212 | #endif |
| 213 | #ifdef TW_INCLUDE_CRYPTO |
| 214 | Can_Be_Encrypted = true; |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 215 | char crypto_blkdev[255]; |
| 216 | property_get("ro.crypto.fs_crypto_blkdev", crypto_blkdev, "error"); |
| 217 | if (strcmp(crypto_blkdev, "error") != 0) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 218 | DataManager::SetValue(TW_DATA_BLK_DEVICE, Primary_Block_Device); |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 219 | DataManager::SetValue(TW_IS_DECRYPTED, 1); |
| 220 | Is_Encrypted = true; |
| 221 | Is_Decrypted = true; |
| 222 | Decrypted_Block_Device = crypto_blkdev; |
| 223 | LOGI("Data already decrypted, new block device: '%s'\n", crypto_blkdev); |
| 224 | } else if (!Mount(false)) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 225 | Is_Encrypted = true; |
| 226 | Is_Decrypted = false; |
Gary Peck | 82599a8 | 2012-11-21 16:23:12 -0800 | [diff] [blame] | 227 | Can_Be_Mounted = false; |
| 228 | Current_File_System = "emmc"; |
| 229 | Setup_Image(Display_Error); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 230 | DataManager::SetValue(TW_IS_ENCRYPTED, 1); |
| 231 | DataManager::SetValue(TW_CRYPTO_PASSWORD, ""); |
| 232 | DataManager::SetValue("tw_crypto_display", ""); |
Gary Peck | 82599a8 | 2012-11-21 16:23:12 -0800 | [diff] [blame] | 233 | } else { |
| 234 | // Filesystem is not encrypted and the mount |
| 235 | // succeeded, so get it back to the original |
| 236 | // unmounted state |
| 237 | UnMount(false); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 238 | } |
Dees_Troy | 9b21af7 | 2012-10-01 15:51:46 -0400 | [diff] [blame] | 239 | #ifdef RECOVERY_SDCARD_ON_DATA |
| 240 | if (!Is_Encrypted || (Is_Encrypted && Is_Decrypted)) |
| 241 | Recreate_Media_Folder(); |
| 242 | #endif |
| 243 | #else |
| 244 | #ifdef RECOVERY_SDCARD_ON_DATA |
| 245 | Recreate_Media_Folder(); |
| 246 | #endif |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 247 | #endif |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 248 | } else if (Mount_Point == "/cache") { |
| 249 | Display_Name = "Cache"; |
| 250 | Wipe_Available_in_GUI = true; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 251 | Wipe_During_Factory_Reset = true; |
Dees_Troy | ce2fe77 | 2012-09-28 12:34:33 -0400 | [diff] [blame] | 252 | if (Mount(false) && !TWFunc::Path_Exists("/cache/recovery/.")) { |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 253 | LOGI("Recreating /cache/recovery folder.\n"); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 254 | if (mkdir("/cache/recovery", S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP) != 0) |
| 255 | return -1; |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 256 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 257 | } else if (Mount_Point == "/datadata") { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 258 | Wipe_During_Factory_Reset = true; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 259 | Display_Name = "DataData"; |
| 260 | Is_SubPartition = true; |
| 261 | SubPartition_Of = "/data"; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 262 | DataManager::SetValue(TW_HAS_DATADATA, 1); |
| 263 | } else if (Mount_Point == "/sd-ext") { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 264 | Wipe_During_Factory_Reset = true; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 265 | Display_Name = "SD-Ext"; |
| 266 | Wipe_Available_in_GUI = true; |
Dees_Troy | c51f1f9 | 2012-09-20 15:32:13 -0400 | [diff] [blame] | 267 | Removable = true; |
Dees_Troy | 2c50e18 | 2012-09-26 20:05:28 -0400 | [diff] [blame] | 268 | } else if (Mount_Point == "/boot") { |
| 269 | Display_Name = "Boot"; |
| 270 | DataManager::SetValue("tw_boot_is_mountable", 1); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 271 | } |
| 272 | #ifdef TW_EXTERNAL_STORAGE_PATH |
| 273 | if (Mount_Point == EXPAND(TW_EXTERNAL_STORAGE_PATH)) { |
| 274 | Is_Storage = true; |
| 275 | Storage_Path = EXPAND(TW_EXTERNAL_STORAGE_PATH); |
Dees_Troy | c51f1f9 | 2012-09-20 15:32:13 -0400 | [diff] [blame] | 276 | Removable = true; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 277 | } |
| 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 | } |
| 288 | #endif |
| 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) { |
| 352 | ptr += 13; |
| 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 | |
| 619 | // In this case, we'll first get the partitions we care about (with labels) |
| 620 | fp = fopen("/proc/partitions", "rt"); |
| 621 | if (fp == NULL) |
| 622 | return false; |
| 623 | |
| 624 | while (fgets(line, sizeof(line), fp) != NULL) |
| 625 | { |
| 626 | unsigned long major, minor, blocks; |
| 627 | char device[512]; |
| 628 | char tmpString[64]; |
| 629 | |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 630 | if (strlen(line) < 7 || line[0] == 'm') continue; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 631 | sscanf(line + 1, "%lu %lu %lu %s", &major, &minor, &blocks, device); |
| 632 | |
| 633 | tmpdevice = "/dev/block/"; |
| 634 | tmpdevice += device; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 635 | if (tmpdevice == Primary_Block_Device || tmpdevice == Alternate_Block_Device) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 636 | // Adjust block size to byte size |
| 637 | Size = blocks * 1024ULL; |
| 638 | fclose(fp); |
| 639 | return true; |
| 640 | } |
| 641 | } |
| 642 | fclose(fp); |
| 643 | return false; |
| 644 | } |
| 645 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 646 | bool TWPartition::Is_Mounted(void) { |
| 647 | if (!Can_Be_Mounted) |
| 648 | return false; |
| 649 | |
| 650 | struct stat st1, st2; |
| 651 | string test_path; |
| 652 | |
| 653 | // Check to see if the mount point directory exists |
| 654 | test_path = Mount_Point + "/."; |
| 655 | if (stat(test_path.c_str(), &st1) != 0) return false; |
| 656 | |
| 657 | // Check to see if the directory above the mount point exists |
| 658 | test_path = Mount_Point + "/../."; |
| 659 | if (stat(test_path.c_str(), &st2) != 0) return false; |
| 660 | |
| 661 | // Compare the device IDs -- if they match then we're (probably) using tmpfs instead of an actual device |
| 662 | int ret = (st1.st_dev != st2.st_dev) ? true : false; |
| 663 | |
| 664 | return ret; |
| 665 | } |
| 666 | |
| 667 | bool TWPartition::Mount(bool Display_Error) { |
| 668 | if (Is_Mounted()) { |
| 669 | return true; |
| 670 | } else if (!Can_Be_Mounted) { |
| 671 | return false; |
| 672 | } |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 673 | |
| 674 | Find_Actual_Block_Device(); |
| 675 | |
| 676 | // Check the current file system before mounting |
| 677 | Check_FS_Type(); |
Dees_Troy | 2204203 | 2012-12-18 21:23:08 +0000 | [diff] [blame] | 678 | if (Fstab_File_System == "yaffs2") { |
| 679 | // mount an MTD partition as a YAFFS2 filesystem. |
| 680 | mtd_scan_partitions(); |
| 681 | const MtdPartition* partition; |
| 682 | partition = mtd_find_partition_by_name(MTD_Name.c_str()); |
| 683 | if (partition == NULL) { |
| 684 | LOGE("Failed to find '%s' partition to mount at '%s'\n", |
| 685 | MTD_Name.c_str(), Mount_Point.c_str()); |
| 686 | return false; |
| 687 | } |
| 688 | if (mtd_mount_partition(partition, Mount_Point.c_str(), Fstab_File_System.c_str(), 0)) { |
| 689 | if (Display_Error) |
| 690 | LOGE("Failed to mount '%s' (MTD)\n", Mount_Point.c_str()); |
| 691 | else |
| 692 | LOGI("Failed to mount '%s' (MTD)\n", Mount_Point.c_str()); |
| 693 | return false; |
| 694 | } else |
| 695 | return true; |
Dees_Troy | 85f44ed | 2013-01-09 18:42:36 +0000 | [diff] [blame] | 696 | } else if (Current_File_System == "exfat" && TWFunc::Path_Exists("/sbin/exfat-fuse")) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 697 | string cmd = "/sbin/exfat-fuse " + Actual_Block_Device + " " + Mount_Point; |
Dees_Troy | 85f44ed | 2013-01-09 18:42:36 +0000 | [diff] [blame] | 698 | LOGI("cmd: %s\n", cmd.c_str()); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 699 | string result; |
| 700 | if (TWFunc::Exec_Cmd(cmd, result) != 0) |
| 701 | return false; |
Dees_Troy | 2204203 | 2012-12-18 21:23:08 +0000 | [diff] [blame] | 702 | } else if (mount(Actual_Block_Device.c_str(), Mount_Point.c_str(), Current_File_System.c_str(), 0, NULL) != 0) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 703 | if (Display_Error) |
| 704 | LOGE("Unable to mount '%s'\n", Mount_Point.c_str()); |
| 705 | else |
| 706 | LOGI("Unable to mount '%s'\n", Mount_Point.c_str()); |
Dees_Troy | 9350b8d | 2012-09-27 12:38:38 -0400 | [diff] [blame] | 707 | 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] | 708 | return false; |
| 709 | } else { |
Dees_Troy | 85f44ed | 2013-01-09 18:42:36 +0000 | [diff] [blame] | 710 | #ifdef TW_INCLUDE_CRYPTO_SAMSUNG |
Dees_Troy | 999b39d | 2013-01-14 15:36:13 +0000 | [diff] [blame] | 711 | string MetaEcfsFile = EXPAND(TW_EXTERNAL_STORAGE_PATH); |
| 712 | MetaEcfsFile += "/.MetaEcfsFile"; |
| 713 | if (EcryptFS_Password.size() > 0 && PartitionManager.Mount_By_Path("/data", false) && TWFunc::Path_Exists(MetaEcfsFile)) { |
Dees_Troy | 85f44ed | 2013-01-09 18:42:36 +0000 | [diff] [blame] | 714 | if (mount_ecryptfs_drive(EcryptFS_Password.c_str(), Mount_Point.c_str(), Mount_Point.c_str(), 0) != 0) { |
| 715 | if (Display_Error) |
| 716 | LOGE("Unable to mount ecryptfs for '%s'\n", Mount_Point.c_str()); |
| 717 | else |
| 718 | LOGI("Unable to mount ecryptfs for '%s'\n", Mount_Point.c_str()); |
| 719 | } else { |
| 720 | LOGI("Successfully mounted ecryptfs for '%s'\n", Mount_Point.c_str()); |
| 721 | } |
| 722 | } |
| 723 | #endif |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 724 | if (Removable) |
| 725 | Update_Size(Display_Error); |
| 726 | |
| 727 | if (!Symlink_Mount_Point.empty()) { |
Dees_Troy | dc8bc1b | 2013-01-17 01:39:28 +0000 | [diff] [blame] | 728 | string Command, Result; |
| 729 | Command = "mount '" + Symlink_Path + "' '" + Symlink_Mount_Point + "'"; |
| 730 | TWFunc::Exec_Cmd(Command, Result); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 731 | } |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 732 | return true; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 733 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 734 | return true; |
| 735 | } |
| 736 | |
| 737 | bool TWPartition::UnMount(bool Display_Error) { |
| 738 | if (Is_Mounted()) { |
| 739 | int never_unmount_system; |
| 740 | |
| 741 | DataManager::GetValue(TW_DONT_UNMOUNT_SYSTEM, never_unmount_system); |
| 742 | if (never_unmount_system == 1 && Mount_Point == "/system") |
| 743 | return true; // Never unmount system if you're not supposed to unmount it |
| 744 | |
Dees_Troy | c8bafa1 | 2013-01-10 15:43:00 +0000 | [diff] [blame] | 745 | #ifdef TW_INCLUDE_CRYPTO_SAMSUNG |
| 746 | if (EcryptFS_Password.size() > 0) { |
| 747 | if (unmount_ecryptfs_drive(Mount_Point.c_str()) != 0) { |
| 748 | if (Display_Error) |
| 749 | LOGE("Unable to unmount ecryptfs for '%s'\n", Mount_Point.c_str()); |
| 750 | else |
| 751 | LOGI("Unable to unmount ecryptfs for '%s'\n", Mount_Point.c_str()); |
| 752 | } else { |
| 753 | LOGI("Successfully unmounted ecryptfs for '%s'\n", Mount_Point.c_str()); |
| 754 | } |
| 755 | } |
| 756 | #endif |
| 757 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 758 | if (!Symlink_Mount_Point.empty()) |
| 759 | umount(Symlink_Mount_Point.c_str()); |
| 760 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 761 | if (umount(Mount_Point.c_str()) != 0) { |
| 762 | if (Display_Error) |
| 763 | LOGE("Unable to unmount '%s'\n", Mount_Point.c_str()); |
| 764 | else |
| 765 | LOGI("Unable to unmount '%s'\n", Mount_Point.c_str()); |
| 766 | return false; |
| 767 | } else |
| 768 | return true; |
| 769 | } else { |
| 770 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 774 | bool TWPartition::Wipe(string New_File_System) { |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 775 | bool wiped = false, update_crypt = false; |
| 776 | int check; |
| 777 | string Layout_Filename = Mount_Point + "/.layout_version"; |
| 778 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 779 | if (!Can_Be_Wiped) { |
| 780 | LOGE("Partition '%s' cannot be wiped.\n", Mount_Point.c_str()); |
| 781 | return false; |
| 782 | } |
| 783 | |
Dees_Troy | c51f1f9 | 2012-09-20 15:32:13 -0400 | [diff] [blame] | 784 | if (Mount_Point == "/cache") |
| 785 | tmplog_offset = 0; |
| 786 | |
Dees_Troy | ce67546 | 2013-01-09 19:48:21 +0000 | [diff] [blame] | 787 | #ifdef TW_INCLUDE_CRYPTO_SAMSUNG |
| 788 | if (Mount_Point == "/data" && Mount(false)) { |
| 789 | if (TWFunc::Path_Exists("/data/system/edk_p_sd")) |
| 790 | TWFunc::copy_file("/data/system/edk_p_sd", "/tmp/edk_p_sd", 0600); |
| 791 | } |
| 792 | #endif |
| 793 | |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 794 | if (Retain_Layout_Version && Mount(false) && TWFunc::Path_Exists(Layout_Filename)) |
| 795 | TWFunc::copy_file(Layout_Filename, "/.layout_version", 0600); |
| 796 | else |
| 797 | unlink("/.layout_version"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 798 | |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 799 | if (Has_Data_Media) { |
| 800 | wiped = Wipe_Data_Without_Wiping_Media(); |
| 801 | } else { |
Gary Peck | e8bc5d7 | 2012-12-21 06:45:25 -0800 | [diff] [blame] | 802 | |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 803 | DataManager::GetValue(TW_RM_RF_VAR, check); |
| 804 | |
| 805 | if (check) |
| 806 | wiped = Wipe_RMRF(); |
| 807 | else if (New_File_System == "ext4") |
| 808 | wiped = Wipe_EXT4(); |
| 809 | else if (New_File_System == "ext2" || New_File_System == "ext3") |
| 810 | wiped = Wipe_EXT23(New_File_System); |
| 811 | else if (New_File_System == "vfat") |
| 812 | wiped = Wipe_FAT(); |
| 813 | else if (New_File_System == "exfat") |
| 814 | wiped = Wipe_EXFAT(); |
| 815 | else if (New_File_System == "yaffs2") |
| 816 | wiped = Wipe_MTD(); |
| 817 | else { |
| 818 | LOGE("Unable to wipe '%s' -- unknown file system '%s'\n", Mount_Point.c_str(), New_File_System.c_str()); |
| 819 | unlink("/.layout_version"); |
| 820 | return false; |
| 821 | } |
| 822 | update_crypt = wiped; |
Gary Peck | e8bc5d7 | 2012-12-21 06:45:25 -0800 | [diff] [blame] | 823 | } |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 824 | |
Gary Peck | e8bc5d7 | 2012-12-21 06:45:25 -0800 | [diff] [blame] | 825 | if (wiped) { |
Dees_Troy | ce67546 | 2013-01-09 19:48:21 +0000 | [diff] [blame] | 826 | #ifdef TW_INCLUDE_CRYPTO_SAMSUNG |
| 827 | if (Mount_Point == "/data" && Mount(false)) { |
| 828 | if (TWFunc::Path_Exists("/tmp/edk_p_sd")) { |
| 829 | Make_Dir("/data/system", true); |
| 830 | TWFunc::copy_file("/tmp/edk_p_sd", "/data/system/edk_p_sd", 0600); |
| 831 | } |
| 832 | } |
| 833 | #endif |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 834 | |
Dees_Troy | 1c1ac44 | 2013-01-17 21:42:14 +0000 | [diff] [blame] | 835 | if (Mount_Point == "/cache") |
| 836 | DataManager::Output_Version(); |
| 837 | |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 838 | if (TWFunc::Path_Exists("/.layout_version") && Mount(false)) |
| 839 | TWFunc::copy_file("/.layout_version", Layout_Filename, 0600); |
| 840 | |
| 841 | if (update_crypt) { |
| 842 | Setup_File_System(false); |
| 843 | if (Is_Encrypted && !Is_Decrypted) { |
| 844 | // just wiped an encrypted partition back to its unencrypted state |
| 845 | Is_Encrypted = false; |
| 846 | Is_Decrypted = false; |
| 847 | Decrypted_Block_Device = ""; |
| 848 | if (Mount_Point == "/data") { |
| 849 | DataManager::SetValue(TW_IS_ENCRYPTED, 0); |
| 850 | DataManager::SetValue(TW_IS_DECRYPTED, 0); |
| 851 | } |
Gary Peck | e8bc5d7 | 2012-12-21 06:45:25 -0800 | [diff] [blame] | 852 | } |
| 853 | } |
| 854 | } |
| 855 | return wiped; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 856 | } |
| 857 | |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 858 | bool TWPartition::Wipe() { |
Gary Peck | 82599a8 | 2012-11-21 16:23:12 -0800 | [diff] [blame] | 859 | if (Is_File_System(Current_File_System)) |
| 860 | return Wipe(Current_File_System); |
| 861 | else |
| 862 | return Wipe(Fstab_File_System); |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 863 | } |
| 864 | |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 865 | bool TWPartition::Wipe_AndSec(void) { |
| 866 | if (!Has_Android_Secure) |
| 867 | return false; |
| 868 | |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 869 | if (!Mount(true)) |
| 870 | return false; |
| 871 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 872 | ui_print("Wiping .android_secure\n"); |
| 873 | TWFunc::removeDir(Mount_Point + "/.android_secure/", true); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 874 | return true; |
| 875 | } |
| 876 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 877 | bool TWPartition::Backup(string backup_folder) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 878 | if (Backup_Method == FILES) |
| 879 | return Backup_Tar(backup_folder); |
| 880 | else if (Backup_Method == DD) |
| 881 | return Backup_DD(backup_folder); |
| 882 | else if (Backup_Method == FLASH_UTILS) |
| 883 | return Backup_Dump_Image(backup_folder); |
| 884 | LOGE("Unknown backup method for '%s'\n", Mount_Point.c_str()); |
| 885 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 886 | } |
| 887 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 888 | bool TWPartition::Check_MD5(string restore_folder) { |
| 889 | string Full_Filename; |
| 890 | char split_filename[512]; |
| 891 | int index = 0; |
| 892 | |
| 893 | Full_Filename = restore_folder + "/" + Backup_FileName; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 894 | if (!TWFunc::Path_Exists(Full_Filename)) { |
| 895 | // This is a split archive, we presume |
| 896 | sprintf(split_filename, "%s%03i", Full_Filename.c_str(), index); |
| 897 | while (index < 1000 && TWFunc::Path_Exists(split_filename)) { |
| 898 | if (TWFunc::Check_MD5(split_filename) == 0) { |
| 899 | LOGE("MD5 failed to match on '%s'.\n", split_filename); |
| 900 | return false; |
| 901 | } |
| 902 | index++; |
| 903 | sprintf(split_filename, "%s%03i", Full_Filename.c_str(), index); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 904 | } |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 905 | return true; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 906 | } else { |
| 907 | // Single file archive |
| 908 | if (TWFunc::Check_MD5(Full_Filename) == 0) { |
| 909 | LOGE("MD5 failed to match on '%s'.\n", split_filename); |
| 910 | return false; |
| 911 | } else |
| 912 | return true; |
| 913 | } |
| 914 | return false; |
| 915 | } |
| 916 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 917 | bool TWPartition::Restore(string restore_folder) { |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 918 | size_t first_period, second_period; |
| 919 | string Restore_File_System; |
| 920 | |
| 921 | TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Display_Name, "Restoring"); |
| 922 | LOGI("Restore filename is: %s\n", Backup_FileName.c_str()); |
| 923 | |
| 924 | // Parse backup filename to extract the file system before wiping |
| 925 | first_period = Backup_FileName.find("."); |
| 926 | if (first_period == string::npos) { |
| 927 | LOGE("Unable to find file system (first period).\n"); |
| 928 | return false; |
| 929 | } |
| 930 | Restore_File_System = Backup_FileName.substr(first_period + 1, Backup_FileName.size() - first_period - 1); |
| 931 | second_period = Restore_File_System.find("."); |
| 932 | if (second_period == string::npos) { |
| 933 | LOGE("Unable to find file system (second period).\n"); |
| 934 | return false; |
| 935 | } |
| 936 | Restore_File_System.resize(second_period); |
| 937 | LOGI("Restore file system is: '%s'.\n", Restore_File_System.c_str()); |
| 938 | |
| 939 | if (Is_File_System(Restore_File_System)) |
| 940 | return Restore_Tar(restore_folder, Restore_File_System); |
| 941 | else if (Is_Image(Restore_File_System)) { |
| 942 | if (Restore_File_System == "emmc") |
| 943 | return Restore_DD(restore_folder); |
| 944 | else if (Restore_File_System == "mtd" || Restore_File_System == "bml") |
| 945 | return Restore_Flash_Image(restore_folder); |
| 946 | } |
| 947 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 948 | LOGE("Unknown restore method for '%s'\n", Mount_Point.c_str()); |
| 949 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | string TWPartition::Backup_Method_By_Name() { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 953 | if (Backup_Method == NONE) |
| 954 | return "none"; |
| 955 | else if (Backup_Method == FILES) |
| 956 | return "files"; |
| 957 | else if (Backup_Method == DD) |
| 958 | return "dd"; |
| 959 | else if (Backup_Method == FLASH_UTILS) |
| 960 | return "flash_utils"; |
| 961 | else |
| 962 | return "undefined"; |
| 963 | return "ERROR!"; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | bool TWPartition::Decrypt(string Password) { |
| 967 | LOGI("STUB TWPartition::Decrypt, password: '%s'\n", Password.c_str()); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 968 | // Is this needed? |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 969 | return 1; |
| 970 | } |
| 971 | |
| 972 | bool TWPartition::Wipe_Encryption() { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 973 | bool Save_Data_Media = Has_Data_Media; |
| 974 | |
| 975 | if (!UnMount(true)) |
| 976 | return false; |
| 977 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 978 | Has_Data_Media = false; |
Gary Peck | e8bc5d7 | 2012-12-21 06:45:25 -0800 | [diff] [blame] | 979 | if (Wipe(Fstab_File_System)) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 980 | Has_Data_Media = Save_Data_Media; |
| 981 | if (Has_Data_Media && !Symlink_Mount_Point.empty()) { |
| 982 | Recreate_Media_Folder(); |
| 983 | } |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 984 | 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] | 985 | return true; |
| 986 | } else { |
| 987 | Has_Data_Media = Save_Data_Media; |
| 988 | LOGE("Unable to format to remove encryption.\n"); |
| 989 | return false; |
| 990 | } |
| 991 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | void TWPartition::Check_FS_Type() { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 995 | string blkCommand, result; |
| 996 | string blkOutput; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 997 | char* blk; |
| 998 | char* arg; |
| 999 | char* ptr; |
Dees_Troy | 4bb33ac | 2013-01-18 21:05:47 +0000 | [diff] [blame] | 1000 | int type_found = 0; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1001 | |
Dees_Troy | 68cab49 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 1002 | if (Fstab_File_System == "yaffs2" || Fstab_File_System == "mtd" || Fstab_File_System == "bml" || Ignore_Blkid) |
| 1003 | 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] | 1004 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1005 | Find_Actual_Block_Device(); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1006 | if (!Is_Present) |
| 1007 | return; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1008 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1009 | blkCommand = "blkid " + Actual_Block_Device; |
| 1010 | TWFunc::Exec_Cmd(blkCommand, result); |
| 1011 | std::stringstream line(result); |
| 1012 | while (getline(line, blkOutput)) |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1013 | { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1014 | blk = (char*) blkOutput.c_str(); |
| 1015 | ptr = (char*) blkOutput.c_str(); |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 1016 | while (*ptr > 32 && *ptr != ':') ptr++; |
| 1017 | if (*ptr == 0) continue; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1018 | *ptr = 0; |
| 1019 | |
| 1020 | // Increment by two, but verify that we don't hit a NULL |
| 1021 | ptr++; |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 1022 | if (*ptr != 0) ptr++; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1023 | |
| 1024 | // Now, find the TYPE field |
| 1025 | while (1) |
| 1026 | { |
| 1027 | arg = ptr; |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 1028 | while (*ptr > 32) ptr++; |
Dees_Troy | 4bb33ac | 2013-01-18 21:05:47 +0000 | [diff] [blame] | 1029 | if (*ptr != 0) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1030 | *ptr = 0; |
| 1031 | ptr++; |
| 1032 | } |
| 1033 | |
Dees_Troy | 4bb33ac | 2013-01-18 21:05:47 +0000 | [diff] [blame] | 1034 | if (strlen(arg) > 6) { |
| 1035 | if (memcmp(arg, "TYPE=\"", 6) == 0) { |
| 1036 | type_found = 1; |
| 1037 | break; |
| 1038 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1039 | } |
| 1040 | |
Dees_Troy | 4bb33ac | 2013-01-18 21:05:47 +0000 | [diff] [blame] | 1041 | if (*ptr == 0) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1042 | arg = NULL; |
| 1043 | break; |
| 1044 | } |
| 1045 | } |
| 1046 | |
Dees_Troy | 4bb33ac | 2013-01-18 21:05:47 +0000 | [diff] [blame] | 1047 | if (type_found) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1048 | arg += 6; // Skip the TYPE=" portion |
| 1049 | arg[strlen(arg)-1] = '\0'; // Drop the tail quote |
Dees_Troy | 4bb33ac | 2013-01-18 21:05:47 +0000 | [diff] [blame] | 1050 | if (Current_File_System != arg) { |
| 1051 | LOGI("'%s' was '%s' now set to '%s'\n", Mount_Point.c_str(), Current_File_System.c_str(), arg); |
| 1052 | Current_File_System = arg; |
| 1053 | } |
| 1054 | } else |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1055 | continue; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1056 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1057 | return; |
| 1058 | } |
| 1059 | |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 1060 | bool TWPartition::Wipe_EXT23(string File_System) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1061 | if (!UnMount(true)) |
| 1062 | return false; |
| 1063 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1064 | if (TWFunc::Path_Exists("/sbin/mke2fs")) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1065 | string command, result; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1066 | |
| 1067 | ui_print("Formatting %s using mke2fs...\n", Display_Name.c_str()); |
| 1068 | Find_Actual_Block_Device(); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1069 | command = "mke2fs -t " + File_System + " -m 0 " + Actual_Block_Device; |
| 1070 | LOGI("mke2fs command: %s\n", command.c_str()); |
| 1071 | if (TWFunc::Exec_Cmd(command, result) == 0) { |
Gary Peck | e8bc5d7 | 2012-12-21 06:45:25 -0800 | [diff] [blame] | 1072 | Current_File_System = File_System; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1073 | Recreate_AndSec_Folder(); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1074 | ui_print("Done.\n"); |
| 1075 | return true; |
| 1076 | } else { |
| 1077 | LOGE("Unable to wipe '%s'.\n", Mount_Point.c_str()); |
| 1078 | return false; |
| 1079 | } |
| 1080 | } else |
| 1081 | return Wipe_RMRF(); |
| 1082 | |
| 1083 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | bool TWPartition::Wipe_EXT4() { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1087 | if (!UnMount(true)) |
| 1088 | return false; |
| 1089 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1090 | if (TWFunc::Path_Exists("/sbin/make_ext4fs")) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1091 | string Command, result; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1092 | |
| 1093 | ui_print("Formatting %s using make_ext4fs...\n", Display_Name.c_str()); |
| 1094 | Find_Actual_Block_Device(); |
| 1095 | Command = "make_ext4fs"; |
| 1096 | if (!Is_Decrypted && Length != 0) { |
| 1097 | // Only use length if we're not decrypted |
| 1098 | char len[32]; |
| 1099 | sprintf(len, "%i", Length); |
| 1100 | Command += " -l "; |
| 1101 | Command += len; |
| 1102 | } |
| 1103 | Command += " " + Actual_Block_Device; |
| 1104 | LOGI("make_ext4fs command: %s\n", Command.c_str()); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1105 | if (TWFunc::Exec_Cmd(Command, result) == 0) { |
Gary Peck | e8bc5d7 | 2012-12-21 06:45:25 -0800 | [diff] [blame] | 1106 | Current_File_System = "ext4"; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1107 | Recreate_AndSec_Folder(); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1108 | ui_print("Done.\n"); |
| 1109 | return true; |
| 1110 | } else { |
| 1111 | LOGE("Unable to wipe '%s'.\n", Mount_Point.c_str()); |
| 1112 | return false; |
| 1113 | } |
| 1114 | } else |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 1115 | return Wipe_EXT23("ext4"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1116 | |
| 1117 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | bool TWPartition::Wipe_FAT() { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1121 | string command, result; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1122 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1123 | if (TWFunc::Path_Exists("/sbin/mkdosfs")) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1124 | if (!UnMount(true)) |
| 1125 | return false; |
| 1126 | |
| 1127 | ui_print("Formatting %s using mkdosfs...\n", Display_Name.c_str()); |
| 1128 | Find_Actual_Block_Device(); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1129 | command = "mkdosfs " + Actual_Block_Device; |
| 1130 | if (TWFunc::Exec_Cmd(command, result) == 0) { |
Gary Peck | e8bc5d7 | 2012-12-21 06:45:25 -0800 | [diff] [blame] | 1131 | Current_File_System = "vfat"; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1132 | Recreate_AndSec_Folder(); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1133 | ui_print("Done.\n"); |
| 1134 | return true; |
| 1135 | } else { |
| 1136 | LOGE("Unable to wipe '%s'.\n", Mount_Point.c_str()); |
| 1137 | return false; |
| 1138 | } |
| 1139 | return true; |
| 1140 | } |
| 1141 | else |
| 1142 | return Wipe_RMRF(); |
| 1143 | |
| 1144 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1145 | } |
| 1146 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1147 | bool TWPartition::Wipe_EXFAT() { |
| 1148 | string command, result; |
| 1149 | |
| 1150 | if (TWFunc::Path_Exists("/sbin/mkexfatfs")) { |
| 1151 | if (!UnMount(true)) |
| 1152 | return false; |
| 1153 | |
| 1154 | ui_print("Formatting %s using mkexfatfs...\n", Display_Name.c_str()); |
| 1155 | Find_Actual_Block_Device(); |
| 1156 | command = "mkexfatfs " + Actual_Block_Device; |
| 1157 | if (TWFunc::Exec_Cmd(command, result) == 0) { |
| 1158 | Recreate_AndSec_Folder(); |
| 1159 | ui_print("Done.\n"); |
| 1160 | return true; |
| 1161 | } else { |
| 1162 | LOGE("Unable to wipe '%s'.\n", Mount_Point.c_str()); |
| 1163 | return false; |
| 1164 | } |
| 1165 | return true; |
| 1166 | } |
| 1167 | return false; |
| 1168 | } |
| 1169 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1170 | bool TWPartition::Wipe_MTD() { |
| 1171 | if (!UnMount(true)) |
| 1172 | return false; |
| 1173 | |
| 1174 | ui_print("MTD Formatting \"%s\"\n", MTD_Name.c_str()); |
| 1175 | |
| 1176 | mtd_scan_partitions(); |
| 1177 | const MtdPartition* mtd = mtd_find_partition_by_name(MTD_Name.c_str()); |
| 1178 | if (mtd == NULL) { |
| 1179 | LOGE("No mtd partition named '%s'", MTD_Name.c_str()); |
| 1180 | return false; |
| 1181 | } |
| 1182 | |
| 1183 | MtdWriteContext* ctx = mtd_write_partition(mtd); |
| 1184 | if (ctx == NULL) { |
| 1185 | LOGE("Can't write '%s', failed to format.", MTD_Name.c_str()); |
| 1186 | return false; |
| 1187 | } |
| 1188 | if (mtd_erase_blocks(ctx, -1) == -1) { |
| 1189 | mtd_write_close(ctx); |
| 1190 | LOGE("Failed to format '%s'", MTD_Name.c_str()); |
| 1191 | return false; |
| 1192 | } |
| 1193 | if (mtd_write_close(ctx) != 0) { |
| 1194 | LOGE("Failed to close '%s'", MTD_Name.c_str()); |
| 1195 | return false; |
| 1196 | } |
Gary Peck | e8bc5d7 | 2012-12-21 06:45:25 -0800 | [diff] [blame] | 1197 | Current_File_System = "yaffs2"; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1198 | Recreate_AndSec_Folder(); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1199 | ui_print("Done.\n"); |
| 1200 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | bool TWPartition::Wipe_RMRF() { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1204 | if (!Mount(true)) |
| 1205 | return false; |
| 1206 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1207 | ui_print("Removing all files under '%s'\n", Mount_Point.c_str()); |
| 1208 | TWFunc::removeDir(Mount_Point, true); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1209 | Recreate_AndSec_Folder(); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1210 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | bool TWPartition::Wipe_Data_Without_Wiping_Media() { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1214 | string dir; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1215 | |
| 1216 | // This handles wiping data on devices with "sdcard" in /data/media |
| 1217 | if (!Mount(true)) |
| 1218 | return false; |
| 1219 | |
| 1220 | ui_print("Wiping data without wiping /data/media ...\n"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1221 | |
| 1222 | DIR* d; |
| 1223 | d = opendir("/data"); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 1224 | if (d != NULL) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1225 | struct dirent* de; |
| 1226 | while ((de = readdir(d)) != NULL) { |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 1227 | if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue; |
| 1228 | // The media folder is the "internal sdcard" |
| 1229 | // The .layout_version file is responsible for determining whether 4.2 decides up upgrade |
| 1230 | // the media folder for multi-user. |
| 1231 | 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] | 1232 | |
| 1233 | dir = "/data/"; |
| 1234 | dir.append(de->d_name); |
Dees_Troy | ce67546 | 2013-01-09 19:48:21 +0000 | [diff] [blame] | 1235 | if (de->d_type == DT_DIR) { |
| 1236 | TWFunc::removeDir(dir, false); |
bigbiff bigbiff | 98f1f90 | 2013-01-19 18:46:13 -0500 | [diff] [blame] | 1237 | } 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] | 1238 | if (!unlink(dir.c_str())) |
| 1239 | LOGI("Unable to unlink '%s'\n", dir.c_str()); |
| 1240 | } |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1241 | } |
| 1242 | closedir(d); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 1243 | ui_print("Done.\n"); |
| 1244 | return true; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1245 | } |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 1246 | ui_print("Dirent failed to open /data, error!\n"); |
| 1247 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | bool TWPartition::Backup_Tar(string backup_folder) { |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1251 | char back_name[255], split_index[5]; |
| 1252 | string Full_FileName, Split_FileName, Tar_Args, Command; |
| 1253 | int use_compression, index, backup_count; |
| 1254 | struct stat st; |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 1255 | unsigned long long total_bsize = 0, file_size; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1256 | twrpTar tar; |
| 1257 | vector <string> files; |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 1258 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1259 | if (!Mount(true)) |
| 1260 | return false; |
| 1261 | |
Dees_Troy | 2c50e18 | 2012-09-26 20:05:28 -0400 | [diff] [blame] | 1262 | if (Backup_Path == "/and-sec") { |
| 1263 | TWFunc::GUI_Operation_Text(TW_BACKUP_TEXT, "Android Secure", "Backing Up"); |
| 1264 | ui_print("Backing up %s...\n", "Android Secure"); |
| 1265 | } else { |
| 1266 | TWFunc::GUI_Operation_Text(TW_BACKUP_TEXT, Display_Name, "Backing Up"); |
| 1267 | ui_print("Backing up %s...\n", Display_Name.c_str()); |
| 1268 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1269 | |
| 1270 | DataManager::GetValue(TW_USE_COMPRESSION_VAR, use_compression); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1271 | |
| 1272 | sprintf(back_name, "%s.%s.win", Backup_Name.c_str(), Current_File_System.c_str()); |
| 1273 | Backup_FileName = back_name; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1274 | Full_FileName = backup_folder + "/" + Backup_FileName; |
| 1275 | if (Backup_Size > MAX_ARCHIVE_SIZE) { |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1276 | // This backup needs to be split into multiple archives |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1277 | ui_print("Breaking backup file into multiple archives...\n"); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1278 | sprintf(back_name, "%s", Backup_Path.c_str()); |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 1279 | tar.setdir(back_name); |
| 1280 | tar.setfn(Full_FileName); |
| 1281 | backup_count = tar.splitArchiveThread(); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1282 | if (backup_count == -1) { |
| 1283 | LOGE("Error tarring split files!\n"); |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1284 | return false; |
| 1285 | } |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1286 | return true; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1287 | } else { |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1288 | Full_FileName = backup_folder + "/" + Backup_FileName; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1289 | if (use_compression) { |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 1290 | tar.setdir(Backup_Path); |
| 1291 | tar.setfn(Full_FileName); |
| 1292 | if (tar.createTarGZThread() != 0) |
| 1293 | return -1; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1294 | string gzname = Full_FileName + ".gz"; |
| 1295 | rename(gzname.c_str(), Full_FileName.c_str()); |
| 1296 | } |
| 1297 | else { |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 1298 | tar.setdir(Backup_Path); |
| 1299 | tar.setfn(Full_FileName); |
| 1300 | if (tar.createTarThread() != 0) |
| 1301 | return -1; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1302 | } |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 1303 | if (TWFunc::Get_File_Size(Full_FileName) == 0) { |
| 1304 | LOGE("Backup file size for '%s' is 0 bytes.\n", Full_FileName.c_str()); |
| 1305 | return false; |
| 1306 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1307 | } |
| 1308 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | bool TWPartition::Backup_DD(string backup_folder) { |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1312 | char back_name[255]; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1313 | string Full_FileName, Command, result; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1314 | int use_compression; |
| 1315 | |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 1316 | TWFunc::GUI_Operation_Text(TW_BACKUP_TEXT, Display_Name, "Backing Up"); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1317 | ui_print("Backing up %s...\n", Display_Name.c_str()); |
| 1318 | |
| 1319 | sprintf(back_name, "%s.%s.win", Backup_Name.c_str(), Current_File_System.c_str()); |
| 1320 | Backup_FileName = back_name; |
| 1321 | |
| 1322 | Full_FileName = backup_folder + "/" + Backup_FileName; |
| 1323 | |
| 1324 | Command = "dd if=" + Actual_Block_Device + " of='" + Full_FileName + "'"; |
| 1325 | LOGI("Backup command: '%s'\n", Command.c_str()); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1326 | TWFunc::Exec_Cmd(Command, result); |
Dees_Troy | c154ac2 | 2012-10-12 15:36:47 -0400 | [diff] [blame] | 1327 | if (TWFunc::Get_File_Size(Full_FileName) == 0) { |
| 1328 | 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] | 1329 | return false; |
| 1330 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1331 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | bool TWPartition::Backup_Dump_Image(string backup_folder) { |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1335 | char back_name[255]; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1336 | string Full_FileName, Command, result; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1337 | int use_compression; |
| 1338 | |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 1339 | TWFunc::GUI_Operation_Text(TW_BACKUP_TEXT, Display_Name, "Backing Up"); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1340 | ui_print("Backing up %s...\n", Display_Name.c_str()); |
| 1341 | |
| 1342 | sprintf(back_name, "%s.%s.win", Backup_Name.c_str(), Current_File_System.c_str()); |
| 1343 | Backup_FileName = back_name; |
| 1344 | |
| 1345 | Full_FileName = backup_folder + "/" + Backup_FileName; |
| 1346 | |
| 1347 | Command = "dump_image " + MTD_Name + " '" + Full_FileName + "'"; |
| 1348 | LOGI("Backup command: '%s'\n", Command.c_str()); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1349 | TWFunc::Exec_Cmd(Command, result); |
Dees_Troy | 7c2dec8 | 2012-09-26 09:49:14 -0400 | [diff] [blame] | 1350 | if (TWFunc::Get_File_Size(Full_FileName) == 0) { |
| 1351 | // Actual size may not match backup size due to bad blocks on MTD devices so just check for 0 bytes |
| 1352 | LOGE("Backup file size for '%s' is 0 bytes.\n", Full_FileName.c_str()); |
| 1353 | return false; |
| 1354 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1355 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1356 | } |
| 1357 | |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 1358 | bool TWPartition::Restore_Tar(string restore_folder, string Restore_File_System) { |
| 1359 | string Full_FileName, Command; |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1360 | int index = 0; |
| 1361 | char split_index[5]; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1362 | |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1363 | if (Has_Android_Secure) { |
| 1364 | ui_print("Wiping android secure...\n"); |
| 1365 | if (!Wipe_AndSec()) |
| 1366 | return false; |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 1367 | } else { |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1368 | ui_print("Wiping %s...\n", Display_Name.c_str()); |
Gary Peck | 43acadf | 2012-11-21 21:19:01 -0800 | [diff] [blame] | 1369 | if (!Wipe(Restore_File_System)) |
| 1370 | return false; |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1371 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1372 | |
| 1373 | if (!Mount(true)) |
| 1374 | return false; |
| 1375 | |
Dees_Troy | da8b55a | 2012-12-12 19:18:30 +0000 | [diff] [blame] | 1376 | TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Display_Name, "Restoring"); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1377 | ui_print("Restoring %s...\n", Display_Name.c_str()); |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1378 | Full_FileName = restore_folder + "/" + Backup_FileName; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1379 | if (!TWFunc::Path_Exists(Full_FileName)) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1380 | if (!TWFunc::Path_Exists(Full_FileName)) { |
| 1381 | // Backup is multiple archives |
| 1382 | LOGI("Backup is multiple archives.\n"); |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1383 | sprintf(split_index, "%03i", index); |
| 1384 | Full_FileName = restore_folder + "/" + Backup_FileName + split_index; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1385 | while (TWFunc::Path_Exists(Full_FileName)) { |
| 1386 | index++; |
| 1387 | ui_print("Restoring archive %i...\n", index); |
| 1388 | LOGI("Restoring '%s'...\n", Full_FileName.c_str()); |
| 1389 | twrpTar tar; |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 1390 | tar.setdir("/"); |
| 1391 | tar.setfn(Full_FileName); |
| 1392 | if (tar.extractTarThread() != 0) |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1393 | return false; |
| 1394 | sprintf(split_index, "%03i", index); |
| 1395 | Full_FileName = restore_folder + "/" + Backup_FileName + split_index; |
| 1396 | } |
| 1397 | if (index == 0) { |
| 1398 | LOGE("Error locating restore file: '%s'\n", Full_FileName.c_str()); |
| 1399 | return false; |
| 1400 | } |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 1401 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1402 | } else { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1403 | twrpTar tar; |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 1404 | tar.setdir(Backup_Path); |
| 1405 | tar.setfn(Full_FileName); |
| 1406 | if (tar.extractTarThread() != 0) |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1407 | return false; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1408 | } |
| 1409 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | bool TWPartition::Restore_DD(string restore_folder) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1413 | string Full_FileName, Command, result; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1414 | |
Dees_Troy | da8b55a | 2012-12-12 19:18:30 +0000 | [diff] [blame] | 1415 | TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Display_Name, "Restoring"); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1416 | Full_FileName = restore_folder + "/" + Backup_FileName; |
Gary Peck | 15e623d | 2012-11-21 21:07:58 -0800 | [diff] [blame] | 1417 | |
| 1418 | if (!Find_Partition_Size()) { |
| 1419 | LOGE("Unable to find partition size for '%s'\n", Mount_Point.c_str()); |
| 1420 | return false; |
| 1421 | } |
| 1422 | unsigned long long backup_size = TWFunc::Get_File_Size(Full_FileName); |
| 1423 | if (backup_size > Size) { |
| 1424 | LOGE("Size (%iMB) of backup '%s' is larger than target device '%s' (%iMB)\n", |
| 1425 | (int)(backup_size / 1048576LLU), Full_FileName.c_str(), |
| 1426 | Actual_Block_Device.c_str(), (int)(Size / 1048576LLU)); |
| 1427 | return false; |
| 1428 | } |
| 1429 | |
| 1430 | ui_print("Restoring %s...\n", Display_Name.c_str()); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1431 | Command = "dd bs=4096 if='" + Full_FileName + "' of=" + Actual_Block_Device; |
| 1432 | LOGI("Restore command: '%s'\n", Command.c_str()); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1433 | TWFunc::Exec_Cmd(Command, result); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1434 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | bool TWPartition::Restore_Flash_Image(string restore_folder) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1438 | string Full_FileName, Command, result; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1439 | |
| 1440 | ui_print("Restoring %s...\n", Display_Name.c_str()); |
| 1441 | Full_FileName = restore_folder + "/" + Backup_FileName; |
| 1442 | // Sometimes flash image doesn't like to flash due to the first 2KB matching, so we erase first to ensure that it flashes |
| 1443 | Command = "erase_image " + MTD_Name; |
| 1444 | LOGI("Erase command: '%s'\n", Command.c_str()); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1445 | TWFunc::Exec_Cmd(Command, result); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1446 | Command = "flash_image " + MTD_Name + " '" + Full_FileName + "'"; |
| 1447 | LOGI("Restore command: '%s'\n", Command.c_str()); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1448 | TWFunc::Exec_Cmd(Command, result); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1449 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1450 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1451 | |
| 1452 | bool TWPartition::Update_Size(bool Display_Error) { |
Dees_Troy | 0550cfb | 2012-10-13 11:56:13 -0400 | [diff] [blame] | 1453 | bool ret = false, Was_Already_Mounted = false; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1454 | |
Dees_Troy | ab10ee2 | 2012-09-21 14:27:30 -0400 | [diff] [blame] | 1455 | if (!Can_Be_Mounted && !Is_Encrypted) |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1456 | return false; |
| 1457 | |
Dees_Troy | 0550cfb | 2012-10-13 11:56:13 -0400 | [diff] [blame] | 1458 | Was_Already_Mounted = Is_Mounted(); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1459 | if (Removable || Is_Encrypted) { |
| 1460 | if (!Mount(false)) |
| 1461 | return true; |
| 1462 | } else if (!Mount(Display_Error)) |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1463 | return false; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1464 | |
| 1465 | ret = Get_Size_Via_statfs(Display_Error); |
Dees_Troy | 0550cfb | 2012-10-13 11:56:13 -0400 | [diff] [blame] | 1466 | if (!ret || Size == 0) { |
| 1467 | if (!Get_Size_Via_df(Display_Error)) { |
| 1468 | if (!Was_Already_Mounted) |
| 1469 | UnMount(false); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1470 | return false; |
Dees_Troy | 0550cfb | 2012-10-13 11:56:13 -0400 | [diff] [blame] | 1471 | } |
| 1472 | } |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1473 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1474 | if (Has_Data_Media) { |
| 1475 | if (Mount(Display_Error)) { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1476 | unsigned long long data_media_used, actual_data; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1477 | Used = TWFunc::Get_Folder_Size("/data", Display_Error); |
| 1478 | data_media_used = TWFunc::Get_Folder_Size("/data/media", Display_Error); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1479 | actual_data = Used - data_media_used; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1480 | Backup_Size = actual_data; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1481 | int bak = (int)(Backup_Size / 1048576LLU); |
| 1482 | int total = (int)(Size / 1048576LLU); |
| 1483 | int us = (int)(Used / 1048576LLU); |
| 1484 | int fre = (int)(Free / 1048576LLU); |
| 1485 | int datmed = (int)(data_media_used / 1048576LLU); |
| 1486 | 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] | 1487 | } else { |
| 1488 | if (!Was_Already_Mounted) |
| 1489 | UnMount(false); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1490 | return false; |
Dees_Troy | 0550cfb | 2012-10-13 11:56:13 -0400 | [diff] [blame] | 1491 | } |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1492 | } else if (Has_Android_Secure) { |
| 1493 | if (Mount(Display_Error)) |
| 1494 | Backup_Size = TWFunc::Get_Folder_Size(Backup_Path, Display_Error); |
Dees_Troy | 0550cfb | 2012-10-13 11:56:13 -0400 | [diff] [blame] | 1495 | else { |
| 1496 | if (!Was_Already_Mounted) |
| 1497 | UnMount(false); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1498 | return false; |
Dees_Troy | 0550cfb | 2012-10-13 11:56:13 -0400 | [diff] [blame] | 1499 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1500 | } |
Dees_Troy | 0550cfb | 2012-10-13 11:56:13 -0400 | [diff] [blame] | 1501 | if (!Was_Already_Mounted) |
| 1502 | UnMount(false); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1503 | return true; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1504 | } |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1505 | |
| 1506 | void TWPartition::Find_Actual_Block_Device(void) { |
| 1507 | if (Is_Decrypted) { |
| 1508 | Actual_Block_Device = Decrypted_Block_Device; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1509 | if (TWFunc::Path_Exists(Primary_Block_Device)) |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1510 | Is_Present = true; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1511 | } else if (TWFunc::Path_Exists(Primary_Block_Device)) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1512 | Is_Present = true; |
| 1513 | Actual_Block_Device = Primary_Block_Device; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1514 | return; |
| 1515 | } |
| 1516 | if (Is_Decrypted) { |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1517 | } else if (!Alternate_Block_Device.empty() && TWFunc::Path_Exists(Alternate_Block_Device)) { |
Dees_Troy | 3f04d03 | 2012-10-07 18:20:09 -0400 | [diff] [blame] | 1518 | Actual_Block_Device = Alternate_Block_Device; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1519 | Is_Present = true; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1520 | } else { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1521 | Is_Present = false; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1522 | } |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | void TWPartition::Recreate_Media_Folder(void) { |
| 1526 | string Command; |
| 1527 | |
| 1528 | if (!Mount(true)) { |
| 1529 | LOGE("Unable to recreate /data/media folder.\n"); |
Dees_Troy | b46a684 | 2012-09-25 11:06:46 -0400 | [diff] [blame] | 1530 | } else if (!TWFunc::Path_Exists("/data/media")) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1531 | PartitionManager.Mount_By_Path(Symlink_Mount_Point, true); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1532 | LOGI("Recreating /data/media folder.\n"); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1533 | mkdir("/data/media", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 1534 | PartitionManager.UnMount_By_Path(Symlink_Mount_Point, true); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1535 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1536 | } |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1537 | |
| 1538 | void TWPartition::Recreate_AndSec_Folder(void) { |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1539 | if (!Has_Android_Secure) |
| 1540 | return; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1541 | LOGI("Creating .android_secure: %s\n", Symlink_Path.c_str()); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1542 | if (!Mount(true)) { |
| 1543 | LOGE("Unable to recreate android secure folder.\n"); |
| 1544 | } else if (!TWFunc::Path_Exists(Symlink_Path)) { |
| 1545 | LOGI("Recreating android secure folder.\n"); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1546 | PartitionManager.Mount_By_Path(Symlink_Mount_Point, true); |
| 1547 | mkdir(Symlink_Path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 1548 | PartitionManager.UnMount_By_Path(Symlink_Mount_Point, true); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1549 | } |
| 1550 | } |