这个问题似乎很幼稚,但我是内核/驱动程序编程的新手。我在块设备上创建了一个设备映射器,工作正常。它的构造函数/析构函数和map方法被调用。
现在,我正在尝试为此映射器编写ioctl。为设备编写ioctl时,它具有以下签名:
int ioctl(int d, /* other args */);
ioctl中需要文件结构/描述符。这可以由应用程序进程轻松使用,因为它可以访问文件。
但设备映射器的ioctl具有以下签名(在 struct target_type 中):
typedef int (*dm_ioctl_fn) (struct dm_target *ti, unsigned int cmd,
unsigned long arg);
用户应用程序如何在不知道 struct dm_target 的情况下使用ioctl访问设备映射器?
答案 0 :(得分:0)
-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 */
}