source: rtems/c/src/tests/psxtests/psxmount/test.c @ 4c1b914

4.104.114.84.95
Last change on this file since 4c1b914 was 4c1b914, checked in by Joel Sherrill <joel.sherrill@…>, on 11/02/99 at 16:39:44

Minor changes to make the screen match a bit better.

  • Property mode set to 100644
File size: 10.4 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  /*
103   * Change directory to the root and create files under
104   * the base file system.
105   */
106
107  printf( "\nchdir to the root directory\n" );
108  status = chdir( "/" );
109  printf( "chdir() status : %d\n\n", status );
110
111  printf( "\nCreating a series of directories under /\n" );
112  i=0;
113  while ( strcmp(dnames[i], "END") != 0 )
114  {
115     status = mkdir( dnames[i], 0777 );
116     printf("Creating : %25s  %d %d   ", dnames[i], status, errno );
117     if ( status == 0 )
118        printf(" Success\n");
119     else
120        printf(" Failure\n");
121
122     i++;
123  }
124
125  /*
126   * Create a Files with all rwx for others group and user.  Verify
127   * the created file.
128   */
129
130  printf("create /b/my_file\n");
131  fd = open ("/b/my_file", O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
132  assert( fd != 0 );
133  close (fd);
134
135  printf("Verify /b/my_file\n");
136  fd = open("/b/my_file", S_IRWXU|S_IRWXG|S_IRWXO);
137  assert( fd != 0 );
138  close( fd );
139
140
141  printf("create c/y/my_mount_point/my_dir/d\n");
142  fd = open ("c/y/my_mount_point/my_dir/d", O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
143  assert( fd != 0 );
144  close (fd);
145 
146  printf("Verify c/y/my_mount_point/my_dir/d\n");
147  fd = open("c/y/my_mount_point/my_dir/d", S_IRWXU|S_IRWXG|S_IRWXO);
148  assert( fd != 0 );
149  close( fd );
150
151  /*
152   *  Mount an the IMFS file system on the base file system.
153   */
154
155  printf("Attempting to mount IMFS file system at /c/z/my_mount_point \n");
156  status = mount(
157     &mt_entry,
158     &IMFS_ops,
159     RTEMS_FILESYSTEM_READ_WRITE,
160     NULL,
161     mount_point_string );
162  assert( status == 0 );
163  if( mt_entry == NULL ){
164     printf(" NULL mount table entry was returned\n");
165  }
166  else {
167     printf("2nd file system successfully mounted at /c/z/my_mount_point \n");
168  }
169
170  /*
171   * Change directory to the mount point and create a group of files under
172   * the mounted file system.
173   */
174
175  printf( "\nchdir to /c/z/my_mount_point.\n" );
176  status = chdir( "/c/z/my_mount_point" );
177  printf( "chdir() status : %d\n\n", status );
178
179  printf( "\nCreating a series of directories under /c/z/my_mount_point\n" );
180  i=0;
181  while ( strcmp(fnames[i], "END") != 0 )
182  {
183     status = mkdir( fnames[i], 0777 );
184     printf("Creating: %46s   %d %d   ", fnames[i], status, errno );
185     if ( status == 0 )
186        printf(" Success\n");
187     else {
188        printf(" Failure\n");
189        perror("errno");
190     }
191
192     status = stat( fnames[i], &statbuf );
193     if ( status == -1 )
194       printf( ": %s\n", strerror( errno ) );
195
196     i++;
197  }
198
199  printf( "\nchdir to /\n" );
200  status = chdir( "/" );
201  printf( "chdir() status : %d\n\n", status );
202
203  /*
204   * Unmount the first file system we mounted
205   */
206
207  printf( "Unmount status:");
208  status = unmount( "/c/z/my_mount_point" );
209  printf( " %d\n", status );
210
211
212  /*
213   * Mount a NULL filesystem and verify it fails.
214   */
215
216  printf("Mount a NULL file system and verify EINVAL\n");
217  status = mount(
218   &mt_entry,
219   NULL,
220   RTEMS_FILESYSTEM_READ_WRITE,
221   NULL,
222   mount_point_string );
223  assert( status == -1 );
224  assert( errno == EINVAL );
225
226  /*
227   * Verify mount with option of -62 fails with EINVAL
228   */
229
230  printf("mount with option of -62 should fail with EINVAL\n");
231  status = mount(
232     &mt_entry,
233     &IMFS_ops,
234     -62,
235     NULL,
236     "/c/y/my_mount_point" );
237  assert( status == -1 );
238  assert( errno == EINVAL );
239
240  /*
241   * Mount a Read Only File system.
242   */
243
244  printf("Mount a Read Only filesystem at /c/y/my_mount_point \n");
245  status = mount(
246     &mt_entry,
247     &IMFS_ops,
248     RTEMS_FILESYSTEM_READ_ONLY,
249     NULL,
250     "/c/y/my_mount_point" );
251  assert( status == 0 );
252  if( mt_entry == NULL ){
253     printf(" NULL mount table entry was returned\n");
254  }
255  else {
256     printf("Read only file system successfully mounted at /c/y/my_mount_point \n");
257  }
258
259  /*
260   * Create a directory that passes through the read only file system.
261   */
262
263  printf("create c/y/my_mount_point/../../y/my_mount_point/new_dir\n");
264  status = mkdir("c/y/my_mount_point/../../y/my_mount_point/new_dir",S_IRWXU );
265  assert( status == 0 );
266  status = stat("c/y/my_mount_point/../../y/my_mount_point/new_dir",&statbuf );
267  assert( status == 0 );
268  status = stat("c/y/my_mount_point/new_dir/..", &statbuf );
269  assert( status == 0 );
270
271  /*
272   * Attempt to mount a second file system at a used mount point.
273   */
274
275  printf("Verify a mount point retruns EBUSY for another mount\n");
276  status = mount(
277     &mt_entry,
278     &IMFS_ops,
279     RTEMS_FILESYSTEM_READ_ONLY,
280     NULL,
281     "/c/y/my_mount_point" );
282  assert( status == -1 );
283  assert( errno == EBUSY);
284
285  /*
286   * Attempt to mount at a file.
287   */
288
289  printf("Mount on a file should fail with ENOTDIR\n");
290  status = mount(
291     &mt_entry,
292     &IMFS_ops,
293     RTEMS_FILESYSTEM_READ_ONLY,
294     NULL,
295     "/b/my_file" );
296  assert( status == -1 );
297  assert( errno == ENOTDIR );
298
299 
300  /*
301   * Verify we cannot unmount a file system while we are in it.
302   */
303
304  printf("Create and chdir to /c/y/my_mount_point/mydir\n");
305  status = mkdir( "/c/y/my_mount_point/mydir", 0777);
306  assert( status == 0 );
307
308  status = chdir( "/c/y/my_mount_point/mydir" );
309  assert( status == 0 );
310
311  printf("unmount of /c/y/my_mount_point should fail with EBUSY\n");
312  status = unmount( "/c/y/my_mount_point" );
313  assert( status == -1 );
314  assert( errno == EBUSY );
315
316  /*
317   * Chdir to root and verify we can unmount the file system now.
318   */
319
320  printf("chdir to / and verify we can unmount /c/y/my_mount_point\n");
321  status = chdir( "/" );
322  assert( status == 0 );
323
324  printf("unmount /c/y/my_mount_point \n");
325  status = unmount( "/c/y/my_mount_point" );
326  assert( status == 0 );
327
328  /*
329   * Attempt to unmount a directory that does not exist.
330   */
331
332  printf(" unmount /b/mount_point should fail with EINVAL\n");
333  status = unmount( "/b/mount_point" );
334  assert( status == -1 );
335  assert( errno == ENOENT );
336 
337  /*
338   * Remount the filesystem.
339   */
340
341  printf("Mount /c/y/my_mount_point\n");
342  status = mount(
343     &mt_entry,
344     &IMFS_ops,
345     RTEMS_FILESYSTEM_READ_ONLY,
346     NULL,
347     "/c/y/my_mount_point" );
348  assert( status == 0 );
349
350  /*
351   * Create a file and directory then open the directory.
352   * Verify unmount will return EBUSY while directory is open.
353   */
354
355  printf("Create and open /c/y/my_mount_point/my_file\n");
356  fd = open( "/c/y/my_mount_point/my_file", O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
357  assert( fd != -1 );
358  status = close( fd );
359  assert( status == 0 );
360
361  printf("\nmkdir /c/y/my_mount_point/my_dir\n");
362  status = mkdir( "/c/y/my_mount_point/my_dir", 0x1c0 );
363  printf("Open /c/y/my_mount_point/my_dir\n");
364  directory = opendir( "/c/y/my_mount_point/my_dir" );
365  assert( directory );
366 
367  printf("Unmount /c/y/my_mount_point should fail with EBUSY\n");
368  status = unmount( "/c/y/my_mount_point" );
369  assert( status == -1 );
370  assert( errno == EBUSY );
371
372  printf("Close /c/y/my_mount_point/my_dir\n");
373  status = closedir( directory );
374  assert( status == 0 );
375
376  /*
377   * Attempt to unmount a directory that is not a mount point.
378   */
379
380  printf("Unmount /c/y/my_mount_point/my_dir\n");
381  status = unmount( "/c/y/my_mount_point/my_dir" );
382  assert( status == -1 );
383  assert( errno == EACCES );
384
385  /*
386   * Verify a file system can not be unmounted with a mounted file system
387   * in it.
388   */
389
390  printf("Mount a file system at /c/y/my_mount_point/my_dir\n");
391  status = mount(
392     &mt_entry,
393     &IMFS_ops,
394     RTEMS_FILESYSTEM_READ_WRITE,
395     NULL,
396     "/c/y/my_mount_point/my_dir");
397  assert( status == 0 );
398
399  printf("unmount /c/y/my_mount_point should fail with EBUSY\n");
400  status = unmount( "/c/y/my_mount_point" );
401  assert( status == -1 );
402  assert( errno == EBUSY );
403
404  /*
405   * Verify you cannot create a hard link across mounted file systems.
406   */
407
408  printf("Verify a hard link across filesystems fails with EXDEV\n");
409  status = mkdir( "/c/y/my_mount_point/my_dir2", S_IRWXU  );
410  assert( status == 0 );
411
412  status = link( "/c/y/my_mount_point/my_dir2", "/c/y/my_mount_point/my_dir/my_link" );
413  assert( status == -1 );
414  assert( errno == EXDEV );
415
416  /*
417   * Create a symbolic link across mountpoints.
418   */
419
420  printf("Verify a symbolic link across file systems works\n");
421  status = symlink( "/c/y/my_mount_point/my_dir2", "/c/y/my_mount_point/my_dir/my_link" );
422  assert( status == 0 );
423  status = stat( "/c/y/my_mount_point/my_dir/my_link", &statbuf );
424  assert( status == 0 );
425
426  printf("unmount /c/y/my_mount_point/my_dir\n");
427  status = unmount( "/c/y/my_mount_point/my_dir" );
428  assert( status == 0 );
429
430  /*
431   * Verify symblic link no longer works.
432   */
433
434  printf("Verify the symbolic link now fails\n");
435  status = stat( "/c/y/my_mount_point/my_dir/my_link", &statbuf );
436  assert( status != 0 );
437
438  printf("unmount /c/y/my_mount_point\n");
439  status = unmount( "/c/y/my_mount_point" );
440  assert( status == 0 );
441
442  printf( "\n\n*** END OF MOUNT/UNMOUNT TEST ***\n" );
443  exit(0);
444}
445
Note: See TracBrowser for help on using the repository browser.