Lines Matching full:files

51  * space if any.  This does not copy the file pointers.  Called with the files
74 * clear the extra space. Called with the files spinlock held for write.
151 * The files->file_lock should be held on entry, and will be held on exit.
153 static int expand_fdtable(struct files_struct *files, unsigned int nr) in expand_fdtable() argument
154 __releases(files->file_lock) in expand_fdtable()
155 __acquires(files->file_lock) in expand_fdtable()
159 spin_unlock(&files->file_lock); in expand_fdtable()
165 if (atomic_read(&files->count) > 1) in expand_fdtable()
168 spin_lock(&files->file_lock); in expand_fdtable()
179 cur_fdt = files_fdtable(files); in expand_fdtable()
182 rcu_assign_pointer(files->fdt, new_fdt); in expand_fdtable()
183 if (cur_fdt != &files->fdtab) in expand_fdtable()
191 * Expand files.
194 * Return <0 error code on error; 0 when nothing done; 1 when files were
196 * The files->file_lock should be held on entry, and will be held on exit.
198 static int expand_files(struct files_struct *files, unsigned int nr) in expand_files() argument
199 __releases(files->file_lock) in expand_files()
200 __acquires(files->file_lock) in expand_files()
206 fdt = files_fdtable(files); in expand_files()
216 if (unlikely(files->resize_in_progress)) { in expand_files()
217 spin_unlock(&files->file_lock); in expand_files()
219 wait_event(files->resize_wait, !files->resize_in_progress); in expand_files()
220 spin_lock(&files->file_lock); in expand_files()
225 files->resize_in_progress = true; in expand_files()
226 expanded = expand_fdtable(files, nr); in expand_files()
227 files->resize_in_progress = false; in expand_files()
229 wake_up_all(&files->resize_wait); in expand_files()
283 * Allocate a new files structure and copy contents from the
284 * passed in files structure.
360 * instantiated in the files array if a sibling thread in dup_fd()
383 static struct fdtable *close_files(struct files_struct * files) in close_files() argument
388 * files structure. in close_files()
390 struct fdtable *fdt = rcu_dereference_raw(files->fdt); in close_files()
403 filp_close(file, files); in close_files()
415 void put_files_struct(struct files_struct *files) in put_files_struct() argument
417 if (atomic_dec_and_test(&files->count)) { in put_files_struct()
418 struct fdtable *fdt = close_files(files); in put_files_struct()
421 if (fdt != &files->fdtab) in put_files_struct()
423 kmem_cache_free(files_cachep, files); in put_files_struct()
429 struct files_struct * files = tsk->files; in exit_files() local
431 if (files) { in exit_files()
433 tsk->files = NULL; in exit_files()
435 put_files_struct(files); in exit_files()
472 struct files_struct *files = current->files; in alloc_fd() local
477 spin_lock(&files->file_lock); in alloc_fd()
479 fdt = files_fdtable(files); in alloc_fd()
481 if (fd < files->next_fd) in alloc_fd()
482 fd = files->next_fd; in alloc_fd()
488 * N.B. For clone tasks sharing a files structure, this test in alloc_fd()
489 * will limit the total number of files that can be opened. in alloc_fd()
495 error = expand_files(files, fd); in alloc_fd()
506 if (start <= files->next_fd) in alloc_fd()
507 files->next_fd = fd + 1; in alloc_fd()
524 spin_unlock(&files->file_lock); in alloc_fd()
539 static void __put_unused_fd(struct files_struct *files, unsigned int fd) in __put_unused_fd() argument
541 struct fdtable *fdt = files_fdtable(files); in __put_unused_fd()
543 if (fd < files->next_fd) in __put_unused_fd()
544 files->next_fd = fd; in __put_unused_fd()
549 struct files_struct *files = current->files; in put_unused_fd() local
550 spin_lock(&files->file_lock); in put_unused_fd()
551 __put_unused_fd(files, fd); in put_unused_fd()
552 spin_unlock(&files->file_lock); in put_unused_fd()
560 * The VFS is full of places where we drop the files lock between
575 struct files_struct *files = current->files; in fd_install() local
580 if (unlikely(files->resize_in_progress)) { in fd_install()
582 spin_lock(&files->file_lock); in fd_install()
583 fdt = files_fdtable(files); in fd_install()
586 spin_unlock(&files->file_lock); in fd_install()
591 fdt = rcu_dereference_sched(files->fdt); in fd_install()
601 * @files: file struct to retrieve file from
609 static struct file *pick_file(struct files_struct *files, unsigned fd) in pick_file() argument
614 spin_lock(&files->file_lock); in pick_file()
615 fdt = files_fdtable(files); in pick_file()
626 __put_unused_fd(files, fd); in pick_file()
629 spin_unlock(&files->file_lock); in pick_file()
635 struct files_struct *files = current->files; in close_fd() local
638 file = pick_file(files, fd); in close_fd()
642 return filp_close(file, files); in close_fd()
648 * @cur_fds: files struct
705 struct files_struct *cur_fds = me->files, *fds = NULL; in __close_range()
753 * We're done closing the files we were supposed to. Time to install in __close_range()
757 me->files = cur_fds; in __close_range()
766 * See close_fd_get_file() below, this variant assumes current->files->file_lock
771 struct files_struct *files = current->files; in __close_fd_get_file() local
775 fdt = files_fdtable(files); in __close_fd_get_file()
782 __put_unused_fd(files, fd); in __close_fd_get_file()
798 struct files_struct *files = current->files; in close_fd_get_file() local
801 spin_lock(&files->file_lock); in close_fd_get_file()
803 spin_unlock(&files->file_lock); in close_fd_get_file()
808 void do_close_on_exec(struct files_struct *files) in do_close_on_exec() argument
814 spin_lock(&files->file_lock); in do_close_on_exec()
818 fdt = files_fdtable(files); in do_close_on_exec()
833 __put_unused_fd(files, fd); in do_close_on_exec()
834 spin_unlock(&files->file_lock); in do_close_on_exec()
835 filp_close(file, files); in do_close_on_exec()
837 spin_lock(&files->file_lock); in do_close_on_exec()
841 spin_unlock(&files->file_lock); in do_close_on_exec()
844 static struct file *__fget_files(struct files_struct *files, unsigned int fd, in __fget_files() argument
851 file = files_lookup_fd_rcu(files, fd); in __fget_files()
870 return __fget_files(current->files, fd, mask, refs); in __fget()
895 if (task->files) in fget_task()
896 file = __fget_files(task->files, fd, 0, 1); in fget_task()
905 struct files_struct *files; in task_lookup_fd_rcu() local
909 files = task->files; in task_lookup_fd_rcu()
910 if (files) in task_lookup_fd_rcu()
911 file = files_lookup_fd_rcu(files, fd); in task_lookup_fd_rcu()
920 struct files_struct *files; in task_lookup_next_fd_rcu() local
925 files = task->files; in task_lookup_next_fd_rcu()
926 if (files) { in task_lookup_next_fd_rcu()
927 for (; fd < files_fdtable(files)->max_fds; fd++) { in task_lookup_next_fd_rcu()
928 file = files_lookup_fd_rcu(files, fd); in task_lookup_next_fd_rcu()
956 struct files_struct *files = current->files; in __fget_light() local
959 if (atomic_read(&files->count) == 1) { in __fget_light()
960 file = files_lookup_fd_raw(files, fd); in __fget_light()
1009 struct files_struct *files = current->files; in set_close_on_exec() local
1011 spin_lock(&files->file_lock); in set_close_on_exec()
1012 fdt = files_fdtable(files); in set_close_on_exec()
1017 spin_unlock(&files->file_lock); in set_close_on_exec()
1022 struct files_struct *files = current->files; in get_close_on_exec() local
1026 fdt = files_fdtable(files); in get_close_on_exec()
1032 static int do_dup2(struct files_struct *files, in do_dup2() argument
1034 __releases(&files->file_lock) in do_dup2()
1045 * fget() treats larval files as absent. Potentially interesting, in do_dup2()
1053 fdt = files_fdtable(files); in do_dup2()
1064 spin_unlock(&files->file_lock); in do_dup2()
1067 filp_close(tofree, files); in do_dup2()
1072 spin_unlock(&files->file_lock); in do_dup2()
1079 struct files_struct *files = current->files; in replace_fd() local
1087 spin_lock(&files->file_lock); in replace_fd()
1088 err = expand_files(files, fd); in replace_fd()
1091 return do_dup2(files, file, fd, flags); in replace_fd()
1094 spin_unlock(&files->file_lock); in replace_fd()
1163 struct files_struct *files = current->files; in ksys_dup3() local
1174 spin_lock(&files->file_lock); in ksys_dup3()
1175 err = expand_files(files, newfd); in ksys_dup3()
1176 file = files_lookup_fd_locked(files, oldfd); in ksys_dup3()
1184 return do_dup2(files, file, newfd, flags); in ksys_dup3()
1189 spin_unlock(&files->file_lock); in ksys_dup3()
1201 struct files_struct *files = current->files; in SYSCALL_DEFINE2() local
1205 if (!files_lookup_fd_rcu(files, oldfd)) in SYSCALL_DEFINE2()
1242 int iterate_fd(struct files_struct *files, unsigned n, in iterate_fd() argument
1248 if (!files) in iterate_fd()
1250 spin_lock(&files->file_lock); in iterate_fd()
1251 for (fdt = files_fdtable(files); n < fdt->max_fds; n++) { in iterate_fd()
1253 file = rcu_dereference_check_fdtable(files, fdt->fd[n]); in iterate_fd()
1260 spin_unlock(&files->file_lock); in iterate_fd()