mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] block/swim: Minor fixes
@ 2026-09-26  7:39 Finn Thain
  2026-09-26  7:39 ` [PATCH 2/2] swim, swim3: Fix FDEJECT ioctl for exclusive open Finn Thain
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Finn Thain @ 2026-09-26  7:39 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Laurent Vivier, Stan Johnson, Geert Uytterhoeven,
	Joshua Thompson, linux-block, linux-m68k, linux-kernel

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(-)

-- 
2.52.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] swim: Return -EROFS when opened with BLK_OPEN_WRITE flag
  2026-09-26  7:39 [PATCH 0/2] block/swim: Minor fixes Finn Thain
  2026-09-26  7:39 ` [PATCH 2/2] swim, swim3: Fix FDEJECT ioctl for exclusive open Finn Thain
@ 2026-09-26  7:39 ` Finn Thain
  2026-09-27 18:27 ` [PATCH 0/2] block/swim: Minor fixes Stanley J. Johnson
  2 siblings, 0 replies; 5+ messages in thread
From: Finn Thain @ 2026-09-26  7:39 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Laurent Vivier, Stan Johnson, Geert Uytterhoeven,
	Joshua Thompson, linux-block, linux-m68k, linux-kernel

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")
Signed-off-by: Finn Thain <fthain@linux-m68k.org>
---
 drivers/block/swim.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 0ccc12a72388..601b1ab1d32c 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -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;
 		}
-- 
2.52.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] swim, swim3: Fix FDEJECT ioctl for exclusive open
  2026-09-26  7:39 [PATCH 0/2] block/swim: Minor fixes Finn Thain
@ 2026-09-26  7:39 ` Finn Thain
  2026-09-27  5:58   ` Finn Thain
  2026-09-26  7:39 ` [PATCH 1/2] swim: Return -EROFS when opened with BLK_OPEN_WRITE flag Finn Thain
  2026-09-27 18:27 ` [PATCH 0/2] block/swim: Minor fixes Stanley J. Johnson
  2 siblings, 1 reply; 5+ messages in thread
From: Finn Thain @ 2026-09-26  7:39 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Laurent Vivier, Stan Johnson, Geert Uytterhoeven,
	Joshua Thompson, linux-block, linux-m68k, linux-kernel

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")
Signed-off-by: Finn Thain <fthain@linux-m68k.org>
---
 drivers/block/swim.c  | 2 +-
 drivers/block/swim3.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 601b1ab1d32c..1552fee28eaa 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -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);
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index d4f0d43e0a72..aa27dfd2820e 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -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;
-- 
2.52.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] swim, swim3: Fix FDEJECT ioctl for exclusive open
  2026-09-26  7:39 ` [PATCH 2/2] swim, swim3: Fix FDEJECT ioctl for exclusive open Finn Thain
@ 2026-09-27  5:58   ` Finn Thain
  0 siblings, 0 replies; 5+ messages in thread
From: Finn Thain @ 2026-09-27  5:58 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Laurent Vivier, Stan Johnson, Geert Uytterhoeven,
	Joshua Thompson, linux-block, linux-m68k, linux-kernel


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.

On Sat, 26 Sep 2026, Finn Thain wrote:

> 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")
> Signed-off-by: Finn Thain <fthain@linux-m68k.org>
> ---
>  drivers/block/swim.c  | 2 +-
>  drivers/block/swim3.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/block/swim.c b/drivers/block/swim.c
> index 601b1ab1d32c..1552fee28eaa 100644
> --- a/drivers/block/swim.c
> +++ b/drivers/block/swim.c
> @@ -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);
> diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
> index d4f0d43e0a72..aa27dfd2820e 100644
> --- a/drivers/block/swim3.c
> +++ b/drivers/block/swim3.c
> @@ -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;
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] block/swim: Minor fixes
  2026-09-26  7:39 [PATCH 0/2] block/swim: Minor fixes Finn Thain
  2026-09-26  7:39 ` [PATCH 2/2] swim, swim3: Fix FDEJECT ioctl for exclusive open Finn Thain
  2026-09-26  7:39 ` [PATCH 1/2] swim: Return -EROFS when opened with BLK_OPEN_WRITE flag Finn Thain
@ 2026-09-27 18:27 ` Stanley J. Johnson
  2 siblings, 0 replies; 5+ messages in thread
From: Stanley J. Johnson @ 2026-09-27 18:27 UTC (permalink / raw)
  To: Finn Thain, Jens Axboe
  Cc: Laurent Vivier, Geert Uytterhoeven, Joshua Thompson, linux-block,
	linux-m68k, linux-kernel

Tested-by: Stan Johnson <userm57@yahoo.com>

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

On 9/26/26 1:39 AM, Finn Thain wrote:
> 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(-)
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-27 18:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-26  7:39 [PATCH 0/2] block/swim: Minor fixes Finn Thain
2026-09-26  7:39 ` [PATCH 2/2] swim, swim3: Fix FDEJECT ioctl for exclusive open Finn Thain
2026-09-27  5:58   ` Finn Thain
2026-09-26  7:39 ` [PATCH 1/2] swim: Return -EROFS when opened with BLK_OPEN_WRITE flag Finn Thain
2026-09-27 18:27 ` [PATCH 0/2] block/swim: Minor fixes Stanley J. Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®