Chapter 6: Device Drivers
memory-related device files. The function pointers are then refined even further depending on the
minor number selected. The end products do not necessarily use identical functions, as the examples of
null_fops(for/dev/null)andrandom_fops(for/dev/random) demonstrate.
Table 6-1: Minor Numbers for Major 1 (Memory Access).
Minor File Description1 /dev/mem Physical memory2 /dev/kmem Virtualkerneladdressspace3 /dev/null Bit bucket4 /dev/port Access to I/O ports5 /dev/zero Source for null characters8 /dev/random Non-deterministic random generatorSelected by
major numberSelected by
minor numberdef_chr_fops memory_fopsmem_fops
kmem_fops
null_fops
random_fopsFigure 6-8: File operations when memory devices are opened.drivers/char/mem.c
static struct file_operations null_fops = {
.llseek = null_lseek,
.read = read_null,
.write = write_null,
.splice_write = splice_write_null,
};drivers/char/random.c
struct file_operations random_fops = {
.read = random_read,
.write = random_write,
.poll = random_poll,
.ioctl = random_ioctl,
};The same approach is adopted for other device types. A specific set of file operations is first installed
on the basis of the major number. These operations can then be replaced by other operations selected
according to the minor number.