10. DEVICE DRIVER


This problem consists of a device driver compiled as module (thus installable in the kernel and removable). I advis eyou to get and read the book by Alessandro Rubini Linux Kernel Drivers O'Reilly, 1998. Even if it is rather old and has examples based on the 2.0 kernels, the basic ideas are unchanged and it has an update chapter for the changes with 2.2 kernels.

The driver name is "foo". It implements a variable number of in-memory FIFO (the book said four but i thought that this is just the same), by default two. It is a character driver, because i/o is not buffered.

The driver consists of

The driver functions are

Two test programns are provided (compile with, e.g., gcc -o test_w test_w.c):

  1. test_r.c: Usage test_r [-n bytes -b] device, where -n specifies the number of bytes to read, and -b specifies a blocking read.
  2. test_w.c: Usage test_w [-n bytes -t -b] device, where -n and -b are as above, and -t specifies to truncate (flush) the device buffer.

Makefile
foo.h
foo.c
test_r.c
test_w.c

Tested on kernel 2.2 and 2.4.

Next   Prev   Up


marco_corvi@geocities.com