#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Errno {
EPERM = 1,
ENOENT = 2,
EINTR = 4,
EIO = 5,
ENXIO = 6,
E2BIG = 7,
EBADF = 9,
EAGAIN = 11,
ENOMEM = 12,
EACCES = 13,
EFAULT = 14,
ENOTBLK = 15,
EBUSY = 16,
EEXIST = 17,
EXDEV = 18,
ENODEV = 19,
ENOTDIR = 20,
EISDIR = 21,
EINVAL = 22,
ENFILE = 23,
EMFILE = 24,
ENOTTY = 25,
ETXTBSY = 26,
EFBIG = 27,
ENOSPC = 28,
ESPIPE = 29,
EROFS = 30,
EMLINK = 31,
EPIPE = 32,
ENAMETOOLONG = 36,
ENOTSUP = 95,
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[allow(unused)]
pub struct Ext4Error {
errno: Errno,
msg: Option<&'static str>,
}
impl Ext4Error {
pub const fn new(errno: Errno) -> Self {
Ext4Error { errno, msg: None }
}
pub const fn with_message(errno: Errno, msg: &'static str) -> Self {
Ext4Error {
errno,
msg: Some(msg),
}
}
pub const fn error(&self) -> Errno {
self.errno
}
}
impl From<Errno> for Ext4Error {
fn from(errno: Errno) -> Self {
Ext4Error::new(errno)
}
}
impl From<core::str::Utf8Error> for Ext4Error {
fn from(_: core::str::Utf8Error) -> Self {
Ext4Error::with_message(Errno::EINVAL, "Invalid utf-8 string")
}
}
impl From<alloc::string::FromUtf8Error> for Ext4Error {
fn from(_: alloc::string::FromUtf8Error) -> Self {
Ext4Error::with_message(Errno::EINVAL, "Invalid utf-8 string")
}
}
#[macro_export]
macro_rules! return_errno {
($errno: expr) => {
return Err(Ext4Error::new($errno))
};
}
#[macro_export]
macro_rules! return_errno_with_message {
($errno: expr, $message: expr) => {
return Err(Ext4Error::with_message($errno, $message))
};
}