Deleted Added
full compact
vnode_if.awk (139825) vnode_if.awk (140165)
1#!/usr/bin/awk -f
2
3#-
4# Copyright (c) 1992, 1993
5# The Regents of the University of California. All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
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.
18#
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
29# SUCH DAMAGE.
30
31#
32# @(#)vnode_if.sh 8.1 (Berkeley) 6/10/93
1#!/usr/bin/awk -f
2
3#-
4# Copyright (c) 1992, 1993
5# The Regents of the University of California. All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
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.
18#
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
29# SUCH DAMAGE.
30
31#
32# @(#)vnode_if.sh 8.1 (Berkeley) 6/10/93
33# $FreeBSD: head/sys/tools/vnode_if.awk 139825 2005-01-07 02:29:27Z imp $
33# $FreeBSD: head/sys/tools/vnode_if.awk 140165 2005-01-13 07:53:01Z phk $
34#
35# Script to produce VFS front-end sugar.
36#
37# usage: vnode_if.awk <srcfile> [-c | -h]
38# (where <srcfile> is currently /sys/kern/vnode_if.src)
39#
40
41function usage()
42{
43 print "usage: vnode_if.awk <srcfile> [-c|-h|-p|-q]";
44 exit 1;
45}
46
47function die(msg, what)
48{
49 printf msg "\n", what > "/dev/stderr";
50 exit 1;
51}
52
53function t_spc(type)
54{
55 # Append a space if the type is not a pointer
56 return (type ~ /\*$/) ? type : type " ";
57}
58
59# These are just for convenience ...
60function printc(s) {print s > cfile;}
61function printh(s) {print s > hfile;}
62function printp(s) {print s > pfile;}
63function printq(s) {print s > qfile;}
64
34#
35# Script to produce VFS front-end sugar.
36#
37# usage: vnode_if.awk <srcfile> [-c | -h]
38# (where <srcfile> is currently /sys/kern/vnode_if.src)
39#
40
41function usage()
42{
43 print "usage: vnode_if.awk <srcfile> [-c|-h|-p|-q]";
44 exit 1;
45}
46
47function die(msg, what)
48{
49 printf msg "\n", what > "/dev/stderr";
50 exit 1;
51}
52
53function t_spc(type)
54{
55 # Append a space if the type is not a pointer
56 return (type ~ /\*$/) ? type : type " ";
57}
58
59# These are just for convenience ...
60function printc(s) {print s > cfile;}
61function printh(s) {print s > hfile;}
62function printp(s) {print s > pfile;}
63function printq(s) {print s > qfile;}
64
65function add_debug_code(name, arg, pos)
65function add_debug_code(name, arg, pos, ind)
66{
67 if (arg == "vpp")
66{
67 if (arg == "vpp")
68 arg = "*vpp";
68 star = "*";
69 else
70 star = "";
69 if (lockdata[name, arg, pos] && (lockdata[name, arg, pos] != "-")) {
70 if (arg ~ /^\*/) {
71 if (lockdata[name, arg, pos] && (lockdata[name, arg, pos] != "-")) {
72 if (arg ~ /^\*/) {
71 printh("\tif ("substr(arg, 2)" != NULL) {");
73 printc(ind"if ("substr(arg, 2)" != NULL) {");
72 }
74 }
73 printh("\tASSERT_VI_UNLOCKED("arg", \""uname"\");");
75 printc(ind"ASSERT_VI_UNLOCKED("star"a->a_"arg", \""uname"\");");
74 # Add assertions for locking
75 if (lockdata[name, arg, pos] == "L")
76 # Add assertions for locking
77 if (lockdata[name, arg, pos] == "L")
76 printh("\tASSERT_VOP_LOCKED("arg", \""uname"\");");
78 printc(ind"ASSERT_VOP_LOCKED(" star "a->a_"arg", \""uname"\");");
77 else if (lockdata[name, arg, pos] == "U")
79 else if (lockdata[name, arg, pos] == "U")
78 printh("\tASSERT_VOP_UNLOCKED("arg", \""uname"\");");
80 printc(ind"ASSERT_VOP_UNLOCKED(" star "a->a_"arg", \""uname"\");");
79 else if (0) {
80 # XXX More checks!
81 }
82 if (arg ~ /^\*/) {
81 else if (0) {
82 # XXX More checks!
83 }
84 if (arg ~ /^\*/) {
83 printh("\t}");
85 printc("ind}");
84 }
85 }
86}
87
88function add_debug_pre(name)
89{
90 if (lockdata[name, "pre"]) {
86 }
87 }
88}
89
90function add_debug_pre(name)
91{
92 if (lockdata[name, "pre"]) {
91 printh("#ifdef DEBUG_VFS_LOCKS");
92 printh("\t"lockdata[name, "pre"]"(&a);");
93 printh("#endif");
93 printc("#ifdef DEBUG_VFS_LOCKS");
94 printc("\t"lockdata[name, "pre"]"(a);");
95 printc("#endif");
94 }
95}
96
97function add_debug_post(name)
98{
99 if (lockdata[name, "post"]) {
96 }
97}
98
99function add_debug_post(name)
100{
101 if (lockdata[name, "post"]) {
100 printh("#ifdef DEBUG_VFS_LOCKS");
101 printh("\t"lockdata[name, "post"]"(&a, rc);");
102 printh("#endif");
102 printc("#ifdef DEBUG_VFS_LOCKS");
103 printc("\t"lockdata[name, "post"]"(a, rc);");
104 printc("#endif");
103 }
104}
105
106function find_arg_with_type (type)
107{
108 for (jj = 0; jj < numargs; jj++) {
109 if (types[jj] == type) {
110 return "VOPARG_OFFSETOF(struct " \
111 name "_args,a_" args[jj] ")";
112 }
113 }
114
115 return "VDESC_NO_OFFSET";
116}
117
118BEGIN{
119
120# Process the command line
121for (i = 1; i < ARGC; i++) {
122 arg = ARGV[i];
123 if (arg !~ /^-[chpq]+$/ && arg !~ /\.src$/)
124 usage();
125 if (arg ~ /^-.*c/)
126 cfile = "vnode_if.c";
127 if (arg ~ /^-.*h/)
128 hfile = "vnode_if.h";
129 if (arg ~ /^-.*p/)
130 pfile = "vnode_if_newproto.h";
131 if (arg ~ /^-.*q/)
132 qfile = "vnode_if_typedef.h";
133 if (arg ~ /\.src$/)
134 srcfile = arg;
135}
136ARGC = 1;
137
138if (!cfile && !hfile && !pfile && !qfile)
139 exit 0;
140
141if (!srcfile)
142 usage();
143
144common_head = \
145 "/*\n" \
146 " * This file is produced automatically.\n" \
147 " * Do not modify anything in here by hand.\n" \
148 " *\n" \
105 }
106}
107
108function find_arg_with_type (type)
109{
110 for (jj = 0; jj < numargs; jj++) {
111 if (types[jj] == type) {
112 return "VOPARG_OFFSETOF(struct " \
113 name "_args,a_" args[jj] ")";
114 }
115 }
116
117 return "VDESC_NO_OFFSET";
118}
119
120BEGIN{
121
122# Process the command line
123for (i = 1; i < ARGC; i++) {
124 arg = ARGV[i];
125 if (arg !~ /^-[chpq]+$/ && arg !~ /\.src$/)
126 usage();
127 if (arg ~ /^-.*c/)
128 cfile = "vnode_if.c";
129 if (arg ~ /^-.*h/)
130 hfile = "vnode_if.h";
131 if (arg ~ /^-.*p/)
132 pfile = "vnode_if_newproto.h";
133 if (arg ~ /^-.*q/)
134 qfile = "vnode_if_typedef.h";
135 if (arg ~ /\.src$/)
136 srcfile = arg;
137}
138ARGC = 1;
139
140if (!cfile && !hfile && !pfile && !qfile)
141 exit 0;
142
143if (!srcfile)
144 usage();
145
146common_head = \
147 "/*\n" \
148 " * This file is produced automatically.\n" \
149 " * Do not modify anything in here by hand.\n" \
150 " *\n" \
149 " * Created from $FreeBSD: head/sys/tools/vnode_if.awk 139825 2005-01-07 02:29:27Z imp $\n" \
151 " * Created from $FreeBSD: head/sys/tools/vnode_if.awk 140165 2005-01-13 07:53:01Z phk $\n" \
150 " */\n" \
151 "\n";
152
153if (pfile) {
154 printp(common_head)
155 printp("struct vop_vector {")
156 printp("\tstruct vop_vector\t*vop_default;")
157 printp("\tvop_bypass_t\t*vop_bypass;")
158}
159
160if (qfile) {
161 printq(common_head)
152 " */\n" \
153 "\n";
154
155if (pfile) {
156 printp(common_head)
157 printp("struct vop_vector {")
158 printp("\tstruct vop_vector\t*vop_default;")
159 printp("\tvop_bypass_t\t*vop_bypass;")
160}
161
162if (qfile) {
163 printq(common_head)
162 printq("struct vop_generic_args;")
163 printq("typedef int vop_bypass_t(struct vop_generic_args *);\n")
164}
165
166if (hfile) {
167 printh(common_head "extern struct vnodeop_desc vop_default_desc;");
168 printh("#include \"vnode_if_typedef.h\"")
169 printh("#include \"vnode_if_newproto.h\"")
170}
171
172if (cfile) {
173 printc(common_head \
174 "#include <sys/param.h>\n" \
175 "#include <sys/systm.h>\n" \
176 "#include <sys/vnode.h>\n" \
177 "\n" \
178 "struct vnodeop_desc vop_default_desc = {\n" \
164}
165
166if (hfile) {
167 printh(common_head "extern struct vnodeop_desc vop_default_desc;");
168 printh("#include \"vnode_if_typedef.h\"")
169 printh("#include \"vnode_if_newproto.h\"")
170}
171
172if (cfile) {
173 printc(common_head \
174 "#include <sys/param.h>\n" \
175 "#include <sys/systm.h>\n" \
176 "#include <sys/vnode.h>\n" \
177 "\n" \
178 "struct vnodeop_desc vop_default_desc = {\n" \
179 " 1,\t\t\t/* special case, vop_default => 1 */\n" \
180 " \"default\",\n" \
181 " 0,\n" \
179 " \"default\",\n" \
180 " 0,\n" \
181 " (void *)(uintptr_t)vop_panic,\n" \
182 " NULL,\n" \
183 " VDESC_NO_OFFSET,\n" \
184 " VDESC_NO_OFFSET,\n" \
185 " VDESC_NO_OFFSET,\n" \
186 " VDESC_NO_OFFSET,\n" \
187 " NULL,\n" \
188 "};\n");
189}
190
191while ((getline < srcfile) > 0) {
192 if (NF == 0)
193 continue;
194 if ($1 ~ /^#%/) {
195 if (NF != 6 || $1 != "#%" || \
196 $2 !~ /^[a-z]+$/ || $3 !~ /^[a-z]+$/ || \
197 $4 !~ /^.$/ || $5 !~ /^.$/ || $6 !~ /^.$/)
198 continue;
182 " NULL,\n" \
183 " VDESC_NO_OFFSET,\n" \
184 " VDESC_NO_OFFSET,\n" \
185 " VDESC_NO_OFFSET,\n" \
186 " VDESC_NO_OFFSET,\n" \
187 " NULL,\n" \
188 "};\n");
189}
190
191while ((getline < srcfile) > 0) {
192 if (NF == 0)
193 continue;
194 if ($1 ~ /^#%/) {
195 if (NF != 6 || $1 != "#%" || \
196 $2 !~ /^[a-z]+$/ || $3 !~ /^[a-z]+$/ || \
197 $4 !~ /^.$/ || $5 !~ /^.$/ || $6 !~ /^.$/)
198 continue;
199 if ($3 == "vpp")
200 $3 = "*vpp";
201 lockdata["vop_" $2, $3, "Entry"] = $4;
202 lockdata["vop_" $2, $3, "OK"] = $5;
203 lockdata["vop_" $2, $3, "Error"] = $6;
204 continue;
205 }
206
207 if ($1 ~ /^#!/) {
208 if (NF != 4 || $1 != "#!")
209 continue;
210 if ($3 != "pre" && $3 != "post")
211 continue;
212 lockdata["vop_" $2, $3] = $4;
213 continue;
214 }
215 if ($1 ~ /^#/)
216 continue;
217
218 # Get the function name.
219 name = $1;
220 uname = toupper(name);
221
222 # Start constructing a ktrpoint string
223 ctrstr = "\"" uname;
224 # Get the function arguments.
225 for (numargs = 0; ; ++numargs) {
226 if ((getline < srcfile) <= 0) {
227 die("Unable to read through the arguments for \"%s\"",
228 name);
229 }
230 if ($1 ~ /^\};/)
231 break;
232
233 # Delete comments, if any.
234 gsub (/\/\*.*\*\//, "");
235
236 # Condense whitespace and delete leading/trailing space.
237 gsub(/[[:space:]]+/, " ");
238 sub(/^ /, "");
239 sub(/ $/, "");
240
241 # Pick off direction.
242 if ($1 != "INOUT" && $1 != "IN" && $1 != "OUT")
243 die("No IN/OUT direction for \"%s\".", $0);
244 dirs[numargs] = $1;
245 sub(/^[A-Z]* /, "");
246
247 if ((reles[numargs] = $1) == "WILLRELE")
248 sub(/^[A-Z]* /, "");
249 else
250 reles[numargs] = "WONTRELE";
251
252 # kill trailing ;
253 if (sub(/;$/, "") < 1)
254 die("Missing end-of-line ; in \"%s\".", $0);
255
256 # pick off variable name
257 if ((argp = match($0, /[A-Za-z0-9_]+$/)) < 1)
258 die("Missing var name \"a_foo\" in \"%s\".", $0);
259 args[numargs] = substr($0, argp);
260 $0 = substr($0, 1, argp - 1);
261
262 # what is left must be type
263 # remove trailing space (if any)
264 sub(/ $/, "");
265 types[numargs] = $0;
266
267 # We can do a maximum of 6 arguments to CTR*
268 if (numargs <= 6) {
269 if (numargs == 0)
270 ctrstr = ctrstr "(" args[numargs];
271 else
272 ctrstr = ctrstr ", " args[numargs];
273 if (types[numargs] ~ /\*/)
274 ctrstr = ctrstr " 0x%lX";
275 else
276 ctrstr = ctrstr " %ld";
277 }
278 }
279 if (numargs > 6)
280 ctrargs = 6;
281 else
282 ctrargs = numargs;
199 lockdata["vop_" $2, $3, "Entry"] = $4;
200 lockdata["vop_" $2, $3, "OK"] = $5;
201 lockdata["vop_" $2, $3, "Error"] = $6;
202 continue;
203 }
204
205 if ($1 ~ /^#!/) {
206 if (NF != 4 || $1 != "#!")
207 continue;
208 if ($3 != "pre" && $3 != "post")
209 continue;
210 lockdata["vop_" $2, $3] = $4;
211 continue;
212 }
213 if ($1 ~ /^#/)
214 continue;
215
216 # Get the function name.
217 name = $1;
218 uname = toupper(name);
219
220 # Start constructing a ktrpoint string
221 ctrstr = "\"" uname;
222 # Get the function arguments.
223 for (numargs = 0; ; ++numargs) {
224 if ((getline < srcfile) <= 0) {
225 die("Unable to read through the arguments for \"%s\"",
226 name);
227 }
228 if ($1 ~ /^\};/)
229 break;
230
231 # Delete comments, if any.
232 gsub (/\/\*.*\*\//, "");
233
234 # Condense whitespace and delete leading/trailing space.
235 gsub(/[[:space:]]+/, " ");
236 sub(/^ /, "");
237 sub(/ $/, "");
238
239 # Pick off direction.
240 if ($1 != "INOUT" && $1 != "IN" && $1 != "OUT")
241 die("No IN/OUT direction for \"%s\".", $0);
242 dirs[numargs] = $1;
243 sub(/^[A-Z]* /, "");
244
245 if ((reles[numargs] = $1) == "WILLRELE")
246 sub(/^[A-Z]* /, "");
247 else
248 reles[numargs] = "WONTRELE";
249
250 # kill trailing ;
251 if (sub(/;$/, "") < 1)
252 die("Missing end-of-line ; in \"%s\".", $0);
253
254 # pick off variable name
255 if ((argp = match($0, /[A-Za-z0-9_]+$/)) < 1)
256 die("Missing var name \"a_foo\" in \"%s\".", $0);
257 args[numargs] = substr($0, argp);
258 $0 = substr($0, 1, argp - 1);
259
260 # what is left must be type
261 # remove trailing space (if any)
262 sub(/ $/, "");
263 types[numargs] = $0;
264
265 # We can do a maximum of 6 arguments to CTR*
266 if (numargs <= 6) {
267 if (numargs == 0)
268 ctrstr = ctrstr "(" args[numargs];
269 else
270 ctrstr = ctrstr ", " args[numargs];
271 if (types[numargs] ~ /\*/)
272 ctrstr = ctrstr " 0x%lX";
273 else
274 ctrstr = ctrstr " %ld";
275 }
276 }
277 if (numargs > 6)
278 ctrargs = 6;
279 else
280 ctrargs = numargs;
283 ctrstr = "\tCTR" ctrargs "(KTR_VOP, " ctrstr ")\"";
284 for (i = 0; i < ctrargs; ++i)
285 ctrstr = ctrstr ", " args[i];
281 ctrstr = "\tCTR" ctrargs "(KTR_VOP,\n\t " ctrstr ")\",\n\t ";
282 ctrstr = ctrstr "a->a_" args[0];
283 for (i = 1; i < ctrargs; ++i)
284 ctrstr = ctrstr ", a->a_" args[i];
286 ctrstr = ctrstr ");";
287
288 if (pfile) {
289 printp("\t"name"_t\t*"name";")
290 }
291 if (qfile) {
292 printq("struct "name"_args;")
293 printq("typedef int "name"_t(struct "name"_args *);\n")
294 }
295
296 if (hfile) {
297 # Print out the vop_F_args structure.
298 printh("struct "name"_args {\n\tstruct vop_generic_args a_gen;");
299 for (i = 0; i < numargs; ++i)
300 printh("\t" t_spc(types[i]) "a_" args[i] ";");
301 printh("};");
285 ctrstr = ctrstr ");";
286
287 if (pfile) {
288 printp("\t"name"_t\t*"name";")
289 }
290 if (qfile) {
291 printq("struct "name"_args;")
292 printq("typedef int "name"_t(struct "name"_args *);\n")
293 }
294
295 if (hfile) {
296 # Print out the vop_F_args structure.
297 printh("struct "name"_args {\n\tstruct vop_generic_args a_gen;");
298 for (i = 0; i < numargs; ++i)
299 printh("\t" t_spc(types[i]) "a_" args[i] ";");
300 printh("};");
301 printh("");
302
303 # Print out extern declaration.
304 printh("extern struct vnodeop_desc " name "_desc;");
302
303 # Print out extern declaration.
304 printh("extern struct vnodeop_desc " name "_desc;");
305 printh("");
305
306
306 # Print out function.
307 # Print out function prototypes.
308 printh("int " uname "_AP(struct " name "_args *);");
309 printh("");
307 printh("static __inline int " uname "(");
308 for (i = 0; i < numargs; ++i) {
309 printh("\t" t_spc(types[i]) args[i] \
310 (i < numargs - 1 ? "," : ")"));
311 }
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 ? "," : ")"));
314 }
312 printh("{\n\tstruct " name "_args a;");
313 printh("\tint rc;");
315 printh("{");
316 printh("\tstruct " name "_args a;");
317 printh("");
314 printh("\ta.a_gen.a_desc = VDESC(" name ");");
315 for (i = 0; i < numargs; ++i)
316 printh("\ta.a_" args[i] " = " args[i] ";");
318 printh("\ta.a_gen.a_desc = VDESC(" name ");");
319 for (i = 0; i < numargs; ++i)
320 printh("\ta.a_" args[i] " = " args[i] ";");
317 for (i = 0; i < numargs; ++i)
318 add_debug_code(name, args[i], "Entry");
319 add_debug_pre(name);
320 printh("\t{")
321 printh("\t\tstruct vop_vector *vop = "args[0]"->v_op;")
322 printh("\t\twhile(vop != NULL && vop->"name" == NULL && vop->vop_bypass == NULL)")
323 printh("\t\t\tvop = vop->vop_default;")
324 printh("\t\tKASSERT(vop != NULL, (\"No "name"(%p...)\", "args[0]"));")
325 printh("\t\tif (vop->"name" != NULL)")
326 printh("\t\t\trc = vop->"name"(&a);")
327 printh("\t\telse")
328 printh("\t\t\trc = vop->vop_bypass(&a.a_gen);")
329 printh("\t}")
330 printh(ctrstr);
331 printh("if (rc == 0) {");
332 for (i = 0; i < numargs; ++i)
333 add_debug_code(name, args[i], "OK");
334 printh("} else {");
335 for (i = 0; i < numargs; ++i)
336 add_debug_code(name, args[i], "Error");
321 printh("\treturn (" uname "_AP(&a));");
337 printh("}");
322 printh("}");
338 add_debug_post(name);
339 printh("\treturn (rc);\n}");
323
324 printh("");
340 }
341
342 if (cfile) {
343 # Print out the vop_F_vp_offsets structure. This all depends
344 # on naming conventions and nothing else.
345 printc("static int " name "_vp_offsets[] = {");
346 # as a side effect, figure out the releflags
347 releflags = "";
348 vpnum = 0;
349 for (i = 0; i < numargs; i++) {
350 if (types[i] == "struct vnode *") {
351 printc("\tVOPARG_OFFSETOF(struct " name \
352 "_args,a_" args[i] "),");
353 if (reles[i] == "WILLRELE") {
354 releflags = releflags \
355 "|VDESC_VP" vpnum "_WILLRELE";
356 }
357 vpnum++;
358 }
359 }
360
361 sub(/^\|/, "", releflags);
362 printc("\tVDESC_NO_OFFSET");
363 printc("};");
364
325 }
326
327 if (cfile) {
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
332 releflags = "";
333 vpnum = 0;
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";
341 }
342 vpnum++;
343 }
344 }
345
346 sub(/^\|/, "", releflags);
347 printc("\tVDESC_NO_OFFSET");
348 printc("};");
349
350 # Print out function.
351 printc("\nint\n" uname "_AP(struct " name "_args *a)");
352 printc("{");
353 printc("\tint rc;");
354 printc("\tstruct vnode *vp = a->a_" args[0]";");
355 printc("\tstruct vop_vector *vop = vp->v_op;");
356 printc("");
357 printc("\tKASSERT(a->a_gen.a_desc == VDESC(" name "),");
358 printc("\t (\"Wrong a_desc in " name "(%p, %p)\", vp, a));");
359 printc("\twhile(vop != NULL && \\");
360 printc("\t vop->"name" == NULL && vop->vop_bypass == NULL)")
361 printc("\t\tvop = vop->vop_default;")
362 printc("\tKASSERT(vop != NULL, (\"No "name"(%p, %p)\", vp, a));")
363 for (i = 0; i < numargs; ++i)
364 add_debug_code(name, args[i], "Entry", "\t");
365 add_debug_pre(name);
366 printc("\tif (vop->"name" != NULL)")
367 printc("\t\trc = vop->"name"(a);")
368 printc("\telse")
369 printc("\t\trc = vop->vop_bypass(&a->a_gen);")
370 printc(ctrstr);
371 printc("\tif (rc == 0) {");
372 for (i = 0; i < numargs; ++i)
373 add_debug_code(name, args[i], "OK", "\t\t");
374 printc("\t} else {");
375 for (i = 0; i < numargs; ++i)
376 add_debug_code(name, args[i], "Error", "\t\t");
377 printc("\t}");
378 add_debug_post(name);
379 printc("\treturn (rc);");
380 printc("}\n");
381
365 # Print out the vnodeop_desc structure.
366 printc("struct vnodeop_desc " name "_desc = {");
382 # Print out the vnodeop_desc structure.
383 printc("struct vnodeop_desc " name "_desc = {");
367 # offset
368 printc("\toffsetof(struct vop_vector, "name"),");
369 # printable name
370 printc("\t\"" name "\",");
371 # flags
372 vppwillrele = "";
373 for (i = 0; i < numargs; i++) {
374 if (types[i] == "struct vnode **" && \
375 reles[i] == "WILLRELE") {
376 vppwillrele = "|VDESC_VPP_WILLRELE";
377 }
378 }
379
380 if (!releflags)
381 releflags = "0";
382 printc("\t" releflags vppwillrele ",");
383
384 # printable name
385 printc("\t\"" name "\",");
386 # flags
387 vppwillrele = "";
388 for (i = 0; i < numargs; i++) {
389 if (types[i] == "struct vnode **" && \
390 reles[i] == "WILLRELE") {
391 vppwillrele = "|VDESC_VPP_WILLRELE";
392 }
393 }
394
395 if (!releflags)
396 releflags = "0";
397 printc("\t" releflags vppwillrele ",");
398
399 # function to call
400 printc("\t(void*)(uintptr_t)" uname "_AP,");
384 # vp offsets
385 printc("\t" name "_vp_offsets,");
386 # vpp (if any)
387 printc("\t" find_arg_with_type("struct vnode **") ",");
388 # cred (if any)
389 printc("\t" find_arg_with_type("struct ucred *") ",");
390 # thread (if any)
391 printc("\t" find_arg_with_type("struct thread *") ",");
392 # componentname
393 printc("\t" find_arg_with_type("struct componentname *") ",");
394 # transport layer information
395 printc("\tNULL,\n};\n");
396 }
397}
398
399if (pfile)
400 printp("};")
401
402if (hfile)
403 close(hfile);
404if (cfile)
405 close(cfile);
406if (pfile)
407 close(pfile);
408close(srcfile);
409
410exit 0;
411
412}
401 # vp offsets
402 printc("\t" name "_vp_offsets,");
403 # vpp (if any)
404 printc("\t" find_arg_with_type("struct vnode **") ",");
405 # cred (if any)
406 printc("\t" find_arg_with_type("struct ucred *") ",");
407 # thread (if any)
408 printc("\t" find_arg_with_type("struct thread *") ",");
409 # componentname
410 printc("\t" find_arg_with_type("struct componentname *") ",");
411 # transport layer information
412 printc("\tNULL,\n};\n");
413 }
414}
415
416if (pfile)
417 printp("};")
418
419if (hfile)
420 close(hfile);
421if (cfile)
422 close(cfile);
423if (pfile)
424 close(pfile);
425close(srcfile);
426
427exit 0;
428
429}