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_debug_pre(name)
94 if (lockdata[name, "pre"]) {
95 printc("#ifdef DEBUG_VFS_LOCKS");
96 printc("\t"lockdata[name, "pre"]"(a);");
101 function add_debug_post(name)
103 if (lockdata[name, "post"]) {
104 printc("#ifdef DEBUG_VFS_LOCKS");
105 printc("\t"lockdata[name, "post"]"(a, rc);");
110 function find_arg_with_type (type)
112 for (jj = 0; jj < numargs; jj++) {
113 if (types[jj] == type) {
114 return "VOPARG_OFFSETOF(struct " \
115 name "_args,a_" args[jj] ")";
119 return "VDESC_NO_OFFSET";
124 # Process the command line
125 for (i = 1; i < ARGC; i++) {
127 if (arg !~ /^-[chpq]+$/ && arg !~ /\.src$/)
130 cfile = "vnode_if.c";
132 hfile = "vnode_if.h";
134 pfile = "vnode_if_newproto.h";
136 qfile = "vnode_if_typedef.h";
142 if (!cfile && !hfile && !pfile && !qfile)
150 " * This file is produced automatically.\n" \
151 " * Do not modify anything in here by hand.\n" \
153 " * Created from $FreeBSD$\n" \
159 printp("struct vop_vector {")
160 printp("\tstruct vop_vector\t*vop_default;")
161 printp("\tvop_bypass_t\t*vop_bypass;")
169 printh(common_head "extern struct vnodeop_desc vop_default_desc;");
170 printh("#include \"vnode_if_typedef.h\"")
171 printh("#include \"vnode_if_newproto.h\"")
176 "#include <sys/param.h>\n" \
177 "#include <sys/systm.h>\n" \
178 "#include <sys/vnode.h>\n" \
179 "#include <sys/systm.h>\n" \
181 "struct vnodeop_desc vop_default_desc = {\n" \
184 " (void *)(uintptr_t)vop_panic,\n" \
186 " VDESC_NO_OFFSET,\n" \
187 " VDESC_NO_OFFSET,\n" \
188 " VDESC_NO_OFFSET,\n" \
189 " VDESC_NO_OFFSET,\n" \
194 while ((getline < srcfile) > 0) {
198 if (NF != 6 || $1 != "#%" || \
199 $2 !~ /^[a-z]+$/ || $3 !~ /^[a-z]+$/ || \
200 $4 !~ /^.$/ || $5 !~ /^.$/ || $6 !~ /^.$/)
202 lockdata["vop_" $2, $3, "Entry"] = $4;
203 lockdata["vop_" $2, $3, "OK"] = $5;
204 lockdata["vop_" $2, $3, "Error"] = $6;
209 if (NF != 4 || $1 != "#!")
211 if ($3 != "pre" && $3 != "post")
213 lockdata["vop_" $2, $3] = $4;
219 # Get the function name.
221 uname = toupper(name);
223 # Start constructing a ktrpoint string
225 # Get the function arguments.
226 for (numargs = 0; ; ++numargs) {
227 if ((getline < srcfile) <= 0) {
228 die("Unable to read through the arguments for \"%s\"",
234 # Delete comments, if any.
235 gsub (/\/\*.*\*\//, "");
237 # Condense whitespace and delete leading/trailing space.
238 gsub(/[[:space:]]+/, " ");
242 # Pick off direction.
243 if ($1 != "INOUT" && $1 != "IN" && $1 != "OUT")
244 die("No IN/OUT direction for \"%s\".", $0);
248 if ((reles[numargs] = $1) == "WILLRELE")
251 reles[numargs] = "WONTRELE";
254 if (sub(/;$/, "") < 1)
255 die("Missing end-of-line ; in \"%s\".", $0);
257 # pick off variable name
258 if ((argp = match($0, /[A-Za-z0-9_]+$/)) < 1)
259 die("Missing var name \"a_foo\" in \"%s\".", $0);
260 args[numargs] = substr($0, argp);
261 $0 = substr($0, 1, argp - 1);
263 # what is left must be type
264 # remove trailing space (if any)
268 # We can do a maximum of 6 arguments to CTR*
271 ctrstr = ctrstr "(" args[numargs];
273 ctrstr = ctrstr ", " args[numargs];
274 if (types[numargs] ~ /\*/)
275 ctrstr = ctrstr " 0x%lX";
277 ctrstr = ctrstr " %ld";
284 ctrstr = "\tCTR" ctrargs "(KTR_VOP,\n\t " ctrstr ")\",\n\t ";
285 ctrstr = ctrstr "a->a_" args[0];
286 for (i = 1; i < ctrargs; ++i)
287 ctrstr = ctrstr ", a->a_" args[i];
288 ctrstr = ctrstr ");";
291 printp("\t"name"_t\t*"name";")
294 printq("struct "name"_args;")
295 printq("typedef int "name"_t(struct "name"_args *);\n")
299 # Print out the vop_F_args structure.
300 printh("struct "name"_args {\n\tstruct vop_generic_args a_gen;");
301 for (i = 0; i < numargs; ++i)
302 printh("\t" t_spc(types[i]) "a_" args[i] ";");
306 # Print out extern declaration.
307 printh("extern struct vnodeop_desc " name "_desc;");
310 # Print out function prototypes.
311 printh("int " uname "_AP(struct " name "_args *);");
312 printh("int " uname "_APV(struct vop_vector *vop, struct " name "_args *);");
314 printh("static __inline int " uname "(");
315 for (i = 0; i < numargs; ++i) {
316 printh("\t" t_spc(types[i]) args[i] \
317 (i < numargs - 1 ? "," : ")"));
320 printh("\tstruct " name "_args a;");
322 printh("\ta.a_gen.a_desc = &" name "_desc;");
323 for (i = 0; i < numargs; ++i)
324 printh("\ta.a_" args[i] " = " args[i] ";");
325 printh("\treturn (" uname "_APV("args[0]"->v_op, &a));");
332 # Print out the vop_F_vp_offsets structure. This all depends
333 # on naming conventions and nothing else.
334 printc("static int " name "_vp_offsets[] = {");
335 # as a side effect, figure out the releflags
338 for (i = 0; i < numargs; i++) {
339 if (types[i] == "struct vnode *") {
340 printc("\tVOPARG_OFFSETOF(struct " name \
341 "_args,a_" args[i] "),");
342 if (reles[i] == "WILLRELE") {
343 releflags = releflags \
344 "|VDESC_VP" vpnum "_WILLRELE";
350 sub(/^\|/, "", releflags);
351 printc("\tVDESC_NO_OFFSET");
354 # Print out function.
355 printc("\nint\n" uname "_AP(struct " name "_args *a)");
358 printc("\treturn(" uname "_APV(a->a_" args[0] "->v_op, a));");
360 printc("\nint\n" uname "_APV(struct vop_vector *vop, struct " name "_args *a)");
364 printc("\tVNASSERT(a->a_gen.a_desc == &" name "_desc, a->a_" args[0]",");
365 printc("\t (\"Wrong a_desc in " name "(%p, %p)\", a->a_" args[0]", a));");
366 printc("\twhile(vop != NULL && \\");
367 printc("\t vop->"name" == NULL && vop->vop_bypass == NULL)")
368 printc("\t\tvop = vop->vop_default;")
369 printc("\tVNASSERT(vop != NULL, a->a_" args[0]", (\"No "name"(%p, %p)\", a->a_" args[0]", a));")
370 for (i = 0; i < numargs; ++i)
371 add_debug_code(name, args[i], "Entry", "\t");
373 printc("\tif (vop->"name" != NULL)")
374 printc("\t\trc = vop->"name"(a);")
376 printc("\t\trc = vop->vop_bypass(&a->a_gen);")
378 printc("\tif (rc == 0) {");
379 for (i = 0; i < numargs; ++i)
380 add_debug_code(name, args[i], "OK", "\t\t");
381 printc("\t} else {");
382 for (i = 0; i < numargs; ++i)
383 add_debug_code(name, args[i], "Error", "\t\t");
385 add_debug_post(name);
386 printc("\treturn (rc);");
389 # Print out the vnodeop_desc structure.
390 printc("struct vnodeop_desc " name "_desc = {");
392 printc("\t\"" name "\",");
395 for (i = 0; i < numargs; i++) {
396 if (types[i] == "struct vnode **" && \
397 reles[i] == "WILLRELE") {
398 vppwillrele = "|VDESC_VPP_WILLRELE";
404 printc("\t" releflags vppwillrele ",");
407 printc("\t(void*)(uintptr_t)" uname "_AP,");
409 printc("\t" name "_vp_offsets,");
411 printc("\t" find_arg_with_type("struct vnode **") ",");
413 printc("\t" find_arg_with_type("struct ucred *") ",");
415 printc("\t" find_arg_with_type("struct thread *") ",");
417 printc("\t" find_arg_with_type("struct componentname *") ",");
418 # transport layer information
419 printc("\tNULL,\n};\n");