Dees Troy | 3be70a8 | 2013-10-22 14:25:12 +0000 | [diff] [blame] | 1 | /* |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 2 | Copyright 2014 to 2016 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> |
| 24 | #include <unistd.h> |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 25 | #include <vector> |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 26 | #include <dirent.h> |
| 27 | #include <time.h> |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 28 | #include <errno.h> |
| 29 | #include <fcntl.h> |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 30 | #include <iostream> |
| 31 | #include <iomanip> |
Ethan Yonker | 8613dc0 | 2014-09-11 09:28:20 -0500 | [diff] [blame] | 32 | #include <sys/wait.h> |
Ethan Yonker | 483e9f4 | 2016-01-11 22:21:18 -0600 | [diff] [blame] | 33 | #include <linux/fs.h> |
| 34 | #include <sys/mount.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 | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 39 | #include "twrp-functions.hpp" |
Ethan Yonker | b5fab76 | 2016-01-28 14:03:33 -0600 | [diff] [blame] | 40 | #include "fixContexts.hpp" |
bigbiff bigbiff | cdcfee4 | 2013-02-27 21:11:26 -0500 | [diff] [blame] | 41 | #include "twrpDigest.hpp" |
bigbiff bigbiff | 34684ff | 2013-12-01 21:03:45 -0500 | [diff] [blame] | 42 | #include "twrpDU.hpp" |
Ethan Yonker | 4b94cfd | 2014-12-11 10:00:45 -0600 | [diff] [blame] | 43 | #include "set_metadata.h" |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 44 | #include "tw_atomic.hpp" |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 45 | #include "gui/gui.hpp" |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 46 | #include "progresstracking.hpp" |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 47 | |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 48 | #ifdef TW_HAS_MTP |
| 49 | #include "mtp/mtp_MtpServer.hpp" |
| 50 | #include "mtp/twrpMtp.hpp" |
Ethan Yonker | 726a020 | 2014-12-16 20:01:38 -0600 | [diff] [blame] | 51 | #include "mtp/MtpMessage.hpp" |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 52 | #endif |
| 53 | |
Dees Troy | 6f6441d | 2014-01-23 02:07:03 +0000 | [diff] [blame] | 54 | extern "C" { |
| 55 | #include "cutils/properties.h" |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 56 | #include "gui/gui.h" |
Dees Troy | 6f6441d | 2014-01-23 02:07:03 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 59 | #ifdef TW_INCLUDE_CRYPTO |
Ethan Yonker | 253368a | 2014-11-25 15:00:52 -0600 | [diff] [blame] | 60 | #include "crypto/lollipop/cryptfs.h" |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 61 | #include "gui/rapidxml.hpp" |
| 62 | #include "gui/pages.hpp" |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 63 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 64 | |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 65 | extern bool datamedia; |
| 66 | |
bigbiff bigbiff | 34684ff | 2013-12-01 21:03:45 -0500 | [diff] [blame] | 67 | TWPartitionManager::TWPartitionManager(void) { |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 68 | mtp_was_enabled = false; |
Ethan Yonker | 726a020 | 2014-12-16 20:01:38 -0600 | [diff] [blame] | 69 | mtp_write_fd = -1; |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 70 | stop_backup.set_value(0); |
| 71 | tar_fork_pid = 0; |
bigbiff bigbiff | 34684ff | 2013-12-01 21:03:45 -0500 | [diff] [blame] | 72 | } |
| 73 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 74 | int TWPartitionManager::Process_Fstab(string Fstab_Filename, bool Display_Error) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 75 | FILE *fstabFile; |
| 76 | char fstab_line[MAX_FSTAB_LINE_LENGTH]; |
Dees Troy | 02a6453 | 2014-03-19 15:23:32 +0000 | [diff] [blame] | 77 | TWPartition* settings_partition = NULL; |
Matt Mower | bf4efa3 | 2014-04-14 23:25:26 -0500 | [diff] [blame] | 78 | TWPartition* andsec_partition = NULL; |
Ethan Yonker | 726a020 | 2014-12-16 20:01:38 -0600 | [diff] [blame] | 79 | unsigned int storageid = 1 << 16; // upper 16 bits are for physical storage device, we pretend to have only one |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 80 | |
| 81 | fstabFile = fopen(Fstab_Filename.c_str(), "rt"); |
| 82 | if (fstabFile == NULL) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 83 | LOGERR("Critical Error: Unable to open fstab at '%s'.\n", Fstab_Filename.c_str()); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 84 | return false; |
| 85 | } |
| 86 | |
| 87 | while (fgets(fstab_line, sizeof(fstab_line), fstabFile) != NULL) { |
| 88 | if (fstab_line[0] != '/') |
| 89 | continue; |
| 90 | |
Dees_Troy | 2a92358 | 2012-09-20 12:13:34 -0400 | [diff] [blame] | 91 | if (fstab_line[strlen(fstab_line) - 1] != '\n') |
| 92 | fstab_line[strlen(fstab_line)] = '\n'; |
Dees_Troy | 2a92358 | 2012-09-20 12:13:34 -0400 | [diff] [blame] | 93 | |
Matt Mower | 2b2dd15 | 2016-04-26 11:24:08 -0500 | [diff] [blame] | 94 | TWPartition* partition = new TWPartition(); |
Matt Mower | 72c87ce | 2016-04-26 14:34:56 -0500 | [diff] [blame] | 95 | if (partition->Process_Fstab_Line(fstab_line, Display_Error)) |
Ethan Yonker | c05c598 | 2014-03-13 09:19:56 -0500 | [diff] [blame] | 96 | Partitions.push_back(partition); |
Matt Mower | 72c87ce | 2016-04-26 14:34:56 -0500 | [diff] [blame] | 97 | else |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 98 | delete partition; |
Matt Mower | 2b2dd15 | 2016-04-26 11:24:08 -0500 | [diff] [blame] | 99 | |
| 100 | memset(fstab_line, 0, sizeof(fstab_line)); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 101 | } |
| 102 | fclose(fstabFile); |
Matt Mower | 72c87ce | 2016-04-26 14:34:56 -0500 | [diff] [blame] | 103 | |
| 104 | std::vector<TWPartition*>::iterator iter; |
| 105 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
| 106 | (*iter)->Partition_Post_Processing(Display_Error); |
| 107 | |
| 108 | if ((*iter)->Is_Storage) { |
| 109 | ++storageid; |
| 110 | (*iter)->MTP_Storage_ID = storageid; |
| 111 | } |
| 112 | |
| 113 | if (!settings_partition && (*iter)->Is_Settings_Storage && (*iter)->Is_Present) |
| 114 | settings_partition = (*iter); |
| 115 | else |
| 116 | (*iter)->Is_Settings_Storage = false; |
| 117 | |
| 118 | if (!andsec_partition && (*iter)->Has_Android_Secure && (*iter)->Is_Present) |
| 119 | andsec_partition = (*iter); |
| 120 | else |
| 121 | (*iter)->Has_Android_Secure = false; |
| 122 | } |
| 123 | |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 124 | if (!datamedia && !settings_partition && Find_Partition_By_Path("/sdcard") == NULL && Find_Partition_By_Path("/internal_sd") == NULL && Find_Partition_By_Path("/internal_sdcard") == NULL && Find_Partition_By_Path("/emmc") == NULL) { |
| 125 | // Attempt to automatically identify /data/media emulated storage devices |
| 126 | TWPartition* Dat = Find_Partition_By_Path("/data"); |
| 127 | if (Dat) { |
| 128 | LOGINFO("Using automatic handling for /data/media emulated storage device.\n"); |
| 129 | datamedia = true; |
that | 9e0593e | 2014-10-08 00:01:24 +0200 | [diff] [blame] | 130 | Dat->Setup_Data_Media(); |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 131 | settings_partition = Dat; |
Ethan Yonker | 726a020 | 2014-12-16 20:01:38 -0600 | [diff] [blame] | 132 | // Since /data was not considered a storage partition earlier, we still need to assign an MTP ID |
| 133 | ++storageid; |
| 134 | Dat->MTP_Storage_ID = storageid; |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 135 | } |
| 136 | } |
Dees Troy | 02a6453 | 2014-03-19 15:23:32 +0000 | [diff] [blame] | 137 | if (!settings_partition) { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 138 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
| 139 | if ((*iter)->Is_Storage) { |
Dees Troy | 02a6453 | 2014-03-19 15:23:32 +0000 | [diff] [blame] | 140 | settings_partition = (*iter); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 141 | break; |
| 142 | } |
| 143 | } |
Dees Troy | 02a6453 | 2014-03-19 15:23:32 +0000 | [diff] [blame] | 144 | if (!settings_partition) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 145 | LOGERR("Unable to locate storage partition for storing settings file.\n"); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 146 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 147 | if (!Write_Fstab()) { |
| 148 | if (Display_Error) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 149 | LOGERR("Error creating fstab\n"); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 150 | else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 151 | LOGINFO("Error creating fstab\n"); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 152 | } |
Matt Mower | ed71fa3 | 2014-04-16 13:21:47 -0500 | [diff] [blame] | 153 | |
Matt Mower | bf4efa3 | 2014-04-14 23:25:26 -0500 | [diff] [blame] | 154 | if (andsec_partition) { |
| 155 | Setup_Android_Secure_Location(andsec_partition); |
Matt Mower | ed71fa3 | 2014-04-16 13:21:47 -0500 | [diff] [blame] | 156 | } else if (settings_partition) { |
Matt Mower | bf4efa3 | 2014-04-14 23:25:26 -0500 | [diff] [blame] | 157 | Setup_Android_Secure_Location(settings_partition); |
| 158 | } |
Matt Mower | ed71fa3 | 2014-04-16 13:21:47 -0500 | [diff] [blame] | 159 | if (settings_partition) { |
| 160 | Setup_Settings_Storage_Partition(settings_partition); |
| 161 | } |
Ethan Yonker | 253368a | 2014-11-25 15:00:52 -0600 | [diff] [blame] | 162 | #ifdef TW_INCLUDE_CRYPTO |
Ethan Yonker | cceebb8 | 2014-11-18 10:17:59 -0600 | [diff] [blame] | 163 | TWPartition* Decrypt_Data = Find_Partition_By_Path("/data"); |
| 164 | if (Decrypt_Data && Decrypt_Data->Is_Encrypted && !Decrypt_Data->Is_Decrypted) { |
| 165 | int password_type = cryptfs_get_password_type(); |
| 166 | if (password_type == CRYPT_TYPE_DEFAULT) { |
| 167 | LOGINFO("Device is encrypted with the default password, attempting to decrypt.\n"); |
| 168 | if (Decrypt_Device("default_password") == 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 169 | gui_msg("decrypt_success=Successfully decrypted with default password."); |
Ethan Yonker | cceebb8 | 2014-11-18 10:17:59 -0600 | [diff] [blame] | 170 | DataManager::SetValue(TW_IS_ENCRYPTED, 0); |
| 171 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 172 | gui_err("unable_to_decrypt=Unable to decrypt with default password."); |
Ethan Yonker | cceebb8 | 2014-11-18 10:17:59 -0600 | [diff] [blame] | 173 | } |
| 174 | } else { |
| 175 | DataManager::SetValue("TW_CRYPTO_TYPE", password_type); |
| 176 | } |
| 177 | } |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 178 | if (Decrypt_Data && (!Decrypt_Data->Is_Encrypted || Decrypt_Data->Is_Decrypted) && Decrypt_Data->Mount(false)) { |
| 179 | Decrypt_Adopted(); |
| 180 | } |
Ethan Yonker | cceebb8 | 2014-11-18 10:17:59 -0600 | [diff] [blame] | 181 | #endif |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 182 | Update_System_Details(); |
Dees_Troy | d0384ef | 2012-10-12 12:15:42 -0400 | [diff] [blame] | 183 | UnMount_Main_Partitions(); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 184 | return true; |
| 185 | } |
| 186 | |
| 187 | int TWPartitionManager::Write_Fstab(void) { |
| 188 | FILE *fp; |
| 189 | std::vector<TWPartition*>::iterator iter; |
| 190 | string Line; |
| 191 | |
| 192 | fp = fopen("/etc/fstab", "w"); |
| 193 | if (fp == NULL) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 194 | LOGINFO("Can not open /etc/fstab.\n"); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 195 | return false; |
| 196 | } |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 197 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 198 | if ((*iter)->Can_Be_Mounted) { |
dianlujitao | 7d304c7 | 2016-01-02 12:15:50 +0800 | [diff] [blame] | 199 | Line = (*iter)->Actual_Block_Device + " " + (*iter)->Mount_Point + " " + (*iter)->Current_File_System + " rw 0 0\n"; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 200 | fputs(Line.c_str(), fp); |
Dees_Troy | 91862e6 | 2013-04-04 23:48:21 +0000 | [diff] [blame] | 201 | } |
| 202 | // Handle subpartition tracking |
| 203 | if ((*iter)->Is_SubPartition) { |
| 204 | TWPartition* ParentPartition = Find_Partition_By_Path((*iter)->SubPartition_Of); |
| 205 | if (ParentPartition) |
| 206 | ParentPartition->Has_SubPartition = true; |
| 207 | else |
| 208 | LOGERR("Unable to locate parent partition '%s' of '%s'\n", (*iter)->SubPartition_Of.c_str(), (*iter)->Mount_Point.c_str()); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | fclose(fp); |
| 212 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 213 | } |
| 214 | |
Ethan Yonker | c05c598 | 2014-03-13 09:19:56 -0500 | [diff] [blame] | 215 | void TWPartitionManager::Setup_Settings_Storage_Partition(TWPartition* Part) { |
Ethan Yonker | c05c598 | 2014-03-13 09:19:56 -0500 | [diff] [blame] | 216 | DataManager::SetValue("tw_settings_path", Part->Storage_Path); |
| 217 | DataManager::SetValue("tw_storage_path", Part->Storage_Path); |
| 218 | LOGINFO("Settings storage is '%s'\n", Part->Storage_Path.c_str()); |
| 219 | } |
| 220 | |
Matt Mower | bf4efa3 | 2014-04-14 23:25:26 -0500 | [diff] [blame] | 221 | void TWPartitionManager::Setup_Android_Secure_Location(TWPartition* Part) { |
| 222 | if (Part->Has_Android_Secure) |
| 223 | Part->Setup_AndSec(); |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 224 | else if (!datamedia) |
Matt Mower | bf4efa3 | 2014-04-14 23:25:26 -0500 | [diff] [blame] | 225 | Part->Setup_AndSec(); |
Matt Mower | bf4efa3 | 2014-04-14 23:25:26 -0500 | [diff] [blame] | 226 | } |
| 227 | |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 228 | void TWPartitionManager::Output_Partition_Logging(void) { |
| 229 | std::vector<TWPartition*>::iterator iter; |
| 230 | |
| 231 | printf("\n\nPartition Logs:\n"); |
| 232 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) |
| 233 | Output_Partition((*iter)); |
| 234 | } |
| 235 | |
| 236 | void TWPartitionManager::Output_Partition(TWPartition* Part) { |
| 237 | unsigned long long mb = 1048576; |
| 238 | |
Gary Peck | 004d48b | 2012-11-21 16:28:18 -0800 | [diff] [blame] | 239 | printf("%s | %s | Size: %iMB", Part->Mount_Point.c_str(), Part->Actual_Block_Device.c_str(), (int)(Part->Size / mb)); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 240 | if (Part->Can_Be_Mounted) { |
Gary Peck | 004d48b | 2012-11-21 16:28:18 -0800 | [diff] [blame] | 241 | printf(" Used: %iMB Free: %iMB Backup Size: %iMB", (int)(Part->Used / mb), (int)(Part->Free / mb), (int)(Part->Backup_Size / mb)); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 242 | } |
Gary Peck | 004d48b | 2012-11-21 16:28:18 -0800 | [diff] [blame] | 243 | printf("\n Flags: "); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 244 | if (Part->Can_Be_Mounted) |
| 245 | printf("Can_Be_Mounted "); |
Gary Peck | 004d48b | 2012-11-21 16:28:18 -0800 | [diff] [blame] | 246 | if (Part->Can_Be_Wiped) |
| 247 | printf("Can_Be_Wiped "); |
Hashcode | dabfd49 | 2013-08-29 22:45:30 -0700 | [diff] [blame] | 248 | if (Part->Use_Rm_Rf) |
| 249 | printf("Use_Rm_Rf "); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 250 | if (Part->Can_Be_Backed_Up) |
| 251 | printf("Can_Be_Backed_Up "); |
Gary Peck | 004d48b | 2012-11-21 16:28:18 -0800 | [diff] [blame] | 252 | if (Part->Wipe_During_Factory_Reset) |
| 253 | printf("Wipe_During_Factory_Reset "); |
| 254 | if (Part->Wipe_Available_in_GUI) |
| 255 | printf("Wipe_Available_in_GUI "); |
| 256 | if (Part->Is_SubPartition) |
| 257 | printf("Is_SubPartition "); |
| 258 | if (Part->Has_SubPartition) |
| 259 | printf("Has_SubPartition "); |
| 260 | if (Part->Removable) |
| 261 | printf("Removable "); |
| 262 | if (Part->Is_Present) |
| 263 | printf("IsPresent "); |
| 264 | if (Part->Can_Be_Encrypted) |
| 265 | printf("Can_Be_Encrypted "); |
| 266 | if (Part->Is_Encrypted) |
| 267 | printf("Is_Encrypted "); |
| 268 | if (Part->Is_Decrypted) |
| 269 | printf("Is_Decrypted "); |
| 270 | if (Part->Has_Data_Media) |
| 271 | printf("Has_Data_Media "); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 272 | if (Part->Can_Encrypt_Backup) |
| 273 | printf("Can_Encrypt_Backup "); |
| 274 | if (Part->Use_Userdata_Encryption) |
| 275 | printf("Use_Userdata_Encryption "); |
Gary Peck | 004d48b | 2012-11-21 16:28:18 -0800 | [diff] [blame] | 276 | if (Part->Has_Android_Secure) |
| 277 | printf("Has_Android_Secure "); |
| 278 | if (Part->Is_Storage) |
| 279 | printf("Is_Storage "); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 280 | if (Part->Is_Settings_Storage) |
| 281 | printf("Is_Settings_Storage "); |
Dees_Troy | 68cab49 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 282 | if (Part->Ignore_Blkid) |
| 283 | printf("Ignore_Blkid "); |
Dees_Troy | 16c2b31 | 2013-01-15 16:51:18 +0000 | [diff] [blame] | 284 | if (Part->Retain_Layout_Version) |
| 285 | printf("Retain_Layout_Version "); |
Ethan Yonker | 253368a | 2014-11-25 15:00:52 -0600 | [diff] [blame] | 286 | if (Part->Mount_To_Decrypt) |
| 287 | printf("Mount_To_Decrypt "); |
Ethan Yonker | 96af84a | 2015-01-05 14:58:36 -0600 | [diff] [blame] | 288 | if (Part->Can_Flash_Img) |
| 289 | printf("Can_Flash_Img "); |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 290 | if (Part->Is_Adopted_Storage) |
| 291 | printf("Is_Adopted_Storage "); |
Gary Peck | 004d48b | 2012-11-21 16:28:18 -0800 | [diff] [blame] | 292 | printf("\n"); |
| 293 | if (!Part->SubPartition_Of.empty()) |
| 294 | printf(" SubPartition_Of: %s\n", Part->SubPartition_Of.c_str()); |
| 295 | if (!Part->Symlink_Path.empty()) |
| 296 | printf(" Symlink_Path: %s\n", Part->Symlink_Path.c_str()); |
| 297 | if (!Part->Symlink_Mount_Point.empty()) |
| 298 | printf(" Symlink_Mount_Point: %s\n", Part->Symlink_Mount_Point.c_str()); |
| 299 | if (!Part->Primary_Block_Device.empty()) |
| 300 | printf(" Primary_Block_Device: %s\n", Part->Primary_Block_Device.c_str()); |
| 301 | if (!Part->Alternate_Block_Device.empty()) |
| 302 | printf(" Alternate_Block_Device: %s\n", Part->Alternate_Block_Device.c_str()); |
| 303 | if (!Part->Decrypted_Block_Device.empty()) |
| 304 | printf(" Decrypted_Block_Device: %s\n", Part->Decrypted_Block_Device.c_str()); |
Ethan Yonker | 253368a | 2014-11-25 15:00:52 -0600 | [diff] [blame] | 305 | if (!Part->Crypto_Key_Location.empty() && Part->Crypto_Key_Location != "footer") |
| 306 | printf(" Crypto_Key_Location: %s\n", Part->Crypto_Key_Location.c_str()); |
Gary Peck | 004d48b | 2012-11-21 16:28:18 -0800 | [diff] [blame] | 307 | if (Part->Length != 0) |
| 308 | printf(" Length: %i\n", Part->Length); |
| 309 | if (!Part->Display_Name.empty()) |
| 310 | printf(" Display_Name: %s\n", Part->Display_Name.c_str()); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 311 | if (!Part->Storage_Name.empty()) |
| 312 | printf(" Storage_Name: %s\n", Part->Storage_Name.c_str()); |
Gary Peck | 004d48b | 2012-11-21 16:28:18 -0800 | [diff] [blame] | 313 | if (!Part->Backup_Path.empty()) |
| 314 | printf(" Backup_Path: %s\n", Part->Backup_Path.c_str()); |
| 315 | if (!Part->Backup_Name.empty()) |
| 316 | printf(" Backup_Name: %s\n", Part->Backup_Name.c_str()); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 317 | if (!Part->Backup_Display_Name.empty()) |
| 318 | printf(" Backup_Display_Name: %s\n", Part->Backup_Display_Name.c_str()); |
Gary Peck | 004d48b | 2012-11-21 16:28:18 -0800 | [diff] [blame] | 319 | if (!Part->Backup_FileName.empty()) |
| 320 | printf(" Backup_FileName: %s\n", Part->Backup_FileName.c_str()); |
| 321 | if (!Part->Storage_Path.empty()) |
| 322 | printf(" Storage_Path: %s\n", Part->Storage_Path.c_str()); |
| 323 | if (!Part->Current_File_System.empty()) |
| 324 | printf(" Current_File_System: %s\n", Part->Current_File_System.c_str()); |
| 325 | if (!Part->Fstab_File_System.empty()) |
| 326 | printf(" Fstab_File_System: %s\n", Part->Fstab_File_System.c_str()); |
| 327 | if (Part->Format_Block_Size != 0) |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 328 | printf(" Format_Block_Size: %lu\n", Part->Format_Block_Size); |
Dees_Troy | 094207a | 2012-09-26 12:00:39 -0400 | [diff] [blame] | 329 | if (!Part->MTD_Name.empty()) |
| 330 | printf(" MTD_Name: %s\n", Part->MTD_Name.c_str()); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 331 | string back_meth = Part->Backup_Method_By_Name(); |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 332 | printf(" Backup_Method: %s\n", back_meth.c_str()); |
Hashcode | 62bd9e0 | 2013-11-19 21:59:42 -0800 | [diff] [blame] | 333 | if (Part->Mount_Flags || !Part->Mount_Options.empty()) |
Matt Mower | 4ab42b1 | 2016-04-21 13:52:18 -0500 | [diff] [blame] | 334 | printf(" Mount_Options: %s\n", Part->Mount_Options.c_str()); |
Ethan Yonker | 726a020 | 2014-12-16 20:01:38 -0600 | [diff] [blame] | 335 | if (Part->MTP_Storage_ID) |
| 336 | printf(" MTP_Storage_ID: %i\n", Part->MTP_Storage_ID); |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 337 | printf("\n"); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 338 | } |
| 339 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 340 | int TWPartitionManager::Mount_By_Path(string Path, bool Display_Error) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 341 | std::vector<TWPartition*>::iterator iter; |
| 342 | int ret = false; |
| 343 | bool found = false; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 344 | string Local_Path = TWFunc::Get_Root_Path(Path); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 345 | |
Dees_Troy | d93bda5 | 2013-07-03 19:55:19 +0000 | [diff] [blame] | 346 | if (Local_Path == "/tmp" || Local_Path == "/") |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 347 | return true; |
| 348 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 349 | // Iterate through all partitions |
| 350 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 351 | if ((*iter)->Mount_Point == Local_Path || (!(*iter)->Symlink_Mount_Point.empty() && (*iter)->Symlink_Mount_Point == Local_Path)) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 352 | ret = (*iter)->Mount(Display_Error); |
| 353 | found = true; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 354 | } else if ((*iter)->Is_SubPartition && (*iter)->SubPartition_Of == Local_Path) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 355 | (*iter)->Mount(Display_Error); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 356 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 357 | } |
| 358 | if (found) { |
| 359 | return ret; |
| 360 | } else if (Display_Error) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 361 | gui_msg(Msg(msg::kError, "unable_find_part_path=Unable to find partition for path '{1}'")(Local_Path)); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 362 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 363 | LOGINFO("Mount: Unable to find partition for path '%s'\n", Local_Path.c_str()); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 364 | } |
| 365 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 366 | } |
| 367 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 368 | int TWPartitionManager::UnMount_By_Path(string Path, bool Display_Error) { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 369 | std::vector<TWPartition*>::iterator iter; |
| 370 | int ret = false; |
| 371 | bool found = false; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 372 | string Local_Path = TWFunc::Get_Root_Path(Path); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 373 | |
| 374 | // Iterate through all partitions |
| 375 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 376 | if ((*iter)->Mount_Point == Local_Path || (!(*iter)->Symlink_Mount_Point.empty() && (*iter)->Symlink_Mount_Point == Local_Path)) { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 377 | ret = (*iter)->UnMount(Display_Error); |
| 378 | found = true; |
| 379 | } else if ((*iter)->Is_SubPartition && (*iter)->SubPartition_Of == Local_Path) { |
| 380 | (*iter)->UnMount(Display_Error); |
| 381 | } |
| 382 | } |
| 383 | if (found) { |
| 384 | return ret; |
| 385 | } else if (Display_Error) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 386 | gui_msg(Msg(msg::kError, "unable_find_part_path=Unable to find partition for path '{1}'")(Local_Path)); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 387 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 388 | LOGINFO("UnMount: Unable to find partition for path '%s'\n", Local_Path.c_str()); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 389 | } |
| 390 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 391 | } |
| 392 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 393 | int TWPartitionManager::Is_Mounted_By_Path(string Path) { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 394 | TWPartition* Part = Find_Partition_By_Path(Path); |
| 395 | |
| 396 | if (Part) |
| 397 | return Part->Is_Mounted(); |
| 398 | else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 399 | LOGINFO("Is_Mounted: Unable to find partition for path '%s'\n", Path.c_str()); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 400 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 401 | } |
| 402 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 403 | int TWPartitionManager::Mount_Current_Storage(bool Display_Error) { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 404 | string current_storage_path = DataManager::GetCurrentStoragePath(); |
| 405 | |
| 406 | if (Mount_By_Path(current_storage_path, Display_Error)) { |
| 407 | TWPartition* FreeStorage = Find_Partition_By_Path(current_storage_path); |
| 408 | if (FreeStorage) |
| 409 | DataManager::SetValue(TW_STORAGE_FREE_SIZE, (int)(FreeStorage->Free / 1048576LLU)); |
| 410 | return true; |
| 411 | } |
| 412 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 413 | } |
| 414 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 415 | int TWPartitionManager::Mount_Settings_Storage(bool Display_Error) { |
| 416 | return Mount_By_Path(DataManager::GetSettingsStoragePath(), Display_Error); |
| 417 | } |
| 418 | |
| 419 | TWPartition* TWPartitionManager::Find_Partition_By_Path(string Path) { |
| 420 | std::vector<TWPartition*>::iterator iter; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 421 | string Local_Path = TWFunc::Get_Root_Path(Path); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 422 | |
| 423 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 424 | if ((*iter)->Mount_Point == Local_Path || (!(*iter)->Symlink_Mount_Point.empty() && (*iter)->Symlink_Mount_Point == Local_Path)) |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 425 | return (*iter); |
| 426 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 427 | return NULL; |
| 428 | } |
| 429 | |
Dees_Troy | c9ff7a3 | 2012-09-27 10:09:41 -0400 | [diff] [blame] | 430 | int TWPartitionManager::Check_Backup_Name(bool Display_Error) { |
| 431 | // Check the backup name to ensure that it is the correct size and contains only valid characters |
| 432 | // and that a backup with that name doesn't already exist |
| 433 | char backup_name[MAX_BACKUP_NAME_LEN]; |
| 434 | char backup_loc[255], tw_image_dir[255]; |
| 435 | int copy_size; |
| 436 | int index, cur_char; |
| 437 | string Backup_Name, Backup_Loc; |
| 438 | |
| 439 | DataManager::GetValue(TW_BACKUP_NAME, Backup_Name); |
| 440 | copy_size = Backup_Name.size(); |
| 441 | // Check size |
| 442 | if (copy_size > MAX_BACKUP_NAME_LEN) { |
| 443 | if (Display_Error) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 444 | gui_err("backup_name_len=Backup name is too long."); |
Dees_Troy | c9ff7a3 | 2012-09-27 10:09:41 -0400 | [diff] [blame] | 445 | return -2; |
| 446 | } |
| 447 | |
| 448 | // Check each character |
| 449 | strncpy(backup_name, Backup_Name.c_str(), copy_size); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 450 | if (copy_size == 1 && strncmp(backup_name, "0", 1) == 0) |
Dees_Troy | c9ff7a3 | 2012-09-27 10:09:41 -0400 | [diff] [blame] | 451 | return 0; // A "0" (zero) means to use the current timestamp for the backup name |
| 452 | for (index=0; index<copy_size; index++) { |
| 453 | cur_char = (int)backup_name[index]; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 454 | if (cur_char == 32 || (cur_char >= 48 && cur_char <= 57) || (cur_char >= 65 && cur_char <= 91) || cur_char == 93 || cur_char == 95 || (cur_char >= 97 && cur_char <= 123) || cur_char == 125 || cur_char == 45 || cur_char == 46) { |
Dees_Troy | c9ff7a3 | 2012-09-27 10:09:41 -0400 | [diff] [blame] | 455 | // These are valid characters |
| 456 | // Numbers |
| 457 | // Upper case letters |
| 458 | // Lower case letters |
| 459 | // Space |
| 460 | // and -_.{}[] |
| 461 | } else { |
| 462 | if (Display_Error) |
Ethan Yonker | 4adc33e | 2016-01-22 16:07:11 -0600 | [diff] [blame] | 463 | gui_msg(Msg(msg::kError, "backup_name_invalid=Backup name '{1}' contains invalid character: '{1}'")(Backup_Name)((char)cur_char)); |
Dees_Troy | c9ff7a3 | 2012-09-27 10:09:41 -0400 | [diff] [blame] | 464 | return -3; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | // Check to make sure that a backup with this name doesn't already exist |
| 469 | DataManager::GetValue(TW_BACKUPS_FOLDER_VAR, Backup_Loc); |
| 470 | strcpy(backup_loc, Backup_Loc.c_str()); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 471 | sprintf(tw_image_dir,"%s/%s", backup_loc, Backup_Name.c_str()); |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 472 | if (TWFunc::Path_Exists(tw_image_dir)) { |
Dees_Troy | c9ff7a3 | 2012-09-27 10:09:41 -0400 | [diff] [blame] | 473 | if (Display_Error) |
Matt Mower | 3c36697 | 2015-12-25 19:28:31 -0600 | [diff] [blame] | 474 | gui_err("backup_name_exists=A backup with that name already exists!"); |
Dees_Troy | c9ff7a3 | 2012-09-27 10:09:41 -0400 | [diff] [blame] | 475 | return -4; |
| 476 | } |
Dees_Troy | c9ff7a3 | 2012-09-27 10:09:41 -0400 | [diff] [blame] | 477 | // No problems found, return 0 |
| 478 | return 0; |
| 479 | } |
| 480 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 481 | bool TWPartitionManager::Make_MD5(bool generate_md5, string Backup_Folder, string Backup_Filename) |
| 482 | { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 483 | string command; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 484 | string Full_File = Backup_Folder + Backup_Filename; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 485 | string result; |
bigbiff bigbiff | cdcfee4 | 2013-02-27 21:11:26 -0500 | [diff] [blame] | 486 | twrpDigest md5sum; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 487 | |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 488 | if (!generate_md5) |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 489 | return true; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 490 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 491 | TWFunc::GUI_Operation_Text(TW_GENERATE_MD5_TEXT, gui_parse_text("{@generating_md51}")); |
| 492 | gui_msg("generating_md52= * Generating md5..."); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 493 | |
| 494 | if (TWFunc::Path_Exists(Full_File)) { |
bigbiff bigbiff | cdcfee4 | 2013-02-27 21:11:26 -0500 | [diff] [blame] | 495 | md5sum.setfn(Backup_Folder + Backup_Filename); |
| 496 | if (md5sum.computeMD5() == 0) |
| 497 | if (md5sum.write_md5digest() == 0) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 498 | gui_msg("md5_created= * MD5 Created."); |
bigbiff bigbiff | cdcfee4 | 2013-02-27 21:11:26 -0500 | [diff] [blame] | 499 | else |
| 500 | return -1; |
| 501 | else |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 502 | gui_err("md5_error= * MD5 Error!"); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 503 | } else { |
| 504 | char filename[512]; |
| 505 | int index = 0; |
bigbiff bigbiff | cdcfee4 | 2013-02-27 21:11:26 -0500 | [diff] [blame] | 506 | string strfn; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 507 | sprintf(filename, "%s%03i", Full_File.c_str(), index); |
bigbiff bigbiff | cdcfee4 | 2013-02-27 21:11:26 -0500 | [diff] [blame] | 508 | strfn = filename; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 509 | while (index < 1000) { |
bigbiff bigbiff | 65a4c73 | 2013-03-15 15:17:50 -0400 | [diff] [blame] | 510 | md5sum.setfn(filename); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 511 | if (TWFunc::Path_Exists(filename)) { |
| 512 | if (md5sum.computeMD5() == 0) { |
| 513 | if (md5sum.write_md5digest() != 0) |
| 514 | { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 515 | gui_err("md5_error= * MD5 Error!"); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 516 | return false; |
| 517 | } |
| 518 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 519 | gui_err("md5_compute_error= * Error computing MD5."); |
bigbiff bigbiff | cdcfee4 | 2013-02-27 21:11:26 -0500 | [diff] [blame] | 520 | return false; |
| 521 | } |
| 522 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 523 | index++; |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 524 | sprintf(filename, "%s%03i", Full_File.c_str(), index); |
bigbiff bigbiff | cdcfee4 | 2013-02-27 21:11:26 -0500 | [diff] [blame] | 525 | strfn = filename; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 526 | } |
| 527 | if (index == 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 528 | LOGERR("Backup file: '%s' not found!\n", filename); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 529 | return false; |
| 530 | } |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 531 | gui_msg("md5_created= * MD5 Created."); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 532 | } |
| 533 | return true; |
| 534 | } |
| 535 | |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 536 | bool TWPartitionManager::Backup_Partition(TWPartition* Part, const string& Backup_Folder, bool generate_md5, unsigned long *img_time, unsigned long *file_time, ProgressTracking *progress) { |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 537 | time_t start, stop; |
that | 203bcc9 | 2015-05-09 17:27:33 +0200 | [diff] [blame] | 538 | int use_compression; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 539 | |
bigbiff | bf1d672 | 2015-02-14 16:25:59 -0500 | [diff] [blame] | 540 | string backup_log = Backup_Folder + "recovery.log"; |
| 541 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 542 | if (Part == NULL) |
| 543 | return true; |
| 544 | |
Dees_Troy | 093b764 | 2012-09-21 15:59:38 -0400 | [diff] [blame] | 545 | DataManager::GetValue(TW_USE_COMPRESSION_VAR, use_compression); |
Dees_Troy | 093b764 | 2012-09-21 15:59:38 -0400 | [diff] [blame] | 546 | |
Tom Hite | 5a92672 | 2014-09-15 01:31:03 +0000 | [diff] [blame] | 547 | TWFunc::SetPerformanceMode(true); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 548 | time(&start); |
| 549 | |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 550 | if (Part->Backup(Backup_Folder, tar_fork_pid, progress)) { |
Tom Hite | 5a92672 | 2014-09-15 01:31:03 +0000 | [diff] [blame] | 551 | bool md5Success = false; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 552 | if (Part->Has_SubPartition) { |
| 553 | std::vector<TWPartition*>::iterator subpart; |
| 554 | |
| 555 | for (subpart = Partitions.begin(); subpart != Partitions.end(); subpart++) { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 556 | if ((*subpart)->Can_Be_Backed_Up && (*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == Part->Mount_Point) { |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 557 | if (!(*subpart)->Backup(Backup_Folder, tar_fork_pid, progress)) { |
Tom Hite | 5a92672 | 2014-09-15 01:31:03 +0000 | [diff] [blame] | 558 | TWFunc::SetPerformanceMode(false); |
bigbiff | bf1d672 | 2015-02-14 16:25:59 -0500 | [diff] [blame] | 559 | Clean_Backup_Folder(Backup_Folder); |
| 560 | TWFunc::copy_file("/tmp/recovery.log", backup_log, 0644); |
| 561 | tw_set_default_metadata(backup_log.c_str()); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 562 | return false; |
Tom Hite | 5a92672 | 2014-09-15 01:31:03 +0000 | [diff] [blame] | 563 | } |
Dees_Troy | 2727b99 | 2013-08-14 20:09:30 +0000 | [diff] [blame] | 564 | sync(); |
| 565 | sync(); |
Tom Hite | 5a92672 | 2014-09-15 01:31:03 +0000 | [diff] [blame] | 566 | if (!Make_MD5(generate_md5, Backup_Folder, (*subpart)->Backup_FileName)) { |
| 567 | TWFunc::SetPerformanceMode(false); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 568 | return false; |
Tom Hite | 5a92672 | 2014-09-15 01:31:03 +0000 | [diff] [blame] | 569 | } |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 573 | time(&stop); |
that | 203bcc9 | 2015-05-09 17:27:33 +0200 | [diff] [blame] | 574 | int backup_time = (int) difftime(stop, start); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 575 | LOGINFO("Partition Backup time: %d\n", backup_time); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 576 | if (Part->Backup_Method == 1) { |
Dees_Troy | 093b764 | 2012-09-21 15:59:38 -0400 | [diff] [blame] | 577 | *file_time += backup_time; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 578 | } else { |
Dees_Troy | 093b764 | 2012-09-21 15:59:38 -0400 | [diff] [blame] | 579 | *img_time += backup_time; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 580 | } |
Tom Hite | 5a92672 | 2014-09-15 01:31:03 +0000 | [diff] [blame] | 581 | |
| 582 | md5Success = Make_MD5(generate_md5, Backup_Folder, Part->Backup_FileName); |
| 583 | TWFunc::SetPerformanceMode(false); |
| 584 | return md5Success; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 585 | } else { |
bigbiff | bf1d672 | 2015-02-14 16:25:59 -0500 | [diff] [blame] | 586 | Clean_Backup_Folder(Backup_Folder); |
| 587 | TWFunc::copy_file("/tmp/recovery.log", backup_log, 0644); |
| 588 | tw_set_default_metadata(backup_log.c_str()); |
Tom Hite | 5a92672 | 2014-09-15 01:31:03 +0000 | [diff] [blame] | 589 | TWFunc::SetPerformanceMode(false); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 590 | return false; |
| 591 | } |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 592 | return 0; |
| 593 | } |
| 594 | |
bigbiff | bf1d672 | 2015-02-14 16:25:59 -0500 | [diff] [blame] | 595 | void TWPartitionManager::Clean_Backup_Folder(string Backup_Folder) { |
| 596 | DIR *d = opendir(Backup_Folder.c_str()); |
| 597 | struct dirent *p; |
| 598 | int r; |
| 599 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 600 | gui_msg("backup_clean=Backup Failed. Cleaning Backup Folder."); |
bigbiff | bf1d672 | 2015-02-14 16:25:59 -0500 | [diff] [blame] | 601 | |
| 602 | if (d == NULL) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 603 | gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(Backup_Folder)(strerror(errno))); |
bigbiff | bf1d672 | 2015-02-14 16:25:59 -0500 | [diff] [blame] | 604 | return; |
| 605 | } |
| 606 | |
Matt Mower | 2b18a53 | 2015-02-20 16:58:05 -0600 | [diff] [blame] | 607 | while ((p = readdir(d))) { |
bigbiff | bf1d672 | 2015-02-14 16:25:59 -0500 | [diff] [blame] | 608 | if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) |
| 609 | continue; |
| 610 | |
| 611 | string path = Backup_Folder + p->d_name; |
| 612 | |
| 613 | size_t dot = path.find_last_of(".") + 1; |
| 614 | if (path.substr(dot) == "win" || path.substr(dot) == "md5" || path.substr(dot) == "info") { |
| 615 | r = unlink(path.c_str()); |
| 616 | if (r != 0) { |
| 617 | LOGINFO("Unable to unlink '%s: %s'\n", path.c_str(), strerror(errno)); |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | closedir(d); |
| 622 | } |
| 623 | |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 624 | int TWPartitionManager::Check_Backup_Cancel() { |
| 625 | return stop_backup.get_value(); |
| 626 | } |
| 627 | |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 628 | int TWPartitionManager::Cancel_Backup() { |
| 629 | string Backup_Folder, Backup_Name, Full_Backup_Path; |
| 630 | |
| 631 | stop_backup.set_value(1); |
| 632 | |
| 633 | if (tar_fork_pid != 0) { |
| 634 | DataManager::GetValue(TW_BACKUP_NAME, Backup_Name); |
| 635 | DataManager::GetValue(TW_BACKUPS_FOLDER_VAR, Backup_Folder); |
| 636 | Full_Backup_Path = Backup_Folder + "/" + Backup_Name + "/"; |
| 637 | LOGINFO("Killing pid: %d\n", tar_fork_pid); |
| 638 | kill(tar_fork_pid, SIGUSR2); |
| 639 | while (kill(tar_fork_pid, 0) == 0) { |
| 640 | usleep(1000); |
| 641 | } |
| 642 | LOGINFO("Backup_Run stopped and returning false, backup cancelled.\n"); |
| 643 | LOGINFO("Removing directory %s\n", Full_Backup_Path.c_str()); |
| 644 | TWFunc::removeDir(Full_Backup_Path, false); |
| 645 | tar_fork_pid = 0; |
| 646 | } |
| 647 | |
| 648 | return 0; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | int TWPartitionManager::Run_Backup(void) { |
Matt Mower | 2b18a53 | 2015-02-20 16:58:05 -0600 | [diff] [blame] | 652 | int check, do_md5, partition_count = 0, disable_free_space_check = 0; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 653 | string Backup_Folder, Backup_Name, Full_Backup_Path, Backup_List, backup_path; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 654 | unsigned long long total_bytes = 0, file_bytes = 0, img_bytes = 0, free_space = 0, img_bytes_remaining, file_bytes_remaining, subpart_size; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 655 | unsigned long img_time = 0, file_time = 0; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 656 | TWPartition* backup_part = NULL; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 657 | TWPartition* storage = NULL; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 658 | std::vector<TWPartition*>::iterator subpart; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 659 | struct tm *t; |
| 660 | time_t start, stop, seconds, total_start, total_stop; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 661 | size_t start_pos = 0, end_pos = 0; |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 662 | stop_backup.set_value(0); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 663 | seconds = time(0); |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 664 | t = localtime(&seconds); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 665 | |
| 666 | time(&total_start); |
| 667 | |
| 668 | Update_System_Details(); |
| 669 | |
| 670 | if (!Mount_Current_Storage(true)) |
| 671 | return false; |
| 672 | |
| 673 | DataManager::GetValue(TW_SKIP_MD5_GENERATE_VAR, do_md5); |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 674 | if (do_md5 == 0) |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 675 | do_md5 = true; |
Dees_Troy | c5865ab | 2012-09-24 15:08:04 -0400 | [diff] [blame] | 676 | else |
| 677 | do_md5 = false; |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 678 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 679 | DataManager::GetValue(TW_BACKUPS_FOLDER_VAR, Backup_Folder); |
| 680 | DataManager::GetValue(TW_BACKUP_NAME, Backup_Name); |
Ethan Yonker | 4adc33e | 2016-01-22 16:07:11 -0600 | [diff] [blame] | 681 | if (Backup_Name == gui_lookup("curr_date", "(Current Date)")) { |
Dees Troy | b21cc64 | 2013-09-10 17:36:41 +0000 | [diff] [blame] | 682 | Backup_Name = TWFunc::Get_Current_Date(); |
Ethan Yonker | 4adc33e | 2016-01-22 16:07:11 -0600 | [diff] [blame] | 683 | } else if (Backup_Name == gui_lookup("auto_generate", "(Auto Generate)") || Backup_Name == "0" || Backup_Name.empty()) { |
Dees Troy | b21cc64 | 2013-09-10 17:36:41 +0000 | [diff] [blame] | 684 | TWFunc::Auto_Generate_Backup_Name(); |
| 685 | DataManager::GetValue(TW_BACKUP_NAME, Backup_Name); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 686 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 687 | LOGINFO("Backup Name is: '%s'\n", Backup_Name.c_str()); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 688 | Full_Backup_Path = Backup_Folder + "/" + Backup_Name + "/"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 689 | LOGINFO("Full_Backup_Path is: '%s'\n", Full_Backup_Path.c_str()); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 690 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 691 | LOGINFO("Calculating backup details...\n"); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 692 | DataManager::GetValue("tw_backup_list", Backup_List); |
| 693 | if (!Backup_List.empty()) { |
| 694 | end_pos = Backup_List.find(";", start_pos); |
| 695 | while (end_pos != string::npos && start_pos < Backup_List.size()) { |
| 696 | backup_path = Backup_List.substr(start_pos, end_pos - start_pos); |
| 697 | backup_part = Find_Partition_By_Path(backup_path); |
| 698 | if (backup_part != NULL) { |
| 699 | partition_count++; |
| 700 | if (backup_part->Backup_Method == 1) |
| 701 | file_bytes += backup_part->Backup_Size; |
| 702 | else |
| 703 | img_bytes += backup_part->Backup_Size; |
| 704 | if (backup_part->Has_SubPartition) { |
| 705 | std::vector<TWPartition*>::iterator subpart; |
| 706 | |
| 707 | for (subpart = Partitions.begin(); subpart != Partitions.end(); subpart++) { |
Dees_Troy | 9e0b71c | 2013-04-08 13:35:37 +0000 | [diff] [blame] | 708 | if ((*subpart)->Can_Be_Backed_Up && (*subpart)->Is_Present && (*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == backup_part->Mount_Point) { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 709 | partition_count++; |
| 710 | if ((*subpart)->Backup_Method == 1) |
| 711 | file_bytes += (*subpart)->Backup_Size; |
| 712 | else |
| 713 | img_bytes += (*subpart)->Backup_Size; |
| 714 | } |
| 715 | } |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 716 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 717 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 718 | gui_msg(Msg(msg::kError, "unable_to_locate_partition=Unable to locate '{1}' partition for backup calculations.")(backup_path)); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 719 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 720 | start_pos = end_pos + 1; |
| 721 | end_pos = Backup_List.find(";", start_pos); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 722 | } |
| 723 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 724 | |
| 725 | if (partition_count == 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 726 | gui_msg("no_partition_selected=No partitions selected for backup."); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 727 | return false; |
| 728 | } |
| 729 | total_bytes = file_bytes + img_bytes; |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 730 | ProgressTracking progress(total_bytes); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 731 | gui_msg(Msg("total_partitions_backup= * Total number of partitions to back up: {1}")(partition_count)); |
| 732 | gui_msg(Msg("total_backup_size= * Total size of all data: {1}MB")(total_bytes / 1024 / 1024)); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 733 | storage = Find_Partition_By_Path(DataManager::GetCurrentStoragePath()); |
| 734 | if (storage != NULL) { |
| 735 | free_space = storage->Free; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 736 | gui_msg(Msg("available_space= * Available space: {1}MB")(free_space / 1024 / 1024)); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 737 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 738 | gui_err("unable_locate_storage=Unable to locate storage device."); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 739 | return false; |
| 740 | } |
bigbiff | bf1d672 | 2015-02-14 16:25:59 -0500 | [diff] [blame] | 741 | |
| 742 | DataManager::GetValue("tw_disable_free_space", disable_free_space_check); |
| 743 | if (!disable_free_space_check) { |
| 744 | if (free_space - (32 * 1024 * 1024) < total_bytes) { |
| 745 | // We require an extra 32MB just in case |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 746 | gui_err("no_space=Not enough free space on storage."); |
bigbiff | bf1d672 | 2015-02-14 16:25:59 -0500 | [diff] [blame] | 747 | return false; |
| 748 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 749 | } |
| 750 | img_bytes_remaining = img_bytes; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 751 | file_bytes_remaining = file_bytes; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 752 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 753 | gui_msg("backup_started=[BACKUP STARTED]"); |
| 754 | gui_msg(Msg("backup_folder= * Backup Folder: {1}")(Full_Backup_Path)); |
Dees_Troy | d4b22b0 | 2013-01-18 17:17:58 +0000 | [diff] [blame] | 755 | if (!TWFunc::Recursive_Mkdir(Full_Backup_Path)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 756 | gui_err("fail_backup_folder=Failed to make backup folder."); |
Dees_Troy | d4b22b0 | 2013-01-18 17:17:58 +0000 | [diff] [blame] | 757 | return false; |
| 758 | } |
| 759 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 760 | DataManager::SetProgress(0.0); |
Dees_Troy | 093b764 | 2012-09-21 15:59:38 -0400 | [diff] [blame] | 761 | |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 762 | start_pos = 0; |
| 763 | end_pos = Backup_List.find(";", start_pos); |
| 764 | while (end_pos != string::npos && start_pos < Backup_List.size()) { |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 765 | if (stop_backup.get_value() != 0) |
| 766 | return -1; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 767 | backup_path = Backup_List.substr(start_pos, end_pos - start_pos); |
| 768 | backup_part = Find_Partition_By_Path(backup_path); |
| 769 | if (backup_part != NULL) { |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 770 | if (!Backup_Partition(backup_part, Full_Backup_Path, do_md5, &img_time, &file_time, &progress)) |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 771 | return false; |
| 772 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 773 | gui_msg(Msg(msg::kError, "unable_to_locate_partition=Unable to locate '{1}' partition for backup calculations.")(backup_path)); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 774 | } |
| 775 | start_pos = end_pos + 1; |
| 776 | end_pos = Backup_List.find(";", start_pos); |
| 777 | } |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 778 | |
| 779 | // Average BPS |
| 780 | if (img_time == 0) |
| 781 | img_time = 1; |
| 782 | if (file_time == 0) |
| 783 | file_time = 1; |
Dees_Troy | 093b764 | 2012-09-21 15:59:38 -0400 | [diff] [blame] | 784 | int img_bps = (int)img_bytes / (int)img_time; |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 785 | unsigned long long file_bps = file_bytes / (int)file_time; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 786 | |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 787 | if (file_bytes != 0) |
| 788 | gui_msg(Msg("avg_backup_fs=Average backup rate for file systems: {1} MB/sec")(file_bps / (1024 * 1024))); |
| 789 | if (img_bytes != 0) |
| 790 | gui_msg(Msg("avg_backup_img=Average backup rate for imaged drives: {1} MB/sec")(img_bps / (1024 * 1024))); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 791 | |
| 792 | time(&total_stop); |
| 793 | int total_time = (int) difftime(total_stop, total_start); |
bigbiff bigbiff | 34684ff | 2013-12-01 21:03:45 -0500 | [diff] [blame] | 794 | uint64_t actual_backup_size = du.Get_Folder_Size(Full_Backup_Path); |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 795 | actual_backup_size /= (1024LLU * 1024LLU); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 796 | |
bigbiff bigbiff | 2c57d78 | 2013-02-19 10:09:21 -0500 | [diff] [blame] | 797 | int prev_img_bps, use_compression; |
| 798 | unsigned long long prev_file_bps; |
Dees_Troy | 093b764 | 2012-09-21 15:59:38 -0400 | [diff] [blame] | 799 | DataManager::GetValue(TW_BACKUP_AVG_IMG_RATE, prev_img_bps); |
| 800 | img_bps += (prev_img_bps * 4); |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 801 | img_bps /= 5; |
Dees_Troy | 093b764 | 2012-09-21 15:59:38 -0400 | [diff] [blame] | 802 | |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 803 | DataManager::GetValue(TW_USE_COMPRESSION_VAR, use_compression); |
Dees_Troy | 093b764 | 2012-09-21 15:59:38 -0400 | [diff] [blame] | 804 | if (use_compression) |
| 805 | DataManager::GetValue(TW_BACKUP_AVG_FILE_COMP_RATE, prev_file_bps); |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 806 | else |
Dees_Troy | 093b764 | 2012-09-21 15:59:38 -0400 | [diff] [blame] | 807 | DataManager::GetValue(TW_BACKUP_AVG_FILE_RATE, prev_file_bps); |
| 808 | file_bps += (prev_file_bps * 4); |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 809 | file_bps /= 5; |
Dees_Troy | 093b764 | 2012-09-21 15:59:38 -0400 | [diff] [blame] | 810 | |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 811 | DataManager::SetValue(TW_BACKUP_AVG_IMG_RATE, img_bps); |
Dees_Troy | 093b764 | 2012-09-21 15:59:38 -0400 | [diff] [blame] | 812 | if (use_compression) |
| 813 | DataManager::SetValue(TW_BACKUP_AVG_FILE_COMP_RATE, file_bps); |
| 814 | else |
| 815 | DataManager::SetValue(TW_BACKUP_AVG_FILE_RATE, file_bps); |
| 816 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 817 | gui_msg(Msg("total_backed_size=[{1} MB TOTAL BACKED UP]")(actual_backup_size)); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 818 | Update_System_Details(); |
Dees_Troy | d0384ef | 2012-10-12 12:15:42 -0400 | [diff] [blame] | 819 | UnMount_Main_Partitions(); |
Ethan Yonker | 56db1c4 | 2015-12-20 22:49:00 -0600 | [diff] [blame] | 820 | gui_msg(Msg(msg::kHighlight, "backup_completed=[BACKUP COMPLETED IN {1} SECONDS]")(total_time)); // the end |
Dees_Troy | 3f5c4e8 | 2013-02-01 15:16:59 +0000 | [diff] [blame] | 821 | string backup_log = Full_Backup_Path + "recovery.log"; |
| 822 | TWFunc::copy_file("/tmp/recovery.log", backup_log, 0644); |
Ethan Yonker | 4b94cfd | 2014-12-11 10:00:45 -0600 | [diff] [blame] | 823 | tw_set_default_metadata(backup_log.c_str()); |
Dees_Troy | 3f5c4e8 | 2013-02-01 15:16:59 +0000 | [diff] [blame] | 824 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 825 | } |
| 826 | |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 827 | bool TWPartitionManager::Restore_Partition(TWPartition* Part, const string& Restore_Name, ProgressTracking *progress) { |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 828 | time_t Start, Stop; |
Tom Hite | 5a92672 | 2014-09-15 01:31:03 +0000 | [diff] [blame] | 829 | TWFunc::SetPerformanceMode(true); |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 830 | time(&Start); |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 831 | |
| 832 | if (!Part->Restore(Restore_Name, progress)) { |
Tom Hite | 5a92672 | 2014-09-15 01:31:03 +0000 | [diff] [blame] | 833 | TWFunc::SetPerformanceMode(false); |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 834 | return false; |
Tom Hite | 5a92672 | 2014-09-15 01:31:03 +0000 | [diff] [blame] | 835 | } |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 836 | if (Part->Has_SubPartition) { |
| 837 | std::vector<TWPartition*>::iterator subpart; |
| 838 | |
| 839 | for (subpart = Partitions.begin(); subpart != Partitions.end(); subpart++) { |
| 840 | if ((*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == Part->Mount_Point) { |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 841 | if (!(*subpart)->Restore(Restore_Name, progress)) { |
Tom Hite | 5a92672 | 2014-09-15 01:31:03 +0000 | [diff] [blame] | 842 | TWFunc::SetPerformanceMode(false); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 843 | return false; |
Tom Hite | 5a92672 | 2014-09-15 01:31:03 +0000 | [diff] [blame] | 844 | } |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 845 | } |
| 846 | } |
| 847 | } |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 848 | time(&Stop); |
Tom Hite | 5a92672 | 2014-09-15 01:31:03 +0000 | [diff] [blame] | 849 | TWFunc::SetPerformanceMode(false); |
z31s1g | 2053fe0 | 2016-02-04 06:45:18 +0100 | [diff] [blame] | 850 | gui_msg(Msg("restore_part_done=[{1} done ({2} seconds)]")(Part->Backup_Display_Name)((int)difftime(Stop, Start))); |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 851 | return true; |
| 852 | } |
| 853 | |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 854 | int TWPartitionManager::Run_Restore(const string& Restore_Name) { |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 855 | int check_md5, check, partition_count = 0; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 856 | TWPartition* restore_part = NULL; |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 857 | time_t rStart, rStop; |
| 858 | time(&rStart); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 859 | string Restore_List, restore_path; |
| 860 | size_t start_pos = 0, end_pos; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 861 | unsigned long long total_restore_size = 0, already_restored_size = 0; |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 862 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 863 | gui_msg("restore_started=[RESTORE STARTED]"); |
| 864 | gui_msg(Msg("restore_folder=Restore folder: '{1}'")(Restore_Name)); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 865 | |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 866 | if (!Mount_Current_Storage(true)) |
| 867 | return false; |
| 868 | |
| 869 | DataManager::GetValue(TW_SKIP_MD5_CHECK_VAR, check_md5); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 870 | if (check_md5 > 0) { |
| 871 | // Check MD5 files first before restoring to ensure that all of them match before starting a restore |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 872 | TWFunc::GUI_Operation_Text(TW_VERIFY_MD5_TEXT, gui_parse_text("{@verifying_md5}")); |
| 873 | gui_msg("verifying_md5=Verifying MD5"); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 874 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 875 | gui_msg("skip_md5=Skipping MD5 check based on user setting."); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 876 | } |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 877 | gui_msg("calc_restore=Calculating restore details..."); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 878 | DataManager::GetValue("tw_restore_selected", Restore_List); |
| 879 | if (!Restore_List.empty()) { |
| 880 | end_pos = Restore_List.find(";", start_pos); |
| 881 | while (end_pos != string::npos && start_pos < Restore_List.size()) { |
| 882 | restore_path = Restore_List.substr(start_pos, end_pos - start_pos); |
| 883 | restore_part = Find_Partition_By_Path(restore_path); |
| 884 | if (restore_part != NULL) { |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 885 | if (restore_part->Mount_Read_Only) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 886 | gui_msg(Msg(msg::kError, "restore_read_only=Cannot restore {1} -- mounted read only.")(restore_part->Backup_Display_Name)); |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 887 | return false; |
| 888 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 889 | if (check_md5 > 0 && !restore_part->Check_MD5(Restore_Name)) |
| 890 | return false; |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 891 | partition_count++; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 892 | total_restore_size += restore_part->Get_Restore_Size(Restore_Name); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 893 | if (restore_part->Has_SubPartition) { |
| 894 | std::vector<TWPartition*>::iterator subpart; |
| 895 | |
| 896 | for (subpart = Partitions.begin(); subpart != Partitions.end(); subpart++) { |
| 897 | if ((*subpart)->Is_SubPartition && (*subpart)->SubPartition_Of == restore_part->Mount_Point) { |
bigbiff bigbiff | 0733881 | 2014-03-30 14:56:41 -0400 | [diff] [blame] | 898 | if (check_md5 > 0 && !(*subpart)->Check_MD5(Restore_Name)) |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 899 | return false; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 900 | total_restore_size += (*subpart)->Get_Restore_Size(Restore_Name); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | } |
| 904 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 905 | gui_msg(Msg(msg::kError, "restore_unable_locate=Unable to locate '{1}' partition for restoring.")(restore_path)); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 906 | } |
| 907 | start_pos = end_pos + 1; |
| 908 | end_pos = Restore_List.find(";", start_pos); |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 909 | } |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 910 | } |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 911 | |
| 912 | if (partition_count == 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 913 | gui_err("no_part_restore=No partitions selected for restore."); |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 914 | return false; |
| 915 | } |
| 916 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 917 | gui_msg(Msg("restore_part_count=Restoring {1} partitions...")(partition_count)); |
| 918 | gui_msg(Msg("total_restore_size=Total restore size is {1}MB")(total_restore_size / 1048576)); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 919 | DataManager::SetProgress(0.0); |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 920 | ProgressTracking progress(total_restore_size); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 921 | |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 922 | start_pos = 0; |
| 923 | if (!Restore_List.empty()) { |
| 924 | end_pos = Restore_List.find(";", start_pos); |
| 925 | while (end_pos != string::npos && start_pos < Restore_List.size()) { |
| 926 | restore_path = Restore_List.substr(start_pos, end_pos - start_pos); |
| 927 | restore_part = Find_Partition_By_Path(restore_path); |
| 928 | if (restore_part != NULL) { |
| 929 | partition_count++; |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 930 | if (!Restore_Partition(restore_part, Restore_Name, &progress)) |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 931 | return false; |
| 932 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 933 | gui_msg(Msg(msg::kError, "restore_unable_locate=Unable to locate '{1}' partition for restoring.")(restore_path)); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 934 | } |
| 935 | start_pos = end_pos + 1; |
| 936 | end_pos = Restore_List.find(";", start_pos); |
| 937 | } |
| 938 | } |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 939 | TWFunc::GUI_Operation_Text(TW_UPDATE_SYSTEM_DETAILS_TEXT, gui_parse_text("{@updating_system_details}")); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 940 | Update_System_Details(); |
Dees_Troy | d0384ef | 2012-10-12 12:15:42 -0400 | [diff] [blame] | 941 | UnMount_Main_Partitions(); |
Dees_Troy | 4a2a126 | 2012-09-18 09:33:47 -0400 | [diff] [blame] | 942 | time(&rStop); |
Matt Mower | 3c36697 | 2015-12-25 19:28:31 -0600 | [diff] [blame] | 943 | gui_msg(Msg(msg::kHighlight, "restore_completed=[RESTORE COMPLETED IN {1} SECONDS]")((int)difftime(rStop,rStart))); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 944 | DataManager::SetValue("tw_file_progress", ""); |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 945 | return true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | void TWPartitionManager::Set_Restore_Files(string Restore_Name) { |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 949 | // Start with the default values |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 950 | string Restore_List; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 951 | bool get_date = true, check_encryption = true; |
| 952 | |
| 953 | DataManager::SetValue("tw_restore_encrypted", 0); |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 954 | |
| 955 | DIR* d; |
| 956 | d = opendir(Restore_Name.c_str()); |
| 957 | if (d == NULL) |
| 958 | { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 959 | gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(Restore_Name)(strerror(errno))); |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 960 | return; |
| 961 | } |
| 962 | |
| 963 | struct dirent* de; |
| 964 | while ((de = readdir(d)) != NULL) |
| 965 | { |
| 966 | // Strip off three components |
| 967 | char str[256]; |
| 968 | char* label; |
| 969 | char* fstype = NULL; |
| 970 | char* extn = NULL; |
| 971 | char* ptr; |
| 972 | |
| 973 | strcpy(str, de->d_name); |
| 974 | if (strlen(str) <= 2) |
| 975 | continue; |
| 976 | |
| 977 | if (get_date) { |
| 978 | char file_path[255]; |
| 979 | struct stat st; |
| 980 | |
| 981 | strcpy(file_path, Restore_Name.c_str()); |
| 982 | strcat(file_path, "/"); |
| 983 | strcat(file_path, str); |
| 984 | stat(file_path, &st); |
| 985 | string backup_date = ctime((const time_t*)(&st.st_mtime)); |
| 986 | DataManager::SetValue(TW_RESTORE_FILE_DATE, backup_date); |
| 987 | get_date = false; |
| 988 | } |
| 989 | |
| 990 | label = str; |
| 991 | ptr = label; |
| 992 | while (*ptr && *ptr != '.') ptr++; |
| 993 | if (*ptr == '.') |
| 994 | { |
| 995 | *ptr = 0x00; |
| 996 | ptr++; |
| 997 | fstype = ptr; |
| 998 | } |
| 999 | while (*ptr && *ptr != '.') ptr++; |
| 1000 | if (*ptr == '.') |
| 1001 | { |
| 1002 | *ptr = 0x00; |
| 1003 | ptr++; |
| 1004 | extn = ptr; |
| 1005 | } |
| 1006 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1007 | if (fstype == NULL || extn == NULL || strcmp(fstype, "log") == 0) continue; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1008 | int extnlength = strlen(extn); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1009 | if (extnlength != 3 && extnlength != 6) continue; |
| 1010 | if (extnlength >= 3 && strncmp(extn, "win", 3) != 0) continue; |
| 1011 | //if (extnlength == 6 && strncmp(extn, "win000", 6) != 0) continue; |
| 1012 | |
| 1013 | if (check_encryption) { |
| 1014 | string filename = Restore_Name + "/"; |
| 1015 | filename += de->d_name; |
| 1016 | if (TWFunc::Get_File_Type(filename) == 2) { |
| 1017 | LOGINFO("'%s' is encrypted\n", filename.c_str()); |
| 1018 | DataManager::SetValue("tw_restore_encrypted", 1); |
| 1019 | } |
| 1020 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1021 | if (extnlength == 6 && strncmp(extn, "win000", 6) != 0) continue; |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 1022 | |
| 1023 | TWPartition* Part = Find_Partition_By_Path(label); |
| 1024 | if (Part == NULL) |
| 1025 | { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1026 | gui_msg(Msg(msg::kError, "unable_locate_part_backup_name=Unable to locate partition by backup name: '{1}'")(label)); |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 1027 | continue; |
| 1028 | } |
| 1029 | |
| 1030 | Part->Backup_FileName = de->d_name; |
| 1031 | if (strlen(extn) > 3) { |
| 1032 | Part->Backup_FileName.resize(Part->Backup_FileName.size() - strlen(extn) + 3); |
| 1033 | } |
| 1034 | |
James Christopher Adduono | fddbdfa | 2016-02-29 15:08:11 -0500 | [diff] [blame] | 1035 | if (!Part->Is_SubPartition) |
| 1036 | Restore_List += Part->Backup_Path + ";"; |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 1037 | } |
| 1038 | closedir(d); |
| 1039 | |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1040 | // Set the final value |
| 1041 | DataManager::SetValue("tw_restore_list", Restore_List); |
| 1042 | DataManager::SetValue("tw_restore_selected", Restore_List); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1043 | return; |
| 1044 | } |
| 1045 | |
| 1046 | int TWPartitionManager::Wipe_By_Path(string Path) { |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 1047 | std::vector<TWPartition*>::iterator iter; |
| 1048 | int ret = false; |
| 1049 | bool found = false; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1050 | string Local_Path = TWFunc::Get_Root_Path(Path); |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 1051 | |
| 1052 | // Iterate through all partitions |
| 1053 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 1054 | if ((*iter)->Mount_Point == Local_Path || (!(*iter)->Symlink_Mount_Point.empty() && (*iter)->Symlink_Mount_Point == Local_Path)) { |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1055 | if (Path == "/and-sec") |
| 1056 | ret = (*iter)->Wipe_AndSec(); |
| 1057 | else |
| 1058 | ret = (*iter)->Wipe(); |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 1059 | found = true; |
| 1060 | } else if ((*iter)->Is_SubPartition && (*iter)->SubPartition_Of == Local_Path) { |
| 1061 | (*iter)->Wipe(); |
| 1062 | } |
| 1063 | } |
| 1064 | if (found) { |
| 1065 | return ret; |
| 1066 | } else |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1067 | gui_msg(Msg(msg::kError, "unable_find_part_path=Unable to find partition for path '{1}'")(Local_Path)); |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 1068 | return false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1069 | } |
| 1070 | |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1071 | int TWPartitionManager::Wipe_By_Path(string Path, string New_File_System) { |
| 1072 | std::vector<TWPartition*>::iterator iter; |
| 1073 | int ret = false; |
| 1074 | bool found = false; |
| 1075 | string Local_Path = TWFunc::Get_Root_Path(Path); |
| 1076 | |
| 1077 | // Iterate through all partitions |
| 1078 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
| 1079 | if ((*iter)->Mount_Point == Local_Path || (!(*iter)->Symlink_Mount_Point.empty() && (*iter)->Symlink_Mount_Point == Local_Path)) { |
| 1080 | if (Path == "/and-sec") |
| 1081 | ret = (*iter)->Wipe_AndSec(); |
| 1082 | else |
| 1083 | ret = (*iter)->Wipe(New_File_System); |
| 1084 | found = true; |
| 1085 | } else if ((*iter)->Is_SubPartition && (*iter)->SubPartition_Of == Local_Path) { |
| 1086 | (*iter)->Wipe(New_File_System); |
| 1087 | } |
| 1088 | } |
| 1089 | if (found) { |
| 1090 | return ret; |
| 1091 | } else |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1092 | gui_msg(Msg(msg::kError, "unable_find_part_path=Unable to find partition for path '{1}'")(Local_Path)); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1093 | return false; |
| 1094 | } |
| 1095 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1096 | int TWPartitionManager::Factory_Reset(void) { |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 1097 | std::vector<TWPartition*>::iterator iter; |
| 1098 | int ret = true; |
| 1099 | |
| 1100 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1101 | if ((*iter)->Wipe_During_Factory_Reset && (*iter)->Is_Present) { |
Ethan Yonker | 89583ef | 2015-08-26 09:01:59 -0500 | [diff] [blame] | 1102 | #ifdef TW_OEM_BUILD |
| 1103 | if ((*iter)->Mount_Point == "/data") { |
| 1104 | if (!(*iter)->Wipe_Encryption()) |
| 1105 | ret = false; |
| 1106 | } else { |
| 1107 | #endif |
| 1108 | if (!(*iter)->Wipe()) |
| 1109 | ret = false; |
| 1110 | #ifdef TW_OEM_BUILD |
| 1111 | } |
| 1112 | #endif |
Dees_Troy | 094207a | 2012-09-26 12:00:39 -0400 | [diff] [blame] | 1113 | } else if ((*iter)->Has_Android_Secure) { |
| 1114 | if (!(*iter)->Wipe_AndSec()) |
| 1115 | ret = false; |
Dees_Troy | 63c8df7 | 2012-09-10 14:02:05 -0400 | [diff] [blame] | 1116 | } |
| 1117 | } |
| 1118 | return ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1119 | } |
| 1120 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1121 | int TWPartitionManager::Wipe_Dalvik_Cache(void) { |
| 1122 | struct stat st; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1123 | vector <string> dir; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1124 | |
| 1125 | if (!Mount_By_Path("/data", true)) |
| 1126 | return false; |
| 1127 | |
| 1128 | if (!Mount_By_Path("/cache", true)) |
| 1129 | return false; |
| 1130 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1131 | dir.push_back("/data/dalvik-cache"); |
| 1132 | dir.push_back("/cache/dalvik-cache"); |
| 1133 | dir.push_back("/cache/dc"); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1134 | gui_msg("wiping_dalvik=Wiping Dalvik Cache Directories..."); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1135 | for (unsigned i = 0; i < dir.size(); ++i) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1136 | if (stat(dir.at(i).c_str(), &st) == 0) { |
| 1137 | TWFunc::removeDir(dir.at(i), false); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1138 | gui_msg(Msg("cleaned=Cleaned: {1}...")(dir.at(i))); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1139 | } |
| 1140 | } |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1141 | TWPartition* sdext = Find_Partition_By_Path("/sd-ext"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1142 | if (sdext && sdext->Is_Present && sdext->Mount(false)) |
| 1143 | { |
| 1144 | if (stat("/sd-ext/dalvik-cache", &st) == 0) |
| 1145 | { |
| 1146 | TWFunc::removeDir("/sd-ext/dalvik-cache", false); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1147 | gui_msg(Msg("cleaned=Cleaned: {1}...")("/sd-ext/dalvik-cache")); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1148 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1149 | } |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1150 | gui_msg("dalvik_done=-- Dalvik Cache Directories Wipe Complete!"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1151 | return true; |
| 1152 | } |
| 1153 | |
| 1154 | int TWPartitionManager::Wipe_Rotate_Data(void) { |
| 1155 | if (!Mount_By_Path("/data", true)) |
| 1156 | return false; |
| 1157 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1158 | unlink("/data/misc/akmd*"); |
| 1159 | unlink("/data/misc/rild*"); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1160 | gui_print("Rotation data wiped.\n"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1161 | return true; |
| 1162 | } |
| 1163 | |
| 1164 | int TWPartitionManager::Wipe_Battery_Stats(void) { |
| 1165 | struct stat st; |
| 1166 | |
| 1167 | if (!Mount_By_Path("/data", true)) |
| 1168 | return false; |
| 1169 | |
| 1170 | if (0 != stat("/data/system/batterystats.bin", &st)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1171 | gui_print("No Battery Stats Found. No Need To Wipe.\n"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1172 | } else { |
| 1173 | remove("/data/system/batterystats.bin"); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1174 | gui_print("Cleared battery stats.\n"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1175 | } |
| 1176 | return true; |
| 1177 | } |
| 1178 | |
Dees_Troy | 2ff5a8d | 2012-09-26 14:53:02 -0400 | [diff] [blame] | 1179 | int TWPartitionManager::Wipe_Android_Secure(void) { |
| 1180 | std::vector<TWPartition*>::iterator iter; |
| 1181 | int ret = false; |
| 1182 | bool found = false; |
| 1183 | |
| 1184 | // Iterate through all partitions |
| 1185 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
| 1186 | if ((*iter)->Has_Android_Secure) { |
| 1187 | ret = (*iter)->Wipe_AndSec(); |
| 1188 | found = true; |
| 1189 | } |
| 1190 | } |
| 1191 | if (found) { |
| 1192 | return ret; |
| 1193 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1194 | gui_err("no_andsec=No android secure partitions found."); |
Dees_Troy | 2ff5a8d | 2012-09-26 14:53:02 -0400 | [diff] [blame] | 1195 | } |
| 1196 | return false; |
| 1197 | } |
| 1198 | |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1199 | int TWPartitionManager::Format_Data(void) { |
| 1200 | TWPartition* dat = Find_Partition_By_Path("/data"); |
| 1201 | |
| 1202 | if (dat != NULL) { |
| 1203 | if (!dat->UnMount(true)) |
| 1204 | return false; |
| 1205 | |
| 1206 | return dat->Wipe_Encryption(); |
| 1207 | } else { |
Matt Mower | 3c36697 | 2015-12-25 19:28:31 -0600 | [diff] [blame] | 1208 | gui_msg(Msg(msg::kError, "unable_to_locate=Unable to locate {1}.")("/data")); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1209 | return false; |
| 1210 | } |
| 1211 | return false; |
| 1212 | } |
| 1213 | |
| 1214 | int TWPartitionManager::Wipe_Media_From_Data(void) { |
| 1215 | TWPartition* dat = Find_Partition_By_Path("/data"); |
| 1216 | |
| 1217 | if (dat != NULL) { |
| 1218 | if (!dat->Has_Data_Media) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1219 | LOGERR("This device does not have /data/media\n"); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1220 | return false; |
| 1221 | } |
| 1222 | if (!dat->Mount(true)) |
| 1223 | return false; |
| 1224 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1225 | gui_msg("wiping_datamedia=Wiping internal storage -- /data/media..."); |
Ethan Yonker | 726a020 | 2014-12-16 20:01:38 -0600 | [diff] [blame] | 1226 | Remove_MTP_Storage(dat->MTP_Storage_ID); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1227 | TWFunc::removeDir("/data/media", false); |
xiaolu | 9416f4f | 2015-06-04 08:22:23 +0800 | [diff] [blame] | 1228 | dat->Recreate_Media_Folder(); |
Ethan Yonker | 726a020 | 2014-12-16 20:01:38 -0600 | [diff] [blame] | 1229 | Add_MTP_Storage(dat->MTP_Storage_ID); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1230 | return true; |
| 1231 | } else { |
Matt Mower | 3c36697 | 2015-12-25 19:28:31 -0600 | [diff] [blame] | 1232 | gui_msg(Msg(msg::kError, "unable_to_locate=Unable to locate {1}.")("/data")); |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1233 | return false; |
| 1234 | } |
| 1235 | return false; |
| 1236 | } |
| 1237 | |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1238 | int TWPartitionManager::Repair_By_Path(string Path, bool Display_Error) { |
| 1239 | std::vector<TWPartition*>::iterator iter; |
| 1240 | int ret = false; |
| 1241 | bool found = false; |
| 1242 | string Local_Path = TWFunc::Get_Root_Path(Path); |
| 1243 | |
| 1244 | if (Local_Path == "/tmp" || Local_Path == "/") |
| 1245 | return true; |
| 1246 | |
| 1247 | // Iterate through all partitions |
| 1248 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
| 1249 | if ((*iter)->Mount_Point == Local_Path || (!(*iter)->Symlink_Mount_Point.empty() && (*iter)->Symlink_Mount_Point == Local_Path)) { |
| 1250 | ret = (*iter)->Repair(); |
| 1251 | found = true; |
| 1252 | } else if ((*iter)->Is_SubPartition && (*iter)->SubPartition_Of == Local_Path) { |
| 1253 | (*iter)->Repair(); |
| 1254 | } |
| 1255 | } |
| 1256 | if (found) { |
| 1257 | return ret; |
| 1258 | } else if (Display_Error) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1259 | gui_msg(Msg(msg::kError, "unable_find_part_path=Unable to find partition for path '{1}'")(Local_Path)); |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 1260 | } else { |
| 1261 | LOGINFO("Repair: Unable to find partition for path '%s'\n", Local_Path.c_str()); |
| 1262 | } |
| 1263 | return false; |
| 1264 | } |
| 1265 | |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 1266 | int TWPartitionManager::Resize_By_Path(string Path, bool Display_Error) { |
| 1267 | std::vector<TWPartition*>::iterator iter; |
| 1268 | int ret = false; |
| 1269 | bool found = false; |
| 1270 | string Local_Path = TWFunc::Get_Root_Path(Path); |
| 1271 | |
| 1272 | if (Local_Path == "/tmp" || Local_Path == "/") |
| 1273 | return true; |
| 1274 | |
| 1275 | // Iterate through all partitions |
| 1276 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
| 1277 | if ((*iter)->Mount_Point == Local_Path || (!(*iter)->Symlink_Mount_Point.empty() && (*iter)->Symlink_Mount_Point == Local_Path)) { |
| 1278 | ret = (*iter)->Resize(); |
| 1279 | found = true; |
| 1280 | } else if ((*iter)->Is_SubPartition && (*iter)->SubPartition_Of == Local_Path) { |
| 1281 | (*iter)->Resize(); |
| 1282 | } |
| 1283 | } |
| 1284 | if (found) { |
| 1285 | return ret; |
| 1286 | } else if (Display_Error) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1287 | gui_msg(Msg(msg::kError, "unable_find_part_path=Unable to find partition for path '{1}'")(Local_Path)); |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 1288 | } else { |
| 1289 | LOGINFO("Resize: Unable to find partition for path '%s'\n", Local_Path.c_str()); |
| 1290 | } |
| 1291 | return false; |
| 1292 | } |
| 1293 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1294 | void TWPartitionManager::Update_System_Details(void) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1295 | std::vector<TWPartition*>::iterator iter; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1296 | int data_size = 0; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1297 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1298 | gui_msg("update_part_details=Updating partition details..."); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1299 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1300 | if ((*iter)->Can_Be_Mounted) { |
| 1301 | (*iter)->Update_Size(true); |
| 1302 | if ((*iter)->Mount_Point == "/system") { |
| 1303 | int backup_display_size = (int)((*iter)->Backup_Size / 1048576LLU); |
| 1304 | DataManager::SetValue(TW_BACKUP_SYSTEM_SIZE, backup_display_size); |
| 1305 | } else if ((*iter)->Mount_Point == "/data" || (*iter)->Mount_Point == "/datadata") { |
| 1306 | data_size += (int)((*iter)->Backup_Size / 1048576LLU); |
| 1307 | } else if ((*iter)->Mount_Point == "/cache") { |
| 1308 | int backup_display_size = (int)((*iter)->Backup_Size / 1048576LLU); |
| 1309 | DataManager::SetValue(TW_BACKUP_CACHE_SIZE, backup_display_size); |
| 1310 | } else if ((*iter)->Mount_Point == "/sd-ext") { |
| 1311 | int backup_display_size = (int)((*iter)->Backup_Size / 1048576LLU); |
| 1312 | DataManager::SetValue(TW_BACKUP_SDEXT_SIZE, backup_display_size); |
| 1313 | if ((*iter)->Backup_Size == 0) { |
| 1314 | DataManager::SetValue(TW_HAS_SDEXT_PARTITION, 0); |
| 1315 | DataManager::SetValue(TW_BACKUP_SDEXT_VAR, 0); |
| 1316 | } else |
| 1317 | DataManager::SetValue(TW_HAS_SDEXT_PARTITION, 1); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1318 | } else if ((*iter)->Has_Android_Secure) { |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1319 | int backup_display_size = (int)((*iter)->Backup_Size / 1048576LLU); |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1320 | DataManager::SetValue(TW_BACKUP_ANDSEC_SIZE, backup_display_size); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1321 | if ((*iter)->Backup_Size == 0) { |
| 1322 | DataManager::SetValue(TW_HAS_ANDROID_SECURE, 0); |
| 1323 | DataManager::SetValue(TW_BACKUP_ANDSEC_VAR, 0); |
| 1324 | } else |
| 1325 | DataManager::SetValue(TW_HAS_ANDROID_SECURE, 1); |
Dees_Troy | 2c50e18 | 2012-09-26 20:05:28 -0400 | [diff] [blame] | 1326 | } else if ((*iter)->Mount_Point == "/boot") { |
| 1327 | int backup_display_size = (int)((*iter)->Backup_Size / 1048576LLU); |
| 1328 | DataManager::SetValue(TW_BACKUP_BOOT_SIZE, backup_display_size); |
| 1329 | if ((*iter)->Backup_Size == 0) { |
| 1330 | DataManager::SetValue("tw_has_boot_partition", 0); |
| 1331 | DataManager::SetValue(TW_BACKUP_BOOT_VAR, 0); |
| 1332 | } else |
| 1333 | DataManager::SetValue("tw_has_boot_partition", 1); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1334 | } |
Dees_Troy | aa9cc40 | 2012-10-13 12:14:05 -0400 | [diff] [blame] | 1335 | } else { |
| 1336 | // Handle unmountable partitions in case we reset defaults |
| 1337 | if ((*iter)->Mount_Point == "/boot") { |
| 1338 | int backup_display_size = (int)((*iter)->Backup_Size / 1048576LLU); |
| 1339 | DataManager::SetValue(TW_BACKUP_BOOT_SIZE, backup_display_size); |
| 1340 | if ((*iter)->Backup_Size == 0) { |
| 1341 | DataManager::SetValue(TW_HAS_BOOT_PARTITION, 0); |
| 1342 | DataManager::SetValue(TW_BACKUP_BOOT_VAR, 0); |
| 1343 | } else |
| 1344 | DataManager::SetValue(TW_HAS_BOOT_PARTITION, 1); |
| 1345 | } else if ((*iter)->Mount_Point == "/recovery") { |
| 1346 | int backup_display_size = (int)((*iter)->Backup_Size / 1048576LLU); |
| 1347 | DataManager::SetValue(TW_BACKUP_RECOVERY_SIZE, backup_display_size); |
| 1348 | if ((*iter)->Backup_Size == 0) { |
| 1349 | DataManager::SetValue(TW_HAS_RECOVERY_PARTITION, 0); |
| 1350 | DataManager::SetValue(TW_BACKUP_RECOVERY_VAR, 0); |
| 1351 | } else |
| 1352 | DataManager::SetValue(TW_HAS_RECOVERY_PARTITION, 1); |
Gary Peck | 82599a8 | 2012-11-21 16:23:12 -0800 | [diff] [blame] | 1353 | } else if ((*iter)->Mount_Point == "/data") { |
| 1354 | data_size += (int)((*iter)->Backup_Size / 1048576LLU); |
Dees_Troy | aa9cc40 | 2012-10-13 12:14:05 -0400 | [diff] [blame] | 1355 | } |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1356 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1357 | } |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1358 | gui_msg("update_part_details_done=...done"); |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1359 | DataManager::SetValue(TW_BACKUP_DATA_SIZE, data_size); |
| 1360 | string current_storage_path = DataManager::GetCurrentStoragePath(); |
| 1361 | TWPartition* FreeStorage = Find_Partition_By_Path(current_storage_path); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1362 | if (FreeStorage != NULL) { |
| 1363 | // Attempt to mount storage |
| 1364 | if (!FreeStorage->Mount(false)) { |
Matt Mower | 2d50cad | 2015-12-03 22:26:55 -0600 | [diff] [blame] | 1365 | gui_msg(Msg(msg::kError, "unable_to_mount_storage=Unable to mount storage")); |
| 1366 | DataManager::SetValue(TW_STORAGE_FREE_SIZE, 0); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1367 | } else { |
| 1368 | DataManager::SetValue(TW_STORAGE_FREE_SIZE, (int)(FreeStorage->Free / 1048576LLU)); |
| 1369 | } |
| 1370 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1371 | LOGINFO("Unable to find storage partition '%s'.\n", current_storage_path.c_str()); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1372 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1373 | if (!Write_Fstab()) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1374 | LOGERR("Error creating fstab\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1375 | return; |
| 1376 | } |
| 1377 | |
| 1378 | int TWPartitionManager::Decrypt_Device(string Password) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1379 | #ifdef TW_INCLUDE_CRYPTO |
| 1380 | int ret_val, password_len; |
Ethan Yonker | a1de149 | 2015-11-04 11:58:27 -0600 | [diff] [blame] | 1381 | char crypto_state[PROPERTY_VALUE_MAX], crypto_blkdev[PROPERTY_VALUE_MAX], cPassword[255]; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1382 | size_t result; |
Ethan Yonker | 253368a | 2014-11-25 15:00:52 -0600 | [diff] [blame] | 1383 | std::vector<TWPartition*>::iterator iter; |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1384 | |
Ethan Yonker | 253368a | 2014-11-25 15:00:52 -0600 | [diff] [blame] | 1385 | // Mount any partitions that need to be mounted for decrypt |
| 1386 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
| 1387 | if ((*iter)->Mount_To_Decrypt) { |
| 1388 | (*iter)->Mount(true); |
| 1389 | } |
a3955269 | 6ff55ce | 2013-01-08 16:14:56 +0000 | [diff] [blame] | 1390 | } |
a3955269 | 6ff55ce | 2013-01-08 16:14:56 +0000 | [diff] [blame] | 1391 | |
Ethan Yonker | a1de149 | 2015-11-04 11:58:27 -0600 | [diff] [blame] | 1392 | property_get("ro.crypto.state", crypto_state, "error"); |
| 1393 | if (strcmp(crypto_state, "error") == 0) { |
| 1394 | property_set("ro.crypto.state", "encrypted"); |
| 1395 | // Sleep for a bit so that services can start if needed |
| 1396 | sleep(1); |
| 1397 | } |
| 1398 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1399 | strcpy(cPassword, Password.c_str()); |
a3955269 | 6ff55ce | 2013-01-08 16:14:56 +0000 | [diff] [blame] | 1400 | int pwret = cryptfs_check_passwd(cPassword); |
| 1401 | |
Ethan Yonker | 253368a | 2014-11-25 15:00:52 -0600 | [diff] [blame] | 1402 | // Unmount any partitions that were needed for decrypt |
| 1403 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
| 1404 | if ((*iter)->Mount_To_Decrypt) { |
| 1405 | (*iter)->UnMount(false); |
| 1406 | } |
| 1407 | } |
| 1408 | |
a3955269 | 6ff55ce | 2013-01-08 16:14:56 +0000 | [diff] [blame] | 1409 | if (pwret != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1410 | gui_err("fail_decrypt=Failed to decrypt data."); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1411 | return -1; |
| 1412 | } |
a3955269 | 6ff55ce | 2013-01-08 16:14:56 +0000 | [diff] [blame] | 1413 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1414 | property_get("ro.crypto.fs_crypto_blkdev", crypto_blkdev, "error"); |
| 1415 | if (strcmp(crypto_blkdev, "error") == 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1416 | LOGERR("Error retrieving decrypted data block device.\n"); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1417 | } else { |
| 1418 | TWPartition* dat = Find_Partition_By_Path("/data"); |
| 1419 | if (dat != NULL) { |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1420 | DataManager::SetValue(TW_IS_DECRYPTED, 1); |
| 1421 | dat->Is_Decrypted = true; |
| 1422 | dat->Decrypted_Block_Device = crypto_blkdev; |
Gary Peck | 82599a8 | 2012-11-21 16:23:12 -0800 | [diff] [blame] | 1423 | dat->Setup_File_System(false); |
Dees_Troy | 74fb2e9 | 2013-04-15 14:35:47 +0000 | [diff] [blame] | 1424 | dat->Current_File_System = dat->Fstab_File_System; // Needed if we're ignoring blkid because encrypted devices start out as emmc |
Matt Mower | 3c36697 | 2015-12-25 19:28:31 -0600 | [diff] [blame] | 1425 | gui_msg(Msg("decrypt_success_dev=Data successfully decrypted, new block device: '{1}'")(crypto_blkdev)); |
a3955269 | 6ff55ce | 2013-01-08 16:14:56 +0000 | [diff] [blame] | 1426 | |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1427 | // Sleep for a bit so that the device will be ready |
| 1428 | sleep(1); |
Ethan Yonker | 6277c79 | 2014-09-15 14:54:30 -0500 | [diff] [blame] | 1429 | if (dat->Has_Data_Media && dat->Mount(false) && TWFunc::Path_Exists("/data/media/0")) { |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 1430 | dat->Storage_Path = "/data/media/0"; |
| 1431 | dat->Symlink_Path = dat->Storage_Path; |
Dees Troy | 98fb46c | 2013-12-04 16:56:45 +0000 | [diff] [blame] | 1432 | DataManager::SetValue("tw_storage_path", "/data/media/0"); |
Ethan Yonker | ec0fa4a | 2014-11-20 09:51:03 -0600 | [diff] [blame] | 1433 | DataManager::SetValue("tw_settings_path", "/data/media/0"); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 1434 | dat->UnMount(false); |
Dees_Troy | dc8bc1b | 2013-01-17 01:39:28 +0000 | [diff] [blame] | 1435 | Output_Partition(dat); |
Dees_Troy | 16b7435 | 2012-11-14 22:27:31 +0000 | [diff] [blame] | 1436 | } |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1437 | Update_System_Details(); |
Dees_Troy | d0384ef | 2012-10-12 12:15:42 -0400 | [diff] [blame] | 1438 | UnMount_Main_Partitions(); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1439 | } else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1440 | LOGERR("Unable to locate data partition.\n"); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1441 | } |
| 1442 | return 0; |
| 1443 | #else |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1444 | gui_err("no_crypto_support=No crypto support was compiled into this build."); |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 1445 | return -1; |
| 1446 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1447 | return 1; |
Dees_Troy | 5112731 | 2012-09-08 13:08:49 -0400 | [diff] [blame] | 1448 | } |
| 1449 | |
Ethan Yonker | b5fab76 | 2016-01-28 14:03:33 -0600 | [diff] [blame] | 1450 | int TWPartitionManager::Fix_Contexts(void) { |
that | a3d31fb | 2014-12-21 22:27:40 +0100 | [diff] [blame] | 1451 | #ifdef HAVE_SELINUX |
Ethan Yonker | b5fab76 | 2016-01-28 14:03:33 -0600 | [diff] [blame] | 1452 | std::vector<TWPartition*>::iterator iter; |
| 1453 | for (iter = Partitions.begin(); iter != Partitions.end(); iter++) { |
| 1454 | if ((*iter)->Has_Data_Media) { |
| 1455 | if ((*iter)->Mount(true)) { |
| 1456 | if (fixContexts::fixDataMediaContexts((*iter)->Mount_Point) != 0) |
| 1457 | return -1; |
| 1458 | } |
| 1459 | } |
| 1460 | } |
Dees_Troy | 1a650e6 | 2012-10-19 20:54:32 -0400 | [diff] [blame] | 1461 | UnMount_Main_Partitions(); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1462 | gui_msg("done=Done."); |
Ethan Yonker | b5fab76 | 2016-01-28 14:03:33 -0600 | [diff] [blame] | 1463 | return 0; |
| 1464 | #else |
| 1465 | LOGERR("Cannot fix contexts, no selinux support present.\n"); |
| 1466 | return -1; |
| 1467 | #endif |
bigbiff bigbiff | a0f8a59 | 2012-10-09 21:01:03 -0400 | [diff] [blame] | 1468 | } |
| 1469 | |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 1470 | TWPartition* TWPartitionManager::Find_Next_Storage(string Path, bool Exclude_Data_Media) { |
Ethan Yonker | 47360be | 2014-04-01 10:34:34 -0500 | [diff] [blame] | 1471 | std::vector<TWPartition*>::iterator iter = Partitions.begin(); |
| 1472 | |
| 1473 | if (!Path.empty()) { |
| 1474 | string Search_Path = TWFunc::Get_Root_Path(Path); |
| 1475 | for (; iter != Partitions.end(); iter++) { |
Matt Mower | 9a561dd | 2016-02-22 21:25:51 -0600 | [diff] [blame] | 1476 | if ((*iter)->Mount_Point == Search_Path) { |
Ethan Yonker | 47360be | 2014-04-01 10:34:34 -0500 | [diff] [blame] | 1477 | iter++; |
| 1478 | break; |
| 1479 | } |
| 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | for (; iter != Partitions.end(); iter++) { |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 1484 | if (Exclude_Data_Media && (*iter)->Has_Data_Media) { |
| 1485 | // do nothing, do not return this type of partition |
| 1486 | } else if ((*iter)->Is_Storage && (*iter)->Is_Present) { |
Ethan Yonker | 47360be | 2014-04-01 10:34:34 -0500 | [diff] [blame] | 1487 | return (*iter); |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | return NULL; |
| 1492 | } |
| 1493 | |
Dees_Troy | d21618c | 2012-10-14 18:48:49 -0400 | [diff] [blame] | 1494 | int TWPartitionManager::Open_Lun_File(string Partition_Path, string Lun_File) { |
Dees_Troy | d21618c | 2012-10-14 18:48:49 -0400 | [diff] [blame] | 1495 | TWPartition* Part = Find_Partition_By_Path(Partition_Path); |
| 1496 | |
| 1497 | if (Part == NULL) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1498 | LOGINFO("Unable to locate '%s' for USB storage mode.", Partition_Path.c_str()); |
| 1499 | gui_msg(Msg(msg::kError, "unable_find_part_path=Unable to find partition for path '{1}'")(Partition_Path)); |
Dees_Troy | d21618c | 2012-10-14 18:48:49 -0400 | [diff] [blame] | 1500 | return false; |
| 1501 | } |
Ethan Yonker | 47360be | 2014-04-01 10:34:34 -0500 | [diff] [blame] | 1502 | LOGINFO("USB mount '%s', '%s' > '%s'\n", Partition_Path.c_str(), Part->Actual_Block_Device.c_str(), Lun_File.c_str()); |
| 1503 | if (!Part->UnMount(true) || !Part->Is_Present) |
Dees_Troy | d21618c | 2012-10-14 18:48:49 -0400 | [diff] [blame] | 1504 | return false; |
| 1505 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1506 | if (TWFunc::write_file(Lun_File, Part->Actual_Block_Device)) { |
| 1507 | LOGERR("Unable to write to ums lunfile '%s': (%s)\n", Lun_File.c_str(), strerror(errno)); |
Dees_Troy | d21618c | 2012-10-14 18:48:49 -0400 | [diff] [blame] | 1508 | return false; |
| 1509 | } |
Dees_Troy | d21618c | 2012-10-14 18:48:49 -0400 | [diff] [blame] | 1510 | return true; |
| 1511 | } |
| 1512 | |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1513 | int TWPartitionManager::usb_storage_enable(void) { |
Dees_Troy | d21618c | 2012-10-14 18:48:49 -0400 | [diff] [blame] | 1514 | int has_dual, has_data_media; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1515 | char lun_file[255]; |
Dees_Troy | d21618c | 2012-10-14 18:48:49 -0400 | [diff] [blame] | 1516 | bool has_multiple_lun = false; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1517 | |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1518 | DataManager::GetValue(TW_HAS_DATA_MEDIA, has_data_media); |
Ethan Yonker | 47360be | 2014-04-01 10:34:34 -0500 | [diff] [blame] | 1519 | string Lun_File_str = CUSTOM_LUN_FILE; |
| 1520 | size_t found = Lun_File_str.find("%"); |
| 1521 | if (found != string::npos) { |
| 1522 | sprintf(lun_file, CUSTOM_LUN_FILE, 1); |
| 1523 | if (TWFunc::Path_Exists(lun_file)) |
| 1524 | has_multiple_lun = true; |
| 1525 | } |
Ethan Yonker | 726a020 | 2014-12-16 20:01:38 -0600 | [diff] [blame] | 1526 | mtp_was_enabled = TWFunc::Toggle_MTP(false); // Must disable MTP for USB Storage |
Ethan Yonker | 47360be | 2014-04-01 10:34:34 -0500 | [diff] [blame] | 1527 | if (!has_multiple_lun) { |
| 1528 | LOGINFO("Device doesn't have multiple lun files, mount current storage\n"); |
| 1529 | sprintf(lun_file, CUSTOM_LUN_FILE, 0); |
| 1530 | if (TWFunc::Get_Root_Path(DataManager::GetCurrentStoragePath()) == "/data") { |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 1531 | TWPartition* Mount = Find_Next_Storage("", true); |
Ethan Yonker | 47360be | 2014-04-01 10:34:34 -0500 | [diff] [blame] | 1532 | if (Mount) { |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 1533 | if (!Open_Lun_File(Mount->Mount_Point, lun_file)) { |
| 1534 | goto error_handle; |
| 1535 | } |
Ethan Yonker | 47360be | 2014-04-01 10:34:34 -0500 | [diff] [blame] | 1536 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1537 | gui_err("unable_locate_storage=Unable to locate storage device."); |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 1538 | goto error_handle; |
Ethan Yonker | 47360be | 2014-04-01 10:34:34 -0500 | [diff] [blame] | 1539 | } |
| 1540 | } else if (!Open_Lun_File(DataManager::GetCurrentStoragePath(), lun_file)) { |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 1541 | goto error_handle; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1542 | } |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1543 | } else { |
Ethan Yonker | 47360be | 2014-04-01 10:34:34 -0500 | [diff] [blame] | 1544 | LOGINFO("Device has multiple lun files\n"); |
| 1545 | TWPartition* Mount1; |
| 1546 | TWPartition* Mount2; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1547 | sprintf(lun_file, CUSTOM_LUN_FILE, 0); |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 1548 | Mount1 = Find_Next_Storage("", true); |
Ethan Yonker | 47360be | 2014-04-01 10:34:34 -0500 | [diff] [blame] | 1549 | if (Mount1) { |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 1550 | if (!Open_Lun_File(Mount1->Mount_Point, lun_file)) { |
| 1551 | goto error_handle; |
| 1552 | } |
Matt Mower | ee71706 | 2014-04-26 01:46:46 -0500 | [diff] [blame] | 1553 | sprintf(lun_file, CUSTOM_LUN_FILE, 1); |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 1554 | Mount2 = Find_Next_Storage(Mount1->Mount_Point, true); |
Matt Mower | 1fdcdb7 | 2016-01-25 20:53:47 -0600 | [diff] [blame] | 1555 | if (Mount2 && Mount2->Mount_Point != Mount1->Mount_Point) { |
Matt Mower | ee71706 | 2014-04-26 01:46:46 -0500 | [diff] [blame] | 1556 | Open_Lun_File(Mount2->Mount_Point, lun_file); |
Ethan Yonker | 47360be | 2014-04-01 10:34:34 -0500 | [diff] [blame] | 1557 | } |
| 1558 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1559 | gui_err("unable_locate_storage=Unable to locate storage device."); |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 1560 | goto error_handle; |
Ethan Yonker | 47360be | 2014-04-01 10:34:34 -0500 | [diff] [blame] | 1561 | } |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1562 | } |
Matt Mower | b6ef478 | 2014-11-06 02:24:36 -0600 | [diff] [blame] | 1563 | property_set("sys.storage.ums_enabled", "1"); |
HandyMenny | 37d4299 | 2014-10-26 22:15:59 +0100 | [diff] [blame] | 1564 | property_set("sys.usb.config", "mass_storage,adb"); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1565 | return true; |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 1566 | error_handle: |
| 1567 | if (mtp_was_enabled) |
| 1568 | if (!Enable_MTP()) |
| 1569 | Disable_MTP(); |
| 1570 | return false; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | int TWPartitionManager::usb_storage_disable(void) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1574 | int index, ret; |
| 1575 | char lun_file[255], ch[2] = {0, 0}; |
| 1576 | string str = ch; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1577 | |
| 1578 | for (index=0; index<2; index++) { |
| 1579 | sprintf(lun_file, CUSTOM_LUN_FILE, index); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1580 | ret = TWFunc::write_file(lun_file, str); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 1581 | if (ret < 0) { |
| 1582 | break; |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1583 | } |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 1584 | } |
Dees_Troy | e58d526 | 2012-09-21 12:27:57 -0400 | [diff] [blame] | 1585 | Mount_All_Storage(); |
| 1586 | Update_System_Details(); |
Dees_Troy | cfd73ef | 2012-10-12 16:52:00 -0400 | [diff] [blame] | 1587 | UnMount_Main_Partitions(); |
Matt Mower | d9cb906 | 2013-12-14 20:34:45 -0600 | [diff] [blame] | 1588 | property_set("sys.storage.ums_enabled", "0"); |
HandyMenny | 37d4299 | 2014-10-26 22:15:59 +0100 | [diff] [blame] | 1589 | property_set("sys.usb.config", "adb"); |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 1590 | if (mtp_was_enabled) |
| 1591 | if (!Enable_MTP()) |
| 1592 | Disable_MTP(); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame |