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. get、post、put、delete请求方式

    对资源的增,删,改,查操作,其实都可以通过GET/POST完成,不需要用到PUT和DELETE. Jersey框架,实现了restful风格,常用的注解@GET.@POST.@PUT.@DELETE如 ...

  2. SSD trim及4k对齐

    trim可以帮助减小SSD的写放大WA问题,删除文件后不仅仅是将文件标记为删除,而是在SSD空闲的时候统一进行删除. Linux下的trim支持叫discard,修改fstab文件,在挂载参数中加上d ...

  3. BZOJ 3173: [Tjoi2013]最长上升子序列 [splay DP]

    3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1613  Solved: 839[Submit][St ...

  4. memcached安装与使用详解

    一.memcache的简介 memcache是高速,分布式的内存缓存服务器 php的缓存方式一般可以使用memcache技术和redis技术,其中各有优劣,因不同的情况而选择较为适合的缓存技术,其中m ...

  5. Jenkins 不同角色不同视图及不同权限设置

    由于jenkins默认的权限管理体系不支持用户组或角色的配置,因此需要安装第三发插件来支持角色的配置,本文将使用Role Strategy Plugin,介绍页面:https://wiki.jenki ...

  6. Ubuntu Linux 与 Windows 7双系统安装教程(图文)

    前期准备: 1. 备份你的重要数据到其他设备上,以防不测2. 准备linux镜像.可以到ubuntu官网下载iso格式的文件.(注意:如果你是双显卡,不要随便下.amd的双显卡请选择含有"a ...

  7. CEF小白人系列1-认识CEF

    手头上有个项目需要做浏览器的相关功能,评估了几个嵌入式方案最后选定CEF作为开发基础. 在入坑新技术的时候第一选择是去官网学习,这是一个非常好的习惯. CEF官网(请科学上网) https://bit ...

  8. Dynamics CRM 2015-Ribbon In Basic Home Tab

    前文中有说到关于Form上Ribbon的配置以及控制,而Ribbon Button还可以在其它地方的配置,今天就来说说在Basic Home Tab里面的配置,效果图如下: 具体配置Customiza ...

  9. Json对象与Json字符串互转(4种转换方式)(转)

    1>jQuery插件支持的转换方式: $.parseJSON( jsonstr ); //jQuery.parseJSON(jsonstr),可以将json字符串转换成json对象  2> ...

  10. Java经典编程题50道之四十五

    判断一个整数能被几个9整除. public class Example45 {    public static void main(String[] args) {        f(729);   ...