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. BZOJ 2809: [Apio2012]dispatching [主席树 DFS序]

    传送门 题意:查询树上根节点值*子树中权值和$\le m$的最大数量 最大值是多少 求$DFS$序,然后变成区间中和$\le m$最多有几个元素,建主席树,然后权值线段树上二分就行了 $WA$:又把边 ...

  2. ZOJ 3557 & BZOJ 2982 combination[Lucas定理]

    How Many Sets II Time Limit: 2 Seconds      Memory Limit: 65536 KB Given a set S = {1, 2, ..., n}, n ...

  3. (转载)Java:按值传递与按引用传递

    原链接:传送门 前天在做系统的时候被Java中参数传递问题卡了一下,回头查阅了相关的资料,对参数传递问题有了新的了解和掌握,但是有个问题感觉还是很模糊,就是Java中到底是否只存在值传递,因为在查阅资 ...

  4. offset / scroll / client Left / Top

    1.offsetHeight / Width (只读) offsetHeight:表示该元素在垂直方向占用的空间大小,包含元素的高度+上边框高度+下边框高度 offsetWidth:表示该元素在水平方 ...

  5. 看完轻松年薪30w+

    弱鸡学git中,百度git追踪方面的博文,突然发现各种git的博文中突然插入了一个这个,不解,本以为又是某个大佬在分享他的心路历程,点进去打算喝鸡汤,666 怪不得标题党标题党这么的叫,可怕可怕,文章 ...

  6. 【算法】哈希表的诞生(Java)

    参考资料 <算法(java)>                           — — Robert Sedgewick, Kevin Wayne <数据结构>       ...

  7. 【转】Nginx配置详解

    转自:http://www.cnblogs.com/knowledgesea/p/5175711.html Nginx常用功能 1. Http代理,反向代理:作为web服务器最常用的功能之一,尤其是反 ...

  8. 浅讲JUnit

    JUnit单元简介:      JUnit ----是一个开发源码的java测试框架,用于编写和运行可重复的测试,它是用于单元测试框架体系xUnit的一个实例, 用于java语言,主要用于白盒测试,回 ...

  9. [CJOJ2410]数列操作d

    [CJOJ2410]数列操作d 标签: 线段树 题解 没时间写题了,我来嘴巴AC吧. 注意区间加的这个值不是 确定的,随着元素位置的变化而改变. 只需要能维护这个东西剩下的就很好做了. 那么\(x*( ...

  10. angularjs ng-csv 异步下载

    相信之前我们 前端下载csv的时候 都是通过后台代码 生成文件,然后发送给前台 文件路径来进行下载,下面介绍一下angular1 ng-csv下载 csv数据(这种不通过后台代码来实现的前台下载) 参 ...