From 3a705e5f3d0843e3765852e26661aeee5ebdfd79 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2012 16:08:01 -0700 Subject: Simplify the logic in open_file(). Move the fstat call into the block which opens a file descriptor. Remove the stat() call in the stat-open case. We already failed the open if !file_existed. --- source3/smbd/open.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'source3/smbd') diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 88f779a527..26b48c1cf1 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -606,6 +606,7 @@ static NTSTATUS open_file(files_struct *fsp, (!file_existed && (local_flags & O_CREAT)) || ((local_flags & O_TRUNC) == O_TRUNC) ) { const char *wild; + int ret; /* * We can't actually truncate here as the file may be locked. @@ -678,6 +679,18 @@ static NTSTATUS open_file(files_struct *fsp, return status; } + ret = SMB_VFS_FSTAT(fsp, &smb_fname->st); + if (ret == -1) { + /* If we have an fd, this stat should succeed. */ + DEBUG(0,("Error doing fstat on open file %s " + "(%s)\n", + smb_fname_str_dbg(smb_fname), + strerror(errno) )); + status = map_nt_error_from_unix(errno); + fd_close(fsp); + return status; + } + if ((local_flags & O_CREAT) && !file_existed) { file_created = true; } @@ -716,28 +729,6 @@ static NTSTATUS open_file(files_struct *fsp, } if (!file_existed) { - int ret; - - if (fsp->fh->fd == -1) { - ret = SMB_VFS_STAT(conn, smb_fname); - } else { - ret = SMB_VFS_FSTAT(fsp, &smb_fname->st); - /* If we have an fd, this stat should succeed. */ - if (ret == -1) { - DEBUG(0,("Error doing fstat on open file %s " - "(%s)\n", - smb_fname_str_dbg(smb_fname), - strerror(errno) )); - } - } - - /* For a non-io open, this stat failing means file not found. JRA */ - if (ret == -1) { - status = map_nt_error_from_unix(errno); - fd_close(fsp); - return status; - } - if (file_created) { bool need_re_stat = false; /* Do all inheritance work after we've @@ -760,6 +751,8 @@ static NTSTATUS open_file(files_struct *fsp, } if (need_re_stat) { + int ret; + if (fsp->fh->fd == -1) { ret = SMB_VFS_STAT(conn, smb_fname); } else { -- cgit