source: rtems/testsuites/psxtests/psxmount/test.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: 11.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  Modifications to support reference counting in the file system are
6 *  Copyright (c) 2012 embedded brains GmbH.
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 */
12
13#ifdef HAVE_CONFIG_H
14#include "config.h"
15#endif
16
17#include <stdio.h>
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <fcntl.h>
21#include <dirent.h>
22#include <string.h>
23#include <unistd.h>
24#include <errno.h>
25#include <rtems.h>
26#include <rtems/libio.h>
27#include <pmacros.h>
28
29DIR *directory;
30DIR *directory2;
31DIR *directory3;
32DIR *directory_not;
33
34char *dnames[] = {
35        "a",
36        "b",
37        "c",
38        "d",
39        "e",
40        "f",
41        "c/y",
42        "c/z",
43        "c/x",
44        "c/y/a3333",
45        "c/y/j123",
46        "c/y/my_mount_point",
47        "c/y/my_mount_point/my_dir",
48        "c/z/my_mount_point",
49        "END"
50};
51
52char *fnames[] = {
53        "a",
54        "b",
55        "c",
56        "d",
57        "e",
58        "f",
59        "c/y",
60        "c/z",
61        "c/x",
62        "c/y/a3333",
63        "c/y/j123",
64        "c/y/my_mount_point",
65        "c/y/my_mount_point/my_dir",
66        "c/y/my_mount_point/my_dir/d",
67        "c/z/my_mount_point",
68        "/c/z/my_mount_point/a/../../my_mount_point/a/g",
69        "END"
70};
71
72#if defined(__rtems__)
73int test_main(void)
74#else
75int main(
76  int argc,
77  char **argv
78)
79#endif
80{
81  int i;
82  int fd;
83  int status;
84  struct stat statbuf;
85  static char mount_point_string[25] = { "/c/z/my_mount_point" };
86  static const char my_sub_fs_dir [] = "/c/y/my_mount_point/my_sub_fs_dir";
87  static const char my_link [] = "/c/y/my_link";
88  static const char mount_point [] = "/c/y/my_mount_point";
89
90  printf( "\n\n*** MOUNT/UNMOUNT TEST ***\n" );
91
92  /*
93   * Change directory to the root and create files under
94   * the base file system.
95   */
96
97  printf( "\nchdir to the root directory\n" );
98  status = chdir( "/" );
99  printf( "chdir() status : %d\n\n", status );
100
101  printf( "\nCreating a series of directories under /\n" );
102  i=0;
103  while ( strcmp(dnames[i], "END") != 0 )
104  {
105     status = mkdir( dnames[i], 0777 );
106     printf("Creating : %25s  %d %d   ", dnames[i], status, errno );
107     if ( status == 0 )
108        printf(" Success\n");
109     else
110        printf(" Failure\n");
111
112     i++;
113  }
114
115  /*
116   * Create a Files with all rwx for others group and user.  Verify
117   * the created file.
118   */
119
120  printf("create /b/my_file\n");
121  fd = open ("/b/my_file", O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
122  rtems_test_assert( fd != 0 );
123  close (fd);
124
125  printf("Verify /b/my_file\n");
126  fd = open("/b/my_file", S_IRWXU|S_IRWXG|S_IRWXO);
127  rtems_test_assert( fd != 0 );
128  close( fd );
129
130
131  printf("create c/y/my_mount_point/my_dir/d\n");
132  fd = open ("c/y/my_mount_point/my_dir/d", O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
133  rtems_test_assert( fd != 0 );
134  close (fd);
135
136  printf("Verify c/y/my_mount_point/my_dir/d\n");
137  fd = open("c/y/my_mount_point/my_dir/d", S_IRWXU|S_IRWXG|S_IRWXO);
138  rtems_test_assert( fd != 0 );
139  close( fd );
140
141  /*
142   *  Mount an the IMFS file system on the base file system.
143   */
144
145  printf("Attempting to mount IMFS file system at /c/z/my_mount_point \n");
146  status = mount(
147    "null",
148    mount_point_string,
149    "imfs",
150    RTEMS_FILESYSTEM_READ_WRITE,
151    NULL );
152  rtems_test_assert( status == 0 );
153  printf("2nd file system successfully mounted at /c/z/my_mount_point \n");
154
155  /*
156   * Change directory to the mount point and create a group of files under
157   * the mounted file system.
158   */
159
160  printf( "\nchdir to /c/z/my_mount_point.\n" );
161  status = chdir( "/c/z/my_mount_point" );
162  printf( "chdir() status : %d\n\n", status );
163
164  printf( "\nCreating a series of directories under /c/z/my_mount_point\n" );
165  i=0;
166  while ( strcmp(fnames[i], "END") != 0 )
167  {
168     status = mkdir( fnames[i], 0777 );
169     printf("Creating: %46s   %d %d   ", fnames[i], status, errno );
170     if ( status == 0 )
171        printf(" Success\n");
172     else {
173        printf(" Failure\n");
174        perror("errno");
175     }
176
177     status = stat( fnames[i], &statbuf );
178     if ( status == -1 )
179       printf( ": %s\n", strerror( errno ) );
180
181     i++;
182  }
183
184  printf( "\nchdir to /\n" );
185  status = chdir( "/" );
186  printf( "chdir() status : %d\n\n", status );
187
188  /*
189   * Unmount the first file system we mounted
190   */
191
192  printf( "Unmount status:");
193  status = unmount( "/c/z/my_mount_point" );
194  printf( " %d\n", status );
195
196
197  /*
198   * Mount a NULL filesystem and verify it fails.
199   */
200
201  printf("Mount a NULL file system and verify EINVAL\n");
202  status = mount(
203    "null",
204    mount_point_string,
205    "nofound",
206    RTEMS_FILESYSTEM_READ_WRITE,
207    NULL );
208  rtems_test_assert( status == -1 );
209  rtems_test_assert( errno == EINVAL );
210
211  /*
212   * Verify mount with option of -62 fails with EINVAL
213   */
214
215  printf("mount with option of -62 should fail with EINVAL\n");
216  status = mount(
217    "null",
218    "/c/y/my_mount_point",
219    "imfs",
220    -62,
221    NULL );
222  rtems_test_assert( status == -1 );
223  rtems_test_assert( errno == EINVAL );
224
225  /*
226   * Mount a Read Only File system.
227   */
228
229  printf("Mount a Read Only filesystem at /c/y/my_mount_point \n");
230  status = mount(
231    "null",
232    "/c/y/my_mount_point",
233    "imfs",
234    RTEMS_FILESYSTEM_READ_ONLY,
235    NULL );
236  rtems_test_assert( status == 0 );
237  printf("Read only file system successfully mounted at /c/y/my_mount_point \n");
238
239  /*
240   * Create a directory that passes through the read only file system.
241   */
242
243  printf("create c/y/my_mount_point/../../y/new_dir\n");
244  status = mkdir("c/y/my_mount_point/../../y/new_dir",S_IRWXU );
245  rtems_test_assert( status == 0 );
246  status = stat("c/y/my_mount_point/../../y/new_dir",&statbuf );
247  rtems_test_assert( status == 0 );
248  status = stat("c/y/new_dir", &statbuf );
249  rtems_test_assert( status == 0 );
250
251  /*
252   * Attempt to mount a second file system at a used mount point.
253   */
254
255  printf("Verify a mount point returns EROFS for another mount\n");
256  status = mount(
257    "null",
258    "/c/y/my_mount_point",
259    "imfs",
260     RTEMS_FILESYSTEM_READ_ONLY,
261     NULL );
262  rtems_test_assert( status == -1 );
263  rtems_test_assert( errno == EROFS);
264
265  printf("Unmount /c/y/my_mount_point\n");
266  status = unmount( "/c/y/my_mount_point" );
267  rtems_test_assert( status == 0 );
268
269  printf("Mount a read-write file system at /c/y/my_mount_point\n");
270  status = mount(
271    "null",
272    "/c/y/my_mount_point",
273    "imfs",
274    RTEMS_FILESYSTEM_READ_WRITE,
275    NULL );
276  rtems_test_assert( status == 0 );
277
278  printf("Verify a mount point returns EBUSY for another mount\n");
279  status = mount(
280    "null",
281    "/c/y/my_mount_point",
282    "imfs",
283     RTEMS_FILESYSTEM_READ_ONLY,
284     NULL );
285  rtems_test_assert( status == -1 );
286  rtems_test_assert( errno == EBUSY);
287
288  /*
289   * Attempt to mount at a file.
290   */
291
292  printf("Mount on a file should fail with ENOTDIR\n");
293  status = mount(
294    "null",
295    "/b/my_file",
296    "imfs",
297    RTEMS_FILESYSTEM_READ_ONLY,
298    NULL );
299  rtems_test_assert( status == -1 );
300  rtems_test_assert( errno == ENOTDIR );
301
302
303  /*
304   * Verify we can unmount a file system while we are in it.
305   */
306
307  printf("Create and chdir to /c/y/my_mount_point/mydir\n");
308  status = mkdir( "/c/y/my_mount_point/mydir", 0777);
309  rtems_test_assert( status == 0 );
310
311  status = chdir( "/c/y/my_mount_point/mydir" );
312  rtems_test_assert( status == 0 );
313
314  printf("unmount of /c/y/my_mount_point\n");
315  status = unmount( "/c/y/my_mount_point" );
316  rtems_test_assert( status == 0 );
317
318  printf("chdir to .. should fail with ENXIO\n");
319  status = chdir( ".." );
320  rtems_test_assert( status == -1 );
321  rtems_test_assert( errno == ENXIO );
322
323  /*
324   * Chdir to root and verify we unmounted the file system now.
325   */
326
327  printf("chdir to / and verify we can unmount /c/y/my_mount_point\n");
328  status = chdir( "/" );
329  rtems_test_assert( status == 0 );
330
331  printf("chdir to /c/y/my_mount_point/my_dir should fail with ENOENT\n");
332  status = chdir( "/c/y/my_mount_point/mydir" );
333  rtems_test_assert( status == -1 );
334  rtems_test_assert( errno == ENOENT );
335
336  /*
337   * Attempt to unmount a directory that does not exist.
338   */
339
340  printf("unmount /b/mount_point should fail with EINVAL\n");
341  status = unmount( "/b/mount_point" );
342  rtems_test_assert( status == -1 );
343  rtems_test_assert( errno == ENOENT );
344
345  /*
346   * Remount the filesystem.
347   */
348
349  printf("Mount /c/y/my_mount_point\n");
350  status = mount(
351    "null",
352    "/c/y/my_mount_point",
353    "imfs",
354    RTEMS_FILESYSTEM_READ_WRITE,
355    NULL );
356  rtems_test_assert( status == 0 );
357
358  /*
359   * Create a file and directory then open the directory.
360   * Verify unmount will return successful while directory is open.
361   */
362
363  printf("Create and open /c/y/my_mount_point/my_file\n");
364  fd = open( "/c/y/my_mount_point/my_file", O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
365  rtems_test_assert( fd != -1 );
366  status = close( fd );
367  rtems_test_assert( status == 0 );
368
369  printf("\nmkdir %s\n", my_sub_fs_dir );
370  status = mkdir( my_sub_fs_dir, S_IRWXU );
371
372  printf("open %s\n", my_sub_fs_dir );
373  directory = opendir( my_sub_fs_dir );
374  rtems_test_assert( directory );
375
376  printf("mkdir %s should fail with EEXIST\n", my_sub_fs_dir );
377  status = mkdir( my_sub_fs_dir, S_IRWXU );
378  rtems_test_assert( status == -1 );
379  rtems_test_assert( errno == EEXIST );
380
381  printf("unmount %s\n", mount_point );
382  status = unmount( mount_point );
383  rtems_test_assert( status == 0 );
384
385  printf("close %s\n", my_sub_fs_dir );
386  status = closedir( directory );
387  rtems_test_assert( status == 0 );
388
389  printf("mkdir %s\n", my_sub_fs_dir );
390  status = mkdir( my_sub_fs_dir, S_IRWXU );
391  rtems_test_assert( status == 0 );
392
393  printf("rmdir %s\n", my_sub_fs_dir );
394  status = rmdir( my_sub_fs_dir );
395  rtems_test_assert( status == 0 );
396
397  /*
398   * Attempt to unmount a directory that is not a mount point.
399   */
400
401  printf("Unmount /c/y/my_mount_point/my_dir should fail with EACCES\n");
402  status = unmount( "/c/y/my_mount_point/my_dir" );
403  rtems_test_assert( status == -1 );
404  rtems_test_assert( errno == EACCES );
405
406  /*
407   * Mount file system
408   */
409
410  printf("Mount a file system at %s\n", mount_point);
411  status = mount(
412     "null",
413     mount_point,
414     "imfs",
415     RTEMS_FILESYSTEM_READ_WRITE,
416     NULL );
417  rtems_test_assert( status == 0 );
418
419  /*
420   * Verify you cannot create a hard link across mounted file systems.
421   */
422
423  printf("Verify a hard link across filesystems fails with EXDEV\n");
424  status = mkdir( my_sub_fs_dir, S_IRWXU  );
425  rtems_test_assert( status == 0 );
426
427  status = link( my_sub_fs_dir, my_link );
428  rtems_test_assert( status == -1 );
429  rtems_test_assert( errno == EXDEV );
430
431  /*
432   * Create a symbolic link across mountpoints.
433   */
434
435  printf("Verify a symbolic link across file systems works\n");
436  status = symlink( my_sub_fs_dir, my_link );
437  rtems_test_assert( status == 0 );
438  status = stat( my_link, &statbuf );
439  rtems_test_assert( status == 0 );
440
441  printf("unmount %s\n", mount_point);
442  status = unmount( mount_point );
443  rtems_test_assert( status == 0 );
444
445  /*
446   * Verify symblic link no longer works.
447   */
448
449  printf("Verify the symbolic link now fails\n");
450  status = stat( my_link, &statbuf );
451  rtems_test_assert( status == -1 );
452  rtems_test_assert( errno == ENOENT );
453
454  printf( "\n\n*** END OF MOUNT/UNMOUNT TEST ***\n" );
455  rtems_test_exit(0);
456}
Note: See TracBrowser for help on using the repository browser.