summaryrefslogtreecommitdiffstats
path: root/updater
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2019-01-08 02:28:52 +0100
committerandroid-build-merger <android-build-merger@google.com>2019-01-08 02:28:52 +0100
commit2f3a0ba7751679a0cc8059ee5671ab3129770532 (patch)
tree99bb6b03559766f51e5cae187d34a31fc624fe94 /updater
parentMerge "minadbd: daemon_service_to_fd takes std::string_view." am: 72aa58dcf7 am: 29578b1117 (diff)
parentMerge "updater: erase ignores EOPNOTSUPP for BLKDISCARD" am: 08a8b40c91 (diff)
downloadandroid_bootable_recovery-2f3a0ba7751679a0cc8059ee5671ab3129770532.tar
android_bootable_recovery-2f3a0ba7751679a0cc8059ee5671ab3129770532.tar.gz
android_bootable_recovery-2f3a0ba7751679a0cc8059ee5671ab3129770532.tar.bz2
android_bootable_recovery-2f3a0ba7751679a0cc8059ee5671ab3129770532.tar.lz
android_bootable_recovery-2f3a0ba7751679a0cc8059ee5671ab3129770532.tar.xz
android_bootable_recovery-2f3a0ba7751679a0cc8059ee5671ab3129770532.tar.zst
android_bootable_recovery-2f3a0ba7751679a0cc8059ee5671ab3129770532.zip
Diffstat (limited to 'updater')
-rw-r--r--updater/blockimg.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp
index c4c09098e..9d5b01734 100644
--- a/updater/blockimg.cpp
+++ b/updater/blockimg.cpp
@@ -178,14 +178,18 @@ static bool SetPartitionUpdatedMarker(const std::string& marker) {
return true;
}
-static bool discard_blocks(int fd, off64_t offset, uint64_t size) {
- // Don't discard blocks unless the update is a retry run.
- if (!is_retry) {
+static bool discard_blocks(int fd, off64_t offset, uint64_t size, bool force = false) {
+ // Don't discard blocks unless the update is a retry run or force == true
+ if (!is_retry && !force) {
return true;
}
uint64_t args[2] = { static_cast<uint64_t>(offset), size };
if (ioctl(fd, BLKDISCARD, &args) == -1) {
+ // On devices that does not support BLKDISCARD, ignore the error.
+ if (errno == EOPNOTSUPP) {
+ return true;
+ }
PLOG(ERROR) << "BLKDISCARD ioctl failed";
return false;
}
@@ -1448,14 +1452,9 @@ static int PerformCommandErase(CommandParameters& params) {
LOG(INFO) << " erasing " << tgt.blocks() << " blocks";
for (const auto& [begin, end] : tgt) {
- uint64_t blocks[2];
- // offset in bytes
- blocks[0] = begin * static_cast<uint64_t>(BLOCKSIZE);
- // length in bytes
- blocks[1] = (end - begin) * static_cast<uint64_t>(BLOCKSIZE);
-
- if (ioctl(params.fd, BLKDISCARD, &blocks) == -1) {
- PLOG(ERROR) << "BLKDISCARD ioctl failed";
+ off64_t offset = static_cast<off64_t>(begin) * BLOCKSIZE;
+ size_t size = (end - begin) * BLOCKSIZE;
+ if (!discard_blocks(params.fd, offset, size, true /* force */)) {
return -1;
}
}