Subject: Re: Getting file descriptor in driver ioctl method
To: Emmanuel Dreyfus <manu@netbsd.org>
From: Aaro J Koskinen <akoskine@cc.helsinki.fi>
List: tech-kern
Date: 05/07/2002 14:00:47
Hello,

On Mon, 6 May 2002, Emmanuel Dreyfus wrote:
> This is a good idea, but I really need the file descriptor (or the
> struct file), since the behavior of /dev/usemaclone really depends on
> it. Here is what can happen on IRIX:
> - open /dev/usemaclone, get fd = 5
> - open /dev/usemaclone, get fd = 6
> - register semaphore S1 with an ioctl on fd = 5
> - register semaphore S2 with an ioctl on fd = 6
> - fork 2 additionnal threads
> - thread 1 does a select on fd = 5
> - thread 2 does a select on fd = 6
> - thread 3 makes semaphore S1 available
> Here thread 1 is awaken, thread 2 keep sleeping on select

I understand this but you still don't need to care about descriptors. :-)

> If you work with vnodes, fd = 5 and fd = 6 have different struct file,
> but f_data points to the same vnode, making impossible to attach a
> semaphore to a struct vnode.

Not necessarily. They may appear to point to the same vnode, but that
depends on how the file system is implemented (and what has happened
between the openings, etc). In UNIX, the connection between the file
name and the file itself is pretty thin...

> Is there a possibility to duplicate the struct vnode on open if I use a
> file on kernfs?

You can implemented the file so that each opening of the file name
opens a different "file" i.e. you can distinguish different openings
from each other and store instance specific data to the vnode (think a
normal file system, where an open file is removed from the name space,
and then a new file is created with the same name, and that file is
opened - they will not have the same vnode).

A.

-- 
Aaro Koskinen
E-mail: aaro@iki.fi            "I'm the ocean, I'm the giant undertow."
http://www.iki.fi/aaro