www.pudn.com > UDiskFileSystem.rar > MX_FFS_FDB.cpp


/*************************************************************************/ 
/*                                                                       */ 
/*        Copyright (c) 1993-2001 Macronix, Inc.           				 */ 
/*                                                                    	 */ 
/* PROPRIETARY RIGHTS of Macronix are involved in the      			     */ 
/* subject matter of this material.  All manufacturing, reproduction,    */ 
/* use, and sales rights pertaining to this subject matter are governed  */ 
/* by the license agreement.  The recipient of this software implicitly  */ 
/* accepts the terms of the license.                                     */ 
/*                                                                       */ 
/*************************************************************************/ 
 
/*************************************************************************/ 
/* FILE NAME                                                     	 	 */ 
/*      MX_FFS_FDB.c        			 						 		 */ 
/* DESCRIPTION                                                           */ 
/*	This file definition only internal used in File System							 */ 
/* AUTHOR                                                                */ 
/*      MXIC ISG , Inc.   System Application Department			 		 */ 
/*                                                                       */ 
/*                                                                       */ 
/* HISTORY                                                               */ 
/*      2006/03/16      Test version 0.00 for BCB6						*/ 
/*************************************************************************/ 
#ifndef  MX_FFS_FDB_C 
#define  MX_FFS_FDB_C 
#include "mx_FFS_Layer2.h" 
 
#ifdef BCB6 
#include "main.h" 
//extern FILE *hFile; 
//extern bFAT32_BootSector        FAT32_BootSector; 
//extern bPartitionInformation    PartitionInformation; 
extern void U_Printf(char *fmt,...); 
#endif 
 
