MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / pwrite_all

Function pwrite_all

nodedb-wal/src/double_write.rs:443–475  ·  view source on GitHub ↗

`pwrite`-retry helper that handles short writes.

(file: &File, data: &[u8], offset: u64)

Source from the content-addressed store, hash-verified

441
442/// `pwrite`-retry helper that handles short writes.
443fn pwrite_all(file: &File, data: &[u8], offset: u64) -> Result<()> {
444 #[cfg(not(target_arch = "wasm32"))]
445 {
446 use std::os::unix::io::AsRawFd as _;
447 let fd = file.as_raw_fd();
448 let mut remaining = data;
449 let mut write_offset = offset;
450 while !remaining.is_empty() {
451 let n = unsafe {
452 libc::pwrite(
453 fd,
454 remaining.as_ptr() as *const libc::c_void,
455 remaining.len(),
456 write_offset as libc::off_t,
457 )
458 };
459 if n < 0 {
460 return Err(WalError::Io(std::io::Error::last_os_error()));
461 }
462 let n = n as usize;
463 remaining = &remaining[n..];
464 write_offset += n as u64;
465 }
466 Ok(())
467 }
468 #[cfg(target_arch = "wasm32")]
469 {
470 let _ = (file, data, offset);
471 Err(WalError::Unsupported {
472 detail: "O_DIRECT pwrite not available on wasm32",
473 })
474 }
475}
476
477#[cfg(test)]
478mod tests {

Callers 2

write_record_deferredMethod · 0.85
flushMethod · 0.85

Calls 4

as_raw_fdMethod · 0.45
is_emptyMethod · 0.45
as_ptrMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected