From 576a69d005df4195543238ba5b4ab57612643be4 Mon Sep 17 00:00:00 2001 From: Felix Obenhuber Date: Thu, 27 May 2021 08:49:02 +0200 Subject: [PATCH] Add `metadata` for a `LoopDevice` 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. --- src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index a52eaf4..4821f79 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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}, @@ -263,6 +263,11 @@ impl LoopDevice { std::fs::read_link(&p).ok() } + /// Get the device metadata + pub fn metadata(&self) -> io::Result { + 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