[PATCH v2 3/3] swim3: Fix FDEJECT ioctl for exclusive open
From: Finn Thain
Date: Mon Sep 28 2026 - 20:32:13 EST
The eject command from the util-linux package does not work with the
swim3 driver: the drive doesn't eject anything and the command fails.
Apparently, ioctl(fd, FDEJECT) returns -EBUSY after fd was 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")
Tested-by: Stan Johnson <userm57@xxxxxxxxx>
Signed-off-by: Finn Thain <fthain@xxxxxxxxxxxxxx>
---
Changed since v1:
- Simplify by removing 'err' temporary variable.
---
drivers/block/swim3.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index 01f7aef3fcfb..b55cfe485beb 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -887,7 +887,6 @@ static int floppy_locked_ioctl(struct block_device *bdev, blk_mode_t mode,
unsigned int cmd, unsigned long param)
{
struct floppy_state *fs = bdev->bd_disk->private_data;
- int err;
if ((cmd & 0x80) && !capable(CAP_SYS_ADMIN))
return -EPERM;
@@ -898,10 +897,9 @@ static int floppy_locked_ioctl(struct block_device *bdev, blk_mode_t mode,
switch (cmd) {
case FDEJECT:
- if (fs->ref_count != 1)
- return -EBUSY;
- err = fd_eject(fs);
- return err;
+ if (fs->ref_count == -1 || fs->ref_count == 1)
+ return fd_eject(fs);
+ return -EBUSY;
case FDGETPRM:
if (copy_to_user((void __user *) param, &floppy_type,
sizeof(struct floppy_struct)))