From 53e57a52cc415e4467f6749bae995a5952b775c2 Mon Sep 17 00:00:00 2001 From: deraadt Date: Sun, 7 Jan 1996 17:38:21 +0000 Subject: [PATCH] add fdshare() and fdinit() calls for dealing with filedesc structures --- sys/kern/kern_descrip.c | 44 +++++++++++++++++++++++++++++++++++++++++ sys/sys/filedesc.h | 2 ++ 2 files changed, 46 insertions(+) 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 -- 2.20.1