From b9d588f8baf5fb4a8647d8378d1418d47605e6e2 Mon Sep 17 00:00:00 2001 From: Moritz Gmeiner Date: Sun, 7 Dec 2025 15:13:28 +0100 Subject: [PATCH] current status --- fat-bits/src/dir.rs | 20 +++++++++++--------- fat-bits/src/iter.rs | 10 ++++++++-- fat-fuse/src/fuse.rs | 15 +++------------ 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/fat-bits/src/dir.rs b/fat-bits/src/dir.rs index 8b8ab6c..e11970e 100644 --- a/fat-bits/src/dir.rs +++ b/fat-bits/src/dir.rs @@ -71,9 +71,9 @@ pub struct DirEntry { file_size: u32, checksum: u8, - long_name: Option, - n_longname_slots: u8, + long_name: Option, + n_slots: u8, offset: u64, } @@ -154,13 +154,13 @@ impl DirEntry { write_date, file_size, long_name: None, - n_longname_slots: 0, + n_slots: 0, checksum: Self::checksum(&bytes[..11]), offset, }) } - pub fn create(_name: &str, attr: Attr) -> anyhow::Result { + pub fn create(name: &str, attr: Attr) -> anyhow::Result { // TODO let now: DateTime = SystemTime::now().into(); @@ -168,7 +168,7 @@ impl DirEntry { let create_time = Time::from_datetime(now)?; let create_time_tenths = (now.time().nanosecond() / 100_000_000) as u8; - let name = [0; 11]; + let mut name = [0; 11]; Ok(DirEntry { name, @@ -183,12 +183,14 @@ impl DirEntry { file_size: 0, checksum: Self::checksum(&name), long_name: None, - n_longname_slots: 0, + n_slots: 0, offset: !0, }) } fn write(&self, mut writer: impl Write) -> std::io::Result<()> { + assert_ne!(self.offset, !0); + let mut buf = [0; 32]; buf[..11].copy_from_slice(self.name()); @@ -360,9 +362,8 @@ impl DirEntry { self.long_name.as_deref() } - pub fn set_long_name(&mut self, long_name: CompactString, n_slots: u8) { + pub fn set_long_name(&mut self, long_name: CompactString) { self.long_name = Some(long_name); - self.n_longname_slots = n_slots; } pub fn attr(&self) -> Attr { @@ -712,7 +713,8 @@ impl Iterator for DirIter<'_> { let long_filename: CompactString = char::decode_utf16(iter).filter_map(|x| x.ok()).collect(); - dir_entry.set_long_name(long_filename, n_slots); + dir_entry.set_long_name(long_filename); + dir_entry.n_slots = n_slots; } me.long_filename_buf.reset(); diff --git a/fat-bits/src/iter.rs b/fat-bits/src/iter.rs index 6c2a9d9..8cdb54f 100644 --- a/fat-bits/src/iter.rs +++ b/fat-bits/src/iter.rs @@ -173,7 +173,7 @@ impl<'a> ClusterChainWriter<'a> { debug!("next cluster: {next_cluster}"); - self.fat_fs.cluster_as_subslice_mut(next_cluster); + self.sub_slice = self.fat_fs.cluster_as_subslice_mut(next_cluster); self.cur_cluster = next_cluster; true @@ -207,13 +207,19 @@ impl<'a> ClusterChainWriter<'a> { impl Write for ClusterChainWriter<'_> { fn write(&mut self, buf: &[u8]) -> std::io::Result { + debug!("ClusterChainWriter: trying to write {} bytes...", buf.len()); + if self.sub_slice.is_empty() { + debug!("sub_slice is empty, trying to advance..."); + if !(self.move_to_next_cluster()) { + debug!("failed to move to next cluster, returning Ok(0)"); + return Ok(0); } } - self.sub_slice.write(buf) + dbg!(self.sub_slice.write(buf)) } fn flush(&mut self) -> std::io::Result<()> { diff --git a/fat-fuse/src/fuse.rs b/fat-fuse/src/fuse.rs index 1df0e03..18813f6 100644 --- a/fat-fuse/src/fuse.rs +++ b/fat-fuse/src/fuse.rs @@ -355,8 +355,6 @@ impl Filesystem for FatFuse { let flags = OpenFlags::from_bits_truncate(flags); - debug!("flags: {flags:?}"); - let Some(inode) = self.get_inode(ino).cloned() else { debug!("inode {ino} not found"); @@ -379,8 +377,6 @@ impl Filesystem for FatFuse { debug!("fh {} was associated with ino {}, now with ino {}", fh, old_ino, ino); } - debug!("opened inode {}: fh {}", ino, fh); - if flags.contains(OpenFlags::Truncate) { inode.update_size(0); inode.update_mtime(SystemTime::now()); @@ -443,8 +439,6 @@ impl Filesystem for FatFuse { let file_size = inode.size(); - debug!("file_size: {}", file_size); - if offset > file_size { debug!("tried to read after EOF"); @@ -480,7 +474,7 @@ impl Filesystem for FatFuse { let mut buf = vec![0; size as usize]; - let bytes_read = match reader.read(&mut buf) { + match reader.read_exact(&mut buf) { Ok(n) => n, Err(err) => { error!("error while reading: {err}"); @@ -489,13 +483,10 @@ impl Filesystem for FatFuse { return; } }; - if bytes_read != size as usize { - debug!("expected to read {size} bytes, but only read {bytes_read}"); - } inode.update_atime(SystemTime::now()); - reply.data(&buf[..bytes_read]); + reply.data(&buf); // TODO: update access time } @@ -512,7 +503,7 @@ impl Filesystem for FatFuse { _lock_owner: Option, reply: fuser::ReplyWrite, ) { - debug!("new write request: ino={ino} fh={fh} offset={offset} data={data:?}"); + debug!("new write request: ino={ino} fh={fh} offset={offset}"); // data={data:?} if offset < 0 { debug!("tried to write with negative offset {offset}");