COMPUTER AND NETWORK
SYSTEM ADINISTRATION
CIS 5406-01
Summer 1998 - 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 (almost 700 on nu)
 
   2. 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. SCSI fixed disks
 
      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 access the disk using the system's 
       normal buffering mechanism
     - they are read and written without regard to physical disk 
       records
     - the raw interface provides for direct transmission between
       the disk and the user's read or write buffer
     - 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)
 
     - kernel configuration in: man(4) sd   (Desktop SPARCsystems)
 
       device-driver esp                    - device driver
       scsibus0 at esp                      - scsibus attached to driver
       disk sd0 at scsibus0 target 3 lun 0  - disks
       disk sd1 at scsibus0 target 1 lun 0
       disk sd2 at scsibus0 target 2 lun 0
       disk sd3 at scsibus0 target 0 lun 0
 
 
     partition naming conventions
 
        sd?a - normally used for the root file system
        sd?b - paging area (e.g. swap),
        sd?c - low level copying, normally maps the entire disk 
        sd?d  
        sd?e
        sd?f
        sd?g - /usr
        sd?h
 
 
   4. SCSI tapes
 
      - kernel configuration (Desktop SPARCsystems)
 
        scsibus0 at esp
        tape st0 at scsibus0 target 4 lun 0
        tape st1 at scsibus0 target 5 lun 0
 
      - 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
 
     For 1/2" reel tape devices (HP-88780):
 
     /dev/rst0        800 BPI density
     /dev/rst8       1600 BPI density
     /dev/rst16      6250 BPI density
     /dev/rst24      data compression
 
     /dev/nrst0      non-rewinding 800 BPI density
     /dev/nrst8      non-rewinding 1600 BPI density
     /dev/nrst16     non-rewinding 6250 density
     /dev/nrst24     non-rewinding data compression
 
C. The kernel jump table
 
   - /usr/sys/sun/conf.c (SunOS 4.x)
 
 
   - the 16th entry into the block device switch statement
     is the jump table for the block-special floppy device:
 
     { fdopen, fdclose, fdstrategy, fddump,   /*16*/
       fdsize, 0 },
 
 
   - the 54th entry into the character special switch statement
     is the jump table for the raw floppy device:
 
    { fdopen,  fdclose, fdread,     fdwrite,  /*54*/
      fdioctl, nulldev, seltrue,    0,
      0,       0,
    },
   
   - a call to device 54 with a jump parameter of 2 will call
     fdread()
 
 
D. Linux device naming conventions
   
   - similar to BSD
 
   - all in /dev directory 
 
   - Slackware default makes about 650 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
 
     - example:
 
       /dev/sda2 is the 2nd DOS primary partition on the first 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 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
 
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 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 need to be also aware of the DOS-style device file names
            supported under NT (LPTn, COMn, etc.).