Lines Matching refs: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)
170 __releases(files->file_lock)
171 __acquires(files->file_lock)
175 spin_unlock(&files->file_lock);
181 if (atomic_read(&files->count) > 1)
184 spin_lock(&files->file_lock);
195 cur_fdt = files_fdtable(files);
198 rcu_assign_pointer(files->fdt, new_fdt);
199 if (cur_fdt != &files->fdtab)
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)
215 __releases(files->file_lock)
216 __acquires(files->file_lock)
222 fdt = files_fdtable(files);
232 if (unlikely(files->resize_in_progress)) {
233 spin_unlock(&files->file_lock);
235 wait_event(files->resize_wait, !files->resize_in_progress);
236 spin_lock(&files->file_lock);
241 files->resize_in_progress = true;
242 expanded = expand_fdtable(files, nr);
243 files->resize_in_progress = false;
245 wake_up_all(&files->resize_wait);
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
412 static struct fdtable *close_files(struct files_struct * files)
417 * files structure.
419 struct fdtable *fdt = rcu_dereference_raw(files->fdt);
432 filp_close(file, files);
446 struct files_struct *files;
449 files = task->files;
450 if (files)
451 atomic_inc(&files->count);
454 return files;
457 void put_files_struct(struct files_struct *files)
459 if (atomic_dec_and_test(&files->count)) {
460 struct fdtable *fdt = close_files(files);
463 if (fdt != &files->fdtab)
465 kmem_cache_free(files_cachep, files);
469 void reset_files_struct(struct files_struct *files)
474 old = tsk->files;
476 tsk->files = files;
483 struct files_struct * files = tsk->files;
485 if (files) {
487 tsk->files = NULL;
489 put_files_struct(files);
524 int __alloc_fd(struct files_struct *files,
531 spin_lock(&files->file_lock);
533 fdt = files_fdtable(files);
535 if (fd < files->next_fd)
536 fd = files->next_fd;
542 * N.B. For clone tasks sharing a files structure, this test
543 * will limit the total number of files that can be opened.
549 error = expand_files(files, fd);
560 if (start <= files->next_fd)
561 files->next_fd = fd + 1;
578 spin_unlock(&files->file_lock);
584 return __alloc_fd(current->files, start, rlimit(RLIMIT_NOFILE), flags);
589 return __alloc_fd(current->files, 0, nofile, flags);
598 static void __put_unused_fd(struct files_struct *files, unsigned int fd)
600 struct fdtable *fdt = files_fdtable(files);
602 if (fd < files->next_fd)
603 files->next_fd = fd;
608 struct files_struct *files = current->files;
609 spin_lock(&files->file_lock);
610 __put_unused_fd(files, fd);
611 spin_unlock(&files->file_lock);
619 * The VFS is full of places where we drop the files lock between
630 * your throat. 'files' *MUST* be either current->files or obtained
636 void __fd_install(struct files_struct *files, unsigned int fd,
643 if (unlikely(files->resize_in_progress)) {
645 spin_lock(&files->file_lock);
646 fdt = files_fdtable(files);
649 spin_unlock(&files->file_lock);
654 fdt = rcu_dereference_sched(files->fdt);
666 __fd_install(current->files, fd, file);
671 static struct file *pick_file(struct files_struct *files, unsigned fd)
676 spin_lock(&files->file_lock);
677 fdt = files_fdtable(files);
685 __put_unused_fd(files, fd);
688 spin_unlock(&files->file_lock);
695 int __close_fd(struct files_struct *files, unsigned fd)
699 file = pick_file(files, fd);
703 return filp_close(file, files);
720 struct files_struct *cur_fds = me->files, *fds = NULL;
773 * We're done closing the files we were supposed to. Time to install
777 me->files = cur_fds;
786 * See close_fd_get_file() below, this variant assumes current->files->file_lock
791 struct files_struct *files = current->files;
795 fdt = files_fdtable(files);
802 __put_unused_fd(files, fd);
818 struct files_struct *files = current->files;
821 spin_lock(&files->file_lock);
823 spin_unlock(&files->file_lock);
828 void do_close_on_exec(struct files_struct *files)
834 spin_lock(&files->file_lock);
838 fdt = files_fdtable(files);
853 __put_unused_fd(files, fd);
854 spin_unlock(&files->file_lock);
855 filp_close(file, files);
857 spin_lock(&files->file_lock);
861 spin_unlock(&files->file_lock);
864 static inline struct file *__fget_files_rcu(struct files_struct *files,
869 struct fdtable *fdt = rcu_dereference_raw(files->fdt);
905 if (unlikely(rcu_dereference_raw(files->fdt) != fdt) ||
919 static struct file *__fget_files(struct files_struct *files, unsigned int fd,
925 file = __fget_files_rcu(files, fd, mask, refs);
934 return __fget_files(current->files, fd, mask, refs);
959 if (task->files)
960 file = __fget_files(task->files, fd, 0, 1);
984 struct files_struct *files = current->files;
987 if (atomic_read(&files->count) == 1) {
988 file = files_lookup_fd_raw(files, fd);
1051 struct files_struct *files = current->files;
1053 spin_lock(&files->file_lock);
1054 fdt = files_fdtable(files);
1059 spin_unlock(&files->file_lock);
1064 struct files_struct *files = current->files;
1068 fdt = files_fdtable(files);
1074 static int do_dup2(struct files_struct *files,
1076 __releases(&files->file_lock)
1087 * fget() treats larval files as absent. Potentially interesting,
1095 fdt = files_fdtable(files);
1106 spin_unlock(&files->file_lock);
1109 filp_close(tofree, files);
1114 spin_unlock(&files->file_lock);
1121 struct files_struct *files = current->files;
1124 return __close_fd(files, fd);
1129 spin_lock(&files->file_lock);
1130 err = expand_files(files, fd);
1133 return do_dup2(files, file, fd, flags);
1136 spin_unlock(&files->file_lock);
1200 struct files_struct *files = current->files;
1211 spin_lock(&files->file_lock);
1212 err = expand_files(files, newfd);
1213 file = files_lookup_fd_locked(files, oldfd);
1221 return do_dup2(files, file, newfd, flags);
1226 spin_unlock(&files->file_lock);
1238 struct files_struct *files = current->files;
1242 if (!fcheck_files(files, oldfd))
1278 int iterate_fd(struct files_struct *files, unsigned n,
1284 if (!files)
1286 spin_lock(&files->file_lock);
1287 for (fdt = files_fdtable(files); n < fdt->max_fds; n++) {
1289 file = rcu_dereference_check_fdtable(files, fdt->fd[n]);
1296 spin_unlock(&files->file_lock);