Lines Matching refs:files

148 static int expand_fdtable(struct files_struct *files, unsigned int nr)  in expand_fdtable()  argument
149 __releases(files->file_lock) in expand_fdtable()
150 __acquires(files->file_lock) in expand_fdtable()
154 spin_unlock(&files->file_lock); in expand_fdtable()
160 if (atomic_read(&files->count) > 1) in expand_fdtable()
163 spin_lock(&files->file_lock); in expand_fdtable()
174 cur_fdt = files_fdtable(files); in expand_fdtable()
177 rcu_assign_pointer(files->fdt, new_fdt); in expand_fdtable()
178 if (cur_fdt != &files->fdtab) in expand_fdtable()
193 static int expand_files(struct files_struct *files, unsigned int nr) in expand_files() argument
194 __releases(files->file_lock) in expand_files()
195 __acquires(files->file_lock) in expand_files()
201 fdt = files_fdtable(files); in expand_files()
211 if (unlikely(files->resize_in_progress)) { in expand_files()
212 spin_unlock(&files->file_lock); in expand_files()
214 wait_event(files->resize_wait, !files->resize_in_progress); in expand_files()
215 spin_lock(&files->file_lock); in expand_files()
220 files->resize_in_progress = true; in expand_files()
221 expanded = expand_fdtable(files, nr); in expand_files()
222 files->resize_in_progress = false; in expand_files()
224 wake_up_all(&files->resize_wait); in expand_files()
368 static struct fdtable *close_files(struct files_struct * files) in close_files() argument
375 struct fdtable *fdt = rcu_dereference_raw(files->fdt); in close_files()
388 filp_close(file, files); in close_files()
402 struct files_struct *files; in get_files_struct() local
405 files = task->files; in get_files_struct()
406 if (files) in get_files_struct()
407 atomic_inc(&files->count); in get_files_struct()
410 return files; in get_files_struct()
413 void put_files_struct(struct files_struct *files) in put_files_struct() argument
415 if (atomic_dec_and_test(&files->count)) { in put_files_struct()
416 struct fdtable *fdt = close_files(files); in put_files_struct()
419 if (fdt != &files->fdtab) in put_files_struct()
421 kmem_cache_free(files_cachep, files); in put_files_struct()
425 void reset_files_struct(struct files_struct *files) in reset_files_struct() argument
430 old = tsk->files; in reset_files_struct()
432 tsk->files = files; in reset_files_struct()
439 struct files_struct * files = tsk->files; in exit_files() local
441 if (files) { in exit_files()
443 tsk->files = NULL; in exit_files()
445 put_files_struct(files); in exit_files()
479 int __alloc_fd(struct files_struct *files, in __alloc_fd() argument
486 spin_lock(&files->file_lock); in __alloc_fd()
488 fdt = files_fdtable(files); in __alloc_fd()
490 if (fd < files->next_fd) in __alloc_fd()
491 fd = files->next_fd; in __alloc_fd()
504 error = expand_files(files, fd); in __alloc_fd()
515 if (start <= files->next_fd) in __alloc_fd()
516 files->next_fd = fd + 1; in __alloc_fd()
533 spin_unlock(&files->file_lock); in __alloc_fd()
539 return __alloc_fd(current->files, start, rlimit(RLIMIT_NOFILE), flags); in alloc_fd()
544 return __alloc_fd(current->files, 0, rlimit(RLIMIT_NOFILE), flags); in get_unused_fd_flags()
548 static void __put_unused_fd(struct files_struct *files, unsigned int fd) in __put_unused_fd() argument
550 struct fdtable *fdt = files_fdtable(files); in __put_unused_fd()
552 if (fd < files->next_fd) in __put_unused_fd()
553 files->next_fd = fd; in __put_unused_fd()
558 struct files_struct *files = current->files; in put_unused_fd() local
559 spin_lock(&files->file_lock); in put_unused_fd()
560 __put_unused_fd(files, fd); in put_unused_fd()
561 spin_unlock(&files->file_lock); in put_unused_fd()
586 void __fd_install(struct files_struct *files, unsigned int fd, in __fd_install() argument
593 if (unlikely(files->resize_in_progress)) { in __fd_install()
595 spin_lock(&files->file_lock); in __fd_install()
596 fdt = files_fdtable(files); in __fd_install()
599 spin_unlock(&files->file_lock); in __fd_install()
604 fdt = rcu_dereference_sched(files->fdt); in __fd_install()
612 __fd_install(current->files, fd, file); in fd_install()
620 int __close_fd(struct files_struct *files, unsigned fd) in __close_fd() argument
625 spin_lock(&files->file_lock); in __close_fd()
626 fdt = files_fdtable(files); in __close_fd()
633 __put_unused_fd(files, fd); in __close_fd()
634 spin_unlock(&files->file_lock); in __close_fd()
635 return filp_close(file, files); in __close_fd()
638 spin_unlock(&files->file_lock); in __close_fd()
643 void do_close_on_exec(struct files_struct *files) in do_close_on_exec() argument
649 spin_lock(&files->file_lock); in do_close_on_exec()
653 fdt = files_fdtable(files); in do_close_on_exec()
668 __put_unused_fd(files, fd); in do_close_on_exec()
669 spin_unlock(&files->file_lock); in do_close_on_exec()
670 filp_close(file, files); in do_close_on_exec()
672 spin_lock(&files->file_lock); in do_close_on_exec()
676 spin_unlock(&files->file_lock); in do_close_on_exec()
681 struct files_struct *files = current->files; in __fget() local
686 file = fcheck_files(files, fd); in __fget()
732 struct files_struct *files = current->files; in __fget_light() local
735 if (atomic_read(&files->count) == 1) { in __fget_light()
736 file = __fcheck_files(files, fd); in __fget_light()
785 struct files_struct *files = current->files; in set_close_on_exec() local
787 spin_lock(&files->file_lock); in set_close_on_exec()
788 fdt = files_fdtable(files); in set_close_on_exec()
793 spin_unlock(&files->file_lock); in set_close_on_exec()
798 struct files_struct *files = current->files; in get_close_on_exec() local
802 fdt = files_fdtable(files); in get_close_on_exec()
808 static int do_dup2(struct files_struct *files, in do_dup2() argument
810 __releases(&files->file_lock) in do_dup2()
829 fdt = files_fdtable(files); in do_dup2()
840 spin_unlock(&files->file_lock); in do_dup2()
843 filp_close(tofree, files); in do_dup2()
848 spin_unlock(&files->file_lock); in do_dup2()
855 struct files_struct *files = current->files; in replace_fd() local
858 return __close_fd(files, fd); in replace_fd()
863 spin_lock(&files->file_lock); in replace_fd()
864 err = expand_files(files, fd); in replace_fd()
867 return do_dup2(files, file, fd, flags); in replace_fd()
870 spin_unlock(&files->file_lock); in replace_fd()
878 struct files_struct *files = current->files; in ksys_dup3() local
889 spin_lock(&files->file_lock); in ksys_dup3()
890 err = expand_files(files, newfd); in ksys_dup3()
899 return do_dup2(files, file, newfd, flags); in ksys_dup3()
904 spin_unlock(&files->file_lock); in ksys_dup3()
916 struct files_struct *files = current->files; in SYSCALL_DEFINE2() local
920 if (!fcheck_files(files, oldfd)) in SYSCALL_DEFINE2()
961 int iterate_fd(struct files_struct *files, unsigned n, in iterate_fd() argument
967 if (!files) in iterate_fd()
969 spin_lock(&files->file_lock); in iterate_fd()
970 for (fdt = files_fdtable(files); n < fdt->max_fds; n++) { in iterate_fd()
972 file = rcu_dereference_check_fdtable(files, fdt->fd[n]); in iterate_fd()
979 spin_unlock(&files->file_lock); in iterate_fd()