2 * linux/fs/read_write.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
7 #include <linux/slab.h>
8 #include <linux/stat.h>
9 #include <linux/fcntl.h>
10 #include <linux/file.h>
11 #include <linux/uio.h>
12 #include <linux/fsnotify.h>
13 #include <linux/security.h>
14 #include <linux/export.h>
15 #include <linux/syscalls.h>
16 #include <linux/pagemap.h>
17 #include <linux/splice.h>
18 #include <linux/compat.h>
21 #include <asm/uaccess.h>
22 #include <asm/unistd.h>
24 typedef ssize_t (*io_fn_t)(struct file *, char __user *, size_t, loff_t *);
25 typedef ssize_t (*iov_fn_t)(struct kiocb *, const struct iovec *,
26 unsigned long, loff_t);
28 const struct file_operations generic_ro_fops = {
29 .llseek = generic_file_llseek,
31 .aio_read = generic_file_aio_read,
32 .mmap = generic_file_readonly_mmap,
33 .splice_read = generic_file_splice_read,
36 EXPORT_SYMBOL(generic_ro_fops);
38 static inline int unsigned_offsets(struct file *file)
40 return file->f_mode & FMODE_UNSIGNED_OFFSET;
43 static loff_t lseek_execute(struct file *file, struct inode *inode,
44 loff_t offset, loff_t maxsize)
46 if (offset < 0 && !unsigned_offsets(file))
51 if (offset != file->f_pos) {
59 * generic_file_llseek_size - generic llseek implementation for regular files
60 * @file: file structure to seek on
61 * @offset: file offset to seek to
62 * @whence: type of seek
63 * @size: max size of this file in file system
64 * @eof: offset used for SEEK_END position
66 * This is a variant of generic_file_llseek that allows passing in a custom
67 * maximum file size and a custom EOF position, for e.g. hashed directories
70 * SEEK_SET and SEEK_END are unsynchronized (but atomic on 64bit platforms)
71 * SEEK_CUR is synchronized against other SEEK_CURs, but not read/writes.
72 * read/writes behave like SEEK_SET against seeks.
75 generic_file_llseek_size(struct file *file, loff_t offset, int whence,
76 loff_t maxsize, loff_t eof)
78 struct inode *inode = file->f_mapping->host;
86 * Here we special-case the lseek(fd, 0, SEEK_CUR)
87 * position-querying operation. Avoid rewriting the "same"
88 * f_pos value back to the file because a concurrent read(),
89 * write() or lseek() might have altered it
94 * f_lock protects against read/modify/write race with other
95 * SEEK_CURs. Note that parallel writes and reads behave
98 spin_lock(&file->f_lock);
99 offset = lseek_execute(file, inode, file->f_pos + offset,
101 spin_unlock(&file->f_lock);
105 * In the generic case the entire file is data, so as long as
106 * offset isn't at the end of the file then the offset is data.
113 * There is a virtual hole at the end of the file, so as long as
114 * offset isn't i_size or larger, return i_size.
122 return lseek_execute(file, inode, offset, maxsize);
124 EXPORT_SYMBOL(generic_file_llseek_size);
127 * generic_file_llseek - generic llseek implementation for regular files
128 * @file: file structure to seek on
129 * @offset: file offset to seek to
130 * @whence: type of seek
132 * This is a generic implemenation of ->llseek useable for all normal local
133 * filesystems. It just updates the file offset to the value specified by
134 * @offset and @whence.
136 loff_t generic_file_llseek(struct file *file, loff_t offset, int whence)
138 struct inode *inode = file->f_mapping->host;
140 return generic_file_llseek_size(file, offset, whence,
141 inode->i_sb->s_maxbytes,
144 EXPORT_SYMBOL(generic_file_llseek);
147 * noop_llseek - No Operation Performed llseek implementation
148 * @file: file structure to seek on
149 * @offset: file offset to seek to
150 * @whence: type of seek
152 * This is an implementation of ->llseek useable for the rare special case when
153 * userspace expects the seek to succeed but the (device) file is actually not
154 * able to perform the seek. In this case you use noop_llseek() instead of
155 * falling back to the default implementation of ->llseek.
157 loff_t noop_llseek(struct file *file, loff_t offset, int whence)
161 EXPORT_SYMBOL(noop_llseek);
163 loff_t no_llseek(struct file *file, loff_t offset, int whence)
167 EXPORT_SYMBOL(no_llseek);
169 loff_t default_llseek(struct file *file, loff_t offset, int whence)
171 struct inode *inode = file_inode(file);
174 mutex_lock(&inode->i_mutex);
177 offset += i_size_read(inode);
181 retval = file->f_pos;
184 offset += file->f_pos;
188 * In the generic case the entire file is data, so as
189 * long as offset isn't at the end of the file then the
192 if (offset >= inode->i_size) {
199 * There is a virtual hole at the end of the file, so
200 * as long as offset isn't i_size or larger, return
203 if (offset >= inode->i_size) {
207 offset = inode->i_size;
211 if (offset >= 0 || unsigned_offsets(file)) {
212 if (offset != file->f_pos) {
213 file->f_pos = offset;
219 mutex_unlock(&inode->i_mutex);
222 EXPORT_SYMBOL(default_llseek);
224 loff_t vfs_llseek(struct file *file, loff_t offset, int whence)
226 loff_t (*fn)(struct file *, loff_t, int);
229 if (file->f_mode & FMODE_LSEEK) {
230 if (file->f_op && file->f_op->llseek)
231 fn = file->f_op->llseek;
233 return fn(file, offset, whence);
235 EXPORT_SYMBOL(vfs_llseek);
237 SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, whence)
240 struct fd f = fdget(fd);
245 if (whence <= SEEK_MAX) {
246 loff_t res = vfs_llseek(f.file, offset, whence);
248 if (res != (loff_t)retval)
249 retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */
256 COMPAT_SYSCALL_DEFINE3(lseek, unsigned int, fd, compat_off_t, offset, unsigned int, whence)
258 return sys_lseek(fd, offset, whence);
262 #ifdef __ARCH_WANT_SYS_LLSEEK
263 SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high,
264 unsigned long, offset_low, loff_t __user *, result,
265 unsigned int, whence)
268 struct fd f = fdget(fd);
275 if (whence > SEEK_MAX)
278 offset = vfs_llseek(f.file, ((loff_t) offset_high << 32) | offset_low,
281 retval = (int)offset;
284 if (!copy_to_user(result, &offset, sizeof(offset)))
294 * rw_verify_area doesn't like huge counts. We limit
295 * them to something that fits in "int" so that others
296 * won't have to do range checks all the time.
298 int rw_verify_area(int read_write, struct file *file, loff_t *ppos, size_t count)
302 int retval = -EINVAL;
304 inode = file_inode(file);
305 if (unlikely((ssize_t) count < 0))
308 if (unlikely(pos < 0)) {
309 if (!unsigned_offsets(file))
311 if (count >= -pos) /* both values are in 0..LLONG_MAX */
313 } else if (unlikely((loff_t) (pos + count) < 0)) {
314 if (!unsigned_offsets(file))
318 if (unlikely(inode->i_flock && mandatory_lock(inode))) {
319 retval = locks_mandatory_area(
320 read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE,
321 inode, file, pos, count);
325 retval = security_file_permission(file,
326 read_write == READ ? MAY_READ : MAY_WRITE);
329 return count > MAX_RW_COUNT ? MAX_RW_COUNT : count;
332 static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
334 set_current_state(TASK_UNINTERRUPTIBLE);
335 if (!kiocbIsKicked(iocb))
338 kiocbClearKicked(iocb);
339 __set_current_state(TASK_RUNNING);
342 ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos)
344 struct iovec iov = { .iov_base = buf, .iov_len = len };
348 init_sync_kiocb(&kiocb, filp);
349 kiocb.ki_pos = *ppos;
351 kiocb.ki_nbytes = len;
354 ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
355 if (ret != -EIOCBRETRY)
357 wait_on_retry_sync_kiocb(&kiocb);
360 if (-EIOCBQUEUED == ret)
361 ret = wait_on_sync_kiocb(&kiocb);
362 *ppos = kiocb.ki_pos;
366 EXPORT_SYMBOL(do_sync_read);
368 ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
372 if (!(file->f_mode & FMODE_READ))
374 if (!file->f_op || (!file->f_op->read && !file->f_op->aio_read))
376 if (unlikely(!access_ok(VERIFY_WRITE, buf, count)))
379 ret = rw_verify_area(READ, file, pos, count);
382 if (file->f_op->read)
383 ret = file->f_op->read(file, buf, count, pos);
385 ret = do_sync_read(file, buf, count, pos);
387 fsnotify_access(file);
388 add_rchar(current, ret);
396 EXPORT_SYMBOL(vfs_read);
398 ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
400 struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = len };
404 init_sync_kiocb(&kiocb, filp);
405 kiocb.ki_pos = *ppos;
407 kiocb.ki_nbytes = len;
410 ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
411 if (ret != -EIOCBRETRY)
413 wait_on_retry_sync_kiocb(&kiocb);
416 if (-EIOCBQUEUED == ret)
417 ret = wait_on_sync_kiocb(&kiocb);
418 *ppos = kiocb.ki_pos;
422 EXPORT_SYMBOL(do_sync_write);
424 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
427 const char __user *p;
430 if (!file->f_op || (!file->f_op->write && !file->f_op->aio_write))
435 p = (__force const char __user *)buf;
436 if (count > MAX_RW_COUNT)
437 count = MAX_RW_COUNT;
438 if (file->f_op->write)
439 ret = file->f_op->write(file, p, count, pos);
441 ret = do_sync_write(file, p, count, pos);
444 fsnotify_modify(file);
445 add_wchar(current, ret);
451 ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_t *pos)
455 if (!(file->f_mode & FMODE_WRITE))
457 if (!file->f_op || (!file->f_op->write && !file->f_op->aio_write))
459 if (unlikely(!access_ok(VERIFY_READ, buf, count)))
462 ret = rw_verify_area(WRITE, file, pos, count);
465 file_start_write(file);
466 if (file->f_op->write)
467 ret = file->f_op->write(file, buf, count, pos);
469 ret = do_sync_write(file, buf, count, pos);
471 fsnotify_modify(file);
472 add_wchar(current, ret);
475 file_end_write(file);
481 EXPORT_SYMBOL(vfs_write);
483 static inline loff_t file_pos_read(struct file *file)
488 static inline void file_pos_write(struct file *file, loff_t pos)
493 SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
495 struct fd f = fdget(fd);
496 ssize_t ret = -EBADF;
499 loff_t pos = file_pos_read(f.file);
500 ret = vfs_read(f.file, buf, count, &pos);
501 file_pos_write(f.file, pos);
507 SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
510 struct fd f = fdget(fd);
511 ssize_t ret = -EBADF;
514 loff_t pos = file_pos_read(f.file);
515 ret = vfs_write(f.file, buf, count, &pos);
516 file_pos_write(f.file, pos);
523 SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf,
524 size_t, count, loff_t, pos)
527 ssize_t ret = -EBADF;
535 if (f.file->f_mode & FMODE_PREAD)
536 ret = vfs_read(f.file, buf, count, &pos);
543 SYSCALL_DEFINE4(pwrite64, unsigned int, fd, const char __user *, buf,
544 size_t, count, loff_t, pos)
547 ssize_t ret = -EBADF;
555 if (f.file->f_mode & FMODE_PWRITE)
556 ret = vfs_write(f.file, buf, count, &pos);
564 * Reduce an iovec's length in-place. Return the resulting number of segments
566 unsigned long iov_shorten(struct iovec *iov, unsigned long nr_segs, size_t to)
568 unsigned long seg = 0;
571 while (seg < nr_segs) {
573 if (len + iov->iov_len >= to) {
574 iov->iov_len = to - len;
582 EXPORT_SYMBOL(iov_shorten);
584 static ssize_t do_sync_readv_writev(struct file *filp, const struct iovec *iov,
585 unsigned long nr_segs, size_t len, loff_t *ppos, iov_fn_t fn)
590 init_sync_kiocb(&kiocb, filp);
591 kiocb.ki_pos = *ppos;
593 kiocb.ki_nbytes = len;
596 ret = fn(&kiocb, iov, nr_segs, kiocb.ki_pos);
597 if (ret != -EIOCBRETRY)
599 wait_on_retry_sync_kiocb(&kiocb);
602 if (ret == -EIOCBQUEUED)
603 ret = wait_on_sync_kiocb(&kiocb);
604 *ppos = kiocb.ki_pos;
608 /* Do it by hand, with file-ops */
609 static ssize_t do_loop_readv_writev(struct file *filp, struct iovec *iov,
610 unsigned long nr_segs, loff_t *ppos, io_fn_t fn)
612 struct iovec *vector = iov;
615 while (nr_segs > 0) {
620 base = vector->iov_base;
621 len = vector->iov_len;
625 nr = fn(filp, base, len, ppos);
640 /* A write operation does a read from user space and vice versa */
641 #define vrfy_dir(type) ((type) == READ ? VERIFY_WRITE : VERIFY_READ)
643 ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
644 unsigned long nr_segs, unsigned long fast_segs,
645 struct iovec *fast_pointer,
646 struct iovec **ret_pointer)
650 struct iovec *iov = fast_pointer;
653 * SuS says "The readv() function *may* fail if the iovcnt argument
654 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
655 * traditionally returned zero for zero segments, so...
663 * First get the "struct iovec" from user memory and
664 * verify all the pointers
666 if (nr_segs > UIO_MAXIOV) {
670 if (nr_segs > fast_segs) {
671 iov = kmalloc(nr_segs*sizeof(struct iovec), GFP_KERNEL);
677 if (copy_from_user(iov, uvector, nr_segs*sizeof(*uvector))) {
683 * According to the Single Unix Specification we should return EINVAL
684 * if an element length is < 0 when cast to ssize_t or if the
685 * total length would overflow the ssize_t return value of the
688 * Linux caps all read/write calls to MAX_RW_COUNT, and avoids the
692 for (seg = 0; seg < nr_segs; seg++) {
693 void __user *buf = iov[seg].iov_base;
694 ssize_t len = (ssize_t)iov[seg].iov_len;
696 /* see if we we're about to use an invalid len or if
697 * it's about to overflow ssize_t */
703 && unlikely(!access_ok(vrfy_dir(type), buf, len))) {
707 if (len > MAX_RW_COUNT - ret) {
708 len = MAX_RW_COUNT - ret;
709 iov[seg].iov_len = len;
718 static ssize_t do_readv_writev(int type, struct file *file,
719 const struct iovec __user * uvector,
720 unsigned long nr_segs, loff_t *pos)
723 struct iovec iovstack[UIO_FASTIOV];
724 struct iovec *iov = iovstack;
734 ret = rw_copy_check_uvector(type, uvector, nr_segs,
735 ARRAY_SIZE(iovstack), iovstack, &iov);
740 ret = rw_verify_area(type, file, pos, tot_len);
746 fn = file->f_op->read;
747 fnv = file->f_op->aio_read;
749 fn = (io_fn_t)file->f_op->write;
750 fnv = file->f_op->aio_write;
751 file_start_write(file);
755 ret = do_sync_readv_writev(file, iov, nr_segs, tot_len,
758 ret = do_loop_readv_writev(file, iov, nr_segs, pos, fn);
761 file_end_write(file);
766 if ((ret + (type == READ)) > 0) {
768 fsnotify_access(file);
770 fsnotify_modify(file);
775 ssize_t vfs_readv(struct file *file, const struct iovec __user *vec,
776 unsigned long vlen, loff_t *pos)
778 if (!(file->f_mode & FMODE_READ))
780 if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read))
783 return do_readv_writev(READ, file, vec, vlen, pos);
786 EXPORT_SYMBOL(vfs_readv);
788 ssize_t vfs_writev(struct file *file, const struct iovec __user *vec,
789 unsigned long vlen, loff_t *pos)
791 if (!(file->f_mode & FMODE_WRITE))
793 if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write))
796 return do_readv_writev(WRITE, file, vec, vlen, pos);
799 EXPORT_SYMBOL(vfs_writev);
801 SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec __user *, vec,
804 struct fd f = fdget(fd);
805 ssize_t ret = -EBADF;
808 loff_t pos = file_pos_read(f.file);
809 ret = vfs_readv(f.file, vec, vlen, &pos);
810 file_pos_write(f.file, pos);
815 add_rchar(current, ret);
820 SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec,
823 struct fd f = fdget(fd);
824 ssize_t ret = -EBADF;
827 loff_t pos = file_pos_read(f.file);
828 ret = vfs_writev(f.file, vec, vlen, &pos);
829 file_pos_write(f.file, pos);
834 add_wchar(current, ret);
839 static inline loff_t pos_from_hilo(unsigned long high, unsigned long low)
841 #define HALF_LONG_BITS (BITS_PER_LONG / 2)
842 return (((loff_t)high << HALF_LONG_BITS) << HALF_LONG_BITS) | low;
845 SYSCALL_DEFINE5(preadv, unsigned long, fd, const struct iovec __user *, vec,
846 unsigned long, vlen, unsigned long, pos_l, unsigned long, pos_h)
848 loff_t pos = pos_from_hilo(pos_h, pos_l);
850 ssize_t ret = -EBADF;
858 if (f.file->f_mode & FMODE_PREAD)
859 ret = vfs_readv(f.file, vec, vlen, &pos);
864 add_rchar(current, ret);
869 SYSCALL_DEFINE5(pwritev, unsigned long, fd, const struct iovec __user *, vec,
870 unsigned long, vlen, unsigned long, pos_l, unsigned long, pos_h)
872 loff_t pos = pos_from_hilo(pos_h, pos_l);
874 ssize_t ret = -EBADF;
882 if (f.file->f_mode & FMODE_PWRITE)
883 ret = vfs_writev(f.file, vec, vlen, &pos);
888 add_wchar(current, ret);
895 static ssize_t compat_do_readv_writev(int type, struct file *file,
896 const struct compat_iovec __user *uvector,
897 unsigned long nr_segs, loff_t *pos)
899 compat_ssize_t tot_len;
900 struct iovec iovstack[UIO_FASTIOV];
901 struct iovec *iov = iovstack;
911 if (!access_ok(VERIFY_READ, uvector, nr_segs*sizeof(*uvector)))
914 ret = compat_rw_copy_check_uvector(type, uvector, nr_segs,
915 UIO_FASTIOV, iovstack, &iov);
920 ret = rw_verify_area(type, file, pos, tot_len);
926 fn = file->f_op->read;
927 fnv = file->f_op->aio_read;
929 fn = (io_fn_t)file->f_op->write;
930 fnv = file->f_op->aio_write;
931 file_start_write(file);
935 ret = do_sync_readv_writev(file, iov, nr_segs, tot_len,
938 ret = do_loop_readv_writev(file, iov, nr_segs, pos, fn);
941 file_end_write(file);
946 if ((ret + (type == READ)) > 0) {
948 fsnotify_access(file);
950 fsnotify_modify(file);
955 static size_t compat_readv(struct file *file,
956 const struct compat_iovec __user *vec,
957 unsigned long vlen, loff_t *pos)
959 ssize_t ret = -EBADF;
961 if (!(file->f_mode & FMODE_READ))
965 if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read))
968 ret = compat_do_readv_writev(READ, file, vec, vlen, pos);
972 add_rchar(current, ret);
977 COMPAT_SYSCALL_DEFINE3(readv, unsigned long, fd,
978 const struct compat_iovec __user *,vec,
981 struct fd f = fdget(fd);
988 ret = compat_readv(f.file, vec, vlen, &pos);
994 COMPAT_SYSCALL_DEFINE4(preadv64, unsigned long, fd,
995 const struct compat_iovec __user *,vec,
996 unsigned long, vlen, loff_t, pos)
1007 if (f.file->f_mode & FMODE_PREAD)
1008 ret = compat_readv(f.file, vec, vlen, &pos);
1013 COMPAT_SYSCALL_DEFINE5(preadv, unsigned long, fd,
1014 const struct compat_iovec __user *,vec,
1015 unsigned long, vlen, u32, pos_low, u32, pos_high)
1017 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
1018 return compat_sys_preadv64(fd, vec, vlen, pos);
1021 static size_t compat_writev(struct file *file,
1022 const struct compat_iovec __user *vec,
1023 unsigned long vlen, loff_t *pos)
1025 ssize_t ret = -EBADF;
1027 if (!(file->f_mode & FMODE_WRITE))
1031 if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write))
1034 ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos);
1038 add_wchar(current, ret);
1043 COMPAT_SYSCALL_DEFINE3(writev, unsigned long, fd,
1044 const struct compat_iovec __user *, vec,
1045 unsigned long, vlen)
1047 struct fd f = fdget(fd);
1053 pos = f.file->f_pos;
1054 ret = compat_writev(f.file, vec, vlen, &pos);
1055 f.file->f_pos = pos;
1060 COMPAT_SYSCALL_DEFINE4(pwritev64, unsigned long, fd,
1061 const struct compat_iovec __user *,vec,
1062 unsigned long, vlen, loff_t, pos)
1073 if (f.file->f_mode & FMODE_PWRITE)
1074 ret = compat_writev(f.file, vec, vlen, &pos);
1079 COMPAT_SYSCALL_DEFINE5(pwritev, unsigned long, fd,
1080 const struct compat_iovec __user *,vec,
1081 unsigned long, vlen, u32, pos_low, u32, pos_high)
1083 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
1084 return compat_sys_pwritev64(fd, vec, vlen, pos);
1088 static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
1089 size_t count, loff_t max)
1092 struct inode *in_inode, *out_inode;
1098 * Get input file, and verify that it is ok..
1104 if (!(in.file->f_mode & FMODE_READ))
1108 ppos = &in.file->f_pos;
1110 if (!(in.file->f_mode & FMODE_PREAD))
1112 retval = rw_verify_area(READ, in.file, ppos, count);
1118 * Get output file, and verify that it is ok..
1121 out = fdget(out_fd);
1124 if (!(out.file->f_mode & FMODE_WRITE))
1127 in_inode = file_inode(in.file);
1128 out_inode = file_inode(out.file);
1129 retval = rw_verify_area(WRITE, out.file, &out.file->f_pos, count);
1135 max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
1138 if (unlikely(pos + count > max)) {
1139 retval = -EOVERFLOW;
1148 * We need to debate whether we can enable this or not. The
1149 * man page documents EAGAIN return for the output at least,
1150 * and the application is arguably buggy if it doesn't expect
1151 * EAGAIN on a non-blocking file descriptor.
1153 if (in.file->f_flags & O_NONBLOCK)
1154 fl = SPLICE_F_NONBLOCK;
1156 retval = do_splice_direct(in.file, ppos, out.file, count, fl);
1159 add_rchar(current, retval);
1160 add_wchar(current, retval);
1161 fsnotify_access(in.file);
1162 fsnotify_modify(out.file);
1168 retval = -EOVERFLOW;
1178 SYSCALL_DEFINE4(sendfile, int, out_fd, int, in_fd, off_t __user *, offset, size_t, count)
1185 if (unlikely(get_user(off, offset)))
1188 ret = do_sendfile(out_fd, in_fd, &pos, count, MAX_NON_LFS);
1189 if (unlikely(put_user(pos, offset)))
1194 return do_sendfile(out_fd, in_fd, NULL, count, 0);
1197 SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd, loff_t __user *, offset, size_t, count)
1203 if (unlikely(copy_from_user(&pos, offset, sizeof(loff_t))))
1205 ret = do_sendfile(out_fd, in_fd, &pos, count, 0);
1206 if (unlikely(put_user(pos, offset)))
1211 return do_sendfile(out_fd, in_fd, NULL, count, 0);
1214 #ifdef CONFIG_COMPAT
1215 COMPAT_SYSCALL_DEFINE4(sendfile, int, out_fd, int, in_fd,
1216 compat_off_t __user *, offset, compat_size_t, count)
1223 if (unlikely(get_user(off, offset)))
1226 ret = do_sendfile(out_fd, in_fd, &pos, count, MAX_NON_LFS);
1227 if (unlikely(put_user(pos, offset)))
1232 return do_sendfile(out_fd, in_fd, NULL, count, 0);
1235 COMPAT_SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd,
1236 compat_loff_t __user *, offset, compat_size_t, count)
1242 if (unlikely(copy_from_user(&pos, offset, sizeof(loff_t))))
1244 ret = do_sendfile(out_fd, in_fd, &pos, count, 0);
1245 if (unlikely(put_user(pos, offset)))
1250 return do_sendfile(out_fd, in_fd, NULL, count, 0);