/*Check FDB Table														*/ 
/* IN :																	*/ 
/*		Buffer  FDB Data 32bytes                						*/ 
/*		Mode   0 is Record FDB data into Temp_FDB and return Temp_FDB   */ 
/*				1 is bypass FDB data, only check FDB Flag				*/ 
/*OUT:																	*/ 
/*		Return FDB Flag 	       										*/ 
u_8 Check_FDB(u_8 * Buffer, mxFDB * Temp_FDB, u_8 Mode) 
{ 
	u_8 i,Error = 0; 
	 
	if(Buffer[11] == 0x0f)// Long File Name Flag. 
	{ 
		Error = FDB_LFNAME; 
	} 
	else 
	{ 
		switch(Buffer[0]) 
		{ 
			case 0x00: 
				Error = FDB_NOUSE; 
				break; 
			case 0x05: 
			case 0xe5: 
				Error = FDB_DELETE; 
				break; 
			case 0x2e: 
				if(Buffer[1] == 0x2e) 
				{ 
					Error = FDB_FOLDER2; 
				} 
				else 
				{ 
					Error = FDB_FOLDER1; 
				} 
			default:  
				if(Error == 0) 
				{ 
					if(Buffer[11] == 0x08) 
					{ 
						Error = FDB_VOLUME; 
					} 
					else if(Buffer[11] & 0x10) 
					{ 
						Error = FDB_FOLDER; 
					} 
					else 
					{ 
						Error = FDB_FILE; 
					} 
				} 
				if(Mode == 0) 
				{ 
					//memcpy(Temp_FDB->mainfilename, Buffer,8); 
					for(i=0;i<8;i++) 
					{ 
						Temp_FDB->mainfilename[i] = Buffer[i]; 
					} 
					Temp_FDB->mainfilename[9] = 0; 
					//memcpy(Temp_FDB->extfilename, Buffer + 8,3); 
					for(i=0;i<3;i++) 
					{ 
						Temp_FDB->extfilename[i] = Buffer[i+8]; 
					} 
					Temp_FDB->extfilename[4] = 0; 
					Temp_FDB->attr = Buffer[11]; 
					Temp_FDB->Reserved = Buffer[12]; 
					Temp_FDB->last_modify_year = (Buffer[19] & 0xfe) >> 1; 
					Temp_FDB->last_modify_month = ((Buffer[19] & 0x01) << 3) | ((Buffer[18] & 0xe0) >> 5);   
					Temp_FDB->last_modify_day = Buffer[18] & 0x1f; 
					Temp_FDB->create_hour = (Buffer[23] & 0xf8) >> 3; 
					Temp_FDB->create_minute = ((Buffer[23] & 0x07) << 3) | ((Buffer[22] & 0xe0) >> 5);   
					Temp_FDB->create_second = (Buffer[22] & 0x1f) ; 
					Temp_FDB->create_year = (Buffer[25] & 0xfe) >> 1; 
					Temp_FDB->create_month = ((Buffer[25] & 0x01) << 3) | ((Buffer[24] & 0xe0) >> 5);   
					Temp_FDB->create_day = Buffer[24] & 0x1f; 
					Temp_FDB->start_cluster = (u_32)Buffer[0x15] * 0x1000000 + (u_32)Buffer[0x14] * 0x10000 
			                + (u_32)Buffer[0x1B] * 0x100   + (u_32)Buffer[0x1A]; 
 
					Temp_FDB->filesize = (u_32)Buffer[0x1F] * 0x1000000 + (u_32)Buffer[0x1E] * 0x10000 
							+ (u_32)Buffer[0x1D] * 0x100     + (u_32)Buffer[0x1C]; 
				} 
				break; 
		}		 
	} 
	return Error; 
	 
} 
#if 1 
/*Search FDB Link Entry																			*/ 
/* IN:																							*/ 
/*		bDisk_Property  FAT Disk Property       												*/ 
/*		bDisk_History   FAT Disk History        												*/ 
/*		Mode   Operation Mode, 0 is Normal mode for FDB Read, NonZero is Seek Mode for FDB Seek */ 
/*OUT:																							*/ 
/*		bDisk_History Return History(FAT Link Table and Current Clust) 							*/		 
/*		Return 0 is Find Entry, 1 is Find to END 	       										*/ 
u_8 SearchFDBLinkEntry( mxDRIVE_PROPERTY *bDisk_Property, mxDISK_HISTORY *bDisk_History, u_8 Mode) 
{ 
	u_8 SectorsPerCluster = bDisk_Property->DiskBoot.SectorsPerCluster; 
	u_16 BytesPerSector = bDisk_Property->DiskBoot.BytesPerSector; 
	u_32 BytesPerCluster = bDisk_Property->DiskBoot.BytesPerCluster; 
	u_16 FATTable_Index; 
	u_8 Entry_num = 0,Error = 0; 
	u_16 rLinkTableSize = 0;  
	u_32 i,j; 
 
	if(Mode == 0)// Normal mode for FDB read 
	{ 
		j = 1; 
	} 
	else// if(Mode == 1)//for FDB search 
	{ 
		j = bDisk_History->EntryNum+1; 
	} 
 
	for(i=0;iEntryNum = i; 
		} 
 
		FATTable_Index = bDisk_History->EntryNum /(BytesPerCluster/32);//EntryNum(FDB) in which cluster  
		Entry_num = FATTable_Index % FATtable_Num; //n-th cluster in current FAT Link table 
	 
		if(bDisk_Property->FatType == FAT32) 
		{ 
			if(bDisk_History->EntryNum == 0) // First FDB Entry 
			{ 
				bDisk_History->FATEndFlag = FAT32_GetFile_FristFATLinkTable(bDisk_Property->DiskInfo.FAT1_Address, BytesPerSector, 
					bDisk_History->CurrentPathCluster, bDisk_History->FATLinkTable, FATtable_Num, &rLinkTableSize); 
				bDisk_History->FATLinkSize = rLinkTableSize; 
				ClusterToLogicBlockAddrFun(bDisk_Property->DiskInfo.BootDIR_Address, bDisk_Property->DiskBoot.RootDir1stCluster, SectorsPerCluster, 
					bDisk_History->CurrentPathCluster, &((u_32)bDisk_History->CurrentLBA)); 
			} 
			else 
			{ 
				if(((FATTable_Index % FATtable_Num) == 0) && ((bDisk_History->EntryNum % FATtable_Num) == 0))// update FAT Table 
				{ 
					if(bDisk_History->FATEndFlag == 1)//EOF 
					{ 
						Error = 1; 
						return Error; 
					} 
					/*Get Folder FAT Table Link */ 
					bDisk_History->FATEndFlag = FAT32_GetFile_FATLinkTable(bDisk_Property->DiskInfo.FAT1_Address, BytesPerSector, 
						bDisk_History->FATLinkTable[FATtable_Num - 1], bDisk_History->FATLinkTable, FATtable_Num, &rLinkTableSize); 
					bDisk_History->FATLinkSize = rLinkTableSize; 
				} 
				if((bDisk_History->FATEndFlag == 1) && (Entry_num == bDisk_History->FATLinkSize)) 
				{ 
					Error = 1; 
					return Error; 
				} 
				ClusterToLogicBlockAddrFun(bDisk_Property->DiskInfo.BootDIR_Address, bDisk_Property->DiskBoot.RootDir1stCluster, SectorsPerCluster, 
   			 		bDisk_History->FATLinkTable[Entry_num], &((u_32)bDisk_History->CurrentLBA)); 
			} 
		} 
		else if(bDisk_Property->FatType == FAT16) 
		{ 
		 
			if(bDisk_History->CurrentPathCluster == (u_32)bDisk_Property->DiskBoot.RootDir1stCluster)//Boot Dir 
			{ 
				if(bDisk_History->EntryNum == 0) 
				{ 
					bDisk_History->CurrentLBA = bDisk_Property->DiskInfo.BootDIR_Address; 
				} 
				else if((bDisk_History->EntryNum % (BytesPerCluster/0x20)) == 0) 
				{ 
					bDisk_History->CurrentLBA+=SectorsPerCluster; 
				} 
				if(bDisk_History->EntryNum >= (u_32)bDisk_Property->DiskBoot.RootEntries) 
				{ 
					Error = 1; 
					bDisk_History->FATEndFlag = 1; 
					return Error; 
				} 
			} 
			else 
			{ 
				if(bDisk_History->EntryNum == 0) // First FDB Entry 
				{ 
					bDisk_History->FATEndFlag = FAT16_GetFile_FristFATLinkTable(bDisk_Property->DiskInfo.FAT1_Address, BytesPerSector, 
						bDisk_History->CurrentPathCluster, bDisk_History->FATLinkTable, FATtable_Num, &rLinkTableSize); 
					bDisk_History->FATLinkSize = rLinkTableSize; 
					ClusterToLogicBlockAddrFun(bDisk_Property->DiskInfo.BootDIR_Address, 2, SectorsPerCluster, 
						bDisk_History->CurrentPathCluster, &((u_32)bDisk_History->CurrentLBA)); 
					bDisk_History->CurrentLBA += ((bDisk_Property->DiskBoot.RootEntries * 0x20) / bDisk_Property->DiskBoot.BytesPerSector); 
				} 
 
				else 
				{ 
					if(((FATTable_Index % FATtable_Num) == 0) && ((bDisk_History->EntryNum % FATtable_Num) == 0))// update FAT Table 
					{ 
						if(bDisk_History->FATEndFlag == 1) 
						{ 
							Error = 1; 
							return Error; 
						} 
						/*Get Folder FAT Table Link */ 
						bDisk_History->FATEndFlag = FAT16_GetFile_FATLinkTable(bDisk_Property->DiskInfo.FAT1_Address, BytesPerSector, 
							bDisk_History->FATLinkTable[FATtable_Num - 1], bDisk_History->FATLinkTable, FATtable_Num, &rLinkTableSize); 
						bDisk_History->FATLinkSize = rLinkTableSize; 
					} 
					if((bDisk_History->FATEndFlag == 1) && (Entry_num == bDisk_History->FATLinkSize)) 
					{ 
						Error = 1; 
						return Error; 
					} 
					ClusterToLogicBlockAddrFun(bDisk_Property->DiskInfo.BootDIR_Address, 2, SectorsPerCluster, 
						bDisk_History->FATLinkTable[Entry_num], &((u_32)bDisk_History->CurrentLBA)); 
					bDisk_History->CurrentLBA += ((bDisk_Property->DiskBoot.RootEntries * 0x20) / bDisk_Property->DiskBoot.BytesPerSector); 
				} 
 
			} 
		 
		} 
	} 
	return Error; 
} 
#endif 
 
 
/*Calc Longfile Name CheckSum					*/ 
/* IN :											*/ 
/*		ShortName     8 main name + 3 ext. name	*/ 
/*OUT:											*/ 
/*		Return CheckSum						    */ 
u_8 LFN_ChsSum( s_8 *ShortName) 
{ 
	u_8	ShortNameLen; 
	u_8 Sum; 
	Sum = 0; 
	for(ShortNameLen = 11 ; ShortNameLen != 0; ShortNameLen--) 
	{ 
		Sum = ((Sum & 1) ? 0x80 : 0) + (Sum >> 1) + *ShortName++; 
	} 
	return Sum; 
} 
 
