Lines Matching full:file

3  *  linux/fs/file.c
17 #include <linux/file.h>
51 * space if any. This does not copy the file pointers. Called with the files
73 * Copy all file descriptors from the old table to the new, expanded table and
82 cpy = ofdt->max_fds * sizeof(struct file *); in copy_fdtable()
83 set = (nfdt->max_fds - ofdt->max_fds) * sizeof(struct file *); in copy_fdtable()
102 nr /= (1024 / sizeof(struct file *)); in alloc_fdtable()
104 nr *= (1024 / sizeof(struct file *)); in alloc_fdtable()
120 data = kvmalloc_array(nr, sizeof(struct file *), GFP_KERNEL_ACCOUNT); in alloc_fdtable()
147 * Expand the file descriptor table.
192 * This function will expand the file structures, if the requested size exceeds
290 struct file **old_fds, **new_fds; in dup_fd()
354 struct file *f = *old_fds++; in dup_fd()
371 memset(new_fds, 0, (new_fdt->max_fds - open_files) * sizeof(struct file *)); in dup_fd()
401 struct file * file = xchg(&fdt->fd[i], NULL); in close_files() local
402 if (file) { in close_files()
403 filp_close(file, files); in close_files()
468 * allocate a file descriptor, mark it busy.
558 * Install a file pointer in the fd array.
561 * setting the open_fds bitmap and installing the file in the file
563 * installing a file in the array before us. We need to detect this and
564 * fput() the struct file we are about to overwrite in this case.
569 * This consumes the "file" refcount, so callers should treat it
570 * as if they had called fput(file).
573 void fd_install(unsigned int fd, struct file *file) in fd_install() argument
585 rcu_assign_pointer(fdt->fd[fd], file); in fd_install()
593 rcu_assign_pointer(fdt->fd[fd], file); in fd_install()
600 * pick_file - return file associatd with fd
601 * @files: file struct to retrieve file from
602 * @fd: file descriptor to retrieve file for
605 * current maximum number of file descriptors for that fdtable.
607 * Returns: The file associated with @fd, on error returns an error pointer.
609 static struct file *pick_file(struct files_struct *files, unsigned fd) in pick_file()
611 struct file *file; in pick_file() local
617 file = ERR_PTR(-EINVAL); in pick_file()
620 file = fdt->fd[fd]; in pick_file()
621 if (!file) { in pick_file()
622 file = ERR_PTR(-EBADF); in pick_file()
630 return file; in pick_file()
636 struct file *file; in close_fd() local
638 file = pick_file(files, fd); in close_fd()
639 if (IS_ERR(file)) in close_fd()
642 return filp_close(file, files); in close_fd()
677 struct file *file; in __range_close() local
679 file = pick_file(cur_fds, fd++); in __range_close()
680 if (!IS_ERR(file)) { in __range_close()
681 /* found a valid file to close */ in __range_close()
682 filp_close(file, cur_fds); in __range_close()
688 if (PTR_ERR(file) == -EINVAL) in __range_close()
694 * __close_range() - Close all file descriptors in a given range.
696 * @fd: starting file descriptor to close
697 * @max_fd: last file descriptor to close
699 * This closes a range of file descriptors. All file descriptors
719 * copy all of the file descriptors since they still want to in __close_range()
726 * file descriptors beneath the lowest file descriptor. in __close_range()
739 * We used to share our file descriptor table, and have now in __close_range()
754 * the new file descriptor table and drop the old one. in __close_range()
769 int __close_fd_get_file(unsigned int fd, struct file **res) in __close_fd_get_file()
772 struct file *file; in __close_fd_get_file() local
778 file = fdt->fd[fd]; in __close_fd_get_file()
779 if (!file) in __close_fd_get_file()
783 get_file(file); in __close_fd_get_file()
784 *res = file; in __close_fd_get_file()
792 * variant of close_fd that gets a ref on the file for later fput.
793 * The caller must ensure that filp_close() called on the file, and then
796 int close_fd_get_file(unsigned int fd, struct file **res) in close_fd_get_file()
826 struct file *file; in do_close_on_exec() local
829 file = fdt->fd[fd]; in do_close_on_exec()
830 if (!file) in do_close_on_exec()
835 filp_close(file, files); in do_close_on_exec()
844 static struct file *__fget_files(struct files_struct *files, unsigned int fd, in __fget_files()
847 struct file *file; in __fget_files() local
851 file = files_lookup_fd_rcu(files, fd); in __fget_files()
852 if (file) { in __fget_files()
853 /* File object ref couldn't be taken. in __fget_files()
855 * we loop to catch the new file (or NULL pointer) in __fget_files()
857 if (file->f_mode & mask) in __fget_files()
858 file = NULL; in __fget_files()
859 else if (!get_file_rcu_many(file, refs)) in __fget_files()
864 return file; in __fget_files()
867 static inline struct file *__fget(unsigned int fd, fmode_t mask, in __fget()
873 struct file *fget_many(unsigned int fd, unsigned int refs) in fget_many()
878 struct file *fget(unsigned int fd) in fget()
884 struct file *fget_raw(unsigned int fd) in fget_raw()
890 struct file *fget_task(struct task_struct *task, unsigned int fd) in fget_task()
892 struct file *file = NULL; in fget_task() local
896 file = __fget_files(task->files, fd, 0, 1); in fget_task()
899 return file; in fget_task()
902 struct file *task_lookup_fd_rcu(struct task_struct *task, unsigned int fd) in task_lookup_fd_rcu()
906 struct file *file = NULL; in task_lookup_fd_rcu() local
911 file = files_lookup_fd_rcu(files, fd); in task_lookup_fd_rcu()
914 return file; in task_lookup_fd_rcu()
917 struct file *task_lookup_next_fd_rcu(struct task_struct *task, unsigned int *ret_fd) in task_lookup_next_fd_rcu()
922 struct file *file = NULL; in task_lookup_next_fd_rcu() local
928 file = files_lookup_fd_rcu(files, fd); in task_lookup_next_fd_rcu()
929 if (file) in task_lookup_next_fd_rcu()
935 return file; in task_lookup_next_fd_rcu()
939 * Lightweight file lookup - no refcnt increment if fd table isn't shared.
944 * to userspace (i.e. you cannot remember the returned struct file * after
946 * 2) You must not call filp_close on the returned struct file * in between
957 struct file *file; in __fget_light() local
960 file = files_lookup_fd_raw(files, fd); in __fget_light()
961 if (!file || unlikely(file->f_mode & mask)) in __fget_light()
963 return (unsigned long)file; in __fget_light()
965 file = __fget(fd, mask, 1); in __fget_light()
966 if (!file) in __fget_light()
968 return FDPUT_FPUT | (unsigned long)file; in __fget_light()
985 struct file *file = (struct file *)(v & ~3); in __fdget_pos() local
987 if (file && (file->f_mode & FMODE_ATOMIC_POS)) { in __fdget_pos()
988 if (file_count(file) > 1) { in __fdget_pos()
990 mutex_lock(&file->f_pos_lock); in __fdget_pos()
996 void __f_unlock_pos(struct file *f) in __f_unlock_pos()
1002 * We only lock f_pos if we have threads or if the file might be
1004 * file count (done either by fdget() or by fork()).
1033 struct file *file, unsigned fd, unsigned flags) in do_dup2() argument
1036 struct file *tofree; in do_dup2()
1043 * file immediately after grabbing descriptor, mark it larval if in do_dup2()
1057 get_file(file); in do_dup2()
1058 rcu_assign_pointer(fdt->fd[fd], file); in do_dup2()
1076 int replace_fd(unsigned fd, struct file *file, unsigned flags) in replace_fd() argument
1081 if (!file) in replace_fd()
1091 return do_dup2(files, file, fd, flags); in replace_fd()
1099 * __receive_fd() - Install received file into file descriptor table
1100 * @file: struct file that was received from another process
1104 * Installs a received file into the file descriptor table, with appropriate
1109 * struct file.
1113 int __receive_fd(struct file *file, int __user *ufd, unsigned int o_flags) in __receive_fd() argument
1118 error = security_file_receive(file); in __receive_fd()
1134 fd_install(new_fd, get_file(file)); in __receive_fd()
1135 __receive_sock(file); in __receive_fd()
1139 int receive_fd_replace(int new_fd, struct file *file, unsigned int o_flags) in receive_fd_replace() argument
1143 error = security_file_receive(file); in receive_fd_replace()
1146 error = replace_fd(new_fd, file, o_flags); in receive_fd_replace()
1149 __receive_sock(file); in receive_fd_replace()
1153 int receive_fd(struct file *file, unsigned int o_flags) in receive_fd() argument
1155 return __receive_fd(file, NULL, o_flags); in receive_fd()
1162 struct file *file; in ksys_dup3() local
1176 file = files_lookup_fd_locked(files, oldfd); in ksys_dup3()
1177 if (unlikely(!file)) in ksys_dup3()
1184 return do_dup2(files, file, newfd, flags); in ksys_dup3()
1216 struct file *file = fget_raw(fildes); in SYSCALL_DEFINE1() local
1218 if (file) { in SYSCALL_DEFINE1()
1221 fd_install(ret, file); in SYSCALL_DEFINE1()
1223 fput(file); in SYSCALL_DEFINE1()
1228 int f_dupfd(unsigned int from, struct file *file, unsigned flags) in f_dupfd() argument
1236 get_file(file); in f_dupfd()
1237 fd_install(err, file); in f_dupfd()
1243 int (*f)(const void *, struct file *, unsigned), in iterate_fd() argument
1252 struct file *file; in iterate_fd() local
1253 file = rcu_dereference_check_fdtable(files, fdt->fd[n]); in iterate_fd()
1254 if (!file) in iterate_fd()
1256 res = f(p, file, n); in iterate_fd()