Skip to content

Commit

Permalink
Replace LoopDevice::metadata with major and minor
Browse files Browse the repository at this point in the history
Instead of exposing `metadata` add two function to `LoopDevice` that
allow access to the the `major` and `minor` number of the device.
  • Loading branch information
Felix Obenhuber authored and mdaffin committed May 31, 2021
1 parent 576a69d commit ef2132a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -263,9 +263,18 @@ impl LoopDevice {
std::fs::read_link(&p).ok()
}

/// Get the device metadata
pub fn metadata(&self) -> io::Result<Metadata> {
self.device.metadata()
/// Get the device major number
pub fn major(&self) -> io::Result<u32> {
self.device
.metadata()
.map(|m| unsafe { libc::major(m.rdev()) as u32 })
}

/// Get the device major number
pub fn minor(&self) -> io::Result<u32> {
self.device
.metadata()
.map(|m| unsafe { libc::minor(m.rdev()) as u32 })
}

/// Detach a loop device from its backing file.
Expand Down

0 comments on commit ef2132a

Please sign in to comment.