TA # Date Created Date Updated   Printer Friendly Version of This TA   Print Article
  E-mail This TA   E-mail Article
103862 06/17/1992 04:17 PM 06/13/2008 07:26 AM
Explanation of the hard drive minor number scheme.
Keywords
mkdev hd filesystems second access hard drive minor numbers scheme device file /dev/hd00 /dev/hd10 block character raw divvy division fdisk partitions filesystems dos unix xenix boot extended osr osr5 openserver openserver5 500 5.0.0 502 5.0.2 504 5.0.4 505 5.0.5 506 5.0.6 507 5.0.7
Release
          SCO XENIX Operating System Release 2.3.4 and earlier 
           SCO UNIX System V/386 Release 3.2 Operating System Version 4.0  
            and earlier 
           SCO Open Desktop Release 2.0 and earlier 
           SCO OpenServer Release 5 
Problem
           How are the minor numbers interpreted for hard drive 
            minor numbers?


Solution
           This article assumes that the user is familiar with 
            representing numbers in binary.  The following bourne 
            shell script is provided so that the user need not know 
            how to convert between decimal and binary and vice versa:

        -------------------------------CUT HERE------------------------------
        :

        for number in $*
        do
                   case `basename $0` in
                   dec2bin)echo "obase=2 \n ${number}" | bc ;;
                   bin2dec)echo "ibase=2 \n ${number}" | bc ;;
                   esac
        done
        -------------------------------CUT HERE------------------------------

           Type the above shell script into a file called /etc/dec2bin 
            using your favorite text editor.  Then make the file executable 
            with the following command:

                      # chmod 755 /etc/dec2bin

           Then create a link to the file with the following command:

                      # ln /etc/dec2bin /etc/bin2dec

           Since these two programs (i.e., dec2bin and bin2dec) are linked 
            together, it is not necessary to make bin2dec executable since 
            it inherits the permissions of dec2bin.

           The following illustrates example uses of dec2bin and bin2dec:

                      # dec2bin 255
                      11111111

                      # bin2dec 11111111
                      255

           Practice using dec2bin and bin2dec until you are comfortable 
            with these utilities.

           Consider the following device file:

               brw-------   2 sysinfo  sysinfo    1,  0 Nov 01 1990 /dev/hd00
                                                  ^   ^
                                                  |   |
                                              major   minor
                                              number  number

           The major number is 1 and the minor number is 0.
           What are major and minor numbers?

           For simplicity, think of the major number as an index 
            into an array in the kernel that lists the available 
            device drivers in the system.  This is represented 
            pictorially below with some of the common device driver 
            names filled in.


                 _____
                |     |
             0  |  *--|-------> console driver
                |_____|
                |     |
             1  |  *--|-------> hard disk driver
                |_____|
                |     |
             2  |  *--|-------> floppy disk driver
                |_____|
                |     |
             3  |     |
                |_____|
                |     |
             4  |     |
                |_____|
                |     |
             5  |  *--|-------> Serial I/O driver
                |_____|
                   .
                   .
                   .


           So the major number is simply a number that says which 
            device driver to use.  For example, the device file listed 
            above, /dev/hd00, has a major number of 1 which, according 
            to the picture above, is the hard disk driver.

           You can determine the specifics of which drivers are 
            linked into your SCO XENIX kernel by examining the file 
            /usr/sys/conf/master.  The analogous file in SCO UNIX 
            System is /etc/conf/cf.d/mdevice.

           What is a minor number?  Think of the minor number as 
            data.  It is simply a piece of data passed into the 
            device driver (whichever device driver that was specified 
            by the major number).  It is up to the writer of a device 
            driver to determine what a particular minor number "means".

           A minor number is one byte.  One byte is eight bits.  
            Therefore, there are 256 (i.e., 2^8) possible combinations 
            for a minor number.  Consequently, a minor number can 
            range between 0 and 255.

           It is common for device drivers to interpret a minor number 
            such that each bit represents one feature of the device driver.
            For instance, suppose we were writing a device driver for a
           doughnut making machine.  Then the low bit might mean "jelly 
            filled", the next bit might mean "glazed", and the next bit 
            might mean "colored sprinkles on top".

           Let's consider a more practical instance of device driver 
            which interprets the minor number such that each bit 
            represents one feature of the driver.  The hard disk driver 
            does just this.

           Before we do this, we must understand the following facts.  
            A hard drive can be divided into up to four logical drives 
            (a.k.a., virtual disks, a.k.a., fdisk partitions).  Each 
            fdisk partition may correspond to an operating system.  For 
            example, you may have SCO XENIX installed on fdisk partition 
            number one, SCO UNIX System on fdisk partition number two, 
            and DOS on fdisk partition number three.  Each SCO XENIX or 
            SCO UNIX System fdisk partition can be further subdivided 
            into up to eight divvy divisions.  Divvy division zero is 
            usually the root filesystem.  Divvy division one is usually 
            the swap space.  The other divisions (with the exception of 
            divvy division seven) may be used for other filesystems such 
            as a /u filesystem.  Divvy division seven always has a special
           significance:  it means "the whole fdisk partition".

                                   MSB                                  LSB
                      bit number |   7    6    5    4    3    2    1    0
                   --------------|------------------------------------------
                    minor number |   #    #    #    #    #    #    #    #
                                     |    |    |    |    |    |    |    |
                                     |    |    |    |    |    |    |    |
                                     |    |    |    |    |    |    |    |
                                     |    |    |    |    |    Divvy
                                     |    |    |    |    |    division #
                                     |    |    |    |    |
                                     |    |    Virtual
                                     |    |    drive #
                                     |    |
                                     Physical
                                     drive #

           The low three bits (i.e., bits 2, 1, and 0) of the hard disk 
            driver minor number represent the divvy division number.  
            Note that 2^3=8 is equal to the number of divvy divisions.

           The middle three bits (i.e., bits 5, 4, and 3) of the hard 
            disk driver minor number represent the virtual disk number.  
            Note that 2^3=8, but there are only a maximum of four fdisk 
            partitions.  So why are there three bits allocated to the 
            virtual drive number?  The answer is revealed in the fol-
           lowing chart:

                            0 = whole disk
                      1, 2, 3, 4 = that fdisk partition number
                            5 = the active fdisk partition
                            6 = the DOS partition
                            7 = unused

           For ease of conversion, the following chart is provided:

                      binary | decimal
                      -------|--------
                       000   |    0
                       001   |    1
                       010   |    2
                       011   |    3
                       100   |    4
                       101   |    5
                       110   |    6
                       111   |    7

           The remaining high two bits (i.e., bits 7 and 6) represent 
            the physical disk number.  Since there are only two bits, 
            there can only be a maximum of four disks specified with 
            this minor number scheme.

           In Version 4.0 of SCO UNIX System and SCO Open Desktop Release 
            2.0, SCO lifts the four hard drive limitation with "extended 
            minor numbers".  See the article titled "Explanation of extended
           minor numbers" for information on how extended minor numbers
           are implemented.


           EXAMPLES:  Consider each of the following:

               brw-------   2 sysinfo  sysinfo    1,  0 Jun 11 1990 /dev/hd00
               brw-------   2 sysinfo  sysinfo    1, 39 Jun 11 1990 /dev/hd04
               brw-------   2 sysinfo  sysinfo    1, 47 Jun 11 1990 /dev/hd0a
               brw-r-----   2 dos      sysinfo    1, 55 Jun 13 1990 /dev/hd0d
               brw-r--r--   1 root     other      1, 40 May 14 1990 /dev/root
               brw-r--r--   1 root     other      1, 41 May 14 1990 /dev/u
               brw-------   2 sysinfo  sysinfo    1, 64 Nov 01 1990 /dev/hd10
               brw-------   2 sysinfo  sysinfo    1, 95 Nov 01 1990 /dev/hd13

           Note that since they are all device files for the hard disk 
            driver, they all use the same major number.



