Theoretical Paper
- Computer Organization
- Data Structure
- Digital Electronics
- Object Oriented Programming
- Discrete Mathematics
- Graph Theory
- Operating Systems
- Software Engineering
- Computer Graphics
- Database Management System
- Operation Research
- Computer Networking
- Image Processing
- Internet Technologies
- Micro Processor
- E-Commerce & ERP
Practical Paper
Industrial Training
Taking Apart The Partition Table
Taking Apart The Partition Table
The murky depths of Partition Table (PT) don't look terribly inviting to most people. It is viewed as sinister and full of technical details that most people do not want to test their strengths with. But if we examine the PT with a thick lens it is straight and simple. Moreover since you have been using hard disks since you were this high in Computers, it's all the more meaningful to get to know the details of the PT if it is the driving force behind the hard disk.
PT exists only on hard disk. This is because today we have hard disks which range in capacity from 20 mb to 300 mb. So huge is this capacity that it would be foolish to use the entire hard disk only for DOS. Hence it is divided into several logical parts called partitions. One partition may contain DOS whereas the other might contain Xenix an so on. The hard disk is partitioned using DOS's FDISK command. While partitioning the hard disk FDISK stores the details about where one partition ends and the next begins, which is the bootable partition etc. in the first physical sector ( side 0, track 0, sector 1 ). It also stores a program called Master Boot Program in the PT. Thus a PT consists of data part and the code part. The following figure 1 shows how the PT is logically divided.
Figure 1
The data part begins at 447th byte. The last two bytes in the PT are always 0x55, 0xAA. The data part is 64 bytes long and is further divided into four parts of 16 bytes each. Each 16 bytes chunk consists of information about a partition on the hard disk. Hence there can be maximum four partitions on the hard disk. The break-up of 16 bytes is given below.
Byte |
Meaning |
0 | Boot indicator. Contains 0x80 for the active partition, 0 for all others. Only one partition can be active at a time. |
1 | Side where the partition begins. |
2 | The low six bits are the sector where the partition begins. The high two bits are the two high bits of the track where the partition begins. |
3 | Low order eight bits of the track where the partition begins. |
4 | Partition type indicator. The contents os this byte indicates the type of the partition. Following values may exist. 0 - Unused partition 1 - DOS partition that uses a 16-bit FAT 2 - Xenix partition 4 - DOS partition that uses a 16-bit FAT 5 - Extended Partition 6 - Huge Partition |
5 | Side where the partition ends. |
6 | Low order six bits are the sector where the partition ends. The high two bits are the high two bits of the ending track number. |
7 | Low eight bits of the track number where the partition ends. |
8-1 | Double word containing the number of sectors preceeding the partition. Low order word is stored first. |
12-15 | Double word containing the number of sectors in the partition. Low order word is stored first. |
# include "bios.h"
struct partition
{
unsigned char bootable ; unsigned char start_side ;
unsigned int start_sec_cyl ; unsigned char parttype ;
unsigned char end_side ; unsigned int end_sec_cyl ;
unsigned long part_beg ; unsigned long plen ;
} ;
struct part
{
unsigned char master_boot[446] ;
struct partition pt[4] ;
int lasttwo ;
} ;
struct part p ;
main( )
{
unsigned int s_sec, s_trk, e_sec, e_trk, i, t1, t2 ;
char type[20], boot[5] ;
biosdisk ( 2, 0x80, 0, 0, 1, 1, &p ) ;
printf("\nPart. Boot Starting locationEnding Location Relative Number of");
printf("\nType Side Cylinder Sector Side Cylinder Sector Sectors Sectors\n");
for ( i = 0 ; i <= 3 ; i++ )
{
if ( p.pt[i].bootable == 0x80 )
strcpy ( boot, "Yes" ) ;
else
strcpy ( boot, "No" ) ;
switch ( p.pt[i].parttype )
{
case 0 :
strcpy ( type, "Unused" ) ; break ;
case 1 :
strcpy ( type, "12-Bit" ) ; break ;
case 2 :
strcpy ( type, "Xenix" ) ; break ;
case 4 :
strcpy ( type, "16-Bit" ) ; break ;
case 5 :
strcpy ( type, "Extended" ) ; break ;
case 6 :
strcpy ( type, "Huge" ) ; break ;
default :
strcpy ( type, "Unknown" ) ; break ;
}
s_sec = ( p.pt[i].start_sec_cyl & 0x3f ) ;
t1 = ( p.pt[i].start_sec_cyl & 0xff00 ) >> 8 ;
t2 = ( p.pt[i].start_sec_cyl & 0x00c0 ) << 2 ;
s_trk = t1 | t2 ;
e_sec = ( p.pt[i].end_sec_cyl & 0x3f ) ;
t1 = ( p.pt[i].end_sec_cyl & 0xff00 ) >> 8 ;
t2 = ( p.pt[i].end_sec_cyl & 0x00c0 ) << 2 ;
e_trk = t1 | t2 ;
printf ( "\n%6s %3s", type, boot ) ;
printf ( "%4d %6d %8d", p.pt[i].start_side, s_trk,s_sec ) ;
printf ( "%7d %6u %8u", p.pt[i].end_side, e_trk, e_sec ) ;
printf ( "%8lu %10lu", p.pt[i].part_beg, p.pt[i].plen ) ;
}
}
To amalgamate the disparate bodies in the data part of the PT what we need is a structure. So first we create a structure struct partition, 16 bytes long. But as we know the PT contains 4 such data blocks, along with 446 bytes code and 0x55, 0xAA at the end. To combine these we need another structure - hence the definition struct part. Having created the space to store the contents of PT we make a call to biosdisk( ), to read the contents of side 0, track 0, sector 1. Once the contents are read we enter into a for loop within which we separate out the information about each partition and display it on the screen.