diff options
author | Jeremy Allison <jra@samba.org> | 2012-07-09 16:08:01 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2012-07-09 16:20:45 -0700 |
commit | 3a705e5f3d0843e3765852e26661aeee5ebdfd79 (patch) | |
tree | 485c5ab17e8d7a5ffa771da35c0da98ecfef442b /source3 | |
parent | 1144b0dc043c42e4845316a4ccc3bdd49bfda822 (diff) | |
download | samba-3a705e5f3d0843e3765852e26661aeee5ebdfd79.tar.gz samba-3a705e5f3d0843e3765852e26661aeee5ebdfd79.tar.bz2 samba-3a705e5f3d0843e3765852e26661aeee5ebdfd79.zip |
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.
Diffstat (limited to 'source3')
-rw-r--r-- | source3/smbd/open.c | 37 |
1 files changed, 15 insertions, 22 deletions
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 { |