From: deraadt Date: Sun, 7 Jan 1996 17:38:21 +0000 (+0000) Subject: add fdshare() and fdinit() calls for dealing with filedesc structures X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=53e57a52cc415e4467f6749bae995a5952b775c2;p=openbsd add fdshare() and fdinit() calls for dealing with filedesc structures --- diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index edc7b618b9f..2aac60d9e02 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -605,6 +605,50 @@ ffree(fp) FREE(fp, M_FILE); } +/* + * Build a new filedesc structure. + */ +struct filedesc * +fdinit(p) + struct proc *p; +{ + register struct filedesc0 *newfdp; + register struct filedesc *fdp = p->p_fd; + extern int cmask; + + MALLOC(newfdp, struct filedesc0 *, sizeof(struct filedesc0), + M_FILEDESC, M_WAITOK); + bzero(newfdp, sizeof(struct filedesc0)); + newfdp->fd_fd.fd_cdir = fdp->fd_cdir; + VREF(newfdp->fd_fd.fd_cdir); + newfdp->fd_fd.fd_rdir = fdp->fd_rdir; + if (newfdp->fd_fd.fd_rdir) + VREF(newfdp->fd_fd.fd_rdir); + + /* Create the file descriptor table. */ + newfdp->fd_fd.fd_refcnt = 1; + newfdp->fd_fd.fd_cmask = cmask; + newfdp->fd_fd.fd_ofiles = newfdp->fd_dfiles; + newfdp->fd_fd.fd_ofileflags = newfdp->fd_dfileflags; + newfdp->fd_fd.fd_nfiles = NDFILE; + + newfdp->fd_fd.fd_freefile = 0; + newfdp->fd_fd.fd_lastfile = 0; + + return (&newfdp->fd_fd); +} + +/* + * Share a filedesc structure. + */ +struct filedesc * +fdshare(p) + struct proc *p; +{ + p->p_fd->fd_refcnt++; + return (p->p_fd); +} + /* * Copy a filedesc structure. */ diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index e37c7a3e8fe..445d78d8e78 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -98,6 +98,8 @@ int dupfdopen __P((struct filedesc *fdp, int indx, int dfd, int mode, int fdalloc __P((struct proc *p, int want, int *result)); int fdavail __P((struct proc *p, int n)); int falloc __P((struct proc *p, struct file **resultfp, int *resultfd)); +struct filedesc *fdinit __P((struct proc *p)); +struct filedesc *fdshare __P((struct proc *p)); struct filedesc *fdcopy __P((struct proc *p)); void fdfree __P((struct proc *p)); #endif