From ef88b2778ed145c94595cec72c5eb962f5dbd05c Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Tue, 24 Dec 2024 22:28:04 +0000 Subject: [PATCH] block: vhdx: advance file offset after read and write This is needed to handle multiple reads or writes in a loop. Signed-off-by: Wei Liu --- block/src/vhdx/mod.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/block/src/vhdx/mod.rs b/block/src/vhdx/mod.rs index 425b5330b..f4ddae19b 100644 --- a/block/src/vhdx/mod.rs +++ b/block/src/vhdx/mod.rs @@ -102,7 +102,7 @@ impl Read for Vhdx { let sector_count = (buf.len() as u64).div_ceil(self.disk_spec.logical_sector_size as u64); let sector_index = self.current_offset / self.disk_spec.logical_sector_size as u64; - vhdx_io::read( + let result = vhdx_io::read( &mut self.file, buf, &self.disk_spec, @@ -117,7 +117,11 @@ impl Read for Vhdx { "Failed reading {sector_count} sectors from VHDx at index {sector_index}: {e}" ), ) - }) + })?; + + self.current_offset += result as u64; + + Ok(result) } } @@ -142,7 +146,7 @@ impl Write for Vhdx { })?; } - vhdx_io::write( + let result = vhdx_io::write( &mut self.file, buf, &mut self.disk_spec, @@ -158,7 +162,11 @@ impl Write for Vhdx { "Failed writing {sector_count} sectors on VHDx at index {sector_index}: {e}" ), ) - }) + })?; + + self.current_offset += result as u64; + + Ok(result) } }