Lines Matching refs:fd

89  * support fcntl(fd, F_DUPFD, minfd).
95 * We then descend that subtree in a binary search for the smallest fd.
97 * of every subtree containing the newly-allocated fd. Freeing an fd
100 * descent to find lowest fd, ascent to update allocation counts) is
103 * We don't implement the fd tree using the customary left/right/parent
108 * fd 0; we'll deal with that later.
187 * Finally, to accommodate fd 0 we must adjust all of our results by +/-1 to
188 * move the fd range from [1, 2^n) to [0, 2^n - 1). This is straightforward,
212 * (2) Find the smallest fd in the subtree discovered by step 1.
214 * smallest available fd. Since the left children have the smaller
223 * simple computationally: by (T5), the right child of fd is just
224 * fd + size, where size = CSIZE(fd) / 2. Applying (T5) again,
225 * we find that the right child's left child is fd + size - (size / 2) =
226 * fd + (size / 2); *its* left child is fd + (size / 2) - (size / 4) =
227 * fd + (size / 4), and so on. In general, fd's right child's
228 * leftmost nth descendant is fd + (size >> n). Thus, to follow
234 * know how many of the root fd's allocations are in the remaining
237 * that fip->fi_list[fd].uf_alloc == ralloc + size -- we descend right
240 * fd_reserve(fip, fd, incr) either allocates or frees fd, depending
241 * on whether incr is 1 or -1. Starting at fd, fd_reserve() ascends
254 * 2^n - 1. This ensures that the fd trees are always full, which saves
260 int size, ralloc, fd;
265 for (fd = minfd; (uint_t)fd < fip->fi_nfiles; fd |= fd + 1) {
266 size = fd ^ (fd | (fd + 1));
267 if (fip->fi_list[fd].uf_alloc == size)
270 ralloc += fip->fi_list[fd + size].uf_alloc;
271 if (fip->fi_list[fd].uf_alloc == ralloc + size) {
272 fd += size;
276 return (fd);
282 fd_reserve(uf_info_t *fip, int fd, int incr)
285 uf_entry_t *ufp = &fip->fi_list[fd];
287 ASSERT((uint_t)fd < fip->fi_nfiles);
293 for (pfd = fd; pfd >= 0; pfd = (pfd & (pfd + 1)) - 1)
302 int fd;
311 for (fd = fip->fi_nfiles; fd != 0; fd >>= 1)
312 if (fip->fi_list[fd >> 1].uf_alloc != 0)
315 return (fd);
321 int fd;
327 for (fd = fip->fi_nfiles; fd != 0; fd >>= 1)
328 nalloc += fip->fi_list[fd >> 1].uf_alloc;
404 * safe to attempt a UF_ENTER() on that fd (which is a valid
410 * end if the fd exceeded the old fi_nfiles.
491 set_active_fd(int fd)
501 ASSERT(fd == -1);
507 /* insert fd into vacant slot, if any */
510 afd->a_fd[i] = fd;
518 ASSERT(fd == -1);
531 afd->a_fd[i] = fd;
541 clear_active_fd(int fd) /* called below and from aio.c */
547 if (afd->a_fd[i] == fd) {
556 * Does this thread have this fd active?
559 is_active_fd(kthread_t *t, int fd)
568 if (afd->a_fd[i] == fd) {
584 getf(int fd)
590 if ((uint_t)fd >= fip->fi_nfiles)
594 * Reserve a slot in the active fd array now so we can call
595 * set_active_fd(fd) for real below, while still inside UF_ENTER().
599 UF_ENTER(ufp, fip, fd);
604 if (fd == fip->fi_badfd && fip->fi_action > 0)
611 set_active_fd(fd); /* record the active file descriptor */
627 closeandsetf(int fd, file_t *newfp)
637 if ((uint_t)fd >= fip->fi_nfiles) {
640 flist_grow(fd);
651 if (fd == fip->fi_badfd) {
657 UF_ENTER(ufp, fip, fd);
663 UF_ENTER(ufp, fip, fd);
668 fd_reserve(fip, fd, 1);
676 UF_ENTER(ufp, fip, fd);
693 * find the ones with this fd as one of their active fds,
724 UF_ENTER(ufp, fip, fd);
731 if (is_active_fd(t, fd)) {
747 UF_ENTER(ufp, fip, fd);
762 UF_ENTER(ufp, fip, fd);
775 * before the fd can be reused. It is important that we don't
790 pollcacheclean(fpip, fd);
799 setf(fd, newfp);
809 releasef(int fd)
814 UF_ENTER(ufp, fip, fd);
816 clear_active_fd(fd); /* clear the active file descriptor */
826 areleasef(int fd, uf_info_t *fip)
830 UF_ENTER(ufp, fip, fd);
843 int fd, nfiles;
857 for (fd = 0, pufp = pfip->fi_list, cufp = cfip->fi_list; fd < nfiles;
858 fd++, pufp++, cufp++) {
871 fd_reserve(cfip, fd, -1);
887 int fd;
892 for (fd = 0; fd < fip->fi_nfiles; fd++, ufp++) {
994 int fd;
1005 fd = fd_find(fip, start);
1006 if (fd >= 0 && fd == fip->fi_badfd) {
1007 start = fd + 1;
1011 if ((uint_t)fd < filelimit)
1013 if (fd >= filelimit) {
1027 UF_ENTER(ufp, fip, fd);
1028 fd_reserve(fip, fd, 1);
1033 return (fd);
1093 int fd;
1096 if ((fd = ufalloc(0)) == -1)
1118 *fdp = fd;
1170 setf(int fd, file_t *fp)
1176 audit_setf(fp, fd);
1180 UF_ENTER(ufp, fip, fd);
1181 fd_reserve(fip, fd, -1);
1184 UF_ENTER(ufp, fip, fd);
1200 f_getfl(int fd, int *flagp)
1207 if ((uint_t)fd >= fip->fi_nfiles)
1210 UF_ENTER(ufp, fip, fd);
1238 f_getfd_error(int fd, int *flagp)
1246 if ((uint_t)fd >= fip->fi_nfiles)
1249 UF_ENTER(ufp, fip, fd);
1269 f_getfd(int fd)
1272 (void) f_getfd_error(fd, &flag);
1282 f_setfd_error(int fd, int flags)
1288 if ((uint_t)fd >= fip->fi_nfiles)
1291 UF_ENTER(ufp, fip, fd);
1304 f_setfd(int fd, char flags)
1306 (void) f_setfd_error(fd, flags);
1380 int fd;
1382 if (error = falloc((vnode_t *)NULL, mode, &fp, &fd))
1385 setf(fd, NULL);
1394 setf(fd, fp);
1395 *fdp = fd;
1426 * This is called from exec to close all fd's that have the FD_CLOEXEC flag
1432 int fd;
1439 for (fd = 0; fd < fip->fi_nfiles; fd++, ufp++) {
1446 fd_reserve(fip, fd, -1);
1453 * in t_pollstate before the fd can be reused. It
1468 pollcacheclean(fpip, fd);
1475 /* Reset bad fd */
1483 * Generate a starting vnode pointer for an (fd, path) pair where 'fd'
1492 fgetstartvp(int fd, char *path, vnode_t **startvpp)
1498 if (fd == AT_FDCWD && path == NULL)
1501 if (fd == AT_FDCWD) {
1520 * be applying the operation to 'fd' itself.
1522 if ((startfp = getf(fd)) == NULL)
1526 releasef(fd);
1538 fsetattrat(int fd, char *path, int flags, struct vattr *vap)
1550 if ((error = fgetstartvp(fd, path, &startvp)) != 0)
1593 int fd;
1600 for (fd = 0; fd < fip->fi_nfiles; fd++) {
1601 UF_ENTER(ufp, fip, fd);
1621 int fd;
1627 for (fd = 0; fd < fip->fi_nfiles; fd++) {
1628 UF_ENTER(ufp, fip, fd);
1666 * curthread does not appear on any fd's fpollinfo list.
1671 int fd;
1676 for (fd = 0; fd < fip->fi_nfiles; fd++) {
1677 UF_ENTER(ufp, fip, fd);
1691 infpollinfo(int fd)
1697 UF_ENTER(ufp, fip, fd);
1706 * Add the curthread to fpollinfo list, meaning this fd is currently in the
1711 addfpollinfo(int fd)
1719 UF_ENTER(ufp, fip, fd);
1722 * this lwp did not call addfpollinfo twice for the same fd.
1738 delfpollinfo(int fd)
1745 UF_ENTER(ufp, fip, fd);
1757 * this lwp did not call addfpollinfo twice for the same fd.
1764 * fd is associated with a port. pfd is a pointer to the fd entry in the
1769 addfd_port(int fd, portfd_t *pfd)
1774 UF_ENTER(ufp, fip, fd);
1792 delfd_port(int fd, portfd_t *pfd)
1797 UF_ENTER(ufp, fip, fd);
1820 * the portfd_t list for this fd. The uf_file, uf_portfd
1821 * pointers in the uf_entry_t struct for this fd would