/* Create Normal MBR */ void Create_BootNormal_MBR(void) { //Qprintf("Creating normal MBR\n"); Read_Physical_Sectors(flags.drive_number,0,0,1,1); memcpy(sector_buffer,bootnormal_code,SIZE_OF_MBR); sector_buffer[0x1fe]=0x55; sector_buffer[0x1ff]=0xaa; Write_Physical_Sectors(flags.drive_number,0,0,1,1); }
/* Clear Partition Table */ void Clear_Partition_Table() { //Qprintf("Clearing partitiontable for drive %02x..",flags.drive_number); Read_Physical_Sectors(flags.drive_number, 0, 0, 1, 1); memset(sector_buffer+0x1be,0,4*16); Write_Physical_Sectors(flags.drive_number, 0, 0, 1, 1); //Qprintf("done\n"); }
/* Remove MBR */ void Remove_MBR() { int index=0; Read_Physical_Sectors((flags.drive_number),0,0,1,1); do { sector_buffer[index]=0x00; index++; }while(index<0x1be); Write_Physical_Sectors((flags.drive_number),0,0,1,1); }
/* Clear the Flag */ void Clear_Flag(int flag_number) { if(flags.flag_sector!=0) { Read_Physical_Sectors((flags.drive_number),0,0,(flags.flag_sector),1); sector_buffer[(446+(flag_number-1))]=0; Write_Physical_Sectors((flags.drive_number),0,0,(flags.flag_sector),1); } else { printf("\nSector flagging functions have been disabled...Program Terminated.\n"); exit(9); } }
/* Create Alternate Master Boot Code */ void Create_Alternate_MBR(void) { char home_path[255]; int index=0; FILE *file_pointer; //Qprintf("Create_Alternate_MBR()\n"); Read_Physical_Sectors(flags.drive_number,0,0,1,1); /* Clear old MBR, if any */ memset(sector_buffer,0x00,0x1be); strcpy(home_path,path); strcat(home_path,"boot.mbr"); /* Search the directory Free FDISK resides in before searching the PATH */ /* in the environment for the boot.mbr file. */ file_pointer=fopen(home_path,"rb"); if(!file_pointer) file_pointer=fopen(searchpath("boot.mbr"),"rb"); if(!file_pointer) { printf("\nThe \"boot.mbr\" file has not been found...Program Terminated.\n"); exit(8); } index=0; do { sector_buffer[index]=fgetc(file_pointer); index++; }while(index<0x1be); fclose(file_pointer); sector_buffer[0x1fe]=0x55; sector_buffer[0x1ff]=0xaa; Write_Physical_Sectors(flags.drive_number,0,0,1,1); }
/* Clear the Boot Sector of a partition */ void Clear_Boot_Sector(int drive,long cylinder,long head,long sector) { unsigned char stored_sector_buffer[512]; long index; /* Save sector_buffer[512] into stored_sector_buffer[512] */ memcpy(stored_sector_buffer,sector_buffer,512); /* Write all 0xf6 values to sector_buffer[index] */ memset(sector_buffer,0xf6,512); for (index=0; index < 16; index++) { Write_Physical_Sectors(drive,cylinder,head,(sector+index),1); } /* Restore sector_buffer[512] to its original contents */ memcpy(sector_buffer,stored_sector_buffer,512); }
/* Clear the first sector on the hard disk...removes the partitions and MBR. */ void Clear_Entire_Sector_Zero() { //Qprintf("Clearing boot sector of drive %x\n", flags.drive_number); Clear_Sector_Buffer(); Write_Physical_Sectors(flags.drive_number, 0, 0, 1, 1); }