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.
167 * The files->file_lock should be held on entry, and will be held on exit.
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()
207 * Expand files.
210 * Return <0 error code on error; 0 when nothing done; 1 when files were
212 * The files->file_lock should be held on entry, and will be held on exit.
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()
312 * Allocate a new files structure and copy contents from the
313 * passed in files structure.
389 * instantiated in the files array if a sibling thread in dup_fd()
412 static struct fdtable *close_files(struct files_struct * files) in close_files() argument
417 * files structure. in close_files()
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()
517 * N.B. For clone tasks sharing a files structure, this test in alloc_fd()
518 * will limit the total number of files that can be opened. 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()
589 * The VFS is full of places where we drop the files lock between
604 struct files_struct *files = current->files; in fd_install() local
612 if (unlikely(files->resize_in_progress)) { in fd_install()
614 spin_lock(&files->file_lock); in fd_install()
615 fdt = files_fdtable(files); in fd_install()
618 spin_unlock(&files->file_lock); in fd_install()
623 fdt = rcu_dereference_sched(files->fdt); in fd_install()
633 * @files: file struct to retrieve file from
642 struct file *file_close_fd_locked(struct files_struct *files, unsigned fd) in file_close_fd_locked() argument
644 struct fdtable *fdt = files_fdtable(files); in file_close_fd_locked()
647 lockdep_assert_held(&files->file_lock); in file_close_fd_locked()
656 __put_unused_fd(files, fd); in file_close_fd_locked()
663 struct files_struct *files = current->files; in close_fd() local
666 spin_lock(&files->file_lock); in close_fd()
667 file = file_close_fd_locked(files, fd); in close_fd()
668 spin_unlock(&files->file_lock); in close_fd()
672 return filp_close(file, files); in close_fd()
703 static inline void __range_close(struct files_struct *files, unsigned int fd, in __range_close() argument
709 spin_lock(&files->file_lock); in __range_close()
710 n = last_fd(files_fdtable(files)); in __range_close()
714 file = file_close_fd_locked(files, fd); in __range_close()
716 spin_unlock(&files->file_lock); in __range_close()
717 filp_close(file, files); in __range_close()
719 spin_lock(&files->file_lock); in __range_close()
721 spin_unlock(&files->file_lock); in __range_close()
723 spin_lock(&files->file_lock); in __range_close()
726 spin_unlock(&files->file_lock); in __range_close()
742 struct files_struct *cur_fds = me->files, *fds = NULL; in __close_range()
790 * We're done closing the files we were supposed to. Time to install in __close_range()
794 me->files = cur_fds; in __close_range()
812 struct files_struct *files = current->files; in file_close_fd() local
815 spin_lock(&files->file_lock); in file_close_fd()
816 file = file_close_fd_locked(files, fd); in file_close_fd()
817 spin_unlock(&files->file_lock); in file_close_fd()
822 void do_close_on_exec(struct files_struct *files) in do_close_on_exec() argument
828 spin_lock(&files->file_lock); in do_close_on_exec()
832 fdt = files_fdtable(files); in do_close_on_exec()
847 __put_unused_fd(files, fd); in do_close_on_exec()
848 spin_unlock(&files->file_lock); in do_close_on_exec()
849 filp_close(file, files); in do_close_on_exec()
851 spin_lock(&files->file_lock); in do_close_on_exec()
855 spin_unlock(&files->file_lock); in do_close_on_exec()
954 static inline struct file *__fget_files_rcu(struct files_struct *files, in __fget_files_rcu() argument
959 struct fdtable *fdt = rcu_dereference_raw(files->fdt); in __fget_files_rcu()
1008 unlikely(rcu_dereference_raw(files->fdt) != fdt)) { in __fget_files_rcu()
1030 static struct file *__fget_files(struct files_struct *files, unsigned int fd, in __fget_files() argument
1036 file = __fget_files_rcu(files, fd, mask); in __fget_files()
1044 return __fget_files(current->files, fd, mask); in __fget()
1064 if (task->files) in fget_task()
1065 file = __fget_files(task->files, fd, 0); in fget_task()
1073 return __fget_files_rcu(current->files, fd, 0); in lookup_fdget_rcu()
1081 struct files_struct *files; in task_lookup_fdget_rcu() local
1085 files = task->files; in task_lookup_fdget_rcu()
1086 if (files) in task_lookup_fdget_rcu()
1087 file = __fget_files_rcu(files, fd, 0); in task_lookup_fdget_rcu()
1096 struct files_struct *files; in task_lookup_next_fdget_rcu() local
1101 files = task->files; in task_lookup_next_fdget_rcu()
1102 if (files) { in task_lookup_next_fdget_rcu()
1103 for (; fd < files_fdtable(files)->max_fds; fd++) { in task_lookup_next_fdget_rcu()
1104 file = __fget_files_rcu(files, fd, 0); in task_lookup_next_fdget_rcu()
1133 struct files_struct *files = current->files; in __fget_light() local
1145 if (likely(atomic_read_acquire(&files->count) == 1)) { in __fget_light()
1146 file = files_lookup_fd_raw(files, fd); in __fget_light()
1151 file = __fget_files(files, fd, mask); in __fget_light()
1209 struct files_struct *files = current->files; in set_close_on_exec() local
1211 spin_lock(&files->file_lock); in set_close_on_exec()
1212 fdt = files_fdtable(files); in set_close_on_exec()
1217 spin_unlock(&files->file_lock); in set_close_on_exec()
1222 struct files_struct *files = current->files; in get_close_on_exec() local
1226 fdt = files_fdtable(files); in get_close_on_exec()
1232 static int do_dup2(struct files_struct *files, in do_dup2() argument
1234 __releases(&files->file_lock) in do_dup2()
1245 * fget() treats larval files as absent. Potentially interesting, in do_dup2()
1253 fdt = files_fdtable(files); in do_dup2()
1264 spin_unlock(&files->file_lock); in do_dup2()
1267 filp_close(tofree, files); in do_dup2()
1272 spin_unlock(&files->file_lock); in do_dup2()
1279 struct files_struct *files = current->files; in replace_fd() local
1287 spin_lock(&files->file_lock); in replace_fd()
1288 err = expand_files(files, fd); in replace_fd()
1291 return do_dup2(files, file, fd, flags); in replace_fd()
1294 spin_unlock(&files->file_lock); in replace_fd()
1358 struct files_struct *files = current->files; in ksys_dup3() local
1369 spin_lock(&files->file_lock); in ksys_dup3()
1370 err = expand_files(files, newfd); in ksys_dup3()
1371 file = files_lookup_fd_locked(files, oldfd); in ksys_dup3()
1379 return do_dup2(files, file, newfd, flags); in ksys_dup3()
1384 spin_unlock(&files->file_lock); in ksys_dup3()
1396 struct files_struct *files = current->files; in SYSCALL_DEFINE2() local
1401 f = __fget_files_rcu(files, oldfd, 0); in SYSCALL_DEFINE2()
1441 int iterate_fd(struct files_struct *files, unsigned n, in iterate_fd() argument
1447 if (!files) in iterate_fd()
1449 spin_lock(&files->file_lock); in iterate_fd()
1450 for (fdt = files_fdtable(files); n < fdt->max_fds; n++) { in iterate_fd()
1452 file = rcu_dereference_check_fdtable(files, fdt->fd[n]); in iterate_fd()
1459 spin_unlock(&files->file_lock); in iterate_fd()