MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / convert_copy

Function convert_copy

block/src/qcow/mod.rs:2194–2223  ·  view source on GitHub ↗
(reader: &mut R, writer: &mut W, offset: u64, size: u64)

Source from the content-addressed store, hash-verified

2192}
2193
2194fn convert_copy<R, W>(reader: &mut R, writer: &mut W, offset: u64, size: u64) -> BlockResult<()>
2195where
2196 R: Read + Seek,
2197 W: Write + Seek,
2198{
2199 const CHUNK_SIZE: usize = 65536;
2200 let mut buf = [0; CHUNK_SIZE];
2201 let mut read_count = 0;
2202 reader
2203 .seek(SeekFrom::Start(offset))
2204 .map_err(|e| BlockError::new(BlockErrorKind::Io, Error::SeekingFile(e)))?;
2205 writer
2206 .seek(SeekFrom::Start(offset))
2207 .map_err(|e| BlockError::new(BlockErrorKind::Io, Error::SeekingFile(e)))?;
2208 loop {
2209 let this_count = min(CHUNK_SIZE as u64, size - read_count) as usize;
2210 let nread = reader
2211 .read(&mut buf[..this_count])
2212 .map_err(|e| BlockError::new(BlockErrorKind::Io, Error::ReadingData(e)))?;
2213 writer
2214 .write(&buf[..nread])
2215 .map_err(|e| BlockError::new(BlockErrorKind::Io, Error::WritingData(e)))?;
2216 read_count += nread as u64;
2217 if nread == 0 || read_count == size {
2218 break;
2219 }
2220 }
2221
2222 Ok(())
2223}
2224
2225fn convert_reader_writer<R, W>(reader: &mut R, writer: &mut W, size: u64) -> BlockResult<()>
2226where

Callers 1

convert_reader_writerFunction · 0.85

Calls 4

newFunction · 0.85
seekMethod · 0.45
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected