Writing program to delete Partition
The program to delete partition is used for troubleshooting purpose. For example, assume that you had the FAT32 file system partitions in your disk. Now you decided to install the LINUX operating system in your disk simultaneously.
If any how, the installation of operating system is interrupted in between, at the stage when the modifications were being made to the partition table of the MBR. In such cases there are a lot of possibilities that the partition, in which you were going to install the other operating system, becomes inaccessible.
In this case the disk space of the lost partition becomes useless due to being inaccessible. However if we delete the partition information of that partition from partition table any how, we can again make this space usable using FDISK command of DOS.
The program to delete the partition entry from the partition table of MBR has been given next:
/* Program to delete the second partition entry from the partition table of MBR */
# include <bios.h>
/* structure to read the partition entry from partition table */
struct partition
{
/* Active Partition Byte */
unsigned char bootable ;
/* Starting Head */
unsigned char start_side ;
/* combination of Starting sector and cylinder number */
unsigned int start_sec_cyl ;
/* File system Indicator Byte */
unsigned char parttype ;
/* Ending Head */
unsigned char end_side ;
/* combination of Starting sector and cylinder number */
unsigned int end_sec_cyl ;
/* Relative Sector Number */
unsigned long part_beg ;
/* Partition length in sectors */
unsigned long plen ;
} ;
/* Structure to read-write MBR */
struct part
{
/* IPL (Initial Program Loader) */
unsigned char master_boot[446] ;
/* Partition table */
struct partition pt[4] ;
/* Magic Number */
int lasttwo ;
} ;
struct part p ;
void main()
{
unsigned int t1,t2;
clrscr();
biosdisk ( 2, 0x80, 0, 0, 1, 1, &p ) ;
display(); /* display the information of
Partition table */
getch();
p.pt[1].bootable = 0;
p.pt[1].start_side = 0 ;
p.pt[1].start_sec_cyl = 0 ;
p.pt[1].parttype = 0;
p.pt[1].end_side = 0;
p.pt[1].end_sec_cyl = 0;
p.pt[1].part_beg = 0;
p.pt[1].plen = 0;
printf("\n\n\n After Deleting the Second Partition
Entry From MBR Partition Table,");
printf("\n The Partition Table will Be Changed as
Follows: ");
/* To Delete Second Partition Information from partition
table of MBR Remove the forward slashes from the
biosdisk( ) function. Do not use Carelessly, Partition
information of Second Partition of Partition Table will
be Erased Completely. */
////// biosdisk ( 3, 0x80, 0, 0, 1, 1, &p ) ;
display(); /* Display the information of partition
table after modification */
getch();
}
Comments on program:
Uncomment the biosdisk ( 3, 0x80, 0, 0, 1, 1, &p ) function to delete the second partition from the partition table of MBR.
To delete the partition, all the parameters of it, are set to 0 in partition table entry in MBR. Always remember that if you delete the extended partition, all the logical partitions of that extended partition will also become inaccessible.
The Function display( ) is used to display the partition table of MBR. The coding of the function is as follows:
/* Function to display partition table of MBR */
display()
{
unsigned int s_sec, s_trk, e_sec, e_trk, i, t1, t2 ;
char type[20], boot[5] ;
printf("\n\nPart. Boot Starting location Ending 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 0x00 :
strcpy ( type, "Unused" ) ; break ;
case 0x1 :
strcpy ( type, "FAT12" ) ; break ;
case 0x2 :
strcpy ( type, "Xenix" ) ; break ;
case 0x3 :
strcpy ( type, "Xenix:usr" ) ; break ;
case 0x4 :
strcpy ( type, "FAT16<32M" ) ; break ;
case 0x5 :
strcpy ( type, "DOS-Ext." ) ; break ;
case 0x6 :
strcpy ( type, "FAT16>32M" ) ; break ;
case 0x7 :
strcpy ( type, "NTFS" ) ; break ;
case 0x0b :
strcpy ( type, "FAT32" ) ; break ;
case 0x0c :
strcpy ( type, "FAT32-LBA" ) ; break ;
case 0x0d :
strcpy ( type, "VFAT16" ) ; break ;
case 0x0e :
strcpy ( type, "VFAT16-LBA" ) ; break ;
case 0x0f :
strcpy ( type, "FAT EXT" ) ; break ;
case 0x17 :
strcpy ( type, "HPFS" ) ; break ;
case 0x81 :
strcpy ( type, "Old LINUX" ) ; break ;
case 0x82 :
strcpy ( type, "LinuxSwap" ) ; break ;
case 0x83 :
strcpy ( type, "LinuxNative" ) ; break ;
case 0x85 :
strcpy ( type, "Linux Ext." ) ; 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 ( " %10lu %10lu", p.pt[i].part_beg,
p.pt[i].plen ) ;
}
return 0;
}
|
page 1 | 2 | 3 | 4 | 5 | 6 |
|
|
|