Start making fs read(2) fail with EISDIR if the implementation does not allow read on directories (kernfs, rumpfs, ptyfs and sysvbfs). Adjust man page accordingly, and add a small corresponding vfs testcase.diff -r1.33 -r1.34 src/lib/libc/sys/read.2
(njoly)
--- src/lib/libc/sys/read.2 2010/04/05 07:53:47 1.33
+++ src/lib/libc/sys/read.2 2011/12/12 19:11:21 1.34
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | .\" $NetBSD: read.2,v 1.33 2010/04/05 07:53:47 wiz Exp $ | 1 | .\" $NetBSD: read.2,v 1.34 2011/12/12 19:11:21 njoly Exp $ | |
2 | .\" | 2 | .\" | |
3 | .\" Copyright (c) 1980, 1991, 1993 | 3 | .\" Copyright (c) 1980, 1991, 1993 | |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. | |
5 | .\" | 5 | .\" | |
6 | .\" Redistribution and use in source and binary forms, with or without | 6 | .\" Redistribution and use in source and binary forms, with or without | |
7 | .\" modification, are permitted provided that the following conditions | 7 | .\" modification, are permitted provided that the following conditions | |
8 | .\" are met: | 8 | .\" are met: | |
9 | .\" 1. Redistributions of source code must retain the above copyright | 9 | .\" 1. Redistributions of source code must retain the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer. | 10 | .\" notice, this list of conditions and the following disclaimer. | |
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the | |
13 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. | |
14 | .\" 3. Neither the name of the University nor the names of its contributors | 14 | .\" 3. Neither the name of the University nor the names of its contributors | |
@@ -19,27 +19,27 @@ | @@ -19,27 +19,27 @@ | |||
19 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
20 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
21 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 21 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
22 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 22 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
23 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 23 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
24 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 24 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 25 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
26 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 26 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
28 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. | |
29 | .\" | 29 | .\" | |
30 | .\" @(#)read.2 8.4 (Berkeley) 2/26/94 | 30 | .\" @(#)read.2 8.4 (Berkeley) 2/26/94 | |
31 | .\" | 31 | .\" | |
32 | .Dd April 3, 2010 | 32 | .Dd December 12, 2011 | |
33 | .Dt READ 2 | 33 | .Dt READ 2 | |
34 | .Os | 34 | .Os | |
35 | .Sh NAME | 35 | .Sh NAME | |
36 | .Nm read , | 36 | .Nm read , | |
37 | .Nm readv , | 37 | .Nm readv , | |
38 | .Nm pread , | 38 | .Nm pread , | |
39 | .Nm preadv | 39 | .Nm preadv | |
40 | .Nd read input | 40 | .Nd read input | |
41 | .Sh LIBRARY | 41 | .Sh LIBRARY | |
42 | .Lb libc | 42 | .Lb libc | |
43 | .Sh SYNOPSIS | 43 | .Sh SYNOPSIS | |
44 | .In unistd.h | 44 | .In unistd.h | |
45 | .Ft ssize_t | 45 | .Ft ssize_t | |
@@ -151,26 +151,36 @@ was interrupted by the delivery of a sig | @@ -151,26 +151,36 @@ was interrupted by the delivery of a sig | |||
151 | before any data arrived. | 151 | before any data arrived. | |
152 | See | 152 | See | |
153 | .Xr sigaction 2 | 153 | .Xr sigaction 2 | |
154 | for more information on the interaction between signals and system | 154 | for more information on the interaction between signals and system | |
155 | calls. | 155 | calls. | |
156 | .It Bq Er EINVAL | 156 | .It Bq Er EINVAL | |
157 | The file pointer associated with | 157 | The file pointer associated with | |
158 | .Fa d | 158 | .Fa d | |
159 | was negative; or | 159 | was negative; or | |
160 | the total length of the I/O is more than can be expressed by the ssize_t | 160 | the total length of the I/O is more than can be expressed by the ssize_t | |
161 | return value. | 161 | return value. | |
162 | .It Bq Er EIO | 162 | .It Bq Er EIO | |
163 | An I/O error occurred while reading from the file system. | 163 | An I/O error occurred while reading from the file system. | |
164 | .It Bq Er EISDIR | |||
165 | .Fa d | |||
166 | refers to a directory and the implementation does not allow the directory | |||
167 | to be read using | |||
168 | .Fn read | |||
169 | or | |||
170 | .Fn pread . | |||
171 | The | |||
172 | .Fn readdir | |||
173 | function should be used instead. | |||
164 | .El | 174 | .El | |
165 | .Pp | 175 | .Pp | |
166 | In addition, | 176 | In addition, | |
167 | .Fn readv | 177 | .Fn readv | |
168 | and | 178 | and | |
169 | .Fn preadv | 179 | .Fn preadv | |
170 | may return one of the following errors: | 180 | may return one of the following errors: | |
171 | .Bl -tag -width Er | 181 | .Bl -tag -width Er | |
172 | .It Bq Er EFAULT | 182 | .It Bq Er EFAULT | |
173 | Part of the | 183 | Part of the | |
174 | .Fa iov | 184 | .Fa iov | |
175 | points outside the process's allocated address space. | 185 | points outside the process's allocated address space. | |
176 | .It Bq Er EINVAL | 186 | .It Bq Er EINVAL |
--- src/sys/fs/ptyfs/ptyfs_vnops.c 2011/11/18 21:18:50 1.37
+++ src/sys/fs/ptyfs/ptyfs_vnops.c 2011/12/12 19:11:21 1.38
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ptyfs_vnops.c,v 1.37 2011/11/18 21:18:50 christos Exp $ */ | 1 | /* $NetBSD: ptyfs_vnops.c,v 1.38 2011/12/12 19:11:21 njoly Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1993, 1995 | 4 | * Copyright (c) 1993, 1995 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Jan-Simon Pendry. | 8 | * Jan-Simon Pendry. | |
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. | |
@@ -66,27 +66,27 @@ | @@ -66,27 +66,27 @@ | |||
66 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 66 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
67 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 67 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
68 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 68 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
69 | * SUCH DAMAGE. | 69 | * SUCH DAMAGE. | |
70 | * | 70 | * | |
71 | * @(#)procfs_vnops.c 8.18 (Berkeley) 5/21/95 | 71 | * @(#)procfs_vnops.c 8.18 (Berkeley) 5/21/95 | |
72 | */ | 72 | */ | |
73 | 73 | |||
74 | /* | 74 | /* | |
75 | * ptyfs vnode interface | 75 | * ptyfs vnode interface | |
76 | */ | 76 | */ | |
77 | 77 | |||
78 | #include <sys/cdefs.h> | 78 | #include <sys/cdefs.h> | |
79 | __KERNEL_RCSID(0, "$NetBSD: ptyfs_vnops.c,v 1.37 2011/11/18 21:18:50 christos Exp $"); | 79 | __KERNEL_RCSID(0, "$NetBSD: ptyfs_vnops.c,v 1.38 2011/12/12 19:11:21 njoly Exp $"); | |
80 | 80 | |||
81 | #include <sys/param.h> | 81 | #include <sys/param.h> | |
82 | #include <sys/systm.h> | 82 | #include <sys/systm.h> | |
83 | #include <sys/time.h> | 83 | #include <sys/time.h> | |
84 | #include <sys/kernel.h> | 84 | #include <sys/kernel.h> | |
85 | #include <sys/file.h> | 85 | #include <sys/file.h> | |
86 | #include <sys/filedesc.h> | 86 | #include <sys/filedesc.h> | |
87 | #include <sys/proc.h> | 87 | #include <sys/proc.h> | |
88 | #include <sys/vnode.h> | 88 | #include <sys/vnode.h> | |
89 | #include <sys/namei.h> | 89 | #include <sys/namei.h> | |
90 | #include <sys/malloc.h> | 90 | #include <sys/malloc.h> | |
91 | #include <sys/mount.h> | 91 | #include <sys/mount.h> | |
92 | #include <sys/select.h> | 92 | #include <sys/select.h> | |
@@ -778,26 +778,29 @@ int | @@ -778,26 +778,29 @@ int | |||
778 | ptyfs_read(void *v) | 778 | ptyfs_read(void *v) | |
779 | { | 779 | { | |
780 | struct vop_read_args /* { | 780 | struct vop_read_args /* { | |
781 | struct vnode *a_vp; | 781 | struct vnode *a_vp; | |
782 | struct uio *a_uio; | 782 | struct uio *a_uio; | |
783 | int a_ioflag; | 783 | int a_ioflag; | |
784 | kauth_cred_t a_cred; | 784 | kauth_cred_t a_cred; | |
785 | } */ *ap = v; | 785 | } */ *ap = v; | |
786 | struct timespec ts; | 786 | struct timespec ts; | |
787 | struct vnode *vp = ap->a_vp; | 787 | struct vnode *vp = ap->a_vp; | |
788 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); | 788 | struct ptyfsnode *ptyfs = VTOPTYFS(vp); | |
789 | int error; | 789 | int error; | |
790 | 790 | |||
791 | if (vp->v_type == VDIR) | |||
792 | return EISDIR; | |||
793 | ||||
791 | ptyfs->ptyfs_flag |= PTYFS_ACCESS; | 794 | ptyfs->ptyfs_flag |= PTYFS_ACCESS; | |
792 | /* hardclock() resolution is good enough for ptyfs */ | 795 | /* hardclock() resolution is good enough for ptyfs */ | |
793 | getnanotime(&ts); | 796 | getnanotime(&ts); | |
794 | (void)ptyfs_update(vp, &ts, &ts, 0); | 797 | (void)ptyfs_update(vp, &ts, &ts, 0); | |
795 | 798 | |||
796 | switch (ptyfs->ptyfs_type) { | 799 | switch (ptyfs->ptyfs_type) { | |
797 | case PTYFSpts: | 800 | case PTYFSpts: | |
798 | case PTYFSptc: | 801 | case PTYFSptc: | |
799 | VOP_UNLOCK(vp); | 802 | VOP_UNLOCK(vp); | |
800 | error = cdev_read(vp->v_rdev, ap->a_uio, ap->a_ioflag); | 803 | error = cdev_read(vp->v_rdev, ap->a_uio, ap->a_ioflag); | |
801 | vn_lock(vp, LK_RETRY|LK_EXCLUSIVE); | 804 | vn_lock(vp, LK_RETRY|LK_EXCLUSIVE); | |
802 | return error; | 805 | return error; | |
803 | default: | 806 | default: |
--- src/sys/fs/sysvbfs/sysvbfs_vnops.c 2011/05/19 03:11:58 1.38
+++ src/sys/fs/sysvbfs/sysvbfs_vnops.c 2011/12/12 19:11:21 1.39
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: sysvbfs_vnops.c,v 1.38 2011/05/19 03:11:58 rmind Exp $ */ | 1 | /* $NetBSD: sysvbfs_vnops.c,v 1.39 2011/12/12 19:11:21 njoly Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2004 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2004 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 UCHIYAMA Yasushi. | 8 | * by UCHIYAMA Yasushi. | |
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. | |
@@ -20,27 +20,27 @@ | @@ -20,27 +20,27 @@ | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: sysvbfs_vnops.c,v 1.38 2011/05/19 03:11:58 rmind Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: sysvbfs_vnops.c,v 1.39 2011/12/12 19:11:21 njoly Exp $"); | |
34 | 34 | |||
35 | #include <sys/param.h> | 35 | #include <sys/param.h> | |
36 | #include <sys/kernel.h> | 36 | #include <sys/kernel.h> | |
37 | #include <sys/resource.h> | 37 | #include <sys/resource.h> | |
38 | #include <sys/vnode.h> | 38 | #include <sys/vnode.h> | |
39 | #include <sys/namei.h> | 39 | #include <sys/namei.h> | |
40 | #include <sys/dirent.h> | 40 | #include <sys/dirent.h> | |
41 | #include <sys/malloc.h> | 41 | #include <sys/malloc.h> | |
42 | #include <sys/lockf.h> | 42 | #include <sys/lockf.h> | |
43 | #include <sys/unistd.h> | 43 | #include <sys/unistd.h> | |
44 | #include <sys/fcntl.h> | 44 | #include <sys/fcntl.h> | |
45 | #include <sys/kauth.h> | 45 | #include <sys/kauth.h> | |
46 | #include <sys/buf.h> | 46 | #include <sys/buf.h> | |
@@ -368,28 +368,34 @@ sysvbfs_read(void *arg) | @@ -368,28 +368,34 @@ sysvbfs_read(void *arg) | |||
368 | struct uio *a_uio; | 368 | struct uio *a_uio; | |
369 | int a_ioflag; | 369 | int a_ioflag; | |
370 | kauth_cred_t a_cred; | 370 | kauth_cred_t a_cred; | |
371 | } */ *a = arg; | 371 | } */ *a = arg; | |
372 | struct vnode *v = a->a_vp; | 372 | struct vnode *v = a->a_vp; | |
373 | struct uio *uio = a->a_uio; | 373 | struct uio *uio = a->a_uio; | |
374 | struct sysvbfs_node *bnode = v->v_data; | 374 | struct sysvbfs_node *bnode = v->v_data; | |
375 | struct bfs_inode *inode = bnode->inode; | 375 | struct bfs_inode *inode = bnode->inode; | |
376 | vsize_t sz, filesz = bfs_file_size(inode); | 376 | vsize_t sz, filesz = bfs_file_size(inode); | |
377 | int err; | 377 | int err; | |
378 | const int advice = IO_ADV_DECODE(a->a_ioflag); | 378 | const int advice = IO_ADV_DECODE(a->a_ioflag); | |
379 | 379 | |||
380 | DPRINTF("%s: type=%d\n", __func__, v->v_type); | 380 | DPRINTF("%s: type=%d\n", __func__, v->v_type); | |
381 | if (v->v_type != VREG) | 381 | switch (v->v_type) { | |
382 | case VREG: | |||
383 | break; | |||
384 | case VDIR: | |||
385 | return EISDIR; | |||
386 | default: | |||
382 | return EINVAL; | 387 | return EINVAL; | |
388 | } | |||
383 | 389 | |||
384 | while (uio->uio_resid > 0) { | 390 | while (uio->uio_resid > 0) { | |
385 | if ((sz = MIN(filesz - uio->uio_offset, uio->uio_resid)) == 0) | 391 | if ((sz = MIN(filesz - uio->uio_offset, uio->uio_resid)) == 0) | |
386 | break; | 392 | break; | |
387 | 393 | |||
388 | err = ubc_uiomove(&v->v_uobj, uio, sz, advice, | 394 | err = ubc_uiomove(&v->v_uobj, uio, sz, advice, | |
389 | UBC_READ | UBC_PARTIALOK | UBC_UNMAP_FLAG(v)); | 395 | UBC_READ | UBC_PARTIALOK | UBC_UNMAP_FLAG(v)); | |
390 | if (err) | 396 | if (err) | |
391 | break; | 397 | break; | |
392 | DPRINTF("%s: read %ldbyte\n", __func__, sz); | 398 | DPRINTF("%s: read %ldbyte\n", __func__, sz); | |
393 | } | 399 | } | |
394 | 400 | |||
395 | return sysvbfs_update(v, NULL, NULL, UPDATE_WAIT); | 401 | return sysvbfs_update(v, NULL, NULL, UPDATE_WAIT); |
--- src/sys/miscfs/kernfs/kernfs_vnops.c 2010/07/21 09:06:38 1.143
+++ src/sys/miscfs/kernfs/kernfs_vnops.c 2011/12/12 19:11:22 1.144
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: kernfs_vnops.c,v 1.143 2010/07/21 09:06:38 hannken Exp $ */ | 1 | /* $NetBSD: kernfs_vnops.c,v 1.144 2011/12/12 19:11:22 njoly Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1992, 1993 | 4 | * Copyright (c) 1992, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software donated to Berkeley by | 7 | * This code is derived from software donated to Berkeley by | |
8 | * Jan-Simon Pendry. | 8 | * Jan-Simon Pendry. | |
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. | |
@@ -29,27 +29,27 @@ | @@ -29,27 +29,27 @@ | |||
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | * SUCH DAMAGE. | 32 | * SUCH DAMAGE. | |
33 | * | 33 | * | |
34 | * @(#)kernfs_vnops.c 8.15 (Berkeley) 5/21/95 | 34 | * @(#)kernfs_vnops.c 8.15 (Berkeley) 5/21/95 | |
35 | */ | 35 | */ | |
36 | 36 | |||
37 | /* | 37 | /* | |
38 | * Kernel parameter filesystem (/kern) | 38 | * Kernel parameter filesystem (/kern) | |
39 | */ | 39 | */ | |
40 | 40 | |||
41 | #include <sys/cdefs.h> | 41 | #include <sys/cdefs.h> | |
42 | __KERNEL_RCSID(0, "$NetBSD: kernfs_vnops.c,v 1.143 2010/07/21 09:06:38 hannken Exp $"); | 42 | __KERNEL_RCSID(0, "$NetBSD: kernfs_vnops.c,v 1.144 2011/12/12 19:11:22 njoly Exp $"); | |
43 | 43 | |||
44 | #ifdef _KERNEL_OPT | 44 | #ifdef _KERNEL_OPT | |
45 | #include "opt_ipsec.h" | 45 | #include "opt_ipsec.h" | |
46 | #endif | 46 | #endif | |
47 | 47 | |||
48 | #include <sys/param.h> | 48 | #include <sys/param.h> | |
49 | #include <sys/systm.h> | 49 | #include <sys/systm.h> | |
50 | #include <sys/kernel.h> | 50 | #include <sys/kernel.h> | |
51 | #include <sys/vmmeter.h> | 51 | #include <sys/vmmeter.h> | |
52 | #include <sys/time.h> | 52 | #include <sys/time.h> | |
53 | #include <sys/proc.h> | 53 | #include <sys/proc.h> | |
54 | #include <sys/vnode.h> | 54 | #include <sys/vnode.h> | |
55 | #include <sys/malloc.h> | 55 | #include <sys/malloc.h> | |
@@ -931,27 +931,27 @@ kernfs_default_xread(void *v) | @@ -931,27 +931,27 @@ kernfs_default_xread(void *v) | |||
931 | struct vnode *a_vp; | 931 | struct vnode *a_vp; | |
932 | struct uio *a_uio; | 932 | struct uio *a_uio; | |
933 | int a_ioflag; | 933 | int a_ioflag; | |
934 | kauth_cred_t a_cred; | 934 | kauth_cred_t a_cred; | |
935 | } */ *ap = v; | 935 | } */ *ap = v; | |
936 | struct uio *uio = ap->a_uio; | 936 | struct uio *uio = ap->a_uio; | |
937 | struct kernfs_node *kfs = VTOKERN(ap->a_vp); | 937 | struct kernfs_node *kfs = VTOKERN(ap->a_vp); | |
938 | char strbuf[KSTRING], *bf; | 938 | char strbuf[KSTRING], *bf; | |
939 | int off; | 939 | int off; | |
940 | size_t len; | 940 | size_t len; | |
941 | int error; | 941 | int error; | |
942 | 942 | |||
943 | if (ap->a_vp->v_type == VDIR) | 943 | if (ap->a_vp->v_type == VDIR) | |
944 | return (EOPNOTSUPP); | 944 | return EISDIR; | |
945 | 945 | |||
946 | off = (int)uio->uio_offset; | 946 | off = (int)uio->uio_offset; | |
947 | /* Don't allow negative offsets */ | 947 | /* Don't allow negative offsets */ | |
948 | if (off < 0) | 948 | if (off < 0) | |
949 | return EINVAL; | 949 | return EINVAL; | |
950 | 950 | |||
951 | bf = strbuf; | 951 | bf = strbuf; | |
952 | if ((error = kernfs_xread(kfs, off, &bf, sizeof(strbuf), &len)) == 0) | 952 | if ((error = kernfs_xread(kfs, off, &bf, sizeof(strbuf), &len)) == 0) | |
953 | error = uiomove(bf, len, uio); | 953 | error = uiomove(bf, len, uio); | |
954 | return (error); | 954 | return (error); | |
955 | } | 955 | } | |
956 | 956 | |||
957 | int | 957 | int |
--- src/sys/rump/librump/rumpvfs/rumpfs.c 2011/09/27 14:24:52 1.103
+++ src/sys/rump/librump/rumpvfs/rumpfs.c 2011/12/12 19:11:22 1.104
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: rumpfs.c,v 1.103 2011/09/27 14:24:52 mbalmer Exp $ */ | 1 | /* $NetBSD: rumpfs.c,v 1.104 2011/12/12 19:11:22 njoly Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2009, 2010, 2011 Antti Kantee. All Rights Reserved. | 4 | * Copyright (c) 2009, 2010, 2011 Antti Kantee. All Rights Reserved. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * | 14 | * | |
@@ -16,27 +16,27 @@ | @@ -16,27 +16,27 @@ | |||
16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
25 | * SUCH DAMAGE. | 25 | * SUCH DAMAGE. | |
26 | */ | 26 | */ | |
27 | 27 | |||
28 | #include <sys/cdefs.h> | 28 | #include <sys/cdefs.h> | |
29 | __KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.103 2011/09/27 14:24:52 mbalmer Exp $"); | 29 | __KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.104 2011/12/12 19:11:22 njoly Exp $"); | |
30 | 30 | |||
31 | #include <sys/param.h> | 31 | #include <sys/param.h> | |
32 | #include <sys/atomic.h> | 32 | #include <sys/atomic.h> | |
33 | #include <sys/buf.h> | 33 | #include <sys/buf.h> | |
34 | #include <sys/dirent.h> | 34 | #include <sys/dirent.h> | |
35 | #include <sys/errno.h> | 35 | #include <sys/errno.h> | |
36 | #include <sys/filedesc.h> | 36 | #include <sys/filedesc.h> | |
37 | #include <sys/fcntl.h> | 37 | #include <sys/fcntl.h> | |
38 | #include <sys/kauth.h> | 38 | #include <sys/kauth.h> | |
39 | #include <sys/malloc.h> | 39 | #include <sys/malloc.h> | |
40 | #include <sys/module.h> | 40 | #include <sys/module.h> | |
41 | #include <sys/mount.h> | 41 | #include <sys/mount.h> | |
42 | #include <sys/namei.h> | 42 | #include <sys/namei.h> | |
@@ -1274,26 +1274,29 @@ rump_vop_read(void *v) | @@ -1274,26 +1274,29 @@ rump_vop_read(void *v) | |||
1274 | struct vop_read_args /* { | 1274 | struct vop_read_args /* { | |
1275 | struct vnode *a_vp; | 1275 | struct vnode *a_vp; | |
1276 | struct uio *a_uio; | 1276 | struct uio *a_uio; | |
1277 | int ioflags a_ioflag; | 1277 | int ioflags a_ioflag; | |
1278 | kauth_cred_t a_cred; | 1278 | kauth_cred_t a_cred; | |
1279 | }; */ *ap = v; | 1279 | }; */ *ap = v; | |
1280 | struct vnode *vp = ap->a_vp; | 1280 | struct vnode *vp = ap->a_vp; | |
1281 | struct rumpfs_node *rn = vp->v_data; | 1281 | struct rumpfs_node *rn = vp->v_data; | |
1282 | struct uio *uio = ap->a_uio; | 1282 | struct uio *uio = ap->a_uio; | |
1283 | const int advice = IO_ADV_DECODE(ap->a_ioflag); | 1283 | const int advice = IO_ADV_DECODE(ap->a_ioflag); | |
1284 | off_t chunk; | 1284 | off_t chunk; | |
1285 | int error = 0; | 1285 | int error = 0; | |
1286 | 1286 | |||
1287 | if (vp->v_type == VDIR) | |||
1288 | return EISDIR; | |||
1289 | ||||
1287 | /* et op? */ | 1290 | /* et op? */ | |
1288 | if (rn->rn_flags & RUMPNODE_ET_PHONE_HOST) | 1291 | if (rn->rn_flags & RUMPNODE_ET_PHONE_HOST) | |
1289 | return etread(rn, uio); | 1292 | return etread(rn, uio); | |
1290 | 1293 | |||
1291 | /* otherwise, it's off to ubc with us */ | 1294 | /* otherwise, it's off to ubc with us */ | |
1292 | while (uio->uio_resid > 0) { | 1295 | while (uio->uio_resid > 0) { | |
1293 | chunk = MIN(uio->uio_resid, (off_t)rn->rn_dlen-uio->uio_offset); | 1296 | chunk = MIN(uio->uio_resid, (off_t)rn->rn_dlen-uio->uio_offset); | |
1294 | if (chunk == 0) | 1297 | if (chunk == 0) | |
1295 | break; | 1298 | break; | |
1296 | error = ubc_uiomove(&vp->v_uobj, uio, chunk, advice, | 1299 | error = ubc_uiomove(&vp->v_uobj, uio, chunk, advice, | |
1297 | UBC_READ | UBC_PARTIALOK | UBC_UNMAP_FLAG(vp)); | 1300 | UBC_READ | UBC_PARTIALOK | UBC_UNMAP_FLAG(vp)); | |
1298 | if (error) | 1301 | if (error) | |
1299 | break; | 1302 | break; |
--- src/tests/fs/vfs/t_vnops.c 2011/10/08 13:08:54 1.29
+++ src/tests/fs/vfs/t_vnops.c 2011/12/12 19:11:22 1.30
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: t_vnops.c,v 1.29 2011/10/08 13:08:54 njoly Exp $ */ | 1 | /* $NetBSD: t_vnops.c,v 1.30 2011/12/12 19:11:22 njoly Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2010 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2010 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -817,54 +817,77 @@ access_simple(const atf_tc_t *tc, const | @@ -817,54 +817,77 @@ access_simple(const atf_tc_t *tc, const | |||
817 | if (FSTYPE_SYSVBFS(tc) || FSTYPE_MSDOS(tc)) | 817 | if (FSTYPE_SYSVBFS(tc) || FSTYPE_MSDOS(tc)) | |
818 | tmode = F_OK; | 818 | tmode = F_OK; | |
819 | else | 819 | else | |
820 | tmode = ALLACC; | 820 | tmode = ALLACC; | |
821 | 821 | |||
822 | RL(rump_sys_access("tfile", tmode)); | 822 | RL(rump_sys_access("tfile", tmode)); | |
823 | 823 | |||
824 | /* PR kern/44648 */ | 824 | /* PR kern/44648 */ | |
825 | ATF_REQUIRE_ERRNO(EINVAL, rump_sys_access("tfile", ALLACC+1) == -1); | 825 | ATF_REQUIRE_ERRNO(EINVAL, rump_sys_access("tfile", ALLACC+1) == -1); | |
826 | #undef ALLACC | 826 | #undef ALLACC | |
827 | FSTEST_EXIT(); | 827 | FSTEST_EXIT(); | |
828 | } | 828 | } | |
829 | 829 | |||
830 | static void | |||
831 | read_directory(const atf_tc_t *tc, const char *mp) | |||
832 | { | |||
833 | char buf[1024]; | |||
834 | int fd, res; | |||
835 | ssize_t size; | |||
836 | ||||
837 | FSTEST_ENTER(); | |||
838 | fd = rump_sys_open(".", O_DIRECTORY | O_RDONLY, 0777); | |||
839 | ATF_REQUIRE(fd != -1); | |||
840 | ||||
841 | size = rump_sys_pread(fd, buf, sizeof(buf), 0); | |||
842 | ATF_CHECK(size != -1 || errno == EISDIR); | |||
843 | size = rump_sys_read(fd, buf, sizeof(buf)); | |||
844 | ATF_CHECK(size != -1 || errno == EISDIR); | |||
845 | ||||
846 | res = rump_sys_close(fd); | |||
847 | ATF_REQUIRE(res != -1); | |||
848 | FSTEST_EXIT(); | |||
849 | } | |||
850 | ||||
830 | ATF_TC_FSAPPLY(lookup_simple, "simple lookup (./.. on root)"); | 851 | ATF_TC_FSAPPLY(lookup_simple, "simple lookup (./.. on root)"); | |
831 | ATF_TC_FSAPPLY(lookup_complex, "lookup of non-dot entries"); | 852 | ATF_TC_FSAPPLY(lookup_complex, "lookup of non-dot entries"); | |
832 | ATF_TC_FSAPPLY(dir_simple, "mkdir/rmdir"); | 853 | ATF_TC_FSAPPLY(dir_simple, "mkdir/rmdir"); | |
833 | ATF_TC_FSAPPLY(dir_notempty, "non-empty directories cannot be removed"); | 854 | ATF_TC_FSAPPLY(dir_notempty, "non-empty directories cannot be removed"); | |
834 | ATF_TC_FSAPPLY(dir_rmdirdotdot, "remove .. and try to cd out"); | 855 | ATF_TC_FSAPPLY(dir_rmdirdotdot, "remove .. and try to cd out"); | |
835 | ATF_TC_FSAPPLY(rename_dir, "exercise various directory renaming ops"); | 856 | ATF_TC_FSAPPLY(rename_dir, "exercise various directory renaming ops"); | |
836 | ATF_TC_FSAPPLY(rename_dotdot, "rename dir .."); | 857 | ATF_TC_FSAPPLY(rename_dotdot, "rename dir .."); | |
837 | ATF_TC_FSAPPLY(rename_reg_nodir, "rename regular files, no subdirectories"); | 858 | ATF_TC_FSAPPLY(rename_reg_nodir, "rename regular files, no subdirectories"); | |
838 | ATF_TC_FSAPPLY(create_nametoolong, "create file with name too long"); | 859 | ATF_TC_FSAPPLY(create_nametoolong, "create file with name too long"); | |
839 | ATF_TC_FSAPPLY(create_exist, "create with O_EXCL"); | 860 | ATF_TC_FSAPPLY(create_exist, "create with O_EXCL"); | |
840 | ATF_TC_FSAPPLY(rename_nametoolong, "rename to file with name too long"); | 861 | ATF_TC_FSAPPLY(rename_nametoolong, "rename to file with name too long"); | |
841 | ATF_TC_FSAPPLY(symlink_zerolen, "symlink with 0-len target"); | 862 | ATF_TC_FSAPPLY(symlink_zerolen, "symlink with 0-len target"); | |
842 | ATF_TC_FSAPPLY(symlink_root, "symlink to root directory"); | 863 | ATF_TC_FSAPPLY(symlink_root, "symlink to root directory"); | |
843 | ATF_TC_FSAPPLY(attrs, "check setting attributes works"); | 864 | ATF_TC_FSAPPLY(attrs, "check setting attributes works"); | |
844 | ATF_TC_FSAPPLY(fcntl_lock, "check fcntl F_SETLK"); | 865 | ATF_TC_FSAPPLY(fcntl_lock, "check fcntl F_SETLK"); | |
845 | ATF_TC_FSAPPLY(fcntl_getlock_pids,"fcntl F_GETLK w/ many procs, PR kern/44494"); | 866 | ATF_TC_FSAPPLY(fcntl_getlock_pids,"fcntl F_GETLK w/ many procs, PR kern/44494"); | |
846 | ATF_TC_FSAPPLY(access_simple, "access(2)"); | 867 | ATF_TC_FSAPPLY(access_simple, "access(2)"); | |
868 | ATF_TC_FSAPPLY(read_directory, "read(2) on directories"); | |||
847 | 869 | |||
848 | ATF_TP_ADD_TCS(tp) | 870 | ATF_TP_ADD_TCS(tp) | |
849 | { | 871 | { | |
850 | 872 | |||
851 | ATF_TP_FSAPPLY(lookup_simple); | 873 | ATF_TP_FSAPPLY(lookup_simple); | |
852 | ATF_TP_FSAPPLY(lookup_complex); | 874 | ATF_TP_FSAPPLY(lookup_complex); | |
853 | ATF_TP_FSAPPLY(dir_simple); | 875 | ATF_TP_FSAPPLY(dir_simple); | |
854 | ATF_TP_FSAPPLY(dir_notempty); | 876 | ATF_TP_FSAPPLY(dir_notempty); | |
855 | ATF_TP_FSAPPLY(dir_rmdirdotdot); | 877 | ATF_TP_FSAPPLY(dir_rmdirdotdot); | |
856 | ATF_TP_FSAPPLY(rename_dir); | 878 | ATF_TP_FSAPPLY(rename_dir); | |
857 | ATF_TP_FSAPPLY(rename_dotdot); | 879 | ATF_TP_FSAPPLY(rename_dotdot); | |
858 | ATF_TP_FSAPPLY(rename_reg_nodir); | 880 | ATF_TP_FSAPPLY(rename_reg_nodir); | |
859 | ATF_TP_FSAPPLY(create_nametoolong); | 881 | ATF_TP_FSAPPLY(create_nametoolong); | |
860 | ATF_TP_FSAPPLY(create_exist); | 882 | ATF_TP_FSAPPLY(create_exist); | |
861 | ATF_TP_FSAPPLY(rename_nametoolong); | 883 | ATF_TP_FSAPPLY(rename_nametoolong); | |
862 | ATF_TP_FSAPPLY(symlink_zerolen); | 884 | ATF_TP_FSAPPLY(symlink_zerolen); | |
863 | ATF_TP_FSAPPLY(symlink_root); | 885 | ATF_TP_FSAPPLY(symlink_root); | |
864 | ATF_TP_FSAPPLY(attrs); | 886 | ATF_TP_FSAPPLY(attrs); | |
865 | ATF_TP_FSAPPLY(fcntl_lock); | 887 | ATF_TP_FSAPPLY(fcntl_lock); | |
866 | ATF_TP_FSAPPLY(fcntl_getlock_pids); | 888 | ATF_TP_FSAPPLY(fcntl_getlock_pids); | |
867 | ATF_TP_FSAPPLY(access_simple); | 889 | ATF_TP_FSAPPLY(access_simple); | |
890 | ATF_TP_FSAPPLY(read_directory); | |||
868 | 891 | |||
869 | return atf_no_error(); | 892 | return atf_no_error(); | |
870 | } | 893 | } |