The definition and actions associated with err, such as error return, should include the header file:
#include <linux/err.h>
Common Err Description Include/asm-generic/errno-base.h
#define eperm 1 /* operation not permitted */ #define enoent 2 / * no such file or directory */ #define ESRCH 3 /* No such process */ #define Eintr 4 /* interrupted system call */ #define eio 5 /* i/o error */ #define enxio 6 /* no such device or address */ #define E2BIG 7 /* Argument list too long */ #define enoexec 8 /* exec format error */ #define EBADF 9 /* Bad file number */ #define echild 10 /* No child processes */ #define EAGAIN 11 /* try again */ #define ENOMEM 12 /* Out of memory */ #define EACCES 13 /* Permission denied */ #define EFAULT 14 /* Bad address */ #define &NBSP;ENOTBLK 15 /* block device required */ #define EBUSY 16 /* Device or resource busy */ #define eexist 17 /* file exists */ #define exdev 18 /* Cross-device link */ #define enodev 19 /* No such device */ #define ENOTDIR 20 /* Not a directory */ #define eisdir 21 /* is a directory */ # define einval 22 /* invalid argument */ #define ENFILE 23 /* File table Overflow */ &nBsp #define EMFILE 24 /* Too many open files */ #define enotty 25 /* not a typewriter */ #define ETXTBSY 26 /* Text file busy */ #define EFBIG 27 /* File too large */ #define Enospc 28 /* no space left on device */ #define ESPIPE 29 /* Illegal seek */ #define EROFS 30 /* read-only file system */ #define emlink 31 /* too many links */ #define EPIPE 32 /* Broken pipe */ #define EDOM 33 /* Math argument out of domain of func */ #define erange 34 /* math result not representable */
The kernel's error code is stored in the area of the last 4K of memory, the 0XFFFFF000~0XFFFFFFFF area. If the pointer points to this area of memory, an error is indicated. If you return a-EINTR error and the error code is -4 (0XFFFFFFFC), then 0XFFFFFFFC is the error code pointer.
Here are several macros related to the error:
Err_ptr () Converts the error code to a pointer.
Include/linux/err.h
static inline void * __must_check err_ptr (long error) {return (void *) error; }
Ptr_err () Converts the pointer to an error code.
Include/linux/err.h
Static inline long __must_check ptr_err (const void *ptr) {return (long) PTR; }
Is_err () Determines whether the pointer falls in the error code area.
Include/linux/err.h
Static inline long __must_check is_err (const void *ptr) {return Is_err_value ((unsigned long) PTR); } #define Max_errno 4095 #define IS_ERR_VALUE (x) unlikely ((x) >= (unsigned long)-max_errno)
Is_err_or_null () Determines whether the pointer falls in the error code area or is empty.
Include/linux/err.h
Static inline long __must_check is_err_or_null (const void *ptr) {return!ptr | | Is_err_value ((unsigned long) PTR); }
Is_err () Determines whether the pointer points to the error code area, Ptr==null or!ptr determines whether the pointer is empty, and these judgements are generally used when the return value of the function being invoked is a pointer type. The difference between the use of Is_err () and ptr==null depends on what function is called, and if the function returns a null pointer if the call fails, then the Ptr==null or!ptr should be used. If the function returns a point pointing to the error code area when the call fails, use either Is_err () or Is_err_value (). Of course, you can also use Is_err_or_null to determine all calls that return as pointers.