Discard the tail of the target partitions when updating.
The partition is normally way bigger than the data it holds and the
remainder of the partition is often ignored by the system. This patch
discards the tail of the partition, past the end of the updated data.
This would ensure that the unused blocks in these partitions can be
reallocated by the SSD controller to other blocks, and that data from
previous updates does not interfere with the current version.
Bug: 28744609
TEST=strace -e trace=file,ioctl shows the device discarding the end of the updated partitions.
(cherry picked from commit b86787cdb2ca619c8e2ef0a2e38af8353f4cf4ac)
Change-Id: I5e815f4fc4d1fbc24a27a3d8dd0b22ee0456e09d
diff --git a/payload_consumer/file_descriptor.h b/payload_consumer/file_descriptor.h
index 3c15415..7bb2974 100644
--- a/payload_consumer/file_descriptor.h
+++ b/payload_consumer/file_descriptor.h
@@ -78,6 +78,10 @@
// may set errno accordingly.
virtual off64_t Seek(off64_t offset, int whence) = 0;
+ // Return the size of the block device in bytes, or 0 if the device is not a
+ // block device or an error occurred.
+ virtual uint64_t BlockDevSize() = 0;
+
// Runs a ioctl() on the file descriptor if supported. Returns whether
// the operation is supported. The |request| can be one of BLKDISCARD,
// BLKZEROOUT and BLKSECDISCARD to discard, write zeros or securely discard
@@ -119,6 +123,7 @@
ssize_t Read(void* buf, size_t count) override;
ssize_t Write(const void* buf, size_t count) override;
off64_t Seek(off64_t offset, int whence) override;
+ uint64_t BlockDevSize() override;
bool BlkIoctl(int request,
uint64_t start,
uint64_t length,