Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 May 2000 07:49:28 -0700
From:      Peter Wemm <peter@netplex.com.au>
To:        Mark Murray <mark@grondar.za>
Cc:        Doug Rabson <dfr@nlsystems.com>, current@FreeBSD.ORG
Subject:   Re: Major device numbers and mem device redesign 
Message-ID:  <20000521144928.B30681CE1@overcee.netplex.com.au>
In-Reply-To: Message from Mark Murray <mark@grondar.za>  of "Sun, 21 May 2000 16:41:48 %2B0200." <200005211441.QAA16615@grimreaper.grondar.za> 

next in thread | previous in thread | raw e-mail | index | archive | help
Mark Murray wrote:
> > > > I want to commit a new /dev/random RSN, so I'll be needing a major
> > > > device; what is the procedure for getting one? I know how to steal one,
> > > > but ISTR that this is not how it is done.
> > > 
> > > Just edit sys/conf/majors and claim the next available number.
> > 
> > You don't need one. You can use the same major/minor numbers.  You can
> > register multiple cdevsw's per major number with make_dev();  (do NOT
> > use cdevsw_add() for this).
> 
> How does this work for all the routines? When you register the
> "new" minor number, can you be specifying new read/write/poll/ioctl/etc
> routines?

Yes.  Each instance of make_dev() takes a cdevsw argument for the minor number
in question.  So, you could have /dev/mem read/write/ioctl etc routines
for major 2, minor 0 and 1, while have minors 3 and 4 being installed with
their own open/close/read/write/etc routines.

Devices are looked up as a hash of major+minor, and the devsw entries from
that point on.

Presently:
        make_dev(&mem_cdevsw, 0, UID_ROOT, GID_KMEM, 0640, "mem");
        make_dev(&mem_cdevsw, 1, UID_ROOT, GID_KMEM, 0640, "kmem");
        make_dev(&mem_cdevsw, 2, UID_ROOT, GID_WHEEL, 0666, "null");
        make_dev(&mem_cdevsw, 3, UID_ROOT, GID_WHEEL, 0644, "random");
        make_dev(&mem_cdevsw, 4, UID_ROOT, GID_WHEEL, 0644, "urandom");
        make_dev(&mem_cdevsw, 12, UID_ROOT, GID_WHEEL, 0666, "zero");
        make_dev(&mem_cdevsw, 14, UID_ROOT, GID_WHEEL, 0600, "io");
There is no reason at all to stop each of those minor devices having
their own cdevsw and handler functions.

> I ask, as my RNG is a kld, and I want it to be as separate as possible
> without getting ridiculous.

Yes.  You could just cut/paste the existing mem.c driver, and remove
everything but the random hooks.  In your init code register minors 3 and
4, and that's all you have to worry about.

Cheers,
-Peter




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000521144928.B30681CE1>