Lines Matching full:file
12 #include <linux/file.h>
37 static inline bool unsigned_offsets(struct file *file) in unsigned_offsets() argument
39 return file->f_op->fop_flags & FOP_UNSIGNED_OFFSET; in unsigned_offsets()
43 * vfs_setpos_cookie - update the file offset for lseek and reset cookie
44 * @file: file structure in question
45 * @offset: file offset to seek to
46 * @maxsize: maximum file size
49 * Update the file offset to the value specified by @offset if the given
50 * offset is valid and it is not equal to the current file offset and
55 static loff_t vfs_setpos_cookie(struct file *file, loff_t offset, in vfs_setpos_cookie() argument
58 if (offset < 0 && !unsigned_offsets(file)) in vfs_setpos_cookie()
63 if (offset != file->f_pos) { in vfs_setpos_cookie()
64 file->f_pos = offset; in vfs_setpos_cookie()
72 * vfs_setpos - update the file offset for lseek
73 * @file: file structure in question
74 * @offset: file offset to seek to
75 * @maxsize: maximum file size
77 * This is a low-level filesystem helper for updating the file offset to
79 * not equal to the current file offset.
83 loff_t vfs_setpos(struct file *file, loff_t offset, loff_t maxsize) in vfs_setpos() argument
85 return vfs_setpos_cookie(file, offset, maxsize, NULL); in vfs_setpos()
91 * @file: file to seek on
94 * @eof: end of file
102 static int must_set_pos(struct file *file, loff_t *offset, int whence, loff_t eof) in must_set_pos() argument
112 * f_pos value back to the file because a concurrent read(), in must_set_pos()
116 *offset = file->f_pos; in must_set_pos()
122 * In the generic case the entire file is data, so as long as in must_set_pos()
123 * offset isn't at the end of the file then the offset is data. in must_set_pos()
130 * There is a virtual hole at the end of the file, so as long as in must_set_pos()
144 * @file: file structure to seek on
145 * @offset: file offset to seek to
147 * @maxsize: max size of this file in file system
151 * maximum file size and a custom EOF position, for e.g. hashed directories
159 generic_file_llseek_size(struct file *file, loff_t offset, int whence, in generic_file_llseek_size() argument
164 ret = must_set_pos(file, &offset, whence, eof); in generic_file_llseek_size()
176 guard(spinlock)(&file->f_lock); in generic_file_llseek_size()
177 return vfs_setpos(file, file->f_pos + offset, maxsize); in generic_file_llseek_size()
180 return vfs_setpos(file, offset, maxsize); in generic_file_llseek_size()
186 * @file: file structure to seek on
187 * @offset: file offset to seek to
196 loff_t generic_llseek_cookie(struct file *file, loff_t offset, int whence, in generic_llseek_cookie() argument
199 struct inode *inode = file->f_mapping->host; in generic_llseek_cookie()
212 if (WARN_ON_ONCE(!(file->f_mode & FMODE_ATOMIC_POS))) in generic_llseek_cookie()
215 ret = must_set_pos(file, &offset, whence, eof); in generic_llseek_cookie()
223 return vfs_setpos_cookie(file, file->f_pos + offset, maxsize, cookie); in generic_llseek_cookie()
225 return vfs_setpos_cookie(file, offset, maxsize, cookie); in generic_llseek_cookie()
231 * @file: file structure to seek on
232 * @offset: file offset to seek to
236 * filesystems. It just updates the file offset to the value specified by
239 loff_t generic_file_llseek(struct file *file, loff_t offset, int whence) in generic_file_llseek() argument
241 struct inode *inode = file->f_mapping->host; in generic_file_llseek()
243 return generic_file_llseek_size(file, offset, whence, in generic_file_llseek()
251 * @file: file structure to seek on
252 * @offset: file offset to seek to
254 * @size: size of the file
257 loff_t fixed_size_llseek(struct file *file, loff_t offset, int whence, loff_t size) in fixed_size_llseek() argument
261 return generic_file_llseek_size(file, offset, whence, in fixed_size_llseek()
271 * @file: file structure to seek on
272 * @offset: file offset to seek to
276 loff_t no_seek_end_llseek(struct file *file, loff_t offset, int whence) in no_seek_end_llseek() argument
280 return generic_file_llseek_size(file, offset, whence, in no_seek_end_llseek()
290 * @file: file structure to seek on
291 * @offset: file offset to seek to
296 loff_t no_seek_end_llseek_size(struct file *file, loff_t offset, int whence, loff_t size) in no_seek_end_llseek_size() argument
300 return generic_file_llseek_size(file, offset, whence, in no_seek_end_llseek_size()
310 * @file: file structure to seek on
311 * @offset: file offset to seek to
315 * userspace expects the seek to succeed but the (device) file is actually not
319 loff_t noop_llseek(struct file *file, loff_t offset, int whence) in noop_llseek() argument
321 return file->f_pos; in noop_llseek()
325 loff_t default_llseek(struct file *file, loff_t offset, int whence) in default_llseek() argument
327 struct inode *inode = file_inode(file); in default_llseek()
337 retval = file->f_pos; in default_llseek()
340 offset += file->f_pos; in default_llseek()
344 * In the generic case the entire file is data, so as in default_llseek()
345 * long as offset isn't at the end of the file then the in default_llseek()
355 * There is a virtual hole at the end of the file, so in default_llseek()
367 if (offset >= 0 || unsigned_offsets(file)) { in default_llseek()
368 if (offset != file->f_pos) in default_llseek()
369 file->f_pos = offset; in default_llseek()
378 loff_t vfs_llseek(struct file *file, loff_t offset, int whence) in vfs_llseek() argument
380 if (!(file->f_mode & FMODE_LSEEK)) in vfs_llseek()
382 return file->f_op->llseek(file, offset, whence); in vfs_llseek()
448 int rw_verify_area(int read_write, struct file *file, const loff_t *ppos, size_t count) in rw_verify_area() argument
460 if (!unsigned_offsets(file)) in rw_verify_area()
465 if (!unsigned_offsets(file)) in rw_verify_area()
470 ret = security_file_permission(file, mask); in rw_verify_area()
474 return fsnotify_file_area_perm(file, mask, ppos, count); in rw_verify_area()
478 static ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos) in new_sync_read()
495 static int warn_unsupported(struct file *file, const char *op) in warn_unsupported() argument
498 "kernel %s not supported for file %pD4 (pid: %d comm: %.20s)\n", in warn_unsupported()
499 op, file, current->pid, current->comm); in warn_unsupported()
503 ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) in __kernel_read() argument
513 if (WARN_ON_ONCE(!(file->f_mode & FMODE_READ))) in __kernel_read()
515 if (!(file->f_mode & FMODE_CAN_READ)) in __kernel_read()
521 if (unlikely(!file->f_op->read_iter || file->f_op->read)) in __kernel_read()
522 return warn_unsupported(file, "read"); in __kernel_read()
524 init_sync_kiocb(&kiocb, file); in __kernel_read()
527 ret = file->f_op->read_iter(&kiocb, &iter); in __kernel_read()
531 fsnotify_access(file); in __kernel_read()
538 ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) in kernel_read() argument
542 ret = rw_verify_area(READ, file, pos, count); in kernel_read()
545 return __kernel_read(file, buf, count, pos); in kernel_read()
549 ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) in vfs_read() argument
553 if (!(file->f_mode & FMODE_READ)) in vfs_read()
555 if (!(file->f_mode & FMODE_CAN_READ)) in vfs_read()
560 ret = rw_verify_area(READ, file, pos, count); in vfs_read()
566 if (file->f_op->read) in vfs_read()
567 ret = file->f_op->read(file, buf, count, pos); in vfs_read()
568 else if (file->f_op->read_iter) in vfs_read()
569 ret = new_sync_read(file, buf, count, pos); in vfs_read()
573 fsnotify_access(file); in vfs_read()
580 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos) in new_sync_write()
598 ssize_t __kernel_write_iter(struct file *file, struct iov_iter *from, loff_t *pos) in __kernel_write_iter() argument
603 if (WARN_ON_ONCE(!(file->f_mode & FMODE_WRITE))) in __kernel_write_iter()
605 if (!(file->f_mode & FMODE_CAN_WRITE)) in __kernel_write_iter()
611 if (unlikely(!file->f_op->write_iter || file->f_op->write)) in __kernel_write_iter()
612 return warn_unsupported(file, "write"); in __kernel_write_iter()
614 init_sync_kiocb(&kiocb, file); in __kernel_write_iter()
616 ret = file->f_op->write_iter(&kiocb, from); in __kernel_write_iter()
620 fsnotify_modify(file); in __kernel_write_iter()
628 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos) in __kernel_write() argument
636 return __kernel_write_iter(file, &iter, pos); in __kernel_write()
647 ssize_t kernel_write(struct file *file, const void *buf, size_t count, in kernel_write() argument
652 ret = rw_verify_area(WRITE, file, pos, count); in kernel_write()
656 file_start_write(file); in kernel_write()
657 ret = __kernel_write(file, buf, count, pos); in kernel_write()
658 file_end_write(file); in kernel_write()
663 ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_t *pos) in vfs_write() argument
667 if (!(file->f_mode & FMODE_WRITE)) in vfs_write()
669 if (!(file->f_mode & FMODE_CAN_WRITE)) in vfs_write()
674 ret = rw_verify_area(WRITE, file, pos, count); in vfs_write()
679 file_start_write(file); in vfs_write()
680 if (file->f_op->write) in vfs_write()
681 ret = file->f_op->write(file, buf, count, pos); in vfs_write()
682 else if (file->f_op->write_iter) in vfs_write()
683 ret = new_sync_write(file, buf, count, pos); in vfs_write()
687 fsnotify_modify(file); in vfs_write()
691 file_end_write(file); in vfs_write()
695 /* file_ppos returns &file->f_pos or NULL if file is stream */
696 static inline loff_t *file_ppos(struct file *file) in file_ppos() argument
698 return file->f_mode & FMODE_STREAM ? NULL : &file->f_pos; in file_ppos()
819 static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter, in do_iter_readv_writev()
841 /* Do it by hand, with file-ops */
842 static ssize_t do_loop_readv_writev(struct file *filp, struct iov_iter *iter, in do_loop_readv_writev()
875 ssize_t vfs_iocb_iter_read(struct file *file, struct kiocb *iocb, in vfs_iocb_iter_read() argument
881 if (!file->f_op->read_iter) in vfs_iocb_iter_read()
883 if (!(file->f_mode & FMODE_READ)) in vfs_iocb_iter_read()
885 if (!(file->f_mode & FMODE_CAN_READ)) in vfs_iocb_iter_read()
891 ret = rw_verify_area(READ, file, &iocb->ki_pos, tot_len); in vfs_iocb_iter_read()
895 ret = file->f_op->read_iter(iocb, iter); in vfs_iocb_iter_read()
898 fsnotify_access(file); in vfs_iocb_iter_read()
903 ssize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *ppos, in vfs_iter_read() argument
909 if (!file->f_op->read_iter) in vfs_iter_read()
911 if (!(file->f_mode & FMODE_READ)) in vfs_iter_read()
913 if (!(file->f_mode & FMODE_CAN_READ)) in vfs_iter_read()
919 ret = rw_verify_area(READ, file, ppos, tot_len); in vfs_iter_read()
923 ret = do_iter_readv_writev(file, iter, ppos, READ, flags); in vfs_iter_read()
926 fsnotify_access(file); in vfs_iter_read()
935 ssize_t vfs_iocb_iter_write(struct file *file, struct kiocb *iocb, in vfs_iocb_iter_write() argument
941 if (!file->f_op->write_iter) in vfs_iocb_iter_write()
943 if (!(file->f_mode & FMODE_WRITE)) in vfs_iocb_iter_write()
945 if (!(file->f_mode & FMODE_CAN_WRITE)) in vfs_iocb_iter_write()
951 ret = rw_verify_area(WRITE, file, &iocb->ki_pos, tot_len); in vfs_iocb_iter_write()
956 ret = file->f_op->write_iter(iocb, iter); in vfs_iocb_iter_write()
960 fsnotify_modify(file); in vfs_iocb_iter_write()
966 ssize_t vfs_iter_write(struct file *file, struct iov_iter *iter, loff_t *ppos, in vfs_iter_write() argument
972 if (!(file->f_mode & FMODE_WRITE)) in vfs_iter_write()
974 if (!(file->f_mode & FMODE_CAN_WRITE)) in vfs_iter_write()
976 if (!file->f_op->write_iter) in vfs_iter_write()
983 ret = rw_verify_area(WRITE, file, ppos, tot_len); in vfs_iter_write()
987 file_start_write(file); in vfs_iter_write()
988 ret = do_iter_readv_writev(file, iter, ppos, WRITE, flags); in vfs_iter_write()
990 fsnotify_modify(file); in vfs_iter_write()
991 file_end_write(file); in vfs_iter_write()
997 static ssize_t vfs_readv(struct file *file, const struct iovec __user *vec, in vfs_readv() argument
1006 if (!(file->f_mode & FMODE_READ)) in vfs_readv()
1008 if (!(file->f_mode & FMODE_CAN_READ)) in vfs_readv()
1020 ret = rw_verify_area(READ, file, pos, tot_len); in vfs_readv()
1024 if (file->f_op->read_iter) in vfs_readv()
1025 ret = do_iter_readv_writev(file, &iter, pos, READ, flags); in vfs_readv()
1027 ret = do_loop_readv_writev(file, &iter, pos, READ, flags); in vfs_readv()
1030 fsnotify_access(file); in vfs_readv()
1035 static ssize_t vfs_writev(struct file *file, const struct iovec __user *vec, in vfs_writev() argument
1044 if (!(file->f_mode & FMODE_WRITE)) in vfs_writev()
1046 if (!(file->f_mode & FMODE_CAN_WRITE)) in vfs_writev()
1058 ret = rw_verify_area(WRITE, file, pos, tot_len); in vfs_writev()
1062 file_start_write(file); in vfs_writev()
1063 if (file->f_op->write_iter) in vfs_writev()
1064 ret = do_iter_readv_writev(file, &iter, pos, WRITE, flags); in vfs_writev()
1066 ret = do_loop_readv_writev(file, &iter, pos, WRITE, flags); in vfs_writev()
1068 fsnotify_modify(file); in vfs_writev()
1069 file_end_write(file); in vfs_writev()
1327 * Get input file, and verify that it is ok.. in do_sendfile()
1350 * Get output file, and verify that it is ok.. in do_sendfile()
1378 * EAGAIN on a non-blocking file descriptor. in do_sendfile()
1499 * Performs necessary checks before doing a file copy
1505 static int generic_copy_file_checks(struct file *file_in, loff_t pos_in, in generic_copy_file_checks()
1506 struct file *file_out, loff_t pos_out, in generic_copy_file_checks()
1521 * a file of the wrong filesystem type to filesystem driver can result in generic_copy_file_checks()
1561 /* Don't allow overlapped copying within the same file. */ in generic_copy_file_checks()
1572 * copy_file_range() differs from regular file read and write in that it
1576 ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, in vfs_copy_file_range()
1577 struct file *file_out, loff_t pos_out, in vfs_copy_file_range()
1606 * Cloning is supported by more file systems, so we implement copy on in vfs_copy_file_range()
1648 * to splicing from input file, while file_start_write() is held on in vfs_copy_file_range()
1649 * the output file on a different sb. in vfs_copy_file_range()
1739 int generic_write_check_limits(struct file *file, loff_t pos, loff_t *count) in generic_write_check_limits() argument
1741 struct inode *inode = file->f_mapping->host; in generic_write_check_limits()
1753 if (!(file->f_flags & O_LARGEFILE)) in generic_write_check_limits()
1768 struct file *file = iocb->ki_filp; in generic_write_checks_count() local
1769 struct inode *inode = file->f_mapping->host; in generic_write_checks_count()
1782 (file->f_op->fop_flags & FOP_BUFFER_WASYNC))) in generic_write_checks_count()
1811 * Performs common checks before doing a file copy/clone
1814 int generic_file_rw_checks(struct file *file_in, struct file *file_out) in generic_file_rw_checks()