Skip to content

Commit

Permalink
Add metadata for a LoopDevice
Browse files Browse the repository at this point in the history
Getting the `Metadata` is usefull to access the major/minor number of
the device that is needed when using the loopdev in combination with
device-mapper.
  • Loading branch information
Felix Obenhuber authored and mdaffin committed May 31, 2021
1 parent 7959858 commit 576a69d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use bindings::{
loop_info64, LOOP_CLR_FD, LOOP_CTL_GET_FREE, LOOP_SET_CAPACITY, LOOP_SET_FD, LOOP_SET_STATUS64,
};
use libc::{c_int, ioctl};
use std::fs::{File, OpenOptions};
use std::{
default::Default,
fs::{File, Metadata, OpenOptions},
io,
os::unix::prelude::*,
path::{Path, PathBuf},
Expand Down Expand Up @@ -263,6 +263,11 @@ impl LoopDevice {
std::fs::read_link(&p).ok()
}

/// Get the device metadata
pub fn metadata(&self) -> io::Result<Metadata> {
self.device.metadata()
}

/// 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
Expand Down

0 comments on commit 576a69d

Please sign in to comment.