关于ioctl,unlocked_ioctl和compat_ioctl执行的顺序
2012-12-29 16:26
447 查看
关于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操作,优先执行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,
};
相关文章推荐
- 技术总结:关于JS执行前台和后台顺序的.另外一个是前后和后台变量的交互的.
- Nginx 关于 Rewrite 执行顺序详解
- 关于try,finally执行顺序的分析
- 关于Java中静态属性和静态代码块的执行顺序问题
- 关于FLEX中AS执行顺序的问题
- ABC线程如何保证顺序执行 关于多线程的一个小例子
- 关于Java中try-catch-finally-return的执行顺序
- 关于CTE的使用,以及TOP/ORDER BY的执行顺序
- 关于try-catch语段中,try内的语句执行顺序的探究
- 类中关于静态构造函数的执行顺序
- 关于js中函数的执行顺序
- 关于try-catch-finally-return的执行顺序的一些总结
- 关于触发器在行级和语句级的执行顺序问题
- 关于Java中try finally return语句的执行顺序浅析
- 关于类继承/初始化成员变量/构造函数/析构函数 执行顺序
- 关于CyclicBarrier的执行顺序
- 关于Java中静态代码块以及构造函数的执行先后顺序
- 关于Java new对象构造方法执行顺序 解释恶汉单例模式死循环问题
- 关于jsp、js、html代码执行顺序
- 关于ENTER_FRAME的执行顺序问题