Re: [PATCH 2/2] swim, swim3: Fix FDEJECT ioctl for exclusive open

From: Finn Thain

Date: Sun Sep 27 2026 - 01:58:31 EST



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