Linux errno 错误对照表

错误对照表:


errno0 :     Success
errno1 :     Operation not permitted
errno2 :     No such file or directory
errno3 :     No such process
errno4 :     Interrupted system call
errno5 :     Input/output error
errno6 :     No such device or address
errno7 :     Argument list too long
errno8 :     Exec format error
errno9 :     Bad file descriptor
errno10 :    No child processes
errno11 :    Resource temporarily unavailable
errno12 :    Cannot allocate memory
errno13 :    Permission denied
errno14 :    Bad address
errno15 :    Block device required
errno16 :    Device or resource busy
errno17 :    File exists
errno18 :    Invalid cross-device link
errno19 :    No such device
errno20 :    Not a directory
errno21 :    Is a directory
errno22 :    Invalid argument
errno23 :    Too many open files in system
errno24 :    Too many open files
errno25 :    Inappropriate ioctl for device
errno26 :    Text file busy
errno27 :    File too large
errno28 :    No space left on device
errno29 :    Illegal seek
errno30 :    Read-only file system
errno31 :    Too many links
errno32 :    Broken pipe
errno33 :    Numerical argument out of domain
errno34 :    Numerical result out of range
errno35 :    Resource deadlock avoided
errno36 :    File name too long
errno37 :    No locks available
errno38 :    Function not implemented
errno39 :    Directory not empty
errno40 :    Too many levels of symbolic links
errno41 :    Unknown error 41
errno42 :    No message of desired type
errno43 :    Identifier removed
errno44 :    Channel number out of range
errno45 :    Level 2 not synchronized
errno46 :    Level 3 halted
errno47 :    Level 3 reset
errno48 :    Link number out of range
errno49 :    Protocol driver not attached
errno50 :    No CSI structure available
errno51 :    Level 2 halted
errno52 :    Invalid exchange
errno53 :    Invalid request descriptor
errno54 :    Exchange full
errno55 :    No anode
errno56 :    Invalid request code
errno57 :    Invalid slot
errno58 :    Unknown error 58
errno59 :    Bad font file format
errno60 :    Device not a stream
errno61 :    No data available
errno62 :    Timer expired
errno63 :    Out of streams resources
errno64 :    Machine is not on the network
errno65 :    Package not installed
errno66 :    Object is remote
errno67 :    Link has been severed
errno68 :    Advertise error
errno69 :    Srmount error
errno70 :    Communication error on send
errno71 :    Protocol error
errno72 :    Multihop attempted
errno73 :    RFS specific error
errno74 :    Bad message
errno75 :    Value too large for defined datatype
errno76 :    Name not unique on network
errno77 :    File descriptor in bad state
errno78 :    Remote address changed
errno79 :    Can not access a needed sharedlibrary
errno80 :    Accessing a corrupted sharedlibrary
errno81 :    .lib section in a.out corrupted
errno82 :    Attempting to link in too manyshared libraries
errno83 :    Cannot exec a shared librarydirectly
errno84 :    Invalid or incomplete multibyte orwide character
errno85 :    Interrupted system call should berestarted
errno86 :    Streams pipe error
errno87 :    Too many users
errno88 :    Socket operation on non-socket
errno89 :    Destinationaddress required
errno90 :    Message too long
errno91 :    Protocol wrong type for socket
errno92 :    Protocol not available
errno93 :    Protocol not supported
errno94 :    Socket type not supported
errno95 :    Operation not supported
errno96 :    Protocol family not supported
errno97 :    Address family not supported byprotocol
errno98 :    Address already in use
errno99 :    Cannot assign requested address
errno100 :   Network is down
errno101 :   Network is unreachable
errno102 :   Network dropped connection onreset
errno103 :   Software caused connection abort
errno104 :   Connection reset by peer
errno105 :   No buffer space available
errno106 :   Transport endpoint is alreadyconnected
errno107 :   Transport endpoint is notconnected
errno108 :   Cannot send after transportendpoint shutdown
errno109 :   Too many references: cannot splice
errno110 :   Connection timed out
errno111 :   Connection refused
errno112 :   Host is down
errno113 :   No route to host
errno114 :   Operation already in progress
errno115 :   Operation now in progress
errno116 :   Stale NFS file handle
errno117 :   Structure needs cleaning
errno118 :   Not a XENIX named type file
errno119 :   No XENIX semaphores available
errno120 :   Is a named type file
errno121 :   Remote I/O error
errno122 :   Disk quota exceeded
errno123 :   No medium found
errno124 :   Wrong medium type
errno125 :   Operation canceled
errno126 :   Required key not available
errno127 :   Key has expired
errno128 :   Key has been revoked
errno129 :   Key was rejected by service
errno130 :   Owner died
errno131 :   State not recoverable
errno132 :   Operation not possible due toRF-kill
errno133 :   Unknown error 133
errno134 :   Unknown error 134
errno135 :   Unknown error 135
errno136 :   Unknown error 136
errno137 :   Unknown error 137
errno138 :   Unknown error 138
errno139 :   Unknown error 139

