From c76b93df9ae61d8ddebf6aa3bc218252f85e80c6 Mon Sep 17 00:00:00 2001 From: Finn Thain Date: Tue, 29 Sep 2026 10:19:35 +1000 Subject: [PATCH] swim: Fix FDEJECT ioctl for exclusive open 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 Signed-off-by: Finn Thain Link: https://patch.msgid.link/ae3ee8e86833a2739d7857460cbe2addf4146088.1790641175.git.fthain@linux-m68k.org Signed-off-by: Jens Axboe --- 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;