Lines Matching refs:files
165 static int expand_fdtable(struct files_struct *files, int nr) in expand_fdtable() argument
166 __releases(files->file_lock) in expand_fdtable()
167 __acquires(files->file_lock) in expand_fdtable()
171 spin_unlock(&files->file_lock); in expand_fdtable()
177 if (atomic_read(&files->count) > 1) in expand_fdtable()
180 spin_lock(&files->file_lock); in expand_fdtable()
191 cur_fdt = files_fdtable(files); in expand_fdtable()
194 rcu_assign_pointer(files->fdt, new_fdt); in expand_fdtable()
195 if (cur_fdt != &files->fdtab) in expand_fdtable()
210 static int expand_files(struct files_struct *files, int nr) in expand_files() argument
211 __releases(files->file_lock) in expand_files()
212 __acquires(files->file_lock) in expand_files()
218 fdt = files_fdtable(files); in expand_files()
228 if (unlikely(files->resize_in_progress)) { in expand_files()
229 spin_unlock(&files->file_lock); in expand_files()
231 wait_event(files->resize_wait, !files->resize_in_progress); in expand_files()
232 spin_lock(&files->file_lock); in expand_files()
237 files->resize_in_progress = true; in expand_files()
238 expanded = expand_fdtable(files, nr); in expand_files()
239 files->resize_in_progress = false; in expand_files()
241 wake_up_all(&files->resize_wait); in expand_files()
385 static struct fdtable *close_files(struct files_struct * files) in close_files() argument
392 struct fdtable *fdt = rcu_dereference_raw(files->fdt); in close_files()
405 filp_close(file, files); in close_files()
419 struct files_struct *files; in get_files_struct() local
422 files = task->files; in get_files_struct()
423 if (files) in get_files_struct()
424 atomic_inc(&files->count); in get_files_struct()
427 return files; in get_files_struct()
430 void put_files_struct(struct files_struct *files) in put_files_struct() argument
432 if (atomic_dec_and_test(&files->count)) { in put_files_struct()
433 struct fdtable *fdt = close_files(files); in put_files_struct()
436 if (fdt != &files->fdtab) in put_files_struct()
438 kmem_cache_free(files_cachep, files); in put_files_struct()
442 void reset_files_struct(struct files_struct *files) in reset_files_struct() argument
447 old = tsk->files; in reset_files_struct()
449 tsk->files = files; in reset_files_struct()
456 struct files_struct * files = tsk->files; in exit_files() local
458 if (files) { in exit_files()
460 tsk->files = NULL; in exit_files()
462 put_files_struct(files); in exit_files()
496 int __alloc_fd(struct files_struct *files, in __alloc_fd() argument
503 spin_lock(&files->file_lock); in __alloc_fd()
505 fdt = files_fdtable(files); in __alloc_fd()
507 if (fd < files->next_fd) in __alloc_fd()
508 fd = files->next_fd; in __alloc_fd()
521 error = expand_files(files, fd); in __alloc_fd()
532 if (start <= files->next_fd) in __alloc_fd()
533 files->next_fd = fd + 1; in __alloc_fd()
550 spin_unlock(&files->file_lock); in __alloc_fd()
556 return __alloc_fd(current->files, start, rlimit(RLIMIT_NOFILE), flags); in alloc_fd()
561 return __alloc_fd(current->files, 0, rlimit(RLIMIT_NOFILE), flags); in get_unused_fd_flags()
565 static void __put_unused_fd(struct files_struct *files, unsigned int fd) in __put_unused_fd() argument
567 struct fdtable *fdt = files_fdtable(files); in __put_unused_fd()
569 if (fd < files->next_fd) in __put_unused_fd()
570 files->next_fd = fd; in __put_unused_fd()
575 struct files_struct *files = current->files; in put_unused_fd() local
576 spin_lock(&files->file_lock); in put_unused_fd()
577 __put_unused_fd(files, fd); in put_unused_fd()
578 spin_unlock(&files->file_lock); in put_unused_fd()
603 void __fd_install(struct files_struct *files, unsigned int fd, in __fd_install() argument
611 while (unlikely(files->resize_in_progress)) { in __fd_install()
613 wait_event(files->resize_wait, !files->resize_in_progress); in __fd_install()
618 fdt = rcu_dereference_sched(files->fdt); in __fd_install()
626 __fd_install(current->files, fd, file); in fd_install()
634 int __close_fd(struct files_struct *files, unsigned fd) in __close_fd() argument
639 spin_lock(&files->file_lock); in __close_fd()
640 fdt = files_fdtable(files); in __close_fd()
648 __put_unused_fd(files, fd); in __close_fd()
649 spin_unlock(&files->file_lock); in __close_fd()
650 return filp_close(file, files); in __close_fd()
653 spin_unlock(&files->file_lock); in __close_fd()
657 void do_close_on_exec(struct files_struct *files) in do_close_on_exec() argument
663 spin_lock(&files->file_lock); in do_close_on_exec()
667 fdt = files_fdtable(files); in do_close_on_exec()
682 __put_unused_fd(files, fd); in do_close_on_exec()
683 spin_unlock(&files->file_lock); in do_close_on_exec()
684 filp_close(file, files); in do_close_on_exec()
686 spin_lock(&files->file_lock); in do_close_on_exec()
690 spin_unlock(&files->file_lock); in do_close_on_exec()
695 struct files_struct *files = current->files; in __fget() local
700 file = fcheck_files(files, fd); in __fget()
746 struct files_struct *files = current->files; in __fget_light() local
749 if (atomic_read(&files->count) == 1) { in __fget_light()
750 file = __fcheck_files(files, fd); in __fget_light()
794 struct files_struct *files = current->files; in set_close_on_exec() local
796 spin_lock(&files->file_lock); in set_close_on_exec()
797 fdt = files_fdtable(files); in set_close_on_exec()
802 spin_unlock(&files->file_lock); in set_close_on_exec()
807 struct files_struct *files = current->files; in get_close_on_exec() local
811 fdt = files_fdtable(files); in get_close_on_exec()
817 static int do_dup2(struct files_struct *files, in do_dup2() argument
819 __releases(&files->file_lock) in do_dup2()
838 fdt = files_fdtable(files); in do_dup2()
849 spin_unlock(&files->file_lock); in do_dup2()
852 filp_close(tofree, files); in do_dup2()
857 spin_unlock(&files->file_lock); in do_dup2()
864 struct files_struct *files = current->files; in replace_fd() local
867 return __close_fd(files, fd); in replace_fd()
872 spin_lock(&files->file_lock); in replace_fd()
873 err = expand_files(files, fd); in replace_fd()
876 return do_dup2(files, file, fd, flags); in replace_fd()
879 spin_unlock(&files->file_lock); in replace_fd()
887 struct files_struct *files = current->files; in SYSCALL_DEFINE3() local
898 spin_lock(&files->file_lock); in SYSCALL_DEFINE3()
899 err = expand_files(files, newfd); in SYSCALL_DEFINE3()
908 return do_dup2(files, file, newfd, flags); in SYSCALL_DEFINE3()
913 spin_unlock(&files->file_lock); in SYSCALL_DEFINE3()
920 struct files_struct *files = current->files; in SYSCALL_DEFINE2() local
924 if (!fcheck_files(files, oldfd)) in SYSCALL_DEFINE2()
960 int iterate_fd(struct files_struct *files, unsigned n, in iterate_fd() argument
966 if (!files) in iterate_fd()
968 spin_lock(&files->file_lock); in iterate_fd()
969 for (fdt = files_fdtable(files); n < fdt->max_fds; n++) { in iterate_fd()
971 file = rcu_dereference_check_fdtable(files, fdt->fd[n]); in iterate_fd()
978 spin_unlock(&files->file_lock); in iterate_fd()