Struct LoopDevice

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

Interface to a loop device ie /dev/loop0.

Implementations§

Source§

impl LoopDevice

Source

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

Opens a loop device.

Source

pub fn with(&self) -> AttachOptions<'_>

Attach the loop device to a file with given options.

§Examples

Attach the device to a file.

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

pub fn attach_file<P: AsRef<Path>>(&self, backing_file: P) -> Result<()>

Attach the loop device to a file that maps to the whole file.

§Examples

Attach the device to a file.

use loopdev::LoopDevice;
let ld = LoopDevice::open("/dev/loop4").unwrap();
ld.attach_file("disk.img").unwrap();
Source

pub fn path(&self) -> Option<PathBuf>

Get the path of the loop device.

Source

pub fn major(&self) -> Result<u32>

Get the device major number

Source

pub fn minor(&self) -> Result<u32>

Get the device major number

Source

pub fn detach(&self) -> Result<()>

Detach a loop device from its backing file.

Note that the device won’t fully detach until a short delay after the underling device file gets closed. This happens when LoopDev goes out of scope so you should ensure the LoopDev lives for a short a time as possible.

§Examples
use loopdev::LoopDevice;
let ld = LoopDevice::open("/dev/loop5").unwrap();
ld.detach().unwrap();
Source

pub fn set_capacity(&self) -> Result<()>

Resize a live loop device. If the size of the backing file changes this can be called to inform the loop driver about the new size.

Trait Implementations§

Source§

impl AsRawFd for LoopDevice

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Debug for LoopDevice

Source§

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

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

impl IntoRawFd for LoopDevice

Source§

fn into_raw_fd(self) -> RawFd

Consumes this object, returning the raw underlying file descriptor. 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> 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.