1
votes

I read the instruction for choosing the ioctl commands (from the O’Reilly linux device driver):

The ioctl command numbers should be unique across the system in order to prevent 
errors caused by issuing the right command to the wrong device.

One of the arguments of the IOCTL function (from user space) is the file descriptor. So if I call to a specific device, why the ioctl command number should be unique across the system?

1

1 Answers

3
votes

IOCTL CMD is not necessary to be unique across the system. It should be unique for the particular device node. But the common practice is to maintain the unique CMD across system is to avoid errors caused by issuing the right command to the wrong device.

If you pass the specific command (lets say Invalid cmd for device-1) to the wrong device-2 which is capable of processing that ioctl CMD will leads to success, you will get some invalid data instead of error. To avoid this scenario we use unique CMD across system.