Lines Matching full:files

50  * space if any.  This does not copy the file pointers.  Called with the files
73 * clear the extra space. Called with the files spinlock held for write.
150 * The files->file_lock should be held on entry, and will be held on exit.
152 static int expand_fdtable(struct files_struct *files, unsigned int nr) in expand_fdtable() argument
153 __releases(files->file_lock) in expand_fdtable()
154 __acquires(files->file_lock) in expand_fdtable()
158 spin_unlock(&files->file_lock); in expand_fdtable()
164 if (atomic_read(&files->count) > 1) in expand_fdtable()
167 spin_lock(&files->file_lock); in expand_fdtable()
178 cur_fdt = files_fdtable(files); in expand_fdtable()
181 rcu_assign_pointer(files->fdt, new_fdt); in expand_fdtable()
182 if (cur_fdt != &files->fdtab) in expand_fdtable()
190 * Expand files.
193 * Return <0 error code on error; 0 when nothing done; 1 when files were
195 * The files->file_lock should be held on entry, and will be held on exit.
197 static int expand_files(struct files_struct *files, unsigned int nr) in expand_files() argument
198 __releases(files->file_lock) in expand_files()
199 __acquires(files->file_lock) in expand_files()
205 fdt = files_fdtable(files); in expand_files()
215 if (unlikely(files->resize_in_progress)) { in expand_files()
216 spin_unlock(&files->file_lock); in expand_files()
218 wait_event(files->resize_wait, !files->resize_in_progress); in expand_files()
219 spin_lock(&files->file_lock); in expand_files()
224 files->resize_in_progress = true; in expand_files()
225 expanded = expand_fdtable(files, nr); in expand_files()
226 files->resize_in_progress = false; in expand_files()
228 wake_up_all(&files->resize_wait); in expand_files()
282 * Allocate a new files structure and copy contents from the
283 * passed in files structure.
359 * instantiated in the files array if a sibling thread in dup_fd()
382 static struct fdtable *close_files(struct files_struct * files) in close_files() argument
387 * files structure. in close_files()
389 struct fdtable *fdt = rcu_dereference_raw(files->fdt); in close_files()
402 filp_close(file, files); in close_files()
416 struct files_struct *files; in get_files_struct() local
419 files = task->files; in get_files_struct()
420 if (files) in get_files_struct()
421 atomic_inc(&files->count); in get_files_struct()
424 return files; in get_files_struct()
427 void put_files_struct(struct files_struct *files) in put_files_struct() argument
429 if (atomic_dec_and_test(&files->count)) { in put_files_struct()
430 struct fdtable *fdt = close_files(files); in put_files_struct()
433 if (fdt != &files->fdtab) in put_files_struct()
435 kmem_cache_free(files_cachep, files); in put_files_struct()
439 void reset_files_struct(struct files_struct *files) in reset_files_struct() argument
444 old = tsk->files; in reset_files_struct()
446 tsk->files = files; in reset_files_struct()
453 struct files_struct * files = tsk->files; in exit_files() local
455 if (files) { in exit_files()
456 io_uring_files_cancel(files); in exit_files()
458 tsk->files = NULL; in exit_files()
460 put_files_struct(files); in exit_files()
495 int __alloc_fd(struct files_struct *files, in __alloc_fd() argument
502 spin_lock(&files->file_lock); in __alloc_fd()
504 fdt = files_fdtable(files); in __alloc_fd()
506 if (fd < files->next_fd) in __alloc_fd()
507 fd = files->next_fd; in __alloc_fd()
513 * N.B. For clone tasks sharing a files structure, this test in __alloc_fd()
514 * will limit the total number of files that can be opened. in __alloc_fd()
520 error = expand_files(files, fd); in __alloc_fd()
531 if (start <= files->next_fd) in __alloc_fd()
532 files->next_fd = fd + 1; in __alloc_fd()
549 spin_unlock(&files->file_lock); in __alloc_fd()
555 return __alloc_fd(current->files, start, rlimit(RLIMIT_NOFILE), flags); in alloc_fd()
560 return __alloc_fd(current->files, 0, nofile, flags); in __get_unused_fd_flags()
569 static void __put_unused_fd(struct files_struct *files, unsigned int fd) in __put_unused_fd() argument
571 struct fdtable *fdt = files_fdtable(files); in __put_unused_fd()
573 if (fd < files->next_fd) in __put_unused_fd()
574 files->next_fd = fd; in __put_unused_fd()
579 struct files_struct *files = current->files; in put_unused_fd() local
580 spin_lock(&files->file_lock); in put_unused_fd()
581 __put_unused_fd(files, fd); in put_unused_fd()
582 spin_unlock(&files->file_lock); in put_unused_fd()
590 * The VFS is full of places where we drop the files lock between
601 * your throat. 'files' *MUST* be either current->files or obtained
607 void __fd_install(struct files_struct *files, unsigned int fd, in __fd_install() argument
614 if (unlikely(files->resize_in_progress)) { in __fd_install()
616 spin_lock(&files->file_lock); in __fd_install()
617 fdt = files_fdtable(files); in __fd_install()
620 spin_unlock(&files->file_lock); in __fd_install()
625 fdt = rcu_dereference_sched(files->fdt); in __fd_install()
637 __fd_install(current->files, fd, file); in fd_install()
642 static struct file *pick_file(struct files_struct *files, unsigned fd) in pick_file() argument
647 spin_lock(&files->file_lock); in pick_file()
648 fdt = files_fdtable(files); in pick_file()
655 __put_unused_fd(files, fd); in pick_file()
658 spin_unlock(&files->file_lock); in pick_file()
665 int __close_fd(struct files_struct *files, unsigned fd) in __close_fd() argument
669 file = pick_file(files, fd); in __close_fd()
673 return filp_close(file, files); in __close_fd()
690 struct files_struct *cur_fds = me->files, *fds = NULL; in __close_range()
743 * We're done closing the files we were supposed to. Time to install in __close_range()
747 me->files = cur_fds; in __close_range()
762 struct files_struct *files = current->files; in __close_fd_get_file() local
766 spin_lock(&files->file_lock); in __close_fd_get_file()
767 fdt = files_fdtable(files); in __close_fd_get_file()
774 __put_unused_fd(files, fd); in __close_fd_get_file()
775 spin_unlock(&files->file_lock); in __close_fd_get_file()
781 spin_unlock(&files->file_lock); in __close_fd_get_file()
786 void do_close_on_exec(struct files_struct *files) in do_close_on_exec() argument
792 spin_lock(&files->file_lock); in do_close_on_exec()
796 fdt = files_fdtable(files); in do_close_on_exec()
811 __put_unused_fd(files, fd); in do_close_on_exec()
812 spin_unlock(&files->file_lock); in do_close_on_exec()
813 filp_close(file, files); in do_close_on_exec()
815 spin_lock(&files->file_lock); in do_close_on_exec()
819 spin_unlock(&files->file_lock); in do_close_on_exec()
822 static struct file *__fget_files(struct files_struct *files, unsigned int fd, in __fget_files() argument
829 file = fcheck_files(files, fd); in __fget_files()
848 return __fget_files(current->files, fd, mask, refs); in __fget()
873 if (task->files) in fget_task()
874 file = __fget_files(task->files, fd, 0, 1); in fget_task()
898 struct files_struct *files = current->files; in __fget_light() local
901 if (atomic_read(&files->count) == 1) { in __fget_light()
902 file = __fcheck_files(files, fd); in __fget_light()
951 struct files_struct *files = current->files; in set_close_on_exec() local
953 spin_lock(&files->file_lock); in set_close_on_exec()
954 fdt = files_fdtable(files); in set_close_on_exec()
959 spin_unlock(&files->file_lock); in set_close_on_exec()
964 struct files_struct *files = current->files; in get_close_on_exec() local
968 fdt = files_fdtable(files); in get_close_on_exec()
974 static int do_dup2(struct files_struct *files, in do_dup2() argument
976 __releases(&files->file_lock) in do_dup2()
987 * fget() treats larval files as absent. Potentially interesting, in do_dup2()
995 fdt = files_fdtable(files); in do_dup2()
1006 spin_unlock(&files->file_lock); in do_dup2()
1009 filp_close(tofree, files); in do_dup2()
1014 spin_unlock(&files->file_lock); in do_dup2()
1021 struct files_struct *files = current->files; in replace_fd() local
1024 return __close_fd(files, fd); in replace_fd()
1029 spin_lock(&files->file_lock); in replace_fd()
1030 err = expand_files(files, fd); in replace_fd()
1033 return do_dup2(files, file, fd, flags); in replace_fd()
1036 spin_unlock(&files->file_lock); in replace_fd()
1100 struct files_struct *files = current->files; in ksys_dup3() local
1111 spin_lock(&files->file_lock); in ksys_dup3()
1112 err = expand_files(files, newfd); in ksys_dup3()
1121 return do_dup2(files, file, newfd, flags); in ksys_dup3()
1126 spin_unlock(&files->file_lock); in ksys_dup3()
1138 struct files_struct *files = current->files; in SYSCALL_DEFINE2() local
1142 if (!fcheck_files(files, oldfd)) in SYSCALL_DEFINE2()
1178 int iterate_fd(struct files_struct *files, unsigned n, in iterate_fd() argument
1184 if (!files) in iterate_fd()
1186 spin_lock(&files->file_lock); in iterate_fd()
1187 for (fdt = files_fdtable(files); n < fdt->max_fds; n++) { in iterate_fd()
1189 file = rcu_dereference_check_fdtable(files, fdt->fd[n]); in iterate_fd()
1196 spin_unlock(&files->file_lock); in iterate_fd()