yaffs Some cleanups.
[yaffs2.git] / direct / dtest.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system. 
3  *
4  * Copyright (C) 2002-2010 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Charles Manning <charles@aleph1.co.uk>
8  *
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.
12  *
13  */
14
15
16
17
18 #include <stdio.h>
19 #include <string.h>
20 #include <unistd.h>
21 #include <fcntl.h>
22
23 #include "yaffsfs.h"
24
25
26 void dumpDir(const char *dname);
27
28 char xx[600];
29
30 void copy_in_a_file(char *yaffsName,char *inName)
31 {
32         int inh,outh;
33         unsigned char buffer[100];
34         int ni,no;
35         inh = open(inName,O_RDONLY);
36         outh = yaffs_open(yaffsName, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
37         
38         while((ni = read(inh,buffer,100)) > 0)
39         {
40                 no = yaffs_write(outh,buffer,ni);
41                 if(ni != no)
42                 {
43                         printf("problem writing yaffs file\n");
44                 }
45                 
46         }
47         
48         yaffs_close(outh);
49         close(inh);
50 }
51
52 void make_a_file(char *yaffsName,char bval,int sizeOfFile)
53 {
54         int outh;
55         int i;
56         unsigned char buffer[100];
57
58         outh = yaffs_open(yaffsName, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
59         
60         memset(buffer,bval,100);
61         
62         do{
63                 i = sizeOfFile;
64                 if(i > 100) i = 100;
65                 sizeOfFile -= i;
66                 
67                 yaffs_write(outh,buffer,i);
68                 
69         } while (sizeOfFile > 0);
70         
71                 
72         yaffs_close(outh);
73
74 }
75
76 void make_pattern_file(char *fn,int size)
77 {
78         int outh;
79         int marker;
80         int i;
81         outh = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
82         yaffs_lseek(outh,size-1,SEEK_SET);
83         yaffs_write(outh,"A",1);
84         
85         for(i = 0; i < size; i+=256)
86         {
87                 marker = ~i;
88                 yaffs_lseek(outh,i,SEEK_SET);
89                 yaffs_write(outh,&marker,sizeof(marker));
90         }
91         yaffs_close(outh);
92         
93 }
94
95 int check_pattern_file(char *fn)
96 {
97         int h;
98         int marker;
99         int i;
100         int size;
101         int ok = 1;
102         
103         h = yaffs_open(fn, O_RDWR,0);
104         size = yaffs_lseek(h,0,SEEK_END);
105                 
106         for(i = 0; i < size; i+=256)
107         {
108                 yaffs_lseek(h,i,SEEK_SET);
109                 yaffs_read(h,&marker,sizeof(marker));
110                 ok = (marker == ~i);
111                 if(!ok)
112                 {
113                    printf("pattern check failed on file %s, size %d at position %d. Got %x instead of %x\n",
114                                         fn,size,i,marker,~i);
115                 }
116         }
117         yaffs_close(h);
118         return ok;
119 }
120
121
122
123
124
125 int dump_file_data(char *fn)
126 {
127         int h;
128         int i = 0;
129         int ok = 1;
130         unsigned char b;
131         
132         h = yaffs_open(fn, O_RDWR,0);
133
134                                 
135         printf("%s\n",fn);
136         while(yaffs_read(h,&b,1)> 0)
137         {
138                 printf("%02x",b);
139                 i++;
140                 if(i > 32) 
141                 {
142                    printf("\n");
143                    i = 0;;
144                  }
145         }
146         printf("\n");
147         yaffs_close(h);
148         return ok;
149 }
150
151
152
153 void dump_file(const char *fn)
154 {
155         int i;
156         int size;
157         int h;
158         
159         h = yaffs_open(fn,O_RDONLY,0);
160         if(h < 0)
161         {
162                 printf("*****\nDump file %s does not exist\n",fn);
163         }
164         else
165         {
166                 size = yaffs_lseek(h,0,SEEK_SET);
167                 printf("*****\nDump file %s size %d\n",fn,size);
168                 for(i = 0; i < size; i++)
169                 {
170                         
171                 }
172         }
173 }
174
175 void create_file_of_size(const char *fn,int syze)
176 {
177         int h;
178         int n;
179         int result;
180         
181         char xx[200];
182         
183         int iterations = (syze + strlen(fn) -1)/ strlen(fn);
184         
185         h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
186                 
187         while (iterations > 0)
188         {
189                 sprintf(xx,"%s %8d",fn,iterations);
190                 n = strlen(xx);
191                 result = yaffs_write(h,xx,n);
192                 if(result != n)
193                         printf("Wrote %d, should have been %d\n",result,n);
194                 iterations--;
195         }
196         yaffs_close (h);
197 }
198
199 void verify_file_of_size(const char *fn,int syze)
200 {
201         int h;
202         int result;
203         
204         char xx[200];
205         char yy[200];
206         int l;
207         
208         int iterations = (syze + strlen(fn) -1)/ strlen(fn);
209         
210         h = yaffs_open(fn, O_RDONLY, S_IREAD | S_IWRITE);
211                 
212         while (iterations > 0)
213         {
214                 sprintf(xx,"%s %8d",fn,iterations);
215                 l = strlen(xx);
216                 
217                 result = yaffs_read(h,yy,l);
218                 yy[l] = 0;
219                 
220                 if(strcmp(xx,yy)){
221                         printf("=====>>>>> verification of file %s failed near position %lld\n",fn,(long long)yaffs_lseek(h,0,SEEK_CUR));
222                 }
223                 iterations--;
224         }
225         yaffs_close (h);
226 }
227
228 void create_resized_file_of_size(const char *fn,int syze1,int reSyze, int syze2)
229 {
230         int h;
231         
232         int iterations;
233         
234         h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
235                 
236         iterations = (syze1 + strlen(fn) -1)/ strlen(fn);
237         while (iterations > 0)
238         {
239                 yaffs_write(h,fn,strlen(fn));
240                 iterations--;
241         }
242         
243         yaffs_ftruncate(h,reSyze);
244         
245         yaffs_lseek(h,0,SEEK_SET);
246         iterations = (syze2 + strlen(fn) -1)/ strlen(fn);
247         while (iterations > 0)
248         {
249                 yaffs_write(h,fn,strlen(fn));
250                 iterations--;
251         }
252         
253         yaffs_close (h);
254 }
255
256
257 void do_some_file_stuff(const char *path)
258 {
259
260         char fn[100];
261
262         sprintf(fn,"%s/%s",path,"f1");
263         create_file_of_size(fn,10000);
264
265         sprintf(fn,"%s/%s",path,"fdel");
266         create_file_of_size(fn,10000);
267         yaffs_unlink(fn);
268
269         sprintf(fn,"%s/%s",path,"f2");
270         
271         create_resized_file_of_size(fn,10000,3000,4000);
272 }
273
274 void yaffs_backward_scan_test(const char *path)
275 {
276         char fn[100];
277         
278         yaffs_StartUp();        
279         
280         yaffs_mount(path);
281         
282         do_some_file_stuff(path);
283         
284         sprintf(fn,"%s/ddd",path);
285         
286         yaffs_mkdir(fn,0);
287         
288         do_some_file_stuff(fn);
289         
290         yaffs_unmount(path);
291         
292         yaffs_mount(path);
293 }
294
295 char xxzz[2000];
296
297
298 void yaffs_device_flush_test(const char *path)
299 {
300         char fn[100];
301         int h;
302         int i;
303         
304         yaffs_StartUp();        
305         
306         yaffs_mount(path);
307         
308         do_some_file_stuff(path);
309         
310         // Open and add some data to a few files
311         for(i = 0; i < 10; i++) {
312         
313                 sprintf(fn,"%s/ff%d",path,i);
314
315                 h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IWRITE | S_IREAD);
316                 yaffs_write(h,xxzz,2000);
317                 yaffs_write(h,xxzz,2000);
318         }
319         yaffs_unmount(path);
320         
321         yaffs_mount(path);
322 }
323
324
325
326 void short_scan_test(const char *path, int fsize, int niterations)
327 {
328         int i;
329         char fn[100];
330         
331         sprintf(fn,"%s/%s",path,"f1");
332         
333         yaffs_StartUp();
334         for(i = 0; i < niterations; i++)
335         {
336                 printf("\n*****************\nIteration %d\n",i);
337                 yaffs_mount(path);
338                 printf("\nmount: Directory look-up of %s\n",path);
339                 dumpDir(path);
340                 make_a_file(fn,1,fsize);
341                 yaffs_unmount(path);
342         }
343 }
344
345
346
347 void scan_pattern_test(const char *path, int fsize, int niterations)
348 {
349         int i;
350         int j;
351         char fn[3][100];
352         int result;
353         
354         sprintf(fn[0],"%s/%s",path,"f0");
355         sprintf(fn[1],"%s/%s",path,"f1");
356         sprintf(fn[2],"%s/%s",path,"f2");
357         
358         yaffs_StartUp();
359         
360         for(i = 0; i < niterations; i++)
361         {
362                 printf("\n*****************\nIteration %d\n",i);
363                 yaffs_mount(path);
364                 printf("\nmount: Directory look-up of %s\n",path);
365                 dumpDir(path);
366                 for(j = 0; j < 3; j++)
367                 {
368                         result = dump_file_data(fn[j]);
369                         result = check_pattern_file(fn[j]);
370                         make_pattern_file(fn[j],fsize); 
371                         result = dump_file_data(fn[j]);
372                         result = check_pattern_file(fn[j]);
373                 }
374                 yaffs_unmount(path);
375         }
376 }
377
378 void fill_disk(const char *path,int nfiles)
379 {
380         int h;
381         int n;
382         int result;
383         int f;
384         
385         char str[50];
386         
387         for(n = 0; n < nfiles; n++)
388         {
389                 sprintf(str,"%s/%d",path,n);
390                 
391                 h = yaffs_open(str, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
392                 
393                 printf("writing file %s handle %d ",str, h);
394                 
395                 while ((result = yaffs_write(h,xx,600)) == 600)
396                 {
397                         f = yaffs_freespace(path);
398                 }
399                 result = yaffs_close(h);
400                 printf(" close %d\n",result);
401         }
402 }
403
404 void fill_disk_and_delete(const char *path, int nfiles, int ncycles)
405 {
406         int i,j;
407         char str[50];
408         int result;
409         
410         for(i = 0; i < ncycles; i++)
411         {
412                 printf("@@@@@@@@@@@@@@ cycle %d\n",i);
413                 fill_disk(path,nfiles);
414                 
415                 for(j = 0; j < nfiles; j++)
416                 {
417                         sprintf(str,"%s/%d",path,j);
418                         result = yaffs_unlink(str);
419                         printf("unlinking file %s, result %d\n",str,result);
420                 }
421         }
422 }
423
424
425 void fill_files(const char *path,int flags, int maxIterations,int siz)
426 {
427         int i;
428         int j;
429         char str[50];
430         int h;
431         
432         i = 0;
433         
434         do{
435                 sprintf(str,"%s/%d",path,i);
436                 h = yaffs_open(str, O_CREAT | O_TRUNC | O_RDWR,S_IREAD | S_IWRITE);
437
438                 if(h >= 0)
439                 {
440                         for(j = 0; j < siz; j++)
441                         {
442                                 yaffs_write(h,str,1);
443                         }
444                 }
445                 
446                 if( flags & 1)
447                 {
448                         yaffs_unlink(str);
449                 }
450                 i++;
451         } while(h >= 0 && i < maxIterations);
452         
453         if(flags & 2)
454         {
455                 i = 0;
456                 do{
457                         sprintf(str,"%s/%d",path,i);
458                         printf("unlink %s\n",str);
459                         i++;
460                 } while(yaffs_unlink(str) >= 0);
461         }
462 }
463
464 void leave_unlinked_file(char *path,int maxIterations,int siz)
465 {
466         int i;
467         char str[50];
468         int h;
469         
470         i = 0;
471         
472         do{
473                 sprintf(str,"%s/%d",path,i);
474                 printf("create %s\n",str);
475                 h = yaffs_open(str, O_CREAT | O_TRUNC | O_RDWR,S_IREAD | S_IWRITE);
476                 if(h >= 0)
477                 {
478                         yaffs_unlink(str);
479                 }
480                 i++;
481         } while(h < 0 && i < maxIterations);
482         
483         if(h >= 0)
484         {
485                 for(i = 0; i < siz; i++)
486                 {
487                         yaffs_write(h,str,1);
488                 }
489         }
490         
491         printf("Leaving file %s open\n",str);
492
493 }
494
495 void dumpDirFollow(const char *dname)
496 {
497         yaffs_DIR *d;
498         yaffs_dirent *de;
499         struct yaffs_stat s;
500         char str[100];
501                         
502         d = yaffs_opendir(dname);
503         
504         if(!d)
505         {
506                 printf("opendir failed\n");
507         }
508         else
509         {
510                 while((de = yaffs_readdir(d)) != NULL)
511                 {
512                         sprintf(str,"%s/%s",dname,de->d_name);
513                         
514                         yaffs_stat(str,&s);
515                         
516                         printf("%s ino %d length %d mode %X ",de->d_name,(int)s.st_ino,(int)s.st_size,s.st_mode);
517                         switch(s.st_mode & S_IFMT)
518                         {
519                                 case S_IFREG: printf("data file"); break;
520                                 case S_IFDIR: printf("directory"); break;
521                                 case S_IFLNK: printf("symlink -->");
522                                                           if(yaffs_readlink(str,str,100) < 0)
523                                                                 printf("no alias");
524                                                           else
525                                                                 printf("\"%s\"",str);    
526                                                           break;
527                                 default: printf("unknown"); break;
528                         }
529                         
530                         printf("\n");           
531                 }
532                 
533                 yaffs_closedir(d);
534         }
535         printf("\n");
536         
537         printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
538
539 }
540
541
542 void dump_directory_tree_worker(const char *dname,int recursive)
543 {
544         yaffs_DIR *d;
545         yaffs_dirent *de;
546         struct yaffs_stat s;
547         char str[1000];
548                         
549         d = yaffs_opendir(dname);
550         
551         if(!d)
552         {
553                 printf("opendir failed\n");
554         }
555         else
556         {
557                 while((de = yaffs_readdir(d)) != NULL)
558                 {
559                         sprintf(str,"%s/%s",dname,de->d_name);
560                         
561                         yaffs_lstat(str,&s);
562                         
563                         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);
564                         switch(s.st_mode & S_IFMT)
565                         {
566                                 case S_IFREG: printf("data file"); break;
567                                 case S_IFDIR: printf("directory"); break;
568                                 case S_IFLNK: printf("symlink -->");
569                                                           if(yaffs_readlink(str,str,100) < 0)
570                                                                 printf("no alias");
571                                                           else
572                                                                 printf("\"%s\"",str);    
573                                                           break;
574                                 default: printf("unknown"); break;
575                         }
576                         
577                         printf("\n");
578
579                         if((s.st_mode & S_IFMT) == S_IFDIR && recursive)
580                                 dump_directory_tree_worker(str,1);
581                                                         
582                 }
583                 
584                 yaffs_closedir(d);
585         }
586
587 }
588
589 static void dump_directory_tree(const char *dname)
590 {
591         dump_directory_tree_worker(dname,1);
592         printf("\n");
593         printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
594 }
595
596 void dumpDir(const char *dname)
597 {       dump_directory_tree_worker(dname,0);
598         printf("\n");
599         printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
600 }
601
602
603 static void PermissionsCheck(const char *path, mode_t tmode, int tflags,int expectedResult)
604 {
605         int fd;
606         
607         if(yaffs_chmod(path,tmode)< 0) printf("chmod failed\n");
608         
609         fd = yaffs_open(path,tflags,0);
610         
611         if((fd >= 0) != (expectedResult > 0))
612         {
613                 printf("Permissions check %x %x %d failed\n",tmode,tflags,expectedResult);
614         }
615         else
616         {
617                 printf("Permissions check %x %x %d OK\n",tmode,tflags,expectedResult);
618         }
619         
620         
621         yaffs_close(fd);
622         
623         
624 }
625
626 int long_test(int argc, char *argv[])
627 {
628
629         int f;
630         int r;
631         char buffer[20];
632         
633         char str[100];
634         
635         int h;
636         mode_t temp_mode;
637         struct yaffs_stat ystat;
638         
639         yaffs_StartUp();
640         
641         yaffs_mount("/boot");
642         yaffs_mount("/data");
643         yaffs_mount("/flash");
644         yaffs_mount("/ram");
645         
646         printf("\nDirectory look-up of /boot\n");
647         dumpDir("/boot");
648         printf("\nDirectory look-up of /data\n");
649         dumpDir("/data");
650         printf("\nDirectory look-up of /flash\n");
651         dumpDir("/flash");
652
653         //leave_unlinked_file("/flash",20000,0);
654         //leave_unlinked_file("/data",20000,0);
655         
656         leave_unlinked_file("/ram",20,0);
657         
658
659         f = yaffs_open("/boot/b1", O_RDONLY,0);
660         
661         printf("open /boot/b1 readonly, f=%d\n",f);
662         
663         f = yaffs_open("/boot/b1", O_CREAT,S_IREAD | S_IWRITE);
664         
665         printf("open /boot/b1 O_CREAT, f=%d\n",f);
666         
667         
668         r = yaffs_write(f,"hello",1);
669         printf("write %d attempted to write to a read-only file\n",r);
670         
671         r = yaffs_close(f);
672         
673         printf("close %d\n",r);
674
675         f = yaffs_open("/boot/b1", O_RDWR,0);
676         
677         printf("open /boot/b1 O_RDWR,f=%d\n",f);
678         
679         
680         r = yaffs_write(f,"hello",2);
681         printf("write %d attempted to write to a writeable file\n",r);
682         r = yaffs_write(f,"world",3);
683         printf("write %d attempted to write to a writeable file\n",r);
684         
685         r= yaffs_lseek(f,0,SEEK_END);
686         printf("seek end %d\n",r);
687         memset(buffer,0,20);
688         r = yaffs_read(f,buffer,10);
689         printf("read %d \"%s\"\n",r,buffer);
690         r= yaffs_lseek(f,0,SEEK_SET);
691         printf("seek set %d\n",r);
692         memset(buffer,0,20);
693         r = yaffs_read(f,buffer,10);
694         printf("read %d \"%s\"\n",r,buffer);
695         memset(buffer,0,20);
696         r = yaffs_read(f,buffer,10);
697         printf("read %d \"%s\"\n",r,buffer);
698
699         // Check values reading at end.
700         // A read past end of file should return 0 for 0 bytes read.
701                 
702         r= yaffs_lseek(f,0,SEEK_END);
703         r = yaffs_read(f,buffer,10);
704         printf("read at end returned  %d\n",r); 
705         r= yaffs_lseek(f,500,SEEK_END);
706         r = yaffs_read(f,buffer,10);
707         printf("read past end returned  %d\n",r);       
708         
709         r = yaffs_close(f);
710         
711         printf("close %d\n",r);
712         
713         copy_in_a_file("/boot/yyfile","xxx");
714         
715         // Create a file with a long name
716         
717         copy_in_a_file("/boot/file with a long name","xxx");
718         
719         
720         printf("\nDirectory look-up of /boot\n");
721         dumpDir("/boot");
722
723         // Check stat
724         r = yaffs_stat("/boot/file with a long name",&ystat);
725         
726         // Check rename
727         
728         r = yaffs_rename("/boot/file with a long name","/boot/r1");
729         
730         printf("\nDirectory look-up of /boot\n");
731         dumpDir("/boot");
732         
733         // Check unlink
734         r = yaffs_unlink("/boot/r1");
735         
736         printf("\nDirectory look-up of /boot\n");
737         dumpDir("/boot");
738
739         // Check mkdir
740         
741         r = yaffs_mkdir("/boot/directory1",0);
742         
743         printf("\nDirectory look-up of /boot\n");
744         dumpDir("/boot");
745         printf("\nDirectory look-up of /boot/directory1\n");
746         dumpDir("/boot/directory1");
747
748         // add a file to the directory                  
749         copy_in_a_file("/boot/directory1/file with a long name","xxx");
750         
751         printf("\nDirectory look-up of /boot\n");
752         dumpDir("/boot");
753         printf("\nDirectory look-up of /boot/directory1\n");
754         dumpDir("/boot/directory1");
755         
756         //  Attempt to delete directory (should fail)
757         
758         r = yaffs_rmdir("/boot/directory1");
759         
760         printf("\nDirectory look-up of /boot\n");
761         dumpDir("/boot");
762         printf("\nDirectory look-up of /boot/directory1\n");
763         dumpDir("/boot/directory1");
764         
765         // Delete file first, then rmdir should work
766         r = yaffs_unlink("/boot/directory1/file with a long name");
767         r = yaffs_rmdir("/boot/directory1");
768         
769         
770         printf("\nDirectory look-up of /boot\n");
771         dumpDir("/boot");
772         printf("\nDirectory look-up of /boot/directory1\n");
773         dumpDir("/boot/directory1");
774
775 #if 0
776         fill_disk_and_delete("/boot",20,20);
777                         
778         printf("\nDirectory look-up of /boot\n");
779         dumpDir("/boot");
780 #endif
781
782         yaffs_symlink("yyfile","/boot/slink");
783         
784         yaffs_readlink("/boot/slink",str,100);
785         printf("symlink alias is %s\n",str);
786         
787         
788         
789         
790         printf("\nDirectory look-up of /boot\n");
791         dumpDir("/boot");
792         printf("\nDirectory look-up of /boot (using stat instead of lstat)\n");
793         dumpDirFollow("/boot");
794         printf("\nDirectory look-up of /boot/directory1\n");
795         dumpDir("/boot/directory1");
796
797         h = yaffs_open("/boot/slink",O_RDWR,0);
798         
799         printf("file length is %d\n",(int)yaffs_lseek(h,0,SEEK_END));
800         
801         yaffs_close(h);
802         
803         yaffs_unlink("/boot/slink");
804
805         
806         printf("\nDirectory look-up of /boot\n");
807         dumpDir("/boot");
808         
809         // Check chmod
810         
811         yaffs_stat("/boot/yyfile",&ystat);
812         temp_mode = ystat.st_mode;
813         
814         yaffs_chmod("/boot/yyfile",0x55555);
815         printf("\nDirectory look-up of /boot\n");
816         dumpDir("/boot");
817         
818         yaffs_chmod("/boot/yyfile",temp_mode);
819         printf("\nDirectory look-up of /boot\n");
820         dumpDir("/boot");
821         
822         // Permission checks...
823         PermissionsCheck("/boot/yyfile",0, O_WRONLY,0);
824         PermissionsCheck("/boot/yyfile",0, O_RDONLY,0);
825         PermissionsCheck("/boot/yyfile",0, O_RDWR,0);
826
827         PermissionsCheck("/boot/yyfile",S_IREAD, O_WRONLY,0);
828         PermissionsCheck("/boot/yyfile",S_IREAD, O_RDONLY,1);
829         PermissionsCheck("/boot/yyfile",S_IREAD, O_RDWR,0);
830
831         PermissionsCheck("/boot/yyfile",S_IWRITE, O_WRONLY,1);
832         PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDONLY,0);
833         PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDWR,0);
834         
835         PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_WRONLY,1);
836         PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDONLY,1);
837         PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDWR,1);
838
839         yaffs_chmod("/boot/yyfile",temp_mode);
840         
841         //create a zero-length file and unlink it (test for scan bug)
842         
843         h = yaffs_open("/boot/zlf",O_CREAT | O_TRUNC | O_RDWR,0);
844         yaffs_close(h);
845         
846         yaffs_unlink("/boot/zlf");
847         
848         
849         yaffs_DumpDevStruct("/boot");
850         
851         fill_disk_and_delete("/boot",20,20);
852         
853         yaffs_DumpDevStruct("/boot");
854         
855         fill_files("/boot",1,10000,0);
856         fill_files("/boot",1,10000,5000);
857         fill_files("/boot",2,10000,0);
858         fill_files("/boot",2,10000,5000);
859         
860         leave_unlinked_file("/data",20000,0);
861         leave_unlinked_file("/data",20000,5000);
862         leave_unlinked_file("/data",20000,5000);
863         leave_unlinked_file("/data",20000,5000);
864         leave_unlinked_file("/data",20000,5000);
865         leave_unlinked_file("/data",20000,5000);
866         
867         yaffs_DumpDevStruct("/boot");
868         yaffs_DumpDevStruct("/data");
869         
870                 
871                 
872         return 0;
873
874 }
875
876 int huge_directory_test_on_path(char *path)
877 {
878
879         yaffs_DIR *d;
880         yaffs_dirent *de;
881         struct yaffs_stat s;
882
883         int f;
884         int i;
885
886         int total = 0;
887         int lastTotal = 0;
888         
889         char str[100];
890
891         
892         yaffs_StartUp();
893         
894         yaffs_mount(path);
895         
896         // Create a large number of files
897         
898         for(i = 0; i < 2000; i++)
899         {
900           sprintf(str,"%s/%d",path,i);
901           
902            f = yaffs_open(str,O_CREAT,S_IREAD | S_IWRITE);
903            yaffs_close(f);
904         }
905         
906         
907         
908         d = yaffs_opendir(path);
909         i = 0;
910         if (d) {
911         while((de = yaffs_readdir(d)) != NULL) {
912         if (total >lastTotal+100*9*1024||(i & 1023)==0){
913         printf("files = %d, total = %d\n",i, total);
914         lastTotal = total;
915         }
916                 i++;
917                 sprintf(str,"%s/%s",path,de->d_name);
918                 yaffs_lstat(str,&s);
919                 switch(s.st_mode & S_IFMT){
920                 case S_IFREG:
921         //printf("data file");
922         total += s.st_size;
923         break;
924         }
925         }
926         
927         yaffs_closedir(d);
928         }
929         
930         return 0;
931 }
932
933 int yaffs_scan_test(const char *path)
934 {
935         return 0;
936 }
937
938
939 void rename_over_test(const char *mountpt)
940 {
941         int i;
942         char a[100];
943         char b[100];
944         char c[100];
945         
946         sprintf(a,"%s/a",mountpt);
947         sprintf(b,"%s/b",mountpt);
948         sprintf(c,"%s/c",mountpt);
949         
950         yaffs_StartUp();
951         
952         yaffs_mount(mountpt);
953         
954         printf("Existing files\n");
955         dumpDirFollow(mountpt);
956         
957         
958         
959         i = yaffs_open(c,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
960         printf("File c handle is %d\n",i);
961         yaffs_close(i);
962         i = yaffs_open(a,O_CREAT | O_TRUNC | O_RDWR,  S_IREAD | S_IWRITE); 
963         yaffs_close(i);
964         i = yaffs_open(b,O_CREAT | O_TRUNC | O_RDWR,  S_IREAD | S_IWRITE);
965         yaffs_close(i);
966         yaffs_rename(a,b); // rename over
967         yaffs_rename(b,a); // rename back again (not renaimng over)
968         yaffs_rename(a,b); // rename back again (not renaimng over)
969         
970         
971         yaffs_unmount(mountpt);
972         
973 }
974
975
976 int resize_stress_test(const char *path)
977 {
978    int a,b,i,j;
979    int x;
980    int r;
981    char aname[100];
982    char bname[100];
983    
984    char abuffer[1000];
985    char bbuffer[1000];
986    
987    yaffs_StartUp();
988    
989    yaffs_mount(path);
990    
991    sprintf(aname,"%s%s",path,"/a");
992    sprintf(bname,"%s%s",path,"/b");
993    
994    memset(abuffer,'a',1000);
995    memset(bbuffer,'b',1000);
996    
997    a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
998    b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
999    
1000    printf(" %s %d %s %d\n",aname,a,bname,b);
1001   
1002    x = 0;
1003    
1004    for(j = 0; j < 100; j++)
1005    {
1006                 yaffs_lseek(a,0,SEEK_END);
1007
1008                 
1009                 for(i = 0; i <20000; i++)
1010                 {
1011                    //r =        yaffs_lseek(b,i,SEEK_SET);
1012                         //r = yaffs_write(b,bbuffer,1000);
1013                         
1014                         if(x & 0x16)
1015                         {
1016                                 // shrink
1017                                 int syz = yaffs_lseek(a,0,SEEK_END);
1018                                 
1019                                 syz -= 500;
1020                                 if(syz < 0) syz = 0;
1021                                 yaffs_ftruncate(a,syz);
1022                                 
1023                         }
1024                         else
1025                         {
1026                                 //expand
1027                                 r = yaffs_lseek(a,i * 500,SEEK_SET);
1028                                 r = yaffs_write(a,abuffer,1000);
1029                         }
1030                         x++;
1031                         
1032                 }
1033    }
1034    
1035    return 0;
1036    
1037 }
1038
1039
1040 int overwrite_test(const char *path)
1041 {
1042    char aname[100];
1043    char bname[100];
1044    int i;
1045    int j;   
1046    int a;
1047    int b;
1048    yaffs_StartUp();
1049    
1050    yaffs_mount(path);
1051    
1052    sprintf(aname,"%s%s",path,"/a");
1053    sprintf(bname,"%s%s",path,"/b");
1054    
1055    b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1056    for(j= 0; j < 500; j++){
1057         yaffs_write(b,bname,100);
1058         a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1059         for(i = 0; i < rand() % 20000; i++)
1060                 yaffs_write(a,&a,sizeof(a));
1061         yaffs_close(a);
1062    }
1063    
1064    return 0;
1065    
1066 }
1067
1068
1069 int root_perm_remount(const char *path)
1070 {
1071    struct yaffs_stat s;
1072    
1073    yaffs_StartUp();
1074    
1075    yaffs_mount(path);
1076    
1077    yaffs_stat(path,&s);
1078    printf("root perms after mount %x\n",s.st_mode);
1079    
1080    yaffs_chmod(path, 0777);
1081
1082    yaffs_stat(path,&s);
1083    printf("root perms after setting to 0777 is  %x\n",s.st_mode);
1084    
1085    yaffs_unmount(path);
1086       
1087    return 0;
1088    
1089 }
1090
1091
1092 int resize_stress_test_no_grow_complex(const char *path,int iters)
1093 {
1094    int a,b,i,j;
1095    int x;
1096    int r;
1097    char aname[100];
1098    char bname[100];
1099    
1100    char abuffer[1000];
1101    char bbuffer[1000];
1102
1103    
1104    yaffs_StartUp();
1105    
1106    yaffs_mount(path);
1107    
1108    sprintf(aname,"%s%s",path,"/a");
1109    sprintf(bname,"%s%s",path,"/b");
1110    
1111    memset(abuffer,'a',1000);
1112    memset(bbuffer,'b',1000);
1113    
1114    a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1115    b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1116    
1117    printf(" %s %d %s %d\n",aname,a,bname,b);
1118   
1119    x = 0;
1120    
1121    for(j = 0; j < iters; j++)
1122    {
1123                 yaffs_lseek(a,0,SEEK_END);
1124
1125                 
1126                 for(i = 0; i <20000; i++)
1127                 {
1128                    //r =        yaffs_lseek(b,i,SEEK_SET);
1129                         //r = yaffs_write(b,bbuffer,1000);
1130                         
1131                         if(!(x%20))
1132                         {
1133                                 // shrink
1134                                 int syz = yaffs_lseek(a,0,SEEK_END);
1135                                 
1136                                 while(syz > 4000)
1137                                 {
1138                                 
1139                                         syz -= 2050;
1140                                         if(syz < 0) syz = 0;
1141                                         yaffs_ftruncate(a,syz);
1142                                         syz = yaffs_lseek(a,0,SEEK_END);
1143                                         printf("shrink to %d\n",syz);
1144                                 }
1145                                 
1146                                 
1147                         }
1148                         else
1149                         {
1150                                 //expand
1151                                 r = yaffs_lseek(a,500,SEEK_END);
1152                                 r = yaffs_write(a,abuffer,1000);
1153                         }
1154                         x++;
1155                         
1156                                         
1157                 }
1158                 
1159                 printf("file size is %lld\n",(long long)yaffs_lseek(a,0,SEEK_END));
1160
1161    }
1162    
1163    return 0;
1164    
1165 }
1166
1167 int resize_stress_test_no_grow(const char *path,int iters)
1168 {
1169    int a,b,i,j;
1170    int x;
1171    int r;
1172    char aname[100];
1173    char bname[100];
1174    
1175    char abuffer[1000];
1176    char bbuffer[1000];
1177    
1178    yaffs_StartUp();
1179    
1180    yaffs_mount(path);
1181    
1182    sprintf(aname,"%s%s",path,"/a");
1183    sprintf(bname,"%s%s",path,"/b");
1184    
1185    memset(abuffer,'a',1000);
1186    memset(bbuffer,'b',1000);
1187    
1188    a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1189    b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1190    
1191    printf(" %s %d %s %d\n",aname,a,bname,b);
1192   
1193    x = 0;
1194    
1195    for(j = 0; j < iters; j++)
1196    {
1197                 yaffs_lseek(a,0,SEEK_END);
1198
1199                 
1200                 for(i = 0; i <20000; i++)
1201                 {
1202                    //r =        yaffs_lseek(b,i,SEEK_SET);
1203                         //r = yaffs_write(b,bbuffer,1000);
1204                         
1205                         if(!(x%20))
1206                         {
1207                                 // shrink
1208                                 int syz = yaffs_lseek(a,0,SEEK_END);
1209                                 
1210                                 while(syz > 4000)
1211                                 {
1212                                 
1213                                         syz -= 2050;
1214                                         if(syz < 0) syz = 0;
1215                                         yaffs_ftruncate(a,syz);
1216                                         syz = yaffs_lseek(a,0,SEEK_END);
1217                                         printf("shrink to %d\n",syz);
1218                                 }
1219                                 
1220                                 
1221                         }
1222                         else
1223                         {
1224                                 //expand
1225                                 r = yaffs_lseek(a,-500,SEEK_END);
1226                                 r = yaffs_write(a,abuffer,1000);
1227                         }
1228                         x++;
1229                         
1230                                         
1231                 }
1232                 printf("file size is %lld\n",(long long)yaffs_lseek(a,0,SEEK_END));
1233
1234    }
1235    
1236    return 0;
1237    
1238 }
1239
1240 int directory_rename_test(void)
1241 {
1242         int r;
1243         yaffs_StartUp();
1244         
1245         yaffs_mount("/ram");
1246         yaffs_mkdir("/ram/a",0);
1247         yaffs_mkdir("/ram/a/b",0);
1248         yaffs_mkdir("/ram/c",0);
1249         
1250         printf("\nDirectory look-up of /ram\n");
1251         dumpDir("/ram");
1252         dumpDir("/ram/a");
1253         dumpDir("/ram/a/b");
1254
1255         printf("Do rename (should fail)\n");
1256                 
1257         r = yaffs_rename("/ram/a","/ram/a/b/d");
1258         printf("\nDirectory look-up of /ram\n");
1259         dumpDir("/ram");
1260         dumpDir("/ram/a");
1261         dumpDir("/ram/a/b");
1262
1263         printf("Do rename (should not fail)\n");
1264                 
1265         r = yaffs_rename("/ram/c","/ram/a/b/d");
1266         printf("\nDirectory look-up of /ram\n");
1267         dumpDir("/ram");
1268         dumpDir("/ram/a");
1269         dumpDir("/ram/a/b");
1270         
1271         
1272         return 1;
1273         
1274 }
1275
1276 int cache_read_test(void)
1277 {
1278         int a,b,c;
1279         int i;
1280         int sizeOfFiles = 500000;
1281         char buffer[100];
1282         
1283         yaffs_StartUp();
1284         
1285         yaffs_mount("/boot");
1286         
1287         make_a_file("/boot/a",'a',sizeOfFiles);
1288         make_a_file("/boot/b",'b',sizeOfFiles);
1289
1290         a = yaffs_open("/boot/a",O_RDONLY,0);
1291         b = yaffs_open("/boot/b",O_RDONLY,0);
1292         c = yaffs_open("/boot/c", O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
1293
1294         do{
1295                 i = sizeOfFiles;
1296                 if (i > 100) i = 100;
1297                 sizeOfFiles  -= i;
1298                 yaffs_read(a,buffer,i);
1299                 yaffs_read(b,buffer,i);
1300                 yaffs_write(c,buffer,i);
1301         } while(sizeOfFiles > 0);
1302         
1303         
1304         
1305         return 1;
1306         
1307 }
1308
1309 int cache_bypass_bug_test(void)
1310 {
1311         // This test reporoduces a bug whereby YAFFS caching *was* buypassed
1312         // resulting in erroneous reads after writes.
1313         // This bug has been fixed.
1314         
1315         int a;
1316         char buffer1[1000];
1317         char buffer2[1000];
1318         
1319         memset(buffer1,0,sizeof(buffer1));
1320         memset(buffer2,0,sizeof(buffer2));
1321                 
1322         yaffs_StartUp();
1323         
1324         yaffs_mount("/boot");
1325         
1326         // Create a file of 2000 bytes.
1327         make_a_file("/boot/a",'X',2000);
1328
1329         a = yaffs_open("/boot/a",O_RDWR, S_IREAD | S_IWRITE);
1330         
1331         // Write a short sequence to the file.
1332         // This will go into the cache.
1333         yaffs_lseek(a,0,SEEK_SET);
1334         yaffs_write(a,"abcdefghijklmnopqrstuvwxyz",20); 
1335
1336         // Read a short sequence from the file.
1337         // This will come from the cache.
1338         yaffs_lseek(a,0,SEEK_SET);
1339         yaffs_read(a,buffer1,30); 
1340
1341         // Read a page size sequence from the file.
1342         yaffs_lseek(a,0,SEEK_SET);
1343         yaffs_read(a,buffer2,512); 
1344         
1345         printf("buffer 1 %s\n",buffer1);
1346         printf("buffer 2 %s\n",buffer2);
1347         
1348         if(strncmp(buffer1,buffer2,20))
1349         {
1350                 printf("Cache bypass bug detected!!!!!\n");
1351         }
1352         
1353         
1354         return 1;
1355 }
1356
1357
1358 int free_space_check(void)
1359 {
1360         int f;
1361         
1362                 yaffs_StartUp();
1363                 yaffs_mount("/boot");
1364             fill_disk("/boot/",2);
1365             f = yaffs_freespace("/boot");
1366             
1367             printf("%d free when disk full\n",f);           
1368             return 1;
1369 }
1370
1371 int truncate_test(void)
1372 {
1373         int a;
1374         int r;
1375         int i;
1376         int l;
1377
1378         char y[10];
1379
1380         yaffs_StartUp();
1381         yaffs_mount("/boot");
1382
1383         yaffs_unlink("/boot/trunctest");
1384         
1385         a = yaffs_open("/boot/trunctest", O_CREAT | O_TRUNC | O_RDWR,  S_IREAD | S_IWRITE);
1386         
1387         yaffs_write(a,"abcdefghijklmnopqrstuvwzyz",26);
1388         
1389         yaffs_ftruncate(a,3);
1390         l= yaffs_lseek(a,0,SEEK_END);
1391         
1392         printf("truncated length is %d\n",l);
1393
1394         yaffs_lseek(a,5,SEEK_SET);
1395         yaffs_write(a,"1",1);
1396
1397         yaffs_lseek(a,0,SEEK_SET);
1398         
1399         r = yaffs_read(a,y,10);
1400
1401         printf("read %d bytes:",r);
1402
1403         for(i = 0; i < r; i++) printf("[%02X]",y[i]);
1404
1405         printf("\n");
1406
1407         return 0;
1408
1409 }
1410
1411
1412
1413
1414
1415 void fill_disk_test(const char *mountpt)
1416 {
1417         int i;
1418         yaffs_StartUp();
1419         
1420         for(i = 0; i < 5; i++)
1421         {
1422                 yaffs_mount(mountpt);
1423                 fill_disk_and_delete(mountpt,100,i+1);
1424                 yaffs_unmount(mountpt);
1425         }
1426         
1427 }
1428
1429
1430 void fill_files_test(const char *mountpt)
1431 {
1432         int i;
1433         yaffs_StartUp();
1434         
1435         for(i = 0; i < 5; i++)
1436         {
1437                 yaffs_mount(mountpt);
1438                 fill_files(mountpt,2,3,100);
1439                 yaffs_unmount(mountpt);
1440         }
1441         
1442 }
1443
1444 void fill_empty_files_test(const char *mountpt)
1445 {
1446         int i;
1447         yaffs_StartUp();
1448         char name[100];
1449         int result = 0;
1450         
1451         int d,f;
1452
1453         for(i = 0; i < 5; i++)
1454         {
1455                 yaffs_mount(mountpt);
1456                 for(d = 0; result >= 0 && d < 1000; d++){
1457                         sprintf(name,"%s/%d",mountpt,d);
1458                         result= yaffs_mkdir(name,0);
1459                         printf("creating directory %s result %d\n",name,result);
1460                         
1461                         for(f = 0; result >= 0 && f < 100; f++){
1462                                 sprintf(name,"%s/%d/%d",mountpt,d,f);
1463                                 result= yaffs_open(name,O_CREAT, 0);
1464                                 yaffs_close(result);
1465                                 printf("creating file %s result %d\n",name,result);
1466                         }
1467                 }
1468                 yaffs_unmount(mountpt);
1469         }
1470         
1471 }
1472
1473 void long_name_test(const char *mountpt)
1474 {
1475         int i;
1476         yaffs_StartUp();
1477         char fullName[1000];
1478         char name[300];
1479         int result = 0;
1480         
1481         int d,f;
1482         
1483         // Make a 256 byte name
1484         memset(name,0,sizeof(name));
1485         for(i = 0; i < 256; i++)
1486                 name[i] = '0' + i % 10;
1487                 
1488         sprintf(fullName,"%s/%s",mountpt,name);
1489
1490         for(i = 0; i < 1; i++)
1491         {
1492                 yaffs_mount(mountpt);
1493                 
1494                 printf("Files at start\n");
1495                 dumpDir(mountpt);
1496                 
1497                 printf("Creating file %s\n",fullName);
1498                 
1499                 f = yaffs_open(fullName,O_CREAT | O_RDWR,0);
1500                 yaffs_close(f);
1501                 
1502                 printf("Result %d\n",f);
1503                         
1504                 printf("Files\n");
1505                 dumpDir(mountpt);
1506                 
1507                 printf("Deleting %s\n",fullName);
1508                 result = yaffs_unlink(fullName);
1509                 printf("Result %d\n",result);
1510                 
1511                 printf("Files\n");
1512                 
1513                 dumpDir(mountpt);
1514                 
1515                 yaffs_unmount(mountpt);
1516         }
1517         
1518 }
1519
1520
1521 void lookup_test(const char *mountpt)
1522 {
1523         int i;
1524         int h;
1525         char a[100];
1526         
1527
1528         yaffs_DIR *d;
1529         yaffs_dirent *de;
1530
1531         yaffs_StartUp();
1532         
1533         yaffs_mount(mountpt);
1534                                 
1535         d = yaffs_opendir(mountpt);
1536         
1537         if(!d)
1538         {
1539                 printf("opendir failed\n");
1540         }
1541         else
1542         {
1543                 
1544                 for(i = 0; (de = yaffs_readdir(d)) != NULL; i++)
1545                 {
1546                         printf("unlinking %s\n",de->d_name);
1547                         yaffs_unlink(de->d_name);
1548                 }
1549                 
1550                 printf("%d files deleted\n",i);
1551         }
1552         
1553         
1554         for(i = 0; i < 2000; i++){
1555         sprintf(a,"%s/%d",mountpt,i);
1556                 h =  yaffs_open(a,O_CREAT | O_TRUNC | O_RDWR, 0);
1557                 yaffs_close(h);
1558         }
1559
1560         yaffs_rewinddir(d);
1561         for(i = 0; (de = yaffs_readdir(d)) != NULL; i++)
1562         {
1563                 printf("%d  %s\n",i,de->d_name);
1564         }       
1565         
1566         printf("%d files listed\n\n\n",i);
1567         
1568         yaffs_rewinddir(d);
1569         yaffs_readdir(d);
1570         yaffs_readdir(d);
1571         yaffs_readdir(d);
1572         
1573         for(i = 0; i < 2000; i++){
1574                 sprintf(a,"%s/%d",mountpt,i);
1575                 yaffs_unlink(a);
1576         }
1577         
1578                 
1579         yaffs_unmount(mountpt);
1580         
1581 }
1582
1583 void link_test0(const char *mountpt)
1584 {
1585         int i;
1586         char namea[300];
1587         char nameb[300];
1588         int result = 0;
1589         
1590
1591         yaffs_StartUp();
1592         yaffs_mount(mountpt);
1593         
1594                 
1595         sprintf(namea,"%s/a",mountpt);
1596         sprintf(nameb,"%s/b",mountpt);
1597
1598         printf("mounted\n");
1599         dumpDir(mountpt);
1600
1601         yaffs_unlink(namea);
1602         printf("a unlinked\n");
1603         dumpDir(mountpt);
1604
1605         yaffs_unlink(nameb);
1606         printf("b unlinked\n");
1607         dumpDir(mountpt);
1608         
1609         result = yaffs_open(namea,O_CREAT| O_RDWR,0666);
1610         yaffs_close(result);
1611         printf("a created\n");
1612         dumpDir(mountpt);
1613
1614         yaffs_link(namea,nameb);
1615         printf("linked\n");
1616         dumpDir(mountpt);
1617         yaffs_unlink(namea);
1618         printf("a ulinked\n");
1619         dumpDir(mountpt);
1620         yaffs_unlink(nameb);
1621         printf("b unlinked\n");
1622         dumpDir(mountpt);
1623
1624         yaffs_unmount(mountpt);
1625 }
1626
1627
1628 void link_test1(const char *mountpt)
1629 {
1630         int i;
1631         int h;
1632         char a[100];
1633         char b[100];
1634         char c[100];
1635
1636         sprintf(a,"%s/aaa",mountpt);
1637         sprintf(b,"%s/bbb",mountpt);
1638         sprintf(c,"%s/ccc",mountpt);
1639         
1640         yaffs_StartUp();
1641         
1642         yaffs_mount(mountpt);
1643         
1644         
1645         h = yaffs_open(a, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1646         for(i = 0; i < 100; i++)
1647                 yaffs_write(h,a,100);
1648         
1649         yaffs_close(h);
1650         
1651         yaffs_unlink(b);
1652         yaffs_unlink(c);
1653         yaffs_link(a,b);
1654         yaffs_link(a,c);
1655         yaffs_unlink(b);
1656         yaffs_unlink(c);
1657         yaffs_unlink(a);
1658         
1659         
1660         yaffs_unmount(mountpt);
1661         yaffs_mount(mountpt);
1662         
1663         printf("link test done\n");     
1664 }
1665
1666 void handle_test(const char *mountpt)
1667 {
1668         int i;
1669         int h;
1670         int cycle;
1671         char a[100];
1672
1673         sprintf(a,"%s/aaa",mountpt);
1674         
1675         yaffs_StartUp();
1676         
1677         yaffs_mount(mountpt);
1678
1679         for(cycle = 0; cycle < 5; cycle++){
1680         printf("Start cycle %d\n",cycle);
1681         i = 0;
1682         do {
1683         h = yaffs_open(a, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1684         printf("%d  handle %d\n",i,h);
1685         i++;
1686         } while(h >= 0);
1687         
1688         while(i >= -1) {
1689          yaffs_close(i);
1690          i--;
1691         }
1692         }
1693         
1694         yaffs_unmount(mountpt);
1695 }
1696
1697 void freespace_test(const char *mountpt)
1698 {
1699         int i;
1700         int h;
1701         char a[100];
1702         
1703         int  f0;
1704         int f1;
1705         int f2;
1706         int f3;
1707         sprintf(a,"%s/aaa",mountpt);
1708         
1709         yaffs_StartUp();
1710         
1711         yaffs_mount(mountpt);
1712         
1713         f0 = yaffs_freespace(mountpt);
1714         
1715         h = yaffs_open(a, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1716         
1717         for(i = 0; i < 100; i++)
1718                 yaffs_write(h,a,100);
1719         
1720         yaffs_close(h);
1721         
1722         f1 = yaffs_freespace(mountpt);
1723         
1724         yaffs_unlink(a);
1725         
1726         f2 = yaffs_freespace(mountpt);
1727         
1728                 
1729         yaffs_unmount(mountpt);
1730         yaffs_mount(mountpt);
1731         
1732         f3 = yaffs_freespace(mountpt);
1733         
1734         printf("%d\n%d\n%d\n%d\n",f0, f1,f2,f3);
1735         
1736         
1737 }
1738
1739 void simple_rw_test(const char *mountpt)
1740 {
1741         int i;
1742         int h;
1743         char a[100];
1744         
1745         int x;
1746         int result;
1747
1748         sprintf(a,"%s/aaa",mountpt);
1749         
1750         yaffs_StartUp();
1751         
1752         yaffs_mount(mountpt);
1753         
1754         yaffs_unlink(a);
1755         
1756         h = yaffs_open(a,O_CREAT| O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1757         
1758         for(i = 100000;i < 200000; i++){
1759                 result = yaffs_write(h,&i,sizeof(i));
1760                 
1761                 if(result != 4)
1762                 {
1763                         printf("write error\n");
1764                         exit(1);
1765                 }
1766         }
1767         
1768         //yaffs_close(h);
1769         
1770         // h = yaffs_open(a,O_RDWR, S_IREAD | S_IWRITE);
1771         
1772         
1773         yaffs_lseek(h,0,SEEK_SET);
1774         
1775         for(i = 100000; i < 200000; i++){
1776                 result = yaffs_read(h,&x,sizeof(x));
1777                 
1778                 if(result != 4 || x != i){
1779                         printf("read error %d %x %x\n",i,result,x);
1780                 }
1781         }
1782         
1783         printf("Simple rw test passed\n");
1784         
1785         
1786         
1787 }
1788
1789
1790 void scan_deleted_files_test(const char *mountpt)
1791 {
1792         char fn[100];
1793         char sub[100];
1794         
1795         const char *p;
1796         
1797         int i;
1798         int j;
1799         int k;
1800         int h;
1801         
1802         sprintf(sub,"%s/sdir",mountpt);
1803         yaffs_StartUp();
1804         
1805         for(j = 0; j < 10; j++)
1806         {
1807                 printf("\n\n>>>>>>> Run %d <<<<<<<<<<<<<\n\n",j);
1808                 yaffs_mount(mountpt);
1809                 yaffs_mkdir(sub,0);
1810                 
1811                 
1812                 p = (j & 0) ? mountpt: sub;
1813         
1814                 for(i = 0; i < 100; i++)
1815                 {
1816                   sprintf(fn,"%s/%d",p,i);  
1817                   
1818                   if(i & 1)
1819                   {
1820                           h = yaffs_open(fn,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1821                           for(k = 0; k < 1000; k++)
1822                                   yaffs_write(h,fn,100);
1823                           yaffs_close(h);
1824                   }
1825                   else
1826                         yaffs_mkdir(fn,0);
1827                 }
1828                 
1829                 for(i = 0; i < 10; i++)
1830                 {
1831                   sprintf(fn,"%s/%d",p,i);  
1832                   if(i & 1) 
1833                         yaffs_unlink(fn);
1834                   else
1835                         yaffs_rmdir(fn);
1836                   
1837                 }
1838                                 
1839                 yaffs_unmount(mountpt);
1840         }
1841         
1842         
1843         
1844
1845 }
1846
1847
1848 void write_10k(int h)
1849 {
1850    int i;
1851    const char *s="0123456789";
1852    for(i = 0; i < 1000; i++)
1853      yaffs_write(h,s,10);
1854
1855 }
1856 void write_200k_file(const char *fn, const char *fdel, const char *fdel1)
1857 {
1858    int h1;
1859    int i;
1860    int offs;
1861    
1862    h1 = yaffs_open(fn, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1863    
1864    for(i = 0; i < 100000; i+= 10000)
1865    {
1866         write_10k(h1);
1867    }
1868    
1869    offs = yaffs_lseek(h1,0,SEEK_CUR);
1870    if( offs != 100000)
1871    {
1872         printf("Could not write file\n");
1873    }
1874    
1875    yaffs_unlink(fdel);
1876    for(i = 0; i < 100000; i+= 10000)
1877    {
1878         write_10k(h1);
1879    }
1880    
1881    offs = yaffs_lseek(h1,0,SEEK_CUR);
1882    if( offs != 200000)
1883    {
1884         printf("Could not write file\n");
1885    }
1886    
1887    yaffs_close(h1);
1888    yaffs_unlink(fdel1);
1889    
1890 }
1891
1892
1893 void verify_200k_file(const char *fn)
1894 {
1895    int h1;
1896    int i;
1897    char x[11];
1898    const char *s="0123456789";
1899    int errCount = 0;
1900    
1901    h1 = yaffs_open(fn, O_RDONLY, 0);
1902    
1903    for(i = 0; i < 200000 && errCount < 10; i+= 10)
1904    {
1905         yaffs_read(h1,x,10);
1906         if(strncmp(x,s,10) != 0)
1907         {
1908                 printf("File %s verification failed at %d\n",fn,i);
1909                 errCount++;
1910         }
1911    }
1912    if(errCount >= 10)
1913         printf("Too many errors... aborted\n");
1914       
1915    yaffs_close(h1);        
1916         
1917 }
1918
1919
1920 void check_resize_gc_bug(const char *mountpt)
1921 {
1922
1923         char a[30];
1924         char b[30];
1925         char c[30];
1926         
1927         int i;
1928         
1929         sprintf(a,"%s/a",mountpt);
1930         sprintf(b,"%s/b",mountpt);
1931         sprintf(c,"%s/c",mountpt);
1932         
1933
1934         
1935         
1936         yaffs_StartUp();
1937         yaffs_mount(mountpt);
1938         yaffs_unlink(a);
1939         yaffs_unlink(b);
1940         
1941         for(i = 0; i < 50; i++)
1942         {  
1943            printf("A\n");write_200k_file(a,"",c);
1944            printf("B\n");verify_200k_file(a);
1945            printf("C\n");write_200k_file(b,a,c);
1946            printf("D\n");verify_200k_file(b);
1947            yaffs_unmount(mountpt);
1948            yaffs_mount(mountpt);
1949            printf("E\n");verify_200k_file(a);
1950            printf("F\n");verify_200k_file(b);
1951         }
1952                 
1953 }
1954
1955
1956 void multi_mount_test(const char *mountpt,int nmounts)
1957 {
1958
1959         char a[30];
1960         
1961         int i;
1962         int j;
1963         
1964         sprintf(a,"%s/a",mountpt);
1965
1966         yaffs_StartUp();
1967         
1968         for(i = 0; i < nmounts; i++){
1969                 int h0;
1970                 int h1;
1971                 int len0;
1972                 int len1;
1973                 
1974                 static char xx[1000];
1975                 
1976                 printf("############### Iteration %d   Start\n",i);
1977                 if(1 || i == 0 || i == 5) 
1978                         yaffs_mount(mountpt);
1979
1980                 dump_directory_tree(mountpt);
1981                 
1982                 
1983                 yaffs_mkdir(a,0);
1984                 
1985                 sprintf(xx,"%s/0",a);
1986                 h0 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
1987                 
1988                 sprintf(xx,"%s/1",a);
1989                 h1 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
1990
1991 #if 0           
1992                 for(j = 0; j < 200; j++){
1993                    yaffs_write(h0,xx,1000);
1994                    yaffs_write(h1,xx,1000);
1995                 }
1996 #else
1997                 while(yaffs_write(h0,xx,1000) > 0){
1998                    
1999                    yaffs_write(h1,xx,1000);
2000                 }
2001 #endif
2002                 len0 = yaffs_lseek(h0,0,SEEK_END);
2003                 len1 = yaffs_lseek(h1,0,SEEK_END);
2004                 
2005                 yaffs_lseek(h0,0,SEEK_SET);
2006                 yaffs_lseek(h1,0,SEEK_SET);
2007
2008                 for(j = 0; j < 200; j++){
2009                    yaffs_read(h0,xx,1000);
2010                    yaffs_read(h1,xx,1000);
2011                 }
2012                 
2013                 
2014         //      yaffs_truncate(h0,0);
2015                 yaffs_close(h0);
2016                 yaffs_close(h1);
2017                 
2018                 printf("########### %d\n",i);
2019                 dump_directory_tree(mountpt);
2020
2021                 if(1 || i == 4 || i == nmounts -1)
2022                         yaffs_unmount(mountpt);
2023         }
2024 }
2025
2026
2027 void small_mount_test(const char *mountpt,int nmounts)
2028 {
2029
2030         char a[30];
2031         
2032         int i;
2033         int j;
2034
2035         int h0;
2036         int h1;
2037         int len0;
2038         int len1;
2039         int nread;
2040         
2041         sprintf(a,"%s/a",mountpt);
2042
2043         yaffs_StartUp();
2044         
2045         
2046         
2047         for(i = 0; i < nmounts; i++){
2048                 
2049                 static char xx[1000];
2050                 
2051                 printf("############### Iteration %d   Start\n",i);
2052                 if(1 || i == 0 || i == 5) 
2053                         yaffs_mount(mountpt);
2054
2055                 dump_directory_tree(mountpt);
2056                 
2057                 yaffs_mkdir(a,0);
2058                 
2059                 sprintf(xx,"%s/0",a);
2060                 if(i ==0){
2061                 
2062                         h0 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
2063                         for(j = 0; j < 130; j++)
2064                                 yaffs_write(h0,xx,1000);
2065                         yaffs_close(h0);
2066                 }
2067                 
2068                 h0 = yaffs_open(xx,O_RDONLY,0);
2069                 
2070                 sprintf(xx,"%s/1",a);
2071                 h1 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
2072                 
2073                 while((nread = yaffs_read(h0,xx,1000)) > 0)
2074                         yaffs_write(h1,xx,nread);
2075                 
2076                 
2077                 len0 = yaffs_lseek(h0,0,SEEK_END);
2078                 len1 = yaffs_lseek(h1,0,SEEK_END);
2079                 
2080                 yaffs_lseek(h0,0,SEEK_SET);
2081                 yaffs_lseek(h1,0,SEEK_SET);
2082
2083                 for(j = 0; j < 200; j++){
2084                    yaffs_read(h0,xx,1000);
2085                    yaffs_read(h1,xx,1000);
2086                 }
2087                 
2088                 yaffs_close(h0);
2089                 yaffs_close(h1);
2090                 
2091                 printf("########### %d\n",i);
2092                 dump_directory_tree(mountpt);
2093
2094                 if(1 || i == 4 || i == nmounts -1)
2095                         yaffs_unmount(mountpt);
2096         }
2097 }
2098
2099
2100 int early_exit;
2101
2102 void small_overwrite_test(const char *mountpt,int nmounts)
2103 {
2104
2105         char a[30];
2106         int i;
2107         int j;
2108
2109         int h0;
2110         int h1;
2111
2112         
2113         sprintf(a,"%s/a",mountpt);
2114
2115         yaffs_StartUp();
2116         
2117         
2118         
2119         for(i = 0; i < nmounts; i++){
2120                 
2121                 static char xx[8000];
2122                 
2123                 printf("############### Iteration %d   Start\n",i);
2124                 if(1)
2125                         yaffs_mount(mountpt);
2126
2127                 dump_directory_tree(mountpt);
2128                 
2129                 yaffs_mkdir(a,0);
2130                 
2131                 sprintf(xx,"%s/0",a);
2132                 h0 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
2133                 sprintf(xx,"%s/1",a);
2134                 h1 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
2135                 
2136                 for(j = 0; j < 1000000; j+=1000){
2137                         yaffs_ftruncate(h0,j);
2138                         yaffs_lseek(h0,j,SEEK_SET);
2139                         yaffs_write(h0,xx,7000);
2140                         yaffs_write(h1,xx,7000);
2141                         
2142                         if(early_exit)
2143                                 exit(0);
2144                 }
2145                 
2146                 yaffs_close(h0);
2147                 
2148                 printf("########### %d\n",i);
2149                 dump_directory_tree(mountpt);
2150
2151                 if(1)
2152                         yaffs_unmount(mountpt);
2153         }
2154 }
2155
2156
2157 void seek_overwrite_test(const char *mountpt,int nmounts)
2158 {
2159
2160         char a[30];
2161         
2162         int i;
2163         int j;
2164
2165         int h0;
2166
2167         
2168         sprintf(a,"%s/f",mountpt);
2169
2170         yaffs_StartUp();
2171         
2172         yaffs_mount(mountpt);
2173         
2174         
2175         for(i = 0; i < nmounts; i++){
2176                 
2177                 h0 = yaffs_open(a, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
2178                         
2179                 for(j = 0; j < 100000; j++){
2180                         yaffs_lseek(h0,0,SEEK_SET);
2181                         yaffs_write(h0,xx,5000);
2182                         yaffs_lseek(h0,0x100000,SEEK_SET);
2183                         yaffs_write(h0,xx,5000);
2184                         
2185                         if(early_exit)
2186                                 exit(0);
2187                 }
2188                 
2189                 yaffs_close(h0);
2190                 
2191         }
2192 }
2193
2194
2195 void yaffs_touch(const char *fn)
2196 {
2197         yaffs_chmod(fn, S_IREAD | S_IWRITE);
2198 }
2199
2200 void checkpoint_fill_test(const char *mountpt,int nmounts)
2201 {
2202
2203         char a[50];
2204         char b[50];
2205         char c[50];
2206         
2207         int i;
2208         int j;
2209         int h;
2210         
2211         sprintf(a,"%s/a",mountpt);
2212         
2213
2214         
2215         
2216         yaffs_StartUp();
2217         
2218         for(i = 0; i < nmounts; i++){
2219                 printf("############### Iteration %d   Start\n",i);
2220                 yaffs_mount(mountpt);
2221                 dump_directory_tree(mountpt);
2222                 yaffs_mkdir(a,0);
2223                 
2224                 sprintf(b,"%s/zz",a);
2225                 
2226                 h = yaffs_open(b,O_CREAT | O_RDWR,S_IREAD |S_IWRITE);
2227                 
2228                 
2229                 while(yaffs_write(h,c,50) == 50){}
2230                 
2231                 yaffs_close(h);
2232                 
2233                 for(j = 0; j < 2; j++){
2234                         printf("touch %d\n",j);
2235                         yaffs_touch(b);
2236                         yaffs_unmount(mountpt);
2237                         yaffs_mount(mountpt);
2238                 }
2239
2240                 dump_directory_tree(mountpt);           
2241                 yaffs_unmount(mountpt);
2242         }
2243 }
2244
2245
2246 int make_file2(const char *name1, const char *name2,int syz)
2247 {
2248
2249         char xx[2500];
2250         int i;
2251         int h1=-1,h2=-1;
2252         int n = 1;
2253
2254
2255         if(name1)
2256                 h1 = yaffs_open(name1,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
2257         if(name2)
2258                 h2 = yaffs_open(name2,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
2259         
2260         while(syz > 0 && n > 0){
2261                 i = (syz > 2500) ? 2500 : syz;
2262                 n = yaffs_write(h1,xx,i);
2263                 n = yaffs_write(h2,xx,i);
2264                 syz -= 500;
2265         }
2266         yaffs_close(h1);
2267         yaffs_close(h2);
2268         return 0;
2269 }
2270
2271
2272 extern void SetCheckpointReservedBlocks(int n);
2273
2274 void checkpoint_upgrade_test(const char *mountpt,int nmounts)
2275 {
2276
2277         char a[50];
2278         char b[50];
2279         char c[50];
2280         char d[50];
2281
2282         int j;
2283         
2284         sprintf(a,"%s/a",mountpt);
2285         
2286
2287         
2288         
2289         printf("Create start condition\n");
2290         yaffs_StartUp();
2291         yaffs_mount(mountpt);
2292         yaffs_mkdir(a,0);
2293         sprintf(b,"%s/zz",a);
2294         sprintf(c,"%s/xx",a);
2295         make_file2(b,c,2000000);
2296         sprintf(d,"%s/aa",a);
2297         make_file2(d,NULL,500000000);
2298         dump_directory_tree(mountpt);
2299         
2300         printf("Umount/mount attempt full\n");
2301         yaffs_unmount(mountpt);
2302         
2303         yaffs_mount(mountpt);
2304         
2305         printf("unlink small file\n");
2306         yaffs_unlink(c);
2307         dump_directory_tree(mountpt);
2308                 
2309         printf("Umount/mount attempt\n");
2310         yaffs_unmount(mountpt);
2311         yaffs_mount(mountpt);
2312         
2313         for(j = 0; j < 500; j++){
2314                 printf("***** touch %d\n",j);
2315                 dump_directory_tree(mountpt);
2316                 yaffs_touch(b);
2317                 yaffs_unmount(mountpt);
2318                 yaffs_mount(mountpt);
2319         }
2320
2321         for(j = 0; j < 500; j++){
2322                 printf("***** touch %d\n",j);
2323                 dump_directory_tree(mountpt);
2324                 yaffs_touch(b);
2325                 yaffs_unmount(mountpt);
2326                 yaffs_mount(mountpt);
2327         }
2328 }
2329         
2330 void huge_array_test(const char *mountpt,int n)
2331 {
2332
2333         char a[50];
2334
2335         
2336         int i;
2337         int space;
2338         
2339         int fnum;
2340         
2341         sprintf(a,"mount point %s",mountpt);
2342         
2343
2344         
2345         yaffs_StartUp();
2346
2347         yaffs_mount(mountpt);
2348         
2349         while(n>0){
2350                 n--;
2351                 fnum = 0;
2352                 printf("\n\n START run\n\n");
2353                 while((space = yaffs_freespace(mountpt)) > 25000000){
2354                         sprintf(a,"%s/file%d",mountpt,fnum);
2355                         fnum++;
2356                         printf("create file %s, free space %d\n",a,space);
2357                         create_file_of_size(a,10000000);
2358                         printf("verifying file %s\n",a);
2359                         verify_file_of_size(a,10000000);
2360                 }
2361                 
2362                 printf("\n\n verification/deletion\n\n");
2363                 
2364                 for(i = 0; i < fnum; i++){
2365                         sprintf(a,"%s/file%d",mountpt,i);
2366                         printf("verifying file %s\n",a);
2367                         verify_file_of_size(a,10000000);
2368                         printf("deleting file %s\n",a);
2369                         yaffs_unlink(a);
2370                 }
2371                 printf("\n\n done \n\n");
2372                         
2373                    
2374         }
2375 }
2376
2377
2378 void random_write(int h)
2379 {
2380         static char buffer[12000];
2381         int n;
2382         
2383         n = random() & 0x1FFF;
2384         yaffs_write(h,buffer,n);
2385 }
2386
2387 void random_seek(int h)
2388 {
2389         int n;
2390         n = random() & 0xFFFFF;
2391         yaffs_lseek(h,n,SEEK_SET);
2392 }
2393
2394 void random_truncate(int h, char * name)
2395 {
2396         int n;
2397         int flen;
2398         n = random() & 0xFFFFF;
2399         flen = yaffs_lseek(h,0,SEEK_END);
2400         if(n > flen)
2401                 n = flen / 2;
2402         yaffs_ftruncate(h,n);
2403         yaffs_lseek(h,n,SEEK_SET);
2404 }
2405
2406
2407 #define NSMALLFILES 10  
2408 void random_small_file_test(const char *mountpt,int iterations)
2409 {
2410
2411         char a[NSMALLFILES][50];
2412
2413         
2414         int i;
2415         int n;
2416         int h[NSMALLFILES];
2417         int r;
2418         
2419         
2420         yaffs_StartUp();
2421
2422         yaffs_mount(mountpt);
2423         
2424         for(i = 0; i < NSMALLFILES; i++){
2425                 h[i]=-1;
2426                 strcpy(a[i],"");
2427         }
2428         
2429         for(n = 0; n < iterations; n++){
2430                                 
2431                 for(i = 0; i < NSMALLFILES; i++) {
2432                         r = random();
2433                         
2434                         if(strlen(a[i]) == 0){
2435                                 sprintf(a[i],"%s/%dx%d",mountpt,n,i);
2436                                 h[i] = yaffs_open(a[i],O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
2437                         }
2438                         
2439                         if(h[i] < -1)
2440                                 printf("Could not open yaffs file %d %d error %d\n",n,i,h[i]);
2441                         else {
2442                                 r = r & 7;
2443                                 switch(r){
2444                                         case 0:
2445                                         case 1:
2446                                         case 2:
2447                                                 random_write(h[i]);
2448                                                 break;
2449                                         case 3:
2450                                                 random_truncate(h[i],a[i]);
2451                                                 break;
2452                                         case 4:
2453                                         case 5: random_seek(h[i]);
2454                                                 break;
2455                                         case 6:
2456                                                 yaffs_close(h[i]);
2457                                                 h[i] = -1;
2458                                                 break;
2459                                         case 7:
2460                                                 yaffs_close(h[i]);
2461                                                 yaffs_unlink(a[i]);
2462                                                 strcpy(a[i],"");
2463                                                 h[i] = -1;
2464                                 }
2465                         }
2466                 }
2467                    
2468         }
2469         
2470         for(i = 0; i < NSMALLFILES; i++)
2471                 yaffs_close(h[i]);
2472                 
2473         yaffs_unmount(mountpt);
2474 }
2475
2476 void rmdir_test(const char *mountpt)
2477 {
2478         char name[100];
2479         yaffs_StartUp();
2480         
2481         yaffs_mount(mountpt);
2482         
2483         strcpy(name,mountpt);
2484         strcat(name,"/");
2485         strcat(name,"hello");
2486         yaffs_mkdir(name,0666);
2487         yaffs_rmdir(name);
2488         yaffs_unmount(mountpt);
2489 }
2490         
2491
2492 int random_seed;
2493 int simulate_power_failure;
2494
2495 int main(int argc, char *argv[])
2496 {
2497         random_seed = time(NULL);
2498         //return long_test(argc,argv);
2499         
2500         //return cache_read_test();
2501         
2502         // resize_stress_test_no_grow("/flash/flash",20);
2503         //root_perm_remount("/flash/flash");
2504         
2505         //huge_directory_test_on_path("/ram2k");
2506         
2507          //yaffs_backward_scan_test("/flash/flash");
2508         // yaffs_device_flush_test("/flash/flash");
2509
2510         //rename_over_test("//////////////////flash///////////////////yaffs1///////////");
2511         
2512         //fill_empty_files_test("/yaffs2/");
2513         //resize_stress_test("/yaffs2");
2514         overwrite_test("/yaffs2");
2515         
2516         //long_name_test("/yaffs2");
2517         //link_test0("/yaffs2");
2518         //link_test1("yaffs2");
2519          //scan_pattern_test("/flash",10000,10);
2520         //short_scan_test("/flash/flash",40000,200);
2521           //small_mount_test("/flash/flash",1000);
2522           //small_overwrite_test("/flash/flash",1000);
2523           //seek_overwrite_test("/flash/flash",1000);
2524          //checkpoint_fill_test("/flash/flash",20);
2525          //checkpoint_upgrade_test("/flash/flash",20);
2526           //small_overwrite_test("/flash/flash",1000);
2527           //checkpoint_fill_test("/flash/flash",20);
2528         // random_small_file_test("/flash/flash",10000);
2529          // huge_array_test("/flash/flash",10);
2530
2531
2532         // handle_test("yaffs2/");
2533         
2534         //long_test_on_path("/ram2k");
2535         // long_test_on_path("/flash");
2536         //simple_rw_test("/flash/flash");
2537         //fill_disk_test("/flash/flash");
2538         // rename_over_test("/flash");
2539         //lookup_test("/flash");
2540         //freespace_test("/flash/flash");
2541         
2542         //link_test("/flash/flash");
2543         
2544         
2545         
2546         
2547         // cache_bypass_bug_test();
2548         
2549          //free_space_check();
2550          
2551          //check_resize_gc_bug("/flash");
2552          
2553          return 0;
2554         
2555 }