设备映射程序'ioctl'签名
问题描述:
这个问题可能看起来很天真,但我是内核/驱动程序编程的新手。我在一个块设备上创建了一个设备映射器,该设备工作正常。它是构造函数/析构函数,并调用映射方法。设备映射程序'ioctl'签名
现在,我正在尝试为此映射器编写一个ioctl。当读写控制为装置写入,它具有以下特征:
int ioctl(int d, /* other args */);
的文件结构/描述符中的ioctl预期。由于它可以访问文件,因此应用程序进程可以轻松使用它。
但对于设备映射的IOCTL具有以下特征(在结构TARGET_TYPE):
哪有用户应用程序可以访问与IOCTL设备映射器,而无需结构dm_target的知识呢?
答
-Ioctl which stand for Input Output control is a system call used in linux to implement system calls which are not be available in the
kernel by default.
-The major use of this is in case of handling some specific operations of a device for which the kernel does not have a system call by default. For eg: Ejecting the media from a "CD" drive. An ioctl command is implemented to give the eject system call to the cd drive.
-ioctl(fd, cmd , INPARAM or OUTPARAM);
|
3rd arguement is INPARAM or OUTPARAM i.e we don't have to read a device, then how how to interact with device ? use ioctl.
-open ioctl.h and check you will get more information
#define "ioctl name" __IOX("magic number","command number","argument type")
static long char_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
/* verify arguemenst using access_ok() */
/* impliment support of ioctl commands */
}