好资料,下面是楼主的主程序main.c文件:
- /*
- +FHDR------------------------------------------------------------------
- Copyright (c),
- Tony Yang –USB,FAT firmware development
- Contact:qq 292942278 e-mail:tony_yang123@sina.com.cn
- ;;;;;;;;;;
- Abstract:
- Sector Read/Write Driver
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- $Id: flash_management.c,v 1.1.1.1 2007/02/26 14:01:12 Design Exp $
- -FHDR-------------------------------------------------------------------
- */
- #include "stdio.h"
- #include "include\types.h"
- #include "fat\fat.h"
- #include "Flash_Management\Flash_Management.h"
- #include "include\FAT_cfg.h"
- #define main__
- #ifdef main__
- extern struct core_ CORE[maximum_disks];;
- //extern u8 bit_map_modified[FAT_Sector_Num];;
- //extern u32 FirstSectorofCluster(u32 N);
- //extern u8 fill_fat_table_on_close_file(u32 first_cluster,u32 FIRST_CLUSTER,u32 ENDCluster,u8 *buf,u8 disk_id);
- /*
- ===============================================================================
- 函数
- main();
- 入口:无
- 出口:无
- ===============================================================================
- */
- static FILE *file2;
- void main(void)
- {
- #if 1
-
- u32 cc,bb,i,cluster,added_cluster,number_of_clusters,last_cluster;
- u16 COUNT;
- u8 a,j,ATTR,mode;
- u8 HANDLE1,HANDLE2;
- u8 buf[655360];
- struct attribute ATTR2;
- struct attribute ATTRIBUTE;
- u8 ddd[] = "c:\\ok\\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa我们aaaaaAAAAAAAAAAAaaaaaaaaa.rar";
- NandFlash_Initialization();
- Makeup_Block_BAD_Table();
- flash_management_sysinit();
- /* if((file2 = fopen("fat32.img","wb+")) == NULL)
- {
- return;
- }
-
- for(i = 0;i<150000*2;i+=32)
- {
- read_flash_sector(buf,i,0,32);
- cc = fwrite(buf,1,512*32,file2);
- }
- scanf("%c",&i);
- scanf("%c",&i);
- scanf("%c",&i);
- scanf("%c",&i);
- */
- FAT_filesystem_autoformat('C',FAT32,150000*2);
- FAT_filesystem_autoformat('D',FAT16,270336);
-
- FAT_filesystem_initialiation();
- Allocate_An_Empty_cluster(&cluster,buf,0);
- printf("cluster=%d",cluster);
- /*create_file("grd g .txt");
- */
- /*cd_folder("d:\\",0);
- a = 0;
- while(folder_enumeration(buf,a,&ATTR2) == SUCC)
- {
- printf("\nreaded entry=%s Attr = %x",buf,ATTR);
- //if(a == 0)
- // delete_folder(buf);
- if(a == 0)
- a = 1;
- }
- scanf("%c",&i);*/
- //return;
- //printf("格式化完成");
- //scanf("%c",&i);
- //disk_id = 1;
- //Allocate_An_Empty_cluster(&cluster,buf,0);
- //printf("cluster=%d",cluster);
- //fill_fat_table_close_file(cluster,cluster+1,1000,buf,1);
- //return;
- /*create_file("d:\\test.txt");
- HANDLE1 = open_file("d:\\test.txt");
- write_file(HANDLE1,buf,500000);
- close_file(HANDLE1);
- printf("写文件完成");
- read_flash_sector(buf,1,1,1);
- buf[100] = 0xff;
- buf[101] = 0xff;
- buf[102] = 0xff;
- buf[103] = 0xf;
- write_flash_sector(buf,1,1,1);
- scanf("%c",&i);
- delete_file("d:\\test.txt");
- return;*/
- // disk_id = 1;
- // printf("first = %d",FirstSectorofCluster(156));
- // scanf("%c",&i);
- /*
- disk_id = 1;
- Allocate_An_Empty_cluster(&cluster,buf,0);
- printf("cluster=%d",cluster);
- scanf("%c",&a);scanf("%c",&a);
- number_of_clusters = 1000;
- Allocate_NUMBERS_OF_EMPTY_CLUSTER_TO_CUR_CLUSTER_CHAIN(cluster,&added_cluster,&last_cluster,buf,0,&number_of_clusters);
- printf("added_cluster =%d,number_of_clusters =%d,last_cluster=%d",added_cluster,number_of_clusters,last_cluster);
- scanf("%c",&a);scanf("%c",&a);
-
-
- Allocate_An_Empty_cluster(&cluster,buf,0);
- printf("cluster=%d",cluster);
- scanf("%c",&a);scanf("%c",&a);
-
- number_of_clusters = 1000;
- Allocate_NUMBERS_OF_EMPTY_CLUSTER_TO_CUR_CLUSTER_CHAIN(cluster,&added_cluster,&last_cluster,buf,0,&number_of_clusters);
- printf("added_cluster =%d,number_of_clusters =%d,last_cluster=%d",added_cluster,number_of_clusters,last_cluster);
- scanf("%c",&a);scanf("%c",&a);
- return;*/
- read_flash_sector(buf,36,0,1);
- buf[100] = 0xff;
- buf[101] = 0xff;
- buf[102] = 0xff;
- buf[103] = 0xf;
- #if 1
- buf[16] = 0xff;
- buf[17] = 0xff;
- buf[18] = 0xff;
- buf[19] = 0xf;
- buf[48] = 0xff;
- buf[49] = 0xff;
- buf[50] = 0xff;
- buf[51] = 0xf;
- buf[32] = 0xff;
- buf[33] = 0xff;
- buf[34] = 0xff;
- buf[35] = 0xf;
- #endif
- buf[108] = 0xff;
- buf[109] = 0xff;
- buf[110] = 0xff;
- buf[111] = 0xf;
- write_flash_sector(buf,36,0,1);
- #if 0
- scanf("%c",&a);
- number_of_clusters = 6;
- Allocate_NUMBERS_OF_EMPTY_CLUSTER_TO_CUR_CLUSTER_CHAIN(cluster,&added_cluster,&last_cluster,buf,0,&number_of_clusters);
- printf("cluster=%d added_cluster =%d last_cluster=%d number_of_clusters=%d\n",cluster,added_cluster,last_cluster,number_of_clusters);
- number_of_clusters = 6;
- Allocate_NUMBERS_OF_EMPTY_CLUSTER_TO_CUR_CLUSTER_CHAIN(cluster,&added_cluster,&last_cluster,buf,0,&number_of_clusters);
- printf("cluster=%d added_cluster =%d last_cluster=%d number_of_clusters=%d\n",cluster,added_cluster,last_cluster,number_of_clusters);
- number_of_clusters = 6;
- Allocate_NUMBERS_OF_EMPTY_CLUSTER_TO_CUR_CLUSTER_CHAIN(cluster,&added_cluster,&last_cluster,buf,0,&number_of_clusters);
- printf("cluster=%d added_cluster =%d last_cluster=%d number_of_clusters=%d\n",cluster,added_cluster,last_cluster,number_of_clusters);
- number_of_clusters = 6;
- Allocate_NUMBERS_OF_EMPTY_CLUSTER_TO_CUR_CLUSTER_CHAIN(cluster,&added_cluster,&last_cluster,buf,0,&number_of_clusters);
- printf("cluster=%d added_cluster =%d last_cluster=%d number_of_clusters=%d\n",cluster,added_cluster,last_cluster,number_of_clusters);
- number_of_clusters = 6;
- Allocate_NUMBERS_OF_EMPTY_CLUSTER_TO_CUR_CLUSTER_CHAIN(cluster,&added_cluster,&last_cluster,buf,0,&number_of_clusters);
- printf("cluster=%d added_cluster =%d last_cluster=%d number_of_clusters=%d\n",cluster,added_cluster,last_cluster,number_of_clusters);
- number_of_clusters = 6;
- Allocate_NUMBERS_OF_EMPTY_CLUSTER_TO_CUR_CLUSTER_CHAIN(cluster,&added_cluster,&last_cluster,buf,0,&number_of_clusters);
- printf("cluster=%d added_cluster =%d last_cluster=%d number_of_clusters=%d\n",cluster,added_cluster,last_cluster,number_of_clusters);
- scanf("%c",&a);
- #endif
- /* cd_folder("d:\\",0);
- create_file("myfile.rar");
- HANDLE1 = open_file("myfile.rar");
- if((file2 = fopen("readed.rar","rb+")) == NULL)
- {
- return;
- }
- if(HANDLE1 != FAIL)
- {
- do{
- printf("#");
- cc = fread(buf,1,500000,file2);
- if(write_file(HANDLE1,buf, cc)==Disk_is_full)
- break;
- if(cc < 500000)
- break;
- }while(1);
- }
- close_file(HANDLE1);
- return;*/
- /*
- printf("copy file");
- scanf("%c",&a);scanf("%c",&a);
- HANDLE1 = open_file("myfile.rar");
- create_file("myfile2.rar");
- HANDLE2 = open_file("myfile2.rar");
- do{
- printf("#");
- cc = read_file(HANDLE1,buf,500000);
- if(write_file(HANDLE2,buf, cc)==Disk_is_full)
- break;
- if(cc < 500000)
- break;
- }while(1);
- scanf("%c",&a);scanf("%c",&a);
- //return;
- close_file(HANDLE1);
- close_file(HANDLE2);
- // return;*/
- #if 0
- create_file("aa.rar");
- HANDLE1 = open_file("aa.rar");
- write_file(HANDLE1,buf,500000);
- write_file(HANDLE1,buf,500000);
- write_file(HANDLE1,buf,500000);
- write_file(HANDLE1,buf,500000);
- write_file(HANDLE1,buf,500000);
- write_file(HANDLE1,buf,500000);
- write_file(HANDLE1,buf,500000);
- write_file(HANDLE1,buf,500000);
- close_file(HANDLE1);
- HANDLE1 = open_file("aa.rar");
- if((file2 = fopen("readed.rar","rb+")) == NULL)
- {
- return;
- }
-
- do{
- printf("#");
- cc = fread(buf,1,500000,file2);
- if(write_file(HANDLE1,buf, cc)==Disk_is_full)
- break;
- if(cc < 500000)
- break;
- }while(1);
- close_file(HANDLE1);
- //printf("close_file");
- fclose(file2);
- #endif
- // return;
- cd_folder("d:\\",0);
- create_floder("中文目录");
- create_floder("中文目录\\中文目录");
- create_file("中文目录\\文件1.txt");
- create_file("中文目录\\文件2.txt");
- create_file("中文目录\\2.txt");
- HANDLE1 = open_file("中文目录\\2.txt");
- write_file(HANDLE1,buf,500000);
- write_file(HANDLE1,buf,500000);
- write_file(HANDLE1,buf,500000);
- write_file(HANDLE1,buf,500000);
- write_file(HANDLE1,buf,500000);
- write_file(HANDLE1,buf,500000);
- write_file(HANDLE1,buf,500000);
- write_file(HANDLE1,buf,500000);
- close_file(HANDLE1);
- //cd_folder("d:\\",0);
- create_file("中文目录\\3.txt");
- HANDLE1 = open_file("中文目录\\3.txt");
- write_file(HANDLE1,buf,500000);
- close_file(HANDLE1);
- printf("write_complete");
- scanf("%c",&i);
- delete_file("中文目录\\2.txt");
- scanf("%c",&i);
- //return;
- cd_folder("中文目录",0);
-
- a = 0;
- while(folder_enumeration(buf,a,&ATTR2) == SUCC)
- {
- printf("\nreaded entry=%s Attr = %x",buf,ATTR);
- printf("\naccess time: %d-%d-%d",ATTR2.access_time_year,ATTR2.access_time_month,ATTR2.access_time_day);
- printf("\ncreate time: %d-%d-%d",ATTR2.create_time_year,ATTR2.create_time_month,ATTR2.create_time_day);
- printf("\ncreate time: %d:%d:%d",ATTR2.create_time_hour,ATTR2.create_time_minute,ATTR2.create_time_second);
- printf("\nmodify time: %d-%d-%d",ATTR2.modify_time_year,ATTR2.modify_time_month,ATTR2.modify_time_day);
- printf("\nmodify time: %d:%d:%d",ATTR2.modify_time_hour,ATTR2.modify_time_minute,ATTR2.modify_time_second);
- printf("\nattr=%x",ATTR2.attr);
- printf("\nFILESIZE=%x",ATTR2.file_size);
- if(a == 0)
- a = 1;
- }
- cd_folder("中文目录",0);
- a = 0;
- while(folder_enumeration(buf,a,&ATTR2) == SUCC)
- {
- printf("\nreaded entry=%s Attr = %x",buf,ATTR);
- printf("\naccess time: %d-%d-%d",ATTR2.access_time_year,ATTR2.access_time_month,ATTR2.access_time_day);
- printf("\ncreate time: %d-%d-%d",ATTR2.create_time_year,ATTR2.create_time_month,ATTR2.create_time_day);
- printf("\ncreate time: %d:%d:%d",ATTR2.create_time_hour,ATTR2.create_time_minute,ATTR2.create_time_second);
- printf("\nmodify time: %d-%d-%d",ATTR2.modify_time_year,ATTR2.modify_time_month,ATTR2.modify_time_day);
- printf("\nmodify time: %d:%d:%d",ATTR2.modify_time_hour,ATTR2.modify_time_minute,ATTR2.modify_time_second);
- printf("\nattr=%x",ATTR2.attr);
- printf("\nFILESIZE=%x",ATTR2.file_size);
- if(a == 0)
- a = 1;
- }
- /*bit_map_modified[0] = 1;
- bit_map_modified[1] = 1;
- bit_map_modified[4] = 1;
- bit_map_modified[5] = 1;
- bit_map_modified[6] = 1;
- bit_map_modified[28] = 1;
- bit_map_modified[29] = 1;
- bit_map_modified[30] = 1;
- bit_map_modified[31] = 1;
- bit_map_modified[32] = 1;
- bit_map_write();
- while(1);*/
- ///disk_id =1;
- Allocate_An_Empty_cluster(&cluster,buf,0);
- printf("cluster=%d",cluster);
-
- /* scanf("%c",&a);
- number_of_clusters = 6;
- Allocate_NUMBERS_OF_EMPTY_CLUSTER_TO_CUR_CLUSTER_CHAIN(cluster,&added_cluster,&last_cluster,buf,0,&number_of_clusters);
- printf("cluster=%d added_cluster =%d last_cluster=%d number_of_clusters=%d\n",cluster,added_cluster,last_cluster,number_of_clusters);
- number_of_clusters = 6;
- Allocate_NUMBERS_OF_EMPTY_CLUSTER_TO_CUR_CLUSTER_CHAIN(cluster,&added_cluster,&last_cluster,buf,0,&number_of_clusters);
- printf("cluster=%d added_cluster =%d last_cluster=%d number_of_clusters=%d\n",cluster,added_cluster,last_cluster,number_of_clusters);
- number_of_clusters = 6;
- Allocate_NUMBERS_OF_EMPTY_CLUSTER_TO_CUR_CLUSTER_CHAIN(cluster,&added_cluster,&last_cluster,buf,0,&number_of_clusters);
- printf("cluster=%d added_cluster =%d last_cluster=%d number_of_clusters=%d\n",cluster,added_cluster,last_cluster,number_of_clusters);
- number_of_clusters = 6;
- Allocate_NUMBERS_OF_EMPTY_CLUSTER_TO_CUR_CLUSTER_CHAIN(cluster,&added_cluster,&last_cluster,buf,0,&number_of_clusters);
- printf("cluster=%d added_cluster =%d last_cluster=%d number_of_clusters=%d\n",cluster,added_cluster,last_cluster,number_of_clusters);
- number_of_clusters = 6;
- Allocate_NUMBERS_OF_EMPTY_CLUSTER_TO_CUR_CLUSTER_CHAIN(cluster,&added_cluster,&last_cluster,buf,0,&number_of_clusters);
- printf("cluster=%d added_cluster =%d last_cluster=%d number_of_clusters=%d\n",cluster,added_cluster,last_cluster,number_of_clusters);
- number_of_clusters = 6;
- Allocate_NUMBERS_OF_EMPTY_CLUSTER_TO_CUR_CLUSTER_CHAIN(cluster,&added_cluster,&last_cluster,buf,0,&number_of_clusters);
- printf("cluster=%d added_cluster =%d last_cluster=%d number_of_clusters=%d\n",cluster,added_cluster,last_cluster,number_of_clusters);
- scanf("%c",&a);
- //return;*/
- #if 1
- volume_inquiry('c',&cc,&bb);
- printf("Volume C Capacity: %ld\n",cc);
- printf("Volume C FreeSpace: %ld\n",bb);
- volume_inquiry('d',&cc,&bb);
-
- printf("Volume D Capacity: %ld\n",cc);
- printf("Volume D FreeSpace: %ld\n",bb);
- scanf("%c",&a);
- scanf("%c",&a);
- //return;
- create_floder("D:\\ok");
- create_file("d:\\ok\\1_1.txt");
- HANDLE1 = open_file("d:\\ok\\1_1.txt");
-
-
- if(HANDLE1 == 0XFF)
- {
- printf("open file failed");
- scanf("%c",&a);
- }
- for(i = 0;i<10000;i++)
- buf[i] = 0x55;
- write_file(HANDLE1,buf,10000);
- write_file(HANDLE1,buf,10000);
- write_file(HANDLE1,buf,10000);
- write_file(HANDLE1,buf,10000);
- f_seek(HANDLE1,200,SEEK_SET);
- for(i = 0;i<100;i++)
- buf[i] = i;
- write_file(HANDLE1,buf,100);
- close_file(HANDLE1);
- //scanf("%c",&a);
- /* 建立一个目录CREATE_FOLDER_TEST,以测试建立目录函数create_floder() */
- create_floder("D:\\aaaaaaaaaa");
- create_floder("d:\\aaaaaaaaaa");
- create_floder("aaaaaaaaaaA");
- create_floder("aaaaaaaaaaA");
- create_file("D:\\aaaaaaaaaaAA我们.TXT");
- create_file("c:\\aaaaaaaaaaAA.TXT");
- create_floder("C:\\AAAAAAAAAAAaaaaaa");
- create_floder("D:\\AAAAAAAAAAAaaaaaa");
- create_floder("c:\\CREATE_FOLDER_TEST");
- create_floder("D:\\CREATE_FOLDER_TEST");
- scanf("%c",&a);
- if(get_file_attribute("c:\\aaaaaaaaaaAA.TXT", The_FILE, &ATTRIBUTE)== SUCC)
- { printf("\n文件:aaaaaaaaaaAA.TXT");
- printf("\naccess time: %d-%d-%d",ATTRIBUTE.access_time_year,ATTRIBUTE.access_time_month,ATTRIBUTE.access_time_day);
- printf("\ncreate time: %d-%d-%d",ATTRIBUTE.create_time_year,ATTRIBUTE.create_time_month,ATTRIBUTE.create_time_day);
- printf("\ncreate time: %d:%d:%d",ATTRIBUTE.create_time_hour,ATTRIBUTE.create_time_minute,ATTRIBUTE.create_time_second);
- printf("\nmodify time: %d-%d-%d",ATTRIBUTE.modify_time_year,ATTRIBUTE.modify_time_month,ATTRIBUTE.modify_time_day);
- printf("\nmodify time: %d:%d:%d",ATTRIBUTE.modify_time_hour,ATTRIBUTE.modify_time_minute,ATTRIBUTE.modify_time_second);
- printf("\nattr=%x",ATTR2.attr);
- }
- else
- {
- printf("FAIL");
- }
-
- scanf("%c",&a);
- /* 在目录CREATE_FOLDER_TEST下建立一个文件,以测试建立目录函数create_file() */
- create_file("C:\\CREATE_FOLDER_TEST\\created_file.txt");
- create_file("D:\\CREATE_FOLDER_TEST\\created_file.txt");
- create_file("C:\\CREATE_FOLDER_TEST\\AAAAAAAAAAB");
- create_file("D:\\CREATE_FOLDER_TEST\\AAAAAAAAAABaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
- create_file("D:\\CREATE_FOLDER_TEST\\AAAAAAAAAABB");
- create_file("D:\\CREATE_FOLDER_TEST\\AAAAAAAAAABBBB");
- create_file("D:\\ok\\aa.rarc");
- //printf("\n\n rename_folder");
- rename_folder("C:\\CREATE_FOLDER_TEST","short");
- //printf("\n\n exit rename_folder");
- /* 重命令文件CREATE_FOLDER_TEST\\created_file.txt为"DFDFDFDFDFDFDFDFSDFSDTONY.TXT"
- ,以测试重命名文件函数rename_file() */
- //rename_file("ok\\bAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.RAR","DFDFDFDFDFDFDFDFSDFSDTONY.TXT");
- //scanf("%c",&a);
- /* 删除文件CREATE_FOLDER_TEST\\created_file.txt */
- //delete_file("ok\\ZZZZZZZZZZZZZZZUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.RAR");
- /* 删除目录CREATE_FOLDER_TEST */
- //delete_folder("CREATE_FOLDER_TEST");
- /* 列举CREATE_FOLDER_TEST目录下面的所有文件,打印到屏幕 */
- cd_folder("C:\\short",0);
-
- a = 0;
- while(folder_enumeration(buf,a,&ATTR2) == SUCC)
- {
- printf("\nreaded entry=%s Attr = %x",buf,ATTR);
- if(a == 0)
- a = 1;
- }
- scanf("%c",&a);
- cd_folder(" ",1);
- /* 列举根目录的文件,打印去屏幕 */
-
- a = 0;
- while(folder_enumeration(buf,a,&ATTR2) == SUCC)
- {
- printf("\nreaded entry=%s Attr = %x",buf,ATTR);
- if(a == 0)
- a = 1;
- }
- printf("开始写连续文件");
- scanf("%c",&a);scanf("%c",&a);
- //delete_file(ddd);
- /* 在OK目录下连续写文件,readed.rar,直到磁盘被写满 */
- create_floder("c:\\ok");
- j = 0;
- COUNT = 0;
- do{
- for(a = 0;a < 25; a++)
- {
- COUNT++;
- //printf("close_file");
- if(create_file(ddd) == SUCC)//File_already_exist)
- {
- printf("Create file %s successfully\n",ddd);
- HANDLE1 = open_file(ddd);
- if((file2 = fopen("readed.rar","rb+")) == NULL)
- {
- return;
- }
- if(HANDLE1 != FAIL)
- {
-
- printf("\nOpen File %s successfully",ddd);
- do{
- printf("#");
- cc = fread(buf,1,500000,file2);
- if(write_file(HANDLE1,buf, cc)==Disk_is_full)
- break;
- //write_file(HANDLE1,buf, cc);
- if(cc < 500000)
- break;
- }while(1);
- close_file(HANDLE1);
- //printf("close_file");
- fclose(file2);
- //break;
- //return;
- }
- else
- printf("\nOpen File %s failed",ddd);
- }
- else
- printf("Create file %s failed\n",ddd);
- ddd[6+j] ++;
- }
- //break;
- j++;
- }while(j< 20);
- printf("CORE[disk_id].min_cluster_for_allocat=%d",CORE[0].min_cluster_for_allocat);
- scanf("%c",&a);
- //return;
- /*
- scanf("%c",&a);
- cd_folder("c:\\ok",0);
-
- a = 0;
- while(folder_enumeration(buf,a,&ATTR) == SUCC)
- {
- printf("\nreaded entry=%s Attr = %x",buf,ATTR);
- delete_file(buf);
- if(a == 0)
- a = 1;
- }
- a = delete_folder("c:\\ok");
- if(a == SUCC)
- printf("delete_folder c:\\ok 成功");
- else if(a == Folder_for_delete_not_exist)
- printf("Folder_for_delete_not_exist");
- else if(a == Folder_is_not_empty)
- printf("Folder_is_not_empty");
- scanf("%c",&a);*/
- /* 分离磁盘0中的所有文件 */
- /* 分离磁盘0中的所有文件 */
- printf(" /* 分离磁盘0中的所有文件 */");
- scanf("%c",&a);
- a = 0;
- while(disk_enumeration(0,buf,a,&ATTR) == SUCC)
- {
- printf("\nreaded entry=%s Attr = %x",buf,ATTR);
- if(a == 0)
- a = 1;
- ///printf("write 6 failed!");
- if(ATTR & ATTR_DIRECTORY)
- {
- mkdir(buf+3);
- continue;
- }
- else
- {//printf("write 5 failed!");
- if ((file2 = fopen(buf+3,"wb+")) == NULL)
- {
- return;
- }
- else
- HANDLE1 = open_file(buf);
- }
- //printf("write 4 failed! %d",HANDLE1);
- if(HANDLE1 != FAIL)
- do{
- // printf("read 21 failed!");
- cc = read_file(HANDLE1,buf+400,55000);
- //printf("read failed!");
- printf("\nreaded chars = %ld ",cc);
- fwrite(buf+400,1,cc,file2);
- //printf("write failed!");
- if(cc != 55000)
- {
- close_file(HANDLE1);
-
-
- break;
- }
-
- }while(1);
- else{
- printf("Openfile failed!");
- }
- fclose(file2);
- }
- scanf("%c",&a);
- scanf("%c",&a);
- #endif
- #endif
- #define new_
- #ifdef new_
- printf("开始拷贝文件");
- scanf("%c",&a);
- scanf("%c",&a);
- /* DISK0 拷贝至DISK1 */
- mode = 0; //设置disk_enumeration列举mode(0)-复位至第一个文件项或目录项开始枚举
- while(disk_enumeration(0,buf,mode,&ATTR) == SUCC) //枚举一个目录项或目录项
- {
- printf("\nreaded entry=%s Attr = %x",buf,ATTR); //打印被枚举的一个目录项或目录项
-
- if(mode == 0)
- mode = 1; //设置disk_enumeration列举mode(1)- 继续上一枚举后的目录项或目录项
- if(ATTR & ATTR_DIRECTORY)
- {
- buf[0]++;
- create_floder(buf); //建一个disk_enumeration的目录
- continue;
- }
- else //复制文件
- { HANDLE1 = open_file(buf); //打开文件
- buf[0]++;
- create_file(buf); //在DISK1上建立文件
-
- }
- if(HANDLE1 != FAIL)
- { HANDLE2 = open_file(buf); //打开DISK1上建立的文件
- if(HANDLE2 == FAIL)
- break;
- if(HANDLE2 == The_disk_is_full)
- break;
- do{ //复制文件
- cc = read_file(HANDLE1,buf+400,500000); //读文件
- printf("\nreaded chars = %ld ",cc); //打印读文件读取的字节数
- if(write_file(HANDLE2,buf+400,cc)==Disk_is_full)
- {close_file(HANDLE1); //文件复制结束,关闭文件
- close_file(HANDLE2);
- break; //将读取的字节写去DISK1上的文件
- }
- if(cc != 500000) //检查读取的字节数,确认文件尾
- {
- close_file(HANDLE1); //文件复制结束,关闭文件
- close_file(HANDLE2);
- break;
- }
- }while(1);
- }
- else
- {
- printf("Openfile failed!");
- }
- }
- #else
- /* DISK0 拷贝至DISK1 */
- mode = 0; //设置disk_enumeration列举mode(0)-复位至第一个文件项或目录项开始枚举
- while(disk_enumeration(0,buf,mode,&ATTR) == SUCC) //枚举一个目录项或目录项
- {
- printf("\nreaded entry=%s Attr = %x",buf,ATTR); //打印被枚举的一个目录项或目录项
-
- if(mode == 0)
- mode = 1; //设置disk_enumeration列举mode(1)- 继续上一枚举后的目录项或目录项
- if(ATTR & ATTR_DIRECTORY)
- {
- buf[0]++;
- create_floder(buf); //建一个disk_enumeration的目录
- continue;
- }
- else //复制文件
- { HANDLE1 = open_file(buf); //打开文件
- buf[0]++;
- create_file(buf); //在DISK1上建立文件
-
- }
- if(HANDLE1 != FAIL)
- { HANDLE2 = open_file(buf); //打开DISK1上建立的文件
- if(HANDLE2 == FAIL)
- break;
- do{ //复制文件
- cc = read_file(HANDLE1,buf+400,50000); //读文件
- printf("\nreaded chars = %ld ",cc); //打印读文件读取的字节数
- cc = write_file(HANDLE2,buf+400,cc); //将读取的字节写去DISK1上的文件
- if(cc != 50000) //检查读取的字节数,确认文件尾
- {
- close_file(HANDLE1); //文件复制结束,关闭文件
- close_file(HANDLE2);
- break;
- }
- }while(1);
- }
- else
- {
- printf("Openfile failed!");
- }
- }
- #endif
- scanf("%c",&a);
- #else
- #endif
- }
- #if 0
- void main(void)
- {
- u8 ret,buf[65536],ATTR;
- u8 a;
- u8 handle;
- struct attribute ATTRIBUTE;
- ret = flash_management_sysinit();
- ret = FAT_filesystem_autoformat('C',FAT32,270336*2*2);
- ret = FAT_filesystem_initialiation();
- ret = create_floder("C:\\newFolder_0");
- if (ret == 0)
- {
- printf("newFolder_0 创建成功!\n");
- }
-
- ret = create_file("C:\\newFolder_0\\newFile_1");
- if (ret == 0)
- {
- printf("newFolder_0\\newFile_1 创建成功!\n");
- }
- ret = create_file("C:\\newFolder_0\\newFile_2");
- if (ret == 0)
- {
- printf("newFolder_0\\newFile_2 创建成功!\n");
- }
- ret = delete_file("C:\\newFolder_0\\newFile_1");
- if (ret == 0)
- {
- printf("newFolder_0\\newFile_1 删除成功!\n");
- }
- ret = delete_file("C:\\newFolder_0\\newFile_2");
- if (ret == 0)
- {
- printf("newFolder_0\\newFile_2 删除成功!\n");
- }
- cd_folder("C:\\newFolder_0",1);
- ret = delete_folder("C:\\newFolder_0");//成功
- if (ret == 0)
- {
- printf("newFolder_0 删除成功!\n\n");
- }
- else
- printf("newFolder_0 删除失败!\n\n");
- create_file("folder"); //1、cd_folder()函数把没有后缀的文件当成文件夹。--解决了
- if(cd_folder("folder",0)==0)
- {
- printf("\n进入目录成功!");
-
- }
- else
- {
- printf("\n进入目录失败!");
-
- }
- //2、create_floder()可以创建带".*"后缀的文件夹,但是folder_enumeration()无法识别(WinImage可以识别为文件夹)。
- //测试结果,可以识别的啊
- cd_folder("c:\\",0);
- create_floder("CREATE_FOLDER.*");
- a = 0;
- while(folder_enumeration(buf,a,&ATTR2) == SUCC)
- {
- printf("\nreaded entry=%s Attr = %x",buf,ATTR);
- if(a == 0)
- a = 1;
- }
- //3、create_file()创建文件后,名称的英文字符会全部变成大写。
- //测试结果----通过WINIMG查看--大小写未变啊!
- create_file("c:\\aaaaaaaaAAAAAAAAAAAAA");
- //4、rename_file()函数重命名文件和文件夹后,名称的英文字符会全部变成大写。
- //代码已经修改--已经解决了
- create_file("c:\\olderFile");
- rename_file("c:\\olderFile","NewFile");
- //5、rename_file()可以把文件夹修改为带".*"后缀的名称,修改成功后无法用cd_folder()进入,用
- // WinImage打开识别为后缀名类型的文件。
- //6、rename_file()函数重命名文件夹成功后,folder_enumeration()可以识别(用WinImage无法识别文
- //件夹,文件类型变成了"本地磁盘")。
- //通过修改代码,rename_file只能修改文件的名称
- create_floder("c:\\olderFolderName");
- if(rename_file("c:\\olderFolderName","NewFileName")==0)
- {
- printf("\nrename_file()修改文件夹成功!");
- }
- else
- {
- printf("\nrename_file()修改文件夹失败!");
- }
- //7、delete_file()函数可以删除文件夹,删除成功后文件夹消失,但是空间并没有释放。
- //代码已修改,现在delete_file()不能删除文件夹
- //删除文件夹请用delete_folder()
- create_floder("c:\\tempfolder");
- if(delete_file("c:\\tempfolder") == 0)
- {
- printf("\ndelete_file()删除文件夹成功!");
- }
- else
- {
- printf("\ndelete_file()删除文件夹失败!");
- }
- //1、添加获取文件夹和文件的属性的函数:包括:是不是文件夹、名称、大小、创建时间,修改时间等。
- //获取文件的访问,建立,修改时间,文件大小
- create_file("test.txt");
- handle = open_file("test.txt");//写入文件50000个字节
- write_file(handle,buf,50000);
- close_file(handle);
- if(get_file_attribute("test.txt", The_FILE, &ATTRIBUTE)== SUCC)
- {
- printf("\n文件:test.txt\naccess time: %d-%d-%d",ATTR2.access_time_year,ATTR2.access_time_month,ATTR2.access_time_day);
- printf("\ncreate time: %d-%d-%d",ATTR2.create_time_year,ATTR2.create_time_month,ATTR2.create_time_day);
- printf("\ncreate time: %d:%d:%d",ATTR2.create_time_hour,ATTR2.create_time_minute,ATTR2.create_time_second);
- printf("\nmodify time: %d-%d-%d",ATTR2.modify_time_year,ATTR2.modify_time_month,ATTR2.modify_time_day);
- printf("\nmodify time: %d:%d:%d",ATTR2.modify_time_hour,ATTR2.modify_time_minute,ATTR2.modify_time_second);
- printf("\nattr=%x",ATTR2.attr);
- if(ATTR2.attr & ATTR_DIRECTORY)
- {
- printf("\n这是一个文件夹");
- }
- else
- {
- printf("\n这是一个文件");
- }
- printf("\nfile_size = %d",ATTR2.file_size);
- }
- else
- {
- printf("FAIL");
- }
- //获取目录的访问,建立,修改时间
- create_floder("test");
- if(get_file_attribute("test", The_DIRECTORY, &ATTRIBUTE)== SUCC)
- {
- printf("\n目录:test\naccess time: %d-%d-%d",ATTR2.access_time_year,ATTR2.access_time_month,ATTR2.access_time_day);
- printf("\ncreate time: %d-%d-%d",ATTR2.create_time_year,ATTR2.create_time_month,ATTR2.create_time_day);
- printf("\ncreate time: %d:%d:%d",ATTR2.create_time_hour,ATTR2.create_time_minute,ATTR2.create_time_second);
- printf("\nmodify time: %d-%d-%d",ATTR2.modify_time_year,ATTR2.modify_time_month,ATTR2.modify_time_day);
- printf("\nmodify time: %d:%d:%d",ATTR2.modify_time_hour,ATTR2.modify_time_minute,ATTR2.modify_time_second);
- printf("\nattr=%x",ATTR2.attr);
- if(ATTR2.attr & ATTR_DIRECTORY)
- {
- printf("\n这是一个文件夹");
- }
- else
- {
- printf("\n这是一个文件");
- }
- }
- else
- {
- printf("FAIL");
- }
- //1. 判断该文件是文件夹还是文件
- printf("\n\n1. 判断该文件是文件夹还是文件");
- create_file("c:\\test.txt");
- switch (check_type("c:\\test.txt"))
- {
- case The_DIRECTORY:printf("\n文件c:\\test.txt是一个目录");break;
- case The_FILE:printf("\n文件c:\\test.txt是一个文件");break;
- case The_file_is_not_exist:printf("\n文件c:\\test.txt不存在");break;
- }
- create_floder("c:\\test");
- switch (check_type("c:\\test"))
- {
- case The_DIRECTORY:printf("\n文件c:\\test是一个目录");break;
- case The_FILE:printf("\n文件c:\\test是一个文件");break;
- case The_file_is_not_exist:printf("\n文件c:\\test不存在");break;
- }
- switch (check_type("c:\\not_exist"))
- {
- case The_DIRECTORY:printf("\n文件c:\\not_exist是一个目录");break;
- case The_FILE:printf("\n文件c:\\not_exist是一个文件");break;
- case The_file_is_not_exist:printf("\n文件c:\\not_exist不存在");break;
- }
- //2.判断文件夹或文件是否存在
- printf("\n\n2.判断文件夹或文件是否存在");
- create_floder("c:\\temp");
- if(check_exist("c:\\temp", The_DIRECTORY) == 0)
- {
- printf("\n\n目录c:\\temp存在!");
- }
- else
- {
- printf("\n\n目录c:\\temp不存在!");
- }
- create_file("c:\\file");
- if(check_exist("c:\\file", The_FILE) == 0)
- {
- printf("\n\n文件c:\\file存在!");
- }
- else
- {
- printf("\n\n文件c:\\file不存在!");
- }
- if(check_exist("c:\\file_not_exist", The_FILE) == 0)
- {
- printf("\n\n文件c:\\file_not_exist存在!");
- }
- else
- {
- printf("\n\n文件c:\\file_not_exist不存在!");
- }
- scanf("%c",&ret);
- }
- #endif
- /*
- +FFTR--------------------------------------------------------------------
- $Log: main.C,v $
- Revision 1.12 2007/05/10 11:13:14 design
- -FFTR--------------------------------------------------------------------
- */
复制代码 |