Subject: Re: device special files
To: None <>
From: Matthew Mondor <>
List: tech-kern
Date: 11/15/2005 18:46:35
On Wed, 16 Nov 2005 00:05:56 +0100
Petar Bogdanovic <> wrote:
> I don't understand the magic behind the device special files, /dev, 
> MAKEDEV, block/character/fifo and mknod. It's not about details - it's 
> more about the fact, that I am not able to imagine the whole thing.
> Can somebody help me with a hint, tutorial or something else? The 
> MAKEDEV-/mknod-manpage helped just a little bit..

This does seem a proper list;

Although both fifos and device special files can be created using mknod,
they are different in that fifos are especially treated via the vfs layer
to src/sys/kern/sys_pipe.c

As for the device special files, the important part is that the kernel
deals with major/minor device descriptors, and character/block device
interfaces...  These files allow inodes to be created which correspond
to actual major/minor numbers with the proper type of interface.
So these files merely serve as an interface to access a specific device
with a familiar ioctl/read/write/etc interface which is common.

For instance, consider /dev/random (i386):
cr--r--r--  1 root  wheel  46, 0 Oct  5  2004 /dev/random

Character device (c), major device 46, minor device 0.  Accessing this
file will in the kernel map the file i/o syscalls in this case to the
code found in src/sys/dev/rnd.c

(see the "struct cdevsw" which is the linking point to the functions)
As for the link of major device 46 to rnd, it can be found (on i386)

device-major    rnd             char 46                 rnd

I hope this helps a bit,

Note: Please only reply on the list, other mail is blocked by default.
Private messages from your address can be allowed by first asking.