cifs: fix wksidarr declaration to be big-endian friendly
[safe/jmp/linux-2.6] / fs / read_write.c
index 0642a16..f0d1240 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/module.h>
 #include <linux/syscalls.h>
 #include <linux/pagemap.h>
+#include <linux/splice.h>
 #include "read_write.h"
 
 #include <asm/uaccess.h>
@@ -25,14 +26,14 @@ const struct file_operations generic_ro_fops = {
        .read           = do_sync_read,
        .aio_read       = generic_file_aio_read,
        .mmap           = generic_file_readonly_mmap,
-       .sendfile       = generic_file_sendfile,
+       .splice_read    = generic_file_splice_read,
 };
 
 EXPORT_SYMBOL(generic_ro_fops);
 
 loff_t generic_file_llseek(struct file *file, loff_t offset, int origin)
 {
-       long long retval;
+       loff_t retval;
        struct inode *inode = file->f_mapping->host;
 
        mutex_lock(&inode->i_mutex);
@@ -59,7 +60,7 @@ EXPORT_SYMBOL(generic_file_llseek);
 
 loff_t remote_llseek(struct file *file, loff_t offset, int origin)
 {
-       long long retval;
+       loff_t retval;
 
        lock_kernel();
        switch (origin) {
@@ -90,7 +91,7 @@ EXPORT_SYMBOL(no_llseek);
 
 loff_t default_llseek(struct file *file, loff_t offset, int origin)
 {
-       long long retval;
+       loff_t retval;
 
        lock_kernel();
        switch (origin) {
@@ -139,7 +140,7 @@ asmlinkage off_t sys_lseek(unsigned int fd, off_t offset, unsigned int origin)
                goto bad;
 
        retval = -EINVAL;
-       if (origin <= 2) {
+       if (origin <= SEEK_MAX) {
                loff_t res = vfs_llseek(file, offset, origin);
                retval = res;
                if (res != (loff_t)retval)
@@ -166,7 +167,7 @@ asmlinkage long sys_llseek(unsigned int fd, unsigned long offset_high,
                goto bad;
 
        retval = -EINVAL;
-       if (origin > 2)
+       if (origin > SEEK_MAX)
                goto out_putf;
 
        offset = vfs_llseek(file, ((loff_t) offset_high << 32) | offset_low,
@@ -196,25 +197,27 @@ int rw_verify_area(int read_write, struct file *file, loff_t *ppos, size_t count
 {
        struct inode *inode;
        loff_t pos;
+       int retval = -EINVAL;
 
        inode = file->f_path.dentry->d_inode;
        if (unlikely((ssize_t) count < 0))
-               goto Einval;
+               return retval;
        pos = *ppos;
        if (unlikely((pos < 0) || (loff_t) (pos + count) < 0))
-               goto Einval;
+               return retval;
 
-       if (unlikely(inode->i_flock && MANDATORY_LOCK(inode))) {
-               int retval = locks_mandatory_area(
+       if (unlikely(inode->i_flock && mandatory_lock(inode))) {
+               retval = locks_mandatory_area(
                        read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE,
                        inode, file, pos, count);
                if (retval < 0)
                        return retval;
        }
+       retval = security_file_permission(file,
+                               read_write == READ ? MAY_READ : MAY_WRITE);
+       if (retval)
+               return retval;
        return count > MAX_RW_COUNT ? MAX_RW_COUNT : count;
-
-Einval:
-       return -EINVAL;
 }
 
 static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
@@ -266,18 +269,15 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
        ret = rw_verify_area(READ, file, pos, count);
        if (ret >= 0) {
                count = ret;
-               ret = security_file_permission (file, MAY_READ);
-               if (!ret) {
-                       if (file->f_op->read)
-                               ret = file->f_op->read(file, buf, count, pos);
-                       else
-                               ret = do_sync_read(file, buf, count, pos);
-                       if (ret > 0) {
-                               fsnotify_access(file->f_path.dentry);
-                               add_rchar(current, ret);
-                       }
-                       inc_syscr(current);
+               if (file->f_op->read)
+                       ret = file->f_op->read(file, buf, count, pos);
+               else
+                       ret = do_sync_read(file, buf, count, pos);
+               if (ret > 0) {
+                       fsnotify_access(file->f_path.dentry);
+                       add_rchar(current, ret);
                }
+               inc_syscr(current);
        }
 
        return ret;
@@ -324,18 +324,15 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
        ret = rw_verify_area(WRITE, file, pos, count);
        if (ret >= 0) {
                count = ret;
-               ret = security_file_permission (file, MAY_WRITE);
-               if (!ret) {
-                       if (file->f_op->write)
-                               ret = file->f_op->write(file, buf, count, pos);
-                       else
-                               ret = do_sync_write(file, buf, count, pos);
-                       if (ret > 0) {
-                               fsnotify_modify(file->f_path.dentry);
-                               add_wchar(current, ret);
-                       }
-                       inc_syscw(current);
+               if (file->f_op->write)
+                       ret = file->f_op->write(file, buf, count, pos);
+               else
+                       ret = do_sync_write(file, buf, count, pos);
+               if (ret > 0) {
+                       fsnotify_modify(file->f_path.dentry);
+                       add_wchar(current, ret);
                }
+               inc_syscw(current);
        }
 
        return ret;
@@ -369,7 +366,6 @@ asmlinkage ssize_t sys_read(unsigned int fd, char __user * buf, size_t count)
 
        return ret;
 }
-EXPORT_SYMBOL_GPL(sys_read);
 
 asmlinkage ssize_t sys_write(unsigned int fd, const char __user * buf, size_t count)
 {
@@ -449,6 +445,7 @@ unsigned long iov_shorten(struct iovec *iov, unsigned long nr_segs, size_t to)
        }
        return seg;
 }
+EXPORT_SYMBOL(iov_shorten);
 
 ssize_t do_sync_readv_writev(struct file *filp, const struct iovec *iov,
                unsigned long nr_segs, size_t len, loff_t *ppos, iov_fn_t fn)
@@ -602,9 +599,6 @@ static ssize_t do_readv_writev(int type, struct file *file,
        ret = rw_verify_area(type, file, pos, tot_len);
        if (ret < 0)
                goto out;
-       ret = security_file_permission(file, type == READ ? MAY_READ : MAY_WRITE);
-       if (ret)
-               goto out;
 
        fnv = NULL;
        if (type == READ) {
@@ -708,7 +702,7 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
        struct inode * in_inode, * out_inode;
        loff_t pos;
        ssize_t retval;
-       int fput_needed_in, fput_needed_out;
+       int fput_needed_in, fput_needed_out, fl;
 
        /*
         * Get input file, and verify that it is ok..
@@ -723,7 +717,7 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
        in_inode = in_file->f_path.dentry->d_inode;
        if (!in_inode)
                goto fput_in;
-       if (!in_file->f_op || !in_file->f_op->sendfile)
+       if (!in_file->f_op || !in_file->f_op->splice_read)
                goto fput_in;
        retval = -ESPIPE;
        if (!ppos)
@@ -736,10 +730,6 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
                goto fput_in;
        count = retval;
 
-       retval = security_file_permission (in_file, MAY_READ);
-       if (retval)
-               goto fput_in;
-
        /*
         * Get output file, and verify that it is ok..
         */
@@ -758,10 +748,6 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
                goto fput_out;
        count = retval;
 
-       retval = security_file_permission (out_file, MAY_WRITE);
-       if (retval)
-               goto fput_out;
-
        if (!max)
                max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
 
@@ -776,7 +762,18 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
                count = max - pos;
        }
 
-       retval = in_file->f_op->sendfile(in_file, ppos, count, file_send_actor, out_file);
+       fl = 0;
+#if 0
+       /*
+        * We need to debate whether we can enable this or not. The
+        * man page documents EAGAIN return for the output at least,
+        * and the application is arguably buggy if it doesn't expect
+        * EAGAIN on a non-blocking file descriptor.
+        */
+       if (in_file->f_flags & O_NONBLOCK)
+               fl = SPLICE_F_NONBLOCK;
+#endif
+       retval = do_splice_direct(in_file, ppos, out_file, count, fl);
 
        if (retval > 0) {
                add_rchar(current, retval);