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

📄 minitow.c

📁 内含纯DOS,WIN32控制台和WIN32 GUI三个版本.它们生成的备份文件可以在任何版本中使用. WIN32 GUI版本暂使用备份功能(其他模块也都已全部写好,全是完整的,现在仅开启备份功能),如
💻 C
📖 第 1 页 / 共 5 页
字号:
	{
		memset(digit,0,16);
		doPointer=digit;
		if(plus)
			strncpy(digit,minus+1,plus-minus-1);
		else
		{
			if(equal)
				strncpy(digit,minus+1,equal-minus-1);
			else doPointer=minus+1;
		}
		
		if(!isNumber(doPointer))
		{
			printf("Non-number found in %s\n",doPointer);
			return -1;
		}
		(*arg)->startToDo=strtoul(doPointer,NULL,10);
		
	}
	
	
		  if((*arg)->startToDo)
		  {
			  (*arg)->startToDoTRUE=1;
			  (*arg)->startToDoGiven=(*arg)->startToDo;
		  }
		  if((*arg)->sectorToDo) (*arg)->sectorToDoTRUE=1;
		  /*
		  printf("(");
		  exit(0);  */
		  if(str[0]=='(')
		  {
			  
			  char killBracket[256];
			  char *fileArg[10];
			  short index=INVALID_INDEX;
			  short i;
			  char *plus;
			  char *minus;
			  char *equal;
			  char *end;  
			  char *qmin[4];
			  (*arg)->argMode=ARGUMENT_IMAGE;
			  
			  memset(killBracket,0,256);
			  for(i=0;i<10;i++)
				  fileArg[i]=NULL;
			  
			  
			  if((end=strchr(str,')'))==NULL)
			  {
				  printf("No \")\" found\n");
				  return -1;
			  }
			  
			  
			  strncpy(killBracket,str+1,strchr(str,')')-str-1);
			  extractFromStr(killBracket,'=',fileArg);
			  
			  strcpy((*arg)->name,fileArg[0]);
			  
			  if(strchr((*arg)->name,':'))
			  {
				  if((*arg)->name[0])	(*arg)->letter=(*arg)->name[0];
				  else
				  {
					  printf("No drive in %s\n",(*arg)->name);
					  
					  return -1;
				  }
			  }
			  
			  else
			  {
				  char buf[MAXPATH];
				  buf[0]='\0';
				  getcwd(buf,MAXPATH);
				  if(buf[0]) (*arg)->letter=buf[0];
				  else printf("Problem occured getting current working directory\n");
			  }
			  
			  getPartitionItem(NULL,(*arg)->letter,partitionTable,&index,win);
			  (*arg)->drive=partitionTable[index]->hardDrive;
			  (*arg)->number=partitionTable[index]->number;
			  
			  
			  for(i=1;fileArg[i];i++)
			  {
				  
				  if(toupper(fileArg[i][0])=='C')
				  {
					  (*arg)->compressDecompress=1;
					  if(strlen(fileArg[i])>1) (*arg)->compressLevel=atoi(&fileArg[i][1]);
					  else (*arg)->compressLevel=DEFAULT_COMPRESS_LEVEL;
				  }
				  
				  else if(toupper(fileArg[i][0])=='K') (*arg)->keyTRUE=1;
				  
				  else if(toupper(fileArg[i][0])=='V')
				  {
					  (*arg)->separatedVolume=1;
					  if(strlen(fileArg[i])>1)  (*arg)->separatedMB=strtoul(&fileArg[i][1],NULL,10);
					  else (*arg)->separatedMB=DEFAULT_EVERY_VOLUME_MB;
				  }
				  
				  else if(toupper(fileArg[i][0])=='E')
				  {
					  
					  if(!((*arg)->compressDecompress) || !((*arg)->keyTRUE) || !((*arg)->separatedVolume))
					  {
						  printf("E needs C K V\n");
						  return -1;
					  }
					  
					  (*arg)->keyEveryTRUE=1;
					  if(fileArg[i][1]=='?') (*arg)->keyEveryPromptTRUE=1;
					  
				  }
				  
			  }
			  
		  }
		  
		  else
		  {
			  typedef struct _deviceArg
			  {
				  char device[10];
				  unsigned long startToDo;
				  unsigned long sectorToDo;
			  }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)
			  {
				  short 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,':');
					  short 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,win)==-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;
					  short 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,win)==-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;
					  
					  if(win) (*arg)->WINletter=letter;
					  else (*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;
}


short 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;
	}
}
short 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;
}


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

void savePrintPartitionTable(Pinfo *pInfo[], short drive, char *file, char mode, char pause, char yes)
{
	short  driveNum=1;
	unsigned long start=0;
	short i,j,k,l,m;
	unsigned char buf[512];
	FILE *f=NULL;
	/*=fopen(file,"wb+"); */
	short 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;
	short 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");*/
printf("Working...\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++)
		{
			
			for(j=0,i-=1; pInfo[i+(j==0 ? 1 : 0)] && pInfo[i+(j==0 ? 1 : 0)]->hardDrive==driveNum;i++,j++)
			{
				
				short k;
				char FAT_NTFS=0;
				
				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);
				}
				
				{
					short 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;
						
			/*printf("pInfo[%d] drive=%d part=%d start=%lu\n",i,pInfo[i]->hardDrive,pInfo[i]->number,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  drive, char *file, char mode, char pause, char yes)
{
	short  driveNum;
	short  currentDrive;
	/*short  supportExtInt13=0;*/
	unsigned long start=0;
	short i,j,l=0;
	unsigned long readf,all;
	unsigned char *buf=NULL;
	unsigned char *diskBuf=NULL;
	FILE *f=NULL;/*=fopen(file,"rb"); */
	short int13Return;
	unsigned long diff=0;

⌨️ 快捷键说明

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