Date: Tue, 7 Feb 2012 13:57:39 -0500 From: John Baldwin <jhb@freebsd.org> To: freebsd-hackers@freebsd.org Cc: PRATIK MOHANTY <pmohanty.cdac@gmail.com> Subject: Re: ioctl, copy structure from user Message-ID: <201202071357.39645.jhb@freebsd.org> In-Reply-To: <CAD-7EriuvnNt5qayXKjWqgc7egDoubhmnDT_y0%2BRfRMS13skew@mail.gmail.com> References: <CAD-7EriuvnNt5qayXKjWqgc7egDoubhmnDT_y0%2BRfRMS13skew@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Monday, February 06, 2012 2:44:23 pm PRATIK MOHANTY wrote:
> Hello sir,
> I need some example for ioctl to copy structure from user space to kernel
> space
In BSD the kernel copies the immediate ioctl argument into and out of userland
for you. Thus, you can do something like this:
struct foo {
...
};
#define MY_IOCTL _IOWR('M', 1, struct foo)
And in your kernel code:
int
foo_ioctl(..., u_long cmd, caddr_t data)
{
struct foo *f;
switch (cmd) {
case MY_IOCTL:
f = (struct foo *)data;
/*
* 'f' is now a pointer to an in-kernel copy of
* the structure. Any changes made to it will
* be copied back out to userland after your
* routine returns.
*/
break;
}
}
--
John Baldwin
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202071357.39645.jhb>
