[RFC]: VFS open return NTSTATUS (was:Add vfs_admin vfs module)

Uri Simchoni uri at samba.org
Wed Oct 28 21:04:33 UTC 2015


Hi,

I've spent some time trying to change the interface of VFS POSIX open 
(open_fn). The change is that instead of returning a created file 
descriptor, it now sets the file descriptor in the FSP and returns an 
ntstatus.This can serve as a POC for a migration for all VFS methods to 
return NTSTATUS.

What got me started was that I wanted VFS open_fn to have a slightly 
different interface, namely that it set the new file descriptor in the 
fsp instead of returning it. Richard indicated that I should use 
accessor functions to do it, and that he wants to drive a change where 
all VFS functions return an NTSTATUS. So I figured that while I'm at it, 
I might as well change the interface of open into one that returns 
NTSTATUS, and see how it looks.

What I've learned:
- Returning the error code (be it POSIX errno or NTSTATUS) instead or 
setting errno simplifies the code compared to setting errno and 
returning -1.

- Returning an error also avoids the case of forgetting to set errno 
(unless one cheats and returns errno), and avoids the case of forgetting 
to save and restore errno in error handling.

- about NTSTATUS instead of POSIX error code:
a. It may seem unnatural as this is a "posix layer" with posix semantics 
(even if the VFS is not the kernel, we have to assume it has posix 
semantics if we are to mix and match vfs modules and sanely reason about 
it).
b. There's a bug where fd_open() does some platform-specific errno 
fixes, thereby applying the fixes even where they do not belong (e.g. if 
the VFS is not calling the kernel's open). It's fixable with the current 
interface as well, but with an interface that returns NTSTATUS it would 
have been harder to make that mistake.
c. Overall returning NTSTATUS simplifies the life of the VFS consumer, 
not affecting much a VFS "transparent" module, and makes life harder to 
VFS "opaque" modules. The latter ones now have to do the translation 
themselves, so if they encapsulate some POSIX-compliant library (e.g. 
ceph), they have extra work.
d. The conversion I made was a "shallow" one - not drilling the 
errno->ntstatus into the call chain in vfs modules. Perhaps doing this 
would simplify the code further and avoid calling the unix->ntstatus 
error mapping function in some cases (see vfs_fruit for example).

- Two bugs fixed while scanning the code (in vfs_fruit and vfs_commit), 
some more minor ones (not setting errno) spotted and not fixed.

The patch set includes this interface change, as well as using accessor 
functions to set the file descriptor of the fsp.

Comments/review appreciated.
Thanks,
Uri.

-------------- next part --------------
From 05fac79bf21dd26d498a97cde9de3b350a364dbe Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Mon, 5 Oct 2015 20:55:43 +0300
Subject: [PATCH 01/35] smbd: add map_nt_open_error_from_unix()

This new function calculates the proper NTSTATUS code for
POSIX open, factored out of fd_open().

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/smbd/open.c  | 54 +++++++++++++++++++++++++++++++---------------------
 source3/smbd/proto.h |  1 +
 2 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index ef1505d..f8422a6 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -344,6 +344,35 @@ static NTSTATUS check_base_file_access(struct connection_struct *conn,
 					access_mask);
 }
 
+
+/****************************************************************************
+ NTSTATUS for posix open errors - wrap map_nt_error_from_unix with some
+ platform-specific open-specific mods
+****************************************************************************/
+
+NTSTATUS map_nt_open_error_from_unix(int posix_errno)
+{
+#ifdef O_NOFOLLOW
+#if defined(ENOTSUP) && defined(OSF1)
+		/* handle special Tru64 errno */
+		if (errno == ENOTSUP) {
+			posix_errno = ELOOP;
+		}
+#endif /* ENOTSUP */
+#ifdef EFTYPE
+		/* fix broken NetBSD errno */
+		if (errno == EFTYPE) {
+			posix_errno = ELOOP;
+		}
+#endif /* EFTYPE */
+		/* fix broken FreeBSD errno */
+		if (errno == EMLINK) {
+			posix_errno = ELOOP;
+		}
+#endif /* O_NOFOLLOW */
+		return map_nt_error_from_unix(posix_errno);
+}
+
 /****************************************************************************
  fd support routines - attempt to do a dos_open.
 ****************************************************************************/
@@ -369,27 +398,8 @@ NTSTATUS fd_open(struct connection_struct *conn,
 
 	fsp->fh->fd = SMB_VFS_OPEN(conn, smb_fname, fsp, flags, mode);
 	if (fsp->fh->fd == -1) {
-		int posix_errno = errno;
-#ifdef O_NOFOLLOW
-#if defined(ENOTSUP) && defined(OSF1)
-		/* handle special Tru64 errno */
-		if (errno == ENOTSUP) {
-			posix_errno = ELOOP;
-		}
-#endif /* ENOTSUP */
-#ifdef EFTYPE
-		/* fix broken NetBSD errno */
-		if (errno == EFTYPE) {
-			posix_errno = ELOOP;
-		}
-#endif /* EFTYPE */
-		/* fix broken FreeBSD errno */
-		if (errno == EMLINK) {
-			posix_errno = ELOOP;
-		}
-#endif /* O_NOFOLLOW */
-		status = map_nt_error_from_unix(posix_errno);
-		if (errno == EMFILE) {
+		status = map_nt_open_error_from_unix(errno);
+		if (NT_STATUS_EQUAL(status, NT_STATUS_TOO_MANY_OPENED_FILES)) {
 			static time_t last_warned = 0L;
 
 			if (time((time_t *) NULL) > last_warned) {
@@ -405,7 +415,7 @@ NTSTATUS fd_open(struct connection_struct *conn,
 
 	DEBUG(10,("fd_open: name %s, flags = 0%o mode = 0%o, fd = %d. %s\n",
 		  smb_fname_str_dbg(smb_fname), flags, (int)mode, fsp->fh->fd,
-		(fsp->fh->fd == -1) ? strerror(errno) : "" ));
+		NT_STATUS_IS_OK(status) ? "" : nt_errstr(status)));
 
 	return status;
 }
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index 2eac3ec..65d9239 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -610,6 +610,7 @@ NTSTATUS smbd_check_access_rights(struct connection_struct *conn,
 				const struct smb_filename *smb_fname,
 				bool use_privs,
 				uint32_t access_mask);
+NTSTATUS map_nt_open_error_from_unix(int posix_errno);
 NTSTATUS fd_open(struct connection_struct *conn, files_struct *fsp,
 		 int flags, mode_t mode);
 NTSTATUS fd_close(files_struct *fsp);
-- 
2.4.3


From 9cf06eaf7d5ad0ec4f5670635bbd9f5e8eb74563 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Mon, 5 Oct 2015 22:32:31 +0300
Subject: [PATCH 02/35] smbd: add accessor functions to file descriptor

These new accessors are to be used when setting the file descriptor
on a files_struct. The advantage of using accessors is that
the semantics are clearer and are enforceable (am I assigning a new
FD, wrapping an exising FD with my own, closing the existing one
and opening my own - these all can be done with different accessor
functions and have different checks applied to them).

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/smbd/files.c | 38 ++++++++++++++++++++++++++++++++++++++
 source3/smbd/proto.h |  4 ++++
 2 files changed, 42 insertions(+)

diff --git a/source3/smbd/files.c b/source3/smbd/files.c
index 8fefddd..c0386d5 100644
--- a/source3/smbd/files.c
+++ b/source3/smbd/files.c
@@ -781,3 +781,41 @@ uint32_t fsp_lease_type(struct files_struct *fsp)
 	}
 	return map_oplock_to_lease_type(fsp->oplock_type);
 }
+
+/**
+ * Assign a file descriptor (or pseudo-FD) to a newly-created
+ * FSP. The assumption is that the FSP currently does not
+ * hold any other FD.
+ */
+void fsp_assign_fd(files_struct *fsp, int fd)
+{
+	SMB_ASSERT(fsp->fh->fd == -1);
+	fsp->fh->fd = fd;
+}
+
+/**
+ * Lose reference to a file descriptor (or pseudo-FD) by an
+ * FSP. Typically used for avoiding refernce to a closed
+ * FD by the FSP.
+ */
+void fsp_reset_fd(files_struct *fsp)
+{
+	/* we're not supposed to be sharing the file handle */
+	SMB_ASSERT(fsp->fh->ref_count == 1);
+	fsp->fh->fd = -1;
+}
+
+/**
+ * Get the current FD or pseudo-FD
+ */
+int fsp_get_fd(files_struct *fsp)
+{
+	return fsp->fh->fd;
+}
+/**
+ * Have we set the file descriptor?
+ */
+bool fsp_fd_isset(files_struct *fsp)
+{
+	return fsp->fh->fd != -1;
+}
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index 65d9239..e8c7554 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -391,6 +391,10 @@ NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
 			   const struct smb_filename *smb_fname_in);
 const struct GUID *fsp_client_guid(const files_struct *fsp);
 uint32_t fsp_lease_type(struct files_struct *fsp);
+void fsp_assign_fd(files_struct *fsp, int fd);
+void fsp_reset_fd(files_struct *fsp);
+int fsp_get_fd(files_struct *fsp);
+bool fsp_fd_isset(files_struct *fsp);
 
 /* The following definitions come from smbd/ipc.c  */
 
-- 
2.4.3


From 6716055ebd3d0eddb4728faa7ab35074daeeae18 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Tue, 27 Oct 2015 21:39:48 +0200
Subject: [PATCH 03/35] smbd: make fsp_new() only allocate and initialize
 without side effects

Have fsp_new() behave as a constructor function, which only initilizes
a file_struct object, but does not tie it to a connection / server
connecion object.

Add fsp_new_attach() which behaves just like the old fsp_new()

This allows creating fsp's in testing scenarios without binding
them to connections.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/smbd/durable.c |  2 +-
 source3/smbd/files.c   | 40 +++++++++++++++++++++++++++++-----------
 source3/smbd/proto.h   |  5 +++--
 3 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/source3/smbd/durable.c b/source3/smbd/durable.c
index d9b88a8..0626ddd 100644
--- a/source3/smbd/durable.c
+++ b/source3/smbd/durable.c
@@ -685,7 +685,7 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
 	 * 2. proceed with opening file
 	 */
 
-	status = fsp_new(conn, conn, &fsp);
+	status = fsp_new_attached(conn, conn, &fsp);
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(0, ("vfs_default_durable_reconnect: failed to create "
 			  "new fsp: %s\n", nt_errstr(status)));
diff --git a/source3/smbd/files.c b/source3/smbd/files.c
index c0386d5..c4bbe67 100644
--- a/source3/smbd/files.c
+++ b/source3/smbd/files.c
@@ -27,14 +27,12 @@
 #define FILE_HANDLE_OFFSET 0x1000
 
 /**
- * create new fsp to be used for file_new or a durable handle reconnect
+ * create and initialize a new fsp
  */
-NTSTATUS fsp_new(struct connection_struct *conn, TALLOC_CTX *mem_ctx,
-		 files_struct **result)
+NTSTATUS fsp_new(TALLOC_CTX *mem_ctx, files_struct **result)
 {
 	NTSTATUS status = NT_STATUS_NO_MEMORY;
 	files_struct *fsp = NULL;
-	struct smbd_server_connection *sconn = conn->sconn;
 
 	fsp = talloc_zero(mem_ctx, struct files_struct);
 	if (fsp == NULL) {
@@ -55,12 +53,6 @@ NTSTATUS fsp_new(struct connection_struct *conn, TALLOC_CTX *mem_ctx,
 	fsp->fh->fd = -1;
 
 	fsp->fnum = FNUM_FIELD_INVALID;
-	fsp->conn = conn;
-
-	DLIST_ADD(sconn->files, fsp);
-	sconn->num_files += 1;
-
-	conn->num_files_open++;
 
 	*result = fsp;
 	return NT_STATUS_OK;
@@ -74,6 +66,32 @@ fail:
 	return status;
 }
 
+/**
+ * create new fsp to be used for file_new or a durable handle reconnect
+ */
+NTSTATUS fsp_new_attached(struct connection_struct *conn, TALLOC_CTX *mem_ctx,
+			  files_struct **result)
+{
+	NTSTATUS status = NT_STATUS_NO_MEMORY;
+	files_struct *fsp = NULL;
+	struct smbd_server_connection *sconn = conn->sconn;
+
+	status = fsp_new(mem_ctx, &fsp);
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
+	}
+
+	fsp->conn = conn;
+
+	DLIST_ADD(sconn->files, fsp);
+	sconn->num_files += 1;
+
+	conn->num_files_open++;
+
+	*result = fsp;
+	return NT_STATUS_OK;
+}
+
 /****************************************************************************
  Find first available file slot.
 ****************************************************************************/
@@ -85,7 +103,7 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
 	files_struct *fsp;
 	NTSTATUS status;
 
-	status = fsp_new(conn, conn, &fsp);
+	status = fsp_new_attached(conn, conn, &fsp);
 	if (!NT_STATUS_IS_OK(status)) {
 		return status;
 	}
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index e8c7554..60d516d 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -347,8 +347,9 @@ NTSTATUS filename_convert_with_privilege(TALLOC_CTX *mem_ctx,
 
 /* The following definitions come from smbd/files.c  */
 
-NTSTATUS fsp_new(struct connection_struct *conn, TALLOC_CTX *mem_ctx,
-		 files_struct **result);
+NTSTATUS fsp_new(TALLOC_CTX *mem_ctx, files_struct **result);
+NTSTATUS fsp_new_attached(struct connection_struct *conn, TALLOC_CTX *mem_ctx,
+			  files_struct **result);
 NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
 		  files_struct **result);
 void file_close_conn(connection_struct *conn);
-- 
2.4.3


From b10675258476792d1c2dff96d3deaa4fbf46bac9 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Tue, 27 Oct 2015 21:50:45 +0200
Subject: [PATCH 04/35] torture: use fsp_new() instead of directly allocating
 an fsp

fsp_new() can be made to guarantee the file_struct invariants
(such as, a file_struct has a file descriptor different from
-1 iff it owns an open open file)

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/torture/cmd_vfs.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/source3/torture/cmd_vfs.c b/source3/torture/cmd_vfs.c
index 040759a..52af016 100644
--- a/source3/torture/cmd_vfs.c
+++ b/source3/torture/cmd_vfs.c
@@ -320,14 +320,9 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
 		}
 	}
 
-	fsp = talloc_zero(vfs, struct files_struct);
-	if (fsp == NULL) {
-		return NT_STATUS_NO_MEMORY;
-	}
-	fsp->fh = talloc_zero(fsp, struct fd_handle);
-	if (fsp->fh == NULL) {
-		TALLOC_FREE(fsp);
-		return NT_STATUS_NO_MEMORY;
+	status = fsp_new(vfs, &fsp);
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
 	}
 	fsp->conn = vfs->conn;
 
@@ -1452,14 +1447,9 @@ static NTSTATUS cmd_set_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int a
 
 	mode = 00400;
 
-	fsp = talloc_zero(vfs, struct files_struct);
-	if (fsp == NULL) {
-		return NT_STATUS_NO_MEMORY;
-	}
-	fsp->fh = talloc_zero(fsp, struct fd_handle);
-	if (fsp->fh == NULL) {
-		TALLOC_FREE(fsp);
-		return NT_STATUS_NO_MEMORY;
+	status = fsp_new(vfs, &fsp);
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
 	}
 	fsp->conn = vfs->conn;
 
-- 
2.4.3


From 2ef43d2826c292c23533ff63e72c64764dd148c2 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Tue, 27 Oct 2015 23:45:10 +0200
Subject: [PATCH 05/35] pysmbd: use fsp_new() instead of directly allocating an
 fsp

