fat-rs/fat-fuse/src/lib.rs

47 lines
902 B
Rust
Raw Normal View History

mod fuse;
mod inode;
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::rc::Rc;
2025-07-27 14:38:31 +02:00
use fat_bits::{FatFs, SliceLike};
use crate::inode::Inode;
2025-07-27 14:38:31 +02:00
#[allow(dead_code)]
pub struct FatFuse {
fat_fs: FatFs,
2025-07-27 14:38:31 +02:00
uid: u32,
gid: u32,
next_fd: u32,
inode_table: BTreeMap<u64, Inode>,
2025-07-27 14:38:31 +02:00
}
impl FatFuse {
pub fn new(data: Rc<RefCell<dyn SliceLike>>) -> anyhow::Result<FatFuse> {
2025-07-27 14:38:31 +02:00
let uid = unsafe { libc::getuid() };
let gid = unsafe { libc::getgid() };
let fat_fs = FatFs::load(data)?;
Ok(FatFuse {
fat_fs,
uid,
gid,
next_fd: 0,
inode_table: BTreeMap::new(),
})
2025-07-27 14:38:31 +02:00
}
fn get_inode(&self, ino: u64) -> Option<&Inode> {
self.inode_table.get(&ino)
2025-07-27 14:38:31 +02:00
}
fn get_inode_mut(&mut self, ino: u64) -> Option<&mut Inode> {
self.inode_table.get_mut(&ino)
2025-07-27 14:38:31 +02:00
}
}