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

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

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

  • fserror/fserror.doc, fserror/test.c, fslink/fslink.doc, fslink/test.c, fspatheval/patheval.doc, fspatheval/test.c, fspermission/fspermission.doc, fspermission/test.c, fsrdwr/fsrdwr.doc, fsrdwr/init.c, fssymlink/fssymlink.doc, fssymlink/test.c, fstime/fstime.doc, fstime/test.c, imfs_support/fs_config.h, imfs_support/fs_support.c, imfs_support/fs_supprot.h, mdosfs_support/fs_config.h, mdosfs_support/fs_support.c, mimfs_support/fs_config.h, mimfs_support/fs_support.c, mrfs_support/fs_config.h, mrfs_support/fs_support.c, support/fstest.h, support/fstest_support.c, support/fstest_support.h, support/ramdisk_support.c, support/ramdisk_support.h: Fix CVS-Ids.
  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[858e013f]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 *
[db6fbdf]9 *  $Id$
[858e013f]10 */
[6fed43e]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>
[7336d4af]18
19#include "rtems.h"
20
21#include "fstest_support.h"
22#include "fs_config.h"
23
[858e013f]24#include "fstest.h"
25
[6fed43e]26#define TEMP_DIR "waterbuffalo"
[7336d4af]27
28
[6fed43e]29/* Break out of a chroot() environment in C */
[7336d4af]30void break_out_of_chroot(void)
31{
32
[6fed43e]33  int dir_fd;       /* File descriptor to directory */
34  struct stat sbuf; /* The stat() buffer */
[7336d4af]35  chdir("/");
36
[6fed43e]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(".");
[7336d4af]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.