static bool open_and_sort_dir(vfs_handle_struct *handle, struct dirsort_privates *data) { unsigned int i = 0; unsigned int total_count = 0; data->number_of_entries = 0; if (get_sorted_dir_mtime(handle, data, &data->mtime) == false) { return false; } while (SMB_VFS_NEXT_READDIR(handle, data->source_directory, NULL) != NULL) { total_count++; } if (total_count == 0) { return false; } /* Open the underlying directory and count the number of entries Skip back to the beginning as we'll read it again */ SMB_VFS_NEXT_REWINDDIR(handle, data->source_directory); /* Set up an array and read the directory entries into it */ TALLOC_FREE(data->directory_list); /* destroy previous cache if needed */ data->directory_list = talloc_zero_array(data, struct dirent, total_count); if (!data->directory_list) { return false; } for (i = 0; i < total_count; i++) { struct dirent *dp = SMB_VFS_NEXT_READDIR(handle, data->source_directory, NULL); if (dp == NULL) { break; } data->directory_list[i] = *dp; } data->number_of_entries = i; /* Sort the directory entries by name */ TYPESAFE_QSORT(data->directory_list, data->number_of_entries, compare_dirent); return true; }
static bool open_and_sort_dir (vfs_handle_struct *handle) { SMB_STRUCT_DIRENT *dp; struct stat dir_stat; long current_pos; struct dirsort_privates *data = NULL; SMB_VFS_HANDLE_GET_DATA(handle, data, struct dirsort_privates, return false); data->number_of_entries = 0; if (fstat(data->fd, &dir_stat) == 0) { data->mtime = dir_stat.st_mtime; } while (SMB_VFS_NEXT_READDIR(handle, data->source_directory, NULL) != NULL) { data->number_of_entries++; } /* Open the underlying directory and count the number of entries Skip back to the beginning as we'll read it again */ SMB_VFS_NEXT_REWINDDIR(handle, data->source_directory); /* Set up an array and read the directory entries into it */ SAFE_FREE(data->directory_list); /* destroy previous cache if needed */ data->directory_list = (SMB_STRUCT_DIRENT *)SMB_MALLOC( data->number_of_entries * sizeof(SMB_STRUCT_DIRENT)); if (!data->directory_list) { return false; } current_pos = data->pos; data->pos = 0; while ((dp = SMB_VFS_NEXT_READDIR(handle, data->source_directory, NULL)) != NULL) { data->directory_list[data->pos++] = *dp; } /* Sort the directory entries by name */ data->pos = current_pos; TYPESAFE_QSORT(data->directory_list, data->number_of_entries, compare_dirent); return true; }
static struct dirent *cap_readdir(vfs_handle_struct *handle, connection_struct *conn, DIR *dirp) { struct dirent *result; DEBUG(3,("cap: cap_readdir\n")); result = SMB_VFS_NEXT_READDIR(handle, conn, dirp); if (result) { DEBUG(3,("cap: cap_readdir: %s\n", result->d_name)); capdecode(result->d_name, result->d_name); } return result; }
static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle, files_struct *fsp, SHADOW_COPY_DATA *shadow_copy_data, BOOL labels) { DIR *p = SMB_VFS_NEXT_OPENDIR(handle,fsp->conn,fsp->conn->connectpath); shadow_copy_data->num_volumes = 0; shadow_copy_data->labels = NULL; if (!p) { DEBUG(0,("shadow_copy_get_shadow_copy_data: SMB_VFS_NEXT_OPENDIR() failed for [%s]\n",fsp->conn->connectpath)); return -1; } while (True) { SHADOW_COPY_LABEL *tlabels; SMB_STRUCT_DIRENT *d; d = SMB_VFS_NEXT_READDIR(handle, fsp->conn, p); if (d == NULL) { break; } /* */ if (!shadow_copy_match_name(d->d_name)) { DEBUG(10,("shadow_copy_get_shadow_copy_data: ignore [%s]\n",d->d_name)); continue; } DEBUG(7,("shadow_copy_get_shadow_copy_data: not ignore [%s]\n",d->d_name)); if (!labels) { shadow_copy_data->num_volumes++; continue; } tlabels = (SHADOW_COPY_LABEL *)TALLOC_REALLOC(shadow_copy_data->mem_ctx, shadow_copy_data->labels, (shadow_copy_data->num_volumes+1)*sizeof(SHADOW_COPY_LABEL)); if (tlabels == NULL) { DEBUG(0,("shadow_copy_get_shadow_copy_data: Out of memory\n")); SMB_VFS_NEXT_CLOSEDIR(handle,fsp->conn,p); return -1; } snprintf(tlabels[shadow_copy_data->num_volumes++], sizeof(*tlabels), "%s",d->d_name); shadow_copy_data->labels = tlabels; } SMB_VFS_NEXT_CLOSEDIR(handle,fsp->conn,p); return 0; }
static DIR *shadow_copy_opendir(vfs_handle_struct *handle, connection_struct *conn, const char *fname) { shadow_copy_Dir *dirp; DIR *p = SMB_VFS_NEXT_OPENDIR(handle,conn,fname); if (!p) { DEBUG(0,("shadow_copy_opendir: SMB_VFS_NEXT_OPENDIR() failed for [%s]\n",fname)); return NULL; } dirp = SMB_MALLOC_P(shadow_copy_Dir); if (!dirp) { DEBUG(0,("shadow_copy_opendir: Out of memory\n")); SMB_VFS_NEXT_CLOSEDIR(handle,conn,p); return NULL; } ZERO_STRUCTP(dirp); while (True) { SMB_STRUCT_DIRENT *d; SMB_STRUCT_DIRENT *r; d = SMB_VFS_NEXT_READDIR(handle, conn, p); if (d == NULL) { break; } if (shadow_copy_match_name(d->d_name)) { DEBUG(8,("shadow_copy_opendir: hide [%s]\n",d->d_name)); continue; } DEBUG(10,("shadow_copy_opendir: not hide [%s]\n",d->d_name)); r = SMB_REALLOC_ARRAY(dirp->dirs,SMB_STRUCT_DIRENT, dirp->num+1); if (!r) { DEBUG(0,("shadow_copy_opendir: Out of memory\n")); break; } dirp->dirs = r; dirp->dirs[dirp->num++] = *d; } SMB_VFS_NEXT_CLOSEDIR(handle,conn,p); return((DIR *)dirp); }
static struct dirent *skel_readdir(vfs_handle_struct *handle, DIR *dirp, SMB_STRUCT_STAT *sbuf) { return SMB_VFS_NEXT_READDIR(handle, dirp, sbuf); }
static SMB_STRUCT_DIRENT *skel_readdir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp) { return SMB_VFS_NEXT_READDIR(handle, dirp); }