OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [fs/] [fat/] [current/] [tests/] [fatfs1.c] - Blame information for rev 856

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.