Minor number for device driver

Minor number for device driver

Post by Yanhong » Sat, 15 May 1993 12:19:53



I wrote a device driver for SUN4, and if I use minor number 0, read
and write of this driver is ok, however, if I specify the minor number
as 1 or 2, it will complain: not owner, no such process, etc. at the
open call. My open procedure in driver simply did nothing.

Anything wrong with that?
Thanks in advance.

--
========================================================================
Yanhong Li                       716-838-6493(h)    645-3198(w)
Dept. of Computer Science                       Good good study
SUNY at Buffalo, Buffalo, NY14260               Up up every day

 
 
 

Minor number for device driver

Post by Chris Tor » Sun, 16 May 1993 10:54:38



writes:

Quote:>I wrote a device driver for SUN4, and if I use minor number 0, read
>and write of this driver is ok, however, if I specify the minor number
>as 1 or 2, it will complain: not owner, no such process, etc. at the
>open call. My open procedure in driver simply did nothing.

You forgot to return an errno from your driver.  Since, on the SPARC,
the return value from a function appears in its %i0 register, and its
first parameter also appears in this same register, a function that
does nothing will wind up returning its first argument:

        int
        ident(x)
                int x;
        {
                /* return x; */
        }

This code is wrong, but `just happens' to work on all SPARCs.

The first argument to an open() function is the device number:

        /* two arguments, in the ancient tradition... */
        int
        xxopen(dev, flag)
                dev_t dev;
                int flag;
        {
        }

If you do absolutely nothing, this code will act as if you wrote
`return (dev)'.  Since your device is probably not major number 0, you
must in fact do something in your open function, such as:

                dev = minor(dev);

so as to discard the major number bits.  Otherwise all opens, not just
those with nonzero minor numbers, would fail.

If you want all opens to succeed, you must return 0 (`no error').
--
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427)


 
 
 

Minor number for device driver

Post by John McDermo » Mon, 17 May 1993 02:03:12




>writes:
>>I wrote a device driver for SUN4, and if I use minor number 0, read
>>and write of this driver is ok, however, if I specify the minor number
>>as 1 or 2, it will complain: not owner, no such process, etc. at the
>>open call. My open procedure in driver simply did nothing.

>You forgot to return an errno from your driver.  Since, on the SPARC,
>the return value from a function appears in its %i0 register, and its
>first parameter also appears in this same register, a function that
>does nothing will wind up returning its first argument:
        [code deleted]
>If you do absolutely nothing, this code will act as if you wrote
>`return (dev)'.  Since your device is probably not major number 0, you
>must in fact do something in your open function, such as:

>            dev = minor(dev);

>so as to discard the major number bits.  Otherwise all opens, not just
>those with nonzero minor numbers, would fail.

>If you want all opens to succeed, you must return 0 (`no error').

  [Sorry to include all this stuff...]
How right you are, Chris.  The confusion lies in the fact that older
versions of UN*X operating systems such as BSD, RTU, etc. required that the
open() and close() functions return NOTHING, e.g. they always ended with
                return;
A quick reading of the SVR4 DDI/DDK shows that Chris is (as usual) correct
and this is one reason why old drivers must be ported to SVR4.

Another issue is credentials (checking for superuser, for example) which
are also implemented differently in SVR4 (and I presume Solaris 2.x).

If you are writing drivers for Solaris 2/SVR4 you really need the DDI/DDK.
--john

--
John McDermott                                  505/897-2064 H/W

[ UNM only lets me use this account because they are nice.  I have no
        relationship with them whatsoever (besides being friends).]