2

Below is the prototype of an ioctl call

long ioctl(struct file *f, unsigned int cmd, unsigned long arg);

Why third argument of an ioctl is unsigned long by default? Some times we pass a pointer to it. But it is using unsigned long.

Chinna
  • 3,930
  • 4
  • 25
  • 55
  • 1
    This page: http://man7.org/linux/man-pages/man2/ioctl.2.html gives a different prototype and says the third argument used to be a pointer. Where are you getting your prototype from exactly? – John Zwinck Nov 11 '13 at 11:41
  • 3
    The [official POSIX reference](http://pubs.opengroup.org/onlinepubs/9699919799/functions/ioctl.html) shows it with ellipsis. On the other hand, POSIX states this call is only for STREAMS devices. – Some programmer dude Nov 11 '13 at 11:42

1 Answers1

3

In kernel unsigned long is often used as a substitution for pointers, for pointers always have this size on every architecture. Ioctls may take an integer as an argument as well, so this makes sense here. This must be defined for each ioctl.

Please mind, that ioctls are deprecated and unlocked_ioctls must be used in current kernel versions: http://lwn.net/Articles/119652/

Stephan Roslen
  • 331
  • 1
  • 5