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/loop0").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/loop0").unwrap();
ld.with()
.offset(1024*1024)
.size_limit(1024*1024*1024)
.attach("disk.img")
.unwrap();
Implementations§
Source§impl AttachOptions<'_>
impl AttachOptions<'_>
Sourcepub fn offset(self, offset: u64) -> Self
pub fn offset(self, offset: u64) -> Self
Offset in bytes from the start of the backing file the data will start at.
Sourcepub fn size_limit(self, size_limit: u64) -> Self
pub fn size_limit(self, size_limit: u64) -> Self
Maximum size of the data in bytes.
Sourcepub fn part_scan(self, enable: bool) -> Self
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
Sourcepub fn attach(self, backing_file: impl AsRef<Path>) -> Result<()>
pub fn attach(self, backing_file: impl AsRef<Path>) -> Result<()>
Attach the loop device to a file with the set options.
§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.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more