Module Name:    src
Committed By:   njoly
Date:           Mon Dec 12 19:11:23 UTC 2011

Modified Files:
        src/lib/libc/sys: read.2
        src/sys/fs/ptyfs: ptyfs_vnops.c
        src/sys/fs/sysvbfs: sysvbfs_vnops.c
        src/sys/miscfs/kernfs: kernfs_vnops.c
        src/sys/rump/librump/rumpvfs: rumpfs.c
        src/tests/fs/vfs: t_vnops.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/lib/libc/sys/read.2
cvs rdiff -u -r1.37 -r1.38 src/sys/fs/ptyfs/ptyfs_vnops.c
cvs rdiff -u -r1.38 -r1.39 src/sys/fs/sysvbfs/sysvbfs_vnops.c
cvs rdiff -u -r1.143 -r1.144 src/sys/miscfs/kernfs/kernfs_vnops.c
cvs rdiff -u -r1.103 -r1.104 src/sys/rump/librump/rumpvfs/rumpfs.c
cvs rdiff -u -r1.29 -r1.30 src/tests/fs/vfs/t_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/sys/read.2
diff -u src/lib/libc/sys/read.2:1.33 src/lib/libc/sys/read.2:1.34
--- src/lib/libc/sys/read.2:1.33	Mon Apr  5 07:53:47 2010
+++ src/lib/libc/sys/read.2	Mon Dec 12 19:11:21 2011
@@ -1,4 +1,4 @@
-.\"	$NetBSD: read.2,v 1.33 2010/04/05 07:53:47 wiz Exp $
+.\"	$NetBSD: read.2,v 1.34 2011/12/12 19:11:21 njoly Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)read.2	8.4 (Berkeley) 2/26/94
 .\"
-.Dd April 3, 2010
+.Dd December 12, 2011
 .Dt READ 2
 .Os
 .Sh NAME
@@ -161,6 +161,16 @@ the total length of the I/O is more than
 return value.
 .It Bq Er EIO
 An I/O error occurred while reading from the file system.
+.It Bq Er EISDIR
+.Fa d
+refers to a directory and the implementation does not allow the directory
+to be read using
+.Fn read
+or
+.Fn pread .
+The
+.Fn readdir
+function should be used instead.
 .El
 .Pp
 In addition,

Index: src/sys/fs/ptyfs/ptyfs_vnops.c
diff -u src/sys/fs/ptyfs/ptyfs_vnops.c:1.37 src/sys/fs/ptyfs/ptyfs_vnops.c:1.38
--- src/sys/fs/ptyfs/ptyfs_vnops.c:1.37	Fri Nov 18 21:18:50 2011
+++ src/sys/fs/ptyfs/ptyfs_vnops.c	Mon Dec 12 19:11:21 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ptyfs_vnops.c,v 1.37 2011/11/18 21:18:50 christos Exp $	*/
+/*	$NetBSD: ptyfs_vnops.c,v 1.38 2011/12/12 19:11:21 njoly Exp $	*/
 
 /*
  * Copyright (c) 1993, 1995
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ptyfs_vnops.c,v 1.37 2011/11/18 21:18:50 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ptyfs_vnops.c,v 1.38 2011/12/12 19:11:21 njoly Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -788,6 +788,9 @@ ptyfs_read(void *v)
 	struct ptyfsnode *ptyfs = VTOPTYFS(vp);
 	int error;
 
+	if (vp->v_type == VDIR)
+		return EISDIR;
+
 	ptyfs->ptyfs_flag |= PTYFS_ACCESS;
 	/* hardclock() resolution is good enough for ptyfs */
 	getnanotime(&ts);

Index: src/sys/fs/sysvbfs/sysvbfs_vnops.c
diff -u src/sys/fs/sysvbfs/sysvbfs_vnops.c:1.38 src/sys/fs/sysvbfs/sysvbfs_vnops.c:1.39
--- src/sys/fs/sysvbfs/sysvbfs_vnops.c:1.38	Thu May 19 03:11:58 2011
+++ src/sys/fs/sysvbfs/sysvbfs_vnops.c	Mon Dec 12 19:11:21 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysvbfs_vnops.c,v 1.38 2011/05/19 03:11:58 rmind Exp $	*/
+/*	$NetBSD: sysvbfs_vnops.c,v 1.39 2011/12/12 19:11:21 njoly Exp $	*/
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysvbfs_vnops.c,v 1.38 2011/05/19 03:11:58 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysvbfs_vnops.c,v 1.39 2011/12/12 19:11:21 njoly Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -378,8 +378,14 @@ sysvbfs_read(void *arg)
 	const int advice = IO_ADV_DECODE(a->a_ioflag);
 
 	DPRINTF("%s: type=%d\n", __func__, v->v_type);
