Struct AttachOptions

Source
pub struct AttachOptions<'d> { /* private fields */ }
Expand description

Used to set options when attaching a device. Created with LoopDevice::with().

§Examples

Enable partition scanning on attach:

use loopdev::LoopDevice;
let mut ld = LoopDevice::open("/dev/loop6").unwrap();
ld.with()
    .part_scan(true)
    .attach("disk.img")
    .unwrap();

A 1MiB slice of the file located at 1KiB into the file.

use loopdev::LoopDevice;
let mut ld = LoopDevice::open("/dev/loop7").unwrap();
ld.with()
    .offset(1024*1024)
    .size_limit(1024*1024*1024)
    .attach("disk.img")
    .unwrap();

Implementations§

Source§

impl AttachOptions<'_>

Source

pub fn offset(self, offset: u64) -> Self

Offset in bytes from the start of the backing file the data will start at.

Source

pub fn size_limit(self, size_limit: u64) -> Self

Maximum size of the data in bytes.

Source

pub fn read_only(self, read_only: bool) -> Self

Set read only flag

Source

pub fn autoclear(self, read_only: bool) -> Self

Set autoclear flag

Source

pub fn part_scan(self, enable: bool) -> Self

Force the kernel to scan the partition table on a newly created loop device. Note that the partition table parsing depends on sector sizes. The default is sector size is 512 bytes

Source

pub fn attach(self, backing_file: impl AsRef<Path>) -> Result<()>

Attach the loop device to a file with the set options.

Source

pub fn attach_fd(self, backing_file_fd: impl AsRawFd) -> Result<()>

Attach the loop device to an fd

Auto Trait Implementations§

§

impl<'d> Freeze for AttachOptions<'d>

§

impl<'d> RefUnwindSafe for AttachOptions<'d>

§

impl<'d> Send for AttachOptions<'d>

§

impl<'d> Sync for AttachOptions<'d>

§

impl<'d> Unpin for AttachOptions<'d>

§

impl<'d> UnwindSafe for AttachOptions<'d>

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