Yet more stuff. Direct IO is not working at all.

This commit is contained in:
Cutieguwu
2025-12-31 20:48:51 -05:00
parent 2da0ab11e5
commit 7537107144
4 changed files with 31 additions and 17 deletions

5
Cargo.lock generated
View File

@@ -125,15 +125,16 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",
"libc",
"ron", "ron",
"serde", "serde",
] ]
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.177" version = "0.2.178"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091"
[[package]] [[package]]
name = "memchr" name = "memchr"

View File

@@ -1,9 +1,10 @@
[package] [package]
name = "kramer" name = "kramer"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2024"
[dependencies] [dependencies]
libc = "0.2.178"
# NOTE: # NOTE:
# = X.X.X is the version used in testing. # = X.X.X is the version used in testing.
# Use this version for greatest compatibility. # Use this version for greatest compatibility.

View File

@@ -1,5 +1,6 @@
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};
use std::io::{self, Seek, SeekFrom}; use std::io::{self, Seek, SeekFrom};
use std::os::unix::fs::{FileExt, OpenOptionsExt};
use crate::cli::CONFIG; use crate::cli::CONFIG;
@@ -22,8 +23,18 @@ pub fn get_stream_length<S: Seek>(stream: &mut S) -> io::Result<u64> {
pub fn load_input() -> anyhow::Result<File> { pub fn load_input() -> anyhow::Result<File> {
OpenOptions::new() OpenOptions::new()
.read(true) .read(true)
//.custom_flags(libc::O_DIRECT)
.open(&CONFIG.input) .open(&CONFIG.input)
.with_context(|| format!("Failed to open input file: {}", &CONFIG.input.display())) .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> { pub fn load_output() -> anyhow::Result<File> {
@@ -40,16 +51,10 @@ pub fn load_output() -> anyhow::Result<File> {
}) })
} }
pub fn load_map_read() -> anyhow::Result<File> { pub fn load_map_read() -> std::io::Result<File> {
OpenOptions::new() OpenOptions::new()
.read(true) .read(true)
.open(crate::path::MAP_PATH.clone()) .open(crate::path::MAP_PATH.clone())
.with_context(|| {
format!(
"Failed to open/create mapping file at: {}",
crate::path::MAP_PATH.display()
)
})
} }
pub fn load_map_write() -> anyhow::Result<File> { pub fn load_map_write() -> anyhow::Result<File> {

View File

@@ -2,7 +2,7 @@ use std::fs::File;
use std::io::{BufWriter, Read, Seek, SeekFrom, Write}; use std::io::{BufWriter, Read, Seek, SeekFrom, Write};
use std::usize; use std::usize;
use anyhow::Context; use anyhow::{Context, anyhow};
use crate::cli::CONFIG; use crate::cli::CONFIG;
use crate::mapping::prelude::*; use crate::mapping::prelude::*;
@@ -18,13 +18,16 @@ pub struct Recover {
impl Recover { impl Recover {
pub fn new() -> anyhow::Result<Self> { pub fn new() -> anyhow::Result<Self> {
let input: File = crate::io::load_input()?; let input: File = crate::io::load_input()?;
let output: File = crate::io::load_output()?; let output: File = crate::io::load_output()?;
let map: MapFile = { let map: MapFile = {
crate::io::load_map_read()? if let Ok(f) = crate::io::load_map_read()
.try_into() && let Ok(map_file) = MapFile::try_from(f)
.unwrap_or(MapFile::new(CONFIG.sector_size)) {
map_file
} else {
MapFile::new(CONFIG.sector_size)
}
}; };
let mut r = Recover { let mut r = Recover {
@@ -120,12 +123,15 @@ impl Recover {
println!("Hit error: {:?}", err); println!("Hit error: {:?}", err);
if CONFIG.reopen_on_error { if CONFIG.reopen_on_error {
self.reload_input() self.reload_input()
.context("Failed to reload input file after previous error.")?; .context("Failed to reload input file after previous error")?;
} }
self.input self.input
.seek_relative((read_position + buf_capacity) as i64) .seek_relative(buf_capacity as i64)
.context("Failed to seek input by buf_capacity to skip previous error")?; .context("Failed to seek input by buf_capacity to skip previous error")?;
self.output
.seek_relative(buf_capacity as i64)
.context("Failed to seek output by buf_capacity to skip previous error")?;
// I don't remember what level was for. // I don't remember what level was for.
cluster.stage = Stage::ForIsolation { level: 1 }; cluster.stage = Stage::ForIsolation { level: 1 };
@@ -138,6 +144,7 @@ impl Recover {
} }
self.map.update(cluster); self.map.update(cluster);
self.map.write_to(&mut crate::io::load_map_write()?)?;
read_position += buf_capacity; read_position += buf_capacity;
} }
} }