Commit 8a0c014c authored by Jiri Kosina's avatar Jiri Kosina Committed by Denis Efremov
Browse files

floppy: reintroduce O_NDELAY fix

This issue was originally fixed in 09954bad ("floppy: refactor open()
flags handling").

The fix as a side-effect, however, introduce issue for open(O_ACCMODE)
that is being used for ioctl-only open. I wrote a fix for that, but
instead of it being merged, full revert of 09954bad was performed,
re-introducing the O_NDELAY / O_NONBLOCK issue, and it strikes again.

This is a forward-port of the original fix to current codebase; the
original submission had the changelog below:

Commit 09954bad ("floppy: refactor open() flags handling"), as a
side-effect, causes open(/dev/fdX, O_ACCMODE) to fail. It turns out that
this is being used setfdprm userspace for ioctl-only open().

Reintroduce back the original behavior wrt !(FMODE_READ|FMODE_WRITE)
modes, while still keeping the original O_NDELAY bug fixed.


Reported-by: default avatarWim Osterholt <>
Tested-by: default avatarWim Osterholt <>
Reported-and-tested-by: default avatarKurt Garloff <>
Fixes: 09954bad ("floppy: refactor open() flags handling")
Fixes: f2791e7e

 ("Revert "floppy: refactor open() flags handling"")
Signed-off-by: default avatarJiri Kosina <>
Signed-off-by: default avatarDenis Efremov <>
parent 0d738971
...@@ -4121,23 +4121,23 @@ static int floppy_open(struct block_device *bdev, fmode_t mode) ...@@ -4121,23 +4121,23 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
if (fdc_state[FDC(drive)].rawcmd == 1) if (fdc_state[FDC(drive)].rawcmd == 1)
fdc_state[FDC(drive)].rawcmd = 2; fdc_state[FDC(drive)].rawcmd = 2;
if (!(mode & FMODE_NDELAY)) { if (mode & (FMODE_READ|FMODE_WRITE)) {
if (mode & (FMODE_READ|FMODE_WRITE)) { drive_state[drive].last_checked = 0;
drive_state[drive].last_checked = 0; clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags);
clear_bit(FD_OPEN_SHOULD_FAIL_BIT, if (bdev_check_media_change(bdev))
&drive_state[drive].flags); floppy_revalidate(bdev->bd_disk);
if (bdev_check_media_change(bdev)) if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags))
floppy_revalidate(bdev->bd_disk); goto out;
if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags)) if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags))
goto out;
if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags))
goto out;
res = -EROFS;
if ((mode & FMODE_WRITE) &&
!test_bit(FD_DISK_WRITABLE_BIT, &drive_state[drive].flags))
goto out; goto out;
} }
res = -EROFS;
if ((mode & FMODE_WRITE) &&
!test_bit(FD_DISK_WRITABLE_BIT, &drive_state[drive].flags))
goto out;
mutex_unlock(&open_lock); mutex_unlock(&open_lock);
mutex_unlock(&floppy_mutex); mutex_unlock(&floppy_mutex);
return 0; return 0;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment