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: 8852ecd974 ("m68k: mac - Add SWIM floppy support")
Tested-by: Stan Johnson <userm57@yahoo.com>
Signed-off-by: Finn Thain <fthain@linux-m68k.org>
Link: https://patch.msgid.link/ae3ee8e86833a2739d7857460cbe2addf4146088.1790641175.git.fthain@linux-m68k.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Finn Thain 2026-09-29 10:19:35 +10:00 committed by Jens Axboe
parent d8fe777978
commit c76b93df9a

View File

@ -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;