Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Start making fs read(2) fail with EISDIR if the implementati...
details: https://anonhg.NetBSD.org/src/rev/02cc9fa43bb9
branches: trunk
changeset: 771992:02cc9fa43bb9
user: njoly <njoly%NetBSD.org@localhost>
date: Mon Dec 12 19:11:21 2011 +0000
description:
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.
diffstat:
lib/libc/sys/read.2 | 14 ++++++++++++--
sys/fs/ptyfs/ptyfs_vnops.c | 7 +++++--
sys/fs/sysvbfs/sysvbfs_vnops.c | 12 +++++++++---
sys/miscfs/kernfs/kernfs_vnops.c | 6 +++---
sys/rump/librump/rumpvfs/rumpfs.c | 7 +++++--
tests/fs/vfs/t_vnops.c | 25 ++++++++++++++++++++++++-
6 files changed, 58 insertions(+), 13 deletions(-)
diffs (205 lines):
diff -r d76b606ffd7c -r 02cc9fa43bb9 lib/libc/sys/read.2
--- a/lib/libc/sys/read.2 Mon Dec 12 19:03:07 2011 +0000
+++ b/lib/libc/sys/read.2 Mon Dec 12 19:11:21 2011 +0000
@@ -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 @@
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,
diff -r d76b606ffd7c -r 02cc9fa43bb9 sys/fs/ptyfs/ptyfs_vnops.c
--- a/sys/fs/ptyfs/ptyfs_vnops.c Mon Dec 12 19:03:07 2011 +0000
+++ b/sys/fs/ptyfs/ptyfs_vnops.c Mon Dec 12 19:11:21 2011 +0000
@@ -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 @@
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);
diff -r d76b606ffd7c -r 02cc9fa43bb9 sys/fs/sysvbfs/sysvbfs_vnops.c
--- a/sys/fs/sysvbfs/sysvbfs_vnops.c Mon Dec 12 19:03:07 2011 +0000
+++ b/sys/fs/sysvbfs/sysvbfs_vnops.c Mon Dec 12 19:11:21 2011 +0000
@@ -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 @@
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)
diff -r d76b606ffd7c -r 02cc9fa43bb9 sys/miscfs/kernfs/kernfs_vnops.c
--- a/sys/miscfs/kernfs/kernfs_vnops.c Mon Dec 12 19:03:07 2011 +0000
+++ b/sys/miscfs/kernfs/kernfs_vnops.c Mon Dec 12 19:11:21 2011 +0000
@@ -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 @@
int error;
if (ap->a_vp->v_type == VDIR)
- return (EOPNOTSUPP);
+ return EISDIR;
off = (int)uio->uio_offset;
/* Don't allow negative offsets */
diff -r d76b606ffd7c -r 02cc9fa43bb9 sys/rump/librump/rumpvfs/rumpfs.c
--- a/sys/rump/librump/rumpvfs/rumpfs.c Mon Dec 12 19:03:07 2011 +0000
+++ b/sys/rump/librump/rumpvfs/rumpfs.c Mon Dec 12 19:11:21 2011 +0000
@@ -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 @@
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);
diff -r d76b606ffd7c -r 02cc9fa43bb9 tests/fs/vfs/t_vnops.c
--- a/tests/fs/vfs/t_vnops.c Mon Dec 12 19:03:07 2011 +0000
+++ b/tests/fs/vfs/t_vnops.c Mon Dec 12 19:11:21 2011 +0000
@@ -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 @@
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(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_FSAPPLY(fcntl_lock);
ATF_TP_FSAPPLY(fcntl_getlock_pids);
ATF_TP_FSAPPLY(access_simple);
+ ATF_TP_FSAPPLY(read_directory);
return atf_no_error();
}
Home |
Main Index |
Thread Index |
Old Index