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

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

 



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

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

What do you think?

 Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com




[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