1

The prototype of ioctl in linux driver modules is

int ioctl(struct inode *i, struct file *f, unsigned int cmd, unsigned long arg);

or

long ioctl(struct file *f, unsigned int cmd, unsigned long arg);

but inside sys/ioctl.h it is

int ioctl(int fd, int request, void *argp);

The first argument type is different, is there any module between ioctl calling program and driver that converts this argument(From file descriptor to file structure pointer)?

How this mapping works?(From file descriptor to file).

1 Answer 1

1

In ${kernel_root}/fs/ioctl.c (in 4.13) there's:

SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)

That SYSCALL_DEFINE3 is a macro that takes those parameters and expands it to the appropriate signature for the system call. That function is the logical entry point for the ioctl system call from user space. That function, in turn, looks up the struct fd corresponding to the given file descriptor and calls do_vfs_ioctl passing the struct file associated with the struct fd. The call will wind through the VFS layer before it reaches a driver, but that should give you a place to start looking.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.