POSIX: when attempting to fdatasync(2) a file which is not open for

writing, fail with EBADF.
This commit is contained in:
kleink 2003-10-25 01:18:01 +00:00
parent 3ebaf267f3
commit 661f76699f
2 changed files with 9 additions and 5 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: fdatasync.2,v 1.13 2003/04/16 13:34:51 wiz Exp $
.\" $NetBSD: fdatasync.2,v 1.14 2003/10/25 01:18:01 kleink Exp $
.\"
.\" Copyright (c) 1998 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -34,7 +34,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd May 30, 1998
.Dd October 25, 2003
.Dt FDATASYNC 2
.Os
.Sh NAME
@ -75,7 +75,7 @@ function will fail if:
.It Bq Er EBADF
The
.Fa fd
argument is not a valid file descriptor.
argument is not a valid file descriptor open for writing.
.It Bq Er EINVAL
This implementation does not support synchronized I/O for this file.
.It Bq Er ENOSYS

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_syscalls.c,v 1.198 2003/10/15 17:26:38 thorpej Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.199 2003/10/25 01:18:01 kleink Exp $ */
/*
* Copyright (c) 1989, 1993
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.198 2003/10/15 17:26:38 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.199 2003/10/25 01:18:01 kleink Exp $");
#include "opt_compat_netbsd.h"
#include "opt_compat_43.h"
@ -3025,6 +3025,10 @@ sys_fdatasync(l, v, retval)
/* getvnode() will use the descriptor for us */
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
if ((fp->f_flag & FWRITE) == 0) {
FILE_UNUSE(fp, p);
return (EBADF);
}
vp = (struct vnode *)fp->f_data;
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
error = VOP_FSYNC(vp, fp->f_cred, FSYNC_WAIT|FSYNC_DATAONLY, 0, 0, p);