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. React 16.3来了:带着全新的Context API

    文章概览 React在版本16.3-alpha里引入了新的Context API,社区一片期待之声.我们先通过简单的例子,看下新的Context API长啥样,然后再简单探讨下新的API的意义. 文中 ...

  2. iOS-NSPredicate正则验证【三种验证方法】

    1.NSPredicate验证(谓词匹配) ///验证(string:验证的字符串) + (BOOL)stringValidate:(NSString *)string{ NSString *regu ...

  3. 小白学Docker之Swarm

    承接上篇文章:小白学Docker之Compose,自学网站来源于https://docs.docker.com/get-started 系列文章: 小白学Docker之基础篇 小白学Docker之Co ...

  4. Oracle 12cR1 RAC 在VMware Workstation上安装(下)—静默安装

    Oracle 12cR1 RAC 在VMware Workstation上安装(下)—静默安装 1.1  静默安装 1.1.1  静默安装grid 安装之前使用脚本进行校验,确保所有的failed选项 ...

  5. BZOJ 1937: [Shoi2004]Mst 最小生成树 [二分图最大权匹配]

    传送门 题意: 给一张无向图和一棵生成树,改变一些边的权值使生成树为最小生成树,代价为改变权值和的绝对值,求最小代价 线性规划的形式: $Min\quad \sum\limits_{i=1}^{m} ...

  6. BZOJ 3669: [Noi2014]魔法森林 [LCT Kruskal | SPFA]

    题目描述 为了得到书法大家的真传,小 E 同学下定决心去拜访住在魔法森林中的隐 士.魔法森林可以被看成一个包含 n 个节点 m 条边的无向图,节点标号为 1,2,3,…,n,边标号为 1,2,3,…, ...

  7. redis requires ruby version 2.2.2的解决方案

    在执行gem install redis时 提示: gem install redis ERROR: Error installing redis: redis requires Ruby versi ...

  8. Orleans入门例子

    Orleans入门例子 这是Orleans系列文章中的一篇.首篇文章在此  一.铺垫. 虽然是个入门例子,还是需要一些铺垫. Orleans的最小完全体,应该分为2个部分.一个是Orleans客户端, ...

  9. 读书共享 Primer Plus C-part 9

    第十二章 存储类.链接和内存管理                                                       针对代码块中的static变量做如下范本 #include ...

  10. javac编译乱码

    PersonTest.java:1: 错误: 非法字符: \65279 解决途径如下 用记事本打开java源文件,另存为ANSI格式 如果java文件包含中文字符,使用-encoding gbk格式进 ...