📄 pdiskio.c
字号:
,pDrive->next_ext[index].start_head
,pDrive->next_ext[index].start_sect
,pDrive->total_head
,pDrive->total_sect);
pDrive->next_ext[index].end_head=pDrive->total_head;
pDrive->next_ext[index].end_sect=pDrive->total_sect;
pDrive->next_ext[index].end_cyl
=Extract_Cylinder_From_LBA_Value(
(pDrive->next_ext[index].rel_sect
+pDrive->ptr_ext_part->rel_sect
+pDrive->next_ext[index].num_sect)
,pDrive->next_ext[index].end_head
,pDrive->next_ext[index].end_sect
,pDrive->total_head
,pDrive->total_sect);
}
error_code=Read_Physical_Sectors(physical_drive
,pDrive->next_ext[index].start_cyl
,pDrive->next_ext[index].start_head
,pDrive->next_ext[index].start_sect,1);
if(error_code!=0) return(error_code);
}
else index=24;
index++;
}while(index<24);
}
}
}
} /* while(drive<8); */
Determine_Drive_Letters();
Get_Partition_Information();
return(0);
}
/* Read_Physical_Sector */
int Read_Physical_Sectors(int drive, long cylinder, long head
, long sector, int number_of_sectors)
{
int error_code;
number_of_sectors=1;
if(flags.use_extended_int_13==FALSE)
{
error_code=Read_Physical_Sectors_CHS(drive,cylinder,head,sector,number_of_sectors);
}
else
{
error_code=Read_Physical_Sectors_LBA(drive,cylinder,head,sector,number_of_sectors);
}
#ifdef DEBUG
if(debug.read_sector==TRUE)
{
Clear_Screen(NULL);
Print_Centered(4,"Read_Physical_Sector() function debugging screen",BOLD);
printAt(4,10,"Information passed to this function:");
printAt(50,11,"Drive: 0x%X",drive);
printAt(50,12,"Cylinder: %d",cylinder);
printAt(50,13,"Head: %d",head);
printAt(50,14,"Sector: %d",sector);
printAt(4,16,"Contents of partition table area in sector_buffer[]:");
{
int index,offset,current_line = 0;
offset=0x1be;
do
{
index=0;
printAt(4,current_line+18,"%d: ",(current_line+1));
do
{
printf("%02X ",sector_buffer[(index+offset)]);
index++;
}while(index<16);
current_line++;
offset=offset+16;
}while(offset<(0x1be+64));
}
printAt(4,23,"Press any key to continue.");
asm{
mov ah,7
int 0x21
}
}
#endif
return(error_code);
}
/* Read physical sector using CHS values */
int Read_Physical_Sectors_CHS(int drive, long cylinder, long head
, long sector, int number_of_sectors)
{
int error_code;
if(number_of_sectors==1)
{
error_code=biosdisk(2, drive, (int)head, (int)cylinder, (int)sector, number_of_sectors, sector_buffer);
}
else
{
printf("sector != 1\n"); exit(1);
// error_code=biosdisk(2, drive, (int)head, (int)cylinder, (int)sector, number_of_sectors, huge_sector_buffer);
}
return(error_code);
}
/* Read a physical sector using LBA values */
int Read_Physical_Sectors_LBA(int drive, long cylinder, long head
, long sector, int number_of_sectors)
{
unsigned int error_code=0;
/* Get the segment and offset of disk_address_packet. */
unsigned int disk_address_packet_address_offset=FP_OFF(disk_address_packet);
/* Translate CHS values to LBA values. */
unsigned long LBA_address=Translate_CHS_To_LBA(cylinder,head,sector
,part_table[(drive-128)].total_head
,part_table[(drive-128)].total_sect);
/* Add number_of_sectors to disk_address_packet */
disk_address_packet[2]=number_of_sectors;
if(number_of_sectors==1)
{
*(void far **)(disk_address_packet+4)=sector_buffer;
}
else
{
printf("sector != 1\n"); exit(1);
// *(void far **)(disk_address_packet+4)=huge_sector_buffer;
}
/* Transfer LBA_address to disk_address_packet */
*(_u32*)(disk_address_packet+8) = LBA_address;
/* Load the registers and call the interrupt. */
asm {
mov ah,0x42
mov dl,BYTE PTR drive
mov si,disk_address_packet_address_offset
int 0x13
mov BYTE PTR error_code,ah
}
return(error_code);
}
/* Translate a CHS value to an LBA value. */
long Translate_CHS_To_LBA(unsigned long cylinder,unsigned long head
,unsigned long sector,unsigned long total_heads,unsigned long total_sectors)
{
return( ( (cylinder*(total_heads+1)+head)*total_sectors+sector-1) );
}
/* Write partition tables */
int Write_Partition_Tables()
{
int error_code;
int index;
int drive_index=0;
long extended_cylinder;
long extended_head;
long extended_sector;
for (drive_index = 0; drive_index < 7; drive_index++)
{
Partition_Table *pDrive = &part_table[drive_index];
if(pDrive->part_values_changed!=TRUE &&
flags.partitions_have_changed != TRUE)
{
continue; /* nothing done, continue with next drive */
}
index=0;
Clear_Sector_Buffer();
#ifdef DEBUG
if(debug.write==TRUE)
#endif
error_code=Read_Physical_Sectors((drive_index+0x80),0,0,1,1);
#ifdef DEBUG
else error_code=0;
#endif
if(error_code!=0) return(error_code);
Clear_Partition_Table_Area_Of_Sector_Buffer();
do
{
/* If this partition was just created, clear its boot sector. */
if(pDrive->pri_part_created[index]==TRUE)
{
Clear_Boot_Sector((drive_index+128),
pDrive->pri_part[index].start_cyl,
pDrive->pri_part[index].start_head,
pDrive->pri_part[index].start_sect);
}
if( (pDrive->pri_part[index].num_type==0x05)
|| (pDrive->pri_part[index].num_type==0x0f) )
{
extended_cylinder=pDrive->pri_part[index].start_cyl;
extended_head =pDrive->pri_part[index].start_head;
extended_sector =pDrive->pri_part[index].start_sect;
}
StorePartitionInSectorBuffer(§or_buffer[0x1be+index*16],
&pDrive->pri_part[index]);
index++;
}while(index<4);
/* Add the partition table marker values */
sector_buffer[0x1fe]=0x55;
sector_buffer[0x1ff]=0xaa;
error_code=Write_Physical_Sectors((drive_index+0x80),0,0,1,1);
if(error_code>0) return(error_code);
/* Write the Extended Partition Table, if applicable. */
if(pDrive->ptr_ext_part)
{
index=0;
do
{
/* If this logical drive was just created, clear its boot sector. */
if(pDrive->log_drive_created[index]==TRUE)
{
if (pDrive->log_drive[index].start_cyl != extended_cylinder)
{
printf("pDrive->log_drive[index].start_cyl (%lu) != extended_cylinder (%lu)",
pDrive->log_drive[index].start_cyl, extended_cylinder);
Pause();
}
Clear_Boot_Sector((drive_index+0x80),
pDrive->log_drive[index].start_cyl,
pDrive->log_drive[index].start_head,
pDrive->log_drive[index].start_sect);
}
Clear_Sector_Buffer();
/* Add the partition table marker values */
sector_buffer[0x1fe]=0x55;
sector_buffer[0x1ff]=0xaa;
StorePartitionInSectorBuffer(§or_buffer[0x1be],
&pDrive->log_drive[index]);
if(pDrive->next_ext_exists[index]==TRUE)
{
StorePartitionInSectorBuffer(§or_buffer[0x1be+16],
&pDrive->next_ext[index]);
}
error_code
=Write_Physical_Sectors((drive_index+0x80)
,extended_cylinder,extended_head,extended_sector,1);
if(error_code!=0) return(error_code);
if(pDrive->next_ext_exists[index]!=TRUE)
{
break;
}
extended_cylinder=pDrive->next_ext[index].start_cyl;
extended_head=pDrive->next_ext[index].start_head;
extended_sector=pDrive->next_ext[index].start_sect;
index++;
}while(index<23);
}
} /* for (drive_index) */
return(0);
}
/* Write physical sectors */
int Write_Physical_Sectors(int drive, long cylinder, long head, long sector, int number_of_sectors)
{
int error_code;
number_of_sectors=1;
if(part_table[(drive-128)].ext_int_13==FALSE)
{
error_code=Write_Physical_Sectors_CHS(drive,cylinder,head,sector,number_of_sectors);
}
else
{
error_code=Write_Physical_Sectors_LBA(drive,cylinder,head,sector,number_of_sectors);
}
return(error_code);
}
/* Write physical sectors using CHS format. */
int Write_Physical_Sectors_CHS(int drive, long cylinder, long head, long sector, int number_of_sectors)
{
int error_code;
#ifdef DEBUG
if(debug.write==TRUE)
{
#endif
if(number_of_sectors==1)
{
error_code=biosdisk(3, drive, (int)head, (int)cylinder, (int)sector, number_of_sectors, sector_buffer);
}
else
{
printf("sector != 1\n"); exit(1);
// error_code=biosdisk(3, drive, (int)head, (int)cylinder, (int)sector, number_of_sectors, huge_sector_buffer);
}
#ifdef DEBUG
}
#endif
#ifdef DEBUG
else
{
int current_line=0;
int index=0;
int offset=0x1be;
Clear_Screen(NULL);
Print_Centered(4,"Write_Physical_Sector_CHS() function debugging screen",BOLD);
printAt(6,6,"Note: WRITE=OFF is set or an emulated disk is in existence...no");
printAt(4,7," changes will be made. Please check the \"fdisk.ini\" file");
printAt(4,8," for details.");
printAt(4,10,"Information passed to this function:");
printAt(50,11,"Drive: 0x%X",drive);
printAt(50,12,"Cylinder: %d",cylinder);
printAt(50,13,"Head: %d",head);
printAt(50,14,"Sector: %d",sector);
printAt(4,16,"Contents of partition table area in sector_buffer[]:");
do
{
index=0;
printAt(4,current_line+18,"%d: ",(current_line+1));
do
{
printf("%02X ",sector_buffer[(index+offset)]);
index++;
}while(index<16);
current_line++;
offset=offset+16;
}while(offset<(0x1be+64));
printAt(4,23,"Press any key to continue.");
asm{
mov ah,7
int 0x21
}
error_code=0;
}
#endif
return(error_code);
}
/* Write physical sectors using LBA format. */
int Write_Physical_Sectors_LBA(int drive, long cylinder, long head, long sector, int number_of_sectors)
{
unsigned int error_code=0;
/* Get the segment and offset of disk_address_packet. */
unsigned int disk_address_packet_address_off=FP_OFF(disk_address_packet);
/* Translate CHS values to LBA values. */
unsigned long LBA_address=Translate_CHS_To_LBA(cylinder,head,sector
,part_table[(drive-128)].total_head
,part_table[(drive-128)].total_sect);
/* Determine the location of sector_buffer[512] */
/* and place the address of sector_buffer[512] into the DAP */
/* Add number_of_sectors to disk_address_packet */
disk_address_packet[2]=number_of_sectors;
if(number_of_sectors==1)
{
*(void far **)(disk_address_packet+4) = sector_buffer;
}
else
{
printf("sector != 1\n"); exit(1);
// *(void far **)(disk_address_packet+4) = huge_sector_buffer;
}
/* Transfer LBA_address to disk_address_packet */
*(_u32*)(disk_address_packet+8) = LBA_address;
#ifdef DEBUG
if(debug.write==TRUE)
{
#endif
/* Load the registers and call the interrupt. */
asm {
mov ah,0x43
mov al,0x00
mov dl,BYTE PTR drive
mov si,disk_address_packet_address_off
int 0x13
mov BYTE PTR error_code,ah
}
#ifdef DEBUG
}
#endif
#ifdef DEBUG
else
{
int current_line=0;
int index=0;
int offset=0x1be;
Clear_Screen(NULL);
Print_Centered(4,"Write_Physical_Sector_LBA() function debugging screen",BOLD);
printAt(4,6,"Note: WRITE=OFF is set or an emulated disk is in existence...no");
printAt(4,7," changes will be made. Please check the \"fdisk.ini\" file");
printAt(4,8," for details.");
printAt(4,10,"Information passed to this function:");
printAt(50,11,"Drive: 0x%X",drive);
printAt(50,12,"Cylinder: %d",cylinder);
printAt(50,13,"Head: %d",head);
printAt(50,14,"Sector: %d",sector);
printAt(4,16,"Contents of partition table area in sector_buffer[]:");
do
{
index=0;
printAt(4,current_line+18,"%d: ",(current_line+1));
do
{
printf("%02X ",sector_buffer[(index+offset)]);
index++;
}while(index<16);
current_line++;
offset=offset+16;
}while(offset<(0x1be+64));
printAt(4,23,"Press any key to continue.");
asm{
mov ah,7
int 0x21
}
error_code=0;
}
#endif
return(error_code);
}
void StorePartitionInSectorBuffer( char *sector_buffer,struct Partition *pPart)
{
sector_buffer[0x00]= pPart->active_status;
sector_buffer[0x01]= pPart->start_head;
*(_u16*)(sector_buffer+0x02) = Combine_Cylinder_and_Sector(
pPart->start_cyl,
pPart->start_sect);
sector_buffer[0x04]= pPart->num_type;
sector_buffer[0x05]= pPart->end_head;
*(_u16*)(sector_buffer+0x06) = Combine_Cylinder_and_Sector(
pPart->end_cyl,
pPart->end_sect);
*(_u32*)(sector_buffer+0x08) = pPart->rel_sect;
*(_u32*)(sector_buffer+0x0c) = pPart->num_sect;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -