51Testing软件测试论坛

标题: linux常见错误码 [打印本页]

作者: 一纸荒年    时间: 2018-4-11 15:42
标题: linux常见错误码
查看错误代码errno是调试程序的一个重要方法。当linuc C api函数发生异常时,一般会将errno变量(需include
errno.h)赋一个整数值,不同的值表示不同的含义,可以通过查看该值推测出错的原因。在实际编程中用这一
招解决了不少原本看来莫名其妙的问题。比较麻烦的是每次都要去linux源代码里面查找错误代码的含义,
现在把它贴出来,以后需要查时就来这里看了。


1-34号错误号是在内核源码的include/asm-generic/errno-base.h定义


35-132则是在include/asm-generic/errno.h中定义


剩下还有一些更大的错误号是留给内核级别的,如系统调用等,用户程序一般是看不见的这些号的,Ubu
ntu9.10中/usr/src/linux-headers-2.6.31-21-generic/include/linux/errno.h



  1. #ifndef _ASM_GENERIC_ERRNO_BASE_H
  2. #define _ASM_GENERIC_ERRNO_BASE_H

  3. #define    EPERM         1    /* Operation not permitted */
  4. #define    ENOENT         2    /* No such file or directory */
  5. #define    ESRCH         3    /* No such process */
  6. #define    EINTR         4    /* Interrupted system call */
  7. #define    EIO         5    /* I/O error */
  8. #define    ENXIO         6    /* No such device or address */
  9. #define    E2BIG         7    /* Argument list too long */
  10. #define    ENOEXEC         8    /* Exec format error */
  11. #define    EBADF         9    /* Bad file number */
  12. #define    ECHILD        10    /* No child processes */
  13. #define    EAGAIN        11    /* Try again */
  14. #define    ENOMEM        12    /* Out of memory */
  15. #define    EACCES        13    /* Permission denied */
  16. #define    EFAULT        14    /* Bad address */
  17. #define    ENOTBLK        15    /* Block device required */
  18. #define    EBUSY        16    /* Device or resource busy */
  19. #define    EEXIST        17    /* File exists */
  20. #define    EXDEV        18    /* Cross-device link */
  21. #define    ENODEV        19    /* No such device */
  22. #define    ENOTDIR        20    /* Not a directory */
  23. #define    EISDIR        21    /* Is a directory */
  24. #define    EINVAL        22    /* Invalid argument */
  25. #define    ENFILE        23    /* File table overflow */
  26. #define    EMFILE        24    /* Too many open files */
  27. #define    ENOTTY        25    /* Not a typewriter */
  28. #define    ETXTBSY        26    /* Text file busy */
  29. #define    EFBIG        27    /* File too large */
  30. #define    ENOSPC        28    /* No space left on device */
  31. #define    ESPIPE        29    /* Illegal seek */
  32. #define    EROFS        30    /* Read-only file system */
  33. #define    EMLINK        31    /* Too many links */
  34. #define    EPIPE        32    /* Broken pipe */
  35. #define    EDOM        33    /* Math argument out of domain of func */
  36. #define    ERANGE        34    /* Math result not representable */

  37. #endif


  38. #include <asm-generic/errno-base.h>

  39. #define    EDEADLK        35    /* Resource deadlock would occur */
  40. #define    ENAMETOOLONG    36    /* File name too long */
  41. #define    ENOLCK        37    /* No record locks available */
  42. #define    ENOSYS        38    /* Function not implemented */
  43. #define    ENOTEMPTY    39    /* Directory not empty */
  44. #define    ELOOP        40    /* Too many symbolic links encountered */
  45. #define    EWOULDBLOCK    EAGAIN    /* Operation would block */
  46. #define    ENOMSG        42    /* No message of desired type */
  47. #define    EIDRM        43    /* Identifier removed */
  48. #define    ECHRNG        44    /* Channel number out of range */
  49. #define    EL2NSYNC    45    /* Level 2 not synchronized */
  50. #define    EL3HLT        46    /* Level 3 halted */
  51. #define    EL3RST        47    /* Level 3 reset */
  52. #define    ELNRNG        48    /* Link number out of range */
  53. #define    EUNATCH        49    /* Protocol driver not attached */
  54. #define    ENOCSI        50    /* No CSI structure available */
  55. #define    EL2HLT        51    /* Level 2 halted */
  56. #define    EBADE        52    /* Invalid exchange */
  57. #define    EBADR        53    /* Invalid request descriptor */
  58. #define    EXFULL        54    /* Exchange full */
  59. #define    ENOANO        55    /* No anode */
  60. #define    EBADRQC        56    /* Invalid request code */
  61. #define    EBADSLT        57    /* Invalid slot */

  62. #define    EDEADLOCK    EDEADLK

  63. #define    EBFONT        59    /* Bad font file format */
  64. #define    ENOSTR        60    /* Device not a stream */
  65. #define    ENODATA        61    /* No data available */
  66. #define    ETIME        62    /* Timer expired */
  67. #define    ENOSR        63    /* Out of streams resources */
  68. #define    ENONET        64    /* Machine is not on the network */
  69. #define    ENOPKG        65    /* Package not installed */
  70. #define    EREMOTE        66    /* Object is remote */
  71. #define    ENOLINK        67    /* Link has been severed */
  72. #define    EADV        68    /* Advertise error */
  73. #define    ESRMNT        69    /* Srmount error */
  74. #define    ECOMM        70    /* Communication error on send */

复制代码



