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