Lines Matching refs:files

169 static int expand_fdtable(struct files_struct *files, unsigned int nr)  in expand_fdtable()  argument
170 __releases(files->file_lock) in expand_fdtable()
171 __acquires(files->file_lock) in expand_fdtable()
175 spin_unlock(&files->file_lock); in expand_fdtable()
181 if (atomic_read(&files->count) > 1) in expand_fdtable()
184 spin_lock(&files->file_lock); in expand_fdtable()
195 cur_fdt = files_fdtable(files); in expand_fdtable()
198 rcu_assign_pointer(files->fdt, new_fdt); in expand_fdtable()
199 if (cur_fdt != &files->fdtab) in expand_fdtable()
214 static int expand_files(struct files_struct *files, unsigned int nr) in expand_files() argument
215 __releases(files->file_lock) in expand_files()
216 __acquires(files->file_lock) in expand_files()
222 fdt = files_fdtable(files); in expand_files()
232 if (unlikely(files->resize_in_progress)) { in expand_files()
233 spin_unlock(&files->file_lock); in expand_files()
235 wait_event(files->resize_wait, !files->resize_in_progress); in expand_files()
236 spin_lock(&files->file_lock); in expand_files()
241 files->resize_in_progress = true; in expand_files()
242 expanded = expand_fdtable(files, nr); in expand_files()
243 files->resize_in_progress = false; in expand_files()
245 wake_up_all(&files->resize_wait); in expand_files()
412 static struct fdtable *close_files(struct files_struct * files) in close_files() argument
419 struct fdtable *fdt = rcu_dereference_raw(files->fdt); in close_files()
432 filp_close(file, files); in close_files()
444 void put_files_struct(struct files_struct *files) in put_files_struct() argument
446 if (atomic_dec_and_test(&files->count)) { in put_files_struct()
447 struct fdtable *fdt = close_files(files); in put_files_struct()
450 if (fdt != &files->fdtab) in put_files_struct()
452 kmem_cache_free(files_cachep, files); in put_files_struct()
458 struct files_struct * files = tsk->files; in exit_files() local
460 if (files) { in exit_files()
462 tsk->files = NULL; in exit_files()
464 put_files_struct(files); in exit_files()
501 struct files_struct *files = current->files; in alloc_fd() local
506 spin_lock(&files->file_lock); in alloc_fd()
508 fdt = files_fdtable(files); in alloc_fd()
510 if (fd < files->next_fd) in alloc_fd()
511 fd = files->next_fd; in alloc_fd()
524 error = expand_files(files, fd); in alloc_fd()
535 if (start <= files->next_fd) in alloc_fd()
536 files->next_fd = fd + 1; in alloc_fd()
553 spin_unlock(&files->file_lock); in alloc_fd()
568 static void __put_unused_fd(struct files_struct *files, unsigned int fd) in __put_unused_fd() argument
570 struct fdtable *fdt = files_fdtable(files); in __put_unused_fd()
572 if (fd < files->next_fd) in __put_unused_fd()
573 files->next_fd = fd; in __put_unused_fd()
578 struct files_struct *files = current->files; in put_unused_fd() local
579 spin_lock(&files->file_lock); in put_unused_fd()
580 __put_unused_fd(files, fd); in put_unused_fd()
581 spin_unlock(&files->file_lock); in put_unused_fd()
604 struct files_struct *files = current->files; in fd_install() local
609 if (unlikely(files->resize_in_progress)) { in fd_install()
611 spin_lock(&files->file_lock); in fd_install()
612 fdt = files_fdtable(files); in fd_install()
615 spin_unlock(&files->file_lock); in fd_install()
620 fdt = rcu_dereference_sched(files->fdt); in fd_install()
637 static struct file *pick_file(struct files_struct *files, unsigned fd) in pick_file() argument
639 struct fdtable *fdt = files_fdtable(files); in pick_file()
648 __put_unused_fd(files, fd); in pick_file()
655 struct files_struct *files = current->files; in close_fd() local
658 spin_lock(&files->file_lock); in close_fd()
659 file = pick_file(files, fd); in close_fd()
660 spin_unlock(&files->file_lock); in close_fd()
664 return filp_close(file, files); in close_fd()
732 struct files_struct *cur_fds = me->files, *fds = NULL; in __close_range()
784 me->files = cur_fds; in __close_range()
798 return pick_file(current->files, fd); in __close_fd_get_file()
807 struct files_struct *files = current->files; in close_fd_get_file() local
810 spin_lock(&files->file_lock); in close_fd_get_file()
811 file = pick_file(files, fd); in close_fd_get_file()
812 spin_unlock(&files->file_lock); in close_fd_get_file()
817 void do_close_on_exec(struct files_struct *files) in do_close_on_exec() argument
823 spin_lock(&files->file_lock); in do_close_on_exec()
827 fdt = files_fdtable(files); in do_close_on_exec()
842 __put_unused_fd(files, fd); in do_close_on_exec()
843 spin_unlock(&files->file_lock); in do_close_on_exec()
844 filp_close(file, files); in do_close_on_exec()
846 spin_lock(&files->file_lock); in do_close_on_exec()
850 spin_unlock(&files->file_lock); in do_close_on_exec()
853 static inline struct file *__fget_files_rcu(struct files_struct *files, in __fget_files_rcu() argument
858 struct fdtable *fdt = rcu_dereference_raw(files->fdt); in __fget_files_rcu()
893 if (unlikely(rcu_dereference_raw(files->fdt) != fdt) || in __fget_files_rcu()
907 static struct file *__fget_files(struct files_struct *files, unsigned int fd, in __fget_files() argument
913 file = __fget_files_rcu(files, fd, mask); in __fget_files()
921 return __fget_files(current->files, fd, mask); in __fget()
941 if (task->files) in fget_task()
942 file = __fget_files(task->files, fd, 0); in fget_task()
951 struct files_struct *files; in task_lookup_fd_rcu() local
955 files = task->files; in task_lookup_fd_rcu()
956 if (files) in task_lookup_fd_rcu()
957 file = files_lookup_fd_rcu(files, fd); in task_lookup_fd_rcu()
966 struct files_struct *files; in task_lookup_next_fd_rcu() local
971 files = task->files; in task_lookup_next_fd_rcu()
972 if (files) { in task_lookup_next_fd_rcu()
973 for (; fd < files_fdtable(files)->max_fds; fd++) { in task_lookup_next_fd_rcu()
974 file = files_lookup_fd_rcu(files, fd); in task_lookup_next_fd_rcu()
1003 struct files_struct *files = current->files; in __fget_light() local
1015 if (atomic_read_acquire(&files->count) == 1) { in __fget_light()
1016 file = files_lookup_fd_raw(files, fd); in __fget_light()
1065 struct files_struct *files = current->files; in set_close_on_exec() local
1067 spin_lock(&files->file_lock); in set_close_on_exec()
1068 fdt = files_fdtable(files); in set_close_on_exec()
1073 spin_unlock(&files->file_lock); in set_close_on_exec()
1078 struct files_struct *files = current->files; in get_close_on_exec() local
1082 fdt = files_fdtable(files); in get_close_on_exec()
1088 static int do_dup2(struct files_struct *files, in do_dup2() argument
1090 __releases(&files->file_lock) in do_dup2()
1109 fdt = files_fdtable(files); in do_dup2()
1120 spin_unlock(&files->file_lock); in do_dup2()
1123 filp_close(tofree, files); in do_dup2()
1128 spin_unlock(&files->file_lock); in do_dup2()
1135 struct files_struct *files = current->files; in replace_fd() local
1143 spin_lock(&files->file_lock); in replace_fd()
1144 err = expand_files(files, fd); in replace_fd()
1147 return do_dup2(files, file, fd, flags); in replace_fd()
1150 spin_unlock(&files->file_lock); in replace_fd()
1219 struct files_struct *files = current->files; in ksys_dup3() local
1230 spin_lock(&files->file_lock); in ksys_dup3()
1231 err = expand_files(files, newfd); in ksys_dup3()
1232 file = files_lookup_fd_locked(files, oldfd); in ksys_dup3()
1240 return do_dup2(files, file, newfd, flags); in ksys_dup3()
1245 spin_unlock(&files->file_lock); in ksys_dup3()
1257 struct files_struct *files = current->files; in SYSCALL_DEFINE2() local
1261 if (!files_lookup_fd_rcu(files, oldfd)) in SYSCALL_DEFINE2()
1298 int iterate_fd(struct files_struct *files, unsigned n, in iterate_fd() argument
1304 if (!files) in iterate_fd()
1306 spin_lock(&files->file_lock); in iterate_fd()
1307 for (fdt = files_fdtable(files); n < fdt->max_fds; n++) { in iterate_fd()
1309 file = rcu_dereference_check_fdtable(files, fdt->fd[n]); in iterate_fd()
1316 spin_unlock(&files->file_lock); in iterate_fd()