O_NONBLOCK for devices with removable media

Bernd Walter ticso at cicely12.cicely.de
Mon Aug 1 17:31:52 GMT 2005


On Mon, Aug 01, 2005 at 04:33:23PM +0300, victor cruceru wrote:
> Hi Marc,
> Thanks for the info. Here it is one my situation. I have a CF reader (fully 
> detected by the USB subsystem) with two slots
> (one with a media and one without any media). An open with O_NONBLOCK on the 
> empty slot (/dev/da1) is blocking me.

It should not block for a long time since the device should directly
reply with either ready or no media.

> Is this OK? 

No, but it is a broken device if you don't get back in a resonable
time.
I don't think that O_NONBLOCK is ment to never block for a short time.
In case of disks you have to ask the device for ready state, if you
don't allow blocking you can't do that and therefor never successfull
open a disk.
The intention should read more in the sense of, don't wait for a disk
to spin up, but even this is problematic to implement correct with many
devices.

> On 8/1/05, Marc Olzheim <marcolz at stack.nl> wrote:
> > 
> > On Mon, Aug 01, 2005 at 02:42:21PM +0300, victor cruceru wrote:
> > > Hi all,
> > > I'm just wondering if it's OK for an open syscall on such a device (i.e.
> > > /dev/acd0 or /dev/da1 with a CF reader attached) to block till the media 
> > is
> > > ready or a timeout occurs.
> > 
> > I'd say that depends completely on whether you supply O_NONBLOCK or not,
> > so yes.
> > 
> > Quoted from a sound driver discussion at:
> > http://sourceforge.net/mailarchive/message.php?msg_id=10011826
> > 
> > 
> > On block devices, O_NONBLOCK also is a way to say "don't try to do any
> > device discovery", ie you can do a O_NONBLOCK open on a removable disk
> > that doesn"t even have any media in it. Again, this has _nothing_ to do
> > with whether the device is "busy" or not.
> > 
> > ...
> > 
> > Short summary:
> > 
> > - O_NONBLOCK should generally be seen as just setting the O_NONBLOCK flag
> > "early" (ie it"s conceptually equivalent to doing a "F_SETFL" fcntl
> > before the open. It _may_ affect the open itself, but when it does, it
> > is generally considered to mean that you can open something that isn't
> > even _reachable_.
> > 
> > - POSIX doesn't say anything much about its behaviour, except for named
> > pipes, where it says the total reverse of what ALSA does. But that
> > doesn't actually mean anything, because even that is very much defined
> > as a special case by POSIX.

-- 
B.Walter                   BWCT                http://www.bwct.de
bernd at bwct.de                                  info at bwct.de



More information about the freebsd-hackers mailing list