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

Function is_valid_alignment

block/src/qcow/raw_file.rs:34–47  ·  view source on GitHub ↗
(fd: RawFd, alignment: usize)

Source from the content-addressed store, hash-verified

32const BLK_ALIGNMENTS: [usize; 2] = [512, 4096];
33
34fn is_valid_alignment(fd: RawFd, alignment: usize) -> bool {
35 let layout = Layout::from_size_align(alignment, alignment).unwrap();
36 // SAFETY: layout has non-zero size
37 let ptr = unsafe { alloc_zeroed(layout) };
38 assert!(!ptr.is_null());
39
40 // SAFETY: FFI call
41 let ret = unsafe { ::libc::pread(fd, ptr.cast(), alignment, alignment.try_into().unwrap()) };
42
43 // SAFETY: ptr was allocated by alloc_zeroed with layout
44 unsafe { dealloc(ptr, layout) };
45
46 ret >= 0
47}
48
49impl RawFile {
50 pub fn new(file: File, direct_io: bool) -> Self {

Callers 1

newMethod · 0.85

Calls 1

try_intoMethod · 0.80

Tested by

no test coverage detected