use anyhow::Result;
use std::io::{Read, Write};
pub trait DeviceReader: Read {
fn open(device_path: &str) -> Result<Self>
where
Self: Sized;
fn device_size(&self) -> Result<u64>;
}
pub trait DeviceWriter: Write {
fn open(device_path: &str) -> Result<Self>
where
Self: Sized;
fn flush_and_sync(&mut self) -> Result<()>;
fn supports_incremental_sync(&self) -> bool {
false
}
fn sync_written_range(&mut self, offset: u64, len: u64) -> Result<()> {
let _ = (offset, len);
Ok(())
}
fn flush_and_sync_with_progress(
&mut self,
sync_bytes: u64,
mut on_progress: Option<&mut dyn FnMut(u64, u64)>,
) -> Result<()> {
if let Some(callback) = on_progress.as_mut() {
callback(0, sync_bytes);
}
self.flush_and_sync()?;
if let Some(callback) = on_progress.as_mut() {
callback(sync_bytes, sync_bytes);
}
Ok(())
}
fn device_size(&self) -> Result<u64>;
fn write_at(&mut self, offset: u64, buf: &[u8]) -> Result<()> {
let _ = (offset, buf);
anyhow::bail!("write_at is not supported on this platform")
}
fn supports_inline_verify(&self) -> bool {
false
}
fn rewind_for_verify(&mut self) -> Result<()> {
anyhow::bail!("rewind_for_verify is not supported on this platform")
}
fn read_for_verify(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
let _ = buf;
Err(std::io::Error::new(
std::io::ErrorKind::Unsupported,
"read_for_verify is not supported on this platform",
))
}
}