OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [tests/] [psxtests/] [psxmount/] [test.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.