source: rtems/testsuites/fstests/support/fstest_support.c @ d957805

4.115
Last change on this file since d957805 was d957805, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/07/11 at 07:42:12

2011-09-07 Ralf Corsépius <ralf.corsepius@…>

  • fserror/test.c, fslink/test.c, fspatheval/test.c, fspermission/test.c, fsrdwr/init.c, fssymlink/test.c, fstime/test.c, support/fstest_support.c, support/ramdisk_support.c: Add config-header support.
  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <stdio.h>
17#include <errno.h>
18#include <fcntl.h>
19#include <string.h>
20#include <unistd.h>
21#include <sys/stat.h>
22#include <sys/types.h>
23
24#include "rtems.h"
25
26#include "fstest_support.h"
27#include "fs_config.h"
28
29#include "fstest.h"
30
31#define TEMP_DIR "waterbuffalo"
32
33
34/* Break out of a chroot() environment in C */
35void break_out_of_chroot(void)
36{
37
38  int dir_fd;       /* File descriptor to directory */
39  struct stat sbuf; /* The stat() buffer */
40  chdir("/");
41
42  if (stat(TEMP_DIR,&sbuf)<0) {
43    if (errno==ENOENT) {
44      if (mkdir(TEMP_DIR,0755)<0) {
45        fprintf(stderr,"Failed to create %s - %s\n", TEMP_DIR,
46            strerror(errno));
47        exit(1);
48      }
49    } else {
50      fprintf(stderr,"Failed to stat %s - %s\n", TEMP_DIR,
51          strerror(errno));
52      exit(1);
53    }
54  } else if (!S_ISDIR(sbuf.st_mode)) {
55    fprintf(stderr,"Error - %s is not a directory!\n",TEMP_DIR);
56    exit(1);
57  }
58
59  if ((dir_fd=open(".",O_RDONLY))<0) {
60    fprintf(stderr,"Failed to open ""."
61        " for reading - %s\n", strerror(errno));
62    exit(1);
63  }
64
65  if (chroot(TEMP_DIR)<0) {
66    fprintf(stderr,"Failed to chroot to %s - %s\n",TEMP_DIR,
67        strerror(errno));
68    exit(1);
69  }
70
71  if (fchdir(dir_fd)<0) {
72    fprintf(stderr,"Failed to fchdir - %s\n",
73        strerror(errno));
74    exit(1);
75  }
76  close(dir_fd);
77  chdir("..");
78  chroot(".");
79
80}
81
82/*
83 *  Main entry point of every filesystem test
84 */
85
86rtems_task Init(
87    rtems_task_argument ignored)
88{
89  int rc=0;
90  puts( "\n\n*** FILE SYSTEM TEST ( " FILESYSTEM " ) ***" );
91
92  puts( "Initializing filesystem " FILESYSTEM );
93  test_initialize_filesystem();
94  rc=chdir(BASE_FOR_TEST);
95  rtems_test_assert(rc==0);
96
97  rc=chroot(BASE_FOR_TEST);
98  rtems_test_assert(rc==0);
99
100  test();
101
102  break_out_of_chroot();
103  chdir("/");
104
105  puts( "\n\nShutting down filesystem " FILESYSTEM );
106  test_shutdown_filesystem();
107
108  puts( "*** END OF FILE SYSTEM TEST ( " FILESYSTEM " ) ***" );
109  rtems_test_exit(0);
110}
Note: See TracBrowser for help on using the repository browser.