From 2df9e8e0f2202c556dad2e8f92d09f96fe021ae5 Mon Sep 17 00:00:00 2001 From: Cutieguwu Date: Thu, 1 Jan 2026 01:09:41 -0500 Subject: [PATCH] Fix reading. --- src/io.rs | 4 ++-- src/recovery.rs | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/io.rs b/src/io.rs index 74e7ef4..8d3f824 100644 --- a/src/io.rs +++ b/src/io.rs @@ -1,6 +1,6 @@ use std::fs::{File, OpenOptions}; use std::io::{self, Seek, SeekFrom}; -use std::os::unix::fs::{FileExt, OpenOptionsExt}; +use std::os::unix::fs::OpenOptionsExt; use crate::cli::CONFIG; @@ -23,7 +23,7 @@ pub fn get_stream_length(stream: &mut S) -> io::Result { pub fn load_input() -> anyhow::Result { OpenOptions::new() .read(true) - //.custom_flags(libc::O_DIRECT) + .custom_flags(libc::O_DIRECT) .open(&CONFIG.input) .with_context(|| format!("Failed to open input file: {}", &CONFIG.input.display())) diff --git a/src/recovery.rs b/src/recovery.rs index f641002..65f2a6b 100644 --- a/src/recovery.rs +++ b/src/recovery.rs @@ -94,14 +94,18 @@ impl Recover { // Caching. let mut read_position: usize; let mut cluster: Cluster; + let mut buf: Vec; let mut buf_capacity = self.get_buf_capacity() as usize; - let mut buf = vec![crate::FB_NULL_VALUE; buf_capacity]; + dbg!(untested.domain); read_position = untested.domain.start; while read_position < untested.domain.end { dbg!(read_position); + buf_capacity = buf_capacity.min(untested.domain.end - read_position); + buf = vec![crate::FB_NULL_VALUE; buf_capacity]; + cluster = Cluster { domain: Domain { start: read_position, @@ -110,8 +114,6 @@ impl Recover { stage: Stage::Intact, }; - buf_capacity = buf_capacity.min(untested.domain.end - read_position); - if let Err(err) = self.input.read_exact(&mut buf) { // If buf were zeroed out before every read, one could theoretically recover // part of that read given the assumption that all null values from the end to