Do not send zero-byte reads to the underlying device

This commit is contained in:
pjht 2024-06-18 20:55:58 -05:00
parent 5284fcd6d1
commit cfb3fb0aca
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E

View File

@ -36,6 +36,9 @@ impl file_rpc::Server for Serv {
fn read(&self, fd: u64, pos: u64, len: usize) -> Result<Vec<u8>, ()> {
let (mount_id, file_offset, size) = self.files.read()[fd as usize];
let read_len = usize::min(len, size - (pos as usize));
if read_len == 0 {
return Ok(Vec::new());
};
let mounts = self.mounts.read();
let mount = &mounts[mount_id as usize];
(&mount.0).seek(std::io::SeekFrom::Start(file_offset + pos)).unwrap();