Lines Matching full:fd
7 * Manage the dynamic fd arrays in the process files_struct.
36 kvfree(fdt->fd); in __free_fdtable()
50 * Copy 'count' fd bits from the old table to the new table and clear the extra
84 memcpy(nfdt->fd, ofdt->fd, cpy); in copy_fdtable()
85 memset((char *)nfdt->fd + cpy, 0, set); in copy_fdtable()
139 fdt->fd = data; in alloc_fdtable()
155 kvfree(fdt->fd); in alloc_fdtable()
164 * This function will allocate a new fdtable and both fd array and fdset, of
249 static inline void __set_close_on_exec(unsigned int fd, struct fdtable *fdt) in __set_close_on_exec() argument
251 __set_bit(fd, fdt->close_on_exec); in __set_close_on_exec()
254 static inline void __clear_close_on_exec(unsigned int fd, struct fdtable *fdt) in __clear_close_on_exec() argument
256 if (test_bit(fd, fdt->close_on_exec)) in __clear_close_on_exec()
257 __clear_bit(fd, fdt->close_on_exec); in __clear_close_on_exec()
260 static inline void __set_open_fd(unsigned int fd, struct fdtable *fdt) in __set_open_fd() argument
262 __set_bit(fd, fdt->open_fds); in __set_open_fd()
263 fd /= BITS_PER_LONG; in __set_open_fd()
264 if (!~fdt->open_fds[fd]) in __set_open_fd()
265 __set_bit(fd, fdt->full_fds_bits); in __set_open_fd()
268 static inline void __clear_open_fd(unsigned int fd, struct fdtable *fdt) in __clear_open_fd() argument
270 __clear_bit(fd, fdt->open_fds); in __clear_open_fd()
271 __clear_bit(fd / BITS_PER_LONG, fdt->full_fds_bits); in __clear_open_fd()
279 /* Find the last open fd */ in count_open_files()
339 new_fdt->fd = &newf->fd_array[0]; in dup_fd()
346 * Check whether we need to allocate a larger fd array and fd set. in dup_fd()
368 * Reacquire the oldf lock and a pointer to its fd table in dup_fd()
369 * who knows it may have a new bigger fd table. We need in dup_fd()
379 old_fds = old_fdt->fd; in dup_fd()
380 new_fds = new_fdt->fd; in dup_fd()
388 * The fd may be claimed in the fd bitmap but not yet in dup_fd()
391 * fd is available to the new process. in dup_fd()
415 * It is safe to dereference the fd table without RCU or in close_files()
430 struct file * file = xchg(&fdt->fd[i], NULL); in close_files()
473 .fd = &init_files.fd_array[0],
502 unsigned int fd; in alloc_fd() local
509 fd = start; in alloc_fd()
510 if (fd < files->next_fd) in alloc_fd()
511 fd = files->next_fd; in alloc_fd()
513 if (fd < fdt->max_fds) in alloc_fd()
514 fd = find_next_fd(fdt, fd); in alloc_fd()
521 if (fd >= end) in alloc_fd()
524 error = expand_files(files, fd); in alloc_fd()
536 files->next_fd = fd + 1; in alloc_fd()
538 __set_open_fd(fd, fdt); in alloc_fd()
540 __set_close_on_exec(fd, fdt); in alloc_fd()
542 __clear_close_on_exec(fd, fdt); in alloc_fd()
543 error = fd; in alloc_fd()
546 if (rcu_access_pointer(fdt->fd[fd]) != NULL) { in alloc_fd()
547 printk(KERN_WARNING "alloc_fd: slot %d not NULL!\n", fd); in alloc_fd()
548 rcu_assign_pointer(fdt->fd[fd], NULL); in alloc_fd()
568 static void __put_unused_fd(struct files_struct *files, unsigned int fd) in __put_unused_fd() argument
571 __clear_open_fd(fd, fdt); in __put_unused_fd()
572 if (fd < files->next_fd) in __put_unused_fd()
573 files->next_fd = fd; in __put_unused_fd()
576 void put_unused_fd(unsigned int fd) in put_unused_fd() argument
580 __put_unused_fd(files, fd); in put_unused_fd()
587 * Install a file pointer in the fd array.
602 void fd_install(unsigned int fd, struct file *file) in fd_install() argument
613 BUG_ON(fdt->fd[fd] != NULL); in fd_install()
614 rcu_assign_pointer(fdt->fd[fd], file); in fd_install()
621 BUG_ON(fdt->fd[fd] != NULL); in fd_install()
622 rcu_assign_pointer(fdt->fd[fd], file); in fd_install()
629 * pick_file - return file associatd with fd
631 * @fd: file descriptor to retrieve file for
635 * Returns: The file associated with @fd (NULL if @fd is not open)
637 static struct file *pick_file(struct files_struct *files, unsigned fd) in pick_file() argument
642 if (fd >= fdt->max_fds) in pick_file()
645 fd = array_index_nospec(fd, fdt->max_fds); in pick_file()
646 file = fdt->fd[fd]; in pick_file()
648 rcu_assign_pointer(fdt->fd[fd], NULL); in pick_file()
649 __put_unused_fd(files, fd); in pick_file()
654 int close_fd(unsigned fd) in close_fd() argument
660 file = pick_file(files, fd); in close_fd()
670 * last_fd - return last valid index into fd table
683 unsigned int fd, unsigned int max_fd) in __range_cloexec() argument
691 if (fd <= max_fd) in __range_cloexec()
692 bitmap_set(fdt->close_on_exec, fd, max_fd - fd + 1); in __range_cloexec()
696 static inline void __range_close(struct files_struct *files, unsigned int fd, in __range_close() argument
706 for (; fd <= max_fd; fd++) { in __range_close()
707 file = pick_file(files, fd); in __range_close()
725 * @fd: starting file descriptor to close
730 * from @fd up to and including @max_fd are closed.
732 int __close_range(unsigned fd, unsigned max_fd, unsigned int flags) in __close_range() argument
740 if (fd > max_fd) in __close_range()
760 max_unshare_fds = fd; in __close_range()
777 __range_cloexec(cur_fds, fd, max_fd); in __close_range()
779 __range_close(cur_fds, fd, max_fd); in __close_range()
799 struct file *__close_fd_get_file(unsigned int fd) in __close_fd_get_file() argument
801 return pick_file(current->files, fd); in __close_fd_get_file()
808 struct file *close_fd_get_file(unsigned int fd) in close_fd_get_file() argument
814 file = pick_file(files, fd); in close_fd_get_file()
829 unsigned fd = i * BITS_PER_LONG; in do_close_on_exec() local
831 if (fd >= fdt->max_fds) in do_close_on_exec()
837 for ( ; set ; fd++, set >>= 1) { in do_close_on_exec()
841 file = fdt->fd[fd]; in do_close_on_exec()
844 rcu_assign_pointer(fdt->fd[fd], NULL); in do_close_on_exec()
845 __put_unused_fd(files, fd); in do_close_on_exec()
857 unsigned int fd, fmode_t mask) in __fget_files_rcu() argument
864 if (unlikely(fd >= fdt->max_fds)) in __fget_files_rcu()
867 fdentry = fdt->fd + array_index_nospec(fd, fdt->max_fds); in __fget_files_rcu()
890 * Note that we don't need to re-check the 'fdt->fd' in __fget_files_rcu()
910 static struct file *__fget_files(struct files_struct *files, unsigned int fd, in __fget_files() argument
916 file = __fget_files_rcu(files, fd, mask); in __fget_files()
922 static inline struct file *__fget(unsigned int fd, fmode_t mask) in __fget() argument
924 return __fget_files(current->files, fd, mask); in __fget()
927 struct file *fget(unsigned int fd) in fget() argument
929 return __fget(fd, FMODE_PATH); in fget()
933 struct file *fget_raw(unsigned int fd) in fget_raw() argument
935 return __fget(fd, 0); in fget_raw()
939 struct file *fget_task(struct task_struct *task, unsigned int fd) in fget_task() argument
945 file = __fget_files(task->files, fd, 0); in fget_task()
951 struct file *task_lookup_fd_rcu(struct task_struct *task, unsigned int fd) in task_lookup_fd_rcu() argument
960 file = files_lookup_fd_rcu(files, fd); in task_lookup_fd_rcu()
970 unsigned int fd = *ret_fd; in task_lookup_next_fd_rcu() local
976 for (; fd < files_fdtable(files)->max_fds; fd++) { in task_lookup_next_fd_rcu()
977 file = files_lookup_fd_rcu(files, fd); in task_lookup_next_fd_rcu()
983 *ret_fd = fd; in task_lookup_next_fd_rcu()
989 * Lightweight file lookup - no refcnt increment if fd table isn't shared.
1004 static unsigned long __fget_light(unsigned int fd, fmode_t mask) in __fget_light() argument
1019 file = files_lookup_fd_raw(files, fd); in __fget_light()
1024 file = __fget(fd, mask); in __fget_light()
1030 unsigned long __fdget(unsigned int fd) in __fdget() argument
1032 return __fget_light(fd, FMODE_PATH); in __fdget()
1036 unsigned long __fdget_raw(unsigned int fd) in __fdget_raw() argument
1038 return __fget_light(fd, 0); in __fdget_raw()
1057 unsigned long __fdget_pos(unsigned int fd) in __fdget_pos() argument
1059 unsigned long v = __fdget(fd); in __fdget_pos()
1080 void set_close_on_exec(unsigned int fd, int flag) in set_close_on_exec() argument
1087 __set_close_on_exec(fd, fdt); in set_close_on_exec()
1089 __clear_close_on_exec(fd, fdt); in set_close_on_exec()
1093 bool get_close_on_exec(unsigned int fd) in get_close_on_exec() argument
1100 res = close_on_exec(fd, fdt); in get_close_on_exec()
1106 struct file *file, unsigned fd, unsigned flags) in do_dup2() argument
1127 tofree = fdt->fd[fd]; in do_dup2()
1128 if (!tofree && fd_is_open(fd, fdt)) in do_dup2()
1131 rcu_assign_pointer(fdt->fd[fd], file); in do_dup2()
1132 __set_open_fd(fd, fdt); in do_dup2()
1134 __set_close_on_exec(fd, fdt); in do_dup2()
1136 __clear_close_on_exec(fd, fdt); in do_dup2()
1142 return fd; in do_dup2()
1149 int replace_fd(unsigned fd, struct file *file, unsigned flags) in replace_fd() argument
1155 return close_fd(fd); in replace_fd()
1157 if (fd >= rlimit(RLIMIT_NOFILE)) in replace_fd()
1161 err = expand_files(files, fd); in replace_fd()
1164 return do_dup2(files, file, fd, flags); in replace_fd()
1174 * @ufd: __user pointer to write new fd number to
1175 * @o_flags: the O_* flags to apply to the new fd entry
1178 * checks and count updates. Optionally writes the fd number to userspace, if
1184 * Returns newly install fd or -ve on error.
1326 file = rcu_dereference_check_fdtable(files, fdt->fd[n]); in iterate_fd()