1*676b8ef6SMork use num_traits::{FromPrimitive, ToPrimitive}; 2*676b8ef6SMork 34454d1a2Slogin #[repr(i32)] 4*676b8ef6SMork #[derive(Debug, FromPrimitive, ToPrimitive, PartialEq, Eq, Clone)] 54454d1a2Slogin #[allow(dead_code)] 64454d1a2Slogin pub enum SystemError { 74454d1a2Slogin /// 参数列表过长,或者在输出buffer中缺少空间 或者参数比系统内建的最大值要大 Argument list too long. 84454d1a2Slogin E2BIG = 1, 94454d1a2Slogin /// 访问被拒绝 Permission denied 104454d1a2Slogin EACCES = 2, 114454d1a2Slogin /// 地址正在被使用 Address in use. 124454d1a2Slogin EADDRINUSE = 3, 134454d1a2Slogin /// 地址不可用 Address not available. 144454d1a2Slogin EADDRNOTAVAIL = 4, 154454d1a2Slogin /// 地址family不支持 Address family not supported. 164454d1a2Slogin EAFNOSUPPORT = 5, 174454d1a2Slogin /// 资源不可用,请重试。 Resource unavailable, try again (may be the same value as [EWOULDBLOCK]) 184454d1a2Slogin EAGAIN = 6, 194454d1a2Slogin /// 连接已经在处理 Connection already in progress. 204454d1a2Slogin EALREADY = 7, 214454d1a2Slogin /// 错误的文件描述符 Bad file descriptor. 224454d1a2Slogin EBADF = 8, 234454d1a2Slogin /// 错误的消息 Bad message. 244454d1a2Slogin EBADMSG = 9, 254454d1a2Slogin /// 设备或资源忙 Device or resource busy. 264454d1a2Slogin EBUSY = 10, 274454d1a2Slogin /// 操作被取消 Operation canceled. 284454d1a2Slogin ECANCELED = 11, 294454d1a2Slogin /// 没有子进程 No child processes. 304454d1a2Slogin ECHILD = 12, 314454d1a2Slogin /// 连接已断开 Connection aborted. 324454d1a2Slogin ECONNABORTED = 13, 334454d1a2Slogin /// 连接被拒绝 Connection refused. 344454d1a2Slogin ECONNREFUSED = 14, 354454d1a2Slogin /// 连接被重置 Connection reset. 364454d1a2Slogin ECONNRESET = 15, 374454d1a2Slogin /// 资源死锁将要发生 Resource deadlock would occur. 384454d1a2Slogin EDEADLK = 16, 394454d1a2Slogin /// 需要目标地址 Destination address required. 404454d1a2Slogin EDESTADDRREQ = 17, 414454d1a2Slogin /// 数学参数超出作用域 Mathematics argument out of domain of function. 424454d1a2Slogin EDOM = 18, 434454d1a2Slogin /// 保留使用 Reserved 444454d1a2Slogin EDQUOT = 19, 454454d1a2Slogin /// 文件已存在 File exists. 464454d1a2Slogin EEXIST = 20, 474454d1a2Slogin /// 错误的地址 Bad address 484454d1a2Slogin EFAULT = 21, 494454d1a2Slogin /// 文件太大 File too large. 504454d1a2Slogin EFBIG = 22, 514454d1a2Slogin /// 主机不可达 Host is unreachable. 524454d1a2Slogin EHOSTUNREACH = 23, 534454d1a2Slogin /// 标志符被移除 Identifier removed. 544454d1a2Slogin EIDRM = 24, 554454d1a2Slogin /// 不合法的字符序列 Illegal byte sequence. 564454d1a2Slogin EILSEQ = 25, 574454d1a2Slogin /// 操作正在处理 Operation in progress. 584454d1a2Slogin EINPROGRESS = 26, 594454d1a2Slogin /// 被中断的函数 Interrupted function. 604454d1a2Slogin EINTR = 27, 614454d1a2Slogin /// 不可用的参数 Invalid argument. 624454d1a2Slogin EINVAL = 28, 634454d1a2Slogin /// I/O错误 I/O error. 644454d1a2Slogin EIO = 29, 654454d1a2Slogin /// 套接字已连接 Socket is connected. 664454d1a2Slogin EISCONN = 30, 674454d1a2Slogin /// 是一个目录 Is a directory 684454d1a2Slogin EISDIR = 31, 694454d1a2Slogin /// 符号链接级别过多 Too many levels of symbolic links. 704454d1a2Slogin ELOOP = 32, 714454d1a2Slogin /// 文件描述符的值过大 File descriptor value too large. 724454d1a2Slogin EMFILE = 33, 734454d1a2Slogin /// 链接数过多 Too many links. 744454d1a2Slogin EMLINK = 34, 754454d1a2Slogin /// 消息过大 Message too large. 764454d1a2Slogin EMSGSIZE = 35, 774454d1a2Slogin /// 保留使用 Reserved. 784454d1a2Slogin EMULTIHOP = 36, 794454d1a2Slogin /// 文件名过长 Filename too long. 804454d1a2Slogin ENAMETOOLONG = 37, 814454d1a2Slogin /// 网络已关闭 Network is down. 824454d1a2Slogin ENETDOWN = 38, 834454d1a2Slogin /// 网络连接已断开 Connection aborted by network. 844454d1a2Slogin ENETRESET = 39, 854454d1a2Slogin /// 网络不可达 Network unreachable. 864454d1a2Slogin ENETUNREACH = 40, 874454d1a2Slogin /// 系统中打开的文件过多 Too many files open in system. 884454d1a2Slogin ENFILE = 41, 894454d1a2Slogin /// 缓冲区空间不足 No buffer space available. 904454d1a2Slogin ENOBUFS = 42, 914454d1a2Slogin /// 队列头没有可读取的消息 No message is available on the STREAM head read queue. 924454d1a2Slogin ENODATA = 43, 934454d1a2Slogin /// 没有指定的设备 No such device. 944454d1a2Slogin ENODEV = 44, 954454d1a2Slogin /// 没有指定的文件或目录 No such file or directory. 964454d1a2Slogin ENOENT = 45, 974454d1a2Slogin /// 可执行文件格式错误 Executable file format error 984454d1a2Slogin ENOEXEC = 46, 994454d1a2Slogin /// 没有可用的锁 No locks available. 1004454d1a2Slogin ENOLCK = 47, 1014454d1a2Slogin /// 保留 Reserved. 1024454d1a2Slogin ENOLINK = 48, 1034454d1a2Slogin /// 没有足够的空间 Not enough space. 1044454d1a2Slogin ENOMEM = 49, 1054454d1a2Slogin /// 没有期待类型的消息 No message of the desired type. 1064454d1a2Slogin ENOMSG = 50, 1074454d1a2Slogin /// 协议不可用 Protocol not available. 1084454d1a2Slogin ENOPROTOOPT = 51, 1094454d1a2Slogin /// 设备上没有空间 No space left on device. 1104454d1a2Slogin ENOSPC = 52, 1114454d1a2Slogin /// 没有STREAM资源 No STREAM resources. 1124454d1a2Slogin ENOSR = 53, 1134454d1a2Slogin /// 不是STREAM Not a STREAM 1144454d1a2Slogin ENOSTR = 54, 1154454d1a2Slogin /// 功能不支持 Function not supported. 1164454d1a2Slogin ENOSYS = 55, 1174454d1a2Slogin /// 套接字未连接 The socket is not connected. 1184454d1a2Slogin ENOTCONN = 56, 1194454d1a2Slogin /// 不是目录 Not a directory. 1204454d1a2Slogin ENOTDIR = 57, 1214454d1a2Slogin /// 目录非空 Directory not empty. 1224454d1a2Slogin ENOTEMPTY = 58, 1234454d1a2Slogin /// 状态不可恢复 State not recoverable. 1244454d1a2Slogin ENOTRECOVERABLE = 59, 1254454d1a2Slogin /// 不是一个套接字 Not a socket. 1264454d1a2Slogin ENOTSOCK = 60, 1274454d1a2Slogin /// 不被支持 Not supported (may be the same value as [EOPNOTSUPP]). 1284454d1a2Slogin ENOTSUP = 61, 1294454d1a2Slogin /// 不正确的I/O控制操作 Inappropriate I/O control operation. 1304454d1a2Slogin ENOTTY = 62, 1314454d1a2Slogin /// 没有这样的设备或地址 No such device or address. 1324454d1a2Slogin ENXIO = 63, 1334454d1a2Slogin /// 套接字不支持该操作 Operation not supported on socket (may be the same value as [ENOTSUP]). 1344454d1a2Slogin EOPNOTSUPP = 64, 1354454d1a2Slogin /// 数值过大,产生溢出 Value too large to be stored in data type. 1364454d1a2Slogin EOVERFLOW = 65, 1374454d1a2Slogin /// 之前的拥有者挂了 Previous owner died. 1384454d1a2Slogin EOWNERDEAD = 66, 1394454d1a2Slogin /// 操作不被允许 Operation not permitted. 1404454d1a2Slogin EPERM = 67, 1414454d1a2Slogin /// 断开的管道 Broken pipe. 1424454d1a2Slogin EPIPE = 68, 1434454d1a2Slogin /// 协议错误 Protocol error. 1444454d1a2Slogin EPROTO = 69, 1454454d1a2Slogin /// 协议不被支持 Protocol not supported. 1464454d1a2Slogin EPROTONOSUPPORT = 70, 1474454d1a2Slogin /// 对于套接字而言,错误的协议 Protocol wrong type for socket. 1484454d1a2Slogin EPROTOTYPE = 71, 1494454d1a2Slogin /// 结果过大 Result too large. 1504454d1a2Slogin ERANGE = 72, 1514454d1a2Slogin /// 只读的文件系统 Read-only file system. 1524454d1a2Slogin EROFS = 73, 1534454d1a2Slogin /// 错误的寻道.当前文件是pipe,不允许seek请求 Invalid seek. 1544454d1a2Slogin ESPIPE = 74, 1554454d1a2Slogin /// 没有这样的进程 No such process. 1564454d1a2Slogin ESRCH = 75, 1574454d1a2Slogin /// 保留 Reserved. 1584454d1a2Slogin ESTALE = 76, 1594454d1a2Slogin /// 流式ioctl()超时 Stream ioctl() timeout 1604454d1a2Slogin ETIME = 77, 1614454d1a2Slogin /// 连接超时 Connection timed out. 1624454d1a2Slogin ETIMEDOUT = 78, 1634454d1a2Slogin /// 文本文件忙 Text file busy. 1644454d1a2Slogin ETXTBSY = 79, 1654454d1a2Slogin /// 操作将被禁止 Operation would block (may be the same value as [EAGAIN]). 1664454d1a2Slogin EWOULDBLOCK = 80, 1674454d1a2Slogin /// 跨设备连接 Cross-device link. 1684454d1a2Slogin EXDEV = 81, 1694454d1a2Slogin } 170*676b8ef6SMork 171*676b8ef6SMork impl SystemError { 172*676b8ef6SMork /// @brief 把posix错误码转换为系统错误枚举类型。 173*676b8ef6SMork pub fn from_posix_errno(errno: i32) -> Option<SystemError> { 174*676b8ef6SMork // posix 错误码是小于0的 175*676b8ef6SMork if errno >= 0 { 176*676b8ef6SMork return None; 177*676b8ef6SMork } 178*676b8ef6SMork return <Self as FromPrimitive>::from_i32(-errno); 179*676b8ef6SMork } 180*676b8ef6SMork 181*676b8ef6SMork /// @brief 把系统错误枚举类型转换为负数posix错误码。 182*676b8ef6SMork pub fn to_posix_errno(&self) -> i32 { 183*676b8ef6SMork return -<Self as ToPrimitive>::to_i32(self).unwrap(); 184*676b8ef6SMork } 185*676b8ef6SMork }