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

📄 scan.c

📁 嵌入式系统中文件系统源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
  if ((options & INTERACTIVE) == INTERACTIVE)
  {
	printString("[FILE] {");
	printString((char *)pathname);
	printString("\\");
	printString((char *)entry->name);
	printString("} ");
  }
*/
  curBlock = entry->startBlock;

  // check block list and the sizes occupied
  while (curBlock != NULL)
  {
  	/* marked by chilong 9/27/2001
	if (RD_checkBlockLocation(curBlock) == -1)
	{
		// block address out of bound
		FileErrCount++;

		if ((options & INTERACTIVE) == INTERACTIVE)
		{
			sprintf(strTemp, "[FILE] {%s\\%s} [INVALID BLOCK ADDRESS/SIZE]", pathname, entry->name);

			//if (RDOutput == TO_SERIAL_PORT)
			//	SprintStringLn(strTemp);
			//else
			//	printStringLn(strTemp);

			RD_showMessage(strTemp);
		}

		if ((options & AUTOFIX) == AUTOFIX)
		{
			if (prevBlock == NULL)
			{
				// the 1st block is out of bound
				// simply delete the file
				entry->name[0] = DELETED_ENTRY;
			}
			else
			{
				// blocks after the 1st block of the file is out of bound
				// cut off the out-of-bound blocks
				prevBlock->nextBlock = NULL;
				entry->fsize = fileSize;
			}
		}

		//else
		//{
		//	if ((options & INTERACTIVE) == INTERACTIVE)
		//		printStringLn("");
		//}
		
		*totalFileSize += fileSize;
		*totalCompressSize += compressSize;
		return totalSize;
	}
  	   marked by chilong 9/27/2001 */

	/**** modified by chilong 9/27/2001 ****/
	if (RD_checkBlockLocation(curBlock) == -1)
		bBlockErr = 1;
	else if (RD_checkBlockChecksum(curBlock) == -1)
		bBlockErr = 2;
	
	if (bBlockErr != 0)
	{
		// !! Note: no matter it's a block address error or data error,
		//	we'll delete this file and related blocks
		//	if the fix flag is set
		
		// block address out of bound or data error
		FileErrCount++;

		if (bBlockErr == 1)
		{
			// block address error
			if ((options & INTERACTIVE) == INTERACTIVE)
			{
				sprintf(strTemp, "[FILE] {%s\\%s} [INVALID BLOCK ADDRESS/SIZE]", pathname, entry->name);
				RD_showMessage(strTemp);
			}

			if ((options & AUTOFIX) == AUTOFIX)
			{
				// blocks after the 1st block of the file is out of bound
				prevBlock->nextBlock = NULL;
			}
		}
		
		// start deleting the file
		if ((options & AUTOFIX) == AUTOFIX)
		{
			// !!Note: 
			//	1. if this is a block address errro,
			//	we can only assure that the chained blocks
			//	before prevBlock could be recycled. Those
			//	blocks after prevBlock will be a memory waste
			//	and won't be recycled until next warm-reset.
			
			//	2. if this is a block data error, we can clean 
			//	the file entirely
			tmpBlock = entry->startBlock;
			while (tmpBlock != NULL)
			{
				/**** added by chilong 01/10/2002 ****/
				if (RD_checkBlockLocation(tmpBlock) == -1)
					break;
				/**** added by chilong 01/10/2002 ****/
				
				RD_freeCurrentBlocks(tmpBlock);
				tmpBlock = tmpBlock->nextBlock;
			}	
			RD_freeBlockLink(entry->startBlock);
			entry->name[0] = DELETED_ENTRY;
		
			fileSize = 0;
			totalSize = 0;
			compressSize = 0;

			if ((options & INTERACTIVE) == INTERACTIVE)
			{
				sprintf(strTemp, "        FIXED!");
				RD_showMessage(strTemp);
			}
		}
		
		*totalFileSize += fileSize;
		*totalCompressSize += compressSize;
		return totalSize;
	}
	/**** modified by chilong 9/27/2001 ****/
	

#ifdef RAMDISK_USE_VARIABLE_SIZE_BLOCK
	totalSize += (curBlock->size + B_HEADER + B_TAIL);
#else
	totalSize += RDSystemBlockSize;
#endif

	fileSize += curBlock->actualSize;
	compressSize += curBlock->dataSize;

	prevBlock = curBlock;
	curBlock = (struct diskBlock *)curBlock->nextBlock;
  }

  // check file size
  if (fileSize != entry->fsize)
  {
	// file size does not match
	FileErrCount++;
	if ((options & INTERACTIVE) == INTERACTIVE)
	{
		sprintf(strTemp, "[FILE] {%s\\%s} [INVALID FILE SIZE] %d/%d", pathname, entry->name, fileSize, entry->fsize);
/*
		if (RDOutput == TO_SERIAL_PORT)
			SprintStringLn(strTemp);
		else
			printStringLn(strTemp);
*/
		RD_showMessage(strTemp);
	}

	if ((options & AUTOFIX) == AUTOFIX)
	{
		// update file size
		entry->fsize = fileSize;
		if ((options & INTERACTIVE) == INTERACTIVE)
		{
			sprintf(strTemp, "        FIXED!");
/*
			if (RDOutput == TO_SERIAL_PORT)
				SprintStringLn(strTemp);
			else
				printStringLn(strTemp);
*/
			RD_showMessage(strTemp);
		}
	}
/*
	else
	{
		if ((options & INTERACTIVE) == INTERACTIVE)
			printStringLn("");
	}
*/
  }
  else
  {
	if ((options & INTERACTIVE) == INTERACTIVE)
	{
		sprintf(strTemp, "[FILE] {%s\\%s} [OK]", pathname, entry->name);
/*
		if (RDOutput == TO_SERIAL_PORT)
			SprintStringLn(strTemp);
		else
			printStringLn(strTemp);
*/
		RD_showMessage(strTemp);
	}
  }

  *totalFileSize += fileSize;
  *totalCompressSize += compressSize;

  return totalSize;
}



