Subject: Re: FreeBSD's /dev on NetBSD
To: None <tech-kern@netbsd.org>
From: Hans Petter Selasky <hselasky@c2i.net>
List: tech-kern
Date: 08/13/2005 17:08:17
On Saturday 13 August 2005 15:40, Jaromir Dolecek wrote:
> On Sat, Aug 13, 2005 at 03:18:45PM +0200, Hans Petter Selasky wrote:
> > 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.
But actually, isn't "mknod" superfluous. Why can't "specfs" try to create the
device if it is not present when one is trying to open it. Why must all
devices be pre-made.
Also much equipment can be plugged/unplugged, so it is very convenient if the
kernel creates devices in "/dev" on demand.
>
> Cloning devices are supported on NetBSD - e.g. /dev/bpf or /dev/ptmx
> are such cloning devices. The nodes in /dev are not created indeed, but
> actual nodes are rarely needed anyway.
Are you sure that this cloning process is dynamic. To me it looks very much
like bpf sets up "n" fixed units:
# ls /dev/bpf*
/dev/bpf0 /dev/bpf1 /dev/bpf2 /dev/bpf3 /dev/bpf4 /dev/bpf5 /dev/bpf6 /dev/bpf7
crw------- 1 root wheel 23, 0 Aug 12 14:42 /dev/bpf0
crw------- 1 root wheel 23, 1 Aug 12 14:42 /dev/bpf1
crw------- 1 root wheel 23, 2 Aug 12 14:42 /dev/bpf2
crw------- 1 root wheel 23, 3 Aug 12 14:42 /dev/bpf3
crw------- 1 root wheel 23, 4 Aug 12 14:42 /dev/bpf4
crw------- 1 root wheel 23, 5 Aug 12 14:42 /dev/bpf5
crw------- 1 root wheel 23, 6 Aug 12 14:42 /dev/bpf6
crw------- 1 root wheel 23, 7 Aug 12 14:42 /dev/bpf7
When I look at the source code I find the following:
int
bpfopen(dev, flag, mode, p)
dev_t dev;
int flag;
int mode;
struct proc *p;
{
struct bpf_d *d;
if (minor(dev) >= NBPFILTER)
return (ENXIO);
/*
* Each minor can be opened by only one process. If the requested
* minor is in use, return EBUSY.
*/
d = &bpf_dtab[minor(dev)];
^^^^^^ does "specfs" assign minor
when one opens "/dev/bpf" ?
if (!D_ISFREE(d))
return (EBUSY);
To me it looks that one has to open /dev/bpfN.
# cat /dev/bpf
cat: /dev/bpf: No such file or directory
Maybe it has got something to do with the version I am using:
# uname -a
NetBSD 2.0.2 NetBSD 2.0.2 (GENERIC) #0: Wed Mar 23 08:53:42 UTC 2005
jmc@faith.netbsd.org:/home/builds/ab/netbsd-2-0-2-RELEASE/i386/200503220140Z-obj/home/builds/ab/netbsd-2-0-2-RELEASE/src/sys/arch/i386/compile/GENERIC
i386
--HPS