> The examples in the documentation don't compile.  I tried one verbatim 
> because I don't understand everything going on and I would like to have 
> taken one of the examples and played with the code a bit from there.

You don't need to understand STREAMS to diagnose this. The skills you 
need are C programming and Solaris DDI. For the latter, see the Writing 
Device Drivers book. Section "21. Compiling, Loading, Packaging, and 
Testing Drivers" of which says this is how you compile a driver:

$ cc -D_KERNEL -c testdriver.c
$ ld -r -o testdriver testdriver.o

Next:

> # cc -o testdriver.o testdriver.c
> "testdriver.c", line 26: syntax error before or at: ddi_attach_cmd_t

Obvisouly this type is undefined, so you need to find a missing header 
file. The bruteforce method:

$ grep ddi_attach_cmd_t /usr/include/sys/*

The smarter method is to read the WDD book and learn about attach(9E), 
the man page for which says you need to include:

      #include <sys/ddi.h>
      #include <sys/sunddi.h>

> "testdriver.c", line 171: undefined symbol: DDI_IDENTIFIED
> "testdriver.c", line 173: undefined symbol: DDI_NOT_IDENTIFIED

According to identify(9E) man page:

      For Solaris 10 and later versions, drivers must  remove  the
      identify(9e)  implementation  to  recompile.  Otherwise, the
      compiler   generates   errors   about   DDI_IDENTIFIED   and
      DDI_NOT_IDENTIFIED.

So we remove xxidentify() and replace it with nulldev in the dev_ops 
structure.

> "testdriver.c", line 205: undefined symbol: devstate_t
 > "testdriver.c", line 205: undefined symbol: sp

Another undefined type, but this time not found in /usr/include: this is 
your driver state, you need to define it yourself. Grepping for 'sp->', 
looks like the only referred member is sp->devi, so add:

typedef struct devstate {
        dev_info_t *devi;
} devstate_t;

> "testdriver.c", line 206: undefined symbol: state
> "testdriver.c", line 206: undefined symbol: statep

Ugh, this is completely broken. This line:

           state *statep;

should actually be moved to global scope:

static void *statep;

and two things missing are:

- a call to ddi_soft_state_init() in _init()
- a call to ddi_soft_state_fini() in _fini()

Check out chapter 6 in WDD for sample code 
http://docs.sun.com/app/docs/doc/816-4854/6mb1o3adq

> "testdriver.c ", line 216: undefined symbol: result

Yep, should be resultp.

> "testdriver.c", line 231: warning: no explicit type given

static
xxopen(rq, devp, flag, sflag, credp)

should be:

static int
xxopen(rq, devp, flag, sflag, credp)

> "testdriver.c", line 257: syntax error before or at: }

Missed semicolon:

                         *devp = makedevice(getmajor(*devp), minordev)

Now the code compiles, though with a few warnings. Might need some more 
polishing to actually work as expected. So yeah, it's a crappy template, 
shame on the doc people who published it. WDD is better written, AFAIK. 
If you are familiar with Linux drivers, also check out Max's article:

http://opensolaris.org/os/article/2005-03-31_inside_opensolaris__solaris_driver_programming/

HTH,
-Artem
_______________________________________________
driver-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/driver-discuss

Reply via email to