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 ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos)
334 struct iovec iov = { .iov_base = buf, .iov_len = len };
338 init_sync_kiocb(&kiocb, filp);
339 kiocb.ki_pos = *ppos;
341 kiocb.ki_nbytes = len;
343 ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
344 if (-EIOCBQUEUED == ret)
345 ret = wait_on_sync_kiocb(&kiocb);
346 *ppos = kiocb.ki_pos;
350 EXPORT_SYMBOL(do_sync_read);
352 ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
356 if (!(file->f_mode & FMODE_READ))
358 if (!file->f_op || (!file->f_op->read && !file->f_op->aio_read))
360 if (unlikely(!access_ok(VERIFY_WRITE, buf, count)))
363 ret = rw_verify_area(READ, file, pos, count);
366 if (file->f_op->read)
367 ret = file->f_op->read(file, buf, count, pos);
369 ret = do_sync_read(file, buf, count, pos);
371 fsnotify_access(file);
372 add_rchar(current, ret);
380 EXPORT_SYMBOL(vfs_read);
382 ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
384 struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = len };
388 init_sync_kiocb(&kiocb, filp);
389 kiocb.ki_pos = *ppos;
391 kiocb.ki_nbytes = len;
393 ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
394 if (-EIOCBQUEUED == ret)
395 ret = wait_on_sync_kiocb(&kiocb);
396 *ppos = kiocb.ki_pos;
400 EXPORT_SYMBOL(do_sync_write);
402 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
405 const char __user *p;
408 if (!file->f_op || (!file->f_op->write && !file->f_op->aio_write))
413 p = (__force const char __user *)buf;
414 if (count > MAX_RW_COUNT)
415 count = MAX_RW_COUNT;
416 if (file->f_op->write)
417 ret = file->f_op->write(file, p, count, pos);
419 ret = do_sync_write(file, p, count, pos);
422 fsnotify_modify(file);
423 add_wchar(current, ret);
429 ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_t *pos)
433 if (!(file->f_mode & FMODE_WRITE))
435 if (!file->f_op || (!file->f_op->write && !file->f_op->aio_write))
437 if (unlikely(!access_ok(VERIFY_READ, buf, count)))
440 ret = rw_verify_area(WRITE, file, pos, count);
443 file_start_write(file);
444 if (file->f_op->write)
445 ret = file->f_op->write(file, buf, count, pos);
447 ret = do_sync_write(file, buf, count, pos);
449 fsnotify_modify(file);
450 add_wchar(current, ret);
453 file_end_write(file);
459 EXPORT_SYMBOL(vfs_write);
461 static inline loff_t file_pos_read(struct file *file)
466 static inline void file_pos_write(struct file *file, loff_t pos)
471 SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
473 struct fd f = fdget(fd);
474 ssize_t ret = -EBADF;
477 loff_t pos = file_pos_read(f.file);
478 ret = vfs_read(f.file, buf, count, &pos);
479 file_pos_write(f.file, pos);
485 SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
488 struct fd f = fdget(fd);
489 ssize_t ret = -EBADF;
492 loff_t pos = file_pos_read(f.file);
493 ret = vfs_write(f.file, buf, count, &pos);
494 file_pos_write(f.file, pos);
501 SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf,
502 size_t, count, loff_t, pos)
505 ssize_t ret = -EBADF;
513 if (f.file->f_mode & FMODE_PREAD)
514 ret = vfs_read(f.file, buf, count, &pos);
521 SYSCALL_DEFINE4(pwrite64, unsigned int, fd, const char __user *, buf,
522 size_t, count, loff_t, pos)
525 ssize_t ret = -EBADF;
533 if (f.file->f_mode & FMODE_PWRITE)
534 ret = vfs_write(f.file, buf, count, &pos);
542 * Reduce an iovec's length in-place. Return the resulting number of segments
544 unsigned long iov_shorten(struct iovec *iov, unsigned long nr_segs, size_t to)
546 unsigned long seg = 0;
549 while (seg < nr_segs) {
551 if (len + iov->iov_len >= to) {
552 iov->iov_len = to - len;
560 EXPORT_SYMBOL(iov_shorten);
562 static ssize_t do_sync_readv_writev(struct file *filp, const struct iovec *iov,
563 unsigned long nr_segs, size_t len, loff_t *ppos, iov_fn_t fn)
568 init_sync_kiocb(&kiocb, filp);
569 kiocb.ki_pos = *ppos;
571 kiocb.ki_nbytes = len;
573 ret = fn(&kiocb, iov, nr_segs, kiocb.ki_pos);
574 if (ret == -EIOCBQUEUED)
575 ret = wait_on_sync_kiocb(&kiocb);
576 *ppos = kiocb.ki_pos;
580 /* Do it by hand, with file-ops */
581 static ssize_t do_loop_readv_writev(struct file *filp, struct iovec *iov,
582 unsigned long nr_segs, loff_t *ppos, io_fn_t fn)
584 struct iovec *vector = iov;
587 while (nr_segs > 0) {
592 base = vector->iov_base;
593 len = vector->iov_len;
597 nr = fn(filp, base, len, ppos);
612 /* A write operation does a read from user space and vice versa */
613 #define vrfy_dir(type) ((type) == READ ? VERIFY_WRITE : VERIFY_READ)
615 ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
616 unsigned long nr_segs, unsigned long fast_segs,
617 struct iovec *fast_pointer,
618 struct iovec **ret_pointer)
622 struct iovec *iov = fast_pointer;
625 * SuS says "The readv() function *may* fail if the iovcnt argument
626 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
627 * traditionally returned zero for zero segments, so...
635 * First get the "struct iovec" from user memory and
636 * verify all the pointers
638 if (nr_segs > UIO_MAXIOV) {
642 if (nr_segs > fast_segs) {
643 iov = kmalloc(nr_segs*sizeof(struct iovec), GFP_KERNEL);
649 if (copy_from_user(iov, uvector, nr_segs*sizeof(*uvector))) {
655 * According to the Single Unix Specification we should return EINVAL
656 * if an element length is < 0 when cast to ssize_t or if the
657 * total length would overflow the ssize_t return value of the
660 * Linux caps all read/write calls to MAX_RW_COUNT, and avoids the
664 for (seg = 0; seg < nr_segs; seg++) {
665 void __user *buf = iov[seg].iov_base;
666 ssize_t len = (ssize_t)iov[seg].iov_len;
668 /* see if we we're about to use an invalid len or if
669 * it's about to overflow ssize_t */
675 && unlikely(!access_ok(vrfy_dir(type), buf, len))) {
679 if (len > MAX_RW_COUNT - ret) {
680 len = MAX_RW_COUNT - ret;
681 iov[seg].iov_len = len;
690 static ssize_t do_readv_writev(int type, struct file *file,
691 const struct iovec __user * uvector,
692 unsigned long nr_segs, loff_t *pos)
695 struct iovec iovstack[UIO_FASTIOV];
696 struct iovec *iov = iovstack;
706 ret = rw_copy_check_uvector(type, uvector, nr_segs,
707 ARRAY_SIZE(iovstack), iovstack, &iov);
712 ret = rw_verify_area(type, file, pos, tot_len);
718 fn = file->f_op->read;
719 fnv = file->f_op->aio_read;
721 fn = (io_fn_t)file->f_op->write;
722 fnv = file->f_op->aio_write;
723 file_start_write(file);
727 ret = do_sync_readv_writev(file, iov, nr_segs, tot_len,
730 ret = do_loop_readv_writev(file, iov, nr_segs, pos, fn);
733 file_end_write(file);
738 if ((ret + (type == READ)) > 0) {
740 fsnotify_access(file);
742 fsnotify_modify(file);
747 ssize_t vfs_readv(struct file *file, const struct iovec __user *vec,
748 unsigned long vlen, loff_t *pos)
750 if (!(file->f_mode & FMODE_READ))
752 if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read))
755 return do_readv_writev(READ, file, vec, vlen, pos);
758 EXPORT_SYMBOL(vfs_readv);
760 ssize_t vfs_writev(struct file *file, const struct iovec __user *vec,
761 unsigned long vlen, loff_t *pos)
763 if (!(file->f_mode & FMODE_WRITE))
765 if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write))
768 return do_readv_writev(WRITE, file, vec, vlen, pos);
771 EXPORT_SYMBOL(vfs_writev);
773 SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec __user *, vec,
776 struct fd f = fdget(fd);
777 ssize_t ret = -EBADF;
780 loff_t pos = file_pos_read(f.file);
781 ret = vfs_readv(f.file, vec, vlen, &pos);
782 file_pos_write(f.file, pos);
787 add_rchar(current, ret);
792 SYSCALL_DEFINE3(writev, 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_writev(f.file, vec, vlen, &pos);
801 file_pos_write(f.file, pos);
806 add_wchar(current, ret);
811 static inline loff_t pos_from_hilo(unsigned long high, unsigned long low)
813 #define HALF_LONG_BITS (BITS_PER_LONG / 2)
814 return (((loff_t)high << HALF_LONG_BITS) << HALF_LONG_BITS) | low;
817 SYSCALL_DEFINE5(preadv, unsigned long, fd, const struct iovec __user *, vec,
818 unsigned long, vlen, unsigned long, pos_l, unsigned long, pos_h)
820 loff_t pos = pos_from_hilo(pos_h, pos_l);
822 ssize_t ret = -EBADF;
830 if (f.file->f_mode & FMODE_PREAD)
831 ret = vfs_readv(f.file, vec, vlen, &pos);
836 add_rchar(current, ret);
841 SYSCALL_DEFINE5(pwritev, unsigned long, fd, const struct iovec __user *, vec,
842 unsigned long, vlen, unsigned long, pos_l, unsigned long, pos_h)
844 loff_t pos = pos_from_hilo(pos_h, pos_l);
846 ssize_t ret = -EBADF;
854 if (f.file->f_mode & FMODE_PWRITE)
855 ret = vfs_writev(f.file, vec, vlen, &pos);
860 add_wchar(current, ret);
867 static ssize_t compat_do_readv_writev(int type, struct file *file,
868 const struct compat_iovec __user *uvector,
869 unsigned long nr_segs, loff_t *pos)
871 compat_ssize_t tot_len;
872 struct iovec iovstack[UIO_FASTIOV];
873 struct iovec *iov = iovstack;
883 if (!access_ok(VERIFY_READ, uvector, nr_segs*sizeof(*uvector)))
886 ret = compat_rw_copy_check_uvector(type, uvector, nr_segs,
887 UIO_FASTIOV, iovstack, &iov);
892 ret = rw_verify_area(type, file, pos, tot_len);
898 fn = file->f_op->read;
899 fnv = file->f_op->aio_read;
901 fn = (io_fn_t)file->f_op->write;
902 fnv = file->f_op->aio_write;
903 file_start_write(file);
907 ret = do_sync_readv_writev(file, iov, nr_segs, tot_len,
910 ret = do_loop_readv_writev(file, iov, nr_segs, pos, fn);
913 file_end_write(file);
918 if ((ret + (type == READ)) > 0) {
920 fsnotify_access(file);
922 fsnotify_modify(file);
927 static size_t compat_readv(struct file *file,
928 const struct compat_iovec __user *vec,
929 unsigned long vlen, loff_t *pos)
931 ssize_t ret = -EBADF;
933 if (!(file->f_mode & FMODE_READ))
937 if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read))
940 ret = compat_do_readv_writev(READ, file, vec, vlen, pos);
944 add_rchar(current, ret);
949 COMPAT_SYSCALL_DEFINE3(readv, unsigned long, fd,
950 const struct compat_iovec __user *,vec,
953 struct fd f = fdget(fd);
960 ret = compat_readv(f.file, vec, vlen, &pos);
966 COMPAT_SYSCALL_DEFINE4(preadv64, unsigned long, fd,
967 const struct compat_iovec __user *,vec,
968 unsigned long, vlen, loff_t, pos)
979 if (f.file->f_mode & FMODE_PREAD)
980 ret = compat_readv(f.file, vec, vlen, &pos);
985 COMPAT_SYSCALL_DEFINE5(preadv, unsigned long, fd,
986 const struct compat_iovec __user *,vec,
987 unsigned long, vlen, u32, pos_low, u32, pos_high)
989 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
990 return compat_sys_preadv64(fd, vec, vlen, pos);
993 static size_t compat_writev(struct file *file,
994 const struct compat_iovec __user *vec,
995 unsigned long vlen, loff_t *pos)
997 ssize_t ret = -EBADF;
999 if (!(file->f_mode & FMODE_WRITE))
1003 if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write))
1006 ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos);
1010 add_wchar(current, ret);
1015 COMPAT_SYSCALL_DEFINE3(writev, unsigned long, fd,
1016 const struct compat_iovec __user *, vec,
1017 unsigned long, vlen)
1019 struct fd f = fdget(fd);
1025 pos = f.file->f_pos;
1026 ret = compat_writev(f.file, vec, vlen, &pos);
1027 f.file->f_pos = pos;
1032 COMPAT_SYSCALL_DEFINE4(pwritev64, unsigned long, fd,
1033 const struct compat_iovec __user *,vec,
1034 unsigned long, vlen, loff_t, pos)
1045 if (f.file->f_mode & FMODE_PWRITE)
1046 ret = compat_writev(f.file, vec, vlen, &pos);
1051 COMPAT_SYSCALL_DEFINE5(pwritev, unsigned long, fd,
1052 const struct compat_iovec __user *,vec,
1053 unsigned long, vlen, u32, pos_low, u32, pos_high)
1055 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
1056 return compat_sys_pwritev64(fd, vec, vlen, pos);
1060 static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
1061 size_t count, loff_t max)
1064 struct inode *in_inode, *out_inode;
1070 * Get input file, and verify that it is ok..
1076 if (!(in.file->f_mode & FMODE_READ))
1080 ppos = &in.file->f_pos;
1082 if (!(in.file->f_mode & FMODE_PREAD))
1084 retval = rw_verify_area(READ, in.file, ppos, count);
1090 * Get output file, and verify that it is ok..
1093 out = fdget(out_fd);
1096 if (!(out.file->f_mode & FMODE_WRITE))
1099 in_inode = file_inode(in.file);
1100 out_inode = file_inode(out.file);
1101 retval = rw_verify_area(WRITE, out.file, &out.file->f_pos, count);
1107 max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
1110 if (unlikely(pos + count > max)) {
1111 retval = -EOVERFLOW;
1120 * We need to debate whether we can enable this or not. The
1121 * man page documents EAGAIN return for the output at least,
1122 * and the application is arguably buggy if it doesn't expect
1123 * EAGAIN on a non-blocking file descriptor.
1125 if (in.file->f_flags & O_NONBLOCK)
1126 fl = SPLICE_F_NONBLOCK;
1128 retval = do_splice_direct(in.file, ppos, out.file, count, fl);
1131 add_rchar(current, retval);
1132 add_wchar(current, retval);
1133 fsnotify_access(in.file);
1134 fsnotify_modify(out.file);
1140 retval = -EOVERFLOW;
1150 SYSCALL_DEFINE4(sendfile, int, out_fd, int, in_fd, off_t __user *, offset, size_t, count)
1157 if (unlikely(get_user(off, offset)))
1160 ret = do_sendfile(out_fd, in_fd, &pos, count, MAX_NON_LFS);
1161 if (unlikely(put_user(pos, offset)))
1166 return do_sendfile(out_fd, in_fd, NULL, count, 0);
1169 SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd, loff_t __user *, offset, size_t, count)
1175 if (unlikely(copy_from_user(&pos, offset, sizeof(loff_t))))
1177 ret = do_sendfile(out_fd, in_fd, &pos, count, 0);
1178 if (unlikely(put_user(pos, offset)))
1183 return do_sendfile(out_fd, in_fd, NULL, count, 0);
1186 #ifdef CONFIG_COMPAT
1187 COMPAT_SYSCALL_DEFINE4(sendfile, int, out_fd, int, in_fd,
1188 compat_off_t __user *, offset, compat_size_t, count)
1195 if (unlikely(get_user(off, offset)))
1198 ret = do_sendfile(out_fd, in_fd, &pos, count, MAX_NON_LFS);
1199 if (unlikely(put_user(pos, offset)))
1204 return do_sendfile(out_fd, in_fd, NULL, count, 0);
1207 COMPAT_SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd,
1208 compat_loff_t __user *, offset, compat_size_t, count)
1214 if (unlikely(copy_from_user(&pos, offset, sizeof(loff_t))))
1216 ret = do_sendfile(out_fd, in_fd, &pos, count, 0);
1217 if (unlikely(put_user(pos, offset)))
1222 return do_sendfile(out_fd, in_fd, NULL, count, 0);