Re: LDD3: opening a character device and counting the opens

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 25 May 2007, pradeep singh wrote:

> On 5/24/07, Robert P. J. Day <rpjday@xxxxxxxxxxxxxx> wrote:
> >
> >   question about the character device example used in the LDD3 book,
> > p. 59, which talks about the "release" method.  in suggesting that the
> > release method shut down the device on last close, this suggests that
> > the code is counting the number of open instances of the device.
> >
> >   what's the best way to do that?  the open() routine would obviously
> > increment a counter, while release() would decrement it.  but where
> > would you keep that counter?  and you'd obviously need one per inode
> > (not one per filp).
> >
> >   what's the cleanest way to do that?  thanks.

> I guess kref is something you should use here. Isn't it? or am i
> missing something here?

that might work, but as i'm following the flow of content in LDD3, the
kref stuff isn't covered until much later in the book.  it quickly
occurred to me that you could just add a counter to the scull_dev
struct to count the current number of open instances (perhaps even an
atomic variable to make sure you didn't have any concurrency
problems, although that might be overkill).

rday

-- 
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://fsdev.net/wiki/index.php?title=Main_Page
========================================================================

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux