diff options
author | 2018-05-09 08:42:02 +0000 | |
---|---|---|
committer | 2018-05-09 08:42:02 +0000 | |
commit | 9e62193759664cae5f8b191cae88100fa3897ec9 (patch) | |
tree | 149e073d9c4ce0ec4f1fdfd5bb1573e6cb544dde | |
parent | Another check for NULL window if looking for index. (diff) | |
download | wireguard-openbsd-9e62193759664cae5f8b191cae88100fa3897ec9.tar.xz wireguard-openbsd-9e62193759664cae5f8b191cae88100fa3897ec9.zip |
Mark `f_ops' as immutable.
The only place where it was modified after initialization is a corner
case where the vnode of an open file is substitued by another one. Sine
the type of the file doesn't change, there's no need to overwrite `f_ops'.
While here proctect file counters with `f_mtx'.
ok bluhm@, visa@
-rw-r--r-- | sys/dev/diskmap.c | 12 | ||||
-rw-r--r-- | sys/sys/file.h | 4 |
2 files changed, 9 insertions, 7 deletions
diff --git a/sys/dev/diskmap.c b/sys/dev/diskmap.c index 75418fff9f5..afc0cf323fb 100644 --- a/sys/dev/diskmap.c +++ b/sys/dev/diskmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diskmap.c,v 1.19 2018/05/02 02:24:55 visa Exp $ */ +/* $OpenBSD: diskmap.c,v 1.20 2018/05/09 08:42:02 mpi Exp $ */ /* * Copyright (c) 2009, 2010 Joel Sing <jsing@openbsd.org> @@ -56,7 +56,7 @@ diskmapioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) { struct dk_diskmap *dm; struct nameidata ndp; - struct filedesc *fdp; + struct filedesc *fdp = p->p_fd; struct file *fp = NULL; struct vnode *vp = NULL, *ovp; char *devname; @@ -83,7 +83,9 @@ diskmapioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) if ((error = getvnode(p, fd, &fp)) != 0) goto invalid; - fdp = p->p_fd; + KASSERT(fp->f_type == DTYPE_VNODE); + KASSERT(fp->f_ops == &vnops); + fdplock(fdp); NDINIT(&ndp, 0, 0, UIO_SYSSPACE, devname, p); @@ -104,15 +106,15 @@ diskmapioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) vput(ovp); } - fp->f_type = DTYPE_VNODE; - fp->f_ops = &vnops; fp->f_data = (caddr_t)vp; fp->f_offset = 0; + mtx_enter(&fp->f_mtx); fp->f_rxfer = 0; fp->f_wxfer = 0; fp->f_seek = 0; fp->f_rbytes = 0; fp->f_wbytes = 0; + mtx_leave(&fp->f_mtx); VOP_UNLOCK(vp); diff --git a/sys/sys/file.h b/sys/sys/file.h index 1866491e5c6..042238ebd3f 100644 --- a/sys/sys/file.h +++ b/sys/sys/file.h @@ -1,4 +1,4 @@ -/* $OpenBSD: file.h,v 1.44 2018/05/08 14:43:24 mpi Exp $ */ +/* $OpenBSD: file.h,v 1.45 2018/05/09 08:42:02 mpi Exp $ */ /* $NetBSD: file.h,v 1.11 1995/03/26 20:24:13 jtc Exp $ */ /* @@ -79,7 +79,7 @@ struct file { short f_type; /* [I] descriptor type */ long f_count; /* [k] reference count */ struct ucred *f_cred; /* [I] credentials associated with descriptor */ - struct fileops *f_ops; /* [k] file operation pointers */ + struct fileops *f_ops; /* [I] file operation pointers */ off_t f_offset; /* [k] */ void *f_data; /* [k] private data */ int f_iflags; /* [k] internal flags */ |