Add two additional arguments to the fileops read and write calls, a

pointer to the offset to use, and a flags word.  Define a flag that
specifies whether or not to update the offset passed by reference.
This commit is contained in:
thorpej 1998-06-30 05:33:11 +00:00
parent 047edc1df7
commit a4a34ba74a
7 changed files with 60 additions and 33 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_ktrace.c,v 1.29 1998/06/25 21:17:16 thorpej Exp $ */
/* $NetBSD: kern_ktrace.c,v 1.30 1998/06/30 05:33:12 thorpej Exp $ */
/*
* Copyright (c) 1989, 1993
@ -594,7 +594,8 @@ ktrwrite(p, v, kth)
if (p->p_traceflag & KTRFAC_FD) {
struct file *fp = v;
error = (*fp->f_ops->fo_write)(fp, &auio, fp->f_cred);
error = (*fp->f_ops->fo_write)(fp, &fp->f_offset, &auio,
fp->f_cred, FOF_UPDATE_OFFSET);
}
else {
struct vnode *vp = v;

View File

@ -1,4 +1,4 @@
/* $NetBSD: sys_generic.c,v 1.37 1998/06/25 21:17:17 thorpej Exp $ */
/* $NetBSD: sys_generic.c,v 1.38 1998/06/30 05:33:12 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@ -111,8 +111,9 @@ sys_read(p, v, retval)
if (KTRPOINT(p, KTR_GENIO))
ktriov = aiov;
#endif
cnt = SCARG(uap, nbyte);
error = (*fp->f_ops->fo_read)(fp, &auio, fp->f_cred);
cnt = auio.uio_resid;
error = (*fp->f_ops->fo_read)(fp, &fp->f_offset, &auio, fp->f_cred,
FOF_UPDATE_OFFSET);
if (error)
if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
@ -196,7 +197,8 @@ sys_readv(p, v, retval)
}
#endif
cnt = auio.uio_resid;
error = (*fp->f_ops->fo_read)(fp, &auio, fp->f_cred);
error = (*fp->f_ops->fo_read)(fp, &fp->f_offset, &auio, fp->f_cred,
FOF_UPDATE_OFFSET);
if (error)
if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
@ -262,8 +264,9 @@ sys_write(p, v, retval)
if (KTRPOINT(p, KTR_GENIO))
ktriov = aiov;
#endif
cnt = SCARG(uap, nbyte);
error = (*fp->f_ops->fo_write)(fp, &auio, fp->f_cred);
cnt = auio.uio_resid;
error = (*fp->f_ops->fo_write)(fp, &fp->f_offset, &auio, fp->f_cred,
FOF_UPDATE_OFFSET);
if (error) {
if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
@ -350,7 +353,8 @@ sys_writev(p, v, retval)
}
#endif
cnt = auio.uio_resid;
error = (*fp->f_ops->fo_write)(fp, &auio, fp->f_cred);
error = (*fp->f_ops->fo_write)(fp, &fp->f_offset, &auio, fp->f_cred,
FOF_UPDATE_OFFSET);
if (error) {
if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))

View File

@ -1,4 +1,4 @@
/* $NetBSD: sys_socket.c,v 1.17 1998/04/25 17:35:18 matt Exp $ */
/* $NetBSD: sys_socket.c,v 1.18 1998/06/30 05:33:12 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1990, 1993
@ -54,10 +54,12 @@ struct fileops socketops =
/* ARGSUSED */
int
soo_read(fp, uio, cred)
soo_read(fp, offset, uio, cred, flags)
struct file *fp;
off_t *offset;
struct uio *uio;
struct ucred *cred;
int flags;
{
struct socket *so = (struct socket *) fp->f_data;
return ((*so->so_receive)(so, (struct mbuf **)0,
@ -66,10 +68,12 @@ soo_read(fp, uio, cred)
/* ARGSUSED */
int
soo_write(fp, uio, cred)
soo_write(fp, offset, uio, cred, flags)
struct file *fp;
off_t *offset;
struct uio *uio;
struct ucred *cred;
int flags;
{
struct socket *so = (struct socket *) fp->f_data;
return ((*so->so_send)(so, (struct mbuf *)0,

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_vnops.c,v 1.28 1998/03/01 02:22:36 fvdl Exp $ */
/* $NetBSD: vfs_vnops.c,v 1.29 1998/06/30 05:33:12 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@ -347,21 +347,24 @@ unionread:
* File table vnode read routine.
*/
int
vn_read(fp, uio, cred)
vn_read(fp, offset, uio, cred, flags)
struct file *fp;
off_t *offset;
struct uio *uio;
struct ucred *cred;
int flags;
{
struct vnode *vp = (struct vnode *)fp->f_data;
int count, error;
VOP_LEASE(vp, uio->uio_procp, cred, LEASE_READ);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
uio->uio_offset = fp->f_offset;
uio->uio_offset = *offset;
count = uio->uio_resid;
error = VOP_READ(vp, uio, (fp->f_flag & FNONBLOCK) ? IO_NDELAY : 0,
cred);
fp->f_offset += count - uio->uio_resid;
if (flags & FOF_UPDATE_OFFSET)
*offset += count - uio->uio_resid;
VOP_UNLOCK(vp, 0);
return (error);
}
@ -370,10 +373,12 @@ vn_read(fp, uio, cred)
* File table vnode write routine.
*/
int
vn_write(fp, uio, cred)
vn_write(fp, offset, uio, cred, flags)
struct file *fp;
off_t *offset;
struct uio *uio;
struct ucred *cred;
int flags;
{
struct vnode *vp = (struct vnode *)fp->f_data;
int count, error, ioflag = IO_UNIT;
@ -387,13 +392,15 @@ vn_write(fp, uio, cred)
ioflag |= IO_SYNC;
VOP_LEASE(vp, uio->uio_procp, cred, LEASE_WRITE);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
uio->uio_offset = fp->f_offset;
uio->uio_offset = *offset;
count = uio->uio_resid;
error = VOP_WRITE(vp, uio, ioflag, cred);
if (ioflag & IO_APPEND)
fp->f_offset = uio->uio_offset;
else
fp->f_offset += count - uio->uio_resid;
if (flags & FOF_UPDATE_OFFSET) {
if (ioflag & IO_APPEND)
*offset = uio->uio_offset;
else
*offset += count - uio->uio_resid;
}
VOP_UNLOCK(vp, 0);
return (error);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: file.h,v 1.14 1998/03/01 02:24:12 fvdl Exp $ */
/* $NetBSD: file.h,v 1.15 1998/06/30 05:33:11 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@ -61,10 +61,12 @@ struct file {
short f_msgcount; /* references from message queue */
struct ucred *f_cred; /* credentials associated with descriptor */
struct fileops {
int (*fo_read) __P((struct file *fp, struct uio *uio,
struct ucred *cred));
int (*fo_write) __P((struct file *fp, struct uio *uio,
struct ucred *cred));
int (*fo_read) __P((struct file *fp, off_t *offset,
struct uio *uio,
struct ucred *cred, int flags));
int (*fo_write) __P((struct file *fp, off_t *offset,
struct uio *uio,
struct ucred *cred, int flags));
int (*fo_ioctl) __P((struct file *fp, u_long com,
caddr_t data, struct proc *p));
int (*fo_poll) __P((struct file *fp, int events,
@ -75,6 +77,11 @@ struct file {
caddr_t f_data; /* vnode or socket */
};
/*
* Flags for fo_read and fo_write.
*/
#define FOF_UPDATE_OFFSET 0x01 /* update the file offset */
LIST_HEAD(filelist, file);
extern struct filelist filehead; /* head of list of open files */
extern int maxfiles; /* kernel limit on number of open files */

View File

@ -1,4 +1,4 @@
/* $NetBSD: socketvar.h,v 1.29 1998/04/25 17:32:24 matt Exp $ */
/* $NetBSD: socketvar.h,v 1.30 1998/06/30 05:33:11 thorpej Exp $ */
/*-
* Copyright (c) 1982, 1986, 1990, 1993
@ -233,8 +233,10 @@ struct stat;
/*
* File operations on sockets.
*/
int soo_read __P((struct file *fp, struct uio *uio, struct ucred *cred));
int soo_write __P((struct file *fp, struct uio *uio, struct ucred *cred));
int soo_read __P((struct file *fp, off_t *offset, struct uio *uio,
struct ucred *cred, int flags));
int soo_write __P((struct file *fp, off_t *offset, struct uio *uio,
struct ucred *cred, int flags));
int soo_ioctl __P((struct file *fp, u_long cmd, caddr_t data,
struct proc *p));
int soo_poll __P((struct file *fp, int events, struct proc *p));

View File

@ -1,4 +1,4 @@
/* $NetBSD: vnode.h,v 1.50 1998/06/05 19:47:00 kleink Exp $ */
/* $NetBSD: vnode.h,v 1.51 1998/06/30 05:33:12 thorpej Exp $ */
/*
* Copyright (c) 1989, 1993
@ -472,12 +472,14 @@ int vn_open __P((struct nameidata *ndp, int fmode, int cmode));
int vn_rdwr __P((enum uio_rw rw, struct vnode *vp, caddr_t base,
int len, off_t offset, enum uio_seg segflg, int ioflg,
struct ucred *cred, int *aresid, struct proc *p));
int vn_read __P((struct file *fp, struct uio *uio, struct ucred *cred));
int vn_read __P((struct file *fp, off_t *offset, struct uio *uio,
struct ucred *cred, int flags));
int vn_readdir __P((struct file *fp, char *buf, int segflg, u_int count,
int *done, struct proc *p, off_t **cookies, int *ncookies));
int vn_poll __P((struct file *fp, int events, struct proc *p));
int vn_stat __P((struct vnode *vp, struct stat *sb, struct proc *p));
int vn_write __P((struct file *fp, struct uio *uio, struct ucred *cred));
int vn_write __P((struct file *fp, off_t *offset, struct uio *uio,
struct ucred *cred, int flags));
int vn_writechk __P((struct vnode *vp));
struct vnode *
checkalias __P((struct vnode *vp, dev_t nvp_rdev, struct mount *mp));