- * Convert a user supplied
- * file descriptor into a pointer
- * to a file structure.
- * Only task is to check range
- * of the descriptor.
- */
-struct file *
-getf(f)
-register int f;
-{
- register struct file *fp;
-
- if(0 <= f && f < NOFILE) {
- fp = u.u_ofile[f];
- if(fp != NULL)
- return(fp);
- }
- u.u_error = EBADF;
- return(NULL);
-}
-
-/*
- * Internal form of close.
- * Decrement reference count on
- * file structure.
- * Also make sure the pipe protocol
- * does not constipate.
- *
- * Decrement reference count on the inode following
- * removal to the referencing file structure.
- * Call device handler on last close.
- */
-closef(fp)
-register struct file *fp;
-{
- register struct inode *ip;
- int flag, mode;
- dev_t dev;
- register int (*cfunc)();
-
- if(fp == NULL)
- return;
- if (fp->f_count > 1) {
- fp->f_count--;
- return;
- }
- ip = fp->f_inode;
- flag = fp->f_flag;
- dev = (dev_t)ip->i_un.i_rdev;
- mode = ip->i_mode;
-
- plock(ip);
- fp->f_count = 0;
- if(flag & FPIPE) {
- ip->i_mode &= ~(IREAD|IWRITE);
- wakeup((caddr_t)ip+1);
- wakeup((caddr_t)ip+2);
- }
- iput(ip);
-
- switch(mode&IFMT) {
-
- case IFCHR:
- case IFMPC:
- cfunc = cdevsw[major(dev)].d_close;
- break;
-
- case IFBLK:
- case IFMPB:
- cfunc = bdevsw[major(dev)].d_close;
- break;
- default:
- return;
- }
-
- if (flag & FMP)
- goto call;
-
- for(fp=file; fp < &file[NFILE]; fp++)
- if (fp->f_count && (ip=fp->f_inode)->i_un.i_rdev==dev &&
- (ip->i_mode&IFMT) == (mode&IFMT))
- return;
-
-call:
- (*cfunc)(dev, flag, fp);
-}
-
-/*
- * openi called to allow handler