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