kernel 2.6.35 及之前的版本中struct file_operations 一共有3个ioctl :
ioctl,unlocked_ioctl和compat_ioctl
现在只有unlocked_ioctl和compat_ioctl 了

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

这个指针函数变了之后最大的影响是参数中少了inode ,不过这个不是问题,因为用户程序中的ioctl对应的系统调用接口没有变化,所以用户程序不需要改变,一切都交给内核处理了,如果想在unlocked_ioctl中获得inode 等信息可以用如下方法:
struct inode *inode = file->f_mapping->host;
struct block_device *bdev = inode->i_bdev;
struct gendisk *disk = bdev->bd_disk;
fmode_t mode = file->f_mode;


和int (*ioctl) (struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)相比

compat_ioctl少了inode参数, 可以通过filp->f_dentry->d_inode方法获得。

2011-08-27 16:28


http://blog.csdn.net/zhangqingsup/article/details/5721924

区别:

ioctl 和 unlock_ioctl

ioctl 不会lock_kernel()

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

引用

http://blog.chinaunix.net/u1/38994/showart_2248151.html

对几个ioctl执行顺序的分析

关于ioctl,unlocked_ioctl和compat_ioctl执行的顺序



对于ioctl操作,优先执行f_op->unlocked_ioctl,如果没有unlocked_ioctl,那么执行f_op->ioctl



sys_ioctl

==> vfs_ioctl

==> file_ioctl

==> do_ioctl

static long do_ioctl(struct file *filp, unsigned int cmd,

        unsigned long arg)

{

    int error = -ENOTTY;



    if (!filp->f_op)

        goto out;



    if (filp->f_op->unlocked_ioctl) { // 优先执行f_op->unlocked_ioctl

        error = filp->f_op->unlocked_ioctl(filp, cmd, arg);

        if (error == -ENOIOCTLCMD)

            error = -EINVAL;

        goto out;

    } else if (filp->f_op->ioctl) { // 如果没有unlocked_ioctl,那么执行f_op->ioctl

        lock_kernel();

        error = filp->f_op->ioctl(filp->f_path.dentry->d_inode,

                      filp, cmd, arg);

        unlock_kernel();

    }



 out:

    return error;

}



对于compat_sys_ioctl系统调用的使用比较麻烦一些,因为默认kernel是不将它built-in进内核的,

可以通过fs/Makefile看到如下定义obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o

对于CONFIG_COMPAT的定义于cpu体系结构有关,比如下面几个默认cpu配置了CONFIG_COMPAT=y

arch/x86_64/defconfig

arch/sparc64/defconfig

arch/powerpc/configs/ppc64_defconfig

arch/s390/defconfig

arch/parisc/configs/a500_defconfig

arch/mips/configs/ip32_defconfig



compat_sys_ioctl

filp->f_op->compat_ioctl(filp, cmd, arg);

如果该cmd在compat_ioctl中没有找到对应的处理,同时没有filp->f_op方法集[luther.gliethttp]

或者filp->f_op->ioct且filp->f_op->unlocked_ioctl均没有,那么将尝试调用vfs_ioctl,看看是不是一些经典的ioctl命令.



对于sound/core/control.c文件[luther.gliethttp]

#ifdef CONFIG_COMPAT

#include "control_compat.c"

#else

#define snd_ctl_ioctl_compat    NULL

#endif

下面的"controlC%i"声卡对应的控制节点fops的compat_ioctl,当没有定义CONFIG_COMPAT时,将被置为NULL

static const struct file_operations snd_ctl_f_ops =

{

    .owner =    THIS_MODULE,

    .read =        snd_ctl_read,

    .open =        snd_ctl_open,

    .release =    snd_ctl_release,

    .poll =        snd_ctl_poll,

    .unlocked_ioctl =    snd_ctl_ioctl,

    .compat_ioctl =    snd_ctl_ioctl_compat,

    .fasync =    snd_ctl_fasync,

};

