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

Function zero_fill_iovecs

block/src/qcow_common.rs:229–252  ·  view source on GitHub ↗

Zero fill iovecs starting at the given byte offset for the given length. # Safety Caller must ensure iovecs point to valid, writable memory of sufficient size.

(iovecs: &[libc::iovec], start: usize, len: usize)

Source from the content-addressed store, hash-verified

227/// # Safety
228/// Caller must ensure iovecs point to valid, writable memory of sufficient size.
229pub unsafe fn zero_fill_iovecs(iovecs: &[libc::iovec], start: usize, len: usize) {
230 let mut remaining = len;
231 let mut pos = 0usize;
232 for iov in iovecs {
233 let iov_end = pos + iov.iov_len;
234 if iov_end <= start || remaining == 0 {
235 pos = iov_end;
236 continue;
237 }
238 let iov_start = start.saturating_sub(pos);
239 let available = iov.iov_len - iov_start;
240 let count = min(available, remaining);
241 // SAFETY: iov_base is valid for iov_len bytes per caller contract.
242 unsafe {
243 let dst = iov.iov_base.cast::<u8>().add(iov_start);
244 ptr::write_bytes(dst, 0, count);
245 }
246 remaining -= count;
247 if remaining == 0 {
248 break;
249 }
250 pos = iov_end;
251 }
252}
253
254/// Gather bytes from iovecs starting at the given byte offset into `dst`.
255///

Callers 2

scatter_read_syncMethod · 0.85
read_vectoredMethod · 0.85

Calls 1

addMethod · 0.80

Tested by

no test coverage detected