MFC corrected printing of the slice number when adding a GPT partition.
[dragonfly.git] / contrib / ipfilter / ml_ipl.c
blob4db9a9b0672226358cb5fbdb0cbe15f4345ebaf8
1 /*
2 * Copyright (C) 1993-2001 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
5 * responsibility and is not changed in any way.
7 * I hate legaleese, don't you ?
8 */
9 /*
10 * 29/12/94 Added code from Marc Huber <huber@fzi.de> to allow it to allocate
11 * its own major char number! Way cool patch!
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #include <sys/time.h>
16 #include <sys/file.h>
17 #include <sys/conf.h>
18 #include <sys/syslog.h>
19 #include <sys/buf.h>
20 #include <sys/param.h>
21 #include <sys/errno.h>
22 #include <sys/uio.h>
23 #include <sys/vnode.h>
24 #include <sundev/mbvar.h>
25 #include <sun/autoconf.h>
26 #include <sun/vddrv.h>
27 #if defined(sun4c) || defined(sun4m)
28 #include <sun/openprom.h>
29 #endif
31 #ifndef IPL_NAME
32 #define IPL_NAME "/dev/ipl"
33 #endif
35 extern int iplattach(), iplopen(), iplclose(), iplioctl(), iplread();
36 extern int nulldev(), iplidentify(), errno;
38 struct cdevsw ipldevsw =
40 iplopen, iplclose, iplread, nulldev,
41 iplioctl, nulldev, nulldev, nulldev,
42 0, nulldev,
46 struct dev_ops ipl_ops =
49 iplidentify,
50 iplattach,
51 iplopen,
52 iplclose,
53 iplread,
54 NULL, /* write */
55 NULL, /* strategy */
56 NULL, /* dump */
57 0, /* psize */
58 iplioctl,
59 NULL, /* reset */
60 NULL /* mmap */
63 int ipl_major = 0;
65 #ifdef sun4m
66 struct vdldrv vd =
68 VDMAGIC_PSEUDO,
69 "ipl",
70 &ipl_ops,
71 NULL,
72 &ipldevsw,
75 NULL,
76 NULL,
77 NULL,
81 #else /* sun4m */
82 struct vdldrv vd =
84 VDMAGIC_PSEUDO, /* magic */
85 "ipl", /* name */
86 #ifdef sun4c
87 &ipl_ops, /* dev_ops */
88 #else
89 NULL, /* struct mb_ctlr *mb_ctlr */
90 NULL, /* struct mb_driver *mb_driver */
91 NULL, /* struct mb_device *mb_device */
92 0, /* num ctlrs */
93 1, /* numdevs */
94 #endif /* sun4c */
95 NULL, /* bdevsw */
96 &ipldevsw, /* cdevsw */
97 0, /* block major */
98 0, /* char major */
100 #endif /* sun4m */
102 extern int vd_unuseddev();
103 extern struct cdevsw cdevsw[];
104 extern int nchrdev;
106 xxxinit(fc, vdp, vdi, vds)
107 u_int fc;
108 struct vddrv *vdp;
109 caddr_t vdi;
110 struct vdstat *vds;
112 struct vdlinkage *v;
113 int i;
115 switch (fc)
117 case VDLOAD:
118 while (ipl_major < nchrdev &&
119 cdevsw[ipl_major].d_open != vd_unuseddev)
120 ipl_major++;
121 if (ipl_major == nchrdev)
122 return ENODEV;
123 vd.Drv_charmajor = ipl_major;
124 vdp->vdd_vdtab = (struct vdlinkage *)&vd;
125 return ipl_attach(vdi);
126 case VDUNLOAD:
127 return unload(vdp, vdi);
129 case VDSTAT:
130 return 0;
132 default:
133 return EIO;
137 static unload(vdp, vdi)
138 struct vddrv *vdp;
139 struct vdioctl_unload *vdi;
141 int i;
143 (void) vn_remove(IPL_NAME, UIO_SYSSPACE, FILE);
144 return ipldetach();
148 static int ipl_attach(vdi)
149 struct vdioctl_load *vdi;
151 struct vnode *vp;
152 struct vattr vattr;
153 int error = 0, fmode = S_IFCHR|0600;
155 (void) vn_remove(IPL_NAME, UIO_SYSSPACE, FILE);
156 vattr_null(&vattr);
157 vattr.va_type = MFTOVT(fmode);
158 vattr.va_mode = (fmode & 07777);
159 vattr.va_rdev = ipl_major<<8;
161 error = vn_create(IPL_NAME, UIO_SYSSPACE, &vattr, EXCL, 0, &vp);
162 if (error == 0)
163 VN_RELE(vp);
164 return iplattach(0);