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

📄 minito.c

📁 内含纯DOS,WIN32控制台和WIN32 GUI三个版本.它们生成的备份文件可以在任何版本中使用. WIN32 GUI版本暂使用备份功能(其他模块也都已全部写好,全是完整的,现在仅开启备份功能),如
💻 C
📖 第 1 页 / 共 5 页
字号:
		}Darg;
		
	   /*	char *pointerMinus=NULL,*pointerPlus=NULL;  */
		Darg deviceStr;

		
		memset(&deviceStr,0,sizeof(Darg));

	  if(minus)	doPointer=minus;
	  else if(plus) doPointer=plus;
	  else if(equal) doPointer=equal;
	  else doPointer=NULL;
		strncpy(deviceStr.device,str,(doPointer ? doPointer-str : strlen(str)+1));

		if(minus)
			deviceStr.startToDo=(*arg)->startToDo;
		if(plus)
			deviceStr.sectorToDo=(*arg)->sectorToDo;

		if(strchr(deviceStr.device,':')==NULL)
		{
			int index;
			char drive;
			
			if(!isNumber(deviceStr.device))
			{
				printf("Non-number found in %s\n",deviceStr.device);
				return -1;
			}
			else drive=atoi(deviceStr.device);
			
			if(getDriveItem(drive,driveTable,&index)==-1) return -1;
			
			if(deviceStr.startToDo>driveTable[index]->totalSector ||
				deviceStr.sectorToDo>driveTable[index]->totalSector ||
				deviceStr.startToDo+deviceStr.sectorToDo>driveTable[index]->totalSector)
			{
				printf("%lu + %lu = %lu > %lu (drive %d total sector)\n",
					deviceStr.startToDo,
					deviceStr.sectorToDo,
					deviceStr.startToDo+deviceStr.sectorToDo,
					driveTable[index]->totalSector,
					driveTable[index]->number);
				return -1;
			}
			
			(*arg)->argMode=ARGUMENT_DISK;
			(*arg)->drive=drive;
			(*arg)->index=index;
			(*arg)->totalSector=driveTable[index]->totalSector;
			(*arg)->startToDo=deviceStr.startToDo;
			(*arg)->sectorToDo=deviceStr.sectorToDo ?
				deviceStr.sectorToDo : driveTable[index]->totalSector-deviceStr.startToDo;
			
		}
		
		else
		{
			if(deviceStr.device[0]>48 && deviceStr.device[0]<58)
			{
				char driveStr[10];
				char drive;
				char partitionStr[10];
				char partition;
				char *p=strchr(deviceStr.device,':');
				int index;
				
				memset(driveStr,0,10);
				memset(partitionStr,0,10);
				strncpy(driveStr,deviceStr.device,p-(deviceStr.device));
				
				if(!isNumber(driveStr))
				{
					printf("Non-number found in %s\n",driveStr);
					return -1;
				}
				
				else drive=atoi(driveStr);

				strcpy(partitionStr,p+1);
				
				if(!isNumber(partitionStr))
				{
					printf("Non-number found in %s\n",partitionStr);
					return -1;
				}
				else partition=atoi(partitionStr);
				
				
				if(getPartitionItem(drive,partition,partitionTable,&index)==-1) return -1;
				
				if(deviceStr.startToDo>partitionTable[index]->total ||
					deviceStr.sectorToDo>partitionTable[index]->total ||
					deviceStr.startToDo+deviceStr.sectorToDo>partitionTable[index]->total)
				{
					printf("%lu + %lu = %lu > %lu (%d:%d total sector)\n",
					deviceStr.startToDo,
					deviceStr.sectorToDo,
					deviceStr.startToDo+deviceStr.sectorToDo,
					partitionTable[index]->total,
					partitionTable[index]->hardDrive,
					partitionTable[index]->number);
					return -1;
				}
				
				(*arg)->argMode=ARGUMENT_PARTITION;
				(*arg)->drive=drive;
				(*arg)->number=partition;
				(*arg)->index=index;
				(*arg)->totalSector=partitionTable[index]->total;
				(*arg)->startToDo=partitionTable[index]->start+deviceStr.startToDo;
				(*arg)->sectorToDo=deviceStr.sectorToDo ? 
					deviceStr.sectorToDo : partitionTable[index]->total-deviceStr.startToDo;
				
			}
			
			else
			{
				char letter;
				int index;
				
				
				letter=toupper(deviceStr.device[0]);
				
				if(letter<65 || letter>90)
				{
					printf("No such drive letter %c\n",deviceStr.device[0]);
					return -1;
				}
				
				if(strlen(deviceStr.device)!=2)
				{
					printf("Invalid DOS letter parameter: %s\n",deviceStr.device);
					return -1;
				}
				
				if(getPartitionItem(NULL,letter,partitionTable,&index)==-1) return -1;
				
				if(deviceStr.startToDo>partitionTable[index]->total ||
					deviceStr.sectorToDo>partitionTable[index]->total ||
					deviceStr.startToDo+deviceStr.sectorToDo>partitionTable[index]->total)
				{
					printf("%lu + %lu = %lu > %lu (%c: total sector)\n",
					deviceStr.startToDo,
					deviceStr.sectorToDo,
					deviceStr.startToDo+deviceStr.sectorToDo,
					partitionTable[index]->total,
					partitionTable[index]->letter);
					return -1;
				}
				
				(*arg)->argMode=ARGUMENT_DOSLETTER;
				(*arg)->drive=partitionTable[index]->hardDrive;
				(*arg)->number=partitionTable[index]->number;
				(*arg)->letter=letter;
				(*arg)->index=index;
				(*arg)->totalSector=partitionTable[index]->total;
				(*arg)->startToDo=partitionTable[index]->start+deviceStr.startToDo;
				(*arg)->sectorToDo=deviceStr.sectorToDo ? 
					deviceStr.sectorToDo : partitionTable[index]->total-deviceStr.startToDo;
				
			}
			
		}
		
		  }
		  
		  return 0;
}
/*
int refreshPartition_ACTIVE_ID(Pinfo *srcPartition, Pinfo *dstPartition)
{
	unsigned char pBuffer[512];
	int int13Return=0;
	
	memset(pBuffer,0,512);
	
	int13Return=extInt13(0x42,dstPartition->hardDrive+127,
		(dstPartition->logicDrive ? dstPartition->start-63 : 0),1,pBuffer);
	if(int13Return!=0)
 {
 int13Error(0x42,dstPartition->hardDrive+127,(dstPartition->logicDrive ? dstPartition->start-63 : 0),int13Return);
 return -1;
 }
	pBuffer[dstPartition->activeOffset]=srcPartition->active;
				pBuffer[dstPartition->IDoffset]=srcPartition->ID;
				int13Return=extInt13(0x43,dstPartition->hardDrive+127,
					(dstPartition->logicDrive ? dstPartition->start-63 : 0),1,pBuffer);
				if(int13Return!=0)
 {
 int13Error(0x43,dstPartition->hardDrive+127,(dstPartition->logicDrive ? dstPartition->start-63 : 0),int13Return);
 return -1;
 }
				return 0;
}
*/

