Exemple #1
0
/*
===============================================================================
函数
main();
入口:无
出口:无
===============================================================================
*/ 
void main()
{
  u32 Volume_Capacity,Volume_FreeSpace;
  u8 mode,ATTR;
  u8 buf[280];
  flash_management_sysinit();
  FAT_filesystem_initialiation();
  //运行volume_inquiry
  volume_inquiry('c',&Volume_Capacity,&Volume_FreeSpace);
  //打印volume_inquiry结果
  printf("Volume Capacity: %ld\n",Volume_Capacity);
  printf("Volume FreeSpace: %ld\n",Volume_FreeSpace);
  printf("\nPress any key to continue!");
  scanf("%c",&mode);
  //设置disk_enumeration模式为从C盘根目录开始枚举
  mode = 0; 
  while(disk_enumeration(buf,mode,&ATTR) == SUCC)
  {  mode = 1; 
     //打印成功枚举的directory entry
     printf("\nreaded entry=%s Attr = %x",buf,ATTR);
	 printf("\nPress any key to continue!");
	 scanf("%c",buf);//按任意键继续枚举
  } 

}
Exemple #2
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);	
}