/* Function To Change the Parameters of DBR */
Recover_with_values()
{
int val =0;
/* Jump Code of 3 Bytes For Floppy */
b.code[0] = 0xEB;
b.code[1]= 0x3E;
b.code[2]= 0x90 ;
/* System Id of 8 Bytes */
strcpy(b.system_id, "+05PSIHC");
/* Bytes Per Sector = 512 */
b.bytes_per_sec = 512;
/* Sector per Cluster for 1.44M 3.5" Floppy = 1 */
b.sec_per_clus = 1;
/* Number of Reserved Sectors = 1 */
b.res_sec =1;
/* Number of FAT Copies = 2 */
b.fat_copies =2;
/* Number of Root Directory Entry = 224 */
b.root_dir_entry =224;
/* Number of Sectors on Disk = 2880 */
b.no_sects =2880;
/* Media Descriptor Byte For Floppy = F0 (H) */
b.format_id =0xF0;
/* Sectors Per FAT = 9 */
b.sec_per_fat =9;
/* Sectors Per Track = 18 */
b.sec_per_trk =18;
/* Number of Sides = 2 */
b.no_sides =2;
/* Number of Special Reserved Sectors (or Hidden
Sectors) = 0 */
b.no_sp_res_sect =0;
/* Use For Floppy Disk*/
val = abswrite ( 0, 1, 0, &b ) ;
if ( val == -1 )
{
printf ( "\n Disk Write Error...bad sector\n" ) ;
printf ( " Disk was not Recovered." ) ;
exit ( 1 ) ;
}
return 0;
}
display_info()
{
printf ( "\n Jump Code (Hex) = %X%X%X (H)\n",
b.code[0],b.code[1],b.code[2]);
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 ( " Media Descriptor Byte = %X\n",
b.format_id ) ;
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 ) ;
return 0;
}
Comments on coding:
The structure boot is used to access the DBR, to read-write the parameters of the disk. The function display_info(), displays the various parameters of the disk, reading from the DBR. The function Recover_with_values() is used to modify and recover the parameters of DBR of Floppy.
The values used by the function Recover_with_values(), are for parameters of 1.44MB, 3 ½ inch floppy disk’s DBR. The description of these values has been given in the table given next:
Value |
Description |
b.code[0] = 0xEB;
b.code[1] = 0x3E;
b.code[2] = 0x90 ; |
Jump Code of 3 Bytes For specified Floppy, has been given EB 3E 90(H) |
strcpy(b.system_id,"+05PSIHC"); |
System Id of 8 Bytes. It is calculated with current date and time of the system, however almost anything works. |
b.bytes_per_sec = 512; |
Bytes Per Sector = 512 |
b.sec_per_clus = 1; |
Number of Sectors per Cluster for 1.44M 3.5" Floppy is 1 |
b.res_sec = 1; |
Number of Reserved Sectors = 1 |
b.fat_copies = 2; |
Number of FAT Copies = 2 |
b.root_dir_entry = 224; |
Number of Root Directory Entries for the specified floppy disk = 224 |
b.no_sects = 2880; |
Number of Sectors on Disk = 2880 |
b.format_id = 0xF0; |
Media Descriptor Byte For the specified Floppy = F0 (H) |
b.sec_per_fat = 9; |
Number of Sectors Per FAT = 9 |
b.sec_per_trk = 18; |
Number of Sectors Per Track = 18 |
b.no_sides = 2; |
Number of Sides = 2 |
b.no_sp_res_sect = 0; |
Number of Special Reserved Sectors (or Hidden Sectors) = 0 |
|