]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ipfilter/ml_ipl.c
This commit was generated by cvs2svn to compensate for changes in r54816,
[FreeBSD/FreeBSD.git] / contrib / ipfilter / ml_ipl.c
1 /*
2  * Copyright (C) 1993-1998 by Darren Reed.
3  *
4  * Redistribution and use in source and binary forms are permitted
5  * provided that this notice is preserved and due credit is given
6  * to the original author and the contributors.  The author accepts no
7  * responsibility and is not changed in any way.
8  *
9  * I hate legaleese, don't you ?
10  */
11 /*
12  * 29/12/94 Added code from Marc Huber <huber@fzi.de> to allow it to allocate
13  * its own major char number! Way cool patch!
14  */
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <sys/time.h>
18 #include <sys/file.h>
19 #include <sys/conf.h>
20 #include <sys/syslog.h>
21 #include <sys/buf.h>
22 #include <sys/param.h>
23 #include <sys/errno.h>
24 #include <sys/uio.h>
25 #include <sys/vnode.h>
26 #include <sundev/mbvar.h>
27 #include <sun/autoconf.h>
28 #include <sun/vddrv.h>
29 #if defined(sun4c) || defined(sun4m)
30 #include <sun/openprom.h>
31 #endif
32
33 #ifndef IPL_NAME
34 #define IPL_NAME        "/dev/ipl"
35 #endif
36
37 extern  int     iplattach(), iplopen(), iplclose(), iplioctl(), iplread();
38 extern  int     nulldev(), iplidentify(), errno;
39
40 struct  cdevsw  ipldevsw = 
41 {
42         iplopen, iplclose, iplread, nulldev,
43         iplioctl, nulldev, nulldev, nulldev,
44         0, nulldev,
45 };
46
47
48 struct  dev_ops ipl_ops = 
49 {
50         1,
51         iplidentify,
52         iplattach,
53         iplopen,
54         iplclose,
55         iplread,
56         NULL,           /* write */
57         NULL,           /* strategy */
58         NULL,           /* dump */
59         0,              /* psize */
60         iplioctl,
61         NULL,           /* reset */
62         NULL            /* mmap */
63 };
64
65 int     ipl_major = 0;
66
67 #ifdef sun4m
68 struct  vdldrv  vd = 
69 {
70         VDMAGIC_PSEUDO,
71         "ipl",
72         &ipl_ops,
73         NULL,
74         &ipldevsw,
75         0,
76         0,
77         NULL,
78         NULL,
79         NULL,
80         0,
81         1,
82 };
83 #else /* sun4m */
84 struct vdldrv vd =
85 {
86         VDMAGIC_PSEUDO, /* magic */
87         "ipl",          /* name */
88 #ifdef sun4c
89         &ipl_ops,       /* dev_ops */
90 #else
91         NULL,           /* struct mb_ctlr *mb_ctlr */
92         NULL,           /* struct mb_driver *mb_driver */
93         NULL,           /* struct mb_device *mb_device */
94         0,              /* num ctlrs */
95         1,              /* numdevs */
96 #endif /* sun4c */
97         NULL,           /* bdevsw */
98         &ipldevsw,      /* cdevsw */
99         0,              /* block major */
100         0,              /* char major */
101 };
102 #endif /* sun4m */
103
104 extern int vd_unuseddev();
105 extern struct cdevsw cdevsw[];
106 extern int nchrdev;
107
108 xxxinit(fc, vdp, vdi, vds)
109 u_int   fc;
110 struct  vddrv   *vdp;
111 caddr_t vdi;
112 struct  vdstat  *vds;
113 {
114         struct  vdlinkage *v;
115         int     i;
116
117         switch (fc)
118         {
119         case VDLOAD:
120                 while (ipl_major < nchrdev &&
121                        cdevsw[ipl_major].d_open != vd_unuseddev)
122                         ipl_major++;
123                 if (ipl_major == nchrdev)
124                         return ENODEV;
125                 vd.Drv_charmajor = ipl_major;
126                 vdp->vdd_vdtab = (struct vdlinkage *)&vd;
127                 return ipl_attach(vdi);
128         case VDUNLOAD:
129                 return unload(vdp, vdi);
130                 
131         case VDSTAT:
132                 return 0;
133
134         default:
135                 return EIO;
136         }
137 }
138
139 static unload(vdp, vdi)
140         struct vddrv *vdp;
141         struct vdioctl_unload  *vdi;
142 {
143         int     i;
144
145         (void) vn_remove(IPL_NAME, UIO_SYSSPACE, FILE);
146         return ipldetach();
147 }
148
149
150 static  int     ipl_attach(vdi)
151 struct  vdioctl_load    *vdi;
152 {
153         struct  vnode   *vp;
154         struct  vattr   vattr;
155         int             error = 0, fmode = S_IFCHR|0600;
156
157         (void) vn_remove(IPL_NAME, UIO_SYSSPACE, FILE);
158         vattr_null(&vattr);
159         vattr.va_type = MFTOVT(fmode);
160         vattr.va_mode = (fmode & 07777);
161         vattr.va_rdev = ipl_major<<8;
162
163         error = vn_create(IPL_NAME, UIO_SYSSPACE, &vattr, EXCL, 0, &vp);
164         if (error == 0)
165                 VN_RELE(vp);
166         return iplattach(0);
167 }