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

Function probe_sparse_support

block/src/lib.rs:336–359  ·  view source on GitHub ↗

Probe whether the file/device supports punch hole and zero range

(file: &File)

Source from the content-addressed store, hash-verified

334
335/// Probe whether the file/device supports punch hole and zero range
336pub fn probe_sparse_support(file: &File) -> bool {
337 let fd = file.as_raw_fd();
338
339 let is_block_device = {
340 let mut stat = std::mem::MaybeUninit::<libc::stat>::uninit();
341 // SAFETY: FFI call with valid fd and buffer
342 let ret = unsafe { libc::fstat(fd, stat.as_mut_ptr()) };
343 if ret != 0 {
344 warn!(
345 "Failed to stat file descriptor for sparse probe: {}",
346 io::Error::last_os_error()
347 );
348 return false;
349 }
350 // SAFETY: stat result is valid at this point
351 unsafe { (*stat.as_ptr()).st_mode & S_IFMT == S_IFBLK }
352 };
353
354 if is_block_device {
355 probe_block_device_sparse_support(fd)
356 } else {
357 probe_file_sparse_support(fd)
358 }
359}
360
361/// Probe sparse support for a regular file using fallocate().
362fn probe_file_sparse_support(fd: libc::c_int) -> bool {

Callers 1

Calls 4

as_mut_ptrMethod · 0.80
as_raw_fdMethod · 0.45

Tested by

no test coverage detected