From owner-freebsd-hackers Sun Apr 21 22:43:12 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id WAA11974 for hackers-outgoing; Sun, 21 Apr 1996 22:43:12 -0700 (PDT) Received: from gateway.zeus.leitch.com (gateway.zeus.leitch.com [205.210.38.6]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id WAA11965 for ; Sun, 21 Apr 1996 22:42:52 -0700 (PDT) Received: from tap.zeus.leitch.com (tap.zeus.leitch.com [204.187.60.10]) by gateway.zeus.leitch.com (8.6.12/8.6.9) with ESMTP id BAA16333; Mon, 22 Apr 1996 01:54:28 -0400 Received: (from dchapes@localhost) by tap.zeus.leitch.com (8.6.12/8.6.6) id BAA01869; Mon, 22 Apr 1996 01:43:03 -0400 From: Dave Chapeskie Message-Id: <199604220543.BAA01869@tap.zeus.leitch.com> Subject: Device Driver ioctl() help To: jfrancis@frii.com Date: Mon, 22 Apr 1996 01:43:03 -0400 (EDT) Cc: hackers@FreeBSD.ORG In-Reply-To: <199604220432.WAA06308@deimos.frii.com> X-Mailer: ELM [version 2.4ME+ PL14 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk In message <199604220432.WAA06308@deimos.frii.com> jfrancis@frii.com writes: >#define JOY_SETTIMEOUT _IOW('J', 1, int) /* set timeout */ [...] > Ok, it looks like the 'J' has something to do with a "group", >but what kind of group? How is this value chosen and what does it do? Get a good book on writing device drivers. Typically you just use group 0 unless you know what you're doing. _IO is used when no data is needed; _IOR when you need data returned from the driver; _IOW when you want data passed into the driver; and _IOWR to pass the data both ways. > In my user-level code, I can call `ioctl(fd,STUFF,0x69)'. In Ack!! RTFM, ioctl's third argument is a pointer. ie: header: #define MYDEV_CMD1 _IOW(0,1,int) user code: int arg = 42; ioctl(fd,MYDEV_CMD1,&arg) driver code: int mydev_ioctl(dev_t dev, int cmd, caddr_t data, int flags, struct proc *p) { switch(cmd) { case MYDEV_CMD1: if( *(int*)data == 42 ) .... >Obviously I'm missing something, but none >of the kernel books I have tell me what, and I can't seem to sort it >out. I think you need a better book. I can't recommend one at the moment since I'm not at work where my bookshelf is. -- Dave Chapeskie Leitch Technology International Inc. Email: dchapes@zeus.leitch.com