/** * Set the next direntry to be read via onefs_readdir() to the beginning of the * directory. * * @param[in] handle vfs handle given in most VFS calls * @param[in] dirp system DIR handle to set offset on * * @return no return value */ void onefs_rewinddir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp) { struct rdp_dir_state *dsp = NULL; bool same_as_last; int ret = -1; /* Fallback to default system routines if readdirplus is disabled */ if (!lp_parm_bool(SNUM(handle->conn), PARM_ONEFS_TYPE, PARM_USE_READDIRPLUS, PARM_USE_READDIRPLUS_DEFAULT)) { return sys_rewinddir(dirp); } /* Retrieve state based off DIR handle */ ret = rdp_retrieve_dir_state(dirp, &dsp, &same_as_last); if (ret) { DEBUG(1, ("Could not retrieve dir_state struct for " "SMB_STRUCT_DIR pointer.\n")); return; } /* Reset location and resume key to beginning */ ret = rdp_init(dsp); if (ret) { DEBUG(0, ("Error re-initializing rdp cursors: %s\n", strerror(ret))); return; } DEBUG(9, ("Rewind DIR: %p, to location: %ld\n", dsp->dirp, dsp->location)); return; }
/* * rewind a directory */ int rewinddir(void * dir) { struct dir * pdir; struct file_t * fp; if(!dir) return -1; pdir = (struct dir *)dir; if((fp = get_fp(pdir->fd)) == NULL) return -1; return sys_rewinddir(fp); }
int main(void) { put_str("I am kernel\n"); init_all(); /******** 测试代码 ********/ printf("/dir1 content before delete /dir1/subdir1:\n"); struct dir* dir = sys_opendir("/dir1/"); char* type = NULL; struct dir_entry* dir_e = NULL; while((dir_e = sys_readdir(dir))) { if (dir_e->f_type == FT_REGULAR) { type = "regular"; } else { type = "directory"; } printf(" %s %s\n", type, dir_e->filename); } printf("try to delete nonempty directory /dir1/subdir1\n"); if (sys_rmdir("/dir1/subdir1") == -1) { printf("sys_rmdir: /dir1/subdir1 delete fail!\n"); } printf("try to delete /dir1/subdir1/file2\n"); if (sys_rmdir("/dir1/subdir1/file2") == -1) { printf("sys_rmdir: /dir1/subdir1/file2 delete fail!\n"); } if (sys_unlink("/dir1/subdir1/file2") == 0 ) { printf("sys_unlink: /dir1/subdir1/file2 delete done\n"); } printf("try to delete directory /dir1/subdir1 again\n"); if (sys_rmdir("/dir1/subdir1") == 0) { printf("/dir1/subdir1 delete done!\n"); } printf("/dir1 content after delete /dir1/subdir1:\n"); sys_rewinddir(dir); while((dir_e = sys_readdir(dir))) { if (dir_e->f_type == FT_REGULAR) { type = "regular"; } else { type = "directory"; } printf(" %s %s\n", type, dir_e->filename); } /******** 测试代码 ********/ while(1); return 0; }
void vfswrap_rewinddir(vfs_handle_struct *handle, connection_struct *conn, SMB_STRUCT_DIR *dirp) { START_PROFILE(syscall_rewinddir); sys_rewinddir(dirp); END_PROFILE(syscall_rewinddir); }