Linux I/O错误码

在程序出错时,我们通过全局变量错误号errno和perror函数能够很快的定位到错误原因。

Linux错误代码及其含义:

C Name Value Description 含义

错误定义返回值错误信息错误描述
Success0Success成功
EPERM1Operation not permitted操作不允许
ENOENT2No such file or directory没有这样的文件或目录
ESRCH3No such process没有这样的过程
EINTR4Interrupted system call系统调用被中断
EIO5I/O errorI/O错误
ENXIO6No such device or address没有这样的设备或地址
E2BIG7Arg list too long参数列表太长
ENOEXEC8Exec format error执行格式错误
EBADF9Bad file number坏的文件描述符
ECHILD10No child processes没有子进程
EAGAIN11Try again资源暂时不可用
ENOMEM12Out of memory内存溢出
EACCES13Permission denied拒绝许可
EFAULT14Bad address错误的地址
ENOTBLK15Block device required块设备请求
EBUSY16Device or resource busy设备或资源忙
EEXIST17File exists文件存在
EXDEV18Cross-device link无效的交叉链接
ENODEV19No such device设备不存在
ENOTDIR20Not a directory不是一个目录
EISDIR21Is a directory是一个目录
EINVAL22Invalid argument无效的参数
ENFILE32File table overflow打开太多的文件系统
EMFILE24Too many open files打开的文件过多
ENOTTY25Not a tty device不是tty设备
ETXTBSY26Text file busy文本文件忙
EFBIG27File too large文件太大
ENOSPC28No space left on device设备上没有空间
ESPIPE29Illegal seek非法移位
EROFS30Read-only file system只读文件系统
EMLINK31Too many links太多的链接
EPIPE32Broken pipe管道破裂
EDOM33Math argument out of domain数值结果超出范围
ERANGE34Math result not representable数值结果不具代表性
EDEADLK35Resource deadlock would occur资源死锁错误
ENAMETOOLONG36Filename too long文件名太长
ENOLCK37No record locks available没有可用锁
ENOSYS38Function not implemented功能没有实现
ENOTEMPTY39Directory not empty目录不空
ELOOP40Too many symbolic links encountered符号链接层次太多
EWOULDBLOCK41Same as EAGAIN和EAGAIN一样
ENOMSG42No message of desired type没有期望类型的消息
EIDRM43Identifier removed标识符删除
ECHRNG44Channel number out of range频道数目超出范围
EL2NSYNC45Level 2 not synchronized2级不同步
EL3HLT46Level 3 halted3级中断
EL3RST47Level 3 reset3级复位
ELNRNG48Link number out of range链接数超出范围
EUNATCH49Protocol driver not attached协议驱动程序没有连接
ENOCSI50No CSI structure available没有可用CSI结构
EL2HLT51Level 2 halted2级中断
EBADE52Invalid exchange无效的交换
EBADR53Invalid request descriptor请求描述符无效
EXFULL54Exchange full交换全
ENOANO55No anode没有阳极
EBADRQC56Invalid request code无效的请求代码
EBADSLT57Invalid slot无效的槽
EDEADLOCK58Same as EDEADLK和EDEADLK一样
EBFONT59Bad font file format错误的字体文件格式
ENOSTR60Device not a stream设备不是字符流
ENODATA61No data available无可用数据
ETIME62Timer expired计时器过期
ENOSR63Out of streams resources流资源溢出
ENONET64Machine is not on the network机器不上网
ENOPKG65Package not installed没有安装软件包
EREMOTE66Object is remote对象是远程的
ENOLINK67Link has been severed联系被切断
EADV68Advertise error广告的错误
ESRMNT69Srmount errorsrmount 错误
ECOMM70Communication error on send发送时的通讯错误
EPROTO71Protocol error协议错误
EMULTIHOP72Multihop attempted多跳尝试
EDOTDOT73RFS specific errorRFS特定的错误
EBADMSG74Not a data message非数据消息
EOVERFLOW75Value too large for defined data type值太大,对于定义数据类型
ENOTUNIQ76Name not unique on network名不是唯一的网络
EBADFD77File descriptor in bad state文件描述符在坏状态
EREMCHG78Remote address changed远程地址改变了
ELIBACC79Cannot access a needed shared library

无法访问必要

的共享库

