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

Function pwrite_all

block/src/qcow_common.rs:77–98  ·  view source on GitHub ↗

Write all bytes to fd at offset, looping on short writes.

(fd: RawFd, buf: &[u8], offset: u64)

Source from the content-addressed store, hash-verified

75
76/// Write all bytes to fd at offset, looping on short writes.
77pub fn pwrite_all(fd: RawFd, buf: &[u8], offset: u64) -> io::Result<()> {
78 let mut total = 0usize;
79 while total < buf.len() {
80 // SAFETY: buf and fd are valid for the lifetime of the call.
81 let ret = unsafe {
82 libc::pwrite64(
83 fd,
84 buf[total..].as_ptr().cast(),
85 buf.len() - total,
86 (offset + total as u64) as libc::off_t,
87 )
88 };
89 if ret < 0 {
90 return Err(io::Error::last_os_error());
91 }
92 if ret == 0 {
93 return Err(io::Error::other("pwrite64 wrote 0 bytes"));
94 }
95 total += ret as usize;
96 }
97 Ok(())
98}
99
100/// RAII wrapper for an aligned heap buffer required by O_DIRECT.
101pub struct AlignedBuf {

Callers 3

cow_write_syncMethod · 0.85
write_vectoredMethod · 0.85
aligned_pwriteFunction · 0.85

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected