Lines Matching refs:files

142 static int expand_fdtable(struct files_struct *files, int nr)  in expand_fdtable()  argument
143 __releases(files->file_lock) in expand_fdtable()
144 __acquires(files->file_lock) in expand_fdtable()
148 spin_unlock(&files->file_lock); in expand_fdtable()
150 spin_lock(&files->file_lock); in expand_fdtable()
165 cur_fdt = files_fdtable(files); in expand_fdtable()
169 rcu_assign_pointer(files->fdt, new_fdt); in expand_fdtable()
170 if (cur_fdt != &files->fdtab) in expand_fdtable()
187 static int expand_files(struct files_struct *files, int nr) in expand_files() argument
191 fdt = files_fdtable(files); in expand_files()
202 return expand_fdtable(files, nr); in expand_files()
349 static struct fdtable *close_files(struct files_struct * files) in close_files() argument
356 struct fdtable *fdt = rcu_dereference_raw(files->fdt); in close_files()
369 filp_close(file, files); in close_files()
383 struct files_struct *files; in get_files_struct() local
386 files = task->files; in get_files_struct()
387 if (files) in get_files_struct()
388 atomic_inc(&files->count); in get_files_struct()
391 return files; in get_files_struct()
394 void put_files_struct(struct files_struct *files) in put_files_struct() argument
396 if (atomic_dec_and_test(&files->count)) { in put_files_struct()
397 struct fdtable *fdt = close_files(files); in put_files_struct()
400 if (fdt != &files->fdtab) in put_files_struct()
402 kmem_cache_free(files_cachep, files); in put_files_struct()
406 void reset_files_struct(struct files_struct *files) in reset_files_struct() argument
411 old = tsk->files; in reset_files_struct()
413 tsk->files = files; in reset_files_struct()
420 struct files_struct * files = tsk->files; in exit_files() local
422 if (files) { in exit_files()
424 tsk->files = NULL; in exit_files()
426 put_files_struct(files); in exit_files()
445 int __alloc_fd(struct files_struct *files, in __alloc_fd() argument
452 spin_lock(&files->file_lock); in __alloc_fd()
454 fdt = files_fdtable(files); in __alloc_fd()
456 if (fd < files->next_fd) in __alloc_fd()
457 fd = files->next_fd; in __alloc_fd()
470 error = expand_files(files, fd); in __alloc_fd()
481 if (start <= files->next_fd) in __alloc_fd()
482 files->next_fd = fd + 1; in __alloc_fd()
499 spin_unlock(&files->file_lock); in __alloc_fd()
505 return __alloc_fd(current->files, start, rlimit(RLIMIT_NOFILE), flags); in alloc_fd()
510 return __alloc_fd(current->files, 0, rlimit(RLIMIT_NOFILE), flags); in get_unused_fd_flags()
514 static void __put_unused_fd(struct files_struct *files, unsigned int fd) in __put_unused_fd() argument
516 struct fdtable *fdt = files_fdtable(files); in __put_unused_fd()
518 if (fd < files->next_fd) in __put_unused_fd()
519 files->next_fd = fd; in __put_unused_fd()
524 struct files_struct *files = current->files; in put_unused_fd() local
525 spin_lock(&files->file_lock); in put_unused_fd()
526 __put_unused_fd(files, fd); in put_unused_fd()
527 spin_unlock(&files->file_lock); in put_unused_fd()
552 void __fd_install(struct files_struct *files, unsigned int fd, in __fd_install() argument
556 spin_lock(&files->file_lock); in __fd_install()
557 fdt = files_fdtable(files); in __fd_install()
560 spin_unlock(&files->file_lock); in __fd_install()
565 __fd_install(current->files, fd, file); in fd_install()
573 int __close_fd(struct files_struct *files, unsigned fd) in __close_fd() argument
578 spin_lock(&files->file_lock); in __close_fd()
579 fdt = files_fdtable(files); in __close_fd()
587 __put_unused_fd(files, fd); in __close_fd()
588 spin_unlock(&files->file_lock); in __close_fd()
589 return filp_close(file, files); in __close_fd()
592 spin_unlock(&files->file_lock); in __close_fd()
596 void do_close_on_exec(struct files_struct *files) in do_close_on_exec() argument
602 spin_lock(&files->file_lock); in do_close_on_exec()
606 fdt = files_fdtable(files); in do_close_on_exec()
621 __put_unused_fd(files, fd); in do_close_on_exec()
622 spin_unlock(&files->file_lock); in do_close_on_exec()
623 filp_close(file, files); in do_close_on_exec()
625 spin_lock(&files->file_lock); in do_close_on_exec()
629 spin_unlock(&files->file_lock); in do_close_on_exec()
634 struct files_struct *files = current->files; in __fget() local
638 file = fcheck_files(files, fd); in __fget()
679 struct files_struct *files = current->files; in __fget_light() local
682 if (atomic_read(&files->count) == 1) { in __fget_light()
683 file = __fcheck_files(files, fd); in __fget_light()
727 struct files_struct *files = current->files; in set_close_on_exec() local
729 spin_lock(&files->file_lock); in set_close_on_exec()
730 fdt = files_fdtable(files); in set_close_on_exec()
735 spin_unlock(&files->file_lock); in set_close_on_exec()
740 struct files_struct *files = current->files; in get_close_on_exec() local
744 fdt = files_fdtable(files); in get_close_on_exec()
750 static int do_dup2(struct files_struct *files, in do_dup2() argument
752 __releases(&files->file_lock) in do_dup2()
771 fdt = files_fdtable(files); in do_dup2()
782 spin_unlock(&files->file_lock); in do_dup2()
785 filp_close(tofree, files); in do_dup2()
790 spin_unlock(&files->file_lock); in do_dup2()
797 struct files_struct *files = current->files; in replace_fd() local
800 return __close_fd(files, fd); in replace_fd()
805 spin_lock(&files->file_lock); in replace_fd()
806 err = expand_files(files, fd); in replace_fd()
809 return do_dup2(files, file, fd, flags); in replace_fd()
812 spin_unlock(&files->file_lock); in replace_fd()
820 struct files_struct *files = current->files; in SYSCALL_DEFINE3() local
831 spin_lock(&files->file_lock); in SYSCALL_DEFINE3()
832 err = expand_files(files, newfd); in SYSCALL_DEFINE3()
841 return do_dup2(files, file, newfd, flags); in SYSCALL_DEFINE3()
846 spin_unlock(&files->file_lock); in SYSCALL_DEFINE3()
853 struct files_struct *files = current->files; in SYSCALL_DEFINE2() local
857 if (!fcheck_files(files, oldfd)) in SYSCALL_DEFINE2()
893 int iterate_fd(struct files_struct *files, unsigned n, in iterate_fd() argument
899 if (!files) in iterate_fd()
901 spin_lock(&files->file_lock); in iterate_fd()
902 for (fdt = files_fdtable(files); n < fdt->max_fds; n++) { in iterate_fd()
904 file = rcu_dereference_check_fdtable(files, fdt->fd[n]); in iterate_fd()
911 spin_unlock(&files->file_lock); in iterate_fd()