Linux Kernel Architecture

(Jacob Rumans) #1

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 Description

1 /dev/mem Physical memory

2 /dev/kmem Virtualkerneladdressspace

3 /dev/null Bit bucket

4 /dev/port Access to I/O ports

5 /dev/zero Source for null characters

8 /dev/random Non-deterministic random generator

Selected by
major number

Selected by
minor number

def_chr_fops memory_fops

mem_fops
kmem_fops
null_fops
random_fops

Figure 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.

Free download pdf