current status

This commit is contained in:
Moritz Gmeiner 2025-12-07 15:13:28 +01:00
commit b9d588f8ba
3 changed files with 22 additions and 23 deletions

View file

@ -71,9 +71,9 @@ pub struct DirEntry {
file_size: u32,
checksum: u8,
long_name: Option<CompactString>,
n_longname_slots: u8,
long_name: Option<CompactString>,
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<Self> {
pub fn create(name: &str, attr: Attr) -> anyhow::Result<Self> {
// TODO
let now: DateTime<Local> = 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();

View file

@ -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<usize> {
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<()> {

View file

@ -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<u64>,
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}");