Project

General

Profile

Bug #5907 ยป module.c

Marcel Telka, 2015-05-15 05:42 PM

 
1
#include <sys/modctl.h>
2
#include <sys/stream.h>
3
#include <sys/types.h>
4
#include <sys/ddi.h>
5
#include <rpc/xdr.h>
6

    
7
#include <sys/cmn_err.h>
8
#include <sys/sunddi.h>
9

    
10
static struct modlmisc modlmisc = {
11
	&mod_miscops, "TEST MODULE"
12
};
13

    
14
static struct modlinkage modlinkage = {
15
	MODREV_1,
16
	{(void *)&modlmisc, NULL}
17
};
18

    
19
int
20
_init(void)
21
{
22
	mblk_t *mp;
23
	XDR xdrs;
24
	uint_t pos;
25
	bool_t val;
26
	int i;
27

    
28
	i = mod_install(&modlinkage);
29
	if (i != 0)
30
		return i;
31

    
32
	mp = allocb(8, BPRI_LO);
33
	if (mp == NULL)
34
		return 1;
35

    
36
	bzero(mp->b_wptr, 8);
37
	mp->b_wptr += 8;
38

    
39
	mp->b_cont = allocb(8, BPRI_LO);
40
	if (mp->b_cont == NULL)
41
		return 1;
42

    
43
	bzero(mp->b_cont->b_wptr, 8);
44
	mp->b_cont->b_wptr += 8;
45

    
46
	xdrmblk_init(&xdrs, mp, XDR_DECODE, 128);
47

    
48
	for (i = 0; ; i++) {
49
		pos = xdr_getpos(&xdrs);
50
		cmn_err(CE_NOTE, "!Position #%d: %d", i, pos);
51

    
52
		if (xdr_bool(&xdrs, &val) == FALSE)
53
			break;
54

    
55
		delay(2 * drv_usectohz(1000000));
56
	}
57

    
58
	cmn_err(CE_NOTE, "!Finished");
59

    
60
	return (0);
61
}
62

    
63
int
64
_info(struct modinfo *modinfop)
65
{
66
	return (mod_info(&modlinkage, modinfop));
67
}
68

    
69
int
70
_fini(void)
71
{
72
	return (mod_remove(&modlinkage));
73
}
    (1-1/1)