Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ pub struct Allocation<Storage: driver::Storage> {
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<Storage: driver::Storage> Sync for Allocation<Storage> {}
/// # 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<Storage: driver::Storage> Send for Allocation<Storage> {}

// pub fn check_storage_requirements(

impl<Storage: driver::Storage> Default for Allocation<Storage> {
Expand Down Expand Up @@ -803,7 +816,7 @@ impl OpenOptions {
pub unsafe fn open<'a, 'b, S: driver::Storage>(
&self,
fs: &'b Filesystem<'a, S>,
alloc: &mut FileAllocation<S>,
alloc: &'b mut FileAllocation<S>,
path: &Path,
) -> Result<File<'a, 'b, S>> {
alloc.config.buffer = alloc.cache.get() as *mut _;
Expand Down Expand Up @@ -1544,4 +1557,21 @@ mod tests {
})
.unwrap();
}

#[allow(unreachable_code)]
fn _filesystem_is_sync() {
fn assert_is_sync<T: Sync, R>(_: &T) -> R {
todo!()
}
fn assert_is_send<T: Send, R>(_: &T) -> R {
todo!()
}

assert_is_sync::<Allocation<TestStorage>, ()>(todo!());
assert_is_send::<&mut Allocation<TestStorage>, ()>(todo!());
assert_is_send::<RefCell<&mut Allocation<TestStorage>>, ()>(todo!());

let mut test_storage = TestStorage::new();
Filesystem::mount_and_then(&mut test_storage, |fs| assert_is_send(fs)).unwrap()
}
}