mod memory_vfs;
#[cfg(feature = "std")]
mod std_vfs;
#[cfg(feature = "std")]
mod write_through_vfs;
#[cfg(all(feature = "std", target_os = "linux"))]
mod std_direct_vfs;
use core::sync::atomic::Ordering;
#[cfg(all(feature = "std", target_os = "linux"))]
pub(crate) use std_direct_vfs::StdDirectVfs;
#[cfg(all(feature = "std", target_os = "linux"))]
mod io_uring_vfs;
#[cfg(all(feature = "std", target_os = "linux"))]
pub(crate) use io_uring_vfs::IoUringVfs;
pub(crate) use memory_vfs::MemoryVfs;
#[cfg(feature = "std")]
pub(crate) use std_vfs::StdVfs;
#[cfg(feature = "std")]
pub(crate) use write_through_vfs::WriteThroughVfs;
use crate::bf_tree::error::IoErrorKind;
use crate::bf_tree::nodes::DISK_PAGE_SIZE;
pub(crate) trait VfsImpl: Send + Sync {
fn read(&self, offset: usize, buf: &mut [u8]) -> Result<(), IoErrorKind>;
fn write(&self, offset: usize, buf: &[u8]) -> Result<(), IoErrorKind>;
fn alloc_offset(&self, size: usize) -> usize;
fn dealloc_offset(&self, offset: usize);
fn flush(&self) -> Result<(), IoErrorKind>;
}
pub(crate) fn buffer_alloc(layout: alloc::alloc::Layout) -> *mut u8 {
unsafe { alloc::alloc::alloc(layout) }
}
pub(crate) fn buffer_dealloc(ptr: *mut u8, layout: alloc::alloc::Layout) {
unsafe { alloc::alloc::dealloc(ptr, layout) }
}
pub(crate) struct OffsetAlloc {
next_available_offset: crate::bf_tree::sync::atomic::AtomicUsize,
}
impl OffsetAlloc {
pub(crate) fn new_with(mut offset: usize) -> Self {
if offset < DISK_PAGE_SIZE {
offset = DISK_PAGE_SIZE;
}
Self {
next_available_offset: crate::bf_tree::sync::atomic::AtomicUsize::new(offset),
}
}
pub(crate) fn alloc(&self, size: usize) -> usize {
self.next_available_offset.fetch_add(size, Ordering::AcqRel)
}
pub(crate) fn dealloc_offset(&self, _offset: usize) {
}
}