/*Get LFN's FDB												*/ 
/* IN :														*/ 
/*		FDB_Buffer     32 byte, to set LFN FDB Data Struct	*/ 
/*OUT:														*/ 
/*		Return FDB_LFN						    			*/ 
void GetLFN_FDB( mxFDB_LFN *FDB_LFN, u_8 *FDB_Buffer) 
{ 
	u_8 x; 
	FDB_LFN->Order = FDB_Buffer[0] & 0x0f; 
	FDB_LFN->Attr = FDB_Buffer[11]; 
	FDB_LFN->Checksum = FDB_Buffer[13]; 
	for(x=0;x<26;x++) 
	{ 
		if(x < 10) 
		{ 
	/* 
			if(x==0||x==3) 
				FDB_LFN->Name[x+1] = FDB_Buffer[x+1]; 
			else if(x==2||x==4) 
				FDB_LFN->Name[x-1] = FDB_Buffer[x+1]; 
			else 
				*/ 
				FDB_LFN->Name[x] = FDB_Buffer[x+1]; 
		} 
		else if((x>= 10) && (x<22)) 
		{ 
			FDB_LFN->Name[x] = FDB_Buffer[x+4]; 
		} 
		else if(x>=22) 
		{ 
			FDB_LFN->Name[x] = FDB_Buffer[x+6]; 
		} 
	} 
//	/* 
 	for (x=0; x<13; x++) 
 	{ 
  	 	if (((u_8)FDB_LFN->Name[x*2]==0xFF) && ((u_8)FDB_LFN->Name[(x*2)+1]==0xFF)) 
  	 	{ 
			FDB_LFN->Name[x*2] = 0; // Replace with spaces 
			FDB_LFN->Name[(x*2)+1] = 0; // Replace with spaces 
  	 	} 
 	} 
//	*/ 
} 
 
