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 10-24-2011, 11:47 PM   #1
GNakul
Member
 
Registered: Oct 2011
Location: Bangalore,India
Posts: 59

Rep: Reputation: Disabled
ioctl()


Hi all,

I want to know how to pass parameters to ioctl(). Pls help.
 
Old 10-25-2011, 12:53 AM   #2
rulingminds
LQ Newbie
 
Registered: Sep 2011
Posts: 9

Rep: Reputation: Disabled
ioctl() prototype is like this:

int ioctl(int d, int request, ...);

The first argument is the file descriptor, second argument is the command and the third argument can be a char *.
The last argument is used to pass parameters to the ioctl and this parameter depends on the second argument 'request'.
Say for example I want to send a parameter to the ioctl for a test command IOCTL_SENDMESG, I can do like this:

struct msg {
int type;
int len;
char buf[100]
};

struct msg msg1;

Fill in the msg1 object properly and send it the ioctl like this:

ret = ioctl(fd, IOCTL_SENDMESG, (char *) &msg1);

In side the driver or where ever the kernel ioctl is, it should type cast it like this.

struct msg *msg1 = (struct msg *) arg;
 
Old 10-25-2011, 01:27 AM   #3
GNakul
Member
 
Registered: Oct 2011
Location: Bangalore,India
Posts: 59

Original Poster
Rep: Reputation: Disabled
@rulingminds: Nice one, thanks dude. Actually i am trying to send TEST_UNIT_READY to SCSI layer.
 
  


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 Help dragon_fly Programming 1 07-16-2009 02:34 AM
How to pass IOCTL arguments from usespace ioctl call devkpict Linux - Kernel 1 12-07-2007 06:45 PM
ioctl.h blackzone Programming 1 07-26-2004 03:30 AM
ioctl dummyagain Programming 2 10-06-2003 07:22 AM
ioctl unosoft Linux - Software 0 09-12-2003 06:58 PM

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

All times are GMT -5. The time now is 08:05 AM.

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