unlocked_ioctl,顾名思义,应该在无大内核锁(BKL)的情况下调用;compat_ioctl,compat 全称 compatible(兼容的),主要目的是为 64 位系统提供 32 位 ioctl 的兼容方法,也是在无大内核锁的情况下调用。 在《Linux Kernel Development》中对两种 ioctl 方法有详细的解说。 在字符设备驱动开发中,一般情况下只要实现 unlo...
在《Linux Kernel Development》中对两种 ioctl 方法有详细的解说。 在字符设备驱动开发中,一般情况下只要实现 unlocked_ioctl 函数即可,因为在 vfs 层的代码是直接调用 unlocked_ioctl 函数 代码语言:javascript 复制 // fs/ioctl.c static long vfs_ioctl(struct file *filp, unsigned int cmd, unsigned long ...
◆ netlink中利用netlink_kernel_create函数创建一个netlink socket. int netlink_unicast(struct sock *ssk, struct sk_buff *skb,u32 pid, int nonblock) ssk字段正是由netlink_kernel_create函数所返回的socket;参数skb指向的是socket缓存,它的data字段用来指向要发送的netlink消息结构;参数pid为接收消息进程的...
kernel中文件的读写操作可以使用vfs_read()和vfs_write 需要在Linux kernel–大多是在需要调试的驱动程序–中读写文件数据。在kernel中操作文件没有标准库可用,需要利用kernel的一些函数,这些函数主要有: filp_open() filp_close(), vfs_read() vfs_write(),set_fs(),get_fs()等,这些函数在linux/fs.h和asm...
这样一来,一个命令就变成了一个整数形式的命令码。但是命令码非常的不直观,所以Linux Kernel中提供了一些宏,这些宏可根据便于理解的字符串生成命令码,或者是从命令码得到一些用户可以理解的字符串以标明这个命令对应的设备类型、设备序列号、数据传送方向和数据传输尺寸。
这样一来,一个命令就变成了一个整数形式的命令码。但是命令码非常的不直观,所以Linux Kernel中提供了一些宏,这些宏可根据便于理解的字符串生成命令码,或者是从命令码得到一些用户可以理解的字符串以标明这个命令对应的设备类型、设备序列号、数据传送方向和数据传输尺寸。这些宏我就不在这里解释了,具体...
我们看看官方是如何介绍他的,ioctl based interfaces — The Linux Kernel documentation 32-bit compat mode¶ In order to support 32-bit user space running on a 64-bit machine, each subsystem or driver that implements an ioctl callback handler must also implement the corresponding compat_ioctl handl...
#include <linux/kernel.h> #include <linux/fs.h> #include <linux/uaccess.h> #include <linux/semaphore.h> #include <linux/cdev.h> #include <linux/device.h> #include <linux/ioctl.h> #include <linux/slab.h> #include <linux/errno.h> ...
这样一来,一个命令就变成了一个整数形式的命令码。但是命令码非常的不直观,所以Linux Kernel中提供了一些宏,这些宏可根据便于理解的字符串生成命令码,或者是从命令码得到一些用户可以理解的字符串以标明这个命令对应的设备类型、设备序列号、数据传送方向和数据传输尺寸。
一、ioctl函数的命令定义方法: int (*unlocked_ioctl)(struct file*filp,unsigned int cmd,unsigned long...