Lines Matching refs: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
250 * The files->file_lock should be held on entry, and will be held on exit.
252 static int expand_fdtable(struct files_struct *files, unsigned int nr)
253 __releases(files->file_lock)
254 __acquires(files->file_lock)
258 spin_unlock(&files->file_lock);
264 if (atomic_read(&files->count) > 1)
267 spin_lock(&files->file_lock);
270 cur_fdt = files_fdtable(files);
273 rcu_assign_pointer(files->fdt, new_fdt);
274 if (cur_fdt != &files->fdtab)
282 * Expand files.
286 * The files->file_lock should be held on entry, and will be held on exit.
288 static int expand_files(struct files_struct *files, unsigned int nr)
289 __releases(files->file_lock)
290 __acquires(files->file_lock)
296 fdt = files_fdtable(files);
302 if (unlikely(files->resize_in_progress)) {
303 spin_unlock(&files->file_lock);
304 wait_event(files->resize_wait, !files->resize_in_progress);
305 spin_lock(&files->file_lock);
314 files->resize_in_progress = true;
315 error = expand_fdtable(files, nr);
316 files->resize_in_progress = false;
318 wake_up_all(&files->resize_wait);
449 * At the same time we know no files will disappear as all other
474 static struct fdtable *close_files(struct files_struct * files)
479 * files structure.
481 struct fdtable *fdt = rcu_dereference_raw(files->fdt);
494 filp_close(file, files);
506 void put_files_struct(struct files_struct *files)
508 if (atomic_dec_and_test(&files->count)) {
509 struct fdtable *fdt = close_files(files);
512 if (fdt != &files->fdtab)
514 kmem_cache_free(files_cachep, files);
520 struct files_struct * files = tsk->files;
522 if (files) {
524 tsk->files = NULL;
526 put_files_struct(files);
572 struct files_struct *files = current->files;
577 spin_lock(&files->file_lock);
579 fdt = files_fdtable(files);
581 if (fd < files->next_fd)
582 fd = files->next_fd;
588 * N.B. For clone tasks sharing a files structure, this test
589 * will limit the total number of files that can be opened.
596 error = expand_files(files, fd);
603 if (start <= files->next_fd)
604 files->next_fd = fd + 1;
611 spin_unlock(&files->file_lock);
626 static void __put_unused_fd(struct files_struct *files, unsigned int fd)
628 struct fdtable *fdt = files_fdtable(files);
630 if (fd < files->next_fd)
631 files->next_fd = fd;
636 struct files_struct *files = current->files;
637 spin_lock(&files->file_lock);
638 __put_unused_fd(files, fd);
639 spin_unlock(&files->file_lock);
654 struct files_struct *files = current->files;
662 if (unlikely(files->resize_in_progress)) {
664 spin_lock(&files->file_lock);
665 fdt = files_fdtable(files);
668 spin_unlock(&files->file_lock);
673 fdt = rcu_dereference_sched(files->fdt);
683 * @files: file struct to retrieve file from
692 struct file *file_close_fd_locked(struct files_struct *files, unsigned fd)
694 struct fdtable *fdt = files_fdtable(files);
697 lockdep_assert_held(&files->file_lock);
706 __put_unused_fd(files, fd);
713 struct files_struct *files = current->files;
716 spin_lock(&files->file_lock);
717 file = file_close_fd_locked(files, fd);
718 spin_unlock(&files->file_lock);
722 return filp_close(file, files);
753 static inline void __range_close(struct files_struct *files, unsigned int fd,
759 spin_lock(&files->file_lock);
760 n = last_fd(files_fdtable(files));
764 file = file_close_fd_locked(files, fd);
766 spin_unlock(&files->file_lock);
767 filp_close(file, files);
769 spin_lock(&files->file_lock);
771 spin_unlock(&files->file_lock);
773 spin_lock(&files->file_lock);
776 spin_unlock(&files->file_lock);
794 struct files_struct *cur_fds = me->files, *fds = NULL;
830 * We're done closing the files we were supposed to. Time to install
834 me->files = cur_fds;
852 struct files_struct *files = current->files;
855 spin_lock(&files->file_lock);
856 file = file_close_fd_locked(files, fd);
857 spin_unlock(&files->file_lock);
862 void do_close_on_exec(struct files_struct *files)
868 spin_lock(&files->file_lock);
872 fdt = files_fdtable(files);
887 __put_unused_fd(files, fd);
888 spin_unlock(&files->file_lock);
889 filp_close(file, files);
891 spin_lock(&files->file_lock);
895 spin_unlock(&files->file_lock);
989 static inline struct file *__fget_files_rcu(struct files_struct *files,
994 struct fdtable *fdt = rcu_dereference_raw(files->fdt);
1043 unlikely(rcu_dereference_raw(files->fdt) != fdt)) {
1065 static struct file *__fget_files(struct files_struct *files, unsigned int fd,
1071 file = __fget_files_rcu(files, fd, mask);
1079 return __fget_files(current->files, fd, mask);
1099 if (task->files)
1100 file = __fget_files(task->files, fd, 0);
1109 struct files_struct *files;
1114 files = task->files;
1115 if (files) {
1117 for (; fd < files_fdtable(files)->max_fds; fd++) {
1118 file = __fget_files_rcu(files, fd, 0);
1155 struct files_struct *files = current->files;
1167 if (likely(atomic_read_acquire(&files->count) == 1)) {
1168 file = files_lookup_fd_raw(files, fd);
1173 file = __fget_files(files, fd, mask);
1250 struct files_struct *files = current->files;
1251 spin_lock(&files->file_lock);
1252 __set_close_on_exec(fd, files_fdtable(files), flag);
1253 spin_unlock(&files->file_lock);
1260 res = close_on_exec(fd, current->files);
1265 static int do_dup2(struct files_struct *files,
1267 __releases(&files->file_lock)
1298 fdt = files_fdtable(files);
1306 spin_unlock(&files->file_lock);
1309 filp_close(tofree, files);
1314 spin_unlock(&files->file_lock);
1321 struct files_struct *files = current->files;
1329 spin_lock(&files->file_lock);
1330 err = expand_files(files, fd);
1333 return do_dup2(files, file, fd, flags);
1336 spin_unlock(&files->file_lock);
1400 struct files_struct *files = current->files;
1411 spin_lock(&files->file_lock);
1412 err = expand_files(files, newfd);
1413 file = files_lookup_fd_locked(files, oldfd);
1421 return do_dup2(files, file, newfd, flags);
1426 spin_unlock(&files->file_lock);
1438 struct files_struct *files = current->files;
1443 f = __fget_files_rcu(files, oldfd, 0);
1483 int iterate_fd(struct files_struct *files, unsigned n,
1489 if (!files)
1491 spin_lock(&files->file_lock);
1492 for (fdt = files_fdtable(files); n < fdt->max_fds; n++) {
1494 file = rcu_dereference_check_fdtable(files, fdt->fd[n]);
1501 spin_unlock(&files->file_lock);