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

4.115
Last change on this file since acec386 was acec386, checked in by Sebastian Huber <sebastian.huber@…>, on 11/22/12 at 16:28:41

Filesystem: PR1619: Use ENOSYS for default statvfs

POSIX does not specify an error number in case the file system does not
support this call. Use the Linux value.

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