Chapter 12. Devfs pseudo file system

The main documentation for devfs can be found at: reference W5. The devfs name conventions for the SCSI subsystem are outlined in Section 3.3. Devfs is selected by the kernel build option CONFIG_DEVFS_FS and whether it is mounted at boot time (as /dev) or not is controlled by the kernel build option CONFIG_DEVFS_MOUNT. The latter option can be overridden by the kernel boot time options "devfs=mount" or "devfs=nomount", whichever is appropriate.

The devfs SCSI node names with their default permissions are:
disc        rw-------   whole disk including mbr
part1       rw-------   first partition {...p1}
...
part15      rw-------   15th partition {...p15}
cd          rw-rw-rw-   cd or dvd devices
mt          rw-rw-rw-   tape mode 0 with rewind {...m0}
mtl         rw-rw-rw-   tape mode 1 with rewind {...m1}
mtm         rw-rw-rw-   tape mode 2 with rewind {...m2}
mta         rw-rw-rw-   tape mode 3 with rewind {...m3}
mtn         rw-rw-rw-   tape mode 0 with no rewind {...m0n}
mtln        rw-rw-rw-   tape mode 1 with no rewind {...m1n}
mtmn        rw-rw-rw-   tape mode 2 with no rewind {...m2n}
mtan        rw-rw-rw-   tape mode 3 with no rewind {...m3n}
generic     rw-r-----

These node names are only present if the corresponding device (or sub-entities of the device (e.g. partitions)) and driver are present. For example if there is no sg driver present then there is no "generic" device name. The strings that appear above in braces are appended to the abridged "c0b0t0u0" notations outlined below as appropriate.

The devfs file names that are block or character special files will be called the primary device names in this description. The devfs daemon, called devfsd, introduces many symbolic links to those primary device names. This is done both for backward compatibility and convenience. These symbolic links will be called secondary device names.

The secondary device names are controlled by the devfsd configuration file usually found in /etc/devfsd.conf . Following is a list of secondary device names when the default devfsd.conf file is used:

Secondary name       slink to this primary device name
--------------------------------------------------------------
/dev/sda             /dev/scsi/host0/bus0/target2/lun0/disc
/dev/sda1            /dev/scsi/host0/bus0/target2/lun0/part1
/dev/sd/c0b0t2u0     /dev/scsi/host0/bus0/target2/lun0/disc
/dev/sd/c0b0t2u0p1   /dev/scsi/host0/bus0/target2/lun0/part1
/dev/sr0             /dev/scsi/host0/bus0/target4/lun0/cd
/dev/sr/c0b0t4u0     /dev/scsi/host0/bus0/target4/lun0/cd
/dev/st0             /dev/scsi/host1/bus0/target0/lun0/mt
/dev/nst0a           /dev/scsi/host1/bus0/target0/lun0/mtan
/dev/st/c1b0t0u0m0   /dev/scsi/host1/bus0/target0/lun0/mt
/dev/st/c1b0t0u0m3n  /dev/scsi/host1/bus0/target0/lun0/mtan
/dev/sg0             /dev/scsi/host0/bus0/target2/lun0/generic
/dev/sg1             /dev/scsi/host0/bus0/target4/lun0/generic
/dev/sg2             /dev/scsi/host1/bus0/target0/lun0/generic
/dev/sg/c0b0t2u0     /dev/scsi/host0/bus0/target2/lun0/generic
/dev/sg/c0b0t4u0     /dev/scsi/host0/bus0/target4/lun0/generic
/dev/sg/c1b0t0u0     /dev/scsi/host1/bus0/target0/lun0/generic

Note that the more common /dev/scd0 variant for SCSI cdroms is not supported. There are also /dev/discs, /dev/cdroms and /dev/tapes directories that contain symbolic links to all devices (i.e. not just SCSI devices) that fall into that categorization:

Secondary name       slink to this primary device
------------------------------------------------------------
/dev/discs/disc0     /dev/ide/host0/bus0/target0/lun0      *
/dev/discs/disc1     /dev/scsi/host0/bus0/target2/lun0     *
/dev/cdroms/cdrom0   /dev/ide/host0/bus1/target1/lun0/cd
/dev/cdroms/cdrom1   /dev/scsi/host0/bus0/target4/lun0/cd
/dev/tapes/tape0     /dev/scsi/host1/bus0/target0/lun0     *

Those entries marked with "*" are directories containing the primary devices. Note that IDE devices are listed before SCSI devices. These secondary device names mimic the same persistence rules as the primary device names. So when a SCSI device (?), or its lower level driver or its upper level driver are removed then so are the primary and secondary device names associated with it.

When devfs is mounted as /dev, the old "/dev/sda6" type can still be used in some contexts. This may be convenient if typing is required at the kernel boot time prompt. For example if a user wants to change the root partition on a "devfs" machine then any of the following examples may be used as a kernel boot time option:
   root=/dev/sda6
   root=/dev/scsi/host0/bus0/target0/lun0/part6
   root=/dev/sd/c0b0t0u0p6

There are many device scanning programs that expect to see the pre-devfs device names present and it will some time before they become devfs aware. Also some programs rely on a open of /dev/sg0 (for example) to load the sg driver (assuming it is a module and not already loaded). This can be arranged by an entry in /etc/devfsd.conf file of:
        LOOKUP          sg.*            MODLOAD
and the following in /etc/modules.devfs :
        probeall        /dev/sg         scsi-hosts sg
        alias           /dev/sg*        /dev/sg

The sg device permissions can be changed with this entry in the /etc/devfsd.conf file:
  REGISTER scsi/host.*/bus.*/target.*/lun.*/generic
                              PERMISSIONS 0.0 rw-rw-rw-
See "man devfsd" for more information.

An application can determine whether devfs is active by the presence or otherwise of the file /dev/.devfsd.

A feature of a /dev directory based on a persistent file system (e.g. ext2) is the ability to associate permissions with a device file name and keep them from one boot to the next. As noted above the default action of devfs is to assign device file name permissions anew each time a machine is booted. The PERMISSIONS action in the /etc/devfsd.conf can be used to assert permissions but this may be considered a little awkward. The devfs document (W5) describes a method for getting the best of both worlds. This technique relies on the recently added feature in lk 2.4 to mount the same file system at multiple points.