| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: vfs_syscalls.c,v 1.490.2.1 2014/12/01 09:54:50 martin Exp $ */ | | 1 | /* $NetBSD: vfs_syscalls.c,v 1.490.2.2 2015/02/18 06:35:58 snj 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.490.2.1 2014/12/01 09:54:50 martin Exp $"); | | 73 | __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.490.2.2 2015/02/18 06:35:58 snj 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> |
| @@ -4706,50 +4706,53 @@ sys_posix_fallocate(struct lwp *l, const | | | @@ -4706,50 +4706,53 @@ sys_posix_fallocate(struct lwp *l, const |
4706 | syscallarg(off_t) len; | | 4706 | syscallarg(off_t) len; |
4707 | } */ | | 4707 | } */ |
4708 | int fd; | | 4708 | int fd; |
4709 | off_t pos, len; | | 4709 | off_t pos, len; |
4710 | struct file *fp; | | 4710 | struct file *fp; |
4711 | struct vnode *vp; | | 4711 | struct vnode *vp; |
4712 | int error; | | 4712 | int error; |
4713 | | | 4713 | |
4714 | fd = SCARG(uap, fd); | | 4714 | fd = SCARG(uap, fd); |
4715 | pos = SCARG(uap, pos); | | 4715 | pos = SCARG(uap, pos); |
4716 | len = SCARG(uap, len); | | 4716 | len = SCARG(uap, len); |
4717 | | | 4717 | |
4718 | if (pos < 0 || len < 0 || len > OFF_T_MAX - pos) { | | 4718 | if (pos < 0 || len < 0 || len > OFF_T_MAX - pos) { |
4719 | return EINVAL; | | 4719 | *retval = EINVAL; |
| | | 4720 | return 0; |
4720 | } | | 4721 | } |
4721 | | | 4722 | |
4722 | error = fd_getvnode(fd, &fp); | | 4723 | error = fd_getvnode(fd, &fp); |
4723 | if (error) { | | 4724 | if (error) { |
4724 | return error; | | 4725 | *retval = error; |
| | | 4726 | return 0; |
4725 | } | | 4727 | } |
4726 | if ((fp->f_flag & FWRITE) == 0) { | | 4728 | if ((fp->f_flag & FWRITE) == 0) { |
4727 | error = EBADF; | | 4729 | error = EBADF; |
4728 | goto fail; | | 4730 | goto fail; |
4729 | } | | 4731 | } |
4730 | vp = fp->f_data; | | 4732 | vp = fp->f_data; |
4731 | | | 4733 | |
4732 | vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); | | 4734 | vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); |
4733 | if (vp->v_type == VDIR) { | | 4735 | if (vp->v_type == VDIR) { |
4734 | error = EISDIR; | | 4736 | error = EISDIR; |
4735 | } else { | | 4737 | } else { |
4736 | error = VOP_FALLOCATE(vp, pos, len); | | 4738 | error = VOP_FALLOCATE(vp, pos, len); |
4737 | } | | 4739 | } |
4738 | VOP_UNLOCK(vp); | | 4740 | VOP_UNLOCK(vp); |
4739 | | | 4741 | |
4740 | fail: | | 4742 | fail: |
4741 | fd_putfile(fd); | | 4743 | fd_putfile(fd); |
4742 | return error; | | 4744 | *retval = error; |
| | | 4745 | return 0; |
4743 | } | | 4746 | } |
4744 | | | 4747 | |
4745 | /* | | 4748 | /* |
4746 | * Deallocate backing store for a file, creating a hole. Also used for | | 4749 | * Deallocate backing store for a file, creating a hole. Also used for |
4747 | * invoking TRIM on disks. | | 4750 | * invoking TRIM on disks. |
4748 | */ | | 4751 | */ |
4749 | /* ARGSUSED */ | | 4752 | /* ARGSUSED */ |
4750 | int | | 4753 | int |
4751 | sys_fdiscard(struct lwp *l, const struct sys_fdiscard_args *uap, | | 4754 | sys_fdiscard(struct lwp *l, const struct sys_fdiscard_args *uap, |
4752 | register_t *retval) | | 4755 | register_t *retval) |
4753 | { | | 4756 | { |
4754 | /* { | | 4757 | /* { |
4755 | syscallarg(int) fd; | | 4758 | syscallarg(int) fd; |