[PATCH v2 2/3] swim: Fix FDEJECT ioctl for exclusive open
From: Finn Thain
Date: Mon Sep 28 2026 - 20:31:39 EST
The eject command from the util-linux package does not work with the swim
driver: 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: 8852ecd97488 ("m68k: mac - Add SWIM floppy support")
Tested-by: Stan Johnson <userm57@xxxxxxxxx>
Signed-off-by: Finn Thain <fthain@xxxxxxxxxxxxxx>
---
Changed since v1:
- Access ref_count after mutex has been acquired.
---
drivers/block/swim.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 49c894af7c13..baeb05f3e003 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -700,10 +700,11 @@ static int floppy_ioctl(struct block_device *bdev, blk_mode_t mode,
switch (cmd) {
case FDEJECT:
- if (fs->ref_count != 1)
- return -EBUSY;
mutex_lock(&swim_mutex);
- err = floppy_eject(fs);
+ if (fs->ref_count == -1 || fs->ref_count == 1)
+ err = floppy_eject(fs);
+ else
+ err = -EBUSY;
mutex_unlock(&swim_mutex);
return err;