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

📄 dosdir.c

📁 一种文件系统的结构
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "..\define.h"
#include "..\all.h"

xdata	U8	gc_Index;
xdata	U8	gc_DIRtable[2048]	_at_	0x4700;
xdata	U16	gw_TotalNumber;

U8 Count_Dir_Fdb(SearchFdb *p_mp);
U8 DOS_Search_DIR(U8 tc_Mode, U8 tc_Type, U8 tc_PrevOrNext);
U8 DOS_DIRtable();


U8 Count_Dir_Fdb(SearchFdb *p_mp)
{
  	U8 tc_sts;
	p_mp->w_DirTotalNum=0;
	p_mp->c_Search_Mode = K_COUNTER_FILENUM;																							
	p_mp->c_Search_Attribute=1;               //look for file			
	tc_sts=Find_Fdb(p_mp);
	return tc_sts;
}


U8	DOS_Search_DIR(U8 tc_Mode, U8 tc_Type, U8 tc_PrevOrNext)
{
	bit tbt_IniFlag;
	U8	tc_sts;
	U8  tc_FindDir,tc_FindFile;      //whether search file or search dir flag
	U8  tc_SearchTime;
	U32 tdw_SectorAdd,tdw_CurrentDirCluster,tdw_PrevDirCluster,tdw_NextDirCluster;
	SearchFdb ptr;
	
	gs_File_FCB[tc_Type].dw_File_StartCluster = 0xffffffff;
	gs_File_FCB[tc_Type].dw_FDB_LogAdd = 0;

	if ((char)gc_DOS_Status <0)
	{//dos error occurs, not to do search
		return 0xff;
	}

	tc_sts=1;	
	tbt_IniFlag=0;
	ptr.w_DirTotalNum=0;
	gc_ReadWriteDataArea=1;
	if((tc_Mode&0x0f)==1)
	{//if search file by time, please search by order
		tc_Mode|=0x03;	
	}	
	ptr.pc_LongFileName = gc_FileLongName;
	ptr.c_Search_Mode=(tc_Mode&0x0f);
	ptr.c_EXTSelect = 0; //the directory doesn't need to compare ExtName, default value
	tc_PrevOrNext = tc_PrevOrNext & 0x0f;
	if((tc_Mode&0x0f)==0||(tc_Mode&0x0f)==4||(tc_Mode&0x0f)==5 ||(tc_Mode&0x0f)==0x0b)
	{//count filenum/dirnum , find next
		tc_PrevOrNext=0;
	}						
	ptr.c_Search_Direction=tc_PrevOrNext;
	ptr.Compare.dw_BubbleFlag = gdw_CurrFlag;
	ptr.dw_File_StartCluster = gdw_StartCluster2;
	ptr.c_type=tc_Type;
	tc_SearchTime=2; 
	while(tc_SearchTime)
	{
		if((tc_Mode&0x0f0)==0x20 || (tc_Mode&0x0f0)==0x30)
		{//find dir 
		 	tc_FindFile=0;
			tc_FindDir=1;
			ptr.dw_FDB_StartCluster=gs_DIR_FCB[tc_Type].dw_FDB_StartCluster;
		}
		else
		{//find file
			return(1); //this function isn't used to find file
		}
		
		if(!(gbt_FindFlag))
		{//have not searched 		       
			ptr.dw_File_StartCluster=0;
			gs_DIR_FCB[tc_Type].dw_FDB_StartCluster = 0;
			gs_DIR_FCB[tc_Type].dw_File_StartCluster = 0;
			if(ptr.c_Search_Direction) //find pre
			{
				if(((tc_Mode&0x0f)==K_NAME_FINDFDB)||((tc_Mode&0x0f)==K_TIME_FINDFDB)) //modify by Ching
				{
					ptr.Compare.dw_BubbleFlag=0xffffffff;
				}
				tc_FindDir=1;
				gw_DirIndex[0]=0xffff;     //gw_DirIndex1 used to save the index of the fdb which find just now     lizhn 040927 add
				gw_DirIndex[1]=0xffff;     //gw_DirIndex0 used to save the index of the last fdb  					
			}
			else //find next
			{
				if(((tc_Mode&0x0f)==K_NAME_FINDFDB)||((tc_Mode&0x0f)==K_TIME_FINDFDB)) //modify by Ching
				{
					ptr.Compare.dw_BubbleFlag=0x00;
				}
				gw_DirIndex[0] = 0;    
				gw_DirIndex[1] = 0;
			}	
		}
		if((tc_Mode&0x0f0)==0x30)
		{//find dir in one dir
			ptr.c_Search_Attribute=1; //find dir
			if((tc_Mode&0x0f)==0x0b)
				tc_sts=Count_Dir_Fdb(&ptr);
			else
				tc_sts=Find_Fdb(&ptr);
			
			gc_ReadWriteDataArea=1;
			if(DOS_Read_LogicSector(ptr.dw_FDB_LogAdd,1))
				return 0xff;

			((U8 *)(&ptr.dw_File_StartCluster))[3]=gc_UserDataBuf[ptr.w_FDB_Offset+0x1a];
			((U8 *)(&ptr.dw_File_StartCluster))[2]=gc_UserDataBuf[ptr.w_FDB_Offset+0x1b];
			((U8 *)(&ptr.dw_File_StartCluster))[1]=gc_UserDataBuf[ptr.w_FDB_Offset+0x14];
			((U8 *)(&ptr.dw_File_StartCluster))[0]=gc_UserDataBuf[ptr.w_FDB_Offset+0x15];
		}
		else //(tc_Mode&0x0f0)==0x20
		{//find in all dir
			if(tc_PrevOrNext)
			{//find pre
				while(1)
				{//A 			
					if(tc_FindDir)
					{//not found dir in the dir in the last time but found file 					
						ptr.c_Search_Mode=K_ORDER_FINDFDB;
						ptr.c_Search_Attribute=1; //find dir
						tc_sts=Find_Fdb(&ptr);						
					}				
					if(tc_sts)
					{//haven't found dir
						if(tbt_IniFlag)
						{
							tbt_IniFlag=0;					
						 	ptr.Compare.dw_BubbleFlag=0xffffffff;
						}
						if((tc_Mode&0x0f)==2)
						{//if find the file by name
							ptr.c_Search_Mode=2;
						}						
						//if(tc_sts) //Here, tc_sts=1, remove by Ching 060113
						{//not find file
							tc_FindDir=1;
							if(ptr.dw_FDB_StartCluster!=gdw_DOS_RootDirClus)                 //if rootdir
							{//current dir is not rootdir							
								tdw_SectorAdd = DOS_ClusterLogicAddr(ptr.dw_FDB_StartCluster);
								gc_ReadWriteDataArea=1;
								if(DOS_Read_LogicSector(tdw_SectorAdd,1))
									return 0xff;

								((U8 *)(&tdw_PrevDirCluster))[3]=gc_UserDataBuf[32+0x1a];
								((U8 *)(&tdw_PrevDirCluster))[2]=gc_UserDataBuf[32+0x1b];
								((U8 *)(&tdw_PrevDirCluster))[1]=gc_UserDataBuf[32+0x14];
								((U8 *)(&tdw_PrevDirCluster))[0]=gc_UserDataBuf[32+0x15];    //computer the startcluster of predir 

	  							if(!(tdw_PrevDirCluster))
								{//predir is rootdir
									tdw_PrevDirCluster=gdw_DOS_RootDirClus;							
								}		
								ptr.dw_File_StartCluster=ptr.dw_FDB_StartCluster;
								ptr.dw_FDB_StartCluster=tdw_PrevDirCluster;	              //return to predir	                  	
								tbt_IniFlag=1;							
								if((tc_Mode&0x0f)==0x03)
								{//find dir by order
									gw_DirIndex[0]=0xffff;
									ptr.c_Search_Mode = K_SPECIFIC_STARTCLUSTER;
									ptr.Compare.dw_StartCluster =ptr.dw_File_StartCluster;       // ptr.dw_FDB_StartCluster;
									ptr.c_Search_Attribute = 1;  
									if(Find_Fdb(&ptr))
										break;

									if(((tc_Mode&0xf0)==0x20))
									{									
										if(gs_DIR_FCB[tc_Type].dw_File_StartCluster!=ptr.dw_File_StartCluster)
										{
											tc_sts=0;
											break;
										}
										else
											gw_DirIndex[1]=0xffff;	
									}
								}							
							}
							else //current dir is rootdir
								break;
						}
					}			
					else
					{//have found dir in dir
		 				gc_ReadWriteDataArea=1;
						if(DOS_Read_LogicSector(ptr.dw_FDB_LogAdd,1))
							return 0xff;

						 tdw_CurrentDirCluster=ptr.dw_FDB_StartCluster;  //save current dir
						((U8 *)(&ptr.dw_FDB_StartCluster))[3]=gc_UserDataBuf[ptr.w_FDB_Offset+0x1a];
						((U8 *)(&ptr.dw_FDB_StartCluster))[2]=gc_UserDataBuf[ptr.w_FDB_Offset+0x1b];
						((U8 *)(&ptr.dw_FDB_StartCluster))[1]=gc_UserDataBuf[ptr.w_FDB_Offset+0x14];
						((U8 *)(&ptr.dw_FDB_StartCluster))[0]=gc_UserDataBuf[ptr.w_FDB_Offset+0x15];	  //next dir cluster 

						tdw_SectorAdd = DOS_ClusterLogicAddr(ptr.dw_FDB_StartCluster);

						if(DOS_Read_LogicSector((tdw_SectorAdd),1))
							return 0xff;						

						((U8 *)(&tdw_PrevDirCluster))[3]=gc_UserDataBuf[32+0x1a];		 //current dir
						((U8 *)(&tdw_PrevDirCluster))[2]=gc_UserDataBuf[32+0x1b];
						((U8 *)(&tdw_PrevDirCluster))[1]=gc_UserDataBuf[32+0x14];
						((U8 *)(&tdw_PrevDirCluster))[0]=gc_UserDataBuf[32+0x15];
	
						((U8 *)(&tdw_NextDirCluster))[3]=gc_UserDataBuf[0x1a];
						((U8 *)(&tdw_NextDirCluster))[2]=gc_UserDataBuf[0x1b];
						((U8 *)(&tdw_NextDirCluster))[1]=gc_UserDataBuf[0x14];
						((U8 *)(&tdw_NextDirCluster))[0]=gc_UserDataBuf[0x15];			//next dir			
													
						if((tdw_PrevDirCluster!=tdw_CurrentDirCluster)&&(tdw_CurrentDirCluster!=gdw_DOS_RootDirClus)||(tdw_NextDirCluster!=ptr.dw_FDB_StartCluster))
						{//dos error					
							 ptr.dw_FDB_StartCluster=tdw_CurrentDirCluster; 							
						}				
						else
						{
							ptr.Compare.dw_BubbleFlag=0xffffffff;	
							gw_DirIndex[1]=0xffff;
							if((tc_Mode&0xf0)==0x20)
							{//find dir by order
								gw_DirIndex[ptr.c_Search_Mode] = 0xffff; 											
								tc_FindFile=0;
							} 
						}
						tc_FindDir=1;						
					}//have found dir in dir			
				}//A
			}//find pre
			else
			{//find next
				while(1)
				{ 
					ptr.c_Search_Mode = (tc_Mode&0x0f);
					if(tc_FindDir==1 && ptr.c_Search_Mode==0x0b)
					{//count dir number in all directories
						tc_sts=Count_Dir_Fdb(&ptr);
						gw_DirTotalNumber = ptr.w_DirTotalNum;
					}
					if(tc_sts) //Here, tc_sts=1
					{//have not found the specific file in one dir or count dir number in one dir
						ptr.c_Search_Mode=0x03;  //if count filenum now,please search dir by order

⌨️ 快捷键说明

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