diff --git a/src/fs.rs b/src/fs.rs index 5bbdaea1..f777d1fa 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -72,6 +72,19 @@ pub struct Allocation { state: ll::lfs_t, } +/// # Safety +/// +/// All operations are done on `&mut Allocation, and the reference is held +/// during the entire lifetime of the filesystem, so once the reference is +/// available again, the filesystem is closed +unsafe impl Sync for Allocation {} +/// # Safety +/// +/// All operations are done on `&mut Allocation, and the reference is held +/// during the entire lifetime of the filesystem, so once the reference is +/// available again, the filesystem is closed +unsafe impl Send for Allocation {} + // pub fn check_storage_requirements( impl Default for Allocation { @@ -803,7 +816,7 @@ impl OpenOptions { pub unsafe fn open<'a, 'b, S: driver::Storage>( &self, fs: &'b Filesystem<'a, S>, - alloc: &mut FileAllocation, + alloc: &'b mut FileAllocation, path: &Path, ) -> Result> { alloc.config.buffer = alloc.cache.get() as *mut _; @@ -1544,4 +1557,21 @@ mod tests { }) .unwrap(); } + + #[allow(unreachable_code)] + fn _filesystem_is_sync() { + fn assert_is_sync(_: &T) -> R { + todo!() + } + fn assert_is_send(_: &T) -> R { + todo!() + } + + assert_is_sync::, ()>(todo!()); + assert_is_send::<&mut Allocation, ()>(todo!()); + assert_is_send::>, ()>(todo!()); + + let mut test_storage = TestStorage::new(); + Filesystem::mount_and_then(&mut test_storage, |fs| assert_is_send(fs)).unwrap() + } }