From f8d77065a111ca8a69e581fcebd556c13a46ee65 Mon Sep 17 00:00:00 2001 From: ache Date: Tue, 20 Jan 2004 01:27:42 +0000 Subject: [PATCH] pread/pwrite: follow lseek spirit - return EINVAL on negative offset for non-VCHR --- sys/kern/sys_generic.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index 881be56f9fb9..e725f8fc1e18 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -63,6 +63,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -138,9 +139,11 @@ pread(td, uap) if ((error = fget_read(td, uap->fd, &fp)) != 0) return (error); - if (!(fp->f_ops->fo_flags & DFLAG_SEEKABLE)) { + if (!(fp->f_ops->fo_flags & DFLAG_SEEKABLE)) error = ESPIPE; - } else { + else if (uap->offset < 0 && fp->f_vnode->v_type != VCHR) + error = EINVAL; + else { error = dofileread(td, fp, uap->fd, uap->buf, uap->nbyte, uap->offset, FOF_OFFSET); } @@ -361,9 +364,11 @@ pwrite(td, uap) int error; if ((error = fget_write(td, uap->fd, &fp)) == 0) { - if (!(fp->f_ops->fo_flags & DFLAG_SEEKABLE)) { + if (!(fp->f_ops->fo_flags & DFLAG_SEEKABLE)) error = ESPIPE; - } else { + else if (uap->offset < 0 && fp->f_vnode->v_type != VCHR) + error = EINVAL; + else { error = dofilewrite(td, fp, uap->fd, uap->buf, uap->nbyte, uap->offset, FOF_OFFSET); }