diff options
author | Peter Wemm <peter@FreeBSD.org> | 1999-11-08 03:27:14 +0000 |
---|---|---|
committer | Peter Wemm <peter@FreeBSD.org> | 1999-11-08 03:27:14 +0000 |
commit | cf87559cabc34b5a26ce24bb0ae167d5f689d1b7 (patch) | |
tree | 979ee0a0ee867ccfe223838f9476922d4b922a15 /sys/kern/kern_descrip.c | |
parent | a2eec8ee15eeabb3c1d32dd9fe4571b1369246dd (diff) | |
download | src-cf87559cabc34b5a26ce24bb0ae167d5f689d1b7.tar.gz src-cf87559cabc34b5a26ce24bb0ae167d5f689d1b7.zip |
Use fo_stat() rather than duplicating knowledge of file type internals
in here for stat(2) and friends. Update the badops entries accordingly.
Notes
Notes:
svn path=/head/; revision=52982
Diffstat (limited to 'sys/kern/kern_descrip.c')
-rw-r--r-- | sys/kern/kern_descrip.c | 75 |
1 files changed, 16 insertions, 59 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index ae9aca359b06..6f4ed7595427 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -95,7 +95,9 @@ static int badfo_ioctl __P((struct file *fp, u_long com, caddr_t data, struct proc *p)); static int badfo_poll __P((struct file *fp, int events, struct ucred *cred, struct proc *p)); +static int badfo_stat __P((struct file *fp, struct stat *sb, struct proc *p)); static int badfo_close __P((struct file *fp, struct proc *p)); + /* * Descriptor management. */ @@ -538,25 +540,7 @@ ofstat(p, uap) if ((unsigned)uap->fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[uap->fd]) == NULL) return (EBADF); - switch (fp->f_type) { - - case DTYPE_FIFO: - case DTYPE_VNODE: - error = vn_stat((struct vnode *)fp->f_data, &ub, p); - break; - - case DTYPE_SOCKET: - error = soo_stat((struct socket *)fp->f_data, &ub); - break; - - case DTYPE_PIPE: - error = pipe_stat((struct pipe *)fp->f_data, &ub); - break; - - default: - panic("ofstat"); - /*NOTREACHED*/ - } + error = fo_stat(fp, &ub, p); cvtstat(&ub, &oub); if (error == 0) error = copyout((caddr_t)&oub, (caddr_t)uap->sb, sizeof (oub)); @@ -587,25 +571,7 @@ fstat(p, uap) if ((unsigned)uap->fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[uap->fd]) == NULL) return (EBADF); - switch (fp->f_type) { - - case DTYPE_FIFO: - case DTYPE_VNODE: - error = vn_stat((struct vnode *)fp->f_data, &ub, p); - break; - - case DTYPE_SOCKET: - error = soo_stat((struct socket *)fp->f_data, &ub); - break; - - case DTYPE_PIPE: - error = pipe_stat((struct pipe *)fp->f_data, &ub); - break; - - default: - panic("fstat"); - /*NOTREACHED*/ - } + error = fo_stat(fp, &ub, p); if (error == 0) error = copyout((caddr_t)&ub, (caddr_t)uap->sb, sizeof (ub)); return (error); @@ -635,25 +601,7 @@ nfstat(p, uap) if ((unsigned)uap->fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[uap->fd]) == NULL) return (EBADF); - switch (fp->f_type) { - - case DTYPE_FIFO: - case DTYPE_VNODE: - error = vn_stat((struct vnode *)fp->f_data, &ub, p); - break; - - case DTYPE_SOCKET: - error = soo_stat((struct socket *)fp->f_data, &ub); - break; - - case DTYPE_PIPE: - error = pipe_stat((struct pipe *)fp->f_data, &ub); - break; - - default: - panic("fstat"); - /*NOTREACHED*/ - } + error = fo_stat(fp, &ub, p); if (error == 0) { cvtnstat(&ub, &nub); error = copyout((caddr_t)&nub, (caddr_t)uap->sb, sizeof (nub)); @@ -1314,6 +1262,7 @@ struct fileops badfileops = { badfo_readwrite, badfo_ioctl, badfo_poll, + badfo_stat, badfo_close }; @@ -1352,6 +1301,16 @@ badfo_poll(fp, events, cred, p) } static int +badfo_stat(fp, sb, p) + struct file *fp; + struct stat *sb; + struct proc *p; +{ + + return (EBADF); +} + +static int badfo_close(fp, p) struct file *fp; struct proc *p; @@ -1362,5 +1321,3 @@ badfo_close(fp, p) SYSINIT(fildescdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, fildesc_drvinit,NULL) - - |