3 Devices in POSIX Systems are files in /dev directory. As with any files
4 in POSIX, they may be opened, closed, read from, written to, seeked,
7 Examples of device files:
9 * /dev/sda - A SCSI block device
10 * /dev/ttyS0 - A Serial terminal device
14 POSIX systems have some standard calls for I/O. Since devices are files,
15 these same system calls are used to work with devices. We are gonna work
16 with the following calls:
25 # Device types and numbers
27 Linux devices may be of different types, including character devices,
28 block devices or network devices. Both character and block devices have
29 identifying numbers, a major and a minor number.
31 # Character devices allocation
33 In Linux, major and minor numbers have to be requested or allocated. The
34 calls to do that for character devices are:
37 * int register\\_chrdev\\_region (dev\\_t first, unsigned int count, char
39 * int alloc\\_chrdev\\_region (dev\\_t *dev, unsigned int firstminor,
40 unsigned int count, char *name);
41 * void unregister\\_chrdev\\_region (dev\\_t dev, unsigned int count);
50 The virtual file system is the hub for almost all operations in a Linux-based
51 system. It allows IPC with pipes, access to devices, including storage through
52 regular files and organization with directories.
54 # Everything is a file
56 In Unix, there's a say: "everything is a file, if it's not a file, it's a
57 process". Well, most things are really files, and that's why the VFS is at the
58 center of the system, including for device drivers.
60 # Special files, procfs and others
62 When handling with special files (character and block device nodes), procfs
63 files and others, we'll use some common structures. These include the
64 *struct file\\_operations*, *struct file* and *struct inode*.
86 # Filesystem File: inode
88 The inode is a representation of the file as in its filesystem, including its
89 major/minor numbers and pointers to the corresponding device representation.