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. 窗口缩小div内容隐藏看不到怎么解决?

    div的宽度设置为100%,并设置其背景颜色,但当窗口发生变化出现横向滚动条,拉滚动条的时候发现右面是空白的. 解决方法:body{min-width:1024px},给body加上一个最小宽度.ie ...

  2. BZOJ 2287. [HZOI 2015]疯狂的机器人 [FFT 组合计数]

    2287. [HZOI 2015]疯狂的机器人 题意:从原点出发,走n次,每次上下左右不动,只能在第一象限,最后回到原点方案数 这不煞笔提,组合数写出来发现卷积NTT,然后没考虑第一象限gg 其实就是 ...

  3. BZOJ 2809: [Apio2012]dispatching [斜堆]

    题意:主席树做法见上一题 我曾发过誓再也不写左偏树(期末考试前一天下午5个小时没写出棘手的操作) 于是我来写斜堆啦 从叶子往根合并,维护斜堆就行了 题目连拓扑序都给你了... 说一下斜堆的操作: 合并 ...

  4. python爬虫(1)——urllib包

    人生苦短,我用python! 一.关于爬虫 鉴于我的windos环境使用命令行感觉非常不便,也懒得折腾虚拟机,于是我选择了一个折中的办法--Cmder.它的下载地址是:cmder.net Cmder是 ...

  5. hibernate连接MySQL配置hibernate.cfg.xml

    今天刚学完hibernate所以急着做一个hibernate的项目,有不足的请帮我改正一下.谢谢大家 <hibernate-configuration> <session-facto ...

  6. 在CentOS上部署多节点Citus集群

    1 在所有节点执行以下步骤 Step 01 添加Citus Repostory # Add Citus repository for package manager curl https://inst ...

  7. python学习:hashlib模块使用

    #!/usr/bin/env python   import sys import hashlib   def md5sum(f):     m = hashlib.md5()     with op ...

  8. Ubuntu系统下crontab的使用

    最近一个项目,需要用到一个定时任务,先说crontab的常用命令. crontab -u //设定某个用户的cron服务,一般root用户在执行这个命令的时候需要此参数 crontab -l //列出 ...

  9. 高可用的MongoDB集群

    1.序言 MongoDB 是一个可扩展的高性能,开源,模式自由,面向文档的数据库. 它使用 C++编写.MongoDB 包含一下特点: l  面向集合的存储:适合存储对象及JSON形式的数据. l ...

  10. appium+Python 启动app(三)登录

    我们根据前面的知识点,用uiautomatorviewer工具来获取我们当前的元素 (注:uiautomatorviewer 是 android sdk 自带的) 知识点:appium的webdriv ...