patch-2.1.23 linux/fs/read_write.c

Next file: linux/fs/readdir.c
Previous file: linux/fs/proc/scsi.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.22/linux/fs/read_write.c linux/fs/read_write.c
@@ -14,6 +14,8 @@
 #include <linux/mm.h>
 #include <linux/uio.h>
 #include <linux/malloc.h>
+#include <linux/smp.h>
+#include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
 
@@ -60,6 +62,7 @@
 	struct file * file;
 	struct inode * inode;
 
+	lock_kernel();
 	retval = -EBADF;
 	if (fd >= NR_OPEN ||
 	    !(file = current->files->fd[fd]) ||
@@ -70,6 +73,7 @@
 		goto bad;
 	retval = llseek(inode, file, offset, origin);
 bad:
+	unlock_kernel();
 	return retval;
 }
 
@@ -82,6 +86,7 @@
 	struct inode * inode;
 	long long offset;
 
+	lock_kernel();
 	retval = -EBADF;
 	if (fd >= NR_OPEN ||
 	    !(file = current->files->fd[fd]) ||
@@ -101,8 +106,8 @@
 		if (retval)
 			retval = -EFAULT;
 	}
-
 bad:
+	unlock_kernel();
 	return retval;
 }
 
@@ -113,6 +118,7 @@
 	struct inode * inode;
 	long (*read)(struct inode *, struct file *, char *, unsigned long);
 
+	lock_kernel();
 	error = -EBADF;
 	file = fget(fd);
 	if (!file)
@@ -133,6 +139,7 @@
 out:
 	fput(file, inode);
 bad_file:
+	unlock_kernel();
 	return error;
 }
 
@@ -143,6 +150,7 @@
 	struct inode * inode;
 	long (*write)(struct inode *, struct file *, const char *, unsigned long);
 
+	lock_kernel();
 	error = -EBADF;
 	file = fget(fd);
 	if (!file)
@@ -164,6 +172,7 @@
 out:
 	fput(file, inode);
 bad_file:
+	unlock_kernel();
 	return error;
 }
 
@@ -259,26 +268,34 @@
 {
 	struct file * file;
 	struct inode * inode;
+	long err = -EBADF;
 
-	if (fd >= NR_OPEN || !(file = current->files->fd[fd]) || !(inode = file->f_inode))
-		return -EBADF;
+	lock_kernel();
+	if (fd >= NR_OPEN || !(file = current->files->fd[fd]) || !(inode=file->f_inode))
+		goto out;
 	if (!(file->f_mode & 1))
-		return -EBADF;
-	return do_readv_writev(VERIFY_WRITE, inode, file, vector, count);
+		goto out;
+	err = do_readv_writev(VERIFY_WRITE, inode, file, vector, count);
+out:
+	unlock_kernel();
+	return err;
 }
 
 asmlinkage long sys_writev(unsigned long fd, const struct iovec * vector, unsigned long count)
 {
-	int error;
+	int error = -EBADF;
 	struct file * file;
 	struct inode * inode;
 
-	if (fd >= NR_OPEN || !(file = current->files->fd[fd]) || !(inode = file->f_inode))
-		return -EBADF;
+	lock_kernel();
+	if (fd >= NR_OPEN || !(file = current->files->fd[fd]) || !(inode=file->f_inode))
+		goto out;
 	if (!(file->f_mode & 2))
-		return -EBADF;
+		goto out;
 	down(&inode->i_sem);
 	error = do_readv_writev(VERIFY_READ, inode, file, vector, count);
 	up(&inode->i_sem);
+out:
+	unlock_kernel();
 	return error;
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov