Subject: Re: Time to fix a 25 year old misdesign
To: Lennart Augustsson <>
From: Manuel Bouyer <>
List: tech-kern
Date: 10/15/2000 15:22:42
On Sun, Oct 15, 2000 at 12:12:28PM +0200, Lennart Augustsson wrote:
> The old UNIX device driver interface is fundamentally broken.  The
> problem is the following
>    The driver routine open() is called every time the device
>    is opened, but close() is only called on the last close.

Sure this is bad.

> [...]
> I can see no way of solving this with the current device driver
> structure.  The only way out would be to have separate devices nodes
> for reading and writing, but that is not what people nor programs
> expect.
> Is this problem an isolated thing?  No, the exact same problem exists
> for other devices too.
> Example: the ugen device and its endpoint devices.
> Example: the wskbd/wsmouse/wsmux devices where you'd like to be able
> to open a device for reading, and also open it for ioctl().
> How should it be fixed?  Well, the only% way I can see is to change
> when the close() routine is called for character device drivers.
> Doing that would be a huge amount of work, so instead I suggest that
> we add a routine to the struct cdevsw.  This routine will have the
> same type as the close() routine, but will be called on every close().
> If left out, it will not be called.  This way all old drivers can
> remain intact, and only those that require the new functionality need
> to know about it.

Ok, so two close routines in cdevsw, but only one is used for each driver
(a driver can use the old or new behavior, but not both). This way we
could eventually convert all drivers to the new behavior and garbage-collect
the old close entry when done.

However for most drivers we only care about the last close, so converting all
driver would add complexity to most of them. Maybe we need some generic
ref-counting for this ?

Manuel Bouyer <>