Subject: Re: Determining what ioctl commands do (was IOCTL RTFM problem)
To: Michael C. Richardson <>
From: Jeremy Cooper <>
List: tech-kern
Date: 11/06/1997 08:46:15
On Wed, 5 Nov 1997, Michael C. Richardson wrote:

>   Let's say I see 
> 	ioctl(s, SIOCFOOBAR, &somecutestruct)
>   in some code.
>   How do I RTFM on this?

I admit that the following isn't the way that it ideally should happen,
but it's how I do research an ioctl command when I'm stuck.  I know you
probably know how to do this, but it might benefit others.  Be aware that
this approach is RTFS rather than RTFM.

The first argument in this code, ``s'', is a file descriptor created by
opening some sort of device or socket.  You must find the statement
in your code which obtains this descriptor.  Once found, you should
be able to determine what file or device was opened.  Next, find the
ioctl function in the code for that device or socket.  Determining the
location of the responsible code may require that you examine your
machine's dmesg output to determine the name of the driver handling that

Once you have found the device driver's ioctl-handling function (search
for 'ioctl' in the driver code), look at the first function it calls and
remember it for later reference.  If it doesn't appear that the driver
handles the ioctl command you are looking for, chances are that the driver
is passing the command to its parent driver with this call.  Now examine
the switch statement later in the function.  If you find the command is
handled there then you are done!  If you can't find it, you need to search
the parent driver.

If a piece of code obtains a file descriptor by opening /dev/ttya on a
SPARC 2, for example, and then issues an ioctl(s, TIOCNOTTY, 0) on that
descriptor, your first mission is to find the SPARC source for the
/dev/ttya driver.  I, your omnipotent narrator, will tell you that this is
contained in the file src/sys/dev/ic/z8530tty.c.  Within this code, the
function zsioctl() handles the ioctl calls for this device.

The first (real) function called by this code is ttioctl(), which for now
you need only note for later reference.  Then examine the switch()
statement that follows it and look for your ioctl command.  (TIOCNOTTY).
You'll notice that it's not there.  Now you need to find the ttioctl()
function, which is in src/sys/kern/tty_tty.c.  Within the switch statement
for that function, you will find the code which handles TIOCNOTTY.