blob: b79e774cb812b9661172deff93a3cb7e9da991b9 [file] [log] [blame]
Dees Troy3be70a82013-10-22 14:25:12 +00001/*
bigbiff bigbiff34684ff2013-12-01 21:03:45 -05002 Copyright 2013 TeamWin
Dees Troy3be70a82013-10-22 14:25:12 +00003 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_Troy51a0e822012-09-05 15:24:24 -040018
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include <sys/stat.h>
23#include <sys/vfs.h>
Dees_Troy5bf43922012-09-07 16:07:55 -040024#include <sys/mount.h>
Dees_Troy51a0e822012-09-05 15:24:24 -040025#include <unistd.h>
Dees_Troy51127312012-09-08 13:08:49 -040026#include <dirent.h>
bigbiff bigbiff9c754052013-01-09 09:09:08 -050027#include <iostream>
28#include <sstream>
Dees_Troy51a0e822012-09-05 15:24:24 -040029
Dees_Troy657c3092012-09-10 20:32:10 -040030#ifdef TW_INCLUDE_CRYPTO
31 #include "cutils/properties.h"
32#endif
33
bigbiff bigbiffe60683a2013-02-22 20:55:50 -050034#include "libblkid/blkid.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040035#include "variables.h"
Dees_Troy2673cec2013-04-02 20:22:16 +000036#include "twcommon.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040037#include "partitions.hpp"
Dees_Troy5bf43922012-09-07 16:07:55 -040038#include "data.hpp"
Dees_Troy43d8b002012-09-17 16:00:01 -040039#include "twrp-functions.hpp"
bigbiff bigbiffcdcfee42013-02-27 21:11:26 -050040#include "twrpDigest.hpp"
bigbiff bigbiff9c754052013-01-09 09:09:08 -050041#include "twrpTar.hpp"
bigbiff bigbiff34684ff2013-12-01 21:03:45 -050042#include "twrpDU.hpp"
Dees_Troy5bf43922012-09-07 16:07:55 -040043extern "C" {
Dees_Troy38bd7602012-09-14 13:33:53 -040044 #include "mtdutils/mtdutils.h"
45 #include "mtdutils/mounts.h"
Dees_Troy85f44ed2013-01-09 18:42:36 +000046#ifdef TW_INCLUDE_CRYPTO_SAMSUNG
47 #include "crypto/libcrypt_samsung/include/libcrypt_samsung.h"
48#endif
Dees_Troya95f55c2013-08-17 13:14:43 +000049#ifdef USE_EXT4
50 #include "make_ext4fs.h"
51#endif
Dees_Troy5bf43922012-09-07 16:07:55 -040052}
bigbiff bigbiffc49d7062013-10-11 20:28:00 -040053#ifdef HAVE_SELINUX
54#include "selinux/selinux.h"
55#endif
Dees_Troy51a0e822012-09-05 15:24:24 -040056
bigbiff bigbiff9c754052013-01-09 09:09:08 -050057using namespace std;
58
Dees_Troya95f55c2013-08-17 13:14:43 +000059extern struct selabel_handle *selinux_handle;
60
Hashcode62bd9e02013-11-19 21:59:42 -080061struct flag_list {
62 const char *name;
63 unsigned flag;
64};
65
66static struct flag_list mount_flags[] = {
67 { "noatime", MS_NOATIME },
68 { "noexec", MS_NOEXEC },
69 { "nosuid", MS_NOSUID },
70 { "nodev", MS_NODEV },
71 { "nodiratime", MS_NODIRATIME },
72 { "ro", MS_RDONLY },
73 { "rw", 0 },
74 { "remount", MS_REMOUNT },
75 { "bind", MS_BIND },
76 { "rec", MS_REC },
Dees Troyc4bc30e2014-02-03 15:04:19 +000077#ifdef MS_UNBINDABLE
Hashcode62bd9e02013-11-19 21:59:42 -080078 { "unbindable", MS_UNBINDABLE },
Dees Troyc4bc30e2014-02-03 15:04:19 +000079#endif
80#ifdef MS_PRIVATE
Hashcode62bd9e02013-11-19 21:59:42 -080081 { "private", MS_PRIVATE },
Dees Troyc4bc30e2014-02-03 15:04:19 +000082#endif
83#ifdef MS_SLAVE
Hashcode62bd9e02013-11-19 21:59:42 -080084 { "slave", MS_SLAVE },
Dees Troyc4bc30e2014-02-03 15:04:19 +000085#endif
86#ifdef MS_SHARED
Hashcode62bd9e02013-11-19 21:59:42 -080087 { "shared", MS_SHARED },
Dees Troyc4bc30e2014-02-03 15:04:19 +000088#endif
Hashcode62bd9e02013-11-19 21:59:42 -080089 { "sync", MS_SYNCHRONOUS },
90 { "defaults", 0 },
91 { 0, 0 },
92};
93
Dees_Troy51a0e822012-09-05 15:24:24 -040094TWPartition::TWPartition(void) {
95 Can_Be_Mounted = false;
96 Can_Be_Wiped = false;
Dees_Troya13d74f2013-03-24 08:54:55 -050097 Can_Be_Backed_Up = false;
Vojtech Bocek1dc30982013-08-30 21:49:30 +020098 Use_Rm_Rf = false;
Dees_Troy51a0e822012-09-05 15:24:24 -040099 Wipe_During_Factory_Reset = false;
100 Wipe_Available_in_GUI = false;
101 Is_SubPartition = false;
Dees_Troy2691f9d2012-09-24 11:15:49 -0400102 Has_SubPartition = false;
Dees_Troy51a0e822012-09-05 15:24:24 -0400103 SubPartition_Of = "";
104 Symlink_Path = "";
105 Symlink_Mount_Point = "";
106 Mount_Point = "";
Dees_Troye58d5262012-09-21 12:27:57 -0400107 Backup_Path = "";
Dees_Troy38bd7602012-09-14 13:33:53 -0400108 Actual_Block_Device = "";
109 Primary_Block_Device = "";
Dees_Troy51a0e822012-09-05 15:24:24 -0400110 Alternate_Block_Device = "";
111 Removable = false;
112 Is_Present = false;
113 Length = 0;
114 Size = 0;
115 Used = 0;
116 Free = 0;
117 Backup_Size = 0;
118 Can_Be_Encrypted = false;
119 Is_Encrypted = false;
120 Is_Decrypted = false;
121 Decrypted_Block_Device = "";
122 Display_Name = "";
Dees_Troya13d74f2013-03-24 08:54:55 -0500123 Backup_Display_Name = "";
124 Storage_Name = "";
Dees_Troy51a0e822012-09-05 15:24:24 -0400125 Backup_Name = "";
Dees_Troy63c8df72012-09-10 14:02:05 -0400126 Backup_FileName = "";
Dees_Troy38bd7602012-09-14 13:33:53 -0400127 MTD_Name = "";
Dees_Troy51a0e822012-09-05 15:24:24 -0400128 Backup_Method = NONE;
Dees_Troy83bd4832013-05-04 12:39:56 +0000129 Can_Encrypt_Backup = false;
130 Use_Userdata_Encryption = false;
Dees_Troy51a0e822012-09-05 15:24:24 -0400131 Has_Data_Media = false;
Dees_Troye58d5262012-09-21 12:27:57 -0400132 Has_Android_Secure = false;
Dees_Troy51a0e822012-09-05 15:24:24 -0400133 Is_Storage = false;
Dees_Troya13d74f2013-03-24 08:54:55 -0500134 Is_Settings_Storage = false;
Dees_Troy51a0e822012-09-05 15:24:24 -0400135 Storage_Path = "";
136 Current_File_System = "";
137 Fstab_File_System = "";
Hashcode62bd9e02013-11-19 21:59:42 -0800138 Mount_Flags = 0;
139 Mount_Options = "";
Dees_Troy51a0e822012-09-05 15:24:24 -0400140 Format_Block_Size = 0;
Dees_Troy68cab492012-12-12 19:29:35 +0000141 Ignore_Blkid = false;
Dees_Troy16c2b312013-01-15 16:51:18 +0000142 Retain_Layout_Version = false;
Dees_Troy85f44ed2013-01-09 18:42:36 +0000143#ifdef TW_INCLUDE_CRYPTO_SAMSUNG
144 EcryptFS_Password = "";
145#endif
Dees_Troy51a0e822012-09-05 15:24:24 -0400146}
147
148TWPartition::~TWPartition(void) {
149 // Do nothing
150}
151
Dees_Troy5bf43922012-09-07 16:07:55 -0400152bool TWPartition::Process_Fstab_Line(string Line, bool Display_Error) {
153 char full_line[MAX_FSTAB_LINE_LENGTH], item[MAX_FSTAB_LINE_LENGTH];
154 int line_len = Line.size(), index = 0, item_index = 0;
155 char* ptr;
Dees_Troy51127312012-09-08 13:08:49 -0400156 string Flags;
Dees_Troy5bf43922012-09-07 16:07:55 -0400157 strncpy(full_line, Line.c_str(), line_len);
Dees_Troya13d74f2013-03-24 08:54:55 -0500158 bool skip = false;
Dees_Troy5bf43922012-09-07 16:07:55 -0400159
Dees_Troy51127312012-09-08 13:08:49 -0400160 for (index = 0; index < line_len; index++) {
Dees_Troya13d74f2013-03-24 08:54:55 -0500161 if (full_line[index] == 34)
162 skip = !skip;
163 if (!skip && full_line[index] <= 32)
Dees_Troy5bf43922012-09-07 16:07:55 -0400164 full_line[index] = '\0';
Dees_Troy5bf43922012-09-07 16:07:55 -0400165 }
Dees_Troy7c2dec82012-09-26 09:49:14 -0400166 Mount_Point = full_line;
Dees_Troy2673cec2013-04-02 20:22:16 +0000167 LOGINFO("Processing '%s'\n", Mount_Point.c_str());
Dees_Troye58d5262012-09-21 12:27:57 -0400168 Backup_Path = Mount_Point;
Dees_Troya13d74f2013-03-24 08:54:55 -0500169 Storage_Path = Mount_Point;
Dees_Troy70737fa2013-04-08 13:19:20 +0000170 Display_Name = full_line + 1;
171 Backup_Display_Name = Display_Name;
172 Storage_Name = Display_Name;
Dees_Troy5bf43922012-09-07 16:07:55 -0400173 index = Mount_Point.size();
174 while (index < line_len) {
175 while (index < line_len && full_line[index] == '\0')
176 index++;
177 if (index >= line_len)
178 continue;
179 ptr = full_line + index;
180 if (item_index == 0) {
181 // File System
182 Fstab_File_System = ptr;
183 Current_File_System = ptr;
184 item_index++;
185 } else if (item_index == 1) {
186 // Primary Block Device
Dees_Troy38bd7602012-09-14 13:33:53 -0400187 if (Fstab_File_System == "mtd" || Fstab_File_System == "yaffs2") {
Dees_Troy094207a2012-09-26 12:00:39 -0400188 MTD_Name = ptr;
189 Find_MTD_Block_Device(MTD_Name);
Dees_Troy5fcd8f92012-10-16 12:22:05 -0400190 } else if (Fstab_File_System == "bml") {
191 if (Mount_Point == "/boot")
192 MTD_Name = "boot";
193 else if (Mount_Point == "/recovery")
194 MTD_Name = "recovery";
195 Primary_Block_Device = ptr;
196 if (*ptr != '/')
Dees_Troy2673cec2013-04-02 20:22:16 +0000197 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_Troy38bd7602012-09-14 13:33:53 -0400198 } else if (*ptr != '/') {
Dees_Troy5bf43922012-09-07 16:07:55 -0400199 if (Display_Error)
Dees_Troy2673cec2013-04-02 20:22:16 +0000200 LOGERR("Invalid block device on '%s', '%s', %i\n", Line.c_str(), ptr, index);
Dees_Troy5bf43922012-09-07 16:07:55 -0400201 else
Dees_Troy2673cec2013-04-02 20:22:16 +0000202 LOGINFO("Invalid block device on '%s', '%s', %i\n", Line.c_str(), ptr, index);
Dees_Troy5bf43922012-09-07 16:07:55 -0400203 return 0;
Dees_Troy38bd7602012-09-14 13:33:53 -0400204 } else {
205 Primary_Block_Device = ptr;
206 Find_Real_Block_Device(Primary_Block_Device, Display_Error);
Dees_Troy5bf43922012-09-07 16:07:55 -0400207 }
Dees_Troy5bf43922012-09-07 16:07:55 -0400208 item_index++;
209 } else if (item_index > 1) {
210 if (*ptr == '/') {
211 // Alternate Block Device
212 Alternate_Block_Device = ptr;
213 Find_Real_Block_Device(Alternate_Block_Device, Display_Error);
214 } else if (strlen(ptr) > 7 && strncmp(ptr, "length=", 7) == 0) {
215 // Partition length
216 ptr += 7;
217 Length = atoi(ptr);
Dees_Troy51127312012-09-08 13:08:49 -0400218 } else if (strlen(ptr) > 6 && strncmp(ptr, "flags=", 6) == 0) {
219 // Custom flags, save for later so that new values aren't overwritten by defaults
220 ptr += 6;
221 Flags = ptr;
Dees_Troy68cab492012-12-12 19:29:35 +0000222 Process_Flags(Flags, Display_Error);
Dees_Troy38bd7602012-09-14 13:33:53 -0400223 } else if (strlen(ptr) == 4 && (strncmp(ptr, "NULL", 4) == 0 || strncmp(ptr, "null", 4) == 0 || strncmp(ptr, "null", 4) == 0)) {
224 // Do nothing
Dees_Troy5bf43922012-09-07 16:07:55 -0400225 } else {
226 // Unhandled data
Dees_Troy2673cec2013-04-02 20:22:16 +0000227 LOGINFO("Unhandled fstab information: '%s', %i, line: '%s'\n", ptr, index, Line.c_str());
Dees_Troy5bf43922012-09-07 16:07:55 -0400228 }
229 }
230 while (index < line_len && full_line[index] != '\0')
231 index++;
232 }
233
234 if (!Is_File_System(Fstab_File_System) && !Is_Image(Fstab_File_System)) {
235 if (Display_Error)
Dees_Troy2673cec2013-04-02 20:22:16 +0000236 LOGERR("Unknown File System: '%s'\n", Fstab_File_System.c_str());
Dees_Troy5bf43922012-09-07 16:07:55 -0400237 else
Dees_Troy2673cec2013-04-02 20:22:16 +0000238 LOGINFO("Unknown File System: '%s'\n", Fstab_File_System.c_str());
Dees_Troy5bf43922012-09-07 16:07:55 -0400239 return 0;
240 } else if (Is_File_System(Fstab_File_System)) {
Dees_Troy38bd7602012-09-14 13:33:53 -0400241 Find_Actual_Block_Device();
Dees_Troy5bf43922012-09-07 16:07:55 -0400242 Setup_File_System(Display_Error);
243 if (Mount_Point == "/system") {
244 Display_Name = "System";
Dees_Troya13d74f2013-03-24 08:54:55 -0500245 Backup_Display_Name = Display_Name;
246 Storage_Name = Display_Name;
Dees_Troy5bf43922012-09-07 16:07:55 -0400247 Wipe_Available_in_GUI = true;
Dees_Troya13d74f2013-03-24 08:54:55 -0500248 Can_Be_Backed_Up = true;
Dees_Troy5bf43922012-09-07 16:07:55 -0400249 } else if (Mount_Point == "/data") {
250 Display_Name = "Data";
Dees_Troya13d74f2013-03-24 08:54:55 -0500251 Backup_Display_Name = Display_Name;
252 Storage_Name = Display_Name;
Dees_Troy5bf43922012-09-07 16:07:55 -0400253 Wipe_Available_in_GUI = true;
Dees_Troy51127312012-09-08 13:08:49 -0400254 Wipe_During_Factory_Reset = true;
Dees_Troya13d74f2013-03-24 08:54:55 -0500255 Can_Be_Backed_Up = true;
Dees_Troy83bd4832013-05-04 12:39:56 +0000256 Can_Encrypt_Backup = true;
257 Use_Userdata_Encryption = true;
Dees_Troy5bf43922012-09-07 16:07:55 -0400258#ifdef RECOVERY_SDCARD_ON_DATA
Dees_Troya13d74f2013-03-24 08:54:55 -0500259 Storage_Name = "Internal Storage";
Dees_Troy5bf43922012-09-07 16:07:55 -0400260 Has_Data_Media = true;
Dees_Troy51127312012-09-08 13:08:49 -0400261 Is_Storage = true;
Dees_Troya13d74f2013-03-24 08:54:55 -0500262 Is_Settings_Storage = true;
Dees_Troy51127312012-09-08 13:08:49 -0400263 Storage_Path = "/data/media";
Dees_Troy16b74352012-11-14 22:27:31 +0000264 Symlink_Path = Storage_Path;
Dees_Troy657c3092012-09-10 20:32:10 -0400265 if (strcmp(EXPAND(TW_EXTERNAL_STORAGE_PATH), "/sdcard") == 0) {
266 Make_Dir("/emmc", Display_Error);
Dees_Troy657c3092012-09-10 20:32:10 -0400267 Symlink_Mount_Point = "/emmc";
268 } else {
269 Make_Dir("/sdcard", Display_Error);
Dees_Troy657c3092012-09-10 20:32:10 -0400270 Symlink_Mount_Point = "/sdcard";
271 }
Dees_Troy16b74352012-11-14 22:27:31 +0000272 if (Mount(false) && TWFunc::Path_Exists("/data/media/0")) {
273 Storage_Path = "/data/media/0";
274 Symlink_Path = Storage_Path;
275 DataManager::SetValue(TW_INTERNAL_PATH, "/data/media/0");
276 UnMount(true);
277 }
Dees_Troy5bf43922012-09-07 16:07:55 -0400278#endif
279#ifdef TW_INCLUDE_CRYPTO
280 Can_Be_Encrypted = true;
Dees_Troy657c3092012-09-10 20:32:10 -0400281 char crypto_blkdev[255];
282 property_get("ro.crypto.fs_crypto_blkdev", crypto_blkdev, "error");
283 if (strcmp(crypto_blkdev, "error") != 0) {
Dees_Troy38bd7602012-09-14 13:33:53 -0400284 DataManager::SetValue(TW_DATA_BLK_DEVICE, Primary_Block_Device);
Dees_Troy657c3092012-09-10 20:32:10 -0400285 DataManager::SetValue(TW_IS_DECRYPTED, 1);
286 Is_Encrypted = true;
287 Is_Decrypted = true;
288 Decrypted_Block_Device = crypto_blkdev;
Dees_Troy2673cec2013-04-02 20:22:16 +0000289 LOGINFO("Data already decrypted, new block device: '%s'\n", crypto_blkdev);
Dees_Troy657c3092012-09-10 20:32:10 -0400290 } else if (!Mount(false)) {
Dees_Troy5bf43922012-09-07 16:07:55 -0400291 Is_Encrypted = true;
292 Is_Decrypted = false;
Gary Peck82599a82012-11-21 16:23:12 -0800293 Can_Be_Mounted = false;
294 Current_File_System = "emmc";
295 Setup_Image(Display_Error);
Dees_Troy5bf43922012-09-07 16:07:55 -0400296 DataManager::SetValue(TW_IS_ENCRYPTED, 1);
297 DataManager::SetValue(TW_CRYPTO_PASSWORD, "");
298 DataManager::SetValue("tw_crypto_display", "");
Gary Peck82599a82012-11-21 16:23:12 -0800299 } else {
300 // Filesystem is not encrypted and the mount
301 // succeeded, so get it back to the original
302 // unmounted state
303 UnMount(false);
Dees_Troy51127312012-09-08 13:08:49 -0400304 }
Dees_Troy9b21af72012-10-01 15:51:46 -0400305 #ifdef RECOVERY_SDCARD_ON_DATA
306 if (!Is_Encrypted || (Is_Encrypted && Is_Decrypted))
307 Recreate_Media_Folder();
308 #endif
309#else
310 #ifdef RECOVERY_SDCARD_ON_DATA
311 Recreate_Media_Folder();
312 #endif
Dees_Troy5bf43922012-09-07 16:07:55 -0400313#endif
Dees_Troy5bf43922012-09-07 16:07:55 -0400314 } else if (Mount_Point == "/cache") {
315 Display_Name = "Cache";
Dees_Troya13d74f2013-03-24 08:54:55 -0500316 Backup_Display_Name = Display_Name;
317 Storage_Name = Display_Name;
Dees_Troy5bf43922012-09-07 16:07:55 -0400318 Wipe_Available_in_GUI = true;
Dees_Troy51127312012-09-08 13:08:49 -0400319 Wipe_During_Factory_Reset = true;
Dees_Troya13d74f2013-03-24 08:54:55 -0500320 Can_Be_Backed_Up = true;
Dees_Troyce2fe772012-09-28 12:34:33 -0400321 if (Mount(false) && !TWFunc::Path_Exists("/cache/recovery/.")) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000322 LOGINFO("Recreating /cache/recovery folder.\n");
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500323 if (mkdir("/cache/recovery", S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP) != 0)
324 return -1;
Dees_Troyb46a6842012-09-25 11:06:46 -0400325 }
Dees_Troy5bf43922012-09-07 16:07:55 -0400326 } else if (Mount_Point == "/datadata") {
Dees_Troy51127312012-09-08 13:08:49 -0400327 Wipe_During_Factory_Reset = true;
Dees_Troy5bf43922012-09-07 16:07:55 -0400328 Display_Name = "DataData";
Dees_Troya13d74f2013-03-24 08:54:55 -0500329 Backup_Display_Name = Display_Name;
330 Storage_Name = Display_Name;
Dees_Troy5bf43922012-09-07 16:07:55 -0400331 Is_SubPartition = true;
332 SubPartition_Of = "/data";
Dees_Troy5bf43922012-09-07 16:07:55 -0400333 DataManager::SetValue(TW_HAS_DATADATA, 1);
Dees_Troya13d74f2013-03-24 08:54:55 -0500334 Can_Be_Backed_Up = true;
Dees_Troy83bd4832013-05-04 12:39:56 +0000335 Can_Encrypt_Backup = true;
336 Use_Userdata_Encryption = false; // This whole partition should be encrypted
Dees_Troy5bf43922012-09-07 16:07:55 -0400337 } else if (Mount_Point == "/sd-ext") {
Dees_Troy51127312012-09-08 13:08:49 -0400338 Wipe_During_Factory_Reset = true;
Dees_Troy5bf43922012-09-07 16:07:55 -0400339 Display_Name = "SD-Ext";
Dees_Troya13d74f2013-03-24 08:54:55 -0500340 Backup_Display_Name = Display_Name;
341 Storage_Name = Display_Name;
Dees_Troy5bf43922012-09-07 16:07:55 -0400342 Wipe_Available_in_GUI = true;
Dees_Troyc51f1f92012-09-20 15:32:13 -0400343 Removable = true;
Dees_Troya13d74f2013-03-24 08:54:55 -0500344 Can_Be_Backed_Up = true;
Dees_Troy83bd4832013-05-04 12:39:56 +0000345 Can_Encrypt_Backup = true;
346 Use_Userdata_Encryption = true;
Dees_Troy2c50e182012-09-26 20:05:28 -0400347 } else if (Mount_Point == "/boot") {
348 Display_Name = "Boot";
Dees_Troya13d74f2013-03-24 08:54:55 -0500349 Backup_Display_Name = Display_Name;
Dees_Troy2c50e182012-09-26 20:05:28 -0400350 DataManager::SetValue("tw_boot_is_mountable", 1);
Dees_Troya13d74f2013-03-24 08:54:55 -0500351 Can_Be_Backed_Up = true;
Dees_Troy8170a922012-09-18 15:40:25 -0400352 }
353#ifdef TW_EXTERNAL_STORAGE_PATH
354 if (Mount_Point == EXPAND(TW_EXTERNAL_STORAGE_PATH)) {
355 Is_Storage = true;
356 Storage_Path = EXPAND(TW_EXTERNAL_STORAGE_PATH);
Dees_Troyc51f1f92012-09-20 15:32:13 -0400357 Removable = true;
Dees_Troya13d74f2013-03-24 08:54:55 -0500358 Wipe_Available_in_GUI = true;
Dees_Troy8170a922012-09-18 15:40:25 -0400359#else
Dees_Troy70737fa2013-04-08 13:19:20 +0000360 if (Mount_Point == "/sdcard" || Mount_Point == "/external_sd" || Mount_Point == "/external_sdcard") {
Dees_Troy8170a922012-09-18 15:40:25 -0400361 Is_Storage = true;
Dees_Troyc51f1f92012-09-20 15:32:13 -0400362 Removable = true;
Dees_Troya13d74f2013-03-24 08:54:55 -0500363 Wipe_Available_in_GUI = true;
Dees_Troye58d5262012-09-21 12:27:57 -0400364#ifndef RECOVERY_SDCARD_ON_DATA
365 Setup_AndSec();
Dees_Troy8e337f32012-10-13 22:07:49 -0400366 Mount_Storage_Retry();
Dees_Troye58d5262012-09-21 12:27:57 -0400367#endif
Dees_Troy8170a922012-09-18 15:40:25 -0400368#endif
Dees_Troyb05ddee2013-01-28 20:24:50 +0000369 }
Dees_Troy8170a922012-09-18 15:40:25 -0400370#ifdef TW_INTERNAL_STORAGE_PATH
371 if (Mount_Point == EXPAND(TW_INTERNAL_STORAGE_PATH)) {
372 Is_Storage = true;
Dees_Troya13d74f2013-03-24 08:54:55 -0500373 Is_Settings_Storage = true;
Dees_Troy8170a922012-09-18 15:40:25 -0400374 Storage_Path = EXPAND(TW_INTERNAL_STORAGE_PATH);
Dees_Troya13d74f2013-03-24 08:54:55 -0500375 Wipe_Available_in_GUI = true;
Dees_Troye58d5262012-09-21 12:27:57 -0400376#ifndef RECOVERY_SDCARD_ON_DATA
377 Setup_AndSec();
Dees_Troy8e337f32012-10-13 22:07:49 -0400378 Mount_Storage_Retry();
Dees_Troye58d5262012-09-21 12:27:57 -0400379#endif
Dees_Troy8170a922012-09-18 15:40:25 -0400380 }
381#else
Dees_Troy70737fa2013-04-08 13:19:20 +0000382 if (Mount_Point == "/emmc" || Mount_Point == "/internal_sd" || Mount_Point == "/internal_sdcard") {
Dees_Troy8170a922012-09-18 15:40:25 -0400383 Is_Storage = true;
Dees_Troya13d74f2013-03-24 08:54:55 -0500384 Is_Settings_Storage = true;
Dees_Troya13d74f2013-03-24 08:54:55 -0500385 Wipe_Available_in_GUI = true;
Dees_Troye58d5262012-09-21 12:27:57 -0400386#ifndef RECOVERY_SDCARD_ON_DATA
387 Setup_AndSec();
Dees_Troy8e337f32012-10-13 22:07:49 -0400388 Mount_Storage_Retry();
Dees_Troye58d5262012-09-21 12:27:57 -0400389#endif
Dees_Troy8170a922012-09-18 15:40:25 -0400390 }
391#endif
Dees_Troy5bf43922012-09-07 16:07:55 -0400392 } else if (Is_Image(Fstab_File_System)) {
Dees_Troy38bd7602012-09-14 13:33:53 -0400393 Find_Actual_Block_Device();
Dees_Troy5bf43922012-09-07 16:07:55 -0400394 Setup_Image(Display_Error);
Dees_Troya13d74f2013-03-24 08:54:55 -0500395 if (Mount_Point == "/boot") {
396 Display_Name = "Boot";
397 Backup_Display_Name = Display_Name;
398 Can_Be_Backed_Up = true;
399 } else if (Mount_Point == "/recovery") {
400 Display_Name = "Recovery";
401 Backup_Display_Name = Display_Name;
Dees_Troya13d74f2013-03-24 08:54:55 -0500402 }
Dees_Troy5bf43922012-09-07 16:07:55 -0400403 }
404
Dees_Troy51127312012-09-08 13:08:49 -0400405 // Process any custom flags
406 if (Flags.size() > 0)
407 Process_Flags(Flags, Display_Error);
Dees_Troy51127312012-09-08 13:08:49 -0400408 return true;
409}
410
Hashcode62bd9e02013-11-19 21:59:42 -0800411bool TWPartition::Process_FS_Flags(string& Options, int Flags) {
412 int i;
413 char *p;
414 char *savep;
415 char fs_options[250];
416
417 strlcpy(fs_options, Options.c_str(), sizeof(fs_options));
418 Options = "";
419
420 p = strtok_r(fs_options, ",", &savep);
421 while (p) {
422 /* Look for the flag "p" in the flag list "fl"
423 * If not found, the loop exits with fl[i].name being null.
424 */
425 for (i = 0; mount_flags[i].name; i++) {
426 if (strncmp(p, mount_flags[i].name, strlen(mount_flags[i].name)) == 0) {
427 Flags |= mount_flags[i].flag;
428 break;
429 }
430 }
431
432 if (!mount_flags[i].name) {
433 if (Options.size() > 0)
434 Options += ",";
435 Options += p;
436 }
437 p = strtok_r(NULL, ",", &savep);
438 }
439
440 return true;
441}
442
Dees_Troy51127312012-09-08 13:08:49 -0400443bool TWPartition::Process_Flags(string Flags, bool Display_Error) {
444 char flags[MAX_FSTAB_LINE_LENGTH];
Dees_Troya13d74f2013-03-24 08:54:55 -0500445 int flags_len, index = 0, ptr_len;
Dees_Troy51127312012-09-08 13:08:49 -0400446 char* ptr;
Dees_Troya13d74f2013-03-24 08:54:55 -0500447 bool skip = false, has_display_name = false, has_storage_name = false, has_backup_name = false;
Dees_Troy51127312012-09-08 13:08:49 -0400448
449 strcpy(flags, Flags.c_str());
450 flags_len = Flags.size();
451 for (index = 0; index < flags_len; index++) {
Dees_Troya13d74f2013-03-24 08:54:55 -0500452 if (flags[index] == 34)
453 skip = !skip;
454 if (!skip && flags[index] == ';')
Dees_Troy51127312012-09-08 13:08:49 -0400455 flags[index] = '\0';
456 }
457
458 index = 0;
459 while (index < flags_len) {
460 while (index < flags_len && flags[index] == '\0')
461 index++;
462 if (index >= flags_len)
463 continue;
464 ptr = flags + index;
Dees_Troya13d74f2013-03-24 08:54:55 -0500465 ptr_len = strlen(ptr);
Dees_Troy51127312012-09-08 13:08:49 -0400466 if (strcmp(ptr, "removable") == 0) {
467 Removable = true;
Ethan Yonker06c3f932014-02-02 22:11:14 -0600468 } else if (strncmp(ptr, "storage", 7) == 0) {
469 if (ptr_len == 7) {
470 LOGINFO("ptr_len is 7, storage set to true\n");
471 Is_Storage = true;
472 } else if (ptr_len == 9) {
473 ptr += 9;
474 if (*ptr == '1' || *ptr == 'y' || *ptr == 'Y') {
475 LOGINFO("storage set to true\n");
476 Is_Storage = true;
477 } else {
478 LOGINFO("storage set to false\n");
479 Is_Storage = false;
480 }
481 }
Dees_Troya13d74f2013-03-24 08:54:55 -0500482 } else if (strcmp(ptr, "settingsstorage") == 0) {
483 Is_Storage = true;
Dees_Troy63c8df72012-09-10 14:02:05 -0400484 } else if (strcmp(ptr, "canbewiped") == 0) {
485 Can_Be_Wiped = true;
Hashcodedabfd492013-08-29 22:45:30 -0700486 } else if (strcmp(ptr, "usermrf") == 0) {
487 Use_Rm_Rf = true;
Dees_Troya13d74f2013-03-24 08:54:55 -0500488 } else if (ptr_len > 7 && strncmp(ptr, "backup=", 7) == 0) {
489 ptr += 7;
490 if (*ptr == '1' || *ptr == 'y' || *ptr == 'Y')
491 Can_Be_Backed_Up = true;
492 else
493 Can_Be_Backed_Up = false;
Dees_Troy63c8df72012-09-10 14:02:05 -0400494 } else if (strcmp(ptr, "wipeingui") == 0) {
495 Can_Be_Wiped = true;
496 Wipe_Available_in_GUI = true;
497 } else if (strcmp(ptr, "wipeduringfactoryreset") == 0) {
498 Can_Be_Wiped = true;
499 Wipe_Available_in_GUI = true;
500 Wipe_During_Factory_Reset = true;
Dees_Troya13d74f2013-03-24 08:54:55 -0500501 } else if (ptr_len > 15 && strncmp(ptr, "subpartitionof=", 15) == 0) {
Dees_Troy2c4c26f2013-01-28 15:26:43 +0000502 ptr += 15;
Dees_Troy51127312012-09-08 13:08:49 -0400503 Is_SubPartition = true;
504 SubPartition_Of = ptr;
Dees_Troy68cab492012-12-12 19:29:35 +0000505 } else if (strcmp(ptr, "ignoreblkid") == 0) {
506 Ignore_Blkid = true;
Dees_Troy16c2b312013-01-15 16:51:18 +0000507 } else if (strcmp(ptr, "retainlayoutversion") == 0) {
508 Retain_Layout_Version = true;
Dees_Troya13d74f2013-03-24 08:54:55 -0500509 } else if (ptr_len > 8 && strncmp(ptr, "symlink=", 8) == 0) {
Dees_Troy51127312012-09-08 13:08:49 -0400510 ptr += 8;
511 Symlink_Path = ptr;
Dees_Troya13d74f2013-03-24 08:54:55 -0500512 } else if (ptr_len > 8 && strncmp(ptr, "display=", 8) == 0) {
513 has_display_name = true;
Dees_Troy51127312012-09-08 13:08:49 -0400514 ptr += 8;
Dees_Troya13d74f2013-03-24 08:54:55 -0500515 if (*ptr == '\"') ptr++;
Dees_Troy51127312012-09-08 13:08:49 -0400516 Display_Name = ptr;
Dees_Troya13d74f2013-03-24 08:54:55 -0500517 if (Display_Name.substr(Display_Name.size() - 1, 1) == "\"") {
518 Display_Name.resize(Display_Name.size() - 1);
519 }
520 } else if (ptr_len > 11 && strncmp(ptr, "storagename=", 11) == 0) {
521 has_storage_name = true;
522 ptr += 11;
523 if (*ptr == '\"') ptr++;
524 Storage_Name = ptr;
525 if (Storage_Name.substr(Storage_Name.size() - 1, 1) == "\"") {
526 Storage_Name.resize(Storage_Name.size() - 1);
527 }
528 } else if (ptr_len > 11 && strncmp(ptr, "backupname=", 10) == 0) {
529 has_backup_name = true;
530 ptr += 10;
531 if (*ptr == '\"') ptr++;
532 Backup_Display_Name = ptr;
533 if (Backup_Display_Name.substr(Backup_Display_Name.size() - 1, 1) == "\"") {
534 Backup_Display_Name.resize(Backup_Display_Name.size() - 1);
535 }
536 } else if (ptr_len > 10 && strncmp(ptr, "blocksize=", 10) == 0) {
Dees_Troy51127312012-09-08 13:08:49 -0400537 ptr += 10;
538 Format_Block_Size = atoi(ptr);
Dees_Troya13d74f2013-03-24 08:54:55 -0500539 } else if (ptr_len > 7 && strncmp(ptr, "length=", 7) == 0) {
Dees_Troy51127312012-09-08 13:08:49 -0400540 ptr += 7;
541 Length = atoi(ptr);
Dees_Troy83bd4832013-05-04 12:39:56 +0000542 } else if (ptr_len > 17 && strncmp(ptr, "canencryptbackup=", 17) == 0) {
543 ptr += 17;
544 if (*ptr == '1' || *ptr == 'y' || *ptr == 'Y')
545 Can_Encrypt_Backup = true;
546 else
547 Can_Encrypt_Backup = false;
548 } else if (ptr_len > 21 && strncmp(ptr, "userdataencryptbackup=", 21) == 0) {
549 ptr += 21;
550 if (*ptr == '1' || *ptr == 'y' || *ptr == 'Y') {
551 Can_Encrypt_Backup = true;
552 Use_Userdata_Encryption = true;
553 } else {
554 Use_Userdata_Encryption = false;
555 }
Hashcode62bd9e02013-11-19 21:59:42 -0800556 } else if (ptr_len > 8 && strncmp(ptr, "fsflags=", 8) == 0) {
557 ptr += 8;
558 if (*ptr == '\"') ptr++;
559
560 Mount_Options = ptr;
561 if (Mount_Options.substr(Mount_Options.size() - 1, 1) == "\"") {
562 Mount_Options.resize(Mount_Options.size() - 1);
563 }
564 Process_FS_Flags(Mount_Options, Mount_Flags);
Dees_Troy51127312012-09-08 13:08:49 -0400565 } else {
566 if (Display_Error)
Dees_Troy2673cec2013-04-02 20:22:16 +0000567 LOGERR("Unhandled flag: '%s'\n", ptr);
Dees_Troy51127312012-09-08 13:08:49 -0400568 else
Dees_Troy2673cec2013-04-02 20:22:16 +0000569 LOGINFO("Unhandled flag: '%s'\n", ptr);
Dees_Troy51127312012-09-08 13:08:49 -0400570 }
571 while (index < flags_len && flags[index] != '\0')
572 index++;
573 }
Dees_Troya13d74f2013-03-24 08:54:55 -0500574 if (has_display_name && !has_storage_name)
575 Storage_Name = Display_Name;
576 if (!has_display_name && has_storage_name)
577 Display_Name = Storage_Name;
Dees_Troy74fb2e92013-04-15 14:35:47 +0000578 if (has_display_name && !has_backup_name && Backup_Display_Name != "Android Secure")
Dees_Troya13d74f2013-03-24 08:54:55 -0500579 Backup_Display_Name = Display_Name;
580 if (!has_display_name && has_backup_name)
581 Display_Name = Backup_Display_Name;
Dees_Troy51127312012-09-08 13:08:49 -0400582 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -0400583}
584
Dees_Troy5bf43922012-09-07 16:07:55 -0400585bool TWPartition::Is_File_System(string File_System) {
586 if (File_System == "ext2" ||
Dees_Troy63c8df72012-09-10 14:02:05 -0400587 File_System == "ext3" ||
Dees_Troy5bf43922012-09-07 16:07:55 -0400588 File_System == "ext4" ||
589 File_System == "vfat" ||
590 File_System == "ntfs" ||
591 File_System == "yaffs2" ||
bigbiff bigbiff3e146522012-11-14 14:32:59 -0500592 File_System == "exfat" ||
Dees_Troye5017042013-08-29 16:38:55 +0000593 File_System == "f2fs" ||
Dees_Troy5bf43922012-09-07 16:07:55 -0400594 File_System == "auto")
595 return true;
596 else
597 return false;
Dees_Troy51a0e822012-09-05 15:24:24 -0400598}
599
Dees_Troy5bf43922012-09-07 16:07:55 -0400600bool TWPartition::Is_Image(string File_System) {
Dees_Troy5fcd8f92012-10-16 12:22:05 -0400601 if (File_System == "emmc" || File_System == "mtd" || File_System == "bml")
Dees_Troy5bf43922012-09-07 16:07:55 -0400602 return true;
603 else
604 return false;
605}
606
Dees_Troy51127312012-09-08 13:08:49 -0400607bool TWPartition::Make_Dir(string Path, bool Display_Error) {
Dees_Troy43d8b002012-09-17 16:00:01 -0400608 if (!TWFunc::Path_Exists(Path)) {
Dees_Troy51127312012-09-08 13:08:49 -0400609 if (mkdir(Path.c_str(), 0777) == -1) {
610 if (Display_Error)
Dees_Troy2673cec2013-04-02 20:22:16 +0000611 LOGERR("Can not create '%s' folder.\n", Path.c_str());
Dees_Troy51127312012-09-08 13:08:49 -0400612 else
Dees_Troy2673cec2013-04-02 20:22:16 +0000613 LOGINFO("Can not create '%s' folder.\n", Path.c_str());
Dees_Troy51127312012-09-08 13:08:49 -0400614 return false;
615 } else {
Dees_Troy2673cec2013-04-02 20:22:16 +0000616 LOGINFO("Created '%s' folder.\n", Path.c_str());
Dees_Troy51127312012-09-08 13:08:49 -0400617 return true;
618 }
619 }
620 return true;
621}
622
Dees_Troy5bf43922012-09-07 16:07:55 -0400623void TWPartition::Setup_File_System(bool Display_Error) {
624 struct statfs st;
625
626 Can_Be_Mounted = true;
627 Can_Be_Wiped = true;
628
Dees_Troy5bf43922012-09-07 16:07:55 -0400629 // Make the mount point folder if it doesn't exist
Dees_Troy51127312012-09-08 13:08:49 -0400630 Make_Dir(Mount_Point, Display_Error);
Dees_Troy5bf43922012-09-07 16:07:55 -0400631 Display_Name = Mount_Point.substr(1, Mount_Point.size() - 1);
632 Backup_Name = Display_Name;
633 Backup_Method = FILES;
634}
635
636void TWPartition::Setup_Image(bool Display_Error) {
Dees_Troy5bf43922012-09-07 16:07:55 -0400637 Display_Name = Mount_Point.substr(1, Mount_Point.size() - 1);
638 Backup_Name = Display_Name;
Gary Peck82599a82012-11-21 16:23:12 -0800639 if (Current_File_System == "emmc")
Dees_Troy5bf43922012-09-07 16:07:55 -0400640 Backup_Method = DD;
Gary Peck82599a82012-11-21 16:23:12 -0800641 else if (Current_File_System == "mtd" || Current_File_System == "bml")
Dees_Troy5bf43922012-09-07 16:07:55 -0400642 Backup_Method = FLASH_UTILS;
643 else
Dees_Troy2673cec2013-04-02 20:22:16 +0000644 LOGINFO("Unhandled file system '%s' on image '%s'\n", Current_File_System.c_str(), Display_Name.c_str());
Dees_Troy5bf43922012-09-07 16:07:55 -0400645 if (Find_Partition_Size()) {
646 Used = Size;
647 Backup_Size = Size;
Dees_Troy51a0e822012-09-05 15:24:24 -0400648 } else {
Dees_Troy5bf43922012-09-07 16:07:55 -0400649 if (Display_Error)
Dees Troyd932ce12013-10-18 17:12:59 +0000650 LOGERR("Unable to find partition size for '%s'\n", Mount_Point.c_str());
Dees_Troy5bf43922012-09-07 16:07:55 -0400651 else
Dees Troyd932ce12013-10-18 17:12:59 +0000652 LOGINFO("Unable to find partition size for '%s'\n", Mount_Point.c_str());
Dees_Troy51a0e822012-09-05 15:24:24 -0400653 }
654}
655
Dees_Troye58d5262012-09-21 12:27:57 -0400656void TWPartition::Setup_AndSec(void) {
Dees_Troya13d74f2013-03-24 08:54:55 -0500657 Backup_Display_Name = "Android Secure";
Dees_Troye58d5262012-09-21 12:27:57 -0400658 Backup_Name = "and-sec";
Dees_Troya13d74f2013-03-24 08:54:55 -0500659 Can_Be_Backed_Up = true;
Dees_Troye58d5262012-09-21 12:27:57 -0400660 Has_Android_Secure = true;
661 Symlink_Path = Mount_Point + "/.android_secure";
662 Symlink_Mount_Point = "/and-sec";
663 Backup_Path = Symlink_Mount_Point;
664 Make_Dir("/and-sec", true);
665 Recreate_AndSec_Folder();
666}
667
Dees_Troy5bf43922012-09-07 16:07:55 -0400668void TWPartition::Find_Real_Block_Device(string& Block, bool Display_Error) {
669 char device[512], realDevice[512];
670
671 strcpy(device, Block.c_str());
672 memset(realDevice, 0, sizeof(realDevice));
673 while (readlink(device, realDevice, sizeof(realDevice)) > 0)
674 {
675 strcpy(device, realDevice);
676 memset(realDevice, 0, sizeof(realDevice));
677 }
678
679 if (device[0] != '/') {
680 if (Display_Error)
Dees_Troy2673cec2013-04-02 20:22:16 +0000681 LOGERR("Invalid symlink path '%s' found on block device '%s'\n", device, Block.c_str());
Dees_Troy5bf43922012-09-07 16:07:55 -0400682 else
Dees_Troy2673cec2013-04-02 20:22:16 +0000683 LOGINFO("Invalid symlink path '%s' found on block device '%s'\n", device, Block.c_str());
Dees_Troy5bf43922012-09-07 16:07:55 -0400684 return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400685 } else {
Dees_Troy5bf43922012-09-07 16:07:55 -0400686 Block = device;
687 return;
688 }
689}
690
Dees_Troy8e337f32012-10-13 22:07:49 -0400691void TWPartition::Mount_Storage_Retry(void) {
692 // On some devices, storage doesn't want to mount right away, retry and sleep
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500693 if (!Mount(true)) {
Dees_Troy8e337f32012-10-13 22:07:49 -0400694 int retry_count = 5;
695 while (retry_count > 0 && !Mount(false)) {
696 usleep(500000);
697 retry_count--;
698 }
699 Mount(true);
700 }
701}
702
Dees_Troy38bd7602012-09-14 13:33:53 -0400703bool TWPartition::Find_MTD_Block_Device(string MTD_Name) {
704 FILE *fp = NULL;
705 char line[255];
706
707 fp = fopen("/proc/mtd", "rt");
708 if (fp == NULL) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000709 LOGERR("Device does not support /proc/mtd\n");
Dees_Troy38bd7602012-09-14 13:33:53 -0400710 return false;
711 }
712
713 while (fgets(line, sizeof(line), fp) != NULL)
714 {
715 char device[32], label[32];
716 unsigned long size = 0;
717 char* fstype = NULL;
718 int deviceId;
719
720 sscanf(line, "%s %lx %*s %*c%s", device, &size, label);
721
722 // Skip header and blank lines
723 if ((strcmp(device, "dev:") == 0) || (strlen(line) < 8))
724 continue;
725
726 // Strip off the trailing " from the label
727 label[strlen(label)-1] = '\0';
728
729 if (strcmp(label, MTD_Name.c_str()) == 0) {
730 // We found our device
731 // Strip off the trailing : from the device
732 device[strlen(device)-1] = '\0';
733 if (sscanf(device,"mtd%d", &deviceId) == 1) {
734 sprintf(device, "/dev/block/mtdblock%d", deviceId);
735 Primary_Block_Device = device;
Dees_Troy76543db2013-06-19 16:24:30 +0000736 fclose(fp);
737 return true;
Dees_Troy38bd7602012-09-14 13:33:53 -0400738 }
739 }
740 }
741 fclose(fp);
742
743 return false;
744}
745
Dees_Troy51127312012-09-08 13:08:49 -0400746bool TWPartition::Get_Size_Via_statfs(bool Display_Error) {
747 struct statfs st;
748 string Local_Path = Mount_Point + "/.";
749
750 if (!Mount(Display_Error))
751 return false;
752
753 if (statfs(Local_Path.c_str(), &st) != 0) {
754 if (!Removable) {
755 if (Display_Error)
Dees_Troy2673cec2013-04-02 20:22:16 +0000756 LOGERR("Unable to statfs '%s'\n", Local_Path.c_str());
Dees_Troy51127312012-09-08 13:08:49 -0400757 else
Dees_Troy2673cec2013-04-02 20:22:16 +0000758 LOGINFO("Unable to statfs '%s'\n", Local_Path.c_str());
Dees_Troy51127312012-09-08 13:08:49 -0400759 }
760 return false;
761 }
762 Size = (st.f_blocks * st.f_bsize);
763 Used = ((st.f_blocks - st.f_bfree) * st.f_bsize);
764 Free = (st.f_bfree * st.f_bsize);
765 Backup_Size = Used;
766 return true;
767}
768
769bool TWPartition::Get_Size_Via_df(bool Display_Error) {
Dees_Troy5bf43922012-09-07 16:07:55 -0400770 FILE* fp;
771 char command[255], line[512];
772 int include_block = 1;
773 unsigned int min_len;
774
775 if (!Mount(Display_Error))
776 return false;
777
Dees_Troy38bd7602012-09-14 13:33:53 -0400778 min_len = Actual_Block_Device.size() + 2;
Dees_Troy51127312012-09-08 13:08:49 -0400779 sprintf(command, "df %s > /tmp/dfoutput.txt", Mount_Point.c_str());
Vojtech Bocek05534202013-09-11 08:11:56 +0200780 TWFunc::Exec_Cmd(command);
Dees_Troy51127312012-09-08 13:08:49 -0400781 fp = fopen("/tmp/dfoutput.txt", "rt");
782 if (fp == NULL) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000783 LOGINFO("Unable to open /tmp/dfoutput.txt.\n");
Dees_Troy5bf43922012-09-07 16:07:55 -0400784 return false;
Dees_Troy51127312012-09-08 13:08:49 -0400785 }
Dees_Troy5bf43922012-09-07 16:07:55 -0400786
787 while (fgets(line, sizeof(line), fp) != NULL)
788 {
789 unsigned long blocks, used, available;
790 char device[64];
791 char tmpString[64];
792
793 if (strncmp(line, "Filesystem", 10) == 0)
794 continue;
795 if (strlen(line) < min_len) {
796 include_block = 0;
797 continue;
798 }
799 if (include_block) {
800 sscanf(line, "%s %lu %lu %lu", device, &blocks, &used, &available);
801 } else {
802 // The device block string is so long that the df information is on the next line
803 int space_count = 0;
Dees_Troye58d5262012-09-21 12:27:57 -0400804 sprintf(tmpString, "/dev/block/%s", Actual_Block_Device.c_str());
Dees_Troy5bf43922012-09-07 16:07:55 -0400805 while (tmpString[space_count] == 32)
806 space_count++;
807 sscanf(line + space_count, "%lu %lu %lu", &blocks, &used, &available);
808 }
809
810 // Adjust block size to byte size
811 Size = blocks * 1024ULL;
812 Used = used * 1024ULL;
813 Free = available * 1024ULL;
814 Backup_Size = Used;
815 }
816 fclose(fp);
817 return true;
818}
819
Dees_Troy5bf43922012-09-07 16:07:55 -0400820bool TWPartition::Find_Partition_Size(void) {
821 FILE* fp;
822 char line[512];
823 string tmpdevice;
824
igoriok87e3d932013-01-31 21:03:53 +0200825 fp = fopen("/proc/dumchar_info", "rt");
826 if (fp != NULL) {
827 while (fgets(line, sizeof(line), fp) != NULL)
828 {
829 char label[32], device[32];
830 unsigned long size = 0;
831
832 sscanf(line, "%s %lx %*lx %*lu %s", label, &size, device);
833
bigbiff bigbiff34684ff2013-12-01 21:03:45 -0500834 // Skip header, annotation and blank lines
igoriok87e3d932013-01-31 21:03:53 +0200835 if ((strncmp(device, "/dev/", 5) != 0) || (strlen(line) < 8))
836 continue;
837
838 tmpdevice = "/dev/";
839 tmpdevice += label;
840 if (tmpdevice == Primary_Block_Device || tmpdevice == Alternate_Block_Device) {
841 Size = size;
842 fclose(fp);
843 return true;
844 }
845 }
846 }
847
Dees_Troy5bf43922012-09-07 16:07:55 -0400848 // In this case, we'll first get the partitions we care about (with labels)
849 fp = fopen("/proc/partitions", "rt");
850 if (fp == NULL)
851 return false;
852
853 while (fgets(line, sizeof(line), fp) != NULL)
854 {
855 unsigned long major, minor, blocks;
856 char device[512];
857 char tmpString[64];
858
Dees_Troy63c8df72012-09-10 14:02:05 -0400859 if (strlen(line) < 7 || line[0] == 'm') continue;
Dees_Troy5bf43922012-09-07 16:07:55 -0400860 sscanf(line + 1, "%lu %lu %lu %s", &major, &minor, &blocks, device);
861
862 tmpdevice = "/dev/block/";
863 tmpdevice += device;
Dees_Troy38bd7602012-09-14 13:33:53 -0400864 if (tmpdevice == Primary_Block_Device || tmpdevice == Alternate_Block_Device) {
Dees_Troy5bf43922012-09-07 16:07:55 -0400865 // Adjust block size to byte size
866 Size = blocks * 1024ULL;
867 fclose(fp);
868 return true;
869 }
870 }
871 fclose(fp);
872 return false;
873}
874
Dees_Troy5bf43922012-09-07 16:07:55 -0400875bool TWPartition::Is_Mounted(void) {
876 if (!Can_Be_Mounted)
877 return false;
878
879 struct stat st1, st2;
880 string test_path;
881
882 // Check to see if the mount point directory exists
883 test_path = Mount_Point + "/.";
884 if (stat(test_path.c_str(), &st1) != 0) return false;
885
886 // Check to see if the directory above the mount point exists
887 test_path = Mount_Point + "/../.";
888 if (stat(test_path.c_str(), &st2) != 0) return false;
889
890 // Compare the device IDs -- if they match then we're (probably) using tmpfs instead of an actual device
891 int ret = (st1.st_dev != st2.st_dev) ? true : false;
892
893 return ret;
894}
895
896bool TWPartition::Mount(bool Display_Error) {
Dees_Troy3f5c4e82013-02-01 15:16:59 +0000897 int exfat_mounted = 0;
898
Dees_Troy5bf43922012-09-07 16:07:55 -0400899 if (Is_Mounted()) {
900 return true;
901 } else if (!Can_Be_Mounted) {
902 return false;
903 }
Dees_Troy38bd7602012-09-14 13:33:53 -0400904
905 Find_Actual_Block_Device();
906
907 // Check the current file system before mounting
908 Check_FS_Type();
Dees_Troy3f5c4e82013-02-01 15:16:59 +0000909 if (Current_File_System == "exfat" && TWFunc::Path_Exists("/sbin/exfat-fuse")) {
Dees_Troye34c1332013-02-06 19:13:00 +0000910 string cmd = "/sbin/exfat-fuse -o big_writes,max_read=131072,max_write=131072 " + Actual_Block_Device + " " + Mount_Point;
Dees_Troy2673cec2013-04-02 20:22:16 +0000911 LOGINFO("cmd: %s\n", cmd.c_str());
Dees_Troy3f5c4e82013-02-01 15:16:59 +0000912 string result;
913 if (TWFunc::Exec_Cmd(cmd, result) != 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000914 LOGINFO("exfat-fuse failed to mount with result '%s', trying vfat\n", result.c_str());
Dees_Troy3f5c4e82013-02-01 15:16:59 +0000915 Current_File_System = "vfat";
916 } else {
917#ifdef TW_NO_EXFAT_FUSE
918 UnMount(false);
919 // We'll let the kernel handle it but using exfat-fuse to detect if the file system is actually exfat
920 // Some kernels let us mount vfat as exfat which doesn't work out too well
921#else
922 exfat_mounted = 1;
923#endif
924 }
925 }
Dees_Troy22042032012-12-18 21:23:08 +0000926 if (Fstab_File_System == "yaffs2") {
927 // mount an MTD partition as a YAFFS2 filesystem.
Dees_Troy76543db2013-06-19 16:24:30 +0000928 const unsigned long flags = MS_NOATIME | MS_NODEV | MS_NODIRATIME;
929 if (mount(Actual_Block_Device.c_str(), Mount_Point.c_str(), Fstab_File_System.c_str(), flags, NULL) < 0) {
930 if (mount(Actual_Block_Device.c_str(), Mount_Point.c_str(), Fstab_File_System.c_str(), flags | MS_RDONLY, NULL) < 0) {
931 if (Display_Error)
932 LOGERR("Failed to mount '%s' (MTD)\n", Mount_Point.c_str());
933 else
934 LOGINFO("Failed to mount '%s' (MTD)\n", Mount_Point.c_str());
935 return false;
936 } else {
937 LOGINFO("Mounted '%s' (MTD) as RO\n", Mount_Point.c_str());
938 return true;
939 }
940 } else {
941 struct stat st;
942 string test_path = Mount_Point;
943 if (stat(test_path.c_str(), &st) < 0) {
944 if (Display_Error)
945 LOGERR("Failed to mount '%s' (MTD)\n", Mount_Point.c_str());
946 else
947 LOGINFO("Failed to mount '%s' (MTD)\n", Mount_Point.c_str());
948 return false;
949 }
950 mode_t new_mode = st.st_mode | S_IXUSR | S_IXGRP | S_IXOTH;
951 if (new_mode != st.st_mode) {
952 LOGINFO("Fixing execute permissions for %s\n", Mount_Point.c_str());
953 if (chmod(Mount_Point.c_str(), new_mode) < 0) {
954 if (Display_Error)
955 LOGERR("Couldn't fix permissions for %s: %s\n", Mount_Point.c_str(), strerror(errno));
956 else
957 LOGINFO("Couldn't fix permissions for %s: %s\n", Mount_Point.c_str(), strerror(errno));
958 return false;
959 }
960 }
Dees_Troy22042032012-12-18 21:23:08 +0000961 return true;
Dees_Troy76543db2013-06-19 16:24:30 +0000962 }
Hashcode62bd9e02013-11-19 21:59:42 -0800963 } 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) {
Dees_Troy3f5c4e82013-02-01 15:16:59 +0000964#ifdef TW_NO_EXFAT_FUSE
965 if (Current_File_System == "exfat") {
Dees_Troy2673cec2013-04-02 20:22:16 +0000966 LOGINFO("Mounting exfat failed, trying vfat...\n");
Dees_Troy3f5c4e82013-02-01 15:16:59 +0000967 if (mount(Actual_Block_Device.c_str(), Mount_Point.c_str(), "vfat", 0, NULL) != 0) {
Dees_Troy85f44ed2013-01-09 18:42:36 +0000968 if (Display_Error)
Dees_Troy2673cec2013-04-02 20:22:16 +0000969 LOGERR("Unable to mount '%s'\n", Mount_Point.c_str());
Dees_Troy85f44ed2013-01-09 18:42:36 +0000970 else
Dees_Troy2673cec2013-04-02 20:22:16 +0000971 LOGINFO("Unable to mount '%s'\n", Mount_Point.c_str());
Hashcode62bd9e02013-11-19 21:59:42 -0800972 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_Troy3f5c4e82013-02-01 15:16:59 +0000973 return false;
Dees_Troy85f44ed2013-01-09 18:42:36 +0000974 }
Dees_Troyb05ddee2013-01-28 20:24:50 +0000975 } else {
Dees_Troy3f5c4e82013-02-01 15:16:59 +0000976#endif
977 if (Display_Error)
Dees_Troy2673cec2013-04-02 20:22:16 +0000978 LOGERR("Unable to mount '%s'\n", Mount_Point.c_str());
Dees_Troy3f5c4e82013-02-01 15:16:59 +0000979 else
Dees_Troy2673cec2013-04-02 20:22:16 +0000980 LOGINFO("Unable to mount '%s'\n", Mount_Point.c_str());
981 LOGINFO("Actual block device: '%s', current file system: '%s'\n", Actual_Block_Device.c_str(), Current_File_System.c_str());
Dees_Troy3f5c4e82013-02-01 15:16:59 +0000982 return false;
983#ifdef TW_NO_EXFAT_FUSE
Dees_Troy85f44ed2013-01-09 18:42:36 +0000984 }
985#endif
Dees_Troy3f5c4e82013-02-01 15:16:59 +0000986 }
987#ifdef TW_INCLUDE_CRYPTO_SAMSUNG
988 string MetaEcfsFile = EXPAND(TW_EXTERNAL_STORAGE_PATH);
989 MetaEcfsFile += "/.MetaEcfsFile";
990 if (EcryptFS_Password.size() > 0 && PartitionManager.Mount_By_Path("/data", false) && TWFunc::Path_Exists(MetaEcfsFile)) {
991 if (mount_ecryptfs_drive(EcryptFS_Password.c_str(), Mount_Point.c_str(), Mount_Point.c_str(), 0) != 0) {
992 if (Display_Error)
Dees_Troy2673cec2013-04-02 20:22:16 +0000993 LOGERR("Unable to mount ecryptfs for '%s'\n", Mount_Point.c_str());
Dees_Troy3f5c4e82013-02-01 15:16:59 +0000994 else
Dees_Troy2673cec2013-04-02 20:22:16 +0000995 LOGINFO("Unable to mount ecryptfs for '%s'\n", Mount_Point.c_str());
Dees_Troy3f5c4e82013-02-01 15:16:59 +0000996 } else {
Dees_Troy2673cec2013-04-02 20:22:16 +0000997 LOGINFO("Successfully mounted ecryptfs for '%s'\n", Mount_Point.c_str());
Dees_Troy3f5c4e82013-02-01 15:16:59 +0000998 Is_Decrypted = true;
Dees_Troy51127312012-09-08 13:08:49 -0400999 }
Dees_Troy066eb302013-08-23 17:20:32 +00001000 } else if (Mount_Point == EXPAND(TW_EXTERNAL_STORAGE_PATH)) {
1001 if (Is_Decrypted)
1002 LOGINFO("Mounting external storage, '%s' is not encrypted\n", Mount_Point.c_str());
Dees_Troy3f5c4e82013-02-01 15:16:59 +00001003 Is_Decrypted = false;
1004 }
1005#endif
1006 if (Removable)
1007 Update_Size(Display_Error);
1008
1009 if (!Symlink_Mount_Point.empty()) {
Vojtech Bocek05534202013-09-11 08:11:56 +02001010 string Command = "mount '" + Symlink_Path + "' '" + Symlink_Mount_Point + "'";
1011 TWFunc::Exec_Cmd(Command);
Dees_Troy5bf43922012-09-07 16:07:55 -04001012 }
Dees_Troy5bf43922012-09-07 16:07:55 -04001013 return true;
1014}
1015
1016bool TWPartition::UnMount(bool Display_Error) {
1017 if (Is_Mounted()) {
1018 int never_unmount_system;
1019
1020 DataManager::GetValue(TW_DONT_UNMOUNT_SYSTEM, never_unmount_system);
1021 if (never_unmount_system == 1 && Mount_Point == "/system")
1022 return true; // Never unmount system if you're not supposed to unmount it
1023
Dees_Troyc8bafa12013-01-10 15:43:00 +00001024#ifdef TW_INCLUDE_CRYPTO_SAMSUNG
1025 if (EcryptFS_Password.size() > 0) {
1026 if (unmount_ecryptfs_drive(Mount_Point.c_str()) != 0) {
1027 if (Display_Error)
Dees_Troy2673cec2013-04-02 20:22:16 +00001028 LOGERR("Unable to unmount ecryptfs for '%s'\n", Mount_Point.c_str());
Dees_Troyc8bafa12013-01-10 15:43:00 +00001029 else
Dees_Troy2673cec2013-04-02 20:22:16 +00001030 LOGINFO("Unable to unmount ecryptfs for '%s'\n", Mount_Point.c_str());
Dees_Troyc8bafa12013-01-10 15:43:00 +00001031 } else {
Dees_Troy2673cec2013-04-02 20:22:16 +00001032 LOGINFO("Successfully unmounted ecryptfs for '%s'\n", Mount_Point.c_str());
Dees_Troyc8bafa12013-01-10 15:43:00 +00001033 }
1034 }
1035#endif
1036
Dees_Troy38bd7602012-09-14 13:33:53 -04001037 if (!Symlink_Mount_Point.empty())
1038 umount(Symlink_Mount_Point.c_str());
1039
Dees_Troyb05ddee2013-01-28 20:24:50 +00001040 umount(Mount_Point.c_str());
1041 if (Is_Mounted()) {
Dees_Troy5bf43922012-09-07 16:07:55 -04001042 if (Display_Error)
Dees_Troy2673cec2013-04-02 20:22:16 +00001043 LOGERR("Unable to unmount '%s'\n", Mount_Point.c_str());
Dees_Troy5bf43922012-09-07 16:07:55 -04001044 else
Dees_Troy2673cec2013-04-02 20:22:16 +00001045 LOGINFO("Unable to unmount '%s'\n", Mount_Point.c_str());
Dees_Troy5bf43922012-09-07 16:07:55 -04001046 return false;
1047 } else
1048 return true;
1049 } else {
1050 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -04001051 }
1052}
1053
Gary Peck43acadf2012-11-21 21:19:01 -08001054bool TWPartition::Wipe(string New_File_System) {
Dees_Troy16c2b312013-01-15 16:51:18 +00001055 bool wiped = false, update_crypt = false;
1056 int check;
1057 string Layout_Filename = Mount_Point + "/.layout_version";
1058
Dees_Troy38bd7602012-09-14 13:33:53 -04001059 if (!Can_Be_Wiped) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001060 LOGERR("Partition '%s' cannot be wiped.\n", Mount_Point.c_str());
Dees_Troy38bd7602012-09-14 13:33:53 -04001061 return false;
1062 }
1063
Dees_Troyc51f1f92012-09-20 15:32:13 -04001064 if (Mount_Point == "/cache")
Dees_Troy2673cec2013-04-02 20:22:16 +00001065 Log_Offset = 0;
Dees_Troyc51f1f92012-09-20 15:32:13 -04001066
Dees_Troyce675462013-01-09 19:48:21 +00001067#ifdef TW_INCLUDE_CRYPTO_SAMSUNG
1068 if (Mount_Point == "/data" && Mount(false)) {
1069 if (TWFunc::Path_Exists("/data/system/edk_p_sd"))
1070 TWFunc::copy_file("/data/system/edk_p_sd", "/tmp/edk_p_sd", 0600);
1071 }
1072#endif
1073
Dees_Troy16c2b312013-01-15 16:51:18 +00001074 if (Retain_Layout_Version && Mount(false) && TWFunc::Path_Exists(Layout_Filename))
1075 TWFunc::copy_file(Layout_Filename, "/.layout_version", 0600);
1076 else
1077 unlink("/.layout_version");
Dees_Troy38bd7602012-09-14 13:33:53 -04001078
Dees_Troy16c2b312013-01-15 16:51:18 +00001079 if (Has_Data_Media) {
1080 wiped = Wipe_Data_Without_Wiping_Media();
1081 } else {
Gary Pecke8bc5d72012-12-21 06:45:25 -08001082
Dees_Troy16c2b312013-01-15 16:51:18 +00001083 DataManager::GetValue(TW_RM_RF_VAR, check);
1084
Hashcodedabfd492013-08-29 22:45:30 -07001085 if (check || Use_Rm_Rf)
Dees_Troy16c2b312013-01-15 16:51:18 +00001086 wiped = Wipe_RMRF();
1087 else if (New_File_System == "ext4")
1088 wiped = Wipe_EXT4();
1089 else if (New_File_System == "ext2" || New_File_System == "ext3")
1090 wiped = Wipe_EXT23(New_File_System);
1091 else if (New_File_System == "vfat")
1092 wiped = Wipe_FAT();
1093 else if (New_File_System == "exfat")
1094 wiped = Wipe_EXFAT();
1095 else if (New_File_System == "yaffs2")
1096 wiped = Wipe_MTD();
Dees_Troye5017042013-08-29 16:38:55 +00001097 else if (New_File_System == "f2fs")
1098 wiped = Wipe_F2FS();
Dees_Troy16c2b312013-01-15 16:51:18 +00001099 else {
Dees_Troy2673cec2013-04-02 20:22:16 +00001100 LOGERR("Unable to wipe '%s' -- unknown file system '%s'\n", Mount_Point.c_str(), New_File_System.c_str());
Dees_Troy16c2b312013-01-15 16:51:18 +00001101 unlink("/.layout_version");
1102 return false;
1103 }
1104 update_crypt = wiped;
Gary Pecke8bc5d72012-12-21 06:45:25 -08001105 }
Dees_Troy38bd7602012-09-14 13:33:53 -04001106
Gary Pecke8bc5d72012-12-21 06:45:25 -08001107 if (wiped) {
Dees_Troyce675462013-01-09 19:48:21 +00001108#ifdef TW_INCLUDE_CRYPTO_SAMSUNG
1109 if (Mount_Point == "/data" && Mount(false)) {
1110 if (TWFunc::Path_Exists("/tmp/edk_p_sd")) {
1111 Make_Dir("/data/system", true);
1112 TWFunc::copy_file("/tmp/edk_p_sd", "/data/system/edk_p_sd", 0600);
1113 }
1114 }
1115#endif
Dees_Troy16c2b312013-01-15 16:51:18 +00001116
Dees_Troy1c1ac442013-01-17 21:42:14 +00001117 if (Mount_Point == "/cache")
1118 DataManager::Output_Version();
1119
Dees_Troy16c2b312013-01-15 16:51:18 +00001120 if (TWFunc::Path_Exists("/.layout_version") && Mount(false))
1121 TWFunc::copy_file("/.layout_version", Layout_Filename, 0600);
1122
1123 if (update_crypt) {
1124 Setup_File_System(false);
1125 if (Is_Encrypted && !Is_Decrypted) {
1126 // just wiped an encrypted partition back to its unencrypted state
1127 Is_Encrypted = false;
1128 Is_Decrypted = false;
1129 Decrypted_Block_Device = "";
1130 if (Mount_Point == "/data") {
1131 DataManager::SetValue(TW_IS_ENCRYPTED, 0);
1132 DataManager::SetValue(TW_IS_DECRYPTED, 0);
1133 }
Gary Pecke8bc5d72012-12-21 06:45:25 -08001134 }
1135 }
1136 }
1137 return wiped;
Dees_Troy51a0e822012-09-05 15:24:24 -04001138}
1139
Gary Peck43acadf2012-11-21 21:19:01 -08001140bool TWPartition::Wipe() {
Gary Peck82599a82012-11-21 16:23:12 -08001141 if (Is_File_System(Current_File_System))
1142 return Wipe(Current_File_System);
1143 else
1144 return Wipe(Fstab_File_System);
Gary Peck43acadf2012-11-21 21:19:01 -08001145}
1146
Dees_Troye58d5262012-09-21 12:27:57 -04001147bool TWPartition::Wipe_AndSec(void) {
1148 if (!Has_Android_Secure)
1149 return false;
1150
Dees_Troye58d5262012-09-21 12:27:57 -04001151 if (!Mount(true))
1152 return false;
1153
Dees_Troy2673cec2013-04-02 20:22:16 +00001154 gui_print("Wiping %s\n", Backup_Display_Name.c_str());
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001155 TWFunc::removeDir(Mount_Point + "/.android_secure/", true);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001156 return true;
Dees_Troye58d5262012-09-21 12:27:57 -04001157}
1158
Dees_Troy51a0e822012-09-05 15:24:24 -04001159bool TWPartition::Backup(string backup_folder) {
Dees_Troy38bd7602012-09-14 13:33:53 -04001160 if (Backup_Method == FILES)
1161 return Backup_Tar(backup_folder);
1162 else if (Backup_Method == DD)
1163 return Backup_DD(backup_folder);
1164 else if (Backup_Method == FLASH_UTILS)
1165 return Backup_Dump_Image(backup_folder);
Dees_Troy2673cec2013-04-02 20:22:16 +00001166 LOGERR("Unknown backup method for '%s'\n", Mount_Point.c_str());
Dees_Troy38bd7602012-09-14 13:33:53 -04001167 return false;
Dees_Troy51a0e822012-09-05 15:24:24 -04001168}
1169
Dees_Troy43d8b002012-09-17 16:00:01 -04001170bool TWPartition::Check_MD5(string restore_folder) {
bigbiff bigbiff65a4c732013-03-15 15:17:50 -04001171 string Full_Filename, md5file;
Dees_Troy43d8b002012-09-17 16:00:01 -04001172 char split_filename[512];
1173 int index = 0;
bigbiff bigbiffcdcfee42013-02-27 21:11:26 -05001174 twrpDigest md5sum;
Dees_Troy43d8b002012-09-17 16:00:01 -04001175
bigbiff bigbiff65a4c732013-03-15 15:17:50 -04001176 memset(split_filename, 0, sizeof(split_filename));
Dees_Troy43d8b002012-09-17 16:00:01 -04001177 Full_Filename = restore_folder + "/" + Backup_FileName;
Dees_Troy43d8b002012-09-17 16:00:01 -04001178 if (!TWFunc::Path_Exists(Full_Filename)) {
1179 // This is a split archive, we presume
1180 sprintf(split_filename, "%s%03i", Full_Filename.c_str(), index);
Dees_Troy2673cec2013-04-02 20:22:16 +00001181 LOGINFO("split_filename: %s\n", split_filename);
bigbiff bigbiff65a4c732013-03-15 15:17:50 -04001182 md5file = split_filename;
1183 md5file += ".md5";
1184 if (!TWFunc::Path_Exists(md5file)) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001185 LOGERR("No md5 file found for '%s'.\n", split_filename);
1186 LOGERR("Please unselect Enable MD5 verification to restore.\n");
bigbiff bigbiff65a4c732013-03-15 15:17:50 -04001187 return false;
1188 }
1189 md5sum.setfn(split_filename);
Dees_Troy83bd4832013-05-04 12:39:56 +00001190 while (index < 1000) {
1191 if (TWFunc::Path_Exists(split_filename) && md5sum.verify_md5digest() != 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001192 LOGERR("MD5 failed to match on '%s'.\n", split_filename);
Dees_Troy43d8b002012-09-17 16:00:01 -04001193 return false;
1194 }
1195 index++;
1196 sprintf(split_filename, "%s%03i", Full_Filename.c_str(), index);
bigbiff bigbiff65a4c732013-03-15 15:17:50 -04001197 md5sum.setfn(split_filename);
Dees_Troy43d8b002012-09-17 16:00:01 -04001198 }
Dees_Troy4a2a1262012-09-18 09:33:47 -04001199 return true;
Dees_Troy43d8b002012-09-17 16:00:01 -04001200 } else {
1201 // Single file archive
bigbiff bigbiff65a4c732013-03-15 15:17:50 -04001202 md5file = Full_Filename + ".md5";
1203 if (!TWFunc::Path_Exists(md5file)) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001204 LOGERR("No md5 file found for '%s'.\n", Full_Filename.c_str());
1205 LOGERR("Please unselect Enable MD5 verification to restore.\n");
bigbiff bigbiff65a4c732013-03-15 15:17:50 -04001206 return false;
1207 }
bigbiff bigbiffcdcfee42013-02-27 21:11:26 -05001208 md5sum.setfn(Full_Filename);
1209 if (md5sum.verify_md5digest() != 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001210 LOGERR("MD5 failed to match on '%s'.\n", Full_Filename.c_str());
Dees_Troy43d8b002012-09-17 16:00:01 -04001211 return false;
1212 } else
1213 return true;
1214 }
1215 return false;
1216}
1217
Dees_Troy51a0e822012-09-05 15:24:24 -04001218bool TWPartition::Restore(string restore_folder) {
Gary Peck43acadf2012-11-21 21:19:01 -08001219 size_t first_period, second_period;
1220 string Restore_File_System;
1221
1222 TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Display_Name, "Restoring");
Dees_Troy2673cec2013-04-02 20:22:16 +00001223 LOGINFO("Restore filename is: %s\n", Backup_FileName.c_str());
Gary Peck43acadf2012-11-21 21:19:01 -08001224
1225 // Parse backup filename to extract the file system before wiping
1226 first_period = Backup_FileName.find(".");
1227 if (first_period == string::npos) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001228 LOGERR("Unable to find file system (first period).\n");
Gary Peck43acadf2012-11-21 21:19:01 -08001229 return false;
1230 }
1231 Restore_File_System = Backup_FileName.substr(first_period + 1, Backup_FileName.size() - first_period - 1);
1232 second_period = Restore_File_System.find(".");
1233 if (second_period == string::npos) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001234 LOGERR("Unable to find file system (second period).\n");
Gary Peck43acadf2012-11-21 21:19:01 -08001235 return false;
1236 }
1237 Restore_File_System.resize(second_period);
Dees_Troy2673cec2013-04-02 20:22:16 +00001238 LOGINFO("Restore file system is: '%s'.\n", Restore_File_System.c_str());
Gary Peck43acadf2012-11-21 21:19:01 -08001239
1240 if (Is_File_System(Restore_File_System))
1241 return Restore_Tar(restore_folder, Restore_File_System);
1242 else if (Is_Image(Restore_File_System)) {
1243 if (Restore_File_System == "emmc")
1244 return Restore_DD(restore_folder);
1245 else if (Restore_File_System == "mtd" || Restore_File_System == "bml")
1246 return Restore_Flash_Image(restore_folder);
1247 }
1248
Dees_Troy2673cec2013-04-02 20:22:16 +00001249 LOGERR("Unknown restore method for '%s'\n", Mount_Point.c_str());
Dees_Troy38bd7602012-09-14 13:33:53 -04001250 return false;
Dees_Troy51a0e822012-09-05 15:24:24 -04001251}
1252
1253string TWPartition::Backup_Method_By_Name() {
Dees_Troy38bd7602012-09-14 13:33:53 -04001254 if (Backup_Method == NONE)
1255 return "none";
1256 else if (Backup_Method == FILES)
1257 return "files";
1258 else if (Backup_Method == DD)
1259 return "dd";
1260 else if (Backup_Method == FLASH_UTILS)
1261 return "flash_utils";
1262 else
1263 return "undefined";
1264 return "ERROR!";
Dees_Troy51a0e822012-09-05 15:24:24 -04001265}
1266
1267bool TWPartition::Decrypt(string Password) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001268 LOGINFO("STUB TWPartition::Decrypt, password: '%s'\n", Password.c_str());
Dees_Troy38bd7602012-09-14 13:33:53 -04001269 // Is this needed?
Dees_Troy51a0e822012-09-05 15:24:24 -04001270 return 1;
1271}
1272
1273bool TWPartition::Wipe_Encryption() {
Dees_Troy38bd7602012-09-14 13:33:53 -04001274 bool Save_Data_Media = Has_Data_Media;
1275
1276 if (!UnMount(true))
1277 return false;
1278
Dees_Troy38bd7602012-09-14 13:33:53 -04001279 Has_Data_Media = false;
Dees_Troy74fb2e92013-04-15 14:35:47 +00001280 Decrypted_Block_Device = "";
1281 Is_Decrypted = false;
1282 Is_Encrypted = false;
Gary Pecke8bc5d72012-12-21 06:45:25 -08001283 if (Wipe(Fstab_File_System)) {
Dees_Troy38bd7602012-09-14 13:33:53 -04001284 Has_Data_Media = Save_Data_Media;
1285 if (Has_Data_Media && !Symlink_Mount_Point.empty()) {
1286 Recreate_Media_Folder();
1287 }
Dees_Troy2673cec2013-04-02 20:22:16 +00001288 gui_print("You may need to reboot recovery to be able to use /data again.\n");
Dees_Troy38bd7602012-09-14 13:33:53 -04001289 return true;
1290 } else {
1291 Has_Data_Media = Save_Data_Media;
Dees_Troy2673cec2013-04-02 20:22:16 +00001292 LOGERR("Unable to format to remove encryption.\n");
Dees_Troy38bd7602012-09-14 13:33:53 -04001293 return false;
1294 }
1295 return false;
Dees_Troy51a0e822012-09-05 15:24:24 -04001296}
1297
1298void TWPartition::Check_FS_Type() {
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001299 const char* type;
1300 blkid_probe pr;
Dees_Troy5bf43922012-09-07 16:07:55 -04001301
Dees_Troy68cab492012-12-12 19:29:35 +00001302 if (Fstab_File_System == "yaffs2" || Fstab_File_System == "mtd" || Fstab_File_System == "bml" || Ignore_Blkid)
1303 return; // Running blkid on some mtd devices causes a massive crash or needs to be skipped
Dees_Troy5bf43922012-09-07 16:07:55 -04001304
Dees_Troy38bd7602012-09-14 13:33:53 -04001305 Find_Actual_Block_Device();
Dees_Troy8170a922012-09-18 15:40:25 -04001306 if (!Is_Present)
1307 return;
Dees_Troy51127312012-09-08 13:08:49 -04001308
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001309 pr = blkid_new_probe_from_filename(Actual_Block_Device.c_str());
1310 if (blkid_do_fullprobe(pr)) {
1311 blkid_free_probe(pr);
Dees_Troy2673cec2013-04-02 20:22:16 +00001312 LOGINFO("Can't probe device %s\n", Actual_Block_Device.c_str());
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001313 return;
Dees_Troy5bf43922012-09-07 16:07:55 -04001314 }
Vojtech Bocek4d4b3362013-06-24 22:46:13 +02001315
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001316 if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL) < 0) {
1317 blkid_free_probe(pr);
Dees_Troy2673cec2013-04-02 20:22:16 +00001318 LOGINFO("can't find filesystem on device %s\n", Actual_Block_Device.c_str());
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001319 return;
1320 }
Vojtech Bocek4d4b3362013-06-24 22:46:13 +02001321
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001322 Current_File_System = type;
Vojtech Bocek4d4b3362013-06-24 22:46:13 +02001323 blkid_free_probe(pr);
Dees_Troy51a0e822012-09-05 15:24:24 -04001324}
1325
Gary Peck43acadf2012-11-21 21:19:01 -08001326bool TWPartition::Wipe_EXT23(string File_System) {
Dees_Troy38bd7602012-09-14 13:33:53 -04001327 if (!UnMount(true))
1328 return false;
1329
Dees_Troy43d8b002012-09-17 16:00:01 -04001330 if (TWFunc::Path_Exists("/sbin/mke2fs")) {
Vojtech Bocek05534202013-09-11 08:11:56 +02001331 string command;
Dees_Troy38bd7602012-09-14 13:33:53 -04001332
Dees_Troy2673cec2013-04-02 20:22:16 +00001333 gui_print("Formatting %s using mke2fs...\n", Display_Name.c_str());
Dees_Troy38bd7602012-09-14 13:33:53 -04001334 Find_Actual_Block_Device();
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001335 command = "mke2fs -t " + File_System + " -m 0 " + Actual_Block_Device;
Dees_Troy2673cec2013-04-02 20:22:16 +00001336 LOGINFO("mke2fs command: %s\n", command.c_str());
Vojtech Bocek05534202013-09-11 08:11:56 +02001337 if (TWFunc::Exec_Cmd(command) == 0) {
Gary Pecke8bc5d72012-12-21 06:45:25 -08001338 Current_File_System = File_System;
Dees_Troye58d5262012-09-21 12:27:57 -04001339 Recreate_AndSec_Folder();
Dees_Troy2673cec2013-04-02 20:22:16 +00001340 gui_print("Done.\n");
Dees_Troy38bd7602012-09-14 13:33:53 -04001341 return true;
1342 } else {
Dees_Troy2673cec2013-04-02 20:22:16 +00001343 LOGERR("Unable to wipe '%s'.\n", Mount_Point.c_str());
Dees_Troy38bd7602012-09-14 13:33:53 -04001344 return false;
1345 }
1346 } else
1347 return Wipe_RMRF();
1348
1349 return false;
Dees_Troy51a0e822012-09-05 15:24:24 -04001350}
1351
1352bool TWPartition::Wipe_EXT4() {
Dees_Troy38bd7602012-09-14 13:33:53 -04001353 if (!UnMount(true))
1354 return false;
1355
Dees_Troyb3265ab2013-08-30 02:59:14 +00001356#if defined(HAVE_SELINUX) && defined(USE_EXT4)
Dees_Troya95f55c2013-08-17 13:14:43 +00001357 gui_print("Formatting %s using make_ext4fs function.\n", Display_Name.c_str());
Dees_Troya95f55c2013-08-17 13:14:43 +00001358 if (make_ext4fs(Actual_Block_Device.c_str(), Length, Mount_Point.c_str(), selinux_handle) != 0) {
Dees_Troya95f55c2013-08-17 13:14:43 +00001359 LOGERR("Unable to wipe '%s' using function call.\n", Mount_Point.c_str());
1360 return false;
1361 } else {
bigbiff bigbiffc49d7062013-10-11 20:28:00 -04001362 #ifdef HAVE_SELINUX
1363 string sedir = Mount_Point + "/lost+found";
1364 PartitionManager.Mount_By_Path(sedir.c_str(), true);
1365 rmdir(sedir.c_str());
1366 mkdir(sedir.c_str(), S_IRWXU | S_IRWXG | S_IWGRP | S_IXGRP);
1367 #endif
Dees_Troya95f55c2013-08-17 13:14:43 +00001368 return true;
1369 }
1370#else
Dees_Troy43d8b002012-09-17 16:00:01 -04001371 if (TWFunc::Path_Exists("/sbin/make_ext4fs")) {
Vojtech Bocek05534202013-09-11 08:11:56 +02001372 string Command;
Dees_Troy38bd7602012-09-14 13:33:53 -04001373
Dees_Troy2673cec2013-04-02 20:22:16 +00001374 gui_print("Formatting %s using make_ext4fs...\n", Display_Name.c_str());
Dees_Troy38bd7602012-09-14 13:33:53 -04001375 Find_Actual_Block_Device();
1376 Command = "make_ext4fs";
1377 if (!Is_Decrypted && Length != 0) {
1378 // Only use length if we're not decrypted
1379 char len[32];
1380 sprintf(len, "%i", Length);
1381 Command += " -l ";
1382 Command += len;
1383 }
Dees_Troy5295d582013-09-06 15:51:08 +00001384 if (TWFunc::Path_Exists("/file_contexts")) {
1385 Command += " -S /file_contexts";
1386 }
1387 Command += " -a " + Mount_Point + " " + Actual_Block_Device;
Dees_Troy2673cec2013-04-02 20:22:16 +00001388 LOGINFO("make_ext4fs command: %s\n", Command.c_str());
Vojtech Bocek05534202013-09-11 08:11:56 +02001389 if (TWFunc::Exec_Cmd(Command) == 0) {
Gary Pecke8bc5d72012-12-21 06:45:25 -08001390 Current_File_System = "ext4";
Dees_Troye58d5262012-09-21 12:27:57 -04001391 Recreate_AndSec_Folder();
Dees_Troy2673cec2013-04-02 20:22:16 +00001392 gui_print("Done.\n");
Dees_Troy38bd7602012-09-14 13:33:53 -04001393 return true;
1394 } else {
Dees_Troy2673cec2013-04-02 20:22:16 +00001395 LOGERR("Unable to wipe '%s'.\n", Mount_Point.c_str());
Dees_Troy38bd7602012-09-14 13:33:53 -04001396 return false;
1397 }
1398 } else
Gary Peck43acadf2012-11-21 21:19:01 -08001399 return Wipe_EXT23("ext4");
Dees_Troya95f55c2013-08-17 13:14:43 +00001400#endif
Dees_Troy38bd7602012-09-14 13:33:53 -04001401 return false;
Dees_Troy51a0e822012-09-05 15:24:24 -04001402}
1403
1404bool TWPartition::Wipe_FAT() {
Vojtech Bocek05534202013-09-11 08:11:56 +02001405 string command;
Dees_Troy38bd7602012-09-14 13:33:53 -04001406
Dees_Troy43d8b002012-09-17 16:00:01 -04001407 if (TWFunc::Path_Exists("/sbin/mkdosfs")) {
Dees_Troy38bd7602012-09-14 13:33:53 -04001408 if (!UnMount(true))
1409 return false;
1410
Dees_Troy2673cec2013-04-02 20:22:16 +00001411 gui_print("Formatting %s using mkdosfs...\n", Display_Name.c_str());
Dees_Troy38bd7602012-09-14 13:33:53 -04001412 Find_Actual_Block_Device();
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001413 command = "mkdosfs " + Actual_Block_Device;
Vojtech Bocek05534202013-09-11 08:11:56 +02001414 if (TWFunc::Exec_Cmd(command) == 0) {
Gary Pecke8bc5d72012-12-21 06:45:25 -08001415 Current_File_System = "vfat";
Dees_Troye58d5262012-09-21 12:27:57 -04001416 Recreate_AndSec_Folder();
Dees_Troy2673cec2013-04-02 20:22:16 +00001417 gui_print("Done.\n");
Dees_Troy38bd7602012-09-14 13:33:53 -04001418 return true;
1419 } else {
Dees_Troy2673cec2013-04-02 20:22:16 +00001420 LOGERR("Unable to wipe '%s'.\n", Mount_Point.c_str());
Dees_Troy38bd7602012-09-14 13:33:53 -04001421 return false;
1422 }
1423 return true;
1424 }
1425 else
1426 return Wipe_RMRF();
1427
1428 return false;
Dees_Troy51a0e822012-09-05 15:24:24 -04001429}
1430
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001431bool TWPartition::Wipe_EXFAT() {
Vojtech Bocek05534202013-09-11 08:11:56 +02001432 string command;
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001433
1434 if (TWFunc::Path_Exists("/sbin/mkexfatfs")) {
1435 if (!UnMount(true))
1436 return false;
1437
Dees_Troy2673cec2013-04-02 20:22:16 +00001438 gui_print("Formatting %s using mkexfatfs...\n", Display_Name.c_str());
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001439 Find_Actual_Block_Device();
1440 command = "mkexfatfs " + Actual_Block_Device;
Vojtech Bocek05534202013-09-11 08:11:56 +02001441 if (TWFunc::Exec_Cmd(command) == 0) {
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001442 Recreate_AndSec_Folder();
Dees_Troy2673cec2013-04-02 20:22:16 +00001443 gui_print("Done.\n");
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001444 return true;
1445 } else {
Dees_Troy2673cec2013-04-02 20:22:16 +00001446 LOGERR("Unable to wipe '%s'.\n", Mount_Point.c_str());
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001447 return false;
1448 }
1449 return true;
1450 }
1451 return false;
1452}
1453
Dees_Troy38bd7602012-09-14 13:33:53 -04001454bool TWPartition::Wipe_MTD() {
1455 if (!UnMount(true))
1456 return false;
1457
Dees_Troy2673cec2013-04-02 20:22:16 +00001458 gui_print("MTD Formatting \"%s\"\n", MTD_Name.c_str());
Dees_Troy38bd7602012-09-14 13:33:53 -04001459
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001460 mtd_scan_partitions();
1461 const MtdPartition* mtd = mtd_find_partition_by_name(MTD_Name.c_str());
1462 if (mtd == NULL) {
1463 LOGERR("No mtd partition named '%s'", MTD_Name.c_str());
1464 return false;
1465 }
Dees_Troy38bd7602012-09-14 13:33:53 -04001466
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001467 MtdWriteContext* ctx = mtd_write_partition(mtd);
1468 if (ctx == NULL) {
1469 LOGERR("Can't write '%s', failed to format.", MTD_Name.c_str());
1470 return false;
1471 }
1472 if (mtd_erase_blocks(ctx, -1) == -1) {
1473 mtd_write_close(ctx);
1474 LOGERR("Failed to format '%s'", MTD_Name.c_str());
1475 return false;
1476 }
1477 if (mtd_write_close(ctx) != 0) {
1478 LOGERR("Failed to close '%s'", MTD_Name.c_str());
1479 return false;
1480 }
Gary Pecke8bc5d72012-12-21 06:45:25 -08001481 Current_File_System = "yaffs2";
Dees_Troye58d5262012-09-21 12:27:57 -04001482 Recreate_AndSec_Folder();
Dees_Troy2673cec2013-04-02 20:22:16 +00001483 gui_print("Done.\n");
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001484 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -04001485}
1486
1487bool TWPartition::Wipe_RMRF() {
Dees_Troy38bd7602012-09-14 13:33:53 -04001488 if (!Mount(true))
1489 return false;
1490
Dees_Troy2673cec2013-04-02 20:22:16 +00001491 gui_print("Removing all files under '%s'\n", Mount_Point.c_str());
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001492 TWFunc::removeDir(Mount_Point, true);
Dees_Troye58d5262012-09-21 12:27:57 -04001493 Recreate_AndSec_Folder();
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001494 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -04001495}
1496
Dees_Troye5017042013-08-29 16:38:55 +00001497bool TWPartition::Wipe_F2FS() {
Vojtech Bocek05534202013-09-11 08:11:56 +02001498 string command;
Dees_Troye5017042013-08-29 16:38:55 +00001499
1500 if (TWFunc::Path_Exists("/sbin/mkfs.f2fs")) {
1501 if (!UnMount(true))
1502 return false;
1503
1504 gui_print("Formatting %s using mkfs.f2fs...\n", Display_Name.c_str());
1505 Find_Actual_Block_Device();
1506 command = "mkfs.f2fs " + Actual_Block_Device;
Vojtech Bocek05534202013-09-11 08:11:56 +02001507 if (TWFunc::Exec_Cmd(command) == 0) {
Dees_Troye5017042013-08-29 16:38:55 +00001508 Recreate_AndSec_Folder();
1509 gui_print("Done.\n");
1510 return true;
1511 } else {
1512 LOGERR("Unable to wipe '%s'.\n", Mount_Point.c_str());
1513 return false;
1514 }
1515 return true;
1516 } else {
1517 gui_print("mkfs.f2fs binary not found, using rm -rf to wipe.\n");
1518 return Wipe_RMRF();
1519 }
1520 return false;
1521}
1522
Dees_Troy51a0e822012-09-05 15:24:24 -04001523bool TWPartition::Wipe_Data_Without_Wiping_Media() {
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001524 string dir;
Dees_Troy38bd7602012-09-14 13:33:53 -04001525
1526 // This handles wiping data on devices with "sdcard" in /data/media
1527 if (!Mount(true))
1528 return false;
1529
Dees_Troy2673cec2013-04-02 20:22:16 +00001530 gui_print("Wiping data without wiping /data/media ...\n");
Dees_Troy38bd7602012-09-14 13:33:53 -04001531
1532 DIR* d;
1533 d = opendir("/data");
Dees_Troy16b74352012-11-14 22:27:31 +00001534 if (d != NULL) {
Dees_Troy38bd7602012-09-14 13:33:53 -04001535 struct dirent* de;
1536 while ((de = readdir(d)) != NULL) {
bigbiff bigbiff34684ff2013-12-01 21:03:45 -05001537 if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
Dees_Troy16b74352012-11-14 22:27:31 +00001538 // The media folder is the "internal sdcard"
1539 // The .layout_version file is responsible for determining whether 4.2 decides up upgrade
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001540 // the media folder for multi-user.
bigbiff bigbiffc7360dd2014-01-25 15:02:57 -05001541 //TODO: convert this to use twrpDU.cpp
Dees_Troy16b74352012-11-14 22:27:31 +00001542 if (strcmp(de->d_name, "media") == 0 || strcmp(de->d_name, ".layout_version") == 0) continue;
bigbiff bigbiffc7360dd2014-01-25 15:02:57 -05001543
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001544 dir = "/data/";
1545 dir.append(de->d_name);
Dees_Troyce675462013-01-09 19:48:21 +00001546 if (de->d_type == DT_DIR) {
1547 TWFunc::removeDir(dir, false);
bigbiff bigbiff98f1f902013-01-19 18:46:13 -05001548 } else if (de->d_type == DT_REG || de->d_type == DT_LNK || de->d_type == DT_FIFO || de->d_type == DT_SOCK) {
Dees_Troyce675462013-01-09 19:48:21 +00001549 if (!unlink(dir.c_str()))
Dees_Troy2673cec2013-04-02 20:22:16 +00001550 LOGINFO("Unable to unlink '%s'\n", dir.c_str());
Dees_Troyce675462013-01-09 19:48:21 +00001551 }
Dees_Troy38bd7602012-09-14 13:33:53 -04001552 }
1553 closedir(d);
bigbiff bigbiffc7360dd2014-01-25 15:02:57 -05001554
Dees_Troy2673cec2013-04-02 20:22:16 +00001555 gui_print("Done.\n");
Dees_Troy16b74352012-11-14 22:27:31 +00001556 return true;
Dees_Troy38bd7602012-09-14 13:33:53 -04001557 }
Dees_Troy2673cec2013-04-02 20:22:16 +00001558 gui_print("Dirent failed to open /data, error!\n");
Dees_Troy16b74352012-11-14 22:27:31 +00001559 return false;
Dees_Troy51a0e822012-09-05 15:24:24 -04001560}
1561
1562bool TWPartition::Backup_Tar(string backup_folder) {
Dees_Troy4a2a1262012-09-18 09:33:47 -04001563 char back_name[255], split_index[5];
1564 string Full_FileName, Split_FileName, Tar_Args, Command;
Dees_Troy83bd4832013-05-04 12:39:56 +00001565 int use_compression, use_encryption = 0, index, backup_count;
Dees_Troy4a2a1262012-09-18 09:33:47 -04001566 struct stat st;
Dees_Troy7c2dec82012-09-26 09:49:14 -04001567 unsigned long long total_bsize = 0, file_size;
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001568 twrpTar tar;
1569 vector <string> files;
bigbiff bigbiffcdcfee42013-02-27 21:11:26 -05001570
Dees_Troy43d8b002012-09-17 16:00:01 -04001571 if (!Mount(true))
1572 return false;
1573
Dees_Troya13d74f2013-03-24 08:54:55 -05001574 TWFunc::GUI_Operation_Text(TW_BACKUP_TEXT, Backup_Display_Name, "Backing Up");
Dees_Troy2673cec2013-04-02 20:22:16 +00001575 gui_print("Backing up %s...\n", Backup_Display_Name.c_str());
Dees_Troy43d8b002012-09-17 16:00:01 -04001576
1577 DataManager::GetValue(TW_USE_COMPRESSION_VAR, use_compression);
Dees_Troy83bd4832013-05-04 12:39:56 +00001578 tar.use_compression = use_compression;
bigbiff bigbiff86e77bc2013-08-26 21:36:23 -04001579 //exclude Google Music Cache
bigbiff bigbiff34684ff2013-12-01 21:03:45 -05001580 vector<string> excludedirs = du.get_absolute_dirs();
1581 for (int i = 0; i < excludedirs.size(); ++i) {
1582 tar.setexcl(excludedirs.at(i));
1583 }
Dees_Troy83bd4832013-05-04 12:39:56 +00001584#ifndef TW_EXCLUDE_ENCRYPTED_BACKUPS
1585 DataManager::GetValue("tw_encrypt_backup", use_encryption);
1586 if (use_encryption && Can_Encrypt_Backup) {
1587 tar.use_encryption = use_encryption;
1588 if (Use_Userdata_Encryption)
1589 tar.userdata_encryption = use_encryption;
1590 } else {
1591 use_encryption = false;
1592 }
1593#endif
Dees_Troy43d8b002012-09-17 16:00:01 -04001594
1595 sprintf(back_name, "%s.%s.win", Backup_Name.c_str(), Current_File_System.c_str());
1596 Backup_FileName = back_name;
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001597 Full_FileName = backup_folder + "/" + Backup_FileName;
Dees_Troy83bd4832013-05-04 12:39:56 +00001598 tar.has_data_media = Has_Data_Media;
Dees Troye0a433a2013-12-02 04:10:37 +00001599 Full_FileName = backup_folder + "/" + Backup_FileName;
1600 tar.setdir(Backup_Path);
1601 tar.setfn(Full_FileName);
1602 tar.setsize(Backup_Size);
1603 if (tar.createTarFork() != 0)
1604 return false;
Dees_Troy43d8b002012-09-17 16:00:01 -04001605 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -04001606}
1607
1608bool TWPartition::Backup_DD(string backup_folder) {
igoriok87e3d932013-01-31 21:03:53 +02001609 char back_name[255], backup_size[32];
Vojtech Bocek05534202013-09-11 08:11:56 +02001610 string Full_FileName, Command, DD_BS;
Dees_Troy43d8b002012-09-17 16:00:01 -04001611 int use_compression;
1612
igoriok87e3d932013-01-31 21:03:53 +02001613 sprintf(backup_size, "%llu", Backup_Size);
1614 DD_BS = backup_size;
1615
Dees_Troyb46a6842012-09-25 11:06:46 -04001616 TWFunc::GUI_Operation_Text(TW_BACKUP_TEXT, Display_Name, "Backing Up");
Dees_Troy2673cec2013-04-02 20:22:16 +00001617 gui_print("Backing up %s...\n", Display_Name.c_str());
Dees_Troy43d8b002012-09-17 16:00:01 -04001618
1619 sprintf(back_name, "%s.%s.win", Backup_Name.c_str(), Current_File_System.c_str());
1620 Backup_FileName = back_name;
1621
1622 Full_FileName = backup_folder + "/" + Backup_FileName;
1623
igoriok87e3d932013-01-31 21:03:53 +02001624 Command = "dd if=" + Actual_Block_Device + " of='" + Full_FileName + "'" + " bs=" + DD_BS + "c count=1";
Dees_Troy2673cec2013-04-02 20:22:16 +00001625 LOGINFO("Backup command: '%s'\n", Command.c_str());
Vojtech Bocek05534202013-09-11 08:11:56 +02001626 TWFunc::Exec_Cmd(Command);
Dees_Troyc154ac22012-10-12 15:36:47 -04001627 if (TWFunc::Get_File_Size(Full_FileName) == 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001628 LOGERR("Backup file size for '%s' is 0 bytes.\n", Full_FileName.c_str());
Dees_Troy7c2dec82012-09-26 09:49:14 -04001629 return false;
1630 }
Dees_Troy43d8b002012-09-17 16:00:01 -04001631 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -04001632}
1633
1634bool TWPartition::Backup_Dump_Image(string backup_folder) {
Dees_Troy43d8b002012-09-17 16:00:01 -04001635 char back_name[255];
Vojtech Bocek05534202013-09-11 08:11:56 +02001636 string Full_FileName, Command;
Dees_Troy43d8b002012-09-17 16:00:01 -04001637 int use_compression;
1638
Dees_Troyb46a6842012-09-25 11:06:46 -04001639 TWFunc::GUI_Operation_Text(TW_BACKUP_TEXT, Display_Name, "Backing Up");
Dees_Troy2673cec2013-04-02 20:22:16 +00001640 gui_print("Backing up %s...\n", Display_Name.c_str());
Dees_Troy43d8b002012-09-17 16:00:01 -04001641
1642 sprintf(back_name, "%s.%s.win", Backup_Name.c_str(), Current_File_System.c_str());
1643 Backup_FileName = back_name;
1644
1645 Full_FileName = backup_folder + "/" + Backup_FileName;
1646
1647 Command = "dump_image " + MTD_Name + " '" + Full_FileName + "'";
Dees_Troy2673cec2013-04-02 20:22:16 +00001648 LOGINFO("Backup command: '%s'\n", Command.c_str());
Vojtech Bocek05534202013-09-11 08:11:56 +02001649 TWFunc::Exec_Cmd(Command);
Dees_Troy7c2dec82012-09-26 09:49:14 -04001650 if (TWFunc::Get_File_Size(Full_FileName) == 0) {
1651 // Actual size may not match backup size due to bad blocks on MTD devices so just check for 0 bytes
Dees_Troy2673cec2013-04-02 20:22:16 +00001652 LOGERR("Backup file size for '%s' is 0 bytes.\n", Full_FileName.c_str());
Dees_Troy7c2dec82012-09-26 09:49:14 -04001653 return false;
1654 }
Dees_Troy43d8b002012-09-17 16:00:01 -04001655 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -04001656}
1657
Gary Peck43acadf2012-11-21 21:19:01 -08001658bool TWPartition::Restore_Tar(string restore_folder, string Restore_File_System) {
1659 string Full_FileName, Command;
Dees_Troy4a2a1262012-09-18 09:33:47 -04001660 int index = 0;
1661 char split_index[5];
Dees_Troy43d8b002012-09-17 16:00:01 -04001662
Dees_Troye58d5262012-09-21 12:27:57 -04001663 if (Has_Android_Secure) {
Dees_Troye58d5262012-09-21 12:27:57 -04001664 if (!Wipe_AndSec())
1665 return false;
Gary Peck43acadf2012-11-21 21:19:01 -08001666 } else {
Dees_Troy2673cec2013-04-02 20:22:16 +00001667 gui_print("Wiping %s...\n", Display_Name.c_str());
Gary Peck43acadf2012-11-21 21:19:01 -08001668 if (!Wipe(Restore_File_System))
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001669 return false;
Dees_Troye58d5262012-09-21 12:27:57 -04001670 }
Dees_Troya13d74f2013-03-24 08:54:55 -05001671 TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Backup_Display_Name, "Restoring");
Dees_Troy2673cec2013-04-02 20:22:16 +00001672 gui_print("Restoring %s...\n", Backup_Display_Name.c_str());
Dees_Troy43d8b002012-09-17 16:00:01 -04001673
1674 if (!Mount(true))
1675 return false;
1676
Dees_Troy4a2a1262012-09-18 09:33:47 -04001677 Full_FileName = restore_folder + "/" + Backup_FileName;
Dees_Troy83bd4832013-05-04 12:39:56 +00001678 /*if (!TWFunc::Path_Exists(Full_FileName)) {
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001679 if (!TWFunc::Path_Exists(Full_FileName)) {
1680 // Backup is multiple archives
Dees_Troy2673cec2013-04-02 20:22:16 +00001681 LOGINFO("Backup is multiple archives.\n");
Dees_Troy4a2a1262012-09-18 09:33:47 -04001682 sprintf(split_index, "%03i", index);
1683 Full_FileName = restore_folder + "/" + Backup_FileName + split_index;
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001684 while (TWFunc::Path_Exists(Full_FileName)) {
1685 index++;
Dees_Troy2673cec2013-04-02 20:22:16 +00001686 gui_print("Restoring archive %i...\n", index);
1687 LOGINFO("Restoring '%s'...\n", Full_FileName.c_str());
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001688 twrpTar tar;
bigbiff bigbiff3bf2b0e2013-01-21 21:26:43 -05001689 tar.setdir("/");
1690 tar.setfn(Full_FileName);
bigbiff bigbiffe6594ab2013-02-17 20:18:31 -05001691 if (tar.extractTarFork() != 0)
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001692 return false;
1693 sprintf(split_index, "%03i", index);
1694 Full_FileName = restore_folder + "/" + Backup_FileName + split_index;
1695 }
1696 if (index == 0) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001697 LOGERR("Error locating restore file: '%s'\n", Full_FileName.c_str());
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001698 return false;
1699 }
Dees_Troy4a2a1262012-09-18 09:33:47 -04001700 }
Dees_Troy83bd4832013-05-04 12:39:56 +00001701 } else {*/
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001702 twrpTar tar;
bigbiff bigbiff3bf2b0e2013-01-21 21:26:43 -05001703 tar.setdir(Backup_Path);
1704 tar.setfn(Full_FileName);
Dees_Troy83bd4832013-05-04 12:39:56 +00001705 tar.backup_name = Backup_Name;
bigbiff bigbiffe6594ab2013-02-17 20:18:31 -05001706 if (tar.extractTarFork() != 0)
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001707 return false;
Dees_Troy83bd4832013-05-04 12:39:56 +00001708 //}
Dees_Troy43d8b002012-09-17 16:00:01 -04001709 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -04001710}
1711
1712bool TWPartition::Restore_DD(string restore_folder) {
Vojtech Bocek05534202013-09-11 08:11:56 +02001713 string Full_FileName, Command;
Dees_Troy43d8b002012-09-17 16:00:01 -04001714
Dees_Troyda8b55a2012-12-12 19:18:30 +00001715 TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Display_Name, "Restoring");
Dees_Troy43d8b002012-09-17 16:00:01 -04001716 Full_FileName = restore_folder + "/" + Backup_FileName;
Gary Peck15e623d2012-11-21 21:07:58 -08001717
1718 if (!Find_Partition_Size()) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001719 LOGERR("Unable to find partition size for '%s'\n", Mount_Point.c_str());
Gary Peck15e623d2012-11-21 21:07:58 -08001720 return false;
1721 }
1722 unsigned long long backup_size = TWFunc::Get_File_Size(Full_FileName);
1723 if (backup_size > Size) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001724 LOGERR("Size (%iMB) of backup '%s' is larger than target device '%s' (%iMB)\n",
Gary Peck15e623d2012-11-21 21:07:58 -08001725 (int)(backup_size / 1048576LLU), Full_FileName.c_str(),
1726 Actual_Block_Device.c_str(), (int)(Size / 1048576LLU));
1727 return false;
1728 }
1729
Dees_Troy2673cec2013-04-02 20:22:16 +00001730 gui_print("Restoring %s...\n", Display_Name.c_str());
Dees_Troy43d8b002012-09-17 16:00:01 -04001731 Command = "dd bs=4096 if='" + Full_FileName + "' of=" + Actual_Block_Device;
Dees_Troy2673cec2013-04-02 20:22:16 +00001732 LOGINFO("Restore command: '%s'\n", Command.c_str());
Vojtech Bocek05534202013-09-11 08:11:56 +02001733 TWFunc::Exec_Cmd(Command);
Dees_Troy43d8b002012-09-17 16:00:01 -04001734 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -04001735}
1736
1737bool TWPartition::Restore_Flash_Image(string restore_folder) {
Vojtech Bocek05534202013-09-11 08:11:56 +02001738 string Full_FileName, Command;
Dees_Troy43d8b002012-09-17 16:00:01 -04001739
Dees_Troy2673cec2013-04-02 20:22:16 +00001740 gui_print("Restoring %s...\n", Display_Name.c_str());
Dees_Troy43d8b002012-09-17 16:00:01 -04001741 Full_FileName = restore_folder + "/" + Backup_FileName;
1742 // Sometimes flash image doesn't like to flash due to the first 2KB matching, so we erase first to ensure that it flashes
1743 Command = "erase_image " + MTD_Name;
Dees_Troy2673cec2013-04-02 20:22:16 +00001744 LOGINFO("Erase command: '%s'\n", Command.c_str());
Vojtech Bocek05534202013-09-11 08:11:56 +02001745 TWFunc::Exec_Cmd(Command);
Dees_Troy43d8b002012-09-17 16:00:01 -04001746 Command = "flash_image " + MTD_Name + " '" + Full_FileName + "'";
Dees_Troy2673cec2013-04-02 20:22:16 +00001747 LOGINFO("Restore command: '%s'\n", Command.c_str());
Vojtech Bocek05534202013-09-11 08:11:56 +02001748 TWFunc::Exec_Cmd(Command);
Dees_Troy43d8b002012-09-17 16:00:01 -04001749 return true;
Dees_Troy51a0e822012-09-05 15:24:24 -04001750}
Dees_Troy5bf43922012-09-07 16:07:55 -04001751
1752bool TWPartition::Update_Size(bool Display_Error) {
Dees_Troy0550cfb2012-10-13 11:56:13 -04001753 bool ret = false, Was_Already_Mounted = false;
Dees_Troy51127312012-09-08 13:08:49 -04001754
Dees_Troyab10ee22012-09-21 14:27:30 -04001755 if (!Can_Be_Mounted && !Is_Encrypted)
Dees_Troy5bf43922012-09-07 16:07:55 -04001756 return false;
1757
Dees_Troy0550cfb2012-10-13 11:56:13 -04001758 Was_Already_Mounted = Is_Mounted();
Dees_Troy38bd7602012-09-14 13:33:53 -04001759 if (Removable || Is_Encrypted) {
1760 if (!Mount(false))
1761 return true;
1762 } else if (!Mount(Display_Error))
Dees_Troy5bf43922012-09-07 16:07:55 -04001763 return false;
Dees_Troy51127312012-09-08 13:08:49 -04001764
1765 ret = Get_Size_Via_statfs(Display_Error);
Dees_Troy0550cfb2012-10-13 11:56:13 -04001766 if (!ret || Size == 0) {
1767 if (!Get_Size_Via_df(Display_Error)) {
1768 if (!Was_Already_Mounted)
1769 UnMount(false);
Dees_Troy51127312012-09-08 13:08:49 -04001770 return false;
Dees_Troy0550cfb2012-10-13 11:56:13 -04001771 }
1772 }
Dees_Troy51127312012-09-08 13:08:49 -04001773
Dees_Troy5bf43922012-09-07 16:07:55 -04001774 if (Has_Data_Media) {
1775 if (Mount(Display_Error)) {
Dees_Troy51127312012-09-08 13:08:49 -04001776 unsigned long long data_media_used, actual_data;
bigbiff bigbiff34684ff2013-12-01 21:03:45 -05001777 du.add_relative_dir("media");
1778 Used = du.Get_Folder_Size("/data");
bigbiff bigbiffc7360dd2014-01-25 15:02:57 -05001779 du.clear_relative_dir("media");
bigbiff bigbiff34684ff2013-12-01 21:03:45 -05001780 Backup_Size = Used;
1781 int bak = (int)(Used / 1048576LLU);
Dees_Troy51127312012-09-08 13:08:49 -04001782 int fre = (int)(Free / 1048576LLU);
bigbiff bigbiff34684ff2013-12-01 21:03:45 -05001783 LOGINFO("Data backup size is %iMB, free: %iMB.\n", bak, fre);
Dees_Troy0550cfb2012-10-13 11:56:13 -04001784 } else {
1785 if (!Was_Already_Mounted)
1786 UnMount(false);
Dees_Troy5bf43922012-09-07 16:07:55 -04001787 return false;
Dees_Troy0550cfb2012-10-13 11:56:13 -04001788 }
Dees_Troye58d5262012-09-21 12:27:57 -04001789 } else if (Has_Android_Secure) {
1790 if (Mount(Display_Error))
bigbiff bigbiff34684ff2013-12-01 21:03:45 -05001791 Backup_Size = du.Get_Folder_Size(Backup_Path);
Dees_Troy0550cfb2012-10-13 11:56:13 -04001792 else {
1793 if (!Was_Already_Mounted)
1794 UnMount(false);
Dees_Troye58d5262012-09-21 12:27:57 -04001795 return false;
Dees_Troy0550cfb2012-10-13 11:56:13 -04001796 }
Dees_Troy5bf43922012-09-07 16:07:55 -04001797 }
Dees_Troy0550cfb2012-10-13 11:56:13 -04001798 if (!Was_Already_Mounted)
1799 UnMount(false);
Dees_Troy5bf43922012-09-07 16:07:55 -04001800 return true;
Dees_Troy51127312012-09-08 13:08:49 -04001801}
Dees_Troy38bd7602012-09-14 13:33:53 -04001802
1803void TWPartition::Find_Actual_Block_Device(void) {
1804 if (Is_Decrypted) {
1805 Actual_Block_Device = Decrypted_Block_Device;
Dees_Troy43d8b002012-09-17 16:00:01 -04001806 if (TWFunc::Path_Exists(Primary_Block_Device))
Dees_Troy38bd7602012-09-14 13:33:53 -04001807 Is_Present = true;
Dees_Troy43d8b002012-09-17 16:00:01 -04001808 } else if (TWFunc::Path_Exists(Primary_Block_Device)) {
Dees_Troy38bd7602012-09-14 13:33:53 -04001809 Is_Present = true;
1810 Actual_Block_Device = Primary_Block_Device;
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001811 return;
1812 }
1813 if (Is_Decrypted) {
Dees_Troy43d8b002012-09-17 16:00:01 -04001814 } else if (!Alternate_Block_Device.empty() && TWFunc::Path_Exists(Alternate_Block_Device)) {
Dees_Troy3f04d032012-10-07 18:20:09 -04001815 Actual_Block_Device = Alternate_Block_Device;
Dees_Troy38bd7602012-09-14 13:33:53 -04001816 Is_Present = true;
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001817 } else {
Dees_Troy38bd7602012-09-14 13:33:53 -04001818 Is_Present = false;
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001819 }
Dees_Troy38bd7602012-09-14 13:33:53 -04001820}
1821
1822void TWPartition::Recreate_Media_Folder(void) {
1823 string Command;
1824
1825 if (!Mount(true)) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001826 LOGERR("Unable to recreate /data/media folder.\n");
Dees_Troyb46a6842012-09-25 11:06:46 -04001827 } else if (!TWFunc::Path_Exists("/data/media")) {
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001828 PartitionManager.Mount_By_Path(Symlink_Mount_Point, true);
Dees_Troy2673cec2013-04-02 20:22:16 +00001829 LOGINFO("Recreating /data/media folder.\n");
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001830 mkdir("/data/media", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
1831 PartitionManager.UnMount_By_Path(Symlink_Mount_Point, true);
Dees_Troy38bd7602012-09-14 13:33:53 -04001832 }
Dees_Troy43d8b002012-09-17 16:00:01 -04001833}
Dees_Troye58d5262012-09-21 12:27:57 -04001834
1835void TWPartition::Recreate_AndSec_Folder(void) {
Dees_Troye58d5262012-09-21 12:27:57 -04001836 if (!Has_Android_Secure)
1837 return;
Dees_Troy2673cec2013-04-02 20:22:16 +00001838 LOGINFO("Creating %s: %s\n", Backup_Display_Name.c_str(), Symlink_Path.c_str());
Dees_Troye58d5262012-09-21 12:27:57 -04001839 if (!Mount(true)) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001840 LOGERR("Unable to recreate %s folder.\n", Backup_Name.c_str());
Dees_Troye58d5262012-09-21 12:27:57 -04001841 } else if (!TWFunc::Path_Exists(Symlink_Path)) {
Dees_Troy2673cec2013-04-02 20:22:16 +00001842 LOGINFO("Recreating %s folder.\n", Backup_Name.c_str());
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001843 PartitionManager.Mount_By_Path(Symlink_Mount_Point, true);
1844 mkdir(Symlink_Path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
1845 PartitionManager.UnMount_By_Path(Symlink_Mount_Point, true);
Dees_Troye58d5262012-09-21 12:27:57 -04001846 }
1847}