Struct fuse_backend_rs::common::file_buf::FileVolatileSlice

source ·
pub struct FileVolatileSlice<'a> { /* private fields */ }
Expand description

An adapter structure to work around limitations of the vm-memory crate.

It solves the compilation failure by masking out the vm_memory::BitmapSlice generic type parameter of vm_memory::VolatileSlice.

Implementations§

source§

impl<'a> FileVolatileSlice<'a>

source

pub unsafe fn from_raw_ptr(addr: *mut u8, size: usize) -> Self

Create a new instance of FileVolatileSlice from a raw pointer.

§Safety

To use this safely, the caller must guarantee that the memory at addr is size bytes long and is available for the duration of the lifetime of the new FileVolatileSlice. The caller must also guarantee that all other users of the given chunk of memory are using volatile accesses.

§Example
let mut buffer = [0u8; 1024];
let s = unsafe { FileVolatileSlice::from_raw_ptr(buffer.as_mut_ptr(), buffer.len()) };

{
    let o: u32 = s.load(0x10, Ordering::Acquire).unwrap();
    assert_eq!(o, 0);
    s.store(1u8, 0x10, Ordering::Release).unwrap();

    let s2 = s.as_volatile_slice();
    let s3 = FileVolatileSlice::from_volatile_slice(&s2);
    assert_eq!(s3.len(), 1024);
}

assert_eq!(buffer[0x10], 1);
source

pub unsafe fn from_mut_slice(buf: &'a mut [u8]) -> Self

Create a new instance of FileVolatileSlice from a mutable slice.

§Safety

The caller must guarantee that all other users of the given chunk of memory are using volatile accesses.

source

pub fn from_volatile_slice<S: BitmapSlice>(s: &VolatileSlice<'a, S>) -> Self

Create a new FileVolatileSlice from vm_memory::VolatileSlice and strip off the vm_memory::BitmapSlice.

The caller needs to handle dirty page tracking for the data buffer.

source

pub fn as_volatile_slice(&self) -> VolatileSlice<'a, ()>

Create a vm_memory::VolatileSlice from FileVolatileSlice without dirty page tracking.

source

pub unsafe fn borrow_as_buf(&self, inited: bool) -> FileVolatileBuf

Borrow as a FileVolatileSlice object to temporarily elide the lifetime parameter.

§Safety

The FileVolatileSlice is borrowed without a lifetime parameter, so the caller must ensure that FileVolatileBuf doesn’t out-live the borrowed FileVolatileSlice object.

source

pub fn as_ptr(&self) -> *mut u8

Return a pointer to the start of the slice.

source

pub fn len(&self) -> usize

Get the size of the slice.

source

pub fn is_empty(&self) -> bool

Check if the slice is empty.

source

pub fn offset(&self, count: usize) -> Result<Self, Error>

Return a subslice of this FileVolatileSlice starting at offset.

Trait Implementations§

source§

impl<'a> Bytes<usize> for FileVolatileSlice<'a>

§

type E = Error

Associated error codes
source§

fn write(&self, buf: &[u8], addr: usize) -> Result<usize, Self::E>

Writes a slice into the container at addr. Read more
source§

fn read(&self, buf: &mut [u8], addr: usize) -> Result<usize, Self::E>

Reads data from the container at addr into a slice. Read more
source§

fn write_slice(&self, buf: &[u8], addr: usize) -> Result<(), Self::E>

Writes the entire content of a slice into the container at addr. Read more
source§

fn read_slice(&self, buf: &mut [u8], addr: usize) -> Result<(), Self::E>

Reads data from the container at addr to fill an entire slice. Read more
source§

fn read_from<F>( &self, addr: usize, src: &mut F, count: usize, ) -> Result<usize, Self::E>
where F: Read,

Reads up to count bytes from an object and writes them into the container at addr. Read more
source§

fn read_exact_from<F>( &self, addr: usize, src: &mut F, count: usize, ) -> Result<(), Self::E>
where F: Read,

Reads exactly count bytes from an object and writes them into the container at addr. Read more
source§

fn write_to<F>( &self, addr: usize, dst: &mut F, count: usize, ) -> Result<usize, Self::E>
where F: Write,

Reads up to count bytes from the container at addr and writes them it into an object. Read more
source§

fn write_all_to<F>( &self, addr: usize, dst: &mut F, count: usize, ) -> Result<(), Self::E>
where F: Write,

Reads exactly count bytes from the container at addr and writes them into an object. Read more
source§

fn store<T: AtomicAccess>( &self, val: T, addr: usize, order: Ordering, ) -> Result<(), Self::E>

Atomically store a value at the specified address.
source§

fn load<T: AtomicAccess>( &self, addr: usize, order: Ordering, ) -> Result<T, Self::E>

Atomically load a value from the specified address.
source§

fn write_obj<T>(&self, val: T, addr: A) -> Result<(), Self::E>
where T: ByteValued,

Writes an object into the container at addr. Read more
source§

fn read_obj<T>(&self, addr: A) -> Result<T, Self::E>
where T: ByteValued,

Reads an object from the container at addr. Read more
source§

impl<'a> Clone for FileVolatileSlice<'a>

source§

fn clone(&self) -> FileVolatileSlice<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for FileVolatileSlice<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Copy for FileVolatileSlice<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for FileVolatileSlice<'a>

§

impl<'a> RefUnwindSafe for FileVolatileSlice<'a>

§

impl<'a> Send for FileVolatileSlice<'a>

§

impl<'a> Sync for FileVolatileSlice<'a>

§

impl<'a> Unpin for FileVolatileSlice<'a>

§

impl<'a> UnwindSafe for FileVolatileSlice<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.