ELIBBAD80Accessing a corrupted shared library访问损坏的共享库
ELIBSCN81A .lib section in an .out is corrupted库段. out损坏
ELIBMAX82Linking in too many shared libraries试图链接太多的共享库
ELIBEXEC83Cannot exec a shared library directly不能直接执行一个共享库
EILSEQ84Illegal byte sequence无效的或不完整的多字节或宽字符
ERESTART85Interrupted system call should be restarted应该重新启动中断的系统调用
ESTRPIPE86Streams pipe error流管错误
EUSERS87Too many users用户太多
ENOTSOCK88Socket operation on non-socket套接字操作在非套接字上
EDESTADDRREQ89Destination address required需要目标地址
EMSGSIZE90Message too long消息太长
EPROTOTYPE91Protocol wrong type for socket socket协议类型错误
ENOPROTOOPT92Protocol not available协议不可用
EPROTONOSUPPORT93Protocol not supported不支持的协议
ESOCKTNOSUPPORT94Socket type not supported套接字类型不受支持
EOPNOTSUPP95Operation not supported on transport不支持的操作
EPFNOSUPPORT96Protocol family not supported不支持的协议族
EAFNOSUPPORT97Address family not supported by protocol协议不支持的地址
EADDRINUSE98Address already in use地址已在使用
EADDRNOTAVAIL99Cannot assign requested address无法分配请求的地址
ENETDOWN100Network is down网络瘫痪
ENETUNREACH101Network is unreachable网络不可达
ENETRESET102Network dropped网络连接丢失
ECONNABORTED103Software caused connection软件导致连接中断
ECONNRESET104Connection reset by连接被重置
ENOBUFS105No buffer space available没有可用的缓冲空间
EISCONN106Transport endpoint传输端点已经连接
ENOTCONN107Transport endpoint传输终点没有连接
ESHUTDOWN108Cannot send after transport传输后无法发送
ETOOMANYREFS109Too many references太多的参考
ETIMEDOUT110Connection timed连接超时
ECONNREFUSED111Connection refused拒绝连接
EHOSTDOWN112Host is down主机已关闭
EHOSTUNREACH113No route to host没有主机的路由
EALREADY114Operation already已运行
EINPROGRESS115Operation now in正在运行
ESTALE116Stale NFS file handle陈旧的NFS文件句柄
EUCLEAN117Structure needs cleaning结构需要清洗
ENOTNAM118Not a XENIX-named不是XENIX命名的
ENAVAIL119No XENIX semaphores没有XENIX信号量
EISNAM120Is a named type file是一个命名的文件类型
EREMOTEIO121Remote I/O error远程输入/输出错误
EDQUOT122Quota exceeded超出磁盘配额
ENOMEDIUM123No medium found没有磁盘被发现
EMEDIUMTYPE124Wrong medium type错误的媒体类型
ECANCELED125Operation Canceled取消操作
ENOKEY126Required key not available所需键不可用
EKEYEXPIRED127Key has expired关键已过期
EKEYREVOKED128Key has been revoked关键被撤销
EKEYREJECTED129Key was rejected by service关键被拒绝服务
EOWNERDEAD130Owner died所有者死亡
ENOTRECOVERABLE131State not recoverable状态不可恢复
ERFKILL132Operation not possible due to RF-kill由于RF-kill而无法操作





 
















 
 

 


 





 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

 

 

 




 




 
 
 
 
 

 




 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 





 












 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

二、错误处理函数

许多不同的函数库都在失败时设置全局变量errno的值来指明失败原因。值得注意的是函数报告出错后必须立刻检查errno变量,因为它有可能被下一个函数调用所覆盖。
有两个非常有用的函数可以用来报告出现的错误:

#include <string.>
char *strerror(int errnum);
该函数把错误代码映射为一个字符串,对错误类型进行说明。

#include <stdio.h>
void perror(const char *s);
该函数也把errno变量中报告的错误应为到一个字符串,并把它输出到标准错误输出流。
---------------------

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

 

 

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


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


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

 

 

 

#ifndef _ASM_GENERIC_ERRNO_BASE_H

#define _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    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 */

#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 */

 

#endif

 

 

#include <asm-generic/errno-base.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    ENOTEMPTY    39    /* Directory not empty */

#define    ELOOP        40    /* Too many symbolic links encountered */

#define    EWOULDBLOCK    EAGAIN    /* Operation would block */

#define    ENOMSG        42    /* No message of desired type */

#define    EIDRM        43    /* Identifier removed */

#define    ECHRNG        44    /* Channel number out of range */

#define    EL2NSYNC    45    /* Level 2 not synchronized */

#define    EL3HLT        46    /* Level 3 halted */

#define    EL3RST        47    /* Level 3 reset */

#define    ELNRNG        48    /* Link number out of range */

#define    EUNATCH        49    /* Protocol driver not attached */

#define    ENOCSI        50    /* No CSI structure available */

#define    EL2HLT        51    /* Level 2 halted */

#define    EBADE        52    /* Invalid exchange */

#define    EBADR        53    /* Invalid request descriptor */

#define    EXFULL        54    /* Exchange full */

#define    ENOANO        55    /* No anode */

#define    EBADRQC        56    /* Invalid request code */

#define    EBADSLT        57    /* Invalid slot */

 

#define    EDEADLOCK    EDEADLK

 

#define    EBFONT        59    /* Bad font file format */

#define    ENOSTR        60    /* Device not a stream */

#define    ENODATA        61    /* No data available */

#define    ETIME        62    /* Timer expired */

#define    ENOSR        63    /* Out of streams resources */

#define    ENONET        64    /* Machine is not on the network */

#define    ENOPKG        65    /* Package not installed */

#define    EREMOTE        66    /* Object is remote */

#define    ENOLINK        67    /* Link has been severed */

