Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 01 Feb 1997 11:34:02 -0500
From:      "Brian J. McGovern" <mcgovern@spoon.beta.com>
To:        hackers@freebsd.org
Cc:        msmith@atrad.adelaide.edu.au
Subject:   Device driver help...
Message-ID:  <199702011634.LAA10659@spoon.beta.com>

next in thread | raw e-mail | index | archive | help


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 <sys/types.h>
#include <sys/param.h>
#include <sys/dir.h>
#include <sys/signal.h>
#include <sys/user.h>
#include <sys/errno.h>

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 <sys/param.h>
#include <sys/systm.h>
#include <sys/reboot.h>
#include <sys/ioctl.h>
#include <sys/tty.h>
#include <sys/proc.h>
#include <sys/conf.h>
#include <sys/file.h>
#include <sys/uio.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/syslog.h>
#ifdef DEVFS
#include <sys/devfsext.h>
#endif
#include <machine/clock.h>
#include <i386/isa/isa.h>
#include <i386/isa/isa_device.h>

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 :)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199702011634.LAA10659>