diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-01-07 17:38:23 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-01-07 17:38:23 +0000 |
commit | 29ea1e379a9c338ff01d1cb70072a389be168462 (patch) | |
tree | 5640042a4e6568dadb267ba820ef4f48e6f90012 | |
parent | cd5ebec1be2b2a34afa54608db531e67f6194c8c (diff) |
add fdshare() and fdinit() calls for dealing with filedesc structures
-rw-r--r-- | sys/kern/kern_descrip.c | 44 | ||||
-rw-r--r-- | sys/sys/filedesc.h | 2 |
2 files changed, 46 insertions, 0 deletions
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 @@ -606,6 +606,50 @@ ffree(fp) } /* + * 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. */ struct filedesc * 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 |