4 # Copyright (c) 1992, 1993
5 # The Regents of the University of California. All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
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 # 4. Neither the name of the University nor the names of its contributors
16 # may be used to endorse or promote products derived from this software
17 # without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 # @(#)vnode_if.sh 8.1 (Berkeley) 6/10/93
35 # Script to produce VFS front-end sugar.
37 # usage: vnode_if.awk <srcfile> [-c | -h]
38 # (where <srcfile> is currently /sys/kern/vnode_if.src)
43 print "usage: vnode_if.awk <srcfile> [-c|-h|-p|-q]";
47 function die(msg, what)
49 printf msg "\n", what > "/dev/stderr";
55 # Append a space if the type is not a pointer
56 return (type ~ /\*$/) ? type : type " ";
59 # These are just for convenience ...
60 function printc(s) {print s > cfile;}
61 function printh(s) {print s > hfile;}
62 function printp(s) {print s > pfile;}
63 function printq(s) {print s > qfile;}
65 function add_debug_code(name, arg, pos, ind)
71 if (lockdata[name, arg, pos] && (lockdata[name, arg, pos] != "-")) {
73 printc(ind"if ("substr(arg, 2)" != NULL) {");
75 printc(ind"ASSERT_VI_UNLOCKED("star"a->a_"arg", \""uname"\");");
76 # Add assertions for locking
77 if (lockdata[name, arg, pos] == "L")
78 printc(ind"ASSERT_VOP_LOCKED(" star "a->a_"arg", \""uname"\");");
79 else if (lockdata[name, arg, pos] == "U")
80 printc(ind"ASSERT_VOP_UNLOCKED(" star "a->a_"arg", \""uname"\");");
81 else if (lockdata[name, arg, pos] == "E")
82 printc(ind"ASSERT_VOP_ELOCKED(" star "a->a_"arg", \""uname"\");");
92 function add_pre(name)
94 if (lockdata[name, "pre"]) {
95 printc("\t"lockdata[name, "pre"]"(a);");
99 function add_post(name)
101 if (lockdata[name, "post"]) {
102 printc("\t"lockdata[name, "post"]"(a, rc);");
106 function find_arg_with_type (type)
108 for (jj = 0; jj < numargs; jj++) {
109 if (types[jj] == type) {
110 return "VOPARG_OFFSETOF(struct " \
111 name "_args,a_" args[jj] ")";
115 return "VDESC_NO_OFFSET";
120 # Process the command line
121 for (i = 1; i < ARGC; i++) {
123 if (arg !~ /^-[chpq]+$/ && arg !~ /\.src$/)
126 cfile = "vnode_if.c";
128 hfile = "vnode_if.h";
130 pfile = "vnode_if_newproto.h";
132 qfile = "vnode_if_typedef.h";
138 if (!cfile && !hfile && !pfile && !qfile)
146 " * This file is produced automatically.\n" \
147 " * Do not modify anything in here by hand.\n" \
149 " * Created from $FreeBSD$\n" \
155 printp("struct vop_vector {")
156 printp("\tstruct vop_vector\t*vop_default;")
157 printp("\tvop_bypass_t\t*vop_bypass;")
165 printh(common_head "extern struct vnodeop_desc vop_default_desc;");
166 printh("#include \"vnode_if_typedef.h\"")
167 printh("#include \"vnode_if_newproto.h\"")
172 "#include <sys/param.h>\n" \
173 "#include <sys/event.h>\n" \
174 "#include <sys/mount.h>\n" \
175 "#include <sys/systm.h>\n" \
176 "#include <sys/vnode.h>\n" \
178 "struct vnodeop_desc vop_default_desc = {\n" \
181 " (vop_bypass_t *)vop_panic,\n" \
183 " VDESC_NO_OFFSET,\n" \
184 " VDESC_NO_OFFSET,\n" \
185 " VDESC_NO_OFFSET,\n" \
186 " VDESC_NO_OFFSET,\n" \
190 while ((getline < srcfile) > 0) {
194 if (NF != 6 || $1 != "#%" || \
195 $2 !~ /^[a-z]+$/ || $3 !~ /^[a-z]+$/ || \
196 $4 !~ /^.$/ || $5 !~ /^.$/ || $6 !~ /^.$/)
198 lockdata["vop_" $2, $3, "Entry"] = $4;
199 lockdata["vop_" $2, $3, "OK"] = $5;
200 lockdata["vop_" $2, $3, "Error"] = $6;
205 if (NF != 4 || $1 != "#!")
207 if ($3 != "pre" && $3 != "post")
209 lockdata["vop_" $2, $3] = $4;
215 # Get the function name.
217 uname = toupper(name);
219 # Start constructing a ktrpoint string
221 # Get the function arguments.
222 for (numargs = 0; ; ++numargs) {
223 if ((getline < srcfile) <= 0) {
224 die("Unable to read through the arguments for \"%s\"",
230 # Delete comments, if any.
231 gsub (/\/\*.*\*\//, "");
233 # Condense whitespace and delete leading/trailing space.
234 gsub(/[[:space:]]+/, " ");
238 # Pick off direction.
239 if ($1 != "INOUT" && $1 != "IN" && $1 != "OUT")
240 die("No IN/OUT direction for \"%s\".", $0);
244 if ((reles[numargs] = $1) == "WILLRELE")
247 reles[numargs] = "WONTRELE";
250 if (sub(/;$/, "") < 1)
251 die("Missing end-of-line ; in \"%s\".", $0);
253 # pick off variable name
254 if ((argp = match($0, /[A-Za-z0-9_]+$/)) < 1)
255 die("Missing var name \"a_foo\" in \"%s\".", $0);
256 args[numargs] = substr($0, argp);
257 $0 = substr($0, 1, argp - 1);
259 # what is left must be type
260 # remove trailing space (if any)
264 # We can do a maximum of 6 arguments to CTR*
267 ctrstr = ctrstr "(" args[numargs];
269 ctrstr = ctrstr ", " args[numargs];
270 if (types[numargs] ~ /\*/)
271 ctrstr = ctrstr " 0x%lX";
273 ctrstr = ctrstr " %ld";
280 ctrstr = "\tCTR" ctrargs "(KTR_VOP,\n\t " ctrstr ")\",\n\t ";
281 ctrstr = ctrstr "a->a_" args[0];
282 for (i = 1; i < ctrargs; ++i)
283 ctrstr = ctrstr ", a->a_" args[i];
284 ctrstr = ctrstr ");";
287 printp("\t"name"_t\t*"name";")
290 printq("struct "name"_args;")
291 printq("typedef int "name"_t(struct "name"_args *);\n")
295 # Print out the vop_F_args structure.
296 printh("struct "name"_args {\n\tstruct vop_generic_args a_gen;");
297 for (i = 0; i < numargs; ++i)
298 printh("\t" t_spc(types[i]) "a_" args[i] ";");
302 # Print out extern declaration.
303 printh("extern struct vnodeop_desc " name "_desc;");
306 # Print out function prototypes.
307 printh("int " uname "_AP(struct " name "_args *);");
308 printh("int " uname "_APV(struct vop_vector *vop, struct " name "_args *);");
310 printh("static __inline int " uname "(");
311 for (i = 0; i < numargs; ++i) {
312 printh("\t" t_spc(types[i]) args[i] \
313 (i < numargs - 1 ? "," : ")"));
316 printh("\tstruct " name "_args a;");
318 printh("\ta.a_gen.a_desc = &" name "_desc;");
319 for (i = 0; i < numargs; ++i)
320 printh("\ta.a_" args[i] " = " args[i] ";");
321 printh("\treturn (" uname "_APV("args[0]"->v_op, &a));");
328 # Print out the vop_F_vp_offsets structure. This all depends
329 # on naming conventions and nothing else.
330 printc("static int " name "_vp_offsets[] = {");
331 # as a side effect, figure out the releflags
334 for (i = 0; i < numargs; i++) {
335 if (types[i] == "struct vnode *") {
336 printc("\tVOPARG_OFFSETOF(struct " name \
337 "_args,a_" args[i] "),");
338 if (reles[i] == "WILLRELE") {
339 releflags = releflags \
340 "|VDESC_VP" vpnum "_WILLRELE";
346 sub(/^\|/, "", releflags);
347 printc("\tVDESC_NO_OFFSET");
350 # Print out function.
351 printc("\nint\n" uname "_AP(struct " name "_args *a)");
354 printc("\treturn(" uname "_APV(a->a_" args[0] "->v_op, a));");
356 printc("\nint\n" uname "_APV(struct vop_vector *vop, struct " name "_args *a)");
360 printc("\tVNASSERT(a->a_gen.a_desc == &" name "_desc, a->a_" args[0]",");
361 printc("\t (\"Wrong a_desc in " name "(%p, %p)\", a->a_" args[0]", a));");
362 printc("\twhile(vop != NULL && \\");
363 printc("\t vop->"name" == NULL && vop->vop_bypass == NULL)")
364 printc("\t\tvop = vop->vop_default;")
365 printc("\tVNASSERT(vop != NULL, a->a_" args[0]", (\"No "name"(%p, %p)\", a->a_" args[0]", a));")
366 for (i = 0; i < numargs; ++i)
367 add_debug_code(name, args[i], "Entry", "\t");
369 printc("\tif (vop->"name" != NULL)")
370 printc("\t\trc = vop->"name"(a);")
372 printc("\t\trc = vop->vop_bypass(&a->a_gen);")
374 printc("\tif (rc == 0) {");
375 for (i = 0; i < numargs; ++i)
376 add_debug_code(name, args[i], "OK", "\t\t");
377 printc("\t} else {");
378 for (i = 0; i < numargs; ++i)
379 add_debug_code(name, args[i], "Error", "\t\t");
382 printc("\treturn (rc);");
385 # Print out the vnodeop_desc structure.
386 printc("struct vnodeop_desc " name "_desc = {");
388 printc("\t\"" name "\",");
391 for (i = 0; i < numargs; i++) {
392 if (types[i] == "struct vnode **" && \
393 reles[i] == "WILLRELE") {
394 vppwillrele = "|VDESC_VPP_WILLRELE";
400 printc("\t" releflags vppwillrele ",");
403 printc("\t(vop_bypass_t *)" uname "_AP,");
405 printc("\t" name "_vp_offsets,");
407 printc("\t" find_arg_with_type("struct vnode **") ",");
409 printc("\t" find_arg_with_type("struct ucred *") ",");
411 printc("\t" find_arg_with_type("struct thread *") ",");
413 printc("\t" find_arg_with_type("struct componentname *") ",");
414 # transport layer information