0

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).

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.