aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'recovery.cpp')
-rw-r--r--recovery.cpp82
1 files changed, 41 insertions, 41 deletions
diff --git a/recovery.cpp b/recovery.cpp
index a374eed8..b24efa96 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -752,13 +752,15 @@ static bool wipe_data(Device* device) {
752 752
753static bool prompt_and_wipe_data(Device* device) { 753static bool prompt_and_wipe_data(Device* device) {
754 const char* const headers[] = { 754 const char* const headers[] = {
755 "Boot halted, user data is corrupt", 755 "Can't load Android system. Your data may be corrupt.",
756 "Wipe all user data to recover", 756 "If you continue to get this message, you may need to",
757 "perform a factory data reset and erase all user data",
758 "stored on this device.",
757 NULL 759 NULL
758 }; 760 };
759 const char* const items[] = { 761 const char* const items[] = {
760 "Retry boot", 762 "Try again",
761 "Wipe user data", 763 "Factory data reset",
762 NULL 764 NULL
763 }; 765 };
764 for (;;) { 766 for (;;) {
@@ -791,47 +793,45 @@ static bool wipe_cache(bool should_confirm, Device* device) {
791 return success; 793 return success;
792} 794}
793 795
794// Secure-wipe a given partition. It uses BLKSECDISCARD, if supported. 796// Secure-wipe a given partition. It uses BLKSECDISCARD, if supported. Otherwise, it goes with
795// Otherwise, it goes with BLKDISCARD (if device supports BLKDISCARDZEROES) or 797// BLKDISCARD (if device supports BLKDISCARDZEROES) or BLKZEROOUT.
796// BLKZEROOUT.
797static bool secure_wipe_partition(const std::string& partition) { 798static bool secure_wipe_partition(const std::string& partition) {
798 android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(partition.c_str(), O_WRONLY))); 799 android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(partition.c_str(), O_WRONLY)));
799 if (fd == -1) { 800 if (fd == -1) {
800 PLOG(ERROR) << "failed to open \"" << partition << "\""; 801 PLOG(ERROR) << "Failed to open \"" << partition << "\"";
801 return false; 802 return false;
802 } 803 }
803 804
804 uint64_t range[2] = {0, 0}; 805 uint64_t range[2] = { 0, 0 };
805 if (ioctl(fd, BLKGETSIZE64, &range[1]) == -1 || range[1] == 0) { 806 if (ioctl(fd, BLKGETSIZE64, &range[1]) == -1 || range[1] == 0) {
806 PLOG(ERROR) << "failed to get partition size"; 807 PLOG(ERROR) << "Failed to get partition size";
808 return false;
809 }
810 LOG(INFO) << "Secure-wiping \"" << partition << "\" from " << range[0] << " to " << range[1];
811
812 LOG(INFO) << " Trying BLKSECDISCARD...";
813 if (ioctl(fd, BLKSECDISCARD, &range) == -1) {
814 PLOG(WARNING) << " Failed";
815
816 // Use BLKDISCARD if it zeroes out blocks, otherwise use BLKZEROOUT.
817 unsigned int zeroes;
818 if (ioctl(fd, BLKDISCARDZEROES, &zeroes) == 0 && zeroes != 0) {
819 LOG(INFO) << " Trying BLKDISCARD...";
820 if (ioctl(fd, BLKDISCARD, &range) == -1) {
821 PLOG(ERROR) << " Failed";
807 return false; 822 return false;
823 }
824 } else {
825 LOG(INFO) << " Trying BLKZEROOUT...";
826 if (ioctl(fd, BLKZEROOUT, &range) == -1) {
827 PLOG(ERROR) << " Failed";
828 return false;
829 }
808 } 830 }
809 printf("Secure-wiping \"%s\" from %" PRIu64 " to %" PRIu64 ".\n", 831 }
810 partition.c_str(), range[0], range[1]);
811
812 printf("Trying BLKSECDISCARD...\t");
813 if (ioctl(fd, BLKSECDISCARD, &range) == -1) {
814 printf("failed: %s\n", strerror(errno));
815
816 // Use BLKDISCARD if it zeroes out blocks, otherwise use BLKZEROOUT.
817 unsigned int zeroes;
818 if (ioctl(fd, BLKDISCARDZEROES, &zeroes) == 0 && zeroes != 0) {
819 printf("Trying BLKDISCARD...\t");
820 if (ioctl(fd, BLKDISCARD, &range) == -1) {
821 printf("failed: %s\n", strerror(errno));
822 return false;
823 }
824 } else {
825 printf("Trying BLKZEROOUT...\t");
826 if (ioctl(fd, BLKZEROOUT, &range) == -1) {
827 printf("failed: %s\n", strerror(errno));
828 return false;
829 }
830 }
831 }
832 832
833 printf("done\n"); 833 LOG(INFO) << " Done";
834 return true; 834 return true;
835} 835}
836 836
837// Check if the wipe package matches expectation: 837// Check if the wipe package matches expectation:
@@ -863,7 +863,7 @@ static bool check_wipe_package(size_t wipe_package_size) {
863 return false; 863 return false;
864 } 864 }
865 std::string metadata; 865 std::string metadata;
866 if (!read_metadata_from_package(&zip, &metadata)) { 866 if (!read_metadata_from_package(zip, &metadata)) {
867 CloseArchive(zip); 867 CloseArchive(zip);
868 return false; 868 return false;
869 } 869 }