int YesNo(char *s, char *filename)
{
	char str[8];
	printf("%s%s ? (Y/N)",s,filename);
	while(1)
	{
		fflush(stdin);
		gets(str);
		if(strcmpi(str,"Y")==0) return 1;
		if(strcmpi(str,"N")==0) return 0;
	}
}
int fopenFile(FILE **f, char rw, char *filename, char allVolumeEnd)
{
	char *prompt1="Opening",*fail1="open";
	char *prompt2="Creating",*fail2="create";
	char *pFront,*pDot;
	char bareName[16];
	char userChangeFile=0;
	while(1)
	{
		memset(bareName,0,16);
		if((pFront=strrchr(filename,'\\'))==NULL) pFront=strchr(filename,':');

		if(pFront) pFront+=1;
		else pFront=filename;

		pDot=strchr(filename,'.');
		if(!pDot) strcpy(bareName,pFront);
		else strncpy(bareName,pFront,pDot-pFront);

		if(strlen(bareName)>8)
		{
			printf("File bare name \"%s\" > 8\n",bareName);
			goto changeFile;
		}

		if(pDot && strlen(pDot+1)>3)
		{
			printf("File suffix name \"%s\" > 3\n",pDot+1);
			goto changeFile;
		}

		if(!rw)
		{
		*f=fopen(filename,"rb");
			if((*f)!=NULL)
			{
				fclose(*f);
				printf("\nFile \"%s\" exists, ",filename);
				if(YesNo("overwrite it","")!=1) goto changeFile;
				if(remove(filename)!=0)
				{
					printf("\nFailed to delete file \"%s\"\n",filename);
					goto changeFile;
				}
			}
		}

		*f=fopen(filename,(rw ? "rb" : "wb+"));
		if((*f)==NULL)
		{
			if(allVolumeEnd) return -2;
			else printf("\nFailed to %s file \"%s\"\n",(rw ? fail1 : fail2),filename);
		}
		else if(rw)
		{
			if(filelength(fileno(*f))==0)
				printf("\nFile \"%s\":\n0 bytes!\n",
				filename);
			else break;
		}
		else break;

		while(1)
		{
			unsigned char choose[128];
			memset(choose,0,128);
			printf("Change to another file, press C\nExit, press E\nC,E ?");
			fflush(stdin);
			scanf("%s",choose);
			if(strcmpi(choose,"C")==0) break;
			else if(strcmpi(choose,"E")==0) return -1;
		}

changeFile :
		printf("Enter a file name:>>");
		memset(filename,0,strlen(filename));
		scanf("%s",filename);
		userChangeFile=1;

	}
	if(userChangeFile) return -3;
	return 0;
}

