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
impl LoopDevice
Sourcepub fn attach(backing: impl AsFd, cfg: &LoopConfig) -> Result<LoopDevice>
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
Errnofrom the open of/dev/loop-controlor of/dev/loopN, for exampleEACCESorEPERMfor a process with no access to the loop devices. - An
ErrnofromLOOP_CTL_GET_FREE. EBUSYif 10 attempts find the device taken.EINVALfromLOOP_CONFIGUREif the kernel refuses a value ofcfgother thanLoopConfig::direct_io.- Another
ErrnofromLOOP_CONFIGURE.
Sourcepub fn flags(&self) -> Result<u32>
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
ENXIOif the device has no backing file.- Another
ErrnofromLOOP_GET_STATUS64.