2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
4 * Copyright (C) 2002-2010 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Charles Manning <charles@aleph1.co.uk>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
26 #include "yaffs_guts.h" /* Only for dumping device innards */
28 extern int yaffs_traceMask;
30 void dumpDir(const char *dname);
32 void copy_in_a_file(const char *yaffsName,const char *inName)
35 unsigned char buffer[100];
37 inh = open(inName,O_RDONLY);
38 outh = yaffs_open(yaffsName, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
40 while((ni = read(inh,buffer,100)) > 0)
42 no = yaffs_write(outh,buffer,ni);
45 printf("problem writing yaffs file\n");
54 void make_a_file(const char *yaffsName,char bval,int sizeOfFile)
58 unsigned char buffer[100];
60 outh = yaffs_open(yaffsName, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
62 memset(buffer,bval,100);
69 yaffs_write(outh,buffer,i);
71 } while (sizeOfFile > 0);
78 void make_pattern_file(char *fn,int size)
83 outh = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
84 yaffs_lseek(outh,size-1,SEEK_SET);
85 yaffs_write(outh,"A",1);
87 for(i = 0; i < size; i+=256)
90 yaffs_lseek(outh,i,SEEK_SET);
91 yaffs_write(outh,&marker,sizeof(marker));
97 int check_pattern_file(char *fn)
105 h = yaffs_open(fn, O_RDWR,0);
106 size = yaffs_lseek(h,0,SEEK_END);
108 for(i = 0; i < size; i+=256)
110 yaffs_lseek(h,i,SEEK_SET);
111 yaffs_read(h,&marker,sizeof(marker));
115 printf("pattern check failed on file %s, size %d at position %d. Got %x instead of %x\n",
116 fn,size,i,marker,~i);
127 int dump_file_data(char *fn)
134 h = yaffs_open(fn, O_RDWR,0);
138 while(yaffs_read(h,&b,1)> 0)
155 void dump_file(const char *fn)
161 h = yaffs_open(fn,O_RDONLY,0);
164 printf("*****\nDump file %s does not exist\n",fn);
168 size = yaffs_lseek(h,0,SEEK_SET);
169 printf("*****\nDump file %s size %d\n",fn,size);
170 for(i = 0; i < size; i++)
177 void create_file_of_size(const char *fn,int syze)
185 h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
189 sprintf(xx,"%s %8d",fn,iteration);
191 result = yaffs_write(h,xx,n);
193 printf("Wrote %d, should have been %d. syze is %d\n",result,n,syze);
202 void verify_file_of_size(const char *fn,int syze)
211 int iterations = (syze + strlen(fn) -1)/ strlen(fn);
213 h = yaffs_open(fn, O_RDONLY, S_IREAD | S_IWRITE);
215 while (iterations > 0)
217 sprintf(xx,"%s %8d",fn,iterations);
220 result = yaffs_read(h,yy,l);
224 printf("=====>>>>> verification of file %s failed near position %lld\n",fn,(long long)yaffs_lseek(h,0,SEEK_CUR));
231 void create_resized_file_of_size(const char *fn,int syze1,int reSyze, int syze2)
237 h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
239 iterations = (syze1 + strlen(fn) -1)/ strlen(fn);
240 while (iterations > 0)
242 yaffs_write(h,fn,strlen(fn));
246 yaffs_ftruncate(h,reSyze);
248 yaffs_lseek(h,0,SEEK_SET);
249 iterations = (syze2 + strlen(fn) -1)/ strlen(fn);
250 while (iterations > 0)
252 yaffs_write(h,fn,strlen(fn));
260 void do_some_file_stuff(const char *path)
265 sprintf(fn,"%s/%s",path,"f1");
266 create_file_of_size(fn,10000);
268 sprintf(fn,"%s/%s",path,"fdel");
269 create_file_of_size(fn,10000);
272 sprintf(fn,"%s/%s",path,"f2");
274 create_resized_file_of_size(fn,10000,3000,4000);
277 void yaffs_backward_scan_test(const char *path)
285 do_some_file_stuff(path);
287 sprintf(fn,"%s/ddd",path);
291 do_some_file_stuff(fn);
298 void null_name_test(const char *path)
306 sprintf(fn,"%s",path);
308 h = yaffs_open(fn,O_CREAT| O_TRUNC| O_RDWR, 0666);
317 void yaffs_device_flush_test(const char *path)
327 do_some_file_stuff(path);
329 // Open and add some data to a few files
330 for(i = 0; i < 10; i++) {
332 sprintf(fn,"%s/ff%d",path,i);
334 h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IWRITE | S_IREAD);
335 yaffs_write(h,xxzz,2000);
336 yaffs_write(h,xxzz,2000);
345 void short_scan_test(const char *path, int fsize, int niterations)
350 sprintf(fn,"%s/%s",path,"f1");
353 for(i = 0; i < niterations; i++)
355 printf("\n*****************\nIteration %d\n",i);
357 printf("\nmount: Directory look-up of %s\n",path);
359 make_a_file(fn,1,fsize);
366 void scan_pattern_test(const char *path, int fsize, int niterations)
373 sprintf(fn[0],"%s/%s",path,"f0");
374 sprintf(fn[1],"%s/%s",path,"f1");
375 sprintf(fn[2],"%s/%s",path,"f2");
379 for(i = 0; i < niterations; i++)
381 printf("\n*****************\nIteration %d\n",i);
383 printf("\nmount: Directory look-up of %s\n",path);
385 for(j = 0; j < 3; j++)
387 result = dump_file_data(fn[j]);
388 result = check_pattern_file(fn[j]);
389 make_pattern_file(fn[j],fsize);
390 result = dump_file_data(fn[j]);
391 result = check_pattern_file(fn[j]);
397 void fill_disk(const char *path,int nfiles)
407 for(n = 0; n < nfiles; n++)
409 sprintf(str,"%s/%d",path,n);
411 h = yaffs_open(str, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
413 printf("writing file %s handle %d ",str, h);
415 while ((result = yaffs_write(h,xx,600)) == 600)
417 f = yaffs_freespace(path);
419 result = yaffs_close(h);
420 printf(" close %d\n",result);
424 void fill_disk_and_delete(const char *path, int nfiles, int ncycles)
430 for(i = 0; i < ncycles; i++)
432 printf("@@@@@@@@@@@@@@ cycle %d\n",i);
433 fill_disk(path,nfiles);
435 for(j = 0; j < nfiles; j++)
437 sprintf(str,"%s/%d",path,j);
438 result = yaffs_unlink(str);
439 printf("unlinking file %s, result %d\n",str,result);
445 void fill_files(const char *path,int flags, int maxIterations,int siz)
455 sprintf(str,"%s/%d",path,i);
456 h = yaffs_open(str, O_CREAT | O_TRUNC | O_RDWR,S_IREAD | S_IWRITE);
460 for(j = 0; j < siz; j++)
462 yaffs_write(h,str,1);
471 } while(h >= 0 && i < maxIterations);
477 sprintf(str,"%s/%d",path,i);
478 printf("unlink %s\n",str);
480 } while(yaffs_unlink(str) >= 0);
484 void leave_unlinked_file(const char *path,int maxIterations,int siz)
493 sprintf(str,"%s/%d",path,i);
494 printf("create %s\n",str);
495 h = yaffs_open(str, O_CREAT | O_TRUNC | O_RDWR,S_IREAD | S_IWRITE);
501 } while(h < 0 && i < maxIterations);
505 for(i = 0; i < siz; i++)
507 yaffs_write(h,str,1);
511 printf("Leaving file %s open\n",str);
515 void dumpDirFollow(const char *dname)
522 d = yaffs_opendir(dname);
526 printf("opendir failed\n");
530 while((de = yaffs_readdir(d)) != NULL)
532 sprintf(str,"%s/%s",dname,de->d_name);
536 printf("%s ino %d length %d mode %X ",de->d_name,(int)s.st_ino,(int)s.st_size,s.st_mode);
537 switch(s.st_mode & S_IFMT)
539 case S_IFREG: printf("data file"); break;
540 case S_IFDIR: printf("directory"); break;
541 case S_IFLNK: printf("symlink -->");
542 if(yaffs_readlink(str,str,100) < 0)
545 printf("\"%s\"",str);
547 default: printf("unknown"); break;
557 printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
562 void dump_directory_tree_worker(const char *dname,int recursive)
569 d = yaffs_opendir(dname);
573 printf("opendir failed\n");
577 while((de = yaffs_readdir(d)) != NULL)
579 sprintf(str,"%s/%s",dname,de->d_name);
583 printf("%s inode %d obj %x length %d mode %X ",str,s.st_ino,de->d_dont_use,(int)s.st_size,s.st_mode);
584 switch(s.st_mode & S_IFMT)
586 case S_IFREG: printf("data file"); break;
587 case S_IFDIR: printf("directory"); break;
588 case S_IFLNK: printf("symlink -->");
589 if(yaffs_readlink(str,str,100) < 0)
592 printf("\"%s\"",str);
594 default: printf("unknown"); break;
599 if((s.st_mode & S_IFMT) == S_IFDIR && recursive)
600 dump_directory_tree_worker(str,1);
609 static void dump_directory_tree(const char *dname)
611 dump_directory_tree_worker(dname,1);
613 printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
616 void dumpDir(const char *dname)
617 { dump_directory_tree_worker(dname,0);
619 printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
623 static void PermissionsCheck(const char *path, mode_t tmode, int tflags,int expectedResult)
627 if(yaffs_chmod(path,tmode)< 0) printf("chmod failed\n");
629 fd = yaffs_open(path,tflags,0);
631 if((fd >= 0) != (expectedResult > 0))
633 printf("Permissions check %x %x %d failed\n",tmode,tflags,expectedResult);
637 printf("Permissions check %x %x %d OK\n",tmode,tflags,expectedResult);
646 int long_test(int argc, char *argv[])
657 struct yaffs_stat ystat;
661 yaffs_mount("/boot");
662 yaffs_mount("/data");
663 yaffs_mount("/flash");
666 printf("\nDirectory look-up of /boot\n");
668 printf("\nDirectory look-up of /data\n");
670 printf("\nDirectory look-up of /flash\n");
673 //leave_unlinked_file("/flash",20000,0);
674 //leave_unlinked_file("/data",20000,0);
676 leave_unlinked_file("/ram",20,0);
679 f = yaffs_open("/boot/b1", O_RDONLY,0);
681 printf("open /boot/b1 readonly, f=%d\n",f);
683 f = yaffs_open("/boot/b1", O_CREAT,S_IREAD | S_IWRITE);
685 printf("open /boot/b1 O_CREAT, f=%d\n",f);
688 r = yaffs_write(f,"hello",1);
689 printf("write %d attempted to write to a read-only file\n",r);
693 printf("close %d\n",r);
695 f = yaffs_open("/boot/b1", O_RDWR,0);
697 printf("open /boot/b1 O_RDWR,f=%d\n",f);
700 r = yaffs_write(f,"hello",2);
701 printf("write %d attempted to write to a writeable file\n",r);
702 r = yaffs_write(f,"world",3);
703 printf("write %d attempted to write to a writeable file\n",r);
705 r= yaffs_lseek(f,0,SEEK_END);
706 printf("seek end %d\n",r);
708 r = yaffs_read(f,buffer,10);
709 printf("read %d \"%s\"\n",r,buffer);
710 r= yaffs_lseek(f,0,SEEK_SET);
711 printf("seek set %d\n",r);
713 r = yaffs_read(f,buffer,10);
714 printf("read %d \"%s\"\n",r,buffer);
716 r = yaffs_read(f,buffer,10);
717 printf("read %d \"%s\"\n",r,buffer);
719 // Check values reading at end.
720 // A read past end of file should return 0 for 0 bytes read.
722 r= yaffs_lseek(f,0,SEEK_END);
723 r = yaffs_read(f,buffer,10);
724 printf("read at end returned %d\n",r);
725 r= yaffs_lseek(f,500,SEEK_END);
726 r = yaffs_read(f,buffer,10);
727 printf("read past end returned %d\n",r);
731 printf("close %d\n",r);
733 copy_in_a_file("/boot/yyfile","xxx");
735 // Create a file with a long name
737 copy_in_a_file("/boot/file with a long name","xxx");
740 printf("\nDirectory look-up of /boot\n");
744 r = yaffs_lstat("/boot/file with a long name",&ystat);
748 r = yaffs_rename("/boot/file with a long name","/boot/r1");
750 printf("\nDirectory look-up of /boot\n");
754 r = yaffs_unlink("/boot/r1");
756 printf("\nDirectory look-up of /boot\n");
761 r = yaffs_mkdir("/boot/directory1",0);
763 printf("\nDirectory look-up of /boot\n");
765 printf("\nDirectory look-up of /boot/directory1\n");
766 dumpDir("/boot/directory1");
768 // add a file to the directory
769 copy_in_a_file("/boot/directory1/file with a long name","xxx");
771 printf("\nDirectory look-up of /boot\n");
773 printf("\nDirectory look-up of /boot/directory1\n");
774 dumpDir("/boot/directory1");
776 // Attempt to delete directory (should fail)
778 r = yaffs_rmdir("/boot/directory1");
780 printf("\nDirectory look-up of /boot\n");
782 printf("\nDirectory look-up of /boot/directory1\n");
783 dumpDir("/boot/directory1");
785 // Delete file first, then rmdir should work
786 r = yaffs_unlink("/boot/directory1/file with a long name");
787 r = yaffs_rmdir("/boot/directory1");
790 printf("\nDirectory look-up of /boot\n");
792 printf("\nDirectory look-up of /boot/directory1\n");
793 dumpDir("/boot/directory1");
796 fill_disk_and_delete("/boot",20,20);
798 printf("\nDirectory look-up of /boot\n");
802 yaffs_symlink("yyfile","/boot/slink");
804 yaffs_readlink("/boot/slink",str,100);
805 printf("symlink alias is %s\n",str);
810 printf("\nDirectory look-up of /boot\n");
812 printf("\nDirectory look-up of /boot (using stat instead of lstat)\n");
813 dumpDirFollow("/boot");
814 printf("\nDirectory look-up of /boot/directory1\n");
815 dumpDir("/boot/directory1");
817 h = yaffs_open("/boot/slink",O_RDWR,0);
819 printf("file length is %d\n",(int)yaffs_lseek(h,0,SEEK_END));
823 yaffs_unlink("/boot/slink");
826 printf("\nDirectory look-up of /boot\n");
831 yaffs_lstat("/boot/yyfile",&ystat);
832 temp_mode = ystat.st_mode;
834 yaffs_chmod("/boot/yyfile",0x55555);
835 printf("\nDirectory look-up of /boot\n");
838 yaffs_chmod("/boot/yyfile",temp_mode);
839 printf("\nDirectory look-up of /boot\n");
842 // Permission checks...
843 PermissionsCheck("/boot/yyfile",0, O_WRONLY,0);
844 PermissionsCheck("/boot/yyfile",0, O_RDONLY,0);
845 PermissionsCheck("/boot/yyfile",0, O_RDWR,0);
847 PermissionsCheck("/boot/yyfile",S_IREAD, O_WRONLY,0);
848 PermissionsCheck("/boot/yyfile",S_IREAD, O_RDONLY,1);
849 PermissionsCheck("/boot/yyfile",S_IREAD, O_RDWR,0);
851 PermissionsCheck("/boot/yyfile",S_IWRITE, O_WRONLY,1);
852 PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDONLY,0);
853 PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDWR,0);
855 PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_WRONLY,1);
856 PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDONLY,1);
857 PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDWR,1);
859 yaffs_chmod("/boot/yyfile",temp_mode);
861 //create a zero-length file and unlink it (test for scan bug)
863 h = yaffs_open("/boot/zlf",O_CREAT | O_TRUNC | O_RDWR,0);
866 yaffs_unlink("/boot/zlf");
869 yaffs_DumpDevStruct("/boot");
871 fill_disk_and_delete("/boot",20,20);
873 yaffs_DumpDevStruct("/boot");
875 fill_files("/boot",1,10000,0);
876 fill_files("/boot",1,10000,5000);
877 fill_files("/boot",2,10000,0);
878 fill_files("/boot",2,10000,5000);
880 leave_unlinked_file("/data",20000,0);
881 leave_unlinked_file("/data",20000,5000);
882 leave_unlinked_file("/data",20000,5000);
883 leave_unlinked_file("/data",20000,5000);
884 leave_unlinked_file("/data",20000,5000);
885 leave_unlinked_file("/data",20000,5000);
887 yaffs_DumpDevStruct("/boot");
888 yaffs_DumpDevStruct("/data");
896 int huge_directory_test_on_path(char *path)
916 // Create a large number of files
918 for(i = 0; i < 2000; i++)
920 sprintf(str,"%s/%d",path,i);
922 f = yaffs_open(str,O_CREAT,S_IREAD | S_IWRITE);
928 d = yaffs_opendir(path);
931 while((de = yaffs_readdir(d)) != NULL) {
932 if (total >lastTotal+100*9*1024||(i & 1023)==0){
933 printf("files = %d, total = %d\n",i, total);
937 sprintf(str,"%s/%s",path,de->d_name);
939 switch(s.st_mode & S_IFMT){
941 //printf("data file");
953 int yaffs_scan_test(const char *path)
959 void rename_over_test(const char *mountpt)
966 sprintf(a,"%s/a",mountpt);
967 sprintf(b,"%s/b",mountpt);
968 sprintf(c,"%s/c",mountpt);
972 yaffs_mount(mountpt);
974 printf("Existing files\n");
975 dumpDirFollow(mountpt);
979 i = yaffs_open(c,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
980 printf("File c handle is %d\n",i);
982 i = yaffs_open(a,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
984 i = yaffs_open(b,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
986 yaffs_rename(a,b); // rename over
987 yaffs_rename(b,a); // rename back again (not renaimng over)
988 yaffs_rename(a,b); // rename back again (not renaimng over)
991 yaffs_unmount(mountpt);
996 int resize_stress_test(const char *path)
1011 sprintf(aname,"%s%s",path,"/a");
1012 sprintf(bname,"%s%s",path,"/b");
1014 memset(abuffer,'a',1000);
1015 memset(bbuffer,'b',1000);
1017 a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1018 b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1020 printf(" %s %d %s %d\n",aname,a,bname,b);
1024 for(j = 0; j < 100; j++)
1026 yaffs_lseek(a,0,SEEK_END);
1029 for(i = 0; i <20000; i++)
1031 //r = yaffs_lseek(b,i,SEEK_SET);
1032 //r = yaffs_write(b,bbuffer,1000);
1037 int syz = yaffs_lseek(a,0,SEEK_END);
1040 if(syz < 0) syz = 0;
1041 yaffs_ftruncate(a,syz);
1047 r = yaffs_lseek(a,i * 500,SEEK_SET);
1048 r = yaffs_write(a,abuffer,1000);
1060 int overwrite_test(const char *path)
1072 sprintf(aname,"%s%s",path,"/a");
1073 sprintf(bname,"%s%s",path,"/b");
1075 b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1076 for(j= 0; j < 500; j++){
1077 yaffs_write(b,bname,100);
1078 a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1079 for(i = 0; i < rand() % 20000; i++)
1080 yaffs_write(a,&a,sizeof(a));
1089 int root_perm_remount(const char *path)
1091 struct yaffs_stat s;
1097 yaffs_lstat(path,&s);
1098 printf("root perms after mount %x\n",s.st_mode);
1100 yaffs_chmod(path, 0777);
1102 yaffs_lstat(path,&s);
1103 printf("root perms after setting to 0777 is %x\n",s.st_mode);
1105 yaffs_unmount(path);
1112 int resize_stress_test_no_grow_complex(const char *path,int iters)
1128 sprintf(aname,"%s%s",path,"/a");
1129 sprintf(bname,"%s%s",path,"/b");
1131 memset(abuffer,'a',1000);
1132 memset(bbuffer,'b',1000);
1134 a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1135 b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1137 printf(" %s %d %s %d\n",aname,a,bname,b);
1141 for(j = 0; j < iters; j++)
1143 yaffs_lseek(a,0,SEEK_END);
1146 for(i = 0; i <20000; i++)
1148 //r = yaffs_lseek(b,i,SEEK_SET);
1149 //r = yaffs_write(b,bbuffer,1000);
1154 int syz = yaffs_lseek(a,0,SEEK_END);
1160 if(syz < 0) syz = 0;
1161 yaffs_ftruncate(a,syz);
1162 syz = yaffs_lseek(a,0,SEEK_END);
1163 printf("shrink to %d\n",syz);
1171 r = yaffs_lseek(a,500,SEEK_END);
1172 r = yaffs_write(a,abuffer,1000);
1179 printf("file size is %lld\n",(long long)yaffs_lseek(a,0,SEEK_END));
1187 int resize_stress_test_no_grow(const char *path,int iters)
1202 sprintf(aname,"%s%s",path,"/a");
1203 sprintf(bname,"%s%s",path,"/b");
1205 memset(abuffer,'a',1000);
1206 memset(bbuffer,'b',1000);
1208 a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1209 b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1211 printf(" %s %d %s %d\n",aname,a,bname,b);
1215 for(j = 0; j < iters; j++)
1217 yaffs_lseek(a,0,SEEK_END);
1220 for(i = 0; i <20000; i++)
1222 //r = yaffs_lseek(b,i,SEEK_SET);
1223 //r = yaffs_write(b,bbuffer,1000);
1228 int syz = yaffs_lseek(a,0,SEEK_END);
1234 if(syz < 0) syz = 0;
1235 yaffs_ftruncate(a,syz);
1236 syz = yaffs_lseek(a,0,SEEK_END);
1237 printf("shrink to %d\n",syz);
1245 r = yaffs_lseek(a,-500,SEEK_END);
1246 r = yaffs_write(a,abuffer,1000);
1252 printf("file size is %lld\n",(long long)yaffs_lseek(a,0,SEEK_END));
1260 int directory_rename_test(void)
1265 yaffs_mount("/ram");
1266 yaffs_mkdir("/ram/a",0);
1267 yaffs_mkdir("/ram/a/b",0);
1268 yaffs_mkdir("/ram/c",0);
1270 printf("\nDirectory look-up of /ram\n");
1273 dumpDir("/ram/a/b");
1275 printf("Do rename (should fail)\n");
1277 r = yaffs_rename("/ram/a","/ram/a/b/d");
1278 printf("\nDirectory look-up of /ram\n");
1281 dumpDir("/ram/a/b");
1283 printf("Do rename (should not fail)\n");
1285 r = yaffs_rename("/ram/c","/ram/a/b/d");
1286 printf("\nDirectory look-up of /ram\n");
1289 dumpDir("/ram/a/b");
1296 int cache_read_test(void)
1300 int sizeOfFiles = 500000;
1305 yaffs_mount("/boot");
1307 make_a_file("/boot/a",'a',sizeOfFiles);
1308 make_a_file("/boot/b",'b',sizeOfFiles);
1310 a = yaffs_open("/boot/a",O_RDONLY,0);
1311 b = yaffs_open("/boot/b",O_RDONLY,0);
1312 c = yaffs_open("/boot/c", O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
1316 if (i > 100) i = 100;
1318 yaffs_read(a,buffer,i);
1319 yaffs_read(b,buffer,i);
1320 yaffs_write(c,buffer,i);
1321 } while(sizeOfFiles > 0);
1329 int cache_bypass_bug_test(void)
1331 // This test reporoduces a bug whereby YAFFS caching *was* buypassed
1332 // resulting in erroneous reads after writes.
1333 // This bug has been fixed.
1339 memset(buffer1,0,sizeof(buffer1));
1340 memset(buffer2,0,sizeof(buffer2));
1344 yaffs_mount("/boot");
1346 // Create a file of 2000 bytes.
1347 make_a_file("/boot/a",'X',2000);
1349 a = yaffs_open("/boot/a",O_RDWR, S_IREAD | S_IWRITE);
1351 // Write a short sequence to the file.
1352 // This will go into the cache.
1353 yaffs_lseek(a,0,SEEK_SET);
1354 yaffs_write(a,"abcdefghijklmnopqrstuvwxyz",20);
1356 // Read a short sequence from the file.
1357 // This will come from the cache.
1358 yaffs_lseek(a,0,SEEK_SET);
1359 yaffs_read(a,buffer1,30);
1361 // Read a page size sequence from the file.
1362 yaffs_lseek(a,0,SEEK_SET);
1363 yaffs_read(a,buffer2,512);
1365 printf("buffer 1 %s\n",buffer1);
1366 printf("buffer 2 %s\n",buffer2);
1368 if(strncmp(buffer1,buffer2,20))
1370 printf("Cache bypass bug detected!!!!!\n");
1378 int free_space_check(void)
1383 yaffs_mount("/boot");
1384 fill_disk("/boot/",2);
1385 f = yaffs_freespace("/boot");
1387 printf("%d free when disk full\n",f);
1391 int truncate_test(void)
1401 yaffs_mount("/boot");
1403 yaffs_unlink("/boot/trunctest");
1405 a = yaffs_open("/boot/trunctest", O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1407 yaffs_write(a,"abcdefghijklmnopqrstuvwzyz",26);
1409 yaffs_ftruncate(a,3);
1410 l= yaffs_lseek(a,0,SEEK_END);
1412 printf("truncated length is %d\n",l);
1414 yaffs_lseek(a,5,SEEK_SET);
1415 yaffs_write(a,"1",1);
1417 yaffs_lseek(a,0,SEEK_SET);
1419 r = yaffs_read(a,y,10);
1421 printf("read %d bytes:",r);
1423 for(i = 0; i < r; i++) printf("[%02X]",y[i]);
1435 void fill_disk_test(const char *mountpt)
1440 for(i = 0; i < 5; i++)
1442 yaffs_mount(mountpt);
1443 fill_disk_and_delete(mountpt,100,i+1);
1444 yaffs_unmount(mountpt);
1450 void fill_files_test(const char *mountpt)
1455 for(i = 0; i < 5; i++)
1457 yaffs_mount(mountpt);
1458 fill_files(mountpt,2,3,100);
1459 yaffs_unmount(mountpt);
1464 void fill_empty_files_test(const char *mountpt)
1473 for(i = 0; i < 5; i++)
1475 yaffs_mount(mountpt);
1476 for(d = 0; result >= 0 && d < 1000; d++){
1477 sprintf(name,"%s/%d",mountpt,d);
1478 result= yaffs_mkdir(name,0);
1479 printf("creating directory %s result %d\n",name,result);
1481 for(f = 0; result >= 0 && f < 100; f++){
1482 sprintf(name,"%s/%d/%d",mountpt,d,f);
1483 result= yaffs_open(name,O_CREAT, 0);
1484 yaffs_close(result);
1485 printf("creating file %s result %d\n",name,result);
1488 yaffs_unmount(mountpt);
1493 void long_name_test(const char *mountpt)
1497 char fullName[1000];
1503 // Make a 256 byte name
1504 memset(name,0,sizeof(name));
1505 for(i = 0; i < 256; i++)
1506 name[i] = '0' + i % 10;
1508 sprintf(fullName,"%s/%s",mountpt,name);
1510 for(i = 0; i < 1; i++)
1512 yaffs_mount(mountpt);
1514 printf("Files at start\n");
1517 printf("Creating file %s\n",fullName);
1519 f = yaffs_open(fullName,O_CREAT | O_RDWR,0);
1522 printf("Result %d\n",f);
1527 printf("Deleting %s\n",fullName);
1528 result = yaffs_unlink(fullName);
1529 printf("Result %d\n",result);
1535 yaffs_unmount(mountpt);
1541 void lookup_test(const char *mountpt)
1553 yaffs_mount(mountpt);
1555 d = yaffs_opendir(mountpt);
1559 printf("opendir failed\n");
1564 for(i = 0; (de = yaffs_readdir(d)) != NULL; i++)
1566 printf("unlinking %s\n",de->d_name);
1567 yaffs_unlink(de->d_name);
1570 printf("%d files deleted\n",i);
1574 for(i = 0; i < 2000; i++){
1575 sprintf(a,"%s/%d",mountpt,i);
1576 h = yaffs_open(a,O_CREAT | O_TRUNC | O_RDWR, 0);
1581 for(i = 0; (de = yaffs_readdir(d)) != NULL; i++)
1583 printf("%d %s\n",i,de->d_name);
1586 printf("%d files listed\n\n\n",i);
1593 for(i = 0; i < 2000; i++){
1594 sprintf(a,"%s/%d",mountpt,i);
1599 yaffs_unmount(mountpt);
1603 void link_test0(const char *mountpt)
1611 yaffs_mount(mountpt);
1614 sprintf(namea,"%s/a",mountpt);
1615 sprintf(nameb,"%s/b",mountpt);
1617 printf("mounted\n");
1620 yaffs_unlink(namea);
1621 printf("a unlinked\n");
1624 yaffs_unlink(nameb);
1625 printf("b unlinked\n");
1628 result = yaffs_open(namea,O_CREAT| O_RDWR,0666);
1629 yaffs_close(result);
1630 printf("a created\n");
1633 yaffs_link(namea,nameb);
1636 yaffs_unlink(namea);
1637 printf("a ulinked\n");
1639 yaffs_unlink(nameb);
1640 printf("b unlinked\n");
1643 yaffs_unmount(mountpt);
1647 void link_test1(const char *mountpt)
1655 sprintf(a,"%s/aaa",mountpt);
1656 sprintf(b,"%s/bbb",mountpt);
1657 sprintf(c,"%s/ccc",mountpt);
1661 yaffs_mount(mountpt);
1664 h = yaffs_open(a, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1665 for(i = 0; i < 100; i++)
1666 yaffs_write(h,a,100);
1679 yaffs_unmount(mountpt);
1680 yaffs_mount(mountpt);
1682 printf("link test done\n");
1685 void handle_test(const char *mountpt)
1692 sprintf(a,"%s/aaa",mountpt);
1696 yaffs_mount(mountpt);
1698 for(cycle = 0; cycle < 5; cycle++){
1699 printf("Start cycle %d\n",cycle);
1702 h = yaffs_open(a, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1703 printf("%d handle %d\n",i,h);
1713 yaffs_unmount(mountpt);
1716 void freespace_test(const char *mountpt)
1726 sprintf(a,"%s/aaa",mountpt);
1730 yaffs_mount(mountpt);
1732 f0 = yaffs_freespace(mountpt);
1734 h = yaffs_open(a, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1736 for(i = 0; i < 100; i++)
1737 yaffs_write(h,a,100);
1741 f1 = yaffs_freespace(mountpt);
1745 f2 = yaffs_freespace(mountpt);
1748 yaffs_unmount(mountpt);
1749 yaffs_mount(mountpt);
1751 f3 = yaffs_freespace(mountpt);
1753 printf("%d\n%d\n%d\n%d\n",f0, f1,f2,f3);
1758 void simple_rw_test(const char *mountpt)
1767 sprintf(a,"%s/aaa",mountpt);
1771 yaffs_mount(mountpt);
1775 h = yaffs_open(a,O_CREAT| O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1777 for(i = 100000;i < 200000; i++){
1778 result = yaffs_write(h,&i,sizeof(i));
1782 printf("write error\n");
1789 // h = yaffs_open(a,O_RDWR, S_IREAD | S_IWRITE);
1792 yaffs_lseek(h,0,SEEK_SET);
1794 for(i = 100000; i < 200000; i++){
1795 result = yaffs_read(h,&x,sizeof(x));
1797 if(result != 4 || x != i){
1798 printf("read error %d %x %x\n",i,result,x);
1802 printf("Simple rw test passed\n");
1809 void scan_deleted_files_test(const char *mountpt)
1821 sprintf(sub,"%s/sdir",mountpt);
1824 for(j = 0; j < 10; j++)
1826 printf("\n\n>>>>>>> Run %d <<<<<<<<<<<<<\n\n",j);
1827 yaffs_mount(mountpt);
1831 p = (j & 0) ? mountpt: sub;
1833 for(i = 0; i < 100; i++)
1835 sprintf(fn,"%s/%d",p,i);
1839 h = yaffs_open(fn,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1840 for(k = 0; k < 1000; k++)
1841 yaffs_write(h,fn,100);
1848 for(i = 0; i < 10; i++)
1850 sprintf(fn,"%s/%d",p,i);
1858 yaffs_unmount(mountpt);
1867 void write_10k(int h)
1870 const char *s="0123456789";
1871 for(i = 0; i < 1000; i++)
1872 yaffs_write(h,s,10);
1875 void write_200k_file(const char *fn, const char *fdel, const char *fdel1)
1881 h1 = yaffs_open(fn, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1883 for(i = 0; i < 100000; i+= 10000)
1888 offs = yaffs_lseek(h1,0,SEEK_CUR);
1891 printf("Could not write file\n");
1895 for(i = 0; i < 100000; i+= 10000)
1900 offs = yaffs_lseek(h1,0,SEEK_CUR);
1903 printf("Could not write file\n");
1907 yaffs_unlink(fdel1);
1912 void verify_200k_file(const char *fn)
1917 const char *s="0123456789";
1920 h1 = yaffs_open(fn, O_RDONLY, 0);
1922 for(i = 0; i < 200000 && errCount < 10; i+= 10)
1924 yaffs_read(h1,x,10);
1925 if(strncmp(x,s,10) != 0)
1927 printf("File %s verification failed at %d\n",fn,i);
1932 printf("Too many errors... aborted\n");
1939 void check_resize_gc_bug(const char *mountpt)
1948 sprintf(a,"%s/a",mountpt);
1949 sprintf(b,"%s/b",mountpt);
1950 sprintf(c,"%s/c",mountpt);
1956 yaffs_mount(mountpt);
1960 for(i = 0; i < 50; i++)
1962 printf("A\n");write_200k_file(a,"",c);
1963 printf("B\n");verify_200k_file(a);
1964 printf("C\n");write_200k_file(b,a,c);
1965 printf("D\n");verify_200k_file(b);
1966 yaffs_unmount(mountpt);
1967 yaffs_mount(mountpt);
1968 printf("E\n");verify_200k_file(a);
1969 printf("F\n");verify_200k_file(b);
1975 void multi_mount_test(const char *mountpt,int nmounts)
1983 sprintf(a,"%s/a",mountpt);
1987 for(i = 0; i < nmounts; i++){
1993 static char xx[1000];
1995 printf("############### Iteration %d Start\n",i);
1996 if(1 || i == 0 || i == 5)
1997 yaffs_mount(mountpt);
1999 dump_directory_tree(mountpt);
2004 sprintf(xx,"%s/0",a);
2005 h0 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
2007 sprintf(xx,"%s/1",a);
2008 h1 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
2011 for(j = 0; j < 200; j++){
2012 yaffs_write(h0,xx,1000);
2013 yaffs_write(h1,xx,1000);
2016 while(yaffs_write(h0,xx,1000) > 0){
2018 yaffs_write(h1,xx,1000);
2021 len0 = yaffs_lseek(h0,0,SEEK_END);
2022 len1 = yaffs_lseek(h1,0,SEEK_END);
2024 yaffs_lseek(h0,0,SEEK_SET);
2025 yaffs_lseek(h1,0,SEEK_SET);
2027 for(j = 0; j < 200; j++){
2028 yaffs_read(h0,xx,1000);
2029 yaffs_read(h1,xx,1000);
2033 // yaffs_truncate(h0,0);
2037 printf("########### %d\n",i);
2038 dump_directory_tree(mountpt);
2040 if(1 || i == 4 || i == nmounts -1)
2041 yaffs_unmount(mountpt);
2046 void small_mount_test(const char *mountpt,int nmounts)
2060 sprintf(a,"%s/a",mountpt);
2066 for(i = 0; i < nmounts; i++){
2068 static char xx[1000];
2070 printf("############### Iteration %d Start\n",i);
2071 if(1 || i == 0 || i == 5)
2072 yaffs_mount(mountpt);
2074 dump_directory_tree(mountpt);
2078 sprintf(xx,"%s/0",a);
2081 h0 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
2082 for(j = 0; j < 130; j++)
2083 yaffs_write(h0,xx,1000);
2087 h0 = yaffs_open(xx,O_RDONLY,0);
2089 sprintf(xx,"%s/1",a);
2090 h1 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
2092 while((nread = yaffs_read(h0,xx,1000)) > 0)
2093 yaffs_write(h1,xx,nread);
2096 len0 = yaffs_lseek(h0,0,SEEK_END);
2097 len1 = yaffs_lseek(h1,0,SEEK_END);
2099 yaffs_lseek(h0,0,SEEK_SET);
2100 yaffs_lseek(h1,0,SEEK_SET);
2102 for(j = 0; j < 200; j++){
2103 yaffs_read(h0,xx,1000);
2104 yaffs_read(h1,xx,1000);
2110 printf("########### %d\n",i);
2111 dump_directory_tree(mountpt);
2113 if(1 || i == 4 || i == nmounts -1)
2114 yaffs_unmount(mountpt);
2121 void small_overwrite_test(const char *mountpt,int nmounts)
2132 sprintf(a,"%s/a",mountpt);
2138 for(i = 0; i < nmounts; i++){
2140 static char xx[8000];
2142 printf("############### Iteration %d Start\n",i);
2144 yaffs_mount(mountpt);
2146 dump_directory_tree(mountpt);
2150 sprintf(xx,"%s/0",a);
2151 h0 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
2152 sprintf(xx,"%s/1",a);
2153 h1 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
2155 for(j = 0; j < 1000000; j+=1000){
2156 yaffs_ftruncate(h0,j);
2157 yaffs_lseek(h0,j,SEEK_SET);
2158 yaffs_write(h0,xx,7000);
2159 yaffs_write(h1,xx,7000);
2167 printf("########### %d\n",i);
2168 dump_directory_tree(mountpt);
2171 yaffs_unmount(mountpt);
2176 void seek_overwrite_test(const char *mountpt,int nmounts)
2178 static char xx[5000];
2187 sprintf(a,"%s/f",mountpt);
2191 yaffs_mount(mountpt);
2194 for(i = 0; i < nmounts; i++){
2196 h0 = yaffs_open(a, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
2198 for(j = 0; j < 100000; j++){
2199 yaffs_lseek(h0,0,SEEK_SET);
2200 yaffs_write(h0,xx,5000);
2201 yaffs_lseek(h0,0x100000,SEEK_SET);
2202 yaffs_write(h0,xx,5000);
2214 void yaffs_touch(const char *fn)
2216 yaffs_chmod(fn, S_IREAD | S_IWRITE);
2219 void checkpoint_fill_test(const char *mountpt,int nmounts)
2230 sprintf(a,"%s/a",mountpt);
2237 for(i = 0; i < nmounts; i++){
2238 printf("############### Iteration %d Start\n",i);
2239 yaffs_mount(mountpt);
2240 dump_directory_tree(mountpt);
2243 sprintf(b,"%s/zz",a);
2245 h = yaffs_open(b,O_CREAT | O_RDWR,S_IREAD |S_IWRITE);
2248 while(yaffs_write(h,c,50) == 50){}
2252 for(j = 0; j < 2; j++){
2253 printf("touch %d\n",j);
2255 yaffs_unmount(mountpt);
2256 yaffs_mount(mountpt);
2259 dump_directory_tree(mountpt);
2260 yaffs_unmount(mountpt);
2265 int make_file2(const char *name1, const char *name2,int syz)
2275 h1 = yaffs_open(name1,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
2277 h2 = yaffs_open(name2,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
2279 while(syz > 0 && n > 0){
2280 i = (syz > 2500) ? 2500 : syz;
2281 n = yaffs_write(h1,xx,i);
2282 n = yaffs_write(h2,xx,i);
2291 extern void SetCheckpointReservedBlocks(int n);
2293 void checkpoint_upgrade_test(const char *mountpt,int nmounts)
2303 sprintf(a,"%s/a",mountpt);
2308 printf("Create start condition\n");
2310 yaffs_mount(mountpt);
2312 sprintf(b,"%s/zz",a);
2313 sprintf(c,"%s/xx",a);
2314 make_file2(b,c,2000000);
2315 sprintf(d,"%s/aa",a);
2316 make_file2(d,NULL,500000000);
2317 dump_directory_tree(mountpt);
2319 printf("Umount/mount attempt full\n");
2320 yaffs_unmount(mountpt);
2322 yaffs_mount(mountpt);
2324 printf("unlink small file\n");
2326 dump_directory_tree(mountpt);
2328 printf("Umount/mount attempt\n");
2329 yaffs_unmount(mountpt);
2330 yaffs_mount(mountpt);
2332 for(j = 0; j < 500; j++){
2333 printf("***** touch %d\n",j);
2334 dump_directory_tree(mountpt);
2336 yaffs_unmount(mountpt);
2337 yaffs_mount(mountpt);
2340 for(j = 0; j < 500; j++){
2341 printf("***** touch %d\n",j);
2342 dump_directory_tree(mountpt);
2344 yaffs_unmount(mountpt);
2345 yaffs_mount(mountpt);
2349 void huge_array_test(const char *mountpt,int n)
2360 sprintf(a,"mount point %s",mountpt);
2366 yaffs_mount(mountpt);
2371 printf("\n\n START run\n\n");
2372 while((space = yaffs_freespace(mountpt)) > 25000000){
2373 sprintf(a,"%s/file%d",mountpt,fnum);
2375 printf("create file %s, free space %d\n",a,space);
2376 create_file_of_size(a,10000000);
2377 printf("verifying file %s\n",a);
2378 verify_file_of_size(a,10000000);
2381 printf("\n\n verification/deletion\n\n");
2383 for(i = 0; i < fnum; i++){
2384 sprintf(a,"%s/file%d",mountpt,i);
2385 printf("verifying file %s\n",a);
2386 verify_file_of_size(a,10000000);
2387 printf("deleting file %s\n",a);
2390 printf("\n\n done \n\n");
2397 void random_write(int h)
2399 static char buffer[12000];
2402 n = random() & 0x1FFF;
2403 yaffs_write(h,buffer,n);
2406 void random_seek(int h)
2409 n = random() & 0xFFFFF;
2410 yaffs_lseek(h,n,SEEK_SET);
2413 void random_truncate(int h, char * name)
2417 n = random() & 0xFFFFF;
2418 flen = yaffs_lseek(h,0,SEEK_END);
2421 yaffs_ftruncate(h,n);
2422 yaffs_lseek(h,n,SEEK_SET);
2426 #define NSMALLFILES 10
2427 void random_small_file_test(const char *mountpt,int iterations)
2430 char a[NSMALLFILES][50];
2441 yaffs_mount(mountpt);
2443 for(i = 0; i < NSMALLFILES; i++){
2448 for(n = 0; n < iterations; n++){
2450 for(i = 0; i < NSMALLFILES; i++) {
2453 if(strlen(a[i]) == 0){
2454 sprintf(a[i],"%s/%dx%d",mountpt,n,i);
2455 h[i] = yaffs_open(a[i],O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
2459 printf("Could not open yaffs file %d %d error %d\n",n,i,h[i]);
2469 random_truncate(h[i],a[i]);
2472 case 5: random_seek(h[i]);
2489 for(i = 0; i < NSMALLFILES; i++)
2492 yaffs_unmount(mountpt);
2495 void rmdir_test(const char *mountpt)
2500 yaffs_mount(mountpt);
2502 strcpy(name,mountpt);
2504 strcat(name,"hello");
2505 yaffs_mkdir(name,0666);
2507 yaffs_unmount(mountpt);
2512 static void print_xattrib_val(const char *path, const char *name)
2517 n = yaffs_getxattr(path,name,buffer,sizeof(buffer));
2519 __u8 *b = (__u8 *)buffer;
2521 printf("%d bytes:",n);
2525 printf("[%02X]",*b);
2531 printf(" Novalue result %d\n",n);
2534 static void list_xattr(const char *path)
2541 list_len = yaffs_listxattr(path,list,sizeof(list));
2542 printf("xattribs for %s, result is %d\n",path,list_len);
2543 while(n < list_len){
2544 len = strlen(list + n);
2545 printf("\"%s\" value ",list+n);
2546 print_xattrib_val(path,list + n);
2552 void basic_xattr_test(const char *mountpt)
2561 yaffs_mount(mountpt);
2563 strcpy(name,mountpt);
2565 strcat(name,"xfile");
2568 h = yaffs_open(name,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
2574 printf("Add an attribute\n");
2576 result = yaffs_setxattr(name,"foo",&val1,sizeof(val1),0);
2577 printf("wrote attribute foo: result %d\n",result);
2579 printf("Add an attribute\n");
2581 result = yaffs_setxattr(name,"bar",&val1,sizeof(val1),0);
2582 printf("wrote attribute bar: result %d\n",result);
2585 printf("Get non-existanrt attribute\n");
2586 print_xattrib_val(name,"not here");
2588 printf("Delete non existing attribute\n");
2589 yaffs_removexattr(name,"not here");
2592 printf("Remove foo\n");
2593 yaffs_removexattr(name,"foo");
2596 printf("Remove bar\n");
2597 yaffs_removexattr(name,"bar");
2602 void big_xattr_test(const char *mountpt)
2611 yaffs_mount(mountpt);
2613 strcpy(name,mountpt);
2615 strcat(name,"xfile");
2618 h = yaffs_open(name,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
2624 printf("Add a large attribute\n");
2625 memset(val,0x1,sizeof(val));
2626 result = yaffs_setxattr(name,"aaa",val,200,0);
2627 printf("wrote attribute aaa: result %d\n",result);
2630 printf("Add a large attribute\n");
2631 memset(val,0x2,sizeof(val));
2632 result = yaffs_setxattr(name,"bbb",val,1000,0);
2633 printf("wrote attribute bbb: result %d\n",result);
2636 printf("Replace attribute\n");
2637 memset(val,0x3,sizeof(val));
2638 result = yaffs_setxattr(name,"aaa",val,1000,0);
2639 printf("wrote attribute aaa: result %d\n",result);
2645 void dump_dev_stats(yaffs_Device *dev, const char * str)
2648 printf( "space free %d erased %d "
2649 "nand reads %d writes %d erases %d "
2650 "gc all %d passive %d oldestdirty %d blocks %d copies %d \n",
2651 dev->nFreeChunks, dev->nErasedBlocks * dev->param.nChunksPerBlock,
2652 dev->nPageReads, dev->nPageWrites, dev->nBlockErasures,
2653 dev->allGCs, dev->passiveGCs, dev->oldestDirtyGCs, dev->nGCBlocks, dev->nGCCopies);
2656 void test_flash_traffic(const char *mountpt)
2663 yaffs_traceMask = 0;
2667 yaffs_mount(mountpt);
2669 dev = yaffs_getdev(mountpt);
2671 strcpy(name0,mountpt);
2674 strcpy(name1,mountpt);
2677 dump_dev_stats(dev,"start");
2678 create_file_of_size(name0,32 * 1024 * 1024);
2679 dump_dev_stats(dev,"32MB written");
2680 for(i = 0; i < 20; i++)
2681 create_file_of_size(name1,1024 * 1024);
2682 dump_dev_stats(dev,"20x 1MB files written");
2686 void link_follow_test(const char *mountpt)
2694 yaffs_traceMask = 0;
2698 yaffs_mount(mountpt);
2700 sprintf(fn,"%s/file",mountpt);
2701 sprintf(sn,"%s/sym",mountpt);
2702 sprintf(hn,"%s/hl-sym",mountpt);
2704 h = yaffs_open(fn,O_CREAT| O_RDWR, S_IREAD | S_IWRITE);
2705 result = yaffs_close(h);
2707 result = yaffs_symlink(fn,sn);
2708 result = yaffs_link(sn,hn);
2710 h =yaffs_open(hn,O_RDWR,0);
2715 int simulate_power_failure;
2717 int main(int argc, char *argv[])
2719 random_seed = time(NULL);
2720 //return long_test(argc,argv);
2722 //return cache_read_test();
2724 // resize_stress_test_no_grow("/flash/flash",20);
2725 //root_perm_remount("/flash/flash");
2727 //huge_directory_test_on_path("/ram2k");
2729 //yaffs_backward_scan_test("/flash/flash");
2730 // yaffs_device_flush_test("/flash/flash");
2732 //rename_over_test("//////////////////flash///////////////////yaffs1///////////");
2734 //fill_empty_files_test("/yaffs2/");
2735 //resize_stress_test("/yaffs2");
2736 //overwrite_test("/yaffs2");
2738 //long_name_test("/yaffs2");
2739 //link_test0("/yaffs2");
2740 //link_test1("yaffs2");
2741 //scan_pattern_test("/flash",10000,10);
2742 //short_scan_test("/flash/flash",40000,200);
2743 //small_mount_test("/flash/flash",1000);
2744 //small_overwrite_test("/flash/flash",1000);
2745 //seek_overwrite_test("/flash/flash",1000);
2746 //checkpoint_fill_test("/flash/flash",20);
2747 //checkpoint_upgrade_test("/flash/flash",20);
2748 //small_overwrite_test("/flash/flash",1000);
2749 //checkpoint_fill_test("/flash/flash",20);
2750 // random_small_file_test("/flash/flash",10000);
2751 // huge_array_test("/flash/flash",10);
2754 // handle_test("yaffs2/");
2756 //long_test_on_path("/ram2k");
2757 // long_test_on_path("/flash");
2758 //simple_rw_test("/flash/flash");
2759 //fill_disk_test("/flash/flash");
2760 // rename_over_test("/flash");
2761 //lookup_test("/flash");
2762 //freespace_test("/flash/flash");
2764 //link_test("/flash/flash");
2766 // cache_bypass_bug_test();
2768 //free_space_check();
2770 //check_resize_gc_bug("/flash");
2772 //basic_xattr_test("/yaffs2");
2773 //big_xattr_test("/yaffs2");
2775 //null_name_test("yaffs2");
2777 test_flash_traffic("yaffs2");
2778 link_follow_test("/yaffs2");