Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Apr 1996 11:23:54 -0400 (EDT)
From:      Dave Chapeskie <dchapes@zeus.leitch.com>
To:        hackers@freebsd.org
Subject:   Device Driver ioctl() help
Message-ID:  <199604231523.LAA03601@ale.zeus.leitch.com>
In-Reply-To: <199604230256.EAA20717@uriah.heep.sax.de>

next in thread | previous in thread | raw e-mail | index | archive | help
In message <199604230256.EAA20717@uriah.heep.sax.de>
joerg_wunsch@uriah.heep.sax.de writes:
>As Dave Chapeskie wrote:
>
>> >#define JOY_SETTIMEOUT    _IOW('J', 1, int)    /* set timeout */
>> [...]
>> >	Ok, it looks like the 'J' has something to do with a "group",
>> >but what kind of group?  How is this value chosen and what does it do?
>> 
>>     Get a good book on writing device drivers.  Typically you just use
>> group 0 unless you know what you're doing. _IO is used when no data is
>
>Hmm, i think the idea behind the `group' (and partially the `cmd')
>value is to be semi-random, in order to reduce the probability of an
>accidental ioctl name space clash with the ioctl of a foreign driver.
>(Since BSD also encodes the lenth and IO direction of the third
>parameter into the actual CMD, name space collisions are seldom
>compared to V7 UNIX anyway.)  The convention was to pick a letter that
>is roughly related to your driver as `group'.  That's why the joystick
>driver is using `J'.

    Certainly there is nothing obviously wrong with choosing any value
    you like for the group.  However one should never rely on this to
produce a unique value for the ioctl request.  You must still manually
make sure you do not use any JOY_* requests on anything other than a file
descriptor of the joystick device.  Therefore using an arbitrary value in
an attempt to generate a unique value, while not wrong, is not very
useful.

    My understanding of the use of the group argument is if you have
different types of ioctls in a single driver that you want to handle
differently.  For example I have a driver that has three different groups
of ioctls and it does some generic processing based on the group before
it looks at what specific request it is.

    Another use, and perhaps the only "correct" one, is if you have a
group of ioctls that may be used by multiple drivers.  For example group
't' is defined for TIOC* ioctls on tty devices.  It may be that you
want/need to support some of these in your device driver and you don't
want to worry about possible conflicts in the ioctl request number
between the TIOC* requests and your own requests.


>I think this is already covered well in the old ``Daemon book'' (The
>4.3BSD Operating System.  Design and Implementation.)  Don't use a

    I admit I've never read anything definitive on the use of ioctl group
numbers, I'm just presenting my own opinions on the matter.

>From "DEC OSF/1 Writing Device Drivers: Reference" (my closest BSDish
reference book, regrettably I can't find any of my BSD books at the
moment):

    "Specifies the group that this ioctl type belongs to.  This argument
    must be a nonnegative 8-bit number (that is, in the range 0-255
    inclusive).  You can pass the value zero (0) to this argument if a
    new ioctl group is not being defined."

    "Specifies the specific ioctl type within the group.  These should be
    sequentially assigned numbers for each different ioctl operation the
    driver supports.  This argument must be a nonnegative 8-bit number
    (that is, in the range 0-255 inclusive)."

-- 
Dave Chapeskie
Leitch Technology International Inc.
Email: dchapes@zeus.leitch.com



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