patch-2.0.37 linux/fs/ioctl.c

Next file: linux/fs/isofs/inode.c
Previous file: linux/fs/ext2/fsync.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.0.36/linux/fs/ioctl.c linux/fs/ioctl.c
@@ -8,6 +8,7 @@
 
 #include <linux/sched.h>
 #include <linux/mm.h>
+#include <linux/file.h>
 #include <linux/errno.h>
 #include <linux/string.h>
 #include <linux/stat.h>
@@ -59,50 +60,57 @@
 {	
 	struct file * filp;
 	int on;
+	int retval = 0;
 
-	if (fd >= NR_OPEN || !(filp = current->files->fd[fd]))
+	filp = fget(fd);
+	
+	if(filp==NULL)
 		return -EBADF;
+		
 	switch (cmd) {
 		case FIOCLEX:
 			FD_SET(fd, &current->files->close_on_exec);
-			return 0;
+			break;
 
 		case FIONCLEX:
 			FD_CLR(fd, &current->files->close_on_exec);
-			return 0;
+			break;
 
 		case FIONBIO:
-			on = verify_area(VERIFY_READ, (unsigned int *)arg,
+			retval = verify_area(VERIFY_READ, (unsigned int *)arg,
 				sizeof(unsigned int));
-			if(on)	
-				return on;
-			on = get_user((unsigned int *) arg);
-			if (on)
-				filp->f_flags |= O_NONBLOCK;
-			else
-				filp->f_flags &= ~O_NONBLOCK;
-			return 0;
+			if(!retval)	
+			{
+				on = get_user((unsigned int *) arg);
+				if (on)
+					filp->f_flags |= O_NONBLOCK;
+				else
+					filp->f_flags &= ~O_NONBLOCK;
+			}
+			break;
 
 		case FIOASYNC: /* O_SYNC is not yet implemented,
 				  but it's here for completeness. */
-			on = verify_area(VERIFY_READ, (unsigned int *)arg,
+			retval = verify_area(VERIFY_READ, (unsigned int *)arg,
 				sizeof(unsigned int));
-			if(on)	
-				return on;
-			on = get_user ((unsigned int *) arg);
-			if (on)
-				filp->f_flags |= O_SYNC;
-			else
-				filp->f_flags &= ~O_SYNC;
-			return 0;
+			if(!retval)	
+			{
+				on = get_user ((unsigned int *) arg);
+				if (on)
+					filp->f_flags |= O_SYNC;
+				else
+					filp->f_flags &= ~O_SYNC;
+			}
+			break;
 
 		default:
 			if (filp->f_inode && S_ISREG(filp->f_inode->i_mode))
-				return file_ioctl(filp, cmd, arg);
-
-			if (filp->f_op && filp->f_op->ioctl)
-				return filp->f_op->ioctl(filp->f_inode, filp, cmd, arg);
-
-			return -ENOTTY;
+				retval = file_ioctl(filp, cmd, arg);
+			else if (filp->f_op && filp->f_op->ioctl)
+				retval = filp->f_op->ioctl(filp->f_inode, filp, cmd, arg);
+			else 
+				retval = -ENOTTY;
 	}
+	fput(filp, filp->f_inode);
+	return retval;
 }

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