Subject: Re: Time to fix a 25 year old misdesign
To: Chris Torek <torek@BSDI.COM>
From: Robert Elz <kre@munnari.OZ.AU>
List: tech-kern
Date: 10/23/2000 00:03:44
    Date:        Sun, 22 Oct 2000 05:37:14 -0600 (MDT)
    From:        Chris Torek <torek@BSDI.COM>
    Message-ID:  <200010221137.FAA26091@forge.BSDI.COM>

  | If you had a new entry point such as "changeref" you could call
  | it with +1 on open-or-dup and -1 on close, perhaps.

Another solution would be to add an extra level of indirection (data
struct) so that there's something that exists exactly once per open,
and upon which dup() fork() (etc) increase a ref count - close decreasing
the ref count, and the driver close routine being called when the
ref count reaches 0.

Of course, this is essentially what the file[] table is now (or was, if
it hasn't been mangled).   dup() adds a ref to the same struct file,
open() creates a new one.

I vaguelly recall someone in Sydney adapting 6th edition to cause
the close routine to be run on each close (ie: when the last reference to
a struct file obtained by open) using that.   Whether anything has changed
in the kernel to alter the relationship that used to exist between open()
close() and struct file I'm not sure.