pub struct LoopDevice { /* private fields */ }
Expand description
Interface to a loop device ie /dev/loop0
.
Implementations§
Source§impl LoopDevice
impl LoopDevice
Sourcepub fn open<P: AsRef<Path>>(dev: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(dev: P) -> Result<Self>
Opens a loop device.
§Errors
This function will return an error for various reasons when opening
the given loop device file. See
OpenOptions::open
for further details.
Sourcepub fn with(&self) -> AttachOptions<'_>
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/loop0").unwrap();
ld.with().part_scan(true).attach("disk.img").unwrap();
Sourcepub fn attach_file<P: AsRef<Path>>(&self, backing_file: P) -> Result<()>
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/loop0").unwrap();
ld.attach_file("disk.img").unwrap();
§Errors
This function will return an error for various reasons. Either when
opening the backing file (see
OpenOptions::open
for further details) or when calling the ioctl to attach the backing
file to the device.
Sourcepub fn major(&self) -> Result<u32>
pub fn major(&self) -> Result<u32>
Get the device major number
§Errors
This function needs to stat the backing file and can fail if there is an IO error.
Sourcepub fn minor(&self) -> Result<u32>
pub fn minor(&self) -> Result<u32>
Get the device major number
§Errors
This function needs to stat the backing file and can fail if there is an IO error.
Sourcepub fn detach(&self) -> Result<()>
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/loop0").unwrap();
ld.detach().unwrap();
§Errors
This function will return an error for various reasons when calling the ioctl to detach the backing file from the device.
Sourcepub fn set_capacity(&self) -> Result<()>
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.
§Errors
This function will return an error for various reasons when calling the ioctl to set the capacity of the device.