Skip to contentSkip to conversation

block/swim: Minor fixes

PATCH Superseded Finn Thain 2 participants 5 messages Sep 26 – Sep 27 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Finn Thain

author
#0 lore raw

cover block/swim: Minor fixes

Two old bugs were reported to me by Stan Johnson while he was testing my recent patch series, "[PATCH v3] block/swim: Fixes and improvements". The following patches fix those bugs.

---

Finn Thain (2):
swim: Return -EROFS when opened with BLK_OPEN_WRITE flag
swim: Fix FDEJECT ioctl for exclusive open

 drivers/block/swim.c  | 5 +++--
 drivers/block/swim3.c | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)
Signature · 1 line
2.52.0
author
#1 lore raw

PATCH 1/2 swim: Return -EROFS when opened with BLK_OPEN_WRITE flag

Write requests are not supported by the driver and produce IO errors as shown below. Avoid this by returning -EROFS when opened for writing.

[ 4111.690000] I/O error, dev fd0, sector 2 op 0x1:(WRITE) flags 0x800800 phys_seg 1 prio class 2
[ 4111.700000] Buffer I/O error on dev fd0, logical block 2, lost async page write
Fixes 8852ecd97488 ("m68k: mac - Add SWIM floppy support")
---
 drivers/block/swim.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/swim.c +2 -1
index 0ccc12a72388..601b1ab1d32c 100644
@@ -640,7 +640,8 @@ static int floppy_open(struct gendisk *disk, blk_mode_t mode)
 	if (mode & (BLK_OPEN_READ | BLK_OPEN_WRITE)) {
 		if (disk_check_media_change(disk) && fs->disk_in)
 			fs->ejected = 0;
-		if ((mode & BLK_OPEN_WRITE) && fs->write_protected) {
+		if (mode & BLK_OPEN_WRITE) {
+			/* Write support isn't implemented. */
 			err = -EROFS;
 			goto out;
 		}
Signature · 1 line
2.52.0
author
#2 lore raw

PATCH 2/2 swim, swim3: Fix FDEJECT ioctl for exclusive open

In reply to Finn Thain

The eject command from the util-linux package does not work with swim3 or swim drivers: the drive doesn't eject anything and the command fails. Apparently, ioctl(fd, FDEJECT) returns -EBUSY when fd is opened O_EXCL. Fix this by checking ref_count for either 1 or -1. Either value means that the caller is the sole user of the disk.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Fixes 8852ecd97488 ("m68k: mac - Add SWIM floppy support")
---
 drivers/block/swim.c  | 2 +-
 drivers/block/swim3.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/block/swim.c +1 -1
index 601b1ab1d32c..1552fee28eaa 100644
@@ -696,7 +696,7 @@ static int floppy_ioctl(struct block_device *bdev, blk_mode_t mode,
 
 	switch (cmd) {
 	case FDEJECT:
-		if (fs->ref_count != 1)
+		if (fs->ref_count != -1 && fs->ref_count != 1)
 			return -EBUSY;
 		mutex_lock(&swim_mutex);
 		err = floppy_eject(fs);
drivers/block/swim3.c +1 -1
index d4f0d43e0a72..aa27dfd2820e 100644
@@ -898,7 +898,7 @@ static int floppy_locked_ioctl(struct block_device *bdev, blk_mode_t mode,
 
 	switch (cmd) {
 	case FDEJECT:
-		if (fs->ref_count != 1)
+		if (fs->ref_count != -1 && fs->ref_count != 1)
 			return -EBUSY;
 		err = fd_eject(fs);
 		return err;
Signature · 1 line
2.52.0
author
#3 lore raw

Re: [PATCH 2/2] swim, swim3: Fix FDEJECT ioctl for exclusive open

Please disregard this patch. When I re-read it, I noticed that the ref_count access should really be protected by the mutex. So I will fix that and re-submit.

Quoted 41 lines · Finn Thain

The eject command from the util-linux package does not work with swim3 or swim drivers: the drive doesn't eject anything and the command fails. Apparently, ioctl(fd, FDEJECT) returns -EBUSY when fd is opened O_EXCL. Fix this by checking ref_count for either 1 or -1. Either value means that the caller is the sole user of the disk.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Fixes 8852ecd97488 ("m68k: mac - Add SWIM floppy support")
---
 drivers/block/swim.c  | 2 +-
 drivers/block/swim3.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/block/swim.c +1 -1
index 601b1ab1d32c..1552fee28eaa 100644
@@ -696,7 +696,7 @@ static int floppy_ioctl(struct block_device *bdev, blk_mode_t mode,
 
 	switch (cmd) {
 	case FDEJECT:
-		if (fs->ref_count != 1)
+		if (fs->ref_count != -1 && fs->ref_count != 1)
 			return -EBUSY;
 		mutex_lock(&swim_mutex);
 		err = floppy_eject(fs);
drivers/block/swim3.c +1 -1
index d4f0d43e0a72..aa27dfd2820e 100644
@@ -898,7 +898,7 @@ static int floppy_locked_ioctl(struct block_device *bdev, blk_mode_t mode,
 
 	switch (cmd) {
 	case FDEJECT:
-		if (fs->ref_count != 1)
+		if (fs->ref_count != -1 && fs->ref_count != 1)
 			return -EBUSY;
 		err = fd_eject(fs);
 		return err;
Tested-by on the v1 series
#4 lore raw
In reply to Finn Thain

This patch series was successfully tested on a Mac IIci and a PowerBook Wallstreet (G3 Series).

Quoted 14 lines · Finn Thain

Two old bugs were reported to me by Stan Johnson while he was testing my recent patch series, "[PATCH v3] block/swim: Fixes and improvements". The following patches fix those bugs.

---

Finn Thain (2):
swim: Return -EROFS when opened with BLK_OPEN_WRITE flag
swim: Fix FDEJECT ioctl for exclusive open

  drivers/block/swim.c  | 5 +++--
  drivers/block/swim3.c | 2 +-
  2 files changed, 4 insertions(+), 3 deletions(-)