Physical Devices  «Prev  Next»
Lesson 2Device special files
ObjectiveDescribe how devices are represented on a UNIX system.

Device Special Files

Physical devices attached to the UNIX system are represented by entries in the filesystem called device special files. By convention, special files corresponding to physical devices are located in the /dev directory, although on some systems, such as Solaris, the entries in this directory are symbolic links to other locations. Although every device is accessed through a special file, there are probably many special files that do not correspond to a physical device. These are created when the operating system is installed as potential locations to attach new physical devices. Although special files are "special," the usual rules of ownership and access permissions apply. The permissions set on the special file control access to the underlying physical devices.
Device files are categorized as block or character and have associated major and minor numbers. The major numbers typically group the devices into subsystems (IDE devices, SCSI devices, and so on), and the minor numbers identify the individual devices within the subsystem.

Creating Special Files

When the system is installed, it creates a large collection of device special files, so that usually when a new device (such as a new disk) is attached to the system, a special file is already available for it. Then, when the system boots, it will automatically associate one of these special files with the new piece of hardware. For these reasons, it is rarely necessary to make a new special file "from scratch". If you add hardware of a completely new type, you may need to add a new device special file for it. The command mknod creates a new device file with specified major and minor numbers. However, the installation software for the new hardware should run this command to create the new special file.

Examining /dev directory on Linux

After the simulation has finished loading, click the Start Simulation button to start examining the /dev directory.
Dev Directory 1
1) Dev Directory 1
Dev Directory 2
2) Dev Directory 2
Dev Directory 3
3) Dev Directory 3
Dev Directory 4
4) Dev Directory 4
Dev Directory 5
5) Dev Directory 5
Dev Directory 6
6) Dev Directory 6
In Linux, the "/dev" directory is a special directory that contains device files. These device files are used to interact with various hardware and software devices on the system. Here are some characteristics of the "/dev" directory in Linux:
  1. Device files: The "/dev" directory contains device files for various hardware and software devices on the system. These files are used to interact with these devices using system calls.
  2. Dynamically created: The device files in the "/dev" directory are created dynamically when the corresponding device is detected by the system. This means that when a new device is added to the system, a new device file is automatically created in the "/dev" directory.
  3. Non-persistent: The device files in the "/dev" directory are non-persistent, meaning that they are not stored on disk and are recreated every time the system boots.
  4. Virtual file system: The "/dev" directory is part of the virtual file system in Linux, which means that it does not correspond to a physical directory on disk.
  5. Root directory: The "/dev" directory is located in the root directory ("/") of the file system.
  6. Permissions: The device files in the "/dev" directory have special permissions that allow only privileged users to access them. This is because accessing these files can potentially allow a user to interact with hardware devices and cause damage to the system.

The "/dev" directory is an essential part of the Linux file system, providing a way to interact with hardware and software devices on the system.
  1. You are now in your /home/user1 directory. Using |||(S7)ls -l|||(S0), list the files in the /dev directory.
  2. List files
  3. ls -l /dev
  4. The command you have entered is incorrect. Please check the instructions and try again.
  1. Notice the extensive list of files for this directory. For the purposes of this simulation, we're only showing you a few lines. Each file is potentially associated with a specific physical device. Type |||(S1)ls -l /dev | grep hdd|||(S0) to view the files associated with the hard drive.
  2. View files,
  3. ls -l /dev | grep hdd
  4. The command you have entered is incorrect. Please check the instructions and try again.
  1. Issue a command that views all the files associated with the point-to-point dialup connections. |||(S5)Hint: Look for the string ipp|||(S0).
  2. Point-to-point dialup,
  3. ls -l /dev | grep ipp
  4. Type ls -l /dev | grep ipp to view all files associated with the point-to-point dialup connections.
  1. Obviously, many other files exist, each associated with its own physical device. Retrieve a list of block device files in /dev by typing |||(S1)ls -l /dev | grep brw-|||(S0).
  2. Retrieve list
  3. ls -l /dev | grep brw-
  4. The command you have entered is incorrect. Please check the instructions and try again.
  1. The list output shows the files that have the bit set, denoting that they are block device files. Note the major device numbers listed in the block device files. To learn more about character device files, type
    ls -l /dev | grep crw- 
    
  2. List characteristics
  3. ls -l /dev | grep crw-
  4. The command you have entered is incorrect. Please check the instructions and try again.
  5. You have just used |||(S7)grep|||(S0) (and a pipe) to view files that have the |||(S7)c|||(S0) bit associated with them. This bit denotes that they are character device files. Note the major and minor numbers in the character device files. This is the end of the simulation. Click the Exit button.
Let us take a closer look at device files on a Linux machine. Click the Linux button to work through a simulation examining the /dev directory.

Examining the /dev directory on Linux (Simulation transcript)

Here are the steps you took to examine the /dev directory:
  1. You are now in your /home/user1 directory. Using ls -l, list the files in the /dev directory.
  2. Notice the extensive list of files for this directory. Each file is potentially associated with a specific physical device. Type ls -l /dev | grep hdd to view the files associated with the hard drive.
  3. Issue a command that views all the files associated with the point-to-point dial-up connections. Hint: Look for the string ipp. Solution: ls -l /dev | grep ipp
  4. Obviously, many other files exist, each associated with its own physical device. Retrieve a list of block device files in /dev by typing ls -l /dev | grep brw-.
  5. The list output shows the files that have the b bit set, denoting that they are block device files. Note the major device numbers listed in the block device files. To learn more about character device files, type ls -l /dev | grep crw-.
  6. You have just used grep (and a pipe) to view files that have the c bit associated with them. This bit denotes that they are character device files. Note the major and minor numbers in the character device files.

symbolic link: A symbolic link is an alias for a file.