diff --git a/fat-bits/src/bpb.rs b/fat-bits/src/bpb.rs index 26e4223..362346c 100644 --- a/fat-bits/src/bpb.rs +++ b/fat-bits/src/bpb.rs @@ -236,6 +236,7 @@ impl Bpb { if self.fat_type() == FatType::Fat32 { return None; } + Some(self.fat_offset() + self.sector_to_offset(self.num_fats() as u32 * self.fat_size())) } diff --git a/fat-bits/src/lib.rs b/fat-bits/src/lib.rs index f17275c..5db4130 100644 --- a/fat-bits/src/lib.rs +++ b/fat-bits/src/lib.rs @@ -98,8 +98,15 @@ pub struct FatFs { fat: fat::Fat, } +unsafe impl Send for FatFs {} + impl FatFs { - pub fn load(data: Rc>) -> anyhow::Result { + pub fn load(data: S) -> anyhow::Result + where + S: SliceLike + Send + 'static, + { + let data = Rc::new(RefCell::new(data)); + let mut bpb_bytes = [0; 512]; data.borrow_mut().read_at_offset(0, &mut bpb_bytes)?; diff --git a/fat-dump/src/main.rs b/fat-dump/src/main.rs index 2ddc569..39e16ff 100644 --- a/fat-dump/src/main.rs +++ b/fat-dump/src/main.rs @@ -22,7 +22,7 @@ pub fn main() -> anyhow::Result<()> { // println!("{}", bpb); - let fat_fs = FatFs::load(Rc::new(RefCell::new(file)))?; + let fat_fs = FatFs::load(file)?; println!("{}", fat_fs.bpb()); println!(); diff --git a/fat-fuse/src/lib.rs b/fat-fuse/src/lib.rs index e3a77c3..309e0e0 100644 --- a/fat-fuse/src/lib.rs +++ b/fat-fuse/src/lib.rs @@ -26,7 +26,10 @@ pub struct FatFuse { } impl FatFuse { - pub fn new(data: Rc>) -> anyhow::Result { + pub fn new(data: S) -> anyhow::Result + where + S: SliceLike + Send + 'static, + { let uid = unsafe { libc::getuid() }; let gid = unsafe { libc::getgid() }; diff --git a/fat-mount/src/main.rs b/fat-mount/src/main.rs index f9ea244..d1e5bef 100644 --- a/fat-mount/src/main.rs +++ b/fat-mount/src/main.rs @@ -15,7 +15,7 @@ fn main() -> anyhow::Result<()> { let file = File::open(path)?; - let fat_fuse = FatFuse::new(Rc::new(RefCell::new(file)))?; + let fat_fuse = FatFuse::new(file)?; let options = vec![ MountOption::RO,