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

📄 dosdir.c

📁 一种文件系统的结构
💻 C
📖 第 1 页 / 共 2 页
字号:

						if((tc_Mode&0xf0)==0x20 && (tc_Mode&0x0f)!=0x0b) //for tc_Mode=0x28, 
							ptr.c_Search_Mode=(tc_Mode&0x0f);                     //it has counted in this dir. Then it must be searching new dir to count overall directories

						ptr.c_Search_Attribute=1;
						tc_sts=Find_Fdb(&ptr);   //look for dir in the dir

						if(tc_sts)
						{//not find dir
							if(ptr.dw_FDB_StartCluster!=gdw_DOS_RootDirClus)                 //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];
							    	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

								if((tc_Mode&0x0f)==0x0b) //add by Ching 051220
									tc_FindDir=0;
								
								tc_FindFile=0;

								if(ptr.c_Search_Mode==0x03)
								{//find by order
									gw_DirIndex[1] = 0;
									ptr.c_Search_Mode = K_SPECIFIC_STARTCLUSTER;
									ptr.Compare.dw_StartCluster =ptr.dw_File_StartCluster;
									ptr.c_Search_Attribute=1;
									if(Find_Fdb(&ptr))
										break;
								}
							}
							else
							{//not find dir in rootdir
								gs_DIR_FCB[tc_Type].dw_FDB_StartCluster=ptr.dw_FDB_StartCluster;
								break; 
							}
						}
						else
						{//have found 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];
							((U8 *)(&tdw_PrevDirCluster))[2]=gc_UserDataBuf[32+0x1b];
							((U8 *)(&tdw_PrevDirCluster))[1]=gc_UserDataBuf[32+0x14];
							((U8 *)(&tdw_PrevDirCluster))[0]=gc_UserDataBuf[32+0x15];	//current dir
	
							((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; 
								tc_FindFile=0; 
							}
							else
							{
								gw_DirIndex[0] = 0;
								if((tc_Mode&0x0f0)==0x20)
								{//put the line in here is to make dw_FDB_StartCluster equal dw_File_StartCluster 
									tc_FindDir=1; //for tc_Mode=0x28,it has been changed. Here it's to re-changed
								    	gw_DirIndex[1] = 0; 
									ptr.dw_File_StartCluster = ptr.dw_FDB_StartCluster;
									tc_sts=0;
									if((tc_Mode&0x0f)!=0x0b)  //for tc_Mode=0x2b, it must continus counting
										break;									
								} 
								ptr.Compare.dw_BubbleFlag=0x0000;
								tc_FindFile=1; 
							}
							tc_sts=1; 
						}//have find dir 
					}
					else
					{//have find the file --> this line does not occur Here!
						break;
					}
				}//whileB 
			}//find next 
		}//find in all dir
		if(!tc_sts)
		{//find the file/dir
			gbt_FindFlag=1;
			if((tc_Mode&0x0f0)==0x20 || (tc_Mode&0x0f0)==0x30)
			{//dir
				gs_DIR_FCB[tc_Type].dw_File_StartCluster=ptr.dw_File_StartCluster; 
			    	gs_DIR_FCB[tc_Type].dw_FDB_StartCluster=ptr.dw_FDB_StartCluster;  //当前文件(目录)的第一个簇链值。
			 	gs_DIR_FCB[tc_Type].dw_LongFDB_LogAdd1=ptr.dw_LongFDB_LogAdd1;     //所要记长档名的上两个扇区地址
			 	gs_DIR_FCB[tc_Type].dw_LongFDB_LogAdd0=ptr.dw_LongFDB_LogAdd0;//所要记长档名的上一个扇区地址
			 	gs_DIR_FCB[tc_Type].dw_FDB_Cluster=ptr.dw_FDB_Cluster;//短档名FDB所在的簇链值。
				gs_DIR_FCB[tc_Type].dw_FDB_LogAdd=ptr.dw_FDB_LogAdd;//短档名FDB所在逻辑sector的值,以sector为单位。(可//以支持到137Gbytes的媒体容量).
			 	gs_DIR_FCB[tc_Type].w_FDB_Offset=ptr.w_FDB_Offset;//短档名FDB所在逻辑sector的偏移量,以字节为单位。	   		
			}
			return(tc_sts); 
		}
		else if((tc_Mode&0x0f)==0x0b)
		{//Count dir total number
			gw_DirTotalNumber = ptr.w_DirTotalNum;
			return(1);
		}
		else
		{ 
			gs_File_FCB[tc_Type].dw_FDB_StartCluster=ptr.dw_FDB_StartCluster;
			gs_DIR_FCB[tc_Type].dw_FDB_StartCluster=ptr.dw_FDB_StartCluster;
			tc_SearchTime--;
			if(((tc_Mode&0x0f)==1)||((tc_Mode&0x0f)==2)||((tc_Mode&0x0f)==3))
				gbt_FindFlag=0; 
		} 
	}//while

	return(1); 
}



