Lines Matching refs:fdt

57 static int _fdt_slot_expand(struct dfs_fdtable *fdt, int fd)  in _fdt_slot_expand()  argument
63 if (fd < fdt->maxfd) in _fdt_slot_expand()
77 fds = (struct dfs_file **)rt_realloc(fdt->fds, nr * sizeof(struct dfs_file *)); in _fdt_slot_expand()
84 for (index = fdt->maxfd; index < nr; index++) in _fdt_slot_expand()
88 fdt->fds = fds; in _fdt_slot_expand()
89 fdt->maxfd = nr; in _fdt_slot_expand()
105 static int _fdt_slot_alloc(struct dfs_fdtable *fdt, int startfd) in _fdt_slot_alloc() argument
110 for (idx = startfd; idx < (int)fdt->maxfd; idx++) in _fdt_slot_alloc()
112 if (fdt->fds[idx] == RT_NULL) in _fdt_slot_alloc()
118 idx = fdt->maxfd; in _fdt_slot_alloc()
124 if (_fdt_slot_expand(fdt, idx) < 0) in _fdt_slot_alloc()
144 static int _fdt_fd_alloc(struct dfs_fdtable *fdt, int startfd) in _fdt_fd_alloc() argument
148 idx = _fdt_slot_alloc(fdt, startfd); in _fdt_fd_alloc()
298 int fdt_fd_new(struct dfs_fdtable *fdt) in fdt_fd_new() argument
309 idx = _fdt_fd_alloc(fdt, (fdt == &_fdtab) ? DFS_STDIO_OFFSET : 0); in fdt_fd_new()
315 else if (!fdt->fds[idx]) in fdt_fd_new()
323 fdt->fds[idx] = file; in fdt_fd_new()
329 fdt->fds[idx] = RT_NULL; in fdt_fd_new()
350 void fdt_fd_release(struct dfs_fdtable *fdt, int fd) in fdt_fd_release() argument
352 if (fd < fdt->maxfd) in fdt_fd_release()
356 file = fdt_get_file(fdt, fd); in fdt_fd_release()
367 fdt->fds[fd] = RT_NULL; in fdt_fd_release()
381 struct dfs_file *fdt_get_file(struct dfs_fdtable *fdt, int fd) in fdt_get_file() argument
385 if (fd < 0 || fd >= (int)fdt->maxfd) in fdt_get_file()
390 f = fdt->fds[fd]; in fdt_get_file()
412 int fdt_fd_associate_file(struct dfs_fdtable *fdt, int fd, struct dfs_file *file) in fdt_fd_associate_file() argument
420 if (!fdt) in fdt_fd_associate_file()
431 if ((fd < 0) || (fd >= fdt->maxfd)) in fdt_fd_associate_file()
436 if (fdt->fds[fd]) in fdt_fd_associate_file()
443 fdt->fds[fd] = file; in fdt_fd_associate_file()
459 struct dfs_fdtable *fdt; in fd_new() local
461 fdt = dfs_fdtable_get(); in fd_new()
463 return fdt_fd_new(fdt); in fd_new()
473 struct dfs_fdtable *fdt; in fd_release() local
475 fdt = dfs_fdtable_get(); in fd_release()
476 fdt_fd_release(fdt, fd); in fd_release()
489 struct dfs_fdtable *fdt; in fd_get() local
491 fdt = dfs_fdtable_get(); in fd_get()
493 return fdt_get_file(fdt, fd); in fd_get()
501 struct dfs_fdtable *fdt; in dfs_fdtable_get() local
512 fdt = &lwp->fdt; in dfs_fdtable_get()
514 fdt = &_fdtab; in dfs_fdtable_get()
516 fdt = &_fdtab; in dfs_fdtable_get()
519 return fdt; in dfs_fdtable_get()
534 struct dfs_fdtable *fdt = RT_NULL; in dfs_fdtable_get_from_pid() local
540 fdt = &lwp->fdt; in dfs_fdtable_get_from_pid()
544 return fdt; in dfs_fdtable_get_from_pid()
634 int dfs_fdtable_drop_fd(struct dfs_fdtable *fdt, int fd) in dfs_fdtable_drop_fd() argument
638 if (fdt == NULL) in dfs_fdtable_drop_fd()
640 fdt = &_fdtab; in dfs_fdtable_drop_fd()
648 err = dfs_file_close(fdt->fds[fd]); in dfs_fdtable_drop_fd()
651 fdt_fd_release(fdt, fd); in dfs_fdtable_drop_fd()
672 struct dfs_fdtable *fdt = NULL; in dfs_dup() local
680 fdt = dfs_fdtable_get(); in dfs_dup()
681 if ((oldfd < 0) || (oldfd >= fdt->maxfd)) in dfs_dup()
686 if (!fdt->fds[oldfd]) in dfs_dup()
691 newfd = _fdt_slot_alloc(fdt, startfd); in dfs_dup()
694 fdt->fds[newfd] = fdt->fds[oldfd]; in dfs_dup()
697 rt_atomic_add(&(fdt->fds[newfd]->ref_count), 1); in dfs_dup()
715 struct dfs_fdtable *fdt = NULL; in dfs_dup_to() local
728 fdt = dfs_fdtable_get(); in dfs_dup_to()
729 if ((oldfd < 0) || (oldfd >= fdt->maxfd)) in dfs_dup_to()
733 if (!fdt->fds[oldfd]) in dfs_dup_to()
741 fdtab->fds[newfd] = fdt->fds[oldfd]; in dfs_dup_to()
847 struct dfs_fdtable *fdt = NULL; in sys_dup2() local
857 fdt = dfs_fdtable_get(); in sys_dup2()
858 if ((oldfd < 0) || (oldfd >= fdt->maxfd)) in sys_dup2()
862 if (!fdt->fds[oldfd]) in sys_dup2()
870 if (newfd >= fdt->maxfd) in sys_dup2()
872 newfd = _fdt_slot_expand(fdt, newfd); in sys_dup2()
878 if (fdt->fds[newfd] == fdt->fds[oldfd]) in sys_dup2()
885 if (fdt->fds[newfd]) in sys_dup2()
887 ret = dfs_file_close(fdt->fds[newfd]); in sys_dup2()
895 fdt->fds[newfd] = fdt->fds[oldfd]; in sys_dup2()
897 rt_atomic_add(&(fdt->fds[newfd]->ref_count), 1); in sys_dup2()