13e55c7196786fb022df7b6f1e6fcf66af21717f
[yaffs2.git] / direct / dtest.c
1 /*
2 * Test code for the "direct" interface. 
3 */
4
5
6 #include <stdio.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include <fcntl.h>
10
11 #include "yaffsfs.h"
12
13 void dumpDir(const char *dname);
14
15 char xx[600];
16
17 void copy_in_a_file(char *yaffsName,char *inName)
18 {
19         int inh,outh;
20         unsigned char buffer[100];
21         int ni,no;
22         inh = open(inName,O_RDONLY);
23         outh = yaffs_open(yaffsName, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
24         
25         while((ni = read(inh,buffer,100)) > 0)
26         {
27                 no = yaffs_write(outh,buffer,ni);
28                 if(ni != no)
29                 {
30                         printf("problem writing yaffs file\n");
31                 }
32                 
33         }
34         
35         yaffs_close(outh);
36         close(inh);
37 }
38
39 void make_a_file(char *yaffsName,char bval,int sizeOfFile)
40 {
41         int outh;
42         int i;
43         unsigned char buffer[100];
44
45         outh = yaffs_open(yaffsName, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
46         
47         memset(buffer,bval,100);
48         
49         do{
50                 i = sizeOfFile;
51                 if(i > 100) i = 100;
52                 sizeOfFile -= i;
53                 
54                 yaffs_write(outh,buffer,i);
55                 
56         } while (sizeOfFile > 0);
57         
58                 
59         yaffs_close(outh);
60
61 }
62
63 void make_pattern_file(char *fn,int size)
64 {
65         int outh;
66         int marker;
67         int i;
68         outh = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
69         yaffs_lseek(outh,size-1,SEEK_SET);
70         yaffs_write(outh,"A",1);
71         
72         for(i = 0; i < size; i+=256)
73         {
74                 marker = ~i;
75                 yaffs_lseek(outh,i,SEEK_SET);
76                 yaffs_write(outh,&marker,sizeof(marker));
77         }
78         yaffs_close(outh);
79         
80 }
81
82 int check_pattern_file(char *fn)
83 {
84         int h;
85         int marker;
86         int i;
87         int size;
88         int ok = 1;
89         
90         h = yaffs_open(fn, O_RDWR,0);
91         size = yaffs_lseek(h,0,SEEK_END);
92                 
93         for(i = 0; i < size; i+=256)
94         {
95                 yaffs_lseek(h,i,SEEK_SET);
96                 yaffs_read(h,&marker,sizeof(marker));
97                 ok = (marker == ~i);
98                 if(!ok)
99                 {
100                    printf("pattern check failed on file %s, size %d at position %d. Got %x instead of %x\n",
101                                         fn,size,i,marker,~i);
102                 }
103         }
104         yaffs_close(h);
105         return ok;
106 }
107
108
109
110
111
112 int dump_file_data(char *fn)
113 {
114         int h;
115         int marker;
116         int i = 0;
117         int size;
118         int ok = 1;
119         unsigned char b;
120         
121         h = yaffs_open(fn, O_RDWR,0);
122
123                                 
124         printf("%s\n",fn);
125         while(yaffs_read(h,&b,1)> 0)
126         {
127                 printf("%02x",b);
128                 i++;
129                 if(i > 32) 
130                 {
131                    printf("\n");
132                    i = 0;;
133                  }
134         }
135         printf("\n");
136         yaffs_close(h);
137         return ok;
138 }
139
140
141
142 void dump_file(const char *fn)
143 {
144         int i;
145         int size;
146         int h;
147         
148         h = yaffs_open(fn,O_RDONLY,0);
149         if(h < 0)
150         {
151                 printf("*****\nDump file %s does not exist\n",fn);
152         }
153         else
154         {
155                 size = yaffs_lseek(h,0,SEEK_SET);
156                 printf("*****\nDump file %s size %d\n",fn,size);
157                 for(i = 0; i < size; i++)
158                 {
159                         
160                 }
161         }
162 }
163
164 void create_file_of_size(const char *fn,int syze)
165 {
166         int h;
167         int n;
168         
169         
170         int iterations = (syze + strlen(fn) -1)/ strlen(fn);
171         
172         h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
173                 
174         while (iterations > 0)
175         {
176                 yaffs_write(h,fn,strlen(fn));
177                 iterations--;
178         }
179         yaffs_close (h);
180 }
181
182 void create_resized_file_of_size(const char *fn,int syze1,int reSyze, int syze2)
183 {
184         int h;
185         int n;
186         
187         
188         int iterations;
189         
190         h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
191                 
192         iterations = (syze1 + strlen(fn) -1)/ strlen(fn);
193         while (iterations > 0)
194         {
195                 yaffs_write(h,fn,strlen(fn));
196                 iterations--;
197         }
198         
199         yaffs_truncate(h,reSyze);
200         
201         yaffs_lseek(h,0,SEEK_SET);
202         iterations = (syze2 + strlen(fn) -1)/ strlen(fn);
203         while (iterations > 0)
204         {
205                 yaffs_write(h,fn,strlen(fn));
206                 iterations--;
207         }
208         
209         yaffs_close (h);
210 }
211
212
213 void do_some_file_stuff(const char *path)
214 {
215
216         char fn[100];
217
218         sprintf(fn,"%s/%s",path,"f1");
219         create_file_of_size(fn,10000);
220
221         sprintf(fn,"%s/%s",path,"fdel");
222         create_file_of_size(fn,10000);
223         yaffs_unlink(fn);
224
225         sprintf(fn,"%s/%s",path,"f2");
226         
227         create_resized_file_of_size(fn,10000,3000,4000);
228 }
229
230 void yaffs_backward_scan_test(const char *path)
231 {
232         char fn[100];
233         
234         yaffs_StartUp();        
235         
236         yaffs_mount(path);
237         
238         do_some_file_stuff(path);
239         
240         sprintf(fn,"%s/ddd",path);
241         
242         yaffs_mkdir(fn,0);
243         
244         do_some_file_stuff(fn);
245         
246         yaffs_unmount(path);
247         
248         yaffs_mount(path);
249 }
250
251 char xxzz[2000];
252
253
254 void yaffs_device_flush_test(const char *path)
255 {
256         char fn[100];
257         int h;
258         int i;
259         
260         yaffs_StartUp();        
261         
262         yaffs_mount(path);
263         
264         do_some_file_stuff(path);
265         
266         // Open and add some data to a few files
267         for(i = 0; i < 10; i++) {
268         
269                 sprintf(fn,"%s/ff%d",path,i);
270
271                 h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IWRITE | S_IREAD);
272                 yaffs_write(h,xxzz,2000);
273                 yaffs_write(h,xxzz,2000);
274         }
275         yaffs_unmount(path);
276         
277         yaffs_mount(path);
278 }
279
280
281
282 void short_scan_test(const char *path, int fsize, int niterations)
283 {
284         int i;
285         char fn[100];
286         
287         sprintf(fn,"%s/%s",path,"f1");
288         
289         yaffs_StartUp();
290         for(i = 0; i < niterations; i++)
291         {
292                 printf("\n*****************\nIteration %d\n",i);
293                 yaffs_mount(path);
294                 printf("\nmount: Directory look-up of %s\n",path);
295                 dumpDir(path);
296                 make_a_file(fn,1,fsize);
297                 yaffs_unmount(path);
298         }
299 }
300
301
302
303 void scan_pattern_test(const char *path, int fsize, int niterations)
304 {
305         int i;
306         int j;
307         char fn[3][100];
308         int result;
309         
310         sprintf(fn[0],"%s/%s",path,"f0");
311         sprintf(fn[1],"%s/%s",path,"f1");
312         sprintf(fn[2],"%s/%s",path,"f2");
313         
314         yaffs_StartUp();
315         
316         for(i = 0; i < niterations; i++)
317         {
318                 printf("\n*****************\nIteration %d\n",i);
319                 yaffs_mount(path);
320                 printf("\nmount: Directory look-up of %s\n",path);
321                 dumpDir(path);
322                 for(j = 0; j < 3; j++)
323                 {
324                         result = dump_file_data(fn[j]);
325                         result = check_pattern_file(fn[j]);
326                         make_pattern_file(fn[j],fsize); 
327                         result = dump_file_data(fn[j]);
328                         result = check_pattern_file(fn[j]);
329                 }
330                 yaffs_unmount(path);
331         }
332 }
333
334 void fill_disk(char *path,int nfiles)
335 {
336         int h;
337         int n;
338         int result;
339         int f;
340         
341         char str[50];
342         
343         for(n = 0; n < nfiles; n++)
344         {
345                 sprintf(str,"%s/%d",path,n);
346                 
347                 h = yaffs_open(str, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
348                 
349                 printf("writing file %s handle %d ",str, h);
350                 
351                 while ((result = yaffs_write(h,xx,600)) == 600)
352                 {
353                         f = yaffs_freespace(path);
354                 }
355                 result = yaffs_close(h);
356                 printf(" close %d\n",result);
357         }
358 }
359
360 void fill_disk_and_delete(char *path, int nfiles, int ncycles)
361 {
362         int i,j;
363         char str[50];
364         int result;
365         
366         for(i = 0; i < ncycles; i++)
367         {
368                 printf("@@@@@@@@@@@@@@ cycle %d\n",i);
369                 fill_disk(path,nfiles);
370                 
371                 for(j = 0; j < nfiles; j++)
372                 {
373                         sprintf(str,"%s/%d",path,j);
374                         result = yaffs_unlink(str);
375                         printf("unlinking file %s, result %d\n",str,result);
376                 }
377         }
378 }
379
380
381 void fill_files(char *path,int flags, int maxIterations,int siz)
382 {
383         int i;
384         int j;
385         char str[50];
386         int h;
387         
388         i = 0;
389         
390         do{
391                 sprintf(str,"%s/%d",path,i);
392                 h = yaffs_open(str, O_CREAT | O_TRUNC | O_RDWR,S_IREAD | S_IWRITE);
393                 yaffs_close(h);
394
395                 if(h >= 0)
396                 {
397                         for(j = 0; j < siz; j++)
398                         {
399                                 yaffs_write(h,str,1);
400                         }
401                 }
402                 
403                 if( flags & 1)
404                 {
405                         yaffs_unlink(str);
406                 }
407                 i++;
408         } while(h >= 0 && i < maxIterations);
409         
410         if(flags & 2)
411         {
412                 i = 0;
413                 do{
414                         sprintf(str,"%s/%d",path,i);
415                         printf("unlink %s\n",str);
416                         i++;
417                 } while(yaffs_unlink(str) >= 0);
418         }
419 }
420
421 void leave_unlinked_file(char *path,int maxIterations,int siz)
422 {
423         int i;
424         char str[50];
425         int h;
426         
427         i = 0;
428         
429         do{
430                 sprintf(str,"%s/%d",path,i);
431                 printf("create %s\n",str);
432                 h = yaffs_open(str, O_CREAT | O_TRUNC | O_RDWR,S_IREAD | S_IWRITE);
433                 if(h >= 0)
434                 {
435                         yaffs_unlink(str);
436                 }
437                 i++;
438         } while(h < 0 && i < maxIterations);
439         
440         if(h >= 0)
441         {
442                 for(i = 0; i < siz; i++)
443                 {
444                         yaffs_write(h,str,1);
445                 }
446         }
447         
448         printf("Leaving file %s open\n",str);
449
450 }
451
452 void dumpDirFollow(const char *dname)
453 {
454         yaffs_DIR *d;
455         yaffs_dirent *de;
456         struct yaffs_stat s;
457         char str[100];
458                         
459         d = yaffs_opendir(dname);
460         
461         if(!d)
462         {
463                 printf("opendir failed\n");
464         }
465         else
466         {
467                 while((de = yaffs_readdir(d)) != NULL)
468                 {
469                         sprintf(str,"%s/%s",dname,de->d_name);
470                         
471                         yaffs_stat(str,&s);
472                         
473                         printf("%s length %d mode %X ",de->d_name,(int)s.st_size,s.st_mode);
474                         switch(s.st_mode & S_IFMT)
475                         {
476                                 case S_IFREG: printf("data file"); break;
477                                 case S_IFDIR: printf("directory"); break;
478                                 case S_IFLNK: printf("symlink -->");
479                                                           if(yaffs_readlink(str,str,100) < 0)
480                                                                 printf("no alias");
481                                                           else
482                                                                 printf("\"%s\"",str);    
483                                                           break;
484                                 default: printf("unknown"); break;
485                         }
486                         
487                         printf("\n");           
488                 }
489                 
490                 yaffs_closedir(d);
491         }
492         printf("\n");
493         
494         printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
495
496 }
497
498
499 void dump_directory_tree_worker(const char *dname,int recursive)
500 {
501         yaffs_DIR *d;
502         yaffs_dirent *de;
503         struct yaffs_stat s;
504         char str[100];
505                         
506         d = yaffs_opendir(dname);
507         
508         if(!d)
509         {
510                 printf("opendir failed\n");
511         }
512         else
513         {
514                 while((de = yaffs_readdir(d)) != NULL)
515                 {
516                         sprintf(str,"%s/%s",dname,de->d_name);
517                         
518                         yaffs_lstat(str,&s);
519                         
520                         printf("%s length %d mode %X ",str,(int)s.st_size,s.st_mode);
521                         switch(s.st_mode & S_IFMT)
522                         {
523                                 case S_IFREG: printf("data file"); break;
524                                 case S_IFDIR: printf("directory"); break;
525                                 case S_IFLNK: printf("symlink -->");
526                                                           if(yaffs_readlink(str,str,100) < 0)
527                                                                 printf("no alias");
528                                                           else
529                                                                 printf("\"%s\"",str);    
530                                                           break;
531                                 default: printf("unknown"); break;
532                         }
533                         
534                         printf("\n");
535
536                         if((s.st_mode & S_IFMT) == S_IFDIR && recursive)
537                                 dump_directory_tree_worker(str,1);
538                                                         
539                 }
540                 
541                 yaffs_closedir(d);
542         }
543
544 }
545
546 static void dump_directory_tree(const char *dname)
547 {
548         dump_directory_tree_worker(dname,1);
549         printf("\n");
550         printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
551 }
552
553 void dumpDir(const char *dname)
554 {       dump_directory_tree_worker(dname,0);
555         printf("\n");
556         printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
557 }
558
559
560 static void PermissionsCheck(const char *path, mode_t tmode, int tflags,int expectedResult)
561 {
562         int fd;
563         
564         if(yaffs_chmod(path,tmode)< 0) printf("chmod failed\n");
565         
566         fd = yaffs_open(path,tflags,0);
567         
568         if((fd >= 0) != (expectedResult > 0))
569         {
570                 printf("Permissions check %x %x %d failed\n",tmode,tflags,expectedResult);
571         }
572         else
573         {
574                 printf("Permissions check %x %x %d OK\n",tmode,tflags,expectedResult);
575         }
576         
577         
578         yaffs_close(fd);
579         
580         
581 }
582
583 int long_test(int argc, char *argv[])
584 {
585
586         int f;
587         int r;
588         char buffer[20];
589         
590         char str[100];
591         
592         int h;
593         mode_t temp_mode;
594         struct yaffs_stat ystat;
595         
596         yaffs_StartUp();
597         
598         yaffs_mount("/boot");
599         yaffs_mount("/data");
600         yaffs_mount("/flash");
601         yaffs_mount("/ram");
602         
603         printf("\nDirectory look-up of /boot\n");
604         dumpDir("/boot");
605         printf("\nDirectory look-up of /data\n");
606         dumpDir("/data");
607         printf("\nDirectory look-up of /flash\n");
608         dumpDir("/flash");
609
610         //leave_unlinked_file("/flash",20000,0);
611         //leave_unlinked_file("/data",20000,0);
612         
613         leave_unlinked_file("/ram",20,0);
614         
615
616         f = yaffs_open("/boot/b1", O_RDONLY,0);
617         
618         printf("open /boot/b1 readonly, f=%d\n",f);
619         
620         f = yaffs_open("/boot/b1", O_CREAT,S_IREAD | S_IWRITE);
621         
622         printf("open /boot/b1 O_CREAT, f=%d\n",f);
623         
624         
625         r = yaffs_write(f,"hello",1);
626         printf("write %d attempted to write to a read-only file\n",r);
627         
628         r = yaffs_close(f);
629         
630         printf("close %d\n",r);
631
632         f = yaffs_open("/boot/b1", O_RDWR,0);
633         
634         printf("open /boot/b1 O_RDWR,f=%d\n",f);
635         
636         
637         r = yaffs_write(f,"hello",2);
638         printf("write %d attempted to write to a writeable file\n",r);
639         r = yaffs_write(f,"world",3);
640         printf("write %d attempted to write to a writeable file\n",r);
641         
642         r= yaffs_lseek(f,0,SEEK_END);
643         printf("seek end %d\n",r);
644         memset(buffer,0,20);
645         r = yaffs_read(f,buffer,10);
646         printf("read %d \"%s\"\n",r,buffer);
647         r= yaffs_lseek(f,0,SEEK_SET);
648         printf("seek set %d\n",r);
649         memset(buffer,0,20);
650         r = yaffs_read(f,buffer,10);
651         printf("read %d \"%s\"\n",r,buffer);
652         memset(buffer,0,20);
653         r = yaffs_read(f,buffer,10);
654         printf("read %d \"%s\"\n",r,buffer);
655
656         // Check values reading at end.
657         // A read past end of file should return 0 for 0 bytes read.
658                 
659         r= yaffs_lseek(f,0,SEEK_END);
660         r = yaffs_read(f,buffer,10);
661         printf("read at end returned  %d\n",r); 
662         r= yaffs_lseek(f,500,SEEK_END);
663         r = yaffs_read(f,buffer,10);
664         printf("read past end returned  %d\n",r);       
665         
666         r = yaffs_close(f);
667         
668         printf("close %d\n",r);
669         
670         copy_in_a_file("/boot/yyfile","xxx");
671         
672         // Create a file with a long name
673         
674         copy_in_a_file("/boot/file with a long name","xxx");
675         
676         
677         printf("\nDirectory look-up of /boot\n");
678         dumpDir("/boot");
679
680         // Check stat
681         r = yaffs_stat("/boot/file with a long name",&ystat);
682         
683         // Check rename
684         
685         r = yaffs_rename("/boot/file with a long name","/boot/r1");
686         
687         printf("\nDirectory look-up of /boot\n");
688         dumpDir("/boot");
689         
690         // Check unlink
691         r = yaffs_unlink("/boot/r1");
692         
693         printf("\nDirectory look-up of /boot\n");
694         dumpDir("/boot");
695
696         // Check mkdir
697         
698         r = yaffs_mkdir("/boot/directory1",0);
699         
700         printf("\nDirectory look-up of /boot\n");
701         dumpDir("/boot");
702         printf("\nDirectory look-up of /boot/directory1\n");
703         dumpDir("/boot/directory1");
704
705         // add a file to the directory                  
706         copy_in_a_file("/boot/directory1/file with a long name","xxx");
707         
708         printf("\nDirectory look-up of /boot\n");
709         dumpDir("/boot");
710         printf("\nDirectory look-up of /boot/directory1\n");
711         dumpDir("/boot/directory1");
712         
713         //  Attempt to delete directory (should fail)
714         
715         r = yaffs_rmdir("/boot/directory1");
716         
717         printf("\nDirectory look-up of /boot\n");
718         dumpDir("/boot");
719         printf("\nDirectory look-up of /boot/directory1\n");
720         dumpDir("/boot/directory1");
721         
722         // Delete file first, then rmdir should work
723         r = yaffs_unlink("/boot/directory1/file with a long name");
724         r = yaffs_rmdir("/boot/directory1");
725         
726         
727         printf("\nDirectory look-up of /boot\n");
728         dumpDir("/boot");
729         printf("\nDirectory look-up of /boot/directory1\n");
730         dumpDir("/boot/directory1");
731
732 #if 0
733         fill_disk_and_delete("/boot",20,20);
734                         
735         printf("\nDirectory look-up of /boot\n");
736         dumpDir("/boot");
737 #endif
738
739         yaffs_symlink("yyfile","/boot/slink");
740         
741         yaffs_readlink("/boot/slink",str,100);
742         printf("symlink alias is %s\n",str);
743         
744         
745         
746         
747         printf("\nDirectory look-up of /boot\n");
748         dumpDir("/boot");
749         printf("\nDirectory look-up of /boot (using stat instead of lstat)\n");
750         dumpDirFollow("/boot");
751         printf("\nDirectory look-up of /boot/directory1\n");
752         dumpDir("/boot/directory1");
753
754         h = yaffs_open("/boot/slink",O_RDWR,0);
755         
756         printf("file length is %d\n",(int)yaffs_lseek(h,0,SEEK_END));
757         
758         yaffs_close(h);
759         
760         yaffs_unlink("/boot/slink");
761
762         
763         printf("\nDirectory look-up of /boot\n");
764         dumpDir("/boot");
765         
766         // Check chmod
767         
768         yaffs_stat("/boot/yyfile",&ystat);
769         temp_mode = ystat.st_mode;
770         
771         yaffs_chmod("/boot/yyfile",0x55555);
772         printf("\nDirectory look-up of /boot\n");
773         dumpDir("/boot");
774         
775         yaffs_chmod("/boot/yyfile",temp_mode);
776         printf("\nDirectory look-up of /boot\n");
777         dumpDir("/boot");
778         
779         // Permission checks...
780         PermissionsCheck("/boot/yyfile",0, O_WRONLY,0);
781         PermissionsCheck("/boot/yyfile",0, O_RDONLY,0);
782         PermissionsCheck("/boot/yyfile",0, O_RDWR,0);
783
784         PermissionsCheck("/boot/yyfile",S_IREAD, O_WRONLY,0);
785         PermissionsCheck("/boot/yyfile",S_IREAD, O_RDONLY,1);
786         PermissionsCheck("/boot/yyfile",S_IREAD, O_RDWR,0);
787
788         PermissionsCheck("/boot/yyfile",S_IWRITE, O_WRONLY,1);
789         PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDONLY,0);
790         PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDWR,0);
791         
792         PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_WRONLY,1);
793         PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDONLY,1);
794         PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDWR,1);
795
796         yaffs_chmod("/boot/yyfile",temp_mode);
797         
798         //create a zero-length file and unlink it (test for scan bug)
799         
800         h = yaffs_open("/boot/zlf",O_CREAT | O_TRUNC | O_RDWR,0);
801         yaffs_close(h);
802         
803         yaffs_unlink("/boot/zlf");
804         
805         
806         yaffs_DumpDevStruct("/boot");
807         
808         fill_disk_and_delete("/boot",20,20);
809         
810         yaffs_DumpDevStruct("/boot");
811         
812         fill_files("/boot",1,10000,0);
813         fill_files("/boot",1,10000,5000);
814         fill_files("/boot",2,10000,0);
815         fill_files("/boot",2,10000,5000);
816         
817         leave_unlinked_file("/data",20000,0);
818         leave_unlinked_file("/data",20000,5000);
819         leave_unlinked_file("/data",20000,5000);
820         leave_unlinked_file("/data",20000,5000);
821         leave_unlinked_file("/data",20000,5000);
822         leave_unlinked_file("/data",20000,5000);
823         
824         yaffs_DumpDevStruct("/boot");
825         yaffs_DumpDevStruct("/data");
826         
827                 
828                 
829         return 0;
830
831 }
832
833 int huge_directory_test_on_path(char *path)
834 {
835
836         yaffs_DIR *d;
837         yaffs_dirent *de;
838         struct yaffs_stat s;
839
840         int f;
841         int i;
842         int r;
843         int total = 0;
844         int lastTotal = 0;
845         char buffer[20];
846         
847         char str[100];
848         char name[100];
849         char name2[100];
850         
851         int h;
852         mode_t temp_mode;
853         struct yaffs_stat ystat;
854         
855         yaffs_StartUp();
856         
857         yaffs_mount(path);
858         
859         // Create a large number of files
860         
861         for(i = 0; i < 2000; i++)
862         {
863           sprintf(str,"%s/%d",path,i);
864           
865            f = yaffs_open(str,O_CREAT,S_IREAD | S_IWRITE);
866            yaffs_close(f);
867         }
868         
869         
870         
871         d = yaffs_opendir(path);
872         i = 0;
873         if (d) {
874         while((de = yaffs_readdir(d)) != NULL) {
875         if (total >lastTotal+100*9*1024||(i & 1023)==0){
876         printf("files = %d, total = %d\n",i, total);
877         lastTotal = total;
878         }
879                 i++;
880                 sprintf(str,"%s/%s",path,de->d_name);
881                 yaffs_lstat(str,&s);
882                 switch(s.st_mode & S_IFMT){
883                 case S_IFREG:
884         //printf("data file");
885         total += s.st_size;
886         break;
887         }
888         }
889         
890         yaffs_closedir(d);
891         }
892         
893         return 0;
894 }
895
896 int yaffs_scan_test(const char *path)
897 {
898 }
899
900
901 void rename_over_test(const char *mountpt)
902 {
903         int i;
904         char a[100];
905         char b[100];
906         
907         sprintf(a,"%s/a",mountpt);
908         sprintf(b,"%s/b",mountpt);
909         
910         yaffs_StartUp();
911         
912         yaffs_mount(mountpt);
913         i = yaffs_open(a,O_CREAT | O_TRUNC | O_RDWR, 0); 
914         yaffs_close(i);
915         i = yaffs_open(b,O_CREAT | O_TRUNC | O_RDWR, 0);
916         yaffs_close(i);
917         yaffs_rename(a,b); // rename over
918         yaffs_rename(b,a); // rename back again (not renaimng over)
919         yaffs_rename(a,b); // rename back again (not renaimng over)
920         
921         
922         yaffs_unmount(mountpt);
923         
924 }
925
926 int resize_stress_test(const char *path)
927 {
928    int a,b,i,j;
929    int x;
930    int r;
931    char aname[100];
932    char bname[100];
933    
934    char abuffer[1000];
935    char bbuffer[1000];
936    
937    yaffs_StartUp();
938    
939    yaffs_mount(path);
940    
941    sprintf(aname,"%s%s",path,"/a");
942    sprintf(bname,"%s%s",path,"/b");
943    
944    memset(abuffer,'a',1000);
945    memset(bbuffer,'b',1000);
946    
947    a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
948    b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
949    
950    printf(" %s %d %s %d\n",aname,a,bname,b);
951   
952    x = 0;
953    
954    for(j = 0; j < 100; j++)
955    {
956                 yaffs_lseek(a,0,SEEK_END);
957
958                 
959                 for(i = 0; i <20000; i++)
960                 {
961                    //r =        yaffs_lseek(b,i,SEEK_SET);
962                         //r = yaffs_write(b,bbuffer,1000);
963                         
964                         if(x & 0x16)
965                         {
966                                 // shrink
967                                 int syz = yaffs_lseek(a,0,SEEK_END);
968                                 
969                                 syz -= 500;
970                                 if(syz < 0) syz = 0;
971                                 yaffs_truncate(a,syz);
972                                 
973                         }
974                         else
975                         {
976                                 //expand
977                                 r = yaffs_lseek(a,i * 500,SEEK_SET);
978                                 r = yaffs_write(a,abuffer,1000);
979                         }
980                         x++;
981                         
982                 }
983    }
984    
985    return 0;
986    
987 }
988
989
990 int resize_stress_test_no_grow_complex(const char *path,int iters)
991 {
992    int a,b,i,j;
993    int x;
994    int r;
995    char aname[100];
996    char bname[100];
997    
998    char abuffer[1000];
999    char bbuffer[1000];
1000    
1001    yaffs_StartUp();
1002    
1003    yaffs_mount(path);
1004    
1005    sprintf(aname,"%s%s",path,"/a");
1006    sprintf(bname,"%s%s",path,"/b");
1007    
1008    memset(abuffer,'a',1000);
1009    memset(bbuffer,'b',1000);
1010    
1011    a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1012    b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1013    
1014    printf(" %s %d %s %d\n",aname,a,bname,b);
1015   
1016    x = 0;
1017    
1018    for(j = 0; j < iters; j++)
1019    {
1020                 yaffs_lseek(a,0,SEEK_END);
1021
1022                 
1023                 for(i = 0; i <20000; i++)
1024                 {
1025                    //r =        yaffs_lseek(b,i,SEEK_SET);
1026                         //r = yaffs_write(b,bbuffer,1000);
1027                         
1028                         if(!(x%20))
1029                         {
1030                                 // shrink
1031                                 int syz = yaffs_lseek(a,0,SEEK_END);
1032                                 
1033                                 while(syz > 4000)
1034                                 {
1035                                 
1036                                         syz -= 2050;
1037                                         if(syz < 0) syz = 0;
1038                                         yaffs_truncate(a,syz);
1039                                         syz = yaffs_lseek(a,0,SEEK_END);
1040                                         printf("shrink to %d\n",syz);
1041                                 }
1042                                 
1043                                 
1044                         }
1045                         else
1046                         {
1047                                 //expand
1048                                 r = yaffs_lseek(a,500,SEEK_END);
1049                                 r = yaffs_write(a,abuffer,1000);
1050                         }
1051                         x++;
1052                         
1053                                         
1054                 }
1055                 printf("file size is %d\n",yaffs_lseek(a,0,SEEK_END));
1056
1057    }
1058    
1059    return 0;
1060    
1061 }
1062
1063 int resize_stress_test_no_grow(const char *path,int iters)
1064 {
1065    int a,b,i,j;
1066    int x;
1067    int r;
1068    char aname[100];
1069    char bname[100];
1070    
1071    char abuffer[1000];
1072    char bbuffer[1000];
1073    
1074    yaffs_StartUp();
1075    
1076    yaffs_mount(path);
1077    
1078    sprintf(aname,"%s%s",path,"/a");
1079    sprintf(bname,"%s%s",path,"/b");
1080    
1081    memset(abuffer,'a',1000);
1082    memset(bbuffer,'b',1000);
1083    
1084    a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1085    b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1086    
1087    printf(" %s %d %s %d\n",aname,a,bname,b);
1088   
1089    x = 0;
1090    
1091    for(j = 0; j < iters; j++)
1092    {
1093                 yaffs_lseek(a,0,SEEK_END);
1094
1095                 
1096                 for(i = 0; i <20000; i++)
1097                 {
1098                    //r =        yaffs_lseek(b,i,SEEK_SET);
1099                         //r = yaffs_write(b,bbuffer,1000);
1100                         
1101                         if(!(x%20))
1102                         {
1103                                 // shrink
1104                                 int syz = yaffs_lseek(a,0,SEEK_END);
1105                                 
1106                                 while(syz > 4000)
1107                                 {
1108                                 
1109                                         syz -= 2050;
1110                                         if(syz < 0) syz = 0;
1111                                         yaffs_truncate(a,syz);
1112                                         syz = yaffs_lseek(a,0,SEEK_END);
1113                                         printf("shrink to %d\n",syz);
1114                                 }
1115                                 
1116                                 
1117                         }
1118                         else
1119                         {
1120                                 //expand
1121                                 r = yaffs_lseek(a,-500,SEEK_END);
1122                                 r = yaffs_write(a,abuffer,1000);
1123                         }
1124                         x++;
1125                         
1126                                         
1127                 }
1128                 printf("file size is %d\n",yaffs_lseek(a,0,SEEK_END));
1129
1130    }
1131    
1132    return 0;
1133    
1134 }
1135
1136 int directory_rename_test(void)
1137 {
1138         int r;
1139         yaffs_StartUp();
1140         
1141         yaffs_mount("/ram");
1142         yaffs_mkdir("/ram/a",0);
1143         yaffs_mkdir("/ram/a/b",0);
1144         yaffs_mkdir("/ram/c",0);
1145         
1146         printf("\nDirectory look-up of /ram\n");
1147         dumpDir("/ram");
1148         dumpDir("/ram/a");
1149         dumpDir("/ram/a/b");
1150
1151         printf("Do rename (should fail)\n");
1152                 
1153         r = yaffs_rename("/ram/a","/ram/a/b/d");
1154         printf("\nDirectory look-up of /ram\n");
1155         dumpDir("/ram");
1156         dumpDir("/ram/a");
1157         dumpDir("/ram/a/b");
1158
1159         printf("Do rename (should not fail)\n");
1160                 
1161         r = yaffs_rename("/ram/c","/ram/a/b/d");
1162         printf("\nDirectory look-up of /ram\n");
1163         dumpDir("/ram");
1164         dumpDir("/ram/a");
1165         dumpDir("/ram/a/b");
1166         
1167         
1168         return 1;
1169         
1170 }
1171
1172 int cache_read_test(void)
1173 {
1174         int a,b,c;
1175         int i;
1176         int sizeOfFiles = 500000;
1177         char buffer[100];
1178         
1179         yaffs_StartUp();
1180         
1181         yaffs_mount("/boot");
1182         
1183         make_a_file("/boot/a",'a',sizeOfFiles);
1184         make_a_file("/boot/b",'b',sizeOfFiles);
1185
1186         a = yaffs_open("/boot/a",O_RDONLY,0);
1187         b = yaffs_open("/boot/b",O_RDONLY,0);
1188         c = yaffs_open("/boot/c", O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
1189
1190         do{
1191                 i = sizeOfFiles;
1192                 if (i > 100) i = 100;
1193                 sizeOfFiles  -= i;
1194                 yaffs_read(a,buffer,i);
1195                 yaffs_read(b,buffer,i);
1196                 yaffs_write(c,buffer,i);
1197         } while(sizeOfFiles > 0);
1198         
1199         
1200         
1201         return 1;
1202         
1203 }
1204
1205 int cache_bypass_bug_test(void)
1206 {
1207         // This test reporoduces a bug whereby YAFFS caching *was* buypassed
1208         // resulting in erroneous reads after writes.
1209         // This bug has been fixed.
1210         
1211         int a;
1212         int i;
1213         char buffer1[1000];
1214         char buffer2[1000];
1215         
1216         memset(buffer1,0,sizeof(buffer1));
1217         memset(buffer2,0,sizeof(buffer2));
1218                 
1219         yaffs_StartUp();
1220         
1221         yaffs_mount("/boot");
1222         
1223         // Create a file of 2000 bytes.
1224         make_a_file("/boot/a",'X',2000);
1225
1226         a = yaffs_open("/boot/a",O_RDWR, S_IREAD | S_IWRITE);
1227         
1228         // Write a short sequence to the file.
1229         // This will go into the cache.
1230         yaffs_lseek(a,0,SEEK_SET);
1231         yaffs_write(a,"abcdefghijklmnopqrstuvwxyz",20); 
1232
1233         // Read a short sequence from the file.
1234         // This will come from the cache.
1235         yaffs_lseek(a,0,SEEK_SET);
1236         yaffs_read(a,buffer1,30); 
1237
1238         // Read a page size sequence from the file.
1239         yaffs_lseek(a,0,SEEK_SET);
1240         yaffs_read(a,buffer2,512); 
1241         
1242         printf("buffer 1 %s\n",buffer1);
1243         printf("buffer 2 %s\n",buffer2);
1244         
1245         if(strncmp(buffer1,buffer2,20))
1246         {
1247                 printf("Cache bypass bug detected!!!!!\n");
1248         }
1249         
1250         
1251         return 1;
1252 }
1253
1254
1255 int free_space_check(void)
1256 {
1257         int f;
1258         
1259                 yaffs_StartUp();
1260                 yaffs_mount("/boot");
1261             fill_disk("/boot/",2);
1262             f = yaffs_freespace("/boot");
1263             
1264             printf("%d free when disk full\n",f);           
1265             return 1;
1266 }
1267
1268 int truncate_test(void)
1269 {
1270         int a;
1271         int r;
1272         int i;
1273         int l;
1274
1275         char y[10];
1276
1277         yaffs_StartUp();
1278         yaffs_mount("/boot");
1279
1280         yaffs_unlink("/boot/trunctest");
1281         
1282         a = yaffs_open("/boot/trunctest", O_CREAT | O_TRUNC | O_RDWR,  S_IREAD | S_IWRITE);
1283         
1284         yaffs_write(a,"abcdefghijklmnopqrstuvwzyz",26);
1285         
1286         yaffs_truncate(a,3);
1287         l= yaffs_lseek(a,0,SEEK_END);
1288         
1289         printf("truncated length is %d\n",l);
1290
1291         yaffs_lseek(a,5,SEEK_SET);
1292         yaffs_write(a,"1",1);
1293
1294         yaffs_lseek(a,0,SEEK_SET);
1295         
1296         r = yaffs_read(a,y,10);
1297
1298         printf("read %d bytes:",r);
1299
1300         for(i = 0; i < r; i++) printf("[%02X]",y[i]);
1301
1302         printf("\n");
1303
1304         return 0;
1305
1306 }
1307
1308
1309
1310
1311
1312 void fill_disk_test(const char *mountpt)
1313 {
1314         int i;
1315         yaffs_StartUp();
1316         
1317         for(i = 0; i < 5; i++)
1318         {
1319                 yaffs_mount(mountpt);
1320                 fill_disk_and_delete(mountpt,100,i+1);
1321                 yaffs_unmount(mountpt);
1322         }
1323         
1324 }
1325
1326
1327
1328 void lookup_test(const char *mountpt)
1329 {
1330         int i;
1331         int h;
1332         char a[100];
1333         char b[100];
1334         
1335
1336         yaffs_DIR *d;
1337         yaffs_dirent *de;
1338         struct yaffs_stat s;
1339         char str[100];
1340
1341         yaffs_StartUp();
1342         
1343         yaffs_mount(mountpt);
1344                                 
1345         d = yaffs_opendir(mountpt);
1346         
1347         if(!d)
1348         {
1349                 printf("opendir failed\n");
1350         }
1351         else
1352         {
1353                 
1354                 for(i = 0; (de = yaffs_readdir(d)) != NULL; i++)
1355                 {
1356                         printf("unlinking %s\n",de->d_name);
1357                         yaffs_unlink(de->d_name);
1358                 }
1359                 
1360                 printf("%d files deleted\n",i);
1361         }
1362         
1363         
1364         for(i = 0; i < 2000; i++){
1365         sprintf(a,"%s/%d",mountpt,i);
1366                 h =  yaffs_open(a,O_CREAT | O_TRUNC | O_RDWR, 0);
1367                 yaffs_close(h);
1368         }
1369
1370         yaffs_rewinddir(d);
1371         for(i = 0; (de = yaffs_readdir(d)) != NULL; i++)
1372         {
1373                 printf("%d  %s\n",i,de->d_name);
1374         }       
1375         
1376         printf("%d files listed\n\n\n",i);
1377         
1378         yaffs_rewinddir(d);
1379         yaffs_readdir(d);
1380         yaffs_readdir(d);
1381         yaffs_readdir(d);
1382         
1383         for(i = 0; i < 2000; i++){
1384                 sprintf(a,"%s/%d",mountpt,i);
1385                 yaffs_unlink(a);
1386         }
1387         
1388                 
1389         yaffs_unmount(mountpt);
1390         
1391 }
1392
1393 void link_test(const char *mountpt)
1394 {
1395         int i;
1396         int h;
1397         char a[100];
1398         char b[100];
1399         char c[100];
1400         
1401         int  f0;
1402         int f1;
1403         int f2;
1404         int f3;
1405         sprintf(a,"%s/aaa",mountpt);
1406         sprintf(b,"%s/bbb",mountpt);
1407         sprintf(c,"%s/ccc",mountpt);
1408         
1409         yaffs_StartUp();
1410         
1411         yaffs_mount(mountpt);
1412         
1413         
1414         h = yaffs_open(a, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1415         for(i = 0; i < 100; i++)
1416                 yaffs_write(h,a,100);
1417         
1418         yaffs_close(h);
1419         
1420         yaffs_unlink(b);
1421         yaffs_unlink(c);
1422         yaffs_link(a,b);
1423         yaffs_link(a,c);
1424         yaffs_unlink(b);
1425         yaffs_unlink(c);
1426         yaffs_unlink(a);
1427         
1428         
1429         yaffs_unmount(mountpt);
1430         yaffs_mount(mountpt);
1431         
1432         printf("link test done\n");     
1433         
1434 }
1435
1436 void freespace_test(const char *mountpt)
1437 {
1438         int i;
1439         int h;
1440         char a[100];
1441         char b[100];
1442         
1443         int  f0;
1444         int f1;
1445         int f2;
1446         int f3;
1447         sprintf(a,"%s/aaa",mountpt);
1448         
1449         yaffs_StartUp();
1450         
1451         yaffs_mount(mountpt);
1452         
1453         f0 = yaffs_freespace(mountpt);
1454         
1455         h = yaffs_open(a, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1456         
1457         for(i = 0; i < 100; i++)
1458                 yaffs_write(h,a,100);
1459         
1460         yaffs_close(h);
1461         
1462         f1 = yaffs_freespace(mountpt);
1463         
1464         yaffs_unlink(a);
1465         
1466         f2 = yaffs_freespace(mountpt);
1467         
1468                 
1469         yaffs_unmount(mountpt);
1470         yaffs_mount(mountpt);
1471         
1472         f3 = yaffs_freespace(mountpt);
1473         
1474         printf("%d\n%d\n%d\n%d\n",f0, f1,f2,f3);
1475         
1476         
1477 }
1478
1479 void simple_rw_test(const char *mountpt)
1480 {
1481         int i;
1482         int h;
1483         char a[100];
1484         
1485         int x;
1486         int result;
1487
1488         sprintf(a,"%s/aaa",mountpt);
1489         
1490         yaffs_StartUp();
1491         
1492         yaffs_mount(mountpt);
1493         
1494         yaffs_unlink(a);
1495         
1496         h = yaffs_open(a,O_CREAT| O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1497         
1498         for(i = 100000;i < 200000; i++){
1499                 result = yaffs_write(h,&i,sizeof(i));
1500                 
1501                 if(result != 4)
1502                 {
1503                         printf("write error\n");
1504                         exit(1);
1505                 }
1506         }
1507         
1508         //yaffs_close(h);
1509         
1510         // h = yaffs_open(a,O_RDWR, S_IREAD | S_IWRITE);
1511         
1512         
1513         yaffs_lseek(h,0,SEEK_SET);
1514         
1515         for(i = 100000; i < 200000; i++){
1516                 result = yaffs_read(h,&x,sizeof(x));
1517                 
1518                 if(result != 4 || x != i){
1519                         printf("read error %d %x %x\n",i,result,x);
1520                 }
1521         }
1522         
1523         printf("Simple rw test passed\n");
1524         
1525         
1526         
1527 }
1528
1529
1530 void scan_deleted_files_test(const char *mountpt)
1531 {
1532         char fn[100];
1533         char sub[100];
1534         
1535         const char *p;
1536         
1537         int i;
1538         int j;
1539         int k;
1540         int h;
1541         
1542         sprintf(sub,"%s/sdir",mountpt);
1543         yaffs_StartUp();
1544         
1545         for(j = 0; j < 10; j++)
1546         {
1547                 printf("\n\n>>>>>>> Run %d <<<<<<<<<<<<<\n\n",j);
1548                 yaffs_mount(mountpt);
1549                 yaffs_mkdir(sub,0);
1550                 
1551                 
1552                 p = (j & 0) ? mountpt: sub;
1553         
1554                 for(i = 0; i < 100; i++)
1555                 {
1556                   sprintf(fn,"%s/%d",p,i);  
1557                   
1558                   if(i & 1)
1559                   {
1560                           h = yaffs_open(fn,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1561                           for(k = 0; k < 1000; k++)
1562                                   yaffs_write(h,fn,100);
1563                           yaffs_close(h);
1564                   }
1565                   else
1566                         yaffs_mkdir(fn,0);
1567                 }
1568                 
1569                 for(i = 0; i < 10; i++)
1570                 {
1571                   sprintf(fn,"%s/%d",p,i);  
1572                   if(i & 1) 
1573                         yaffs_unlink(fn);
1574                   else
1575                         yaffs_rmdir(fn);
1576                   
1577                 }
1578                                 
1579                 yaffs_unmount(mountpt);
1580         }
1581         
1582         
1583         
1584
1585 }
1586
1587
1588 void write_10k(int h)
1589 {
1590    int i;
1591    const char *s="0123456789";
1592    for(i = 0; i < 1000; i++)
1593      yaffs_write(h,s,10);
1594
1595 }
1596 void write_200k_file(const char *fn, const char *fdel, const char *fdel1)
1597 {
1598    int h1;
1599    int i;
1600    int offs;
1601    
1602    h1 = yaffs_open(fn, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1603    
1604    for(i = 0; i < 100000; i+= 10000)
1605    {
1606         write_10k(h1);
1607    }
1608    
1609    offs = yaffs_lseek(h1,0,SEEK_CUR);
1610    if( offs != 100000)
1611    {
1612         printf("Could not write file\n");
1613    }
1614    
1615    yaffs_unlink(fdel);
1616    for(i = 0; i < 100000; i+= 10000)
1617    {
1618         write_10k(h1);
1619    }
1620    
1621    offs = yaffs_lseek(h1,0,SEEK_CUR);
1622    if( offs != 200000)
1623    {
1624         printf("Could not write file\n");
1625    }
1626    
1627    yaffs_close(h1);
1628    yaffs_unlink(fdel1);
1629    
1630 }
1631
1632
1633 void verify_200k_file(const char *fn)
1634 {
1635    int h1;
1636    int i;
1637    char x[11];
1638    const char *s="0123456789";
1639    int errCount = 0;
1640    
1641    h1 = yaffs_open(fn, O_RDONLY, 0);
1642    
1643    for(i = 0; i < 200000 && errCount < 10; i+= 10)
1644    {
1645         yaffs_read(h1,x,10);
1646         if(strncmp(x,s,10) != 0)
1647         {
1648                 printf("File %s verification failed at %d\n",fn,i);
1649                 errCount++;
1650         }
1651    }
1652    if(errCount >= 10)
1653         printf("Too many errors... aborted\n");
1654       
1655    yaffs_close(h1);        
1656         
1657 }
1658
1659
1660 void check_resize_gc_bug(const char *mountpt)
1661 {
1662
1663         char a[30];
1664         char b[30];
1665         char c[30];
1666         
1667         int i;
1668         
1669         sprintf(a,"%s/a",mountpt);
1670         sprintf(b,"%s/b",mountpt);
1671         sprintf(c,"%s/c",mountpt);
1672         
1673
1674         
1675         
1676         yaffs_StartUp();
1677         yaffs_mount(mountpt);
1678         yaffs_unlink(a);
1679         yaffs_unlink(b);
1680         
1681         for(i = 0; i < 50; i++)
1682         {  
1683            printf("A\n");write_200k_file(a,"",c);
1684            printf("B\n");verify_200k_file(a);
1685            printf("C\n");write_200k_file(b,a,c);
1686            printf("D\n");verify_200k_file(b);
1687            yaffs_unmount(mountpt);
1688            yaffs_mount(mountpt);
1689            printf("E\n");verify_200k_file(a);
1690            printf("F\n");verify_200k_file(b);
1691         }
1692                 
1693 }
1694
1695
1696 void multi_mount_test(const char *mountpt,int nmounts)
1697 {
1698
1699         char a[30];
1700         char b[30];
1701         char c[30];
1702         
1703         int i;
1704         int j;
1705         
1706         sprintf(a,"%s/a",mountpt);
1707         
1708
1709         
1710         
1711         yaffs_StartUp();
1712         
1713         for(i = 0; i < nmounts; i++){
1714                 printf("############### Iteration %d   Start\n",i);
1715                 yaffs_mount(mountpt);
1716                 dump_directory_tree(mountpt);
1717                 yaffs_mkdir(a,0);
1718                 for(j = 0; j < i; j++){
1719                         sprintf(b,"%s/%d",a,j);
1720                         verify_200k_file(b);
1721                 }
1722                 sprintf(b,"%s/%d",a,i);
1723
1724                 write_200k_file(b,"","");
1725                 
1726                 printf("######## Iteration %d   Start\n",i);
1727                 dump_directory_tree(mountpt);
1728                 
1729                 yaffs_unmount(mountpt);
1730         }
1731 }
1732
1733
1734 int main(int argc, char *argv[])
1735 {
1736         //return long_test(argc,argv);
1737         
1738         //return cache_read_test();
1739         
1740         //resize_stress_test_no_grow("/flash",20);
1741         
1742         //huge_directory_test_on_path("/ram2k");
1743         
1744          //yaffs_backward_scan_test("/flash/flash");
1745         // yaffs_device_flush_test("/flash/flash");
1746
1747          
1748          //scan_pattern_test("/flash",10000,10);
1749         //short_scan_test("/flash/flash",40000,200);
1750          multi_mount_test("/flash/flash",20);
1751
1752
1753         
1754         //long_test_on_path("/ram2k");
1755         // long_test_on_path("/flash");
1756         //simple_rw_test("/flash/flash");
1757         //fill_disk_test("/flash/flash");
1758         // rename_over_test("/flash");
1759         //lookup_test("/flash");
1760         //freespace_test("/flash/flash");
1761         
1762         //link_test("/flash/flash");
1763         
1764         
1765         
1766         
1767         // cache_bypass_bug_test();
1768         
1769          //free_space_check();
1770          
1771          //check_resize_gc_bug("/flash");
1772          
1773          return 0;
1774         
1775 }