FreeBSD 101 : The "/dev" directory and the DEVFS filesystem

Device Naming:

The /dev directory holds all the static device nodes.
Device nodes represent the hardware connected to the system.
Programs access the hardware through different device nodes.

When we remove a device from the system the device node stays in the /dev directory even if the hardware that corresponds to it is not there anymore.

The MAKEDEV script(Manual device management):

The script /dev/MAKEDEV manages the creation of most of the device nodes in /dev when connecting a new hardware to the system.
The device nodes in some cases have to be created manually.

When adding a device through the script we will need to add the exact reference numbers (called minor and major numbers) the kernel uses to represent the device and add these references to the script.

Using this manual process when creating device nodes in the /dev directory gives us more freedom in terms of the names we could give to devices, access permissions,...

The DEVFS filesystem(Automatic device discovery):

DEVFS filesystem is mounted on /dev directory at boot time. when the system discovers a new device, its name is added automatically to the /dev filesystem.

When the device is removed from the system, its corresponding name gets removed automatically from /dev.

The /etc/defaults/devfs.rules and /dev/devfs.rules files: 

DEVFS provide a scheme through which we can tune the automatic process of device node creation through the configuration files /etc/defaults/devfs.rules and /dev/devfs.rules

Rules we add in the /dev/devfs.rules override the ones that exist in /etc/defaults/devfs.rules.
In these file we can set among other things the devices to be readable or writable, we can also set the users or groups that have these rights.

Format of the file /dev/devfs.rules:


Adds a path to the device nodes /dev/stdin, /dev/stdout and /dev/stderr and un-hides them.


Leave as a comment: