Table of Contents Previous Chapter Devices and Drivers.
- Devices are presented as special files in /dev
- Devices are either block or character special files
- Any peripheral is seen by Unix as a device
- Even memory is a device (/dev/kmem and /dev/mem)
- Devices are created with mknod just as directories are created with mkdir
- Devices have major and minor number
- The major number represents the device driver
- The minor number represents the instance of a device of the type specified by the major device number
- Devices are created by /dev/MAKEDEV script (SunOS 5.x creates devices at boot time; use boot -r)
Here is an example of the contents of the /dev directory.
The Small Computer System Interface (pronounced "scuzzy") specification was developed to allow up to 7 devices to be intelligently controlled by each interface rather than the computer. SCSI adapters are common on most workstations today as part of the motherboard.
- Uses 50 pin "Centronics" style connectors
- Devices daisy-chained to form a "bus" topology
- Only one SCSI device should be terminated - the final one (the bus is also terminated internally)
- SCSI controller occupies address 7 - all other devices can use addresses 0 through 6 (addresses do not have to be contiguous, e.g. can use 1, 2 and 4 for devices)
- Addresses must be unique
Table 3: Disk Special File Names
--------------------------------------------------------------------------------
BSD System V.4 SunOS 4.1.3 IRIX
--------------------------------------------------------------------------------
File Name /dev/rdisk0g /dev/rdsk/c1d0s2 /dev/rsd0g /dev/rdsk/dks0d0s2
Raw access mode /dev/rdisk0g /dev/rdsk/c1d0s2 /dev/rsd0g /dev/rdsk/dks0d0s2
Device Type /dev/rdisk0g /dev/rdsk/c1d0s2 /dev/rsd0g /dev/rdsk/dks0d0s2
Drive # /dev/rdisk0g /dev/rdsk/c1d0s2 /dev/rsd0g /dev/rdsk/dks0d0s2
Disk Partition /dev/rdisk0g /dev/rdsk/c1d0s2 /dev/rsd0g /dev/rdsk/dks0d0s2
Controller # /dev/rdsk/c1d0s2 /dev/rdsk/dks0d0s2
--------------------------------------------------------------------------------
OSF/1 (Digital Unix) and Digital Ultrix look similar to BSD style, while SunOS 5.x uses System V.4 style device files but also provides BSD style device names via use of symbolic links (for backward compatibility with SunOS 4.x).
- SunOS 4.x - /dev/sdAP
- SunOS 5.x - /dev/[r]dsk/cCtAd0sS
- Digital Unix - /dev/[r]rzNP
- Linux - /dev/sdLK
Where: A = SCSI address, C = Controller number, K = DOS primary/extended partition, L = drive letter "a" through "h", N = 8 * controller # + SCSI address, P = BSD-style partition, S = System V-style slice
[Note: Linux device names and portioning is quite different from other flavors of Unix. Partition 0, or no partition number, refers to the whole drive. Partitions 1-4 are DOS primary partitions, while partitions 5-8 are extended DOS partitions.]
- Example of association between /dev/*tape and tape device
- Example of association between /dev/floppy and high-density floppy device
- Determine the "unit number" of the device(assume first SCSI bus, SCSI ID of tape drive is 5)
N = (8 * SCSI bus #) + SCSI target #
= (8 * 0) + 5
= 5
# cd /dev
# ./MAKEDEV tz5
MAKEDEV: special file(s) for tz5:
rmt0l
rmt0h
rmt0m
rmt0a
nrmt0l
nrmt0h
nrmt0m
nrmt0a
- Determine the number of inodes on the root partition (See "man df"). How many more files can you create on that partition?
- Determine the device names of all devices on your system
- If you have a tape drive, how do you specify use of non-rewind mode? How do you specify the high-density mode?
- If you were to add a new CD-ROM drive or SCSI tape device (assuming you don't have either yet), what would its device name be? (Check in /dev/MAKEDEV to see how its device files are created.)
Table of Contents Next Chapter