|
428
|
1 //========================================================================== |
|
|
2 // |
|
|
3 // yaffs1.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, 2006, 2007 Free Software Foundation, Inc. |
|
|
12 // Copyright (C) 2004, 2006, 2007 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 |
|
|
17 // version. |
|
|
18 // |
|
|
19 // eCos is distributed in the hope that it will be useful, but WITHOUT |
|
|
20 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
|
21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
|
22 // for more details. |
|
|
23 // |
|
|
24 // You should have received a copy of the GNU General Public License |
|
|
25 // along with eCos; if not, write to the Free Software Foundation, Inc., |
|
|
26 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
|
27 // |
|
|
28 // As a special exception, if other files instantiate templates or use |
|
|
29 // macros or inline functions from this file, or you compile this file |
|
|
30 // and link it with other works to produce a work based on this file, |
|
|
31 // this file does not by itself cause the resulting work to be covered by |
|
|
32 // the GNU General Public License. However the source code for this file |
|
|
33 // must still be made available in accordance with section (3) of the GNU |
|
|
34 // General Public License v2. |
|
|
35 // |
|
|
36 // This exception does not invalidate any other reasons why a work based |
|
|
37 // on this file might be covered by the GNU General Public License. |
|
|
38 // ------------------------------------------- |
|
|
39 // ####ECOSGPLCOPYRIGHTEND#### |
|
|
40 //========================================================================== |
|
|
41 //#####DESCRIPTIONBEGIN#### |
|
|
42 // |
|
|
43 // Author(s): nickg |
|
|
44 // Contributors: nickg |
|
|
45 // Date: 2000-05-25 |
|
|
46 // Purpose: Test fileio system |
|
|
47 // Description: This test uses the testfs to check out the initialization |
|
|
48 // and basic operation of the fileio system |
|
|
49 // |
|
|
50 // |
|
|
51 // |
|
|
52 // |
|
|
53 // |
|
|
54 // |
|
|
55 // |
|
|
56 //####DESCRIPTIONEND#### |
|
|
57 // |
|
|
58 //========================================================================== |
|
|
59 |
|
|
60 #include <pkgconf/system.h> |
|
|
61 |
|
|
62 #ifdef CYGPKG_KERNEL |
|
|
63 |
|
|
64 #include <pkgconf/hal.h> |
|
|
65 #include <pkgconf/kernel.h> |
|
|
66 #include <pkgconf/io_fileio.h> |
|
|
67 |
|
|
68 #include CYGDAT_DEVS_DISK_CFG // testing config defines |
|
|
69 |
|
|
70 #include <cyg/kernel/ktypes.h> // base kernel types |
|
|
71 #include <cyg/infra/cyg_trac.h> // tracing macros |
|
|
72 #include <cyg/infra/cyg_ass.h> // assertion macros |
|
|
73 |
|
|
74 #include <unistd.h> |
|
|
75 #include <fcntl.h> |
|
|
76 #include <sys/stat.h> |
|
|
77 #include <errno.h> |
|
|
78 #include <string.h> |
|
|
79 #include <dirent.h> |
|
|
80 |
|
|
81 #include <cyg/fileio/fileio.h> |
|
|
82 |
|
|
83 #include <cyg/infra/testcase.h> |
|
|
84 #include <cyg/infra/diag.h> // HAL polled output |
|
|
85 |
|
|
86 //========================================================================== |
|
|
87 // Config options |
|
|
88 |
|
|
89 #define TEST_DEVICE CYGDAT_DEVS_DISK_TEST_DEVICE |
|
|
90 |
|
|
91 #define TEST_MOUNTPOINT CYGDAT_DEVS_DISK_TEST_MOUNTPOINT |
|
|
92 |
|
|
93 #define TEST_DIRECTORY CYGDAT_DEVS_DISK_TEST_DIRECTORY |
|
|
94 |
|
|
95 #define TEST_FSTYPE "yaffs" |
|
|
96 |
|
|
97 #ifdef CYGDAT_DEVS_DISK_TEST_MOUNTPOINT2 |
|
|
98 |
|
|
99 #define TEST_DEVICE2 CYGDAT_DEVS_DISK_TEST_DEVICE2 |
|
|
100 |
|
|
101 #define TEST_MOUNTPOINT2 CYGDAT_DEVS_DISK_TEST_MOUNTPOINT2 |
|
|
102 |
|
|
103 #define TEST_DIRECTORY2 CYGDAT_DEVS_DISK_TEST_DIRECTORY2 |
|
|
104 |
|
|
105 #define TEST_FSTYPE2 "yaffs" |
|
|
106 |
|
|
107 #endif |
|
|
108 |
|
|
109 //========================================================================== |
|
|
110 |
|
|
111 #define SHOW_RESULT( _fn, _res ) \ |
|
|
112 { \ |
|
|
113 diag_printf("<FAIL>: " #_fn "() returned %ld %s\n", (long)_res, _res<0?strerror(errno):""); \ |
|
|
114 } |
|
|
115 |
|
|
116 //========================================================================== |
|
|
117 |
|
|
118 #define IOSIZE 100 |
|
|
119 |
|
|
120 #define LONGNAME1 "long_file_name_that_should_take_up_more_than_one_directory_entry_1" |
|
|
121 #define LONGNAME2 "long_file_name_that_should_take_up_more_than_one_directory_entry_2" |
|
|
122 |
|
|
123 |
|
|
124 //========================================================================== |
|
|
125 |
|
|
126 #ifndef CYGPKG_LIBC_STRING |
|
|
127 |
|
|
128 char *strcat( char *s1, const char *s2 ) |
|
|
129 { |
|
|
130 char *s = s1; |
|
|
131 while( *s1 ) s1++; |
|
|
132 while( (*s1++ = *s2++) != 0); |
|
|
133 return s; |
|
|
134 } |
|
|
135 |
|
|
136 #endif |
|
|
137 |
|
|
138 __externC int |
|
|
139 rename( const char * /* oldpath */, const char * /* newpath */ ) __THROW; |
|
|
140 |
|
|
141 //========================================================================== |
|
|
142 |
|
|
143 static void listdir( char *name, int statp, int numexpected, int *numgot ) |
|
|
144 { |
|
|
145 int err; |
|
|
146 DIR *dirp; |
|
|
147 int num=0; |
|
|
148 |
|
|
149 diag_printf("<INFO>: reading directory %s\n",name); |
|
|
150 |
|
|
151 // diag_printf("<INFO>: opendir(%s)\n",name); |
|
|
152 dirp = opendir( name ); |
|
|
153 if( dirp == NULL ) SHOW_RESULT( opendir, -1 ); |
|
|
154 |
|
|
155 for(;;) |
|
|
156 { |
|
|
157 struct dirent *entry = readdir( dirp ); |
|
|
158 |
|
|
159 if( entry == NULL ) |
|
|
160 break; |
|
|
161 num++; |
|
|
162 diag_printf("<INFO>: entry %14s",entry->d_name); |
|
|
163 #ifdef CYGPKG_FS_FAT_RET_DIRENT_DTYPE |
|
|
164 diag_printf(" d_type %2x", entry->d_type); |
|
|
165 #endif |
|
|
166 if( statp ) |
|
|
167 { |
|
|
168 char fullname[PATH_MAX]; |
|
|
169 struct stat sbuf; |
|
|
170 |
|
|
171 if( name[0] ) |
|
|
172 { |
|
|
173 strcpy(fullname, name ); |
|
|
174 if( !(name[0] == '/' && name[1] == 0 ) ) |
|
|
175 strcat(fullname, "/" ); |
|
|
176 } |
|
|
177 else fullname[0] = 0; |
|
|
178 |
|
|
179 strcat(fullname, entry->d_name ); |
|
|
180 |
|
|
181 err = stat( fullname, &sbuf ); |
|
|
182 if( err < 0 ) |
|
|
183 { |
|
|
184 if( errno == ENOSYS ) |
|
|
185 diag_printf(" <no status available>"); |
|
|
186 else SHOW_RESULT( stat, err ); |
|
|
187 } |
|
|
188 else |
|
|
189 { |
|
|
190 diag_printf(" [mode %08x ino %08x nlink %d size %ld]", |
|
|
191 sbuf.st_mode,sbuf.st_ino,sbuf.st_nlink,sbuf.st_size); |
|
|
192 } |
|
|
193 #ifdef CYGPKG_FS_FAT_RET_DIRENT_DTYPE |
|
|
194 if ((entry->d_type & S_IFMT) != (sbuf.st_mode & S_IFMT)) |
|
|
195 CYG_TEST_FAIL("File mode's don't match between dirent and stat"); |
|
|
196 #endif |
|
|
197 } |
|
|
198 |
|
|
199 diag_printf("\n"); |
|
|
200 } |
|
|
201 |
|
|
202 // diag_printf("<INFO>: closedir(%s)\n",name); |
|
|
203 err = closedir( dirp ); |
|
|
204 if( err < 0 ) SHOW_RESULT( stat, err ); |
|
|
205 if (numexpected >= 0 && num != numexpected) |
|
|
206 CYG_TEST_FAIL("Wrong number of dir entries\n"); |
|
|
207 if ( numgot != NULL ) |
|
|
208 *numgot = num; |
|
|
209 } |
|
|
210 |
|
|
211 //========================================================================== |
|
|
212 |
|
|
213 static void createfile( char *name, size_t size ) |
|
|
214 { |
|
|
215 char buf[IOSIZE]; |
|
|
216 int fd; |
|
|
217 ssize_t wrote; |
|
|
218 int i; |
|
|
219 int err; |
|
|
220 |
|
|
221 diag_printf("<INFO>: create file %s size %zd\n",name,size); |
|
|
222 |
|
|
223 err = access( name, F_OK ); |
|
|
224 if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); |
|
|
225 |
|
|
226 for( i = 0; i < IOSIZE; i++ ) buf[i] = i%256; |
|
|
227 |
|
|
228 fd = open( name, O_WRONLY|O_CREAT ); |
|
|
229 if( fd < 0 ) SHOW_RESULT( open, fd ); |
|
|
230 |
|
|
231 while( size > 0 ) |
|
|
232 { |
|
|
233 ssize_t len = size; |
|
|
234 if ( len > IOSIZE ) len = IOSIZE; |
|
|
235 |
|
|
236 wrote = write( fd, buf, len ); |
|
|
237 if( wrote != len ) SHOW_RESULT( write, wrote ); |
|
|
238 |
|
|
239 size -= wrote; |
|
|
240 } |
|
|
241 |
|
|
242 err = close( fd ); |
|
|
243 if( err < 0 ) SHOW_RESULT( close, err ); |
|
|
244 } |
|
|
245 |
|
|
246 //========================================================================== |
|
|
247 |
|
|
248 #if 0 |
|
|
249 static void maxfile( char *name ) |
|
|
250 { |
|
|
251 char buf[IOSIZE]; |
|
|
252 int fd; |
|
|
253 ssize_t wrote; |
|
|
254 int i; |
|
|
255 int err; |
|
|
256 size_t size = 0; |
|
|
257 size_t prevsize = 0; |
|
|
258 |
|
|
259 diag_printf("<INFO>: create maximal file %s\n",name); |
|
|
260 diag_printf("<INFO>: This may take a few minutes\n"); |
|
|
261 |
|
|
262 err = access( name, F_OK ); |
|
|
263 if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); |
|
|
264 |
|
|
265 for( i = 0; i < IOSIZE; i++ ) buf[i] = i%256; |
|
|
266 |
|
|
267 fd = open( name, O_WRONLY|O_CREAT ); |
|
|
268 if( fd < 0 ) SHOW_RESULT( open, fd ); |
|
|
269 |
|
|
270 do |
|
|
271 { |
|
|
272 wrote = write( fd, buf, IOSIZE ); |
|
|
273 //if( wrote < 0 ) SHOW_RESULT( write, wrote ); |
|
|
274 |
|
|
275 if( wrote >= 0 ) |
|
|
276 size += wrote; |
|
|
277 |
|
|
278 if( (size-prevsize) > 100000 ) |
|
|
279 { |
|
|
280 diag_printf("<INFO>: size = %zd\n", size); |
|
|
281 prevsize = size; |
|
|
282 } |
|
|
283 |
|
|
284 } while( wrote == IOSIZE ); |
|
|
285 |
|
|
286 diag_printf("<INFO>: file size == %zd\n",size); |
|
|
287 |
|
|
288 err = close( fd ); |
|
|
289 if( err < 0 ) SHOW_RESULT( close, err ); |
|
|
290 } |
|
|
291 #endif |
|
|
292 |
|
|
293 //========================================================================== |
|
|
294 |
|
|
295 static void checkfile( char *name ) |
|
|
296 { |
|
|
297 char buf[IOSIZE]; |
|
|
298 int fd; |
|
|
299 ssize_t done; |
|
|
300 int i; |
|
|
301 int err; |
|
|
302 off_t pos = 0; |
|
|
303 |
|
|
304 diag_printf("<INFO>: check file %s\n",name); |
|
|
305 |
|
|
306 err = access( name, F_OK ); |
|
|
307 if( err != 0 ) SHOW_RESULT( access, err ); |
|
|
308 |
|
|
309 fd = open( name, O_RDONLY ); |
|
|
310 if( fd < 0 ) SHOW_RESULT( open, fd ); |
|
|
311 |
|
|
312 for(;;) |
|
|
313 { |
|
|
314 done = read( fd, buf, IOSIZE ); |
|
|
315 if( done < 0 ) SHOW_RESULT( read, done ); |
|
|
316 |
|
|
317 if( done == 0 ) break; |
|
|
318 |
|
|
319 for( i = 0; i < done; i++ ) |
|
|
320 if( buf[i] != i%256 ) |
|
|
321 { |
|
|
322 diag_printf("buf[%ld+%d](%02x) != %02x\n",pos,i,buf[i],i%256); |
|
|
323 CYG_TEST_FAIL("Data read not equal to data written\n"); |
|
|
324 for(;;); |
|
|
325 } |
|
|
326 |
|
|
327 pos += done; |
|
|
328 } |
|
|
329 |
|
|
330 err = close( fd ); |
|
|
331 if( err < 0 ) SHOW_RESULT( close, err ); |
|
|
332 } |
|
|
333 |
|
|
334 //========================================================================== |
|
|
335 |
|
|
336 static void copyfile( char *name2, char *name1 ) |
|
|
337 { |
|
|
338 |
|
|
339 int err; |
|
|
340 char buf[IOSIZE]; |
|
|
341 int fd1, fd2; |
|
|
342 ssize_t done, wrote; |
|
|
343 |
|
|
344 diag_printf("<INFO>: copy file %s -> %s\n",name2,name1); |
|
|
345 |
|
|
346 err = access( name1, F_OK ); |
|
|
347 if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); |
|
|
348 |
|
|
349 err = access( name2, F_OK ); |
|
|
350 if( err != 0 ) SHOW_RESULT( access, err ); |
|
|
351 |
|
|
352 fd1 = open( name1, O_WRONLY|O_CREAT ); |
|
|
353 if( fd1 < 0 ) SHOW_RESULT( open, fd1 ); |
|
|
354 |
|
|
355 fd2 = open( name2, O_RDONLY ); |
|
|
356 if( fd2 < 0 ) SHOW_RESULT( open, fd2 ); |
|
|
357 |
|
|
358 for(;;) |
|
|
359 { |
|
|
360 done = read( fd2, buf, IOSIZE ); |
|
|
361 if( done < 0 ) SHOW_RESULT( read, done ); |
|
|
362 |
|
|
363 if( done == 0 ) break; |
|
|
364 |
|
|
365 wrote = write( fd1, buf, done ); |
|
|
366 if( wrote != done ) SHOW_RESULT( write, wrote ); |
|
|
367 |
|
|
368 if( wrote != done ) break; |
|
|
369 } |
|
|
370 |
|
|
371 err = close( fd1 ); |
|
|
372 if( err < 0 ) SHOW_RESULT( close, err ); |
|
|
373 |
|
|
374 err = close( fd2 ); |
|
|
375 if( err < 0 ) SHOW_RESULT( close, err ); |
|
|
376 |
|
|
377 } |
|
|
378 |
|
|
379 //========================================================================== |
|
|
380 |
|
|
381 static void comparefiles( char *name2, char *name1 ) |
|
|
382 { |
|
|
383 int err; |
|
|
384 char buf1[IOSIZE]; |
|
|
385 char buf2[IOSIZE]; |
|
|
386 int fd1, fd2; |
|
|
387 ssize_t done1, done2; |
|
|
388 int i; |
|
|
389 |
|
|
390 diag_printf("<INFO>: compare files %s == %s\n",name2,name1); |
|
|
391 |
|
|
392 err = access( name1, F_OK ); |
|
|
393 if( err != 0 ) SHOW_RESULT( access, err ); |
|
|
394 |
|
|
395 err = access( name1, F_OK ); |
|
|
396 if( err != 0 ) SHOW_RESULT( access, err ); |
|
|
397 |
|
|
398 fd1 = open( name1, O_RDONLY ); |
|
|
399 if( fd1 < 0 ) SHOW_RESULT( open, fd1 ); |
|
|
400 |
|
|
401 fd2 = open( name2, O_RDONLY ); |
|
|
402 if( fd2 < 0 ) SHOW_RESULT( open, fd2 ); |
|
|
403 |
|
|
404 for(;;) |
|
|
405 { |
|
|
406 done1 = read( fd1, buf1, IOSIZE ); |
|
|
407 if( done1 < 0 ) SHOW_RESULT( read, done1 ); |
|
|
408 |
|
|
409 done2 = read( fd2, buf2, IOSIZE ); |
|
|
410 if( done2 < 0 ) SHOW_RESULT( read, done2 ); |
|
|
411 |
|
|
412 if( done1 != done2 ) |
|
|
413 diag_printf("Files different sizes\n"); |
|
|
414 |
|
|
415 if( done1 == 0 ) break; |
|
|
416 |
|
|
417 for( i = 0; i < done1; i++ ) |
|
|
418 if( buf1[i] != buf2[i] ) |
|
|
419 { |
|
|
420 diag_printf("buf1[%d](%02x) != buf1[%d](%02x)\n",i,buf1[i],i,buf2[i]); |
|
|
421 CYG_TEST_FAIL("Data in files not equal\n"); |
|
|
422 } |
|
|
423 } |
|
|
424 |
|
|
425 err = close( fd1 ); |
|
|
426 if( err < 0 ) SHOW_RESULT( close, err ); |
|
|
427 |
|
|
428 err = close( fd2 ); |
|
|
429 if( err < 0 ) SHOW_RESULT( close, err ); |
|
|
430 |
|
|
431 } |
|
|
432 |
|
|
433 //========================================================================== |
|
|
434 |
|
|
435 void checkcwd( const char *cwd ) |
|
|
436 { |
|
|
437 static char cwdbuf[PATH_MAX]; |
|
|
438 char *ret; |
|
|
439 |
|
|
440 ret = getcwd( cwdbuf, sizeof(cwdbuf)); |
|
|
441 if( ret == NULL ) SHOW_RESULT( getcwd, ret ); |
|
|
442 |
|
|
443 if( strcmp( cwdbuf, cwd ) != 0 ) |
|
|
444 { |
|
|
445 diag_printf( "cwdbuf %s cwd %s\n",cwdbuf, cwd ); |
|
|
446 CYG_TEST_FAIL( "Current directory mismatch"); |
|
|
447 } |
|
|
448 } |
|
|
449 |
|
|
450 //========================================================================== |
|
|
451 // main |
|
|
452 |
|
|
453 void fileio1_main( CYG_ADDRESS id ) |
|
|
454 { |
|
|
455 int err; |
|
|
456 int existingdirents=-1; |
|
|
457 cyg_bool mp2 = false; |
|
|
458 int fd; |
|
|
459 #if defined(CYGSEM_FILEIO_BLOCK_USAGE) |
|
|
460 struct cyg_fs_block_usage usage; |
|
|
461 #endif |
|
|
462 |
|
|
463 char dirname[64]; |
|
|
464 char filename1[64]; |
|
|
465 char filename2[64]; |
|
|
466 |
|
|
467 #define NEW_FILENAME( fn, f ) \ |
|
|
468 { \ |
|
|
469 fn[0]=0; \ |
|
|
470 strcat(fn, dirname); \ |
|
|
471 strcat(fn, "/"); \ |
|
|
472 strcat(fn,f); \ |
|
|
473 } |
|
|
474 |
|
|
475 #define NEW_FILENAME1( f ) NEW_FILENAME( filename1, f ) |
|
|
476 #define NEW_FILENAME2( f ) NEW_FILENAME( filename2, f ) |
|
|
477 |
|
|
478 CYG_TEST_INIT(); |
|
|
479 |
|
|
480 // -------------------------------------------------------------- |
|
|
481 |
|
|
482 err = mount( TEST_DEVICE, TEST_MOUNTPOINT, TEST_FSTYPE ); |
|
|
483 if( err < 0 ) { |
|
|
484 SHOW_RESULT( mount, err ); |
|
|
485 CYG_TEST_FAIL_FINISH("yaffs1"); |
|
|
486 } |
|
|
487 |
|
|
488 err = access( TEST_MOUNTPOINT TEST_DIRECTORY, F_OK ); |
|
|
489 if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); |
|
|
490 |
|
|
491 if( err < 0 && errno == EACCES ) |
|
|
492 { |
|
|
493 diag_printf("<INFO>: create %s\n", |
|
|
494 TEST_MOUNTPOINT TEST_DIRECTORY); |
|
|
495 err = mkdir( TEST_MOUNTPOINT TEST_DIRECTORY, 0 ); |
|
|
496 if( err < 0 ) SHOW_RESULT( mkdir, err ); |
|
|
497 } |
|
|
498 |
|
|
499 err = chdir( TEST_MOUNTPOINT TEST_DIRECTORY ); |
|
|
500 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
501 |
|
|
502 checkcwd( TEST_MOUNTPOINT TEST_DIRECTORY ); |
|
|
503 |
|
|
504 listdir( TEST_MOUNTPOINT TEST_DIRECTORY, true, -1, &existingdirents ); |
|
|
505 |
|
|
506 // -------------------------------------------------------------- |
|
|
507 #if defined(CYGSEM_FILEIO_BLOCK_USAGE) |
|
|
508 err = cyg_fs_getinfo(TEST_MOUNTPOINT, FS_INFO_BLOCK_USAGE, |
|
|
509 &usage, sizeof(usage)); |
|
|
510 if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err ); |
|
|
511 diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n", |
|
|
512 usage.total_blocks, usage.total_blocks * usage.block_size); |
|
|
513 diag_printf("<INFO>: free size: %6lld blocks, %10lld bytes\n", |
|
|
514 usage.free_blocks, usage.free_blocks * usage.block_size); |
|
|
515 diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size); |
|
|
516 #endif |
|
|
517 // -------------------------------------------------------------- |
|
|
518 |
|
|
519 dirname[0] = 0; |
|
|
520 strcat(dirname, TEST_MOUNTPOINT ); |
|
|
521 strcat(dirname, TEST_DIRECTORY ); |
|
|
522 |
|
|
523 // -------------------------------------------------------------- |
|
|
524 |
|
|
525 createfile( "foo", 20257 ); |
|
|
526 checkfile( "foo" ); |
|
|
527 copyfile( "foo", "fee"); |
|
|
528 checkfile( "fee" ); |
|
|
529 comparefiles( "foo", "fee" ); |
|
|
530 diag_printf("<INFO>: mkdir bar\n"); |
|
|
531 err = mkdir( "bar", 0 ); |
|
|
532 if( err < 0 ) SHOW_RESULT( mkdir, err ); |
|
|
533 |
|
|
534 listdir( dirname , true, existingdirents+3, NULL ); |
|
|
535 |
|
|
536 copyfile( "fee", "bar/fum" ); |
|
|
537 checkfile( "bar/fum" ); |
|
|
538 comparefiles( "fee", "bar/fum" ); |
|
|
539 diag_printf("<INFO>: cd bar\n"); |
|
|
540 err = chdir( "bar" ); |
|
|
541 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
542 |
|
|
543 // Create a further subdirectory and immediately remove it |
|
|
544 // This should make no overall change, but may expose later |
|
|
545 // node cache reference counting issues. |
|
|
546 diag_printf("<INFO>: mkdir delme\n"); |
|
|
547 err = mkdir( "delme", 0); |
|
|
548 if( err < 0 ) SHOW_RESULT( mkdir, err ); |
|
|
549 diag_printf("<INFO>: cd delme\n"); |
|
|
550 err = chdir( "delme"); |
|
|
551 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
552 diag_printf("<INFO>: cd ..\n"); |
|
|
553 err = chdir( ".." ); |
|
|
554 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
555 diag_printf("<INFO>: rmdir delme\n"); |
|
|
556 err = rmdir( "delme" ); |
|
|
557 if( err < 0 ) SHOW_RESULT( rmdir, err ); |
|
|
558 NEW_FILENAME1( "bar/delme1" ); |
|
|
559 diag_printf("<INFO>: mkdir %s\n",filename1); |
|
|
560 err = mkdir( filename1, 0); |
|
|
561 if( err < 0 ) SHOW_RESULT( mkdir, err ); |
|
|
562 diag_printf("<INFO>: rmdir %s\n",filename1); |
|
|
563 err = rmdir( filename1 ); |
|
|
564 if( err < 0 ) SHOW_RESULT( rmdir, err ); |
|
|
565 |
|
|
566 |
|
|
567 NEW_FILENAME1( "bar" ); |
|
|
568 checkcwd( filename1 ); |
|
|
569 |
|
|
570 diag_printf("<INFO>: rename ../foo bundy\n"); |
|
|
571 err = rename( "../foo", "bundy" ); |
|
|
572 if( err < 0 ) SHOW_RESULT( rename, err ); |
|
|
573 |
|
|
574 listdir( dirname, true, existingdirents+2, NULL ); |
|
|
575 listdir( "." , true, 4, NULL ); |
|
|
576 |
|
|
577 checkfile( "../bar/bundy" ); |
|
|
578 comparefiles("../fee", "bundy" ); |
|
|
579 |
|
|
580 #if defined(CYGSEM_FILEIO_BLOCK_USAGE) |
|
|
581 err = cyg_fs_getinfo(TEST_MOUNTPOINT, FS_INFO_BLOCK_USAGE, |
|
|
582 &usage, sizeof(usage)); |
|
|
583 if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err ); |
|
|
584 diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n", |
|
|
585 usage.total_blocks, usage.total_blocks * usage.block_size); |
|
|
586 diag_printf("<INFO>: free size: %6lld blocks, %10lld bytes\n", |
|
|
587 usage.free_blocks, usage.free_blocks * usage.block_size); |
|
|
588 diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size); |
|
|
589 #endif |
|
|
590 // -------------------------------------------------------------- |
|
|
591 // Check for some common error cases |
|
|
592 |
|
|
593 |
|
|
594 // First make some directories |
|
|
595 diag_printf("<INFO>: mkdir doo\n"); |
|
|
596 err = mkdir( "doo", 0 ); |
|
|
597 if( err < 0 ) SHOW_RESULT( mkdir, err ); |
|
|
598 |
|
|
599 diag_printf("<INFO>: mkdir fie\n"); |
|
|
600 err = mkdir( "fie", 0 ); |
|
|
601 if( err < 0 ) SHOW_RESULT( mkdir, err ); |
|
|
602 |
|
|
603 diag_printf("<INFO>: mkdir fie/foe\n"); |
|
|
604 err = mkdir( "fie/foe", 0 ); |
|
|
605 if( err < 0 ) SHOW_RESULT( mkdir, err ); |
|
|
606 |
|
|
607 |
|
|
608 diag_printf("<INFO>: rename fum doo -- should fail\n"); |
|
|
609 err = rename( "fum", "doo" ); |
|
|
610 if( err < 0 && errno != EISDIR ) SHOW_RESULT( rename, err ); |
|
|
611 |
|
|
612 diag_printf("<INFO>: rename doo fum -- should fail\n"); |
|
|
613 err = rename( "doo", "fum" ); |
|
|
614 if( err < 0 && errno != ENOTDIR ) SHOW_RESULT( rename, err ); |
|
|
615 |
|
|
616 diag_printf("<INFO>: rename doo fie -- should fail\n"); |
|
|
617 err = rename( "doo", "fie" ); |
|
|
618 // FATFS returns ENOTEMPTY, since fie has foe within it |
|
|
619 if( err < 0 && errno != EIO ) SHOW_RESULT( rename, err ); |
|
|
620 |
|
|
621 diag_printf("<INFO>: open floop for reading -- should fail\n"); |
|
|
622 err = open( "floop", O_RDONLY ); |
|
|
623 if( err < 0 && errno != ENOENT ) SHOW_RESULT( open, err ); |
|
|
624 |
|
|
625 NEW_FILENAME1( "x/y" ) |
|
|
626 diag_printf("<INFO>: rename fum %s -- should fail\n",filename1); |
|
|
627 err = rename( "fum", filename1 ); |
|
|
628 if( err < 0 && errno != ENOENT ) SHOW_RESULT( rename, err ); |
|
|
629 |
|
|
630 diag_printf("<INFO>: rename fum fum -- should succeed\n"); |
|
|
631 err = rename( "fum", "fum" ); |
|
|
632 if( err < 0 ) SHOW_RESULT( rename, err ); |
|
|
633 |
|
|
634 diag_printf("<INFO>: unlink fee -- should fail\n"); |
|
|
635 err = unlink( "fee" ); |
|
|
636 if( err < 0 && errno != ENOENT ) SHOW_RESULT( unlink, err ); |
|
|
637 |
|
|
638 NEW_FILENAME1( "bar" ); |
|
|
639 diag_printf("<INFO>: rmdir %s -- should fail\n",filename1); |
|
|
640 err = rmdir( filename1 ); |
|
|
641 // FATFS gives EBUSY here, since bar is the current dir |
|
|
642 if( err < 0 && errno != ENOTEMPTY ) SHOW_RESULT( rmdir, err ); |
|
|
643 |
|
|
644 diag_printf("<INFO>: unlink %s -- should fail\n",filename1); |
|
|
645 err = unlink( filename1 ); |
|
|
646 // FATFS returns EBUSY here, also because bar is current dir |
|
|
647 if( err < 0 && errno != EISDIR ) SHOW_RESULT( unlink, err ); |
|
|
648 |
|
|
649 NEW_FILENAME1( "bar/fum" ); |
|
|
650 diag_printf("<INFO>: rmdir %s -- should fail\n",filename1); |
|
|
651 err = rmdir( filename1 ); |
|
|
652 if( err < 0 && errno != ENOTDIR ) SHOW_RESULT( rmdir, err ); |
|
|
653 |
|
|
654 diag_printf("<INFO>: mkdir %s -- should fail\n",filename1); |
|
|
655 err = mkdir( filename1, 0 ); |
|
|
656 if( err < 0 && errno != EEXIST ) SHOW_RESULT( mkdir, err ); |
|
|
657 |
|
|
658 diag_printf("<INFO>: open bundy exclusive -- should fail\n"); |
|
|
659 fd = open( "bundy", O_WRONLY|O_CREAT|O_EXCL ); |
|
|
660 if( fd < 0 && errno != EEXIST ) SHOW_RESULT( open, fd ); |
|
|
661 |
|
|
662 diag_printf("<INFO>: open %s -- should fail\n",dirname); |
|
|
663 fd = open( dirname, O_WRONLY ); |
|
|
664 if( fd < 0 && errno != EISDIR ) SHOW_RESULT( open, fd ); |
|
|
665 |
|
|
666 |
|
|
667 listdir( dirname, true, existingdirents+2, NULL ); |
|
|
668 listdir( "." , true, 6, NULL ); |
|
|
669 |
|
|
670 // -------------------------------------------------------------- |
|
|
671 |
|
|
672 diag_printf("<INFO>: rename fie doo\n"); |
|
|
673 err = rename( "fie", "doo" ); |
|
|
674 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
675 |
|
|
676 diag_printf("<INFO>: rmdir doo/foe\n"); |
|
|
677 err = rmdir("doo/foe"); |
|
|
678 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
679 |
|
|
680 diag_printf("<INFO>: rmdir doo\n"); |
|
|
681 err = rmdir("doo"); |
|
|
682 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
683 |
|
|
684 diag_printf("<INFO>: unlink ../fee\n"); |
|
|
685 err = unlink( "../fee" ); |
|
|
686 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
687 |
|
|
688 diag_printf("<INFO>: unlink fum\n"); |
|
|
689 err = unlink( "fum" ); |
|
|
690 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
691 |
|
|
692 diag_printf("<INFO>: unlink ../bar/bundy\n"); |
|
|
693 err = unlink( "../bar/bundy" ); |
|
|
694 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
695 |
|
|
696 diag_printf("<INFO>: cd ..\n"); |
|
|
697 err = chdir( ".." ); |
|
|
698 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
699 |
|
|
700 checkcwd( dirname ); |
|
|
701 |
|
|
702 diag_printf("<INFO>: rmdir bar\n"); |
|
|
703 err = rmdir( "bar" ); |
|
|
704 if( err < 0 ) SHOW_RESULT( rmdir, err ); |
|
|
705 |
|
|
706 listdir( dirname, false, existingdirents, NULL ); |
|
|
707 |
|
|
708 // -------------------------------------------------------------- |
|
|
709 |
|
|
710 #ifdef TEST_MOUNTPOINT2 |
|
|
711 diag_printf("<INFO>: mount %s\n", TEST_MOUNTPOINT2); |
|
|
712 err = mount( TEST_DEVICE2, TEST_MOUNTPOINT2, TEST_FSTYPE2 ); |
|
|
713 |
|
|
714 if( err == 0 ) |
|
|
715 { |
|
|
716 mp2 = true; |
|
|
717 diag_printf("<INFO>: mount %s succeeded\n", TEST_MOUNTPOINT2); |
|
|
718 err = access( TEST_MOUNTPOINT2 TEST_DIRECTORY2, F_OK ); |
|
|
719 if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); |
|
|
720 |
|
|
721 if( err < 0 && errno == EACCES ) |
|
|
722 { |
|
|
723 diag_printf("<INFO>: create %s\n", |
|
|
724 TEST_MOUNTPOINT2 TEST_DIRECTORY2); |
|
|
725 err = mkdir( TEST_MOUNTPOINT2 TEST_DIRECTORY2, 0 ); |
|
|
726 if( err < 0 ) SHOW_RESULT( mkdir, err ); |
|
|
727 } |
|
|
728 |
|
|
729 err = chdir( TEST_MOUNTPOINT2 TEST_DIRECTORY2 ); |
|
|
730 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
731 |
|
|
732 checkcwd( TEST_MOUNTPOINT2 TEST_DIRECTORY2 ); |
|
|
733 |
|
|
734 dirname[0] = 0; |
|
|
735 strcat(dirname, TEST_MOUNTPOINT2 ); |
|
|
736 strcat(dirname, TEST_DIRECTORY2 ); |
|
|
737 |
|
|
738 } |
|
|
739 else |
|
|
740 { |
|
|
741 mp2 = false; |
|
|
742 diag_printf("<INFO>: mount %s failed, ", TEST_MOUNTPOINT2); |
|
|
743 diag_printf("using %s instead\n", dirname ); |
|
|
744 } |
|
|
745 |
|
|
746 #endif |
|
|
747 |
|
|
748 listdir( dirname , true, -1, &existingdirents); |
|
|
749 |
|
|
750 NEW_FILENAME1( "tinky" ); |
|
|
751 NEW_FILENAME2( "laalaa" ); |
|
|
752 |
|
|
753 createfile( filename1, 4567 ); |
|
|
754 copyfile( filename1, filename2 ); |
|
|
755 checkfile( filename1); |
|
|
756 checkfile( filename2); |
|
|
757 comparefiles( filename1, filename2 ); |
|
|
758 |
|
|
759 diag_printf("<INFO>: cd %s\n",dirname); |
|
|
760 err = chdir( dirname ); |
|
|
761 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
762 |
|
|
763 checkcwd( dirname ); |
|
|
764 |
|
|
765 diag_printf("<INFO>: mkdir noonoo\n"); |
|
|
766 err = mkdir( "noonoo", 0 ); |
|
|
767 if( err < 0 ) SHOW_RESULT( mkdir, err ); |
|
|
768 |
|
|
769 listdir( dirname , true, existingdirents+3, NULL); |
|
|
770 |
|
|
771 diag_printf("<INFO>: cd noonoo\n"); |
|
|
772 err = chdir( "noonoo" ); |
|
|
773 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
774 |
|
|
775 NEW_FILENAME1( "noonoo" ); |
|
|
776 checkcwd( filename1 ); |
|
|
777 |
|
|
778 createfile( "tinky", 6789 ); |
|
|
779 checkfile( "tinky" ); |
|
|
780 |
|
|
781 createfile( "dipsy", 34567 ); |
|
|
782 checkfile( "dipsy" ); |
|
|
783 copyfile( "dipsy", "po" ); |
|
|
784 checkfile( "po" ); |
|
|
785 comparefiles( "dipsy", "po" ); |
|
|
786 |
|
|
787 listdir( ".", true, 5, NULL ); |
|
|
788 listdir( "..", true, existingdirents+3, NULL ); |
|
|
789 |
|
|
790 // -------------------------------------------------------------- |
|
|
791 |
|
|
792 diag_printf("<INFO>: unlink tinky\n"); |
|
|
793 err = unlink( "tinky" ); |
|
|
794 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
795 |
|
|
796 diag_printf("<INFO>: unlink dipsy\n"); |
|
|
797 err = unlink( "dipsy" ); |
|
|
798 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
799 |
|
|
800 diag_printf("<INFO>: unlink po\n"); |
|
|
801 err = unlink( "po" ); |
|
|
802 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
803 |
|
|
804 diag_printf("<INFO>: cd ..\n"); |
|
|
805 err = chdir( ".." ); |
|
|
806 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
807 checkcwd( dirname ); |
|
|
808 |
|
|
809 diag_printf("<INFO>: rmdir noonoo\n"); |
|
|
810 err = rmdir( "noonoo" ); |
|
|
811 if( err < 0 ) SHOW_RESULT( rmdir, err ); |
|
|
812 |
|
|
813 // -------------------------------------------------------------- |
|
|
814 |
|
|
815 diag_printf("<INFO>: mkdir x\n"); |
|
|
816 err = mkdir( "x", 0 ); |
|
|
817 if( err < 0 ) SHOW_RESULT( mkdir, err ); |
|
|
818 |
|
|
819 diag_printf("<INFO>: mkdir x/y\n"); |
|
|
820 err = mkdir( "x/y", 0 ); |
|
|
821 if( err < 0 ) SHOW_RESULT( mkdir, err ); |
|
|
822 |
|
|
823 diag_printf("<INFO>: mkdir x/y/z\n"); |
|
|
824 err = mkdir( "x/y/z", 0 ); |
|
|
825 if( err < 0 ) SHOW_RESULT( mkdir, err ); |
|
|
826 |
|
|
827 diag_printf("<INFO>: mkdir x/y/z/w\n"); |
|
|
828 err = mkdir( "x/y/z/w", 0 ); |
|
|
829 if( err < 0 ) SHOW_RESULT( mkdir, err ); |
|
|
830 |
|
|
831 NEW_FILENAME1( "x/y/z/w" ); |
|
|
832 diag_printf("<INFO>: cd %s\n",filename1); |
|
|
833 err = chdir( filename1 ); |
|
|
834 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
835 checkcwd( filename1 ); |
|
|
836 |
|
|
837 NEW_FILENAME1( "x/y/z" ); |
|
|
838 diag_printf("<INFO>: cd ..\n"); |
|
|
839 err = chdir( ".." ); |
|
|
840 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
841 checkcwd( filename1 ); |
|
|
842 |
|
|
843 NEW_FILENAME1( "x/y/z" ); |
|
|
844 diag_printf("<INFO>: cd .\n"); |
|
|
845 err = chdir( "." ); |
|
|
846 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
847 checkcwd( filename1 ); |
|
|
848 |
|
|
849 NEW_FILENAME1( "x/y" ); |
|
|
850 diag_printf("<INFO>: cd ../../y\n"); |
|
|
851 err = chdir( "../../y" ); |
|
|
852 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
853 checkcwd( filename1 ); |
|
|
854 |
|
|
855 diag_printf("<INFO>: cd ../..\n"); |
|
|
856 err = chdir( "../.." ); |
|
|
857 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
858 checkcwd( dirname ); |
|
|
859 |
|
|
860 diag_printf("<INFO>: rmdir x/y/z/w\n"); |
|
|
861 err = rmdir( "x/y/z/w" ); |
|
|
862 if( err < 0 ) SHOW_RESULT( rmdir, err ); |
|
|
863 |
|
|
864 diag_printf("<INFO>: rmdir x/y/z\n"); |
|
|
865 err = rmdir( "x/y/z" ); |
|
|
866 if( err < 0 ) SHOW_RESULT( rmdir, err ); |
|
|
867 |
|
|
868 diag_printf("<INFO>: rmdir x/y\n"); |
|
|
869 err = rmdir( "x/y" ); |
|
|
870 if( err < 0 ) SHOW_RESULT( rmdir, err ); |
|
|
871 |
|
|
872 diag_printf("<INFO>: rmdir x\n"); |
|
|
873 err = rmdir( "x" ); |
|
|
874 if( err < 0 ) SHOW_RESULT( rmdir, err ); |
|
|
875 |
|
|
876 // -------------------------------------------------------------- |
|
|
877 |
|
|
878 checkcwd( dirname ); |
|
|
879 |
|
|
880 diag_printf("<INFO>: unlink tinky\n"); |
|
|
881 err = unlink( "tinky" ); |
|
|
882 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
883 |
|
|
884 diag_printf("<INFO>: unlink laalaa\n"); |
|
|
885 err = unlink( "laalaa" ); |
|
|
886 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
887 |
|
|
888 // -------------------------------------------------------------- |
|
|
889 |
|
|
890 diag_printf("<INFO>: cd %s\n", TEST_MOUNTPOINT TEST_DIRECTORY); |
|
|
891 err = chdir( TEST_MOUNTPOINT TEST_DIRECTORY); |
|
|
892 if( err < 0 ) SHOW_RESULT( chdir, err ); |
|
|
893 checkcwd( TEST_MOUNTPOINT TEST_DIRECTORY ); |
|
|
894 |
|
|
895 listdir( ".", true, -1, NULL ); |
|
|
896 |
|
|
897 #ifdef TEST_MOUNTPOINT2 |
|
|
898 if( mp2 ) |
|
|
899 { |
|
|
900 diag_printf("<INFO>: umount %s\n",TEST_MOUNTPOINT2); |
|
|
901 err = umount( TEST_MOUNTPOINT2 ); |
|
|
902 if( err < 0 ) SHOW_RESULT( umount, err ); |
|
|
903 } |
|
|
904 #endif |
|
|
905 |
|
|
906 // -------------------------------------------------------------- |
|
|
907 |
|
|
908 #if 0 |
|
|
909 maxfile("file.max"); |
|
|
910 |
|
|
911 listdir( "/", true, -1, NULL ); |
|
|
912 |
|
|
913 diag_printf("<INFO>: unlink file.max\n"); |
|
|
914 err = unlink( "file.max" ); |
|
|
915 if( err < 0 ) SHOW_RESULT( unlink, err ); |
|
|
916 #endif |
|
|
917 |
|
|
918 // -------------------------------------------------------------- |
|
|
919 |
|
|
920 diag_printf("<INFO>: cd /\n"); |
|
|
921 err = chdir( "/" ); |
|
|
922 if( err == 0 ) |
|
|
923 { |
|
|
924 checkcwd( "/" ); |
|
|
925 |
|
|
926 diag_printf("<INFO>: umount %s\n",TEST_MOUNTPOINT); |
|
|
927 err = umount( TEST_MOUNTPOINT ); |
|
|
928 if( err < 0 ) SHOW_RESULT( umount, err ); |
|
|
929 } |
|
|
930 |
|
|
931 diag_printf("<INFO>: syncing\n"); |
|
|
932 cyg_fs_setinfo(TEST_MOUNTPOINT, FS_INFO_SYNC, NULL, 0); // sync(); |
|
|
933 |
|
|
934 CYG_TEST_PASS_FINISH("yaffs1"); |
|
|
935 } |
|
|
936 |
|
|
937 // ------------------------------------------------------------------------- |
|
|
938 |
|
|
939 #include <cyg/kernel/kapi.h> |
|
|
940 |
|
|
941 static cyg_handle_t thread_handle; |
|
|
942 static cyg_thread thread; |
|
|
943 static char stack[CYGNUM_HAL_STACK_SIZE_TYPICAL+1024]; |
|
|
944 |
|
|
945 externC void |
|
|
946 cyg_start( void ) |
|
|
947 { |
|
|
948 cyg_thread_create(3, // Priority - just a number |
|
|
949 fileio1_main, // entry |
|
|
950 0, // index |
|
|
951 0, // no name |
|
|
952 &stack[0], // Stack |
|
|
953 sizeof(stack), // Size |
|
|
954 &thread_handle, // Handle |
|
|
955 &thread // Thread data structure |
|
|
956 ); |
|
|
957 cyg_thread_resume(thread_handle); |
|
|
958 |
|
|
959 cyg_scheduler_start(); |
|
|
960 } |
|
|
961 |
|
|
962 #else // CYGPKG_KERNEL |
|
|
963 |
|
|
964 #include <cyg/infra/testcase.h> |
|
|
965 |
|
|
966 externC void cyg_start(void) |
|
|
967 { |
|
|
968 CYG_TEST_NA("Needs CYGPKG_KERNEL"); |
|
|
969 } |
|
|
970 |
|
|
971 #endif |
|
|
972 |
|
|
973 // ------------------------------------------------------------------------- |
|
|
974 // EOF yaffs1.c |