yaffsfs.c: Fix NULL dereference in yaffs_unmount2_reldev()
[yaffs2.git] / rtems / rtems-y-test / common / yaffs-rtems-test-wrapper.c
1 /*
2  *  Simple test program -- demonstrating use of IMFS
3  */
4
5 #include <bsp.h>
6
7 #include <fcntl.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11
12 #include <rtems/libio.h>
13 #include <yaffs/rtems_yaffs.h>
14
15 #include "yaffs-rtems-flashsim.h"
16
17 #define YPATH "/yaffs_mount_pt"
18 //#define YPATH ""
19
20 void yaffs_bug_fn(const char *file_name, int line_no)
21 {
22         printf("Yaffs bug at %s:%d\n", file_name, line_no);
23 }
24
25 int filesystem_init(const char *mount_target)
26 {
27         struct yaffs_dev *device;
28         rtems_yaffs_default_os_context *os_context;
29         rtems_yaffs_mount_data mount_args;
30
31
32         rtems_filesystem_register(RTEMS_FILESYSTEM_TYPE_YAFFS,
33                                   rtems_yaffs_mount_handler);
34
35         // We mount the filesystem by passing an appropriate
36         // rtems_yaffs_mount_data as the last argument to mount(). mount_data is
37         // used to pass a yaffs_dev pointer by-value.
38
39
40         device = yaffs_rtems_flashsim_setup();
41
42         // Initialize callback storage for RTEMS's VFS inside the yaffs_dev.
43         os_context = malloc(sizeof(rtems_yaffs_default_os_context));
44         rtems_yaffs_initialize_default_os_context(os_context);
45
46         device->os_context = os_context;
47
48         mount_args.dev = device;
49
50         if (mount_and_make_target_path(NULL,
51                               mount_target,
52                               RTEMS_FILESYSTEM_TYPE_YAFFS,
53                               RTEMS_FILESYSTEM_READ_WRITE,
54                               &mount_args) < 0) {
55                 perror("mount_and_make");
56                 return errno;
57         } else {
58                 chmod(mount_target, 0777); /* Make partition rw/modifiable */
59                 return 0;
60         }
61 }
62
63 extern int run_the_test(void);
64
65 rtems_task Init(
66   rtems_task_argument ignored
67 )
68 {
69         int err;
70
71          printf("Starting\n");
72
73         err = filesystem_init(YPATH);
74
75         printf("filesystem_init(\"%s\") returned %d\n", YPATH, err);
76
77         run_the_test();
78
79         yaffs_rtems_flashsim_dump_status();
80
81    exit(0);
82 }
83
84
85
86
87 #if 0
88 So basically, we are registering our NAND-specific callbacks with YAFFS
89 and registering the RTEMS-YAFFS filesystem callbacks with RTEMS.
90 The rtems_filesystem_register() associates the mount() system call with
91 a callback function to handle that system call, in this case
92 rtems_yaffs_mount_handler().  rtems_yaffs_mount_handler() and
93 RTEMS_FILESYSTEM_TYPE_YAFFS (just a string) are provided
94 by the rtems-yaffs fork.
95
96 mount_and_make_target_path() is provided by RTEMS: it combines a
97 mkdir -p` with mount(), passing the mount_args to the
98 previously-registered handler.
99 #endif
100
101
102 /* configuration information */
103
104 /* NOTICE: the clock driver is explicitly disabled */
105 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
106 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
107
108 #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
109 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 32
110
111 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
112 #define CONFIGURE_MAXIMUM_TASKS 1
113
114 #define CONFIGURE_MAXIMUM_SEMAPHORES        20
115
116 #define CONFIGURE_INIT
117
118 #include <rtems/confdefs.h>
119 /* end of file */