Skip to content

Commit 8a42c8f

Browse files
committed
Clarify ioctl third argument as untyped pointer
Correct the description of the third parameter passed to the ioctl function. It was previously described as being of type long, but it is actually an untyped pointer to memory, traditionally declared as char *argp from before void * was valid in C. This change improves technical accuracy and helps developers understand how to correctly pass data—especially structures—between user space and the kernel using ioctl.
1 parent 0800ceb commit 8a42c8f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lkmpg.tex

+2-2
Original file line numberDiff line numberDiff line change
@@ -1383,8 +1383,8 @@ \section{Talking To Device Files}
13831383
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.
13841384
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.
13851385

1386-
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.
1387-
You will not be able to pass a structure this way, but you will be able to pass a pointer to the structure.
1386+
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.
1387+
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.
13881388
Here is an example:
13891389

13901390
\samplec{examples/ioctl.c}

0 commit comments

Comments
 (0)