Lines Matching full:files

121  * space if any.  This does not copy the file pointers.  Called with the files
139 * clear the extra space. Called with the files spinlock held for write.
174 * with slots_wanted > BITS_PER_LONG (embedded instance in files->fdtab in alloc_fdtable()
235 * The files->file_lock should be held on entry, and will be held on exit.
237 static int expand_fdtable(struct files_struct *files, unsigned int nr) in expand_fdtable() argument
238 __releases(files->file_lock) in expand_fdtable()
239 __acquires(files->file_lock) in expand_fdtable()
243 spin_unlock(&files->file_lock); in expand_fdtable()
249 if (atomic_read(&files->count) > 1) in expand_fdtable()
252 spin_lock(&files->file_lock); in expand_fdtable()
255 cur_fdt = files_fdtable(files); in expand_fdtable()
258 rcu_assign_pointer(files->fdt, new_fdt); in expand_fdtable()
259 if (cur_fdt != &files->fdtab) in expand_fdtable()
267 * Expand files.
271 * The files->file_lock should be held on entry, and will be held on exit.
273 static int expand_files(struct files_struct *files, unsigned int nr) in expand_files() argument
274 __releases(files->file_lock) in expand_files()
275 __acquires(files->file_lock) in expand_files()
281 fdt = files_fdtable(files); in expand_files()
287 if (unlikely(files->resize_in_progress)) { in expand_files()
288 spin_unlock(&files->file_lock); in expand_files()
289 wait_event(files->resize_wait, !files->resize_in_progress); in expand_files()
290 spin_lock(&files->file_lock); in expand_files()
299 files->resize_in_progress = true; in expand_files()
300 error = expand_fdtable(files, nr); in expand_files()
301 files->resize_in_progress = false; in expand_files()
303 wake_up_all(&files->resize_wait); in expand_files()
434 * At the same time we know no files will disappear as all other in dup_fd()
459 static struct fdtable *close_files(struct files_struct * files) in close_files() argument
464 * files structure. in close_files()
466 struct fdtable *fdt = rcu_dereference_raw(files->fdt); in close_files()
479 filp_close(file, files); in close_files()
491 void put_files_struct(struct files_struct *files) in put_files_struct() argument
493 if (atomic_dec_and_test(&files->count)) { in put_files_struct()
494 struct fdtable *fdt = close_files(files); in put_files_struct()
497 if (fdt != &files->fdtab) in put_files_struct()
499 kmem_cache_free(files_cachep, files); in put_files_struct()
505 struct files_struct * files = tsk->files; in exit_files() local
507 if (files) { in exit_files()
509 tsk->files = NULL; in exit_files()
511 put_files_struct(files); in exit_files()
557 struct files_struct *files = current->files; in alloc_fd() local
562 spin_lock(&files->file_lock); in alloc_fd()
564 fdt = files_fdtable(files); in alloc_fd()
566 if (fd < files->next_fd) in alloc_fd()
567 fd = files->next_fd; in alloc_fd()
573 * N.B. For clone tasks sharing a files structure, this test in alloc_fd()
574 * will limit the total number of files that can be opened. in alloc_fd()
581 error = expand_files(files, fd); in alloc_fd()
588 if (start <= files->next_fd) in alloc_fd()
589 files->next_fd = fd + 1; in alloc_fd()
596 spin_unlock(&files->file_lock); in alloc_fd()
611 static void __put_unused_fd(struct files_struct *files, unsigned int fd) in __put_unused_fd() argument
613 struct fdtable *fdt = files_fdtable(files); in __put_unused_fd()
615 if (fd < files->next_fd) in __put_unused_fd()
616 files->next_fd = fd; in __put_unused_fd()
621 struct files_struct *files = current->files; in put_unused_fd() local
622 spin_lock(&files->file_lock); in put_unused_fd()
623 __put_unused_fd(files, fd); in put_unused_fd()
624 spin_unlock(&files->file_lock); in put_unused_fd()
639 struct files_struct *files = current->files; in fd_install() local
647 if (unlikely(files->resize_in_progress)) { in fd_install()
649 spin_lock(&files->file_lock); in fd_install()
650 fdt = files_fdtable(files); in fd_install()
653 spin_unlock(&files->file_lock); in fd_install()
658 fdt = rcu_dereference_sched(files->fdt); in fd_install()
668 * @files: file struct to retrieve file from
677 struct file *file_close_fd_locked(struct files_struct *files, unsigned fd) in file_close_fd_locked() argument
679 struct fdtable *fdt = files_fdtable(files); in file_close_fd_locked()
682 lockdep_assert_held(&files->file_lock); in file_close_fd_locked()
691 __put_unused_fd(files, fd); in file_close_fd_locked()
698 struct files_struct *files = current->files; in close_fd() local
701 spin_lock(&files->file_lock); in close_fd()
702 file = file_close_fd_locked(files, fd); in close_fd()
703 spin_unlock(&files->file_lock); in close_fd()
707 return filp_close(file, files); in close_fd()
738 static inline void __range_close(struct files_struct *files, unsigned int fd, in __range_close() argument
744 spin_lock(&files->file_lock); in __range_close()
745 n = last_fd(files_fdtable(files)); in __range_close()
749 file = file_close_fd_locked(files, fd); in __range_close()
751 spin_unlock(&files->file_lock); in __range_close()
752 filp_close(file, files); in __range_close()
754 spin_lock(&files->file_lock); in __range_close()
756 spin_unlock(&files->file_lock); in __range_close()
758 spin_lock(&files->file_lock); in __range_close()
761 spin_unlock(&files->file_lock); in __range_close()
779 struct files_struct *cur_fds = me->files, *fds = NULL; in SYSCALL_DEFINE3()
815 * We're done closing the files we were supposed to. Time to install in SYSCALL_DEFINE3()
819 me->files = cur_fds; in SYSCALL_DEFINE3()
837 struct files_struct *files = current->files; in file_close_fd() local
840 spin_lock(&files->file_lock); in file_close_fd()
841 file = file_close_fd_locked(files, fd); in file_close_fd()
842 spin_unlock(&files->file_lock); in file_close_fd()
847 void do_close_on_exec(struct files_struct *files) in do_close_on_exec() argument
853 spin_lock(&files->file_lock); in do_close_on_exec()
857 fdt = files_fdtable(files); in do_close_on_exec()
872 __put_unused_fd(files, fd); in do_close_on_exec()
873 spin_unlock(&files->file_lock); in do_close_on_exec()
874 filp_close(file, files); in do_close_on_exec()
876 spin_lock(&files->file_lock); in do_close_on_exec()
880 spin_unlock(&files->file_lock); in do_close_on_exec()
974 static inline struct file *__fget_files_rcu(struct files_struct *files, in __fget_files_rcu() argument
979 struct fdtable *fdt = rcu_dereference_raw(files->fdt); in __fget_files_rcu()
1028 unlikely(rcu_dereference_raw(files->fdt) != fdt)) { in __fget_files_rcu()
1050 static struct file *__fget_files(struct files_struct *files, unsigned int fd, in __fget_files() argument
1056 file = __fget_files_rcu(files, fd, mask); in __fget_files()
1064 return __fget_files(current->files, fd, mask); in __fget()
1084 if (task->files) in fget_task()
1085 file = __fget_files(task->files, fd, 0); in fget_task()
1094 struct files_struct *files; in fget_task_next() local
1099 files = task->files; in fget_task_next()
1100 if (files) { in fget_task_next()
1102 for (; fd < files_fdtable(files)->max_fds; fd++) { in fget_task_next()
1103 file = __fget_files_rcu(files, fd, 0); in fget_task_next()
1140 struct files_struct *files = current->files; in __fget_light() local
1152 if (likely(atomic_read_acquire(&files->count) == 1)) { in __fget_light()
1153 file = files_lookup_fd_raw(files, fd); in __fget_light()
1158 file = __fget_files(files, fd, mask); in __fget_light()
1231 struct files_struct *files = current->files; in set_close_on_exec() local
1232 spin_lock(&files->file_lock); in set_close_on_exec()
1233 __set_close_on_exec(fd, files_fdtable(files), flag); in set_close_on_exec()
1234 spin_unlock(&files->file_lock); in set_close_on_exec()
1241 res = close_on_exec(fd, current->files); in get_close_on_exec()
1246 static int do_dup2(struct files_struct *files, in do_dup2() argument
1248 __releases(&files->file_lock) in do_dup2()
1279 fdt = files_fdtable(files); in do_dup2()
1287 spin_unlock(&files->file_lock); in do_dup2()
1290 filp_close(tofree, files); in do_dup2()
1295 spin_unlock(&files->file_lock); in do_dup2()
1302 struct files_struct *files = current->files; in replace_fd() local
1310 spin_lock(&files->file_lock); in replace_fd()
1311 err = expand_files(files, fd); in replace_fd()
1314 return do_dup2(files, file, fd, flags); in replace_fd()
1317 spin_unlock(&files->file_lock); in replace_fd()
1381 struct files_struct *files = current->files; in ksys_dup3() local
1392 spin_lock(&files->file_lock); in ksys_dup3()
1393 err = expand_files(files, newfd); in ksys_dup3()
1394 file = files_lookup_fd_locked(files, oldfd); in ksys_dup3()
1402 return do_dup2(files, file, newfd, flags); in ksys_dup3()
1407 spin_unlock(&files->file_lock); in ksys_dup3()
1419 struct files_struct *files = current->files; in SYSCALL_DEFINE2() local
1424 f = __fget_files_rcu(files, oldfd, 0); in SYSCALL_DEFINE2()
1464 int iterate_fd(struct files_struct *files, unsigned n, in iterate_fd() argument
1470 if (!files) in iterate_fd()
1472 spin_lock(&files->file_lock); in iterate_fd()
1473 for (fdt = files_fdtable(files); n < fdt->max_fds; n++) { in iterate_fd()
1475 file = rcu_dereference_check_fdtable(files, fdt->fd[n]); in iterate_fd()
1482 spin_unlock(&files->file_lock); in iterate_fd()