作者: 一纸荒年    时间: 2018-4-11 15:42
  1. #define EPROTO 71 /* Protocol error */
  2. #define EMULTIHOP 72 /* Multihop attempted */
  3. #define EDOTDOT 73 /* RFS specific error */
  4. #define EBADMSG 74 /* Not a data message */
  5. #define EOVERFLOW 75 /* Value too large for defined data type */
  6. #define ENOTUNIQ 76 /* Name not unique on network */
  7. #define EBADFD 77 /* File descriptor in bad state */
  8. #define EREMCHG 78 /* Remote address changed */
  9. #define ELIBACC 79 /* Can not access a needed shared library */
  10. #define ELIBBAD 80 /* Accessing a corrupted shared library */
  11. #define ELIBSCN 81 /* .lib section in a.out corrupted */
  12. #define ELIBMAX 82 /* Attempting to link in too many shared libraries */
  13. #define ELIBEXEC 83 /* Cannot exec a shared library directly */
  14. #define EILSEQ 84 /* Illegal byte sequence */
  15. #define ERESTART 85 /* Interrupted system call should be restarted */
  16. #define ESTRPIPE 86 /* Streams pipe error */
  17. #define EUSERS 87 /* Too many users */
  18. #define ENOTSOCK 88 /* Socket operation on non-socket */
  19. #define EDESTADDRREQ 89 /* Destination address required */
  20. #define EMSGSIZE 90 /* Message too long */
  21. #define EPROTOTYPE 91 /* Protocol wrong type for socket */
  22. #define ENOPROTOOPT 92 /* Protocol not available */
  23. #define EPROTONOSUPPORT 93 /* Protocol not supported */
  24. #define ESOCKTNOSUPPORT 94 /* Socket type not supported */
  25. #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
  26. #define EPFNOSUPPORT 96 /* Protocol family not supported */
  27. #define EAFNOSUPPORT 97 /* Address family not supported by protocol */
  28. #define EADDRINUSE 98 /* Address already in use */
  29. #define EADDRNOTAVAIL 99 /* Cannot assign requested address */
  30. #define ENETDOWN 100 /* Network is down */
  31. #define ENETUNREACH 101 /* Network is unreachable */
  32. #define ENETRESET 102 /* Network dropped connection because of reset */
  33. #define ECONNABORTED 103 /* Software caused connection abort */
  34. #define ECONNRESET 104 /* Connection reset by peer */
  35. #define ENOBUFS 105 /* No buffer space available */
  36. #define EISCONN 106 /* Transport endpoint is already connected */
  37. #define ENOTCONN 107 /* Transport endpoint is not connected */
  38. #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
  39. #define ETOOMANYREFS 109 /* Too many references: cannot splice */
  40. #define ETIMEDOUT 110 /* Connection timed out */
  41. #define ECONNREFUSED 111 /* Connection refused */
  42. #define EHOSTDOWN 112 /* Host is down */
  43. #define EHOSTUNREACH 113 /* No route to host */
  44. #define EALREADY 114 /* Operation already in progress */
  45. #define EINPROGRESS 115 /* Operation now in progress */
  46. #define ESTALE 116 /* Stale NFS file handle */
  47. #define EUCLEAN 117 /* Structure needs cleaning */
  48. #define ENOTNAM 118 /* Not a XENIX named type file */
  49. #define ENAVAIL 119 /* No XENIX semaphores available */
  50. #define EISNAM 120 /* Is a named type file */
  51. #define EREMOTEIO 121 /* Remote I/O error */
  52. #define EDQUOT 122 /* Quota exceeded */

  53. #define ENOMEDIUM 123 /* No medium found */
  54. #define EMEDIUMTYPE 124 /* Wrong medium type */
  55. #define ECANCELED 125 /* Operation Canceled */
  56. #define ENOKEY 126 /* Required key not available */
  57. #define EKEYEXPIRED 127 /* Key has expired */
  58. #define EKEYREVOKED 128 /* Key has been revoked */
  59. #define EKEYREJECTED 129 /* Key was rejected by service */

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

  63. #define ERFKILL 132 /* Operation not possible due to RF-kill */


  64. #ifdef __KERNEL__

  65. /*
  66. * These should never be seen by user programs. To return one of ERESTART*
  67. * codes, signal_pending() MUST be set. Note that ptrace can observe these
  68. * at syscall exit tracing, but they will never be left for the debugged user
  69. * process to see.
  70. */
  71. #define ERESTARTSYS 512
  72. #define ERESTARTNOINTR 513
  73. #define ERESTARTNOHAND 514 /* restart if no handler.. */
  74. #define ENOIOCTLCMD 515 /* No ioctl command */
  75. #define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */

  76. /* Defined for the NFSv3 protocol */
  77. #define EBADHANDLE 521 /* Illegal NFS file handle */
  78. #define ENOTSYNC 522 /* Update synchronization mismatch */
  79. #define EBADCOOKIE 523 /* Cookie is stale */
  80. #define ENOTSUPP 524 /* Operation is not supported */
  81. #define ETOOSMALL 525 /* Buffer or request is too small */
  82. #define ESERVERFAULT 526 /* An untranslatable error occurred */
  83. #define EBADTYPE 527 /* Type not supported by server */
  84. #define EJUKEBOX 528 /* Request initiated, but will not complete before timeout */
  85. #define EIOCBQUEUED 529 /* iocb queued, will get completion event */
  86. #define EIOCBRETRY 530 /* iocb queued, will trigger a retry */

  87. #endif
复制代码





欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2