source: rtems/testsuites/psxtests/psxmount/test.c @ 0895bdb

4.104.114.84.9
Last change on this file since 0895bdb was 0895bdb, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 23, 1998 at 6:57:48 PM

Added tests in support of the file system infrastructure.

  • Property mode set to 100644
File size: 9.6 KB
Line 
1/*
2 *  This is a native test to explore how the readdir() family works.
3 *  Newlib supports the following readdir() family members:
4 *
5 *    closedir()   -
6 *    readdir()    -
7 *    scandir()    -
8 *    opendir()    -
9 *    rewinddir()  -
10 *    telldir()    - BSD not in POSIX
11 *    seekdir()    - BSD not in POSIX
12 *
13 *
14 *  seekdir() takes an offset which is a byte offset.  The Linux
15 *  implementation of this appears to seek to the ((off/DIRENT_SIZE) + 1)
16 *  record where DIRENT_SIZE seems to be 12 bytes.
17 *
18 *
19 *
20 *  $Id$
21 */
22#include <stdio.h>
23#include <sys/types.h>
24#include <sys/stat.h>
25#include <fcntl.h>
26#include <dirent.h>
27#include <string.h>
28#include <assert.h>
29#include <unistd.h>
30#include <errno.h>
31#include <rtems.h>
32#include <rtems/libio.h>
33
34extern rtems_filesystem_location_info_t rtems_filesystem_current;
35
36DIR *directory;
37DIR *directory2;
38DIR *directory3;
39DIR *directory_not;
40
41#ifndef __P
42#define __P(args)()
43#endif
44
45char *dnames[] = {
46        "a",
47        "b",
48        "c",
49        "d",
50        "e",
51        "f",
52        "c/y",
53        "c/z",
54        "c/x",
55        "c/y/a3333",
56        "c/y/j123",
57        "c/y/my_mount_point", 
58        "c/y/my_mount_point/my_dir",
59        "c/z/my_mount_point",
60        "END"
61};
62
63char *fnames[] = {
64        "a",
65        "b",
66        "c",
67        "d",
68        "e",
69        "f",
70        "c/y",
71        "c/z",
72        "c/x",
73        "c/y/a3333",
74        "c/y/j123",
75        "c/y/my_mount_point",
76        "c/y/my_mount_point/my_dir",
77        "c/y/my_mount_point/my_dir/d",
78        "c/z/my_mount_point",
79        "/c/z/my_mount_point/a/../../my_mount_point/a/g",
80        "END"
81};
82
83#if defined(__rtems__)
84int test_main(void)
85#else
86int main(
87  int argc,
88  char **argv
89)
90#endif
91{
92  int i;
93  int fd;
94  int status;
95  struct stat statbuf;
96  rtems_filesystem_mount_table_entry_t *mt_entry;
97  static char mount_point_string[25] = { "/c/z/my_mount_point" };
98
99
100  printf( "\n\n*** MOUNT/UNMOUNT TEST ***\n" );
101
102  printf( "\nchdir to the root directory\n" );
103  status = chdir( "/" );
104  printf( "chdir() status : %d\n\n", status );
105
106  printf( "\nCreating a series of directories under /\n" );
107  i=0;
108  while ( strcmp(dnames[i], "END") != 0 )
109  {
110     status = mkdir( dnames[i], 0777 );
111     printf("Creating directory: %s      %d %d   ", dnames[i], status, errno );
112     if ( status == 0 )
113        printf(" Success\n");
114     else
115        printf(" Failure\n");
116
117     i++;
118  }
119
120  fd = open ("/b/my_file", O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
121  close (fd);
122  fd = open("/b/my_file", S_IRWXU|S_IRWXG|S_IRWXO);
123  close( fd );
124
125  fd = open ("c/y/my_mount_point/my_dir/d", O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
126  close (fd);
127  fd = open("c/y/my_mount_point/my_dir/d", S_IRWXU|S_IRWXG|S_IRWXO);
128  close( fd );
129
130  printf("Attempting to mount IMFS file system at /c/z/my_mount_point \n");
131  status = mount(
132     &mt_entry,
133     &IMFS_ops,
134     "RW",
135     NULL,
136     mount_point_string );
137  assert( status == 0 );
138  if( mt_entry == NULL ){
139     printf(" NULL mount table entry was returned\n");
140  }
141  else {
142     printf("2nd file system successfully mounted at /c/z/my_mount_point \n");
143  }
144
145  printf( "\nchdir to /c/z/my_mount_point the mount point of the \n" );
146  printf( "second file system \n" );
147  status = chdir( "/c/z/my_mount_point" );
148  printf( "chdir() status : %d\n\n", status );
149
150  printf( "\nCreating a series of directories under /c/z/my_mount_point\n" );
151  i=0;
152  while ( strcmp(fnames[i], "END") != 0 )
153  {
154     status = mkdir( fnames[i], 0777 );
155     printf("Creating directory: %s      %d %d   ", fnames[i], status, errno );
156     if ( status == 0 )
157        printf(" Success\n");
158     else {
159        printf(" Failure\n");
160        perror("errno");
161     }
162
163     status = stat( fnames[i], &statbuf );
164     if ( status == -1 )
165       printf( ": %s\n", strerror( errno ) );
166
167     i++;
168  }
169
170  printf( "\nchdir to / the mount point of the first file system \n" );
171  status = chdir( "/" );
172  printf( "chdir() status : %d\n\n", status );
173
174  /*
175   * Unmount the first file system we mounted
176   */
177
178  printf( "Unmount status:");
179  status = unmount( "/c/z/my_mount_point" );
180  printf( " %d\n", status );
181
182/*
183  status = chmod( "c/y/j123", S_IRUSR );
184  assert( status == 0 );
185
186  printf("Attempting to mount IMFS file system at c/y/j123\n");
187  status = mount(
188     &mt_entry,
189     &IMFS_ops,
190     "RO",
191     NULL,
192     "c/y/j123" );
193  assert( status == 0 );
194
195  status = mkdir( "c/y/j123/new_dir", S_IRUSR );
196  assert( status == -1 );
197
198  printf("Unmount c/y/j123\n");
199  status = unmount( "c/y/j123" );
200  assert( status == 0 );
201*/
202
203  printf(" File system type should be invalid.\n");
204  status = mount(
205   &mt_entry,
206   NULL,
207   "RW",
208   NULL,
209   mount_point_string );
210  assert( status == -1 );
211  assert( errno == EINVAL );
212
213  printf("Attempting to mount IMFS file system at /c/y/my_mount_point \n");
214  status = mount(
215     &mt_entry,
216     &IMFS_ops,
217     "RO",
218     NULL,
219     "/c/y/my_mount_point" );
220  assert( status == 0 );
221  if( mt_entry == NULL ){
222     printf(" NULL mount table entry was returned\n");
223  }
224  else {
225     printf("3rd file system successfully mounted at /c/y/my_mount_point \n");
226  }
227
228  status = mkdir("c/y/my_mount_point/../../y/my_mount_point/new_dir",S_IRWXU );
229  assert( status == 0 );
230
231  status = stat("c/y/my_mount_point/../../y/my_mount_point/new_dir",&statbuf );
232  assert( status == 0 );
233  status = stat("c/y/my_mount_point/new_dir/..", &statbuf );
234  assert( status == 0 );
235
236  printf("Mount another file system at /c/y/my_mount_point should fail with EBUSY\n");
237  status = mount(
238     &mt_entry,
239     &IMFS_ops,
240     "RO",
241     NULL,
242     "/c/y/my_mount_point" );
243  assert( status == -1 );
244  assert( errno == EBUSY);
245
246  printf("Mount /b/my_file should fail in rtems_filesystem_evaluate_path\n");
247  status = mount(
248     &mt_entry,
249     &IMFS_ops,
250     "RO",
251     NULL,
252     "/b/my_file" );
253  assert( status == -1 );
254 
255  printf("Unmount /c/y/my_mount_point\n");
256  status = unmount( "/c/y/my_mount_point" );
257  assert( status == 0 );
258
259/* What's wrong with this? It should be causing failure at unmount.c:87,
260 * instead, it's returning a status of 0.
261 */
262
263  printf("Mount /c/y/my_mount_point to cause error\n");
264  status = mount(
265     &mt_entry,
266     &IMFS_ops,
267     "RO",
268     NULL,
269     "/c/y/my_mount_point" );
270
271  assert( status == 0 );
272  status = mkdir( "/c/y/my_mount_point/mydir", 0777);
273  assert( status == 0 );
274
275  status = chdir( "/c/y/my_mount_point/mydir" );
276  assert( status == 0 );
277
278  printf(" unmount of /c/y/my_mount_point should fail with EBUSY\n");
279  status = unmount( "/c/y/my_mount_point" );
280  assert( status == -1 );
281  assert( errno == EBUSY );
282
283  status = chdir( "/" );
284  assert( status == 0 );
285
286  printf(" unmount /c/y/my_mount_point \n");
287  status = unmount( "/c/y/my_mount_point" );
288  assert( status == 0 );
289
290  printf(" unmount /b/mount_point should fail\n");
291  status = unmount( "/b/mount_point" );
292  assert( status == -1 );
293
294  printf("Mount /c/y/my_mount_point\n");
295  status = mount(
296     &mt_entry,
297     &IMFS_ops,
298     "RO",
299     NULL,
300     "/c/y/my_mount_point" );
301  assert( status == 0 );
302
303  /* XXX - There is an error in open that calculates incorrect mode. */
304  printf("Create and open /c/y/my_mount_point/my_file\n");
305  fd = open( "/c/y/my_mount_point/my_file", O_CREAT ); 
306  assert( fd != -1 );
307  status = close( fd );
308  assert( status == 0 );
309
310  printf("\nmkdir /c/y/my_mount_point/my_dir\n");
311  status = mkdir( "/c/y/my_mount_point/my_dir", 0x1c0 );
312  printf("Open /c/y/my_mount_point/my_dir\n");
313  directory = opendir( "/c/y/my_mount_point/my_dir" );
314  assert( directory ); 
315 
316  printf("Unmount /c/y/my_mount_point should fail with EBUSY\n");
317  status = unmount( "/c/y/my_mount_point" );
318  assert( status == -1 );
319
320  printf("Close /c/y/my_mount_point/my_dir\n");
321  status = closedir( directory ); 
322  assert( status == 0 );
323
324  printf("Unmount /c/y/my_mount_point/d should fail at 107\n");
325  status = unmount( "/c/y/my_mount_point/d" );
326  assert( status == -1 );
327
328  printf("unmount /c/y/my_mount_point\n");
329  status = unmount( "/c/y/my_mount_point" );
330  assert( status == 0 );
331
332  printf("mount with option RA should fail with EINVAL\n");
333  status = mount(
334     &mt_entry,
335     &IMFS_ops,
336     "RA",
337     NULL,
338     "/c/y/my_mount_point" );
339  assert( status == -1 );
340
341  printf("Mount a file system at /c/y/my_mount_point/my_dir\n");
342  status = mount(
343     &mt_entry,
344     &IMFS_ops,
345     "RW",
346     NULL,
347     "/c/y/my_mount_point/my_dir");
348  assert( status == 0 );
349
350  printf("unmount /c/y/my_mount_point/my_dir should fail in ");
351  printf("file_systems_below_this_mountpoint \n");
352  status = unmount( "/c/y/my_mount_point/my_dir" );
353  assert( status == 0 );
354
355  printf("mount first filesystem /c/y/my_mount_point/\n");
356  status = mount(
357     &mt_entry,
358     &IMFS_ops,
359     "RW",
360     NULL,
361     "/c/y/my_mount_point" );
362  assert( status == 0 );
363
364  printf("\nmkdir /c/y/my_mount_point/my_dir\n");
365  status = mkdir( "/c/y/my_mount_point/my_dir", S_IRWXU );
366  assert( status == 0 );
367
368  printf("Mount another filesystem at /c/y/my_mount_point/my_dir\n");
369  status = mount(
370     &mt_entry,
371     &IMFS_ops,
372     "RW",
373     NULL,
374     "/c/y/my_mount_point/my_dir");
375  assert( status == 0 );
376
377  status = mkdir( "/c/y/my_mount_point/my_dir2", S_IRWXU  );
378  assert( status != -1 ); 
379
380  status = link( "/c/y/my_mount_point/my_dir2", "/c/y/my_mount_point/my_dir/my_link" );
381  assert( status == -1 );
382
383  printf("unmount /c/y/my_mount_point\n");
384  status = unmount( "/c/y/my_mount_point" );
385  assert( status == -1 );
386
387  printf("unmount /c/y/my_mount_point/my_dir\n");
388  status = unmount( "/c/y/my_mount_point/my_dir" );
389  assert( status == 0 );
390
391  printf("unmount /c/y/my_mount_point\n");
392  status = unmount( "/c/y/my_mount_point" );
393  assert( status == 0 );
394
395/*  printf("Mount /c/y/my_mount_point\n");
396  status = mount(
397     &mt_entry,
398     &IMFS_ops,
399     "RO",
400     NULL,
401     "/c/y/my_mount_point" );
402  assert( status == 0 );
403*/
404
405  printf( "\n\n*** END OF MOUNT/UNMOUNT TEST ***\n" );
406  exit(0);
407}
408
Note: See TracBrowser for help on using the repository browser.