LinuxQuestions.org
Review your favorite Linux distribution.
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 09-23-2009, 01:10 PM   #1
ranthal
LQ Newbie
 
Registered: Jun 2009
Location: Carlsbad, CA
Posts: 24

Rep: Reputation: 15
ioctl numbers-kernel & user space mismatch


Hey all,

I'm working on a driver write now that makes use of some ioctl calls and I'm having some strange problems. In the kernel I have a header file for the driver that defines the ioctl commands similar to this:
#define DRIVER_IOCTL_MAGIC 0xFA
#define DRIVER_IOCTL_REG_PROC _IOW(DRIVER_IOCTL_MAGIC, 1, struct sigproc_info)
a few more commands...

sigproc_info is a pretty simple struct made up mostly of ints that I have already defined in the header file.

I go ahead and include this header file in the relevant user space applications and send the DRIVER_IOCTL_REG_PROC command as such:
const int fd = open ( "/dev/driver_file", O_RDWR );
...
struct sigproc_info info;
...
rc = ( fd, DRIVER_IOCTL_REG_PROC, &info);
...

So here's the problem-the value that the kernel assigns to the DRIVER_IOCTL_REG_PROC command differs from the value that the user space application uses. Further, it is called from a couple user space applications which all seem to agree on the value of DRIVER_IOCTL_REG_PROC. So in the actual driver implementation of ioctl handling the switch statement hits the default case due to the mismatch and I can't get it to recognize the command correctly.

Any ideas?
 
Old 09-23-2009, 04:35 PM   #2
ranthal
LQ Newbie
 
Registered: Jun 2009
Location: Carlsbad, CA
Posts: 24

Original Poster
Rep: Reputation: 15
Solved

Problem was in the struct I was passing. Guess it wasn't as simple and benign as I made it sound. Really stupid mistake just too involved with the code to notice it. Here's the original with the mistake, can you figure it out?
struct sigproc_info
{
#if defined(__KERNEL__)
int dirty;
#endif
int pid;
int signum;
int irq;
} __attribute__ ((__packed__));

...
...
...
The call to _IOW takes the last argument, struct sigproc_info, and calls sizeof on it then performs some bit-shifting based on this value. So the kernel-space version was 4 larger than the user-space version since it had an extra int, dirty
 
  


Reply

Tags
driver, ioctl



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
how to call socket prog code written in user space from kernel space???HELP kurt2 Programming 2 07-15-2009 09:56 PM
How to get data from a terminal driver from user space? Any ioctl for this? Sreeram B S Linux - Kernel 0 02-24-2007 12:51 AM
how to assign names to PCI devices, that ioctl() can use from user space? MarkGaleck Linux - Kernel 2 10-23-2006 03:55 PM
gcc & kernel mismatch jd20878 Programming 4 03-14-2004 10:41 AM

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

All times are GMT -5. The time now is 10:32 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