From 0c4b824b005939b4424be62d3386d7a51d3417e0 Mon Sep 17 00:00:00 2001
From: Kanonenvogel <kanonenvogel.87g@gmail.com>
Date: Tue, 14 Apr 2015 04:41:56 +0400
Subject: [PATCH 2/4] getvnode() api modification

---
 compat/linux/linux_misc.c |  2 +-
 dev/diskmap.c             |  2 +-
 kern/vfs_syscalls.c       | 20 ++++++++++----------
 sys/vnode.h               |  2 +-
 uvm/uvm_mmap.c            |  2 +-
 5 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/compat/linux/linux_misc.c b/compat/linux/linux_misc.c
index 357d8de..fda7cd8 100644
--- a/compat/linux/linux_misc.c
+++ b/compat/linux/linux_misc.c
@@ -1183,7 +1183,7 @@ getdents_common(p, v, retval, is64bit)
 	int error;
 	int nbytes = SCARG(uap, count);
 
-	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
+	if ((error = getvnode(p, SCARG(uap, fd), &fp)) != 0)
 		return (error);
 
 	if (nbytes == 1) {	/* emulating old, broken behaviour */
diff --git a/dev/diskmap.c b/dev/diskmap.c
index 9948756..22e8b2d 100644
--- a/dev/diskmap.c
+++ b/dev/diskmap.c
@@ -82,7 +82,7 @@ diskmapioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
 	fdp = p->p_fd;
 	fdplock(fdp);
 
-	if ((error = getvnode(fdp, fd, &fp)) != 0)
+	if ((error = getvnode(p, fd, &fp)) != 0)
 		goto bad;
 
 	ndp.ni_segflg = UIO_SYSSPACE;
diff --git a/kern/vfs_syscalls.c b/kern/vfs_syscalls.c
index 8cabaa1..6a3a2c8 100644
--- a/kern/vfs_syscalls.c
+++ b/kern/vfs_syscalls.c
@@ -592,7 +592,7 @@ sys_fstatfs(struct proc *p, void *v, register_t *retval)
 	struct statfs *sp;
 	int error;
 
-	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
+	if ((error = getvnode(p, SCARG(uap, fd), &fp)) != 0)
 		return (error);
 	mp = ((struct vnode *)fp->f_data)->v_mount;
 	if (!mp) {
@@ -1884,7 +1884,7 @@ sys_fchflags(struct proc *p, void *v, register_t *retval)
 	struct vnode *vp;
 	int error;
 
-	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
+	if ((error = getvnode(p, SCARG(uap, fd), &fp)) != 0)
 		return (error);
 	vp = fp->f_data;
 	vref(vp);
@@ -2000,7 +2000,7 @@ sys_fchmod(struct proc *p, void *v, register_t *retval)
 	if (SCARG(uap, mode) & ~(S_IFMT | ALLPERMS))
 		return (EINVAL);
 
-	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
+	if ((error = getvnode(p, SCARG(uap, fd), &fp)) != 0)
 		return (error);
 	vp = (struct vnode *)fp->f_data;
 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
@@ -2162,7 +2162,7 @@ sys_fchown(struct proc *p, void *v, register_t *retval)
 	uid_t uid = SCARG(uap, uid);
 	gid_t gid = SCARG(uap, gid);
 
-	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
+	if ((error = getvnode(p, SCARG(uap, fd), &fp)) != 0)
 		return (error);
 	vp = (struct vnode *)fp->f_data;
 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
@@ -2380,7 +2380,7 @@ dofutimens(struct proc *p, int fd, struct timespec ts[2])
 	struct vnode *vp;
 	int error;
 
-	if ((error = getvnode(p->p_fd, fd, &fp)) != 0)
+	if ((error = getvnode(p, fd, &fp)) != 0)
 		return (error);
 	vp = (struct vnode *)fp->f_data;
 	vref(vp);
@@ -2441,7 +2441,7 @@ sys_ftruncate(struct proc *p, void *v, register_t *retval)
 	off_t len;
 	int error;
 
-	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
+	if ((error = getvnode(p, SCARG(uap, fd), &fp)) != 0)
 		return (error);
 	len = SCARG(uap, length);
 	if ((fp->f_flag & FWRITE) == 0 || len < 0) {
@@ -2477,7 +2477,7 @@ sys_fsync(struct proc *p, void *v, register_t *retval)
 	struct file *fp;
 	int error;
 
-	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
+	if ((error = getvnode(p, SCARG(uap, fd), &fp)) != 0)
 		return (error);
 	vp = (struct vnode *)fp->f_data;
 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
@@ -2696,7 +2696,7 @@ sys_getdents(struct proc *p, void *v, register_t *retval)
 
 	if (buflen > INT_MAX)
 		return EINVAL;
-	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
+	if ((error = getvnode(p, SCARG(uap, fd), &fp)) != 0)
 		return (error);
 	if ((fp->f_flag & FREAD) == 0) {
 		error = EBADF;
@@ -2787,12 +2787,12 @@ out:
  * On return *fpp is FREF:ed.
  */
 int
-getvnode(struct filedesc *fdp, int fd, struct file **fpp)
+getvnode(struct proc *p, int fd, struct file **fpp)
 {
 	struct file *fp;
 	struct vnode *vp;
 
-	if ((fp = fd_getfile(fdp, fd)) == NULL)
+	if ((fp = fd_getfile(p->p_fd, fd)) == NULL)
 		return (EBADF);
 
 	if (fp->f_type != DTYPE_VNODE)
diff --git a/sys/vnode.h b/sys/vnode.h
index b9dc772..81e12bf 100644
--- a/sys/vnode.h
+++ b/sys/vnode.h
@@ -650,7 +650,7 @@ void	vn_syncer_add_to_worklist(struct vnode *, int);
 /* misc */
 int	vn_isdisk(struct vnode *, int *);
 int	softdep_fsync(struct vnode *);
-int 	getvnode(struct filedesc *, int, struct file **);
+int 	getvnode(struct proc *, int, struct file **);
 
 /* uvm */
 void	uvm_vnp_setsize(struct vnode *, off_t);
diff --git a/uvm/uvm_mmap.c b/uvm/uvm_mmap.c
index b2d749c..a45a12f 100644
--- a/uvm/uvm_mmap.c
+++ b/uvm/uvm_mmap.c
@@ -141,7 +141,7 @@ sys_mquery(struct proc *p, void *v, register_t *retval)
 		flags |= UVM_FLAG_FIXED;
 
 	if (fd >= 0) {
-		if ((error = getvnode(p->p_fd, fd, &fp)) != 0)
+		if ((error = getvnode(p, fd, &fp)) != 0)
 			return (error);
 		uobj = &((struct vnode *)fp->f_data)->v_uvm->u_obj;
 		uoff = SCARG(uap, pos);
-- 
1.9.3

