Date: Wed, 03 Sep 1997 22:08:11 -0700 (PDT) From: Simon Shapiro <Shimon@i-Connect.Net> To: Mike Smith <mike@smith.net.au> Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: IOCTL Commands - Where is my mistake? - Summary Message-ID: <XFMail.970903220811.Shimon@i-Connect.Net> In-Reply-To: <199709040247.MAA00870@word.smith.net.au>
next in thread | previous in thread | raw e-mail | index | archive | help
OK Folks, Those of you who followed this thread with a smirk on your face, here is what I learned; * Define the ioctl command as follows: typedef struct foo {int bar} foo_t; -- If you want to GIVE the kernl data: #define MY_COMMANDS 'M' #define SILLY_COMMAND 1 #define SILLY_IOCTL _IOW(MY_COMMANDS, SILLY_COMMAND, foo_t) -- If you want to GET data out of the kernel, replace IOW with _IOR. -- If you want to send, and then receive, use _IOWR instead. It is NOT very smart to use _IOWR in all cases as every system call will copy in when started, and copy out when done. * In your user code, pass the address of (a pointer to) your object, as in: int fd, result; foo_t foo; fd = open(..... result = ioctl(fd, SILLY_COMMAND, &foo); * In the kernel, in the ioctl entry point (service routine, whatever): foo_t *foop; -- Now, the kernel's foop and the application's foo are the same. If you just need to do some work on the structure passed by the user, just do the above and refer to foo->bar. Once the system call is complete, the user's foo.bar will automagically be updated. If you just want to pass some data back and forth, you can use memcpy to move the data back and forth. remember, the memory looks to either side as local, temporary memory (dies when you return). If you want to save the memcpy, then do NOT use the _IO{W,R,WR} macros, They force an implicit copy{in,out} and then your code will do funny things. This wisdom is based on data graciously provided by the honorable Mrs. Smith and Eischen. This summary is based on code written and compiled by myself on 3.0-current as of today. --- Sincerely Yours, (Sent on 03-Sep-97, 21:46:22 by XF-Mail) Simon Shapiro Atlas Telecom Senior Architect 14355 SW Allen Blvd., Suite 130 Beaverton OR 97005 Shimon@i-Connect.Net Voice: 503.643.5559, Emergency: 503.799.2313
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.970903220811.Shimon>