2 * Simple test program -- demonstrating use of IMFS
14 #include <rtems/libio.h>
15 #include <yaffs/rtems_yaffs.h>
18 #define YPATH "/yaffs_mount_pt"
24 void set_uint8_t_buffer(uint8_t *buf, uint32_t n, uint8_t start, uint8_t inc)
35 #define FNAME YPATH"/test"
36 #define DIRNAME YPATH"/dirtest"
38 void dump_directory_tree_worker(const char *dname,int recursive)
49 printf("opendir failed\n");
53 while((de = readdir(d)) != NULL)
55 sprintf(str,"%s/%s",dname,de->d_name);
59 printf("%s inode %d length %d mode %X ",
60 str, (int)s.st_ino, (int)s.st_size, s.st_mode);
61 switch(s.st_mode & S_IFMT)
63 case S_IFREG: printf("data file"); break;
64 case S_IFDIR: printf("directory"); break;
65 case S_IFLNK: printf("symlink -->");
66 if(readlink(str,str,100) < 0)
71 default: printf("unknown"); break;
76 if((s.st_mode & S_IFMT) == S_IFDIR && recursive)
77 dump_directory_tree_worker(str,1);
86 static void dump_directory_tree(const char *dname)
88 dump_directory_tree_worker(dname,1);
92 void dumpDir(const char *dname)
93 { dump_directory_tree_worker(dname,0);
96 int run_the_test(void)
104 dump_directory_tree(YPATH);
106 ret = mkdir(DIRNAME, 0777);
108 perror("mkdir "DIRNAME);
110 fd = open(FNAME, O_RDWR | O_CREAT | O_TRUNC, 0666);
111 printf("open %s = %d\n", FNAME, fd);
113 perror("opening " FNAME);
115 set_uint8_t_buffer(buf, sizeof(buf), 0xAA, 1);
117 ret = write(fd, buf, sizeof(buf));
119 printf("write returned %d\n", ret);
122 perror("writing file");
124 ret = lseek(fd, 0, SEEK_END);
126 printf("lseek end ret = %d\n", ret);
128 ret = lseek(fd, 0, SEEK_SET);
129 printf("lseek start ret = %d\n", ret);
131 ret = read(fd, buf2, sizeof(buf2));
133 printf("reading file ret = %d\n", ret);
136 perror("reading file");
144 fd = open("test1", O_CREAT);
145 printf( "fcntl flags =0x%x\n", fcntl( fd, F_GETFL ) );
148 fd = open("test", O_RDONLY);
150 printf("Starting on the wrong foot....\n");
154 printf( "fcntl flags =0x%x\n", fcntl( fd, F_GETFL ) );
156 fp = fdopen(fd, "r");
158 printf("Nothing ever goes my way!\n");
162 printf("Soon, I will be able to take over the world!\n");