fsp_new() can be made to guarantee the file_struct invariants
(such as, a file_struct has a file descriptor different from
-1 iff it owns an open open file)

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/smbd/pysmbd.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/source3/smbd/pysmbd.c b/source3/smbd/pysmbd.c
index df8d079..a2c951b 100644
--- a/source3/smbd/pysmbd.c
+++ b/source3/smbd/pysmbd.c
@@ -108,15 +108,10 @@ static NTSTATUS set_nt_acl_conn(const char *fname,
 	int flags, ret;
 	mode_t saved_umask;
 
-	fsp = talloc_zero(frame, struct files_struct);
-	if (fsp == NULL) {
-		TALLOC_FREE(frame);
-		return NT_STATUS_NO_MEMORY;
-	}
-	fsp->fh = talloc(fsp, struct fd_handle);
-	if (fsp->fh == NULL) {
+	status = fsp_new(frame, &fsp);
+	if (!NT_STATUS_IS_OK(status)) {
 		TALLOC_FREE(frame);
-		return NT_STATUS_NO_MEMORY;
+		return status;
 	}
 	fsp->conn = conn;
 
-- 
2.4.3


From be571a5a71598e8252620698d7d97fddbae5b1c1 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Mon, 5 Oct 2015 21:51:42 +0300
Subject: [PATCH 06/35] VFS: add open2 operation

This new op is supposed to eventually be the next open. When
all the code uses/implements open2, the old open will be removed
and open2 will be renamed to open.

open2 differs from open in that it returns NTSTATUS, and it also
sets sets the newly-created file descriptor in the FSP structure,
instead of returning it.

both SMB_VFS_OPEN() and SMB_VFS_OPEN2() (and their _NEXT_
derivatives) use the first open_fn or open2_fn they find
in the VFS stack, thus maintaining backward compatibility
during the migration process.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/include/vfs.h        |  6 ++++++
 source3/include/vfs_macros.h |  4 ++++
 source3/smbd/vfs.c           | 42 ++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/source3/include/vfs.h b/source3/include/vfs.h
index 9945375..3f11dc1 100644
--- a/source3/include/vfs.h
+++ b/source3/include/vfs.h
@@ -545,6 +545,9 @@ struct vfs_fn_pointers {
 	int (*open_fn)(struct vfs_handle_struct *handle,
 		       struct smb_filename *smb_fname, files_struct *fsp,
 		       int flags, mode_t mode);
+	NTSTATUS (*open2_fn)(struct vfs_handle_struct *handle,
+			     struct smb_filename *smb_fname, files_struct *fsp,
+			     int flags, mode_t mode);
 	NTSTATUS (*create_file_fn)(struct vfs_handle_struct *handle,
 				   struct smb_request *req,
 				   uint16_t root_dir_fid,
@@ -962,6 +965,9 @@ void smb_vfs_call_init_search_op(struct vfs_handle_struct *handle,
 int smb_vfs_call_open(struct vfs_handle_struct *handle,
 		      struct smb_filename *smb_fname, struct files_struct *fsp,
 		      int flags, mode_t mode);
+NTSTATUS smb_vfs_call_open2(struct vfs_handle_struct *handle,
+			   struct smb_filename *smb_fname,
+			   struct files_struct *fsp, int flags, mode_t mode);
 NTSTATUS smb_vfs_call_create_file(struct vfs_handle_struct *handle,
 				  struct smb_request *req,
 				  uint16_t root_dir_fid,
diff --git a/source3/include/vfs_macros.h b/source3/include/vfs_macros.h
index eaf0c19..bbc130b 100644
--- a/source3/include/vfs_macros.h
+++ b/source3/include/vfs_macros.h
@@ -134,6 +134,10 @@
 	smb_vfs_call_open((conn)->vfs_handles, (fname), (fsp), (flags), (mode))
 #define SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode) \
 	smb_vfs_call_open((handle)->next, (fname), (fsp), (flags), (mode))
+#define SMB_VFS_OPEN2(conn, fname, fsp, flags, mode) \
+	smb_vfs_call_open2((conn)->vfs_handles, (fname), (fsp), (flags), (mode))
+#define SMB_VFS_NEXT_OPEN2(handle, fname, fsp, flags, mode) \
+	smb_vfs_call_open2((handle)->next, (fname), (fsp), (flags), (mode))
 
 #define SMB_VFS_CREATE_FILE(conn, req, root_dir_fid, smb_fname, access_mask, share_access, create_disposition, \
         create_options, file_attributes, oplock_request, lease, allocation_size, private_flags, sd, ea_list, result, pinfo, in_context_blobs, out_context_blobs) \
diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c
index 9f3ba6d..006359a 100644
--- a/source3/smbd/vfs.c
+++ b/source3/smbd/vfs.c
@@ -1493,8 +1493,46 @@ int smb_vfs_call_open(struct vfs_handle_struct *handle,
 		      struct smb_filename *smb_fname, struct files_struct *fsp,
 		      int flags, mode_t mode)
 {
-	VFS_FIND(open);
-	return handle->fns->open_fn(handle, smb_fname, fsp, flags, mode);
+	while (true) {
+		if (handle->fns->open2_fn) {
+			NTSTATUS status = handle->fns->open2_fn(
+			    handle, smb_fname, fsp, flags, mode);
+			if (!NT_STATUS_IS_OK(status)) {
+				errno = map_errno_from_nt_status(status);
+			}
+
+			return fsp->fh->fd;
+		} else if (handle->fns->open_fn) {
+			return handle->fns->open_fn(handle, smb_fname, fsp,
+						    flags, mode);
+		}
+
+		handle = handle->next;
+	}
+}
+
+NTSTATUS smb_vfs_call_open2(struct vfs_handle_struct *handle,
+			   struct smb_filename *smb_fname,
+			   struct files_struct *fsp, int flags, mode_t mode)
+{
+	while (true) {
+		if (handle->fns->open2_fn) {
+			return handle->fns->open2_fn(handle, smb_fname, fsp,
+						     flags, mode);
+		} else if (handle->fns->open_fn) {
+			NTSTATUS status = NT_STATUS_OK;
+			int hostfd = handle->fns->open_fn(handle, smb_fname,
+							  fsp, flags, mode);
+			fsp_assign_fd(fsp,hostfd);
+			if (hostfd == -1) {
+				status = map_nt_open_error_from_unix(errno);
+			}
+
+			return status;
+		}
+
+		handle = handle->next;
+	}
 }
 
 NTSTATUS smb_vfs_call_create_file(struct vfs_handle_struct *handle,
-- 
2.4.3


From 48c575d22dc8da157f6eb39f7b8ca388ec46f784 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Mon, 5 Oct 2015 23:07:09 +0300
Subject: [PATCH 07/35] smbd: use new VFS open in fd_open()

Use the new VFS open signature when opening files in smbd.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/smbd/open.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index f8422a6..713d72f 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -383,7 +383,7 @@ NTSTATUS fd_open(struct connection_struct *conn,
 		 mode_t mode)
 {
 	struct smb_filename *smb_fname = fsp->fsp_name;
-	NTSTATUS status = NT_STATUS_OK;
+	NTSTATUS status;
 
 #ifdef O_NOFOLLOW
 	/* 
@@ -396,21 +396,17 @@ NTSTATUS fd_open(struct connection_struct *conn,
 	}
 #endif
 
-	fsp->fh->fd = SMB_VFS_OPEN(conn, smb_fname, fsp, flags, mode);
-	if (fsp->fh->fd == -1) {
-		status = map_nt_open_error_from_unix(errno);
-		if (NT_STATUS_EQUAL(status, NT_STATUS_TOO_MANY_OPENED_FILES)) {
-			static time_t last_warned = 0L;
-
-			if (time((time_t *) NULL) > last_warned) {
-				DEBUG(0,("Too many open files, unable "
-					"to open more!  smbd's max "
-					"open files = %d\n",
-					lp_max_open_files()));
-				last_warned = time((time_t *) NULL);
-			}
-		}
+	status = SMB_VFS_OPEN2(conn, smb_fname, fsp, flags, mode);
+	if (NT_STATUS_EQUAL(status, NT_STATUS_TOO_MANY_OPENED_FILES)) {
+		static time_t last_warned = 0L;
 
+		if (time((time_t *) NULL) > last_warned) {
+			DEBUG(0,("Too many open files, unable "
+				"to open more!  smbd's max "
+				"open files = %d\n",
+				lp_max_open_files()));
+			last_warned = time((time_t *) NULL);
+		}
 	}
 
 	DEBUG(10,("fd_open: name %s, flags = 0%o mode = 0%o, fd = %d. %s\n",
-- 
2.4.3


From 5a3f2a667f66437f9c65ba036dcc3e755b62538f Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Mon, 5 Oct 2015 23:25:06 +0300
Subject: [PATCH 08/35] pysmbd: use the new VFS open signature

Use the new VFS open signature when opening files in pysmbd

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/smbd/pysmbd.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/source3/smbd/pysmbd.c b/source3/smbd/pysmbd.c
index a2c951b..3fc2305 100644
--- a/source3/smbd/pysmbd.c
+++ b/source3/smbd/pysmbd.c
@@ -135,12 +135,13 @@ static NTSTATUS set_nt_acl_conn(const char *fname,
 	flags = O_RDONLY;
 #endif
 
-	fsp->fh->fd = SMB_VFS_OPEN(conn, smb_fname, fsp, O_RDWR, 00400);
-	if (fsp->fh->fd == -1 && errno == EISDIR) {
-		fsp->fh->fd = SMB_VFS_OPEN(conn, smb_fname, fsp, flags, 00400);
+	status = SMB_VFS_OPEN2(conn, smb_fname, fsp, O_RDWR, 00400);
+	if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) {
+		status = SMB_VFS_OPEN2(conn, smb_fname, fsp, flags, 00400);
 	}
-	if (fsp->fh->fd == -1) {
-		printf("open: error=%d (%s)\n", errno, strerror(errno));
+	if (!NT_STATUS_IS_OK(status)) {
+		printf("open: error=%s (%s)\n", nt_errstr(status),
+		       get_friendly_nt_error_msg(status));
 		TALLOC_FREE(frame);
 		umask(saved_umask);
 		return NT_STATUS_UNSUCCESSFUL;
-- 
2.4.3


From a4afc09faf27fd719ab4ce73b1ec19f0a3e4752d Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Mon, 5 Oct 2015 23:38:19 +0300
Subject: [PATCH 09/35] vfstest: use new VFS open signature

Use the new VFS open signature in vfstest

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/torture/cmd_vfs.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/source3/torture/cmd_vfs.c b/source3/torture/cmd_vfs.c
index 52af016..dd53727 100644
--- a/source3/torture/cmd_vfs.c
+++ b/source3/torture/cmd_vfs.c
@@ -334,15 +334,15 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
 
 	fsp->fsp_name = smb_fname;
 
-	fsp->fh->fd = SMB_VFS_OPEN(vfs->conn, smb_fname, fsp, flags, mode);
-	if (fsp->fh->fd == -1) {
-		printf("open: error=%d (%s)\n", errno, strerror(errno));
+	status = SMB_VFS_OPEN2(vfs->conn, smb_fname, fsp, flags, mode);
+	if (!NT_STATUS_IS_OK(status)) {
+		printf("open: error=%s (%s)\n", nt_errstr(status),
+		       get_friendly_nt_error_msg(status));
 		TALLOC_FREE(fsp);
 		TALLOC_FREE(smb_fname);
 		return NT_STATUS_UNSUCCESSFUL;
 	}
 
-	status = NT_STATUS_OK;
 	ret = SMB_VFS_FSTAT(fsp, &smb_fname->st);
 	if (ret == -1) {
 		/* If we have an fd, this stat should succeed. */
@@ -1468,18 +1468,18 @@ static NTSTATUS cmd_set_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int a
 	flags = O_RDONLY;
 #endif
 
-	fsp->fh->fd = SMB_VFS_OPEN(vfs->conn, smb_fname, fsp, O_RDWR, mode);
-	if (fsp->fh->fd == -1 && errno == EISDIR) {
-		fsp->fh->fd = SMB_VFS_OPEN(vfs->conn, smb_fname, fsp, flags, mode);
+	status = SMB_VFS_OPEN2(vfs->conn, smb_fname, fsp, O_RDWR, mode);
+	if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) {
+		status = SMB_VFS_OPEN2(vfs->conn, smb_fname, fsp, flags, mode);
 	}
-	if (fsp->fh->fd == -1) {
-		printf("open: error=%d (%s)\n", errno, strerror(errno));
+	if (!NT_STATUS_IS_OK(status)) {
+		printf("open: error=%s (%s)\n", nt_errstr(status),
+		       get_friendly_nt_error_msg(status));
 		TALLOC_FREE(fsp);
 		TALLOC_FREE(smb_fname);
 		return NT_STATUS_UNSUCCESSFUL;
 	}
 
-	status = NT_STATUS_OK;
 	ret = SMB_VFS_FSTAT(fsp, &smb_fname->st);
 	if (ret == -1) {
 		/* If we have an fd, this stat should succeed. */
-- 
2.4.3


From 048fa07abed3d8afc2bf6f427e99ed5a5daa4ef3 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Tue, 6 Oct 2015 00:29:25 +0300
Subject: [PATCH 10/35] vfs_default: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_default.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index bbe8cca..9f2744d 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -524,23 +524,31 @@ static void vfswrap_init_search_op(vfs_handle_struct *handle,
 
 /* File operations */
 
-static int vfswrap_open(vfs_handle_struct *handle,
-			struct smb_filename *smb_fname,
-			files_struct *fsp, int flags, mode_t mode)
+static NTSTATUS vfswrap_open(vfs_handle_struct *handle,
+			     struct smb_filename *smb_fname, files_struct *fsp,
+			     int flags, mode_t mode)
 {
-	int result = -1;
+	int fd;
+	NTSTATUS status;
 
 	START_PROFILE(syscall_open);
 
 	if (smb_fname->stream_name) {
-		errno = ENOENT;
+		status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
 		goto out;
 	}
 
-	result = open(smb_fname->base_name, flags, mode);
+	fd = open(smb_fname->base_name, flags, mode);
+	fsp_assign_fd(fsp, fd);
+	if (fd == -1) {
+		status = map_nt_open_error_from_unix(errno);
+		goto out;
+	}
+
+	status = NT_STATUS_OK;
  out:
 	END_PROFILE(syscall_open);
-	return result;
+	return status;
 }
 
 static NTSTATUS vfswrap_create_file(vfs_handle_struct *handle,
@@ -2583,7 +2591,7 @@ static struct vfs_fn_pointers vfs_default_fns = {
 
 	/* File operations */
 
-	.open_fn = vfswrap_open,
+	.open2_fn = vfswrap_open,
 	.create_file_fn = vfswrap_create_file,
 	.close_fn = vfswrap_close,
 	.read_fn = vfswrap_read,
-- 
2.4.3


From 90b100731395329a8efd7c6d0b12d21cb8680dbd Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Tue, 6 Oct 2015 21:21:21 +0300
Subject: [PATCH 11/35] vfs_fruit: use new open signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_fruit.c | 137 +++++++++++++++++++-------------------------
 1 file changed, 60 insertions(+), 77 deletions(-)

diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c
index a09e288..d566ada 100644
--- a/source3/modules/vfs_fruit.c
+++ b/source3/modules/vfs_fruit.c
@@ -2106,24 +2106,24 @@ static int fruit_connect(vfs_handle_struct *handle,
 	return rc;
 }
 
-static int fruit_open_meta(vfs_handle_struct *handle,
-			   struct smb_filename *smb_fname,
-			   files_struct *fsp, int flags, mode_t mode)
+static NTSTATUS fruit_open_meta(vfs_handle_struct *handle,
+				struct smb_filename *smb_fname,
+				files_struct *fsp, int flags, mode_t mode)
 {
-	int rc = 0;
+	NTSTATUS status;
+	int rc;
 	struct fruit_config_data *config = NULL;
 	struct smb_filename *smb_fname_base = NULL;
 	int baseflags;
-	int hostfd = -1;
 	struct adouble *ad = NULL;
 
 	DEBUG(10, ("fruit_open_meta for %s\n", smb_fname_str_dbg(smb_fname)));
 
-	SMB_VFS_HANDLE_GET_DATA(handle, config,
-				struct fruit_config_data, return -1);
+	SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
+				return NT_STATUS_UNSUCCESSFUL);
 
 	if (config->meta == FRUIT_META_STREAM) {
-		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 	}
 
 	/* Create an smb_filename with stream_name == NULL. */
@@ -2131,8 +2131,7 @@ static int fruit_open_meta(vfs_handle_struct *handle,
 					     smb_fname->base_name, NULL, NULL);
 
 	if (smb_fname_base == NULL) {
-		errno = ENOMEM;
-		rc = -1;
+		status = NT_STATUS_NO_MEMORY;
 		goto exit;
 	}
 
@@ -2145,24 +2144,23 @@ static int fruit_open_meta(vfs_handle_struct *handle,
 	baseflags &= ~O_EXCL;
 	baseflags &= ~O_CREAT;
 
-	hostfd = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
+	status = SMB_VFS_OPEN2(handle->conn, smb_fname_base, fsp,
 			      baseflags, mode);
 
 	/*
 	 * It is legit to open a stream on a directory, but the base
 	 * fd has to be read-only.
 	 */
-	if ((hostfd == -1) && (errno == EISDIR)) {
+	if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) {
 		baseflags &= ~O_ACCMODE;
 		baseflags |= O_RDONLY;
-		hostfd = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
+		status = SMB_VFS_OPEN2(handle->conn, smb_fname_base, fsp,
 				      baseflags, mode);
 	}
 
 	TALLOC_FREE(smb_fname_base);
 
-	if (hostfd == -1) {
-		rc = -1;
+	if (!NT_STATUS_IS_OK(status)) {
 		goto exit;
 	}
 
@@ -2174,83 +2172,79 @@ static int fruit_open_meta(vfs_handle_struct *handle,
 		ad = ad_init(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
 			     handle, ADOUBLE_META, fsp);
 		if (ad == NULL) {
-			rc = -1;
+			status = map_nt_error_from_unix(errno);
 			goto exit;
 		}
 
 		rc = ad_write(ad, smb_fname->base_name);
 		if (rc != 0) {
-			rc = -1;
+			status = map_nt_error_from_unix(errno);
 			goto exit;
 		}
 	} else {
 		ad = ad_alloc(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
 			      handle, ADOUBLE_META, fsp);
 		if (ad == NULL) {
-			rc = -1;
+			status = map_nt_error_from_unix(errno);
 			goto exit;
 		}
 		if (ad_read(ad, smb_fname->base_name) == -1) {
-			rc = -1;
+			status = map_nt_error_from_unix(errno);
 			goto exit;
 		}
 	}
 
 exit:
-	DEBUG(10, ("fruit_open meta rc=%d, fd=%d\n", rc, hostfd));
-	if (rc != 0) {
-		int saved_errno = errno;
-		if (hostfd >= 0) {
-			/*
-			 * BUGBUGBUG -- we would need to call
-			 * fd_close_posix here, but we don't have a
-			 * full fsp yet
-			 */
-			fsp->fh->fd = hostfd;
+	DEBUG(10, ("fruit_open meta status=%s, fd=%d\n", nt_errstr(status),
+		   fsp_get_fd(fsp)));
+	if (!NT_STATUS_IS_OK(status)) {
+		if (fsp_fd_isset(fsp)) {
 			SMB_VFS_CLOSE(fsp);
+			fsp_reset_fd(fsp);
 		}
-		hostfd = -1;
-		errno = saved_errno;
 	}
-	return hostfd;
+	return status;
 }
 
-static int fruit_open_rsrc(vfs_handle_struct *handle,
-			   struct smb_filename *smb_fname,
-			   files_struct *fsp, int flags, mode_t mode)
+static NTSTATUS fruit_open_rsrc(vfs_handle_struct *handle,
+				struct smb_filename *smb_fname,
+				files_struct *fsp, int flags, mode_t mode)
 {
-	int rc = 0;
+	NTSTATUS status = NT_STATUS_OK;
+	int rc;
 	struct fruit_config_data *config = NULL;
 	struct adouble *ad = NULL;
 	struct smb_filename *smb_fname_base = NULL;
 	char *adpath = NULL;
-	int hostfd = -1;
+#ifdef HAVE_ATTROPEN
+	int hostfd;
+#endif
 
 	DEBUG(10, ("fruit_open_rsrc for %s\n", smb_fname_str_dbg(smb_fname)));
 
-	SMB_VFS_HANDLE_GET_DATA(handle, config,
-				struct fruit_config_data, return -1);
+	SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
+				return NT_STATUS_UNSUCCESSFUL);
 
 	switch (config->rsrc) {
 	case FRUIT_RSRC_STREAM:
-		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 	case FRUIT_RSRC_XATTR:
 #ifdef HAVE_ATTROPEN
 		hostfd = attropen(smb_fname->base_name,
 				  AFPRESOURCE_EA_NETATALK, flags, mode);
 		if (hostfd == -1) {
-			return -1;
+			return map_nt_error_from_unix(errno);
 		}
+		fsp_assign_fd(fsp, hostfd);
 		ad = ad_init(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
 			     handle, ADOUBLE_RSRC, fsp);
 		if (ad == NULL) {
-			rc = -1;
+			status = map_nt_error_from_unix(errno);
 			goto exit;
 		}
 		goto exit;
 #else
-		errno = ENOTSUP;
-		return -1;
+		return NT_STATUS_NOT_SUPPORTED;
 #endif
 	default:
 		break;
@@ -2259,19 +2253,20 @@ static int fruit_open_rsrc(vfs_handle_struct *handle,
 	if (!(flags & O_CREAT) && !VALID_STAT(smb_fname->st)) {
 		rc = SMB_VFS_NEXT_STAT(handle, smb_fname);
 		if (rc != 0) {
-			rc = -1;
+			status = map_nt_error_from_unix(errno);
 			goto exit;
 		}
 	}
 
 	if (VALID_STAT(smb_fname->st) && S_ISDIR(smb_fname->st.st_ex_mode)) {
 		/* sorry, but directories don't habe a resource fork */
-		rc = -1;
+		status = NT_STATUS_FILE_IS_A_DIRECTORY;
 		goto exit;
 	}
 
 	rc = adouble_path(talloc_tos(), smb_fname->base_name, &adpath);
 	if (rc != 0) {
+		status = map_nt_error_from_unix(errno);
 		goto exit;
 	}
 
@@ -2279,8 +2274,7 @@ static int fruit_open_rsrc(vfs_handle_struct *handle,
 	smb_fname_base = synthetic_smb_fname(talloc_tos(),
 					     adpath, NULL, NULL);
 	if (smb_fname_base == NULL) {
-		errno = ENOMEM;
-		rc = -1;
+		status = NT_STATUS_NO_MEMORY;
 		goto exit;
 	}
 
@@ -2291,37 +2285,33 @@ static int fruit_open_rsrc(vfs_handle_struct *handle,
 		flags |= O_RDWR;
 	}
 
-	hostfd = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
+	status = SMB_VFS_OPEN2(handle->conn, smb_fname_base, fsp,
 			      flags, mode);
-	if (hostfd == -1) {
-		rc = -1;
+	if (!NT_STATUS_IS_OK(status)) {
 		goto exit;
 	}
 
-	/* REVIEW: we need this in ad_write() */
-	fsp->fh->fd = hostfd;
-
 	if (flags & (O_CREAT | O_TRUNC)) {
 		ad = ad_init(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
 			     handle, ADOUBLE_RSRC, fsp);
 		if (ad == NULL) {
-			rc = -1;
+			status = map_nt_error_from_unix(errno);
 			goto exit;
 		}
 		rc = ad_write(ad, smb_fname->base_name);
 		if (rc != 0) {
-			rc = -1;
+			status = map_nt_error_from_unix(errno);
 			goto exit;
 		}
 	} else {
 		ad = ad_alloc(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
 			      handle, ADOUBLE_RSRC, fsp);
 		if (ad == NULL) {
-			rc = -1;
+			status = map_nt_error_from_unix(errno);
 			goto exit;
 		}
 		if (ad_read(ad, smb_fname->base_name) == -1) {
-			rc = -1;
+			status = map_nt_error_from_unix(errno);
 			goto exit;
 		}
 	}
@@ -2331,33 +2321,26 @@ exit:
 	TALLOC_FREE(adpath);
 	TALLOC_FREE(smb_fname_base);
 
-	DEBUG(10, ("fruit_open resource fork: rc=%d, fd=%d\n", rc, hostfd));
-	if (rc != 0) {
-		int saved_errno = errno;
-		if (hostfd >= 0) {
-			/*
-			 * BUGBUGBUG -- we would need to call
-			 * fd_close_posix here, but we don't have a
-			 * full fsp yet
-			 */
-			fsp->fh->fd = hostfd;
+	DEBUG(10, ("fruit_open resource fork: status=%s, fd=%d\n",
+		   nt_errstr(status), fsp_get_fd(fsp)));
+	if (!NT_STATUS_IS_OK(status)) {
+		if (fsp_fd_isset(fsp)) {
 			SMB_VFS_CLOSE(fsp);
+			fsp_reset_fd(fsp);
 		}
-		hostfd = -1;
-		errno = saved_errno;
 	}
-	return hostfd;
+	return status;
 }
 
-static int fruit_open(vfs_handle_struct *handle,
-                      struct smb_filename *smb_fname,
-                      files_struct *fsp, int flags, mode_t mode)
+static NTSTATUS fruit_open(vfs_handle_struct *handle,
+			   struct smb_filename *smb_fname,
+			   files_struct *fsp, int flags, mode_t mode)
 {
 	DEBUG(10, ("fruit_open called for %s\n",
 		   smb_fname_str_dbg(smb_fname)));
 
 	if (!is_ntfs_stream_smb_fname(smb_fname)) {
-		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 	}
 
 	if (is_afpinfo_stream(smb_fname)) {
@@ -2366,7 +2349,7 @@ static int fruit_open(vfs_handle_struct *handle,
 		return fruit_open_rsrc(handle, smb_fname, fsp, flags, mode);
 	}
 
-	return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+	return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 }
 
 static int fruit_rename(struct vfs_handle_struct *handle,
@@ -3829,7 +3812,7 @@ static struct vfs_fn_pointers vfs_fruit_fns = {
 	.unlink_fn = fruit_unlink,
 	.rename_fn = fruit_rename,
 	.rmdir_fn = fruit_rmdir,
-	.open_fn = fruit_open,
+	.open2_fn = fruit_open,
 	.pread_fn = fruit_pread,
 	.pwrite_fn = fruit_pwrite,
 	.stat_fn = fruit_stat,
-- 
2.4.3


From b7336b9be07a246745d114e8ad90a1a6d53c8522 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Tue, 6 Oct 2015 22:28:42 +0300
Subject: [PATCH 12/35] vfs_streams_xattr: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_streams_xattr.c | 60 +++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 33 deletions(-)

diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c
index b54809f..d6fec39 100644
--- a/source3/modules/vfs_streams_xattr.c
+++ b/source3/modules/vfs_streams_xattr.c
@@ -385,9 +385,9 @@ static int streams_xattr_lstat(vfs_handle_struct *handle,
 	return result;
 }
 
-static int streams_xattr_open(vfs_handle_struct *handle,
-			      struct smb_filename *smb_fname,
-			      files_struct *fsp, int flags, mode_t mode)
+static NTSTATUS streams_xattr_open(vfs_handle_struct *handle,
+				   struct smb_filename *smb_fname,
+				   files_struct *fsp, int flags, mode_t mode)
 {
 	NTSTATUS status;
 	struct smb_filename *smb_fname_base = NULL;
@@ -395,34 +395,32 @@ static int streams_xattr_open(vfs_handle_struct *handle,
 	struct ea_struct ea;
 	char *xattr_name = NULL;
 	int baseflags;
-	int hostfd = -1;
 
 	DEBUG(10, ("streams_xattr_open called for %s with flags 0x%x\n",
 		   smb_fname_str_dbg(smb_fname), flags));
 
 	if (!is_ntfs_stream_smb_fname(smb_fname)) {
-		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 	}
 
 	/* If the default stream is requested, just open the base file. */
 	if (is_ntfs_default_stream_smb_fname(smb_fname)) {
 		char *tmp_stream_name;
-		int ret;
 
 		tmp_stream_name = smb_fname->stream_name;
 		smb_fname->stream_name = NULL;
 
-		ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+		status =
+		    SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 
 		smb_fname->stream_name = tmp_stream_name;
 
-		return ret;
+		return status;
 	}
 
 	status = streams_xattr_get_name(handle, talloc_tos(),
 					smb_fname->stream_name, &xattr_name);
 	if (!NT_STATUS_IS_OK(status)) {
-		errno = map_errno_from_nt_status(status);
 		goto fail;
 	}
 
@@ -430,7 +428,7 @@ static int streams_xattr_open(vfs_handle_struct *handle,
 	smb_fname_base = synthetic_smb_fname(
 		talloc_tos(), smb_fname->base_name, NULL, NULL);
 	if (smb_fname_base == NULL) {
-		errno = ENOMEM;
+		status = NT_STATUS_NO_MEMORY;
 		goto fail;
 	}
 
@@ -443,22 +441,22 @@ static int streams_xattr_open(vfs_handle_struct *handle,
         baseflags &= ~O_EXCL;
         baseflags &= ~O_CREAT;
 
-        hostfd = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
-			      baseflags, mode);
+	status =
+	    SMB_VFS_OPEN2(handle->conn, smb_fname_base, fsp, baseflags, mode);
 
 	TALLOC_FREE(smb_fname_base);
 
         /* It is legit to open a stream on a directory, but the base
          * fd has to be read-only.
          */
-        if ((hostfd == -1) && (errno == EISDIR)) {
-                baseflags &= ~O_ACCMODE;
-                baseflags |= O_RDONLY;
-                hostfd = SMB_VFS_OPEN(handle->conn, smb_fname, fsp, baseflags,
-				      mode);
-        }
+	if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) {
+		baseflags &= ~O_ACCMODE;
+		baseflags |= O_RDONLY;
+		status = SMB_VFS_OPEN2(handle->conn, smb_fname, fsp, baseflags,
+				       mode);
+	}
 
-        if (hostfd == -1) {
+	if (!NT_STATUS_IS_OK(status)) {
 		goto fail;
         }
 
@@ -476,7 +474,7 @@ static int streams_xattr_open(vfs_handle_struct *handle,
 		 */
 		DEBUG(10, ("streams_xattr_open: base file %s not around, "
 			   "returning ENOENT\n", smb_fname->base_name));
-		errno = ENOENT;
+		status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
 		goto fail;
 	}
 
@@ -494,7 +492,7 @@ static int streams_xattr_open(vfs_handle_struct *handle,
 		DEBUG(10, ("creating or truncating attribute %s on file %s\n",
 			   xattr_name, smb_fname->base_name));
 
-		if (fsp->base_fsp->fh->fd != -1) {
+		if (fsp_fd_isset(fsp->base_fsp)) {
 			if (SMB_VFS_FSETXATTR(
 					fsp->base_fsp, xattr_name,
 					&null, sizeof(null),
@@ -515,8 +513,8 @@ static int streams_xattr_open(vfs_handle_struct *handle,
 							struct stream_io,
 							NULL);
         if (sio == NULL) {
-                errno = ENOMEM;
-                goto fail;
+		status = NT_STATUS_NO_MEMORY;
+		goto fail;
         }
 
         sio->xattr_name = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
@@ -528,23 +526,19 @@ static int streams_xattr_open(vfs_handle_struct *handle,
 	sio->fsp = fsp;
 
 	if ((sio->xattr_name == NULL) || (sio->base == NULL)) {
-		errno = ENOMEM;
+		status = NT_STATUS_NO_MEMORY;
 		goto fail;
 	}
 
-	return hostfd;
+	return NT_STATUS_OK;
 
  fail:
-	if (hostfd >= 0) {
-		/*
-		 * BUGBUGBUG -- we would need to call fd_close_posix here, but
-		 * we don't have a full fsp yet
-		 */
-		fsp->fh->fd = hostfd;
+	 if (fsp_fd_isset(fsp)) {
 		SMB_VFS_CLOSE(fsp);
+		fsp_reset_fd(fsp);
 	}
 
-	return -1;
+	return status;
 }
 
 static int streams_xattr_unlink(vfs_handle_struct *handle,
@@ -1134,7 +1128,7 @@ static int streams_xattr_fallocate(struct vfs_handle_struct *handle,
 static struct vfs_fn_pointers vfs_streams_xattr_fns = {
 	.fs_capabilities_fn = streams_xattr_fs_capabilities,
 	.connect_fn = streams_xattr_connect,
-	.open_fn = streams_xattr_open,
+	.open2_fn = streams_xattr_open,
 	.stat_fn = streams_xattr_stat,
 	.fstat_fn = streams_xattr_fstat,
 	.lstat_fn = streams_xattr_lstat,
-- 
2.4.3


From 3defd0c94631d4b5e65cac13ad2a5e2ab98111ee Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Wed, 7 Oct 2015 22:09:27 +0300
Subject: [PATCH 13/35] VFS examples: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 examples/VFS/skel_opaque.c      | 10 +++++-----
 examples/VFS/skel_transparent.c |  9 +++++----
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c
index 29fe6f4..477bea0 100644
--- a/examples/VFS/skel_opaque.c
+++ b/examples/VFS/skel_opaque.c
@@ -179,11 +179,11 @@ static void skel_init_search_op(struct vfs_handle_struct *handle, DIR *dirp)
 	;
 }
 
-static int skel_open(vfs_handle_struct *handle, struct smb_filename *smb_fname,
-		     files_struct *fsp, int flags, mode_t mode)
+static NTSTATUS skel_open(vfs_handle_struct *handle,
+			  struct smb_filename *smb_fname, files_struct *fsp,
+			  int flags, mode_t mode)
 {
-	errno = ENOSYS;
-	return -1;
+	return NT_STATUS_INVALID_SYSTEM_SERVICE;
 }
 
 static NTSTATUS skel_create_file(struct vfs_handle_struct *handle,
@@ -863,7 +863,7 @@ struct vfs_fn_pointers skel_opaque_fns = {
 
 	/* File operations */
 
-	.open_fn = skel_open,
+	.open2_fn = skel_open,
 	.create_file_fn = skel_create_file,
 	.close_fn = skel_close_fn,
 	.read_fn = skel_vfs_read,
diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c
index c5a36a6..ae8d0d9 100644
--- a/examples/VFS/skel_transparent.c
+++ b/examples/VFS/skel_transparent.c
@@ -176,10 +176,11 @@ static void skel_init_search_op(struct vfs_handle_struct *handle, DIR *dirp)
 	SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
 }
 
-static int skel_open(vfs_handle_struct *handle, struct smb_filename *smb_fname,
-		     files_struct *fsp, int flags, mode_t mode)
+static NTSTATUS skel_open(vfs_handle_struct *handle,
+			  struct smb_filename *smb_fname, files_struct *fsp,
+			  int flags, mode_t mode)
 {
-	return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+	return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 }
 
 static NTSTATUS skel_create_file(struct vfs_handle_struct *handle,
@@ -972,7 +973,7 @@ struct vfs_fn_pointers skel_transparent_fns = {
 
 	/* File operations */
 
-	.open_fn = skel_open,
+	.open2_fn = skel_open,
 	.create_file_fn = skel_create_file,
 	.close_fn = skel_close_fn,
 	.read_fn = skel_vfs_read,
-- 
2.4.3


From 960be48876cdd9c4d5b80c6d0a44fe4661c5e2fa Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Wed, 7 Oct 2015 22:10:12 +0300
Subject: [PATCH 14/35] vfs_aio_pthread: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_aio_pthread.c | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/source3/modules/vfs_aio_pthread.c b/source3/modules/vfs_aio_pthread.c
index 059d745..6818c4e 100644
--- a/source3/modules/vfs_aio_pthread.c
+++ b/source3/modules/vfs_aio_pthread.c
@@ -441,36 +441,39 @@ static bool find_completed_open(files_struct *fsp,
  opens to prevent any race conditions.
 *****************************************************************/
 
-static int aio_pthread_open_fn(vfs_handle_struct *handle,
-			struct smb_filename *smb_fname,
-			files_struct *fsp,
-			int flags,
-			mode_t mode)
+static NTSTATUS aio_pthread_open_fn(vfs_handle_struct *handle,
+				    struct smb_filename *smb_fname,
+				    files_struct *fsp,
+				    int flags,
+				    mode_t mode)
 {
 	int my_errno = 0;
 	int fd = -1;
+	NTSTATUS status = NT_STATUS_OK;
 	bool aio_allow_open = lp_parm_bool(
 		SNUM(handle->conn), "aio_pthread", "aio open", false);
 
 	if (smb_fname->stream_name) {
 		/* Don't handle stream opens. */
-		errno = ENOENT;
-		return -1;
+		return NT_STATUS_OBJECT_NAME_NOT_FOUND;
 	}
 
 	if (!aio_allow_open) {
 		/* aio opens turned off. */
-		return open(smb_fname->base_name, flags, mode);
+		fd = open(smb_fname->base_name, flags, mode);
+		goto out;
 	}
 
 	if (!(flags & O_CREAT)) {
 		/* Only creates matter. */
-		return open(smb_fname->base_name, flags, mode);
+		fd = open(smb_fname->base_name, flags, mode);
+		goto out;
 	}
 
 	if (!(flags & O_EXCL)) {
 		/* Only creates with O_EXCL matter. */
-		return open(smb_fname->base_name, flags, mode);
+		fd = open(smb_fname->base_name, flags, mode);
+		goto out;
 	}
 
 	/*
@@ -482,17 +485,25 @@ static int aio_pthread_open_fn(vfs_handle_struct *handle,
 				&fd,
 				&my_errno)) {
 		errno = my_errno;
-		return fd;
+		goto out;
 	}
 
 	/* Ok, it's a create exclusive call - pass it to a thread helper. */
-	return open_async(fsp, flags, mode);
+	fd = open_async(fsp, flags, mode);
+
+out:
+	fsp_assign_fd(fsp,fd);
+	if (fd == -1) {
+		status = map_nt_open_error_from_unix(errno);
+	}
+
+	return status;
 }
 #endif
 
 static struct vfs_fn_pointers vfs_aio_pthread_fns = {
 #if defined(HAVE_OPENAT) && defined(USE_LINUX_THREAD_CREDENTIALS)
-	.open_fn = aio_pthread_open_fn,
+	.open2_fn = aio_pthread_open_fn,
 #endif
 };
 
-- 
2.4.3


From facb2a31c92bfe159512e6cf967bdfc9d525e459 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Wed, 7 Oct 2015 22:11:01 +0300
Subject: [PATCH 15/35] vfs_audit: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_audit.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/source3/modules/vfs_audit.c b/source3/modules/vfs_audit.c
index 02e8f35..1425c16 100644
--- a/source3/modules/vfs_audit.c
+++ b/source3/modules/vfs_audit.c
@@ -148,19 +148,19 @@ static int audit_rmdir(vfs_handle_struct *handle, const char *path)
 	return result;
 }
 
-static int audit_open(vfs_handle_struct *handle,
-		      struct smb_filename *smb_fname, files_struct *fsp,
-		      int flags, mode_t mode)
+static NTSTATUS audit_open(vfs_handle_struct *handle,
+			   struct smb_filename *smb_fname, files_struct *fsp,
+			   int flags, mode_t mode)
 {
-	int result;
+	NTSTATUS result;
 
-	result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+	result = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 
 	syslog(audit_syslog_priority(handle), "open %s (fd %d) %s%s%s\n", 
-	       smb_fname->base_name, result,
+	       smb_fname->base_name, fsp_get_fd(fsp),
 	       ((flags & O_WRONLY) || (flags & O_RDWR)) ? "for writing " : "", 
-	       (result < 0) ? "failed: " : "",
-	       (result < 0) ? strerror(errno) : "");
+	       !NT_STATUS_IS_OK(result) ? "failed: " : "",
+	       !NT_STATUS_IS_OK(result) ? nt_errstr(result) : "");
 
 	return result;
 }
@@ -273,7 +273,7 @@ static struct vfs_fn_pointers vfs_audit_fns = {
 	.opendir_fn = audit_opendir,
 	.mkdir_fn = audit_mkdir,
 	.rmdir_fn = audit_rmdir,
-	.open_fn = audit_open,
+	.open2_fn = audit_open,
 	.close_fn = audit_close,
 	.rename_fn = audit_rename,
 	.unlink_fn = audit_unlink,
-- 
2.4.3


From 091bc4daf83f72964f319dd22a54f807da43037c Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Wed, 7 Oct 2015 22:11:36 +0300
Subject: [PATCH 16/35] vfs_cap: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_cap.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/source3/modules/vfs_cap.c b/source3/modules/vfs_cap.c
index b5a1906..273487b 100644
--- a/source3/modules/vfs_cap.c
+++ b/source3/modules/vfs_cap.c
@@ -107,25 +107,25 @@ static int cap_rmdir(vfs_handle_struct *handle, const char *path)
 	return SMB_VFS_NEXT_RMDIR(handle, cappath);
 }
 
-static int cap_open(vfs_handle_struct *handle, struct smb_filename *smb_fname,
-		    files_struct *fsp, int flags, mode_t mode)
+static NTSTATUS cap_open(vfs_handle_struct *handle,
+			 struct smb_filename *smb_fname,
+			 files_struct *fsp, int flags, mode_t mode)
 {
 	char *cappath;
 	char *tmp_base_name = NULL;
-	int ret;
+	NTSTATUS ret;
 
 	cappath = capencode(talloc_tos(), smb_fname->base_name);
 
 	if (!cappath) {
-		errno = ENOMEM;
-		return -1;
+		return NT_STATUS_NO_MEMORY;
 	}
 
 	tmp_base_name = smb_fname->base_name;
 	smb_fname->base_name = cappath;
 
 	DEBUG(3,("cap: cap_open for %s\n", smb_fname_str_dbg(smb_fname)));
-	ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+	ret = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 
 	smb_fname->base_name = tmp_base_name;
 	TALLOC_FREE(cappath);
@@ -521,7 +521,7 @@ static struct vfs_fn_pointers vfs_cap_fns = {
 	.readdir_fn = cap_readdir,
 	.mkdir_fn = cap_mkdir,
 	.rmdir_fn = cap_rmdir,
-	.open_fn = cap_open,
+	.open2_fn = cap_open,
 	.rename_fn = cap_rename,
 	.stat_fn = cap_stat,
 	.lstat_fn = cap_lstat,
-- 
2.4.3


From 8920d36e5bd83c2dc68db90809ca4127cac4428c Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Wed, 7 Oct 2015 22:12:20 +0300
Subject: [PATCH 17/35] vfs_catia: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_catia.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/source3/modules/vfs_catia.c b/source3/modules/vfs_catia.c
index c17ffa8..2656f01 100644
--- a/source3/modules/vfs_catia.c
+++ b/source3/modules/vfs_catia.c
@@ -337,15 +337,14 @@ static NTSTATUS catia_translate_name(struct vfs_handle_struct *handle,
 	return ret;
 }
 
-static int catia_open(vfs_handle_struct *handle,
-		      struct smb_filename *smb_fname,
-		      files_struct *fsp,
-		      int flags,
-		      mode_t mode)
+static NTSTATUS catia_open(vfs_handle_struct *handle,
+			   struct smb_filename *smb_fname,
+			   files_struct *fsp,
+			   int flags,
+			   mode_t mode)
 {
 	char *name_mapped = NULL;
 	char *tmp_base_name;
-	int ret;
 	NTSTATUS status;
 
 	tmp_base_name = smb_fname->base_name;
@@ -353,16 +352,15 @@ static int catia_open(vfs_handle_struct *handle,
 					smb_fname->base_name,
 					&name_mapped, vfs_translate_to_unix);
 	if (!NT_STATUS_IS_OK(status)) {
-		errno = map_errno_from_nt_status(status);
-		return -1;
+		return status;
 	}
 
 	smb_fname->base_name = name_mapped;
-	ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+	status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 	smb_fname->base_name = tmp_base_name;
 	TALLOC_FREE(name_mapped);
 
-	return ret;
+	return status;
 }
 
 static int catia_rename(vfs_handle_struct *handle,
@@ -980,7 +978,7 @@ static struct vfs_fn_pointers vfs_catia_fns = {
 	.mkdir_fn = catia_mkdir,
 	.rmdir_fn = catia_rmdir,
 	.opendir_fn = catia_opendir,
-	.open_fn = catia_open,
+	.open2_fn = catia_open,
 	.rename_fn = catia_rename,
 	.stat_fn = catia_stat,
 	.lstat_fn = catia_lstat,
-- 
2.4.3


From 553c976f902abc92d182ce83675dec0a233fba04 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Wed, 7 Oct 2015 22:13:00 +0300
Subject: [PATCH 18/35] vfs_ceph: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_ceph.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/source3/modules/vfs_ceph.c b/source3/modules/vfs_ceph.c
index 0113faa..1639093 100644
--- a/source3/modules/vfs_ceph.c
+++ b/source3/modules/vfs_ceph.c
@@ -385,9 +385,9 @@ static int cephwrap_closedir(struct vfs_handle_struct *handle, DIR *dirp)
 
 /* File operations */
 
-static int cephwrap_open(struct vfs_handle_struct *handle,
-			struct smb_filename *smb_fname,
-			files_struct *fsp, int flags, mode_t mode)
+static NTSTATUS cephwrap_open(struct vfs_handle_struct *handle,
+			      struct smb_filename *smb_fname,
+			      files_struct *fsp, int flags, mode_t mode)
 {
 	int result = -ENOENT;
 	DEBUG(10, ("[CEPH] open(%p, %s, %p, %d, %d)\n", handle, smb_fname_str_dbg(smb_fname), fsp, flags, mode));
@@ -399,7 +399,12 @@ static int cephwrap_open(struct vfs_handle_struct *handle,
 	result = ceph_open(handle->data, smb_fname->base_name, flags, mode);
 out:
 	DEBUG(10, ("[CEPH] open(...) = %d\n", result));
-	WRAP_RETURN(result);
+	if (result < 0) {
+		return map_nt_error_from_unix(-result);
+	}
+
+	fsp_assign_fd(fsp, result);
+	return NT_STATUS_OK;
 }
 
 static int cephwrap_close(struct vfs_handle_struct *handle, files_struct *fsp)
@@ -1253,7 +1258,7 @@ static struct vfs_fn_pointers ceph_fns = {
 
 	/* File operations */
 
-	.open_fn = cephwrap_open,
+	.open2_fn = cephwrap_open,
 	.close_fn = cephwrap_close,
 	.read_fn = cephwrap_read,
 	.pread_fn = cephwrap_pread,
-- 
2.4.3


From ab742a5fd4a9eb5bc2c986b846862d7189935132 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Wed, 7 Oct 2015 22:13:36 +0300
Subject: [PATCH 19/35] vfs_commit: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_commit.c | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/source3/modules/vfs_commit.c b/source3/modules/vfs_commit.c
index f1e2743..42b2286 100644
--- a/source3/modules/vfs_commit.c
+++ b/source3/modules/vfs_commit.c
@@ -177,7 +177,7 @@ static int commit_connect(
         return 0;
 }
 
-static int commit_open(
+static NTSTATUS commit_open(
 	vfs_handle_struct * handle,
 	struct smb_filename *smb_fname,
 	files_struct *	    fsp,
@@ -187,11 +187,11 @@ static int commit_open(
         off_t dthresh;
 	const char *eof_mode;
         struct commit_info *c = NULL;
-        int fd;
+        NTSTATUS status;
 
         /* Don't bother with read-only files. */
         if ((flags & O_ACCMODE) == O_RDONLY) {
-                return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+                return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
         }
 
         /* Read and check module configuration */
@@ -221,31 +221,22 @@ static int commit_open(
                 }
         }
 
-        fd = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
-	if (fd == -1) {
+        status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	if (!NT_STATUS_IS_OK(status)) {
 		VFS_REMOVE_FSP_EXTENSION(handle, fsp);
-		return fd;
+		return status;
 	}
 
         /* EOF commit modes require us to know the initial file size. */
         if (c && (c->on_eof != EOF_NONE)) {
                 SMB_STRUCT_STAT st;
-		/*
-		 * Setting the fd of the FSP is a hack
-		 * but also practiced elsewhere -
-		 * needed for calling the VFS.
-		 */
-		fsp->fh->fd = fd;
-		if (SMB_VFS_FSTAT(fsp, &st) == -1) {
-			int saved_errno = errno;
-			SMB_VFS_CLOSE(fsp);
-			errno = saved_errno;
-                        return -1;
+                if (SMB_VFS_FSTAT(fsp, &st) == -1) {
+                        return map_nt_error_from_unix(errno);
                 }
 		c->eof = st.st_ex_size;
         }
 
-        return fd;
+        return status;
 }
 
 static ssize_t commit_write(
@@ -392,7 +383,7 @@ static int commit_ftruncate(
 }
 
 static struct vfs_fn_pointers vfs_commit_fns = {
-        .open_fn = commit_open,
+        .open2_fn = commit_open,
         .close_fn = commit_close,
         .write_fn = commit_write,
         .pwrite_fn = commit_pwrite,
-- 
2.4.3


From 3571b99c610ee4982f90a951ac36163d4dce27f7 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Thu, 8 Oct 2015 22:53:07 +0300
Subject: [PATCH 20/35] vfs_extd_audit: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_extd_audit.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/source3/modules/vfs_extd_audit.c b/source3/modules/vfs_extd_audit.c
index 7d6b4d3..2ad9b34 100644
--- a/source3/modules/vfs_extd_audit.c
+++ b/source3/modules/vfs_extd_audit.c
@@ -176,25 +176,25 @@ static int audit_rmdir(vfs_handle_struct *handle, const char *path)
 	return result;
 }
 
-static int audit_open(vfs_handle_struct *handle,
-		      struct smb_filename *smb_fname, files_struct *fsp,
-		      int flags, mode_t mode)
+static NTSTATUS  audit_open(vfs_handle_struct *handle,
+			    struct smb_filename *smb_fname, files_struct *fsp,
+			    int flags, mode_t mode)
 {
-	int result;
+	NTSTATUS result;
 
-	result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+	result = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 
 	if (lp_syslog() > 0) {
 		syslog(audit_syslog_priority(handle), "open %s (fd %d) %s%s%s\n",
-		       smb_fname->base_name, result,
+		       smb_fname->base_name, fsp_get_fd(fsp),
 		       ((flags & O_WRONLY) || (flags & O_RDWR)) ? "for writing " : "",
-		       (result < 0) ? "failed: " : "",
-		       (result < 0) ? strerror(errno) : "");
+		       NT_STATUS_IS_OK(result) ? "" : "failed: ",
+		       NT_STATUS_IS_OK(result) ? "" : nt_errstr(result));
 	}
 	DEBUG(2, ("vfs_extd_audit: open %s %s %s\n",
 	       smb_fname_str_dbg(smb_fname),
-	       (result < 0) ? "failed: " : "",
-	       (result < 0) ? strerror(errno) : ""));
+	       NT_STATUS_IS_OK(result) ? "" : "failed: ",
+	       NT_STATUS_IS_OK(result) ? "" : nt_errstr(result)));
 
 	return result;
 }
@@ -350,7 +350,7 @@ static struct vfs_fn_pointers vfs_extd_audit_fns = {
 	.opendir_fn = audit_opendir,
 	.mkdir_fn = audit_mkdir,
 	.rmdir_fn = audit_rmdir,
-	.open_fn = audit_open,
+	.open2_fn = audit_open,
 	.close_fn = audit_close,
 	.rename_fn = audit_rename,
 	.unlink_fn = audit_unlink,
-- 
2.4.3


From 3d7d954817e515b62229e968d387caf2616d16e7 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Thu, 8 Oct 2015 22:53:44 +0300
Subject: [PATCH 21/35] vfs_full_audit: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_full_audit.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c
index 11f5d82..d07ce43 100644
--- a/source3/modules/vfs_full_audit.c
+++ b/source3/modules/vfs_full_audit.c
@@ -887,15 +887,15 @@ static void smb_full_audit_init_search_op(vfs_handle_struct *handle,
 	do_log(SMB_VFS_OP_INIT_SEARCH_OP, True, handle, "");
 }
 
-static int smb_full_audit_open(vfs_handle_struct *handle,
-			       struct smb_filename *smb_fname,
-			       files_struct *fsp, int flags, mode_t mode)
+static NTSTATUS smb_full_audit_open(vfs_handle_struct *handle,
+				    struct smb_filename *smb_fname,
+				    files_struct *fsp, int flags, mode_t mode)
 {
-	int result;
+	NTSTATUS result;
 	
-	result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+	result = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 
-	do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s",
+	do_log(SMB_VFS_OP_OPEN, NT_STATUS_IS_OK(result), handle, "%s|%s",
 	       ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
 	       smb_fname_str_do_log(smb_fname));
 
@@ -2240,7 +2240,7 @@ static struct vfs_fn_pointers vfs_full_audit_fns = {
 	.rmdir_fn = smb_full_audit_rmdir,
 	.closedir_fn = smb_full_audit_closedir,
 	.init_search_op_fn = smb_full_audit_init_search_op,
-	.open_fn = smb_full_audit_open,
+	.open2_fn = smb_full_audit_open,
 	.create_file_fn = smb_full_audit_create_file,
 	.close_fn = smb_full_audit_close,
 	.read_fn = smb_full_audit_read,
-- 
2.4.3


From 63334b5fd38cbbfc4020f2bcb5a3c0683886b2bf Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Thu, 8 Oct 2015 22:54:26 +0300
Subject: [PATCH 22/35] vfs_glusterfs: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_glusterfs.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c
index cf8066e..1dd1d3f 100644
--- a/source3/modules/vfs_glusterfs.c
+++ b/source3/modules/vfs_glusterfs.c
@@ -439,9 +439,9 @@ static int vfs_gluster_rmdir(struct vfs_handle_struct *handle, const char *path)
 	return glfs_rmdir(handle->data, path);
 }
 
-static int vfs_gluster_open(struct vfs_handle_struct *handle,
-			    struct smb_filename *smb_fname, files_struct *fsp,
-			    int flags, mode_t mode)
+static NTSTATUS vfs_gluster_open(struct vfs_handle_struct *handle,
+				 struct smb_filename *smb_fname,
+				 files_struct *fsp, int flags, mode_t mode)
 {
 	glfs_fd_t *glfd;
 	glfs_fd_t **p_tmp;
@@ -456,13 +456,15 @@ static int vfs_gluster_open(struct vfs_handle_struct *handle,
 	}
 
 	if (glfd == NULL) {
-		return -1;
+		return map_nt_error_from_unix(errno);
 	}
 	p_tmp = (glfs_fd_t **)VFS_ADD_FSP_EXTENSION(handle, fsp,
 							  glfs_fd_t *, NULL);
 	*p_tmp = glfd;
 	/* An arbitrary value for error reporting, so you know its us. */
-	return 13371337;
+	fsp_assign_fd(fsp, 13371337);
+
+	return NT_STATUS_OK;
 }
 
 static int vfs_gluster_close(struct vfs_handle_struct *handle,
@@ -1704,7 +1706,7 @@ static struct vfs_fn_pointers glusterfs_fns = {
 
 	/* File Operations */
 
-	.open_fn = vfs_gluster_open,
+	.open2_fn = vfs_gluster_open,
 	.create_file_fn = NULL,
 	.close_fn = vfs_gluster_close,
 	.read_fn = vfs_gluster_read,
-- 
2.4.3


From d111e28d40257b5a88e684a109e93b5975b0139c Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Thu, 8 Oct 2015 22:55:03 +0300
Subject: [PATCH 23/35] vfs_gpfs: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_gpfs.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/source3/modules/vfs_gpfs.c b/source3/modules/vfs_gpfs.c
index ee4c1f6..949f9f6 100644
--- a/source3/modules/vfs_gpfs.c
+++ b/source3/modules/vfs_gpfs.c
@@ -2230,19 +2230,18 @@ static int vfs_gpfs_open(struct vfs_handle_struct *handle,
 			 int flags, mode_t mode)
 {
 	struct gpfs_config_data *config;
-	int ret;
+	NTSTATUS status;
 	struct gpfs_fsp_extension *ext;
 
 	SMB_VFS_HANDLE_GET_DATA(handle, config,
 				struct gpfs_config_data,
-				return -1);
+				return NT_STATUS_UNSUCCESSFUL);
 
 	if (config->hsm && !config->recalls &&
 	    vfs_gpfs_fsp_is_offline(handle, fsp)) {
 		DEBUG(10, ("Refusing access to offline file %s\n",
 			   fsp_str_dbg(fsp)));
-		errno = EACCES;
-		return -1;
+		return NT_STATUS_ACCESS_DENIED;
 	}
 
 	if (config->syncio) {
@@ -2252,8 +2251,7 @@ static int vfs_gpfs_open(struct vfs_handle_struct *handle,
 	ext = VFS_ADD_FSP_EXTENSION(handle, fsp, struct gpfs_fsp_extension,
 				    NULL);
 	if (ext == NULL) {
-		errno = ENOMEM;
-		return -1;
+		return NT_STATUS_NO_MEMORY;
 	}
 
 	/*
@@ -2261,11 +2259,11 @@ static int vfs_gpfs_open(struct vfs_handle_struct *handle,
 	 */
 	*ext = (struct gpfs_fsp_extension) { .offline = true };
 
-	ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
-	if (ret == -1) {
+	status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	if (!NT_STATUS_OK(status)) {
 		VFS_REMOVE_FSP_EXTENSION(handle, fsp);
 	}
-	return ret;
+	return status;
 }
 
 static ssize_t vfs_gpfs_pread(vfs_handle_struct *handle, files_struct *fsp,
@@ -2472,7 +2470,7 @@ static struct vfs_fn_pointers vfs_gpfs_fns = {
 	.aio_force_fn = vfs_gpfs_aio_force,
 	.sendfile_fn = vfs_gpfs_sendfile,
 	.fallocate_fn = vfs_gpfs_fallocate,
-	.open_fn = vfs_gpfs_open,
+	.open2_fn = vfs_gpfs_open,
 	.pread_fn = vfs_gpfs_pread,
 	.pread_send_fn = vfs_gpfs_pread_send,
 	.pread_recv_fn = vfs_gpfs_pread_recv,
-- 
2.4.3


From e8d9549660a4fa2d3a297794cbb115f737eb5a17 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Thu, 8 Oct 2015 22:55:41 +0300
Subject: [PATCH 24/35] vfs_media_harmony: convert open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_media_harmony.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/source3/modules/vfs_media_harmony.c b/source3/modules/vfs_media_harmony.c
index d960fae..e8fb7b0 100644
--- a/source3/modules/vfs_media_harmony.c
+++ b/source3/modules/vfs_media_harmony.c
@@ -1138,13 +1138,13 @@ static void mh_init_search_op(vfs_handle_struct *handle,
  * Success: return non-negative file descriptor
  * Failure: set errno, return -1
  */
-static int mh_open(vfs_handle_struct *handle,
+static NTSTATUS mh_open(vfs_handle_struct *handle,
 		struct smb_filename *smb_fname,
 		files_struct *fsp,
 		int flags,
 		mode_t mode)
 {
-	int ret;
+	NTSTATUS status;
 	struct smb_filename *clientFname;
 	TALLOC_CTX *ctx;
 
@@ -1154,8 +1154,8 @@ static int mh_open(vfs_handle_struct *handle,
 
 	if (!is_in_media_files(smb_fname->base_name))
 	{
-		ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags,
-				mode);
+		status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags,
+					   mode);
 		goto out;
 	}
 
@@ -1166,7 +1166,7 @@ static int mh_open(vfs_handle_struct *handle,
 				smb_fname,
 				&clientFname))
 	{
-		ret = -1;
+		status = map_nt_error_from_unix(errno);
 		goto err;
 	}
 
@@ -1181,13 +1181,13 @@ static int mh_open(vfs_handle_struct *handle,
 			ctime(&(smb_fname->st.st_ex_mtime.tv_sec)),
 			ctime(&(fsp->fsp_name->st.st_ex_mtime.tv_sec))));
 
-	ret = SMB_VFS_NEXT_OPEN(handle, clientFname, fsp, flags, mode);
+	status = SMB_VFS_NEXT_OPEN2(handle, clientFname, fsp, flags, mode);
 err:
 	TALLOC_FREE(clientFname);
 out:
 	DEBUG(MH_INFO_DEBUG, ("Leaving with smb_fname->base_name '%s'\n",
 				smb_fname->base_name));
-	return ret;
+	return status;
 }
 
 /*
@@ -2457,7 +2457,7 @@ static struct vfs_fn_pointers vfs_mh_fns = {
 
 	/* File operations */
 
-	.open_fn = mh_open,
+	.open2_fn = mh_open,
 	.create_file_fn = mh_create_file,
 	.rename_fn = mh_rename,
 	.stat_fn = mh_stat,
-- 
2.4.3


From a1937c4fe65380b68c888f532017389ef602bdfd Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sat, 10 Oct 2015 22:16:42 +0300
Subject: [PATCH 25/35] vfs_prealloc: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_prealloc.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/source3/modules/vfs_prealloc.c b/source3/modules/vfs_prealloc.c
index 7b96d36..df613ba 100644
--- a/source3/modules/vfs_prealloc.c
+++ b/source3/modules/vfs_prealloc.c
@@ -106,12 +106,13 @@ static int prealloc_connect(
 	return 0;
 }
 
-static int prealloc_open(vfs_handle_struct* handle,
-			struct smb_filename *smb_fname,
-			files_struct *	    fsp,
-			int		    flags,
-			mode_t		    mode)
+static NTSTATUS prealloc_open(vfs_handle_struct* handle,
+			      struct smb_filename *smb_fname,
+			      files_struct *	    fsp,
+			      int		    flags,
+			      mode_t		    mode)
 {
+	NTSTATUS status;
 	int fd;
 	off_t size = 0;
 
@@ -153,9 +154,9 @@ static int prealloc_open(vfs_handle_struct* handle,
 		goto normal_open;
 	}
 
-	fd = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
-	if (fd < 0) {
-		return fd;
+	status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	if (!NT_STATUS_OK(status)) {
+		return status;
 	}
 
 	/* Prellocate only if the file is being created or replaced. Note that
@@ -164,10 +165,11 @@ static int prealloc_open(vfs_handle_struct* handle,
 	 */
 	if ((flags & O_CREAT) || (flags & O_TRUNC)) {
 		off_t * psize;
+		int fd = fsp_get_fd(fsp);
 
 		psize = VFS_ADD_FSP_EXTENSION(handle, fsp, off_t, NULL);
 		if (psize == NULL || *psize == -1) {
-			return fd;
+			return status;
 		}
 
 		DEBUG(module_debug,
@@ -181,7 +183,7 @@ static int prealloc_open(vfs_handle_struct* handle,
 		}
 	}
 
-	return fd;
+	return status;
 
 normal_open:
 	/* We are not creating or replacing a file. Skip the
@@ -189,7 +191,7 @@ normal_open:
 	 */
 	DEBUG(module_debug, ("%s: skipping preallocation for %s\n",
 		MODULE, smb_fname_str_dbg(smb_fname)));
-	return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+	return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 }
 
 static int prealloc_ftruncate(vfs_handle_struct * handle,
@@ -208,7 +210,7 @@ static int prealloc_ftruncate(vfs_handle_struct * handle,
 }
 
 static struct vfs_fn_pointers prealloc_fns = {
-	.open_fn = prealloc_open,
+	.open2_fn = prealloc_open,
 	.ftruncate_fn = prealloc_ftruncate,
 	.connect_fn = prealloc_connect,
 };
-- 
2.4.3


From 46456fcaa2e1ef5842b8771be9a0005e1d2b54e7 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sat, 10 Oct 2015 22:17:40 +0300
Subject: [PATCH 26/35] vfs_preopen: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_preopen.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/source3/modules/vfs_preopen.c b/source3/modules/vfs_preopen.c
index b67aad8..ec8616e 100644
--- a/source3/modules/vfs_preopen.c
+++ b/source3/modules/vfs_preopen.c
@@ -375,34 +375,34 @@ static bool preopen_parse_fname(const char *fname, unsigned long *pnum,
 	return true;
 }
 
-static int preopen_open(vfs_handle_struct *handle,
-			struct smb_filename *smb_fname, files_struct *fsp,
-			int flags, mode_t mode)
+static NTSTATUS preopen_open(vfs_handle_struct *handle,
+			     struct smb_filename *smb_fname, files_struct *fsp,
+			     int flags, mode_t mode)
 {
 	struct preopen_state *state;
-	int res;
+	NTSTATUS status;
 	unsigned long num;
 
 	DEBUG(10, ("preopen_open called on %s\n", smb_fname_str_dbg(smb_fname)));
 
 	state = preopen_state_get(handle);
 	if (state == NULL) {
-		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 	}
 
-	res = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
-	if (res == -1) {
-		return -1;
+	status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
 	}
 
 	if (flags != O_RDONLY) {
-		return res;
+		return status;
 	}
 
 	if (!is_in_path(smb_fname->base_name, state->preopen_names, true)) {
 		DEBUG(10, ("%s does not match the preopen:names list\n",
 			   smb_fname_str_dbg(smb_fname)));
-		return res;
+		return status;
 	}
 
 	TALLOC_FREE(state->template_fname);
@@ -410,13 +410,13 @@ static int preopen_open(vfs_handle_struct *handle,
 		state, "%s/%s", fsp->conn->cwd, smb_fname->base_name);
 
 	if (state->template_fname == NULL) {
-		return res;
+		return status;
 	}
 
 	if (!preopen_parse_fname(state->template_fname, &num,
 				 &state->number_start, &state->num_digits)) {
 		TALLOC_FREE(state->template_fname);
-		return res;
+		return status;
 	}
 
 	if (num > state->fnum_sent) {
@@ -441,11 +441,11 @@ static int preopen_open(vfs_handle_struct *handle,
 
 	preopen_queue_run(state);
 
-	return res;
+	return status;
 }
 
 static struct vfs_fn_pointers vfs_preopen_fns = {
-	.open_fn = preopen_open
+	.open2_fn = preopen_open
 };
 
 NTSTATUS vfs_preopen_init(void);
-- 
2.4.3


From f074b4ca353cb948208a04f39f3fb9dd31565e56 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sat, 10 Oct 2015 22:18:37 +0300
Subject: [PATCH 27/35] vfs_shadow_copy2: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_shadow_copy2.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/source3/modules/vfs_shadow_copy2.c b/source3/modules/vfs_shadow_copy2.c
index 4d2ec54..dc53ae2 100644
--- a/source3/modules/vfs_shadow_copy2.c
+++ b/source3/modules/vfs_shadow_copy2.c
@@ -854,21 +854,21 @@ static int shadow_copy2_fstat(vfs_handle_struct *handle, files_struct *fsp,
 	return 0;
 }
 
-static int shadow_copy2_open(vfs_handle_struct *handle,
-			     struct smb_filename *smb_fname, files_struct *fsp,
-			     int flags, mode_t mode)
+static NTSTATUS shadow_copy2_open(vfs_handle_struct *handle,
+				  struct smb_filename *smb_fname, files_struct *fsp,
+				  int flags, mode_t mode)
 {
 	time_t timestamp;
 	char *stripped, *tmp;
-	int ret, saved_errno;
+	NTSTATUS status;
 
 	if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
 					 smb_fname->base_name,
 					 &timestamp, &stripped)) {
-		return -1;
+		return map_nt_error_from_unix(errno);
 	}
 	if (timestamp == 0) {
-		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 	}
 
 	tmp = smb_fname->base_name;
@@ -878,17 +878,15 @@ static int shadow_copy2_open(vfs_handle_struct *handle,
 
 	if (smb_fname->base_name == NULL) {
 		smb_fname->base_name = tmp;
-		return -1;
+		return map_nt_error_from_unix(errno);
 	}
 
-	ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
-	saved_errno = errno;
+	status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 
 	TALLOC_FREE(smb_fname->base_name);
 	smb_fname->base_name = tmp;
 
-	errno = saved_errno;
-	return ret;
+	return status;
 }
 
 static int shadow_copy2_unlink(vfs_handle_struct *handle,
@@ -2012,7 +2010,7 @@ static struct vfs_fn_pointers vfs_shadow_copy2_fns = {
 	.stat_fn = shadow_copy2_stat,
 	.lstat_fn = shadow_copy2_lstat,
 	.fstat_fn = shadow_copy2_fstat,
-	.open_fn = shadow_copy2_open,
+	.open2_fn = shadow_copy2_open,
 	.unlink_fn = shadow_copy2_unlink,
 	.chmod_fn = shadow_copy2_chmod,
 	.chown_fn = shadow_copy2_chown,
-- 
2.4.3


From 80e5fda1c9c6e6956746fcef38a04f1e384308ad Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sat, 10 Oct 2015 23:31:23 +0300
Subject: [PATCH 28/35] vfs_smb_traffic_analyzer: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_smb_traffic_analyzer.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/source3/modules/vfs_smb_traffic_analyzer.c b/source3/modules/vfs_smb_traffic_analyzer.c
index f5c39ad..8777716 100644
--- a/source3/modules/vfs_smb_traffic_analyzer.c
+++ b/source3/modules/vfs_smb_traffic_analyzer.c
@@ -869,22 +869,24 @@ static ssize_t smb_traffic_analyzer_pwrite(vfs_handle_struct *handle, \
 	return s_data.len;
 }
 
-static int smb_traffic_analyzer_open(vfs_handle_struct *handle, \
+static NTSTATUS smb_traffic_analyzer_open(vfs_handle_struct *handle, \
 	struct smb_filename *smb_fname, files_struct *fsp,\
 	int flags, mode_t mode)
 {
+	NTSTATUS status;
 	struct open_data s_data;
 
-	s_data.result = SMB_VFS_NEXT_OPEN( handle, smb_fname, fsp,
+	status = SMB_VFS_NEXT_OPEN2( handle, smb_fname, fsp,
 			flags, mode);
 	DEBUG(10,("smb_traffic_analyzer_open: OPEN: %s\n",
 		fsp_str_dbg(fsp)));
+	s_data.result = fsp_get_fd(fsp);
 	s_data.filename = fsp->fsp_name->base_name;
 	s_data.mode = mode;
 	smb_traffic_analyzer_send_data(handle,
 			&s_data,
 			vfs_id_open);
-	return s_data.result;
+	return status;
 }
 
 static int smb_traffic_analyzer_close(vfs_handle_struct *handle, \
@@ -911,7 +913,7 @@ static struct vfs_fn_pointers vfs_smb_traffic_analyzer_fns = {
 	.mkdir_fn = smb_traffic_analyzer_mkdir,
 	.rename_fn = smb_traffic_analyzer_rename,
 	.chdir_fn = smb_traffic_analyzer_chdir,
-	.open_fn = smb_traffic_analyzer_open,
+	.open2_fn = smb_traffic_analyzer_open,
 	.rmdir_fn = smb_traffic_analyzer_rmdir,
 	.close_fn = smb_traffic_analyzer_close,
 	.sendfile_fn = smb_traffic_analyzer_sendfile,
-- 
2.4.3


From 6580d97182525b93305d1b47842b3e1507fa7024 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sat, 10 Oct 2015 23:31:25 +0300
Subject: [PATCH 29/35] vfs_snapper: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_snapper.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/source3/modules/vfs_snapper.c b/source3/modules/vfs_snapper.c
index a25ae95..afb7acb 100644
--- a/source3/modules/vfs_snapper.c
+++ b/source3/modules/vfs_snapper.c
@@ -2129,21 +2129,21 @@ static int snapper_gmt_fstat(vfs_handle_struct *handle, files_struct *fsp,
 	return 0;
 }
 
-static int snapper_gmt_open(vfs_handle_struct *handle,
-			    struct smb_filename *smb_fname, files_struct *fsp,
-			    int flags, mode_t mode)
+static NTSTATUS snapper_gmt_open(vfs_handle_struct *handle,
+				 struct smb_filename *smb_fname, files_struct *fsp,
+				 int flags, mode_t mode)
 {
 	time_t timestamp;
 	char *stripped, *tmp;
-	int ret, saved_errno;
+	NTSTATUS status;
 
 	if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
 					smb_fname->base_name,
 					&timestamp, &stripped)) {
-		return -1;
+		return map_nt_error_from_unix(errno);
 	}
 	if (timestamp == 0) {
-		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 	}
 
 	tmp = smb_fname->base_name;
@@ -2156,14 +2156,12 @@ static int snapper_gmt_open(vfs_handle_struct *handle,
 		return -1;
 	}
 
-	ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
-	saved_errno = errno;
+	status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 
 	TALLOC_FREE(smb_fname->base_name);
 	smb_fname->base_name = tmp;
 
-	errno = saved_errno;
-	return ret;
+	return status;
 }
 
 static int snapper_gmt_unlink(vfs_handle_struct *handle,
@@ -2781,7 +2779,7 @@ static struct vfs_fn_pointers snapper_fns = {
 	.stat_fn = snapper_gmt_stat,
 	.lstat_fn = snapper_gmt_lstat,
 	.fstat_fn = snapper_gmt_fstat,
-	.open_fn = snapper_gmt_open,
+	.open2_fn = snapper_gmt_open,
 	.unlink_fn = snapper_gmt_unlink,
 	.chmod_fn = snapper_gmt_chmod,
 	.chown_fn = snapper_gmt_chown,
-- 
2.4.3


From 01e0123dce7f0e63983fcc6561bddb7a7a286f0d Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sat, 10 Oct 2015 23:31:26 +0300
Subject: [PATCH 30/35] vfs_streams_depot: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_streams_depot.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/source3/modules/vfs_streams_depot.c b/source3/modules/vfs_streams_depot.c
index 5964852..435326b 100644
--- a/source3/modules/vfs_streams_depot.c
+++ b/source3/modules/vfs_streams_depot.c
@@ -541,17 +541,17 @@ static int streams_depot_lstat(vfs_handle_struct *handle,
 	return ret;
 }
 
-static int streams_depot_open(vfs_handle_struct *handle,
-			      struct smb_filename *smb_fname,
-			      files_struct *fsp, int flags, mode_t mode)
+static NTSTATUS streams_depot_open(vfs_handle_struct *handle,
+				   struct smb_filename *smb_fname,
+				   files_struct *fsp, int flags, mode_t mode)
 {
 	struct smb_filename *smb_fname_stream = NULL;
 	struct smb_filename *smb_fname_base = NULL;
+	int ret;
 	NTSTATUS status;
-	int ret = -1;
 
 	if (!is_ntfs_stream_smb_fname(smb_fname)) {
-		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 	}
 
 	/* If the default stream is requested, just open the base file. */
@@ -560,40 +560,39 @@ static int streams_depot_open(vfs_handle_struct *handle,
 
 		tmp_stream_name = smb_fname->stream_name;
 		smb_fname->stream_name = NULL;
-		ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+		status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp,
+					   flags, mode);
 		smb_fname->stream_name = tmp_stream_name;
 
-		return ret;
+		return status;
 	}
 
 	/* Ensure the base file still exists. */
 	smb_fname_base = synthetic_smb_fname(
 		talloc_tos(), smb_fname->base_name, NULL, NULL);
 	if (smb_fname_base == NULL) {
-		ret = -1;
-		errno = ENOMEM;
+		status = NT_STATUS_NO_MEMORY;
 		goto done;
 	}
 
 	ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
 	if (ret == -1) {
+		status = map_nt_error_from_unix(errno);
 		goto done;
 	}
 
 	/* Determine the stream name, and then open it. */
 	status = stream_smb_fname(handle, smb_fname, &smb_fname_stream, true);
 	if (!NT_STATUS_IS_OK(status)) {
-		ret = -1;
-		errno = map_errno_from_nt_status(status);
 		goto done;
 	}
 
-	ret = SMB_VFS_NEXT_OPEN(handle, smb_fname_stream, fsp, flags, mode);
+	status = SMB_VFS_NEXT_OPEN2(handle, smb_fname_stream, fsp, flags, mode);
 
  done:
 	TALLOC_FREE(smb_fname_stream);
 	TALLOC_FREE(smb_fname_base);
-	return ret;
+	return status;
 }
 
 static int streams_depot_unlink(vfs_handle_struct *handle,
@@ -919,7 +918,7 @@ static uint32_t streams_depot_fs_capabilities(struct vfs_handle_struct *handle,
 
 static struct vfs_fn_pointers vfs_streams_depot_fns = {
 	.fs_capabilities_fn = streams_depot_fs_capabilities,
-	.open_fn = streams_depot_open,
+	.open2_fn = streams_depot_open,
 	.stat_fn = streams_depot_stat,
 	.lstat_fn = streams_depot_lstat,
 	.unlink_fn = streams_depot_unlink,
-- 
2.4.3


From d7ede77f171cd222e4fb86e0624b979167c52800 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sat, 10 Oct 2015 23:31:26 +0300
Subject: [PATCH 31/35] vfs_syncops: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_syncops.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/source3/modules/vfs_syncops.c b/source3/modules/vfs_syncops.c
index 99f6178..c0607ae 100644
--- a/source3/modules/vfs_syncops.c
+++ b/source3/modules/vfs_syncops.c
@@ -185,6 +185,19 @@ static int syncops_rename(vfs_handle_struct *handle,
 	return ret; \
 } while (0)
 
+#define SYNCOPS_NEXT_SMB_FNAME_NTSTATUS(op, fname, args) do {   \
+	NTSTATUS status; \
+	struct syncops_config_data *config; \
+	SMB_VFS_HANDLE_GET_DATA(handle, config, \
+				struct syncops_config_data, \
+				return NT_STATUS_UNSUCCESSFUL); \
+	status = SMB_VFS_NEXT_ ## op args; \
+	if (!NT_STATUS_IS_OK(status) \
+	&& config->onmeta && !config->disable \
+	&& fname) syncops_smb_fname(fname); \
+	return status; \
+} while (0)
+
 static int syncops_symlink(vfs_handle_struct *handle,
 			   const char *oldname, const char *newname)
 {
@@ -197,11 +210,11 @@ static int syncops_link(vfs_handle_struct *handle,
 	SYNCOPS_NEXT(LINK, newname, (handle, oldname, newname));
 }
 
-static int syncops_open(vfs_handle_struct *handle,
-			struct smb_filename *smb_fname, files_struct *fsp,
-			int flags, mode_t mode)
+static NTSTATUS syncops_open(vfs_handle_struct *handle,
+			     struct smb_filename *smb_fname, files_struct *fsp,
+			     int flags, mode_t mode)
 {
-	SYNCOPS_NEXT_SMB_FNAME(OPEN, (flags&O_CREAT?smb_fname:NULL),
+	SYNCOPS_NEXT_SMB_FNAME_NTSTATUS(OPEN2, (flags&O_CREAT?smb_fname:NULL),
 			       (handle, smb_fname, fsp, flags, mode));
 }
 
@@ -282,7 +295,7 @@ static struct vfs_fn_pointers vfs_syncops_fns = {
 	.connect_fn = syncops_connect,
 	.mkdir_fn = syncops_mkdir,
 	.rmdir_fn = syncops_rmdir,
-	.open_fn = syncops_open,
+	.open2_fn = syncops_open,
 	.rename_fn = syncops_rename,
 	.unlink_fn = syncops_unlink,
 	.symlink_fn = syncops_symlink,
-- 
2.4.3


From 19d4d865a204d1eed8687c3de0032bbac2dcd69d Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sat, 10 Oct 2015 23:31:26 +0300
Subject: [PATCH 32/35] vfs_time_audit: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_time_audit.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/source3/modules/vfs_time_audit.c b/source3/modules/vfs_time_audit.c
index 7efad1e..606e9f2 100644
--- a/source3/modules/vfs_time_audit.c
+++ b/source3/modules/vfs_time_audit.c
@@ -532,17 +532,17 @@ static void smb_time_audit_init_search_op(vfs_handle_struct *handle,
 	}
 }
 
-static int smb_time_audit_open(vfs_handle_struct *handle,
-			       struct smb_filename *fname,
-			       files_struct *fsp,
-			       int flags, mode_t mode)
+static NTSTATUS smb_time_audit_open(vfs_handle_struct *handle,
+				    struct smb_filename *fname,
+				    files_struct *fsp,
+				    int flags, mode_t mode)
 {
-	int result;
+	NTSTATUS status;
 	struct timespec ts1,ts2;
 	double timediff;
 
 	clock_gettime_mono(&ts1);
-	result = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
+	status = SMB_VFS_NEXT_OPEN2(handle, fname, fsp, flags, mode);
 	clock_gettime_mono(&ts2);
 	timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
 
@@ -550,7 +550,7 @@ static int smb_time_audit_open(vfs_handle_struct *handle,
 		smb_time_audit_log_fsp("open", timediff, fsp);
 	}
 
-	return result;
+	return status;
 }
 
 static NTSTATUS smb_time_audit_create_file(vfs_handle_struct *handle,
@@ -2437,7 +2437,7 @@ static struct vfs_fn_pointers vfs_time_audit_fns = {
 	.rmdir_fn = smb_time_audit_rmdir,
 	.closedir_fn = smb_time_audit_closedir,
 	.init_search_op_fn = smb_time_audit_init_search_op,
-	.open_fn = smb_time_audit_open,
+	.open2_fn = smb_time_audit_open,
 	.create_file_fn = smb_time_audit_create_file,
 	.close_fn = smb_time_audit_close,
 	.read_fn = smb_time_audit_read,
-- 
2.4.3


From 9b780b8adccea3428348462204a122b2d62d141b Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Sat, 10 Oct 2015 23:31:26 +0300
Subject: [PATCH 33/35] vfs_unityed_media: migrate open to new signature

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_unityed_media.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/source3/modules/vfs_unityed_media.c b/source3/modules/vfs_unityed_media.c
index b4d7dc0..a811245 100644
--- a/source3/modules/vfs_unityed_media.c
+++ b/source3/modules/vfs_unityed_media.c
@@ -845,26 +845,26 @@ static void um_init_search_op(vfs_handle_struct *handle,
 				    ((um_dirinfo_struct*)dirp)->dirstream);
 }
 
-static int um_open(vfs_handle_struct *handle,
-		   struct smb_filename *smb_fname,
-		   files_struct *fsp,
-		   int flags,
-		   mode_t mode)
+static NTSTATUS um_open(vfs_handle_struct *handle,
+			struct smb_filename *smb_fname,
+			files_struct *fsp,
+			int flags,
+			mode_t mode)
 {
-	int ret;
+	NTSTATUS status;
 	struct smb_filename *client_fname = NULL;
 
 	DEBUG(10, ("Entering with smb_fname->base_name '%s'\n",
 			      smb_fname->base_name));
 
 	if (!is_in_media_files(smb_fname->base_name)) {
-		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
 	}
 
 	if (alloc_get_client_smb_fname(handle, talloc_tos(),
 				       smb_fname,
 				       &client_fname)) {
-		ret = -1;
+		status = map_nt_error_from_unix(errno);
 		goto err;
 	}
 
@@ -881,12 +881,12 @@ static int um_open(vfs_handle_struct *handle,
 			      ctime(&(smb_fname->st.st_ex_mtime.tv_sec)),
 			      ctime(&(fsp->fsp_name->st.st_ex_mtime.tv_sec))));
 
-	ret = SMB_VFS_NEXT_OPEN(handle, client_fname, fsp, flags, mode);
+	status = SMB_VFS_NEXT_OPEN2(handle, client_fname, fsp, flags, mode);
 err:
 	TALLOC_FREE(client_fname);
 	DEBUG(10, ("Leaving with smb_fname->base_name '%s'\n",
 			      smb_fname->base_name));
-	return ret;
+	return status;
 }
 
 static NTSTATUS um_create_file(vfs_handle_struct *handle,
@@ -1887,7 +1887,7 @@ static struct vfs_fn_pointers vfs_um_fns = {
 
 	/* File operations */
 
-	.open_fn = um_open,
+	.open2_fn = um_open,
 	.create_file_fn = um_create_file,
 	.rename_fn = um_rename,
 	.stat_fn = um_stat,
-- 
2.4.3


From 11f57438ee599b90c91b84451ab1b9684a067bf5 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Wed, 28 Oct 2015 20:59:11 +0200
Subject: [PATCH 34/35] vfs: remove old open_fn

Remove the open_fn operation which returns an fd and sets errno.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/include/vfs.h        |  3 ---
 source3/include/vfs_macros.h |  4 ----
 source3/smbd/vfs.c           | 42 ++----------------------------------------
 3 files changed, 2 insertions(+), 47 deletions(-)

diff --git a/source3/include/vfs.h b/source3/include/vfs.h
index 3f11dc1..d3c94b4 100644
--- a/source3/include/vfs.h
+++ b/source3/include/vfs.h
@@ -542,9 +542,6 @@ struct vfs_fn_pointers {
 
 	/* File operations */
 
-	int (*open_fn)(struct vfs_handle_struct *handle,
-		       struct smb_filename *smb_fname, files_struct *fsp,
-		       int flags, mode_t mode);
 	NTSTATUS (*open2_fn)(struct vfs_handle_struct *handle,
 			     struct smb_filename *smb_fname, files_struct *fsp,
 			     int flags, mode_t mode);
diff --git a/source3/include/vfs_macros.h b/source3/include/vfs_macros.h
index bbc130b..c26d73e 100644
--- a/source3/include/vfs_macros.h
+++ b/source3/include/vfs_macros.h
@@ -130,10 +130,6 @@
 	smb_vfs_call_init_search_op((handle)->next, (dirp))
 
 /* File operations */
-#define SMB_VFS_OPEN(conn, fname, fsp, flags, mode) \
-	smb_vfs_call_open((conn)->vfs_handles, (fname), (fsp), (flags), (mode))
-#define SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode) \
-	smb_vfs_call_open((handle)->next, (fname), (fsp), (flags), (mode))
 #define SMB_VFS_OPEN2(conn, fname, fsp, flags, mode) \
 	smb_vfs_call_open2((conn)->vfs_handles, (fname), (fsp), (flags), (mode))
 #define SMB_VFS_NEXT_OPEN2(handle, fname, fsp, flags, mode) \
diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c
index 006359a..2768130 100644
--- a/source3/smbd/vfs.c
+++ b/source3/smbd/vfs.c
@@ -1489,50 +1489,12 @@ void smb_vfs_call_init_search_op(struct vfs_handle_struct *handle,
 	handle->fns->init_search_op_fn(handle, dirp);
 }
 
-int smb_vfs_call_open(struct vfs_handle_struct *handle,
-		      struct smb_filename *smb_fname, struct files_struct *fsp,
-		      int flags, mode_t mode)
-{
-	while (true) {
-		if (handle->fns->open2_fn) {
-			NTSTATUS status = handle->fns->open2_fn(
-			    handle, smb_fname, fsp, flags, mode);
-			if (!NT_STATUS_IS_OK(status)) {
-				errno = map_errno_from_nt_status(status);
-			}
-
-			return fsp->fh->fd;
-		} else if (handle->fns->open_fn) {
-			return handle->fns->open_fn(handle, smb_fname, fsp,
-						    flags, mode);
-		}
-
-		handle = handle->next;
-	}
-}
-
 NTSTATUS smb_vfs_call_open2(struct vfs_handle_struct *handle,
 			   struct smb_filename *smb_fname,
 			   struct files_struct *fsp, int flags, mode_t mode)
 {
-	while (true) {
-		if (handle->fns->open2_fn) {
-			return handle->fns->open2_fn(handle, smb_fname, fsp,
-						     flags, mode);
-		} else if (handle->fns->open_fn) {
-			NTSTATUS status = NT_STATUS_OK;
-			int hostfd = handle->fns->open_fn(handle, smb_fname,
-							  fsp, flags, mode);
-			fsp_assign_fd(fsp,hostfd);
-			if (hostfd == -1) {
-				status = map_nt_open_error_from_unix(errno);
-			}
-
-			return status;
-		}
-
-		handle = handle->next;
-	}
+	VFS_FIND(open2);
+	return handle->fns->open2_fn(handle, smb_fname, fsp, flags, mode);
 }
 
 NTSTATUS smb_vfs_call_create_file(struct vfs_handle_struct *handle,
-- 
2.4.3


From dc789a298eb27c825b6f9487391e22809ed749c7 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Wed, 28 Oct 2015 21:59:37 +0200
Subject: [PATCH 35/35] Massive rename open2 -> open

This completes the change of VFS open signature. Now
that all the code uses the new open2_fn signature and open_fn
is deleted, we can rename open2_fn back to the original name.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 examples/VFS/skel_opaque.c                 |  2 +-
 examples/VFS/skel_transparent.c            |  4 ++--
 source3/include/vfs.h                      |  4 ++--
 source3/include/vfs_macros.h               |  8 ++++----
 source3/modules/vfs_aio_pthread.c          |  2 +-
 source3/modules/vfs_audit.c                |  4 ++--
 source3/modules/vfs_cap.c                  |  4 ++--
 source3/modules/vfs_catia.c                |  4 ++--
 source3/modules/vfs_ceph.c                 |  2 +-
 source3/modules/vfs_commit.c               |  6 +++---
 source3/modules/vfs_default.c              |  2 +-
 source3/modules/vfs_extd_audit.c           |  4 ++--
 source3/modules/vfs_fruit.c                | 16 ++++++++--------
 source3/modules/vfs_full_audit.c           |  4 ++--
 source3/modules/vfs_glusterfs.c            |  2 +-
 source3/modules/vfs_gpfs.c                 |  4 ++--
 source3/modules/vfs_media_harmony.c        |  6 +++---
 source3/modules/vfs_prealloc.c             |  6 +++---
 source3/modules/vfs_preopen.c              |  6 +++---
 source3/modules/vfs_shadow_copy2.c         |  6 +++---
 source3/modules/vfs_smb_traffic_analyzer.c |  4 ++--
 source3/modules/vfs_snapper.c              |  6 +++---
 source3/modules/vfs_streams_depot.c        |  8 ++++----
 source3/modules/vfs_streams_xattr.c        | 10 +++++-----
 source3/modules/vfs_syncops.c              |  2 +-
 source3/modules/vfs_time_audit.c           |  4 ++--
 source3/modules/vfs_unityed_media.c        |  6 +++---
 source3/smbd/open.c                        |  2 +-
 source3/smbd/pysmbd.c                      |  4 ++--
 source3/smbd/vfs.c                         |  6 +++---
 source3/torture/cmd_vfs.c                  |  6 +++---
 31 files changed, 77 insertions(+), 77 deletions(-)

diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c
index 477bea0..00490b6 100644
--- a/examples/VFS/skel_opaque.c
+++ b/examples/VFS/skel_opaque.c
@@ -863,7 +863,7 @@ struct vfs_fn_pointers skel_opaque_fns = {
 
 	/* File operations */
 
-	.open2_fn = skel_open,
+	.open_fn = skel_open,
 	.create_file_fn = skel_create_file,
 	.close_fn = skel_close_fn,
 	.read_fn = skel_vfs_read,
diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c
index ae8d0d9..e46e1c4 100644
--- a/examples/VFS/skel_transparent.c
+++ b/examples/VFS/skel_transparent.c
@@ -180,7 +180,7 @@ static NTSTATUS skel_open(vfs_handle_struct *handle,
 			  struct smb_filename *smb_fname, files_struct *fsp,
 			  int flags, mode_t mode)
 {
-	return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 }
 
 static NTSTATUS skel_create_file(struct vfs_handle_struct *handle,
@@ -973,7 +973,7 @@ struct vfs_fn_pointers skel_transparent_fns = {
 
 	/* File operations */
 
-	.open2_fn = skel_open,
+	.open_fn = skel_open,
 	.create_file_fn = skel_create_file,
 	.close_fn = skel_close_fn,
 	.read_fn = skel_vfs_read,
diff --git a/source3/include/vfs.h b/source3/include/vfs.h
index d3c94b4..5efe40c 100644
--- a/source3/include/vfs.h
+++ b/source3/include/vfs.h
@@ -542,7 +542,7 @@ struct vfs_fn_pointers {
 
 	/* File operations */
 
-	NTSTATUS (*open2_fn)(struct vfs_handle_struct *handle,
+	NTSTATUS (*open_fn)(struct vfs_handle_struct *handle,
 			     struct smb_filename *smb_fname, files_struct *fsp,
 			     int flags, mode_t mode);
 	NTSTATUS (*create_file_fn)(struct vfs_handle_struct *handle,
@@ -962,7 +962,7 @@ void smb_vfs_call_init_search_op(struct vfs_handle_struct *handle,
 int smb_vfs_call_open(struct vfs_handle_struct *handle,
 		      struct smb_filename *smb_fname, struct files_struct *fsp,
 		      int flags, mode_t mode);
-NTSTATUS smb_vfs_call_open2(struct vfs_handle_struct *handle,
+NTSTATUS smb_vfs_call_open(struct vfs_handle_struct *handle,
 			   struct smb_filename *smb_fname,
 			   struct files_struct *fsp, int flags, mode_t mode);
 NTSTATUS smb_vfs_call_create_file(struct vfs_handle_struct *handle,
diff --git a/source3/include/vfs_macros.h b/source3/include/vfs_macros.h
index c26d73e..eaf0c19 100644
--- a/source3/include/vfs_macros.h
+++ b/source3/include/vfs_macros.h
@@ -130,10 +130,10 @@
 	smb_vfs_call_init_search_op((handle)->next, (dirp))
 
 /* File operations */
-#define SMB_VFS_OPEN2(conn, fname, fsp, flags, mode) \
-	smb_vfs_call_open2((conn)->vfs_handles, (fname), (fsp), (flags), (mode))
-#define SMB_VFS_NEXT_OPEN2(handle, fname, fsp, flags, mode) \
-	smb_vfs_call_open2((handle)->next, (fname), (fsp), (flags), (mode))
+#define SMB_VFS_OPEN(conn, fname, fsp, flags, mode) \
+	smb_vfs_call_open((conn)->vfs_handles, (fname), (fsp), (flags), (mode))
+#define SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode) \
+	smb_vfs_call_open((handle)->next, (fname), (fsp), (flags), (mode))
 
 #define SMB_VFS_CREATE_FILE(conn, req, root_dir_fid, smb_fname, access_mask, share_access, create_disposition, \
         create_options, file_attributes, oplock_request, lease, allocation_size, private_flags, sd, ea_list, result, pinfo, in_context_blobs, out_context_blobs) \
diff --git a/source3/modules/vfs_aio_pthread.c b/source3/modules/vfs_aio_pthread.c
index 6818c4e..d5ee525 100644
--- a/source3/modules/vfs_aio_pthread.c
+++ b/source3/modules/vfs_aio_pthread.c
@@ -503,7 +503,7 @@ out:
 
 static struct vfs_fn_pointers vfs_aio_pthread_fns = {
 #if defined(HAVE_OPENAT) && defined(USE_LINUX_THREAD_CREDENTIALS)
-	.open2_fn = aio_pthread_open_fn,
+	.open_fn = aio_pthread_open_fn,
 #endif
 };
 
diff --git a/source3/modules/vfs_audit.c b/source3/modules/vfs_audit.c
index 1425c16..46d64de 100644
--- a/source3/modules/vfs_audit.c
+++ b/source3/modules/vfs_audit.c
@@ -154,7 +154,7 @@ static NTSTATUS audit_open(vfs_handle_struct *handle,
 {
 	NTSTATUS result;
 
-	result = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 
 	syslog(audit_syslog_priority(handle), "open %s (fd %d) %s%s%s\n", 
 	       smb_fname->base_name, fsp_get_fd(fsp),
@@ -273,7 +273,7 @@ static struct vfs_fn_pointers vfs_audit_fns = {
 	.opendir_fn = audit_opendir,
 	.mkdir_fn = audit_mkdir,
 	.rmdir_fn = audit_rmdir,
-	.open2_fn = audit_open,
+	.open_fn = audit_open,
 	.close_fn = audit_close,
 	.rename_fn = audit_rename,
 	.unlink_fn = audit_unlink,
diff --git a/source3/modules/vfs_cap.c b/source3/modules/vfs_cap.c
index 273487b..e6d8bfc 100644
--- a/source3/modules/vfs_cap.c
+++ b/source3/modules/vfs_cap.c
@@ -125,7 +125,7 @@ static NTSTATUS cap_open(vfs_handle_struct *handle,
 	smb_fname->base_name = cappath;
 
 	DEBUG(3,("cap: cap_open for %s\n", smb_fname_str_dbg(smb_fname)));
-	ret = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 
 	smb_fname->base_name = tmp_base_name;
 	TALLOC_FREE(cappath);
@@ -521,7 +521,7 @@ static struct vfs_fn_pointers vfs_cap_fns = {
 	.readdir_fn = cap_readdir,
 	.mkdir_fn = cap_mkdir,
 	.rmdir_fn = cap_rmdir,
-	.open2_fn = cap_open,
+	.open_fn = cap_open,
 	.rename_fn = cap_rename,
 	.stat_fn = cap_stat,
 	.lstat_fn = cap_lstat,
diff --git a/source3/modules/vfs_catia.c b/source3/modules/vfs_catia.c
index 2656f01..98b0e1c 100644
--- a/source3/modules/vfs_catia.c
+++ b/source3/modules/vfs_catia.c
@@ -356,7 +356,7 @@ static NTSTATUS catia_open(vfs_handle_struct *handle,
 	}
 
 	smb_fname->base_name = name_mapped;
-	status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	status = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 	smb_fname->base_name = tmp_base_name;
 	TALLOC_FREE(name_mapped);
 
@@ -978,7 +978,7 @@ static struct vfs_fn_pointers vfs_catia_fns = {
 	.mkdir_fn = catia_mkdir,
 	.rmdir_fn = catia_rmdir,
 	.opendir_fn = catia_opendir,
-	.open2_fn = catia_open,
+	.open_fn = catia_open,
 	.rename_fn = catia_rename,
 	.stat_fn = catia_stat,
 	.lstat_fn = catia_lstat,
diff --git a/source3/modules/vfs_ceph.c b/source3/modules/vfs_ceph.c
index 1639093..a260bee 100644
--- a/source3/modules/vfs_ceph.c
+++ b/source3/modules/vfs_ceph.c
@@ -1258,7 +1258,7 @@ static struct vfs_fn_pointers ceph_fns = {
 
 	/* File operations */
 
-	.open2_fn = cephwrap_open,
+	.open_fn = cephwrap_open,
 	.close_fn = cephwrap_close,
 	.read_fn = cephwrap_read,
 	.pread_fn = cephwrap_pread,
diff --git a/source3/modules/vfs_commit.c b/source3/modules/vfs_commit.c
index 42b2286..b92eec1 100644
--- a/source3/modules/vfs_commit.c
+++ b/source3/modules/vfs_commit.c
@@ -191,7 +191,7 @@ static NTSTATUS commit_open(
 
         /* Don't bother with read-only files. */
         if ((flags & O_ACCMODE) == O_RDONLY) {
-                return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+                return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
         }
 
         /* Read and check module configuration */
@@ -221,7 +221,7 @@ static NTSTATUS commit_open(
                 }
         }
 
-        status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+        status = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 	if (!NT_STATUS_IS_OK(status)) {
 		VFS_REMOVE_FSP_EXTENSION(handle, fsp);
 		return status;
@@ -383,7 +383,7 @@ static int commit_ftruncate(
 }
 
 static struct vfs_fn_pointers vfs_commit_fns = {
-        .open2_fn = commit_open,
+        .open_fn = commit_open,
         .close_fn = commit_close,
         .write_fn = commit_write,
         .pwrite_fn = commit_pwrite,
diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index 9f2744d..e1cc7cc 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -2591,7 +2591,7 @@ static struct vfs_fn_pointers vfs_default_fns = {
 
 	/* File operations */
 
-	.open2_fn = vfswrap_open,
+	.open_fn = vfswrap_open,
 	.create_file_fn = vfswrap_create_file,
 	.close_fn = vfswrap_close,
 	.read_fn = vfswrap_read,
diff --git a/source3/modules/vfs_extd_audit.c b/source3/modules/vfs_extd_audit.c
index 2ad9b34..3e9e837 100644
--- a/source3/modules/vfs_extd_audit.c
+++ b/source3/modules/vfs_extd_audit.c
@@ -182,7 +182,7 @@ static NTSTATUS  audit_open(vfs_handle_struct *handle,
 {
 	NTSTATUS result;
 
-	result = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 
 	if (lp_syslog() > 0) {
 		syslog(audit_syslog_priority(handle), "open %s (fd %d) %s%s%s\n",
@@ -350,7 +350,7 @@ static struct vfs_fn_pointers vfs_extd_audit_fns = {
 	.opendir_fn = audit_opendir,
 	.mkdir_fn = audit_mkdir,
 	.rmdir_fn = audit_rmdir,
-	.open2_fn = audit_open,
+	.open_fn = audit_open,
 	.close_fn = audit_close,
 	.rename_fn = audit_rename,
 	.unlink_fn = audit_unlink,
diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c
index d566ada..f1ba821 100644
--- a/source3/modules/vfs_fruit.c
+++ b/source3/modules/vfs_fruit.c
@@ -2123,7 +2123,7 @@ static NTSTATUS fruit_open_meta(vfs_handle_struct *handle,
 				return NT_STATUS_UNSUCCESSFUL);
 
 	if (config->meta == FRUIT_META_STREAM) {
-		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 	}
 
 	/* Create an smb_filename with stream_name == NULL. */
@@ -2144,7 +2144,7 @@ static NTSTATUS fruit_open_meta(vfs_handle_struct *handle,
 	baseflags &= ~O_EXCL;
 	baseflags &= ~O_CREAT;
 
-	status = SMB_VFS_OPEN2(handle->conn, smb_fname_base, fsp,
+	status = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
 			      baseflags, mode);
 
 	/*
@@ -2154,7 +2154,7 @@ static NTSTATUS fruit_open_meta(vfs_handle_struct *handle,
 	if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) {
 		baseflags &= ~O_ACCMODE;
 		baseflags |= O_RDONLY;
-		status = SMB_VFS_OPEN2(handle->conn, smb_fname_base, fsp,
+		status = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
 				      baseflags, mode);
 	}
 
@@ -2227,7 +2227,7 @@ static NTSTATUS fruit_open_rsrc(vfs_handle_struct *handle,
 
 	switch (config->rsrc) {
 	case FRUIT_RSRC_STREAM:
-		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 	case FRUIT_RSRC_XATTR:
 #ifdef HAVE_ATTROPEN
 		hostfd = attropen(smb_fname->base_name,
@@ -2285,7 +2285,7 @@ static NTSTATUS fruit_open_rsrc(vfs_handle_struct *handle,
 		flags |= O_RDWR;
 	}
 
-	status = SMB_VFS_OPEN2(handle->conn, smb_fname_base, fsp,
+	status = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
 			      flags, mode);
 	if (!NT_STATUS_IS_OK(status)) {
 		goto exit;
@@ -2340,7 +2340,7 @@ static NTSTATUS fruit_open(vfs_handle_struct *handle,
 		   smb_fname_str_dbg(smb_fname)));
 
 	if (!is_ntfs_stream_smb_fname(smb_fname)) {
-		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 	}
 
 	if (is_afpinfo_stream(smb_fname)) {
@@ -2349,7 +2349,7 @@ static NTSTATUS fruit_open(vfs_handle_struct *handle,
 		return fruit_open_rsrc(handle, smb_fname, fsp, flags, mode);
 	}
 
-	return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 }
 
 static int fruit_rename(struct vfs_handle_struct *handle,
@@ -3812,7 +3812,7 @@ static struct vfs_fn_pointers vfs_fruit_fns = {
 	.unlink_fn = fruit_unlink,
 	.rename_fn = fruit_rename,
 	.rmdir_fn = fruit_rmdir,
-	.open2_fn = fruit_open,
+	.open_fn = fruit_open,
 	.pread_fn = fruit_pread,
 	.pwrite_fn = fruit_pwrite,
 	.stat_fn = fruit_stat,
diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c
index d07ce43..b8ce719 100644
--- a/source3/modules/vfs_full_audit.c
+++ b/source3/modules/vfs_full_audit.c
@@ -893,7 +893,7 @@ static NTSTATUS smb_full_audit_open(vfs_handle_struct *handle,
 {
 	NTSTATUS result;
 	
-	result = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	result = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 
 	do_log(SMB_VFS_OP_OPEN, NT_STATUS_IS_OK(result), handle, "%s|%s",
 	       ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r",
@@ -2240,7 +2240,7 @@ static struct vfs_fn_pointers vfs_full_audit_fns = {
 	.rmdir_fn = smb_full_audit_rmdir,
 	.closedir_fn = smb_full_audit_closedir,
 	.init_search_op_fn = smb_full_audit_init_search_op,
-	.open2_fn = smb_full_audit_open,
+	.open_fn = smb_full_audit_open,
 	.create_file_fn = smb_full_audit_create_file,
 	.close_fn = smb_full_audit_close,
 	.read_fn = smb_full_audit_read,
diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c
index 1dd1d3f..7a103f6 100644
--- a/source3/modules/vfs_glusterfs.c
+++ b/source3/modules/vfs_glusterfs.c
@@ -1706,7 +1706,7 @@ static struct vfs_fn_pointers glusterfs_fns = {
 
 	/* File Operations */
 
-	.open2_fn = vfs_gluster_open,
+	.open_fn = vfs_gluster_open,
 	.create_file_fn = NULL,
 	.close_fn = vfs_gluster_close,
 	.read_fn = vfs_gluster_read,
diff --git a/source3/modules/vfs_gpfs.c b/source3/modules/vfs_gpfs.c
index 949f9f6..1695af3 100644
--- a/source3/modules/vfs_gpfs.c
+++ b/source3/modules/vfs_gpfs.c
@@ -2259,7 +2259,7 @@ static int vfs_gpfs_open(struct vfs_handle_struct *handle,
 	 */
 	*ext = (struct gpfs_fsp_extension) { .offline = true };
 
-	status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	status = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 	if (!NT_STATUS_OK(status)) {
 		VFS_REMOVE_FSP_EXTENSION(handle, fsp);
 	}
@@ -2470,7 +2470,7 @@ static struct vfs_fn_pointers vfs_gpfs_fns = {
 	.aio_force_fn = vfs_gpfs_aio_force,
 	.sendfile_fn = vfs_gpfs_sendfile,
 	.fallocate_fn = vfs_gpfs_fallocate,
-	.open2_fn = vfs_gpfs_open,
+	.open_fn = vfs_gpfs_open,
 	.pread_fn = vfs_gpfs_pread,
 	.pread_send_fn = vfs_gpfs_pread_send,
 	.pread_recv_fn = vfs_gpfs_pread_recv,
diff --git a/source3/modules/vfs_media_harmony.c b/source3/modules/vfs_media_harmony.c
index e8fb7b0..d38d98e 100644
--- a/source3/modules/vfs_media_harmony.c
+++ b/source3/modules/vfs_media_harmony.c
@@ -1154,7 +1154,7 @@ static NTSTATUS mh_open(vfs_handle_struct *handle,
 
 	if (!is_in_media_files(smb_fname->base_name))
 	{
-		status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags,
+		status = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags,
 					   mode);
 		goto out;
 	}
@@ -1181,7 +1181,7 @@ static NTSTATUS mh_open(vfs_handle_struct *handle,
 			ctime(&(smb_fname->st.st_ex_mtime.tv_sec)),
 			ctime(&(fsp->fsp_name->st.st_ex_mtime.tv_sec))));
 
-	status = SMB_VFS_NEXT_OPEN2(handle, clientFname, fsp, flags, mode);
+	status = SMB_VFS_NEXT_OPEN(handle, clientFname, fsp, flags, mode);
 err:
 	TALLOC_FREE(clientFname);
 out:
@@ -2457,7 +2457,7 @@ static struct vfs_fn_pointers vfs_mh_fns = {
 
 	/* File operations */
 
-	.open2_fn = mh_open,
+	.open_fn = mh_open,
 	.create_file_fn = mh_create_file,
 	.rename_fn = mh_rename,
 	.stat_fn = mh_stat,
diff --git a/source3/modules/vfs_prealloc.c b/source3/modules/vfs_prealloc.c
index df613ba..d89ad19 100644
--- a/source3/modules/vfs_prealloc.c
+++ b/source3/modules/vfs_prealloc.c
@@ -154,7 +154,7 @@ static NTSTATUS prealloc_open(vfs_handle_struct* handle,
 		goto normal_open;
 	}
 
-	status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	status = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 	if (!NT_STATUS_OK(status)) {
 		return status;
 	}
@@ -191,7 +191,7 @@ normal_open:
 	 */
 	DEBUG(module_debug, ("%s: skipping preallocation for %s\n",
 		MODULE, smb_fname_str_dbg(smb_fname)));
-	return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 }
 
 static int prealloc_ftruncate(vfs_handle_struct * handle,
@@ -210,7 +210,7 @@ static int prealloc_ftruncate(vfs_handle_struct * handle,
 }
 
 static struct vfs_fn_pointers prealloc_fns = {
-	.open2_fn = prealloc_open,
+	.open_fn = prealloc_open,
 	.ftruncate_fn = prealloc_ftruncate,
 	.connect_fn = prealloc_connect,
 };
diff --git a/source3/modules/vfs_preopen.c b/source3/modules/vfs_preopen.c
index ec8616e..60bf2cb 100644
--- a/source3/modules/vfs_preopen.c
+++ b/source3/modules/vfs_preopen.c
@@ -387,10 +387,10 @@ static NTSTATUS preopen_open(vfs_handle_struct *handle,
 
 	state = preopen_state_get(handle);
 	if (state == NULL) {
-		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 	}
 
-	status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	status = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 	if (!NT_STATUS_IS_OK(status)) {
 		return status;
 	}
@@ -445,7 +445,7 @@ static NTSTATUS preopen_open(vfs_handle_struct *handle,
 }
 
 static struct vfs_fn_pointers vfs_preopen_fns = {
-	.open2_fn = preopen_open
+	.open_fn = preopen_open
 };
 
 NTSTATUS vfs_preopen_init(void);
diff --git a/source3/modules/vfs_shadow_copy2.c b/source3/modules/vfs_shadow_copy2.c
index dc53ae2..f0b0f84 100644
--- a/source3/modules/vfs_shadow_copy2.c
+++ b/source3/modules/vfs_shadow_copy2.c
@@ -868,7 +868,7 @@ static NTSTATUS shadow_copy2_open(vfs_handle_struct *handle,
 		return map_nt_error_from_unix(errno);
 	}
 	if (timestamp == 0) {
-		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 	}
 
 	tmp = smb_fname->base_name;
@@ -881,7 +881,7 @@ static NTSTATUS shadow_copy2_open(vfs_handle_struct *handle,
 		return map_nt_error_from_unix(errno);
 	}
 
-	status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	status = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 
 	TALLOC_FREE(smb_fname->base_name);
 	smb_fname->base_name = tmp;
@@ -2010,7 +2010,7 @@ static struct vfs_fn_pointers vfs_shadow_copy2_fns = {
 	.stat_fn = shadow_copy2_stat,
 	.lstat_fn = shadow_copy2_lstat,
 	.fstat_fn = shadow_copy2_fstat,
-	.open2_fn = shadow_copy2_open,
+	.open_fn = shadow_copy2_open,
 	.unlink_fn = shadow_copy2_unlink,
 	.chmod_fn = shadow_copy2_chmod,
 	.chown_fn = shadow_copy2_chown,
diff --git a/source3/modules/vfs_smb_traffic_analyzer.c b/source3/modules/vfs_smb_traffic_analyzer.c
index 8777716..322a512 100644
--- a/source3/modules/vfs_smb_traffic_analyzer.c
+++ b/source3/modules/vfs_smb_traffic_analyzer.c
@@ -876,7 +876,7 @@ static NTSTATUS smb_traffic_analyzer_open(vfs_handle_struct *handle, \
 	NTSTATUS status;
 	struct open_data s_data;
 
-	status = SMB_VFS_NEXT_OPEN2( handle, smb_fname, fsp,
+	status = SMB_VFS_NEXT_OPEN( handle, smb_fname, fsp,
 			flags, mode);
 	DEBUG(10,("smb_traffic_analyzer_open: OPEN: %s\n",
 		fsp_str_dbg(fsp)));
@@ -913,7 +913,7 @@ static struct vfs_fn_pointers vfs_smb_traffic_analyzer_fns = {
 	.mkdir_fn = smb_traffic_analyzer_mkdir,
 	.rename_fn = smb_traffic_analyzer_rename,
 	.chdir_fn = smb_traffic_analyzer_chdir,
-	.open2_fn = smb_traffic_analyzer_open,
+	.open_fn = smb_traffic_analyzer_open,
 	.rmdir_fn = smb_traffic_analyzer_rmdir,
 	.close_fn = smb_traffic_analyzer_close,
 	.sendfile_fn = smb_traffic_analyzer_sendfile,
diff --git a/source3/modules/vfs_snapper.c b/source3/modules/vfs_snapper.c
index afb7acb..e0de753 100644
--- a/source3/modules/vfs_snapper.c
+++ b/source3/modules/vfs_snapper.c
@@ -2143,7 +2143,7 @@ static NTSTATUS snapper_gmt_open(vfs_handle_struct *handle,
 		return map_nt_error_from_unix(errno);
 	}
 	if (timestamp == 0) {
-		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 	}
 
 	tmp = smb_fname->base_name;
@@ -2156,7 +2156,7 @@ static NTSTATUS snapper_gmt_open(vfs_handle_struct *handle,
 		return -1;
 	}
 
-	status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+	status = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 
 	TALLOC_FREE(smb_fname->base_name);
 	smb_fname->base_name = tmp;
@@ -2779,7 +2779,7 @@ static struct vfs_fn_pointers snapper_fns = {
 	.stat_fn = snapper_gmt_stat,
 	.lstat_fn = snapper_gmt_lstat,
 	.fstat_fn = snapper_gmt_fstat,
-	.open2_fn = snapper_gmt_open,
+	.open_fn = snapper_gmt_open,
 	.unlink_fn = snapper_gmt_unlink,
 	.chmod_fn = snapper_gmt_chmod,
 	.chown_fn = snapper_gmt_chown,
diff --git a/source3/modules/vfs_streams_depot.c b/source3/modules/vfs_streams_depot.c
index 435326b..18e8984 100644
--- a/source3/modules/vfs_streams_depot.c
+++ b/source3/modules/vfs_streams_depot.c
@@ -551,7 +551,7 @@ static NTSTATUS streams_depot_open(vfs_handle_struct *handle,
 	NTSTATUS status;
 
 	if (!is_ntfs_stream_smb_fname(smb_fname)) {
-		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 	}
 
 	/* If the default stream is requested, just open the base file. */
@@ -560,7 +560,7 @@ static NTSTATUS streams_depot_open(vfs_handle_struct *handle,
 
 		tmp_stream_name = smb_fname->stream_name;
 		smb_fname->stream_name = NULL;
-		status = SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp,
+		status = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp,
 					   flags, mode);
 		smb_fname->stream_name = tmp_stream_name;
 
@@ -587,7 +587,7 @@ static NTSTATUS streams_depot_open(vfs_handle_struct *handle,
 		goto done;
 	}
 
-	status = SMB_VFS_NEXT_OPEN2(handle, smb_fname_stream, fsp, flags, mode);
+	status = SMB_VFS_NEXT_OPEN(handle, smb_fname_stream, fsp, flags, mode);
 
  done:
 	TALLOC_FREE(smb_fname_stream);
@@ -918,7 +918,7 @@ static uint32_t streams_depot_fs_capabilities(struct vfs_handle_struct *handle,
 
 static struct vfs_fn_pointers vfs_streams_depot_fns = {
 	.fs_capabilities_fn = streams_depot_fs_capabilities,
-	.open2_fn = streams_depot_open,
+	.open_fn = streams_depot_open,
 	.stat_fn = streams_depot_stat,
 	.lstat_fn = streams_depot_lstat,
 	.unlink_fn = streams_depot_unlink,
diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c
index d6fec39..3be4a87 100644
--- a/source3/modules/vfs_streams_xattr.c
+++ b/source3/modules/vfs_streams_xattr.c
@@ -400,7 +400,7 @@ static NTSTATUS streams_xattr_open(vfs_handle_struct *handle,
 		   smb_fname_str_dbg(smb_fname), flags));
 
 	if (!is_ntfs_stream_smb_fname(smb_fname)) {
-		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 	}
 
 	/* If the default stream is requested, just open the base file. */
@@ -411,7 +411,7 @@ static NTSTATUS streams_xattr_open(vfs_handle_struct *handle,
 		smb_fname->stream_name = NULL;
 
 		status =
-		    SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+		    SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 
 		smb_fname->stream_name = tmp_stream_name;
 
@@ -442,7 +442,7 @@ static NTSTATUS streams_xattr_open(vfs_handle_struct *handle,
         baseflags &= ~O_CREAT;
 
 	status =
-	    SMB_VFS_OPEN2(handle->conn, smb_fname_base, fsp, baseflags, mode);
+	    SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp, baseflags, mode);
 
 	TALLOC_FREE(smb_fname_base);
 
@@ -452,7 +452,7 @@ static NTSTATUS streams_xattr_open(vfs_handle_struct *handle,
 	if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) {
 		baseflags &= ~O_ACCMODE;
 		baseflags |= O_RDONLY;
-		status = SMB_VFS_OPEN2(handle->conn, smb_fname, fsp, baseflags,
+		status = SMB_VFS_OPEN(handle->conn, smb_fname, fsp, baseflags,
 				       mode);
 	}
 
@@ -1128,7 +1128,7 @@ static int streams_xattr_fallocate(struct vfs_handle_struct *handle,
 static struct vfs_fn_pointers vfs_streams_xattr_fns = {
 	.fs_capabilities_fn = streams_xattr_fs_capabilities,
 	.connect_fn = streams_xattr_connect,
-	.open2_fn = streams_xattr_open,
+	.open_fn = streams_xattr_open,
 	.stat_fn = streams_xattr_stat,
 	.fstat_fn = streams_xattr_fstat,
 	.lstat_fn = streams_xattr_lstat,
diff --git a/source3/modules/vfs_syncops.c b/source3/modules/vfs_syncops.c
index c0607ae..c916cc4 100644
--- a/source3/modules/vfs_syncops.c
+++ b/source3/modules/vfs_syncops.c
@@ -295,7 +295,7 @@ static struct vfs_fn_pointers vfs_syncops_fns = {
 	.connect_fn = syncops_connect,
 	.mkdir_fn = syncops_mkdir,
 	.rmdir_fn = syncops_rmdir,
-	.open2_fn = syncops_open,
+	.open_fn = syncops_open,
 	.rename_fn = syncops_rename,
 	.unlink_fn = syncops_unlink,
 	.symlink_fn = syncops_symlink,
diff --git a/source3/modules/vfs_time_audit.c b/source3/modules/vfs_time_audit.c
index 606e9f2..627df5a 100644
--- a/source3/modules/vfs_time_audit.c
+++ b/source3/modules/vfs_time_audit.c
@@ -542,7 +542,7 @@ static NTSTATUS smb_time_audit_open(vfs_handle_struct *handle,
 	double timediff;
 
 	clock_gettime_mono(&ts1);
-	status = SMB_VFS_NEXT_OPEN2(handle, fname, fsp, flags, mode);
+	status = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
 	clock_gettime_mono(&ts2);
 	timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
 
@@ -2437,7 +2437,7 @@ static struct vfs_fn_pointers vfs_time_audit_fns = {
 	.rmdir_fn = smb_time_audit_rmdir,
 	.closedir_fn = smb_time_audit_closedir,
 	.init_search_op_fn = smb_time_audit_init_search_op,
-	.open2_fn = smb_time_audit_open,
+	.open_fn = smb_time_audit_open,
 	.create_file_fn = smb_time_audit_create_file,
 	.close_fn = smb_time_audit_close,
 	.read_fn = smb_time_audit_read,
diff --git a/source3/modules/vfs_unityed_media.c b/source3/modules/vfs_unityed_media.c
index a811245..2b1f140 100644
--- a/source3/modules/vfs_unityed_media.c
+++ b/source3/modules/vfs_unityed_media.c
@@ -858,7 +858,7 @@ static NTSTATUS um_open(vfs_handle_struct *handle,
 			      smb_fname->base_name));
 
 	if (!is_in_media_files(smb_fname->base_name)) {
-		return SMB_VFS_NEXT_OPEN2(handle, smb_fname, fsp, flags, mode);
+		return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
 	}
 
 	if (alloc_get_client_smb_fname(handle, talloc_tos(),
@@ -881,7 +881,7 @@ static NTSTATUS um_open(vfs_handle_struct *handle,
 			      ctime(&(smb_fname->st.st_ex_mtime.tv_sec)),
 			      ctime(&(fsp->fsp_name->st.st_ex_mtime.tv_sec))));
 
-	status = SMB_VFS_NEXT_OPEN2(handle, client_fname, fsp, flags, mode);
+	status = SMB_VFS_NEXT_OPEN(handle, client_fname, fsp, flags, mode);
 err:
 	TALLOC_FREE(client_fname);
 	DEBUG(10, ("Leaving with smb_fname->base_name '%s'\n",
@@ -1887,7 +1887,7 @@ static struct vfs_fn_pointers vfs_um_fns = {
 
 	/* File operations */
 
-	.open2_fn = um_open,
+	.open_fn = um_open,
 	.create_file_fn = um_create_file,
 	.rename_fn = um_rename,
 	.stat_fn = um_stat,
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 713d72f..8d18f6d 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -396,7 +396,7 @@ NTSTATUS fd_open(struct connection_struct *conn,
 	}
 #endif
 
-	status = SMB_VFS_OPEN2(conn, smb_fname, fsp, flags, mode);
+	status = SMB_VFS_OPEN(conn, smb_fname, fsp, flags, mode);
 	if (NT_STATUS_EQUAL(status, NT_STATUS_TOO_MANY_OPENED_FILES)) {
 		static time_t last_warned = 0L;
 
diff --git a/source3/smbd/pysmbd.c b/source3/smbd/pysmbd.c
index 3fc2305..cd46c7e 100644
--- a/source3/smbd/pysmbd.c
+++ b/source3/smbd/pysmbd.c
@@ -135,9 +135,9 @@ static NTSTATUS set_nt_acl_conn(const char *fname,
 	flags = O_RDONLY;
 #endif
 
-	status = SMB_VFS_OPEN2(conn, smb_fname, fsp, O_RDWR, 00400);
+	status = SMB_VFS_OPEN(conn, smb_fname, fsp, O_RDWR, 00400);
 	if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) {
-		status = SMB_VFS_OPEN2(conn, smb_fname, fsp, flags, 00400);
+		status = SMB_VFS_OPEN(conn, smb_fname, fsp, flags, 00400);
 	}
 	if (!NT_STATUS_IS_OK(status)) {
 		printf("open: error=%s (%s)\n", nt_errstr(status),
diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c
index 2768130..62a54d5 100644
--- a/source3/smbd/vfs.c
+++ b/source3/smbd/vfs.c
@@ -1489,12 +1489,12 @@ void smb_vfs_call_init_search_op(struct vfs_handle_struct *handle,
 	handle->fns->init_search_op_fn(handle, dirp);
 }
 
-NTSTATUS smb_vfs_call_open2(struct vfs_handle_struct *handle,
+NTSTATUS smb_vfs_call_open(struct vfs_handle_struct *handle,
 			   struct smb_filename *smb_fname,
 			   struct files_struct *fsp, int flags, mode_t mode)
 {
-	VFS_FIND(open2);
-	return handle->fns->open2_fn(handle, smb_fname, fsp, flags, mode);
+	VFS_FIND(open);
+	return handle->fns->open_fn(handle, smb_fname, fsp, flags, mode);
 }
 
 NTSTATUS smb_vfs_call_create_file(struct vfs_handle_struct *handle,
diff --git a/source3/torture/cmd_vfs.c b/source3/torture/cmd_vfs.c
index dd53727..87cf44e 100644
--- a/source3/torture/cmd_vfs.c
+++ b/source3/torture/cmd_vfs.c
@@ -334,7 +334,7 @@ static NTSTATUS cmd_open(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, c
 
 	fsp->fsp_name = smb_fname;
 
-	status = SMB_VFS_OPEN2(vfs->conn, smb_fname, fsp, flags, mode);
+	status = SMB_VFS_OPEN(vfs->conn, smb_fname, fsp, flags, mode);
 	if (!NT_STATUS_IS_OK(status)) {
 		printf("open: error=%s (%s)\n", nt_errstr(status),
 		       get_friendly_nt_error_msg(status));
@@ -1468,9 +1468,9 @@ static NTSTATUS cmd_set_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int a
 	flags = O_RDONLY;
 #endif
 
-	status = SMB_VFS_OPEN2(vfs->conn, smb_fname, fsp, O_RDWR, mode);
+	status = SMB_VFS_OPEN(vfs->conn, smb_fname, fsp, O_RDWR, mode);
 	if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) {
-		status = SMB_VFS_OPEN2(vfs->conn, smb_fname, fsp, flags, mode);
+		status = SMB_VFS_OPEN(vfs->conn, smb_fname, fsp, flags, mode);
 	}
 	if (!NT_STATUS_IS_OK(status)) {
 		printf("open: error=%s (%s)\n", nt_errstr(status),
-- 
2.4.3



More information about the samba-technical mailing list