void cmd_yaffs_ls(const char *mountpt, int longlist) { int i; yaffs_DIR *d; yaffs_dirent *de; struct yaffs_stat stat; char tempstr[255]; checkMount(); d = yaffs_opendir(mountpt); if(!d) { printf("opendir failed\n"); } else { for(i = 0; (de = yaffs_readdir(d)) != NULL; i++) { if (longlist) { sprintf(tempstr, "%s/%s", mountpt, de->d_name); yaffs_stat(tempstr, &stat); printf("%-25s\t%7ld\n",de->d_name, stat.st_size); } else { printf("%s\n",de->d_name); } } } }
void cmd_yaffs_ls(const char *mountpt, int longlist) { int i; yaffs_DIR *d; struct yaffs_dirent *de; struct yaffs_stat stat; char tempstr[255]; d = yaffs_opendir(mountpt); if (!d) { printf("opendir failed, %s\n", yaffs_error_str()); return; } for (i = 0; (de = yaffs_readdir(d)) != NULL; i++) { if (longlist) { sprintf(tempstr, "%s/%s", mountpt, de->d_name); yaffs_lstat(tempstr, &stat); printf("%-25s\t%7ld", de->d_name, (long)stat.st_size); printf(" %5d %s\n", stat.st_ino, yaffs_file_type_str(&stat)); } else { printf("%s\n", de->d_name); } } yaffs_closedir(d); }
/*============================================================================== * - _album_add_file() * * - search all file in <path> dir, and add extern with <ext> to list */ static int _album_add_file (const char *path, const char *ext) { yaffs_DIR *d; yaffs_dirent *de; int i; PIC_NAME_NODE *pNewPic = NULL; int file_name_len; d = yaffs_opendir(path); for(i = 0; (de = yaffs_readdir(d)) != NULL; i++) { file_name_len = strlen (de->d_name); if (strlen(path) + file_name_len < PATH_LEN_MAX && /* file name not too long */ strcmp (de->d_name + file_name_len - strlen(ext), ext) == 0) { pNewPic = malloc (sizeof (PIC_NAME_NODE)); if (pNewPic != NULL) { strcpy(pNewPic->name, path); strcat(pNewPic->name, de->d_name); dlist_add (&_G_pic_list, (DL_NODE *)pNewPic); } } } yaffs_closedir(d); return i; }
static struct dirent *__yaffs_readdir(mount_point_t *point, file_t *file) { /* * 重要: 必须要调整 struct yaffs_dirent 结构成员位置后才能转换类型 */ return (struct dirent *)yaffs_readdir(file->ctx);
int huge_directory_test_on_path(char *path) { yaffs_DIR *d; yaffs_dirent *de; struct yaffs_stat s; int f; int i; int total = 0; int lastTotal = 0; char str[100]; yaffs_StartUp(); yaffs_mount(path); // Create a large number of files for(i = 0; i < 2000; i++) { sprintf(str,"%s/%d",path,i); f = yaffs_open(str,O_CREAT,S_IREAD | S_IWRITE); yaffs_close(f); } d = yaffs_opendir(path); i = 0; if (d) { while((de = yaffs_readdir(d)) != NULL) { if (total >lastTotal+100*9*1024||(i & 1023)==0){ printf("files = %d, total = %d\n",i, total); lastTotal = total; } i++; sprintf(str,"%s/%s",path,de->d_name); yaffs_lstat(str,&s); switch(s.st_mode & S_IFMT){ case S_IFREG: //printf("data file"); total += s.st_size; break; } } yaffs_closedir(d); } return 0; }
static void dump_directory_tree_worker(const char *dname,int recursive) { yaffs_DIR *d; yaffs_dirent *de; struct yaffs_stat s; char str[1000]; d = yaffs_opendir(dname); if(!d) { printf("opendir failed\n"); } else { while((de = yaffs_readdir(d)) != NULL) { strcpy(str,dname); strcat(str,"/"); strcat(str,de->d_name); yaffs_lstat(str,&s); printf("%s inode %d obj %x length %d mode %X ",str,s.st_ino,de->d_dont_use,(int)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(str,1); if(s.st_ino > 10000) FatalError(); } yaffs_closedir(d); } }
/* ** Directory iterator */ static int dir_iter (lua_State *L) { struct yaffs_dirent *entry; dir_data *d = (dir_data *)luaL_checkudata (L, 1, DIR_METATABLE); luaL_argcheck (L, d->closed == 0, 1, "closed directory"); if ((entry = yaffs_readdir (d->dir)) != NULL) { lua_pushstring (L, entry->d_name); return 1; } else { /* no more entries => close directory */ yaffs_closedir (d->dir); d->closed = 1; return 0; } }
void dumpDirFollow(const char *dname) { yaffs_DIR *d; yaffs_dirent *de; struct yaffs_stat s; char str[100]; d = yaffs_opendir(dname); if(!d) { printf("opendir failed\n"); } else { while((de = yaffs_readdir(d)) != NULL) { sprintf(str,"%s/%s",dname,de->d_name); yaffs_stat(str,&s); printf("%s ino %d length %d mode %X ",de->d_name,(int)s.st_ino,(int)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"); } yaffs_closedir(d); } printf("\n"); printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname)); }
/*============================================================================== * - ls() * * - list the files and direcories in a directory */ int ls(int argc, char *argv[]) { int i, j; char dir[PATH_LEN_MAX]; yaffs_DIR *d; yaffs_dirent *de; if (argc < 2) { strcpy(dir, _G_pwd); } else { _make_abs_path(dir, argv[1]); } d = yaffs_opendir(dir); if(!d) { serial_printf("opendir failed"); return CMD_ERROR; } else { for(i = 0; (de = yaffs_readdir(d)) != NULL; i++) { if ((i != 0) && (i % NAMES_PER_LINE) == 0 ) { serial_printf("\n"); } if (yaffs_is_dir2 (dir, de->d_name)) { serial_printf (COLOR_FG_GREEN); } else { serial_printf (COLOR_FG_WHITE); } serial_printf ("%s", de->d_name); for (j = strlen (de->d_name); j < NAME_WIDTH; j++) { serial_putc (' '); } } serial_printf (COLOR_FG_WHITE); } yaffs_closedir(d); return CMD_OK; }
/*============================================================================== * - _list_dir() * * - refresh the directory list nodes */ static int _list_dir (const char *path, DL_LIST *pDirList) { int i; yaffs_DIR *d; yaffs_dirent *de; DIR_LIST_NODE *pListNode = NULL; char full_name[PATH_LEN_MAX]; d = yaffs_opendir(path); /* free previous list nodes */ pListNode = (DIR_LIST_NODE *)dlist_get (pDirList); while (pListNode != NULL) { free (pListNode); pListNode = (DIR_LIST_NODE *)dlist_get (&_G_dir_list); } if (!d) { return 0; } /* alloc new list nodes */ for(i = 0; (de = yaffs_readdir(d)) != NULL; i++) { pListNode = malloc (sizeof (DIR_LIST_NODE)); if (pListNode != NULL) { strcpy(pListNode->name, de->d_name); strcpy(full_name, path); strcat(full_name, de->d_name); if (yaffs_is_dir (full_name)) { strcat(pListNode->name, "/"); } dlist_add (pDirList, (DL_NODE *)pListNode); } } yaffs_closedir(d); return i; }
void ListDir(const char *DirName) { yaffs_DIR *d; yaffs_dirent *de; struct yaffs_stat s; char str[100]; d = yaffs_opendir(DirName); if(!d) { printf("opendir failed\n"); } else { printf("%s\n", DirName); while((de = yaffs_readdir(d)) != NULL) { sprintf(str,"%s/%s",DirName,de->d_name); yaffs_lstat(str,&s); printf("%20s %8d %5d ", de->d_name, s.yst_size, s.yst_mode); switch(s.yst_mode & S_IFMT) { case S_IFREG: printf("data file"); break; case S_IFDIR: printf("directory"); break; case S_IFLNK: printf("symlink"); break; default: printf("unknown"); break; } printf("\n"); } yaffs_closedir(d); } printf("FreeSpace: %d\n\n", yaffs_freespace(DirName)); }
void test_b(void *x) { struct bovver_context *bc = (struct bovver_context *)x; int n = rand() % 20; bc->cycle++; if(!bc->dirH) bc->dirH = yaffs_opendir(bc->baseDir); if(!bc->dirH) return; if(n == 0){ yaffs_closedir(bc->dirH); bc->dirH = NULL; } else { while(n > 1){ n--; yaffs_readdir(bc->dirH); } } }
void lookup_test(const char *mountpt) { int i; int h; char a[100]; yaffs_DIR *d; yaffs_dirent *de; yaffs_StartUp(); yaffs_mount(mountpt); d = yaffs_opendir(mountpt); if(!d) { printf("opendir failed\n"); } else { for(i = 0; (de = yaffs_readdir(d)) != NULL; i++) { printf("unlinking %s\n",de->d_name); yaffs_unlink(de->d_name); } printf("%d files deleted\n",i); } for(i = 0; i < 2000; i++){ sprintf(a,"%s/%d",mountpt,i); h = yaffs_open(a,O_CREAT | O_TRUNC | O_RDWR, 0); yaffs_close(h); } yaffs_rewinddir(d); for(i = 0; (de = yaffs_readdir(d)) != NULL; i++) { printf("%d %s\n",i,de->d_name); } printf("%d files listed\n\n\n",i); yaffs_rewinddir(d); yaffs_readdir(d); yaffs_readdir(d); yaffs_readdir(d); for(i = 0; i < 2000; i++){ sprintf(a,"%s/%d",mountpt,i); yaffs_unlink(a); } yaffs_unmount(mountpt); }