ioctl
function name: ioctl
Function: Control I /O device
Usage: int ioctl (int handle, int cmd, [int *argdx, int argcx]);
Comments for macros defined in include/asm/ioctl.h:
#define _IOC_NRBITS 8 //word bits of the number field Width, 8bits
#define _IOC_TYPEBITS 8 //The width of the word field of the type field, 8bits
#define _IOC_SIZEBITS 14 //The width of the word size of the size field, 14bits
word bit width
#define _IOC_DIRBITS 2 //direction (direction) field, 2bits
#define _IOC_NRMASK ((1 & lt; & lt; _IOC_NRBITS) -1) //sequence number field mask, 0x000000FF
#define _IOC_TYPEMASK ((1 & lt; & lt; _IOC_TYPEBITS) -1) //mask magic number field, 0x000000FF
#define _IOC_SIZEMASK ((1 & lt; & lt ; _IOC_SIZEBITS)-1) //Mask of the size field, 0x00003FFF
#define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1) //Mask of the direction field, 0x00000003
#define _IOC_NRSHIFT 0 //The displacement of the ordinal field in the whole field, 0
#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) //The displacement of the magic field, 8
#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+ _IOC_TYPEBITS) //The displacement of the size field, 16
#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS) //The displacement of the direction field, 30
/*
* Direction bits.
*/
#define _IOC_NONE 0U //No data transfer
#define _IOC_WRITE 1U //Write data to the device, the driver must read data from user space
#define _IOC_READ 2U //Read data from the device, the driver must write data to the user space
#define _IOC(dir,type,nr,size) \\
(((dir) << _IOC_DIRSHIFT) |
\\
((type) << _IOC_TYPESHIFT) |
\\
((nr) << _IOC_NRSHIFT) |
\\
((size) << _IOC_SIZESHIFT))
/*
* used to create numbers
*/
//Construct a command number with no arguments
#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
//Construct from the driver Command number for reading data
#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
//for Driver write data command
#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
//for two-way Transfer
#define _IOWR(type,nr,size) _IOC(_IOC_READ|
_IOC_WRITE,(type),(nr),sizeof(size))
/*
*used to decode ioctl numbers..
*/
//Parse the data direction from the command parameters, ie write or read
#define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
//parse the magic number from the command parameters type
#define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
//from the command parameters Interpret the number in the number
#define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
//Resolve the user data size from the command parameters
#define _IOC_SIZE (nr) (((nr) & gt; & gt; _IOC_SIZESHIFT) & _IOC_SIZEMASK)
/* ... and for the drivers /sound files ... * /
#define IOC_IN (_IOC_WRITE & lt; & lt; _IOC_DIRSHIFT)
#define IOC_OUT (_IOC_READ & lt; & lt; _IOC_DIRSHIFT)
#define IOC_INOUT ((_IOC_WRITE |
_IOC_READ) & lt; & lt; _IOC_DIRSHIFT)
#define IOCSIZE_MASK (_IOC_SIZEMASK & lt; & lt; _IOC_SIZESHIFT)
#define IOCSIZE_SHIFT (_IOC_SIZESHIFT)
Program Example:
< #include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
int main(void ) {
..int stat;
/* use func 8 to determine if the default drive is removable */
..stat = ioctl(0, 8, 0, 0);
..if (!stat)
....printf("Drive %c is removable.\ ", getdisk() + 'A') ;
..else
....printf("Drive %c is not removable.\ ", getdisk() + 'A');
..return 0;
}
Do you know what a Linux system is? Some users dont know much about Linux. Linux is a free and free
“ A real programmer does not need an IDE. They all use a text editor with a plugin to write c
CentOS modify IP address First turn off the firewall: service iptables stop# ifconfig eth0 192.168.1
What is the boot process for Linux? How to complete the system startup through grub boot? These pro
How to use ReiserFS file system in Linux environment
Detailed TCP programming functions and steps
When using yum, another application is applying yum lock; wait for it to exit
Linux operating system sound card driver installation and configuration
Linux under the lack of boot space solution
Introduction to three commonly used network security tools under Linux system
Linux file copy, delete and move commands
Kdump and crash configuration methods and failure analysis methods
Linux input subsystem analysis
Problems with the Windows 8 keyboard using the on-screen keyboard in the system
Solve Windows login performance issues in Active Directory environment
How to cancel the index function created by win7 system
Windows 8 application skills big delivery
Two ways to make your command line run more efficiently (1)
You have to know the WindowsPE usage
What is the process of WmiPrvSE in Win7 system? Will WmiPrvSE.exe be a virus?
Several Win 7 mouse unknown tips
Win10 10074 ME browser crash and start menu bug how to solve
Win7 Internet to see the reason for the green screen video and its solution