From owner-freebsd-hackers Sat Feb 1 08:34:17 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id IAA28900 for hackers-outgoing; Sat, 1 Feb 1997 08:34:17 -0800 (PST) Received: from spoon.beta.com (root@[199.165.180.33]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id IAA28889 for ; Sat, 1 Feb 1997 08:34:11 -0800 (PST) Received: from spoon.beta.com (mcgovern@localhost [127.0.0.1]) by spoon.beta.com (8.8.4/8.6.9) with ESMTP id LAA10659; Sat, 1 Feb 1997 11:34:03 -0500 (EST) Message-Id: <199702011634.LAA10659@spoon.beta.com> To: hackers@freebsd.org cc: msmith@atrad.adelaide.edu.au Subject: Device driver help... Date: Sat, 01 Feb 1997 11:34:02 -0500 From: "Brian J. McGovern" Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Ok. I'm underway writing my pseudo-device driver, as promised. Unfortuately, I think I hit my first snag early on in that the book I'm using for reference was slanted towards SCO. Here's what they recommend: #include #include #include #include #include #include static char message[] = "This is a test message\n"; fooinit() { printf("Test Data Character Device Driver\n"); } void fooread(dev_t dev) { while (u.u_count) { if (copyout(&message[u.u_offset % sizeof(message)], u.u_base, 1) == -1) { u.u_error = EFAULT; return; } u.u_base++; u.u_offset++; u.u_count--; } } At this point, I figured it'd be a good idea to actually try to compile it out of kernel, just to see how close I was to the mark. Lets just say I missed :) I started checking out some of the drivers, such as sio.c, and a few others for "how they did it". I ended up (to date) with something that looks like this: #define KERNEL #include #include #include #include #include #include #include #include #include #include #include #include #ifdef DEVFS #include #endif #include #include #include static char message[] = "This is a test message\n"; fooinit() { printf("Test Character Device Driver\n"); } static int fooread(dev,myuio, flag) dev_t dev; struct uio *myuio; int flag; { while(myuio->u_count) { if (copyout(&message[myuio->u_count % sizeof(message)], myuio->u_base, 1) == -1) { myuio->u_error = EFAULT; return; } myuio->u_base++; myuio->u_offset++; myuio->u_count--; } } Unfortunately, the uio structure doesn't seem to be the same as SCOs (hence, things like uio->u_base don't exist). Could someone please tell me if I'm even on the right path with struct uio, and if so, provide some minimal documentation as to the fields, and how to apply them in this circumstance? Thanks. -Brian PS - I realize this driver is pretty hideous, and a lot could be done to it. Remember, however, its 15 minutes of work :)