Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / ipf / ml_ipl.c
blobb12b954363d66397f59b8fb594523d15b7d3e2a0
1 /* $NetBSD: ml_ipl.c,v 1.5 2007/06/04 12:38:58 martti Exp $ */
3 /*
4 * Copyright (C) 1993-2001 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
7 */
8 /*
9 * 29/12/94 Added code from Marc Huber <huber@fzi.de> to allow it to allocate
10 * its own major char number! Way cool patch!
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <sys/time.h>
15 #include <sys/file.h>
16 #include <sys/conf.h>
17 #include <sys/syslog.h>
18 #include <sys/buf.h>
19 #include <sys/param.h>
20 #include <sys/errno.h>
21 #include <sys/uio.h>
22 #include <sys/vnode.h>
23 #include <sundev/mbvar.h>
24 #include <sun/autoconf.h>
25 #include <sun/vddrv.h>
26 #if defined(sun4c) || defined(sun4m)
27 #include <sun/openprom.h>
28 #endif
30 #ifndef IPL_NAME
31 #define IPL_NAME "/dev/ipl"
32 #endif
34 extern int ipfattach(), iplopen(), iplclose(), iplioctl(), iplread();
35 extern int nulldev(), iplidentify(), errno;
37 struct cdevsw ipldevsw =
39 iplopen, iplclose, iplread, nulldev,
40 iplioctl, nulldev, nulldev, nulldev,
41 0, nulldev,
45 struct dev_ops ipl_ops =
48 iplidentify,
49 ipfattach,
50 iplopen,
51 iplclose,
52 iplread,
53 NULL, /* write */
54 NULL, /* strategy */
55 NULL, /* dump */
56 0, /* psize */
57 iplioctl,
58 NULL, /* reset */
59 NULL /* mmap */
62 int ipl_major = 0;
64 #ifdef sun4m
65 struct vdldrv vd =
67 VDMAGIC_PSEUDO,
68 "ipl",
69 &ipl_ops,
70 NULL,
71 &ipldevsw,
74 NULL,
75 NULL,
76 NULL,
80 #else /* sun4m */
81 struct vdldrv vd =
83 VDMAGIC_PSEUDO, /* magic */
84 "ipl", /* name */
85 #ifdef sun4c
86 &ipl_ops, /* dev_ops */
87 #else
88 NULL, /* struct mb_ctlr *mb_ctlr */
89 NULL, /* struct mb_driver *mb_driver */
90 NULL, /* struct mb_device *mb_device */
91 0, /* num ctlrs */
92 1, /* numdevs */
93 #endif /* sun4c */
94 NULL, /* bdevsw */
95 &ipldevsw, /* cdevsw */
96 0, /* block major */
97 0, /* char major */
99 #endif /* sun4m */
101 extern int vd_unuseddev();
102 extern struct cdevsw cdevsw[];
103 extern int nchrdev;
105 xxxinit(fc, vdp, vdi, vds)
106 u_int fc;
107 struct vddrv *vdp;
108 caddr_t vdi;
109 struct vdstat *vds;
111 struct vdlinkage *v;
112 int i;
114 switch (fc)
116 case VDLOAD:
117 while (ipl_major < nchrdev &&
118 cdevsw[ipl_major].d_open != vd_unuseddev)
119 ipl_major++;
120 if (ipl_major == nchrdev)
121 return ENODEV;
122 vd.Drv_charmajor = ipl_major;
123 vdp->vdd_vdtab = (struct vdlinkage *)&vd;
124 return ipl_attach(vdi);
125 case VDUNLOAD:
126 return unload(vdp, vdi);
128 case VDSTAT:
129 return 0;
131 default:
132 return EIO;
136 static unload(vdp, vdi)
137 struct vddrv *vdp;
138 struct vdioctl_unload *vdi;
140 int i;
142 (void) vn_remove(IPL_NAME, UIO_SYSSPACE, FILE);
143 return ipfdetach();
147 static int ipl_attach(vdi)
148 struct vdioctl_load *vdi;
150 struct vnode *vp;
151 struct vattr vattr;
152 int error = 0, fmode = S_IFCHR|0600;
154 (void) vn_remove(IPL_NAME, UIO_SYSSPACE, FILE);
155 vattr_null(&vattr);
156 vattr.va_type = MFTOVT(fmode);
157 vattr.va_mode = (fmode & 07777);
158 vattr.va_rdev = ipl_major<<8;
160 error = vn_create(IPL_NAME, UIO_SYSSPACE, &vattr, EXCL, 0, &vp);
161 if (error == 0)
162 VN_RELE(vp);
163 return ipfattach(0);