Lines Matching defs:fd

139 static int close_internal_locked(struct proc *p, int fd, struct fileproc *fp, int flags);
150 static void _fdrelse(struct proc * p, int fd);
292 procfdtbl_reservefd(struct proc * p, int fd)
294 p->p_fd->fd_ofiles[fd] = NULL;
295 p->p_fd->fd_ofileflags[fd] |= UF_RESERVED;
299 procfdtbl_markclosefd(struct proc * p, int fd)
301 p->p_fd->fd_ofileflags[fd] |= (UF_RESERVED | UF_CLOSING);
305 procfdtbl_releasefd(struct proc * p, int fd, struct fileproc * fp)
308 p->p_fd->fd_ofiles[fd] = fp;
309 p->p_fd->fd_ofileflags[fd] &= ~UF_RESERVED;
310 if ((p->p_fd->fd_ofileflags[fd] & UF_RESVWAIT) == UF_RESVWAIT) {
311 p->p_fd->fd_ofileflags[fd] &= ~UF_RESVWAIT;
317 procfdtbl_waitfd(struct proc * p, int fd)
319 p->p_fd->fd_ofileflags[fd] |= UF_RESVWAIT;
325 procfdtbl_clearfd(struct proc * p, int fd)
329 waiting = (p->p_fd->fd_ofileflags[fd] & UF_RESVWAIT);
330 p->p_fd->fd_ofiles[fd] = NULL;
331 p->p_fd->fd_ofileflags[fd] = 0;
340 * Description: Inline utility function to free an fd in a filedesc
342 * Parameters: fdp Pointer to filedesc fd lies in
343 * fd fd to free
344 * reserv fd should be reserved
352 _fdrelse(struct proc * p, int fd)
357 if (fd < fdp->fd_freefile)
358 fdp->fd_freefile = fd;
360 if (fd > fdp->fd_lastfile)
363 procfdtbl_clearfd(p, fd);
374 int fd,
394 error = fp_lookup(p, fd, &fp, 0);
439 fp_drop_written(p, fd, fp);
441 fp_drop(p, fd, fp, 0);
454 * uap->fd The fd to dup
467 int old = uap->fd;
494 * uap->from The fd to dup
495 * uap->to The fd to dup it to
595 * uap->fd The fd to operate against
624 * uap->fd The fd to operate against
674 int fd = uap->fd;
689 AUDIT_ARG(fd, uap->fd);
693 if ( (error = fp_lookup(p, fd, &fp, 1)) ) {
717 pop = &fdp->fd_ofileflags[fd];
739 error = finishdup(p, fdp, fd, i,
1371 case F_FREEZE_FS: // freeze all other fs operations for the fs of this fd
1372 case F_THAW_FS: { // thaw all frozen fs operations for the fs of this fd
1389 * SPI (private) for opening a file starting from a dir fd
1451 * SPI (private) for unlinking a file starting from a dir fd
1782 * while we still hold the proc fd lock
1809 AUDIT_ARG(fd, fd2);
1928 * Set the vnode pointed to by 'fd'
2123 fp_drop(p, fd, fp, 0);
2126 fp_drop(p, fd, fp, 1);
2138 * old The fd to dup
2139 * new The fd to dup it to
2140 * fd_flags Flags to augment the new fd
2228 * uap->fd fd to be closed
2249 int fd = uap->fd;
2252 AUDIT_SYSCLOSE(p, fd);
2256 if ( (error = fp_lookup(p,fd,&fp, 1)) ) {
2261 error = close_internal_locked(p, fd, fp, 0);
2276 * fd fd to be closed
2277 * fp fileproc associated with the fd
2280 * EBADF fd already in close wait state
2293 close_internal_locked(proc_t p, int fd, struct fileproc *fp, int flags)
2305 procfdtbl_markclosefd(p, fd);
2309 panic("close_internal_locked: being called on already closing fd");
2314 if ((fdp->fd_ofileflags[fd] & UF_RESERVED) == 0)
2315 panic("close_internal: unreserved fileflags with fd %d", fd);
2342 _aio_close( p, fd );
2347 if (fd < fdp->fd_knlistsize)
2348 knote_fdclose(p, fd);
2357 _fdrelse(p, fd);
2359 procfdtbl_reservefd(p, fd);
2375 if ((fdp->fd_ofileflags[fd] & UF_RESERVED) == 0)
2376 panic("close with reserved fd returns with freed fd:%d: proc: %p", fd, p);
2390 * fd The fd to stat
2419 fstat1(proc_t p, int fd, user_addr_t ub, user_addr_t xsecurity, user_addr_t xsecurity_size, int isstat64)
2442 AUDIT_ARG(fd, fd);
2444 if ((error = fp_lookup(p, fd, &fp, 0)) != 0) {
2557 fp_drop(p, fd, fp, 0);
2571 * uap->fd The fd to stat
2583 return(fstat1(p, uap->fd, uap->ub, uap->xsecurity, uap->xsecurity_size, 0));
2590 * Description: Get file status for the file associated with fd
2593 * uap->fd The fd to stat
2602 return(fstat1(p, uap->fd, uap->ub, 0, 0, 0));
2613 * uap->fd The fd to stat
2625 return(fstat1(p, uap->fd, uap->ub, uap->xsecurity, uap->xsecurity_size, 1));
2633 * with fd
2636 * uap->fd The fd to stat
2645 return(fstat1(p, uap->fd, uap->ub, 0, 0, 1));
2655 * uap->fd fd to get information about
2671 int fd = uap->fd;
2679 AUDIT_ARG(fd, uap->fd);
2680 if ( (error = fp_lookup(p, fd, &fp, 0)) )
2727 fp_drop(p, fd, fp, 0);
2745 * Parameters: p Process to allocate the fd in
2746 * want The fd we would prefer to get
2747 * result Pointer to fd we got
2754 * *result (modified) The fd which was allocated
2847 * n The number of fd's desired
2882 * Parameters: p Process in which fd lives
2883 * fd fd to free
2890 fdrelse(proc_t p, int fd)
2892 _fdrelse(p, fd);
2899 * Description: Get the fileproc pointer for the given fd from the per process
2902 * Parameters: p Process containing fd
2903 * fd fd to obtain fileproc for
2919 fdgetf_noref(proc_t p, int fd, struct fileproc **resultfp)
2924 if (fd < 0 || fd >= fdp->fd_nfiles ||
2925 (fp = fdp->fd_ofiles[fd]) == NULL ||
2926 (fdp->fd_ofileflags[fd] & UF_RESERVED)) {
2938 * Description: Get fileproc and vnode pointer for a given fd from the per
2942 * Parameters: p Process in which fd lives
2943 * fd fd to get information for
2951 * ENOTSUP fd does not refer to a vnode
2963 fp_getfvp(proc_t p, int fd, struct fileproc **resultfp, struct vnode **resultvp)
2969 if (fd < 0 || fd >= fdp->fd_nfiles ||
2970 (fp = fdp->fd_ofiles[fd]) == NULL ||
2971 (fdp->fd_ofileflags[fd] & UF_RESERVED)) {
2994 * Description: Get fileproc, vnode pointer, and vid for a given fd from the
2998 * Parameters: p Process in which fd lives
2999 * fd fd to get information for
3008 * ENOTSUP fd does not refer to a vnode
3021 fp_getfvpandvid(proc_t p, int fd, struct fileproc **resultfp,
3028 if (fd < 0 || fd >= fdp->fd_nfiles ||
3029 (fp = fdp->fd_ofiles[fd]) == NULL ||
3030 (fdp->fd_ofileflags[fd] & UF_RESERVED)) {
3055 * Description: Get fileproc and socket pointer for a given fd from the
3059 * Parameters: p Process in which fd lives
3060 * fd fd to get information for
3078 fp_getfsock(proc_t p, int fd, struct fileproc **resultfp,
3085 if (fd < 0 || fd >= fdp->fd_nfiles ||
3086 (fp = fdp->fd_ofiles[fd]) == NULL ||
3087 (fdp->fd_ofileflags[fd] & UF_RESERVED)) {
3110 * Description: Get fileproc and kqueue pointer for a given fd from the
3114 * Parameters: p Process in which fd lives
3115 * fd fd to get information for
3133 fp_getfkq(proc_t p, int fd, struct fileproc **resultfp,
3140 if ( fd < 0 || fd >= fdp->fd_nfiles ||
3141 (fp = fdp->fd_ofiles[fd]) == NULL ||
3142 (fdp->fd_ofileflags[fd] & UF_RESERVED)) {
3165 * Description: Get fileproc and POSIX shared memory pointer for a given fd
3169 * Parameters: p Process in which fd lives
3170 * fd fd to get information for
3190 fp_getfpshm(proc_t p, int fd, struct fileproc **resultfp,
3197 if (fd < 0 || fd >= fdp->fd_nfiles ||
3198 (fp = fdp->fd_ofiles[fd]) == NULL ||
3199 (fdp->fd_ofileflags[fd] & UF_RESERVED)) {
3223 * Description: Get fileproc and POSIX semaphore pointer for a given fd from
3227 * Parameters: p Process in which fd lives
3228 * fd fd to get information for
3257 fp_getfpsem(proc_t p, int fd, struct fileproc **resultfp,
3264 if (fd < 0 || fd >= fdp->fd_nfiles ||
3265 (fp = fdp->fd_ofiles[fd]) == NULL ||
3266 (fdp->fd_ofileflags[fd] & UF_RESERVED)) {
3289 * Description: Get fileproc and pipe pointer for a given fd from the
3293 * Parameters: p Process in which fd lives
3294 * fd fd to get information for
3312 fp_getfpipe(proc_t p, int fd, struct fileproc **resultfp,
3319 if (fd < 0 || fd >= fdp->fd_nfiles ||
3320 (fp = fdp->fd_ofiles[fd]) == NULL ||
3321 (fdp->fd_ofileflags[fd] & UF_RESERVED)) {
3347 * Description: Get fileproc and atalk pointer for a given fd from the
3351 * Parameters: p Process in which fd lives
3352 * fd fd to get information for
3372 fp_getfatalk(proc_t p, int fd, struct fileproc **resultfp,
3379 if (fd < 0 || fd >= fdp->fd_nfiles ||
3380 (fp = fdp->fd_ofiles[fd]) == NULL ||
3381 (fdp->fd_ofileflags[fd] & UF_RESERVED)) {
3405 * Description: Get fileproc pointer for a given fd from the per process
3409 * Parameters: p Process in which fd lives
3410 * fd fd to get information for
3427 fp_lookup(proc_t p, int fd, struct fileproc **resultfp, int locked)
3434 if (fd < 0 || fdp == NULL || fd >= fdp->fd_nfiles ||
3435 (fp = fdp->fd_ofiles[fd]) == NULL ||
3436 (fdp->fd_ofileflags[fd] & UF_RESERVED)) {
3458 * Parameters: p Process in which the fd lives
3459 * fd fd associated with the fileproc
3469 * Notes: The fileproc must correspond to the fd in the supplied proc
3472 fp_drop_written(proc_t p, int fd, struct fileproc *fp)
3480 error = fp_drop(p, fd, fp, 1);
3494 * Parameters: p Process in which the fd lives
3495 * fd fd associated with the fileproc
3505 * Notes: The fileproc must correspond to the fd in the supplied proc
3508 fp_drop_event(proc_t p, int fd, struct fileproc *fp)
3516 error = fp_drop(p, fd, fp, 1);
3530 * Parameters: p Process in which the fd lives
3531 * fd fd associated with the fileproc
3545 * Notes: The fileproc must correspond to the fd in the supplied proc
3548 fp_drop(proc_t p, int fd, struct fileproc *fp, int locked)
3555 if ((fp == FILEPROC_NULL) && (fd < 0 || fd >= fdp->fd_nfiles ||
3556 (fp = fdp->fd_ofiles[fd]) == NULL ||
3557 ((fdp->fd_ofileflags[fd] & UF_RESERVED) &&
3558 !(fdp->fd_ofileflags[fd] & UF_CLOSING)))) {
3586 * Description: Given an fd, look it up in the current process's per process
3589 * Parameters: fd fd to obtain vnode from
3593 * EINVAL The fd does not refer to a
3604 * fd's corresponding fileproc.
3619 file_vnode(int fd, struct vnode **vpp)
3626 if ( (error = fp_lookup(p, fd, &fp, 1)) ) {
3631 fp_drop(p, fd, fp,1);
3646 * Description: Given an fd, look it up in the current process's per process
3649 * Parameters: fd fd to obtain vnode from
3654 * EINVAL The fd does not refer to a
3665 * fd's corresponding fileproc.
3680 file_vnode_withvid(int fd, struct vnode **vpp, uint32_t * vidp)
3688 if ( (error = fp_lookup(p, fd, &fp, 1)) ) {
3693 fp_drop(p, fd, fp,1);
3713 * Description: Given an fd, look it up in the current process's per process
3716 * Parameters: fd fd to obtain vnode from
3730 * fd's corresponding fileproc.
3745 file_socket(int fd, struct socket **sp)
3752 if ( (error = fp_lookup(p, fd, &fp, 1)) ) {
3757 fp_drop(p, fd, fp,1);
3771 * Description: Given an fd, look it up in the current process's per process
3774 * Parameters: fd fd whose flags are to be
3792 file_flags(int fd, int *flags)
3800 if ( (error = fp_lookup(p, fd, &fp, 1)) ) {
3805 fp_drop(p, fd, fp,1);
3815 * Description: Drop an iocount reference on an fd, and wake up any waiters
3819 * Parameters: fd fd on which an ioreference is
3825 * Description: Given an fd, look it up in the current process's per process
3833 * the fd refers to a character device, and that device has had
3838 * Since it's possible for an fd that refers to a character
3843 * case where multiple fd's in a process refer to the same
3849 file_drop(int fd)
3856 if (fd < 0 || fd >= p->p_fd->fd_nfiles ||
3857 (fp = p->p_fd->fd_ofiles[fd]) == NULL ||
3858 ((p->p_fd->fd_ofileflags[fd] & UF_RESERVED) &&
3859 !(p->p_fd->fd_ofileflags[fd] & UF_CLOSING))) {
3886 * return the corresponding fileproc and fd.
3889 * table the fd is to be allocated
3892 * resultfd Pointer to fd return area
3903 * *resultfd (modified) Returned fd
3935 * return the corresponding fileproc and fd.
3938 * table the fd is to be allocated
3941 * resultfd Pointer to fd return area
3955 * *resultfd (modified) Returned fd
4480 * Parameters: fp Pointer to fileproc for fd
4481 * fg Pointer to fileglob for fd
4527 * Parameters: fp Pointer to fileproc for fd
4528 * fg Pointer to fileglob for fd
4627 * close to prevent fd's from being closed out from under
4675 * Description: Release the fd and free the fileproc associated with the fd
4679 * Parameters: p Process containing fd
4680 * fd fd to be released
4689 fp_free(proc_t p, int fd, struct fileproc * fp)
4692 fdrelse(p, fd);
4707 * uap->fd fd on which the lock is to be
4714 * fp_getfvp:ENOTSUP fd does not refer to a vnode
4727 int fd = uap->fd;
4735 AUDIT_ARG(fd, uap->fd);
4736 if ( (error = fp_getfvp(p, fd, &fp, &vp)) ) {
4775 fp_drop(p, fd, fp, 0);
4786 * uap->fd The fd to reference
4803 int fd = uap->fd;
4810 err = fp_lookup(p, fd, &fp, 0);
4849 fp_drop(p, fd, fp, 0);
4860 fp_drop(p, fd, fp, 0);
4899 int fd;
4928 err = fdalloc(p, 0, &fd);
4933 *fdflags(p, fd) |= UF_EXCLOSE;
4935 procfdtbl_releasefd(p, fd, fp);
4938 *retval = fd;
4960 * indx fd to dup to
4961 * dfd fd to dup from
4962 * mode mode to set on new fd
4966 * EBADF Source fd is bad
4984 * If the to-be-dup'd fd number is greater than the allowed number
4985 * of file descriptors, or the fd to be dup'd has already been