DirectIO is working! Also a bit more cleanup.

This commit is contained in:
Cutieguwu
2026-01-01 23:22:26 -05:00
parent 1607f7ebfa
commit 53d773e2ea
5 changed files with 30 additions and 34 deletions

View File

@@ -20,39 +20,12 @@ pub fn get_stream_length<S: Seek>(stream: &mut S) -> io::Result<u64> {
len
}
/*
* IO Error Poisoning:
*
*
* Attempt 1:
*
* Wrap C calls w/ `ffi`. Most importantly, execute the `close()` through C.
*
*
* Attempt 2:
*
* Return to using safe-on-the-surface Rust, but attempt to execute the reads
* via a separate thread, hoping that the observed poisoning goes away with the
* thread being closed and doesn't affect the main thread.
*
* May need `mpsc` to transfer data without spawning a thread on every read.
*/
pub fn load_input() -> anyhow::Result<File> {
OpenOptions::new()
.read(true)
.custom_flags(libc::O_DIRECT)
.open(&CONFIG.input)
.with_context(|| format!("Failed to open input file: {}", &CONFIG.input.display()))
/*
use std::ffi::CString;
use std::os::fd::FromRawFd;
let path = CString::new(CONFIG.input.to_str().unwrap().to_owned()).unwrap();
let flags = libc::O_DIRECT | libc::O_RDONLY;
let f = unsafe { File::from_raw_fd(libc::open(path.as_ptr(), flags)) };
*/
}
pub fn load_output() -> anyhow::Result<File> {
@@ -88,3 +61,18 @@ pub fn load_map_write() -> anyhow::Result<File> {
)
})
}
#[repr(C, align(512))]
pub struct DirectIOBuffer(pub [u8; crate::MAX_BUFFER_SIZE]);
impl Default for DirectIOBuffer {
fn default() -> Self {
Self([crate::FB_NULL_VALUE; _])
}
}
impl From<[u8; crate::MAX_BUFFER_SIZE]> for DirectIOBuffer {
fn from(value: [u8; crate::MAX_BUFFER_SIZE]) -> Self {
Self(value)
}
}