aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-03-24 15:11:51 -0500
committerGerrit Code Review2017-03-24 15:11:53 -0500
commit6014db5da64dae2c9ce6be2f8115db235b75af8a (patch)
tree527b4b20820b8fd154673224f977c5e6d8bf4134 /recovery.cpp
parentf09efaff895a0a050f43842a015aef6457dabfd4 (diff)
parent1b2a98bda3406682b038dcdb2f462f0d6ce3e455 (diff)
downloadplatform-bootable-recovery-6014db5da64dae2c9ce6be2f8115db235b75af8a.tar.gz
platform-bootable-recovery-6014db5da64dae2c9ce6be2f8115db235b75af8a.tar.xz
platform-bootable-recovery-6014db5da64dae2c9ce6be2f8115db235b75af8a.zip
Merge "Fix the wrong parameter when calling read_metadata_from_package()."
Diffstat (limited to 'recovery.cpp')
-rw-r--r--recovery.cpp72
1 files changed, 35 insertions, 37 deletions
diff --git a/recovery.cpp b/recovery.cpp
index 4bbc7831..c2262161 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -793,47 +793,45 @@ static bool wipe_cache(bool should_confirm, Device* device) {
793 return success; 793 return success;
794} 794}
795 795
796// 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
797// Otherwise, it goes with BLKDISCARD (if device supports BLKDISCARDZEROES) or 797// BLKDISCARD (if device supports BLKDISCARDZEROES) or BLKZEROOUT.
798// BLKZEROOUT.
799static bool secure_wipe_partition(const std::string& partition) { 798static bool secure_wipe_partition(const std::string& partition) {
800 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)));
801 if (fd == -1) { 800 if (fd == -1) {
802 PLOG(ERROR) << "failed to open \"" << partition << "\""; 801 PLOG(ERROR) << "Failed to open \"" << partition << "\"";
803 return false; 802 return false;
804 } 803 }
805 804
806 uint64_t range[2] = {0, 0}; 805 uint64_t range[2] = { 0, 0 };
807 if (ioctl(fd, BLKGETSIZE64, &range[1]) == -1 || range[1] == 0) { 806 if (ioctl(fd, BLKGETSIZE64, &range[1]) == -1 || range[1] == 0) {
808 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";
809 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 }
810 } 830 }
811 printf("Secure-wiping \"%s\" from %" PRIu64 " to %" PRIu64 ".\n", 831 }
812 partition.c_str(), range[0], range[1]);
813
814 printf("Trying BLKSECDISCARD...\t");
815 if (ioctl(fd, BLKSECDISCARD, &range) == -1) {
816 printf("failed: %s\n", strerror(errno));
817
818 // Use BLKDISCARD if it zeroes out blocks, otherwise use BLKZEROOUT.
819 unsigned int zeroes;
820 if (ioctl(fd, BLKDISCARDZEROES, &zeroes) == 0 && zeroes != 0) {
821 printf("Trying BLKDISCARD...\t");
822 if (ioctl(fd, BLKDISCARD, &range) == -1) {
823 printf("failed: %s\n", strerror(errno));
824 return false;
825 }
826 } else {
827 printf("Trying BLKZEROOUT...\t");
828 if (ioctl(fd, BLKZEROOUT, &range) == -1) {
829 printf("failed: %s\n", strerror(errno));
830 return false;
831 }
832 }
833 }
834 832
835 printf("done\n"); 833 LOG(INFO) << " Done";
836 return true; 834 return true;
837} 835}
838 836
839// Check if the wipe package matches expectation: 837// Check if the wipe package matches expectation:
@@ -865,7 +863,7 @@ static bool check_wipe_package(size_t wipe_package_size) {
865 return false; 863 return false;
866 } 864 }
867 std::string metadata; 865 std::string metadata;
868 if (!read_metadata_from_package(&zip, &metadata)) { 866 if (!read_metadata_from_package(zip, &metadata)) {
869 CloseArchive(zip); 867 CloseArchive(zip);
870 return false; 868 return false;
871 } 869 }