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