<think>嗯,用户现在遇到了在Linux上使用ioctl控制/dev/fb设备时返回错误码22(EINVAL)的问题。这通常表示无效的参数。我需要根据用户提供的引用和之前的知识来帮助解决这个问题。 首先,用户提到的引用中有几个相关的错误情况。例如,引用[3]中的Python程序遇到了Errno 22,提示无效参数,这可能是因为文件操作时参数不正确。同样,引用[4]提到了fdisk添加分区时的错误22,可能与参数或操作顺序有关。这些例子都指向参数传递的问题,所以用户的ioctl调用可能存在类似问题。 根据用户之前的回答,可能的原因包括权限不足、设备未初始化、结构体对齐或参数错误。现在用户特别提到了errno 22,所以重点应放在参数有效性上。例如,检查传递给ioctl的结构体是否正确初始化,字段是否合法,或者命令是否适用于fb设备。 另外,用户提供的引用[2]中的错误对照表显示errno 22对应EINVAL,即无效参数。需要确保ioctl的请求命令(如FBIOGET_VSCREENINFO)正确,并且结构体与内核版本匹配。例如,struct fb_var_screeninfo在不同内核版本中可能有不同字段,导致结构体大小不匹配,从而引发EINVAL。 用户可能没有正确初始化结构体,比如未使用memset清零,导致内核解析时遇到未知字段。或者传递了超出设备支持的参数值,如分辨率或颜色深度。此外,检查设备是否存在,如/dev/fb0是否正确,是否被其他进程占用,比如图形服务器(Xorg/Wayland)可能独占访问,导致ioctl失败。 需要建议用户检查以下几点:确保使用正确的头文件,结构体正确初始化和填充,验证设备状态,以及是否有权限访问设备。此外,参考之前回答中的诊断步骤,如使用strace跟踪系统调用,检查内核日志(dmesg)是否有相关错误信息。 用户可能需要提供代码片段以便更具体地诊断问题,但根据现有信息,应指导他们逐步排查参数和结构体的问题,确保所有字段合法,并验证设备支持的操作。</think>### Linux帧缓冲设备ioctl返回EINVAL(错误码22)解决方案 --- #### 一、核心问题定位(基于错误码22特性) 1. **EINVAL典型场景** - 传递给ioctl的参数结构体包含非法字段值 - 请求的ioctl命令与设备不兼容 - 结构体版本与内核不匹配(常见于跨版本开发)[^3] 2. **设备状态验证** ```bash # 确认设备存在且支持对应操作 $ cat /proc/fb # 应显示活动设备如"0: virtgpu" $ sudo fbset -i # 查看当前显示模式支持列表 ``` --- #### 二、代码级修复方案 1. **结构体初始化规范** ```c struct fb_var_screeninfo vi; memset(&vi, 0, sizeof(vi)); // 必须清零初始化[^3] if (ioctl(fd, FBIOGET_VSCREENINFO, &vi) == -1) { perror("FBIOGET_VSCREENINFO failed"); } ``` *常见错误字段:* - `vi.xres`/`vi.yres` 超过硬件支持的最大分辨率 - `vi.bits_per_pixel` 设置为无效值(如非8的整数倍) 2. **参数合法性检查表** | 字段 | 合法范围 | 验证方法 | |----------------------|--------------------------|----------------------------| | xres/yres | ≥32且≤设备最大分辨率 | 读取`fb_var_screeninfo` | | bits_per_pixel | 8/16/24/32 | 检查`fb_fix_screeninfo` | | pixclock | >0且符合设备时序要求 | 参考硬件手册 | 3. **内核头文件验证** ```c // 检查结构体定义是否与运行内核一致 #include <linux/version.h> #include <linux/fb.h> printf("内核头文件版本: %d\n", LINUX_VERSION_CODE); printf("结构体大小: %zu\n", sizeof(struct fb_var_screeninfo)); ``` *对比方法:* ```bash # 查看运行中内核的实际结构体大小 $ sudo cat /sys/kernel/debug/dynamic_debug/control | grep fb_ioctl ``` --- #### 三、动态诊断工具 1. **strace跟踪系统调用** ```bash $ strace -e trace=ioctl ./fb_test 2>&1 | grep FBIO # 示例输出: ioctl(3, FBIOGET_VSCREENINFO, 0x7ffd5d7d8e60) = -1 EINVAL (Invalid argument) ``` 2. **内核日志实时监控** ```bash $ dmesg -w | grep -C5 'fb.*error' # 观察驱动层错误日志 ``` --- #### 四、特殊场景解决方案 1. **多显示设备冲突处理** ```c // 显式指定活动控制台 int console_fd = open("/dev/tty0", O_RDWR); ioctl(console_fd, VT_ACTIVATE, 1); // 切换到目标控制台 ``` 2. **UEFI帧缓冲兼容模式** 在GRUB配置添加: ```text video=vesafb:ywrap,mtrr vga=0x318 ``` 3. **Wayland环境解决方案** ```bash # 临时禁用合成器 $ systemctl stop weston.service # 或使用DRM直接渲染模式 ``` --- #### 验证代码模板 ```c #include <linux/fb.h> #include <sys/ioctl.h> #include <stdio.h> #include <string.h> int main() { int fd = open("/dev/fb0", O_RDWR); if (fd < 0) { perror("open"); return -1; } struct fb_var_screeninfo vinfo; memset(&vinfo, 0, sizeof(vinfo)); // 关键步骤 if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0) { perror("FBIOGET_VSCREENINFO"); close(fd); return -1; } printf("Valid resolution: %dx%d@%dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel); close(fd); return 0; } ``` --- ### 相关问题扩展 1. 如何检测Linux帧缓冲设备的硬件加速能力? 2. 在多GPU系统中如何正确选择/dev/fbX设备? 3. 怎样通过ioctl实现屏幕旋转功能? 4. 如何调试Linux图形子系统中的DMA-BUF问题? [^3]: 基于参数校验机制的Linux内核开发规范 [^4]: 多路径存储设备管理实践
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值