Lesson 3 | Device files and other special files |
Objective | Describe the Special Properties of Device Files. |
Describe the Special Properties of Device Files
Access to hardware devices on a UNIX system is managed through special files.
These files have
- permissions,
- owners, and
- groups,
just as regular files and directories do, and this permission data determines access to the associated device.
Most device files are, by convention, located in a directory called /dev (or in subdirectories of /dev). Device files are marked in directory listings by
b
or
c
in the initial position:
crw------- 1 root system 10, 0 Oct 01 1997 __vg10
brw-rw---- 1 root system 10, 1 Aug 14 1996 hd6
Here the
b
and
c
denote, respectively, block devices and character devices. This distinction is not particularly significant for the administrator. Every device file also has a major number and a minor number.
The major number associates the device with a particular major
device[1],
and the minor number identifies the particular instance of that device. In the above example,
the major and minor numbers appear as 10, 0 and 10, 1 respectively.
Special Properties of device files in Unix
Device files in Unix and Unix-like operating systems are special types of files that provide a way for software and hardware to interact. These special files are used to represent and manage physical and virtual devices, making them accessible in the same way regular files are.
Here are some key properties of device files in Unix:
- Everything is a File: In accordance with Unix's "everything is a file" philosophy, devices are accessed and manipulated like regular files. You can read from a device file and write to it, much like a regular file.
- File Location: Device files typically reside in the /dev directory. This directory is populated at boot time with device files corresponding to the hardware detected by the system.
- File Types: Device files are classified into two categories: character (or raw) devices and block devices.
- Character Devices: These devices transfer data one character at a time and have no buffering mechanism. This means that data is processed immediately, making it suitable for devices like keyboards or mice, where immediate data transfer is essential.
- Block Devices: These devices transfer data in large fixed-size blocks. They have a buffering mechanism and support random access, meaning you can read or write data in non-sequential order. Block devices are commonly used for storage devices like hard drives, flash drives, and CD-ROM drives.
- File Naming: The names of device files often give clues about the device they represent. For example, 'sda' refers to the first SCSI hard disk, 'tty' represents a terminal, and 'lp' refers to a printer.
- Major and Minor Numbers: Every device file is associated with a pair of numbers: a major number and a minor number. The major number identifies the driver associated with the device. The minor number is used by the kernel to differentiate between devices that use the same driver, such as multiple hard drives.
- Permissions: Device files have the same permission settings as regular files. They can be set to read, write, or execute for the file owner, group, and others. This is critical for controlling access to hardware devices. For instance, limiting write access to certain devices can prevent inadvertent data loss.
- Inodes: Like regular files, each device file has an inode (index node) that stores its metadata (like permissions, ownership, major and minor numbers).
- Symbolic Links: In some cases, more user-friendly symbolic links are created to device files. For example, /dev/dvd might be a symbolic link to the actual DVD drive device file, providing a more intuitive way for users and applications to access the device.
Unix's device files, with their unique properties and functions, serve as an elegant and consistent mechanism for interacting with both physical and virtual devices, and provide a seamless interface for users and applications to interact with hardware.
How IP Addresses Apply to Network Interfaces
To connect to the network, a system must have at least one physical network interface.
Each network interface must have its own unique IP address. During Oracle Solaris installation, you must supply the IP address for the first interface that the installation program finds. Usually that interface has the name device-name0, for example eri0 or hme0. This interface is considered the primary network interface.
If you add a second network interface to a host, that interface also must have its own unique IP address. When you add the second network interface, the host then becomes multihomed. By contrast, when you add a second network interface to a host and enable IP forwarding, that host becomes a router. Each network interface has a device name, a device driver, and an associated device file in the /devices directory. The network interface might have a device name such as eri or smc0, which are device names for two commonly used Ethernet interfaces.
[1][1]device: A device is a piece of hardware used by the system, such as hard drives, CD-ROMs, and so on. Devices are treated as a special type of file.