From owner-freebsd-hackers@FreeBSD.ORG Tue Feb 7 19:03:47 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B162E106564A for ; Tue, 7 Feb 2012 19:03:47 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 889968FC13 for ; Tue, 7 Feb 2012 19:03:47 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [96.47.65.170]) by cyrus.watson.org (Postfix) with ESMTPSA id 4310A46B2A; Tue, 7 Feb 2012 14:03:47 -0500 (EST) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id A3CAFB962; Tue, 7 Feb 2012 14:03:46 -0500 (EST) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Tue, 7 Feb 2012 13:57:39 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p10; KDE/4.5.5; amd64; ; ) References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201202071357.39645.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 07 Feb 2012 14:03:46 -0500 (EST) Cc: PRATIK MOHANTY Subject: Re: ioctl, copy structure from user X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Feb 2012 19:03:47 -0000 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