/*#include "more.c" */
/*
extern unsigned char zlibMark[]/*="zlib-1.2.3.f-GOTOmsdos-grub2linux-v1.0";
extern unsigned char zlibKeyTRUE[]/*="zlib-GOTOmsdos-grub2linux-EncryptedTRUE";

extern int fopenFile(FILE **f, char rw, char *fileName, char allVolumeEnd);

extern void preCompress(char *zlibMark,
				 FILE *f,
				 char *zlibKey,
				 char *zlibKeyTRUE,
				 char compressKeyTRUE,
				 char compressKeyEveryAskTRUE,
				 char mute,
				 unsigned long freeSpace,
				 unsigned long *writtenSpace);

extern int checkFile(char *zlibMark,
			  FILE *f,
			  char *compressDecompress,
			  unsigned long *saveFileSize,
			  unsigned long *saveFileRealSize,
			  char *zlibKeyTRUE,
			  char *key,
			  char separatedVolume,
			  unsigned long sectorToDoVar,
			  char *fileName,
			  char mute);

extern int checkExtInt13(int driveNum);
extern int extInt13(unsigned int cmd,
					int driveNum,
					unsigned long startSector,
					unsigned int sectorToDo,
					char *buf);

extern void int13Error(int cmd, int drive, unsigned long start, int returnValue);
extern int int13DriveParameter(int driveNum,
						unsigned long *maxCylinder,
						unsigned long *maxHead,
						unsigned long *maxSector,
						unsigned long *totalSector);

extern int extInt13DriveParameter(int driveNum,
								  unsigned long *maxCylinder,
								  unsigned long *maxHead,
								  unsigned long *maxSector,
								  unsigned long *totalSector);
/*
extern int sectorToSector(int drive1,
						  unsigned long drive1_startToDoGiven,
						  unsigned long drive1_startSector,
						  int drive2,
						  unsigned long drive2_startToDoGiven,
						  unsigned long drive2_startSector,
						  unsigned long sectorToDo,
						  unsigned long *sectorDoneAll,
						  unsigned char *pBufferPar,
						  char *doSrcStr,
						  char *doDstStr,
						  char quiet,
						  char mute,
						  char ignoreReadError,
						  char ignoreWriteError,
						  char *errorSide);
*/


/*extern void takeFS(unsigned char ID, char *FS, char *hidden); */

char getDOSletterFromFileName(char *file)
{
char *p;
p=strchr(file,':');
if(p)
{
if(p-file!=1)
{
printf("\":\" invalid\n");
return 0;
}
return file[0];
}
else return getdisk()+65;
}

