ioctl() system call on Linux-i386


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users ioctl() system call on Linux-i386
# 1  
Old 09-15-2008
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.
# 2  
Old 09-15-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

system call

Trying to figure out a load issue with a webserver. I have traced a php script and noticed the following connect(4, {sa_family=AF_INET, sin_port=htons(3306), sin_addr=inet_addr("XX.XX.XX.XX")}, 16) = -1 EINPROGRESS (Operation now in progress) <0.000035> poll(, 1, 2000) = 1 () <0.000120>... (5 Replies)
Discussion started by: rajan007
5 Replies

2. Programming

need help with system call

hi everyone i wrote a system call and compiled the kernel succesfully... my system call is in a file in the kernel folder named my_syscall1.c (kernel/my_syscall1.c) the header file for this system call i added it in the folder include like this include/my_syscall1/my_syscall1.h my problem is... (2 Replies)
Discussion started by: demis87
2 Replies

3. Shell Programming and Scripting

stty: tcgetattr: A specified file does not support the ioctl system call

Hi Gurus, I have scheduled a script using cron scheduler. Script works fine when i run it manually. But it gives the following error in cron log. stty: tcgetattr: A specified file does not support the ioctl system call. I have given the following statement in cron. 0-59 * * * *... (5 Replies)
Discussion started by: svajhala
5 Replies

4. Programming

system call

I have a cgi script which is called after certain time interval, which has this: system ("ls -l /tmp/cgic* | grep -v \"cgicsave.env\" | awk '{print $5}'"); During the execution of this script,the output is 0 sometimes. But due to this the system call is not working at all and doesnt o/p... (2 Replies)
Discussion started by: xs2punit
2 Replies

5. Linux

How to implement a system call in linux?

I encountered a variety of difficulties when implementing a system call as simple as HelloWorld example in Linux so far. Firstly, according to the book "Linux Kernel Development Second Edition", I tried to implement a syscall in 2.6.31 but no way absolutely because 2.6.10 has a very different way... (5 Replies)
Discussion started by: sunnyhay
5 Replies

6. Programming

C:system call

Hi I'm studing the system call. I've written a small program that return the time spent in doing some operations. Now I'd like to write one that return the time spent in user mode of a process. I'm reading that i should use the tms struct: clock_t times(struct tms *buf); struct tms {... (2 Replies)
Discussion started by: Dedalus
2 Replies

7. Programming

c system call

How the c compiler differentiates the system calls and function calls? (1 Reply)
Discussion started by: rangaswamy
1 Replies

8. UNIX for Advanced & Expert Users

how to differentiate system call from library call

Hi, Ho do I differentiate system call from library call? for example if I am using chmod , how do I find out if it is a system call or library call? Thanks Muru (2 Replies)
Discussion started by: muru
2 Replies

9. UNIX for Advanced & Expert Users

stty: tcgetattr: A specified file does not support the ioctl system call.

Hi, I am trying to implement SSH between two systems say ukblx151 & ukapx047 with ID say khzs228, i follow the following process: Step-1) $ ssh-keygen -t rsa -f rsa Generating public/private rsa key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your... (9 Replies)
Discussion started by: vishal_ranjan
9 Replies

10. Linux

Making Socket System Call From Linux Kernel Module?

Hi Everyone! How can we make a socket() system call from a linux module executing in kernel space? If any one knows, kindly tell me. It will be great. I want to use the socket interface in linux kernel space for sending raw packets over the network. Hamayun (0 Replies)
Discussion started by: mian_m_hamayun
0 Replies
Login or Register to Ask a Question