+void dump_directory_tree_worker_fd(const char *dname,int recursive)
+{
+ int h;
+ struct yaffs_dirent *de;
+ struct yaffs_stat s;
+ char str[1000];
+
+ h = yaffs_open(dname, O_RDONLY, 0);
+
+ if(h < 0)
+ {
+ printf("open of dir failed\n");
+ }
+ else
+ {
+ printf("using fd %d\n", h);
+
+ while((de = yaffs_readdir_fd(h)) != NULL)
+ {
+ sprintf(str,"%s/%s",dname,de->d_name);
+
+ yaffs_lstat(str,&s);
+
+ printf("%s inode %d obj %x length %lld mode %X ",
+ str,s.st_ino,de->d_dont_use, s.st_size,s.st_mode);
+ switch(s.st_mode & S_IFMT)
+ {
+ case S_IFREG: printf("data file"); break;
+ case S_IFDIR: printf("directory"); break;
+ case S_IFLNK: printf("symlink -->");
+ if(yaffs_readlink(str,str,100) < 0)
+ printf("no alias");
+ else
+ printf("\"%s\"",str);
+ break;
+ default: printf("unknown"); break;
+ }
+
+ printf("\n");
+
+ if((s.st_mode & S_IFMT) == S_IFDIR && recursive)
+ dump_directory_tree_worker_fd(str,1);
+
+ }
+
+ yaffs_close(h);
+ }
+
+}
+
+static void dump_directory_tree_fd(const char *dname)
+{
+ dump_directory_tree_worker_fd(dname,1);
+ printf("\n");
+ printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
+}
+