Skip to content

Commit

Permalink
fix: fix visualibility for crate
Browse files Browse the repository at this point in the history
Signed-off-by: Yiyang Wu <[email protected]>
  • Loading branch information
ToolmanP committed Sep 23, 2024
1 parent e0f8d60 commit 8d91bda
Show file tree
Hide file tree
Showing 15 changed files with 263 additions and 64 deletions.
42 changes: 26 additions & 16 deletions erofs-sys/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Copyright 2024 Yiyang Wu SPDX-License-Identifier: MIT or GPL-2.0-or-later
pub(crate) mod backends;
// Copyright 2024 Yiyang Wu
// SPDX-License-Identifier: MIT or GPL-2.0-or-later

/// Backend modules
pub mod backends;
pub(crate) mod raw_iters;

use alloc::boxed::Box;
Expand All @@ -14,54 +17,61 @@ use super::*;

/// Represent some sort of generic data source. This cound be file, memory or even network.
/// Note that users should never use this directly please use backends instead.
pub(crate) trait Source {
pub trait Source {
///Fill data from a raw source into data.
fn fill(&self, data: &mut [u8], device_id: i32, offset: Off) -> PosixResult<u64>;
}

/// Represents a file source.
pub(crate) trait FileSource: Source {}
pub trait FileSource: Source {}

// Represents a memory source. Note that as_buf and as_buf_mut should only represent memory within
// a page. Cross page memory is not supported and treated as an error.
pub(crate) trait PageSource<'a>: Source {
/// Represents a memory source. Note that as_buf and as_buf_mut should only represent memory within
/// a page. Cross page memory is not supported and treated as an error.
pub trait PageSource<'a>: Source {
/// Takes the slice of the data.
fn as_buf(&'a self, device_id: i32, offset: Off, len: Off) -> PosixResult<RefBuffer<'a>>;
}

/// Represents a generic data access backend that is backed by some sort of data source.
/// This often has temporary buffers to decompress the data from the data source.
/// The method signatures are the same as those of the Source trait.
pub(crate) trait Backend {
pub trait Backend {
/// Fill data from a backend source bank.
fn fill(&self, data: &mut [u8], device_id: i32, offset: Off) -> PosixResult<u64>;
}

/// Represents a file backend whose source is a file.
pub(crate) trait FileBackend: Backend {}
pub trait FileBackend: Backend {}

/// Represents a memory backend whose source is memory.
pub(crate) trait MemoryBackend<'a>: Backend {
pub trait MemoryBackend<'a>: Backend {
/// Fill data from a memmap backend source bank.
fn as_buf(&'a self, device_id: i32, offset: Off, len: Off) -> PosixResult<RefBuffer<'a>>;
}

/// Represents a TempBuffer which owns a temporary on-stack/on-heap buffer.
/// Note that file or network backend can only use this since they can't access the data from the
/// memory directly.
pub(crate) struct TempBuffer {
pub struct TempBuffer {
pub(crate) block: Vec<u8>,
pub(crate) start: usize,
pub(crate) maxsize: usize,
}

/// Represents a buffer trait which can yield its internal reference or be casted as an iterator of
/// DirEntries.
pub(crate) trait Buffer {
pub trait Buffer {
/// get the content of internal buffer
fn content(&self) -> &[u8];
/// get the iterative directory
fn iter_dir(&self) -> DirCollection<'_> {
DirCollection::new(self.content())
}
}

impl TempBuffer {
pub(crate) fn new(block: Vec<u8>, start: usize, maxsize: usize) -> Self {
/// Wrap a heap based block with a temp buffer, starting with start and maxsize.
pub fn new(block: Vec<u8>, start: usize, maxsize: usize) -> Self {
Self {
block,
start,
Expand All @@ -78,9 +88,9 @@ impl Buffer for TempBuffer {

/// Represents a buffer that holds a reference to a slice of data that
/// is borrowed from the thin air.
pub(crate) struct RefBuffer<'a> {
buf: &'a [u8],
start: usize,
pub struct RefBuffer<'a> {
pub(crate) buf: &'a [u8],
pub(crate) start: usize,
len: usize,
put_buf: fn(*mut core::ffi::c_void),
}
Expand Down
3 changes: 2 additions & 1 deletion erofs-sys/src/data/backends.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2024 Yiyang Wu
// SPDX-License-Identifier: MIT or GPL-2.0-or-later

pub(crate) mod uncompressed;
/// uncompressed backends.
pub mod uncompressed;
6 changes: 4 additions & 2 deletions erofs-sys/src/data/backends/uncompressed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

use super::super::*;

pub(crate) struct UncompressedBackend<T>
/// An uncompressed Backend for Data Source
pub struct UncompressedBackend<T>
where
T: Source,
{
Expand All @@ -30,7 +31,8 @@ where
}

impl<T: Source> UncompressedBackend<T> {
pub(crate) fn new(source: T) -> Self {
/// Create a new uncompressed backend from source.
pub fn new(source: T) -> Self {
Self { source }
}
}
Expand Down
9 changes: 2 additions & 7 deletions erofs-sys/src/data/raw_iters/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ use super::super::*;

/// Represents a basic iterator over a range of bytes from data backends.
/// The access order is guided by the block maps from the filesystem.
pub(crate) trait BufferMapIter<'a>:
Iterator<Item = PosixResult<Box<dyn Buffer + 'a>>>
{
}
pub trait BufferMapIter<'a>: Iterator<Item = PosixResult<Box<dyn Buffer + 'a>>> {}

/// Represents a basic iterator over a range of bytes from data backends.
/// Note that this is skippable and can be used to move the iterator's cursor forward.
pub(crate) trait ContinuousBufferIter<'a>:
Iterator<Item = PosixResult<Box<dyn Buffer + 'a>>>
{
pub trait ContinuousBufferIter<'a>: Iterator<Item = PosixResult<Box<dyn Buffer + 'a>>> {
fn advance_off(&mut self, offset: Off);
fn eof(&self) -> bool;
}
2 changes: 1 addition & 1 deletion erofs-sys/src/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl From<[u8; 128]> for DeviceSlot {
}

/// Device information.
pub(crate) struct DeviceInfo {
pub struct DeviceInfo {
pub(crate) mask: u16,
pub(crate) specs: Vec<DeviceSpec>,
}
Expand Down
7 changes: 4 additions & 3 deletions erofs-sys/src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) struct DirentDesc {

/// In memory representation of a real directory entry.
#[derive(Debug, Clone, Copy)]
pub(crate) struct Dirent<'a> {
pub struct Dirent<'a> {
pub(crate) desc: DirentDesc,
pub(crate) name: &'a [u8],
}
Expand All @@ -36,7 +36,7 @@ impl From<[u8; size_of::<DirentDesc>()]> for DirentDesc {

/// Create a collection of directory entries from a buffer.
/// This is a helper struct to iterate over directory entries.
pub(crate) struct DirCollection<'a> {
pub struct DirCollection<'a> {
data: &'a [u8],
offset: usize,
total: usize,
Expand Down Expand Up @@ -94,7 +94,8 @@ impl<'a> Iterator for DirCollection<'a> {
}

impl<'a> Dirent<'a> {
pub(crate) fn dirname(&self) -> &'a [u8] {
/// Dirname
pub fn dirname(&self) -> &'a [u8] {
self.name
}
}
Loading

0 comments on commit 8d91bda

Please sign in to comment.