Skip to main content

FileBlockDevice

Struct FileBlockDevice 

Source
pub struct FileBlockDevice { /* private fields */ }
Expand description

A block device backed by a file on the host filesystem.

This is useful for working with disk images or loopback devices.

Implementations§

Source§

impl FileBlockDevice

Source

pub fn create<P: AsRef<Path>>(path: P, size: u64) -> Result<Self>

Create a new disk image file with the specified size.

§Arguments
  • path - Path to create the file at
  • size - Total size in bytes
  • block_size - Block size (default 512)
§Returns

A new FileBlockDevice wrapping the created file

Source

pub fn create_with_block_size<P: AsRef<Path>>( path: P, size: u64, block_size: u32, ) -> Result<Self>

Create a new disk image file with custom block size.

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open an existing disk image file.

§Arguments
  • path - Path to the file
§Returns

A FileBlockDevice wrapping the file

Source

pub fn open_with_block_size<P: AsRef<Path>>( path: P, block_size: u32, ) -> Result<Self>

Open an existing disk image file with custom block size.

Source

pub fn open_read_only<P: AsRef<Path>>(path: P) -> Result<Self>

Open an existing disk image file in read-only mode.

Source

pub fn open_read_only_with_block_size<P: AsRef<Path>>( path: P, block_size: u32, ) -> Result<Self>

Open an existing disk image file in read-only mode with custom block size.

Trait Implementations§

Source§

impl BlockDevice for FileBlockDevice

Source§

fn read_blocks(&self, block_id: u64, buf: &mut [u8]) -> Result<u32>

Read blocks from the device. Read more
Source§

fn write_blocks(&mut self, block_id: u64, buf: &[u8]) -> Result<u32>

Write blocks to the device. Read more
Source§

fn flush(&mut self) -> Result<()>

Flush any pending writes to the device.
Source§

fn block_size(&self) -> u32

Get the physical block size in bytes.
Source§

fn block_count(&self) -> u64

Get the total number of blocks.
Source§

fn open(&mut self) -> Result<()>

Open the device (called before first I/O operation). Read more
Source§

fn close(&mut self) -> Result<()>

Close the device (called when unmounting). Read more

Auto Trait Implementations§

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> BlockDeviceExt for T
where T: BlockDevice,

Source§

fn total_size(&self) -> u64

Get the total size of the device in bytes.
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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.