Skip to content

Commit

Permalink
Merge pull request Smithay#41 from carlosmn/cmn/from-devnum
Browse files Browse the repository at this point in the history
device: add constructor from devnum
  • Loading branch information
Drakulix authored Apr 13, 2023
2 parents ae6f8fa + c3b5953 commit cca0d7f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@ impl Device {
Ok(Self::from_raw(udev, ptr))
}

/// Creates a device for a given major/minor number
///
/// The `dev_type` parameter is the type of device as a u8 char (`b'c'` or
/// `b'b'`). `devnum` is a device major/minor as you can find from `fstat`
/// or [`devnum`][Self::devnum]
pub fn from_devnum(dev_type: u8, devnum: dev_t) -> Result<Self> {
let udev = Udev::new()?;

Self::from_devnum_with_context(udev, dev_type, devnum)
}

/// Creates a device for a given major/minor number, using an existing
/// `Udev` instance rather than creating one automatically.
///
/// The `dev_type` parameter is the type of device as a u8 char(`b'c'` or
/// `b'b'`). `devnum` is a device major/minor as you can find from `fstat`
/// or [`devnum`][Self::devnum]
pub fn from_devnum_with_context(udev: Udev, dev_type: u8, devnum: dev_t) -> Result<Self> {
let ptr = try_alloc!(unsafe {
ffi::udev_device_new_from_devnum(udev.as_raw(), dev_type as i8, devnum)
});

Ok(Self::from_raw(udev, ptr))
}

/// Creates a rust `Device` given an already created libudev `ffi::udev_device*` and a
/// corresponding `Udev` instance from which the device was created.
///
Expand Down

0 comments on commit cca0d7f

Please sign in to comment.