Discussion:
_IOWR ioctl
Danilo Reinhardt
2004-07-27 09:32:08 UTC
Permalink
Hi,

i want to use an read and write ioctl. My problem is that i dont know
what i have to do to write something back from kernel to the userland
app that has called ioctl()?

To exchange data i've a struct with one parameter used as input for the
kernel and another as output to the userspace.

struct st_cmd_getBridgeInfo {
__u32 bridge; // param for kernel
char info[4092]; // result to userspace
};

#define TIS_IOC_GETBRIDGEINFO _IOWR(0x88, 1, struct
st_cmd_getBridgeInfo)

I guessed that i have to do it this way, but if i write something to the
info array in kernel ive got nothing at userspace. The input to kernel
works very well. Do i have to use copy_to_user or something?

Any suggestions?

Bye Dan


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
Dhiman, Gaurav
2004-07-27 09:52:34 UTC
Permalink
It is always a better idea to use copy_to_user() function for writing
something back to user space buffer. As mentioned in Rubini's books, it
take cares of all the issues related to coping across the kernel and
user space.

If you are doing direct copying to the user buffer without any kernel
function used for this purpose, theoretically there should not be any
problem except that you can get a page fault, but in case if you are not
getting any page fault and the control is returning to user space
successfully, then there should be no problem in copying directly, but
again saying it is not a preferred way.

Use copy_to_user() for smooth execution.

Regards,
Gaurav.


-----Original Message-----
From: kernelnewbies-***@nl.linux.org
[mailto:kernelnewbies-***@nl.linux.org] On Behalf Of Danilo Reinhardt
Sent: Tuesday, July 27, 2004 3:02 PM
To: Kernel Newbies
Subject: _IOWR ioctl

Hi,

i want to use an read and write ioctl. My problem is that i dont know
what i have to do to write something back from kernel to the userland
app that has called ioctl()?

To exchange data i've a struct with one parameter used as input for the
kernel and another as output to the userspace.

struct st_cmd_getBridgeInfo {
__u32 bridge; // param for kernel
char info[4092]; // result to userspace
};

#define TIS_IOC_GETBRIDGEINFO _IOWR(0x88, 1, struct
st_cmd_getBridgeInfo)

I guessed that i have to do it this way, but if i write something to the
info array in kernel ive got nothing at userspace. The input to kernel
works very well. Do i have to use copy_to_user or something?

Any suggestions?

Bye Dan


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
Danilo Reinhardt
2004-07-27 13:35:52 UTC
Permalink
Does anyone has an working example of using _IOWR()?
Post by Dhiman, Gaurav
It is always a better idea to use copy_to_user() function for writing
something back to user space buffer. As mentioned in Rubini's books, it
take cares of all the issues related to coping across the kernel and
user space.
If you are doing direct copying to the user buffer without any kernel
function used for this purpose, theoretically there should not be any
problem except that you can get a page fault, but in case if you are not
getting any page fault and the control is returning to user space
successfully, then there should be no problem in copying directly, but
again saying it is not a preferred way.
Use copy_to_user() for smooth execution.
Regards,
Gaurav.
-----Original Message-----
Sent: Tuesday, July 27, 2004 3:02 PM
To: Kernel Newbies
Subject: _IOWR ioctl
Hi,
i want to use an read and write ioctl. My problem is that i dont know
what i have to do to write something back from kernel to the userland
app that has called ioctl()?
To exchange data i've a struct with one parameter used as input for the
kernel and another as output to the userspace.
struct st_cmd_getBridgeInfo {
__u32 bridge; // param for kernel
char info[4092]; // result to userspace
};
#define TIS_IOC_GETBRIDGEINFO _IOWR(0x88, 1, struct
st_cmd_getBridgeInfo)
I guessed that i have to do it this way, but if i write something to the
info array in kernel ive got nothing at userspace. The input to kernel
works very well. Do i have to use copy_to_user or something?
Any suggestions?
Bye Dan
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
J Kang
2004-07-27 13:36:48 UTC
Permalink
hi Danilo,
You'd have to use copy_to_user!
Rgds
J Kang
Post by Dhiman, Gaurav
Subject: _IOWR ioctl
Date: Tue, 27 Jul 2004 11:32:08 +0200
Hi,
i want to use an read and write ioctl. My problem is that i dont know
what i have to do to write something back from kernel to the userland
app that has called ioctl()?
To exchange data i've a struct with one parameter used as input for the
kernel and another as output to the userspace.
struct st_cmd_getBridgeInfo {
__u32 bridge; // param for kernel
char info[4092]; // result to userspace
};
#define TIS_IOC_GETBRIDGEINFO _IOWR(0x88, 1, struct
st_cmd_getBridgeInfo)
I guessed that i have to do it this way, but if i write something to the
info array in kernel ive got nothing at userspace. The input to kernel
works very well. Do i have to use copy_to_user or something?
Any suggestions?
Bye Dan
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfee®
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
Dhiman, Gaurav
2004-07-27 15:52:47 UTC
Permalink
See the following links:
http://lxr.linux.no/source/include/linux/ppdev.h?v=2.4.21#L87
http://lxr.linux.no/source/drivers/char/ppdev.c?v=2.4.21#L442

In first link you will see the use of _IOR macro to define the ioctl
command and in second link you can see how that command is handled in
ioclt driver function.

Similar thing can be done for _IOW, _IOWR etc.

Regards,
Gaurav



-----Original Message-----
From: kernelnewbies-***@nl.linux.org
[mailto:kernelnewbies-***@nl.linux.org] On Behalf Of Danilo Reinhardt
Sent: Tuesday, July 27, 2004 7:06 PM
To: Kernel Newbies
Subject: RE: _IOWR ioctl

Does anyone has an working example of using _IOWR()?
Post by Dhiman, Gaurav
It is always a better idea to use copy_to_user() function for writing
something back to user space buffer. As mentioned in Rubini's books,
it
Post by Dhiman, Gaurav
take cares of all the issues related to coping across the kernel and
user space.
If you are doing direct copying to the user buffer without any kernel
function used for this purpose, theoretically there should not be any
problem except that you can get a page fault, but in case if you are
not
Post by Dhiman, Gaurav
getting any page fault and the control is returning to user space
successfully, then there should be no problem in copying directly, but
again saying it is not a preferred way.
Use copy_to_user() for smooth execution.
Regards,
Gaurav.
-----Original Message-----
Reinhardt
Post by Dhiman, Gaurav
Sent: Tuesday, July 27, 2004 3:02 PM
To: Kernel Newbies
Subject: _IOWR ioctl
Hi,
i want to use an read and write ioctl. My problem is that i dont know
what i have to do to write something back from kernel to the userland
app that has called ioctl()?
To exchange data i've a struct with one parameter used as input for
the
Post by Dhiman, Gaurav
kernel and another as output to the userspace.
struct st_cmd_getBridgeInfo {
__u32 bridge; // param for kernel
char info[4092]; // result to userspace
};
#define TIS_IOC_GETBRIDGEINFO _IOWR(0x88, 1, struct
st_cmd_getBridgeInfo)
I guessed that i have to do it this way, but if i write something to
the
Post by Dhiman, Gaurav
info array in kernel ive got nothing at userspace. The input to kernel
works very well. Do i have to use copy_to_user or something?
Any suggestions?
Bye Dan
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/

Loading...