]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/fs/fat/v2_0/tests/fatfs1.c
Initial revision
[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         if( statp )
133         {
134             char fullname[PATH_MAX];
135             struct stat sbuf;
136
137             if( name[0] )
138             {
139                 strcpy(fullname, name );
140                 if( !(name[0] == '/' && name[1] == 0 ) )
141                     strcat(fullname, "/" );
142             }
143             else fullname[0] = 0;
144             
145             strcat(fullname, entry->d_name );
146             
147             err = stat( fullname, &sbuf );
148             if( err < 0 )
149             {
150                 if( errno == ENOSYS )
151                     diag_printf(" <no status available>");
152                 else SHOW_RESULT( stat, err );
153             }
154             else
155             {
156                 diag_printf(" [mode %08x ino %08x nlink %d size %ld]",
157                             sbuf.st_mode,sbuf.st_ino,sbuf.st_nlink,(long)sbuf.st_size);
158             }
159         }
160
161         diag_printf("\n");
162     }
163
164     err = closedir( dirp );
165     if( err < 0 ) SHOW_RESULT( stat, err );
166     if (numexpected >= 0 && num != numexpected)
167         CYG_TEST_FAIL("Wrong number of dir entries\n");
168     if ( numgot != NULL )
169         *numgot = num;
170 }
171
172 //==========================================================================
173
174 static void createfile( char *name, size_t size )
175 {
176     char buf[IOSIZE];
177     int fd;
178     ssize_t wrote;
179     int i;
180     int err;
181
182     diag_printf("<INFO>: create file %s size %d\n",name,size);
183
184     err = access( name, F_OK );
185     if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err );
186     
187     for( i = 0; i < IOSIZE; i++ ) buf[i] = i%256;
188  
189     fd = open( name, O_WRONLY|O_CREAT );
190     if( fd < 0 ) SHOW_RESULT( open, fd );
191
192     while( size > 0 )
193     {
194         ssize_t len = size;
195         if ( len > IOSIZE ) len = IOSIZE;
196         
197         wrote = write( fd, buf, len );
198         if( wrote != len ) SHOW_RESULT( write, (int)wrote );        
199
200         size -= wrote;
201     }
202
203     err = close( fd );
204     if( err < 0 ) SHOW_RESULT( close, err );
205 }
206
207 //==========================================================================
208
209 static void maxfile( char *name )
210 {
211     char buf[IOSIZE];
212     int fd;
213     ssize_t wrote;
214     int i;
215     int err;
216     size_t size = 0;
217     size_t prevsize = 0;
218     
219     diag_printf("<INFO>: create maximal file %s\n",name);
220     diag_printf("<INFO>: This may take a few minutes\n");
221
222     err = access( name, F_OK );
223     if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err );
224     
225     for( i = 0; i < IOSIZE; i++ ) buf[i] = i%256;
226  
227     fd = open( name, O_WRONLY|O_CREAT );
228     if( fd < 0 ) SHOW_RESULT( open, fd );
229
230     do
231     {
232         wrote = write( fd, buf, IOSIZE );
233         //if( wrote < 0 ) SHOW_RESULT( write, wrote );        
234
235         if( wrote >= 0 )
236             size += wrote;
237
238         if( (size-prevsize) > 100000 )
239         {
240             diag_printf("<INFO>: size = %d \n", size);
241             prevsize = size;
242         }
243         
244     } while( wrote == IOSIZE );
245
246     diag_printf("<INFO>: file size == %d\n",size);
247
248     err = close( fd );
249     if( err < 0 ) SHOW_RESULT( close, err );
250 }
251
252 //==========================================================================
253
254 static void checkfile( char *name )
255 {
256     char buf[IOSIZE];
257     int fd;
258     ssize_t done;
259     int i;
260     int err;
261     off_t pos = 0;
262
263     diag_printf("<INFO>: check file %s\n",name);
264     
265     err = access( name, F_OK );
266     if( err != 0 ) SHOW_RESULT( access, err );
267
268     fd = open( name, O_RDONLY );
269     if( fd < 0 ) SHOW_RESULT( open, fd );
270
271     for(;;)
272     {
273         done = read( fd, buf, IOSIZE );
274         if( done < 0 ) SHOW_RESULT( read, (int)done );
275
276         if( done == 0 ) break;
277
278         for( i = 0; i < done; i++ )
279             if( buf[i] != i%256 )
280             {
281                 diag_printf("buf[%ld+%d](%02x) != %02x\n",pos,i,buf[i],i%256);
282                 CYG_TEST_FAIL("Data read not equal to data written\n");
283             }
284         
285         pos += done;
286     }
287
288     err = close( fd );
289     if( err < 0 ) SHOW_RESULT( close, err );
290 }
291
292 #ifdef CYGCFG_FS_FAT_USE_ATTRIBUTES
293 //==========================================================================
294
295 static void checkattrib(const char *name, 
296                         const cyg_fs_attrib_t test_attrib )
297 {
298     int err;
299     cyg_fs_attrib_t file_attrib;
300
301     diag_printf("<INFO>: check attrib %s\n",name);
302
303     err = cyg_fs_get_attrib(name, &file_attrib);
304     if( err != 0 ) SHOW_RESULT( stat, err );
305
306     if ( (file_attrib & S_FATFS_ATTRIB) != test_attrib )
307         diag_printf("<FAIL>: attrib %s incorrect\n\tExpected %x Was %x\n",
308                     name,test_attrib,(file_attrib & S_FATFS_ATTRIB));
309 }
310 #endif // CYGCFG_FS_FAT_USE_ATTRIBUTES
311
312 //==========================================================================
313
314 static void copyfile( char *name2, char *name1 )
315 {
316
317     int err;
318     char buf[IOSIZE];
319     int fd1, fd2;
320     ssize_t done, wrote;
321
322     diag_printf("<INFO>: copy file %s -> %s\n",name2,name1);
323
324     err = access( name1, F_OK );
325     if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err );
326
327     err = access( name2, F_OK );
328     if( err != 0 ) SHOW_RESULT( access, err );
329     
330     fd1 = open( name1, O_WRONLY|O_CREAT );
331     if( fd1 < 0 ) SHOW_RESULT( open, fd1 );
332
333     fd2 = open( name2, O_RDONLY );
334     if( fd2 < 0 ) SHOW_RESULT( open, fd2 );
335     
336     for(;;)
337     {
338         done = read( fd2, buf, IOSIZE );
339         if( done < 0 ) SHOW_RESULT( read, (int)done );
340
341         if( done == 0 ) break;
342
343         wrote = write( fd1, buf, done );
344         if( wrote != done ) SHOW_RESULT( write, (int) wrote );
345
346         if( wrote != done ) break;
347     }
348
349     err = close( fd1 );
350     if( err < 0 ) SHOW_RESULT( close, err );
351
352     err = close( fd2 );
353     if( err < 0 ) SHOW_RESULT( close, err );
354     
355 }
356
357 //==========================================================================
358
359 static void comparefiles( char *name2, char *name1 )
360 {
361     int err;
362     char buf1[IOSIZE];
363     char buf2[IOSIZE];
364     int fd1, fd2;
365     ssize_t done1, done2;
366     int i;
367
368     diag_printf("<INFO>: compare files %s == %s\n",name2,name1);
369
370     err = access( name1, F_OK );
371     if( err != 0 ) SHOW_RESULT( access, err );
372
373     err = access( name1, F_OK );
374     if( err != 0 ) SHOW_RESULT( access, err );
375     
376     fd1 = open( name1, O_RDONLY );
377     if( fd1 < 0 ) SHOW_RESULT( open, fd1 );
378
379     fd2 = open( name2, O_RDONLY );
380     if( fd2 < 0 ) SHOW_RESULT( open, fd2 );
381     
382     for(;;)
383     {
384         done1 = read( fd1, buf1, IOSIZE );
385         if( done1 < 0 ) SHOW_RESULT( read, (int)done1 );
386
387         done2 = read( fd2, buf2, IOSIZE );
388         if( done2 < 0 ) SHOW_RESULT( read, (int)done2 );
389
390         if( done1 != done2 )
391             diag_printf("Files different sizes\n");
392         
393         if( done1 == 0 ) break;
394
395         for( i = 0; i < done1; i++ )
396             if( buf1[i] != buf2[i] )
397             {
398                 diag_printf("buf1[%d](%02x) != buf1[%d](%02x)\n",i,buf1[i],i,buf2[i]);
399                 CYG_TEST_FAIL("Data in files not equal\n");
400             }
401     }
402
403     err = close( fd1 );
404     if( err < 0 ) SHOW_RESULT( close, err );
405
406     err = close( fd2 );
407     if( err < 0 ) SHOW_RESULT( close, err );
408     
409 }
410
411 //==========================================================================
412
413 void checkcwd( const char *cwd )
414 {
415     static char cwdbuf[PATH_MAX];
416     char *ret;
417
418     ret = getcwd( cwdbuf, sizeof(cwdbuf));
419     if( ret == NULL ) SHOW_RESULT( getcwd, (int)ret );    
420
421     if( strcmp( cwdbuf, cwd ) != 0 )
422     {
423         diag_printf( "cwdbuf %s cwd %s\n",cwdbuf, cwd );
424         CYG_TEST_FAIL( "Current directory mismatch");
425     }
426 }
427
428 //==========================================================================
429 // main
430
431 int main( int argc, char **argv )
432 {
433     int err;
434     int existingdirents=-1;
435
436     CYG_TEST_INIT();
437
438     // --------------------------------------------------------------
439
440     err = mount( "/dev/disk0/1", "/", "fatfs" );    
441     if( err < 0 ) SHOW_RESULT( mount, err );    
442
443     err = chdir( "/" );
444     if( err < 0 ) SHOW_RESULT( chdir, err );
445
446     checkcwd( "/" );
447     
448     listdir( "/", true, -1, &existingdirents );
449
450     // --------------------------------------------------------------
451
452     createfile( "/foo", 20257 );
453     checkfile( "foo" );
454     copyfile( "foo", "fee");
455     checkfile( "fee" );
456     comparefiles( "foo", "/fee" );
457     diag_printf("<INFO>: mkdir bar\n");
458     err = mkdir( "/bar", 0 );
459     if( err < 0 ) SHOW_RESULT( mkdir, err );
460
461     listdir( "/" , true, existingdirents+3, NULL );
462
463     copyfile( "fee", "/bar/fum" );
464     checkfile( "bar/fum" );
465     comparefiles( "/fee", "bar/fum" );
466
467     diag_printf("<INFO>: cd bar\n");
468     err = chdir( "bar" );
469     if( err < 0 ) SHOW_RESULT( chdir, err );
470
471     checkcwd( "/bar" );
472     
473     diag_printf("<INFO>: rename /foo bundy\n");    
474     err = rename( "/foo", "bundy" );
475     if( err < 0 ) SHOW_RESULT( rename, err );
476     
477     listdir( "/", true, existingdirents+2, NULL );
478     listdir( "" , true, 4, NULL );
479
480     checkfile( "/bar/bundy" );
481     comparefiles("/fee", "bundy" );
482
483     // --------------------------------------------------------------
484
485     diag_printf("<INFO>: unlink fee\n");    
486     err = unlink( "/fee" );
487     if( err < 0 ) SHOW_RESULT( unlink, err );
488
489     diag_printf("<INFO>: unlink fum\n");        
490     err = unlink( "fum" );
491     if( err < 0 ) SHOW_RESULT( unlink, err );
492
493     diag_printf("<INFO>: unlink /bar/bundy\n");        
494     err = unlink( "/bar/bundy" );
495     if( err < 0 ) SHOW_RESULT( unlink, err );
496
497     diag_printf("<INFO>: cd /\n");        
498     err = chdir( "/" );
499     if( err < 0 ) SHOW_RESULT( chdir, err );
500
501     checkcwd( "/" );
502     
503     diag_printf("<INFO>: rmdir /bar\n");        
504     err = rmdir( "/bar" );
505     if( err < 0 ) SHOW_RESULT( rmdir, err );
506     
507     listdir( "/", false, existingdirents, NULL );
508
509     // --------------------------------------------------------------
510
511 #if 0
512     diag_printf("<INFO>: mkdir disk2\n");
513     err = mkdir( "/disk2", 0 );
514     if( err < 0 ) SHOW_RESULT( mkdir, err );
515 #else
516     diag_printf("<INFO>: mount /disk2\n");    
517     err = mount( "/dev/disk0/2", "/disk2", "fatfs" );    
518     if( err < 0 ) SHOW_RESULT( mount, err );    
519 #endif
520     
521     listdir( "/disk2" , true, -1, &existingdirents);
522         
523     createfile( "/disk2/tinky", 4567 );
524     copyfile( "/disk2/tinky", "/disk2/laalaa" );
525     checkfile( "/disk2/tinky");
526     checkfile( "/disk2/laalaa");
527     comparefiles( "/disk2/tinky", "/disk2/laalaa" );
528
529     diag_printf("<INFO>: cd /disk2\n");    
530     err = chdir( "/disk2" );
531     if( err < 0 ) SHOW_RESULT( chdir, err );
532
533     checkcwd( "/disk2" );
534         
535     diag_printf("<INFO>: mkdir noonoo\n");    
536     err = mkdir( "noonoo", 0 );
537     if( err < 0 ) SHOW_RESULT( mkdir, err );
538
539     listdir( "/disk2" , true, existingdirents+3, NULL);
540
541     diag_printf("<INFO>: cd noonoo\n");
542     err = chdir( "noonoo" );
543     if( err < 0 ) SHOW_RESULT( chdir, err );
544
545     checkcwd( "/disk2/noonoo" );
546     
547     createfile( "tinky", 6789 );
548     checkfile( "tinky" );
549
550     createfile( "dipsy", 34567 );
551     checkfile( "dipsy" );
552     copyfile( "dipsy", "po" );
553     checkfile( "po" );
554     comparefiles( "dipsy", "po" );
555
556     listdir( ".", true, 5, NULL );
557     listdir( "", true, 5, NULL );
558     listdir( "..", true, existingdirents+3, NULL );
559
560     // --------------------------------------------------------------
561
562     diag_printf("<INFO>: unlink tinky\n");    
563     err = unlink( "tinky" );
564     if( err < 0 ) SHOW_RESULT( unlink, err );
565
566     diag_printf("<INFO>: unlink dipsy\n");    
567     err = unlink( "dipsy" );
568     if( err < 0 ) SHOW_RESULT( unlink, err );
569
570     diag_printf("<INFO>: unlink po\n");    
571     err = unlink( "po" );
572     if( err < 0 ) SHOW_RESULT( unlink, err );
573
574     diag_printf("<INFO>: cd ..\n"); 
575     err = chdir( ".." );
576     if( err < 0 ) SHOW_RESULT( chdir, err );
577     checkcwd( "/disk2" );
578     
579     diag_printf("<INFO>: rmdir noonoo\n"); 
580     err = rmdir( "noonoo" );
581     if( err < 0 ) SHOW_RESULT( rmdir, err );
582
583     // --------------------------------------------------------------
584
585     err = mkdir( "x", 0 );
586     if( err < 0 ) SHOW_RESULT( mkdir, err );
587     
588     err = mkdir( "x/y", 0 );
589     if( err < 0 ) SHOW_RESULT( mkdir, err );
590     
591     err = mkdir( "x/y/z", 0 );
592     if( err < 0 ) SHOW_RESULT( mkdir, err );
593
594     err = mkdir( "x/y/z/w", 0 );
595     if( err < 0 ) SHOW_RESULT( mkdir, err );
596     
597     diag_printf("<INFO>: cd /disk2/x/y/z/w\n");
598     err = chdir( "/disk2/x/y/z/w" );
599     if( err < 0 ) SHOW_RESULT( chdir, err );
600     checkcwd( "/disk2/x/y/z/w" );
601
602     diag_printf("<INFO>: cd ..\n");
603     err = chdir( ".." );
604     if( err < 0 ) SHOW_RESULT( chdir, err );
605     checkcwd( "/disk2/x/y/z" );
606     
607     diag_printf("<INFO>: cd .\n");
608     err = chdir( "." );
609     if( err < 0 ) SHOW_RESULT( chdir, err );
610     checkcwd( "/disk2/x/y/z" );
611
612     diag_printf("<INFO>: cd ../../y\n");
613     err = chdir( "../../y" );
614     if( err < 0 ) SHOW_RESULT( chdir, err );
615     checkcwd( "/disk2/x/y" );
616
617     diag_printf("<INFO>: cd ../..\n");
618     err = chdir( "../.." );
619     if( err < 0 ) SHOW_RESULT( chdir, err );
620     checkcwd( "/disk2" );
621
622     diag_printf("<INFO>: rmdir x/y/z/w\n"); 
623     err = rmdir( "x/y/z/w" );
624     if( err < 0 ) SHOW_RESULT( rmdir, err );
625
626     diag_printf("<INFO>: rmdir x/y/z\n"); 
627     err = rmdir( "x/y/z" );
628     if( err < 0 ) SHOW_RESULT( rmdir, err );
629
630     diag_printf("<INFO>: rmdir x/y\n"); 
631     err = rmdir( "x/y" );
632     if( err < 0 ) SHOW_RESULT( rmdir, err );
633
634     diag_printf("<INFO>: rmdir x\n"); 
635     err = rmdir( "x" );
636     if( err < 0 ) SHOW_RESULT( rmdir, err );
637     
638     // --------------------------------------------------------------
639
640     checkcwd( "/disk2" );
641     
642     diag_printf("<INFO>: unlink tinky\n");    
643     err = unlink( "tinky" );
644     if( err < 0 ) SHOW_RESULT( unlink, err );
645
646     diag_printf("<INFO>: unlink laalaa\n");    
647     err = unlink( "laalaa" );
648     if( err < 0 ) SHOW_RESULT( unlink, err );
649
650     diag_printf("<INFO>: cd /\n");    
651     err = chdir( "/" );
652     if( err < 0 ) SHOW_RESULT( chdir, err );
653     checkcwd( "/" );
654
655     listdir( "/disk2", true, -1, NULL );
656     
657 #if 0
658     diag_printf("<INFO>: rmdir dir\n"); 
659     err = rmdir( "disk2" );
660     if( err < 0 ) SHOW_RESULT( rmdir, err );
661 #else
662     diag_printf("<INFO>: umount /disk2\n");    
663     err = umount( "/disk2" );
664     if( err < 0 ) SHOW_RESULT( umount, err );    
665 #endif
666     
667 #ifdef CYGCFG_FS_FAT_USE_ATTRIBUTES
668     // Create file
669     diag_printf("<INFO>: create /foo\n");
670     createfile( "/foo", 20257 );
671
672     // Verify it is created with archive bit set
673     checkattrib( "/foo", S_FATFS_ARCHIVE );
674
675     // Make it System
676     diag_printf("<INFO>: attrib -A+S /foo\n");
677     err = cyg_fs_set_attrib( "/foo", S_FATFS_SYSTEM );
678     if( err < 0 ) SHOW_RESULT( chmod system , err );
679
680     // Verify it is now System
681     checkattrib( "/foo", S_FATFS_SYSTEM );
682
683     // Make it Hidden
684     diag_printf("<INFO>: attrib -S+H /foo\n");
685     err = cyg_fs_set_attrib( "/foo", S_FATFS_HIDDEN );
686     if( err < 0 ) SHOW_RESULT( chmod system , err );
687
688     // Verify it is now Hidden
689     checkattrib( "/foo", S_FATFS_HIDDEN );
690
691     // Make it Read-only
692     diag_printf("<INFO>: attrib -H+R /foo\n");
693     err = cyg_fs_set_attrib( "/foo", S_FATFS_RDONLY );
694     if( err < 0 ) SHOW_RESULT( chmod system , err );
695
696     // Verify it is now Read-only
697     checkattrib( "/foo", S_FATFS_RDONLY );
698
699     // Verify we cannot unlink a read-only file
700     diag_printf("<INFO>: unlink /foo\n");
701     err = unlink( "/foo" );
702     if( (err != -1) || (errno != EPERM) ) SHOW_RESULT( unlink, err );
703
704     // Verify we cannot rename a read-only file
705     diag_printf("<INFO>: rename /foo bundy\n");
706     err = rename( "/foo", "bundy" );
707     if( (err != -1) || (errno != EPERM) ) SHOW_RESULT( rename, err );
708
709     // Verify we cannot open read-only file for writing
710     int fd;
711     diag_printf("<INFO>: create file /foo\n");
712     fd = open( "/foo", O_WRONLY );
713     if( (err != -1) || (errno != EACCES) ) SHOW_RESULT( open, err );
714     if( err > 0 ) close(fd);
715
716     // Make it Normal
717     diag_printf("<INFO>: attrib -H /foo\n");
718     err = cyg_fs_set_attrib( "/foo", 0 );
719     if( err < 0 ) SHOW_RESULT( chmod none , err );
720
721     // Verify it is now nothing
722     checkattrib( "/foo", 0 );
723
724     // Now delete our test file
725     diag_printf("<INFO>: unlink /foo\n");
726     err = unlink( "/foo" );
727     if( err < 0 ) SHOW_RESULT( unlink, err );
728
729 #endif // CYGCFG_FS_FAT_USE_ATTRIBUTES
730
731     maxfile("file.max");
732
733     listdir( "/", true, -1, NULL );    
734         
735     diag_printf("<INFO>: unlink file.max\n");    
736     err = unlink( "file.max" );
737     if( err < 0 ) SHOW_RESULT( unlink, err );    
738     diag_printf("<INFO>: umount /\n");    
739     err = umount( "/" );
740     if( err < 0 ) SHOW_RESULT( umount, err );    
741     
742     CYG_TEST_PASS_FINISH("fatfs1");
743 }
744
745 // -------------------------------------------------------------------------
746 // EOF fatfs1.c