/*Get Long File Name										*/ 
/* IN :														*/ 
/*		FDB_LFN     FDB_LFN Struct Array					*/ 
/*		LFN_Num     there are n FDB_LFN Array, n= LFN_Num	*/ 
/*OUT:														*/ 
/*		Return LFN						    				*/ 
void GetLongFileName( mxLFN *LFN, mxFDB_LFN *FDB_LFN, u_8 LFN_Num) 
{ 
	u_16 NameCounter = 0; 
	u_16 x; 
	u_8 y; 
	for(x=0;xLongName[x] = 0; 
	} 
	for(x=0;x= LFN_Length) 
			{ 
				break; 
			} 
			LFN->LongName[NameCounter] = FDB_LFN[x].Name[y]; 
			NameCounter++; 
		} 
		if(NameCounter >= LFN_Length) 
		{ 
			break; 
		} 
	} 
} 
 
/*Get Folder Layer Number									*/ 
/* IN :														*/ 
/*		Path     Full Path Name								*/ 
/*		PathLen	Path Length									*/ 
/*OUT:														*/ 
/*		Return Layer Number	(0xffff is only Folder Name)    */ 
u_16 GetFolderLayer( s_8 *Path, u_16 PathLen) 
{ 
	u_16 layer,i,j; 
 
	layer = 0; 
	if(Path[1] != ':') // Check Full Path or Folder Name, Follow Windows Name rule "\/:*?"<>|" 
	{ 
		layer = 0xffff; // String "Path" is a Folder Name not Full Path Name 
		return layer; 
	} 
	else if((Path[1] == ':') && (Path[2] == '\\') && (Path[3] == '\\') && (PathLen == 4)) 
	{ 
		layer = 0; // Root  
		return layer;  
	} 
	//j = 4; 
	for(i = 2;i8) 
	{ 
		Error = FAT_FOLDERPATH_ERROR;// Error, FolderName is not 8.3 file name format 
	} 
	for(i=0; i<(k - j); i++) 
	{ 
		FolderName[i] = Path[i+j]; 
	} 
	FolderName[i] = 0; 
	return Error; 
	//return layer; 
} 
 
