• Home
  • Raw
  • Download

Lines Matching full:file

3  *  linux/fs/file.c
17 #include <linux/file.h>
53 * space if any. This does not copy the file pointers. Called with the files
70 * Copy all file descriptors from the old table to the new, expanded table and
79 cpy = ofdt->max_fds * sizeof(struct file *); in copy_fdtable()
80 set = (nfdt->max_fds - ofdt->max_fds) * sizeof(struct file *); in copy_fdtable()
114 nr /= (1024 / sizeof(struct file *)); in alloc_fdtable()
116 nr *= (1024 / sizeof(struct file *)); in alloc_fdtable()
133 data = kvmalloc_array(nr, sizeof(struct file *), GFP_KERNEL_ACCOUNT); in alloc_fdtable()
160 * Expand the file descriptor table.
205 * This function will expand the file structures, if the requested size exceeds
302 struct file **old_fds, **new_fds; in dup_fd()
371 * the file can show up as we are walking the array below. in dup_fd()
377 * ref the file if we see it and mark the fd slot as unused otherwise. in dup_fd()
380 struct file *f = rcu_dereference_raw(*old_fds++); in dup_fd()
391 memset(new_fds, 0, (new_fdt->max_fds - open_files) * sizeof(struct file *)); in dup_fd()
420 struct file * file = xchg(&fdt->fd[i], NULL); in close_files() local
421 if (file) { in close_files()
422 filp_close(file, files); in close_files()
487 * allocate a file descriptor, mark it busy.
577 * Install a file pointer in the fd array.
580 * setting the open_fds bitmap and installing the file in the file
582 * installing a file in the array before us. We need to detect this and
583 * fput() the struct file we are about to overwrite in this case.
588 * This consumes the "file" refcount, so callers should treat it
589 * as if they had called fput(file).
592 void fd_install(unsigned int fd, struct file *file) in fd_install() argument
604 rcu_assign_pointer(fdt->fd[fd], file); in fd_install()
612 rcu_assign_pointer(fdt->fd[fd], file); in fd_install()
619 * pick_file - return file associatd with fd
620 * @files: file struct to retrieve file from
621 * @fd: file descriptor to retrieve file for
625 * Returns: The file associated with @fd (NULL if @fd is not open)
627 static struct file *pick_file(struct files_struct *files, unsigned fd) in pick_file()
630 struct file *file; in pick_file() local
636 file = rcu_dereference_raw(fdt->fd[fd]); in pick_file()
637 if (file) { in pick_file()
641 return file; in pick_file()
647 struct file *file; in close_fd() local
650 file = pick_file(files, fd); in close_fd()
652 if (!file) in close_fd()
655 return filp_close(file, files); in close_fd()
661 * @fdt: File descriptor table.
689 struct file *file; in __range_close() local
697 file = pick_file(files, fd); in __range_close()
698 if (file) { in __range_close()
700 filp_close(file, files); in __range_close()
713 * __close_range() - Close all file descriptors in a given range.
715 * @fd: starting file descriptor to close
716 * @max_fd: last file descriptor to close
719 * This closes a range of file descriptors. All file descriptors
738 * copy all of the file descriptors since they still want to in __close_range()
748 * We used to share our file descriptor table, and have now in __close_range()
762 * the new file descriptor table and drop the old one. in __close_range()
777 struct file *__close_fd_get_file(unsigned int fd) in __close_fd_get_file()
783 * variant of close_fd that gets a ref on the file for later fput.
784 * The caller must ensure that filp_close() called on the file.
786 struct file *close_fd_get_file(unsigned int fd) in close_fd_get_file()
789 struct file *file; in close_fd_get_file() local
792 file = pick_file(files, fd); in close_fd_get_file()
795 return file; in close_fd_get_file()
816 struct file *file; in do_close_on_exec() local
819 file = fdt->fd[fd]; in do_close_on_exec()
820 if (!file) in do_close_on_exec()
825 filp_close(file, files); in do_close_on_exec()
834 static inline struct file *__fget_files_rcu(struct files_struct *files, in __fget_files_rcu()
838 struct file *file; in __fget_files_rcu() local
840 struct file __rcu **fdentry; in __fget_files_rcu()
846 file = rcu_dereference_raw(*fdentry); in __fget_files_rcu()
847 if (unlikely(!file)) in __fget_files_rcu()
850 if (unlikely(file->f_mode & mask)) in __fget_files_rcu()
854 * Ok, we have a file pointer. However, because we do in __fget_files_rcu()
856 * that file being closed. in __fget_files_rcu()
860 * (a) the file ref already went down to zero, in __fget_files_rcu()
863 if (unlikely(!get_file_rcu(file))) in __fget_files_rcu()
867 * (b) the file table entry has changed under us. in __fget_files_rcu()
875 unlikely(rcu_dereference_raw(*fdentry) != file)) { in __fget_files_rcu()
876 fput(file); in __fget_files_rcu()
881 * Ok, we have a ref to the file, and checked that it in __fget_files_rcu()
884 return file; in __fget_files_rcu()
888 static struct file *__fget_files(struct files_struct *files, unsigned int fd, in __fget_files()
891 struct file *file; in __fget_files() local
894 file = __fget_files_rcu(files, fd, mask); in __fget_files()
897 return file; in __fget_files()
900 static inline struct file *__fget(unsigned int fd, fmode_t mask) in __fget()
905 struct file *fget(unsigned int fd) in fget()
911 struct file *fget_raw(unsigned int fd) in fget_raw()
917 struct file *fget_task(struct task_struct *task, unsigned int fd) in fget_task()
919 struct file *file = NULL; in fget_task() local
923 file = __fget_files(task->files, fd, 0); in fget_task()
926 return file; in fget_task()
929 struct file *task_lookup_fd_rcu(struct task_struct *task, unsigned int fd) in task_lookup_fd_rcu()
933 struct file *file = NULL; in task_lookup_fd_rcu() local
938 file = files_lookup_fd_rcu(files, fd); in task_lookup_fd_rcu()
941 return file; in task_lookup_fd_rcu()
944 struct file *task_lookup_next_fd_rcu(struct task_struct *task, unsigned int *ret_fd) in task_lookup_next_fd_rcu()
949 struct file *file = NULL; in task_lookup_next_fd_rcu() local
955 file = files_lookup_fd_rcu(files, fd); in task_lookup_next_fd_rcu()
956 if (file) in task_lookup_next_fd_rcu()
962 return file; in task_lookup_next_fd_rcu()
967 * Lightweight file lookup - no refcnt increment if fd table isn't shared.
972 * to userspace (i.e. you cannot remember the returned struct file * after
974 * 2) You must not call filp_close on the returned struct file * in between
985 struct file *file; in __fget_light() local
991 * return a file that is concurrently being freed. in __fget_light()
997 file = files_lookup_fd_raw(files, fd); in __fget_light()
998 if (!file || unlikely(file->f_mode & mask)) in __fget_light()
1000 return (unsigned long)file; in __fget_light()
1002 file = __fget(fd, mask); in __fget_light()
1003 if (!file) in __fget_light()
1005 return FDPUT_FPUT | (unsigned long)file; in __fget_light()
1021 * file is marked for FMODE_ATOMIC_POS, and it can be
1025 * can make a file accessible even if it otherwise would
1029 static inline bool file_needs_f_pos_lock(struct file *file) in file_needs_f_pos_lock() argument
1031 return (file->f_mode & FMODE_ATOMIC_POS) && in file_needs_f_pos_lock()
1032 (file_count(file) > 1 || file->f_op->iterate_shared); in file_needs_f_pos_lock()
1038 struct file *file = (struct file *)(v & ~3); in __fdget_pos() local
1040 if (file && file_needs_f_pos_lock(file)) { in __fdget_pos()
1042 mutex_lock(&file->f_pos_lock); in __fdget_pos()
1047 void __f_unlock_pos(struct file *f) in __f_unlock_pos()
1053 * We only lock f_pos if we have threads or if the file might be
1055 * file count (done either by fdget() or by fork()).
1084 struct file *file, unsigned fd, unsigned flags) in do_dup2() argument
1087 struct file *tofree; in do_dup2()
1094 * file immediately after grabbing descriptor, mark it larval if in do_dup2()
1109 get_file(file); in do_dup2()
1110 rcu_assign_pointer(fdt->fd[fd], file); in do_dup2()
1128 int replace_fd(unsigned fd, struct file *file, unsigned flags) in replace_fd() argument
1133 if (!file) in replace_fd()
1143 return do_dup2(files, file, fd, flags); in replace_fd()
1151 * __receive_fd() - Install received file into file descriptor table
1152 * @file: struct file that was received from another process
1156 * Installs a received file into the file descriptor table, with appropriate
1161 * struct file.
1165 int __receive_fd(struct file *file, int __user *ufd, unsigned int o_flags) in __receive_fd() argument
1170 error = security_file_receive(file); in __receive_fd()
1186 fd_install(new_fd, get_file(file)); in __receive_fd()
1187 __receive_sock(file); in __receive_fd()
1191 int receive_fd_replace(int new_fd, struct file *file, unsigned int o_flags) in receive_fd_replace() argument
1195 error = security_file_receive(file); in receive_fd_replace()
1198 error = replace_fd(new_fd, file, o_flags); in receive_fd_replace()
1201 __receive_sock(file); in receive_fd_replace()
1205 int receive_fd(struct file *file, unsigned int o_flags) in receive_fd() argument
1207 return __receive_fd(file, NULL, o_flags); in receive_fd()
1214 struct file *file; in ksys_dup3() local
1228 file = files_lookup_fd_locked(files, oldfd); in ksys_dup3()
1229 if (unlikely(!file)) in ksys_dup3()
1236 return do_dup2(files, file, newfd, flags); in ksys_dup3()
1268 struct file *file = fget_raw(fildes); in SYSCALL_DEFINE1() local
1270 if (file) { in SYSCALL_DEFINE1()
1273 fd_install(ret, file); in SYSCALL_DEFINE1()
1275 fput(file); in SYSCALL_DEFINE1()
1280 int f_dupfd(unsigned int from, struct file *file, unsigned flags) in f_dupfd() argument
1288 get_file(file); in f_dupfd()
1289 fd_install(err, file); in f_dupfd()
1295 int (*f)(const void *, struct file *, unsigned), in iterate_fd() argument
1304 struct file *file; in iterate_fd() local
1305 file = rcu_dereference_check_fdtable(files, fdt->fd[n]); in iterate_fd()
1306 if (!file) in iterate_fd()
1308 res = f(p, file, n); in iterate_fd()