source: rtems/testsuites/psxtests/psximfs02/init.c @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

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