mirror of
https://github.com/samba-team/samba.git
synced 2025-03-27 22:50:26 +03:00
Add fdopendir to the VFS. We will use this to reuse a directory fd already open by NtCreateX.
Autobuild-User: Jeremy Allison <jra@samba.org> Autobuild-Date: Wed Feb 9 00:55:22 CET 2011 on sn-devel-104
This commit is contained in:
parent
224fc03cb5
commit
a674a56a97
@ -87,6 +87,11 @@ static SMB_STRUCT_DIR *skel_opendir(vfs_handle_struct *handle, const char *fnam
|
||||
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)
|
||||
@ -784,6 +789,7 @@ struct vfs_fn_pointers skel_transparent_fns = {
|
||||
/* Directory operations */
|
||||
|
||||
.opendir = skel_opendir,
|
||||
.fdopendir = skel_fdopendir,
|
||||
.readdir = skel_readdir,
|
||||
.seekdir = skel_seekdir,
|
||||
.telldir = skel_telldir,
|
||||
|
@ -84,6 +84,11 @@ static SMB_STRUCT_DIR *skel_opendir(vfs_handle_struct *handle, const char *fnam
|
||||
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)
|
||||
@ -728,6 +733,7 @@ struct vfs_fn_pointers skel_transparent_fns = {
|
||||
/* Directory operations */
|
||||
|
||||
.opendir = skel_opendir,
|
||||
.fdopendir = skel_fdopendir,
|
||||
.readdir = skel_readdir,
|
||||
.seekdir = skel_seekdir,
|
||||
.telldir = skel_telldir,
|
||||
|
@ -43,6 +43,10 @@ enum profile_stats_values
|
||||
#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)
|
||||
|
@ -132,6 +132,7 @@
|
||||
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
|
||||
|
||||
|
||||
@ -198,6 +199,7 @@ struct vfs_fn_pointers {
|
||||
/* 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);
|
||||
@ -526,6 +528,10 @@ uint32_t smb_vfs_call_fs_capabilities(struct vfs_handle_struct *handle,
|
||||
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);
|
||||
|
@ -74,6 +74,11 @@
|
||||
#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) \
|
||||
|
@ -167,6 +167,20 @@ static SMB_STRUCT_DIR *vfswrap_opendir(vfs_handle_struct *handle, const char *f
|
||||
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)
|
||||
|
@ -122,6 +122,48 @@ static SMB_STRUCT_DIR *dirsort_opendir(vfs_handle_struct *handle,
|
||||
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)
|
||||
@ -179,6 +221,7 @@ static void dirsort_rewinddir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp)
|
||||
|
||||
static struct vfs_fn_pointers vfs_dirsort_fns = {
|
||||
.opendir = dirsort_opendir,
|
||||
.fdopendir = dirsort_fdopendir,
|
||||
.readdir = dirsort_readdir,
|
||||
.seekdir = dirsort_seekdir,
|
||||
.telldir = dirsort_telldir,
|
||||
|
@ -87,6 +87,7 @@ typedef enum _vfs_op_type {
|
||||
/* Directory operations */
|
||||
|
||||
SMB_VFS_OP_OPENDIR,
|
||||
SMB_VFS_OP_FDOPENDIR,
|
||||
SMB_VFS_OP_READDIR,
|
||||
SMB_VFS_OP_SEEKDIR,
|
||||
SMB_VFS_OP_TELLDIR,
|
||||
@ -229,6 +230,7 @@ static struct {
|
||||
{ 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" },
|
||||
@ -735,6 +737,19 @@ static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle,
|
||||
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)
|
||||
{
|
||||
@ -2201,6 +2216,7 @@ static struct vfs_fn_pointers vfs_full_audit_fns = {
|
||||
.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,
|
||||
|
@ -198,6 +198,31 @@ static SMB_STRUCT_DIR *atalk_opendir(struct vfs_handle_struct *handle, const cha
|
||||
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;
|
||||
@ -432,6 +457,7 @@ exit_lchown:
|
||||
|
||||
static struct vfs_fn_pointers vfs_netatalk_fns = {
|
||||
.opendir = atalk_opendir,
|
||||
.fdopendir = atalk_fdopendir,
|
||||
.rmdir = atalk_rmdir,
|
||||
.rename = atalk_rename,
|
||||
.unlink = atalk_unlink,
|
||||
|
@ -526,6 +526,35 @@ static SMB_STRUCT_DIR *scannedonly_opendir(vfs_handle_struct * handle,
|
||||
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)
|
||||
@ -986,6 +1015,7 @@ static int scannedonly_connect(struct vfs_handle_struct *handle,
|
||||
/* 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,
|
||||
|
@ -118,6 +118,58 @@ static SMB_STRUCT_DIR *shadow_copy_opendir(vfs_handle_struct *handle, const char
|
||||
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)
|
||||
@ -216,6 +268,7 @@ static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle, files_str
|
||||
|
||||
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,
|
||||
|
@ -221,6 +221,26 @@ static SMB_STRUCT_DIR *smb_time_audit_opendir(vfs_handle_struct *handle,
|
||||
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)
|
||||
@ -2324,6 +2344,7 @@ static struct vfs_fn_pointers vfs_time_audit_fns = {
|
||||
.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,
|
||||
|
@ -1200,6 +1200,15 @@ SMB_STRUCT_DIR *smb_vfs_call_opendir(struct vfs_handle_struct *handle,
|
||||
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)
|
||||
|
@ -57,6 +57,8 @@ bool status_profile_dump(bool verbose)
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user