1#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "windows")))]
13std::compile_error!(
14 "Your operating system is not supported, yet. \
15 Please open an issue on GitHub: \
16 https://github.com/mbuesch/disktest/issues"
17);
18
19use anyhow as ah;
20use std::path::Path;
21
22#[cfg(any(target_os = "linux", target_os = "android"))]
23mod linux;
24
25#[cfg(target_os = "windows")]
26mod windows;
27
28pub const DEFAULT_SECTOR_SIZE: u32 = 512;
29
30pub trait RawIoOsIntf: Sized {
32 fn new(path: &Path, create: bool, read: bool, write: bool) -> ah::Result<Self>;
34
35 fn get_sector_size(&self) -> Option<u32>;
38
39 fn drop_file_caches(&mut self, offset: u64, size: u64) -> ah::Result<()>;
42
43 fn close(&mut self) -> ah::Result<()>;
46
47 fn sync(&mut self) -> ah::Result<()>;
50
51 fn set_len(&mut self, size: u64) -> ah::Result<()>;
54
55 fn seek(&mut self, offset: u64) -> ah::Result<u64>;
57
58 fn read(&mut self, buffer: &mut [u8]) -> ah::Result<RawIoResult>;
60
61 fn write(&mut self, buffer: &[u8]) -> ah::Result<RawIoResult>;
63}
64
65pub enum RawIoResult {
67 Ok(usize),
69 Enospc,
71}
72
73#[cfg(any(target_os = "linux", target_os = "android"))]
74pub use crate::linux::RawIoLinux as RawIo;
75
76#[cfg(target_os = "windows")]
77pub use crate::windows::RawIoWindows as RawIo;
78
79