Re: Review/Test: Pseudo-device unit number management patch

From: Poul-Henning Kamp <phk_at_phk.freebsd.dk>
Date: Mon, 09 Feb 2004 16:54:09 +0100
In message <20040209150039.GS2803_at_pcwin002.win.tue.nl>, Stijn Hoop writes:
>
>--qo7zVO9a9OQ5oQtr
>Content-Type: text/plain; charset=us-ascii
>Content-Disposition: inline
>Content-Transfer-Encoding: quoted-printable
>
>On Mon, Feb 09, 2004 at 03:32:16PM +0100, Poul-Henning Kamp wrote:
>> Please also remember:  /dev is _not_ an inventory of available devices.
>
>Just curious: what is it then? An inventory of available drivers? An
>inventory of open devices?

	"A naming-space gateway from filenames to device drivers
	whose exact mapping is only stable in the timeinterval
	between a successful open(2) and the corresponding close
	(be it an explict close or not)." [2]

Fortunately it is a good deal more deterministic than what my feeble
attempt at a definition above could make it sound :-)

The practical effects are hard to explain, but one example is that
the stat/open race is much more fundamental in /dev than anywhere
else in the filesystem.

In the normal filesystem, a few odd things may happen between calls
to stat(2) and open(2), in /proc you may get a different process
than you intended, but in /dev _any_ odd thing may happen.

You thought you opened a serial port called /dev/foo connected to
your printer ?  Well, I got news for you:  it disappeared!  Ohh and
by the way: a new device appeared calling itself /dev/foo, looks
like some sort of ICMB launch thingie or something...

Furthermore, if you open(2) a normal filesystem node, you hold a
reference on it, so that even if people remove the file, you can
still work on it until you are finished.

If for instance you open a file and write a megabyte from the
beginning, and call fsync on it and all your return codes were good,
you can be assured that no reads nor writes inside that one megabyte
will fail subsequently (provided the hardware doesn't croak) [1].

In /dev, if somebody removes your hardware, it's gone and there's
not a damn thing you can do about it, and no stake or state you can
claim to have reservation on.

/dev is strange I tell ya!  :-)

Poul-Henning

[1] It's still a good idea to check, hardware _does_ croak.

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk_at_FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.
Received on Mon Feb 09 2004 - 06:54:31 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:42 UTC