Results 1 to 2 of 2
Thread: Ioctl magic number problem
Enjoy an ad free experience by logging in. Not a member yet? Register.
- Join Date
- Aug 2012
Ioctl magic number problem
I am using ioctl command in linux for just playing with transferring data from kernel to user and from user to kernel.
It works fine if I give
#define cmd0 _IO(42,0).
upto my knowledge 42 is magic number here.
but when I give different magic number it does not work.why so?
and if I am getting wrong then what exactly this magic number is? and for what purpose do we need to use it?
please help me out friends.
hoping for quick reply.
- Join Date
- Apr 2009
- I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
The kernel needs to know where to deliver the ioctl() call. The first argument is a file descriptor, so it will assume that the driver for that device is one part of the equation. The second argument is the request ID, and that determines which function (registered with the driver) is to get/set the data passed in the third argument. That definition is specifying the request number associated with the symbol cmd0. Look at the kernel header file include/asm-generic/ioctl.h. There you will find how _IO(type,nr) is defined - it is a compiler macro. IE, it turns 42,0 into a set of bits that uniquely identify the request so it knows what to do. Example:
include/linux/fs.h:#define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */ include/linux/fs.h:#define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!