- * fp_getfkq
- *
- * Description: Get fileproc and kqueue pointer for a given fd from the
- * per process open file table of the specified process, and if
- * successful, increment the f_iocount
- *
- * Parameters: p Process in which fd lives
- * fd fd to get information for
- * resultfp Pointer to result fileproc
- * pointer area, or 0 if none
- * resultkq Pointer to result kqueue
- * pointer area, or 0 if none
- *
- * Returns: EBADF The file descriptor is invalid
- * EBADF The file descriptor is not a socket
- * 0 Success
- *
- * Implicit returns:
- * *resultfp (modified) Fileproc pointer
- * *resultkq (modified) kqueue pointer
- *
- * Notes: The second EBADF should probably be something else to make
- * the error condition distinct.
- */
-int
-fp_getfkq(proc_t p, int fd, struct fileproc **resultfp,
- struct kqueue **resultkq)
-{
- struct filedesc *fdp = p->p_fd;
- struct fileproc *fp;
-
- proc_fdlock_spin(p);
- if ( fd < 0 || fd >= fdp->fd_nfiles ||
- (fp = fdp->fd_ofiles[fd]) == NULL ||
- (fdp->fd_ofileflags[fd] & UF_RESERVED)) {
- proc_fdunlock(p);
- return (EBADF);
- }
- if (fp->f_type != DTYPE_KQUEUE) {
- proc_fdunlock(p);
- return(EBADF);
- }
- fp->f_iocount++;
-
- if (resultfp)
- *resultfp = fp;
- if (resultkq)
- *resultkq = (struct kqueue *)fp->f_data;
- proc_fdunlock(p);
-
- return (0);
-}
-
-
-/*
- * fp_getfpshm
- *
- * Description: Get fileproc and POSIX shared memory pointer for a given fd
- * from the per process open file table of the specified process
- * and if successful, increment the f_iocount
- *
- * Parameters: p Process in which fd lives
- * fd fd to get information for
- * resultfp Pointer to result fileproc
- * pointer area, or 0 if none
- * resultpshm Pointer to result POSIX
- * shared memory pointer
- * pointer area, or 0 if none
- *
- * Returns: EBADF The file descriptor is invalid
- * EBADF The file descriptor is not a POSIX
- * shared memory area
- * 0 Success
- *
- * Implicit returns:
- * *resultfp (modified) Fileproc pointer
- * *resultpshm (modified) POSIX shared memory pointer
- *
- * Notes: The second EBADF should probably be something else to make
- * the error condition distinct.
- */
-int
-fp_getfpshm(proc_t p, int fd, struct fileproc **resultfp,
- struct pshmnode **resultpshm)
-{
- struct filedesc *fdp = p->p_fd;
- struct fileproc *fp;
-
- proc_fdlock_spin(p);
- if (fd < 0 || fd >= fdp->fd_nfiles ||
- (fp = fdp->fd_ofiles[fd]) == NULL ||
- (fdp->fd_ofileflags[fd] & UF_RESERVED)) {
- proc_fdunlock(p);
- return (EBADF);
- }
- if (fp->f_type != DTYPE_PSXSHM) {
-
- proc_fdunlock(p);
- return(EBADF);
- }
- fp->f_iocount++;
-
- if (resultfp)
- *resultfp = fp;
- if (resultpshm)
- *resultpshm = (struct pshmnode *)fp->f_data;
- proc_fdunlock(p);
-
- return (0);
-}
-
-
-/*
- * fp_getfsem
- *
- * Description: Get fileproc and POSIX semaphore pointer for a given fd from
- * the per process open file table of the specified process
- * and if successful, increment the f_iocount
- *
- * Parameters: p Process in which fd lives
- * fd fd to get information for
- * resultfp Pointer to result fileproc
- * pointer area, or 0 if none
- * resultpsem Pointer to result POSIX
- * semaphore pointer area, or
- * 0 if none
- *
- * Returns: EBADF The file descriptor is invalid
- * EBADF The file descriptor is not a POSIX
- * semaphore
- * 0 Success
- *
- * Implicit returns:
- * *resultfp (modified) Fileproc pointer
- * *resultpsem (modified) POSIX semaphore pointer
- *
- * Notes: The second EBADF should probably be something else to make
- * the error condition distinct.
- *
- * In order to support unnamed POSIX semaphores, the named
- * POSIX semaphores will have to move out of the per-process
- * open filetable, and into a global table that is shared with
- * unnamed POSIX semaphores, since unnamed POSIX semaphores
- * are typically used by declaring instances in shared memory,
- * and there's no other way to do this without changing the
- * underlying type, which would introduce binary compatibility
- * issues.
- */
-int
-fp_getfpsem(proc_t p, int fd, struct fileproc **resultfp,
- struct psemnode **resultpsem)
-{
- struct filedesc *fdp = p->p_fd;
- struct fileproc *fp;
-
- proc_fdlock_spin(p);
- if (fd < 0 || fd >= fdp->fd_nfiles ||
- (fp = fdp->fd_ofiles[fd]) == NULL ||
- (fdp->fd_ofileflags[fd] & UF_RESERVED)) {
- proc_fdunlock(p);
- return (EBADF);
- }
- if (fp->f_type != DTYPE_PSXSEM) {
- proc_fdunlock(p);
- return(EBADF);
- }
- fp->f_iocount++;
-
- if (resultfp)
- *resultfp = fp;
- if (resultpsem)
- *resultpsem = (struct psemnode *)fp->f_data;
- proc_fdunlock(p);
-
- return (0);
-}
-
-
-/*
- * fp_getfpipe
- *
- * Description: Get fileproc and pipe pointer for a given fd from the
- * per process open file table of the specified process
- * and if successful, increment the f_iocount
- *
- * Parameters: p Process in which fd lives
- * fd fd to get information for
- * resultfp Pointer to result fileproc
- * pointer area, or 0 if none
- * resultpipe Pointer to result pipe
- * pointer area, or 0 if none
- *
- * Returns: EBADF The file descriptor is invalid
- * EBADF The file descriptor is not a socket
- * 0 Success
- *
- * Implicit returns:
- * *resultfp (modified) Fileproc pointer
- * *resultpipe (modified) pipe pointer
- *
- * Notes: The second EBADF should probably be something else to make
- * the error condition distinct.
- */
-int
-fp_getfpipe(proc_t p, int fd, struct fileproc **resultfp,
- struct pipe **resultpipe)
-{
- struct filedesc *fdp = p->p_fd;
- struct fileproc *fp;
-
- proc_fdlock_spin(p);
- if (fd < 0 || fd >= fdp->fd_nfiles ||
- (fp = fdp->fd_ofiles[fd]) == NULL ||
- (fdp->fd_ofileflags[fd] & UF_RESERVED)) {
- proc_fdunlock(p);
- return (EBADF);
- }
- if (fp->f_type != DTYPE_PIPE) {
- proc_fdunlock(p);
- return(EBADF);
- }
- fp->f_iocount++;
-
- if (resultfp)
- *resultfp = fp;
- if (resultpipe)
- *resultpipe = (struct pipe *)fp->f_data;
- proc_fdunlock(p);
-
- return (0);
-}
-
-
-/*
- * fp_lookup
- *
- * Description: Get fileproc pointer for a given fd from the per process
- * open file table of the specified process and if successful,
- * increment the f_iocount
- *
- * Parameters: p Process in which fd lives
- * fd fd to get information for
- * resultfp Pointer to result fileproc
- * pointer area, or 0 if none
- * locked !0 if the caller holds the
- * proc_fdlock, 0 otherwise
- *
- * Returns: 0 Success
- * EBADF Bad file descriptor
- *
- * Implicit returns:
- * *resultfp (modified) Fileproc pointer
- *
- * Locks: If the argument 'locked' is non-zero, then the caller is
- * expected to have taken and held the proc_fdlock; if it is
- * zero, than this routine internally takes and drops this lock.
- */
-int
-fp_lookup(proc_t p, int fd, struct fileproc **resultfp, int locked)
-{
- struct filedesc *fdp = p->p_fd;
- struct fileproc *fp;
-
- if (!locked)
- proc_fdlock_spin(p);
- if (fd < 0 || fdp == NULL || fd >= fdp->fd_nfiles ||
- (fp = fdp->fd_ofiles[fd]) == NULL ||
- (fdp->fd_ofileflags[fd] & UF_RESERVED)) {
- if (!locked)
- proc_fdunlock(p);
- return (EBADF);
- }
- fp->f_iocount++;
-
- if (resultfp)
- *resultfp = fp;
- if (!locked)
- proc_fdunlock(p);
-
- return (0);
-}
-
-
-/*
- * fp_tryswap