]> git.ozlabs.org Git - ppp.git/blob - sunos4/ppp_vdcmd.c
include Makedefs
[ppp.git] / sunos4 / ppp_vdcmd.c
1 #include <sys/types.h>
2 #include <sys/errno.h>
3 #include <sys/conf.h>
4 #include <sun/vddrv.h>
5
6 extern struct streamtab pppinfo;
7 extern int ppp_count;
8 extern int nchrdev;
9
10 static struct vdldrv vd = {
11     VDMAGIC_PSEUDO,
12     "ppp"
13 };
14
15 extern int nodev();
16
17 static struct cdevsw ppp_cdevsw = {
18     nodev, nodev, nodev, nodev, nodev, nodev, nodev, 0,
19     &pppinfo
20 };
21
22 static struct cdevsw old_entry;
23
24 int
25 ppp_vdcmd(fun, vdp, vdi, vds)
26     unsigned int fun;
27     struct vddrv *vdp;
28     addr_t vdi;
29     struct vdstat *vds;
30 {
31     static int majnum = -1;
32     int n, maj;
33
34     switch (fun) {
35     case VDLOAD:
36         /*
37          * It seems like modload doesn't install the cdevsw entry
38          * for us.  Oh well...
39          */
40         for (maj = 1; maj < nchrdev; ++maj)
41             if (cdevsw[maj].d_open == vd_unuseddev)
42                 break;
43         if (maj >= nchrdev)
44             return ENODEV;
45         vd.Drv_charmajor = maj;
46         old_entry = cdevsw[maj];
47         cdevsw[maj] = ppp_cdevsw;
48         vd.Drv_cdevsw = &ppp_cdevsw;
49         vdp->vdd_vdtab = (struct vdlinkage *) &vd;
50         majnum = maj;
51         break;
52
53     case VDUNLOAD:
54         if (ppp_count > 0)
55             return EBUSY;
56         if (vd.Drv_charmajor > 0)
57             cdevsw[vd.Drv_charmajor] = old_entry;
58         break;
59
60     case VDSTAT:
61         /*
62          * We have to fool the modstat command into thinking
63          * that this module is actually a driver! This is
64          * so that installation commands that use the -exec
65          * option of modload to run a shell script find out
66          * the block and/or char major numbers of the driver
67          * loaded (so that the shell script can go off to
68          * /dev and *MAKE* the bloody device nodes- remember
69          * they might change from one load to another if
70          * you don't hardwire the number!).
71          */
72         vds->vds_magic = VDMAGIC_DRV;
73         vds->vds_modinfo[0] = (char) 0;
74         vds->vds_modinfo[1] = (char) majnum;
75         break;
76
77     default:
78         return EIO;
79     }
80     return 0;
81 }