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/aio.h>
13 #include <linux/fsnotify.h>
14 #include <linux/security.h>
15 #include <linux/export.h>
16 #include <linux/syscalls.h>
17 #include <linux/pagemap.h>
18 #include <linux/splice.h>
19 #include <linux/compat.h>
22 #include <asm/uaccess.h>
23 #include <asm/unistd.h>
25 typedef ssize_t (*io_fn_t)(struct file *, char __user *, size_t, loff_t *);
26 typedef ssize_t (*iov_fn_t)(struct kiocb *, const struct iovec *,
27 unsigned long, loff_t);
29 const struct file_operations generic_ro_fops = {
30 .llseek = generic_file_llseek,
32 .aio_read = generic_file_aio_read,
33 .mmap = generic_file_readonly_mmap,
34 .splice_read = generic_file_splice_read,
37 EXPORT_SYMBOL(generic_ro_fops);
39 static inline int unsigned_offsets(struct file *file)
41 return file->f_mode & FMODE_UNSIGNED_OFFSET;
44 static loff_t lseek_execute(struct file *file, 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)
84 * Here we special-case the lseek(fd, 0, SEEK_CUR)
85 * position-querying operation. Avoid rewriting the "same"
86 * f_pos value back to the file because a concurrent read(),
87 * write() or lseek() might have altered it
92 * f_lock protects against read/modify/write race with other
93 * SEEK_CURs. Note that parallel writes and reads behave
96 spin_lock(&file->f_lock);
97 offset = lseek_execute(file, file->f_pos + offset, maxsize);
98 spin_unlock(&file->f_lock);
102 * In the generic case the entire file is data, so as long as
103 * offset isn't at the end of the file then the offset is data.
110 * There is a virtual hole at the end of the file, so as long as
111 * offset isn't i_size or larger, return i_size.
119 return lseek_execute(file, offset, maxsize);
121 EXPORT_SYMBOL(generic_file_llseek_size);
124 * generic_file_llseek - generic llseek implementation for regular files
125 * @file: file structure to seek on
126 * @offset: file offset to seek to
127 * @whence: type of seek
129 * This is a generic implemenation of ->llseek useable for all normal local
130 * filesystems. It just updates the file offset to the value specified by
131 * @offset and @whence.
133 loff_t generic_file_llseek(struct file *file, loff_t offset, int whence)
135 struct inode *inode = file->f_mapping->host;
137 return generic_file_llseek_size(file, offset, whence,
138 inode->i_sb->s_maxbytes,
141 EXPORT_SYMBOL(generic_file_llseek);
144 * fixed_size_llseek - llseek implementation for fixed-sized devices
145 * @file: file structure to seek on
146 * @offset: file offset to seek to
147 * @whence: type of seek
148 * @size: size of the file
151 loff_t fixed_size_llseek(struct file *file, loff_t offset, int whence, loff_t size)
154 case SEEK_SET: case SEEK_CUR: case SEEK_END:
155 return generic_file_llseek_size(file, offset, whence,
161 EXPORT_SYMBOL(fixed_size_llseek);
164 * noop_llseek - No Operation Performed llseek implementation
165 * @file: file structure to seek on
166 * @offset: file offset to seek to
167 * @whence: type of seek
169 * This is an implementation of ->llseek useable for the rare special case when
170 * userspace expects the seek to succeed but the (device) file is actually not
171 * able to perform the seek. In this case you use noop_llseek() instead of
172 * falling back to the default implementation of ->llseek.
174 loff_t noop_llseek(struct file *file, loff_t offset, int whence)
178 EXPORT_SYMBOL(noop_llseek);
180 loff_t no_llseek(struct file *file, loff_t offset, int whence)
184 EXPORT_SYMBOL(no_llseek);
186 loff_t default_llseek(struct file *file, loff_t offset, int whence)
188 struct inode *inode = file_inode(file);
191 mutex_lock(&inode->i_mutex);
194 offset += i_size_read(inode);
198 retval = file->f_pos;
201 offset += file->f_pos;
205 * In the generic case the entire file is data, so as
206 * long as offset isn't at the end of the file then the
209 if (offset >= inode->i_size) {
216 * There is a virtual hole at the end of the file, so
217 * as long as offset isn't i_size or larger, return
220 if (offset >= inode->i_size) {
224 offset = inode->i_size;
228 if (offset >= 0 || unsigned_offsets(file)) {
229 if (offset != file->f_pos) {
230 file->f_pos = offset;
236 mutex_unlock(&inode->i_mutex);
239 EXPORT_SYMBOL(default_llseek);
241 loff_t vfs_llseek(struct file *file, loff_t offset, int whence)
243 loff_t (*fn)(struct file *, loff_t, int);
246 if (file->f_mode & FMODE_LSEEK) {
247 if (file->f_op && file->f_op->llseek)
248 fn = file->f_op->llseek;
250 return fn(file, offset, whence);
252 EXPORT_SYMBOL(vfs_llseek);
254 SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, whence)
257 struct fd f = fdget(fd);
262 if (whence <= SEEK_MAX) {
263 loff_t res = vfs_llseek(f.file, offset, whence);
265 if (res != (loff_t)retval)
266 retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */
273 COMPAT_SYSCALL_DEFINE3(lseek, unsigned int, fd, compat_off_t, offset, unsigned int, whence)
275 return sys_lseek(fd, offset, whence);
279 #ifdef __ARCH_WANT_SYS_LLSEEK
280 SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high,
281 unsigned long, offset_low, loff_t __user *, result,
282 unsigned int, whence)
285 struct fd f = fdget(fd);
292 if (whence > SEEK_MAX)
295 offset = vfs_llseek(f.file, ((loff_t) offset_high << 32) | offset_low,
298 retval = (int)offset;
301 if (!copy_to_user(result, &offset, sizeof(offset)))
311 * rw_verify_area doesn't like huge counts. We limit
312 * them to something that fits in "int" so that others
313 * won't have to do range checks all the time.
315 int rw_verify_area(int read_write, struct file *file, const loff_t *ppos, size_t count)
319 int retval = -EINVAL;
321 inode = file_inode(file);
322 if (unlikely((ssize_t) count < 0))
325 if (unlikely(pos < 0)) {
326 if (!unsigned_offsets(file))
328 if (count >= -pos) /* both values are in 0..LLONG_MAX */
330 } else if (unlikely((loff_t) (pos + count) < 0)) {
331 if (!unsigned_offsets(file))
335 if (unlikely(inode->i_flock && mandatory_lock(inode))) {
336 retval = locks_mandatory_area(
337 read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE,
338 inode, file, pos, count);
342 retval = security_file_permission(file,
343 read_write == READ ? MAY_READ : MAY_WRITE);
346 return count > MAX_RW_COUNT ? MAX_RW_COUNT : count;
349 ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos)
351 struct iovec iov = { .iov_base = buf, .iov_len = len };
355 init_sync_kiocb(&kiocb, filp);
356 kiocb.ki_pos = *ppos;
358 kiocb.ki_nbytes = len;
360 ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
361 if (-EIOCBQUEUED == ret)
362 ret = wait_on_sync_kiocb(&kiocb);
363 *ppos = kiocb.ki_pos;
367 EXPORT_SYMBOL(do_sync_read);
369 ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
373 if (!(file->f_mode & FMODE_READ))
375 if (!file->f_op || (!file->f_op->read && !file->f_op->aio_read))
377 if (unlikely(!access_ok(VERIFY_WRITE, buf, count)))
380 ret = rw_verify_area(READ, file, pos, count);
383 if (file->f_op->read)
384 ret = file->f_op->read(file, buf, count, pos);
386 ret = do_sync_read(file, buf, count, pos);
388 fsnotify_access(file);
389 add_rchar(current, ret);
397 EXPORT_SYMBOL(vfs_read);
399 ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
401 struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = len };
405 init_sync_kiocb(&kiocb, filp);
406 kiocb.ki_pos = *ppos;
408 kiocb.ki_nbytes = len;
410 ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
411 if (-EIOCBQUEUED == ret)
412 ret = wait_on_sync_kiocb(&kiocb);
413 *ppos = kiocb.ki_pos;
417 EXPORT_SYMBOL(do_sync_write);
419 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
422 const char __user *p;
425 if (!file->f_op || (!file->f_op->write && !file->f_op->aio_write))
430 p = (__force const char __user *)buf;
431 if (count > MAX_RW_COUNT)
432 count = MAX_RW_COUNT;
433 if (file->f_op->write)
434 ret = file->f_op->write(file, p, count, pos);
436 ret = do_sync_write(file, p, count, pos);
439 fsnotify_modify(file);
440 add_wchar(current, ret);
446 ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_t *pos)
450 if (!(file->f_mode & FMODE_WRITE))
452 if (!file->f_op || (!file->f_op->write && !file->f_op->aio_write))
454 if (unlikely(!access_ok(VERIFY_READ, buf, count)))
457 ret = rw_verify_area(WRITE, file, pos, count);
460 file_start_write(file);
461 if (file->f_op->write)
462 ret = file->f_op->write(file, buf, count, pos);
464 ret = do_sync_write(file, buf, count, pos);
466 fsnotify_modify(file);
467 add_wchar(current, ret);
470 file_end_write(file);
476 EXPORT_SYMBOL(vfs_write);
478 static inline loff_t file_pos_read(struct file *file)
483 static inline void file_pos_write(struct file *file, loff_t pos)
488 SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
490 struct fd f = fdget(fd);
491 ssize_t ret = -EBADF;
494 loff_t pos = file_pos_read(f.file);
495 ret = vfs_read(f.file, buf, count, &pos);
497 file_pos_write(f.file, pos);
503 SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
506 struct fd f = fdget(fd);
507 ssize_t ret = -EBADF;
510 loff_t pos = file_pos_read(f.file);
511 ret = vfs_write(f.file, buf, count, &pos);
513 file_pos_write(f.file, pos);
520 SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf,
521 size_t, count, loff_t, pos)
524 ssize_t ret = -EBADF;
532 if (f.file->f_mode & FMODE_PREAD)
533 ret = vfs_read(f.file, buf, count, &pos);
540 SYSCALL_DEFINE4(pwrite64, unsigned int, fd, const char __user *, buf,
541 size_t, count, loff_t, pos)
544 ssize_t ret = -EBADF;
552 if (f.file->f_mode & FMODE_PWRITE)
553 ret = vfs_write(f.file, buf, count, &pos);
561 * Reduce an iovec's length in-place. Return the resulting number of segments
563 unsigned long iov_shorten(struct iovec *iov, unsigned long nr_segs, size_t to)
565 unsigned long seg = 0;
568 while (seg < nr_segs) {
570 if (len + iov->iov_len >= to) {
571 iov->iov_len = to - len;
579 EXPORT_SYMBOL(iov_shorten);
581 static ssize_t do_sync_readv_writev(struct file *filp, const struct iovec *iov,
582 unsigned long nr_segs, size_t len, loff_t *ppos, iov_fn_t fn)
587 init_sync_kiocb(&kiocb, filp);
588 kiocb.ki_pos = *ppos;
590 kiocb.ki_nbytes = len;
592 ret = fn(&kiocb, iov, nr_segs, kiocb.ki_pos);
593 if (ret == -EIOCBQUEUED)
594 ret = wait_on_sync_kiocb(&kiocb);
595 *ppos = kiocb.ki_pos;
599 /* Do it by hand, with file-ops */
600 static ssize_t do_loop_readv_writev(struct file *filp, struct iovec *iov,
601 unsigned long nr_segs, loff_t *ppos, io_fn_t fn)
603 struct iovec *vector = iov;
606 while (nr_segs > 0) {
611 base = vector->iov_base;
612 len = vector->iov_len;
616 nr = fn(filp, base, len, ppos);
631 /* A write operation does a read from user space and vice versa */
632 #define vrfy_dir(type) ((type) == READ ? VERIFY_WRITE : VERIFY_READ)
634 ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
635 unsigned long nr_segs, unsigned long fast_segs,
636 struct iovec *fast_pointer,
637 struct iovec **ret_pointer)
641 struct iovec *iov = fast_pointer;
644 * SuS says "The readv() function *may* fail if the iovcnt argument
645 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
646 * traditionally returned zero for zero segments, so...
654 * First get the "struct iovec" from user memory and
655 * verify all the pointers
657 if (nr_segs > UIO_MAXIOV) {
661 if (nr_segs > fast_segs) {
662 iov = kmalloc(nr_segs*sizeof(struct iovec), GFP_KERNEL);
668 if (copy_from_user(iov, uvector, nr_segs*sizeof(*uvector))) {
674 * According to the Single Unix Specification we should return EINVAL
675 * if an element length is < 0 when cast to ssize_t or if the
676 * total length would overflow the ssize_t return value of the
679 * Linux caps all read/write calls to MAX_RW_COUNT, and avoids the
683 for (seg = 0; seg < nr_segs; seg++) {
684 void __user *buf = iov[seg].iov_base;
685 ssize_t len = (ssize_t)iov[seg].iov_len;
687 /* see if we we're about to use an invalid len or if
688 * it's about to overflow ssize_t */
694 && unlikely(!access_ok(vrfy_dir(type), buf, len))) {
698 if (len > MAX_RW_COUNT - ret) {
699 len = MAX_RW_COUNT - ret;
700 iov[seg].iov_len = len;
709 static ssize_t do_readv_writev(int type, struct file *file,
710 const struct iovec __user * uvector,
711 unsigned long nr_segs, loff_t *pos)
714 struct iovec iovstack[UIO_FASTIOV];
715 struct iovec *iov = iovstack;
725 ret = rw_copy_check_uvector(type, uvector, nr_segs,
726 ARRAY_SIZE(iovstack), iovstack, &iov);
731 ret = rw_verify_area(type, file, pos, tot_len);
737 fn = file->f_op->read;
738 fnv = file->f_op->aio_read;
740 fn = (io_fn_t)file->f_op->write;
741 fnv = file->f_op->aio_write;
742 file_start_write(file);
746 ret = do_sync_readv_writev(file, iov, nr_segs, tot_len,
749 ret = do_loop_readv_writev(file, iov, nr_segs, pos, fn);
752 file_end_write(file);
757 if ((ret + (type == READ)) > 0) {
759 fsnotify_access(file);
761 fsnotify_modify(file);
766 ssize_t vfs_readv(struct file *file, const struct iovec __user *vec,
767 unsigned long vlen, loff_t *pos)
769 if (!(file->f_mode & FMODE_READ))
771 if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read))
774 return do_readv_writev(READ, file, vec, vlen, pos);
777 EXPORT_SYMBOL(vfs_readv);
779 ssize_t vfs_writev(struct file *file, const struct iovec __user *vec,
780 unsigned long vlen, loff_t *pos)
782 if (!(file->f_mode & FMODE_WRITE))
784 if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write))
787 return do_readv_writev(WRITE, file, vec, vlen, pos);
790 EXPORT_SYMBOL(vfs_writev);
792 SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec __user *, vec,
795 struct fd f = fdget(fd);
796 ssize_t ret = -EBADF;
799 loff_t pos = file_pos_read(f.file);
800 ret = vfs_readv(f.file, vec, vlen, &pos);
802 file_pos_write(f.file, pos);
807 add_rchar(current, ret);
812 SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec,
815 struct fd f = fdget(fd);
816 ssize_t ret = -EBADF;
819 loff_t pos = file_pos_read(f.file);
820 ret = vfs_writev(f.file, vec, vlen, &pos);
822 file_pos_write(f.file, pos);
827 add_wchar(current, ret);
832 static inline loff_t pos_from_hilo(unsigned long high, unsigned long low)
834 #define HALF_LONG_BITS (BITS_PER_LONG / 2)
835 return (((loff_t)high << HALF_LONG_BITS) << HALF_LONG_BITS) | low;
838 SYSCALL_DEFINE5(preadv, unsigned long, fd, const struct iovec __user *, vec,
839 unsigned long, vlen, unsigned long, pos_l, unsigned long, pos_h)
841 loff_t pos = pos_from_hilo(pos_h, pos_l);
843 ssize_t ret = -EBADF;
851 if (f.file->f_mode & FMODE_PREAD)
852 ret = vfs_readv(f.file, vec, vlen, &pos);
857 add_rchar(current, ret);
862 SYSCALL_DEFINE5(pwritev, unsigned long, fd, const struct iovec __user *, vec,
863 unsigned long, vlen, unsigned long, pos_l, unsigned long, pos_h)
865 loff_t pos = pos_from_hilo(pos_h, pos_l);
867 ssize_t ret = -EBADF;
875 if (f.file->f_mode & FMODE_PWRITE)
876 ret = vfs_writev(f.file, vec, vlen, &pos);
881 add_wchar(current, ret);
888 static ssize_t compat_do_readv_writev(int type, struct file *file,
889 const struct compat_iovec __user *uvector,
890 unsigned long nr_segs, loff_t *pos)
892 compat_ssize_t tot_len;
893 struct iovec iovstack[UIO_FASTIOV];
894 struct iovec *iov = iovstack;
904 if (!access_ok(VERIFY_READ, uvector, nr_segs*sizeof(*uvector)))
907 ret = compat_rw_copy_check_uvector(type, uvector, nr_segs,
908 UIO_FASTIOV, iovstack, &iov);
913 ret = rw_verify_area(type, file, pos, tot_len);
919 fn = file->f_op->read;
920 fnv = file->f_op->aio_read;
922 fn = (io_fn_t)file->f_op->write;
923 fnv = file->f_op->aio_write;
924 file_start_write(file);
928 ret = do_sync_readv_writev(file, iov, nr_segs, tot_len,
931 ret = do_loop_readv_writev(file, iov, nr_segs, pos, fn);
934 file_end_write(file);
939 if ((ret + (type == READ)) > 0) {
941 fsnotify_access(file);
943 fsnotify_modify(file);
948 static size_t compat_readv(struct file *file,
949 const struct compat_iovec __user *vec,
950 unsigned long vlen, loff_t *pos)
952 ssize_t ret = -EBADF;
954 if (!(file->f_mode & FMODE_READ))
958 if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read))
961 ret = compat_do_readv_writev(READ, file, vec, vlen, pos);
965 add_rchar(current, ret);
970 COMPAT_SYSCALL_DEFINE3(readv, unsigned long, fd,
971 const struct compat_iovec __user *,vec,
974 struct fd f = fdget(fd);
981 ret = compat_readv(f.file, vec, vlen, &pos);
988 COMPAT_SYSCALL_DEFINE4(preadv64, unsigned long, fd,
989 const struct compat_iovec __user *,vec,
990 unsigned long, vlen, loff_t, pos)
1001 if (f.file->f_mode & FMODE_PREAD)
1002 ret = compat_readv(f.file, vec, vlen, &pos);
1007 COMPAT_SYSCALL_DEFINE5(preadv, unsigned long, fd,
1008 const struct compat_iovec __user *,vec,
1009 unsigned long, vlen, u32, pos_low, u32, pos_high)
1011 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
1012 return compat_sys_preadv64(fd, vec, vlen, pos);
1015 static size_t compat_writev(struct file *file,
1016 const struct compat_iovec __user *vec,
1017 unsigned long vlen, loff_t *pos)
1019 ssize_t ret = -EBADF;
1021 if (!(file->f_mode & FMODE_WRITE))
1025 if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write))
1028 ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos);
1032 add_wchar(current, ret);
1037 COMPAT_SYSCALL_DEFINE3(writev, unsigned long, fd,
1038 const struct compat_iovec __user *, vec,
1039 unsigned long, vlen)
1041 struct fd f = fdget(fd);
1047 pos = f.file->f_pos;
1048 ret = compat_writev(f.file, vec, vlen, &pos);
1050 f.file->f_pos = pos;
1055 COMPAT_SYSCALL_DEFINE4(pwritev64, unsigned long, fd,
1056 const struct compat_iovec __user *,vec,
1057 unsigned long, vlen, loff_t, pos)
1068 if (f.file->f_mode & FMODE_PWRITE)
1069 ret = compat_writev(f.file, vec, vlen, &pos);
1074 COMPAT_SYSCALL_DEFINE5(pwritev, unsigned long, fd,
1075 const struct compat_iovec __user *,vec,
1076 unsigned long, vlen, u32, pos_low, u32, pos_high)
1078 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
1079 return compat_sys_pwritev64(fd, vec, vlen, pos);
1083 static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
1084 size_t count, loff_t max)
1087 struct inode *in_inode, *out_inode;
1094 * Get input file, and verify that it is ok..
1100 if (!(in.file->f_mode & FMODE_READ))
1104 pos = in.file->f_pos;
1107 if (!(in.file->f_mode & FMODE_PREAD))
1110 retval = rw_verify_area(READ, in.file, &pos, count);
1116 * Get output file, and verify that it is ok..
1119 out = fdget(out_fd);
1122 if (!(out.file->f_mode & FMODE_WRITE))
1125 in_inode = file_inode(in.file);
1126 out_inode = file_inode(out.file);
1127 out_pos = out.file->f_pos;
1128 retval = rw_verify_area(WRITE, out.file, &out_pos, count);
1134 max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
1136 if (unlikely(pos + count > max)) {
1137 retval = -EOVERFLOW;
1146 * We need to debate whether we can enable this or not. The
1147 * man page documents EAGAIN return for the output at least,
1148 * and the application is arguably buggy if it doesn't expect
1149 * EAGAIN on a non-blocking file descriptor.
1151 if (in.file->f_flags & O_NONBLOCK)
1152 fl = SPLICE_F_NONBLOCK;
1154 file_start_write(out.file);
1155 retval = do_splice_direct(in.file, &pos, out.file, &out_pos, count, fl);
1156 file_end_write(out.file);
1159 add_rchar(current, retval);
1160 add_wchar(current, retval);
1161 fsnotify_access(in.file);
1162 fsnotify_modify(out.file);
1163 out.file->f_pos = out_pos;
1167 in.file->f_pos = pos;
1173 retval = -EOVERFLOW;
1183 SYSCALL_DEFINE4(sendfile, int, out_fd, int, in_fd, off_t __user *, offset, size_t, count)
1190 if (unlikely(get_user(off, offset)))
1193 ret = do_sendfile(out_fd, in_fd, &pos, count, MAX_NON_LFS);
1194 if (unlikely(put_user(pos, offset)))
1199 return do_sendfile(out_fd, in_fd, NULL, count, 0);
1202 SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd, loff_t __user *, offset, size_t, count)
1208 if (unlikely(copy_from_user(&pos, offset, sizeof(loff_t))))
1210 ret = do_sendfile(out_fd, in_fd, &pos, count, 0);
1211 if (unlikely(put_user(pos, offset)))
1216 return do_sendfile(out_fd, in_fd, NULL, count, 0);
1219 #ifdef CONFIG_COMPAT
1220 COMPAT_SYSCALL_DEFINE4(sendfile, int, out_fd, int, in_fd,
1221 compat_off_t __user *, offset, compat_size_t, count)
1228 if (unlikely(get_user(off, offset)))
1231 ret = do_sendfile(out_fd, in_fd, &pos, count, MAX_NON_LFS);
1232 if (unlikely(put_user(pos, offset)))
1237 return do_sendfile(out_fd, in_fd, NULL, count, 0);
1240 COMPAT_SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd,
1241 compat_loff_t __user *, offset, compat_size_t, count)
1247 if (unlikely(copy_from_user(&pos, offset, sizeof(loff_t))))
1249 ret = do_sendfile(out_fd, in_fd, &pos, count, 0);
1250 if (unlikely(put_user(pos, offset)))
1255 return do_sendfile(out_fd, in_fd, NULL, count, 0);