From 8a42c8f35f55d205e0045914a852032ff200bb16 Mon Sep 17 00:00:00 2001 From: "Guan-Chun.Wu" <409411716@gms.tku.edu.tw> Date: Fri, 25 Apr 2025 18:22:35 +0800 Subject: [PATCH] Clarify ioctl third argument as untyped pointer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lkmpg.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lkmpg.tex b/lkmpg.tex index acf1325f..c77a3c51 100644 --- a/lkmpg.tex +++ b/lkmpg.tex @@ -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}