Subject: Re: FreeBSD's /dev on NetBSD
To: Tonnerre <tonnerre@thundrix.ch>
From: Hans Petter Selasky <hselasky@c2i.net>
List: tech-kern
Date: 08/13/2005 15:18:45
On Saturday 13 August 2005 14:25, Tonnerre wrote:
> Salut,
>
> On Sat, Aug 13, 2005 at 03:45:03AM +0200, Hans Petter Selasky wrote:
> > I'm working on porting a driver from FreeBSD to NetBSD and have found the
> > kernel API for creating devices in /dev/ very difficult to use.
> >
> > I want to be able to clone, create and delete devices. Therefore I want
> > to implement a file system similar to FreeBSD's "devfs".
>
> Doesn't everyone want to get rid of that?
>
> Anyway, you just get a major number, and then you can do with your
> cdevsw/bdevsw whatever you want - just copy/insert/delete/clone devices
> as you like, and have them everywhere.

Yes, but the problem with /dev is that one has to pre-make the devices with 
"mknod" which is not acceptable.

For example want want the following to work:

I create a dummy device like "/dev/capi20 ". Note that there is a space at the 
end of the string.

Then when applications open "/dev/capi20", and the kernel finds out that this 
file does not exist, it should call a routine in my driver, and pass 
"capi20". When my routine recognizes this string, it makes a new device 
"/dev/capi20.000" and returns that to the application. When another 
application opens "/dev/capi20", "/dev/capi20.001" will be returned and so 
on. When the application closes this device, they will be recycled.

What I am thinking about now, is to re-implement FreeBSD's "devfs", 
lite-version, on NetBSD in "/cdev", and then do:

mount_union /cdev /dev

How can I create and mount /cdev from the kernel, and how can I do the union 
mount from the kernel ?



--HPS