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

Method is_block_device

block/src/lib.rs:724–735  ·  view source on GitHub ↗
(f: &File)

Source from the content-addressed store, hash-verified

722
723impl DiskTopology {
724 fn is_block_device(f: &File) -> std::io::Result<bool> {
725 let mut stat = std::mem::MaybeUninit::<libc::stat>::uninit();
726 // SAFETY: FFI call with a valid fd and buffer
727 let ret = unsafe { libc::fstat(f.as_raw_fd(), stat.as_mut_ptr()) };
728 if ret != 0 {
729 return Err(std::io::Error::last_os_error());
730 }
731
732 // SAFETY: stat is valid at this point
733 let is_block = unsafe { (*stat.as_ptr()).st_mode & S_IFMT == S_IFBLK };
734 Ok(is_block)
735 }
736
737 // libc::ioctl() takes different types on different architectures
738 fn query_block_size(f: &File, block_size_type: BlockSize) -> std::io::Result<u64> {

Callers 2

query_device_sizeFunction · 0.80
resizeMethod · 0.80

Calls 2

as_mut_ptrMethod · 0.80
as_raw_fdMethod · 0.45

Tested by

no test coverage detected