0

The question may seem naive, but I'm new to kernel/driver programming. I created a device mapper over a block device, which is working fine. It's constructor/destructor and map methods are called.

Now, I'm trying to write an ioctl for this mapper. When ioctl is written for a device, it has the following signature:

int ioctl(int d, /* other args */);

A file structure/descriptor is expected in ioctl. This can be easily used by application process as it has access to file.

But the ioctl for device mapper has the following signature ( in struct target_type):

typedef int (*dm_ioctl_fn) (struct dm_target *ti, unsigned int cmd,
             unsigned long arg);

How can user application get access to device mapper with ioctl without having knowledge of struct dm_target ?

user2255299
  • 185
  • 7

1 Answers1

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 argument 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 argument using access_ok() */
    /*  impliment support of ioctl commands */
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459