From b063c2baa0ef4ae0e3ebcce96e90b2c7dee0d09b Mon Sep 17 00:00:00 2001 From: Michael Daffin Date: Tue, 30 Mar 2021 22:23:48 +0100 Subject: [PATCH] Fixes example test and makes attach_with_loop_info consume the loop_info64 struct Even though it is passed by reference to the ioctl conceptually the it should be created and consumed once per call to a attach function. --- src/lib.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e39b8a6..f9513f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -167,7 +167,7 @@ impl LoopDevice { info.lo_offset = offset; info.lo_sizelimit = sizelimit; - Self::attach_with_loop_info(self, backing_file, &mut info) + Self::attach_with_loop_info(self, backing_file, info) } /// Attach the loop device with automatic partition scanning. @@ -180,19 +180,14 @@ impl LoopDevice { /// ld.attach_with_partscan("test.img").unwrap(); /// # ld.detach().unwrap(); /// ``` - pub fn attach_with_partscan>( - &self, - backing_file: P, - ) -> io::Result<()> { + pub fn attach_with_partscan>(&self, backing_file: P) -> io::Result<()> { // Set lo_flags to LO_FLAGS_PARTSCAN value let mut info = loop_info64::default(); info.lo_flags = 8; - Self::attach_with_loop_info(self, backing_file, &mut info) + Self::attach_with_loop_info(self, backing_file, info) } - - /// Attach the loop device to a file with loop_info. /// /// # Examples @@ -200,7 +195,7 @@ impl LoopDevice { /// Attach the device with default loop_info values. /// /// ```rust - /// use loopdev::LoopDevice; + /// use loopdev::{LoopDevice, loop_info64}; /// let ld = LoopDevice::open("/dev/loop5").unwrap(); /// ld.attach_with_loop_info("test.img", loop_info64::default()).unwrap(); /// # ld.detach().unwrap(); @@ -208,7 +203,7 @@ impl LoopDevice { pub fn attach_with_loop_info>( &self, backing_file: P, - loop_info: &mut loop_info64, + loop_info: loop_info64, ) -> io::Result<()> { let bf = OpenOptions::new() .read(true) @@ -228,7 +223,7 @@ impl LoopDevice { ioctl( self.device.as_raw_fd() as c_int, LOOP_SET_STATUS64.into(), - loop_info, + &loop_info, ) }) { // Ignore the error to preserve the original error