diff options
-rw-r--r-- | source3/smbd/open.c | 2 | ||||
-rw-r--r-- | source3/smbd/proto.h | 1 | ||||
-rw-r--r-- | source3/smbd/vfs.c | 31 |
3 files changed, 33 insertions, 1 deletions
diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 5860155263b..9493021c48d 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -1327,7 +1327,7 @@ static NTSTATUS open_file(files_struct *fsp, * too. With blocking file descriptors this * does not happen. */ - ret = set_blocking(fsp->fh->fd, true); + ret = vfs_set_blocking(fsp, true); if (ret == -1) { status = map_nt_error_from_unix(errno); DBG_WARNING("Could not set fd to blocking: " diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 11c9dc0f8b1..e9d04474df6 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -1230,6 +1230,7 @@ int vfs_allocate_file_space(files_struct *fsp, uint64_t len); int vfs_set_filelen(files_struct *fsp, off_t len); int vfs_slow_fallocate(files_struct *fsp, off_t offset, off_t len); int vfs_fill_sparse(files_struct *fsp, off_t len); +int vfs_set_blocking(files_struct *fsp, bool set); off_t vfs_transfer_file(files_struct *in, files_struct *out, off_t n); const char *vfs_readdirname(connection_struct *conn, void *p, SMB_STRUCT_STAT *sbuf, char **talloced); diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index bef79e4c64e..5332f00e876 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -711,6 +711,37 @@ int vfs_fill_sparse(files_struct *fsp, off_t len) return ret; } +/******************************************************************************* + Set a fd into blocking/nonblocking mode through VFS +*******************************************************************************/ + +int vfs_set_blocking(files_struct *fsp, bool set) +{ + int val; +#ifdef O_NONBLOCK +#define FLAG_TO_SET O_NONBLOCK +#else +#ifdef SYSV +#define FLAG_TO_SET O_NDELAY +#else /* BSD */ +#define FLAG_TO_SET FNDELAY +#endif +#endif + val = SMB_VFS_FCNTL(fsp, F_GETFL, 0); + if (val == -1) { + return -1; + } + + if (set) { + val &= ~FLAG_TO_SET; + } else { + val |= FLAG_TO_SET; + } + + return SMB_VFS_FCNTL(fsp, F_SETFL, val); +#undef FLAG_TO_SET +} + /**************************************************************************** Transfer some data (n bytes) between two file_struct's. ****************************************************************************/ |