summary refs log tree commit diff
path: root/qcow_utils
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2019-09-18 11:22:07 -0700
committerCommit Bot <commit-bot@chromium.org>2019-09-25 00:06:27 +0000
commit71a6f0a790eb3f9a6fccbaf08aa915396a9d6749 (patch)
treee9e9c632f671860534afc1efa932acd41f006d05 /qcow_utils
parentb2d4e11579b23e84ef62290600337084a64770c4 (diff)
downloadcrosvm-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_utils')
-rw-r--r--qcow_utils/src/qcow_img.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/qcow_utils/src/qcow_img.rs b/qcow_utils/src/qcow_img.rs
index 08040a1..b4ad422 100644
--- a/qcow_utils/src/qcow_img.rs
+++ b/qcow_utils/src/qcow_img.rs
@@ -264,7 +264,7 @@ fn dd(file_path: &str, source_path: &str, count: Option<usize>) -> std::result::
         let nread = src_file.read(&mut buf[..this_count]).map_err(|_| ())?;
         // If this block is all zeros, then use write_zeros so the output file is sparse.
         if buf.iter().all(|b| *b == 0) {
-            qcow_file.write_zeroes(CHUNK_SIZE).map_err(|_| ())?;
+            qcow_file.write_zeroes_all(CHUNK_SIZE).map_err(|_| ())?;
         } else {
             qcow_file.write(&buf).map_err(|_| ())?;
         }