Subject: Re: Pseudo device
To: Ljubisa Milenkovic <ljubisa.milenkovic@reddo.net>
From: Bill Studenmund <wrstuden@netbsd.org>
List: tech-kern
Date: 12/19/2001 10:00:35
On Wed, 19 Dec 2001, Ljubisa Milenkovic wrote:

> I have several user-land processes that communicate with different kernel
> modules. To simplify this communication I would like to have a common
> communication dispatcher in kernel.
> I have defined a character pseudo-device that supports open, close, read,
> write, ioctl and poll.
> My problem is how to identify different user-land processes in my read in
> write functions to dispatch data to corresponding kernel module and
> vice-versa, how to know to which user-land process to send data when a
> kernel module has issued a send request.
>
> In user-land I have the file descriptor, but in kernel read (or write)
> function I have uio struct. Where is the mapping made? I would also like to
> have asynchronous call to read and write. Is that possible with my
> definition of the device?

In the kernel, you have a file descriptor too, it's just not used anymore
by the time your code is entered.

Since you have made a device, you have its minor number space at your
disposal. You could use that. Make your open routine remember if a given
minor number is in use. If it is, don't let a new open succeed. Then you
can use minor numbers to map to userland requestors. I assume you use an
ioctl for userland to say what it is interested in. You can have the same
code remember which minor device has requested kernel service foo, so when
foo has something to say, you know which minor number to wake up & send
to.

Take care,

Bill