Lines Matching refs:fdp

104 static int	closefp(struct filedesc *fdp, int fd, struct file *fp,
108 struct filedesc *fdp, int flags);
109 static int fd_first_free(struct filedesc *fdp, int low, int size);
110 static void fdgrowtable(struct filedesc *fdp, int nfd);
111 static void fdgrowtable_exp(struct filedesc *fdp, int nfd);
112 static void fdunused(struct filedesc *fdp, int fd);
113 static void fdused(struct filedesc *fdp, int fd);
154 #define FILEDESC_FOREACH_FDE(fdp, _iterator, _fde) \
155 struct filedesc *_fdp = (fdp); \
160 #define FILEDESC_FOREACH_FP(fdp, _iterator, _fp) \
161 struct filedesc *_fdp = (fdp); \
205 fd_first_free(struct filedesc *fdp, int low, int size)
207 NDSLOTTYPE *map = fdp->fd_map;
230 * Call this variant if fdp can't be modified by anyone else (e.g, during exec).
234 fdlastfile_single(struct filedesc *fdp)
236 NDSLOTTYPE *map = fdp->fd_map;
239 off = NDSLOT(fdp->fd_nfiles - 1);
247 fdlastfile(struct filedesc *fdp)
250 FILEDESC_LOCK_ASSERT(fdp);
251 return (fdlastfile_single(fdp));
255 fdisused(struct filedesc *fdp, int fd)
258 KASSERT(fd >= 0 && fd < fdp->fd_nfiles,
259 ("file descriptor %d out of range (0, %d)", fd, fdp->fd_nfiles));
261 return ((fdp->fd_map[NDSLOT(fd)] & NDBIT(fd)) != 0);
268 fdused_init(struct filedesc *fdp, int fd)
271 KASSERT(!fdisused(fdp, fd), ("fd=%d is already used", fd));
273 fdp->fd_map[NDSLOT(fd)] |= NDBIT(fd);
277 fdused(struct filedesc *fdp, int fd)
280 FILEDESC_XLOCK_ASSERT(fdp);
282 fdused_init(fdp, fd);
283 if (fd == fdp->fd_freefile)
284 fdp->fd_freefile++;
291 fdunused(struct filedesc *fdp, int fd)
294 FILEDESC_XLOCK_ASSERT(fdp);
296 KASSERT(fdisused(fdp, fd), ("fd=%d is already unused", fd));
297 KASSERT(fdp->fd_ofiles[fd].fde_file == NULL,
300 fdp->fd_map[NDSLOT(fd)] &= ~NDBIT(fd);
301 if (fd < fdp->fd_freefile)
302 fdp->fd_freefile = fd;
308 * Avoid some work if fdp is about to be destroyed.
318 fdfree(struct filedesc *fdp, int fd)
322 FILEDESC_XLOCK_ASSERT(fdp);
323 fde = &fdp->fd_ofiles[fd];
332 fdunused(fdp, fd);
486 struct filedesc *fdp;
501 fdp = p->p_fd;
528 FILEDESC_SLOCK(fdp);
529 fde = fdeget_noref(fdp, fd);
535 FILEDESC_SUNLOCK(fdp);
540 FILEDESC_XLOCK(fdp);
541 fde = fdeget_noref(fdp, fd);
547 FILEDESC_XUNLOCK(fdp);
893 FILEDESC_SLOCK(fdp);
894 error = fget_cap_noref(fdp, fd, &cap_fcntl_rights, &fp, NULL);
896 export_file_to_kinfo(fp, fd, NULL, kif, fdp, 0);
897 FILEDESC_SUNLOCK(fdp);
906 FILEDESC_SUNLOCK(fdp);
933 struct filedesc *fdp;
941 fdp = p->p_fd;
964 FILEDESC_XLOCK(fdp);
965 if (fget_noref(fdp, old) == NULL)
970 fdp->fd_ofiles[new].fde_flags |= UF_EXCLOSE;
975 oldfde = &fdp->fd_ofiles[old];
994 if (new >= fdp->fd_nfiles) {
1013 fdgrowtable_exp(fdp, new + 1);
1015 if (!fdisused(fdp, new))
1016 fdused(fdp, new);
1025 oldfde = &fdp->fd_ofiles[old];
1030 newfde = &fdp->fd_ofiles[new];
1057 (void) closefp(fdp, new, delfp, td, true, false);
1058 FILEDESC_UNLOCK_ASSERT(fdp);
1061 FILEDESC_XUNLOCK(fdp);
1290 closefp_impl(struct filedesc *fdp, int fd, struct file *fp, struct thread *td,
1295 FILEDESC_XLOCK_ASSERT(fdp);
1303 if (__predict_false(!TAILQ_EMPTY(&fdp->fd_kqlist)))
1311 FILEDESC_XUNLOCK(fdp);
1331 closefp_hl(struct filedesc *fdp, int fd, struct file *fp, struct thread *td,
1336 FILEDESC_XLOCK_ASSERT(fdp);
1344 fdp->fd_holdleaderscount++;
1350 error = closefp_impl(fdp, fd, fp, td, audit);
1352 FILEDESC_XLOCK(fdp);
1353 fdp->fd_holdleaderscount--;
1354 if (fdp->fd_holdleaderscount == 0 &&
1355 fdp->fd_holdleaderswakeup != 0) {
1356 fdp->fd_holdleaderswakeup = 0;
1357 wakeup(&fdp->fd_holdleaderscount);
1359 FILEDESC_XUNLOCK(fdp);
1365 closefp(struct filedesc *fdp, int fd, struct file *fp, struct thread *td,
1369 FILEDESC_XLOCK_ASSERT(fdp);
1372 return (closefp_hl(fdp, fd, fp, td, holdleaders, audit));
1374 return (closefp_impl(fdp, fd, fp, td, audit));
1397 struct filedesc *fdp;
1400 fdp = td->td_proc->p_fd;
1402 FILEDESC_XLOCK(fdp);
1403 if ((fp = fget_noref(fdp, fd)) == NULL) {
1404 FILEDESC_XUNLOCK(fdp);
1407 fdfree(fdp, fd);
1410 return (closefp(fdp, fd, fp, td, true, true));
1416 struct filedesc *fdp;
1421 fdp = td->td_proc->p_fd;
1422 FILEDESC_XLOCK(fdp);
1423 fdt = atomic_load_ptr(&fdp->fd_files);
1435 FILEDESC_XUNLOCK(fdp);
1442 struct filedesc *fdp;
1447 fdp = td->td_proc->p_fd;
1448 FILEDESC_XLOCK(fdp);
1449 fdt = atomic_load_ptr(&fdp->fd_files);
1461 fdfree(fdp, fd);
1462 (void) closefp(fdp, fd, fp, td, true, true);
1465 FILEDESC_XLOCK(fdp);
1466 fdt = atomic_load_ptr(&fdp->fd_files);
1471 FILEDESC_XUNLOCK(fdp);
1874 fdgrowtable_exp(struct filedesc *fdp, int nfd)
1878 FILEDESC_XLOCK_ASSERT(fdp);
1880 nfd1 = fdp->fd_nfiles * 2;
1883 fdgrowtable(fdp, nfd1);
1890 fdgrowtable(struct filedesc *fdp, int nfd)
1899 KASSERT(fdp->fd_nfiles > 0, ("zero-length file table"));
1902 onfiles = fdp->fd_nfiles;
1903 otable = fdp->fd_files;
1904 omap = fdp->fd_map;
1938 fdp->fd_map = nmap;
1946 atomic_store_rel_ptr((volatile void *)&fdp->fd_files, (uintptr_t)ntable);
1958 * static allocation contained within (struct filedesc0 *)fdp,
1967 if (curproc->p_fd != fdp || FILEDESC_IS_ONLY_USER(fdp)) {
1971 fdp0 = (struct filedesc0 *)fdp;
1992 struct filedesc *fdp = p->p_fd;
1998 FILEDESC_XLOCK_ASSERT(fdp);
2000 if (fdp->fd_freefile > minfd)
2001 minfd = fdp->fd_freefile;
2009 fd = fd_first_free(fdp, minfd, fdp->fd_nfiles);
2012 if (__predict_false(fd >= fdp->fd_nfiles)) {
2025 fdgrowtable_exp(fdp, allocfd);
2032 KASSERT(fd >= 0 && fd < min(maxfd, fdp->fd_nfiles),
2034 KASSERT(!fdisused(fdp, fd),
2036 KASSERT(fdp->fd_ofiles[fd].fde_file == NULL,
2038 fdused(fdp, fd);
2050 struct filedesc *fdp = p->p_fd;
2053 FILEDESC_XLOCK_ASSERT(fdp);
2061 fdunused(fdp, fds[i]);
2152 _finstall(struct filedesc *fdp, struct file *fp, int fd, int flags,
2160 FILEDESC_XLOCK_ASSERT(fdp);
2162 fde = &fdp->fd_ofiles[fd];
2181 struct filedesc *fdp = td->td_proc->p_fd;
2186 FILEDESC_XLOCK(fdp);
2189 _finstall(fdp, fp, *fd, flags, fcaps);
2191 FILEDESC_XUNLOCK(fdp);
2215 * If fdp is not NULL, return with it shared locked.
2287 struct filedesc *fdp;
2290 fdp = atomic_load_ptr(&p->p_fd);
2291 if (fdp != NULL)
2292 refcount_acquire(&fdp->fd_holdcnt);
2293 return (fdp);
2309 fddrop(struct filedesc *fdp)
2312 if (refcount_load(&fdp->fd_holdcnt) > 1) {
2313 if (refcount_release(&fdp->fd_holdcnt) == 0)
2317 FILEDESC_LOCK_DESTROY(fdp);
2318 uma_zfree(filedesc0_zone, fdp);
2347 fdshare(struct filedesc *fdp)
2350 refcount_acquire(&fdp->fd_refcnt);
2351 return (fdp);
2405 fdcopy(struct filedesc *fdp)
2411 MPASS(fdp != NULL);
2414 FILEDESC_SLOCK(fdp);
2416 lastfile = fdlastfile(fdp);
2419 FILEDESC_SUNLOCK(fdp);
2421 FILEDESC_SLOCK(fdp);
2424 newfdp->fd_freefile = fdp->fd_freefile;
2425 FILEDESC_FOREACH_FDE(fdp, i, ofde) {
2428 if (newfdp->fd_freefile == fdp->fd_freefile)
2438 FILEDESC_SUNLOCK(fdp);
2459 * Clear POSIX style locks. This is only used when fdp looses a reference (i.e.
2465 struct filedesc *fdp;
2474 fdp = p->p_fd;
2478 FILEDESC_XLOCK(fdp);
2484 FILEDESC_FOREACH_FP(fdp, i, fp) {
2488 FILEDESC_XUNLOCK(fdp);
2497 FILEDESC_XLOCK(fdp);
2503 if (fdp->fd_holdleaderscount > 0 &&
2509 fdp->fd_holdleaderswakeup = 1;
2510 sx_sleep(&fdp->fd_holdleaderscount,
2511 FILEDESC_LOCK(fdp), PLOCK, "fdlhold", 0);
2520 sx_sleep(fdtol, FILEDESC_LOCK(fdp), PLOCK,
2533 FILEDESC_XUNLOCK(fdp);
2542 fdescfree_fds(struct thread *td, struct filedesc *fdp)
2550 KASSERT(refcount_load(&fdp->fd_refcnt) == 0,
2551 ("%s: fd table %p carries references", __func__, fdp));
2556 if (refcount_load(&fdp->fd_holdcnt) > 1) {
2557 FILEDESC_XLOCK(fdp);
2558 FILEDESC_XUNLOCK(fdp);
2561 FILEDESC_FOREACH_FDE(fdp, i, fde) {
2567 if (NDSLOTS(fdp->fd_nfiles) > NDSLOTS(NDFILE))
2568 free(fdp->fd_map, M_FILEDESC);
2569 if (fdp->fd_nfiles > NDFILE)
2570 free(fdp->fd_files, M_FILEDESC);
2572 fdp0 = (struct filedesc0 *)fdp;
2576 fddrop(fdp);
2583 struct filedesc *fdp;
2586 fdp = p->p_fd;
2587 MPASS(fdp != NULL);
2604 if (refcount_release(&fdp->fd_refcnt) == 0)
2607 fdescfree_fds(td, fdp);
2657 struct filedesc *fdp;
2661 fdp = td->td_proc->p_fd;
2662 KASSERT(refcount_load(&fdp->fd_refcnt) == 1,
2664 MPASS(fdp->fd_nfiles >= 3);
2666 fp = fdp->fd_ofiles[i].fde_file;
2668 FILEDESC_XLOCK(fdp);
2674 fdfree(fdp, i);
2675 FILEDESC_XUNLOCK(fdp);
2691 struct filedesc *fdp = td->td_proc->p_fd;
2693 FILEDESC_XLOCK(fdp);
2694 if (fdp->fd_ofiles[idx].fde_file == fp) {
2695 fdfree(fdp, idx);
2696 FILEDESC_XUNLOCK(fdp);
2699 FILEDESC_XUNLOCK(fdp);
2708 struct filedesc *fdp;
2713 fdp = td->td_proc->p_fd;
2714 KASSERT(refcount_load(&fdp->fd_refcnt) == 1,
2716 FILEDESC_FOREACH_FDE(fdp, i, fde) {
2720 FILEDESC_XLOCK(fdp);
2721 fdfree(fdp, i);
2722 (void) closefp(fdp, i, fp, td, false, false);
2723 FILEDESC_UNLOCK_ASSERT(fdp);
2738 struct filedesc *fdp;
2742 fdp = td->td_proc->p_fd;
2743 KASSERT(refcount_load(&fdp->fd_refcnt) == 1,
2745 MPASS(fdp->fd_nfiles >= 3);
2748 if (fdp->fd_ofiles[i].fde_file != NULL)
2780 struct filedesc *fdp;
2812 fdp = td->td_proc->p_fd;
2813 FILEDESC_XLOCK(fdp);
2821 FILEDESC_XUNLOCK(fdp);
2830 FILEDESC_XLOCK(fdp);
2838 FILEDESC_XUNLOCK(fdp);
2880 fget_cap_noref(struct filedesc *fdp, int fd, cap_rights_t *needrightsp,
2886 FILEDESC_LOCK_ASSERT(fdp);
2889 fde = fdeget_noref(fdp, fd);
2916 struct filedesc *fdp = td->td_proc->p_fd;
2928 if (!filecaps_copy(&fdp->fd_ofiles[fd].fde_caps,
2935 if (!fd_modified(fdp, fd, seq))
2944 FILEDESC_SLOCK(fdp);
2945 error = fget_cap_noref(fdp, fd, needrightsp, fpp, havecapsp);
2948 FILEDESC_SUNLOCK(fdp);
2968 struct filedesc *fdp;
2976 fdp = fdhold(p);
2978 if (fdp == NULL)
2980 FILEDESC_SLOCK(fdp);
2981 if (refcount_load(&fdp->fd_refcnt) != 0) {
2982 fp = fget_noref(fdp, fd);
2992 FILEDESC_SUNLOCK(fdp);
2993 fddrop(fdp);
3003 struct filedesc *fdp;
3017 fdp = curproc->p_fd;
3018 fdt = fdp->fd_files;
3042 fdt = fdp->fd_files;
3070 struct filedesc *fdp;
3078 fdp = curproc->p_fd;
3079 fdt = fdp->fd_files;
3095 fdt = fdp->fd_files;
3186 struct filedesc *fdp;
3194 fdp = td->td_proc->p_fd;
3195 fdt = fdp->fd_files;
3207 fdt = atomic_load_ptr(&fdp->fd_files);
3214 fdt = atomic_load_ptr(&fdp->fd_files);
3218 fdt = atomic_load_ptr(&fdp->fd_files);
3226 fdt = fdp->fd_files;
3242 struct filedesc *fdp;
3246 fdp = td->td_proc->p_fd;
3247 fdt = fdp->fd_files;
3256 fdt = atomic_load_ptr(&fdp->fd_files);
3264 fdt = fdp->fd_files;
3285 struct filedesc *fdp;
3296 fdp = td->td_proc->p_fd;
3297 fdt = fdp->fd_files;
3324 fdt = fdp->fd_files;
3351 fget_only_user(struct filedesc *fdp, int fd, cap_rights_t *needrightsp,
3360 MPASS(FILEDESC_IS_ONLY_USER(fdp));
3363 if (__predict_false(fd >= fdp->fd_nfiles))
3366 fdt = fdp->fd_files;
3381 fget_only_user(struct filedesc *fdp, int fd, cap_rights_t *needrightsp,
3386 MPASS(FILEDESC_IS_ONLY_USER(fdp));
3389 if (__predict_false(fd >= fdp->fd_nfiles))
3392 fp = fdp->fd_ofiles[fd].fde_file;
3481 struct filedesc *fdp;
3486 fdp = td->td_proc->p_fd;
3497 fdrights = *cap_rights(fdp, fd);
3498 if (!fd_modified(fdp, fd, seq))
3534 struct filedesc *fdp = td->td_proc->p_fd;
3545 error = cap_fcntl_check(fdp, fd, needfcntl);
3546 if (!fd_modified(fdp, fd, seq))
3739 dupfdopen(struct thread *td, struct filedesc *fdp, int dfd, int mode,
3755 FILEDESC_XLOCK(fdp);
3756 if ((fp = fget_noref(fdp, dfd)) == NULL) {
3757 FILEDESC_XUNLOCK(fdp);
3763 FILEDESC_XUNLOCK(fdp);
3782 fdunused(fdp, indx);
3783 FILEDESC_XUNLOCK(fdp);
3787 fdunused(fdp, indx);
3788 FILEDESC_XUNLOCK(fdp);
3791 newfde = &fdp->fd_ofiles[indx];
3792 oldfde = &fdp->fd_ofiles[dfd];
3808 newfde = &fdp->fd_ofiles[indx];
3809 oldfde = &fdp->fd_ofiles[dfd];
3816 fdunused(fdp, dfd);
3823 FILEDESC_XUNLOCK(fdp);
3847 chroot_refuse_vdir_fds(struct filedesc *fdp)
3853 FILEDESC_LOCK_ASSERT(fdp);
3855 FILEDESC_FOREACH_FP(fdp, i, fp) {
3992 struct filedesc *fdp;
3996 fdp = td->td_proc->p_fd;
3999 FILEDESC_SLOCK(fdp);
4005 error = chroot_refuse_vdir_fds(fdp);
4006 FILEDESC_SUNLOCK(fdp);
4013 FILEDESC_SUNLOCK(fdp);
4091 struct filedesc *fdp;
4095 fdp = td->td_proc->p_fd;
4098 FILEDESC_SLOCK(fdp);
4101 error = chroot_refuse_vdir_fds(fdp);
4102 FILEDESC_SUNLOCK(fdp);
4274 descrip_check_write_mp(struct filedesc *fdp, struct mount *mp)
4281 FILEDESC_SLOCK(fdp);
4282 FILEDESC_FOREACH_FP(fdp, i, fp) {
4292 FILEDESC_SUNLOCK(fdp);
4297 filedesc_to_leader_alloc(struct filedesc_to_leader *old, struct filedesc *fdp,
4309 FILEDESC_XLOCK(fdp);
4314 FILEDESC_XUNLOCK(fdp);
4323 filedesc_to_leader_share(struct filedesc_to_leader *fdtol, struct filedesc *fdp)
4325 FILEDESC_XLOCK(fdp);
4327 FILEDESC_XUNLOCK(fdp);
4335 struct filedesc *fdp;
4346 fdp = curproc->p_fd;
4348 FILEDESC_SLOCK(fdp);
4349 map = fdp->fd_map;
4350 off = NDSLOT(fdp->fd_nfiles - 1);
4353 FILEDESC_SUNLOCK(fdp);
4369 struct filedesc *fdp;
4386 fdp = fdhold(p);
4388 if (fdp == NULL)
4391 n += fdp->fd_nfiles;
4392 fddrop(fdp);
4413 fdp = fdhold(p);
4415 if (fdp == NULL)
4417 FILEDESC_SLOCK(fdp);
4418 if (refcount_load(&fdp->fd_refcnt) == 0)
4420 FILEDESC_FOREACH_FP(fdp, n, fp) {
4441 FILEDESC_SUNLOCK(fdp);
4442 fddrop(fdp);
4502 struct kinfo_file *kif, struct filedesc *fdp, int flags)
4523 error = fo_fill_kinfo(fp, kif, fdp);
4557 struct filedesc *fdp;
4589 export_file_to_kinfo(fp, fd, rightsp, &efbuf->kif, efbuf->fdp,
4591 FILEDESC_SUNLOCK(efbuf->fdp);
4593 FILEDESC_SLOCK(efbuf->fdp);
4624 struct filedesc *fdp;
4647 fdp = fdhold(p);
4652 efbuf->fdp = NULL;
4668 if (error != 0 || pdp == NULL || fdp == NULL)
4670 efbuf->fdp = fdp;
4699 FILEDESC_SLOCK(fdp);
4700 if (refcount_load(&fdp->fd_refcnt) == 0)
4702 FILEDESC_FOREACH_FP(fdp, i, fp) {
4704 rights = *cap_rights(fdp, i);
4715 if (error != 0 || refcount_load(&fdp->fd_refcnt) == 0)
4719 FILEDESC_SUNLOCK(fdp);
4721 if (fdp != NULL)
4722 fddrop(fdp);
4821 struct filedesc *fdp;
4837 fdp = fdhold(p);
4838 if (fdp != NULL)
4841 if (fdp == NULL || pdp == NULL) {
4842 if (fdp != NULL)
4843 fddrop(fdp);
4864 FILEDESC_SLOCK(fdp);
4865 if (refcount_load(&fdp->fd_refcnt) == 0)
4867 FILEDESC_FOREACH_FP(fdp, i, fp) {
4868 export_file_to_kinfo(fp, i, NULL, kif, fdp,
4870 FILEDESC_SUNLOCK(fdp);
4873 FILEDESC_SLOCK(fdp);
4874 if (error != 0 || refcount_load(&fdp->fd_refcnt) == 0)
4878 FILEDESC_SUNLOCK(fdp);
4879 fddrop(fdp);
4946 efbuf->fdp = NULL;
5055 struct filedesc *fdp;
5062 fdp = p->p_fd;
5063 if (fdp == NULL)
5065 for (n = 0; n < fdp->fd_nfiles; n++) {
5066 if (fp == fdp->fd_ofiles[n].fde_file)
5107 struct filedesc *fdp;
5117 if ((fdp = p->p_fd) == NULL)
5119 for (n = 0; n < fdp->fd_nfiles; ++n) {
5120 if ((fp = fdp->fd_ofiles[n].fde_file) == NULL)
5240 badfo_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)