1
0
Fork 0
forked from wry/wry

all: simplify handling of Errno values

This commit is contained in:
Julian Orth 2026-04-02 18:34:12 +02:00
parent 9c605df692
commit 34914eccb0
58 changed files with 443 additions and 464 deletions

View file

@ -8,7 +8,11 @@ use {
format::Format,
io_uring::{IoUring, IoUringError},
utils::{
buf::Buf, errorfmt::ErrorFmt, oserror::OsError, stack::Stack, syncqueue::SyncQueue,
buf::Buf,
errorfmt::ErrorFmt,
oserror::{OsError, OsErrorExt2},
stack::Stack,
syncqueue::SyncQueue,
vec_ext::VecExt,
},
video::{
@ -179,10 +183,9 @@ fn reopen(fd: c::c_int, need_primary: bool) -> Result<Rc<OwnedFd>, DrmError> {
}
device_node_name(fd)?
};
match uapi::open(path, c::O_RDWR | c::O_CLOEXEC, 0) {
Ok(f) => Ok(Rc::new(f)),
Err(e) => Err(DrmError::ReopenNode(e.into())),
}
uapi::open(path, c::O_RDWR | c::O_CLOEXEC, 0)
.map(Rc::new)
.map_os_err(DrmError::ReopenNode)
}
pub struct Drm {
@ -192,7 +195,7 @@ pub struct Drm {
impl Drm {
pub fn open_existing(fd: Rc<OwnedFd>) -> Result<Self, DrmError> {
let stat = uapi::fstat(fd.raw()).map_err(|e| DrmError::Stat(e.into()))?;
let stat = uapi::fstat(fd.raw()).map_os_err(DrmError::Stat)?;
Ok(Self {
fd,
dev: stat.st_rdev,

View file

@ -7,7 +7,7 @@ use {
errorfmt::ErrorFmt,
hash_map_ext::HashMapExt,
linkedlist::{LinkedList, LinkedNode},
oserror::OsError,
oserror::OsErrorExt2,
},
video::drm::{
DrmError, NodeType, get_drm_nodes_from_dev,
@ -116,8 +116,7 @@ impl SyncobjCtx {
.ok_or(DrmError::NoDeviceNodes)?;
let device_fd = uapi::open(path.as_c_str(), c::O_RDWR | c::O_CLOEXEC, 0)
.map(Rc::new)
.map_err(Into::into)
.map_err(DrmError::ReopenNode)?;
.map_os_err(DrmError::ReopenNode)?;
Ok(Self::new(&device_fd))
}
@ -193,9 +192,7 @@ impl SyncobjCtx {
fn supports_async_wait_(&self) -> Result<(), DrmError> {
let syncobj = self.create_syncobj()?;
let eventfd = uapi::eventfd(0, c::EFD_CLOEXEC)
.map_err(OsError::from)
.map_err(DrmError::EventFd)?;
let eventfd = uapi::eventfd(0, c::EFD_CLOEXEC).map_os_err(DrmError::EventFd)?;
self.wait_for_point(&eventfd, &syncobj, SyncobjPoint(1), true)?;
Ok(())
}

View file

@ -3,7 +3,11 @@
use {
crate::{
utils::{bitflags::BitflagsExt, compat::IoctlNumber, oserror::OsError},
utils::{
bitflags::BitflagsExt,
compat::IoctlNumber,
oserror::{OsError, OsErrorExt},
},
video::drm::{
DrmBlob, DrmCardResources, DrmConnector, DrmConnectorInfo, DrmCrtc, DrmEncoder,
DrmEncoderInfo, DrmError, DrmFb, DrmModeInfo, DrmPlane, DrmPlaneInfo, DrmProperty,
@ -124,10 +128,10 @@ pub fn get_minor_name_from_fd(fd: c::c_int, ty: NodeType) -> Result<Ustring, OsE
let (_, maj, min) = drm_stat(fd)?;
let dir = device_dir(maj, min);
let mut dir = uapi::opendir(dir)?;
let mut dir = uapi::opendir(dir).to_os_error()?;
while let Some(entry) = uapi::readdir(&mut dir) {
let entry = entry?;
let entry = entry.to_os_error()?;
if entry.name().to_bytes().starts_with_str(ty.name()) {
return Ok(uapi::format_ustr!(
"{}/{}",
@ -140,7 +144,7 @@ pub fn get_minor_name_from_fd(fd: c::c_int, ty: NodeType) -> Result<Ustring, OsE
}
fn drm_stat(fd: c::c_int) -> Result<(c::stat, u64, u64), OsError> {
let stat = uapi::fstat(fd)?;
let stat = uapi::fstat(fd).to_os_error()?;
let maj = uapi::major(stat.st_rdev);
let min = uapi::minor(stat.st_rdev);
@ -160,7 +164,7 @@ pub fn get_device_name_from_fd2(fd: c::c_int) -> Result<Ustring, OsError> {
let (_, maj, min) = drm_stat(fd)?;
let path = uapi::format_ustr!("/sys/dev/char/{maj}:{min}/uevent");
let mut buf = vec![];
let mut br = BufReader::new(uapi::open(path, c::O_RDONLY, 0)?);
let mut br = BufReader::new(uapi::open(path, c::O_RDONLY, 0).to_os_error()?);
loop {
buf.clear();
if br.read_until(b'\n', &mut buf)? == 0 {
@ -180,12 +184,12 @@ pub fn get_nodes(fd: c::c_int) -> Result<AHashMap<NodeType, CString>, OsError> {
pub fn get_drm_nodes_from_dev(maj: u64, min: u64) -> Result<AHashMap<NodeType, CString>, OsError> {
let dir = device_dir(maj, min);
let mut dir = uapi::opendir(dir)?;
let mut dir = uapi::opendir(dir).to_os_error()?;
let mut res = AHashMap::new();
'outer: while let Some(entry) = uapi::readdir(&mut dir) {
let entry = entry?;
let entry = entry.to_os_error()?;
let name = entry.name().to_bytes();
let ty = 'ty: {
for ty in [NodeType::Render, NodeType::Control, NodeType::Primary] {

View file

@ -4,7 +4,7 @@ use {
io_uring::IoUring,
utils::{
asyncevent::AsyncEvent, buf::Buf, clonecell::CloneCell, copyhashmap::CopyHashMap,
hash_map_ext::HashMapExt, numcell::NumCell, oserror::OsError, stack::Stack,
hash_map_ext::HashMapExt, numcell::NumCell, oserror::OsErrorExt2, stack::Stack,
},
video::drm::{
DrmError,
@ -136,9 +136,7 @@ impl WaitForSyncobj {
let waiter = match self.inner.idle.pop() {
Some(w) => w,
None => {
let eventfd = uapi::eventfd(0, c::EFD_CLOEXEC)
.map_err(OsError::from)
.map_err(DrmError::EventFd)?;
let eventfd = uapi::eventfd(0, c::EFD_CLOEXEC).map_os_err(DrmError::EventFd)?;
let waiter = Rc::new(WaiterInner {
inner: self.inner.clone(),
eventfd: Rc::new(eventfd),