xref: /DragonOS/kernel/src/syscall/mod.rs (revision 676b8ef62e1a0a1e52d65b40c53c1636a2954040)
1 use num_traits::{FromPrimitive, ToPrimitive};
2 
3 #[repr(i32)]
4 #[derive(Debug, FromPrimitive, ToPrimitive, PartialEq, Eq, Clone)]
5 #[allow(dead_code)]
6 pub enum SystemError {
7     /// 参数列表过长,或者在输出buffer中缺少空间 或者参数比系统内建的最大值要大 Argument list too long.
8     E2BIG = 1,
9     /// 访问被拒绝 Permission denied
10     EACCES = 2,
11     /// 地址正在被使用 Address in use.
12     EADDRINUSE = 3,
13     /// 地址不可用 Address  not available.
14     EADDRNOTAVAIL = 4,
15     /// 地址family不支持 Address family not supported.
16     EAFNOSUPPORT = 5,
17     /// 资源不可用,请重试。 Resource unavailable, try again (may be the same value as [EWOULDBLOCK])
18     EAGAIN = 6,
19     /// 连接已经在处理 Connection already in progress.
20     EALREADY = 7,
21     /// 错误的文件描述符 Bad file descriptor.
22     EBADF = 8,
23     /// 错误的消息 Bad message.
24     EBADMSG = 9,
25     /// 设备或资源忙 Device or resource busy.
26     EBUSY = 10,
27     /// 操作被取消 Operation canceled.
28     ECANCELED = 11,
29     /// 没有子进程 No child processes.
30     ECHILD = 12,
31     /// 连接已断开 Connection aborted.
32     ECONNABORTED = 13,
33     /// 连接被拒绝 Connection refused.
34     ECONNREFUSED = 14,
35     /// 连接被重置 Connection reset.
36     ECONNRESET = 15,
37     /// 资源死锁将要发生 Resource deadlock would occur.
38     EDEADLK = 16,
39     /// 需要目标地址 Destination address required.
40     EDESTADDRREQ = 17,
41     /// 数学参数超出作用域 Mathematics argument out of domain of function.
42     EDOM = 18,
43     /// 保留使用 Reserved
44     EDQUOT = 19,
45     /// 文件已存在 File exists.
46     EEXIST = 20,
47     /// 错误的地址 Bad address
48     EFAULT = 21,
49     /// 文件太大 File too large.
50     EFBIG = 22,
51     /// 主机不可达 Host is unreachable.
52     EHOSTUNREACH = 23,
53     /// 标志符被移除 Identifier removed.
54     EIDRM = 24,
55     /// 不合法的字符序列 Illegal byte sequence.
56     EILSEQ = 25,
57     /// 操作正在处理 Operation in progress.
58     EINPROGRESS = 26,
59     /// 被中断的函数 Interrupted function.
60     EINTR = 27,
61     /// 不可用的参数 Invalid argument.
62     EINVAL = 28,
63     /// I/O错误 I/O error.
64     EIO = 29,
65     /// 套接字已连接 Socket is connected.
66     EISCONN = 30,
67     /// 是一个目录 Is a directory
68     EISDIR = 31,
69     /// 符号链接级别过多 Too many levels of symbolic links.
70     ELOOP = 32,
71     /// 文件描述符的值过大 File descriptor value too large.
72     EMFILE = 33,
73     /// 链接数过多 Too many links.
74     EMLINK = 34,
75     /// 消息过大 Message too large.
76     EMSGSIZE = 35,
77     /// 保留使用 Reserved.
78     EMULTIHOP = 36,
79     /// 文件名过长 Filename too long.
80     ENAMETOOLONG = 37,
81     /// 网络已关闭 Network is down.
82     ENETDOWN = 38,
83     /// 网络连接已断开 Connection aborted by network.
84     ENETRESET = 39,
85     /// 网络不可达 Network unreachable.
86     ENETUNREACH = 40,
87     /// 系统中打开的文件过多 Too many files open in system.
88     ENFILE = 41,
89     /// 缓冲区空间不足 No buffer space available.
90     ENOBUFS = 42,
91     /// 队列头没有可读取的消息 No message is available on the STREAM head read queue.
92     ENODATA = 43,
93     /// 没有指定的设备 No such device.
94     ENODEV = 44,
95     /// 没有指定的文件或目录 No such file or directory.
96     ENOENT = 45,
97     /// 可执行文件格式错误 Executable file format error
98     ENOEXEC = 46,
99     /// 没有可用的锁 No locks available.
100     ENOLCK = 47,
101     /// 保留 Reserved.
102     ENOLINK = 48,
103     /// 没有足够的空间 Not enough space.
104     ENOMEM = 49,
105     /// 没有期待类型的消息 No message of the desired type.
106     ENOMSG = 50,
107     /// 协议不可用 Protocol not available.
108     ENOPROTOOPT = 51,
109     /// 设备上没有空间 No space left on device.
110     ENOSPC = 52,
111     /// 没有STREAM资源  No STREAM resources.
112     ENOSR = 53,
113     /// 不是STREAM Not a STREAM
114     ENOSTR = 54,
115     /// 功能不支持 Function not supported.
116     ENOSYS = 55,
117     /// 套接字未连接 The socket is not connected.
118     ENOTCONN = 56,
119     /// 不是目录 Not a directory.
120     ENOTDIR = 57,
121     /// 目录非空 Directory not empty.
122     ENOTEMPTY = 58,
123     /// 状态不可恢复 State not recoverable.
124     ENOTRECOVERABLE = 59,
125     /// 不是一个套接字 Not a socket.
126     ENOTSOCK = 60,
127     /// 不被支持 Not supported (may be the same value as [EOPNOTSUPP]).
128     ENOTSUP = 61,
129     /// 不正确的I/O控制操作 Inappropriate I/O control operation.
130     ENOTTY = 62,
131     /// 没有这样的设备或地址 No such device or address.
132     ENXIO = 63,
133     /// 套接字不支持该操作 Operation not supported on socket (may be the same value as [ENOTSUP]).
134     EOPNOTSUPP = 64,
135     /// 数值过大,产生溢出 Value too large to be stored in data type.
136     EOVERFLOW = 65,
137     /// 之前的拥有者挂了 Previous owner died.
138     EOWNERDEAD = 66,
139     /// 操作不被允许 Operation not permitted.
140     EPERM = 67,
141     /// 断开的管道 Broken pipe.
142     EPIPE = 68,
143     /// 协议错误 Protocol error.
144     EPROTO = 69,
145     /// 协议不被支持 Protocol not supported.
146     EPROTONOSUPPORT = 70,
147     /// 对于套接字而言,错误的协议 Protocol wrong type for socket.
148     EPROTOTYPE = 71,
149     /// 结果过大 Result too large.
150     ERANGE = 72,
151     /// 只读的文件系统 Read-only file system.
152     EROFS = 73,
153     /// 错误的寻道.当前文件是pipe,不允许seek请求  Invalid seek.
154     ESPIPE = 74,
155     /// 没有这样的进程 No such process.
156     ESRCH = 75,
157     /// 保留 Reserved.
158     ESTALE = 76,
159     /// 流式ioctl()超时 Stream ioctl() timeout
160     ETIME = 77,
161     /// 连接超时 Connection timed out.
162     ETIMEDOUT = 78,
163     /// 文本文件忙 Text file busy.
164     ETXTBSY = 79,
165     /// 操作将被禁止 Operation would block (may be the same value as [EAGAIN]).
166     EWOULDBLOCK = 80,
167     /// 跨设备连接 Cross-device link.
168     EXDEV = 81,
169 }
170 
171 impl SystemError {
172     /// @brief 把posix错误码转换为系统错误枚举类型。
173     pub fn from_posix_errno(errno: i32) -> Option<SystemError> {
174         // posix 错误码是小于0的
175         if errno >= 0 {
176             return None;
177         }
178         return <Self as FromPrimitive>::from_i32(-errno);
179     }
180 
181     /// @brief 把系统错误枚举类型转换为负数posix错误码。
182     pub fn to_posix_errno(&self) -> i32 {
183         return -<Self as ToPrimitive>::to_i32(self).unwrap();
184     }
185 }