ioctl() system call on Linux-i386

Greetings,

Please help me with the following :

Where can I find what means exactly and how to use each of the second
argument of the ioctl() system call in Linux/386 : FIOxxx (file IOCTL
requests), SIOxxx (socket IOCTL requests), TCxxx TIOxxx (terminal
IOCTL requests) ?

I did not find yet anything useful on Internet about this topic.

Maybe a Linux [kernel] developer could help me.

Trying to understand which are the ioctl() requests (the second argument to the system call ioctl() ) in Linux and what does each request, I looked in the kernel sources directory, /usr/src/linux, where I found that ioctl() it is coded in a hexadecimal number of 8 hexadecimal figures : bits 31-30 mean fi the call is of type _IO, _IOW, _IOR, _IOWR, bits 29-16 mean the size of the structure gived as the argument, bits 15-8 mean an ASCII character, supposed unique to each driver, and bits 7-0 mean the number of the ioctl() function in that driver.

I set out to study which are the ioctl() requests for files, (those with type FIOxxx) : FIOCLEX, FIONCLEX, FIOASYNC, FIONBIO, FIONREAD, FIOQSIZE.

Writing a short program, I found out that in hexadecimal, for a Linux-i386 machine, they have the following values : 0x5451, 0x5450, 0x5452, 0x5421, 0x541b, 0x5460.

What I do not understand, in first instance, and here I hope you to help me, is why the bits 29-16, of these hexadecimal numbers above, are set to 0 and why bits 31-30 are also 0, so we have _IO commands, and NOT _IOR or _IOW, as would normal be.

If I could understand these, I could go further, to the second step : looking to the Linux kernel sources and to exactly see what does every ioctl() request (what does every ioctl() function) and to enlighten myself, without the need of more documentation.

Thanks,
Alexandru Goia.

First of all, ioctl is a driver entry point. So look at the documentation for the driver to see what each argument does. Most of the ioctl calls will be documented on a man page, like this one:

http://www.linuxmanpages.com/man4/tty_ioctl.4.php

Those sub-fields you ask about are mostly suggestions to the driver writer on how to use the argument. Very few drivers will use the length subfield. The ascii character (15-8) and the op code (7-0) are pretty universal. The ascii character enables drivers to diagnose the famous "inappropiate ioctl for device" error. But most driver writers ignore the other stuff.

That character is not unique to each driver the way that the major number is. For example, there might be 3 or 4 mag tape drivers, each with a unique major number to control each type of tape drive. But the "mt -f /dev/tape rewind" command will send the exact same ioctl to each one.