1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * This test exercises stat() via fstat() and generates as many of the |
---|
5 | * path evaluation cases as possible. |
---|
6 | * |
---|
7 | * This test also exercises lstat() and lchown() when symlinks are |
---|
8 | * involved. |
---|
9 | */ |
---|
10 | |
---|
11 | /* |
---|
12 | * COPYRIGHT (c) 1989-2012. |
---|
13 | * On-Line Applications Research Corporation (OAR). |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.org/license/LICENSE. |
---|
18 | */ |
---|
19 | |
---|
20 | #ifdef HAVE_CONFIG_H |
---|
21 | #include "config.h" |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <tmacros.h> |
---|
25 | #include <sys/stat.h> |
---|
26 | #include <fcntl.h> |
---|
27 | #include <limits.h> |
---|
28 | #include <stdio.h> |
---|
29 | #include <unistd.h> |
---|
30 | #include <errno.h> |
---|
31 | #include <string.h> |
---|
32 | #include <reent.h> |
---|
33 | #include <rtems.h> |
---|
34 | #include <rtems/libio.h> |
---|
35 | #include <rtems/imfs.h> |
---|
36 | #include <pmacros.h> |
---|
37 | |
---|
38 | #include "primode.h" |
---|
39 | |
---|
40 | const char rtems_test_name[] = "PSXSTAT"; |
---|
41 | |
---|
42 | /* forward declarations to avoid warnings */ |
---|
43 | int test_main(void); |
---|
44 | void stat_a_file_helper(const char *file, int follow_link); |
---|
45 | void stat_a_file(const char *file); |
---|
46 | void lstat_a_file(const char *file); |
---|
47 | void stat_multiple_files(char **files); |
---|
48 | void chown_multiple_files_helper(char **files, int follow_link); |
---|
49 | void chown_multiple_files(char **files); |
---|
50 | void lchown_multiple_files(char **files); |
---|
51 | void make_multiple_files(char **files); |
---|
52 | void make_multiple_bad_files(char **files); |
---|
53 | void make_multiple_links(char **existing, char **new); |
---|
54 | void make_too_many_links(void); |
---|
55 | void make_a_symlink(char *existing, char *new); |
---|
56 | void make_multiple_symlinks(void); |
---|
57 | void make_many_symlinks(char *real_file, int link_count); |
---|
58 | void make_multiple_directories(char **files); |
---|
59 | void Cause_faults(void); |
---|
60 | void Show_Time(void); |
---|
61 | void test_statvfs(void); |
---|
62 | |
---|
63 | #define MAXSYMLINK 5 /* There needs to be a better way of getting this. */ |
---|
64 | #define TIMEOUT_VALUE ( 5 * rtems_clock_get_ticks_per_second() ) |
---|
65 | |
---|
66 | int _lstat_r(struct _reent *, const char *, struct stat *); |
---|
67 | |
---|
68 | /* |
---|
69 | * List of files which should exist. |
---|
70 | */ |
---|
71 | |
---|
72 | char *Files[] = { |
---|
73 | "/////my_mount_point/dir1/\\//file1", |
---|
74 | "/my_mount_point/dir1/file2", |
---|
75 | "/my_mount_point/dir1/file3", |
---|
76 | "/my_mount_point/dir1/file4", |
---|
77 | "/my_mount_point/dir1/dir1/file1", |
---|
78 | "../../..//my_mount_point/dir1/./././dir1/ file1", |
---|
79 | "main.c", |
---|
80 | 0 |
---|
81 | }; |
---|
82 | |
---|
83 | /* |
---|
84 | * List of directories which should exist. |
---|
85 | */ |
---|
86 | |
---|
87 | char *Directories[] = { |
---|
88 | "/my_mount_point/dir1\\\\//", |
---|
89 | "/my_mount_point/dir2", |
---|
90 | "/my_mount_point/dir3", |
---|
91 | "/my_mount_point/dir4", |
---|
92 | "/my_mount_point/dir1/dir1", |
---|
93 | "/./././my_mount_point/dir1/ dir1", |
---|
94 | "/./././my_mount_point/links", |
---|
95 | "///my_mount_point/dir1/dir1/../../dir1/../symlinks/////", |
---|
96 | 0 |
---|
97 | }; |
---|
98 | |
---|
99 | char *Links_to_Dirs[]= { |
---|
100 | "dir1/dir1/../../links/dir1", |
---|
101 | "links/dir2", |
---|
102 | "links/dir3", |
---|
103 | "links/dir4", |
---|
104 | "links/dir1_dir1", |
---|
105 | "links/dir1_ dir1", |
---|
106 | "links/../links/../links/links", |
---|
107 | 0 |
---|
108 | }; |
---|
109 | |
---|
110 | char *Links_to_Files[]= { |
---|
111 | "links/dir1_file1", |
---|
112 | "links/dir1_file2", |
---|
113 | "links/dir1_file3", |
---|
114 | "links/dir1_file4", |
---|
115 | "links/dir1_dir1_f1", |
---|
116 | "links/dir1_dir1 f1", |
---|
117 | 0 |
---|
118 | }; |
---|
119 | |
---|
120 | char *Links_to_dirlinks[]= { |
---|
121 | "links/links/links/links_dir1", |
---|
122 | "links//links_dir2", |
---|
123 | "links//links_dir3", |
---|
124 | "links//links_dir4", |
---|
125 | "links//links_dir1_d1", |
---|
126 | "links//links_dir1 d1", |
---|
127 | "links//links_links", |
---|
128 | 0 |
---|
129 | }; |
---|
130 | |
---|
131 | char *Links_to_filelinks[]= { |
---|
132 | "links///links_d1_file1", |
---|
133 | "links///links_d1_file2", |
---|
134 | "links///links_d1_file3", |
---|
135 | "links///links_d1_file4", |
---|
136 | "links///links_d1_d1_f1", |
---|
137 | "links///links_r1_d1 f1", |
---|
138 | 0 |
---|
139 | }; |
---|
140 | |
---|
141 | char *SymLinks[]= { |
---|
142 | "/my_mount_point/symlinks/a_file_symlink", |
---|
143 | "/my_mount_point/symlinks/a_dir_symlink", |
---|
144 | "/my_mount_point/symlinks/a_link_symlink", |
---|
145 | "../symlinks/no_file", |
---|
146 | "/my_mount_point/symlinks/a_dir_symlink/a_file_symlink", |
---|
147 | 0 |
---|
148 | }; |
---|
149 | |
---|
150 | /* |
---|
151 | * List of absolute paths to stat. |
---|
152 | */ |
---|
153 | |
---|
154 | char *Good_absolute_paths[] = { |
---|
155 | "/my_mount_point/dev", |
---|
156 | "////my_mount_point/dir1/\\//file1\\\\//", |
---|
157 | "/my_mount_point/dir1/\\\\/file2", |
---|
158 | "/my_mount_point/dir1/file3/////\\\\\\", |
---|
159 | "/my_mount_point/dir1/file4", |
---|
160 | "/my_mount_point/dir1/dir1/file1", |
---|
161 | "/my_mount_point/dir1/dir1/ file1", |
---|
162 | "/my_mount_point/dir1", |
---|
163 | "/my_mount_point/dir2//////\\", |
---|
164 | "/my_mount_point/dir3", |
---|
165 | "/my_mount_point/dir4", |
---|
166 | "/my_mount_point/dir1/dir1", |
---|
167 | "/my_mount_point/dir1/ dir1///\\\\", |
---|
168 | "/my_mount_point/\\/\\/\\/\\/\\/\\/links\\/\\/\\/\\/\\/\\", |
---|
169 | 0 |
---|
170 | }; |
---|
171 | |
---|
172 | |
---|
173 | char *Bad_paths[] = { |
---|
174 | "/my_mount_point/links/ENAMETOOLONG________________________________________" |
---|
175 | "__________________________________________________________________________" |
---|
176 | "__________________________________________________________________________" |
---|
177 | "__________________________________________________________________________" |
---|
178 | "______________________________________", |
---|
179 | "/my_mount_point/dir1/file4/NOTADIR", |
---|
180 | "/my_mount_point/dir1/dir1/EACCES__", |
---|
181 | 0 |
---|
182 | }; |
---|
183 | |
---|
184 | /* |
---|
185 | * List of relative paths to stat. |
---|
186 | */ |
---|
187 | |
---|
188 | char *Good_relative_paths[] = { |
---|
189 | "dev", |
---|
190 | "dir1/\\//file1\\\\//", |
---|
191 | "dir1/\\\\/file2", |
---|
192 | "dir1/file3/////\\\\\\", |
---|
193 | "dir1/file4", |
---|
194 | "dir1/dir1/file1", |
---|
195 | "dir1/dir1/ file1", |
---|
196 | "dir1", |
---|
197 | "dir2//////\\", |
---|
198 | "dir3", |
---|
199 | "dir4", |
---|
200 | "dir1/dir1", |
---|
201 | "dir1/ dir1///\\\\", |
---|
202 | "main.c", |
---|
203 | 0 |
---|
204 | }; |
---|
205 | |
---|
206 | /* |
---|
207 | * Do a stat/lstat on a single file and report the status. |
---|
208 | */ |
---|
209 | void stat_a_file_helper( |
---|
210 | const char *file, |
---|
211 | int follow_link |
---|
212 | ) |
---|
213 | { |
---|
214 | int status; |
---|
215 | struct stat statbuf; |
---|
216 | int major1; |
---|
217 | int minor1; |
---|
218 | int major2; |
---|
219 | int minor2; |
---|
220 | |
---|
221 | |
---|
222 | rtems_test_assert( file ); |
---|
223 | |
---|
224 | if ( follow_link ) { |
---|
225 | printf( "stat( %s ) returned ", file ); |
---|
226 | fflush( stdout ); |
---|
227 | status = stat( file, &statbuf ); |
---|
228 | } else { |
---|
229 | printf( "lstat( %s ) returned ", file ); |
---|
230 | fflush( stdout ); |
---|
231 | status = lstat( file, &statbuf ); |
---|
232 | } |
---|
233 | |
---|
234 | if ( status == -1 ) { |
---|
235 | printf( ": %s\n", strerror( errno ) ); |
---|
236 | } else { |
---|
237 | |
---|
238 | rtems_filesystem_split_dev_t( statbuf.st_dev, major1, minor1 ); |
---|
239 | rtems_filesystem_split_dev_t( statbuf.st_rdev, major2, minor2 ); |
---|
240 | |
---|
241 | |
---|
242 | printf("\n...st_dev (0x%x:0x%x)\n", major1, minor1 ); |
---|
243 | printf( "...st_ino %" PRIxino_t "\n", statbuf.st_ino ); |
---|
244 | printf( "...st_mode %" PRIomode_t "\n", statbuf.st_mode ); |
---|
245 | printf( "...st_nlink %x\n", statbuf.st_nlink ); |
---|
246 | printf( "...st_uid %d\n", statbuf.st_uid ); |
---|
247 | printf( "...st_gid %d\n", statbuf.st_gid ); |
---|
248 | printf( "...st_rdev (0x%x:0x%x)\n", major2, minor2 ); |
---|
249 | printf( "...st_size %" PRIdoff_t "\n", statbuf.st_size ); |
---|
250 | printf( "...st_atime %s", ctime( &statbuf.st_atime ) ); |
---|
251 | printf( "...st_mtime %s", ctime( &statbuf.st_mtime ) ); |
---|
252 | printf( "...st_ctime %s", ctime( &statbuf.st_ctime ) ); |
---|
253 | printf( "...st_blksize %" PRIxblksize_t "\n", statbuf.st_blksize ); |
---|
254 | printf( "...st_blocks %" PRIxblkcnt_t "\n", statbuf.st_blocks ); |
---|
255 | } |
---|
256 | } |
---|
257 | |
---|
258 | /* |
---|
259 | * Do a stat on a single file and report the status. |
---|
260 | */ |
---|
261 | void stat_a_file( |
---|
262 | const char *file |
---|
263 | ) |
---|
264 | { |
---|
265 | stat_a_file_helper( file, true ); |
---|
266 | } |
---|
267 | |
---|
268 | /* |
---|
269 | * Do a lstat on a single file and report the status. |
---|
270 | */ |
---|
271 | void lstat_a_file( |
---|
272 | const char *file |
---|
273 | ) |
---|
274 | { |
---|
275 | stat_a_file_helper( file, false ); |
---|
276 | } |
---|
277 | |
---|
278 | /* |
---|
279 | * stat() multiple files at a time |
---|
280 | */ |
---|
281 | void stat_multiple_files( |
---|
282 | char **files |
---|
283 | ) |
---|
284 | { |
---|
285 | int i; |
---|
286 | |
---|
287 | i = 0; |
---|
288 | while ( files[i] ) { |
---|
289 | stat_a_file( files[i] ); |
---|
290 | i++; |
---|
291 | } |
---|
292 | } |
---|
293 | |
---|
294 | /* |
---|
295 | * chown()/lchown() multiple files at a time |
---|
296 | */ |
---|
297 | void chown_multiple_files_helper( |
---|
298 | char **files, |
---|
299 | int follow_link |
---|
300 | ) |
---|
301 | { |
---|
302 | int i; |
---|
303 | uid_t st_uid; |
---|
304 | gid_t st_gid; |
---|
305 | |
---|
306 | st_uid = geteuid(); |
---|
307 | st_gid = getegid(); |
---|
308 | |
---|
309 | i = 0; |
---|
310 | while ( files[i] ) { |
---|
311 | printf("Change group of %s\n", files[i]); |
---|
312 | if ( follow_link ) { |
---|
313 | chown( files[i], st_uid, (st_gid+1) ); |
---|
314 | stat_a_file( files[i] ); |
---|
315 | } else { |
---|
316 | lchown( files[i], st_uid, (st_gid+1) ); |
---|
317 | lstat_a_file( files[i] ); |
---|
318 | } |
---|
319 | |
---|
320 | printf("Change owner of %s\n", files[i]); |
---|
321 | if ( follow_link ) { |
---|
322 | chown( files[i], (st_uid+1), st_gid ); |
---|
323 | stat_a_file( files[i] ); |
---|
324 | } else { |
---|
325 | lchown( files[i], (st_uid+1), st_gid ); |
---|
326 | lstat_a_file( files[i] ); |
---|
327 | } |
---|
328 | i++; |
---|
329 | } |
---|
330 | |
---|
331 | } |
---|
332 | |
---|
333 | /* |
---|
334 | * chown() multiple files at a time |
---|
335 | */ |
---|
336 | void chown_multiple_files( |
---|
337 | char **files |
---|
338 | ) |
---|
339 | { |
---|
340 | chown_multiple_files_helper( files, true ); |
---|
341 | } |
---|
342 | |
---|
343 | /* |
---|
344 | * lchown() multiple files at a time |
---|
345 | */ |
---|
346 | void lchown_multiple_files( |
---|
347 | char **files |
---|
348 | ) |
---|
349 | { |
---|
350 | chown_multiple_files_helper( files, false ); |
---|
351 | } |
---|
352 | |
---|
353 | /* |
---|
354 | * mknod() multiple files at a time |
---|
355 | */ |
---|
356 | void make_multiple_files( |
---|
357 | char **files |
---|
358 | ) |
---|
359 | { |
---|
360 | int i; |
---|
361 | int status; |
---|
362 | |
---|
363 | i = 0; |
---|
364 | while ( files[i] ) { |
---|
365 | printf( "Making file %s\n", files[i] ); |
---|
366 | status = mknod( files[i], ( S_IFREG | S_IROTH|S_IWOTH ), 0LL ); |
---|
367 | rtems_test_assert( !status ); |
---|
368 | i++; |
---|
369 | } |
---|
370 | puts( "" ); |
---|
371 | } |
---|
372 | |
---|
373 | void make_multiple_bad_files( |
---|
374 | char **files |
---|
375 | ) |
---|
376 | { |
---|
377 | int i; |
---|
378 | int status; |
---|
379 | |
---|
380 | i = 0; |
---|
381 | while ( files[i] ) { |
---|
382 | printf( "Making file %s ", files[i] ); |
---|
383 | status = mknod( files[i], ( S_IFREG | S_IROTH|S_IWOTH ), 0LL ); |
---|
384 | rtems_test_assert( status ); |
---|
385 | printf( ": %s\n", strerror( errno ) ); |
---|
386 | i++; |
---|
387 | } |
---|
388 | puts( "" ); |
---|
389 | } |
---|
390 | |
---|
391 | void make_multiple_links( |
---|
392 | char **existing, |
---|
393 | char **new |
---|
394 | ) |
---|
395 | { |
---|
396 | int i; |
---|
397 | int status; |
---|
398 | |
---|
399 | i = 0; |
---|
400 | while ( new[i] && existing[i] ) { |
---|
401 | printf( "Making file %s\n", new[i] ); |
---|
402 | status = link( existing[i], new[i] ); |
---|
403 | rtems_test_assert( !status ); |
---|
404 | i++; |
---|
405 | } |
---|
406 | puts( "" ); |
---|
407 | |
---|
408 | status = link( "fred", "bob" ); |
---|
409 | rtems_test_assert( status == -1 ); |
---|
410 | |
---|
411 | status = link( existing[1], "doug/bob" ); |
---|
412 | rtems_test_assert( status == -1 ); |
---|
413 | } |
---|
414 | |
---|
415 | void make_too_many_links(void) |
---|
416 | { |
---|
417 | int i; |
---|
418 | int status; |
---|
419 | char name [20]; |
---|
420 | |
---|
421 | status = mkdir("/dummy", S_IRWXU ); |
---|
422 | rtems_test_assert( status == 0 ); |
---|
423 | |
---|
424 | for (i=1; i<= LINK_MAX; i++) { |
---|
425 | |
---|
426 | sprintf(name,"/LinkName%d",i); |
---|
427 | printf( "Making file %s\n", name ); |
---|
428 | status = link("/dummy" , name ); |
---|
429 | if( i < LINK_MAX ) |
---|
430 | rtems_test_assert( !status ); |
---|
431 | else |
---|
432 | rtems_test_assert( status == -1 ); |
---|
433 | |
---|
434 | } |
---|
435 | } |
---|
436 | |
---|
437 | void make_a_symlink( |
---|
438 | char *existing, |
---|
439 | char *new |
---|
440 | ) |
---|
441 | { |
---|
442 | int status; |
---|
443 | char buf[100]; |
---|
444 | int len; |
---|
445 | |
---|
446 | memset( buf, 0, 100 ); |
---|
447 | |
---|
448 | printf( "Making file %s\n", new ); |
---|
449 | status = symlink( existing, new ); |
---|
450 | rtems_test_assert( !status ); |
---|
451 | |
---|
452 | printf( "Verify with readlink\n"); |
---|
453 | status = readlink( new, buf, 100 ); |
---|
454 | len = strlen( existing ); |
---|
455 | rtems_test_assert ( status == len ); |
---|
456 | |
---|
457 | status = readlink( new, buf, 3 ); |
---|
458 | len = strlen( existing ); |
---|
459 | if (len < 3 ) |
---|
460 | rtems_test_assert( status == len ); |
---|
461 | else |
---|
462 | rtems_test_assert( status == 3 ); |
---|
463 | |
---|
464 | status = strcmp( existing, buf ); |
---|
465 | rtems_test_assert( !status ); |
---|
466 | } |
---|
467 | |
---|
468 | void make_multiple_symlinks(void) |
---|
469 | { |
---|
470 | int status, i; |
---|
471 | |
---|
472 | make_a_symlink( Files[0], SymLinks[0] ); |
---|
473 | make_a_symlink( Directories[0], SymLinks[1] ); |
---|
474 | make_a_symlink( Links_to_dirlinks[0], SymLinks[2] ); |
---|
475 | make_a_symlink( "No_File", SymLinks[3] ); |
---|
476 | make_a_symlink( SymLinks[1], SymLinks[4] ); |
---|
477 | make_a_symlink( "//my_mount_point/links","/my_mount_point/symlinks/links" ); |
---|
478 | |
---|
479 | for (i = 0; i < 5; i++) { |
---|
480 | stat_a_file( SymLinks[i] ); |
---|
481 | lstat_a_file( SymLinks[i] ); |
---|
482 | } |
---|
483 | |
---|
484 | status = symlink( "//links", "bob/frank" ); |
---|
485 | rtems_test_assert (status == -1); |
---|
486 | |
---|
487 | } |
---|
488 | /* |
---|
489 | void make_too_many_symlinks() |
---|
490 | { |
---|
491 | int i, status; |
---|
492 | char name1[8]; |
---|
493 | |
---|
494 | for (i=1; i <= MAXSYMLINK; i++) { |
---|
495 | sprintf( name1, "SymLink%d", i ); |
---|
496 | status = symlink( "/dummy", name1 ); |
---|
497 | if( i < MAXSYMLINK ) |
---|
498 | rtems_test_assert( !status ); |
---|
499 | else |
---|
500 | rtems_test_assert( status == -1 ); |
---|
501 | } |
---|
502 | } |
---|
503 | */ |
---|
504 | |
---|
505 | void make_many_symlinks( |
---|
506 | char *real_file, |
---|
507 | int link_count |
---|
508 | ) |
---|
509 | { |
---|
510 | int i; |
---|
511 | char name1[32]; |
---|
512 | char name2[32]; |
---|
513 | char *link_file; |
---|
514 | |
---|
515 | /* limit the link_count to ensure filename buffer doesn't overflow */ |
---|
516 | rtems_test_assert( link_count < 1000 ); |
---|
517 | |
---|
518 | link_file = real_file; |
---|
519 | for (i=1; i < link_count; i++) { |
---|
520 | sprintf( name1, "%04d", i ); |
---|
521 | make_a_symlink( link_file, name1 ); |
---|
522 | strcpy( name2, name1 ); |
---|
523 | link_file = name2; |
---|
524 | } |
---|
525 | |
---|
526 | for (i=1; i < link_count; i++) { |
---|
527 | sprintf( name1, "%04d", i ); |
---|
528 | stat_a_file( name1 ); |
---|
529 | lstat_a_file( name1 ); |
---|
530 | } |
---|
531 | |
---|
532 | } |
---|
533 | |
---|
534 | /* |
---|
535 | * mkdir() multiple directories at a time |
---|
536 | */ |
---|
537 | void make_multiple_directories( |
---|
538 | char **files |
---|
539 | ) |
---|
540 | { |
---|
541 | int i; |
---|
542 | int status; |
---|
543 | |
---|
544 | i = 0; |
---|
545 | while ( files[i] ) { |
---|
546 | printf( "Making directory %s\n", files[i] ); |
---|
547 | status = mkdir( files[i], S_IRWXU ); |
---|
548 | rtems_test_assert( !status ); |
---|
549 | i++; |
---|
550 | } |
---|
551 | puts( "" ); |
---|
552 | } |
---|
553 | |
---|
554 | /* |
---|
555 | * Cause faults. |
---|
556 | */ |
---|
557 | void Cause_faults(void) |
---|
558 | { |
---|
559 | int fd; |
---|
560 | int status; |
---|
561 | char longer_name[100]; |
---|
562 | |
---|
563 | /* |
---|
564 | * Verify chmod with an invalid type. |
---|
565 | */ |
---|
566 | |
---|
567 | #if 0 |
---|
568 | status = chmod( Files[0], S_IFREG ); |
---|
569 | rtems_test_assert( status == -1 ); |
---|
570 | rtems_test_assert( errno == EPERM ); |
---|
571 | #endif |
---|
572 | |
---|
573 | /* |
---|
574 | * Change file to executable then try to chdir to it. |
---|
575 | */ |
---|
576 | |
---|
577 | status = chmod( Files[0], S_IXUSR ); |
---|
578 | rtems_test_assert( status != -1 ); |
---|
579 | |
---|
580 | printf("chdir to a file should fail with ENOTDIR\n"); |
---|
581 | status = chdir( Files[0] ); |
---|
582 | rtems_test_assert( status == -1 ); |
---|
583 | rtems_test_assert( errno == ENOTDIR ); |
---|
584 | |
---|
585 | /* |
---|
586 | * Change mode to read/write on a directory. |
---|
587 | * Verify directory works properly. |
---|
588 | */ |
---|
589 | |
---|
590 | printf("Verify RWX permission on %s via access\n", Directories[0]); |
---|
591 | status = access( Directories[0], ( R_OK | W_OK | X_OK ) ); |
---|
592 | rtems_test_assert( status == 0 ); |
---|
593 | |
---|
594 | printf( "chmod of %s to Read/Write\n", Directories[0] ); |
---|
595 | status = chmod( Directories[0], (S_IXGRP | S_IXOTH) ); |
---|
596 | rtems_test_assert( status == 0 ); |
---|
597 | |
---|
598 | printf( "chmod fred should fail with ENOENT\n" ); |
---|
599 | status = chmod( "fred", (S_IXGRP | S_IXOTH) ); |
---|
600 | rtems_test_assert( status == -1 ); |
---|
601 | rtems_test_assert( errno == ENOENT ); |
---|
602 | |
---|
603 | strcpy(longer_name, Directories[0] ); |
---|
604 | strcat(longer_name, "/BADNAME" ); |
---|
605 | printf( "Create under %s should fail with EACCES\n", Directories[0] ); |
---|
606 | status = mkdir( longer_name , S_IRWXU ); |
---|
607 | rtems_test_assert( status == -1 ); |
---|
608 | rtems_test_assert( errno == EACCES ); |
---|
609 | |
---|
610 | printf("chdir to %s should fail with EACCES\n", Directories[4] ); |
---|
611 | status = chdir( Directories[4] ); |
---|
612 | rtems_test_assert( status == -1 ); |
---|
613 | rtems_test_assert( errno == EACCES ); |
---|
614 | |
---|
615 | /* |
---|
616 | * Set current to a directory with no owner permissions. |
---|
617 | * Verify it works properly. |
---|
618 | */ |
---|
619 | |
---|
620 | status = chmod( Directories[0], (S_IXGRP | S_IXOTH) ); |
---|
621 | rtems_test_assert( status == 0 ); |
---|
622 | |
---|
623 | printf("mkdir %s should fail with EACCESS\n", longer_name ); |
---|
624 | status = mkdir( longer_name , S_IRWXU ); |
---|
625 | rtems_test_assert( status == -1 ); |
---|
626 | rtems_test_assert( errno == EACCES ); |
---|
627 | |
---|
628 | printf("\n%s Should exist ( access )\n",Directories[0] ); |
---|
629 | status = access( Directories[0], F_OK ); |
---|
630 | rtems_test_assert( status == 0 ); |
---|
631 | printf("\n%s Should have read permission( access )\n",Directories[0] ); |
---|
632 | status = access( Directories[0], R_OK ); |
---|
633 | rtems_test_assert( status != 0 ); |
---|
634 | printf("\n%s Should have write permission( access )\n",Directories[0] ); |
---|
635 | status = access( Directories[0], W_OK ); |
---|
636 | rtems_test_assert( status != 0 ); |
---|
637 | printf("\n%s Should not have execute permission( access )\n",Directories[0] ); |
---|
638 | status = access( Directories[0], X_OK ); |
---|
639 | rtems_test_assert( status != 0 ); |
---|
640 | |
---|
641 | printf("\nRestore %s to RWX\n",Directories[0] ); |
---|
642 | status = chmod( Directories[0], S_IRWXU ); |
---|
643 | rtems_test_assert( status == 0 ); |
---|
644 | |
---|
645 | printf("chdir to /my_mount_point \n"); |
---|
646 | status = chdir( "/my_mount_point" ); |
---|
647 | rtems_test_assert( status == 0 ); |
---|
648 | |
---|
649 | /* |
---|
650 | * Remove one of the directories. |
---|
651 | * Verify links to the removed directory still work. |
---|
652 | */ |
---|
653 | |
---|
654 | printf( "Remove %s\n", Directories[5] ); |
---|
655 | status = rmdir( Directories[5] ); |
---|
656 | rtems_test_assert( status == 0 ); |
---|
657 | |
---|
658 | stat_a_file( Directories[5] ); |
---|
659 | status = access( Directories[5], F_OK ); |
---|
660 | rtems_test_assert( status != 0 ); |
---|
661 | |
---|
662 | stat_a_file( Links_to_Dirs[5] ); |
---|
663 | status = readlink( Links_to_Dirs[5], longer_name, 3 ); |
---|
664 | rtems_test_assert( status == -1 ); |
---|
665 | rtems_test_assert( errno == EINVAL ); |
---|
666 | |
---|
667 | stat_a_file( Links_to_dirlinks[5] ); |
---|
668 | printf("Chdir to %s\n", Links_to_Dirs[5] ); |
---|
669 | status = chdir( Links_to_Dirs[5] ); |
---|
670 | rtems_test_assert( status == 0 ); |
---|
671 | |
---|
672 | /* |
---|
673 | * Verify we cannot move up from a node with no parent node. |
---|
674 | */ |
---|
675 | |
---|
676 | printf("Chdir to .. should fail with ENOENT\n" ); |
---|
677 | status = chdir( ".." ); |
---|
678 | rtems_test_assert( status == -1 ); |
---|
679 | rtems_test_assert( errno == ENOENT ); |
---|
680 | |
---|
681 | /* |
---|
682 | * Create a subdirectory under the dangling node. |
---|
683 | */ |
---|
684 | |
---|
685 | printf("mkdir ../t should fail with ENOENT\n" ); |
---|
686 | status = mkdir( "../t" , S_IRWXU ); |
---|
687 | rtems_test_assert( status == -1 ); |
---|
688 | rtems_test_assert( errno == ENOENT ); |
---|
689 | |
---|
690 | printf("mkdir t\n"); |
---|
691 | status = mkdir( "t" , S_IRWXU ); |
---|
692 | rtems_test_assert( status == 0 ); |
---|
693 | |
---|
694 | printf("chdir to /my_mount_point\n"); |
---|
695 | status = chdir( "/my_mount_point" ); |
---|
696 | rtems_test_assert( status == 0 ); |
---|
697 | |
---|
698 | /* |
---|
699 | * Check rmdir, rmnod, and unlink |
---|
700 | */ |
---|
701 | |
---|
702 | printf("rmdir %s\n", Links_to_Dirs[5] ); |
---|
703 | status = rmdir( Links_to_Dirs[5] ); |
---|
704 | rtems_test_assert( status == 0 ); |
---|
705 | |
---|
706 | printf("unlink %s should fail with ENOTEMPTY\n", Links_to_dirlinks[5] ); |
---|
707 | status = unlink( Links_to_dirlinks[5] ); |
---|
708 | rtems_test_assert( status == -1 ); |
---|
709 | rtems_test_assert( errno == ENOTEMPTY ); |
---|
710 | |
---|
711 | strcpy( longer_name, Links_to_dirlinks[5] ); |
---|
712 | strcat( longer_name, "/t"); |
---|
713 | printf("rmdir %s\n", longer_name ); |
---|
714 | status = rmdir( longer_name ); |
---|
715 | rtems_test_assert( status == 0 ); |
---|
716 | |
---|
717 | printf("unlink %s\n", Links_to_dirlinks[5]); |
---|
718 | status = unlink( Links_to_dirlinks[5] ); |
---|
719 | rtems_test_assert( status == 0 ); |
---|
720 | |
---|
721 | status = chdir( Directories[0] ); |
---|
722 | status = mkdir ( "my_mount_point", S_IRWXU ); |
---|
723 | rtems_test_assert( status == 0 ); |
---|
724 | |
---|
725 | printf("Attempting to mount IMFS file system at /dir1/my_mount_point \n"); |
---|
726 | status = mount( |
---|
727 | "null", |
---|
728 | "/my_mount_point/dir1/my_mount_point", |
---|
729 | "imfs", |
---|
730 | RTEMS_FILESYSTEM_READ_WRITE, |
---|
731 | NULL ); |
---|
732 | rtems_test_assert( status == 0 ); |
---|
733 | |
---|
734 | printf("rmdir /dir1/my_mount_point should fail with EBUSY\n"); |
---|
735 | status = rmdir ("/my_mount_point/dir1/my_mount_point" ); |
---|
736 | rtems_test_assert( status == -1 ); |
---|
737 | rtems_test_assert( errno == EBUSY ); |
---|
738 | |
---|
739 | printf( "Unmount /my_mount_point/dir1/my_mount_point\n"); |
---|
740 | status = unmount( "/my_mount_point/dir1/my_mount_point" ); |
---|
741 | rtems_test_assert( status == 0 ); |
---|
742 | |
---|
743 | /* |
---|
744 | * Verify write permission is checked. |
---|
745 | */ |
---|
746 | |
---|
747 | printf("chmod of %s to group and other execute\n", Files[0] ); |
---|
748 | status = chmod (Files[0], (S_IXGRP | S_IXOTH) ); |
---|
749 | rtems_test_assert( status == 0 ); |
---|
750 | |
---|
751 | printf("Open %s for write should fail with EACCES\n", Files[0] ); |
---|
752 | fd = open (Files[0], O_WRONLY); |
---|
753 | rtems_test_assert( fd == -1 ); |
---|
754 | rtems_test_assert( errno == EACCES ); |
---|
755 | |
---|
756 | printf("chmod of %s to User Execute and Read\n", Directories[3] ); |
---|
757 | status = chmod (Directories[3], (S_IXUSR | S_IRUSR) ); |
---|
758 | rtems_test_assert( status == 0 ); |
---|
759 | strcpy(longer_name, Directories[3] ); |
---|
760 | strcat(longer_name, "/NewFile" ); |
---|
761 | printf("Mkdir of %s should fail with EACCES\n",longer_name ); |
---|
762 | status = mkdir( longer_name, S_IRWXU ); |
---|
763 | rtems_test_assert( status != 0 ); |
---|
764 | rtems_test_assert( errno == EACCES ); |
---|
765 | |
---|
766 | printf("Making too many hard links.\n" ); |
---|
767 | make_too_many_links( ); |
---|
768 | |
---|
769 | /* |
---|
770 | * The current directory MUST be restored at the end of this test. |
---|
771 | */ |
---|
772 | |
---|
773 | printf("chdir to /my_mount_point \n"); |
---|
774 | status = chdir( "/my_mount_point" ); |
---|
775 | rtems_test_assert( status == 0 ); |
---|
776 | |
---|
777 | } |
---|
778 | |
---|
779 | void Show_Time(void) |
---|
780 | { |
---|
781 | rtems_status_code sc; |
---|
782 | rtems_time_of_day time; |
---|
783 | |
---|
784 | sc = rtems_clock_get_tod( &time ); |
---|
785 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
786 | printf("--->Current Time: "); |
---|
787 | print_time( " - rtems_clock_get_tod - ", &time, "\n" ); |
---|
788 | } |
---|
789 | |
---|
790 | void test_statvfs(void) |
---|
791 | { |
---|
792 | |
---|
793 | int status = 0; |
---|
794 | struct statvfs stat; |
---|
795 | |
---|
796 | puts( "statvfs, with invalid path - expect ENOENT" ); |
---|
797 | status = statvfs( "" , &stat ); |
---|
798 | rtems_test_assert( status == -1 ); |
---|
799 | rtems_test_assert( errno == ENOENT ); |
---|
800 | |
---|
801 | puts( "create /tmp -- OK" ); |
---|
802 | status = mkdir( "/tmp", 0777 ); |
---|
803 | rtems_test_assert( status == 0 ); |
---|
804 | |
---|
805 | puts( "statvfs, with valid path - expect ENOSYS" ); |
---|
806 | status = statvfs( "/tmp", &stat ); |
---|
807 | rtems_test_assert( status == -1 ); |
---|
808 | rtems_test_assert( errno == ENOSYS ); |
---|
809 | |
---|
810 | puts( "statvfs tested!" ); |
---|
811 | } |
---|
812 | |
---|
813 | /* |
---|
814 | * main entry point to the test |
---|
815 | */ |
---|
816 | |
---|
817 | #if defined(__rtems__) |
---|
818 | int test_main(void) |
---|
819 | #else |
---|
820 | int main( |
---|
821 | int argc, |
---|
822 | char **argv |
---|
823 | ) |
---|
824 | #endif |
---|
825 | { |
---|
826 | rtems_status_code sc; |
---|
827 | rtems_time_of_day time; |
---|
828 | int status; |
---|
829 | |
---|
830 | TEST_BEGIN(); |
---|
831 | |
---|
832 | build_time( &time, 12, 31, 1988, 9, 0, 0, 0 ); |
---|
833 | sc = rtems_clock_set( &time ); |
---|
834 | Show_Time(); |
---|
835 | |
---|
836 | /* |
---|
837 | * Create and mount another version of the filesyste. |
---|
838 | * This allows expected node id's to be consistant across |
---|
839 | * platforms and bsp's. |
---|
840 | */ |
---|
841 | |
---|
842 | status = mkdir("/my_mount_point", S_IRWXU ); |
---|
843 | rtems_test_assert( status == 0 ); |
---|
844 | status = mount( |
---|
845 | "null", |
---|
846 | "my_mount_point", |
---|
847 | "imfs", |
---|
848 | RTEMS_FILESYSTEM_READ_WRITE, |
---|
849 | NULL ); |
---|
850 | rtems_test_assert( status == 0 ); |
---|
851 | status = chdir( "/my_mount_point" ); |
---|
852 | rtems_test_assert( status == 0 ); |
---|
853 | status = mkdir("dev", S_IRWXU ); |
---|
854 | rtems_test_assert( status == 0 ); |
---|
855 | |
---|
856 | |
---|
857 | /* |
---|
858 | * Create the files and directories for the test. |
---|
859 | */ |
---|
860 | |
---|
861 | make_multiple_directories( Directories ); |
---|
862 | make_multiple_files( Files ); |
---|
863 | make_multiple_links( Directories, Links_to_Dirs ); |
---|
864 | make_multiple_links( Files, Links_to_Files ); |
---|
865 | |
---|
866 | sc = rtems_task_wake_after( TIMEOUT_VALUE ); |
---|
867 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
868 | make_multiple_links( Links_to_Dirs, Links_to_dirlinks ); |
---|
869 | sc = rtems_task_wake_after( TIMEOUT_VALUE ); |
---|
870 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
871 | make_multiple_links( Links_to_Files, Links_to_filelinks ); |
---|
872 | |
---|
873 | sc = rtems_task_wake_after( TIMEOUT_VALUE ); |
---|
874 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
875 | |
---|
876 | /* |
---|
877 | * Now go through all the absolute path. |
---|
878 | */ |
---|
879 | |
---|
880 | puts( "Doing the stat() on all the good absolute paths" ); |
---|
881 | stat_multiple_files( Good_absolute_paths ); |
---|
882 | |
---|
883 | /* |
---|
884 | * run through the relative paths. |
---|
885 | */ |
---|
886 | |
---|
887 | puts( "\nDoing the stat() on all the good relative paths" ); |
---|
888 | stat_multiple_files( Good_relative_paths ); |
---|
889 | |
---|
890 | /* |
---|
891 | * Change directory and releative paths are now bad. |
---|
892 | */ |
---|
893 | |
---|
894 | puts("\nchdir to dev"); |
---|
895 | chdir("dev"); |
---|
896 | puts("\nstat relative paths that are now bad"); |
---|
897 | stat_multiple_files( Good_relative_paths ); |
---|
898 | |
---|
899 | /* |
---|
900 | * Change directory to the link directory and follow links. |
---|
901 | */ |
---|
902 | |
---|
903 | puts("\nchdir to ../links"); |
---|
904 | chdir("../links"); |
---|
905 | puts("Doing the stat() on good links\n"); |
---|
906 | stat_multiple_files( Links_to_Dirs ); |
---|
907 | stat_multiple_files( Links_to_Files ); |
---|
908 | stat_multiple_files( Links_to_dirlinks ); |
---|
909 | stat_multiple_files( Links_to_filelinks ); |
---|
910 | |
---|
911 | /* |
---|
912 | * Chmod on dir1/dir1. This allows the error path to be hit. |
---|
913 | */ |
---|
914 | |
---|
915 | printf( "chmod of %s to Read/Write\n", Directories[4] ); |
---|
916 | chmod( Directories[4], (S_IROTH|S_IWOTH) ); |
---|
917 | puts( "\nDoing the stat() on all the bad paths" ); |
---|
918 | |
---|
919 | stat_multiple_files( Bad_paths ); |
---|
920 | make_multiple_bad_files( Bad_paths ); |
---|
921 | |
---|
922 | printf( "Return %s to RWX\n", Directories[4] ); |
---|
923 | chmod( Directories[4], S_IRWXU ); |
---|
924 | |
---|
925 | |
---|
926 | /* |
---|
927 | * Check out symbolic links. |
---|
928 | */ |
---|
929 | |
---|
930 | make_multiple_symlinks(); |
---|
931 | make_many_symlinks( "/symlinks", 10 ); |
---|
932 | |
---|
933 | sc = rtems_task_wake_after( TIMEOUT_VALUE ); |
---|
934 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
935 | Cause_faults(); |
---|
936 | |
---|
937 | sc = rtems_task_wake_after( TIMEOUT_VALUE ); |
---|
938 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
939 | chown_multiple_files( Files ); |
---|
940 | |
---|
941 | sc = rtems_task_wake_after( TIMEOUT_VALUE ); |
---|
942 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
943 | chown_multiple_files( Links_to_Dirs ); |
---|
944 | |
---|
945 | sc = rtems_task_wake_after( TIMEOUT_VALUE ); |
---|
946 | rtems_test_assert( sc == RTEMS_SUCCESSFUL ); |
---|
947 | lchown_multiple_files( SymLinks ); |
---|
948 | |
---|
949 | test_statvfs(); |
---|
950 | |
---|
951 | TEST_END(); |
---|
952 | rtems_test_exit(0); |
---|
953 | } |
---|