| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: vfs_syscalls.c,v 1.516 2017/06/01 02:45:13 chs Exp $ */ | | 1 | /* $NetBSD: vfs_syscalls.c,v 1.516.2.1 2020/04/22 18:18:26 martin Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Andrew Doran. | | 8 | * by Andrew Doran. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -60,27 +60,27 @@ | | | @@ -60,27 +60,27 @@ |
60 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 60 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
63 | * SUCH DAMAGE. | | 63 | * SUCH DAMAGE. |
64 | * | | 64 | * |
65 | * @(#)vfs_syscalls.c 8.42 (Berkeley) 7/31/95 | | 65 | * @(#)vfs_syscalls.c 8.42 (Berkeley) 7/31/95 |
66 | */ | | 66 | */ |
67 | | | 67 | |
68 | /* | | 68 | /* |
69 | * Virtual File System System Calls | | 69 | * Virtual File System System Calls |
70 | */ | | 70 | */ |
71 | | | 71 | |
72 | #include <sys/cdefs.h> | | 72 | #include <sys/cdefs.h> |
73 | __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.516 2017/06/01 02:45:13 chs Exp $"); | | 73 | __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.516.2.1 2020/04/22 18:18:26 martin Exp $"); |
74 | | | 74 | |
75 | #ifdef _KERNEL_OPT | | 75 | #ifdef _KERNEL_OPT |
76 | #include "opt_fileassoc.h" | | 76 | #include "opt_fileassoc.h" |
77 | #include "veriexec.h" | | 77 | #include "veriexec.h" |
78 | #endif | | 78 | #endif |
79 | | | 79 | |
80 | #include <sys/param.h> | | 80 | #include <sys/param.h> |
81 | #include <sys/systm.h> | | 81 | #include <sys/systm.h> |
82 | #include <sys/namei.h> | | 82 | #include <sys/namei.h> |
83 | #include <sys/filedesc.h> | | 83 | #include <sys/filedesc.h> |
84 | #include <sys/kernel.h> | | 84 | #include <sys/kernel.h> |
85 | #include <sys/file.h> | | 85 | #include <sys/file.h> |
86 | #include <sys/fcntl.h> | | 86 | #include <sys/fcntl.h> |
| @@ -3994,28 +3994,27 @@ sys_fsync(struct lwp *l, const struct sy | | | @@ -3994,28 +3994,27 @@ sys_fsync(struct lwp *l, const struct sy |
3994 | return (error); | | 3994 | return (error); |
3995 | vp = fp->f_vnode; | | 3995 | vp = fp->f_vnode; |
3996 | vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); | | 3996 | vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); |
3997 | error = VOP_FSYNC(vp, fp->f_cred, FSYNC_WAIT, 0, 0); | | 3997 | error = VOP_FSYNC(vp, fp->f_cred, FSYNC_WAIT, 0, 0); |
3998 | VOP_UNLOCK(vp); | | 3998 | VOP_UNLOCK(vp); |
3999 | fd_putfile(SCARG(uap, fd)); | | 3999 | fd_putfile(SCARG(uap, fd)); |
4000 | return (error); | | 4000 | return (error); |
4001 | } | | 4001 | } |
4002 | | | 4002 | |
4003 | /* | | 4003 | /* |
4004 | * Sync a range of file data. API modeled after that found in AIX. | | 4004 | * Sync a range of file data. API modeled after that found in AIX. |
4005 | * | | 4005 | * |
4006 | * FDATASYNC indicates that we need only save enough metadata to be able | | 4006 | * FDATASYNC indicates that we need only save enough metadata to be able |
4007 | * to re-read the written data. Note we duplicate AIX's requirement that | | 4007 | * to re-read the written data. |
4008 | * the file be open for writing. | | | |
4009 | */ | | 4008 | */ |
4010 | /* ARGSUSED */ | | 4009 | /* ARGSUSED */ |
4011 | int | | 4010 | int |
4012 | sys_fsync_range(struct lwp *l, const struct sys_fsync_range_args *uap, register_t *retval) | | 4011 | sys_fsync_range(struct lwp *l, const struct sys_fsync_range_args *uap, register_t *retval) |
4013 | { | | 4012 | { |
4014 | /* { | | 4013 | /* { |
4015 | syscallarg(int) fd; | | 4014 | syscallarg(int) fd; |
4016 | syscallarg(int) flags; | | 4015 | syscallarg(int) flags; |
4017 | syscallarg(off_t) start; | | 4016 | syscallarg(off_t) start; |
4018 | syscallarg(off_t) length; | | 4017 | syscallarg(off_t) length; |
4019 | } */ | | 4018 | } */ |
4020 | struct vnode *vp; | | 4019 | struct vnode *vp; |
4021 | file_t *fp; | | 4020 | file_t *fp; |
| @@ -4076,30 +4075,26 @@ out: | | | @@ -4076,30 +4075,26 @@ out: |
4076 | int | | 4075 | int |
4077 | sys_fdatasync(struct lwp *l, const struct sys_fdatasync_args *uap, register_t *retval) | | 4076 | sys_fdatasync(struct lwp *l, const struct sys_fdatasync_args *uap, register_t *retval) |
4078 | { | | 4077 | { |
4079 | /* { | | 4078 | /* { |
4080 | syscallarg(int) fd; | | 4079 | syscallarg(int) fd; |
4081 | } */ | | 4080 | } */ |
4082 | struct vnode *vp; | | 4081 | struct vnode *vp; |
4083 | file_t *fp; | | 4082 | file_t *fp; |
4084 | int error; | | 4083 | int error; |
4085 | | | 4084 | |
4086 | /* fd_getvnode() will use the descriptor for us */ | | 4085 | /* fd_getvnode() will use the descriptor for us */ |
4087 | if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0) | | 4086 | if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0) |
4088 | return (error); | | 4087 | return (error); |
4089 | if ((fp->f_flag & FWRITE) == 0) { | | | |
4090 | fd_putfile(SCARG(uap, fd)); | | | |
4091 | return (EBADF); | | | |
4092 | } | | | |
4093 | vp = fp->f_vnode; | | 4088 | vp = fp->f_vnode; |
4094 | vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); | | 4089 | vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); |
4095 | error = VOP_FSYNC(vp, fp->f_cred, FSYNC_WAIT|FSYNC_DATAONLY, 0, 0); | | 4090 | error = VOP_FSYNC(vp, fp->f_cred, FSYNC_WAIT|FSYNC_DATAONLY, 0, 0); |
4096 | VOP_UNLOCK(vp); | | 4091 | VOP_UNLOCK(vp); |
4097 | fd_putfile(SCARG(uap, fd)); | | 4092 | fd_putfile(SCARG(uap, fd)); |
4098 | return (error); | | 4093 | return (error); |
4099 | } | | 4094 | } |
4100 | | | 4095 | |
4101 | /* | | 4096 | /* |
4102 | * Rename files, (standard) BSD semantics frontend. | | 4097 | * Rename files, (standard) BSD semantics frontend. |
4103 | */ | | 4098 | */ |
4104 | /* ARGSUSED */ | | 4099 | /* ARGSUSED */ |
4105 | int | | 4100 | int |