hd00:  minor= 0 = 00000000  ---> 00 000 000
                                 || ||| |||
                                 || ||| divvy division #0
                                 || whole disk
                                 physical drive #0

hd04:  minor=39 = 00100111  ---> 00 100 111
                                 || ||| |||
                                 || ||| divvy division #7 (whole partition)
                                 || fdisk partition #4
                                 physical drive #0

hd0a:  minor=47 = 00101111  ---> 00 101 111
                                 || ||| |||
                                 || ||| divvy division #7 (whole partition)
                                 || active fdisk partition
                                 physical drive #0

hd0d:  minor=55 = 00110111  ---> 00 110 111
                                 || ||| |||
                                 || ||| divvy division #7 (whole partition)
                                 || DOS fdisk partition
                                 physical drive #0

root:  minor=40 = 00101000  ---> 00 101 000
                                 || ||| |||
                                 || ||| divvy division #0
                                 || active fdisk partition
                                 physical drive #0

   u:  minor=41 = 00101001  ---> 00 101 001
                                 || ||| |||
                                 || ||| divvy division #1
                                 || active fdisk partition
                                 physical drive #0

hd10:  minor=64 = 01000000  ---> 01 000 000
                                 || ||| |||
                                 || ||| divvy division #0
                                 || fdisk partition #3
                                 physical drive #1

hd13:  minor=95 = 01011111  ---> 01 011 111
                                 || ||| |||
                                 || ||| divvy division #7 (whole partition)
                                 || fdisk partition #3
                                 physical drive #1

hd13:  minor=95 = 01011111  ---> 01 011 111
                                 || ||| |||
                                 || ||| divvy division #7 (whole partition)
                                 || fdisk partition #3
                                 physical drive #1


SEE ALSO:
           hd(HW), divvy(ADM), fdisk(ADM), bc(C), mdevice(F), master(F)
Related Articles
•  Minor numbers for first 4 hard disks, fdisk partitions, divvy divisions
•  How do I increase the swap area on SCO UNIX System 3.2 Version 2.0?
•  What is postscript?
•  What are minor device numbers, and where do they come from?
•  How to recover root filesystem after crash if backups, boot/root exist. 4.2.
HomeHome