1/* @title: Error Codes */
2#pragma once
3#include <stdint.h>
4
5#define ERR_IS_FATAL(e) (e != ERR_OK && e != ERR_AGAIN)
6
7enum errno {
8 ERR_OK = 0, // Success
9 ERR_UNKNOWN = -1, // Unknown or unspecified error
10 ERR_NO_MEM = -2, // Out of memory
11 ERR_NO_DEV = -3, // No such device
12 ERR_NO_ENT = -4, // No such file or directory
13 ERR_EXIST = -5, // File already exists
14 ERR_IO = -6, // I/O error
15 ERR_NOT_DIR = -7, // Not a directory
16 ERR_IS_DIR = -8, // Is a directory
17 ERR_INVAL = -9, // Invalid argument
18 ERR_PERM = -10, // Permission denied
19 ERR_FAULT = -11, // Bad address
20 ERR_BUSY = -12, // Resource/device busy
21 ERR_AGAIN = -13, // Try again later
22 ERR_NOT_IMPL = -14, // Not implemented
23 ERR_NOSPC = -15, // No space left on device
24 ERR_OVERFLOW = -16, // Value too large
25 ERR_NOT_EMPTY = -17, // Directory not empty
26
27 ERR_FS_NO_INODE = -100, // Inode not found
28 ERR_FS_CORRUPT = -101, // Filesystem corruption
29 ERR_FS_SYMLINK_LOOP = -102, // Too many symlink levels
30 ERR_FS_INTERNAL = -103, // Internal filesystem error
31
32};
33
34static inline const char *errno_to_str(enum errno err) {
35 switch (err) {
36 case ERR_OK: return "No error";
37 case ERR_UNKNOWN: return "Unknown error";
38 case ERR_NO_MEM: return "Out of memory";
39 case ERR_NO_DEV: return "No such device";
40 case ERR_NO_ENT: return "No such file or directory";
41 case ERR_EXIST: return "File already exists";
42 case ERR_IO: return "I/O error";
43 case ERR_NOT_DIR: return "Not a directory";
44 case ERR_IS_DIR: return "Is a directory";
45 case ERR_INVAL: return "Invalid argument";
46 case ERR_PERM: return "Permission denied";
47 case ERR_FAULT: return "Bad memory access";
48 case ERR_BUSY: return "Resource busy";
49 case ERR_AGAIN: return "Try again";
50 case ERR_NOT_IMPL: return "Not implemented";
51 case ERR_NOSPC: return "No space left";
52 case ERR_OVERFLOW: return "Value too large";
53
54 case ERR_FS_NO_INODE: return "Inode not found";
55 case ERR_FS_CORRUPT: return "Filesystem corruption";
56 case ERR_FS_SYMLINK_LOOP: return "Symlink loop";
57
58 default: return "Unrecognized error code";
59 }
60}
61