source: rtems/testsuites/psxtests/psximfs02/init.c @ cb9bb9d1

4.11
Last change on this file since cb9bb9d1 was cb9bb9d1, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 20, 2015 at 7:47:10 PM

CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK was undocumented and not error checked

closes #2431.

  • Property mode set to 100644
File size: 6.2 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2015.
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.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <tmacros.h>
15#include "test_support.h"
16
17#include <unistd.h>
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <fcntl.h>
21#include <errno.h>
22#include <rtems/libio.h>
23#include <rtems/malloc.h>
24#include <rtems/libcsupport.h>
25
26const char rtems_test_name[] = "PSXIMFS 2";
27
28#if !HAVE_DECL_SETEUID
29extern int seteuid(uid_t euid);
30#endif
31
32/* forward declarations to avoid warnings */
33rtems_task Init(rtems_task_argument argument);
34
35rtems_task Init(
36  rtems_task_argument argument
37)
38{
39  static const char mount_point [] = "dir01";
40  static const char fs_type [] = RTEMS_FILESYSTEM_TYPE_IMFS;
41  static const char slink_2_name [] = "node-slink-2";
42  static const uintptr_t mount_table_entry_size [] = {
43    sizeof( rtems_filesystem_mount_table_entry_t )
44      + sizeof( fs_type )
45      + sizeof( rtems_filesystem_global_location_t )
46  };
47  static const uintptr_t slink_2_name_size [] = {
48    sizeof( slink_2_name )
49  };
50
51  int status = 0;
52  void *opaque;
53  char linkname_n[20] = {0};
54  char linkname_p[20] = {0};
55  int i;
56  struct stat stat_buf;
57
58  TEST_BEGIN();
59
60  puts( "Creating directory /dir00" );
61  status = mkdir( "/dir00", S_IRWXU );
62  rtems_test_assert( status == 0 );
63
64  puts( "Creating directory /dir00/dir01" );
65  status = mkdir( "/dir00/dir01", S_IRWXU );
66  rtems_test_assert( status == 0 );
67
68  puts( "Changing directory to /dir00" );
69  status = chdir( "/dir00" );
70  rtems_test_assert( status == 0 );
71
72  puts( "Creating link dir01-link0 for dir01" );
73  status = link( "dir01", "dir01-link0" );
74  rtems_test_assert( status == 0 );
75
76  for( i = 1 ; ; ++i ) {
77    sprintf( linkname_p, "dir01-link%d", i-1 );
78    sprintf( linkname_n, "dir01-link%d", i );
79    printf( "\nCreating link %s for %s\n", linkname_n, linkname_p );
80    status = link( linkname_p, linkname_n );
81    if( status != 0 ) {
82      puts("Link creation failed" );
83      break;
84    }
85  }
86
87  puts( "Creating a regular node /node, RDONLY" );
88  status = mknod( "/node", S_IFREG | S_IRUSR, 0LL );
89  rtems_test_assert( status == 0 );
90
91  puts( "Creating link /node-link for /node" );
92  status = link( "/node" , "/node-link" );
93  rtems_test_assert( status == 0 );
94
95  puts( "Opening /node-link in WRONLY mode -- expect EACCES" );
96  status = open( "/node-link", O_WRONLY );
97  rtems_test_assert( status == -1 );
98  rtems_test_assert( errno == EACCES );
99
100  puts( "Creating a symlink /node-slink for /node" );
101  status = symlink( "/node" , "/node-slink" );
102  rtems_test_assert( status == 0 );
103
104  puts( "Opening /node-slink in WRONLY mode -- expect EACCES" ); 
105  status = open( "/node-slink", O_WRONLY );
106  rtems_test_assert( status == -1 );
107  rtems_test_assert( errno == EACCES );
108
109  puts( "Allocate most of heap" );
110  opaque = rtems_heap_greedy_allocate( mount_table_entry_size, 1 );
111
112  printf( "Attempt to mount a fs at %s -- expect ENOMEM", mount_point );
113  status = mount( NULL,
114                  mount_point,
115                  fs_type,
116                  RTEMS_FILESYSTEM_READ_WRITE,
117                  NULL );
118  rtems_test_assert( status == -1 );
119  rtems_test_assert( errno == ENOMEM );
120
121  puts( "Freeing allocated memory" );
122  rtems_heap_greedy_free( opaque );
123
124  puts( "Changing directory to /" );
125  status = chdir( "/" );
126  rtems_test_assert( status == 0 );
127
128  puts( "Allocate most of heap" );
129  opaque = rtems_heap_greedy_allocate( NULL, 0 );
130
131  puts( "Attempt to create /node-link-2 for /node -- expect ENOMEM" );
132  status = link( "/node", "/node-link-2" );
133  rtems_test_assert( status == -1 );
134  rtems_test_assert( errno == ENOMEM );
135
136  puts( "Attempt to create /node-slink-2 for /node -- expect ENOMEM" );
137  status = symlink( "/node", "node-slink-2" );
138  rtems_test_assert( status == -1 );
139  rtems_test_assert( errno == ENOMEM );
140
141  puts( "Freeing allocated memory" );
142  rtems_heap_greedy_free( opaque );
143
144  puts( "Allocate most of heap" );
145  opaque = rtems_heap_greedy_allocate( slink_2_name_size, 1 );
146
147  printf( "Attempt to create %s for /node -- expect ENOMEM", slink_2_name );
148  status = symlink( "/node", slink_2_name );
149  rtems_test_assert( status == -1 );
150  rtems_test_assert( errno == ENOMEM );
151
152  puts( "Freeing allocated memory" );
153  rtems_heap_greedy_free( opaque );
154
155  puts( "Attempt to stat a hardlink" );
156  status = lstat( "/node-link", &stat_buf );
157  rtems_test_assert( status == 0 );
158
159  puts( "Changing euid to 10" );
160  status = seteuid( 10 );
161  rtems_test_assert( status == 0 );
162
163#if defined(RTEMS_POSIX_API)
164  puts( "Attempt chmod on /node -- expect EPERM" );
165  status = chmod( "/node", S_IRUSR );
166  rtems_test_assert( status == -1 );
167  rtems_test_assert( errno == EPERM );
168
169  puts( "Attempt chown on /node -- expect EPERM" );
170  status = chown( "/node", 10, 10 );
171  rtems_test_assert( status == -1 );
172  rtems_test_assert( errno == EPERM );
173#else
174  puts( "Attempt chmod on /node -- EPERM only when POSIX enabled" );
175  puts( "Attempt chown on /node -- EPERM only when POSIX enabled" );
176#endif
177
178  puts( "Changing euid back to 0 [root]" );
179  status = seteuid( 0 );
180  rtems_test_assert( status == 0 );
181
182  puts( "Creating a fifo -- OK" );
183  status = mkfifo( "/fifo", S_IRWXU );
184  rtems_test_assert( status == 0 );
185 
186  puts( "chown /fifo to 10 -- OK" );
187  status = chown( "/fifo", 10, 10 );
188  rtems_test_assert( status == 0 );
189
190  puts( "Changing euid to 10" );
191  status = seteuid( 10 );
192  rtems_test_assert( status == 0 );
193
194  puts( "chmod /fifo -- OK" );
195  status = chmod( "/fifo", S_IRWXU );
196  rtems_test_assert( status == 0 );
197
198  printf( "chown /fifo to %o -- OK\n", 0 );
199  status = chown( "/fifo", 0, 0 );
200  rtems_test_assert( status == 0 );
201
202  TEST_END();
203  rtems_test_exit(0);
204}
205
206/* configuration information */
207
208#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
209#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
210
211#define CONFIGURE_FILESYSTEM_IMFS
212
213#define CONFIGURE_MAXIMUM_TASKS                  1
214#define CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK   16
215#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
216#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
217
218#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
219
220#define CONFIGURE_INIT
221
222#define CONFIGURE_MAXIMUM_FIFOS 1
223
224#include <rtems/confdefs.h>
225/* end of file */
Note: See TracBrowser for help on using the repository browser.