From owner-freebsd-hackers Thu Sep 4 01:28:48 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id BAA15320 for hackers-outgoing; Thu, 4 Sep 1997 01:28:48 -0700 (PDT) Received: from sendero-ppp.i-connect.net (sendero-ppp.i-Connect.Net [206.190.143.100]) by hub.freebsd.org (8.8.7/8.8.7) with SMTP id BAA15315 for ; Thu, 4 Sep 1997 01:28:46 -0700 (PDT) Received: (qmail 20247 invoked by uid 1000); 4 Sep 1997 08:29:00 -0000 Message-ID: X-Mailer: XFMail 1.2-alpha [p0] on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit MIME-Version: 1.0 In-Reply-To: <199709040519.PAA09446@ogre.dtir.qld.gov.au> Date: Thu, 04 Sep 1997 01:29:00 -0700 (PDT) Organization: Atlas Telecom From: Simon Shapiro To: Stephen McKay Subject: Re: IOCTL Commands - Where is my mistake? Cc: freebsd-hackers@freebsd.org, Mike Smith Sender: owner-freebsd-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Hi Stephen McKay; On 04-Sep-97 you wrote: > >From this, I expect that Simon wants to use his ioctl like: > > dpt_perf_t metrics; > > if ( (result = ioctl(fd, DPT_IOCTL_INTERNAL_METRICS, &metrics)) != 0 > ) { > ... > } > > Define his ioctl like: > > #define DPT_IOCTL_INTERNAL_METRICS _IOR('D', 1, dpt_perf_t) > > And put this in his driver: > > int > dpt_ioctl(dev_t dev, int cmd, caddr_t cmdarg, int flags, struct proc > *p) > > ... > > switch (cmd) { > case DPT_IOCTL_INTERNAL_METRICS: > *(dpt_perf_t *)cmdarg = dpt->performance; > break; This is essentially how it is now. > The reason that: > > #define DPT_IOCTL_INTERNAL_METRICS IOC_INOUT | 1 > > works with his current driver code is sheer luck, as Mike says. The > size > is encoded as 0, and that falls through some odd code in ioctl() and > hands > you a cmdarg that points to the pointer that was passed in from user > mode. > A zero size should be an error in my books. In SystemV, it would not have been luck, it would have been the way it should be. One could argue that BSD's was of encoding three separate arguments into one is not exactly a mark of engineering ellegance. Unix code dating back to the dark ages of PDP-11 worked flawlessly that way. I have a sneaking suspicion that throwing out all these encodings and just passing a streight, plain argument actually works, by design. David? --- Sincerely Yours, (Sent on 04-Sep-97, 01:11:04 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