From 149dbc85da9e028a2623aa63bd163576af00c194 Mon Sep 17 00:00:00 2001 From: Felix Obenhuber Date: Mon, 31 May 2021 16:14:20 +0200 Subject: [PATCH] Replace LoopDevice::metadata with major and minor Instead of exposing `metadata` add two function to `LoopDevice` that allow access to the the `major` and `minor` number of the device. --- src/lib.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4821f79..8fe5428 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,7 @@ use bindings::{ use libc::{c_int, ioctl}; use std::{ default::Default, - fs::{File, Metadata, OpenOptions}, + fs::{File, OpenOptions}, io, os::unix::prelude::*, path::{Path, PathBuf}, @@ -263,9 +263,18 @@ impl LoopDevice { std::fs::read_link(&p).ok() } - /// Get the device metadata - pub fn metadata(&self) -> io::Result { - self.device.metadata() + /// Get the device major number + pub fn major(&self) -> io::Result { + self.device + .metadata() + .map(|m| unsafe { libc::major(m.rdev()) as u32 }) + } + + /// Get the device major number + pub fn minor(&self) -> io::Result { + self.device + .metadata() + .map(|m| unsafe { libc::minor(m.rdev()) as u32 }) } /// Detach a loop device from its backing file.