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.

1
  • It would be helpful if you put your code at least main function. Commented Jun 1, 2024 at 0:03

1 Answer 1

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.)

3
  • 2
    +1 for "over-enthusiastic" Commented 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? Commented Jun 1, 2024 at 0:10
  • 1
    @CloudCho the question asks what the difference between the two ioctl.h files is, not how to use them. If you have questions about ioctl, please ask them separately. Commented Jun 1, 2024 at 8:04

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.