| 32 | const BLK_ALIGNMENTS: [usize; 2] = [512, 4096]; |
| 33 | |
| 34 | fn 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 | |
| 49 | impl RawFile { |
| 50 | pub fn new(file: File, direct_io: bool) -> Self { |