Example #1
0
/*
===============================================================================
函数
列举disk中所有文件和目录
入口:无
出口:无
===============================================================================
*/ 
u8 disk_enumeration(u8 *return_string,u8 mode,u8* ATTR)
{
 u16 temp; 
 do{ 
    if( ! mode)
	{
     cd_folder("C:\\",0);
	 if(folder_enumeration(return_string,0,ATTR) == FAIL)
         return(FAIL);
	 mode = 1;
	}
    else if(folder_enumeration(return_string,1,ATTR) == FAIL)
	{
		do{ 		  
          if(cd_folder("C",1) == 0x55)
		    return(FAIL);
   CORE.DIR_ENUM_ClusterNum = CORE.ClusterNum;   //存放当前Enumerated Directory Entry所在Directory的ClusterNum,SectorNum,offset
   CORE.DIR_ENUM_SectorNum =CORE.SectorNum ;
   CORE.DIR_ENUM_offset = CORE.offset;
   CORE.DIR_ENUM_ClusterOfDirectoryEntry = CORE.ClusterOfDirectoryEntry;  //存放Directory Entry32字节中对应first Cluster Num
   CORE.DIR_ENUM_DirectoryType = CORE.CurrentDirectoryType; 
   CORE.DIR_ENUM_FullPathType = CORE.FullPathType;
   CORE.DIR_ENUM_CurPathType = CORE.CurPathType; 
	      if(folder_enumeration(return_string,1,ATTR) == SUCC)
		    break;
	  }while(1);
	}
  if((*ATTR) & ATTR_DIRECTORY)
  {   
      temp = LengthofString(return_string);
	  if(return_string[temp - 1] == '.' || (return_string[temp - 1] == '.' &&
		  return_string[temp - 2] == '.') )
		  continue;
    #if filter_hidden_entry
	  if ((*ATTR) & ATTR_HIDDEN)
		  continue;
    #endif 
	  if(cd_folder(return_string,0) == FAIL)
	    return(FAIL);
   CORE.DIR_ENUM_ClusterNum = CORE.ClusterNum;   //存放当前Enumerated Directory Entry所在Directory的ClusterNum,SectorNum,offset
   CORE.DIR_ENUM_SectorNum =CORE.SectorNum ;
   CORE.DIR_ENUM_offset = CORE.offset;
   CORE.DIR_ENUM_ClusterOfDirectoryEntry = CORE.ClusterOfDirectoryEntry;  //存放Directory Entry32字节中对应first Cluster Num
   CORE.DIR_ENUM_DirectoryType = CORE.DirectoryType; 
   CORE.DIR_ENUM_FullPathType = CORE.FullPathType;
   CORE.DIR_ENUM_CurPathType = CORE.CurPathType; 
	}
    return(SUCC);
 }while(1);
  
}
Example #2
0
u8 folder_enumeration(u8 *return_string,u8 mode,u8 *ATTR)
{ 
  u8  Extension[4];
  u16 temp;
  if(mode == 0x0)
  {
   CORE.FullPathType = DirectoryPath; 
   if(cd_folder(CORE.current_folder,0) != SUCC)
	   return(FAIL);
   CORE.offset = 0;
   if(CORE.CurrentDirectoryType ==  RootDirectory)
      CORE.SectorNum = CORE.FirstRootDirSecNum; 
   else
     {
       CORE.ClusterNum = CORE.ClusterNOofCurrentFolder;
       CORE.SectorNum = FirstSectorofCluster(CORE.ClusterNum); 
     }
   CORE.DIR_ENUM_ClusterNum = CORE.ClusterNum;   //存放当前Enumerated Directory Entry所在Directory的ClusterNum,SectorNum,offset
   CORE.DIR_ENUM_SectorNum =CORE.SectorNum ;
   CORE.DIR_ENUM_offset = CORE.offset;
   CORE.DIR_ENUM_ClusterOfDirectoryEntry = CORE.ClusterOfDirectoryEntry;  //存放Directory Entry32字节中对应first Cluster Num
   CORE.DIR_ENUM_DirectoryType = CORE.DirectoryType; 
   CORE.DIR_ENUM_FullPathType = CORE.FullPathType;
   CORE.DIR_ENUM_CurPathType = CORE.CurPathType; 
  } 
   CORE.ClusterNum = CORE.DIR_ENUM_ClusterNum;   //存放当前Enumerated Directory Entry所在Directory的ClusterNum,SectorNum,offset
   CORE.SectorNum = CORE.DIR_ENUM_SectorNum;
   CORE.offset = CORE.DIR_ENUM_offset;
   CORE.ClusterOfDirectoryEntry = CORE.DIR_ENUM_ClusterOfDirectoryEntry;  //存放Directory Entry32字节中对应first Cluster Num
   CORE.DirectoryType = CORE.DIR_ENUM_DirectoryType; 
   CORE.FullPathType = CORE.DIR_ENUM_FullPathType;
   CORE.CurPathType = CORE.DIR_ENUM_CurPathType; 
  stringcpy(CORE.current_folder,return_string);
  temp = LengthofString(return_string);
  if(return_string[temp-1] != '\\')
  {
   return_string[temp] = '\\';
   return_string[temp+1] = 0;
  }
  if(GetEntryFromDirectory(return_string+LengthofString(return_string), Extension,Get_All_Entries) == SUCC)
  {
   temp = LengthofString(return_string);
   *ATTR = CORE.Entry_Attr;
   if(temp > 0 && (!((*ATTR) & ATTR_DIRECTORY)))
   {
    if(Extension[0] != 0)
	{
     return_string[temp] = '.';
     return_string[temp+1] = 0;
	 concanenateString(return_string,Extension);
	}
   }
   CORE.DIR_ENUM_ClusterNum = CORE.ClusterNum;   //存放当前Enumerated Directory Entry所在Directory的ClusterNum,SectorNum,offset
   CORE.DIR_ENUM_SectorNum =CORE.SectorNum ;
   CORE.DIR_ENUM_offset = CORE.offset;
   CORE.DIR_ENUM_ClusterOfDirectoryEntry = CORE.ClusterOfDirectoryEntry;  //存放Directory Entry32字节中对应first Cluster Num
   CORE.DIR_ENUM_DirectoryType = CORE.DirectoryType; 
   CORE.DIR_ENUM_FullPathType = CORE.FullPathType;
   CORE.DIR_ENUM_CurPathType = CORE.CurPathType; 
   return(SUCC);
  }
  return(FAIL);
} 
Example #3
0
int main(void)
{
  u32 cc,bb;
  u16 COUNT;
  u8 a,ATTR,j;
  u8 HANDLE1; 
  u8 buf[65535];
  u8 ddd[] = "c:\\ok\\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAaaaaaaaaa.rar";
  
  //初始化虚拟磁盘的驱动
  flash_management_sysinit();
  FAT_filesystem_autoformat(0,FAT16,483328);
  FAT_filesystem_initialiation();

  //调用函数volume_inquiry,查询分区容量和剩余空间
  volume_inquiry('c',&cc,&bb);

  //打印虚拟磁盘分区容量和剩余空间
  printf("Volume Capacity: %ld\n",cc);
  printf("Volume FreeSpace: %ld\n",bb);
  scanf("%c",&a);

  /*建立目录CREATE_FOLDER_TEST,用于测试建立目录函数create_floder()*/

  create_floder("CREATE_FOLDER_TEST");
  create_floder("CREATE_FOLDER_TEST");//目录再建失败, 不可以建重复的目录


  /*目录建立测试*/
  create_floder("a");
  create_floder("a\\b");
  create_floder("a\\b\\c");
  create_floder("a\\b\\c\\d");


  /*建文件在目录CREATE_FOLDER_TEST下,用于测试建立文件函数create_file()*/
  
  create_file("C:\\CREATE_FOLDER_TEST\\created_file.txt");

  create_file("C:\\CREATE_FOLDER_TEST\\created_file.txt");//文件再建失败,不可以建重复的文件


  /* 重命名文件CREATE_FOLDER_TEST\\created_file.txt为"created_file_new.txt",用于测试文件重命名函数rename_file() */
  rename_file("C:\\CREATE_FOLDER_TEST\\created_file.txt","created_file_new.txt");
	
  /*  读取目录CREATE_FOLDER_TEST下面的所有ENTRY,打印出来到屏幕*/
  cd_folder("CREATE_FOLDER_TEST",0);
 
  a = 0; //枚举模式初始设定
  while(folder_enumeration(buf,a,&ATTR) == SUCC)
  { 
      //打印读取的Directory ENTRY及其attribute
	  printf("\nreaded entry=%s Attr = %x",buf,ATTR);

     if(a == 0)
	   a = 1;//枚举模式修改为枚举继续
  }

  scanf("%c",&a);	

  cd_folder(" ",1); //返回到根目录

  /*  读取根目录的所有ENTRY,打印出来到屏幕  */

  a = 0;//枚举模式初始设定
  while(folder_enumeration(buf,a,&ATTR) == SUCC)
  { 
	  //打印读取的Directory ENTRY及其attribute
     printf("\nreaded entry=%s Attr = %x",buf,ATTR);

     if(a == 0)
	   a = 1;//枚举模式修改为枚举继续
  }

  scanf("%c",&a);	 

  /* 建立一个OK目录,之后向其写文件readed.rar,直到虚拟盘被写满 */ 
  create_floder("OK");

  j = 0;
  COUNT = 0;
  do{
  for(a = 0;a<25;a++)
  {
  COUNT++;
  //调用create_file()往磁盘上建立文件 
  if(create_file(ddd) == SUCC)
  {
   printf("Create file %s successfully\n",ddd);
   
   HANDLE1 = open_file(ddd);//打开刚刚完成建立的文件

   //打开readed.rar,作为写入源文件
   if ((file2 = fopen("readed.rar","rb+")) == NULL)
     {
      return 0;
     }
   if(HANDLE1 != FAIL)
	{   
		//将readed.rar拷入刚刚建立的文件   
		printf("\nOpen File %s successfully",ddd);
		do{
            printf("x");
			//从readed.rar里读数据
            cc = fread(buf,1,40000,file2);  
	        //读数据后拷入刚刚建立的文件 
			write_file(HANDLE1,buf, cc);
		    if(cc < 40000)
			    break;
		}while(1);
		//拷贝整个文件到结束,之后关闭文件
		close_file(HANDLE1);   
		fclose(file2);
	}

  }
  else
   printf("Create file %s failed\n",ddd);
   ddd[6+j] ++; 
  }
  j++;
 }while(j< 40);



  /*把虚拟磁盘上的所有的文件与目录分离到WINDOWS下*/
 
  a = 0;//枚举模式初始设定
  while(disk_enumeration(buf,a,&ATTR) == SUCC)
  { 
     printf("\nreaded entry=%s Attr = %x",buf,ATTR);
     
     if(a == 0)
	   a = 1;	//枚举模式修改为枚举继续

	 if(ATTR & ATTR_DIRECTORY)
	 { 
	   //mkdir(buf+3);
	   continue;
	 }
	 else
     {   //在windows当前目录下建立一个文件,文件名与当前枚举的文件名一致*/
		 if ((file2 = fopen(buf+3,"wb+")) == NULL)
		 {  
            return 0;
		 }    
	     else 
		     HANDLE1 = open_file(buf);
	 }//读数据后拷入刚刚建立的文件 
	if(HANDLE1 != FAIL)
		do{	
	    //从当前的文件读取数据
	    cc = read_file(HANDLE1,buf+400,50000);
		printf("\nreaded chars = %ld ",cc);
        //读数据后拷入刚刚建立的文件
		fwrite(buf+400,1,cc,file2);
		if(cc != 50000)
		{ 
			close_file(HANDLE1);
		    break;   
		}   
	
	}while(1);
    else{
	}
    fclose(file2);	 
  }

  scanf("%c",&a);	
}