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 # 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.
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
35 # @(#)vnode_if.sh 8.1 (Berkeley) 6/10/93
36 # $FreeBSD: src/sys/tools/vnode_if.awk,v 1.39 2003/06/22 21:20:06 truckman Exp $
37 # $DragonFly: src/sys/tools/Attic/vnode_if.awk,v 1.5 2004/03/07 12:48:34 eirikn Exp $
39 # Script to produce VFS front-end sugar.
41 # usage: vnode_if.awk <srcfile> [-c | -h]
42 # (where <srcfile> is currently /sys/kern/vnode_if.src)
47 print "usage: vnode_if.awk <srcfile> [-c|-h]";
51 function die(msg, what)
53 printf msg "\n", what > "/dev/stderr";
59 # Append a space if the type is not a pointer
60 return (type ~ /\*$/) ? type : type " ";
63 # These are just for convenience ...
64 function printc(s) {print s > cfile;}
65 function printh(s) {print s > hfile;}
67 function add_debug_code(name, arg, pos)
71 if (lockdata[name, arg, pos] && (lockdata[name, arg, pos] != "-")) {
73 printh("\tif ("substr(arg, 2)" != NULL) {");
75 # Add assertions for locking
76 if (lockdata[name, arg, pos] == "L")
77 printh("\tASSERT_VOP_LOCKED("arg", \""uname"\");");
78 else if (lockdata[name, arg, pos] == "U")
79 printh("\tASSERT_VOP_UNLOCKED("arg", \""uname"\");");
89 function add_debug_pre(name)
91 if (lockdata[name, "pre"]) {
92 printh("#ifdef DEBUG_VFS_LOCKS");
93 printh("\t"lockdata[name, "pre"]"(&a);");
98 function add_debug_post(name)
100 if (lockdata[name, "post"]) {
101 printh("#ifdef DEBUG_VFS_LOCKS");
102 printh("\t"lockdata[name, "post"]"(&a, rc);");
107 function find_arg_with_type (type)
109 for (jj = 0; jj < numargs; jj++) {
110 if (types[jj] == type) {
111 return "VOPARG_OFFSETOF(struct " \
112 name "_args,a_" args[jj] ")";
116 return "VDESC_NO_OFFSET";
121 # Process the command line
122 for (i = 1; i < ARGC; i++) {
124 if (arg !~ /^-[ch]+$/ && arg !~ /\.src$/)
127 cfile = "vnode_if.c";
129 hfile = "vnode_if.h";
135 if (!cfile && !hfile)
143 " * This file is produced automatically.\n" \
144 " * Do not modify anything in here by hand.\n" \
146 " * Created from $DragonFly: src/sys/tools/Attic/vnode_if.awk,v 1.5 2004/03/07 12:48:34 eirikn Exp $\n" \
151 printh(common_head "extern struct vnodeop_desc vop_default_desc;");
155 "#include <sys/param.h>\n" \
156 "#include <sys/systm.h>\n" \
157 "#include <sys/vnode.h>\n" \
159 "struct vnodeop_desc vop_default_desc = {\n" \
160 " 1,\t\t\t/* special case, vop_default => 1 */\n" \
164 " VDESC_NO_OFFSET,\n" \
165 " VDESC_NO_OFFSET,\n" \
166 " VDESC_NO_OFFSET,\n" \
167 " VDESC_NO_OFFSET,\n" \
172 while ((getline < srcfile) > 0) {
176 if (NF != 6 || $1 != "#%" || \
177 $2 !~ /^[a-z]+$/ || $3 !~ /^[a-z]+$/ || \
178 $4 !~ /^.$/ || $5 !~ /^.$/ || $6 !~ /^.$/)
182 lockdata["vop_" $2, $3, "Entry"] = $4;
183 lockdata["vop_" $2, $3, "OK"] = $5;
184 lockdata["vop_" $2, $3, "Error"] = $6;
189 if (NF != 4 || $1 != "#!")
191 if ($3 != "pre" && $3 != "post")
193 lockdata["vop_" $2, $3] = $4;
199 # Get the function name.
201 uname = toupper(name);
203 # Get the function arguments.
204 for (numargs = 0; ; ++numargs) {
205 if ((getline < srcfile) <= 0) {
206 die("Unable to read through the arguments for \"%s\"",
212 # Delete comments, if any.
213 gsub (/\/\*.*\*\//, "");
215 # Condense whitespace and delete leading/trailing space.
216 gsub(/[[:space:]]+/, " ");
220 # Pick off direction.
221 if ($1 != "INOUT" && $1 != "IN" && $1 != "OUT")
222 die("No IN/OUT direction for \"%s\".", $0);
226 if ((reles[numargs] = $1) == "WILLRELE")
229 reles[numargs] = "WONTRELE";
232 if (sub(/;$/, "") < 1)
233 die("Missing end-of-line ; in \"%s\".", $0);
235 # pick off variable name
236 if ((argp = match($0, /[A-Za-z0-9_]+$/)) < 1)
237 die("Missing var name \"a_foo\" in \"%s\".", $0);
238 args[numargs] = substr($0, argp);
239 $0 = substr($0, 1, argp - 1);
241 # what is left must be type
242 # remove trailing space (if any)
249 # Print out the vop_F_args structure.
250 printh("struct "name"_args {\n\tstruct vnodeop_desc *a_desc;");
251 for (i = 0; i < numargs; ++i)
252 printh("\t" t_spc(types[i]) "a_" args[i] ";");
255 # Print out extern declaration.
256 printh("extern struct vnodeop_desc " name "_desc;");
258 # Print out prototype.
259 printh("static __inline int " uname "(");
260 for (i = 0; i < numargs; ++i) {
261 printh("\t" t_spc(types[i]) args[i] \
262 (i < numargs - 1 ? "," : ");"));
265 # Print out function.
266 printh("static __inline int " uname "(");
267 for (i = 0; i < numargs; ++i) {
268 printh("\t" t_spc(types[i]) args[i] \
269 (i < numargs - 1 ? "," : ")"));
271 printh("{\n\tstruct " name "_args a;");
273 printh("\ta.a_desc = VDESC(" name ");");
274 for (i = 0; i < numargs; ++i)
275 printh("\ta.a_" args[i] " = " args[i] ";");
276 for (i = 0; i < numargs; ++i)
277 add_debug_code(name, args[i], "Entry");
279 printh("\trc = VCALL(" args[0] ", VOFFSET(" name "), &a);");
280 printh("if (rc == 0) {");
281 for (i = 0; i < numargs; ++i)
282 add_debug_code(name, args[i], "OK");
284 for (i = 0; i < numargs; ++i)
285 add_debug_code(name, args[i], "Error");
287 add_debug_post(name);
288 printh("\treturn (rc);\n}");
292 # Print out the vop_F_vp_offsets structure. This all depends
293 # on naming conventions and nothing else.
294 printc("static int " name "_vp_offsets[] = {");
295 # as a side effect, figure out the releflags
298 for (i = 0; i < numargs; i++) {
299 if (types[i] == "struct vnode *") {
300 printc("\tVOPARG_OFFSETOF(struct " name \
301 "_args,a_" args[i] "),");
302 if (reles[i] == "WILLRELE") {
303 releflags = releflags \
304 "|VDESC_VP" vpnum "_WILLRELE";
310 sub(/^\|/, "", releflags);
311 printc("\tVDESC_NO_OFFSET");
314 # Print out the vnodeop_desc structure.
315 printc("struct vnodeop_desc " name "_desc = {");
319 printc("\t\"" name "\",");
322 for (i = 0; i < numargs; i++) {
323 if (types[i] == "struct vnode **" && \
324 reles[i] == "WILLRELE") {
325 vppwillrele = "|VDESC_VPP_WILLRELE";
331 printc("\t" releflags vppwillrele ",");
334 printc("\t" name "_vp_offsets,");
336 printc("\t" find_arg_with_type("struct vnode **") ",");
338 printc("\t" find_arg_with_type("struct ucred *") ",");
340 printc("\t" find_arg_with_type("struct proc *") ",");
342 printc("\t" find_arg_with_type("struct componentname *") ",");
343 # transport layer information
344 printc("\tNULL,\n};\n");