Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:40

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  *  @file
0005  *
0006  *  This test exercises stat() via fstat() and generates as many of the
0007  *  path evaluation cases as possible.
0008  *
0009  *  This test also exercises lstat() and lchown() when symlinks are
0010  *  involved.
0011  */
0012 
0013 /*
0014  *  COPYRIGHT (c) 1989-2012.
0015  *  On-Line Applications Research Corporation (OAR).
0016  *
0017  * Redistribution and use in source and binary forms, with or without
0018  * modification, are permitted provided that the following conditions
0019  * are met:
0020  * 1. Redistributions of source code must retain the above copyright
0021  *    notice, this list of conditions and the following disclaimer.
0022  * 2. Redistributions in binary form must reproduce the above copyright
0023  *    notice, this list of conditions and the following disclaimer in the
0024  *    documentation and/or other materials provided with the distribution.
0025  *
0026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0036  * POSSIBILITY OF SUCH DAMAGE.
0037  */
0038 
0039 #ifdef HAVE_CONFIG_H
0040 #include "config.h"
0041 #endif
0042 
0043 #include <tmacros.h>
0044 #include <sys/stat.h>
0045 #include <fcntl.h>
0046 #include <limits.h>
0047 #include <stdio.h>
0048 #include <unistd.h>
0049 #include <errno.h>
0050 #include <string.h>
0051 #include <reent.h>
0052 #include <rtems.h>
0053 #include <rtems/libio.h>
0054 #include <rtems/imfs.h>
0055 #include <pmacros.h>
0056 
0057 #include "primode.h"
0058 
0059 const char rtems_test_name[] = "PSXSTAT";
0060 
0061 /* forward declarations to avoid warnings */
0062 int test_main(void);
0063 void stat_a_file_helper(const char *file, int follow_link);
0064 void stat_a_file(const char *file);
0065 void lstat_a_file(const char *file);
0066 void stat_multiple_files(char **files);
0067 void chown_multiple_files_helper(char **files, int follow_link);
0068 void chown_multiple_files(char **files);
0069 void lchown_multiple_files(char **files);
0070 void make_multiple_files(char **files);
0071 void make_multiple_bad_files(char **files);
0072 void make_multiple_links(char **existing, char **new);
0073 void make_too_many_links(void);
0074 void make_a_symlink(char *existing, char *new);
0075 void make_multiple_symlinks(void);
0076 void make_many_symlinks(char  *real_file, int link_count);
0077 void make_multiple_directories(char **files);
0078 void Cause_faults(void);
0079 void Show_Time(void);
0080 void test_statvfs(void);
0081 
0082 #define MAXSYMLINK 5   /* There needs to be a better way of getting this. */
0083 #define TIMEOUT_VALUE  ( 5 * rtems_clock_get_ticks_per_second() )
0084 
0085 int _lstat_r(struct _reent *, const char *, struct stat *);
0086 
0087 /*
0088  *  List of files which should exist.
0089  */
0090 
0091 char *Files[] = {
0092   "/////my_mount_point/dir1/\\//file1",
0093   "/my_mount_point/dir1/file2",
0094   "/my_mount_point/dir1/file3",
0095   "/my_mount_point/dir1/file4",
0096   "/my_mount_point/dir1/dir1/file1",
0097   "../../..//my_mount_point/dir1/./././dir1/ file1",
0098   "main.c",
0099   0
0100 };
0101 
0102 /*
0103  *  List of directories which should exist.
0104  */
0105 
0106 char *Directories[] = {
0107   "/my_mount_point/dir1\\\\//",
0108   "/my_mount_point/dir2",
0109   "/my_mount_point/dir3",
0110   "/my_mount_point/dir4",
0111   "/my_mount_point/dir1/dir1",
0112   "/./././my_mount_point/dir1/ dir1",
0113   "/./././my_mount_point/links",
0114   "///my_mount_point/dir1/dir1/../../dir1/../symlinks/////",
0115   0
0116 };
0117 
0118 char *Links_to_Dirs[]= {
0119   "dir1/dir1/../../links/dir1",
0120   "links/dir2",
0121   "links/dir3",
0122   "links/dir4",
0123   "links/dir1_dir1",
0124   "links/dir1_ dir1",
0125   "links/../links/../links/links",
0126   0
0127 };
0128 
0129 char *Links_to_Files[]= {
0130   "links/dir1_file1",
0131   "links/dir1_file2",
0132   "links/dir1_file3",
0133   "links/dir1_file4",
0134   "links/dir1_dir1_f1",
0135   "links/dir1_dir1 f1",
0136   0
0137 };
0138 
0139 char *Links_to_dirlinks[]= {
0140   "links/links/links/links_dir1",
0141   "links//links_dir2",
0142   "links//links_dir3",
0143   "links//links_dir4",
0144   "links//links_dir1_d1",
0145   "links//links_dir1 d1",
0146   "links//links_links",
0147   0
0148 };
0149 
0150 char *Links_to_filelinks[]= {
0151   "links///links_d1_file1",
0152   "links///links_d1_file2",
0153   "links///links_d1_file3",
0154   "links///links_d1_file4",
0155   "links///links_d1_d1_f1",
0156   "links///links_r1_d1 f1",
0157   0
0158 };
0159 
0160 char *SymLinks[]= {
0161   "/my_mount_point/symlinks/a_file_symlink",
0162   "/my_mount_point/symlinks/a_dir_symlink",
0163   "/my_mount_point/symlinks/a_link_symlink",
0164   "../symlinks/no_file",
0165   "/my_mount_point/symlinks/a_dir_symlink/a_file_symlink",
0166   0
0167 };
0168 
0169 /*
0170  *  List of absolute paths to stat.
0171  */
0172 
0173 char *Good_absolute_paths[] = {
0174   "/my_mount_point/dev",
0175   "////my_mount_point/dir1/\\//file1\\\\//",
0176   "/my_mount_point/dir1/\\\\/file2",
0177   "/my_mount_point/dir1/file3/////\\\\\\",
0178   "/my_mount_point/dir1/file4",
0179   "/my_mount_point/dir1/dir1/file1",
0180   "/my_mount_point/dir1/dir1/ file1",
0181   "/my_mount_point/dir1",
0182   "/my_mount_point/dir2//////\\",
0183   "/my_mount_point/dir3",
0184   "/my_mount_point/dir4",
0185   "/my_mount_point/dir1/dir1",
0186   "/my_mount_point/dir1/ dir1///\\\\",
0187   "/my_mount_point/\\/\\/\\/\\/\\/\\/links\\/\\/\\/\\/\\/\\",
0188   0
0189 };
0190 
0191 
0192 char *Bad_paths[] = {
0193   "/my_mount_point/links/ENAMETOOLONG________________________________________"
0194   "__________________________________________________________________________"
0195   "__________________________________________________________________________"
0196   "__________________________________________________________________________"
0197   "______________________________________",
0198   "/my_mount_point/dir1/file4/NOTADIR",
0199   "/my_mount_point/dir1/dir1/EACCES__",
0200   0
0201 };
0202 
0203 /*
0204  *  List of relative paths to stat.
0205  */
0206 
0207 char *Good_relative_paths[] = {
0208   "dev",
0209   "dir1/\\//file1\\\\//",
0210   "dir1/\\\\/file2",
0211   "dir1/file3/////\\\\\\",
0212   "dir1/file4",
0213   "dir1/dir1/file1",
0214   "dir1/dir1/ file1",
0215   "dir1",
0216   "dir2//////\\",
0217   "dir3",
0218   "dir4",
0219   "dir1/dir1",
0220   "dir1/ dir1///\\\\",
0221   "main.c",
0222   0
0223 };
0224 
0225 /*
0226  *  Do a stat/lstat on a single file and report the status.
0227  */
0228 void stat_a_file_helper(
0229   const char *file,
0230   int         follow_link
0231 )
0232 {
0233   int         status;
0234   struct stat statbuf;
0235   int         major1;
0236   int         minor1;
0237   int         major2;
0238   int         minor2;
0239 
0240 
0241   rtems_test_assert( file );
0242 
0243   if ( follow_link ) {
0244     printf( "stat( %s ) returned ", file );
0245     fflush( stdout );
0246     status = stat( file, &statbuf );
0247   } else {
0248     printf( "lstat( %s ) returned ", file );
0249     fflush( stdout );
0250     status = lstat( file, &statbuf );
0251   }
0252 
0253   if ( status == -1 ) {
0254     printf( ": %s\n", strerror( errno ) );
0255   } else {
0256 
0257     rtems_filesystem_split_dev_t( statbuf.st_dev, major1, minor1 );
0258     rtems_filesystem_split_dev_t( statbuf.st_rdev, major2, minor2 );
0259 
0260 
0261     printf("\n...st_dev     (0x%x:0x%x)\n", major1, minor1 );
0262     printf(  "...st_ino     %" PRIxino_t "\n", statbuf.st_ino );
0263     printf(  "...st_mode    %" PRIomode_t "\n", statbuf.st_mode );
0264     printf(  "...st_nlink   %x\n", statbuf.st_nlink );
0265     printf(  "...st_uid     %d\n", statbuf.st_uid );
0266     printf(  "...st_gid     %d\n", statbuf.st_gid );
0267     printf(  "...st_rdev    (0x%x:0x%x)\n", major2, minor2 );
0268     printf(  "...st_size    %" PRIdoff_t "\n", statbuf.st_size );
0269     printf(  "...st_atime   %s", ctime( &statbuf.st_atime ) );
0270     printf(  "...st_mtime   %s", ctime( &statbuf.st_mtime ) );
0271     printf(  "...st_ctime   %s", ctime( &statbuf.st_ctime ) );
0272     printf(  "...st_blksize %" PRIxblksize_t "\n", statbuf.st_blksize );
0273     printf(  "...st_blocks  %" PRIxblkcnt_t "\n", statbuf.st_blocks );
0274   }
0275 }
0276 
0277 /*
0278  *  Do a stat on a single file and report the status.
0279 */
0280 void stat_a_file(
0281   const char *file
0282 )
0283 {
0284   stat_a_file_helper( file, true );
0285 }
0286 
0287 /*
0288  *  Do a lstat on a single file and report the status.
0289  */
0290 void lstat_a_file(
0291   const char *file
0292 )
0293 {
0294   stat_a_file_helper( file, false );
0295 }
0296 
0297 /*
0298  *  stat() multiple files at a time
0299  */
0300 void stat_multiple_files(
0301   char **files
0302 )
0303 {
0304   int    i;
0305 
0306   i = 0;
0307   while ( files[i] ) {
0308     stat_a_file( files[i] );
0309     i++;
0310   }
0311 }
0312 
0313 /*
0314  *  chown()/lchown() multiple files at a time
0315  */
0316 void chown_multiple_files_helper(
0317   char **files,
0318   int    follow_link
0319 )
0320 {
0321   int    i;
0322   uid_t  st_uid;
0323   gid_t  st_gid;
0324 
0325   st_uid = geteuid();
0326   st_gid = getegid();
0327 
0328   i = 0;
0329   while ( files[i] ) {
0330     printf("Change group of %s\n", files[i]);
0331     if ( follow_link ) {
0332       chown( files[i], st_uid, (st_gid+1) );
0333       stat_a_file( files[i] );
0334     } else {
0335       lchown( files[i], st_uid, (st_gid+1) );
0336       lstat_a_file( files[i] );
0337     }
0338 
0339     printf("Change owner of %s\n", files[i]);
0340     if ( follow_link ) {
0341       chown( files[i], (st_uid+1), st_gid );
0342       stat_a_file( files[i] );
0343     } else {
0344       lchown( files[i], (st_uid+1), st_gid );
0345       lstat_a_file( files[i] );
0346     }
0347     i++;
0348   }
0349 
0350 }
0351 
0352 /*
0353  *  chown() multiple files at a time
0354  */
0355 void chown_multiple_files(
0356   char **files
0357 )
0358 {
0359   chown_multiple_files_helper( files, true );
0360 }
0361 
0362 /*
0363  *  lchown() multiple files at a time
0364  */
0365 void lchown_multiple_files(
0366   char **files
0367 )
0368 {
0369   chown_multiple_files_helper( files, false );
0370 }
0371 
0372 /*
0373  *  mknod() multiple files at a time
0374  */
0375 void make_multiple_files(
0376   char **files
0377 )
0378 {
0379   int    i;
0380   int    status;
0381 
0382   i = 0;
0383   while ( files[i] ) {
0384     printf( "Making file %s\n", files[i] );
0385     status = mknod( files[i], ( S_IFREG | S_IROTH|S_IWOTH ), 0LL );
0386     rtems_test_assert( !status );
0387     i++;
0388   }
0389   puts( "" );
0390 }
0391 
0392 void make_multiple_bad_files(
0393   char **files
0394 )
0395 {
0396   int    i;
0397   int    status;
0398 
0399   i = 0;
0400   while ( files[i] ) {
0401     printf( "Making file %s ", files[i] );
0402     status = mknod( files[i], ( S_IFREG | S_IROTH|S_IWOTH ), 0LL );
0403     rtems_test_assert( status );
0404     printf( ": %s\n", strerror( errno ) );
0405     i++;
0406   }
0407   puts( "" );
0408 }
0409 
0410 void make_multiple_links(
0411   char **existing,
0412   char **new
0413 )
0414 {
0415   int    i;
0416   int    status;
0417 
0418   i = 0;
0419   while ( new[i] && existing[i] ) {
0420     printf( "Making file %s\n", new[i] );
0421     status = link( existing[i], new[i] );
0422     rtems_test_assert( !status );
0423     i++;
0424   }
0425   puts( "" );
0426 
0427   status = link( "fred", "bob" );
0428   rtems_test_assert( status == -1 );
0429 
0430   status = link( existing[1], "doug/bob" );
0431   rtems_test_assert( status == -1 );
0432 }
0433 
0434 void make_too_many_links(void)
0435 {
0436   int    i;
0437   int    status;
0438   char   name [20];
0439 
0440   status = mkdir("/dummy", S_IRWXU );
0441   rtems_test_assert( status == 0 );
0442 
0443   for (i=1; i<= LINK_MAX; i++) {
0444 
0445     sprintf(name,"/LinkName%d",i);
0446     printf( "Making file %s\n", name );
0447     status = link("/dummy" , name );
0448     if( i < LINK_MAX )
0449        rtems_test_assert( !status );
0450     else
0451        rtems_test_assert( status == -1 );
0452 
0453   }
0454 }
0455 
0456 void make_a_symlink(
0457   char *existing,
0458   char *new
0459 )
0460 {
0461   int    status;
0462   char   buf[100];
0463   int    len;
0464 
0465   memset( buf, 0, 100 );
0466 
0467   printf( "Making file %s\n", new );
0468   status = symlink( existing, new );
0469   rtems_test_assert( !status );
0470 
0471   printf( "Verify with readlink\n");
0472   status = readlink( new, buf, 100 );
0473   len = strlen( existing );
0474   rtems_test_assert ( status == len );
0475 
0476   status = readlink( new, buf, 3 );
0477   len = strlen( existing );
0478   if (len < 3 )
0479     rtems_test_assert( status == len );
0480   else
0481     rtems_test_assert( status == 3 );
0482 
0483   status = strcmp( existing, buf );
0484   rtems_test_assert( !status );
0485 }
0486 
0487 void make_multiple_symlinks(void)
0488 {
0489  int  status, i;
0490 
0491  make_a_symlink( Files[0],             SymLinks[0] );
0492  make_a_symlink( Directories[0],       SymLinks[1] );
0493  make_a_symlink( Links_to_dirlinks[0], SymLinks[2] );
0494  make_a_symlink( "No_File",            SymLinks[3] );
0495  make_a_symlink( SymLinks[1],          SymLinks[4] );
0496  make_a_symlink( "//my_mount_point/links","/my_mount_point/symlinks/links" );
0497 
0498  for (i = 0; i < 5; i++) {
0499    stat_a_file( SymLinks[i] );
0500    lstat_a_file( SymLinks[i] );
0501  }
0502 
0503  status = symlink(  "//links", "bob/frank" );
0504  rtems_test_assert (status == -1);
0505 
0506 }
0507 /*
0508 void make_too_many_symlinks()
0509 {
0510   int  i, status;
0511   char name1[8];
0512 
0513   for (i=1; i <= MAXSYMLINK; i++) {
0514     sprintf( name1, "SymLink%d", i );
0515     status = symlink( "/dummy", name1 );
0516     if( i < MAXSYMLINK )
0517        rtems_test_assert( !status );
0518     else
0519        rtems_test_assert( status == -1 );
0520   }
0521 }
0522 */
0523 
0524 void make_many_symlinks(
0525   char  *real_file,
0526   int    link_count
0527 )
0528 {
0529   int  i;
0530   char name1[32];
0531   char name2[32];
0532   char *link_file;
0533 
0534   /* limit the link_count to ensure filename buffer doesn't overflow */
0535   rtems_test_assert( link_count < 1000 );
0536 
0537   link_file = real_file;
0538   for (i=1; i < link_count; i++) {
0539     sprintf( name1, "%04d", i );
0540     make_a_symlink( link_file, name1 );
0541     strcpy( name2, name1 );
0542     link_file = name2;
0543   }
0544 
0545   for (i=1; i < link_count; i++) {
0546     sprintf( name1, "%04d", i );
0547     stat_a_file( name1 );
0548     lstat_a_file( name1 );
0549   }
0550 
0551 }
0552 
0553 /*
0554  *  mkdir() multiple directories at a time
0555  */
0556 void make_multiple_directories(
0557   char **files
0558 )
0559 {
0560   int    i;
0561   int    status;
0562 
0563   i = 0;
0564   while ( files[i] ) {
0565     printf( "Making directory %s\n", files[i] );
0566     status = mkdir( files[i], S_IRWXU );
0567     rtems_test_assert( !status );
0568     i++;
0569   }
0570   puts( "" );
0571 }
0572 
0573 /*
0574  * Cause faults.
0575  */
0576 void Cause_faults(void)
0577 {
0578   int                                   fd;
0579   int                                   status;
0580   char                                  longer_name[100];
0581 
0582   /*
0583    * Verify chmod with an invalid type.
0584    */
0585 
0586 #if 0
0587   status = chmod( Files[0], S_IFREG );
0588   rtems_test_assert( status == -1 );
0589   rtems_test_assert( errno == EPERM );
0590 #endif
0591 
0592   /*
0593    * Change file to executable then try to chdir to it.
0594    */
0595 
0596   status = chmod( Files[0], S_IXUSR );
0597   rtems_test_assert( status != -1 );
0598 
0599   printf("chdir to a file should fail with ENOTDIR\n");
0600   status = chdir( Files[0] );
0601   rtems_test_assert( status == -1 );
0602   rtems_test_assert( errno == ENOTDIR );
0603 
0604   /*
0605    * Change mode to read/write on a directory.
0606    * Verify directory works properly.
0607    */
0608 
0609   printf("Verify RWX permission on %s via access\n", Directories[0]);
0610   status = access( Directories[0], ( R_OK | W_OK | X_OK )  );
0611   rtems_test_assert( status == 0 );
0612 
0613   printf( "chmod of %s to Read/Write\n", Directories[0] );
0614   status = chmod( Directories[0], (S_IXGRP | S_IXOTH) );
0615   rtems_test_assert( status == 0 );
0616 
0617   printf( "chmod fred should fail with ENOENT\n" );
0618   status = chmod( "fred", (S_IXGRP | S_IXOTH) );
0619   rtems_test_assert( status == -1 );
0620   rtems_test_assert( errno == ENOENT );
0621 
0622   strcpy(longer_name, Directories[0] );
0623   strcat(longer_name, "/BADNAME" );
0624   printf( "Create under %s should fail with EACCES\n", Directories[0] );
0625   status = mkdir( longer_name , S_IRWXU );
0626   rtems_test_assert( status == -1 );
0627   rtems_test_assert( errno == EACCES );
0628 
0629   printf("chdir to %s should fail with EACCES\n", Directories[4] );
0630   status = chdir( Directories[4] );
0631   rtems_test_assert( status == -1 );
0632   rtems_test_assert( errno == EACCES );
0633 
0634   /*
0635    * Set current to a directory with no owner permissions.
0636    * Verify it works properly.
0637    */
0638 
0639   status = chmod( Directories[0], (S_IXGRP | S_IXOTH) );
0640   rtems_test_assert( status == 0 );
0641 
0642   printf("mkdir %s should fail with EACCESS\n", longer_name );
0643   status = mkdir( longer_name , S_IRWXU );
0644   rtems_test_assert( status == -1 );
0645   rtems_test_assert( errno == EACCES );
0646 
0647   printf("\n%s Should exist ( access )\n",Directories[0] );
0648   status = access( Directories[0], F_OK );
0649   rtems_test_assert( status == 0 );
0650   printf("\n%s Should have read  permission( access )\n",Directories[0] );
0651   status = access( Directories[0], R_OK );
0652   rtems_test_assert( status != 0 );
0653   printf("\n%s Should have write permission( access )\n",Directories[0] );
0654   status = access( Directories[0], W_OK );
0655   rtems_test_assert( status != 0 );
0656   printf("\n%s Should not have execute permission( access )\n",Directories[0] );
0657   status = access( Directories[0], X_OK );
0658   rtems_test_assert( status != 0 );
0659 
0660   printf("\nRestore %s to RWX\n",Directories[0] );
0661   status = chmod( Directories[0], S_IRWXU );
0662   rtems_test_assert( status == 0 );
0663 
0664   printf("chdir to /my_mount_point \n");
0665   status = chdir( "/my_mount_point" );
0666   rtems_test_assert( status == 0 );
0667 
0668   /*
0669    * Remove one of the directories.
0670    * Verify links to the removed directory still work.
0671    */
0672 
0673   printf( "Remove %s\n", Directories[5] );
0674   status = rmdir( Directories[5] );
0675   rtems_test_assert( status == 0 );
0676 
0677   stat_a_file( Directories[5] );
0678   status = access( Directories[5], F_OK );
0679   rtems_test_assert( status != 0 );
0680 
0681   stat_a_file( Links_to_Dirs[5] );
0682   status = readlink( Links_to_Dirs[5], longer_name, 3 );
0683   rtems_test_assert( status == -1 );
0684   rtems_test_assert( errno == EINVAL );
0685 
0686   stat_a_file( Links_to_dirlinks[5] );
0687   printf("Chdir to %s\n", Links_to_Dirs[5] );
0688   status = chdir( Links_to_Dirs[5] );
0689   rtems_test_assert( status == 0 );
0690 
0691   /*
0692    * Verify we cannot move up from a node with no parent node.
0693    */
0694 
0695   printf("Chdir to .. should fail with ENOENT\n" );
0696   status = chdir( ".." );
0697   rtems_test_assert( status == -1 );
0698   rtems_test_assert( errno == ENOENT );
0699 
0700   /*
0701    * Create a subdirectory under the dangling node.
0702    */
0703 
0704   printf("mkdir ../t should fail with ENOENT\n" );
0705   status = mkdir( "../t" , S_IRWXU );
0706   rtems_test_assert( status == -1 );
0707   rtems_test_assert( errno == ENOENT );
0708 
0709   printf("mkdir t\n");
0710   status = mkdir( "t" , S_IRWXU );
0711   rtems_test_assert( status == 0 );
0712 
0713   printf("chdir to /my_mount_point\n");
0714   status = chdir( "/my_mount_point" );
0715   rtems_test_assert( status == 0 );
0716 
0717   /*
0718    * Check rmdir, rmnod, and unlink
0719    */
0720 
0721   printf("rmdir %s\n", Links_to_Dirs[5] );
0722   status = rmdir( Links_to_Dirs[5] );
0723   rtems_test_assert( status == 0 );
0724 
0725   printf("unlink %s should fail with ENOTEMPTY\n", Links_to_dirlinks[5] );
0726   status = unlink(  Links_to_dirlinks[5] );
0727   rtems_test_assert( status == -1 );
0728   rtems_test_assert( errno == ENOTEMPTY );
0729 
0730   strcpy( longer_name,  Links_to_dirlinks[5] );
0731   strcat( longer_name, "/t");
0732   printf("rmdir %s\n", longer_name );
0733   status = rmdir( longer_name );
0734   rtems_test_assert( status == 0 );
0735 
0736   printf("unlink %s\n", Links_to_dirlinks[5]);
0737   status = unlink( Links_to_dirlinks[5] );
0738   rtems_test_assert( status == 0 );
0739 
0740   status = chdir( Directories[0] );
0741   status = mkdir ( "my_mount_point", S_IRWXU );
0742   rtems_test_assert( status == 0 );
0743 
0744   printf("Attempting to mount IMFS file system at /dir1/my_mount_point \n");
0745   status = mount(
0746     "null",
0747     "/my_mount_point/dir1/my_mount_point",
0748     "imfs",
0749      RTEMS_FILESYSTEM_READ_WRITE,
0750      NULL );
0751   rtems_test_assert( status == 0 );
0752 
0753   printf("rmdir /dir1/my_mount_point should fail with EBUSY\n");
0754   status = rmdir ("/my_mount_point/dir1/my_mount_point" );
0755   rtems_test_assert( status == -1 );
0756   rtems_test_assert( errno == EBUSY );
0757 
0758   printf( "Unmount /my_mount_point/dir1/my_mount_point\n");
0759   status = unmount( "/my_mount_point/dir1/my_mount_point" );
0760   rtems_test_assert( status == 0 );
0761 
0762   /*
0763    * Verify write permission is checked.
0764    */
0765 
0766   printf("chmod of %s to group and other execute\n", Files[0] );
0767   status = chmod (Files[0], (S_IXGRP | S_IXOTH) );
0768   rtems_test_assert( status == 0 );
0769 
0770   printf("Open %s for write should fail with EACCES\n", Files[0] );
0771   fd = open (Files[0], O_WRONLY);
0772   rtems_test_assert( fd == -1 );
0773   rtems_test_assert( errno == EACCES );
0774 
0775   printf("chmod of %s to User Execute and Read\n", Directories[3] );
0776   status = chmod (Directories[3], (S_IXUSR | S_IRUSR) );
0777   rtems_test_assert( status == 0 );
0778   strcpy(longer_name, Directories[3] );
0779   strcat(longer_name, "/NewFile" );
0780   printf("Mkdir of %s should fail with EACCES\n",longer_name );
0781   status = mkdir( longer_name, S_IRWXU );
0782   rtems_test_assert( status != 0 );
0783   rtems_test_assert( errno == EACCES );
0784 
0785   printf("Making too many hard links.\n" );
0786   make_too_many_links( );
0787 
0788   /*
0789    * The current directory MUST be restored at the end of this test.
0790    */
0791 
0792   printf("chdir to /my_mount_point \n");
0793   status = chdir( "/my_mount_point" );
0794   rtems_test_assert( status == 0 );
0795 
0796 }
0797 
0798 void Show_Time(void)
0799 {
0800   rtems_status_code sc;
0801   rtems_time_of_day time;
0802 
0803   sc = rtems_clock_get_tod( &time );
0804   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0805   printf("--->Current Time: ");
0806   print_time( " - rtems_clock_get_tod - ", &time, "\n" );
0807 }
0808 
0809 void test_statvfs(void)
0810 {
0811 
0812   int status = 0;
0813   struct statvfs stat;
0814 
0815   puts( "statvfs, with invalid path - expect ENOENT" );
0816   status = statvfs( "" , &stat );
0817   rtems_test_assert( status == -1 );
0818   rtems_test_assert( errno == ENOENT );
0819 
0820   puts( "create /tmp -- OK" );
0821   status = mkdir( "/tmp", 0777 );
0822   rtems_test_assert( status == 0 );
0823 
0824   puts( "statvfs, with valid path - expect ENOSYS" );
0825   status = statvfs( "/tmp", &stat );
0826   rtems_test_assert( status == -1 );
0827   rtems_test_assert( errno == ENOSYS );
0828 
0829   puts( "statvfs tested!" );
0830 }
0831 
0832 /*
0833  *  main entry point to the test
0834  */
0835 
0836 #if defined(__rtems__)
0837 int test_main(void)
0838 #else
0839 int main(
0840   int    argc,
0841   char **argv
0842 )
0843 #endif
0844 {
0845   rtems_status_code sc;
0846   rtems_time_of_day time;
0847   int status;
0848 
0849   TEST_BEGIN();
0850 
0851   build_time( &time, 12, 31, 1988, 9, 0, 0, 0 );
0852   sc = rtems_clock_set( &time );
0853   Show_Time();
0854 
0855   /*
0856    * Create and mount another version of the filesyste.
0857    * This allows expected node id's to be consistant across
0858    * platforms and bsp's.
0859    */
0860 
0861   status = mkdir("/my_mount_point",  S_IRWXU );
0862   rtems_test_assert( status == 0 );
0863   status = mount(
0864     "null",
0865     "my_mount_point",
0866     "imfs",
0867      RTEMS_FILESYSTEM_READ_WRITE,
0868      NULL );
0869   rtems_test_assert( status == 0 );
0870   status = chdir( "/my_mount_point" );
0871   rtems_test_assert( status == 0 );
0872   status = mkdir("dev",  S_IRWXU );
0873   rtems_test_assert( status == 0 );
0874 
0875 
0876   /*
0877    *  Create the files and directories for the test.
0878    */
0879 
0880   make_multiple_directories( Directories );
0881   make_multiple_files( Files );
0882   make_multiple_links( Directories,    Links_to_Dirs );
0883   make_multiple_links( Files,          Links_to_Files );
0884 
0885   sc = rtems_task_wake_after( TIMEOUT_VALUE );
0886   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0887   make_multiple_links( Links_to_Dirs,  Links_to_dirlinks );
0888   sc = rtems_task_wake_after( TIMEOUT_VALUE );
0889   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0890   make_multiple_links( Links_to_Files, Links_to_filelinks );
0891 
0892   sc = rtems_task_wake_after( TIMEOUT_VALUE );
0893   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0894 
0895   /*
0896    *  Now go through all the absolute path.
0897    */
0898 
0899   puts( "Doing the stat() on all the good absolute paths" );
0900   stat_multiple_files( Good_absolute_paths );
0901 
0902   /*
0903    *  run through the relative paths.
0904    */
0905 
0906   puts( "\nDoing the stat() on all the good relative paths" );
0907   stat_multiple_files( Good_relative_paths );
0908 
0909   /*
0910    * Change directory and releative paths are now bad.
0911    */
0912 
0913   puts("\nchdir to dev");
0914   chdir("dev");
0915   puts("\nstat relative paths that are now bad");
0916   stat_multiple_files( Good_relative_paths );
0917 
0918   /*
0919    * Change directory to the link directory and follow links.
0920    */
0921 
0922   puts("\nchdir to ../links");
0923   chdir("../links");
0924   puts("Doing the stat() on good links\n");
0925   stat_multiple_files( Links_to_Dirs );
0926   stat_multiple_files( Links_to_Files );
0927   stat_multiple_files( Links_to_dirlinks  );
0928   stat_multiple_files( Links_to_filelinks );
0929 
0930   /*
0931    * Chmod on dir1/dir1.  This allows the error path to be hit.
0932    */
0933 
0934   printf( "chmod of %s to Read/Write\n", Directories[4] );
0935   chmod( Directories[4], (S_IROTH|S_IWOTH) );
0936   puts( "\nDoing the stat() on all the bad paths" );
0937 
0938   stat_multiple_files( Bad_paths );
0939   make_multiple_bad_files( Bad_paths );
0940 
0941   printf( "Return %s to RWX\n", Directories[4] );
0942   chmod( Directories[4], S_IRWXU );
0943 
0944 
0945   /*
0946    * Check out symbolic links.
0947    */
0948 
0949   make_multiple_symlinks();
0950   make_many_symlinks( "/symlinks", 10 );
0951 
0952   sc = rtems_task_wake_after( TIMEOUT_VALUE );
0953   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0954   Cause_faults();
0955 
0956   sc = rtems_task_wake_after( TIMEOUT_VALUE );
0957   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0958   chown_multiple_files( Files );
0959 
0960   sc = rtems_task_wake_after( TIMEOUT_VALUE );
0961   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0962   chown_multiple_files( Links_to_Dirs );
0963 
0964   sc = rtems_task_wake_after( TIMEOUT_VALUE );
0965   rtems_test_assert( sc == RTEMS_SUCCESSFUL );
0966   lchown_multiple_files( SymLinks );
0967 
0968   test_statvfs();
0969 
0970   TEST_END();
0971   rtems_test_exit(0);
0972 }