diff options
Diffstat (limited to 'recovery.cpp')
-rw-r--r-- | recovery.cpp | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/recovery.cpp b/recovery.cpp index ccb8e5d9..e4e5e54e 100644 --- a/recovery.cpp +++ b/recovery.cpp | |||
@@ -791,47 +791,45 @@ static bool wipe_cache(bool should_confirm, Device* device) { | |||
791 | return success; | 791 | return success; |
792 | } | 792 | } |
793 | 793 | ||
794 | // Secure-wipe a given partition. It uses BLKSECDISCARD, if supported. | 794 | // 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 | 795 | // BLKDISCARD (if device supports BLKDISCARDZEROES) or BLKZEROOUT. |
796 | // BLKZEROOUT. | ||
797 | static bool secure_wipe_partition(const std::string& partition) { | 796 | static bool secure_wipe_partition(const std::string& partition) { |
798 | android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(partition.c_str(), O_WRONLY))); | 797 | android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(partition.c_str(), O_WRONLY))); |
799 | if (fd == -1) { | 798 | if (fd == -1) { |
800 | PLOG(ERROR) << "failed to open \"" << partition << "\""; | 799 | PLOG(ERROR) << "Failed to open \"" << partition << "\""; |
801 | return false; | 800 | return false; |
802 | } | 801 | } |
803 | 802 | ||
804 | uint64_t range[2] = {0, 0}; | 803 | uint64_t range[2] = { 0, 0 }; |
805 | if (ioctl(fd, BLKGETSIZE64, &range[1]) == -1 || range[1] == 0) { | 804 | if (ioctl(fd, BLKGETSIZE64, &range[1]) == -1 || range[1] == 0) { |
806 | PLOG(ERROR) << "failed to get partition size"; | 805 | PLOG(ERROR) << "Failed to get partition size"; |
806 | return false; | ||
807 | } | ||
808 | LOG(INFO) << "Secure-wiping \"" << partition << "\" from " << range[0] << " to " << range[1]; | ||
809 | |||
810 | LOG(INFO) << " Trying BLKSECDISCARD..."; | ||
811 | if (ioctl(fd, BLKSECDISCARD, &range) == -1) { | ||
812 | PLOG(WARNING) << " Failed"; | ||
813 | |||
814 | // Use BLKDISCARD if it zeroes out blocks, otherwise use BLKZEROOUT. | ||
815 | unsigned int zeroes; | ||
816 | if (ioctl(fd, BLKDISCARDZEROES, &zeroes) == 0 && zeroes != 0) { | ||
817 | LOG(INFO) << " Trying BLKDISCARD..."; | ||
818 | if (ioctl(fd, BLKDISCARD, &range) == -1) { | ||
819 | PLOG(ERROR) << " Failed"; | ||
807 | return false; | 820 | return false; |
821 | } | ||
822 | } else { | ||
823 | LOG(INFO) << " Trying BLKZEROOUT..."; | ||
824 | if (ioctl(fd, BLKZEROOUT, &range) == -1) { | ||
825 | PLOG(ERROR) << " Failed"; | ||
826 | return false; | ||
827 | } | ||
808 | } | 828 | } |
809 | printf("Secure-wiping \"%s\" from %" PRIu64 " to %" PRIu64 ".\n", | 829 | } |
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 | 830 | ||
833 | printf("done\n"); | 831 | LOG(INFO) << " Done"; |
834 | return true; | 832 | return true; |
835 | } | 833 | } |
836 | 834 | ||
837 | // Check if the wipe package matches expectation: | 835 | // Check if the wipe package matches expectation: |
@@ -863,7 +861,7 @@ static bool check_wipe_package(size_t wipe_package_size) { | |||
863 | return false; | 861 | return false; |
864 | } | 862 | } |
865 | std::string metadata; | 863 | std::string metadata; |
866 | if (!read_metadata_from_package(&zip, &metadata)) { | 864 | if (!read_metadata_from_package(zip, &metadata)) { |
867 | CloseArchive(zip); | 865 | CloseArchive(zip); |
868 | return false; | 866 | return false; |
869 | } | 867 | } |