device driver: cdesw questions?

Andriy Gapon avg at icyb.net.ua
Wed Jan 21 06:12:30 PST 2009


on 21/01/2009 16:05 Robert Watson said the following:
> 
> On Wed, 21 Jan 2009, Andriy Gapon wrote:
> 
>> Question 1: I am writing a driver that would use per-open private data
>> (among other features). Do I have to use D_TRACKCLOSE flag in this
>> case? In general I am a little bit confused about when d_close is
>> invoked. Supposing D_TRACKCLOSE is not set and multiple programs
>> concurrently open, use and close a device - when d_close is called -
>> when one program closes its last descriptor tied to the device or when
>> the system-wide last such descriptor is closed?
> 
> Kostik has already pointed at the cdevpriv API, but just to reiterate
> his point: most people will find the semantics of D_TRACKCLOSE confusing
> and consider them incorrect, so I would advise against using them.

Robert, Kostik,

in simplistic layman's terms I need the following - when a particular
program "closes my cdev" (explicitly or via exit) I need to catch that
and de-allocate certain resources. There can be multiple concurrent
programs opening, using and closing my cdev.

I guess what you both say is that I shouldn't use D_TRACKCLOSE, instead
I should perform the resource management in cdevpriv destructor.
Am I guessing correctly this time?

-- 
Andriy Gapon


More information about the freebsd-hackers mailing list