San
San

Reputation: 935

Linux IOCTL commands

Trying to implement IOCTL commands, and just encountered as below:

If _IO is for both read and write

than why should I consider _IOR and _IOW

any clue please ?

Upvotes: 0

Views: 12240

Answers (2)

Gautham Kantharaju
Gautham Kantharaju

Reputation: 1763

_IOR --- For reading from device to user space app, _IOW --- Write data passed from user space app to device(Hardware) and _IOWR --- For both read/write data from/to device. But _IO --- are basically used to send device configurable commands to intended device i.e. for example if you want to read/write to flash you need to send command first and then read/write data from/to flash. Since read/write command is constant/fixed as specified in the flash datasheet, so there is no need to explicitly send/pass command from user space app to driver ioctl, you can form a command packet as required inside _IO ioctl case and send it to flash. _IO --- Tells that you don't have to pass data(command) from user space app, you in the driver have use hard coded read/write command and send command to the intended device. _IOR or _IOW or _IOWR are used read/write volatile data passed form user space app to/from device (ex:flash). Hope this answer would clarify your doubt :-).

Upvotes: 2

Benjamin Leinweber
Benjamin Leinweber

Reputation: 2954

Actually _IO is for ioctls that don't take any parameters at all. For instance, say that you want to trigger a command that has been previously set up in the driver, you may not need to pass any data at all!

_IOWR is for ioctls that pass parameters in and then out. In my experience these are rare and can be confusing since one parameter is utilized for two very different purposes but it can be useful when you need it.

See the beginning of http://www.mjmwired.net/kernel/Documentation/ioctl-number.txt

There isn't anything in the kernel that enforces the direction, so it is mostly for documentation purposes.

Upvotes: 4

Related Questions