Skip to main content

LoopDevice

Struct LoopDevice 

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

An open loop device with a backing file.

The value holds an open descriptor of /dev/loopN. With LoopConfig::autoclear, the kernel detaches the backing file at the last close of the device. A file system that the device holds keeps the device open until its unmount.

Implementations§

Source§

impl LoopDevice

Source

pub fn attach(backing: impl AsFd, cfg: &LoopConfig) -> Result<LoopDevice>

Attaches backing to a free loop device with cfg.

The call asks /dev/loop-control for a free device, opens /dev/loopN, and configures it with LOOP_CONFIGURE in one step. The open is read-only for LoopConfig::read_only, and for reading and writing otherwise. If another process configures the same device first, the kernel returns EBUSY, and the call tries the next free device, up to 10 times.

If the kernel refuses LoopConfig::direct_io with EINVAL, the call configures the same device again without direct I/O. A backing file that does not accept direct I/O gives this refusal.

LOOP_CONFIGURE is available since Linux 5.8.

§Errors
  • An Errno from the open of /dev/loop-control or of /dev/loopN, for example EACCES or EPERM for a process with no access to the loop devices.
  • An Errno from LOOP_CTL_GET_FREE.
  • EBUSY if 10 attempts find the device taken.
  • EINVAL from LOOP_CONFIGURE if the kernel refuses a value of cfg other than LoopConfig::direct_io.
  • Another Errno from LOOP_CONFIGURE.
Source

pub fn number(&self) -> u32

Returns the number N of the device /dev/loopN.

Source

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

Returns the lo_flags value that the kernel holds for the device.

The value is a combination of LO_FLAGS_READ_ONLY, LO_FLAGS_AUTOCLEAR, LO_FLAGS_DIRECT_IO, and other flags of the kernel. A kernel can clear LO_FLAGS_DIRECT_IO when the backing file does not accept direct I/O.

§Errors
  • ENXIO if the device has no backing file.
  • Another Errno from LOOP_GET_STATUS64.

Trait Implementations§

Source§

impl AsFd for LoopDevice

Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the 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

Auto Trait Implementations§

§

impl Forget for LoopDevice

§

impl Freeze for LoopDevice
where I32NotAllOnes: Freeze,

§

impl Move for LoopDevice

§

impl RefUnwindSafe for LoopDevice
where I32NotAllOnes: RefUnwindSafe,

§

impl Send for LoopDevice
where I32NotAllOnes: Send,

§

impl Sync for LoopDevice
where I32NotAllOnes: Sync,

§

impl Unpin for LoopDevice
where I32NotAllOnes: Unpin,

§

impl UnsafeUnpin for LoopDevice
where I32NotAllOnes: UnsafeUnpin,

§

impl UnwindSafe for LoopDevice
where I32NotAllOnes: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.