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, struct inode *inode,
45 loff_t offset, loff_t maxsize)
47 if (offset < 0 && !unsigned_offsets(file))
52 if (offset != file->f_pos) {
60 * generic_file_llseek_size - generic llseek implementation for regular files
61 * @file: file structure to seek on
62 * @offset: file offset to seek to
63 * @whence: type of seek
64 * @size: max size of this file in file system
65 * @eof: offset used for SEEK_END position
67 * This is a variant of generic_file_llseek that allows passing in a custom
68 * maximum file size and a custom EOF position, for e.g. hashed directories
71 * SEEK_SET and SEEK_END are unsynchronized (but atomic on 64bit platforms)
72 * SEEK_CUR is synchronized against other SEEK_CURs, but not read/writes.
73 * read/writes behave like SEEK_SET against seeks.
76 generic_file_llseek_size(struct file *file, loff_t offset, int whence,
77 loff_t maxsize, loff_t eof)
79 struct inode *inode = file->f_mapping->host;
87 * Here we special-case the lseek(fd, 0, SEEK_CUR)
88 * position-querying operation. Avoid rewriting the "same"
89 * f_pos value back to the file because a concurrent read(),
90 * write() or lseek() might have altered it
95 * f_lock protects against read/modify/write race with other
96 * SEEK_CURs. Note that parallel writes and reads behave
99 spin_lock(&file->f_lock);
100 offset = lseek_execute(file, inode, file->f_pos + offset,
102 spin_unlock(&file->f_lock);
106 * In the generic case the entire file is data, so as long as
107 * offset isn't at the end of the file then the offset is data.
114 * There is a virtual hole at the end of the file, so as long as
115 * offset isn't i_size or larger, return i_size.
123 return lseek_execute(file, inode, offset, maxsize);
125 EXPORT_SYMBOL(generic_file_llseek_size);
128 * generic_file_llseek - generic llseek implementation for regular files
129 * @file: file structure to seek on
130 * @offset: file offset to seek to
131 * @whence: type of seek
133 * This is a generic implemenation of ->llseek useable for all normal local
134 * filesystems. It just updates the file offset to the value specified by
135 * @offset and @whence.
137 loff_t generic_file_llseek(struct file *file, loff_t offset, int whence)
139 struct inode *inode = file->f_mapping->host;
141 return generic_file_llseek_size(file, offset, whence,
142 inode->i_sb->s_maxbytes,
145 EXPORT_SYMBOL(generic_file_llseek);
148 * noop_llseek - No Operation Performed llseek implementation
149 * @file: file structure to seek on
150 * @offset: file offset to seek to
151 * @whence: type of seek
153 * This is an implementation of ->llseek useable for the rare special case when
154 * userspace expects the seek to succeed but the (device) file is actually not
155 * able to perform the seek. In this case you use noop_llseek() instead of
156 * falling back to the default implementation of ->llseek.
158 loff_t noop_llseek(struct file *file, loff_t offset, int whence)
162 EXPORT_SYMBOL(noop_llseek);
164 loff_t no_llseek(struct file *file, loff_t offset, int whence)
168 EXPORT_SYMBOL(no_llseek);
170 loff_t default_llseek(struct file *file, loff_t offset, int whence)
172 struct inode *inode = file_inode(file);
175 mutex_lock(&inode->i_mutex);
178 offset += i_size_read(inode);
182 retval = file->f_pos;
185 offset += file->f_pos;
189 * In the generic case the entire file is data, so as
190 * long as offset isn't at the end of the file then the
193 if (offset >= inode->i_size) {
200 * There is a virtual hole at the end of the file, so
201 * as long as offset isn't i_size or larger, return
204 if (offset >= inode->i_size) {
208 offset = inode->i_size;
212 if (offset >= 0 || unsigned_offsets(file)) {
213 if (offset != file->f_pos) {
214 file->f_pos = offset;
220 mutex_unlock(&inode->i_mutex);
223 EXPORT_SYMBOL(default_llseek);
225 loff_t vfs_llseek(struct file *file, loff_t offset, int whence)
227 loff_t (*fn)(struct file *, loff_t, int);
230 if (file->f_mode & FMODE_LSEEK) {
231 if (file->f_op && file->f_op->llseek)
232 fn = file->f_op->llseek;
234 return fn(file, offset, whence);
236 EXPORT_SYMBOL(vfs_llseek);
238 SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, whence)
241 struct fd f = fdget(fd);
246 if (whence <= SEEK_MAX) {
247 loff_t res = vfs_llseek(f.file, offset, whence);
249 if (res != (loff_t)retval)
250 retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */
257 COMPAT_SYSCALL_DEFINE3(lseek, unsigned int, fd, compat_off_t, offset, unsigned int, whence)
259 return sys_lseek(fd, offset, whence);
263 #ifdef __ARCH_WANT_SYS_LLSEEK
264 SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high,
265 unsigned long, offset_low, loff_t __user *, result,
266 unsigned int, whence)
269 struct fd f = fdget(fd);
276 if (whence > SEEK_MAX)
279 offset = vfs_llseek(f.file, ((loff_t) offset_high << 32) | offset_low,
282 retval = (int)offset;
285 if (!copy_to_user(result, &offset, sizeof(offset)))
295 * rw_verify_area doesn't like huge counts. We limit
296 * them to something that fits in "int" so that others
297 * won't have to do range checks all the time.
299 int rw_verify_area(int read_write, struct file *file, loff_t *ppos, size_t count)
303 int retval = -EINVAL;
305 inode = file_inode(file);
306 if (unlikely((ssize_t) count < 0))
309 if (unlikely(pos < 0)) {
310 if (!unsigned_offsets(file))
312 if (count >= -pos) /* both values are in 0..LLONG_MAX */
314 } else if (unlikely((loff_t) (pos + count) < 0)) {
315 if (!unsigned_offsets(file))
319 if (unlikely(inode->i_flock && mandatory_lock(inode))) {
320 retval = locks_mandatory_area(
321 read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE,
322 inode, file, pos, count);
326 retval = security_file_permission(file,
327 read_write == READ ? MAY_READ : MAY_WRITE);
330 return count > MAX_RW_COUNT ? MAX_RW_COUNT : count;
333 ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos)
335 struct iovec iov = { .iov_base = buf, .iov_len = len };
339 init_sync_kiocb(&kiocb, filp);
340 kiocb.ki_pos = *ppos;
342 kiocb.ki_nbytes = len;
344 ret = filp->f_op->aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
345 if (-EIOCBQUEUED == ret)
346 ret = wait_on_sync_kiocb(&kiocb);
347 *ppos = kiocb.ki_pos;
351 EXPORT_SYMBOL(do_sync_read);
353 ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
357 if (!(file->f_mode & FMODE_READ))
359 if (!file->f_op || (!file->f_op->read && !file->f_op->aio_read))
361 if (unlikely(!access_ok(VERIFY_WRITE, buf, count)))
364 ret = rw_verify_area(READ, file, pos, count);
367 if (file->f_op->read)
368 ret = file->f_op->read(file, buf, count, pos);
370 ret = do_sync_read(file, buf, count, pos);
372 fsnotify_access(file);
373 add_rchar(current, ret);
381 EXPORT_SYMBOL(vfs_read);
383 ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
385 struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = len };
389 init_sync_kiocb(&kiocb, filp);
390 kiocb.ki_pos = *ppos;
392 kiocb.ki_nbytes = len;
394 ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
395 if (-EIOCBQUEUED == ret)
396 ret = wait_on_sync_kiocb(&kiocb);
397 *ppos = kiocb.ki_pos;
401 EXPORT_SYMBOL(do_sync_write);
403 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
406 const char __user *p;
409 if (!file->f_op || (!file->f_op->write && !file->f_op->aio_write))
414 p = (__force const char __user *)buf;
415 if (count > MAX_RW_COUNT)
416 count = MAX_RW_COUNT;
417 if (file->f_op->write)
418 ret = file->f_op->write(file, p, count, pos);
420 ret = do_sync_write(file, p, count, pos);
423 fsnotify_modify(file);
424 add_wchar(current, ret);
430 ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_t *pos)
434 if (!(file->f_mode & FMODE_WRITE))
436 if (!file->f_op || (!file->f_op->write && !file->f_op->aio_write))
438 if (unlikely(!access_ok(VERIFY_READ, buf, count)))
441 ret = rw_verify_area(WRITE, file, pos, count);
444 file_start_write(file);
445 if (file->f_op->write)
446 ret = file->f_op->write(file, buf, count, pos);
448 ret = do_sync_write(file, buf, count, pos);
450 fsnotify_modify(file);
451 add_wchar(current, ret);
454 file_end_write(file);
460 EXPORT_SYMBOL(vfs_write);
462 static inline loff_t file_pos_read(struct file *file)
467 static inline void file_pos_write(struct file *file, loff_t pos)
472 SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
474 struct fd f = fdget(fd);
475 ssize_t ret = -EBADF;
478 loff_t pos = file_pos_read(f.file);
479 ret = vfs_read(f.file, buf, count, &pos);
480 file_pos_write(f.file, pos);
486 SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
489 struct fd f = fdget(fd);
490 ssize_t ret = -EBADF;
493 loff_t pos = file_pos_read(f.file);
494 ret = vfs_write(f.file, buf, count, &pos);
495 file_pos_write(f.file, pos);
502 SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf,
503 size_t, count, loff_t, pos)
506 ssize_t ret = -EBADF;
514 if (f.file->f_mode & FMODE_PREAD)
515 ret = vfs_read(f.file, buf, count, &pos);
522 SYSCALL_DEFINE4(pwrite64, unsigned int, fd, const char __user *, buf,
523 size_t, count, loff_t, pos)
526 ssize_t ret = -EBADF;
534 if (f.file->f_mode & FMODE_PWRITE)
535 ret = vfs_write(f.file, buf, count, &pos);
543 * Reduce an iovec's length in-place. Return the resulting number of segments
545 unsigned long iov_shorten(struct iovec *iov, unsigned long nr_segs, size_t to)
547 unsigned long seg = 0;
550 while (seg < nr_segs) {
552 if (len + iov->iov_len >= to) {
553 iov->iov_len = to - len;
561 EXPORT_SYMBOL(iov_shorten);
563 static ssize_t do_sync_readv_writev(struct file *filp, const struct iovec *iov,
564 unsigned long nr_segs, size_t len, loff_t *ppos, iov_fn_t fn)
569 init_sync_kiocb(&kiocb, filp);
570 kiocb.ki_pos = *ppos;
572 kiocb.ki_nbytes = len;
574 ret = fn(&kiocb, iov, nr_segs, kiocb.ki_pos);
575 if (ret == -EIOCBQUEUED)
576 ret = wait_on_sync_kiocb(&kiocb);
577 *ppos = kiocb.ki_pos;
581 /* Do it by hand, with file-ops */
582 static ssize_t do_loop_readv_writev(struct file *filp, struct iovec *iov,
583 unsigned long nr_segs, loff_t *ppos, io_fn_t fn)
585 struct iovec *vector = iov;
588 while (nr_segs > 0) {
593 base = vector->iov_base;
594 len = vector->iov_len;
598 nr = fn(filp, base, len, ppos);
613 /* A write operation does a read from user space and vice versa */
614 #define vrfy_dir(type) ((type) == READ ? VERIFY_WRITE : VERIFY_READ)
616 ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
617 unsigned long nr_segs, unsigned long fast_segs,
618 struct iovec *fast_pointer,
619 struct iovec **ret_pointer)
623 struct iovec *iov = fast_pointer;
626 * SuS says "The readv() function *may* fail if the iovcnt argument
627 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
628 * traditionally returned zero for zero segments, so...
636 * First get the "struct iovec" from user memory and
637 * verify all the pointers
639 if (nr_segs > UIO_MAXIOV) {
643 if (nr_segs > fast_segs) {
644 iov = kmalloc(nr_segs*sizeof(struct iovec), GFP_KERNEL);
650 if (copy_from_user(iov, uvector, nr_segs*sizeof(*uvector))) {
656 * According to the Single Unix Specification we should return EINVAL
657 * if an element length is < 0 when cast to ssize_t or if the
658 * total length would overflow the ssize_t return value of the
661 * Linux caps all read/write calls to MAX_RW_COUNT, and avoids the
665 for (seg = 0; seg < nr_segs; seg++) {
666 void __user *buf = iov[seg].iov_base;
667 ssize_t len = (ssize_t)iov[seg].iov_len;
669 /* see if we we're about to use an invalid len or if
670 * it's about to overflow ssize_t */
676 && unlikely(!access_ok(vrfy_dir(type), buf, len))) {
680 if (len > MAX_RW_COUNT - ret) {
681 len = MAX_RW_COUNT - ret;
682 iov[seg].iov_len = len;
691 static ssize_t do_readv_writev(int type, struct file *file,
692 const struct iovec __user * uvector,
693 unsigned long nr_segs, loff_t *pos)
696 struct iovec iovstack[UIO_FASTIOV];
697 struct iovec *iov = iovstack;
707 ret = rw_copy_check_uvector(type, uvector, nr_segs,
708 ARRAY_SIZE(iovstack), iovstack, &iov);
713 ret = rw_verify_area(type, file, pos, tot_len);
719 fn = file->f_op->read;
720 fnv = file->f_op->aio_read;
722 fn = (io_fn_t)file->f_op->write;
723 fnv = file->f_op->aio_write;
724 file_start_write(file);
728 ret = do_sync_readv_writev(file, iov, nr_segs, tot_len,
731 ret = do_loop_readv_writev(file, iov, nr_segs, pos, fn);
734 file_end_write(file);
739 if ((ret + (type == READ)) > 0) {
741 fsnotify_access(file);
743 fsnotify_modify(file);
748 ssize_t vfs_readv(struct file *file, const struct iovec __user *vec,
749 unsigned long vlen, loff_t *pos)
751 if (!(file->f_mode & FMODE_READ))
753 if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read))
756 return do_readv_writev(READ, file, vec, vlen, pos);
759 EXPORT_SYMBOL(vfs_readv);
761 ssize_t vfs_writev(struct file *file, const struct iovec __user *vec,
762 unsigned long vlen, loff_t *pos)
764 if (!(file->f_mode & FMODE_WRITE))
766 if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write))
769 return do_readv_writev(WRITE, file, vec, vlen, pos);
772 EXPORT_SYMBOL(vfs_writev);
774 SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec __user *, vec,
777 struct fd f = fdget(fd);
778 ssize_t ret = -EBADF;
781 loff_t pos = file_pos_read(f.file);
782 ret = vfs_readv(f.file, vec, vlen, &pos);
783 file_pos_write(f.file, pos);
788 add_rchar(current, ret);
793 SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec __user *, vec,
796 struct fd f = fdget(fd);
797 ssize_t ret = -EBADF;
800 loff_t pos = file_pos_read(f.file);
801 ret = vfs_writev(f.file, vec, vlen, &pos);
802 file_pos_write(f.file, pos);
807 add_wchar(current, ret);
812 static inline loff_t pos_from_hilo(unsigned long high, unsigned long low)
814 #define HALF_LONG_BITS (BITS_PER_LONG / 2)
815 return (((loff_t)high << HALF_LONG_BITS) << HALF_LONG_BITS) | low;
818 SYSCALL_DEFINE5(preadv, unsigned long, fd, const struct iovec __user *, vec,
819 unsigned long, vlen, unsigned long, pos_l, unsigned long, pos_h)
821 loff_t pos = pos_from_hilo(pos_h, pos_l);
823 ssize_t ret = -EBADF;
831 if (f.file->f_mode & FMODE_PREAD)
832 ret = vfs_readv(f.file, vec, vlen, &pos);
837 add_rchar(current, ret);
842 SYSCALL_DEFINE5(pwritev, unsigned long, fd, const struct iovec __user *, vec,
843 unsigned long, vlen, unsigned long, pos_l, unsigned long, pos_h)
845 loff_t pos = pos_from_hilo(pos_h, pos_l);
847 ssize_t ret = -EBADF;
855 if (f.file->f_mode & FMODE_PWRITE)
856 ret = vfs_writev(f.file, vec, vlen, &pos);
861 add_wchar(current, ret);
868 static ssize_t compat_do_readv_writev(int type, struct file *file,
869 const struct compat_iovec __user *uvector,
870 unsigned long nr_segs, loff_t *pos)
872 compat_ssize_t tot_len;
873 struct iovec iovstack[UIO_FASTIOV];
874 struct iovec *iov = iovstack;
884 if (!access_ok(VERIFY_READ, uvector, nr_segs*sizeof(*uvector)))
887 ret = compat_rw_copy_check_uvector(type, uvector, nr_segs,
888 UIO_FASTIOV, iovstack, &iov);
893 ret = rw_verify_area(type, file, pos, tot_len);
899 fn = file->f_op->read;
900 fnv = file->f_op->aio_read;
902 fn = (io_fn_t)file->f_op->write;
903 fnv = file->f_op->aio_write;
904 file_start_write(file);
908 ret = do_sync_readv_writev(file, iov, nr_segs, tot_len,
911 ret = do_loop_readv_writev(file, iov, nr_segs, pos, fn);
914 file_end_write(file);
919 if ((ret + (type == READ)) > 0) {
921 fsnotify_access(file);
923 fsnotify_modify(file);
928 static size_t compat_readv(struct file *file,
929 const struct compat_iovec __user *vec,
930 unsigned long vlen, loff_t *pos)
932 ssize_t ret = -EBADF;
934 if (!(file->f_mode & FMODE_READ))
938 if (!file->f_op || (!file->f_op->aio_read && !file->f_op->read))
941 ret = compat_do_readv_writev(READ, file, vec, vlen, pos);
945 add_rchar(current, ret);
950 COMPAT_SYSCALL_DEFINE3(readv, unsigned long, fd,
951 const struct compat_iovec __user *,vec,
954 struct fd f = fdget(fd);
961 ret = compat_readv(f.file, vec, vlen, &pos);
967 COMPAT_SYSCALL_DEFINE4(preadv64, unsigned long, fd,
968 const struct compat_iovec __user *,vec,
969 unsigned long, vlen, loff_t, pos)
980 if (f.file->f_mode & FMODE_PREAD)
981 ret = compat_readv(f.file, vec, vlen, &pos);
986 COMPAT_SYSCALL_DEFINE5(preadv, unsigned long, fd,
987 const struct compat_iovec __user *,vec,
988 unsigned long, vlen, u32, pos_low, u32, pos_high)
990 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
991 return compat_sys_preadv64(fd, vec, vlen, pos);
994 static size_t compat_writev(struct file *file,
995 const struct compat_iovec __user *vec,
996 unsigned long vlen, loff_t *pos)
998 ssize_t ret = -EBADF;
1000 if (!(file->f_mode & FMODE_WRITE))
1004 if (!file->f_op || (!file->f_op->aio_write && !file->f_op->write))
1007 ret = compat_do_readv_writev(WRITE, file, vec, vlen, pos);
1011 add_wchar(current, ret);
1016 COMPAT_SYSCALL_DEFINE3(writev, unsigned long, fd,
1017 const struct compat_iovec __user *, vec,
1018 unsigned long, vlen)
1020 struct fd f = fdget(fd);
1026 pos = f.file->f_pos;
1027 ret = compat_writev(f.file, vec, vlen, &pos);
1028 f.file->f_pos = pos;
1033 COMPAT_SYSCALL_DEFINE4(pwritev64, unsigned long, fd,
1034 const struct compat_iovec __user *,vec,
1035 unsigned long, vlen, loff_t, pos)
1046 if (f.file->f_mode & FMODE_PWRITE)
1047 ret = compat_writev(f.file, vec, vlen, &pos);
1052 COMPAT_SYSCALL_DEFINE5(pwritev, unsigned long, fd,
1053 const struct compat_iovec __user *,vec,
1054 unsigned long, vlen, u32, pos_low, u32, pos_high)
1056 loff_t pos = ((loff_t)pos_high << 32) | pos_low;
1057 return compat_sys_pwritev64(fd, vec, vlen, pos);
1061 static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
1062 size_t count, loff_t max)
1065 struct inode *in_inode, *out_inode;
1071 * Get input file, and verify that it is ok..
1077 if (!(in.file->f_mode & FMODE_READ))
1081 ppos = &in.file->f_pos;
1083 if (!(in.file->f_mode & FMODE_PREAD))
1085 retval = rw_verify_area(READ, in.file, ppos, count);
1091 * Get output file, and verify that it is ok..
1094 out = fdget(out_fd);
1097 if (!(out.file->f_mode & FMODE_WRITE))
1100 in_inode = file_inode(in.file);
1101 out_inode = file_inode(out.file);
1102 retval = rw_verify_area(WRITE, out.file, &out.file->f_pos, count);
1108 max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
1111 if (unlikely(pos + count > max)) {
1112 retval = -EOVERFLOW;
1121 * We need to debate whether we can enable this or not. The
1122 * man page documents EAGAIN return for the output at least,
1123 * and the application is arguably buggy if it doesn't expect
1124 * EAGAIN on a non-blocking file descriptor.
1126 if (in.file->f_flags & O_NONBLOCK)
1127 fl = SPLICE_F_NONBLOCK;
1129 retval = do_splice_direct(in.file, ppos, out.file, count, fl);
1132 add_rchar(current, retval);
1133 add_wchar(current, retval);
1134 fsnotify_access(in.file);
1135 fsnotify_modify(out.file);
1141 retval = -EOVERFLOW;
1151 SYSCALL_DEFINE4(sendfile, int, out_fd, int, in_fd, off_t __user *, offset, size_t, count)
1158 if (unlikely(get_user(off, offset)))
1161 ret = do_sendfile(out_fd, in_fd, &pos, count, MAX_NON_LFS);
1162 if (unlikely(put_user(pos, offset)))
1167 return do_sendfile(out_fd, in_fd, NULL, count, 0);
1170 SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd, loff_t __user *, offset, size_t, count)
1176 if (unlikely(copy_from_user(&pos, offset, sizeof(loff_t))))
1178 ret = do_sendfile(out_fd, in_fd, &pos, count, 0);
1179 if (unlikely(put_user(pos, offset)))
1184 return do_sendfile(out_fd, in_fd, NULL, count, 0);
1187 #ifdef CONFIG_COMPAT
1188 COMPAT_SYSCALL_DEFINE4(sendfile, int, out_fd, int, in_fd,
1189 compat_off_t __user *, offset, compat_size_t, count)
1196 if (unlikely(get_user(off, offset)))
1199 ret = do_sendfile(out_fd, in_fd, &pos, count, MAX_NON_LFS);
1200 if (unlikely(put_user(pos, offset)))
1205 return do_sendfile(out_fd, in_fd, NULL, count, 0);
1208 COMPAT_SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd,
1209 compat_loff_t __user *, offset, compat_size_t, count)
1215 if (unlikely(copy_from_user(&pos, offset, sizeof(loff_t))))
1217 ret = do_sendfile(out_fd, in_fd, &pos, count, 0);
1218 if (unlikely(put_user(pos, offset)))
1223 return do_sendfile(out_fd, in_fd, NULL, count, 0);