4 * Copyright (c) 1992, 1993, 1994, 1995
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. 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 SCRIPT_ID
='$NetBSD: vnode_if.sh,v 1.52 2009/09/29 11:51:02 pooka Exp $'
34 # Script to produce VFS front-end sugar.
36 # usage: vnode_if.sh srcfile
37 # (where srcfile is currently /sys/kern/vnode_if.src)
40 if [ $# -ne 1 ] ; then
41 echo 'usage: vnode_if.sh srcfile'
45 # Name and revision of the source file.
47 SRC_ID
=`head -1 $src | sed -e 's/.*\$\(.*\)\$.*/\1/'`
49 # Names of the created files.
51 out_rumpc
=..
/rump
/librump
/rumpvfs
/rumpvnode_if.c
52 out_h
=..
/sys
/vnode_if.h
53 out_rumph
=..
/rump
/include
/rump
/rumpvnode_if.h
55 # generate VNODE_LOCKDEBUG checks (not fully functional)
58 # Awk program (must support nawk extensions)
59 # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
62 # Does this awk have a "toupper" function? (i.e. is it GNU awk)
63 isgawk
=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
65 # If this awk does not define "toupper" then define our own.
66 if [ "$isgawk" = TRUE
] ; then
67 # GNU awk provides it.
70 # Provide our own toupper()
72 function toupper(str) {
73 _toupper_cmd = "echo "str" |tr a-z A-Z"
74 _toupper_cmd | getline _toupper_str;
81 # This is the common part of all awk programs that read $src
82 # This parses the input for one function into the arrays:
83 # argdir, argtype, argname, willrele
84 # and calls "doit()" to generate output for the function.
86 # Input to this parser is pre-processed slightly by sed
87 # so this awk parser doesn't have to work so hard. The
88 # changes done by the sed pre-processing step are:
89 # insert a space beween * and pointer name
90 # replace semicolons with spaces
92 sed_prep
='s:\*\([^\*/]\):\* \1:g
97 # First line of description
104 # Last line of description
109 # Middle lines of description
111 argdir[argc] = $1; i=2;
113 if ($2 == "LOCKED=YES") {
116 } else if ($2 == "LOCKED=NO") {
120 lockstate[argc] = -1;
122 if ($2 == "WILLRELE" ||
126 } else if ($2 == "WILLUNLOCK" ||
127 $3 == "WILLUNLOCK") {
130 } else if ($2 == "WILLPUT" ||
137 if ($2 == "WILLMAKE") {
142 # XXX: replace non-portable types for rump. We should really
143 # nuke the types from the kernel, but that is a battle for
146 if (length(rump) != 0) {
147 if (at == "vm_prot_t")
155 argtype[argc] = argtype[argc]" "$i;
164 # This is put before the copyright on each generated file.
169 * Warning: DO NOT EDIT! This file is automatically generated!
170 * (Modifications made here may easily be lost!)
172 * Created from the file:
179 # This is to satisfy McKusick (get rid of evil spaces 8^)
180 anal_retentive
='s:\([^/]\*\) :\1:g'
184 # Redirect stdout to the H file.
186 echo "$0: Creating $1" 1>&2
191 if [ -z "${rump}" ]; then
196 echo -n "$warning" |
sed -e 's/\$//g;s/@/\$/g;s/ $//'
200 echo "#ifndef _${SYS}VNODE_IF_H_"
201 echo "#define _${SYS}VNODE_IF_H_"
202 if [ ${lockdebug} -ne 0 ] ; then
204 echo '#ifdef _KERNEL_OPT'
205 echo '#include "opt_vnode_lockdebug.h"'
206 echo '#endif /* _KERNEL_OPT */'
209 extern const struct vnodeop_desc ${rump}vop_default_desc;
213 # This awk program needs toupper() so define it if necessary.
214 sed -e "$sed_prep" $src |
$awk -v rump
=${rump} "$toupper"'
216 # Declare arg struct, descriptor.
217 printf("\n#define %s_DESCOFFSET %d\n", toupper(name), vop_offset++);
218 printf("struct %s_args {\n", name);
219 printf("\tconst struct vnodeop_desc * a_desc;\n");
220 for (i=0; i<argc; i++) {
221 printf("\t%s a_%s;\n", argtype[i], argname[i]);
224 printf("extern const struct vnodeop_desc %s_desc;\n", name);
226 protoarg = sprintf("int %s(", toupper(name));
227 protolen = length(protoarg);
228 printf("%s", protoarg);
229 for (i=0; i<argc; i++) {
230 protoarg = sprintf("%s", argtype[i]);
231 if (i < (argc-1)) protoarg = (protoarg ", ");
232 arglen = length(protoarg);
233 if ((protolen + arglen) > 77) {
234 protoarg = ("\n " protoarg);
238 printf("%s", protoarg);
245 vop_offset = 1; # start at 1, to count the 'default
' op
247 printf("\n/* Special cases: */\nstruct buf;\n");
248 printf("#ifndef _KERNEL\n#include <stdbool.h>\n#endif\n\n");
251 argtype[0]="struct buf *";
254 arg0special="->b_vp";
255 name=rump "vop_bwrite";
257 printf("/* End of special cases */\n");
260 printf("\n#define VNODE_OPS_COUNT\t%d\n", vop_offset);
262 '"$awk_parser" |
sed -e "$anal_retentive"
266 /* End of special cases. */'
268 echo "#endif /* !_${SYS}VNODE_IF_H_ */"
271 do_hfile
$out_rumph 'rump_'
275 # Redirect stdout to the C file.
277 echo "$0: Creating $1" 1>&2
282 echo -n "$warning" |
sed -e 's/\$//g;s/@/\$/g;s/ $//'
286 #include <sys/cdefs.h>
287 __KERNEL_RCSID(0, \"\$NetBSD\$\");"
289 [ ${lockdebug} -ne 0 ] && echo && echo '#include "opt_vnode_lockdebug.h"'
292 #include <sys/param.h>
293 #include <sys/mount.h>
295 #include <sys/vnode.h>
296 #include <sys/lock.h>'
297 [ ! -z "${rump}" ] && echo '#include <rump/rumpvnode_if.h>' \
298 && echo '#include "rump_private.h"'
301 const struct vnodeop_desc ${rump}vop_default_desc = {"
314 sed -e "$sed_prep" $src |
$awk -v rump
=${rump} -v lockdebug
=${lockdebug} '
315 function do_offset(typematch) {
316 for (i=0; i<argc; i++) {
317 if (argtype[i] == typematch) {
318 printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n",
323 print "\tVDESC_NO_OFFSET,";
328 # Define offsets array
329 printf("\nconst int %s_vp_offsets[] = {\n", name);
330 for (i=0; i<argc; i++) {
331 if (argtype[i] == "struct vnode *") {
332 printf ("\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
336 print "\tVDESC_NO_OFFSET";
339 printf("const struct vnodeop_desc %s_desc = {\n", name);
341 printf ("\t%s_DESCOFFSET,\n", toupper(name));
343 printf ("\t\"%s\",\n", name);
347 for (i=0; i<argc; i++) {
349 if (willrele[i] == 2) {
351 } else if (willrele[i] == 3) {
356 if (argdir[i] ~ /OUT/) {
357 printf(" | VDESC_VPP_WILL%s", word);
359 printf(" | VDESC_VP%s_WILL%s", vpnum, word);
366 printf ("\t%s_vp_offsets,\n", name);
368 do_offset("struct vnode **");
370 do_offset("kauth_cred_t");
372 do_offset("struct componentname *");
373 # transport layer information
374 printf ("\tNULL,\n};\n");
377 printf("int\n%s(", toupper(name));
378 for (i=0; i<argc; i++) {
379 printf("%s %s", argtype[i], argname[i]);
380 if (i < (argc-1)) printf(",\n ");
383 printf("{\n\tint error;\n\tbool mpsafe;\n\tstruct %s_args a;\n", name);
385 printf("#ifdef VNODE_LOCKDEBUG\n");
386 for (i=0; i<argc; i++) {
387 if (lockstate[i] != -1)
388 printf("\tint islocked_%s;\n", argname[i]);
392 printf("\ta.a_desc = VDESC(%s);\n", name);
393 for (i=0; i<argc; i++) {
394 printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
395 if (lockdebug && lockstate[i] != -1) {
396 printf("#ifdef VNODE_LOCKDEBUG\n");
397 printf("\tislocked_%s = (%s->v_vflag & VV_LOCKSWORK) ? (VOP_ISLOCKED(%s) == LK_EXCLUSIVE) : %d;\n",
398 argname[i], argname[i], argname[i], lockstate[i]);
399 printf("\tif (islocked_%s != %d)\n", argname[i],
401 printf("\t\tpanic(\"%s: %s: locked %%d, expected %%d\", islocked_%s, %d);\n", name, argname[i], argname[i], lockstate[i]);
405 printf("\tmpsafe = (%s%s->v_vflag & VV_MPSAFE);\n", argname[0], arg0special);
407 printf("\trump_schedule();\n");
408 printf("\tif (!mpsafe) { KERNEL_LOCK(1, curlwp); }\n");
409 printf("\terror = (VCALL(%s%s, VOFFSET(%s), &a));\n",
410 argname[0], arg0special, name);
411 printf("\tif (!mpsafe) { KERNEL_UNLOCK_ONE(curlwp); }\n");
413 printf("\trump_unschedule();\n");
414 if (willmake != -1) {
415 printf("#ifdef DIAGNOSTIC\n");
416 printf("\tif (error == 0)\n" \
417 "\t\tKASSERT((*%s)->v_size != VSIZENOTSET\n" \
418 "\t\t && (*%s)->v_writesize != VSIZENOTSET);\n",
419 argname[willmake], argname[willmake]);
420 printf("#endif /* DIAGNOSTIC */\n");
422 printf("\treturn error;\n}\n");
425 printf("\n/* Special cases: */\n");
426 # start from 1 (vop_default is at 0)
430 argtype[0]="struct buf *";
433 arg0special="->b_vp";
435 name=rump "vop_bwrite";
437 printf("\n/* End of special cases */\n");
441 '"$awk_parser" |
sed -e "$anal_retentive"
445 /* End of special cases. */'
447 # Add the vfs_op_descs array to the C file.
450 const struct vnodeop_desc * const ${rump}vfs_op_descs[] = {
451 &${rump}vop_default_desc, /* MUST BE FIRST */
452 &${rump}vop_bwrite_desc, /* XXX: SPECIAL CASE */
456 sed -e "$sed_prep" $src |
$awk -v rump
=${rump} '
458 printf("\t&%s_desc,\n", name);
468 do_cfile
$out_rumpc 'rump_'