Lines Matching full:file
3 * linux/fs/file.c
17 #include <linux/file.h>
50 * space if any. This does not copy the file pointers. Called with the files
72 * Copy all file descriptors from the old table to the new, expanded table and
81 cpy = ofdt->max_fds * sizeof(struct file *); in copy_fdtable()
82 set = (nfdt->max_fds - ofdt->max_fds) * sizeof(struct file *); in copy_fdtable()
101 nr /= (1024 / sizeof(struct file *)); in alloc_fdtable()
103 nr *= (1024 / sizeof(struct file *)); in alloc_fdtable()
119 data = kvmalloc_array(nr, sizeof(struct file *), GFP_KERNEL_ACCOUNT); in alloc_fdtable()
146 * Expand the file descriptor table.
191 * This function will expand the file structures, if the requested size exceeds
289 struct file **old_fds, **new_fds; in dup_fd()
353 struct file *f = *old_fds++; in dup_fd()
370 memset(new_fds, 0, (new_fdt->max_fds - open_files) * sizeof(struct file *)); in dup_fd()
400 struct file * file = xchg(&fdt->fd[i], NULL); in close_files() local
401 if (file) { in close_files()
402 filp_close(file, files); in close_files()
493 * allocate a file descriptor, mark it busy.
588 * Install a file pointer in the fd array.
591 * setting the open_fds bitmap and installing the file in the file
593 * installing a file in the array before us. We need to detect this and
594 * fput() the struct file we are about to overwrite in this case.
608 struct file *file) in __fd_install() argument
619 rcu_assign_pointer(fdt->fd[fd], file); in __fd_install()
627 rcu_assign_pointer(fdt->fd[fd], file); in __fd_install()
632 * This consumes the "file" refcount, so callers should treat it
633 * as if they had called fput(file).
635 void fd_install(unsigned int fd, struct file *file) in fd_install() argument
637 __fd_install(current->files, fd, file); in fd_install()
642 static struct file *pick_file(struct files_struct *files, unsigned fd) in pick_file()
644 struct file *file = NULL; in pick_file() local
651 file = fdt->fd[fd]; in pick_file()
652 if (!file) in pick_file()
659 return file; in pick_file()
667 struct file *file; in __close_fd() local
669 file = pick_file(files, fd); in __close_fd()
670 if (!file) in __close_fd()
673 return filp_close(file, files); in __close_fd()
678 * __close_range() - Close all file descriptors in a given range.
680 * @fd: starting file descriptor to close
681 * @max_fd: last file descriptor to close
683 * This closes a range of file descriptors. All file descriptors
711 * we're closing everything so only copy all file descriptors in __close_range()
712 * beneath the lowest file descriptor. in __close_range()
722 * We used to share our file descriptor table, and have now in __close_range()
731 struct file *file; in __close_range() local
733 file = pick_file(cur_fds, fd++); in __close_range()
734 if (!file) in __close_range()
737 filp_close(file, cur_fds); in __close_range()
744 * the new file descriptor table and drop the old one. in __close_range()
756 * variant of __close_fd that gets a ref on the file for later fput.
757 * The caller must ensure that filp_close() called on the file, and then
760 int __close_fd_get_file(unsigned int fd, struct file **res) in __close_fd_get_file()
763 struct file *file; in __close_fd_get_file() local
770 file = fdt->fd[fd]; in __close_fd_get_file()
771 if (!file) in __close_fd_get_file()
776 get_file(file); in __close_fd_get_file()
777 *res = file; in __close_fd_get_file()
804 struct file *file; in do_close_on_exec() local
807 file = fdt->fd[fd]; in do_close_on_exec()
808 if (!file) in do_close_on_exec()
813 filp_close(file, files); in do_close_on_exec()
822 static struct file *__fget_files(struct files_struct *files, unsigned int fd, in __fget_files()
825 struct file *file; in __fget_files() local
829 file = fcheck_files(files, fd); in __fget_files()
830 if (file) { in __fget_files()
831 /* File object ref couldn't be taken. in __fget_files()
833 * we loop to catch the new file (or NULL pointer) in __fget_files()
835 if (file->f_mode & mask) in __fget_files()
836 file = NULL; in __fget_files()
837 else if (!get_file_rcu_many(file, refs)) in __fget_files()
842 return file; in __fget_files()
845 static inline struct file *__fget(unsigned int fd, fmode_t mask, in __fget()
851 struct file *fget_many(unsigned int fd, unsigned int refs) in fget_many()
856 struct file *fget(unsigned int fd) in fget()
862 struct file *fget_raw(unsigned int fd) in fget_raw()
868 struct file *fget_task(struct task_struct *task, unsigned int fd) in fget_task()
870 struct file *file = NULL; in fget_task() local
874 file = __fget_files(task->files, fd, 0, 1); in fget_task()
877 return file; in fget_task()
881 * Lightweight file lookup - no refcnt increment if fd table isn't shared.
886 * to userspace (i.e. you cannot remember the returned struct file * after
888 * 2) You must not call filp_close on the returned struct file * in between
899 struct file *file; in __fget_light() local
902 file = __fcheck_files(files, fd); in __fget_light()
903 if (!file || unlikely(file->f_mode & mask)) in __fget_light()
905 return (unsigned long)file; in __fget_light()
907 file = __fget(fd, mask, 1); in __fget_light()
908 if (!file) in __fget_light()
910 return FDPUT_FPUT | (unsigned long)file; in __fget_light()
927 struct file *file = (struct file *)(v & ~3); in __fdget_pos() local
929 if (file && (file->f_mode & FMODE_ATOMIC_POS)) { in __fdget_pos()
930 if (file_count(file) > 1) { in __fdget_pos()
932 mutex_lock(&file->f_pos_lock); in __fdget_pos()
938 void __f_unlock_pos(struct file *f) in __f_unlock_pos()
944 * We only lock f_pos if we have threads or if the file might be
946 * file count (done either by fdget() or by fork()).
975 struct file *file, unsigned fd, unsigned flags) in do_dup2() argument
978 struct file *tofree; in do_dup2()
985 * file immediately after grabbing descriptor, mark it larval if in do_dup2()
999 get_file(file); in do_dup2()
1000 rcu_assign_pointer(fdt->fd[fd], file); in do_dup2()
1018 int replace_fd(unsigned fd, struct file *file, unsigned flags) in replace_fd() argument
1023 if (!file) in replace_fd()
1033 return do_dup2(files, file, fd, flags); in replace_fd()
1041 * __receive_fd() - Install received file into file descriptor table
1044 * @file: struct file that was received from another process
1048 * Installs a received file into the file descriptor table, with appropriate
1053 * struct file.
1057 int __receive_fd(int fd, struct file *file, int __user *ufd, unsigned int o_flags) in __receive_fd() argument
1062 error = security_file_receive(file); in __receive_fd()
1084 fd_install(new_fd, get_file(file)); in __receive_fd()
1086 error = replace_fd(new_fd, file, o_flags); in __receive_fd()
1092 __receive_sock(file); in __receive_fd()
1099 struct file *file; in ksys_dup3() local
1113 file = fcheck(oldfd); in ksys_dup3()
1114 if (unlikely(!file)) in ksys_dup3()
1121 return do_dup2(files, file, newfd, flags); in ksys_dup3()
1153 struct file *file = fget_raw(fildes); in SYSCALL_DEFINE1() local
1155 if (file) { in SYSCALL_DEFINE1()
1158 fd_install(ret, file); in SYSCALL_DEFINE1()
1160 fput(file); in SYSCALL_DEFINE1()
1165 int f_dupfd(unsigned int from, struct file *file, unsigned flags) in f_dupfd() argument
1172 get_file(file); in f_dupfd()
1173 fd_install(err, file); in f_dupfd()
1179 int (*f)(const void *, struct file *, unsigned), in iterate_fd() argument
1188 struct file *file; in iterate_fd() local
1189 file = rcu_dereference_check_fdtable(files, fdt->fd[n]); in iterate_fd()
1190 if (!file) in iterate_fd()
1192 res = f(p, file, n); in iterate_fd()