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);
444 void put_files_struct(struct files_struct *files)
446 if (atomic_dec_and_test(&files->count)) {
447 struct fdtable *fdt = close_files(files);
450 if (fdt != &files->fdtab)
452 kmem_cache_free(files_cachep, files);
458 struct files_struct * files = tsk->files;
460 if (files) {
462 tsk->files = NULL;
464 put_files_struct(files);
501 struct files_struct *files = current->files;
506 spin_lock(&files->file_lock);
508 fdt = files_fdtable(files);
510 if (fd < files->next_fd)
511 fd = files->next_fd;
517 * N.B. For clone tasks sharing a files structure, this test
518 * will limit the total number of files that can be opened.
524 error = expand_files(files, fd);
535 if (start <= files->next_fd)
536 files->next_fd = fd + 1;
553 spin_unlock(&files->file_lock);
568 static void __put_unused_fd(struct files_struct *files, unsigned int fd)
570 struct fdtable *fdt = files_fdtable(files);
572 if (fd < files->next_fd)
573 files->next_fd = fd;
578 struct files_struct *files = current->files;
579 spin_lock(&files->file_lock);
580 __put_unused_fd(files, fd);
581 spin_unlock(&files->file_lock);
589 * The VFS is full of places where we drop the files lock between
604 struct files_struct *files = current->files;
612 if (unlikely(files->resize_in_progress)) {
614 spin_lock(&files->file_lock);
615 fdt = files_fdtable(files);
618 spin_unlock(&files->file_lock);
623 fdt = rcu_dereference_sched(files->fdt);
633 * @files: file struct to retrieve file from
642 struct file *file_close_fd_locked(struct files_struct *files, unsigned fd)
644 struct fdtable *fdt = files_fdtable(files);
647 lockdep_assert_held(&files->file_lock);
656 __put_unused_fd(files, fd);
663 struct files_struct *files = current->files;
666 spin_lock(&files->file_lock);
667 file = file_close_fd_locked(files, fd);
668 spin_unlock(&files->file_lock);
672 return filp_close(file, files);
703 static inline void __range_close(struct files_struct *files, unsigned int fd,
709 spin_lock(&files->file_lock);
710 n = last_fd(files_fdtable(files));
714 file = file_close_fd_locked(files, fd);
716 spin_unlock(&files->file_lock);
717 filp_close(file, files);
719 spin_lock(&files->file_lock);
721 spin_unlock(&files->file_lock);
723 spin_lock(&files->file_lock);
726 spin_unlock(&files->file_lock);
742 struct files_struct *cur_fds = me->files, *fds = NULL;
790 * We're done closing the files we were supposed to. Time to install
794 me->files = cur_fds;
812 struct files_struct *files = current->files;
815 spin_lock(&files->file_lock);
816 file = file_close_fd_locked(files, fd);
817 spin_unlock(&files->file_lock);
822 void do_close_on_exec(struct files_struct *files)
828 spin_lock(&files->file_lock);
832 fdt = files_fdtable(files);
847 __put_unused_fd(files, fd);
848 spin_unlock(&files->file_lock);
849 filp_close(file, files);
851 spin_lock(&files->file_lock);
855 spin_unlock(&files->file_lock);
954 static inline struct file *__fget_files_rcu(struct files_struct *files,
959 struct fdtable *fdt = rcu_dereference_raw(files->fdt);
1008 unlikely(rcu_dereference_raw(files->fdt) != fdt)) {
1030 static struct file *__fget_files(struct files_struct *files, unsigned int fd,
1036 file = __fget_files_rcu(files, fd, mask);
1044 return __fget_files(current->files, fd, mask);
1064 if (task->files)
1065 file = __fget_files(task->files, fd, 0);
1073 return __fget_files_rcu(current->files, fd, 0);
1081 struct files_struct *files;
1085 files = task->files;
1086 if (files)
1087 file = __fget_files_rcu(files, fd, 0);
1096 struct files_struct *files;
1101 files = task->files;
1102 if (files) {
1103 for (; fd < files_fdtable(files)->max_fds; fd++) {
1104 file = __fget_files_rcu(files, fd, 0);
1133 struct files_struct *files = current->files;
1145 if (likely(atomic_read_acquire(&files->count) == 1)) {
1146 file = files_lookup_fd_raw(files, fd);
1151 file = __fget_files(files, fd, mask);
1209 struct files_struct *files = current->files;
1211 spin_lock(&files->file_lock);
1212 fdt = files_fdtable(files);
1217 spin_unlock(&files->file_lock);
1222 struct files_struct *files = current->files;
1226 fdt = files_fdtable(files);
1232 static int do_dup2(struct files_struct *files,
1234 __releases(&files->file_lock)
1245 * fget() treats larval files as absent. Potentially interesting,
1253 fdt = files_fdtable(files);
1264 spin_unlock(&files->file_lock);
1267 filp_close(tofree, files);
1272 spin_unlock(&files->file_lock);
1279 struct files_struct *files = current->files;
1287 spin_lock(&files->file_lock);
1288 err = expand_files(files, fd);
1291 return do_dup2(files, file, fd, flags);
1294 spin_unlock(&files->file_lock);
1358 struct files_struct *files = current->files;
1369 spin_lock(&files->file_lock);
1370 err = expand_files(files, newfd);
1371 file = files_lookup_fd_locked(files, oldfd);
1379 return do_dup2(files, file, newfd, flags);
1384 spin_unlock(&files->file_lock);
1396 struct files_struct *files = current->files;
1401 f = __fget_files_rcu(files, oldfd, 0);
1441 int iterate_fd(struct files_struct *files, unsigned n,
1447 if (!files)
1449 spin_lock(&files->file_lock);
1450 for (fdt = files_fdtable(files); n < fdt->max_fds; n++) {
1452 file = rcu_dereference_check_fdtable(files, fdt->fd[n]);
1459 spin_unlock(&files->file_lock);