• Home
  • Raw
  • Download

Lines Matching full:file

3  *  linux/fs/file.c
17 #include <linux/file.h>
49 * space if any. This does not copy the file pointers. Called with the files
71 * Copy all file descriptors from the old table to the new, expanded table and
80 cpy = ofdt->max_fds * sizeof(struct file *); in copy_fdtable()
81 set = (nfdt->max_fds - ofdt->max_fds) * sizeof(struct file *); in copy_fdtable()
100 nr /= (1024 / sizeof(struct file *)); in alloc_fdtable()
102 nr *= (1024 / sizeof(struct file *)); in alloc_fdtable()
118 data = kvmalloc_array(nr, sizeof(struct file *), GFP_KERNEL_ACCOUNT); in alloc_fdtable()
145 * Expand the file descriptor table.
190 * This function will expand the file structures, if the requested size exceeds
288 struct file **old_fds, **new_fds; in dup_fd()
352 struct file *f = *old_fds++; in dup_fd()
369 memset(new_fds, 0, (new_fdt->max_fds - open_files) * sizeof(struct file *)); in dup_fd()
399 struct file * file = xchg(&fdt->fd[i], NULL); in close_files() local
400 if (file) { in close_files()
401 filp_close(file, files); in close_files()
491 * allocate a file descriptor, mark it busy.
586 * Install a file pointer in the fd array.
589 * setting the open_fds bitmap and installing the file in the file
591 * installing a file in the array before us. We need to detect this and
592 * fput() the struct file we are about to overwrite in this case.
606 struct file *file) in __fd_install() argument
617 rcu_assign_pointer(fdt->fd[fd], file); in __fd_install()
625 rcu_assign_pointer(fdt->fd[fd], file); in __fd_install()
630 * This consumes the "file" refcount, so callers should treat it
631 * as if they had called fput(file).
633 void fd_install(unsigned int fd, struct file *file) in fd_install() argument
635 __fd_install(current->files, fd, file); in fd_install()
640 static struct file *pick_file(struct files_struct *files, unsigned fd) in pick_file()
642 struct file *file = NULL; in pick_file() local
649 file = fdt->fd[fd]; in pick_file()
650 if (!file) in pick_file()
657 return file; in pick_file()
665 struct file *file; in __close_fd() local
667 file = pick_file(files, fd); in __close_fd()
668 if (!file) in __close_fd()
671 return filp_close(file, files); in __close_fd()
676 * __close_range() - Close all file descriptors in a given range.
678 * @fd: starting file descriptor to close
679 * @max_fd: last file descriptor to close
681 * This closes a range of file descriptors. All file descriptors
709 * we're closing everything so only copy all file descriptors in __close_range()
710 * beneath the lowest file descriptor. in __close_range()
720 * We used to share our file descriptor table, and have now in __close_range()
729 struct file *file; in __close_range() local
731 file = pick_file(cur_fds, fd++); in __close_range()
732 if (!file) in __close_range()
735 filp_close(file, cur_fds); in __close_range()
742 * the new file descriptor table and drop the old one. in __close_range()
754 * variant of __close_fd that gets a ref on the file for later fput.
755 * The caller must ensure that filp_close() called on the file, and then
758 int __close_fd_get_file(unsigned int fd, struct file **res) in __close_fd_get_file()
761 struct file *file; in __close_fd_get_file() local
768 file = fdt->fd[fd]; in __close_fd_get_file()
769 if (!file) in __close_fd_get_file()
774 get_file(file); in __close_fd_get_file()
775 *res = file; in __close_fd_get_file()
802 struct file *file; in do_close_on_exec() local
805 file = fdt->fd[fd]; in do_close_on_exec()
806 if (!file) in do_close_on_exec()
811 filp_close(file, files); in do_close_on_exec()
820 static struct file *__fget_files(struct files_struct *files, unsigned int fd, in __fget_files()
823 struct file *file; in __fget_files() local
827 file = fcheck_files(files, fd); in __fget_files()
828 if (file) { in __fget_files()
829 /* File object ref couldn't be taken. in __fget_files()
831 * we loop to catch the new file (or NULL pointer) in __fget_files()
833 if (file->f_mode & mask) in __fget_files()
834 file = NULL; in __fget_files()
835 else if (!get_file_rcu_many(file, refs)) in __fget_files()
837 else if (__fcheck_files(files, fd) != file) { in __fget_files()
838 fput_many(file, refs); in __fget_files()
844 return file; in __fget_files()
847 static inline struct file *__fget(unsigned int fd, fmode_t mask, in __fget()
853 struct file *fget_many(unsigned int fd, unsigned int refs) in fget_many()
858 struct file *fget(unsigned int fd) in fget()
864 struct file *fget_raw(unsigned int fd) in fget_raw()
870 struct file *fget_task(struct task_struct *task, unsigned int fd) in fget_task()
872 struct file *file = NULL; in fget_task() local
876 file = __fget_files(task->files, fd, 0, 1); in fget_task()
879 return file; in fget_task()
883 * Lightweight file lookup - no refcnt increment if fd table isn't shared.
888 * to userspace (i.e. you cannot remember the returned struct file * after
890 * 2) You must not call filp_close on the returned struct file * in between
901 struct file *file; in __fget_light() local
904 file = __fcheck_files(files, fd); in __fget_light()
905 if (!file || unlikely(file->f_mode & mask)) in __fget_light()
907 return (unsigned long)file; in __fget_light()
909 file = __fget(fd, mask, 1); in __fget_light()
910 if (!file) in __fget_light()
912 return FDPUT_FPUT | (unsigned long)file; in __fget_light()
929 struct file *file = (struct file *)(v & ~3); in __fdget_pos() local
931 if (file && (file->f_mode & FMODE_ATOMIC_POS)) { in __fdget_pos()
932 if (file_count(file) > 1) { in __fdget_pos()
934 mutex_lock(&file->f_pos_lock); in __fdget_pos()
940 void __f_unlock_pos(struct file *f) in __f_unlock_pos()
946 * We only lock f_pos if we have threads or if the file might be
948 * file count (done either by fdget() or by fork()).
977 struct file *file, unsigned fd, unsigned flags) in do_dup2() argument
980 struct file *tofree; in do_dup2()
987 * file immediately after grabbing descriptor, mark it larval if in do_dup2()
1001 get_file(file); in do_dup2()
1002 rcu_assign_pointer(fdt->fd[fd], file); in do_dup2()
1020 int replace_fd(unsigned fd, struct file *file, unsigned flags) in replace_fd() argument
1025 if (!file) in replace_fd()
1035 return do_dup2(files, file, fd, flags); in replace_fd()
1043 * __receive_fd() - Install received file into file descriptor table
1046 * @file: struct file that was received from another process
1050 * Installs a received file into the file descriptor table, with appropriate
1055 * struct file.
1059 int __receive_fd(int fd, struct file *file, int __user *ufd, unsigned int o_flags) in __receive_fd() argument
1064 error = security_file_receive(file); in __receive_fd()
1086 fd_install(new_fd, get_file(file)); in __receive_fd()
1088 error = replace_fd(new_fd, file, o_flags); in __receive_fd()
1094 __receive_sock(file); in __receive_fd()
1101 struct file *file; in ksys_dup3() local
1115 file = fcheck(oldfd); in ksys_dup3()
1116 if (unlikely(!file)) in ksys_dup3()
1123 return do_dup2(files, file, newfd, flags); in ksys_dup3()
1155 struct file *file = fget_raw(fildes); in SYSCALL_DEFINE1() local
1157 if (file) { in SYSCALL_DEFINE1()
1160 fd_install(ret, file); in SYSCALL_DEFINE1()
1162 fput(file); in SYSCALL_DEFINE1()
1167 int f_dupfd(unsigned int from, struct file *file, unsigned flags) in f_dupfd() argument
1174 get_file(file); in f_dupfd()
1175 fd_install(err, file); in f_dupfd()
1181 int (*f)(const void *, struct file *, unsigned), in iterate_fd() argument
1190 struct file *file; in iterate_fd() local
1191 file = rcu_dereference_check_fdtable(files, fdt->fd[n]); in iterate_fd()
1192 if (!file) in iterate_fd()
1194 res = f(p, file, n); in iterate_fd()