#define    EADV        68    /* Advertise error */

#define    ESRMNT        69    /* Srmount error */

#define    ECOMM        70    /* Communication error on send */

#define    EPROTO        71    /* Protocol error */

#define    EMULTIHOP    72    /* Multihop attempted */

#define    EDOTDOT        73    /* RFS specific error */

#define    EBADMSG        74    /* Not a data message */

#define    EOVERFLOW    75    /* Value too large for defined data type */

#define    ENOTUNIQ    76    /* Name not unique on network */

#define    EBADFD        77    /* File descriptor in bad state */

#define    EREMCHG        78    /* Remote address changed */

#define    ELIBACC        79    /* Can not access a needed shared library */

#define    ELIBBAD        80    /* Accessing a corrupted shared library */

#define    ELIBSCN        81    /* .lib section in a.out corrupted */

#define    ELIBMAX        82    /* Attempting to link in too many shared libraries */

#define    ELIBEXEC    83    /* Cannot exec a shared library directly */

#define    EILSEQ        84    /* Illegal byte sequence */

#define    ERESTART    85    /* Interrupted system call should be restarted */

#define    ESTRPIPE    86    /* Streams pipe error */

#define    EUSERS        87    /* Too many users */

#define    ENOTSOCK    88    /* Socket operation on non-socket */

#define    EDESTADDRREQ    89    /* Destination address required */

#define    EMSGSIZE    90    /* Message too long */

#define    EPROTOTYPE    91    /* Protocol wrong type for socket */

#define    ENOPROTOOPT    92    /* Protocol not available */

#define    EPROTONOSUPPORT    93    /* Protocol not supported */

#define    ESOCKTNOSUPPORT    94    /* Socket type not supported */

#define    EOPNOTSUPP    95    /* Operation not supported on transport endpoint */

#define    EPFNOSUPPORT    96    /* Protocol family not supported */

#define    EAFNOSUPPORT    97    /* Address family not supported by protocol */

#define    EADDRINUSE    98    /* Address already in use */

#define    EADDRNOTAVAIL    99    /* Cannot assign requested address */

#define    ENETDOWN    100    /* Network is down */

#define    ENETUNREACH    101    /* Network is unreachable */

#define    ENETRESET    102    /* Network dropped connection because of reset */

#define    ECONNABORTED    103    /* Software caused connection abort */

#define    ECONNRESET    104    /* Connection reset by peer */

#define    ENOBUFS        105    /* No buffer space available */

#define    EISCONN        106    /* Transport endpoint is already connected */

#define    ENOTCONN    107    /* Transport endpoint is not connected */

#define    ESHUTDOWN    108    /* Cannot send after transport endpoint shutdown */

#define    ETOOMANYREFS    109    /* Too many references: cannot splice */

#define    ETIMEDOUT    110    /* Connection timed out */

#define    ECONNREFUSED    111    /* Connection refused */

#define    EHOSTDOWN    112    /* Host is down */

#define    EHOSTUNREACH    113    /* No route to host */

#define    EALREADY    114    /* Operation already in progress */

#define    EINPROGRESS    115    /* Operation now in progress */

#define    ESTALE        116    /* Stale NFS file handle */

#define    EUCLEAN        117    /* Structure needs cleaning */

#define    ENOTNAM        118    /* Not a XENIX named type file */

#define    ENAVAIL        119    /* No XENIX semaphores available */

#define    EISNAM        120    /* Is a named type file */

#define    EREMOTEIO    121    /* Remote I/O error */

#define    EDQUOT        122    /* Quota exceeded */

 

#define    ENOMEDIUM    123    /* No medium found */

#define    EMEDIUMTYPE    124    /* Wrong medium type */

#define    ECANCELED    125    /* Operation Canceled */

#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 */

 

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

 

 

#ifdef __KERNEL__

 

/*

 * These should never be seen by user programs. To return one of ERESTART*

 * codes, signal_pending() MUST be set. Note that ptrace can observe these

 * at syscall exit tracing, but they will never be left for the debugged user

 * process to see.

 */

#define ERESTARTSYS    512

#define ERESTARTNOINTR    513

#define ERESTARTNOHAND    514    /* restart if no handler.. */

#define ENOIOCTLCMD    515    /* No ioctl command */

#define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */

 

/* Defined for the NFSv3 protocol */

#define EBADHANDLE    521    /* Illegal NFS file handle */

#define ENOTSYNC    522    /* Update synchronization mismatch */

#define EBADCOOKIE    523    /* Cookie is stale */

#define ENOTSUPP    524    /* Operation is not supported */

#define ETOOSMALL    525    /* Buffer or request is too small */

#define ESERVERFAULT    526    /* An untranslatable error occurred */

#define EBADTYPE    527    /* Type not supported by server */

#define EJUKEBOX    528    /* Request initiated, but will not complete before timeout */

#define EIOCBQUEUED    529    /* iocb queued, will get completion event */

#define EIOCBRETRY    530    /* iocb queued, will trigger a retry */

 

#endif

 

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值