Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 13: System Calls


Of course, neither programs nor the kernel itself operates with raw numbers but with symbolic
constants defined with the help of the pre-processor ininclude/asm-generic/errno-base.hand
include/asm-generic/errno.h.^7 The file named<errno.h>contains several additional error codes, but
these are kernel-specific and are never visible to the user application. Error codes up to and including
511 are reserved for general errors; kernel-specific constants use the values above 512.

Because (not surprisingly) there are a very large number of potential errors, only a few constants are
listed below:

<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 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 ‘‘classic‘‘ errors that occur when working withUnixsystem calls are listed inerrno-base.h.Onthe
other hand,errno.hcontains more unusual error codes whose meanings are not immediately obvious
even to seasoned programmers. Examples such asEOPNOTSUPP— which stands for ‘‘Operation not sup-
ported on transport endpoint’’ — andELNRNG— which means ‘‘Link number out of range’’ — are not
what might be classified as common knowledge. Some more examples:

<asm-generic/errno.h>
#define EDEADLK 35 /* Resource deadlock would occur */
#define ENAMETOOLONG 36 /* File name too long */
#define ENOLCK 37 /* No record locks available */
#define ENOSYS 38 /* Function not implemented */
...
#define ENOKEY 126 /* Required key not available */
#define EKEYEXPIRED 127 /* Key has expired */
#define EKEYREVOKED 128 /* Key has been revoked */
#define EKEYREJECTED 129 /* Key was rejected by service */

/* for robust mutexes */
#define EOWNERDEAD 130 /* Owner died */
#define ENOTRECOVERABLE 131 /* State not recoverable */

Although I just mentioned that error codes are always returned with a negative number, all codes shown
here are positive. It is a kernel convention that thenumbers are defined as positive but are returned as

(^7) SPARC, Alpha, PA-RISC, and MIPS architectures define their own versions of these files because they use different numeric error
codes from the remaining Linux ports. This is because of the fact that binary specifications for different platforms do not always use
the same magic constants.

Free download pdf