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

Function zero_tail

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

Fill the unwritten tail of `buf` with zero bytes so an O_DIRECT write of the entire aligned slot does not leak stale buffer contents to disk.

(buf: &mut AlignedBuf)

Source from the content-addressed store, hash-verified

420/// Fill the unwritten tail of `buf` with zero bytes so an O_DIRECT write of
421/// the entire aligned slot does not leak stale buffer contents to disk.
422fn zero_tail(buf: &mut AlignedBuf) {
423 let written = buf.len();
424 let cap = buf.capacity();
425 if written < cap {
426 // SAFETY: `as_mut_ptr` is valid for `capacity` bytes; we write only
427 // the uninitialized tail between `written..capacity`.
428 unsafe {
429 std::ptr::write_bytes(buf.as_mut_ptr().add(written), 0, cap - written);
430 }
431 }
432}
433
434/// View the entire allocated capacity of `buf` as a byte slice. Requires
435/// that the caller has zeroed any unwritten tail (see `zero_tail`).

Callers 2

write_record_deferredMethod · 0.85
flushMethod · 0.85

Calls 4

lenMethod · 0.45
capacityMethod · 0.45
addMethod · 0.45
as_mut_ptrMethod · 0.45

Tested by

no test coverage detected