source: rtems/testsuites/psxtests/psxmount/test.c @ 042a442

4.104.115
Last change on this file since 042a442 was 042a442, checked in by Chris Johns <chrisj@…>, on 06/02/10 at 00:50:37

2010-06-02 Chris Johns <chrisj@…>

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