ioctl,unlocked_ioctl 处理方法的更多相关文章

  1. The difference among ioctl, unlocked_ioctl and compat_ioctl (RT)

    Meta-answer: All the raw stuff happening to the Linux kernel goes through lkml (the Linux kernel mai ...

  2. linux ioctl 接口

    大部分驱动需要 -- 除了读写设备的能力 -- 通过设备驱动进行各种硬件控制的能力. 大 部分设备可进行超出简单的数据传输之外的操作; 用户空间必须常常能够请求, 例如, 设 备锁上它的门, 弹出它的 ...

  3. Linux Device Driver 3th 中的一些坑

    linux设备驱动第三版由于年代比较久远,有很多东西已过时.开一贴记录自己发现的一些问题. 4.3.1.4. seq_file接口 此节最后提到用 struct proc_dir_entry* cre ...

  4. 【转】 bio 与块设备驱动

    原文地址: bio 与块设备驱动      系统中能够随机访问固定大小数据片(chunk)的设备被称作块设备,这些数据片就称作块.块设备文件都是以安装文件系统的方式使用,此也是块设备通常的访问方式.块 ...

  5. 手把手教Linux驱动3-之字符设备架构详解,有这篇就够了

    一.Linux设备分类 Linux系统为了管理方便,将设备分成三种基本类型: 字符设备 块设备 网络设备 字符设备: 字符(char)设备是个能够像字节流(类似文件)一样被访问的设备,由字符设备驱动程 ...

  6. Python底层socket库

    Python底层socket库将Unix关于网络通信的系统调用对象化处理,是底层函数的高级封装,socket()函数返回一个套接字,它的方法实现了各种套接字系统调用.read与write与Python ...

  7. MTD应用学习:mtd和mtdblock的区别

    http://my.oschina.net/shelllife/blog/123482 http://www.cnblogs.com/hnrainll/archive/2011/06/09/20760 ...

  8. Linux驱动开发相关

    一般用printk 查看/etc/sysconf文件,看看内核调试信息放到了哪里 打印的消息一般放在/var/log/messages文件里面. 如果你是在X Windows下的XTerm中insmo ...

  9. [虚拟化/云] kvm的架构分析

    预备知识 1. 客户机物理页框到宿主机虚拟地址转换 http://blog.csdn.net/zhuriyuxiao/article/details/8968781 http://www.tuicoo ...

随机推荐

  1. bootstrap tabs 默认tab页的使用方式

    HTML中引入tabs如下: <ul class="nav"> <li><a href="#a" tt="A.html& ...

  2. 随机切换IP和UA

    在爬虫爬取过程中,网站会根据我们的IP和UA去确认到底是浏览器操作还是爬虫在操作,所以,为了让爬虫不被网站禁止,随机切换Ip 和UA是很重要的,因为这个类在各个爬虫中经常要用到,所以可以自已维护一份随 ...

  3. cookie和session的那些事

    对于经常网购的朋友来说,经常会遇到一种情况: 打开淘宝或京东商城的首页,输入个人账号和密码进行登陆,然后进行购物,支付等操作都不需要用户再次输入用户名和密码 但是如果用户换一个浏览器或者等几个小时后再 ...

  4. Install MongoDB on Linux Systems 速记

    下载mongodb最新版本: 下载链接:http://pan.baidu.com/s/1kTDnkyz curl -O http://downloads.mongodb.org/linux/mongo ...

  5. tomcat配置JNDI获取数据源

    各个web工程可以通过工程内的xml文件配置访问数据库的数据源,这样的配置是各个工程私有的.基于JNDI为tomcat配置数据源,则可以做成全局的,各工程只需要通过便签引用数据源即可. 1.需要将数据 ...

  6. Codevs 3990 [中国剩余定理]

    模板题 注意如何得到[a,b]区间范围内的解 #include <iostream> #include <cstdio> #include <cstring> #i ...

  7. HDU3488 Tour [有向环覆盖 费用流]

    Tour Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submis ...

  8. SSM项目手动分页详解

    环境:idea+mysql 首先,既然是mysql,那肯定会用到limit,用这个分页的确很方便. 第一步,编写sql语句 <select id="selectImages" ...

  9. 让linux 服务器网卡物理口不停闪烁

    [root@DBSERVER51 ~]# ethtool -p eth0 此时就会看到对应的物理口一个灯在不停的闪烁,对了.这就是我们在系统看到的那个叫eth0的网卡了.就是这么简单.

  10. VS2015 (C/C++) 生成的程序,不能在server2008上运行

    项目本来是为Linux下运行做的,但是客户环境需要在windows下运行,幸好用的一些库是跨平台的. 于是用vs2015编译. 然后就发现在2008上却运行时库,装了2015的运行时库后, 在运行,就 ...