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

4.11
Last change on this file since c40d3c4b was c40d3c4b, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 1, 2010 at 5:24:35 PM

2010-07-01 Vinu Rajashekhar <vinutheraj@…>

PR 1597/cpukit

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