diff --git a/examples/sample.rs b/examples/sample.rs index dcbb5cf..bb77a7a 100644 --- a/examples/sample.rs +++ b/examples/sample.rs @@ -7,7 +7,7 @@ use std::str; use rustfat::FatFileSystem; fn main() { - let file = File::open("resources/fat12.img").unwrap(); + let file = File::open("resources/fat32.img").unwrap(); let buf_rdr = BufReader::new(file); let mut fs = FatFileSystem::new(Box::new(buf_rdr)).unwrap(); let mut root_dir = fs.root_dir(); diff --git a/src/dir.rs b/src/dir.rs index 429b2df..a666116 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -64,7 +64,7 @@ impl FatDirEntry { } pub fn get_file(&self) -> FatFile { - FatFile::new(self.get_cluster(), self.size, self.state.clone()) + FatFile::new(self.get_cluster(), Some(self.size), self.state.clone()) } pub fn get_size(&self) -> u32 { diff --git a/src/file.rs b/src/file.rs index cf58527..5e13d1f 100644 --- a/src/file.rs +++ b/src/file.rs @@ -8,14 +8,14 @@ use fs::FatSharedStateRef; #[allow(dead_code)] pub struct FatFile { first_cluster: u32, - size: u32, + size: Option, offset: u32, current_cluster: Option, state: FatSharedStateRef, } impl FatFile { - pub(crate) fn new(first_cluster: u32, size: u32, state: FatSharedStateRef) -> FatFile { + pub(crate) fn new(first_cluster: u32, size: Option, state: FatSharedStateRef) -> FatFile { FatFile { first_cluster, size, state, current_cluster: Some(first_cluster), @@ -32,9 +32,9 @@ impl Read for FatFile { loop { let offset_in_cluster = self.offset % cluster_size; let bytes_left_in_cluster = (cluster_size - offset_in_cluster) as usize; - let bytes_left_in_file = (self.size - self.offset) as usize; + let bytes_left_in_file = self.size.map(|size| (size - self.offset) as usize).unwrap_or(bytes_left_in_cluster); let bytes_left_in_buf = buf.len() - buf_offset; - let read_size = cmp::min(cmp::min(bytes_left_in_file, bytes_left_in_cluster), bytes_left_in_buf); + let read_size = cmp::min(cmp::min(bytes_left_in_buf, bytes_left_in_cluster), bytes_left_in_file); if read_size == 0 { break; } diff --git a/src/fs.rs b/src/fs.rs index ed453e8..f2e88ca 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -244,7 +244,7 @@ impl FatFileSystem { let root_rdr: Box = match state.fat_type { FatType::Fat12 | FatType::Fat16 => Box::new(FatSlice::from_sectors( state.first_data_sector - state.root_dir_sectors, state.root_dir_sectors, self.state.clone())), - _ => Box::new(FatFile::new(state.boot.bpb.root_cluster, state.root_dir_sectors, self.state.clone())) + _ => Box::new(FatFile::new(state.boot.bpb.root_cluster, None, self.state.clone())) // FIXME }; FatDir::new(root_rdr, self.state.clone()) }