Subject: Re: kern/5377: sys/system.h inludes lib/libkern/libkern.h for LKM too
To: Jason Thorpe <thorpej@nas.nasa.gov>
From: Stefan Grefen <grefen@hprc.tandem.com>
List: netbsd-bugs
Date: 04/29/1998 23:28:15
In message <199804292103.OAA07610@lestat.nas.nasa.gov>  Jason Thorpe wrote:
> On Wed, 29 Apr 1998 23:01:38 +0200 
>  Stefan Grefen <grefen@hprc.tandem.com> wrote:
> 
>  > BTW. I've a clone-device driver, should I send-pr it (after a little 
>  > clean  up?).
> 
> What exactly is a clone-device driver?

In SYSV devies can change their minor-number during open. 
It has also a clone-device which 'clones' other devices. 
This works with all devices but doesn't make sense for all ...

It is handy for pseudo devices (like bpf,ptys) where a unique device is 
needed but it doesn't matter which one it is. I've just one /dev/bpf and
tcpdump just opens it, gets a unique device, and is happy. 

I needed the the first functionality, but thought it a nice exercise to do
the second one too.

E.g. one:
crw-------  1 root  wheel  34, 23 Apr 29 12:58 /dev/bpf

Instead of:
crw-------  1 root  wheel  23,  0 Apr 28 00:51 /dev/bpf0
crw-------  1 root  wheel  23,  1 Apr 28 00:51 /dev/bpf1
crw-------  1 root  wheel  23,  2 Apr 28 00:51 /dev/bpf2
...
crw-------  1 root  wheel  23,  X Apr 28 00:51 /dev/bpfX



(From the Unixware manpage)

       clone(7)                                                    clone(7)

       NAME
             clone - open any major/minor device pair on a STREAMS driver

       DESCRIPTION
             clone is a STREAMS software driver that finds and opens an
             unused major/minor device on another STREAMS driver.  The
             major device number passed to clone during open corresponds to
             the clone driver and the minor device number corresponds to
             the target driver.  Each open results in a separate stream to
             a previously unused major/minor device.

             The clone driver consists solely of an open function.  This
             open function performs all of the necessary work so that
             subsequent system calls [including close(2)] require no
             further involvement of clone.

             clone will generate an ENXIO error, without opening the
             device, if the major/minor device number provided does not
             correspond to a valid major/minor device, or if the driver
             indicated is not a STREAMS driver.

       NOTICES
             Multiple opens of the same major/minor device cannot be done
             through the clone interface.  Executing stat(2) on the file
             system node for a cloned device yields a different result from
             executing fstat using a file descriptor obtained from opening
             the node.




Stefan

> 
> Jason R. Thorpe                                       thorpej@nas.nasa.gov
> NASA Ames Research Center                            Home: +1 408 866 1912
> NAS: M/S 258-5                                       Work: +1 650 604 0935
> Moffett Field, CA 94035                             Pager: +1 415 428 6939

--
Stefan Grefen                                Tandem Computers Europe Inc.
grefen@hprc.tandem.com                       High Performance Research Center
 --- Hacking's just another word for nothing left to kludge. ---