source: rtems/testsuites/psxtests/psxstat/test.c @ e0bc543

4.115
Last change on this file since e0bc543 was a3ca5f36, checked in by Sebastian Huber <sebastian.huber@…>, on 04/15/11 at 14:21:19

2011-04-15 Sebastian Huber <Sebastian.Huber@…>

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