⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mini.c

📁 内含纯DOS,WIN32控制台和WIN32 GUI三个版本.它们生成的备份文件可以在任何版本中使用. WIN32 GUI版本暂使用备份功能(其他模块也都已全部写好,全是完整的,现在仅开启备份功能),如
💻 C
📖 第 1 页 / 共 5 页
字号:
unsigned long startSector, */
commonArg *arg,
unsigned short *reservedSectorBeforeFAT,
unsigned long *FATsector,
char *FATcount)
{
	char buffer[512]; /* 存放 DBR 的缓冲 */
	char fat12TRUE=0;
	char fat16TRUE=0;
	char fat32TRUE=0;
	unsigned short fat1216=0;
	unsigned long fat32=0;
	/*char fat32TRUE=1; */
	short int13Return;
	short drive=0;
	unsigned long start=0;
	
	drive=arg->drive;
	start=partitionTable[arg->index]->start;
	/*	}    */
	/*获取DBR,以便 获取FAT参数 */
	/*biosdisk(2,hardDisk,1,0,1,1,buffer); */
	
	if(drive==-127 || drive==-126)
	{
		if (absread(drive+127, 1, start, buffer) != 0)
		{
			printf("Failed to read %c: sector:%lu\n",(drive==-127 ? 'A' : 'B'),start);
			return -1;
		}
	}
	else
	{
		int13Return=extInt13(0x42,
			drive+127,
			start,
			1,
			buffer);
		
		if(int13Return!=0)
		{
			int13Error(0x42,drive+127,start,int13Return);
			return -1;
		}
	}	/* 获取FAT前距离DBR的扇区数 */
	
	
	*reservedSectorBeforeFAT=*(unsigned short *)(buffer+0xE);
	*FATcount=buffer[0x10];
	/* 获取FAT所占的扇区数 */
	fat1216=*(unsigned short *)(buffer+0x16);
	fat32=*(unsigned long *)(buffer+0x24);
	
	if(fat1216)
	{
		if(strnicmp(buffer+0x36,"FAT12",5)==0) fat12TRUE=1;
		if(strnicmp(buffer+0x36,"FAT16",5)==0) fat16TRUE=1;
	}
	else if(strnicmp(buffer+0x52,"FAT32",5)==0 && fat32) fat32TRUE=1;
	else
	{
		printf("Invalid FAT.\n");
		return 0;
	}
	if(fat32TRUE) /* 如果是 FAT32 */*FATsector=fat32;
	   /*	printf("This is FAT32. Sector number per FAT is %lu.\n",*FATsector);
	*/
	
	/* 如果是 FAT16 */
	else *FATsector=fat1216;
	   /*	printf("This is FAT16. Sector number per FAT is %lu.\n",*FATsector);
	*/
	if(fat12TRUE) return 1;
	else if(fat16TRUE) return 2;
	else if(fat32TRUE) return 3;
	
	else return 0;
	
}


