]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/fs/fat/v2_0/tests/fatfs1.c
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / fs / fat / v2_0 / tests / fatfs1.c
1 //==========================================================================
2 //
3 //      fatfs1.c
4 //
5 //      Test fileio system
6 //
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 // Copyright (C) 2004 eCosCentric Limited
13 //
14 // eCos is free software; you can redistribute it and/or modify it under
15 // the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 or (at your option) any later version.
17 //
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21 // for more details.
22 //
23 // You should have received a copy of the GNU General Public License along
24 // with eCos; if not, write to the Free Software Foundation, Inc.,
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 //
27 // As a special exception, if other files instantiate templates or use macros
28 // or inline functions from this file, or you compile this file and link it
29 // with other works to produce a work based on this file, this file does not
30 // by itself cause the resulting work to be covered by the GNU General Public
31 // License. However the source code for this file must still be made available
32 // in accordance with section (3) of the GNU General Public License.
33 //
34 // This exception does not invalidate any other reasons why a work based on
35 // this file might be covered by the GNU General Public License.
36 //
37 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38 // at http://sources.redhat.com/ecos/ecos-license/
39 // -------------------------------------------
40 //####ECOSGPLCOPYRIGHTEND####
41 //==========================================================================
42 //#####DESCRIPTIONBEGIN####
43 //
44 // Author(s):           nickg
45 // Contributors:        nickg
46 // Date:                2000-05-25
47 // Purpose:             Test fileio system
48 // Description:         This test uses the testfs to check out the initialization
49 //                      and basic operation of the fileio system
50 //                      
51 //                      
52 //                      
53 //                      
54 //                      
55 //              
56 //
57 //####DESCRIPTIONEND####
58 //
59 //==========================================================================
60
61 #include <pkgconf/hal.h>
62 #include <pkgconf/io_fileio.h>
63 #include <pkgconf/fs_fat.h>
64
65 #include <cyg/infra/cyg_trac.h>        // tracing macros
66 #include <cyg/infra/cyg_ass.h>         // assertion macros
67
68 #include <unistd.h>
69 #include <fcntl.h>
70 #include <sys/stat.h>
71 #include <errno.h>
72 #include <string.h>
73 #include <dirent.h>
74 #include <stdio.h>
75
76 #include <cyg/fileio/fileio.h>
77
78 #include <cyg/infra/testcase.h>
79 #include <cyg/infra/diag.h>            // HAL polled output
80 #include <cyg/fs/fatfs.h>
81
82
83
84 //==========================================================================
85
86 #define SHOW_RESULT( _fn, _res ) \
87 diag_printf("<FAIL>: " #_fn "() returned %d %s\n", _res, _res<0?strerror(errno):"");
88
89 //==========================================================================
90
91 #define IOSIZE  100
92
93 #define LONGNAME1       "long_file_name_that_should_take_up_more_than_one_directory_entry_1"
94 #define LONGNAME2       "long_file_name_that_should_take_up_more_than_one_directory_entry_2"
95
96
97 //==========================================================================
98
99 #ifndef CYGPKG_LIBC_STRING
100
101 char *strcat( char *s1, const char *s2 )
102 {
103     char *s = s1;
104     while( *s1 ) s1++;
105     while( (*s1++ = *s2++) != 0);
106     return s;
107 }
108
109 #endif
110
111 //==========================================================================
112
113 static void listdir( char *name, int statp, int numexpected, int *numgot )
114 {
115     int err;
116     DIR *dirp;
117     int num=0;
118     
119     diag_printf("<INFO>: reading directory %s\n",name);
120     
121     dirp = opendir( name );
122     if( dirp == NULL ) SHOW_RESULT( opendir, -1 );
123
124     for(;;)
125     {
126         struct dirent *entry = readdir( dirp );
127         
128         if( entry == NULL )
129             break;
130         num++;
131         diag_printf("<INFO>: entry %14s",entry->d_name);
132 #ifdef CYGPKG_FS_FAT_RET_DIRENT_DTYPE
133         diag_printf(" d_type %2x", entry->d_type);
134 #endif
135         if( statp )
136         {
137             char fullname[PATH_MAX];
138             struct stat sbuf;
139
140             if( name[0] )
141             {
142                 strcpy(fullname, name );
143                 if( !(name[0] == '/' && name[1] == 0 ) )
144                     strcat(fullname, "/" );
145             }
146             else fullname[0] = 0;
147             
148             strcat(fullname, entry->d_name );
149             
150             err = stat( fullname, &sbuf );
151             if( err < 0 )
152             {
153                 if( errno == ENOSYS )
154                     diag_printf(" <no status available>");
155                 else SHOW_RESULT( stat, err );
156             }
157             else
158             {
159                 diag_printf(" [mode %08x ino %08x nlink %d size %ld]",
160                             sbuf.st_mode,sbuf.st_ino,sbuf.st_nlink,(long)sbuf.st_size);
161             }
162 #ifdef CYGPKG_FS_FAT_RET_DIRENT_DTYPE
163             if ((entry->d_type & S_IFMT) != (sbuf.st_mode & S_IFMT))
164               CYG_TEST_FAIL("File mode's don't match between dirent and stat");
165 #endif
166         }
167
168         diag_printf("\n");
169     }
170
171     err = closedir( dirp );
172     if( err < 0 ) SHOW_RESULT( stat, err );
173     if (numexpected >= 0 && num != numexpected)
174         CYG_TEST_FAIL("Wrong number of dir entries\n");
175     if ( numgot != NULL )
176         *numgot = num;
177 }
178
179 //==========================================================================
180
181 static void createfile( char *name, size_t size )
182 {
183     char buf[IOSIZE];
184     int fd;
185     ssize_t wrote;
186     int i;
187     int err;
188
189     diag_printf("<INFO>: create file %s size %zd \n",name,size);
190
191     err = access( name, F_OK );
192     if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err );
193     
194     for( i = 0; i < IOSIZE; i++ ) buf[i] = i%256;
195  
196     fd = open( name, O_WRONLY|O_CREAT );
197     if( fd < 0 ) SHOW_RESULT( open, fd );
198
199     while( size > 0 )
200     {
201         ssize_t len = size;
202         if ( len > IOSIZE ) len = IOSIZE;
203         
204         wrote = write( fd, buf, len );
205         if( wrote != len ) SHOW_RESULT( write, (int)wrote );        
206
207         size -= wrote;
208     }
209
210     err = close( fd );
211     if( err < 0 ) SHOW_RESULT( close, err );
212 }
213
214 //==========================================================================
215
216 static void maxfile( char *name )
217 {
218     char buf[IOSIZE];
219     int fd;
220     ssize_t wrote;
221     int i;
222     int err;
223     size_t size = 0;
224     size_t prevsize = 0;
225     
226     diag_printf("<INFO>: create maximal file %s\n",name);
227     diag_printf("<INFO>: This may take a few minutes\n");
228
229     err = access( name, F_OK );
230     if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err );
231     
232     for( i = 0; i < IOSIZE; i++ ) buf[i] = i%256;
233  
234     fd = open( name, O_WRONLY|O_CREAT );
235     if( fd < 0 ) SHOW_RESULT( open, fd );
236
237     do
238     {
239         wrote = write( fd, buf, IOSIZE );
240         //if( wrote < 0 ) SHOW_RESULT( write, wrote );        
241
242         if( wrote >= 0 )
243             size += wrote;
244
245         if( (size-prevsize) > 100000 )
246         {
247             diag_printf("<INFO>: size = %zd \n", size);
248             prevsize = size;
249         }
250         
251     } while( wrote == IOSIZE );
252
253     diag_printf("<INFO>: file size == %zd\n",size);
254
255     err = close( fd );
256     if( err < 0 ) SHOW_RESULT( close, err );
257 }
258
259 //==========================================================================
260
261 static void checkfile( char *name )
262 {
263     char buf[IOSIZE];
264     int fd;
265     ssize_t done;
266     int i;
267     int err;
268     off_t pos = 0;
269
270     diag_printf("<INFO>: check file %s\n",name);
271     
272     err = access( name, F_OK );
273     if( err != 0 ) SHOW_RESULT( access, err );
274
275     fd = open( name, O_RDONLY );
276     if( fd < 0 ) SHOW_RESULT( open, fd );
277
278     for(;;)
279     {
280         done = read( fd, buf, IOSIZE );
281         if( done < 0 ) SHOW_RESULT( read, (int)done );
282
283         if( done == 0 ) break;
284
285         for( i = 0; i < done; i++ )
286             if( buf[i] != i%256 )
287             {
288                 diag_printf("buf[%ld+%d](%02x) != %02x\n",pos,i,buf[i],i%256);
289                 CYG_TEST_FAIL("Data read not equal to data written\n");
290             }
291         
292         pos += done;
293     }
294
295     err = close( fd );
296     if( err < 0 ) SHOW_RESULT( close, err );
297 }
298
299 #ifdef CYGCFG_FS_FAT_USE_ATTRIBUTES
300 //==========================================================================
301
302 static void checkattrib(const char *name, 
303                         const cyg_fs_attrib_t test_attrib )
304 {
305     int err;
306     cyg_fs_attrib_t file_attrib;
307
308     diag_printf("<INFO>: check attrib %s\n",name);
309
310     err = cyg_fs_get_attrib(name, &file_attrib);
311     if( err != 0 ) SHOW_RESULT( stat, err );
312
313     if ( (file_attrib & S_FATFS_ATTRIB) != test_attrib )
314         diag_printf("<FAIL>: attrib %s incorrect\n\tExpected %x Was %x\n",
315                     name,test_attrib,(file_attrib & S_FATFS_ATTRIB));
316 }
317 #endif // CYGCFG_FS_FAT_USE_ATTRIBUTES
318
319 //==========================================================================
320
321 static void copyfile( char *name2, char *name1 )
322 {
323
324     int err;
325     char buf[IOSIZE];
326     int fd1, fd2;
327     ssize_t done, wrote;
328
329     diag_printf("<INFO>: copy file %s -> %s\n",name2,name1);
330
331     err = access( name1, F_OK );
332     if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err );
333
334     err = access( name2, F_OK );
335     if( err != 0 ) SHOW_RESULT( access, err );
336     
337     fd1 = open( name1, O_WRONLY|O_CREAT );
338     if( fd1 < 0 ) SHOW_RESULT( open, fd1 );
339
340     fd2 = open( name2, O_RDONLY );
341     if( fd2 < 0 ) SHOW_RESULT( open, fd2 );
342     
343     for(;;)
344     {
345         done = read( fd2, buf, IOSIZE );
346         if( done < 0 ) SHOW_RESULT( read, (int)done );
347
348         if( done == 0 ) break;
349
350         wrote = write( fd1, buf, done );
351         if( wrote != done ) SHOW_RESULT( write, (int) wrote );
352
353         if( wrote != done ) break;
354     }
355
356     err = close( fd1 );
357     if( err < 0 ) SHOW_RESULT( close, err );
358
359     err = close( fd2 );
360     if( err < 0 ) SHOW_RESULT( close, err );
361     
362 }
363
364 //==========================================================================
365
366 static void comparefiles( char *name2, char *name1 )
367 {
368     int err;
369     char buf1[IOSIZE];
370     char buf2[IOSIZE];
371     int fd1, fd2;
372     ssize_t done1, done2;
373     int i;
374
375     diag_printf("<INFO>: compare files %s == %s\n",name2,name1);
376
377     err = access( name1, F_OK );
378     if( err != 0 ) SHOW_RESULT( access, err );
379
380     err = access( name1, F_OK );
381     if( err != 0 ) SHOW_RESULT( access, err );
382     
383     fd1 = open( name1, O_RDONLY );
384     if( fd1 < 0 ) SHOW_RESULT( open, fd1 );
385
386     fd2 = open( name2, O_RDONLY );
387     if( fd2 < 0 ) SHOW_RESULT( open, fd2 );
388     
389     for(;;)
390     {
391         done1 = read( fd1, buf1, IOSIZE );
392         if( done1 < 0 ) SHOW_RESULT( read, (int)done1 );
393
394         done2 = read( fd2, buf2, IOSIZE );
395         if( done2 < 0 ) SHOW_RESULT( read, (int)done2 );
396
397         if( done1 != done2 )
398             diag_printf("Files different sizes\n");
399         
400         if( done1 == 0 ) break;
401
402         for( i = 0; i < done1; i++ )
403             if( buf1[i] != buf2[i] )
404             {
405                 diag_printf("buf1[%d](%02x) != buf1[%d](%02x)\n",i,buf1[i],i,buf2[i]);
406                 CYG_TEST_FAIL("Data in files not equal\n");
407             }
408     }
409
410     err = close( fd1 );
411     if( err < 0 ) SHOW_RESULT( close, err );
412
413     err = close( fd2 );
414     if( err < 0 ) SHOW_RESULT( close, err );
415     
416 }
417
418 //==========================================================================
419
420 void checkcwd( const char *cwd )
421 {
422     static char cwdbuf[PATH_MAX];
423     char *ret;
424
425     ret = getcwd( cwdbuf, sizeof(cwdbuf));
426     if( ret == NULL ) SHOW_RESULT( getcwd, (int)ret );    
427
428     if( strcmp( cwdbuf, cwd ) != 0 )
429     {
430         diag_printf( "cwdbuf %s cwd %s\n",cwdbuf, cwd );
431         CYG_TEST_FAIL( "Current directory mismatch");
432     }
433 }
434
435 //==========================================================================
436 // main
437
438 int main( int argc, char **argv )
439 {
440     int err;
441     int existingdirents=-1;
442 #if defined(CYGSEM_FILEIO_BLOCK_USAGE)
443     struct cyg_fs_block_usage usage;
444 #endif
445
446     CYG_TEST_INIT();
447
448     // --------------------------------------------------------------
449
450     err = mount( "/dev/disk0/1", "/", "fatfs" );    
451     if( err < 0 ) SHOW_RESULT( mount, err );    
452
453     err = chdir( "/" );
454     if( err < 0 ) SHOW_RESULT( chdir, err );
455
456     checkcwd( "/" );
457     
458     listdir( "/", true, -1, &existingdirents );
459
460     // --------------------------------------------------------------
461 #if defined(CYGSEM_FILEIO_BLOCK_USAGE)
462     err = cyg_fs_getinfo("/", FS_INFO_BLOCK_USAGE, &usage, sizeof(usage));
463     if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err );
464     diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n",
465                 usage.total_blocks, usage.total_blocks * usage.block_size); 
466     diag_printf("<INFO>: free size:  %6lld blocks, %10lld bytes\n",
467                 usage.free_blocks, usage.free_blocks * usage.block_size); 
468     diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size);
469 #endif
470     // --------------------------------------------------------------
471
472     createfile( "/foo", 20257 );
473     checkfile( "foo" );
474     copyfile( "foo", "fee");
475     checkfile( "fee" );
476     comparefiles( "foo", "/fee" );
477     diag_printf("<INFO>: mkdir bar\n");
478     err = mkdir( "/bar", 0 );
479     if( err < 0 ) SHOW_RESULT( mkdir, err );
480
481     listdir( "/" , true, existingdirents+3, NULL );
482
483     copyfile( "fee", "/bar/fum" );
484     checkfile( "bar/fum" );
485     comparefiles( "/fee", "bar/fum" );
486
487     diag_printf("<INFO>: cd bar\n");
488     err = chdir( "bar" );
489     if( err < 0 ) SHOW_RESULT( chdir, err );
490
491     checkcwd( "/bar" );
492     
493     diag_printf("<INFO>: rename /foo bundy\n");    
494     err = rename( "/foo", "bundy" );
495     if( err < 0 ) SHOW_RESULT( rename, err );
496     
497     listdir( "/", true, existingdirents+2, NULL );
498     listdir( "" , true, 4, NULL );
499
500     checkfile( "/bar/bundy" );
501     comparefiles("/fee", "bundy" );
502
503 #if defined(CYGSEM_FILEIO_BLOCK_USAGE)
504     err = cyg_fs_getinfo("/", FS_INFO_BLOCK_USAGE, &usage, sizeof(usage));
505     if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err );
506     diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n",
507                 usage.total_blocks, usage.total_blocks * usage.block_size); 
508     diag_printf("<INFO>: free size:  %6lld blocks, %10lld bytes\n",
509                 usage.free_blocks, usage.free_blocks * usage.block_size); 
510     diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size);
511 #endif
512     // --------------------------------------------------------------
513
514     diag_printf("<INFO>: unlink fee\n");    
515     err = unlink( "/fee" );
516     if( err < 0 ) SHOW_RESULT( unlink, err );
517
518     diag_printf("<INFO>: unlink fum\n");        
519     err = unlink( "fum" );
520     if( err < 0 ) SHOW_RESULT( unlink, err );
521
522     diag_printf("<INFO>: unlink /bar/bundy\n");        
523     err = unlink( "/bar/bundy" );
524     if( err < 0 ) SHOW_RESULT( unlink, err );
525
526     diag_printf("<INFO>: cd /\n");        
527     err = chdir( "/" );
528     if( err < 0 ) SHOW_RESULT( chdir, err );
529
530     checkcwd( "/" );
531     
532     diag_printf("<INFO>: rmdir /bar\n");        
533     err = rmdir( "/bar" );
534     if( err < 0 ) SHOW_RESULT( rmdir, err );
535     
536     listdir( "/", false, existingdirents, NULL );
537
538     // --------------------------------------------------------------
539
540 #if 0
541     diag_printf("<INFO>: mkdir disk2\n");
542     err = mkdir( "/disk2", 0 );
543     if( err < 0 ) SHOW_RESULT( mkdir, err );
544 #else
545     diag_printf("<INFO>: mount /disk2\n");    
546     err = mount( "/dev/disk0/2", "/disk2", "fatfs" );    
547     if( err < 0 ) SHOW_RESULT( mount, err );    
548 #endif
549     
550     listdir( "/disk2" , true, -1, &existingdirents);
551         
552     createfile( "/disk2/tinky", 4567 );
553     copyfile( "/disk2/tinky", "/disk2/laalaa" );
554     checkfile( "/disk2/tinky");
555     checkfile( "/disk2/laalaa");
556     comparefiles( "/disk2/tinky", "/disk2/laalaa" );
557
558     diag_printf("<INFO>: cd /disk2\n");    
559     err = chdir( "/disk2" );
560     if( err < 0 ) SHOW_RESULT( chdir, err );
561
562     checkcwd( "/disk2" );
563         
564     diag_printf("<INFO>: mkdir noonoo\n");    
565     err = mkdir( "noonoo", 0 );
566     if( err < 0 ) SHOW_RESULT( mkdir, err );
567
568     listdir( "/disk2" , true, existingdirents+3, NULL);
569
570     diag_printf("<INFO>: cd noonoo\n");
571     err = chdir( "noonoo" );
572     if( err < 0 ) SHOW_RESULT( chdir, err );
573
574     checkcwd( "/disk2/noonoo" );
575     
576     createfile( "tinky", 6789 );
577     checkfile( "tinky" );
578
579     createfile( "dipsy", 34567 );
580     checkfile( "dipsy" );
581     copyfile( "dipsy", "po" );
582     checkfile( "po" );
583     comparefiles( "dipsy", "po" );
584
585     listdir( ".", true, 5, NULL );
586     listdir( "", true, 5, NULL );
587     listdir( "..", true, existingdirents+3, NULL );
588
589     // --------------------------------------------------------------
590
591     diag_printf("<INFO>: unlink tinky\n");    
592     err = unlink( "tinky" );
593     if( err < 0 ) SHOW_RESULT( unlink, err );
594
595     diag_printf("<INFO>: unlink dipsy\n");    
596     err = unlink( "dipsy" );
597     if( err < 0 ) SHOW_RESULT( unlink, err );
598
599     diag_printf("<INFO>: unlink po\n");    
600     err = unlink( "po" );
601     if( err < 0 ) SHOW_RESULT( unlink, err );
602
603     diag_printf("<INFO>: cd ..\n"); 
604     err = chdir( ".." );
605     if( err < 0 ) SHOW_RESULT( chdir, err );
606     checkcwd( "/disk2" );
607     
608     diag_printf("<INFO>: rmdir noonoo\n"); 
609     err = rmdir( "noonoo" );
610     if( err < 0 ) SHOW_RESULT( rmdir, err );
611
612     // --------------------------------------------------------------
613
614     err = mkdir( "x", 0 );
615     if( err < 0 ) SHOW_RESULT( mkdir, err );
616     
617     err = mkdir( "x/y", 0 );
618     if( err < 0 ) SHOW_RESULT( mkdir, err );
619     
620     err = mkdir( "x/y/z", 0 );
621     if( err < 0 ) SHOW_RESULT( mkdir, err );
622
623     err = mkdir( "x/y/z/w", 0 );
624     if( err < 0 ) SHOW_RESULT( mkdir, err );
625     
626     diag_printf("<INFO>: cd /disk2/x/y/z/w\n");
627     err = chdir( "/disk2/x/y/z/w" );
628     if( err < 0 ) SHOW_RESULT( chdir, err );
629     checkcwd( "/disk2/x/y/z/w" );
630
631     diag_printf("<INFO>: cd ..\n");
632     err = chdir( ".." );
633     if( err < 0 ) SHOW_RESULT( chdir, err );
634     checkcwd( "/disk2/x/y/z" );
635     
636     diag_printf("<INFO>: cd .\n");
637     err = chdir( "." );
638     if( err < 0 ) SHOW_RESULT( chdir, err );
639     checkcwd( "/disk2/x/y/z" );
640
641     diag_printf("<INFO>: cd ../../y\n");
642     err = chdir( "../../y" );
643     if( err < 0 ) SHOW_RESULT( chdir, err );
644     checkcwd( "/disk2/x/y" );
645
646     diag_printf("<INFO>: cd ../..\n");
647     err = chdir( "../.." );
648     if( err < 0 ) SHOW_RESULT( chdir, err );
649     checkcwd( "/disk2" );
650
651     diag_printf("<INFO>: rmdir x/y/z/w\n"); 
652     err = rmdir( "x/y/z/w" );
653     if( err < 0 ) SHOW_RESULT( rmdir, err );
654
655     diag_printf("<INFO>: rmdir x/y/z\n"); 
656     err = rmdir( "x/y/z" );
657     if( err < 0 ) SHOW_RESULT( rmdir, err );
658
659     diag_printf("<INFO>: rmdir x/y\n"); 
660     err = rmdir( "x/y" );
661     if( err < 0 ) SHOW_RESULT( rmdir, err );
662
663     diag_printf("<INFO>: rmdir x\n"); 
664     err = rmdir( "x" );
665     if( err < 0 ) SHOW_RESULT( rmdir, err );
666     
667     // --------------------------------------------------------------
668
669     checkcwd( "/disk2" );
670     
671     diag_printf("<INFO>: unlink tinky\n");    
672     err = unlink( "tinky" );
673     if( err < 0 ) SHOW_RESULT( unlink, err );
674
675     diag_printf("<INFO>: unlink laalaa\n");    
676     err = unlink( "laalaa" );
677     if( err < 0 ) SHOW_RESULT( unlink, err );
678
679     diag_printf("<INFO>: cd /\n");    
680     err = chdir( "/" );
681     if( err < 0 ) SHOW_RESULT( chdir, err );
682     checkcwd( "/" );
683
684     listdir( "/disk2", true, -1, NULL );
685     
686 #if 0
687     diag_printf("<INFO>: rmdir dir\n"); 
688     err = rmdir( "disk2" );
689     if( err < 0 ) SHOW_RESULT( rmdir, err );
690 #else
691     diag_printf("<INFO>: umount /disk2\n");    
692     err = umount( "/disk2" );
693     if( err < 0 ) SHOW_RESULT( umount, err );    
694 #endif
695     
696 #ifdef CYGCFG_FS_FAT_USE_ATTRIBUTES
697     // Create file
698     diag_printf("<INFO>: create /foo\n");
699     createfile( "/foo", 20257 );
700
701     // Verify it is created with archive bit set
702     checkattrib( "/foo", S_FATFS_ARCHIVE );
703
704     // Make it System
705     diag_printf("<INFO>: attrib -A+S /foo\n");
706     err = cyg_fs_set_attrib( "/foo", S_FATFS_SYSTEM );
707     if( err < 0 ) SHOW_RESULT( chmod system , err );
708
709     // Verify it is now System
710     checkattrib( "/foo", S_FATFS_SYSTEM );
711
712     // Make it Hidden
713     diag_printf("<INFO>: attrib -S+H /foo\n");
714     err = cyg_fs_set_attrib( "/foo", S_FATFS_HIDDEN );
715     if( err < 0 ) SHOW_RESULT( chmod system , err );
716
717     // Verify it is now Hidden
718     checkattrib( "/foo", S_FATFS_HIDDEN );
719
720     // Make it Read-only
721     diag_printf("<INFO>: attrib -H+R /foo\n");
722     err = cyg_fs_set_attrib( "/foo", S_FATFS_RDONLY );
723     if( err < 0 ) SHOW_RESULT( chmod system , err );
724
725     // Verify it is now Read-only
726     checkattrib( "/foo", S_FATFS_RDONLY );
727
728     // Verify we cannot unlink a read-only file
729     diag_printf("<INFO>: unlink /foo\n");
730     err = unlink( "/foo" );
731     if( (err != -1) || (errno != EPERM) ) SHOW_RESULT( unlink, err );
732
733     // Verify we cannot rename a read-only file
734     diag_printf("<INFO>: rename /foo bundy\n");
735     err = rename( "/foo", "bundy" );
736     if( (err != -1) || (errno != EPERM) ) SHOW_RESULT( rename, err );
737
738     // Verify we cannot open read-only file for writing
739     int fd;
740     diag_printf("<INFO>: create file /foo\n");
741     fd = open( "/foo", O_WRONLY );
742     if( (err != -1) || (errno != EACCES) ) SHOW_RESULT( open, err );
743     if( err > 0 ) close(fd);
744
745     // Make it Normal
746     diag_printf("<INFO>: attrib -H /foo\n");
747     err = cyg_fs_set_attrib( "/foo", 0 );
748     if( err < 0 ) SHOW_RESULT( chmod none , err );
749
750     // Verify it is now nothing
751     checkattrib( "/foo", 0 );
752
753     // Now delete our test file
754     diag_printf("<INFO>: unlink /foo\n");
755     err = unlink( "/foo" );
756     if( err < 0 ) SHOW_RESULT( unlink, err );
757
758 #endif // CYGCFG_FS_FAT_USE_ATTRIBUTES
759
760     maxfile("file.max");
761
762     listdir( "/", true, -1, NULL );    
763         
764     diag_printf("<INFO>: unlink file.max\n");    
765     err = unlink( "file.max" );
766     if( err < 0 ) SHOW_RESULT( unlink, err );    
767     diag_printf("<INFO>: umount /\n");    
768     err = umount( "/" );
769     if( err < 0 ) SHOW_RESULT( umount, err );    
770     
771     CYG_TEST_PASS_FINISH("fatfs1");
772 }
773
774 // -------------------------------------------------------------------------
775 // EOF fatfs1.c