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.
1 Answer
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.)
- 2+1 for "over-enthusiastic"Archemar– Archemar2022-05-03 07:32:45 +00:00Commented May 3, 2022 at 7:32
- Would you share a snippet using "ioctl.h"? Your suggestion be abstract...If you don't have, is the user "rigor" code at linuxquestions.org/questions/programming-9/… good example?Cloud Cho– Cloud Cho2024-06-01 00:10:26 +00:00Commented Jun 1, 2024 at 0:10
- 1@CloudCho the question asks what the difference between the two
ioctl.hfiles is, not how to use them. If you have questions aboutioctl, please ask them separately.Stephen Kitt– Stephen Kitt2024-06-01 08:04:12 +00:00Commented Jun 1, 2024 at 8:04