/*************************************************************
Fuction : RD_checkDir
	Check the integrity of a dir
Input:
	options - interactive? auto-fix?
	target - the directory information of the directory being checked
	strTemp - a string buffer
Output:
	totalFileSize - the total size of the files
	totalCompressSize - the total compressed size of the files
Return value:
	  -1: system error
	else; the total RAMDisk memory size taken by the dir excluding its sub-dirs
**************************************************************/
long RD_checkDir(char options, struct scanDir *targetDir, long *totalFileSize, long *totalCompressSize, char *strTemp)
{
  long totalSize = 0;
  long status;
  struct diskBlock *curBlock;
  struct diskBlock *prevBlock;
  struct directory *curEntry;
  struct scanDir *curDir;
  int i, j;
  char noMore = 0;
  unsigned char *filename;

  curBlock = targetDir->startBlock;

  // check dir
  while (curBlock != NULL)
  {
	if (RD_checkBlockLocation(curBlock) == -1)
	{
		// directory block out of bound
		FileErrCount++;

		// directory block out of bound
		if ((options & INTERACTIVE) == INTERACTIVE)
		{
			sprintf(strTemp, "[DIR]  {%s\\} [LINK ERROR]", targetDir->pathName);
/*
			if (RDOutput == TO_SERIAL_PORT)
				SprintStringLn(strTemp);
			else
				printStringLn(strTemp);
*/
			RD_showMessage(strTemp);
		}

		if ((options & AUTOFIX) == AUTOFIX)
		{
			if (prevBlock == NULL)
			{
				if (targetDir->theEntry == NULL)
				{
					// the 1st block of the root dir is dead, can't fix
					if ((options & INTERACTIVE) == INTERACTIVE)
					{
						sprintf(strTemp, "        ROOT corrupted. Impossible to fix!");
/*
						if (RDOutput == TO_SERIAL_PORT)
							SprintStringLn(strTemp);
						else
							printStringLn(strTemp);
*/
						RD_showMessage(strTemp);
					}
					RDerrno = ERROR_FILE_SYSTEM;
					return -1;
				}
				else
				{
					// the 1st block of a sub-dir is dead
					(targetDir->theEntry)->startBlock = NULL;
					if ((options & INTERACTIVE) == INTERACTIVE)
					{
						sprintf(strTemp, "        FIXED!");
/*
						if (RDOutput == TO_SERIAL_PORT)
							SprintStringLn(strTemp);
						else
							printStringLn(strTemp);
*/
						RD_showMessage(strTemp);
					}
					return 0;
				}
				
			}
			else
			{
				prevBlock->nextBlock = NULL;
				if ((options & INTERACTIVE) == INTERACTIVE)
				{
					sprintf(strTemp, "        FIXED!");
/*
					if (RDOutput == TO_SERIAL_PORT)
						SprintStringLn(strTemp);
					else
						printStringLn(strTemp);
*/
					RD_showMessage(strTemp);
				}
				return totalSize;
			}
		}
/*
		else
			printStringLn("");
*/
	}
		
	// one more block
#ifdef RAMDISK_USE_VARIABLE_SIZE_BLOCK
	totalSize += (B_HEADER + curBlock->size + B_TAIL);
#else
	totalSize += RDSystemBlockSize;
#endif

	curEntry = (struct directory *)((unsigned long)curBlock + sizeof(struct diskBlock));

	// check root sector entry by entry
	for (j = 0; j < DIR_BLOCK_SIZE; j += sizeof(struct directory))
	{
		if (curEntry->name[0] == FREE_ENTRY)
		{
			noMore = 1;	// no more entry after empty one
			break;
		}

		if (curEntry->name[0] != DELETED_ENTRY)
		{
			// not a deleted entry, check it
			if ((curEntry->attribute & DA_DIR) == DA_DIR)
			{
				// this entry is a directory, add it to dir list
				if ((curDir = (struct scanDir *)ap_malloc(sizeof(struct scanDir))) == NULL)
				{
					RDerrno = ERROR_ALLOC_MEM;
					return -1;
				}
				memoryZero((void *)curDir, (unsigned int)sizeof(struct scanDir));

				// copy the pathname
				for (i = 0; i < MAX_PATH_LENGTH; i++)
				{
					if (targetDir->pathName[i] == '\0')
						break;
					curDir->pathName[i] = targetDir->pathName[i];
				}
				curDir->pathName[i++] = '\\';	// connect the dir name and the entry name
				// copy the directory name
				filename = curEntry->name;
				for (; i < MAX_PATH_LENGTH; i++)
				{
					if (*filename == '\0')
						break;
					curDir->pathName[i] = *filename++;
				}

				curDir->startBlock = curEntry->startBlock;
				curDir->theEntry = curEntry;

				if (insertTo(&DirList, (void *)curDir) == FAIL)
				{
					RDerrno = ERROR_OPERATING_SYSTEM_ERROR;
				  	ap_free(curDir);
					return -1;
				}
			}
			else
			{
				status = RD_checkFile(options, targetDir->pathName, curEntry, totalFileSize, totalCompressSize, strTemp);
				if (status != -1)
				{
					totalSize += status;
				}
			}
		}

		// try next entry
		curEntry = (struct directory *)((unsigned long)curEntry + sizeof(struct directory));
	}

	if (noMore == 1)
	{
		if (curBlock->nextBlock != NULL)
			if ((options & AUTOFIX) == AUTOFIX)
				// free the unused directory blocks
				RD_freeBlockLink((struct diskBlock *)curBlock->nextBlock);
		break;
	}

	// done checking current block, go to the next block
	prevBlock = curBlock;
	curBlock = (struct diskBlock *)curBlock->nextBlock;
  }

  if ((options & INTERACTIVE) == INTERACTIVE)
  {
	sprintf(strTemp, "[DIR]  {%s\\} [OK]", targetDir->pathName);
/*
	if (RDOutput == TO_SERIAL_PORT)
		SprintStringLn(strTemp);
	else
		printStringLn(strTemp);
*/
	RD_showMessage(strTemp);
  }

  return totalSize;
}



#endif	// #ifdef RAMDISK_ID



⌨️ 快捷键说明

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