-	if (v->v_type != VREG)
+	switch (v->v_type) {
+	case VREG:
+		break;
+	case VDIR:
+		return EISDIR;
+	default:
 		return EINVAL;
+	}
 
 	while (uio->uio_resid > 0) {
 		if ((sz = MIN(filesz - uio->uio_offset, uio->uio_resid)) == 0)

Index: src/sys/miscfs/kernfs/kernfs_vnops.c
diff -u src/sys/miscfs/kernfs/kernfs_vnops.c:1.143 src/sys/miscfs/kernfs/kernfs_vnops.c:1.144
--- src/sys/miscfs/kernfs/kernfs_vnops.c:1.143	Wed Jul 21 09:06:38 2010
+++ src/sys/miscfs/kernfs/kernfs_vnops.c	Mon Dec 12 19:11:22 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: kernfs_vnops.c,v 1.143 2010/07/21 09:06:38 hannken Exp $	*/
+/*	$NetBSD: kernfs_vnops.c,v 1.144 2011/12/12 19:11:22 njoly Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kernfs_vnops.c,v 1.143 2010/07/21 09:06:38 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kernfs_vnops.c,v 1.144 2011/12/12 19:11:22 njoly Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -941,7 +941,7 @@ kernfs_default_xread(void *v)
 	int error;
 
 	if (ap->a_vp->v_type == VDIR)
-		return (EOPNOTSUPP);
+		return EISDIR;
 
 	off = (int)uio->uio_offset;
 	/* Don't allow negative offsets */

Index: src/sys/rump/librump/rumpvfs/rumpfs.c
diff -u src/sys/rump/librump/rumpvfs/rumpfs.c:1.103 src/sys/rump/librump/rumpvfs/rumpfs.c:1.104
--- src/sys/rump/librump/rumpvfs/rumpfs.c:1.103	Tue Sep 27 14:24:52 2011
+++ src/sys/rump/librump/rumpvfs/rumpfs.c	Mon Dec 12 19:11:22 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpfs.c,v 1.103 2011/09/27 14:24:52 mbalmer Exp $	*/
+/*	$NetBSD: rumpfs.c,v 1.104 2011/12/12 19:11:22 njoly Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.103 2011/09/27 14:24:52 mbalmer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.104 2011/12/12 19:11:22 njoly Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -1284,6 +1284,9 @@ rump_vop_read(void *v)
 	off_t chunk;
 	int error = 0;
 
+	if (vp->v_type == VDIR)
+		return EISDIR;
+
 	/* et op? */
 	if (rn->rn_flags & RUMPNODE_ET_PHONE_HOST)
 		return etread(rn, uio);

Index: src/tests/fs/vfs/t_vnops.c
diff -u src/tests/fs/vfs/t_vnops.c:1.29 src/tests/fs/vfs/t_vnops.c:1.30
--- src/tests/fs/vfs/t_vnops.c:1.29	Sat Oct  8 13:08:54 2011
+++ src/tests/fs/vfs/t_vnops.c	Mon Dec 12 19:11:22 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_vnops.c,v 1.29 2011/10/08 13:08:54 njoly Exp $	*/
+/*	$NetBSD: t_vnops.c,v 1.30 2011/12/12 19:11:22 njoly Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -827,6 +827,27 @@ access_simple(const atf_tc_t *tc, const 
 	FSTEST_EXIT();
 }
 
+static void
+read_directory(const atf_tc_t *tc, const char *mp)
+{
+	char buf[1024];
+	int fd, res;
+	ssize_t size;
+
+	FSTEST_ENTER();
+	fd = rump_sys_open(".", O_DIRECTORY | O_RDONLY, 0777);
+	ATF_REQUIRE(fd != -1);
+
+	size = rump_sys_pread(fd, buf, sizeof(buf), 0);
+	ATF_CHECK(size != -1 || errno == EISDIR);
+	size = rump_sys_read(fd, buf, sizeof(buf));
+	ATF_CHECK(size != -1 || errno == EISDIR);
+
+	res = rump_sys_close(fd);
+	ATF_REQUIRE(res != -1);
+	FSTEST_EXIT();
+}
+
 ATF_TC_FSAPPLY(lookup_simple, "simple lookup (./.. on root)");
 ATF_TC_FSAPPLY(lookup_complex, "lookup of non-dot entries");
 ATF_TC_FSAPPLY(dir_simple, "mkdir/rmdir");
@@ -844,6 +865,7 @@ ATF_TC_FSAPPLY(attrs, "check setting att
 ATF_TC_FSAPPLY(fcntl_lock, "check fcntl F_SETLK");
 ATF_TC_FSAPPLY(fcntl_getlock_pids,"fcntl F_GETLK w/ many procs, PR kern/44494");
 ATF_TC_FSAPPLY(access_simple, "access(2)");
+ATF_TC_FSAPPLY(read_directory, "read(2) on directories");
 
 ATF_TP_ADD_TCS(tp)
 {
@@ -865,6 +887,7 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_FSAPPLY(fcntl_lock);
 	ATF_TP_FSAPPLY(fcntl_getlock_pids);
 	ATF_TP_FSAPPLY(access_simple);
+	ATF_TP_FSAPPLY(read_directory);
 
 	return atf_no_error();
 }

Reply via email to