patch for 2.1.56 floppy oops

Bill Hawes (whawes@star.net)
Sun, 21 Sep 1997 10:08:19 -0400


This is a multi-part message in MIME format.
--------------D5F000AF590687ABA9113B79
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

The attached patch should fix the floppy oops you reported. The problem
was that the floppy_release operation can be called with a NULL file
pointer in some cases, so it's not possible to pass filp->f_dentry to
block_fsync. But in both of these cases the device has either been
synced already or doesn't need syncing, so a test to avoid calling
block_fsync should suffice.

BTW, at some point we should reexamine what arguments are really needed
by these low-level calls. The case in point, block_fsync, should only
need a device number to call fsync_dev.

Regards,
Bill
--------------D5F000AF590687ABA9113B79
Content-Type: text/plain; charset=us-ascii; name="floppy_56-patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="floppy_56-patch"

--- linux-2.1.56/drivers/block/floppy.c.old Sat Sep 20 08:16:10 1997
+++ linux-2.1.56/drivers/block/floppy.c Sun Sep 21 09:44:03 1997
@@ -3500,9 +3500,13 @@

drive = DRIVE(inode->i_rdev);

- if (!filp || (filp->f_mode & (2 | OPEN_WRITE_BIT)))
- /* if the file is mounted OR (writable now AND writable at
- * open time) Linus: Does this cover all cases? */
+ /*
+ * If filp is NULL, we're being called from blkdev_release
+ * or after a failed mount attempt. In the former case the
+ * device has already been sync'ed, and in the latter no
+ * sync is required. Otherwise, sync if filp is writable.
+ */
+ if (filp && (filp->f_mode & (2 | OPEN_WRITE_BIT)))
block_fsync(filp, filp->f_dentry);

if (UDRS->fd_ref < 0)
--- linux-2.1.56/drivers/block/ataflop.c.old Sat Sep 20 08:16:10 1997
+++ linux-2.1.56/drivers/block/ataflop.c Sun Sep 21 09:41:11 1997
@@ -1978,10 +1978,14 @@

drive = inode->i_rdev & 3;

- if (!filp || (filp->f_mode & (2 | OPEN_WRITE_BIT)))
- /* if the file is mounted OR (writable now AND writable at open
- time) Linus: Does this cover all cases? */
- block_fsync (filp, filp->f_dentry);
+ /*
+ * If filp is NULL, we're being called from blkdev_release
+ * or after a failed mount attempt. In the former case the
+ * device has already been sync'ed, and in the latter no
+ * sync is required. Otherwise, sync if filp is writable.
+ */
+ if (filp && (filp->f_mode & (2 | OPEN_WRITE_BIT)))
+ block_fsync (filp, filp->f_dentry);

if (fd_ref[drive] < 0)
fd_ref[drive] = 0;
--- linux-2.1.56/drivers/block/swim3.c.old Sat Sep 20 08:16:11 1997
+++ linux-2.1.56/drivers/block/swim3.c Sun Sep 21 09:47:28 1997
@@ -840,9 +840,16 @@

if (MINOR(inode->i_rdev) != 0)
return -ENXIO;
+ /*
+ * If filp is NULL, we're being called from blkdev_release
+ * or after a failed mount attempt. In the former case the
+ * device has already been sync'ed, and in the latter no
+ * sync is required. Otherwise, sync if filp is writable.
+ */
+ if (filp && (filp->f_mode & (2 | OPEN_WRITE_BIT)))
+ block_fsync (filp, filp->f_dentry);
+
fs = &floppy_states[0];
- if (filp == 0 || (filp->f_mode & (2 | OPEN_WRITE_BIT)))
- block_fsync(filp, filp->f_dentry);
sw = fs->swim3;
if (fs->ref_count > 0 && --fs->ref_count == 0) {
swim3_action(fs, MOTOR_OFF);

--------------D5F000AF590687ABA9113B79--