From owner-freebsd-current Tue Oct 15 13:26:25 1996 Return-Path: owner-current Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id NAA05997 for current-outgoing; Tue, 15 Oct 1996 13:26:25 -0700 (PDT) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id NAA05990 for ; Tue, 15 Oct 1996 13:26:19 -0700 (PDT) Received: (from bde@localhost) by godzilla.zeta.org.au (8.7.6/8.6.9) id GAA21446; Wed, 16 Oct 1996 06:22:23 +1000 Date: Wed, 16 Oct 1996 06:22:23 +1000 From: Bruce Evans Message-Id: <199610152022.GAA21446@godzilla.zeta.org.au> To: current@freebsd.org, phk@critter.tfs.com Subject: Re: device driver open/close inconsistency Sender: owner-current@freebsd.org X-Loop: FreeBSD.org Precedence: bulk >Why do we call a device-driver->open() on all opens, but only ->close() >once on the last close ? Because it's easier to count references in vfs than in hundreds of drivers. The device close function would also need to be called on all dup()s and implicit dup()s for fork()s to give it a chance of counting references. There is also an extra reference for controlling terminals. There are also complications for /dev/tty. Unfortunately, it's hard to count references properly in vfs too: Bug 1: the reference count is incremented before calling the device open function, so processes sleeping in open are effectively counted as successful opens. Suppose there is a process sleeping in open and another process opens the device, does some ioctls to mess up the device state, and closes the device. Then it is necessary to call the device close function to clean up and kick the process sleeping in open, but the device close function is never called because the reference count is always >= 1. I believe this is (mis)handled in some versions of **ix by not allowing processes to sleep in open when another open of the same device to complete. This causes other problems. O_NONBLOCK is per-open, so I think it is wrong to let a !O_NOBLOCK open succeed in the presences of the blocking condition just because another process has done a successful open using O_NOBLOCK. Bug 2: It is difficult to get rid of controlling terminals. In 4.4Lite, exiting was the only way. Thus device close functions for controlliing terminals were never called until exit. In 4.4Lite2 and most versions of FreeBSD-2.x, the controlling terminal can be changed using TIOCSCTTY. Bruce