void savePrintPartitionTable(Pinfo *pInfo[], int drive, char *file, char mode, char pause, char yes)
{
short int driveNum=1;
unsigned long start=0;
int i,j,k,l,m;
unsigned char buf[512];
FILE *f=NULL;
/*=fopen(file,"wb+"); */
int int13Return;
char done=0;
unsigned char FAT_NTFS_ID[]={0x04,0x06,0x0B,0x0C,0x01,0x0E,
							 0x14,0x16,0x1B,0x1C,0x11,0x1E,
							 0x07,0x17,0x00};
unsigned long offsetAllRecord=0;
int lastSpare=0;
unsigned long sectorToSave=1;

if(mode==SAVE)
{
if(fopenFile(&f, 0, file, NULL)==-1) goto end;
fwrite(miniTOtag,strlen(miniTOtag),1,f);

}
 printf("Press ESC to exit...\n");

for(i=0,l=0;l<2;l++)
if(pInfo[l]->hardDrive==-127 || pInfo[l]->hardDrive==-126) i++;

for(m=0;pInfo[i];driveNum++)
{

if(!checkExtInt13(driveNum+127))
{
printf("Drive %d doesn't support int13 extension\n",driveNum+127);
while(pInfo[i] && pInfo[i]->hardDrive==driveNum) i++;
continue;
}
for(j=0,i-=1;pInfo[i+(j==0 ? 1 : 0)]->hardDrive==driveNum;i++,j++)
{

 int k;
 char FAT_NTFS=0;
 /*printf("[%d] ",i+1);  */

 if(bioskey(1)!=0)
{
			if(bioskey(0)==0x11B)
			{
				printf("\nStopped.\n");
				goto end;
			}
}
 if(drive && driveNum!=drive)
 {
 /*printf("continue..."); */
 continue;
 }

 if(j==0) start=0;
 else
 {
 /*if(pInfo[i]->logicDrive==0) /*continue; */
 for(k=0;FAT_NTFS_ID[k];k++)
 if(FAT_NTFS_ID[k]==pInfo[i]->ID) FAT_NTFS=1;

 if(!FAT_NTFS && !pInfo[i]->logicDrive) break;
 start=pInfo[i]->start-(pInfo[i]->logicDrive ? 63 : 0);
 }

 {
 int doLogicDrive=2;
 done=1;
 while(1)
 {

 int13Return=extInt13(0x42,
			 driveNum+127,
			 start,
			 1,
			 buf);

 if(int13Return!=0)
 {
 /*printf("Drive %d sector %lu\n",driveNum,start); */
 int13Error(0x42,driveNum+127,start,int13Return);
 goto skip;
 }

 if(mode==PRINT)
 {
 if(printByte(buf,512,0,&offsetAllRecord,pause,&lastSpare)==-1)
goto end;
 }
 else
 {

if(mode==SAVE && !yes)
			{
				printf("Save drive_%d sector_%-10lu 1 sector. ",driveNum,start);
				if(YesNo("Continue","")!=1) goto skip;
			}

 fwrite(&driveNum,2,1,f);
 fwrite(&start,4,1,f);
fwrite(&sectorToSave,2,1,f);
 fwrite(buf,512,1,f);
 }

 m++;

 if(mode==SAVE && !yes)
 printf("Saved drive:%d sector:%-10lu 1 sector\n",driveNum,start);
 /*l++;  */
 skip :
 if(j!=0 && FAT_NTFS && pInfo[i]->logicDrive==1) doLogicDrive--;
 if(j==0 || !FAT_NTFS || pInfo[i]->logicDrive==0 || doLogicDrive==0) break;
 else start=pInfo[i]->start;


 }
 }

}
if(driveNum==drive) break;

}

end :


if(!done) printf("No found\n");
else if(mode==SAVE) printf("Saved %d sectors in all\n",m);

if(f) fclose(f);

}

void restoreComparePrintPartitionTable(short int drive, char *file, char mode, char pause, char yes)
{
short int driveNum;
short int currentDrive;
short int supportExtInt13;
unsigned long start=0;
int i,j,l=0;
unsigned long readf,all;
unsigned char *buf=NULL;
unsigned char *diskBuf=NULL;
FILE *f=NULL;/*=fopen(file,"rb"); */
int int13Return;
unsigned long diff=0;
unsigned long oldDiff=0;
/*unsigned long offsetAllRecord=0; */
char done=0;
unsigned long offsetAllRecord=0;
int lastSpare=0;
unsigned long sectorToRestore=0;
unsigned long sectorDone=0;

/*if(fopenFile(&f, 1, file, NULL)==-1) goto end;   */

char checkFile[32];

if(fopenFile(&f, 1, file, NULL)==-1) goto end;
memset(checkFile,0,32);
fread(checkFile,strlen(miniTOtag),1,f);
if(strnicmp(miniTOtag,checkFile,strlen(miniTOtag))!=0)
{
	printf("Invalid drive file");
	return -1;
}


driveNum=(drive ? drive : 1);
all=filelength(fileno(f));

buf=(char *)mallo

⌨️ 快捷键说明

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