//======================================================================================================
U8 DOS_DIRtable()
{//search all directories dir by dir
	U8 tc_sts, tc_count;
	U8 tc_TempNo,tc_DirTableNo;
	U16 tw_TempTotalNum; //add for the sum of dir and file number in one directory
	U16 tw_DirTable_Offset;
	U8 tc_temp;

	memset(gc_DIRtable,0,2048);	//clear buffer gc_DIRtable

	{ // 1st 32-byte is used for root dir, whose father/child/previous/next folder are still root dir (Offset 0)
		memset(&gc_DIRtable[0x00],1,1);	//mark this 32Bytes is used to save the information of the found dir
		memcpy(&gc_DIRtable[0x01],&gdw_DOS_RootDirClus,4);
		memcpy(&gc_DIRtable[0x05],&gdw_DOS_RootDirClus,4);
	}

	tw_DirTable_Offset = 32;
	for(tc_DirTableNo=0;tc_DirTableNo<64;tc_DirTableNo++)//Root Dir: tc_DirTableNo=0; Finally, tc_DirTableNo is the total directory number
	{		
		if(!gc_DIRtable[tc_DirTableNo<<5]) // not save the info of DIR
			break;
		
		memcpy(&gs_DIR_FCB[0].dw_FDB_StartCluster,&gc_DIRtable[(tc_DirTableNo<<5)+0x01],4); //count which directory for dir
		memcpy(&gs_File_FCB[0].dw_FDB_StartCluster,&gc_DIRtable[(tc_DirTableNo<<5)+0x01],4); //count which directory for file
		gbt_FindFlag = 0;

		DOS_Search_DIR(0x3B,0,0);	//count directory number in this directory, get gw_DirTotalNumber
		DOS_Search_File(0x10,0,0x10);	//count file number in this directory, get gw_FileTotalNumber[0]

		if(!tc_DirTableNo) tc_temp=(U8)gw_DirTotalNumber;
		
		if(tc_DirTableNo==0 && gw_DirTotalNumber==0) //there is no directory
			return 2;

		tw_TempTotalNum=gw_DirTotalNumber+gw_FileTotalNumber[0];
		memcpy(&gc_DIRtable[(tc_DirTableNo<<5)+0x1c],&tw_TempTotalNum,2);//save total number of dir and file in this directory
		memset(&gc_DIRtable[(tc_DirTableNo<<5)+0x1e],(U8)gw_FileTotalNumber[0],1);//save file number of this directory
		memset(&gc_DIRtable[(tc_DirTableNo<<5)+0x1f],(U8)gw_DirTotalNumber,1);//save dir number of this directory

		memcpy(&gs_DIR_FCB[0].dw_FDB_StartCluster,&gc_DIRtable[(tc_DirTableNo<<5)+0x01],4); //from which cluster to search
		for(tc_count=0;tc_count<gw_DirTotalNumber;tc_count++)
		{
			if(tw_DirTable_Offset<2048)
			{
				tc_sts = DOS_Search_DIR(0x33,0,0); //search dir by order in one directory
				if(tc_sts)		//error
					return 1;

				memset(&gc_DIRtable[tw_DirTable_Offset+0x00],1,1);	//mark this 32Bytes is used to save the information of the found dir
				memcpy(&gc_DIRtable[tw_DirTable_Offset+0x01],&gs_DIR_FCB[0].dw_File_StartCluster,4);
				memcpy(&gc_DIRtable[tw_DirTable_Offset+0x05],&gs_DIR_FCB[0].dw_FDB_StartCluster,4);
				memcpy(&gc_DIRtable[tw_DirTable_Offset+0x09],&gs_DIR_FCB[0].dw_LongFDB_LogAdd0,4);
				memcpy(&gc_DIRtable[tw_DirTable_Offset+0x0d],&gs_DIR_FCB[0].dw_FDB_Cluster,4);
				memcpy(&gc_DIRtable[tw_DirTable_Offset+0x11],&gs_DIR_FCB[0].dw_FDB_LogAdd,4);
				memcpy(&gc_DIRtable[tw_DirTable_Offset+0x15],&gs_DIR_FCB[0].w_FDB_Offset,2);
				memcpy(&gc_DIRtable[tw_DirTable_Offset+0x17],&tc_DirTableNo,1); //father folder

				tc_TempNo = (U8)(tw_DirTable_Offset>>5); // /32
				memcpy(&gc_DIRtable[tw_DirTable_Offset+0x18],&tc_TempNo,1); //temporary child folder, set itself
				if(!tc_count)					
				{						
					// 1st folder in this dir, return child folder no to his father folder
					memcpy(&gc_DIRtable[(tc_DirTableNo<<5)+0x18],&tc_TempNo,1); //child folder
					// 1st folder in this dir, then its previous folder is itself
					memcpy(&gc_DIRtable[tw_DirTable_Offset+0x19],&tc_TempNo,1); //previous folder	
				}			
				else
				{	// not 1st folder in this dir, then its previous folder in its previous folder
					tc_TempNo --;
					memcpy(&gc_DIRtable[tw_DirTable_Offset+0x19],&tc_TempNo,1); //previous folder
					tc_TempNo ++;
				}
				if(tc_count==(gw_DirTotalNumber-1)) // last folder in this dir, then its next folder is itself
					memcpy(&gc_DIRtable[tw_DirTable_Offset+0x1a],&tc_TempNo,1); //next folder
				else // not last folder in this dir, then its next folder is its next folder
				{
					tc_TempNo ++;
					memcpy(&gc_DIRtable[tw_DirTable_Offset+0x1a],&tc_TempNo,1); //next folder
					tc_TempNo --;
				}
				tw_DirTable_Offset += 32;
			}
			else	//buffer gc_DIRtable is full
			{
				break;
			}
		}
	}

	gc_Index=1; //for class dir
	memcpy(&gw_TotalNumber, &gc_DIRtable[0x1c],2); //Total number of directory and file in Root dir
	gw_DirTotalNumber=(U16)tc_temp; //Total number of directory in Root dir

	gs_File_FCB[0].dw_FDB_StartCluster = gdw_DOS_RootDirClus;
	gbt_FindFlag = 0;
	gw_FileIndex[0]=0;
	DOS_Search_File(0x03,0,0x10);//FF
	gw_FileTotalNumber[0]=gw_MP3TotalNum;

	return 0;
}


⌨️ 快捷键说明

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