Subject: Re: FreeBSD's /dev on NetBSD
To: Hans Petter Selasky <hselasky@c2i.net>
From: Rui Paulo <rpaulo@NetBSD.org>
List: tech-kern
Date: 08/13/2005 16:13:19
--XsQoSWH+UP9D9v3l
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On 2005.08.13 17:08:17 +0000, Hans Petter Selasky wrote:
| > 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.
|=20
| Are you sure that this cloning process is dynamic. To me it looks very mu=
ch=20
| like bpf sets up "n" fixed units:
Not on 3.0+.
| # ls /dev/bpf*
| /dev/bpf0 /dev/bpf1 /dev/bpf2 /dev/bpf3 /dev/bpf4 /dev/bpf5 /dev/bpf6 /de=
v/bpf7
|=20
| 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
proton> ls /dev/bpf* =
[~]
/dev/bpf /dev/bpf0@
proton> ls -l /dev/bpf0 =
[~]
lrwx------ 1 root wheel 3 Jun 18 02:27 /dev/bpf0@ -> bpf
| When I look at the source code I find the following:
|=20
| int
| bpfopen(dev, flag, mode, p)
| dev_t dev;
| int flag;
| int mode;
| struct proc *p;
| {
| struct bpf_d *d;
|=20
| if (minor(dev) >=3D NBPFILTER)
| return (ENXIO);
| /*
| * Each minor can be opened by only one process. If the requested
| * minor is in use, return EBUSY.
| */
| d =3D &bpf_dtab[minor(dev)];
| ^^^^^^ does "specfs" assign minor=20
| when one opens "/dev/bpf" ?
|=20
| if (!D_ISFREE(d))
| return (EBUSY);
int
bpfopen(dev, flag, mode, p)
dev_t dev;
int flag;
int mode;
struct proc *p;
{
struct bpf_d *d;
struct file *fp;
int error, fd;
/* falloc() will use the descriptor for us. */
if ((error =3D falloc(p, &fp, &fd)) !=3D 0)
return error;
d =3D malloc(sizeof(*d), M_DEVBUF, M_WAITOK);
(void)memset(d, 0, sizeof(*d));
d->bd_bufsize =3D bpf_bufsize;
d->bd_seesent =3D 1;
d->bd_pid =3D p->p_pid;
callout_init(&d->bd_callout);
simple_lock(&bpf_slock);
LIST_INSERT_HEAD(&bpf_list, d, bd_list);
simple_unlock(&bpf_slock);
return fdclone(p, fp, fd, flag, &bpf_fileops, d);
^^^^^^^
}
| To me it looks that one has to open /dev/bpfN.
|=20
| # cat /dev/bpf
| cat: /dev/bpf: No such file or directory
proton# cat /dev/bpf =
[~]
cat: /dev/bpf: Invalid argument
| Maybe it has got something to do with the version I am using:
Yes. :)
-- Rui Paulo
--XsQoSWH+UP9D9v3l
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (NetBSD)
iD8DBQFC/g4PZPqyxs9FH4QRAg6FAJ9MaAJK71bGQls6nnUJGRCuGdz3LgCgrbOQ
UlaIm1rrYfbqoheG8yPe0B0=
=gbOQ
-----END PGP SIGNATURE-----
--XsQoSWH+UP9D9v3l--