📄 minitow.c
字号:
unsigned long *maxHead,
unsigned long *maxSectorPerTrack,
unsigned long *totalSector,
char ignoreHDDparameter)
{
short result;
char buffer[512];
char device[32];
memset(device,0,32);
strcpy(device,"\\\\.\\PHISICALDRIVE\0");
sprintf(device+strlen(device),"%d",0);
*supportExtInt13=/*checkExtInt13(drive+127);*/1;
/* printf("passed\n"); */
if(*supportExtInt13)
{
/*if(ignoreHDDparameter) return 0;*/
return extInt13(0x42,
drive+127,
0,
1,
buffer);
/*
if(CreateFile(device,0,FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0)!=INVALID_HANDLE_VALUE)
return 0;*/
}
else return -1;
}
void getDriveTable(Dinfo *driveTable[], char useFloppy, char ignoreHDDparameter)
{
short i,j,k;
short floppy;
short hard;
for(i=0,j=0,k=1,floppy=-127,hard=1;j<MAX_DRIVE_NUM-2;j++,floppy++)
{
driveTable[i]=(Dinfo *)malloc(sizeof(Dinfo));
memset(driveTable[i],0,sizeof(Dinfo));
if(useFloppy || floppy>-126) floppy=0;
if(getDrive((floppy ? floppy : hard++),
&(driveTable[i]->supportExtInt13),
&(driveTable[i]->maxCylinder),
&(driveTable[i]->maxHead),
&(driveTable[i]->maxSectorPerTrack),
&(driveTable[i]->totalSector),
ignoreHDDparameter)==-1)
{
if(driveTable[i]) free(driveTable[i]);
driveTable[i]=NULL;
if(!floppy) break;
else continue;
}
else
{
if(floppy)
{
driveTable[i]->floppy=1;
driveTable[i]->number=floppy;
}
else driveTable[i]->number=k++;
i++;
}
}
}
short getDriveItem(char drive,
Dinfo *driveTable[],
short *driveIndex)
{
short i=0;
*driveIndex=INVALID_INDEX;
if(driveTable[0]==NULL)
{
printf("No drive\n");
return -1;
}
while(1)
{
if(driveTable[i]==NULL)
{
printf("No drive %d\n",drive);
return -1;
}
if(driveTable[i]->number==drive) break;
i++;
}
*driveIndex=i;
return 0;
}
short putInDrivePartNum(Dinfo *driveTable[], Pinfo *partitionTable[])
{
int i,j;
for(i=0,j=0;driveTable[i];i++)
if(driveTable[i]->number>0)
{
for(;partitionTable[j] && driveTable[i]->number==partitionTable[j]->hardDrive;j++)
driveTable[i]->part++;
/*if(driveTable[i]->number==partitionTable[j]->hardDrive)
{
part++;
if(partitionTable[j+1] && driveTable[i]->number!=partitionTable[j+1]->hardDrive)
{
driveTable[i]->part=part;
j++;
break;
}
}*/
}
return 0;
}
short printDrive(Dinfo *driveTable[], Pinfo *partitionTable[], short index)
{
short i=0,j=0;
if(index==INVALID_INDEX) return -1;
else if(index==PRINT_DRIVE_ALL || index==PRINT_DRIVE_FLOPPY) i=0;
else /*if(index!=PRINT_DRIVE_FLOPPY) */i=index;
/*if(driveTable==NULL)
{
printf("No drive\n");
return -1;
} */
/*printf("%d",index);*/
if(driveTable[0]==NULL)
{
printf("No drive\n");
return -1;
}
if(driveTable[0] && driveTable[i]==NULL)
{
printf("No drive %d\n",driveTable[i]->number);
return -1;
}
printf("\n DRIVE PARTITIONS CYLINDER HEAD SECTOR ALL SECTOR CAPACITY\n");
for(;driveTable[i]/*!=NULL*/;i++)
{
unsigned long GB=0;
unsigned long MB=0;
short part=0;
if(index==PRINT_DRIVE_FLOPPY)
{
if(driveTable[i]->number!=-127 && driveTable[i]->number!=-126)
break;
}
if(driveTable[i]->totalSector/2/1024/1024>=1)
GB=driveTable[i]->totalSector/2/1024/1024;
else MB=driveTable[i]->totalSector/2/1024;
/*printf("[%-2d] ",i+1); */
/*driveTable[i]->number*/
if(driveTable[i]->number==-127 || driveTable[i]->number==-126)
printf(" FLOPPY ");
else printf(" %-6d ",driveTable[i]->number);
/* printf("%c ",(driveTable[i]->supportExtInt13 ? '*' : ' ')); */
/* if(driveTable[i]->number>0)
{
for(;partitionTable[j];j++)
{
if(driveTable[i]->number==partitionTable[j]->hardDrive)
{
part++;
if(partitionTable[j+1] && driveTable[i]->number!=partitionTable[j+1]->hardDrive)
{
j++;
break;
}
}
}
printf("%-10d ",part);
}
else printf("%10s ","");*/
printf("%-10d ",driveTable[i]->part);
printf("%-10lu %-8lu %-8lu ",
driveTable[i]->maxCylinder,
driveTable[i]->maxHead,
driveTable[i]->maxSectorPerTrack);
printf("%-10lu ",driveTable[i]->totalSector);
(GB ? printf("%-4lu GB\n",GB) : printf("%-4lu MB\n",MB));
if(index!=PRINT_DRIVE_ALL) break;
}
return 0;
}
/*
short getFATlabel(Pinfo *part, unsigned char *buf)
{
unsigned short fat1216=*(unsigned short *)(buf+0x16);
unsigned long fat32=*(unsigned long *)(buf+0x24);
memset(part->label,0,12);
if((strnicmp(buf+0x36,"FAT12",5)==0 || strnicmp(buf+0x36,"FAT16",5)==0) && fat1216)
strncpy(part->label,buf+0x2B,11);
else if(strnicmp(buf+0x52,"FAT32",5)==0 && fat32) strncpy(part->label,buf+0x47,11);
else return -1;
return 0;
}
short getFATvol(Pinfo *part, unsigned char *buf)
{
unsigned long reservedSector=*(unsigned short *)(buf+0xE);
char FATcount=buf[0x10];
/* 获取FAT所占的扇区数
unsigned long FATsector=0;
unsigned short fat1216=*(unsigned short *)(buf+0x16);
unsigned long fat32=*(unsigned long *)(buf+0x24);
unsigned long fat1216TotalFileItem=0;
unsigned long startClusterForFirstCluster=0;
unsigned long sectorsPerCluster=0;
unsigned long volSearchTime=0;
unsigned long posToSearch=0;
unsigned char *buf2=NULL;
char foundVol;
unsigned long j,k;
short returnValue;
char fat32TRUE;
if((strnicmp(buf+0x36,"FAT16",5)==0 || strnicmp(buf+0x36,"FAT12",5)==0) && fat1216) fat32TRUE=0;
else if(strnicmp(buf+0x52,"FAT32",5)==0 && fat32) fat32TRUE=1;
else return -1;
if(fat32TRUE)
{
if(fat32) FATsector=fat32;
/* printf("This is FAT32. Sector number per FAT is %lu.\n",*FATsector);
}
else /* 如果是 FAT16
{
if(fat1216) FATsector=fat1216;
/* printf("This is FAT16. Sector number per FAT is %lu.\n",*FATsector);
}
if(!FATsector) return -1;
if(FATcount>2) return -1;
if(reservedSector+FATsector*FATcount>part->total) return -1;
posToSearch=part->start+reservedSector+FATsector*FATcount;
volSearchTime=MAX_FAT32_VOL_SEARCH;
if(fat32TRUE)
{
startClusterForFirstCluster=*(unsigned long *)(buf+0x2C);
sectorsPerCluster=buf[0x0D];
if(startClusterForFirstCluster>part->total) startClusterForFirstCluster=2;
if(sectorsPerCluster>64) sectorsPerCluster=64;
posToSearch+=(startClusterForFirstCluster-2UL)*sectorsPerCluster;
}
buf2=(unsigned char *)malloc(51200);
foundVol=0;
for(j=0;j<volSearchTime;j++)
{
if(part->hardDrive<0)
{
if (absread(part->hardDrive+127, 100, posToSearch, buf2) != 0)
{
/* printf("Failed to read %c:\n",part[i]->letter);
return -1;
}
}
else
{
if(returnValue=extInt13(0x42,part->hardDrive+127,posToSearch,100,buf2))
return -1;
}
posToSearch+=100;
for(k=0;k<(/*fat1216 ? fat1216TotalFileItem*2 : 16*200);)
{
if((buf2[11+16*k]==(unsigned char)0x08 || buf2[11+16*k]==(unsigned char)0x28) &&
*(unsigned long *)(buf2+12+16*k)==0 &&
*(unsigned short *)(buf2+26+16*k)==0 &&
*(unsigned long *)(buf2+28+16*k)==0)
{
memset(part->label,0,12);
strncpy(part->label,buf2+(16*k),11);
foundVol=1;
break;
}
/*if(fat1216) k+=2;
else k++;
}
if(foundVol) break;
}
if(buf2) free(buf2);
return 0;
}
short getFATlabelVol(Pinfo *part[], char vol)
{
unsigned char buf[512];
short i,j,k;
char fatTRUE=0;
char fat32TRUE=0;
unsigned short fat1216=0;
unsigned short fat32=0;
unsigned char fat[]={0x04,0x06,0x0B,0x0C,0x01,0x0E,
0x14,0x16,0x1B,0x1C,0x11,0x1E,0x00};
char labelVolTRUE=0;
Pinfo *partForVol;
unsigned char *bufForVol;
char foundVol=0;
int(* pFunc1)();
int(* pFunc2)();
for(i=0;part[i];i++)
{
fatTRUE=0;
if(part[i]->hardDrive<0)
{
if (absread(part[i]->hardDrive+127, 1, 0, buf) != 0)
{
/* printf("Failed to read %c:\n",part[i]->letter);
continue;
}
}
else
{
if(extInt13(0x42,part[i]->hardDrive+127,part[i]->start,1,buf)!=0) continue;
}
if(part[i]->ID==0x07 || part[i]->ID==0x17)
part[i]->volumeSerialNumber=*((unsigned long *)(buf+0x48));
for(j=0;fat[j];j++)
{
if(part[i]->ID==fat[j])
{
fatTRUE=1;
break;
}
}
if(!fatTRUE) continue;
fat1216=*(unsigned short *)(buf+0x16);
fat32=*(unsigned long *)(buf+0x24);
if((strnicmp(buf+0x36,"FAT16",5)==0 || strnicmp(buf+0x36,"FAT12",5)==0) && fat1216) fat32TRUE=0;
else if(strnicmp(buf+0x52,"FAT32",5)==0 && fat32) fat32TRUE=1;
else /*return -1;continue;
part[i]->volumeSerialNumber=*(unsigned long *)(buf+(fat32TRUE ? 0x43 : 0x27));
if(!vol)
{
pFunc1=getFATlabel;
pFunc2=getFATvol;
}
else
{
pFunc1=getFATvol;
pFunc2=getFATlabel;
}
/* if((*pFunc1)(part[i],buf)) continue;
partForVol=part[i];
bufForVol=buf;
if((*pFunc1)(partForVol,bufForVol)) continue;
labelVolTRUE=0;
for(j=0;j<11;j++)
{
if(part[i]->label[j])
{
labelVolTRUE=1;
break;
}
}
if(!vol && labelVolTRUE)
{
if(/*strcmpi(part[i]->label,"NO NAME ")==0 ||
strstr(strupr(part[i]->label),"NO NAME"))
labelVolTRUE=0;
}
if(!labelVolTRUE)
{
(*pFunc2)(partForVol,bufForVol);
}
}
return 0;
}
*/
extern void putInDOSletter(Pinfo *part[]);
void getPartitionTable(Dinfo *driveTable[], Pinfo *partP[])
{
short drive,i,j,k,l;
unsigned char pBuffer[512];
short int13Return=0;
for(l=0,j=0,drive=-127;driveTable[l] && drive<=-126;drive++)
{
if(driveTable[l]->floppy)
{
partP[j]=(Pinfo *)malloc(sizeof(Pinfo));
memset(partP[j],0,sizeof(Pinfo));
/* partP[j]->totalNumber=j+1; */
partP[j]->hardDrive=drive;
partP[j]->number=1;
partP[j]->ID=0x01;
partP[j]->start=0;
partP[j]->total=driveTable[j]->totalSector;
l++;
j++;
}
}
for(drive=1/*,j=0*/;driveTable[l] && drive<MAX_DRIVE_NUM+1;l++,drive++)
{
memset(pBuffer,0,512);
int13Return=extInt13(0x42,drive+127,0,1,pBuffer);
if(int13Return!=0)
{
/* int13Error(0x42,int13Return); */
if(drive==MAX_DRIVE_NUM) break;
else continue;
}
for(i=0,k=1;i<4;i++)
{
unsigned char active=*(unsigned char *)(pBuffer+0x01BE+i*0x10);
unsigned char ID=*(unsigned char *)(pBuffer+0x01C2+i*0x10);
unsigned long start=*(unsigned long *)(pBuffer+0x01C6+i*0x10);
unsigned long total=*(unsigned long *)(pBuffer+0x01CA+i*0x10);
if(start==0 || total==0)
{
if(i==0)
{
printf("Drive %d partition table error!\n",drive);
break;
}
else continue;
}
if(ID!=0x05 && ID!=0x0F)
{
partP[j]=(Pinfo *)malloc(sizeof(Pinfo));
memset(partP[j],0,sizeof(Pinfo));
/* partP[j]->totalNumber=j+1; */
partP[j]->hardDrive=drive;
partP[j]->number=k;
partP[j]->logicDrive=0;
partP[j]->active=active;
partP[j]->activeOffset=0x01BE+i*0x10;
partP[j]->ID=ID;
partP[j]->IDoffset=0x01C2+i*0x10;
partP[j]->start=start;
partP[j]->total=total;
j++;
k++;
}
else
{
unsigned char active;
unsigned char ID;
unsigned long startLogic;
unsigned long total;
unsigned char pBuffer[512];
unsigned long nextExtended=0,size;
while(1)
{
/* printf("reading sector %lu...\n",start+nextExtended); */
int13Return=extInt13(0x42,drive+127,start+nextExtended,1,pBuffer);
/* printf("passed\n"); */
if(int13Return!=0)
{
/* int13Error(0x42,int13Return); */
break;
}
active=*(unsigned char *)(pBuffer+0x01BE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -