Skip to content

Clarify ioctl third argument as untyped pointer #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lkmpg.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1383,8 +1383,8 @@ \section{Talking To Device Files}
Every device can have its own \cpp|ioctl| commands, which can be read ioctl's (to send information from a process to the kernel), write ioctl's (to return information to a process), both or neither.
Notice here the roles of read and write are reversed again, so in ioctl's read is to send information to the kernel and write is to receive information from the kernel.

The ioctl function is called with three parameters: the file descriptor of the appropriate device file, the ioctl number, and a parameter, which is of type long so you can use a cast to use it to pass anything.
You will not be able to pass a structure this way, but you will be able to pass a pointer to the structure.
The ioctl function is called with three parameters: the file descriptor of the appropriate device file that is already open, the ioctl number, and a parameter, which is an untyped pointer to memory—traditionally declared as char *argp (from the days before void * was valid in C)—allowing you to cast it to pass various types of data.
You cannot pass a structure by value this way, but you can pass a pointer to a structure, which the kernel can then dereference and access.
Here is an example:

\samplec{examples/ioctl.c}
Expand Down