source: rtems/testsuites/fstests/support/fstest_support.c @ 6fed43e

4.115
Last change on this file since 6fed43e was 6fed43e, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 2, 2011 at 2:24:59 PM

2011-08-02 Xiang Cui <medivhc@…>

  • configure.ac, fserror/test.c, fslink/test.c, fspermission/test.c, fsrdwr/init.c, fssymlink/test.c, fstime/test.c, mdosfs_support/fs_config.h, mdosfs_support/fs_support.c, mimfs_support/fs_support.c, mrfs_support/fs_config.h, support/fstest.h, support/fstest_support.c, support/ramdisk_support.c, support/ramdisk_support.h: Perform first phase of clean up.
  • 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 Exp $
10 */
11#include <stdio.h>
12#include <errno.h>
13#include <fcntl.h>
14#include <string.h>
15#include <unistd.h>
16#include <sys/stat.h>
17#include <sys/types.h>
18
19#include "rtems.h"
20
21#include "fstest_support.h"
22#include "fs_config.h"
23
24#include "fstest.h"
25
26#define TEMP_DIR "waterbuffalo"
27
28
29/* Break out of a chroot() environment in C */
30void break_out_of_chroot(void)
31{
32
33  int dir_fd;       /* File descriptor to directory */
34  struct stat sbuf; /* The stat() buffer */
35  chdir("/");
36
37  if (stat(TEMP_DIR,&sbuf)<0) {
38    if (errno==ENOENT) {
39      if (mkdir(TEMP_DIR,0755)<0) {
40        fprintf(stderr,"Failed to create %s - %s\n", TEMP_DIR,
41            strerror(errno));
42        exit(1);
43      }
44    } else {
45      fprintf(stderr,"Failed to stat %s - %s\n", TEMP_DIR,
46          strerror(errno));
47      exit(1);
48    }
49  } else if (!S_ISDIR(sbuf.st_mode)) {
50    fprintf(stderr,"Error - %s is not a directory!\n",TEMP_DIR);
51    exit(1);
52  }
53
54  if ((dir_fd=open(".",O_RDONLY))<0) {
55    fprintf(stderr,"Failed to open ""."
56        " for reading - %s\n", strerror(errno));
57    exit(1);
58  }
59
60  if (chroot(TEMP_DIR)<0) {
61    fprintf(stderr,"Failed to chroot to %s - %s\n",TEMP_DIR,
62        strerror(errno));
63    exit(1);
64  }
65
66  if (fchdir(dir_fd)<0) {
67    fprintf(stderr,"Failed to fchdir - %s\n",
68        strerror(errno));
69    exit(1);
70  }
71  close(dir_fd);
72  chdir("..");
73  chroot(".");
74
75}
76
77/*
78 *  Main entry point of every filesystem test
79 */
80
81rtems_task Init(
82    rtems_task_argument ignored)
83{
84  int rc=0;
85  puts( "\n\n*** FILE SYSTEM TEST ( " FILESYSTEM " ) ***" );
86
87  puts( "Initializing filesystem " FILESYSTEM );
88  test_initialize_filesystem();
89  rc=chdir(BASE_FOR_TEST);
90  rtems_test_assert(rc==0);
91
92  rc=chroot(BASE_FOR_TEST);
93  rtems_test_assert(rc==0);
94
95  test();
96
97  break_out_of_chroot();
98  chdir("/");
99
100  puts( "\n\nShutting down filesystem " FILESYSTEM );
101  test_shutdown_filesystem();
102
103  puts( "*** END OF FILE SYSTEM TEST ( " FILESYSTEM " ) ***" );
104  rtems_test_exit(0);
105}
Note: See TracBrowser for help on using the repository browser.