COMPUTER AND NETWORK
SYSTEM ADINISTRATION
CIS 5406-01
Summer 1999 - Lesson 10
Devices and Drivers
A. UNIX Devices and the file system
- The file system abstraction allows users to
access device driver directly
- echo "hi there" > tempfile
echo "hi there" > /dev/ttya
- Each of these eventually accesses a device
- Both write() to a file descriptor,
but each accesses a different device driver
B. Device naming conventions
1. BSD (SunOS) conventions
- Device file are in /dev
- A lot of them in one directory
2. SunOS Floppy disks (as an example)
brw-rw-rw- 2 root staff 16, 2 Jul 11 1994 /dev/fd0
brw-rw-rw- 1 root staff 16, 0 Jul 11 1994 /dev/fd0a
brw-rw-rw- 1 root staff 16, 1 Jul 11 1994 /dev/fd0b
brw-rw-rw- 2 root staff 16, 2 Jul 11 1994 /dev/fd0c
crw-rw-rw- 2 root staff 54, 2 Jul 11 1994 /dev/rfd0
crw-rw-rw- 1 root staff 54, 0 Jul 11 1994 /dev/rfd0a
crw-rw-rw- 1 root staff 54, 1 Jul 11 1994 /dev/rfd0b
crw-rw-rw- 2 root staff 54, 2 Jul 11 1994 /dev/rfd0c
- Note that the mode is 666
- The block fd devices have the same major device # (16)
- The raw (character) devices have the same major device # (54)
- The minor device number encodes the unit number as well
as the partition
3. SunOS SCSI hard drives
crw-r----- 1 root backup 17, 0 Jul 11 1994 /dev/rsd0a
crw-r----- 1 root backup 17, 1 Jul 11 1994 /dev/rsd0b
crw-r----- 1 root backup 17, 2 Jul 11 1994 /dev/rsd0c
crw-r----- 1 root backup 17, 3 Jul 11 1994 /dev/rsd0d
crw-r----- 1 root backup 17, 4 Jul 11 1994 /dev/rsd0e
crw-r----- 1 root backup 17, 5 Jul 11 1994 /dev/rsd0f
crw-r----- 1 root backup 17, 6 Jul 11 1994 /dev/rsd0g
crw-r----- 1 root backup 17, 7 Jul 11 1994 /dev/rsd0h
brw-r----- 1 root backup 7, 0 Jul 11 1994 /dev/sd0a
brw-r----- 1 root backup 7, 1 Jul 11 1994 /dev/sd0b
brw-r----- 1 root backup 7, 2 Jul 11 1994 /dev/sd0c
brw-r----- 1 root backup 7, 3 Jul 11 1994 /dev/sd0d
brw-r----- 1 root backup 7, 4 Jul 11 1994 /dev/sd0e
brw-r----- 1 root backup 7, 5 Jul 11 1994 /dev/sd0f
brw-r----- 1 root backup 7, 6 Jul 11 1994 /dev/sd0g
brw-r----- 1 root backup 7, 7 Jul 11 1994 /dev/sd0h
- Note permissions...why?
- The block special files (type b) access the disk using the system's
normal buffering mechanism
- They are read and written without regard to physical disk
records
- The raw interface (type c provides for direct transmission between
the disk and the user's read or write buffer; this is also
known as a character device (thus the c)
- A single read() or write() call usually results in one I/O operation
- Raw I/O is therefore considerably more efficient when many
bytes are transmitted (to local disk)
Partition naming conventions (BSD)
sd0 - refers to SCSI disk zero (first one seen)
sd0a - normally used for the root file system
sd0b - paging area (e.g. swap),
sd0c - low level copying, normally maps the entire disk
sd0d - SysAdmin-definable
sd0e - SysAdmin-definable
sd0f - SysAdmin-definable
sd0g - /usr
sd0h - SysAdmin-definable
4. SCSI tapes
- Uses same device driver and scsibus as the SCSI disks
- The driver can be opened with either rewind on close
/dev/rst*
or no rewind on close
/dev/nrst*
- The minor device numbers indicate tape format options,
see "man st".
C. Linux device naming conventions
- Similar to BSD, but different! (Flip the use of letter/number)
- All in /dev directory
- RedHat default /dev/MAKEDEV makes over 1,300 devices!
- Example for SCSI drive:
brw-rw---- 1 root disk 8, 0 Jul 17 1994 sda
brw-rw---- 1 root disk 8, 1 Jul 17 1994 sda1
brw-rw---- 1 root disk 8, 2 Jul 17 1994 sda2
brw-rw---- 1 root disk 8, 3 Jul 17 1994 sda3
...
brw-rw---- 1 root disk 8, 16 Jul 17 1994 sdb
brw-rw---- 1 root disk 8, 17 Jul 17 1994 sdb1
...
- The block device name has the following form: sdDP
- D denotes the physical drive
- P denotes the partition
- SCSI disks have a major device number of 8
- Minor device number = (16 * drive_number) + partition number
- Drive_number = number of the physical drive in order of detection
- Partition numbers are:
Partition 0 is the whole drive
Partitions 1-4 are the DOS primary partitions
Partitions 5-8 are the DOS extended partitions
- IDE drives use the "hd" prefix.
- Example:
/dev/sda2 is the 2nd DOS primary partition on the first SCSI drive
/dev/hda1 is the 1st DOS primary partition on the first IDE drive
D. Solaris device naming conventions
- /dev contains the usual character and block special
file names
- But, they are links to other directories:
root root 37 Oct 1 1993 diskette ->../devices/obio/SUNW,fdtwo@0,400000:c
root root 37 Aug 16 02:49 fd0a ->../devices/obio/SUNW,fdtwo@0,400000:a
root root 37 Aug 16 02:49 fd0b ->../devices/obio/SUNW,fdtwo@0,400000:b
root root 8 Aug 16 02:49 fd0c -> diskette
root root 41 Oct 1 1993 rdiskette ->../devices/obio/SUNW,fdtwo@0,400000:c,raw
root root 41 Aug 16 02:49 rfd0a ->../devices/obio/SUNW,fdtwo@0,400000:a,raw
root root 41 Aug 16 02:49 rfd0b ->../devices/obio/SUNW,fdtwo@0,400000:b,raw
root root 9 Aug 16 02:49 rfd0c -> rdiskette
- Look in /devices/obio:
brw-rw-rw- 1 root 36, 0 Jul 11 1994 SUNW,fdtwo@0,400000:a
crw-rw-rw- 1 root 36, 0 Oct 1 1993 SUNW,fdtwo@0,400000:a,raw
brw-rw-rw- 1 root 36, 1 Oct 1 1993 SUNW,fdtwo@0,400000:b
crw-rw-rw- 1 root 36, 1 Oct 1 1993 SUNW,fdtwo@0,400000:b,raw
brw-rw-rw- 1 root 36, 2 Oct 1 1993 SUNW,fdtwo@0,400000:c
crw-rw-rw- 1 root 36, 2 Oct 1 1993 SUNW,fdtwo@0,400000:c,raw
- Note the major, minor device numbers and the
block and character special file designators
- How about SCSI drives?
- They are also linked to the directory
> One of the most complex UNIX device naming schemes ever!
/devices/iommu@0,10000000/sbus@0,10001000/espdma@4,8400000/esp@4,8800000
- In here you will find the usual device files:
brw-r----- 1 root 32, 24 Oct 1 1993 sd@3,0:a
crw-r----- 1 root 32, 24 Oct 1 1993 sd@3,0:a,raw
Figure 2-5 on page 55 of ESA is a handy table showing the
disk device file naming conventions for SunOS, OSF/1 (Digital UNIX),
Linux, HP-UX, IRIX and Solaris.
Of particular note is the Solaris naming convention:
/dev/dsk/cMtNdOsP
where:
M = controller ID (0 = first disk controller, etc.)
N = target ID (for SCSI, this is the SCSI ID)
O = disk ID (for multi-disk addresses, as with RAID)
P = slice number (slice == partition)
For example,
/dev/dsk/c0t1d0s4 refers to slice 4 (partition 4) on
disk 0 of SCSI ID # 1 on the first SCSI controller seen by the
system.
/dev/rdsk/c0t1d0s4 refers to the same slice, but any I/O
to the device using this name will happen directly (the system
buffer cache will not be involved).
Windows NT Devices
Windows NT devices can be more complex, given the great diversity of
possible hardware configurations among PCs. Most information about devices
and device drivers can be viewed via Settings/Control Panel.
Devices - display list of device drivers installed on system. Note that
most truly drive a device; others are software devices (like
WINS Client(TCP/IP)).
Windows '95/'98 has an excellent Explorer interface to the hardware devices,
presented as a file tree. The Windows NT Diagnostics
does provide an Explorer interface, but not all the hardware is
represented (well, it seems to be there, but takes some mouse
work to find, say, the IRQs in use, etc. -- look at the Resources
tab.
Under Windows NT you can also get a glimpse of devices through the individual
control panels.
As an NT SysAdmin you also need to be aware of the DOS-style device file names
supported under NT (LPTn, COMn, etc.).