diff --git a/drm-ffi/drm-sys/src/bindings.rs b/drm-ffi/drm-sys/src/bindings.rs index 9143a0e..fb673aa 100644 --- a/drm-ffi/drm-sys/src/bindings.rs +++ b/drm-ffi/drm-sys/src/bindings.rs @@ -1,4 +1,4 @@ -/* automatically generated by rust-bindgen 0.69.4 */ +/* automatically generated by rust-bindgen 0.69.5 */ pub const DRM_NAME: &[u8; 4] = b"drm\0"; pub const DRM_MIN_ORDER: u32 = 5; diff --git a/examples/enumerate.rs b/examples/enumerate.rs new file mode 100644 index 0000000..4bc29b2 --- /dev/null +++ b/examples/enumerate.rs @@ -0,0 +1,7 @@ +pub fn main() { + let devices = drm::node::devices().unwrap(); + + for dev in devices { + println!("{:?}", dev); + } +} diff --git a/src/node/constants.rs b/src/node/constants.rs index 4828842..a0f9eeb 100644 --- a/src/node/constants.rs +++ b/src/node/constants.rs @@ -43,3 +43,11 @@ pub const RENDER_NAME: &str = "renderD"; /// Render DRM node prefix. #[cfg(target_os = "openbsd")] pub const RENDER_NAME: &str = "drmR"; + +/// Directory to search DRM devices +#[cfg(target_os = "openbsd")] +pub const DRM_DIR_NAME: &str = "/dev"; + +/// Directory to search DRM devices +#[cfg(not(target_os = "openbsd"))] +pub const DRM_DIR_NAME: &str = "/dev/dri"; diff --git a/src/node/mod.rs b/src/node/mod.rs index 5fcecb3..0a955aa 100644 --- a/src/node/mod.rs +++ b/src/node/mod.rs @@ -4,9 +4,9 @@ pub mod constants; use std::error::Error; use std::fmt::{self, Debug, Display, Formatter}; -use std::io; use std::os::unix::io::AsFd; use std::path::{Path, PathBuf}; +use std::{fs, io}; use rustix::fs::{fstat, major, minor, stat, Dev as dev_t, Stat}; @@ -380,3 +380,12 @@ pub fn dev_path(dev: dev_t, ty: NodeType) -> io::Result { ), )) } + +/// Returns an iterator with all DRM Nodes we managed to find. There might be duplicates. +pub fn devices() -> io::Result> { + let result = fs::read_dir(DRM_DIR_NAME)? + .filter_map(|entry| entry.ok()) + .filter_map(|entry| DrmNode::from_path(entry.path()).ok()); + + Ok(result) +}