Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BIOS ProgrammingRSS Feeds

Program to read the Partition Table Information of Drive C using biosdisk( ) function

Posted By: Easy Tutor     Category: C Programming     Views: 5317

Write a program to read the Partition Table Information of Drive C using biosdisk( ) function.

Code for Program to read the Partition Table Information of Drive C using biosdisk( ) function in C Programming

 # include <stdlib.h>
 # include  <stdio.h>
 # include  <conio.h>
 # include   <bios.h>

 struct Partition
 {
    unsigned char ucBootable;
    unsigned char ucStartHead;
    unsigned int  uiStartCylinderSector;
    unsigned char ucTypeOfPartition;
    unsigned char ucEndHead;
    unsigned int  uiEndCylinderSector;
    unsigned long ulStartSector;
    unsigned long ulPartitionLength;
 };


 int main( )
 {
    unsigned char sBuffer[512]={NULL};

    clrscr( );
    textmode(BW80);

    biosdisk(2,0x80,0,0,1,1,sBuffer);

    if((_AH&0xFF)!=0x00)
    {
       switch(_AH)
       {
      case 0x01 : printf("Bad command");
              break;

      case 0x02 : printf("Address mark not found");
              break;

      case 0x03 : printf("Attempt to write to write-protected disk");
              break;

      case 0x04 : printf("Sector not found");
              break;

      case 0x05 : printf("Reset failed (hard disk)");
              break;

      case 0x06 : printf("Disk changed since last operation");
              break;

      case 0x07 : printf("Drive parameter activity failed");
              break;

      case 0x08 : printf("Direct memory access (DMA) overrun");
              break;

      case 0x09 : printf("Attempt to perform DMA across 64K boundary");
              break;

      case 0x0A : printf("Bad sector detected");
              break;

      case 0x0B : printf("Bad track detected");
              break;

      case 0x0C : printf("Unsupported track");
              break;

      case 0x10 : printf("Bad CRC/ECC on disk read");
              break;

      case 0x11 : printf("CRC/ECC corrected data error");
              break;

      case 0x20 : printf("Controller has failed");
              break;

      case 0x40 : printf("Seek operation failed");
              break;

      case 0x80 : printf("Attachment failed to respond");
              break;

      case 0xAA : printf("Drive not ready (hard disk only)");
              break;

      case 0xBB : printf("Undefined error occurred (hard disk only)");
              break;

      case 0xCC : printf("Write fault occurred");
              break;

      case 0xE0 : printf("Status error");
              break;

      case 0xFF : printf("Sense operation failed");
              break;

      default   : printf("Unknown Error");
       }
    }

    else
    {
       struct Partition *ptrDriveC=(struct Partition*)&sBuffer[0x1BE];

       int iStartingCylinderHighByte=(ptrDriveC->uiStartCylinderSector>>8);
       int iStartingCylinderLowByte=((ptrDriveC->uiStartCylinderSector&0x00C0)<<2);
       int iStartingCylinder=(iStartingCylinderLowByte+iStartingCylinderHighByte);

       int iEndingCylinderHighByte=(ptrDriveC->uiEndCylinderSector>>8);
       int iEndingCylinderLowByte=((ptrDriveC->uiEndCylinderSector&0x00C0)<<2);
       int iEndingCylinder=(iEndingCylinderLowByte+iEndingCylinderHighByte);

       printf("* * * * * * * * * *  Partition Information  * * * * * * * * * *\n\n");
       printf("Drive C: ");

       if(ptrDriveC->ucBootable==0x80)
      printf("Bootable\n");

       else
      printf("Not Bootable\n");

       printf("Start Head = %d\n",ptrDriveC->ucStartHead);
       printf("Starting Sector Number = %d\n",(ptrDriveC->uiStartCylinderSector&0x003F));
       printf("Starting Cylinder Number = %d\n",iStartingCylinder);

       printf("Partition Type = ");

       switch(ptrDriveC->ucTypeOfPartition)
       {
      case 0x00 : printf("Unused\n");
              break;

      case 0x01 : printf("12-Bit\n");
              break;

      case 0x02 : printf("Xenix\n");
              break;

      case 0x04 : printf("16-Bit\n");
              break;

      case 0x05 : printf("Extends\n");
              break;

      case 0x06 : printf("Huge\n");
              break;

      case 0x64 : printf("Novell\n");
              break;

      case 0x75 : printf("PCIX\n");
              break;

      case 0xDB : printf("CP/M\n");
              break;

      case 0xFF : printf("BBT\n");
              break;

      default   : printf("UnKnown\n");
              break;
       }

       printf("End Head = %d\n",ptrDriveC->ucEndHead);
       printf("Ending Sector Number = %d\n",(ptrDriveC->uiEndCylinderSector&0x003F));
       printf("Ending Cylinder Number = %d\n",iEndingCylinder);
       printf("Start Sector relative to Disk Begining = %ld\n",ptrDriveC->ulStartSector);
       printf("Partition Length = %ld\n",ptrDriveC->ulPartitionLength);

       printf("\n* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
    }

    getch( );
    return 0;
 }
  
Share: 



Easy Tutor
Easy Tutor author of Program to read the Partition Table Information of Drive C using biosdisk( ) function is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!