diff options
author | Daniel Verkamp <dverkamp@chromium.org> | 2019-09-18 11:22:07 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-09-25 00:06:27 +0000 |
commit | 71a6f0a790eb3f9a6fccbaf08aa915396a9d6749 (patch) | |
tree | e9e9c632f671860534afc1efa932acd41f006d05 /qcow/src/qcow.rs | |
parent | b2d4e11579b23e84ef62290600337084a64770c4 (diff) | |
download | crosvm-71a6f0a790eb3f9a6fccbaf08aa915396a9d6749.tar crosvm-71a6f0a790eb3f9a6fccbaf08aa915396a9d6749.tar.gz crosvm-71a6f0a790eb3f9a6fccbaf08aa915396a9d6749.tar.bz2 crosvm-71a6f0a790eb3f9a6fccbaf08aa915396a9d6749.tar.lz crosvm-71a6f0a790eb3f9a6fccbaf08aa915396a9d6749.tar.xz crosvm-71a6f0a790eb3f9a6fccbaf08aa915396a9d6749.tar.zst crosvm-71a6f0a790eb3f9a6fccbaf08aa915396a9d6749.zip |
sys_util: add write_zeroes_all() function
In the same spirit as write_all() for the standard io::Write::write() function, add a write_zeroes_all() function with a default implementation that calls write_zeroes() in a loop until the requested length is met. This will allow write_zeroes implementations that don't necessarily fulfill the entire requested length. BUG=None TEST=cargo test -p sys_util write_zeroes Change-Id: I0fc3a4b3fe8904946e253ab8a2687555b12657be Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1811466 Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Cody Schuffelen <schuffelen@google.com> Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'qcow/src/qcow.rs')
-rw-r--r-- | qcow/src/qcow.rs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/qcow/src/qcow.rs b/qcow/src/qcow.rs index aaff5f1..633b21c 100644 --- a/qcow/src/qcow.rs +++ b/qcow/src/qcow.rs @@ -1239,7 +1239,7 @@ impl QcowFile { if let Some(offset) = self.file_offset_read(curr_addr)? { // Partial cluster - zero it out. self.raw_file.file_mut().seek(SeekFrom::Start(offset))?; - self.raw_file.file_mut().write_zeroes(count)?; + self.raw_file.file_mut().write_zeroes_all(count)?; } } @@ -1822,8 +1822,7 @@ mod tests { q.write(&b).expect("Failed to write test string."); // Overwrite the test data with zeroes. q.seek(SeekFrom::Start(0xfff2000)).expect("Failed to seek."); - let nwritten = q.write_zeroes(0x200).expect("Failed to write zeroes."); - assert_eq!(nwritten, 0x200); + q.write_zeroes_all(0x200).expect("Failed to write zeroes."); // Verify that the correct part of the data was zeroed out. let mut buf = [0u8; 0x1000]; q.seek(SeekFrom::Start(0xfff2000)).expect("Failed to seek."); @@ -1848,8 +1847,8 @@ mod tests { q.write(&b).expect("Failed to write test string."); // Overwrite the full cluster with zeroes. q.seek(SeekFrom::Start(0)).expect("Failed to seek."); - let nwritten = q.write_zeroes(CHUNK_SIZE).expect("Failed to write zeroes."); - assert_eq!(nwritten, CHUNK_SIZE); + q.write_zeroes_all(CHUNK_SIZE) + .expect("Failed to write zeroes."); // Verify that the data was zeroed out. let mut buf = [0u8; CHUNK_SIZE]; q.seek(SeekFrom::Start(0)).expect("Failed to seek."); |