authfs: support resizing file
There are three major changes:
1. Add resize() to MerkleLeaves as the simple hash container.
2. Handle resize for a writable file. The special case is that the hash
of the new last chunk can change, and the only way to calculate is to
read the original data back.
3. Handle the size change in FUSE.
Bug: 186265793
Test: atest
Test: dex2oat succeeds (with more local changes)
Change-Id: I1ec20b6f0c69fd3ec24a6d04fc34583962265479
diff --git a/authfs/src/file/remote_file.rs b/authfs/src/file/remote_file.rs
index 9d614f5..bd99893 100644
--- a/authfs/src/file/remote_file.rs
+++ b/authfs/src/file/remote_file.rs
@@ -118,6 +118,17 @@
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.get_description()))?;
Ok(size as usize) // within range because size is supposed to <= buf.len(), which is a usize
}
+
+ fn resize(&self, size: u64) -> io::Result<()> {
+ let size =
+ i64::try_from(size).map_err(|_| io::Error::from_raw_os_error(libc::EOVERFLOW))?;
+ self.service
+ .lock()
+ .unwrap()
+ .resize(self.file_fd, size)
+ .map_err(|e| io::Error::new(io::ErrorKind::Other, e.get_description()))?;
+ Ok(())
+ }
}
impl ReadByChunk for RemoteFileEditor {