📄 pdiskio.c
字号:
/* of physical sectors returned from service 0x48. */
number_of_physical_sectors = *(_u32*)(result_buffer+16);
total_cylinders=((number_of_physical_sectors/total_sectors)/(total_heads+1));
/* If the number of cylinders calculated using service 0x48 is in error,*/
/* use the total cylinders reported by service 0x08. */
if(legacy_total_cylinders>total_cylinders)
total_cylinders=legacy_total_cylinders;
}
/* Check for an extra cylinder */
if(flags.check_for_extra_cylinder==TRUE)
{
if(0==Read_Physical_Sectors(physical_drive,(total_cylinders)
,total_heads,total_sectors,1))
total_cylinders++;
}
pDrive->total_cyl=total_cylinders;
return(0);
}
/* Get the volume labels and file system types from the boot sectors */
void Get_Partition_Information()
{
int drivenum;
int partnum;
int label_offset;
/* First get the information from the primary partitions. */
for (drivenum = 0; drivenum <8; drivenum++)
{
Partition_Table *pDrive = &part_table[drivenum];
for (partnum=0; partnum < 4; partnum++)
{
strcpy(pDrive->pri_part[partnum].vol_label," ");
/* Check for and get the volume label on a FAT12/FAT16 partition. */
if(IsRecognizedFatPartition(pDrive->pri_part[partnum].num_type))
{
if (pDrive->pri_part[partnum].num_type == 11 ||
pDrive->pri_part[partnum].num_type == 12 )
{
label_offset = 71;
}
else
{
label_offset = 43;
}
Read_Physical_Sectors((drivenum+128)
,pDrive->pri_part[partnum].start_cyl
,pDrive->pri_part[partnum].start_head
,pDrive->pri_part[partnum].start_sect,1);
if( sector_buffer[label_offset+10]>=32 &&
sector_buffer[label_offset+10]<=122 )
{
/* Get Volume Label */
memcpy(pDrive->pri_part[partnum].vol_label,
sector_buffer+label_offset,
11);
}
}
} /* primary partitions */
/* Get the information from the extended partitions. */
for (partnum=0; partnum < 23; partnum++)
{
strcpy(pDrive->log_drive[partnum].vol_label," ");
if(IsRecognizedFatPartition(pDrive->log_drive[partnum].num_type))
{
if (pDrive->log_drive[partnum].num_type == 11 ||
pDrive->log_drive[partnum].num_type == 12 )
{
label_offset = 71;
}
else
{
label_offset = 43;
}
Read_Physical_Sectors((drivenum+128)
,pDrive->log_drive[partnum].start_cyl
,pDrive->log_drive[partnum].start_head
,pDrive->log_drive[partnum].start_sect,1);
if( sector_buffer[label_offset+10]>=32 &&
sector_buffer[label_offset+10]<=122 )
{
/* Get Volume Label */
memcpy(pDrive->log_drive[partnum].vol_label,
sector_buffer+label_offset,
11);
}
}
} /* while(partnum<23); */
}/* while(drivenum<8);*/
}
/* Initialize the LBA Structures */
void Initialize_LBA_Structures()
{
/* Initialize the Disk Address Packet */
/* ---------------------------------- */
memset(disk_address_packet,0,sizeof(disk_address_packet));
/* Packet size = 16 */
disk_address_packet[0]=16;
/* Reserved, must be 0 */
disk_address_packet[1]=0;
/* Number of blocks to transfer = 1 */
disk_address_packet[2]=1;
/* Reserved, must be 0 */
disk_address_packet[3]=0;
/* Initialize the Result Buffer */
/* ---------------------------- */
/* Buffer Size = 26 */
result_buffer[0]=26;
}
/* Load the brief_partition_table[8] [27] */
void Load_Brief_Partition_Table()
{
int drivenum;
int partnum;
for (drivenum=0; drivenum < 8; drivenum++)
{
Partition_Table *pDrive = &part_table[drivenum];
/* Load the primary partitions into brief_partition_table[8] [27] */
for (partnum=0; partnum < 4; partnum++)
{
brief_partition_table[drivenum] [partnum]=pDrive->pri_part[partnum].num_type;
}
/* Load the extended partitions into brief_partition_table[8] [27] */
for (partnum=0; partnum < 23; partnum++)
{
brief_partition_table[drivenum] [partnum+4]=
pDrive->log_drive[partnum].num_type;
}
}/*while(drivenum<8);*/
}
/* Load the Partition Tables and get information on all drives */
int Read_Partition_Tables()
{
int drive;
int error_code=0;
int index;
int entry_offset;
int physical_drive;
flags.more_than_one_drive=FALSE;
for (drive = 0; drive < 8; drive++)
{
Partition_Table *pDrive = &part_table[drive];
physical_drive=drive+0x80;
/* Get the hard drive parameters and ensure that the drive exists. */
error_code=Get_Hard_Drive_Parameters(physical_drive);
/* If there was an error accessing the drive, skip that drive. */
/* If this drive is emulated, then load the emulation values instead. */
if( (error_code==0)
#ifdef DEBUG
&& (debug.emulate_disk!=(drive+1) )
#endif
)
{
/* Pre-compute the total size of the hard drive */
/* */
pDrive->total_hard_disk_size_in_log_sect
=(pDrive->total_cyl+1)
*(pDrive->total_head+1)
*pDrive->total_sect;
pDrive->total_hard_disk_size_in_MB
= Convert_Cyl_To_MB((pDrive->total_cyl+1)
, pDrive->total_head+1
, pDrive->total_sect);
}
else
{
#ifdef DEBUG
if(debug.emulate_disk==(drive+1) )
{
/* If this is an emulated drive, set it up. */
if( (flags.version==FOUR)
|| (flags.version==FIVE)
|| (flags.version==SIX) )
{
#pragma warn -ccc
#pragma warn -rch
if(EMULATED_CYLINDERS>1023)
pDrive->total_cyl=1023;
#pragma warn +ccc
#pragma warn +rch
}
else
{
pDrive->total_cyl=EMULATED_CYLINDERS;
}
pDrive->total_head=EMULATED_HEADS;
pDrive->total_sect=EMULATED_SECTORS;
pDrive->total_hard_disk_size_in_log_sectors
=(pDrive->total_cyl+1)
*(pDrive->total_head+1)
*pDrive->total_sect;
pDrive->total_hard_disk_size_in_MB
= Convert_Cyl_To_MB((pDrive->total_cyl+1)
, pDrive->total_head+1
, pDrive->total_sect);
flags.maximum_drive_number=drive+128;
if(drive>0) flags.more_than_one_drive=TRUE;
}
else
{
#endif
if(drive==0)
{
cprintf("\n No fixed disks present.\n");
exit(6);
}
pDrive->total_cyl=0;
pDrive->total_head=0;
pDrive->total_sect=0;
#ifdef DEBUG
}
#endif
}
/* Clear the partition_table_structure structure. */
pDrive->pri_part_largest_free_space=0;
pDrive->pp_largest_free_space_start_cyl=0;
pDrive->pp_largest_free_space_start_head=0;
pDrive->pp_largest_free_space_start_sect=0;
pDrive->pp_largest_free_space_end_cyl=0;
index=0;
do
{
memset(&pDrive->pri_part[index],0,sizeof(pDrive->pri_part[0]));
pDrive->pri_part_created[index]=FALSE;
index++;
}while(index<4);
Clear_Extended_Partition_Table(drive);
/* Read the Primary Partition Table. */
if(error_code==0)
{
error_code=Read_Physical_Sectors(physical_drive,0,0,1,1);
if(error_code!=0) return(error_code);
flags.maximum_drive_number=drive+128;
if(drive>0) flags.more_than_one_drive=TRUE;
index=0;
do
{
entry_offset=0x1be+(index*16);
pDrive->pri_part[index].active_status=sector_buffer[(entry_offset+0x00)];
pDrive->pri_part[index].num_type=sector_buffer[(entry_offset+0x04)];
if(pDrive->ext_int_13==FALSE)
{
/* If int 0x13 extensions are not used get the CHS values. */
pDrive->pri_part[index].start_cyl =Extract_Cylinder(sector_buffer[(entry_offset+0x02)],sector_buffer[(entry_offset+0x03)]);
pDrive->pri_part[index].start_head =sector_buffer[(entry_offset+0x01)];
pDrive->pri_part[index].start_sect =Extract_Sector(sector_buffer[(entry_offset+0x02)],sector_buffer[(entry_offset+0x03)]);
pDrive->pri_part[index].end_cyl=Extract_Cylinder(sector_buffer[(entry_offset+0x06)],sector_buffer[(entry_offset+0x07)]);
pDrive->pri_part[index].end_head=sector_buffer[(entry_offset+0x05)];
pDrive->pri_part[index].end_sect=Extract_Sector(sector_buffer[(entry_offset+0x06)],sector_buffer[(entry_offset+0x07)]);
}
pDrive->pri_part[index].rel_sect=
*(_u32*)(sector_buffer+entry_offset+0x08);
pDrive->pri_part[index].num_sect=
*(_u32*)(sector_buffer+entry_offset+0x0c);
if( (pDrive->ext_int_13==TRUE)
&& (pDrive->pri_part[index].num_type!=0) )
{
/* If int 0x13 extensions are used compute the virtual CHS values. */
/* The head number is 0 unless the cyl is 0...then the head is 1. */
if(pDrive->pri_part[index].rel_sect==pDrive->total_sect)
{
pDrive->pri_part[index].start_head=1;
}
else pDrive->pri_part[index].start_head=0;
pDrive->pri_part[index].start_sect=1;
pDrive->pri_part[index].start_cyl
=Extract_Cylinder_From_LBA_Value(
pDrive->pri_part[index].rel_sect
,pDrive->pri_part[index].start_head
,pDrive->pri_part[index].start_sect
,pDrive->total_head
,pDrive->total_sect);
pDrive->pri_part[index].end_head=pDrive->total_head;
pDrive->pri_part[index].end_sect=pDrive->total_sect;
pDrive->pri_part[index].end_cyl
=Extract_Cylinder_From_LBA_Value(
/* */
(pDrive->pri_part[index].rel_sect
+pDrive->pri_part[index].num_sect)
,pDrive->pri_part[index].end_head
,pDrive->pri_part[index].end_sect
,pDrive->total_head
,pDrive->total_sect);
}
pDrive->pri_part[index].size_in_MB
= Convert_Cyl_To_MB(
(pDrive->pri_part[index].end_cyl - pDrive->pri_part[index].start_cyl +1)
, pDrive->total_head+1
, pDrive->total_sect);
/* Record the necessary information to easilly and quickly find the */
/* extended partition when it is time to read it. */
if( (pDrive->pri_part[index].num_type==0x05)
|| ( (pDrive->pri_part[index].num_type==0x0f)
&& ( (flags.version==W95) || (flags.version==W95B)
|| (flags.version==W98) ) ) )
{
pDrive->ptr_ext_part = &pDrive->pri_part[index];
pDrive->ext_part_num_sect=pDrive->pri_part[index].num_sect;
pDrive->ext_part_size_in_MB=pDrive->pri_part[index].size_in_MB;
}
index++;
}while(index<4);
/* Read the Extended Partition Table, if applicable. */
if(pDrive->ptr_ext_part)
{
error_code=Read_Physical_Sectors(
physical_drive,
pDrive->ptr_ext_part->start_cyl
,pDrive->ptr_ext_part->start_head,
pDrive->ptr_ext_part->start_sect,1);
if(error_code!=0) return(error_code);
/* Ensure that the sector has a valid partition table before */
/* any information is loaded into pDrive-> */
if( (sector_buffer[0x1fe]==0x55) && (sector_buffer[0x1ff]==0xaa) )
{
index=0;
do
{
entry_offset=0x1be;
if(sector_buffer[(entry_offset+0x04)]>0)
pDrive->num_of_log_drives++;
pDrive->log_drive[index].num_type
=sector_buffer[(entry_offset+0x04)];
if(pDrive->ext_int_13==FALSE)
{
/* If int 0x13 extensions are not used get the CHS values. */
pDrive->log_drive[index].start_cyl=Extract_Cylinder(sector_buffer[(entry_offset+0x02)],sector_buffer[(entry_offset+0x03)]);
pDrive->log_drive[index].start_head=sector_buffer[(entry_offset+0x01)];
pDrive->log_drive[index].start_sect=Extract_Sector(sector_buffer[(entry_offset+0x02)],sector_buffer[(entry_offset+0x03)]);
pDrive->log_drive[index].end_cyl=Extract_Cylinder(sector_buffer[(entry_offset+0x06)],sector_buffer[(entry_offset+0x07)]);
pDrive->log_drive[index].end_head=sector_buffer[(entry_offset+0x05)];
pDrive->log_drive[index].end_sect=Extract_Sector(sector_buffer[(entry_offset+0x06)],sector_buffer[(entry_offset+0x07)]);
}
pDrive->log_drive[index].rel_sect=
*(_u32*)(sector_buffer+entry_offset+0x08);
pDrive->log_drive[index].num_sect=
*(_u32*)(sector_buffer+entry_offset+0x0c);
if( (pDrive->ext_int_13==TRUE)
&& (pDrive->log_drive[index].num_type!=0) )
{
/* If int 0x13 extensions are used compute the virtual CHS values. */
/* The head number is 0 unless the cyl is 0...then the head is 1. */
if(pDrive->log_drive[index].rel_sect==pDrive->total_sect)
{
pDrive->log_drive[index].start_head=1;
}
else pDrive->log_drive[index].start_head=0;
pDrive->log_drive[index].start_sect=1;
if(index==0)
pDrive->log_drive[index].start_cyl
=Extract_Cylinder_From_LBA_Value(
(pDrive->log_drive[index].rel_sect
+pDrive->ptr_ext_part->rel_sect)
,pDrive->log_drive[index].start_head
,pDrive->log_drive[index].start_sect
,pDrive->total_head
,pDrive->total_sect);
else
pDrive->log_drive[index].start_cyl
=Extract_Cylinder_From_LBA_Value(
(pDrive->log_drive[index].rel_sect
+pDrive->ptr_ext_part->rel_sect
+pDrive->next_ext[index-1].rel_sect)
,pDrive->log_drive[index].start_head
,pDrive->log_drive[index].start_sect
,pDrive->total_head
,pDrive->total_sect);
pDrive->log_drive[index].end_head=pDrive->total_head;
pDrive->log_drive[index].end_sect=pDrive->total_sect;
if(index==0)
pDrive->log_drive[index].end_cyl
=Extract_Cylinder_From_LBA_Value(
(pDrive->log_drive[index].rel_sect
+pDrive->ptr_ext_part->rel_sect
+pDrive->log_drive[index].num_sect)
,pDrive->log_drive[index].end_head
,pDrive->log_drive[index].end_sect
,pDrive->total_head
,pDrive->total_sect);
else
pDrive->log_drive[index].end_cyl
=Extract_Cylinder_From_LBA_Value(
(pDrive->log_drive[index].rel_sect
+pDrive->ptr_ext_part->rel_sect
+pDrive->log_drive[index].num_sect
+pDrive->next_ext[index-1].rel_sect)
,pDrive->log_drive[index].end_head
,pDrive->log_drive[index].end_sect
,pDrive->total_head
,pDrive->total_sect);
}
pDrive->log_drive[index].size_in_MB
= Convert_Cyl_To_MB(
(pDrive->log_drive[index].end_cyl - pDrive->log_drive[index].start_cyl +1)
, pDrive->total_head+1
, pDrive->total_sect);
entry_offset=entry_offset+16;
if(sector_buffer[(entry_offset+0x04)]==0x05)
{
pDrive->next_ext_exists[index]=TRUE;
pDrive->next_ext[index].num_type=sector_buffer[(entry_offset+0x04)];
if(pDrive->ext_int_13==FALSE)
{
/* If int 0x13 extensions are not used get the CHS values. */
pDrive->next_ext[index].start_cyl =Extract_Cylinder(sector_buffer[(entry_offset+0x02)],sector_buffer[(entry_offset+0x03)]);
pDrive->next_ext[index].start_head =sector_buffer[(entry_offset+0x01)];
pDrive->next_ext[index].start_sect =Extract_Sector(sector_buffer[(entry_offset+0x02)],sector_buffer[(entry_offset+0x03)]);
pDrive->next_ext[index].end_cyl =Extract_Cylinder(sector_buffer[(entry_offset+0x06)],sector_buffer[(entry_offset+0x07)]);
pDrive->next_ext[index].end_head =sector_buffer[(entry_offset+0x05)];
pDrive->next_ext[index].end_sect =Extract_Sector(sector_buffer[(entry_offset+0x06)],sector_buffer[(entry_offset+0x07)]);
}
pDrive->next_ext[index].rel_sect =*(_u32*)(sector_buffer+entry_offset+0x08);
pDrive->next_ext[index].num_sect =*(_u32*)(sector_buffer+entry_offset+0x0c);
if( (pDrive->ext_int_13==TRUE)
&& (pDrive->next_ext[index].num_type!=0) )
{
/* If int 0x13 extensions are used compute the virtual CHS values. */
pDrive->next_ext[index].start_head=0;
pDrive->next_ext[index].start_sect=1;
/* */
pDrive->next_ext[index].start_cyl
=Extract_Cylinder_From_LBA_Value(
(pDrive->next_ext[index].rel_sect
+pDrive->ptr_ext_part->rel_sect)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -