[PATCH 2/2] swim, swim3: Fix FDEJECT ioctl for exclusive open
From: Finn Thain
Date: Sat Sep 26 2026 - 03:50:06 EST
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@xxxxxxxxxxxxxx>
---
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