return NULL;
}
+static SMB_STRUCT_DIR *skel_fdopendir(vfs_handle_struct *handle, files_struct *fsp, const char *mask, uint32 attr)
+{
+ return NULL;
+}
+
static SMB_STRUCT_DIRENT *skel_readdir(vfs_handle_struct *handle,
SMB_STRUCT_DIR *dirp,
SMB_STRUCT_STAT *sbuf)
/* Directory operations */
.opendir = skel_opendir,
+ .fdopendir = skel_fdopendir,
.readdir = skel_readdir,
.seekdir = skel_seekdir,
.telldir = skel_telldir,
return SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
}
+static SMB_STRUCT_DIR *skel_fdopendir(vfs_handle_struct *handle, files_struct *fsp, const char *mask, uint32 attr)
+{
+ return SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
+}
+
static SMB_STRUCT_DIRENT *skel_readdir(vfs_handle_struct *handle,
SMB_STRUCT_DIR *dirp,
SMB_STRUCT_STAT *sbuf)
/* Directory operations */
.opendir = skel_opendir,
+ .fdopendir = skel_fdopendir,
.readdir = skel_readdir,
.seekdir = skel_seekdir,
.telldir = skel_telldir,
#define syscall_opendir_count __profile_stats_value(PR_VALUE_SYSCALL_OPENDIR, count)
#define syscall_opendir_time __profile_stats_value(PR_VALUE_SYSCALL_OPENDIR, time)
+ PR_VALUE_SYSCALL_FDOPENDIR,
+#define syscall_fdopendir_count __profile_stats_value(PR_VALUE_SYSCALL_FDOPENDIR, count)
+#define syscall_fdopendir_time __profile_stats_value(PR_VALUE_SYSCALL_FDOPENDIR, time)
+
PR_VALUE_SYSCALL_READDIR,
#define syscall_readdir_count __profile_stats_value(PR_VALUE_SYSCALL_READDIR, count)
#define syscall_readdir_time __profile_stats_value(PR_VALUE_SYSCALL_READDIR, time)
where it belongs. JRA. */
/* Leave at 28 - not yet released. Rename posix_fallocate to fallocate
to split out the two possible uses. JRA. */
+/* Leave at 28 - not yet released. Add fdopendir. JRA. */
#define SMB_VFS_INTERFACE_VERSION 28
/* Directory operations */
SMB_STRUCT_DIR *(*opendir)(struct vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attributes);
+ SMB_STRUCT_DIR *(*fdopendir)(struct vfs_handle_struct *handle, files_struct *fsp, const char *mask, uint32 attributes);
SMB_STRUCT_DIRENT *(*readdir)(struct vfs_handle_struct *handle,
SMB_STRUCT_DIR *dirp,
SMB_STRUCT_STAT *sbuf);
SMB_STRUCT_DIR *smb_vfs_call_opendir(struct vfs_handle_struct *handle,
const char *fname, const char *mask,
uint32 attributes);
+SMB_STRUCT_DIR *smb_vfs_call_fdopendir(struct vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ const char *mask,
+ uint32 attributes);
SMB_STRUCT_DIRENT *smb_vfs_call_readdir(struct vfs_handle_struct *handle,
SMB_STRUCT_DIR *dirp,
SMB_STRUCT_STAT *sbuf);
#define SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr) \
smb_vfs_call_opendir((handle)->next, (fname), (mask), (attr))
+#define SMB_VFS_FDOPENDIR(conn, fsp, mask, attr) \
+ smb_vfs_call_fdopendir((conn)->vfs_handles, (fsp), (mask), (attr))
+#define SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr) \
+ smb_vfs_call_fdopendir((handle)->next, (fsp), (mask), (attr))
+
#define SMB_VFS_READDIR(conn, dirp, sbuf) \
smb_vfs_call_readdir((conn)->vfs_handles, (dirp), (sbuf))
#define SMB_VFS_NEXT_READDIR(handle, dirp, sbuf) \
return result;
}
+static SMB_STRUCT_DIR *vfswrap_fdopendir(vfs_handle_struct *handle,
+ files_struct *fsp,
+ const char *mask,
+ uint32 attr)
+{
+ SMB_STRUCT_DIR *result;
+
+ START_PROFILE(syscall_fdopendir);
+ result = sys_fdopendir(fsp->fh->fd);
+ END_PROFILE(syscall_fdopendir);
+ return result;
+}
+
+
static SMB_STRUCT_DIRENT *vfswrap_readdir(vfs_handle_struct *handle,
SMB_STRUCT_DIR *dirp,
SMB_STRUCT_STAT *sbuf)
return data->source_directory;
}
+static SMB_STRUCT_DIR *dirsort_fdopendir(vfs_handle_struct *handle,
+ files_struct *fsp,
+ const char *mask,
+ uint32 attr)
+{
+ struct dirsort_privates *data = NULL;
+
+ /* set up our private data about this directory */
+ data = (struct dirsort_privates *)SMB_MALLOC(
+ sizeof(struct dirsort_privates));
+
+ if (!data) {
+ return NULL;
+ }
+
+ data->directory_list = NULL;
+ data->pos = 0;
+
+ /* Open the underlying directory and count the number of entries */
+ data->source_directory = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask,
+ attr);
+
+ if (data->source_directory == NULL) {
+ SAFE_FREE(data);
+ return NULL;
+ }
+
+ data->fd = dirfd(data->source_directory);
+
+ SMB_VFS_HANDLE_SET_DATA(handle, data, free_dirsort_privates,
+ struct dirsort_privates, return NULL);
+
+ if (!open_and_sort_dir(handle)) {
+ SMB_VFS_NEXT_CLOSEDIR(handle,data->source_directory);
+ /* fd is now closed. */
+ fsp->fh->fd = -1;
+ return NULL;
+ }
+
+ return data->source_directory;
+}
+
static SMB_STRUCT_DIRENT *dirsort_readdir(vfs_handle_struct *handle,
SMB_STRUCT_DIR *dirp,
SMB_STRUCT_STAT *sbuf)
static struct vfs_fn_pointers vfs_dirsort_fns = {
.opendir = dirsort_opendir,
+ .fdopendir = dirsort_fdopendir,
.readdir = dirsort_readdir,
.seekdir = dirsort_seekdir,
.telldir = dirsort_telldir,
/* Directory operations */
SMB_VFS_OP_OPENDIR,
+ SMB_VFS_OP_FDOPENDIR,
SMB_VFS_OP_READDIR,
SMB_VFS_OP_SEEKDIR,
SMB_VFS_OP_TELLDIR,
{ SMB_VFS_OP_STATVFS, "statvfs" },
{ SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" },
{ SMB_VFS_OP_OPENDIR, "opendir" },
+ { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
{ SMB_VFS_OP_READDIR, "readdir" },
{ SMB_VFS_OP_SEEKDIR, "seekdir" },
{ SMB_VFS_OP_TELLDIR, "telldir" },
return result;
}
+static SMB_STRUCT_DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
+ files_struct *fsp, const char *mask, uint32 attr)
+{
+ SMB_STRUCT_DIR *result;
+
+ result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
+
+ do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
+ fsp_str_do_log(fsp));
+
+ return result;
+}
+
static SMB_STRUCT_DIRENT *smb_full_audit_readdir(vfs_handle_struct *handle,
SMB_STRUCT_DIR *dirp, SMB_STRUCT_STAT *sbuf)
{
.statvfs = smb_full_audit_statvfs,
.fs_capabilities = smb_full_audit_fs_capabilities,
.opendir = smb_full_audit_opendir,
+ .fdopendir = smb_full_audit_fdopendir,
.readdir = smb_full_audit_readdir,
.seekdir = smb_full_audit_seekdir,
.telldir = smb_full_audit_telldir,
return ret;
}
+static SMB_STRUCT_DIR *atalk_fdopendir(struct vfs_handle_struct *handle, files_struct *fsp, const char *mask, uint32 attr)
+{
+ SMB_STRUCT_DIR *ret = 0;
+
+ ret = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
+
+ if (ret == NULL) {
+ return ret;
+ }
+
+ /*
+ * when we try to perform delete operation upon file which has fork
+ * in ./.AppleDouble and this directory wasn't hidden by Samba,
+ * MS Windows explorer causes the error: "Cannot find the specified file"
+ * There is some workaround to avoid this situation, i.e. if
+ * connection has not .AppleDouble entry in either veto or hide
+ * list then it would be nice to add one.
+ */
+
+ atalk_add_to_list(&handle->conn->hide_list);
+ atalk_add_to_list(&handle->conn->veto_list);
+
+ return ret;
+}
+
static int atalk_rmdir(struct vfs_handle_struct *handle, const char *path)
{
bool add = False;
static struct vfs_fn_pointers vfs_netatalk_fns = {
.opendir = atalk_opendir,
+ .fdopendir = atalk_fdopendir,
.rmdir = atalk_rmdir,
.rename = atalk_rename,
.unlink = atalk_unlink,
return (SMB_STRUCT_DIR *) sDIR;
}
+static SMB_STRUCT_DIR *scannedonly_fdopendir(vfs_handle_struct * handle,
+ files_struct *fsp,
+ const char *mask, uint32 attr)
+{
+ SMB_STRUCT_DIR *DIRp;
+ struct scannedonly_DIR *sDIR;
+ const char *fname;
+
+ DIRp = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
+ if (!DIRp) {
+ return NULL;
+ }
+
+ fname = (const char *)fsp->fsp_name->base_name;
+
+ sDIR = TALLOC_P(NULL, struct scannedonly_DIR);
+ if (fname[0] != '/') {
+ sDIR->base = construct_full_path(sDIR,handle, fname, true);
+ } else {
+ sDIR->base = name_w_ending_slash(sDIR, fname);
+ }
+ DEBUG(SCANNEDONLY_DEBUG,
+ ("scannedonly_fdopendir, fname=%s, base=%s\n",fname,sDIR->base));
+ sDIR->DIR = DIRp;
+ sDIR->notify_loop_done = 0;
+ return (SMB_STRUCT_DIR *) sDIR;
+}
+
+
static SMB_STRUCT_DIRENT *scannedonly_readdir(vfs_handle_struct *handle,
SMB_STRUCT_DIR * dirp,
SMB_STRUCT_STAT *sbuf)
/* VFS operations structure */
static struct vfs_fn_pointers vfs_scannedonly_fns = {
.opendir = scannedonly_opendir,
+ .fdopendir = scannedonly_fdopendir,
.readdir = scannedonly_readdir,
.seekdir = scannedonly_seekdir,
.telldir = scannedonly_telldir,
return((SMB_STRUCT_DIR *)dirp);
}
+static SMB_STRUCT_DIR *shadow_copy_fdopendir(vfs_handle_struct *handle, files_struct *fsp, const char *mask, uint32 attr)
+{
+ shadow_copy_Dir *dirp;
+ SMB_STRUCT_DIR *p = SMB_VFS_NEXT_FDOPENDIR(handle,fsp,mask,attr);
+
+ if (!p) {
+ DEBUG(10,("shadow_copy_opendir: SMB_VFS_NEXT_FDOPENDIR() failed for [%s]\n",
+ smb_fname_str_dbg(fsp->fsp_name)));
+ return NULL;
+ }
+
+ dirp = SMB_MALLOC_P(shadow_copy_Dir);
+ if (!dirp) {
+ DEBUG(0,("shadow_copy_fdopendir: Out of memory\n"));
+ SMB_VFS_NEXT_CLOSEDIR(handle,p);
+ /* We have now closed the fd in fsp. */
+ fsp->fh->fd = -1;
+ return NULL;
+ }
+
+ ZERO_STRUCTP(dirp);
+
+ while (True) {
+ SMB_STRUCT_DIRENT *d;
+
+ d = SMB_VFS_NEXT_READDIR(handle, p, NULL);
+ if (d == NULL) {
+ break;
+ }
+
+ if (shadow_copy_match_name(d->d_name)) {
+ DEBUG(8,("shadow_copy_fdopendir: hide [%s]\n",d->d_name));
+ continue;
+ }
+
+ DEBUG(10,("shadow_copy_fdopendir: not hide [%s]\n",d->d_name));
+
+ dirp->dirs = SMB_REALLOC_ARRAY(dirp->dirs,SMB_STRUCT_DIRENT, dirp->num+1);
+ if (!dirp->dirs) {
+ DEBUG(0,("shadow_copy_fdopendir: Out of memory\n"));
+ break;
+ }
+
+ dirp->dirs[dirp->num++] = *d;
+ }
+
+ SMB_VFS_NEXT_CLOSEDIR(handle,p);
+ /* We have now closed the fd in fsp. */
+ fsp->fh->fd = -1;
+ return((SMB_STRUCT_DIR *)dirp);
+}
+
static SMB_STRUCT_DIRENT *shadow_copy_readdir(vfs_handle_struct *handle,
SMB_STRUCT_DIR *_dirp,
SMB_STRUCT_STAT *sbuf)
static struct vfs_fn_pointers vfs_shadow_copy_fns = {
.opendir = shadow_copy_opendir,
+ .fdopendir = shadow_copy_fdopendir,
.readdir = shadow_copy_readdir,
.seekdir = shadow_copy_seekdir,
.telldir = shadow_copy_telldir,
return result;
}
+static SMB_STRUCT_DIR *smb_time_audit_fdopendir(vfs_handle_struct *handle,
+ files_struct *fsp,
+ const char *mask, uint32 attr)
+{
+ SMB_STRUCT_DIR *result;
+ struct timespec ts1,ts2;
+ double timediff;
+
+ clock_gettime_mono(&ts1);
+ result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
+ clock_gettime_mono(&ts2);
+ timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
+
+ if (timediff > audit_timeout) {
+ smb_time_audit_log("fdopendir", timediff);
+ }
+
+ return result;
+}
+
static SMB_STRUCT_DIRENT *smb_time_audit_readdir(vfs_handle_struct *handle,
SMB_STRUCT_DIR *dirp,
SMB_STRUCT_STAT *sbuf)
.statvfs = smb_time_audit_statvfs,
.fs_capabilities = smb_time_audit_fs_capabilities,
.opendir = smb_time_audit_opendir,
+ .fdopendir = smb_time_audit_fdopendir,
.readdir = smb_time_audit_readdir,
.seekdir = smb_time_audit_seekdir,
.telldir = smb_time_audit_telldir,
return handle->fns->opendir(handle, fname, mask, attributes);
}
+SMB_STRUCT_DIR *smb_vfs_call_fdopendir(struct vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ const char *mask,
+ uint32 attributes)
+{
+ VFS_FIND(fdopendir);
+ return handle->fns->fdopendir(handle, fsp, mask, attributes);
+}
+
SMB_STRUCT_DIRENT *smb_vfs_call_readdir(struct vfs_handle_struct *handle,
SMB_STRUCT_DIR *dirp,
SMB_STRUCT_STAT *sbuf)
profile_separator("System Calls");
d_printf("opendir_count: %u\n", profile_p->syscall_opendir_count);
d_printf("opendir_time: %u\n", profile_p->syscall_opendir_time);
+ d_printf("fdopendir_count: %u\n", profile_p->syscall_fdopendir_count);
+ d_printf("fdopendir_time: %u\n", profile_p->syscall_fdopendir_time);
d_printf("readdir_count: %u\n", profile_p->syscall_readdir_count);
d_printf("readdir_time: %u\n", profile_p->syscall_readdir_time);
d_printf("mkdir_count: %u\n", profile_p->syscall_mkdir_count);