Re: [PATCH 2/2] libblkid: reopen floppy without O_NONBLOCK

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



14.12.2021 15:03, Karel Zak wrote:

  Hi Vladimir,

On Thu, Dec 09, 2021 at 03:12:33PM +0100, Vladimir Sementsov-Ogievskiy wrote:
Note, that this commit is done as a "minimal change", i.e. I only try to
rollback O_NONBLOCK for floppy. The other way is to detect CDROM
instead, and reopen with original flags for everything except CDROM.

I also tried fcntl instead of close/open, and that didn't help.

What does it mean didn't help?

I tried it, but the bug remains as it was.. As I understand, dropping O_NONBLOCK by fcntl just removes this flag, to change further behavior of device to non-blocking. But it doesn't do any additional actions in driver.

In floppy.c the only place where FMODE_NDELAY take place is floppy_open(). So, we want to change the behavior exactly of thet open() call. As I understand fcntl() doesn't trigger floppy_open() call, that's why it can't help.


I guess that drop O_NONBLOCk in blkid_probe_set_device() for floppies
would be enough, something like:

int blkid_probe_set_device(blkid_probe pr, int fd,
                 blkid_loff_t off, blkid_loff_t size)
{
    ...

     if (ioctl(fd, FDGETDRVTYP, &name) >= 0) {
         int flags;

         if ((flags = fcntl(fd, F_GETFL, 0)) != -1)
             fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
     }
    ...
}

Yes, it's a little bit dirty to modify FD in the library (if the FD is
provided by the application), but if O_NONBLOCK is wrong in all cases for
floppies, then it seems like a good thing.

This solution will fix the problem without libblkid API change, and it
will fix it in all current applications.

The solution based on blkid_safe_open() means that we have to modify
many applications. For example, systemd/udevd uses
     fd = open(devnode, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
     r = blkid_probe_set_device(pr, fd, offset, 0);

Hmm, yes, that's not very good :(


The same is probably in many other places (mkfs-like programs, etc.).

What do you think?


Maybe be we can get filename from fd reading it from /proc, then do open() and than dup() to old fd.. But that's even more dirty to do in a library call.



--
Best regards,
Vladimir



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux