Probe whether the file/device supports punch hole and zero range
(file: &File)
| 334 | |
| 335 | /// Probe whether the file/device supports punch hole and zero range |
| 336 | pub 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(). |
| 362 | fn probe_file_sparse_support(fd: libc::c_int) -> bool { |
no test coverage detected