/*Set Disk History Initial							*/ 
/* IN :												*/ 
/*		Property     Send Root Clust and Address	*/ 
/*OUT:												*/ 
/*		History	Set Disk History at Root and record */ 
void SetDiskHistoryInit( mxDISK_HISTORY *History, mxDRIVE_PROPERTY Property) 
{ 
	u_16 i,length; 
	length = strlen(History->CurrentPath); 
	for(i=0;iCurrentPath[i] = 0; 
	} 
	History->FatherCluster = NULL; 
	History->CurrentCluster = History->CurrentPathCluster = Property.DiskBoot.RootDir1stCluster; 
	History->CurrentLBA = Property.DiskInfo.BootDIR_Address; 
	History->FileNum = 0; 
	History->FolderNum = 0; 
	History->LFNFileNum = 0; 
	History->EntryNum= 0; 
	History->FATEndFlag = 0; // Change Folder must to set 0 
	History->FolderLayerNum = 0; 
} 
 
/*Set Folder Link Path									*/ 
/* IN :													*/ 
/*		FolderFDB     Send FDB Link Data Struct Address	*/ 
/*OUT:													*/ 
/*		History	Set Disk History at Root and record     */ 
 
void MX_SetFolderLinkPath(mxFDB FolderFDB, mxDISK_HISTORY *History) 
{ 
	History->FatherCluster = History->CurrentPathCluster; 
	//History->CurrentPathCluster = FolderFDB.start_cluster; 
	History->CurrentCluster = History->CurrentPathCluster = FolderFDB.start_cluster; 
	History->FileNum = 0; 
	History->FolderNum = 0; 
	History->LFNFileNum = 0; 
	History->EntryNum= 0; 
	History->FATEndFlag = 0; // Change Folder must to set 0 
	History->FolderLayerNum = 0; 
} 
 
 
 
 
// 4/1============================================================================================== 
/*Search File Link Entry																			*/ 
/* IN :																								*/ 
/*		Handle  File History        																*/ 
/*		Mode   Operation Mode, 0 is Normal mode for File Read, NonZero is Seek Mode for File Seek	*/ 
/*OUT:																								*/ 
/*		Handle Record History(File FAT Link Table and Current Clust) 								*/		 
/*		Return 0 is Find Entry, 1 is Find to END 	       											*/ 
u_8 SearchFileLinkEntry( mx_FHANDLE *Handle, u_8 Mode) 
//u_8 SearchFileLinkEntry( mx_FHANDLE *Handle) 
{ 
	u_8 SectorsPerCluster = Handle->Disk_Property.DiskBoot.SectorsPerCluster; 
	u_16 BytesPerSector = Handle->Disk_Property.DiskBoot.BytesPerSector; 
	//u_32 BytesPerCluster = Handle->Disk_Property.DiskBoot.BytesPerCluster; 
	u_16 FATTable_Index; 
	u_32 i,j; 
	u_8 Entry_num = 0,Error = 0; 
	u_16 rLinkTableSize = 0;  
	//u_32 EntryNum; 
 
	if(Mode == 0)// Normal mode 
	{ 
		j = 1; 
	} 
	else// if(Mode == 1) 
	{ 
		j = Handle->File_History.EntryNum+1; 
		//EntryNum = Handle->File_History.EntryNum; 
		//Handle->File_History.EntryNum = 0; 
	} 
	for(i=0;iFile_History.EntryNum = i; 
		} 
 
		FATTable_Index = Handle->File_History.EntryNum /SectorsPerCluster;//16; 
		Entry_num = FATTable_Index % FATtable_Num; 
 
		if(Handle->Disk_Property.FatType == FAT32) 
		{ 
			if(Handle->File_History.EntryNum == 0) // First File Entry 
			{ 
				Handle->File_History.FATEndFlag = FAT32_GetFile_FristFATLinkTable(Handle->Disk_Property.DiskInfo.FAT1_Address, BytesPerSector, 
	      	         		Handle->File_History.File1stCluster, Handle->File_History.FATLinkTable, FATtable_Num, &rLinkTableSize); 
 
				Handle->File_History.FATLinkSize = rLinkTableSize; 
 
				ClusterToLogicBlockAddrFun(Handle->Disk_Property.DiskInfo.BootDIR_Address, Handle->Disk_Property.DiskBoot.RootDir1stCluster, SectorsPerCluster, 
		            		Handle->File_History.File1stCluster, &(Handle->File_History.CurrentLBA)); 
			} 
			else 
			{ 
				if(((FATTable_Index % FATtable_Num) == 0) && ((Handle->File_History.EntryNum % FATtable_Num) == 0))// update FAT Table 
				{ 
					if(Handle->File_History.FATEndFlag == 1) 
					{ 
						//if(Mode != 0) 
						//{ 
							//Handle->File_History.EntryNum = EntryNum; 
						//} 
						Error = 1; 
						return Error; 
					} 
					/*Get Folder FAT Table Link */ 
					Handle->File_History.FATEndFlag = FAT32_GetFile_FATLinkTable(Handle->Disk_Property.DiskInfo.FAT1_Address, BytesPerSector, 
						Handle->File_History.FATLinkTable[FATtable_Num - 1], Handle->File_History.FATLinkTable, FATtable_Num, &rLinkTableSize); 
 
					Handle->File_History.FATLinkSize = rLinkTableSize; 
				} 
				if((Handle->File_History.FATEndFlag == 1) && (Entry_num == Handle->File_History.FATLinkSize)) 
				{ 
					//if(Mode != 0) 
					//{ 
					//	Handle->File_History.EntryNum = EntryNum; 
					//} 
					Error = 1; 
					return Error; 
				} 
				ClusterToLogicBlockAddrFun(Handle->Disk_Property.DiskInfo.BootDIR_Address, Handle->Disk_Property.DiskBoot.RootDir1stCluster, SectorsPerCluster, 
    		        		Handle->File_History.FATLinkTable[Entry_num], &(Handle->File_History.CurrentLBA)); 
			} 
		} 
		else if(Handle->Disk_Property.FatType == FAT16) 
		{ 
			 
			if(Handle->File_History.EntryNum == 0) // First FDB Entry 
			{ 
				Handle->File_History.FATEndFlag = FAT16_GetFile_FristFATLinkTable(Handle->Disk_Property.DiskInfo.FAT1_Address, BytesPerSector, 
      		 	       	Handle->File_History.File1stCluster, Handle->File_History.FATLinkTable, FATtable_Num, &rLinkTableSize); 
 
				Handle->File_History.FATLinkSize = rLinkTableSize; 
 
				ClusterToLogicBlockAddrFun(Handle->Disk_Property.DiskInfo.BootDIR_Address, 2, SectorsPerCluster, 
		       		Handle->File_History.File1stCluster, &(Handle->File_History.CurrentLBA)); 
				Handle->File_History.CurrentLBA += ((Handle->Disk_Property.DiskBoot.RootEntries * 0x20) / Handle->Disk_Property.DiskBoot.BytesPerSector); 
			} 
			else 
			{ 
				if(((FATTable_Index % FATtable_Num) == 0) && ((Handle->File_History.EntryNum % FATtable_Num) == 0))// update FAT Table 
				{ 
					if(Handle->File_History.FATEndFlag == 1) 
					{ 
						//if(Mode != 0) 
						//{ 
							//Handle->File_History.EntryNum = EntryNum; 
						//} 
						Error = 1; 
						return Error; 
					} 
					/*Get Folder FAT Table Link */ 
					Handle->File_History.FATEndFlag = FAT16_GetFile_FATLinkTable(Handle->Disk_Property.DiskInfo.FAT1_Address, BytesPerSector, 
						Handle->File_History.FATLinkTable[FATtable_Num - 1], Handle->File_History.FATLinkTable, FATtable_Num, &rLinkTableSize); 
 
					Handle->File_History.FATLinkSize = rLinkTableSize; 
				} 
				if((Handle->File_History.FATEndFlag == 1) && (Entry_num == Handle->File_History.FATLinkSize)) 
				{ 
					//if(Mode != 0) 
					//{ 
						//Handle->File_History.EntryNum = EntryNum; 
					//} 
					Error = 1; 
					return Error; 
				} 
 
				ClusterToLogicBlockAddrFun(Handle->Disk_Property.DiskInfo.BootDIR_Address, 2, SectorsPerCluster, 
    		        		Handle->File_History.FATLinkTable[Entry_num], &(Handle->File_History.CurrentLBA)); 
				Handle->File_History.CurrentLBA += ((Handle->Disk_Property.DiskBoot.RootEntries * 0x20) / Handle->Disk_Property.DiskBoot.BytesPerSector); 
			} 
		} 
	} 
	//if(Mode != 0) 
	//{ 
		//Handle->File_History.EntryNum = EntryNum; 
	//} 
	return Error; 
} 
 
