0

I have to write a device driver code for temperature sensor using IOCTL, when I was going through a lot of sample codes, I found while surfing the net, I came across this difference in header file, I counldn't get an accurate answer for it, hence I'm posting it here, hoping that I may get a lead to work with my code.

muru
  • 69,900
  • 13
  • 192
  • 292
hari
  • 9
  • 1

1 Answers1

3

sys/ioctl.h is what you’d use when writing a program which relies on ioctl; it defines the ioctl function and ends up including linux/ioctl.h, which defines macros such as _IOR.

linux/ioctl.h shouldn’t be referenced directly in user code; however that’s what you’d use when writing a Linux driver.

Basically, if you see #include <sys/ioctl.h>, you’re looking at program code; if you see #include <linux/ioctl.h>, you’re looking at either kernel (device driver) code, or program code with over-enthusiastic #includes.

See also the Linux kernel documentation on writing ioctl interfaces.

(In this particular case, the user and kernel view of linux/ioctl.h are the same; ioctl.h is part of the UAPI in the Linux kernel.)

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164