vnode_if.sh revision 1.1.1.1 1 1.1 mycroft #!/bin/sh -
2 1.1 mycroft #
3 1.1 mycroft # Copyright (c) 1992, 1993
4 1.1 mycroft # The Regents of the University of California. All rights reserved.
5 1.1 mycroft #
6 1.1 mycroft # Redistribution and use in source and binary forms, with or without
7 1.1 mycroft # modification, are permitted provided that the following conditions
8 1.1 mycroft # are met:
9 1.1 mycroft # 1. Redistributions of source code must retain the above copyright
10 1.1 mycroft # notice, this list of conditions and the following disclaimer.
11 1.1 mycroft # 2. Redistributions in binary form must reproduce the above copyright
12 1.1 mycroft # notice, this list of conditions and the following disclaimer in the
13 1.1 mycroft # documentation and/or other materials provided with the distribution.
14 1.1 mycroft # 3. All advertising materials mentioning features or use of this software
15 1.1 mycroft # must display the following acknowledgement:
16 1.1 mycroft # This product includes software developed by the University of
17 1.1 mycroft # California, Berkeley and its contributors.
18 1.1 mycroft # 4. Neither the name of the University nor the names of its contributors
19 1.1 mycroft # may be used to endorse or promote products derived from this software
20 1.1 mycroft # without specific prior written permission.
21 1.1 mycroft #
22 1.1 mycroft # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.1 mycroft # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 mycroft # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 mycroft # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.1 mycroft # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 mycroft # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 mycroft # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 mycroft # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 mycroft # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 mycroft # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 mycroft # SUCH DAMAGE.
33 1.1 mycroft #
34 1.1.1.1 fvdl # @(#)vnode_if.sh 8.1 (Berkeley) 6/10/93
35 1.1 mycroft #
36 1.1 mycroft
37 1.1 mycroft # Script to produce VFS front-end sugar.
38 1.1 mycroft #
39 1.1 mycroft # usage: vnode_if.sh srcfile
40 1.1 mycroft # (where srcfile is currently /sys/kern/vnode_if.src)
41 1.1 mycroft #
42 1.1 mycroft # These awk scripts are not particularly well written, specifically they
43 1.1 mycroft # don't use arrays well and figure out the same information repeatedly.
44 1.1 mycroft # Please rewrite them if you actually understand how to use awk. Note,
45 1.1 mycroft # they use nawk extensions and gawk's toupper.
46 1.1 mycroft
47 1.1 mycroft if [ $# -ne 1 ] ; then
48 1.1 mycroft echo 'usage: vnode_if.sh srcfile'
49 1.1 mycroft exit 1
50 1.1 mycroft fi
51 1.1 mycroft
52 1.1 mycroft # Name of the source file.
53 1.1 mycroft SRC=$1
54 1.1 mycroft
55 1.1 mycroft # Names of the created files.
56 1.1 mycroft CFILE=vnode_if.c
57 1.1 mycroft HEADER=vnode_if.h
58 1.1 mycroft
59 1.1 mycroft # Awk program (must support nawk extensions and gawk's "toupper")
60 1.1 mycroft # Use "awk" at Berkeley, "gawk" elsewhere.
61 1.1 mycroft AWK=awk
62 1.1 mycroft
63 1.1 mycroft # Print out header information for vnode_if.h.
64 1.1 mycroft cat << END_OF_LEADING_COMMENT > $HEADER
65 1.1 mycroft /*
66 1.1 mycroft * This file is produced automatically.
67 1.1 mycroft * Do not modify anything in here by hand.
68 1.1 mycroft *
69 1.1 mycroft * Created from @(#)vnode_if.sh 8.1 (Berkeley) 6/10/93
70 1.1 mycroft */
71 1.1 mycroft
72 1.1 mycroft extern struct vnodeop_desc vop_default_desc;
73 1.1 mycroft END_OF_LEADING_COMMENT
74 1.1 mycroft
75 1.1 mycroft # Awk script to take vnode_if.src and turn it into vnode_if.h.
76 1.1 mycroft $AWK '
77 1.1 mycroft NF == 0 || $0 ~ "^#" {
78 1.1 mycroft next;
79 1.1 mycroft }
80 1.1 mycroft {
81 1.1 mycroft # Get the function name.
82 1.1 mycroft name = $1;
83 1.1 mycroft uname = toupper(name);
84 1.1 mycroft
85 1.1 mycroft # Get the function arguments.
86 1.1 mycroft for (c1 = 0;; ++c1) {
87 1.1 mycroft if (getline <= 0)
88 1.1 mycroft exit
89 1.1 mycroft if ($0 ~ "^};")
90 1.1 mycroft break;
91 1.1 mycroft a[c1] = $0;
92 1.1 mycroft }
93 1.1 mycroft
94 1.1 mycroft # Print out the vop_F_args structure.
95 1.1 mycroft printf("struct %s_args {\n\tstruct vnodeop_desc *a_desc;\n",
96 1.1 mycroft name);
97 1.1 mycroft for (c2 = 0; c2 < c1; ++c2) {
98 1.1 mycroft c3 = split(a[c2], t);
99 1.1 mycroft printf("\t");
100 1.1 mycroft if (t[2] ~ "WILLRELE")
101 1.1 mycroft c4 = 3;
102 1.1 mycroft else
103 1.1 mycroft c4 = 2;
104 1.1 mycroft for (; c4 < c3; ++c4)
105 1.1 mycroft printf("%s ", t[c4]);
106 1.1 mycroft beg = match(t[c3], "[^*]");
107 1.1 mycroft printf("%sa_%s\n",
108 1.1 mycroft substr(t[c4], 0, beg - 1), substr(t[c4], beg));
109 1.1 mycroft }
110 1.1 mycroft printf("};\n");
111 1.1 mycroft
112 1.1 mycroft # Print out extern declaration.
113 1.1 mycroft printf("extern struct vnodeop_desc %s_desc;\n", name);
114 1.1 mycroft
115 1.1 mycroft # Print out inline struct.
116 1.1 mycroft printf("static inline int %s(", uname);
117 1.1 mycroft sep = ", ";
118 1.1 mycroft for (c2 = 0; c2 < c1; ++c2) {
119 1.1 mycroft if (c2 == c1 - 1)
120 1.1 mycroft sep = ")\n";
121 1.1 mycroft c3 = split(a[c2], t);
122 1.1 mycroft beg = match(t[c3], "[^*]");
123 1.1 mycroft end = match(t[c3], ";");
124 1.1 mycroft printf("%s%s", substr(t[c3], beg, end - beg), sep);
125 1.1 mycroft }
126 1.1 mycroft for (c2 = 0; c2 < c1; ++c2) {
127 1.1 mycroft c3 = split(a[c2], t);
128 1.1 mycroft printf("\t");
129 1.1 mycroft if (t[2] ~ "WILLRELE")
130 1.1 mycroft c4 = 3;
131 1.1 mycroft else
132 1.1 mycroft c4 = 2;
133 1.1 mycroft for (; c4 < c3; ++c4)
134 1.1 mycroft printf("%s ", t[c4]);
135 1.1 mycroft beg = match(t[c3], "[^*]");
136 1.1 mycroft printf("%s%s\n",
137 1.1 mycroft substr(t[c4], 0, beg - 1), substr(t[c4], beg));
138 1.1 mycroft }
139 1.1 mycroft printf("{\n\tstruct %s_args a;\n\n", name);
140 1.1 mycroft printf("\ta.a_desc = VDESC(%s);\n", name);
141 1.1 mycroft for (c2 = 0; c2 < c1; ++c2) {
142 1.1 mycroft c3 = split(a[c2], t);
143 1.1 mycroft printf("\t");
144 1.1 mycroft beg = match(t[c3], "[^*]");
145 1.1 mycroft end = match(t[c3], ";");
146 1.1 mycroft printf("a.a_%s = %s\n",
147 1.1 mycroft substr(t[c3], beg, end - beg), substr(t[c3], beg));
148 1.1 mycroft }
149 1.1 mycroft c1 = split(a[0], t);
150 1.1 mycroft beg = match(t[c1], "[^*]");
151 1.1 mycroft end = match(t[c1], ";");
152 1.1 mycroft printf("\treturn (VCALL(%s, VOFFSET(%s), &a));\n}\n",
153 1.1 mycroft substr(t[c1], beg, end - beg), name);
154 1.1 mycroft }' < $SRC >> $HEADER
155 1.1 mycroft
156 1.1 mycroft # Print out header information for vnode_if.c.
157 1.1 mycroft cat << END_OF_LEADING_COMMENT > $CFILE
158 1.1 mycroft /*
159 1.1 mycroft * This file is produced automatically.
160 1.1 mycroft * Do not modify anything in here by hand.
161 1.1 mycroft *
162 1.1 mycroft * Created from @(#)vnode_if.sh 8.1 (Berkeley) 6/10/93
163 1.1 mycroft */
164 1.1 mycroft
165 1.1 mycroft #include <sys/param.h>
166 1.1 mycroft #include <sys/mount.h>
167 1.1 mycroft #include <sys/vnode.h>
168 1.1 mycroft
169 1.1 mycroft struct vnodeop_desc vop_default_desc = {
170 1.1 mycroft 0,
171 1.1 mycroft "default",
172 1.1 mycroft 0,
173 1.1 mycroft NULL,
174 1.1 mycroft VDESC_NO_OFFSET,
175 1.1 mycroft VDESC_NO_OFFSET,
176 1.1 mycroft VDESC_NO_OFFSET,
177 1.1 mycroft VDESC_NO_OFFSET,
178 1.1 mycroft NULL,
179 1.1 mycroft };
180 1.1 mycroft
181 1.1 mycroft END_OF_LEADING_COMMENT
182 1.1 mycroft
183 1.1 mycroft # Awk script to take vnode_if.src and turn it into vnode_if.c.
184 1.1 mycroft $AWK 'function kill_surrounding_ws (s) {
185 1.1 mycroft sub (/^[ \t]*/, "", s);
186 1.1 mycroft sub (/[ \t]*$/, "", s);
187 1.1 mycroft return s;
188 1.1 mycroft }
189 1.1 mycroft
190 1.1 mycroft function read_args() {
191 1.1 mycroft numargs = 0;
192 1.1 mycroft while (getline ln) {
193 1.1 mycroft if (ln ~ /}/) {
194 1.1 mycroft break;
195 1.1 mycroft };
196 1.1 mycroft
197 1.1 mycroft # Delete comments, if any.
198 1.1 mycroft gsub (/\/\*.*\*\//, "", ln);
199 1.1 mycroft
200 1.1 mycroft # Delete leading/trailing space.
201 1.1 mycroft ln = kill_surrounding_ws(ln);
202 1.1 mycroft
203 1.1 mycroft # Pick off direction.
204 1.1 mycroft if (1 == sub(/^INOUT[ \t]+/, "", ln))
205 1.1 mycroft dir = "INOUT";
206 1.1 mycroft else if (1 == sub(/^IN[ \t]+/, "", ln))
207 1.1 mycroft dir = "IN";
208 1.1 mycroft else if (1 == sub(/^OUT[ \t]+/, "", ln))
209 1.1 mycroft dir = "OUT";
210 1.1 mycroft else
211 1.1 mycroft bail("No IN/OUT direction for \"" ln "\".");
212 1.1 mycroft
213 1.1 mycroft # check for "WILLRELE"
214 1.1 mycroft if (1 == sub(/^WILLRELE[ \t]+/, "", ln)) {
215 1.1 mycroft rele = "WILLRELE";
216 1.1 mycroft } else {
217 1.1 mycroft rele = "WONTRELE";
218 1.1 mycroft };
219 1.1 mycroft
220 1.1 mycroft # kill trailing ;
221 1.1 mycroft if (1 != sub (/;$/, "", ln)) {
222 1.1 mycroft bail("Missing end-of-line ; in \"" ln "\".");
223 1.1 mycroft };
224 1.1 mycroft
225 1.1 mycroft # pick off variable name
226 1.1 mycroft if (!(i = match(ln, /[A-Za-z0-9_]+$/))) {
227 1.1 mycroft bail("Missing var name \"a_foo\" in \"" ln "\".");
228 1.1 mycroft };
229 1.1 mycroft arg = substr (ln, i);
230 1.1 mycroft # Want to <<substr(ln, i) = "";>>, but nawk cannot.
231 1.1 mycroft # Hack around this.
232 1.1 mycroft ln = substr(ln, 1, i-1);
233 1.1 mycroft
234 1.1 mycroft # what is left must be type
235 1.1 mycroft # (put clean it up some)
236 1.1 mycroft type = ln;
237 1.1 mycroft gsub (/[ \t]+/, " ", type); # condense whitespace
238 1.1 mycroft type = kill_surrounding_ws(type);
239 1.1 mycroft
240 1.1 mycroft # (boy this was easier in Perl)
241 1.1 mycroft
242 1.1 mycroft numargs++;
243 1.1 mycroft dirs[numargs] = dir;
244 1.1 mycroft reles[numargs] = rele;
245 1.1 mycroft types[numargs] = type;
246 1.1 mycroft args[numargs] = arg;
247 1.1 mycroft };
248 1.1 mycroft }
249 1.1 mycroft
250 1.1 mycroft function generate_operation_vp_offsets() {
251 1.1 mycroft printf ("int %s_vp_offsets[] = {\n", name);
252 1.1 mycroft # as a side effect, figure out the releflags
253 1.1 mycroft releflags = "";
254 1.1 mycroft vpnum = 0;
255 1.1 mycroft for (i=1; i<=numargs; i++) {
256 1.1 mycroft if (types[i] == "struct vnode *") {
257 1.1 mycroft printf ("\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
258 1.1 mycroft name, args[i]);
259 1.1 mycroft if (reles[i] == "WILLRELE") {
260 1.1 mycroft releflags = releflags "|VDESC_VP" vpnum "_WILLRELE";
261 1.1 mycroft };
262 1.1 mycroft vpnum++;
263 1.1 mycroft };
264 1.1 mycroft };
265 1.1 mycroft sub (/^\|/, "", releflags);
266 1.1 mycroft print "\tVDESC_NO_OFFSET";
267 1.1 mycroft print "};";
268 1.1 mycroft }
269 1.1 mycroft
270 1.1 mycroft function find_arg_with_type (type) {
271 1.1 mycroft for (i=1; i<=numargs; i++) {
272 1.1 mycroft if (types[i] == type) {
273 1.1 mycroft return "VOPARG_OFFSETOF(struct " name "_args,a_" args[i] ")";
274 1.1 mycroft };
275 1.1 mycroft };
276 1.1 mycroft return "VDESC_NO_OFFSET";
277 1.1 mycroft }
278 1.1 mycroft
279 1.1 mycroft function generate_operation_desc() {
280 1.1 mycroft printf ("struct vnodeop_desc %s_desc = {\n", name);
281 1.1 mycroft # offset
282 1.1 mycroft printf ("\t0,\n");
283 1.1 mycroft # printable name
284 1.1 mycroft printf ("\t\"%s\",\n", name);
285 1.1 mycroft # flags
286 1.1 mycroft vppwillrele = "";
287 1.1 mycroft for (i=1; i<=numargs; i++) {
288 1.1 mycroft if (types[i] == "struct vnode **" &&
289 1.1 mycroft (reles[i] == "WILLRELE")) {
290 1.1 mycroft vppwillrele = "|VDESC_VPP_WILLRELE";
291 1.1 mycroft };
292 1.1 mycroft };
293 1.1 mycroft if (releflags == "") {
294 1.1 mycroft printf ("\t0%s,\n", vppwillrele);
295 1.1 mycroft } else {
296 1.1 mycroft printf ("\t%s%s,\n", releflags, vppwillrele);
297 1.1 mycroft };
298 1.1 mycroft # vp offsets
299 1.1 mycroft printf ("\t%s_vp_offsets,\n", name);
300 1.1 mycroft # vpp (if any)
301 1.1 mycroft printf ("\t%s,\n", find_arg_with_type("struct vnode **"));
302 1.1 mycroft # cred (if any)
303 1.1 mycroft printf ("\t%s,\n", find_arg_with_type("struct ucred *"));
304 1.1 mycroft # proc (if any)
305 1.1 mycroft printf ("\t%s,\n", find_arg_with_type("struct proc *"));
306 1.1 mycroft # componentname
307 1.1 mycroft printf ("\t%s,\n", find_arg_with_type("struct componentname *"));
308 1.1 mycroft # transport layer information
309 1.1 mycroft printf ("\tNULL,\n};\n");
310 1.1 mycroft }
311 1.1 mycroft
312 1.1 mycroft NF == 0 || $0 ~ "^#" {
313 1.1 mycroft next;
314 1.1 mycroft }
315 1.1 mycroft {
316 1.1 mycroft # get the function name
317 1.1 mycroft name = $1;
318 1.1 mycroft
319 1.1 mycroft # get the function arguments
320 1.1 mycroft read_args();
321 1.1 mycroft
322 1.1 mycroft # Print out the vop_F_vp_offsets structure. This all depends
323 1.1 mycroft # on naming conventions and nothing else.
324 1.1 mycroft generate_operation_vp_offsets();
325 1.1 mycroft
326 1.1 mycroft # Print out the vnodeop_desc structure.
327 1.1 mycroft generate_operation_desc();
328 1.1 mycroft
329 1.1 mycroft printf "\n";
330 1.1 mycroft
331 1.1 mycroft }' < $SRC >> $CFILE
332 1.1 mycroft # THINGS THAT DON'T WORK RIGHT YET.
333 1.1 mycroft #
334 1.1 mycroft # Two existing BSD vnodeops (bwrite and strategy) don't take any vnodes as
335 1.1 mycroft # arguments. This means that these operations can't function successfully
336 1.1 mycroft # through a bypass routine.
337 1.1 mycroft #
338 1.1 mycroft # Bwrite and strategy will be replaced when the VM page/buffer cache
339 1.1 mycroft # integration happens.
340 1.1 mycroft #
341 1.1 mycroft # To get around this problem for now we handle these ops as special cases.
342 1.1 mycroft
343 1.1 mycroft cat << END_OF_SPECIAL_CASES >> $HEADER
344 1.1 mycroft #include <sys/buf.h>
345 1.1 mycroft struct vop_strategy_args {
346 1.1 mycroft struct vnodeop_desc *a_desc;
347 1.1 mycroft struct buf *a_bp;
348 1.1 mycroft };
349 1.1 mycroft extern struct vnodeop_desc vop_strategy_desc;
350 1.1 mycroft static inline int VOP_STRATEGY(bp)
351 1.1 mycroft struct buf *bp;
352 1.1 mycroft {
353 1.1 mycroft struct vop_strategy_args a;
354 1.1 mycroft
355 1.1 mycroft a.a_desc = VDESC(vop_strategy);
356 1.1 mycroft a.a_bp = bp;
357 1.1 mycroft return (VCALL((bp)->b_vp, VOFFSET(vop_strategy), &a));
358 1.1 mycroft }
359 1.1 mycroft
360 1.1 mycroft struct vop_bwrite_args {
361 1.1 mycroft struct vnodeop_desc *a_desc;
362 1.1 mycroft struct buf *a_bp;
363 1.1 mycroft };
364 1.1 mycroft extern struct vnodeop_desc vop_bwrite_desc;
365 1.1 mycroft static inline int VOP_BWRITE(bp)
366 1.1 mycroft struct buf *bp;
367 1.1 mycroft {
368 1.1 mycroft struct vop_bwrite_args a;
369 1.1 mycroft
370 1.1 mycroft a.a_desc = VDESC(vop_bwrite);
371 1.1 mycroft a.a_bp = bp;
372 1.1 mycroft return (VCALL((bp)->b_vp, VOFFSET(vop_bwrite), &a));
373 1.1 mycroft }
374 1.1 mycroft END_OF_SPECIAL_CASES
375 1.1 mycroft
376 1.1 mycroft cat << END_OF_SPECIAL_CASES >> $CFILE
377 1.1 mycroft int vop_strategy_vp_offsets[] = {
378 1.1 mycroft VDESC_NO_OFFSET
379 1.1 mycroft };
380 1.1 mycroft struct vnodeop_desc vop_strategy_desc = {
381 1.1 mycroft 0,
382 1.1 mycroft "vop_strategy",
383 1.1 mycroft 0,
384 1.1 mycroft vop_strategy_vp_offsets,
385 1.1 mycroft VDESC_NO_OFFSET,
386 1.1 mycroft VDESC_NO_OFFSET,
387 1.1 mycroft VDESC_NO_OFFSET,
388 1.1 mycroft VDESC_NO_OFFSET,
389 1.1 mycroft NULL,
390 1.1 mycroft };
391 1.1 mycroft int vop_bwrite_vp_offsets[] = {
392 1.1 mycroft VDESC_NO_OFFSET
393 1.1 mycroft };
394 1.1 mycroft struct vnodeop_desc vop_bwrite_desc = {
395 1.1 mycroft 0,
396 1.1 mycroft "vop_bwrite",
397 1.1 mycroft 0,
398 1.1 mycroft vop_bwrite_vp_offsets,
399 1.1 mycroft VDESC_NO_OFFSET,
400 1.1 mycroft VDESC_NO_OFFSET,
401 1.1 mycroft VDESC_NO_OFFSET,
402 1.1 mycroft VDESC_NO_OFFSET,
403 1.1 mycroft NULL,
404 1.1 mycroft };
405 1.1 mycroft END_OF_SPECIAL_CASES
406 1.1 mycroft
407 1.1 mycroft # Add the vfs_op_descs array to the C file.
408 1.1 mycroft $AWK '
409 1.1 mycroft BEGIN {
410 1.1 mycroft printf("\nstruct vnodeop_desc *vfs_op_descs[] = {\n");
411 1.1 mycroft printf("\t&vop_default_desc, /* MUST BE FIRST */\n");
412 1.1 mycroft printf("\t&vop_strategy_desc, /* XXX: SPECIAL CASE */\n");
413 1.1 mycroft printf("\t&vop_bwrite_desc, /* XXX: SPECIAL CASE */\n");
414 1.1 mycroft }
415 1.1 mycroft END {
416 1.1 mycroft printf("\tNULL\n};\n");
417 1.1 mycroft }
418 1.1 mycroft NF == 0 || $0 ~ "^#" {
419 1.1 mycroft next;
420 1.1 mycroft }
421 1.1 mycroft {
422 1.1 mycroft # Get the function name.
423 1.1 mycroft printf("\t&%s_desc,\n", $1);
424 1.1 mycroft
425 1.1 mycroft # Skip the function arguments.
426 1.1 mycroft for (;;) {
427 1.1 mycroft if (getline <= 0)
428 1.1 mycroft exit
429 1.1 mycroft if ($0 ~ "^};")
430 1.1 mycroft break;
431 1.1 mycroft }
432 1.1 mycroft }' < $SRC >> $CFILE
433 1.1 mycroft
434