LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 08-01-2011, 08:31 PM   #1
AustinMarton
Member
 
Registered: May 2007
Location: New Zealand
Distribution: Ubuntu
Posts: 88

Rep: Reputation: 16
Question Where to put the include file which defines ioctl numbers?


Hello,

I have come across this a few times and wonder if I am doing things correctly. Say I write a new char driver (drivers/char/mychar.c) which defines some ioctls in it's header file:
Code:
#define MYCHAR_IOC_MAGIC  0xE4 /* magic number */
#define MYCHAR_IOC_MODE_GET	_IOR(MYCHAR_IOC_MAGIC, 0, int)
#define MYCHAR_IOC_MODE_SET	_IOW(MYCHAR_IOC_MAGIC, 1, int)
#define MYCHAR_IOC_MAXNR 2
Now I want to use these definitions in my user space application, so I place the header file at linux/include/linux/mychar.h and include it (because linux/include is already added as an include dir to my user space applications make file).

The problem is, what if I have some structures or definitions in the .h file that won't compile in user space? And what about the linux/include directory getting flooded with unorganised driver header files?

My other options I guess would be to duplicate the definitions in a user space header file, or perhaps have two header files for the driver (one that only contains the ioctls for user space).

Any opinions appreciated.

Regards,
Austin.

Last edited by AustinMarton; 08-01-2011 at 08:33 PM.
 
Old 08-03-2011, 03:00 PM   #2
bastl
Member
 
Registered: Sep 2003
Location: Germany/BW
Distribution: My own
Posts: 237

Rep: Reputation: 22
Your char device is your interface between userspace appls. and module/hardware.
Your haeder file describes your interface standards (IOCTLs) for both the user space appl. and your module !
So the haeder file have to be the same included in any appl./module wants to use this interface and must only include interface definitions.

I can not folow, why it should not be possible to compile this haeder file in user space ? (for help you should post some code)
In haeders there is nothing that makes any byte of programm code so there is no execution limitation and so no compilation limitation.

The right place for your haeder file should be "/usr/include/linux/yourhaeder.h" or if you can specify a category (maybe usb) of your device "/usr/include/linux/usb/yourhaeder.h"
You should then submit your driver as a patch:
http://linuxtv.org/wiki/index.php/De...submit_patches

So you can #include <linux/usb/yourhaeder.h>

Else you can place it to "/usr/include/ modulename /yourhaeder.h" if it is only you using this module.

So you can #include < modulename /yourhaeder.h>
 
Old 08-04-2011, 04:30 PM   #3
AustinMarton
Member
 
Registered: May 2007
Location: New Zealand
Distribution: Ubuntu
Posts: 88

Original Poster
Rep: Reputation: 16
Cheers for your response. That convention makes sense. The reason my header file wasn't compiling in user space was that I had defined some structures that used kernel data types, but I have just moved them into the driver itself.

Thanks,
Austin.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ioctl() Errno Numbers halturata Linux - Newbie 5 08-06-2013 04:53 PM
[SOLVED] find the total of numbers that are higher than x in a text file with numbers (using awk??) Mike_V Programming 12 11-24-2010 09:51 AM
[SOLVED] ioctl numbers-kernel & user space mismatch ranthal Linux - Kernel 1 09-23-2009 04:35 PM
where to put path to include file bonosa Linux - Newbie 1 05-25-2004 08:27 AM
File that defines root command prompt? WeNdeL Linux - Newbie 6 11-20-2002 12:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 02:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration