reading boot parameters

Upload: prashantonline

Post on 30-May-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 Reading Boot Parameters

    1/5

    Reading Boot ParametersThe Boot sector on the floppy disk contains two things, namely, boot parameters and thedisk bootstrap program. The purpose of the disk bootstrap program is to load DOS files fromthe disk into memory. Whether the disk bootstrap program would be used or not depends onwhether the disk is being used for booting the computer or not. The boot parameters are

    used by DOS at the time a read or write operation is performed on the disk. This is becausethe boot parameters contain the vital information about how the disk has been formatted.From format to format the values of the boot parameters may change, but their order remainssame. The following program display boot parameters of floppy.

    /* Display boot parameters of floppy */

    # include "dos.h"

    # include "stdio.h"main( ){

    struct boot

    {unsigned char code[3] ;unsigned char system_id[8] ;int bytes_per_sec ;char sec_per_clus ;int res_sec ;char fat_copies ;int root_dir_entry ;unsigned int no_sects ;unsigned char format_id ;int sec_per_fat ;int sec_per_trk ;int no_sides ;

    int no_sp_res_sect ;unsigned char rest_code[482] ;

    } ;struct boot b ;char temp[4] ;

    int val, drive ;val = absread ( 0, 1, 0, &b ) ;

    if ( val == -1 ){

    printf ( "Disk read Error...bad sector\n" ) ;exit ( 1 ) ;

    }

    clrscr ( ) ;printf ( "System id %s\n", b.system_id ) ;printf ( "Bytes per sector %d\n", b.bytes_per_sec ) ;printf ( "Sectors per cluster %d\n", b.sec_per_clus ) ;printf ( "Reserved sectors %d\n", b.res_sec ) ;printf ( "FAT copies %d\n", b.fat_copies ) ;printf ( "Root directory entries %d\n", b.root_dir_entry ) ;printf ( "No. of sectors on disk %u\n", b.no_sects ) ;printf ( "Format id %X\n", b.format_id ) ;

  • 8/14/2019 Reading Boot Parameters

    2/5

    printf ( "Sectors per FAT %d\n", b.sec_per_fat ) ;printf ( "Sectors per track %d\n", b.sec_per_trk ) ;printf ( "No. of sides %d\n", b.no_sides ) ;printf ( "No. of reserved sectors %d\n", b.no_sp_res_sect ) ;

    }

    The typical values obtained are tabulated as follows :

    Description Length in bytes Typical D9 disk values

    Jump Instruction 3 EB 34 90

    System ID 8 IBM 3.0

    No.of bytes per sector 2 512

    No. of sectors per cluster 1 2

    No. of sectors in reserved area 2 1

    No. of copies of FAT 1 2

    Max. no. of root directory entry 2 112

    Total no. of sectors 2 720

    Media descriptor 1 FDNo of sectors per FAT 2 2

    No of sectors per track 2 9

    No. of sides 2 2

    No. of hidden sectors 2 0

    Taking Apart The Partition TableThe murky depths of Partition Table (PT) don't look terribly inviting to most people. It isviewed as sinister and full of technical details that most people do not want to test theirstrengths with. But if we examine the PT with a thick lens it is straight and simple. Moreoversince you have been using hard disks since you were this high in Computers, it's all the moremeaningful 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 incapacity from 20 mb to 300 mb. So huge is this capacity that it would be foolish to use theentire 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 harddisk is partitioned using DOS's FDISK command. While partitioning the hard disk FDISKstores the details about where one partition ends and the next begins, which is the bootablepartition etc. in the first physical sector ( side 0, track 0, sector 1 ). It also stores a programcalled 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

  • 8/14/2019 Reading Boot Parameters

    3/5

    The data part begins at 447th byte. The last two bytes in the PT are always 0x55, 0xAA. Thedata part is 64 bytes long and is further divided into four parts of 16 bytes each. Each 16bytes chunk consists of information about a partition on the hard disk. Hence there can bemaximum 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. Onlyone 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 bitsare 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 partition1 - DOS partition that uses a 16-bit FAT

    2 - Xenix partition4 - DOS partition that uses a 16-bit FAT5 - Extended Partition6 - 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 thehigh 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 isstored first.

    let us put the theorey into a program which analyses the PT. Here it is.

    # 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 ;

  • 8/14/2019 Reading Boot Parameters

    4/5

    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 > 8 ;

    t2 = ( p.pt[i].start_sec_cyl & 0x00c0 ) > 8 ;

    t2 = ( p.pt[i].end_sec_cyl & 0x00c0 )

  • 8/14/2019 Reading Boot Parameters

    5/5

    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 contains4 such data blocks, along with 446 bytes code and 0x55, 0xAA at the end. To combine thesewe need another structure - hence the definition struct part. Having created the space tostore 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 outthe information about each partition and display it on the screen.