7 #include <linux/slab.h>
8 #include <linux/stat.h>
9 #include <linux/fcntl.h>
11 #include <linux/uio.h>
14 #include <linux/export.h>
20 #include <asm/uaccess.h>
21 #include <asm/unistd.h>
33 static inline int unsigned_offsets(
struct file *
file)
39 loff_t
offset, loff_t maxsize)
41 if (offset < 0 && !unsigned_offsets(file))
46 if (offset != file->
f_pos) {
71 loff_t maxsize, loff_t eof)
73 struct inode *inode = file->
f_mapping->host;
94 offset = lseek_execute(file, inode, file->
f_pos + offset,
96 spin_unlock(&file->
f_lock);
117 return lseek_execute(file, inode, offset, maxsize);
133 struct inode *inode = file->
f_mapping->host;
136 inode->
i_sb->s_maxbytes,
166 struct inode *inode = file->
f_path.dentry->d_inode;
172 offset += i_size_read(inode);
176 retval = file->
f_pos;
179 offset += file->
f_pos;
187 if (offset >= inode->
i_size) {
198 if (offset >= inode->
i_size) {
206 if (offset >= 0 || unsigned_offsets(file)) {
207 if (offset != file->
f_pos) {
221 loff_t (*
fn)(
struct file *, loff_t,
int);
225 if (file->
f_op && file->
f_op->llseek)
228 return fn(file, offset, origin);
235 struct fd f = fdget(
fd);
243 if (res != (loff_t)retval)
250 #ifdef __ARCH_WANT_SYS_LLSEEK
256 struct fd f = fdget(
fd);
269 retval = (
int)offset;
293 inode = file->
f_path.dentry->d_inode;
298 if (!unsigned_offsets(file))
302 }
else if (
unlikely((loff_t) (pos + count) < 0)) {
303 if (!unsigned_offsets(file))
310 inode, file, pos, count);
321 static void wait_on_retry_sync_kiocb(
struct kiocb *
iocb)
337 init_sync_kiocb(&kiocb, filp);
343 ret = filp->
f_op->aio_read(&kiocb, &iov, 1, kiocb.
ki_pos);
346 wait_on_retry_sync_kiocb(&kiocb);
363 if (!file->
f_op || (!file->
f_op->read && !file->
f_op->aio_read))
371 if (file->
f_op->read)
372 ret = file->
f_op->read(file, buf, count, pos);
376 fsnotify_access(file);
393 init_sync_kiocb(&kiocb, filp);
399 ret = filp->
f_op->aio_write(&kiocb, &iov, 1, kiocb.
ki_pos);
402 wait_on_retry_sync_kiocb(&kiocb);
419 if (!file->
f_op || (!file->
f_op->write && !file->
f_op->aio_write))
427 if (file->
f_op->write)
428 ret = file->
f_op->write(file, buf, count, pos);
432 fsnotify_modify(file);
443 static inline loff_t file_pos_read(
struct file *file)
448 static inline void file_pos_write(
struct file *file, loff_t
pos)
455 struct fd f = fdget(
fd);
459 loff_t
pos = file_pos_read(f.
file);
461 file_pos_write(f.
file, pos);
470 struct fd f = fdget(
fd);
474 loff_t
pos = file_pos_read(f.
file);
476 file_pos_write(f.
file, pos);
502 #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS
503 asmlinkage long SyS_pread64(
long fd,
long buf,
long count, loff_t
pos)
505 return SYSC_pread64((
unsigned int) fd, (
char __user *) buf,
506 (
size_t) count, pos);
530 #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS
531 asmlinkage long SyS_pwrite64(
long fd,
long buf,
long count, loff_t pos)
533 return SYSC_pwrite64((
unsigned int) fd, (
const char __user *) buf,
534 (
size_t) count, pos);
544 unsigned long seg = 0;
547 while (seg < nr_segs) {
549 if (len + iov->
iov_len >= to) {
561 unsigned long nr_segs,
size_t len, loff_t *ppos,
iov_fn_t fn)
566 init_sync_kiocb(&kiocb, filp);
572 ret =
fn(&kiocb, iov, nr_segs, kiocb.
ki_pos);
575 wait_on_retry_sync_kiocb(&kiocb);
586 unsigned long nr_segs, loff_t *ppos,
io_fn_t fn)
591 while (nr_segs > 0) {
601 nr =
fn(filp, base, len, ppos);
617 #define vrfy_dir(type) ((type) == READ ? VERIFY_WRITE : VERIFY_READ)
620 unsigned long nr_segs,
unsigned long fast_segs,
621 struct iovec *fast_pointer,
622 struct iovec **ret_pointer)
626 struct iovec *iov = fast_pointer;
646 if (nr_segs > fast_segs) {
668 for (seg = 0; seg < nr_segs; seg++) {
694 static ssize_t do_readv_writev(
int type,
struct file *file,
695 const struct iovec __user * uvector,
696 unsigned long nr_segs, loff_t *pos)
700 struct iovec *iov = iovstack;
722 fn = file->
f_op->read;
723 fnv = file->
f_op->aio_read;
726 fnv = file->
f_op->aio_write;
738 if ((ret + (type ==
READ)) > 0) {
740 fsnotify_access(file);
742 fsnotify_modify(file);
748 unsigned long vlen, loff_t *pos)
752 if (!file->
f_op || (!file->
f_op->aio_read && !file->
f_op->read))
755 return do_readv_writev(
READ, file, vec, vlen, pos);
761 unsigned long vlen, loff_t *pos)
765 if (!file->
f_op || (!file->
f_op->aio_write && !file->
f_op->write))
768 return do_readv_writev(
WRITE, file, vec, vlen, pos);
776 struct fd f = fdget(fd);
780 loff_t pos = file_pos_read(f.
file);
782 file_pos_write(f.
file, pos);
795 struct fd f = fdget(fd);
799 loff_t pos = file_pos_read(f.
file);
801 file_pos_write(f.
file, pos);
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;
818 unsigned long, vlen,
unsigned long, pos_l,
unsigned long, pos_h)
820 loff_t pos = pos_from_hilo(pos_h, pos_l);
842 unsigned long, vlen,
unsigned long, pos_l,
unsigned long, pos_h)
844 loff_t pos = pos_from_hilo(pos_h, pos_l);
869 struct inode *in_inode, *out_inode;
885 ppos = &in.
file->f_pos;
904 in_inode = in.
file->f_path.dentry->d_inode;
905 out_inode = out.
file->f_path.dentry->d_inode;
912 max =
min(in_inode->
i_sb->s_maxbytes, out_inode->
i_sb->s_maxbytes);
972 SYSCALL_DEFINE4(sendfile64,
int, out_fd,
int, in_fd, loff_t __user *, offset,
size_t, count)