2 * Simple test program -- demonstrating use of IMFS
12 #include <rtems/libio.h>
13 #include <yaffs/rtems_yaffs.h>
15 #include "yaffs-rtems-flashsim.h"
17 //#define YPATH "/yaffs_mount_pt/"
20 void yaffs_bug_fn(const char *file_name, int line_no)
22 printf("Yaffs bug at %s:%d\n", file_name, line_no);
25 int filesystem_init(const char *mount_target)
27 struct yaffs_dev *device;
28 rtems_yaffs_default_os_context *os_context;
29 rtems_yaffs_mount_data mount_args;
32 rtems_filesystem_register(RTEMS_FILESYSTEM_TYPE_YAFFS,
33 rtems_yaffs_mount_handler);
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.
40 device = yaffs_rtems_flashsim_setup();
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);
46 device->os_context = os_context;
48 mount_args.dev = device;
50 if (mount_and_make_target_path(NULL,
51 NULL /*mount_target */,
52 RTEMS_FILESYSTEM_TYPE_YAFFS,
53 RTEMS_FILESYSTEM_READ_WRITE,
62 void set_uint8_t_buffer(uint8_t *buf, uint32_t n, uint8_t start, uint8_t inc)
72 int run_basic_file_test(void)
79 fd = open(YPATH"/test", O_RDWR | O_CREAT | O_TRUNC, 0666);
80 printf("open = %d\n", fd);
82 set_uint8_t_buffer(buf, sizeof(buf), 0xAA, 1);
84 ret = write(fd, buf, sizeof(buf));
86 printf("write returned %d\n", ret);
89 perror("writing file");
91 ret = lseek(fd, 0, SEEK_END);
93 printf("lseek end ret = %d\n", ret);
95 ret = lseek(fd, 0, SEEK_SET);
96 printf("lseek start ret = %d\n", ret);
98 ret = read(fd, buf2, sizeof(buf2));
100 printf("reading file ret = %d\n", ret);
103 perror("reading file");
111 fd = open("test1", O_CREAT);
112 printf( "fcntl flags =0x%x\n", fcntl( fd, F_GETFL ) );
115 fd = open("test", O_RDONLY);
117 printf("Starting on the wrong foot....\n");
121 printf( "fcntl flags =0x%x\n", fcntl( fd, F_GETFL ) );
123 fp = fdopen(fd, "r");
125 printf("Nothing ever goes my way!\n");
129 printf("Soon, I will be able to take over the world!\n");
139 rtems_task_argument ignored
144 printf("Starting\n");
146 err = filesystem_init(YPATH);
148 printf("filesystem_init(\"%s\") returned %d\n", YPATH, err);
150 run_basic_file_test();
160 So basically, we are registering our NAND-specific callbacks with YAFFS
161 and registering the RTEMS-YAFFS filesystem callbacks with RTEMS.
162 The rtems_filesystem_register() associates the mount() system call with
163 a callback function to handle that system call, in this case
164 rtems_yaffs_mount_handler(). rtems_yaffs_mount_handler() and
165 RTEMS_FILESYSTEM_TYPE_YAFFS (just a string) are provided
166 by the rtems-yaffs fork.
168 mount_and_make_target_path() is provided by RTEMS: it combines a
169 mkdir -p` with mount(), passing the mount_args to the
170 previously-registered handler.
174 /* configuration information */
176 /* NOTICE: the clock driver is explicitly disabled */
177 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
178 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
180 #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
181 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 6
183 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
184 #define CONFIGURE_MAXIMUM_TASKS 1
186 #define CONFIGURE_MAXIMUM_SEMAPHORES 20
188 #define CONFIGURE_INIT
190 #include <rtems/confdefs.h>