#if 0 
// 4/1============================================================================================== 
/*Search File Link Entry							*/ 
/* IN :											*/ 
/*		bDisk_Property  FAT Disk Property       */ 
/*		bDisk_History   FAT Disk History        */ 
/*OUT:											*/ 
/*		Return 0 is Find Entry, 1 is Find to END 	       */ 
//u_8 SearchFileLinkEntry( mx_FHANDLE *Handle, u_8 Mode) 
u_8 SearchFileLinkEntry( mx_FHANDLE *Handle) 
{ 
	u_8 SectorsPerCluster = Handle->Disk_Property.DiskBoot.SectorsPerCluster; 
	u_16 BytesPerSector = Handle->Disk_Property.DiskBoot.BytesPerSector; 
//	u_32 BytesPerCluster = Handle->Disk_Property.DiskBoot.BytesPerCluster; 
	u_16 FATTable_Index; 
	u_8 Entry_num = 0,Error = 0; 
	u_16 rLinkTableSize = 0;  
 
	FATTable_Index = Handle->File_History.EntryNum /SectorsPerCluster;//16; 
	Entry_num = FATTable_Index % FATtable_Num; 
	if(Handle->Disk_Property.FatType == FAT32) 
	{ 
		if(Handle->File_History.EntryNum == 0) // First File Entry 
		{ 
			Handle->File_History.FATEndFlag = FAT32_GetFile_FristFATLinkTable(Handle->Disk_Property.DiskInfo.FAT1_Address, BytesPerSector, 
               		Handle->File_History.File1stCluster, Handle->File_History.FATLinkTable, FATtable_Num, &rLinkTableSize); 
 
			Handle->File_History.FATLinkSize = rLinkTableSize; 
 
			ClusterToLogicBlockAddrFun(Handle->Disk_Property.DiskInfo.BootDIR_Address, Handle->Disk_Property.DiskBoot.RootDir1stCluster, SectorsPerCluster, 
	            		Handle->File_History.File1stCluster, &(Handle->File_History.CurrentLBA)); 
		} 
		else 
		{ 
			if(((FATTable_Index % FATtable_Num) == 0) && ((Handle->File_History.EntryNum % FATtable_Num) == 0))// update FAT Table 
			{ 
				if(Handle->File_History.FATEndFlag == 1) 
				{ 
					Error = 1; 
					return Error; 
				} 
				/*Get Folder FAT Table Link */ 
				Handle->File_History.FATEndFlag = FAT32_GetFile_FATLinkTable(Handle->Disk_Property.DiskInfo.FAT1_Address, BytesPerSector, 
					Handle->File_History.FATLinkTable[FATtable_Num - 1], Handle->File_History.FATLinkTable, FATtable_Num, &rLinkTableSize); 
 
				Handle->File_History.FATLinkSize = rLinkTableSize; 
			} 
			if((Handle->File_History.FATEndFlag == 1) && (Entry_num == Handle->File_History.FATLinkSize)) 
			{ 
				Error = 1; 
				return Error; 
			} 
			ClusterToLogicBlockAddrFun(Handle->Disk_Property.DiskInfo.BootDIR_Address, Handle->Disk_Property.DiskBoot.RootDir1stCluster, SectorsPerCluster, 
    	        		Handle->File_History.FATLinkTable[Entry_num], &(Handle->File_History.CurrentLBA)); 
		} 
	} 
	else if(Handle->Disk_Property.FatType == FAT16) 
	{ 
		 
		if(Handle->File_History.EntryNum == 0) // First FDB Entry 
		{ 
			Handle->File_History.FATEndFlag = FAT16_GetFile_FristFATLinkTable(Handle->Disk_Property.DiskInfo.FAT1_Address, BytesPerSector, 
       	       	Handle->File_History.File1stCluster, Handle->File_History.FATLinkTable, FATtable_Num, &rLinkTableSize); 
 
			Handle->File_History.FATLinkSize = rLinkTableSize; 
 
			ClusterToLogicBlockAddrFun(Handle->Disk_Property.DiskInfo.BootDIR_Address, 2, SectorsPerCluster, 
	       		Handle->File_History.File1stCluster, &(Handle->File_History.CurrentLBA)); 
			Handle->File_History.CurrentLBA += ((Handle->Disk_Property.DiskBoot.RootEntries * 0x20) / Handle->Disk_Property.DiskBoot.BytesPerSector); 
		} 
		else 
		{ 
			if(((FATTable_Index % FATtable_Num) == 0) && ((Handle->File_History.EntryNum % FATtable_Num) == 0))// update FAT Table 
			{ 
				if(Handle->File_History.FATEndFlag == 1) 
				{ 
					Error = 1; 
					return Error; 
				} 
				/*Get Folder FAT Table Link */ 
				Handle->File_History.FATEndFlag = FAT16_GetFile_FATLinkTable(Handle->Disk_Property.DiskInfo.FAT1_Address, BytesPerSector, 
					Handle->File_History.FATLinkTable[FATtable_Num - 1], Handle->File_History.FATLinkTable, FATtable_Num, &rLinkTableSize); 
 
				Handle->File_History.FATLinkSize = rLinkTableSize; 
			} 
			if((Handle->File_History.FATEndFlag == 1) && (Entry_num == Handle->File_History.FATLinkSize)) 
			{ 
				Error = 1; 
				return Error; 
			} 
 
			ClusterToLogicBlockAddrFun(Handle->Disk_Property.DiskInfo.BootDIR_Address, 2, SectorsPerCluster, 
    	        		Handle->File_History.FATLinkTable[Entry_num], &(Handle->File_History.CurrentLBA)); 
			Handle->File_History.CurrentLBA += ((Handle->Disk_Property.DiskBoot.RootEntries * 0x20) / Handle->Disk_Property.DiskBoot.BytesPerSector); 
		} 
	} 
	return Error; 
} 
#endif 
#endif   /*MX_FFS_FDB_C*/