0

这个问题可能看起来很幼稚,但我是内核/驱动程序编程的新手。我在块设备上创建了一个设备映射器,它工作正常。它的构造函数/析构函数和映射方法被调用。

现在,我正在尝试为这个映射器编写一个 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 访问设备映射器?

4

1 回答 1

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 */
}
于 2017-08-29T19:06:01.720 回答