The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
c system call rangaswamy High Level Programming 1 02-19-2008 10:53 AM
how to differentiate system call from library call muru UNIX for Advanced & Expert Users 2 07-19-2007 08:20 PM
stty: tcgetattr: A specified file does not support the ioctl system call. vishal_ranjan UNIX for Advanced & Expert Users 9 05-30-2007 01:29 AM
Making Socket System Call From Linux Kernel Module? mian_m_hamayun Linux 0 04-06-2005 06:34 AM
read system call Madhu Babu High Level Programming 1 11-16-2002 04:11 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-15-2008
Registered User
 

Join Date: Sep 2008
Posts: 1
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.
Reply With Quote
Forum Sponsor
  #2  
Old 09-15-2008
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0