patch-2.1.89 linux/fs/ioctl.c

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

diff -u --recursive --new-file v2.1.88/linux/fs/ioctl.c linux/fs/ioctl.c
@@ -13,6 +13,7 @@
 #include <linux/smp.h>
 #include <linux/smp_lock.h>
 #include <linux/fcntl.h> /* for f_flags values */
+#include <linux/file.h>
 
 #include <asm/uaccess.h>
 
@@ -52,7 +53,8 @@
 	int on, error = -EBADF;
 
 	lock_kernel();
-	if (fd >= NR_OPEN || !(filp = current->files->fd[fd]))
+	filp = fget(fd);
+	if (!filp)
 		goto out;
 	error = 0;
 	switch (cmd) {
@@ -90,13 +92,16 @@
 			break;
 
 		default:
-			if (filp->f_dentry && filp->f_dentry->d_inode && S_ISREG(filp->f_dentry->d_inode->i_mode))
+			error = -ENOTTY;
+			if (!filp->f_dentry || !filp->f_dentry->d_inode)
+				error = -ENOENT;
+			else if (S_ISREG(filp->f_dentry->d_inode->i_mode))
 				error = file_ioctl(filp, cmd, arg);
 			else if (filp->f_op && filp->f_op->ioctl)
 				error = filp->f_op->ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
-			else
-				error = -ENOTTY;
 	}
+	fput(filp);
+
 out:
 	unlock_kernel();
 	return error;

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