ioctl/unlocked_ioctl/compat_ioctl

本文探讨了Linux内核2.6.35及以前版本中file_operations结构体的ioctl函数指针,并介绍其在2.6.36版本中的重大变更。详细解释了unlocked_ioctl取代传统ioctl的原因,包括其内部实现的改进,如移除大内核锁的调用,以及兼容模式下32位与64位转换的处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在kernel 2.6.35及之前的版本中struct file_opertation一共有3个ioctl:ioctl, unlocked_ioctl, compat_ioctl,

struct file_operations {
        int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
        long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
        long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
...

在kernel 2.6.36中已经完全删除了struct file_operation中的ioctl指针,取而代之的是unlocked_ioctl。

struct file_operations {
        long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
        long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
...

unlocked_ioctl与ioctl最大的不同是参数中少了inode,不过用户空间中ioctl对应的系统调用接口却没有变化,用户程序不需要改变。unlocked_ioctl最主要的改进是不再需要上大内核锁(调用之前不再先调用lock_kernel()然后再unlock_kernel()),内核的开发者试图朝移除大内核锁的方向努力。

compat_ioctl被用在用户空间为32位模式,而内核运行在64位模式时,这时候需要将64位转到32位。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

luckywang1103

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值