patch-2.4.0-test5 linux/drivers/block/floppy.c

Next file: linux/drivers/block/linear.c
Previous file: linux/drivers/block/elevator.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.0-test4/linux/drivers/block/floppy.c linux/drivers/block/floppy.c
@@ -2339,6 +2339,13 @@
 {
 	int nr_sectors, ssize, eoc, heads;
 
+	if (R_HEAD >= 2) {
+	    /* some Toshiba floppy controllers occasionnally seem to
+	     * return bogus interrupts after read/write operations, which
+	     * can be recognized by a bad head number (>= 2) */
+	     return;
+	}  
+
 	if (!DRS->first_read_date)
 		DRS->first_read_date = jiffies;
 
@@ -3422,6 +3429,9 @@
 static int fd_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
 		    unsigned long param)
 {
+#define IOCTL_MODE_BIT 8
+#define OPEN_WRITE_BIT 16
+#define IOCTL_ALLOWED (filp && (filp->f_mode & IOCTL_MODE_BIT))
 #define OUT(c,x) case c: outparam = (const char *) (x); break
 #define IN(c,x,tag) case c: *(x) = inparam. tag ; return 0
 
@@ -3489,7 +3499,8 @@
 		return -EINVAL;
 
 	/* permission checks */
-	if ((cmd & 0x80) && !suser())
+	if (((cmd & 0x40) && !IOCTL_ALLOWED) ||
+	    ((cmd & 0x80) && !suser()))
 		return -EPERM;
 
 	/* copyin */
@@ -3609,6 +3620,7 @@
 		return fd_copyout((void *)param, outparam, size);
 	else
 		return 0;
+#undef IOCTL_ALLOWED
 #undef OUT
 #undef IN
 }
@@ -3760,6 +3772,12 @@
 			buffer_track = -1;
 		invalidate_buffers(MKDEV(FLOPPY_MAJOR,old_dev));
 	}
+
+	/* Allow ioctls if we have write-permissions even if read-only open */
+	if ((filp->f_mode & 2) || (permission(inode,2) == 0))
+		filp->f_mode |= IOCTL_MODE_BIT;
+	if (filp->f_mode & 2)
+		filp->f_mode |= OPEN_WRITE_BIT;
 
 	if (UFDCS->rawcmd == 1)
 		UFDCS->rawcmd = 2;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)