vnode_if.sh revision 1.2 1 1.1 mycroft #!/bin/sh -
2 1.2 gwr copyright='
3 1.2 gwr /*
4 1.2 gwr * Copyright (c) 1992, 1993
5 1.2 gwr * The Regents of the University of California. All rights reserved.
6 1.2 gwr *
7 1.2 gwr * Redistribution and use in source and binary forms, with or without
8 1.2 gwr * modification, are permitted provided that the following conditions
9 1.2 gwr * are met:
10 1.2 gwr * 1. Redistributions of source code must retain the above copyright
11 1.2 gwr * notice, this list of conditions and the following disclaimer.
12 1.2 gwr * 2. Redistributions in binary form must reproduce the above copyright
13 1.2 gwr * notice, this list of conditions and the following disclaimer in the
14 1.2 gwr * documentation and/or other materials provided with the distribution.
15 1.2 gwr * 3. All advertising materials mentioning features or use of this software
16 1.2 gwr * must display the following acknowledgement:
17 1.2 gwr * This product includes software developed by the University of
18 1.2 gwr * California, Berkeley and its contributors.
19 1.2 gwr * 4. Neither the name of the University nor the names of its contributors
20 1.2 gwr * may be used to endorse or promote products derived from this software
21 1.2 gwr * without specific prior written permission.
22 1.2 gwr *
23 1.2 gwr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.2 gwr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.2 gwr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.2 gwr * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.2 gwr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.2 gwr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.2 gwr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.2 gwr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.2 gwr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.2 gwr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.2 gwr * SUCH DAMAGE.
34 1.2 gwr */
35 1.2 gwr '
36 1.2 gwr SCRIPT_ID='$Id: vnode_if.sh,v 1.2 1994/06/15 15:49:03 gwr Exp $'
37 1.1 mycroft
38 1.1 mycroft # Script to produce VFS front-end sugar.
39 1.1 mycroft #
40 1.1 mycroft # usage: vnode_if.sh srcfile
41 1.1 mycroft # (where srcfile is currently /sys/kern/vnode_if.src)
42 1.1 mycroft #
43 1.1 mycroft
44 1.1 mycroft if [ $# -ne 1 ] ; then
45 1.1 mycroft echo 'usage: vnode_if.sh srcfile'
46 1.1 mycroft exit 1
47 1.1 mycroft fi
48 1.1 mycroft
49 1.2 gwr # Disable filename generation (globbing)
50 1.2 gwr set -f
51 1.2 gwr
52 1.1 mycroft # Name of the source file.
53 1.2 gwr src=$1
54 1.1 mycroft
55 1.1 mycroft # Names of the created files.
56 1.2 gwr out_c=vnode_if.c
57 1.2 gwr out_h=vnode_if.h
58 1.2 gwr
59 1.2 gwr # Awk program (must support nawk extensions)
60 1.2 gwr # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
61 1.2 gwr awk=${AWK:-awk}
62 1.2 gwr
63 1.2 gwr # Does this awk have a "toupper" function? (i.e. is it GNU awk)
64 1.2 gwr isgawk=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
65 1.2 gwr
66 1.2 gwr # If this awk does not define "toupper" then define our own.
67 1.2 gwr if [ "$isgawk" = TRUE ] ; then
68 1.2 gwr # GNU awk provides it.
69 1.2 gwr toupper=
70 1.2 gwr else
71 1.2 gwr # Provide our own toupper()
72 1.2 gwr toupper='
73 1.2 gwr function toupper(str) {
74 1.2 gwr _toupper_cmd = "echo "str" |tr a-z A-Z"
75 1.2 gwr _toupper_cmd | getline _toupper_str;
76 1.2 gwr close(_toupper_cmd);
77 1.2 gwr return _toupper_str;
78 1.2 gwr }'
79 1.2 gwr fi
80 1.1 mycroft
81 1.2 gwr #
82 1.2 gwr # This is the common part of all awk programs that read $src
83 1.2 gwr # This parses the input for one function into the arrays:
84 1.2 gwr # argdir, argtype, argname, willrele
85 1.2 gwr # and calls "doit()" to generate output for the function.
86 1.2 gwr #
87 1.2 gwr # Input to this parser is pre-processed slightly by sed
88 1.2 gwr # so this awk parser doesn't have to work so hard. The
89 1.2 gwr # changes done by the sed pre-processing step are:
90 1.2 gwr # insert a space beween * and pointer name
91 1.2 gwr # replace semicolons with spaces
92 1.2 gwr #
93 1.2 gwr sed_prep='s:\*\([^\*/]\):\* \1:g
94 1.2 gwr s/;/ /'
95 1.2 gwr awk_parser='
96 1.2 gwr # Comment line
97 1.2 gwr /^#/ { next; }
98 1.2 gwr # First line of description
99 1.2 gwr /^vop_/ {
100 1.2 gwr name=$1;
101 1.2 gwr argc=0;
102 1.2 gwr next;
103 1.2 gwr }
104 1.2 gwr # Last line of description
105 1.2 gwr /^}/ {
106 1.2 gwr doit();
107 1.2 gwr next;
108 1.2 gwr }
109 1.2 gwr # Middle lines of description
110 1.2 gwr {
111 1.2 gwr argdir[argc] = $1; i=2;
112 1.2 gwr if ($2 == "WILLRELE") {
113 1.2 gwr willrele[argc] = 1;
114 1.2 gwr i++;
115 1.2 gwr } else
116 1.2 gwr willrele[argc] = 0;
117 1.2 gwr argtype[argc] = $i; i++;
118 1.2 gwr while (i < NF) {
119 1.2 gwr argtype[argc] = argtype[argc]" "$i;
120 1.2 gwr i++;
121 1.2 gwr }
122 1.2 gwr argname[argc] = $i;
123 1.2 gwr argc++;
124 1.2 gwr next;
125 1.2 gwr }
126 1.2 gwr '
127 1.1 mycroft
128 1.2 gwr # This is put after the copyright on each generated file.
129 1.2 gwr warning="
130 1.1 mycroft /*
131 1.2 gwr * Warning: This file is generated automatically.
132 1.2 gwr * (Modifications made here may easily be lost!)
133 1.1 mycroft *
134 1.2 gwr * Created by the script:
135 1.2 gwr * ${SCRIPT_ID}
136 1.1 mycroft */
137 1.2 gwr "
138 1.2 gwr
139 1.2 gwr
140 1.2 gwr #
141 1.2 gwr # Redirect stdout to the H file.
142 1.2 gwr #
143 1.2 gwr echo "$0: Creating $out_h" 1>&2
144 1.2 gwr exec > $out_h
145 1.1 mycroft
146 1.2 gwr # Begin stuff
147 1.2 gwr echo "$copyright"
148 1.2 gwr echo "$warning"
149 1.2 gwr echo '
150 1.1 mycroft extern struct vnodeop_desc vop_default_desc;
151 1.2 gwr '
152 1.1 mycroft
153 1.2 gwr # Body stuff
154 1.2 gwr # This awk program needs toupper() so define it if necessary.
155 1.2 gwr sed -e "$sed_prep" $src | $awk "$toupper"'
156 1.2 gwr function doit() {
157 1.2 gwr # Declare arg struct, descriptor.
158 1.2 gwr printf("\nstruct %s_args {\n", name);
159 1.2 gwr printf("\tstruct vnodeop_desc * a_desc;\n");
160 1.2 gwr for (i=0; i<argc; i++) {
161 1.2 gwr printf("\t%s a_%s;\n", argtype[i], argname[i]);
162 1.1 mycroft }
163 1.2 gwr printf("};\n");
164 1.2 gwr printf("extern struct vnodeop_desc %s_desc;\n", name);
165 1.2 gwr # Define inline function.
166 1.2 gwr printf("static inline int %s(", toupper(name));
167 1.2 gwr for (i=0; i<argc; i++) {
168 1.2 gwr printf("%s", argname[i]);
169 1.2 gwr if (i < (argc-1)) printf(", ");
170 1.2 gwr }
171 1.2 gwr printf(")\n");
172 1.2 gwr for (i=0; i<argc; i++) {
173 1.2 gwr printf("\t%s %s;\n", argtype[i], argname[i]);
174 1.2 gwr }
175 1.2 gwr printf("{\n\tstruct %s_args a;\n", name);
176 1.2 gwr printf("\ta.a_desc = VDESC(%s);\n", name);
177 1.2 gwr for (i=0; i<argc; i++) {
178 1.2 gwr printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
179 1.2 gwr }
180 1.2 gwr printf("\treturn (VCALL(%s%s, VOFFSET(%s), &a));\n}\n",
181 1.2 gwr argname[0], arg0special, name);
182 1.2 gwr }
183 1.2 gwr BEGIN {
184 1.2 gwr arg0special="";
185 1.2 gwr }
186 1.2 gwr END {
187 1.2 gwr printf("\n/* Special cases: */\n#include <sys/buf.h>\n");
188 1.2 gwr argc=1;
189 1.2 gwr argtype[0]="struct buf *";
190 1.2 gwr argname[0]="bp";
191 1.2 gwr arg0special="->b_vp";
192 1.2 gwr name="vop_strategy";
193 1.2 gwr doit();
194 1.2 gwr name="vop_bwrite";
195 1.2 gwr doit();
196 1.2 gwr }
197 1.2 gwr '"$awk_parser"
198 1.1 mycroft
199 1.2 gwr # End stuff
200 1.2 gwr echo '
201 1.2 gwr /* End of special cases. */'
202 1.1 mycroft
203 1.1 mycroft
204 1.2 gwr #
205 1.2 gwr # Redirect stdout to the C file.
206 1.2 gwr #
207 1.2 gwr echo "$0: Creating $out_c" 1>&2
208 1.2 gwr exec > $out_c
209 1.1 mycroft
210 1.2 gwr # Begin stuff
211 1.2 gwr echo "$copyright"
212 1.2 gwr echo "$warning"
213 1.2 gwr echo '
214 1.1 mycroft #include <sys/param.h>
215 1.1 mycroft #include <sys/mount.h>
216 1.1 mycroft #include <sys/vnode.h>
217 1.1 mycroft
218 1.1 mycroft struct vnodeop_desc vop_default_desc = {
219 1.1 mycroft 0,
220 1.1 mycroft "default",
221 1.1 mycroft 0,
222 1.1 mycroft NULL,
223 1.1 mycroft VDESC_NO_OFFSET,
224 1.1 mycroft VDESC_NO_OFFSET,
225 1.1 mycroft VDESC_NO_OFFSET,
226 1.1 mycroft VDESC_NO_OFFSET,
227 1.1 mycroft NULL,
228 1.1 mycroft };
229 1.2 gwr '
230 1.1 mycroft
231 1.2 gwr # Body stuff
232 1.2 gwr sed -e "$sed_prep" $src | $awk '
233 1.2 gwr function do_offset(typematch) {
234 1.2 gwr for (i=0; i<argc; i++) {
235 1.2 gwr if (argtype[i] == typematch) {
236 1.2 gwr printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n",
237 1.2 gwr name, argname[i]);
238 1.2 gwr return i;
239 1.2 gwr };
240 1.2 gwr };
241 1.2 gwr print "\tVDESC_NO_OFFSET,";
242 1.2 gwr return -1;
243 1.2 gwr }
244 1.1 mycroft
245 1.2 gwr function doit() {
246 1.2 gwr # Define offsets array
247 1.2 gwr printf("\nint %s_vp_offsets[] = {\n", name);
248 1.2 gwr for (i=0; i<argc; i++) {
249 1.2 gwr if (argtype[i] == "struct vnode *") {
250 1.2 gwr printf ("\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
251 1.2 gwr name, argname[i]);
252 1.2 gwr }
253 1.1 mycroft }
254 1.2 gwr print "\tVDESC_NO_OFFSET";
255 1.2 gwr print "};";
256 1.2 gwr # Define F_desc
257 1.2 gwr printf("struct vnodeop_desc %s_desc = {\n", name);
258 1.2 gwr # offset
259 1.2 gwr printf ("\t0,\n");
260 1.2 gwr # printable name
261 1.2 gwr printf ("\t\"%s\",\n", name);
262 1.2 gwr # flags
263 1.2 gwr printf("\t0");
264 1.2 gwr vpnum = 0;
265 1.2 gwr for (i=0; i<argc; i++) {
266 1.2 gwr if (willrele[i]) {
267 1.2 gwr if (argdir[i] ~ /OUT/) {
268 1.2 gwr printf(" | VDESC_VPP_WILLRELE");
269 1.1 mycroft } else {
270 1.2 gwr printf(" | VDESC_VP%s_WILLRELE", vpnum);
271 1.1 mycroft };
272 1.2 gwr vpnum++;
273 1.2 gwr }
274 1.1 mycroft }
275 1.2 gwr print ",";
276 1.2 gwr # vp offsets
277 1.2 gwr printf ("\t%s_vp_offsets,\n", name);
278 1.2 gwr # vpp (if any)
279 1.2 gwr do_offset("struct vnode **");
280 1.2 gwr # cred (if any)
281 1.2 gwr do_offset("struct ucred *");
282 1.2 gwr # proc (if any)
283 1.2 gwr do_offset("struct proc *");
284 1.2 gwr # componentname
285 1.2 gwr do_offset("struct componentname *");
286 1.2 gwr # transport layer information
287 1.2 gwr printf ("\tNULL,\n};\n");
288 1.2 gwr }
289 1.2 gwr END {
290 1.2 gwr printf("\n/* Special cases: */\n");
291 1.2 gwr argc=1;
292 1.2 gwr argdir[0]="IN";
293 1.2 gwr argtype[0]="struct buf *";
294 1.2 gwr argname[0]="bp";
295 1.2 gwr willrele[0]=0;
296 1.2 gwr name="vop_strategy";
297 1.2 gwr doit();
298 1.2 gwr name="vop_bwrite";
299 1.2 gwr doit();
300 1.1 mycroft }
301 1.2 gwr '"$awk_parser"
302 1.1 mycroft
303 1.2 gwr # End stuff
304 1.2 gwr echo '
305 1.2 gwr /* End of special cases. */'
306 1.1 mycroft
307 1.2 gwr # Add the vfs_op_descs array to the C file.
308 1.2 gwr # Begin stuff
309 1.2 gwr echo '
310 1.2 gwr struct vnodeop_desc *vfs_op_descs[] = {
311 1.2 gwr &vop_default_desc, /* MUST BE FIRST */
312 1.2 gwr &vop_strategy_desc, /* XXX: SPECIAL CASE */
313 1.2 gwr &vop_bwrite_desc, /* XXX: SPECIAL CASE */
314 1.2 gwr '
315 1.2 gwr
316 1.2 gwr # Body stuff
317 1.2 gwr sed -e "$sed_prep" $src | $awk '
318 1.2 gwr function doit() {
319 1.2 gwr printf("\t&%s_desc,\n", name);
320 1.1 mycroft }
321 1.2 gwr '"$awk_parser"
322 1.1 mycroft
323 1.2 gwr # End stuff
324 1.2 gwr echo ' NULL
325 1.1 mycroft };
326 1.2 gwr '
327 1.1 mycroft
328 1.2 gwr exit 0
329 1.1 mycroft
330 1.2 gwr # Local Variables:
331 1.2 gwr # tab-width: 4
332 1.2 gwr # End:
333