
This document tries to describe how one extended partition is divided
into several logical sub partitions. It is assumed that you already are
familiar with the geometry of a hard disk (cylinder/head/sector etc).
[If not then refer to the file recovery.txt for web places to visit]


--------------------------------------------------------------------------------

The very first sector on the disk (CHS=0/0/1) is called the Master Boot
Record (MBR) and contains the following:
   Offset
    0 - 0x1BD	Boot code that is loaded into 0000:7C00 and executed
		by the BIOS at boot time.
0x1BE - 0x1FD	The partition table
0x1FE - 0x1FF	Two signature bytes (0x55 and 0xAA)


The partition table consists of 4 entries that is 16 bytes long.
Each table entry contains the following:

  1 Byte  -  Bootable Flag. Must be 0 (not bootable) or 80h (bootable).
             At most one Partition may be bootable at a time.
  1 Byte  -  Start Head. The number of the head of the first sector of
             the partition.
  2 Bytes -  Start Sector + Cylinder. The Bits are as follows:
  			CCSSSSSS CCCCCCCC
	     where the first byte contains the sector number (1 - 63),
	     and the high two bits of the cylinder number. The second
	     byte contains the low eight bits of the cylinder number.
  1 Byte  -  System Indicator. For DOS this may be:
 		0x01 - 12-bit FAT, 16-bit sector number
		0x04 - 16-bit FAT, 16-bit sector number
		0x05 - Extended Partition
		0x06 - 16-bit FAT, 32-bit sector number
  1 Byte  -  End Head. Head Number of the last sector of the partition
  2 Bytes -  End Sector + Cylinder. Same format as Start Sector + Cylinder
  4 Bytes -  Relative Start Sector.
  4 Bytes -  Total number of Sectors.



Since the partition table only contains 4 entries it meant that a maximum
of 4 different partitions could be created. To overcome this limitation
DOS 3.3 introduced the extended partition.

A partition defined by a entry in the partition table in the MBR is
called a PRIMARY partition.

If the system indicator to one of the primary partitions equals 0x05 then
that partition is called an EXTENDED partition. This extended partition
is then divided into several sub partitions called LOGICAL partitions.

How this extended partition is divided into logical partitions is best
described using an example. Suppose that the partition table in the MBR
defines two entries -- one primary partition and one extended, like this:


              +----------+
              |          |
  Primary     |    C:    |
              |          |
              |----------|
            / |          |
          /   |          |
  Extended    |          |
          \   |          |
            \ |          |
              +----------+


Reading only the partition table at the MBR gives no information about
what the extended partition contains, except that it exists and how much
space it occupies. So when a program wants to obtain information about
the contents of the extended partition, it must read the first sector of
the extended partition. This sector is similar to the MBR and contains
it's own variation of a partition table called DRIVE TABLE.

The difference between this sector and the MBR is that this sector
contains no bootable code. The MBR partition table and the drive table
differs a bit more. A drive table contains only one or two entries
(and the 3rd and 4th drive table entries are alway unused).

The first entry in the drive table defines a partition just like an
entry in the MBR partition table does. Lets call this logical partition
drive D:. The second entry in the drive table defines a "new" extended
partition which is the rest of the extended partition [Note 1].


              +----------+
              |          |
  Primary     |    C:    |
              |          |
              |----------|
            / |    D:    |  Logical
          /   +----------+
  Extended    |          | \
          \   |          |  remaining extended partition
            \ |          | /
              +----------+



Just like an extended partition entry in the MBR this
remaining-extended-partition entry does not give any information about
the partition other than its existence and size.

This new "extended partition" contains another drive table at its first
sector. This drive table is just like the drive table at the start of
the extended partition (except that this for the remaining extended
partition).


Suppose that this drive table also contains two entries: the first
defines a logical partition (drive E:) and the second defines another
remaining extended partition.


              +----------+
              |          |
  Primary     |    C:    |
              |          |
              |----------|
            / |    D:    |  Logical
          /   +----------+
  Extended    |    E:    |  Logical
          \   +----------+
            \ |          |  remaining extended partition
              +----------+


Again nothing about the contents of the remaining extended partition
is know until the drive table at the start of the remaining partition
is examined.

Suppose that this drive table only contains the first entry defining a
logical partition (drive F:) for the rest of disk. With no second entry
this means that this logical partition is the last in the chain.


              +----------+
              |          |
  Primary     |    C:    |
              |          |
              |----------|
            / |    D:    |  Logical
          /   +----------+
  Extended    |    E:    |  Logical
          \   +----------+
            \ |    F:    |  Logical
              +----------+



[Note 1]
This isn't quite true but I'll just pretend so to keep this example simple.
The second entry doesn't spawn the whole remaining part of the extended
partition, only the next partition in the chain. Look at example.txt to
get the idea of how it works.