UINT /*void*/  doDPTDBRFAT(LPVOID p/*Pinfo **partitionTable, commonArg *arg, char mode, char target, char *file, char pause, char compress, char level, char yes)
						   */){
						   
						   CMiniGUIDlg *p2=(CMiniGUIDlg *)p;

Pinfo **partitionTable=p2->argu.partitionTable;
commonArg *arg=p2->argu.mainArg;
char mode=p2->argu.mode; 
char target=p2->argu.target;
char *file=p2->argu.fileStr;
char pause=p2->argu.pause;
char compress=p2->argu.compress;
char level=p2->argu.level;
char yes=p2->argu.yesTRUE;



char zlibKey[256];

unsigned long fileSize=0;
unsigned long doLen=0;
unsigned long dstLen=MAX_BUF_BYTE;

/*char *dst=NULL;   */
unsigned long allCompressed=0;

char compressKeyTRUE=1;
char compressKeyEveryAskTRUE=1;

unsigned long fileRealSize;

char noUse=1;
char mute=0;

char fat[]={0x04,0x06,0x0B,0x0C,0x01,0x0E,
0x14,0x16,0x1B,0x1C,0x11,0x1E,0x00};
char fat32[]={0x0B,0x0C,0x1B,0x1C,0x00};
char ntfs[]={0x07,0x17,0x00};
short i,j=0;
short drive;
unsigned long startToDo,startToDo2;

char *sharedBuf=NULL,*oneSide=NULL;

unsigned long sectorToDo=0;
FILE *f=NULL;
/*char read=1,write=0; */
unsigned short reservedSectorBeforeFAT=0;
unsigned long sectorDone=0;
unsigned short doSector=120;
unsigned long diff=0;
unsigned long offsetAllRecord=0;
short int13Return;
char FS[16];
char hidden=0;
char compressVar=0;
char result=0;
char done=0;
unsigned long freeSpaceKB=0;
unsigned long writtenSpace=0;
short x,y;
char gif[]={'-','\\','|','/','-','\\','|','/','\0'};
char FATcount=0;
short DBRbackupPos=0;
char DBRwarning[128];
char fat32TRUE=0;
/*unsigned long offsetAllRecord=0; */
short lastSpare=0;
CString report1,report2;

p2->start=true;

/*((CProgressCtrl *)p2->GetDlgItem(IDC_PROGRESS1))->SetRange(0,65535);*/
((CProgressCtrl *)p2->GetDlgItem(IDC_PROGRESS1))->SetPos(0);

if(mode==SAVE || mode==RESTORE || mode==COMPARE || (mode==PRINT && target==PRINTFILE))
{
	if(fopenFile(&f, (mode==SAVE ? 0 : 1), file, NULL)==-1) goto end;
if(mode==SAVE) fwrite(miniTOtag,strlen(miniTOtag),1,f);
}

sharedBuf=(char *)malloc(MAX_BUF_BYTE);
if(mode==COMPARE/* || compress || compressVar*/) oneSide=(char *)malloc(MAX_BUF_BYTE);

if(mode==SAVE || mode==REPLACE || (mode==PRINT && (target==DPT || target==DBR || target==FAT)))
{
	
	if(mode==SAVE)
	{
		
	/*if(getDiskFree(partitionTable, getDOSletterFromFileName(file), &freeSpaceKB)==-1)
		goto end;*/
	}
	drive=arg->drive;
	/*printf("%d\n",arg->drive); */
	if(target==DPT)
	{
		if(arg->argMode==ARGUMENT_DISK) startToDo=0;
		else
		{
			if(!partitionTable[arg->index]->logicDrive) startToDo=0;
			else startToDo=partitionTable[arg->index]->start-63;
		}
	}
	
	
	if(target==DBR)
	{
		for(i=0;fat[i];i++)
		{
			if(partitionTable[arg->index]->ID==fat[i]) goto out;
		}
		for(j=0;ntfs[j];j++)
		{
			if(partitionTable[arg->index]->ID==ntfs[j]) goto out;
		}
out :
		if(!fat[i] && !ntfs[j])
		{
			printf("Not FAT/NTFS, no DBR\n");
			p2->MessageBox("Not FAT/NTFS, no DBR");
			goto end;
		}
		
		if(mode==REPLACE)
		{
			
			for(i=0;fat32[i];i++)
				if(partitionTable[arg->index]->ID==fat32[i]) fat32TRUE=1;
				if(!fat32TRUE)
				{
					printf("Not FAT32, no DBR backup\n");
					p2->MessageBox("Not FAT32, no DBR backup");
					goto end;
				}
		}
		
		i=0;
		j=0;
		
		startToDo=partitionTable[arg->index]->start;
	}
	
	if(target==DPT || target==DBR) sectorToDo=1;
	
	if(target==FAT)
	{
		
		for(i=0;fat[i];i++)
		{
			
			if(partitionTable[arg->index]->ID==fat[i]) break;
			else if(!fat[i+1])
			{
				printf("Not FAT\n");
				p2->MessageBox("Not FAT");
				goto end;
			}
		}
		if(!getFATinfo(partitionTable,arg,&reservedSectorBeforeFAT,&sectorToDo,&FATcount))
			goto end;
		if(mode==REPLACE && FATcount!=2)
		{
			printf("FAT count %d is not normal 2\n",FATcount);
			
			goto end;
		}
		printf("Sector number per FAT is %lu\n",sectorToDo);
		
		startToDo=partitionTable[arg->index]->start+reservedSectorBeforeFAT;
		if(startToDo==0 || sectorToDo==0)
		{
			goto end;
		}
	}
	
	/* printf("2\n"); */
	if(mode==SAVE)
	{
	/*
	if(freeSpaceKB<(sectorToDo*512+8)/1024UL)
	{
				
				  printf("Space needed : %lu bytes\n  Free space : %lu bytes\nNo enough space\n",
				  (sectorToDo*512+8)/1024UL,freeSpaceKB);
				  goto end;
	}*/
	/*	fwrite(&drive,2,1,f);
		fwrite(&startToDo,4,1,f);
		fwrite(&sectorToDo,2,1,f);*/
		/*} */
	}
	
 }
 
 else
 {
	 fread(&drive,2,1,f);
	 fread(&startToDo,4,1,f);
	 fread(&sectorToDo,2,1,f);
	 /*}   */
 }
 
 
 
 /*x=wherex();
 y=wherey();*/
 
 

 
 startToDo2=startToDo;
 /*printf("Press ESC to exit...\n");*/
 printf("Working...\n");

/*
if(!yes)			 	 
 {

	 switch(mode)
	 {
	 case SAVE : report1="Save "; break;
	 case RESTORE : report1="Restore "; break;
	 case REPLACE : report1="Replace "; break;
	 case COMPARE : report1="Compare "; break;
	 }
				 
	 
report2.Format("drive_%d sector_%lu %lu sectors ",drive,startToDo,sectorToDo);
if(p2->MessageBox(report1+report2+"?",NULL,MB_YESNO)!=IDYES) goto end;				 
 }
*/
report1.Format("总任务是 %lu 个扇区。",sectorToDo);
p2->MessageBox(report1);

 while(sectorDone<sectorToDo)
 {
	 
 /*
 if(p2->pause==true)
 {
	while(p2->pause==true);
	
	  
 }*/

 
	 if(p2->stop == true) 
	 {
		 ((CProgressCtrl *)p2->GetDlgItem(IDC_PROGRESS1))->SetPos(0);
		 
		 /*	p2->Stop==false;*/
		 goto end;
		 
	 }
	 
	 if(sectorToDo-sectorDone<doSector) doSector=sectorToDo-sectorDone;
	 
	 
if(!yes)
{

switch(mode)
{
case SAVE : report1="保存 "; break;
case RESTORE : report1="恢复 "; break;
case REPLACE : report1="替换 "; break;
case COMPARE : report1="Compared "; break;
}

/*	report2.Format("drive_%d sector_%-10lu %-10lu sectors %s\n",drive,startToDo2,sectorDone,(mode==COMPARE ? "with file" : ""));
*/
report2.Format("%s 第 %d 硬盘 第 %lu 扇区 %u 个扇区吗?",report1,drive,startToDo,doSector);
	if(p2->MessageBox(report2,NULL,MB_YESNO)!=IDYES) 
	{
		sectorToDo-=doSector;
		continue;
	}

}

	 dstLen=MAX_BUF_BYTE;
	 


	 
	 if(mode==SAVE || mode==COMPARE || mode==REPLACE || (mode==PRINT && target!=PRINTFILE))
	 {
		 
		 int13Return=extInt13(0x42,
			 drive+127,
			 startToDo+((mode==REPLACE && target==FAT) ? sectorToDo : 0),
			 doSector,
			 sharedBuf);
		 /* printf("%d %lu\n",drive,startToDo); */
		 if(int13Return!=0)
		 {
			 int13Error(0x42,drive+127,startToDo,int13Return);
			 goto end;
		 }
		 
		 if(mode==SAVE) 
		 {
			 
			 fwrite(&drive,2,1,f);
			 fwrite(&startToDo,4,1,f);
			 fwrite(&doSector,2,1,f);
			 
			 fwrite(sharedBuf,doSector*512,1,f);
		 }
		 if(mode==PRINT)
		 {
		 /*if(printByte(sharedBuf,doSector*512,0,&offsetAllRecord,pause,&lastSpare)==-1)
			 goto end;*/
		 }
		 if(mode==REPLACE && target==DBR)
		 {
			 DBRbackupPos=*(unsigned short *)(sharedBuf+0x32);
			 
			 if(DBRbackupPos!=6)
			 {
				 memset(DBRwarning,0,128);
				 if(DBRbackupPos==0)
				 {
					 DBRbackupPos=6;
					 sprintf(DBRwarning,
						 "Invalid DBR backup sector position 0, not normal 6\nDo it as 6");
				 }
				 else
					 sprintf(DBRwarning,
					 "DBR backup sector position %d is not normal 6\nDo it as %d",
					 DBRbackupPos,DBRbackupPos);
				 /*if(YesNo(DBRwarning,"")!=1) goto end;*/
if(p2->MessageBox(CString(DBRwarning)+"?",NULL,MB_YESNO)!=IDYES) goto end;	
				 
			 }
			 
		 }
		 
	 }
	 
	 if(mode==RESTORE ||/* mode==COMPARE ||*/ mode==REPLACE || (mode==PRINT && target==PRINTFILE))
	 {
		 
	 /*if(mode==RESTORE || mode==REPLACE)
		 {   */
		 
		 if(mode==RESTORE || mode==PRINT) 
		 {
			 
			 fread(sharedBuf,doSector*512,1,f);
		 }
		 
		 if(mode==REPLACE && target==DBR)
		 {
			 int13Return=extInt13(0x42,
				 drive+127,
				 startToDo+DBRbackupPos,
				 doSector,
				 sharedBuf);
			 /* printf("%d %lu\n",drive,startToDo); */
			 if(int13Return!=0)
			 {
				 int13Error(0x42,drive+127,startToDo,int13Return);
				 goto end;
			 }
		 }
		 
		 if(mode==RESTORE || mode==REPLACE)
		 {
			 
			 
			 int13Return=extInt13(0x43,
				 drive+127,
				 startToDo,
				 doSector,
				 /*((mode==RESTORE && compressVar) ? oneSide : */sharedBuf/*)*/);
				 if(int13Return!=0)
				 {
					 int13Error(0x43,drive+127,startToDo,int13Return);
					 goto end;
				 }
		 }
		 
		 else
		 {
			 
		 }
		 /*}  */
	 }
	 
	 if(mode==COMPARE)
		 /*else  */
	 {
		 
		 
		 
		 /*if(!compressVar) */fread(oneSide,doSector*512,1,f);
		 
		 
		 /*getch();  */
		 if(compareByte(sharedBuf,oneSide,doSector*512,pause,&diff,&offsetAllRecord)==-1)
			 break;
		 done=1;
		 
		 
	 }


sectorDone+=doSector;
((CProgressCtrl *)p2->GetDlgItem(IDC_PROGRESS1))->SetPos(sectorDone*65535/sectorToDo);

	 
if(!yes)
{	 	 
	 switch(mode)
{
case SAVE : report1="保存了 "; break;
case RESTORE : report1="恢复了 "; break;
case REPLACE : report1="替换了 "; break;
case COMPARE : report1="Compared "; break;
}

/*	report2.Format("drive_%d sector_%-10lu %-10lu sectors %s\n",drive,startToDo2,sectorDone,(mode==COMPARE ? "with file" : ""));
*/
report2.Format("%s 第 %d 硬盘 第 %lu 扇区 %u 个扇区。",report1,drive,startToDo,doSector);

	p2->MessageBox(report2);

}

startToDo+=doSector;
	 
}
end :

/*
printf("drive_%d sector_%-10lu %-10lu sectors %s\n",drive,startToDo2,sectorDone,(mode==COMPARE ? "with file" : ""));
*/

switch(mode)
{
case SAVE : report1="保存了 "; break;
case RESTORE : report1="恢复了 "; break;
case REPLACE : report1="替换了 "; break;
case COMPARE : report1="Compared "; break;
}

/*	report2.Format("drive_%d sector_%-10lu %-10lu sectors %s\n",drive,startToDo2,sectorDone,(mode==COMPARE ? "with file" : ""));
*/
report2.Format("总共%s %lu 个扇区。",report1,sectorDone);
	p2->MessageBox(report2);


if(mode==COMPARE && done) printf("\n%lu differences found\n",diff);

if(f) fclose(f);
if(sharedBuf) free(sharedBuf);
if(oneSide) free(oneSide);

p2->start=false;
p2->finish=1;
return 0;
}





short DOSletterPartitionConverter(Dinfo *driveTable[], Pinfo *partitionTable[], char *str,char win)
{
	
	commonArg *arg=NULL;
	short index=INVALID_INDEX;
	if(!str) return -1;
	
	arg=(commonArg *)malloc(sizeof(commonArg));
	if(getCommonArgFromArg(str,
		driveTable,
		partitionTable,
		&arg,
		win)==-1)
		return -1;
	
	if(!arg) return -1;
	
	
	if(arg->argMode==ARGUMENT_PARTITION)
	{
		if(getPartitionItem(arg->drive,arg->number,partitionTable,&index,win)==-1)
			return -1;
		if(index==INVALID_INDEX) return -1;
		if(win ? partitionTable[index]->WINletter : partitionTable[index]->letter) printf("%c:",toupper(win ? partitionTable[index]->WINletter : partitionTable[index]->letter));
		else return -1;
	}
	else if(arg->argMode==ARGUMENT_DOSLETTER)
	{
		if(arg->drive>0 && arg->number)
			printf("%d:%d",arg->drive,arg->number);
		else return -1;
	}
	else return -1;
	
	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -