Home | History | Annotate | Line # | Download | only in kern
vnode_if.sh revision 1.53.4.1
      1       1.1   mycroft #!/bin/sh -
      2       1.9       cgd copyright="\
      3       1.2       gwr /*
      4      1.16      fvdl  * Copyright (c) 1992, 1993, 1994, 1995
      5       1.2       gwr  *	The Regents of the University of California.  All rights reserved.
      6       1.2       gwr  *
      7       1.2       gwr  * Redistribution and use in source and binary forms, with or without
      8       1.2       gwr  * modification, are permitted provided that the following conditions
      9       1.2       gwr  * are met:
     10       1.2       gwr  * 1. Redistributions of source code must retain the above copyright
     11       1.2       gwr  *    notice, this list of conditions and the following disclaimer.
     12       1.2       gwr  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.2       gwr  *    notice, this list of conditions and the following disclaimer in the
     14       1.2       gwr  *    documentation and/or other materials provided with the distribution.
     15      1.33       agc  * 3. Neither the name of the University nor the names of its contributors
     16       1.2       gwr  *    may be used to endorse or promote products derived from this software
     17       1.2       gwr  *    without specific prior written permission.
     18       1.2       gwr  *
     19      1.18  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS \`\`AS IS'' AND
     20       1.2       gwr  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21       1.2       gwr  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22       1.2       gwr  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23       1.2       gwr  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24       1.2       gwr  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25       1.2       gwr  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26       1.2       gwr  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27       1.2       gwr  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28       1.2       gwr  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29       1.2       gwr  * SUCH DAMAGE.
     30       1.2       gwr  */
     31       1.9       cgd "
     32  1.53.4.1     rmind SCRIPT_ID='$NetBSD: vnode_if.sh,v 1.53.4.1 2010/05/30 05:17:59 rmind Exp $'
     33       1.1   mycroft 
     34       1.1   mycroft # Script to produce VFS front-end sugar.
     35       1.1   mycroft #
     36       1.1   mycroft # usage: vnode_if.sh srcfile
     37       1.1   mycroft #	(where srcfile is currently /sys/kern/vnode_if.src)
     38       1.1   mycroft #
     39       1.1   mycroft 
     40       1.1   mycroft if [ $# -ne 1 ] ; then
     41       1.1   mycroft 	echo 'usage: vnode_if.sh srcfile'
     42       1.1   mycroft 	exit 1
     43       1.1   mycroft fi
     44       1.2       gwr 
     45       1.9       cgd # Name and revision of the source file.
     46       1.2       gwr src=$1
     47       1.9       cgd SRC_ID=`head -1 $src | sed -e 's/.*\$\(.*\)\$.*/\1/'`
     48       1.1   mycroft 
     49       1.1   mycroft # Names of the created files.
     50       1.2       gwr out_c=vnode_if.c
     51      1.51     pooka out_rumpc=../rump/librump/rumpvfs/rumpvnode_if.c
     52       1.9       cgd out_h=../sys/vnode_if.h
     53      1.50     pooka out_rumph=../rump/include/rump/rumpvnode_if.h
     54       1.2       gwr 
     55      1.52     pooka # generate VNODE_LOCKDEBUG checks (not fully functional)
     56      1.52     pooka lockdebug=0
     57      1.52     pooka 
     58       1.2       gwr # Awk program (must support nawk extensions)
     59       1.2       gwr # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
     60       1.2       gwr awk=${AWK:-awk}
     61       1.2       gwr 
     62       1.2       gwr # Does this awk have a "toupper" function? (i.e. is it GNU awk)
     63       1.2       gwr isgawk=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
     64       1.2       gwr 
     65       1.2       gwr # If this awk does not define "toupper" then define our own.
     66       1.2       gwr if [ "$isgawk" = TRUE ] ; then
     67       1.2       gwr 	# GNU awk provides it.
     68       1.2       gwr 	toupper=
     69       1.2       gwr else
     70       1.2       gwr 	# Provide our own toupper()
     71       1.2       gwr 	toupper='
     72       1.2       gwr function toupper(str) {
     73       1.2       gwr 	_toupper_cmd = "echo "str" |tr a-z A-Z"
     74       1.2       gwr 	_toupper_cmd | getline _toupper_str;
     75       1.2       gwr 	close(_toupper_cmd);
     76       1.2       gwr 	return _toupper_str;
     77       1.2       gwr }'
     78       1.2       gwr fi
     79       1.1   mycroft 
     80       1.2       gwr #
     81       1.2       gwr # This is the common part of all awk programs that read $src
     82       1.2       gwr # This parses the input for one function into the arrays:
     83       1.2       gwr #	argdir, argtype, argname, willrele
     84       1.2       gwr # and calls "doit()" to generate output for the function.
     85       1.2       gwr #
     86       1.2       gwr # Input to this parser is pre-processed slightly by sed
     87       1.2       gwr # so this awk parser doesn't have to work so hard.  The
     88       1.2       gwr # changes done by the sed pre-processing step are:
     89       1.2       gwr #	insert a space beween * and pointer name
     90       1.2       gwr #	replace semicolons with spaces
     91       1.2       gwr #
     92       1.2       gwr sed_prep='s:\*\([^\*/]\):\* \1:g
     93       1.2       gwr s/;/ /'
     94       1.2       gwr awk_parser='
     95       1.2       gwr # Comment line
     96       1.2       gwr /^#/	{ next; }
     97       1.2       gwr # First line of description
     98       1.2       gwr /^vop_/	{
     99  1.53.4.1     rmind 	name=$1;
    100       1.2       gwr 	argc=0;
    101      1.44     pooka 	willmake=-1;
    102       1.2       gwr 	next;
    103       1.2       gwr }
    104       1.2       gwr # Last line of description
    105       1.2       gwr /^}/	{
    106       1.2       gwr 	doit();
    107       1.2       gwr 	next;
    108       1.2       gwr }
    109       1.2       gwr # Middle lines of description
    110       1.2       gwr {
    111       1.2       gwr 	argdir[argc] = $1; i=2;
    112      1.35   thorpej 
    113      1.35   thorpej 	if ($2 == "LOCKED=YES") {
    114      1.35   thorpej 		lockstate[argc] = 1;
    115      1.35   thorpej 		i++;
    116      1.35   thorpej 	} else if ($2 == "LOCKED=NO") {
    117      1.35   thorpej 		lockstate[argc] = 0;
    118      1.35   thorpej 		i++;
    119      1.35   thorpej 	} else
    120      1.35   thorpej 		lockstate[argc] = -1;
    121      1.35   thorpej 
    122      1.35   thorpej 	if ($2 == "WILLRELE" ||
    123      1.35   thorpej 	    $3 == "WILLRELE") {
    124       1.2       gwr 		willrele[argc] = 1;
    125       1.2       gwr 		i++;
    126      1.35   thorpej 	} else if ($2 == "WILLUNLOCK" ||
    127      1.35   thorpej 		   $3 == "WILLUNLOCK") {
    128      1.19  wrstuden 		willrele[argc] = 2;
    129      1.19  wrstuden 		i++;
    130      1.35   thorpej 	} else if ($2 == "WILLPUT" ||
    131      1.35   thorpej 		   $3 == "WILLPUT") {
    132      1.19  wrstuden 		willrele[argc] = 3;
    133      1.19  wrstuden 		i++;
    134       1.2       gwr 	} else
    135       1.2       gwr 		willrele[argc] = 0;
    136      1.44     pooka 
    137      1.44     pooka 	if ($2 == "WILLMAKE") {
    138      1.44     pooka 		willmake=argc;
    139      1.44     pooka 		i++;
    140      1.44     pooka 	}
    141      1.44     pooka 
    142      1.50     pooka 	# XXX: replace non-portable types for rump.  We should really
    143      1.50     pooka 	# nuke the types from the kernel, but that is a battle for
    144      1.50     pooka 	# another day.
    145      1.50     pooka 	at = $i;
    146  1.53.4.1     rmind 	if (rump) {
    147      1.50     pooka 		if (at == "vm_prot_t")
    148      1.50     pooka 			at = "int";
    149      1.50     pooka 		if (at == "voff_t")
    150      1.50     pooka 			at = "off_t";
    151  1.53.4.1     rmind 		if (at == "kauth_cred_t")
    152  1.53.4.1     rmind 			at = "struct kauth_cred *"
    153      1.50     pooka 	}
    154      1.50     pooka 	argtype[argc] = at;
    155      1.50     pooka 	i++;
    156       1.2       gwr 	while (i < NF) {
    157       1.7       cgd 		argtype[argc] = argtype[argc]" "$i;
    158       1.2       gwr 		i++;
    159       1.2       gwr 	}
    160       1.2       gwr 	argname[argc] = $i;
    161       1.2       gwr 	argc++;
    162       1.2       gwr 	next;
    163       1.2       gwr }
    164       1.2       gwr '
    165       1.1   mycroft 
    166      1.15   thorpej # This is put before the copyright on each generated file.
    167       1.9       cgd warning="\
    168      1.15   thorpej /*	@NetBSD@	*/
    169      1.15   thorpej 
    170       1.1   mycroft /*
    171      1.37     perry  * Warning: DO NOT EDIT! This file is automatically generated!
    172       1.2       gwr  * (Modifications made here may easily be lost!)
    173       1.1   mycroft  *
    174       1.9       cgd  * Created from the file:
    175       1.9       cgd  *	${SRC_ID}
    176       1.9       cgd  * by the script:
    177       1.2       gwr  *	${SCRIPT_ID}
    178       1.1   mycroft  */
    179      1.36     perry "
    180       1.2       gwr 
    181       1.7       cgd # This is to satisfy McKusick (get rid of evil spaces 8^)
    182       1.7       cgd anal_retentive='s:\([^/]\*\) :\1:g'
    183       1.2       gwr 
    184      1.50     pooka do_hfile () {
    185       1.2       gwr #
    186       1.2       gwr # Redirect stdout to the H file.
    187       1.2       gwr #
    188      1.50     pooka echo "$0: Creating $1" 1>&2
    189      1.50     pooka exec > $1
    190      1.50     pooka rump=$2
    191       1.1   mycroft 
    192       1.2       gwr # Begin stuff
    193      1.50     pooka if [ -z "${rump}" ]; then
    194      1.50     pooka 	SYS='SYS_'
    195      1.50     pooka else
    196      1.50     pooka 	SYS='RUMP_RUMP'
    197      1.50     pooka fi
    198      1.38     perry echo -n "$warning" | sed -e 's/\$//g;s/@/\$/g;s/ $//'
    199       1.9       cgd echo ""
    200       1.9       cgd echo -n "$copyright"
    201      1.10     mikel echo ''
    202      1.50     pooka echo "#ifndef _${SYS}VNODE_IF_H_"
    203      1.50     pooka echo "#define _${SYS}VNODE_IF_H_"
    204      1.52     pooka if [ ${lockdebug} -ne 0 ] ; then
    205      1.52     pooka 	echo ''
    206      1.52     pooka 	echo '#ifdef _KERNEL_OPT'
    207      1.52     pooka 	echo '#include "opt_vnode_lockdebug.h"'
    208      1.52     pooka 	echo '#endif /* _KERNEL_OPT */'
    209      1.52     pooka fi
    210  1.53.4.1     rmind [ -z "${rump}" ] && echo "
    211  1.53.4.1     rmind extern const struct vnodeop_desc ${rump}vop_default_desc;"
    212  1.53.4.1     rmind echo
    213       1.1   mycroft 
    214       1.2       gwr # Body stuff
    215       1.2       gwr # This awk program needs toupper() so define it if necessary.
    216      1.50     pooka sed -e "$sed_prep" $src | $awk -v rump=${rump} "$toupper"'
    217       1.2       gwr function doit() {
    218  1.53.4.1     rmind 	name = rump name
    219       1.2       gwr 	# Declare arg struct, descriptor.
    220  1.53.4.1     rmind 	if (!rump) {
    221  1.53.4.1     rmind 		printf("\n#define %s_DESCOFFSET %d\n",
    222  1.53.4.1     rmind 		    toupper(name), vop_offset++);
    223  1.53.4.1     rmind 		printf("struct %s_args {\n", name);
    224  1.53.4.1     rmind 		printf("\tconst struct vnodeop_desc * a_desc;\n");
    225  1.53.4.1     rmind 		for (i=0; i<argc; i++) {
    226  1.53.4.1     rmind 			printf("\t%s a_%s;\n", argtype[i], argname[i]);
    227  1.53.4.1     rmind 		}
    228  1.53.4.1     rmind 		printf("};\n");
    229  1.53.4.1     rmind 		printf("extern const struct vnodeop_desc %s_desc;\n", name);
    230       1.1   mycroft 	}
    231       1.8    chopps 	# Prototype it.
    232      1.20   thorpej 	protoarg = sprintf("int %s(", toupper(name));
    233       1.8    chopps 	protolen = length(protoarg);
    234       1.8    chopps 	printf("%s", protoarg);
    235       1.8    chopps 	for (i=0; i<argc; i++) {
    236       1.8    chopps 		protoarg = sprintf("%s", argtype[i]);
    237       1.8    chopps 		if (i < (argc-1)) protoarg = (protoarg ", ");
    238       1.8    chopps 		arglen = length(protoarg);
    239       1.8    chopps 		if ((protolen + arglen) > 77) {
    240       1.8    chopps 			protoarg = ("\n    " protoarg);
    241       1.8    chopps 			arglen += 4;
    242       1.8    chopps 			protolen = 0;
    243       1.8    chopps 		}
    244       1.8    chopps 		printf("%s", protoarg);
    245       1.8    chopps 		protolen += arglen;
    246       1.8    chopps 	}
    247      1.39   thorpej 	printf(");\n");
    248       1.2       gwr }
    249       1.2       gwr BEGIN	{
    250       1.2       gwr 	arg0special="";
    251      1.43     pooka 	vop_offset = 1; # start at 1, to count the 'default' op
    252      1.43     pooka 
    253  1.53.4.1     rmind 	printf("struct buf;\n");
    254  1.53.4.1     rmind 	if (rump) {
    255  1.53.4.1     rmind 		printf("struct flock;\n");
    256  1.53.4.1     rmind 		printf("struct knote;\n");
    257  1.53.4.1     rmind 		printf("struct vm_page;\n");
    258  1.53.4.1     rmind 	}
    259  1.53.4.1     rmind 	printf("\n#ifndef _KERNEL\n#include <stdbool.h>\n#endif\n");
    260  1.53.4.1     rmind 	printf("\n/* Special cases: */\n");
    261      1.48        ad 
    262       1.2       gwr 	argc=1;
    263       1.2       gwr 	argtype[0]="struct buf *";
    264       1.2       gwr 	argname[0]="bp";
    265      1.35   thorpej 	lockstate[0] = -1;
    266       1.2       gwr 	arg0special="->b_vp";
    267  1.53.4.1     rmind 	name="vop_bwrite";
    268       1.2       gwr 	doit();
    269  1.53.4.1     rmind 	printf("\n/* End of special cases */\n");
    270  1.53.4.1     rmind 	if (rump)
    271  1.53.4.1     rmind 		printf("\n");
    272      1.43     pooka }
    273      1.43     pooka END	{
    274  1.53.4.1     rmind 	if (!rump) {
    275  1.53.4.1     rmind 		printf("\n#define VNODE_OPS_COUNT\t%d\n", vop_offset);
    276  1.53.4.1     rmind 	}
    277       1.2       gwr }
    278       1.7       cgd '"$awk_parser" | sed -e "$anal_retentive"
    279       1.1   mycroft 
    280       1.2       gwr # End stuff
    281      1.10     mikel echo ''
    282      1.50     pooka echo "#endif /* !_${SYS}VNODE_IF_H_ */"
    283      1.50     pooka }
    284      1.50     pooka do_hfile $out_h ''
    285      1.50     pooka do_hfile $out_rumph 'rump_'
    286       1.1   mycroft 
    287      1.50     pooka do_cfile () {
    288       1.2       gwr #
    289       1.2       gwr # Redirect stdout to the C file.
    290       1.2       gwr #
    291      1.50     pooka echo "$0: Creating $1" 1>&2
    292      1.50     pooka exec > $1
    293      1.50     pooka rump=$2
    294       1.1   mycroft 
    295       1.2       gwr # Begin stuff
    296      1.38     perry echo -n "$warning" | sed -e 's/\$//g;s/@/\$/g;s/ $//'
    297       1.9       cgd echo ""
    298       1.9       cgd echo -n "$copyright"
    299      1.30     lukem echo "
    300      1.30     lukem #include <sys/cdefs.h>
    301      1.52     pooka __KERNEL_RCSID(0, \"\$NetBSD\$\");"
    302      1.52     pooka 
    303      1.52     pooka [ ${lockdebug} -ne 0 ] && echo && echo '#include "opt_vnode_lockdebug.h"'
    304      1.30     lukem 
    305      1.21   thorpej echo '
    306       1.1   mycroft #include <sys/param.h>
    307       1.1   mycroft #include <sys/mount.h>
    308      1.20   thorpej #include <sys/buf.h>
    309       1.1   mycroft #include <sys/vnode.h>
    310      1.50     pooka #include <sys/lock.h>'
    311      1.53     pooka [ ! -z "${rump}" ] && echo '#include <rump/rumpvnode_if.h>'		\
    312      1.53     pooka 	&& echo '#include "rump_private.h"'
    313       1.1   mycroft 
    314  1.53.4.1     rmind if [ -z "${rump}" ] ; then
    315  1.53.4.1     rmind 	echo "
    316  1.53.4.1     rmind const struct vnodeop_desc vop_default_desc = {"
    317      1.50     pooka echo '	0,
    318       1.1   mycroft 	"default",
    319       1.1   mycroft 	0,
    320       1.1   mycroft 	NULL,
    321       1.1   mycroft 	VDESC_NO_OFFSET,
    322       1.1   mycroft 	VDESC_NO_OFFSET,
    323       1.1   mycroft 	VDESC_NO_OFFSET,
    324       1.1   mycroft };
    325       1.2       gwr '
    326  1.53.4.1     rmind fi
    327       1.1   mycroft 
    328       1.2       gwr # Body stuff
    329      1.52     pooka sed -e "$sed_prep" $src | $awk -v rump=${rump} -v lockdebug=${lockdebug} '
    330       1.2       gwr function do_offset(typematch) {
    331       1.2       gwr 	for (i=0; i<argc; i++) {
    332       1.2       gwr 		if (argtype[i] == typematch) {
    333       1.2       gwr 			printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n",
    334       1.2       gwr 				name, argname[i]);
    335       1.2       gwr 			return i;
    336       1.2       gwr 		};
    337       1.2       gwr 	};
    338       1.2       gwr 	print "\tVDESC_NO_OFFSET,";
    339       1.2       gwr 	return -1;
    340       1.2       gwr }
    341       1.1   mycroft 
    342  1.53.4.1     rmind function offsets() {
    343       1.2       gwr 	# Define offsets array
    344  1.53.4.1     rmind 	printf("const int %s_vp_offsets[] = {\n", name);
    345       1.2       gwr 	for (i=0; i<argc; i++) {
    346       1.2       gwr 		if (argtype[i] == "struct vnode *") {
    347       1.2       gwr 			printf ("\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
    348       1.2       gwr 				name, argname[i]);
    349       1.2       gwr 		}
    350       1.1   mycroft 	}
    351       1.2       gwr 	print "\tVDESC_NO_OFFSET";
    352       1.2       gwr 	print "};";
    353       1.2       gwr 	# Define F_desc
    354      1.28  jdolecek 	printf("const struct vnodeop_desc %s_desc = {\n", name);
    355       1.2       gwr 	# offset
    356      1.43     pooka 	printf ("\t%s_DESCOFFSET,\n", toupper(name));
    357       1.2       gwr 	# printable name
    358       1.2       gwr 	printf ("\t\"%s\",\n", name);
    359       1.2       gwr 	# flags
    360       1.2       gwr 	printf("\t0");
    361       1.2       gwr 	vpnum = 0;
    362       1.2       gwr 	for (i=0; i<argc; i++) {
    363       1.2       gwr 		if (willrele[i]) {
    364      1.19  wrstuden 			if (willrele[i] == 2) {
    365      1.19  wrstuden 				word = "UNLOCK";
    366      1.19  wrstuden 			} else if (willrele[i] == 3) {
    367      1.19  wrstuden 				word = "PUT";
    368      1.19  wrstuden 			} else {
    369      1.19  wrstuden 				word = "RELE";
    370      1.19  wrstuden 			}
    371       1.2       gwr 			if (argdir[i] ~ /OUT/) {
    372      1.19  wrstuden 				printf(" | VDESC_VPP_WILL%s", word);
    373       1.1   mycroft 			} else {
    374      1.19  wrstuden 				printf(" | VDESC_VP%s_WILL%s", vpnum, word);
    375       1.1   mycroft 			};
    376       1.2       gwr 			vpnum++;
    377       1.2       gwr 		}
    378       1.1   mycroft 	}
    379       1.2       gwr 	print ",";
    380       1.2       gwr 	# vp offsets
    381       1.2       gwr 	printf ("\t%s_vp_offsets,\n", name);
    382       1.2       gwr 	# vpp (if any)
    383       1.2       gwr 	do_offset("struct vnode **");
    384       1.2       gwr 	# cred (if any)
    385      1.42      elad 	do_offset("kauth_cred_t");
    386       1.2       gwr 	# componentname
    387       1.2       gwr 	do_offset("struct componentname *");
    388  1.53.4.1     rmind 	printf ("};\n");
    389  1.53.4.1     rmind }
    390      1.20   thorpej 
    391  1.53.4.1     rmind function bodyrump() {
    392  1.53.4.1     rmind 	printf("{\n\tint error;\n\n");
    393  1.53.4.1     rmind 	printf("\trump_schedule();\n");
    394  1.53.4.1     rmind 	printf("\terror = %s(", toupper(name));
    395      1.20   thorpej 	for (i=0; i<argc; i++) {
    396  1.53.4.1     rmind 		printf("%s", argname[i]);
    397  1.53.4.1     rmind 		if (i < (argc-1)) printf(", ");
    398      1.20   thorpej 	}
    399  1.53.4.1     rmind 	printf(");\n");
    400  1.53.4.1     rmind 	printf("\trump_unschedule();\n\n");
    401  1.53.4.1     rmind 	printf("\treturn error;\n}\n");
    402  1.53.4.1     rmind }
    403  1.53.4.1     rmind 
    404  1.53.4.1     rmind function bodynorm() {
    405      1.46        ad 	printf("{\n\tint error;\n\tbool mpsafe;\n\tstruct %s_args a;\n", name);
    406      1.52     pooka 	if (lockdebug) {
    407      1.52     pooka 		printf("#ifdef VNODE_LOCKDEBUG\n");
    408      1.52     pooka 		for (i=0; i<argc; i++) {
    409      1.52     pooka 			if (lockstate[i] != -1)
    410      1.52     pooka 				printf("\tint islocked_%s;\n", argname[i]);
    411      1.52     pooka 		}
    412      1.52     pooka 		printf("#endif\n");
    413      1.35   thorpej 	}
    414      1.20   thorpej 	printf("\ta.a_desc = VDESC(%s);\n", name);
    415      1.20   thorpej 	for (i=0; i<argc; i++) {
    416      1.20   thorpej 		printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
    417      1.52     pooka 		if (lockdebug && lockstate[i] != -1) {
    418      1.35   thorpej 			printf("#ifdef VNODE_LOCKDEBUG\n");
    419      1.45        ad 			printf("\tislocked_%s = (%s->v_vflag & VV_LOCKSWORK) ? (VOP_ISLOCKED(%s) == LK_EXCLUSIVE) : %d;\n",
    420      1.35   thorpej 			    argname[i], argname[i], argname[i], lockstate[i]);
    421      1.35   thorpej 			printf("\tif (islocked_%s != %d)\n", argname[i],
    422      1.35   thorpej 			    lockstate[i]);
    423      1.35   thorpej 			printf("\t\tpanic(\"%s: %s: locked %%d, expected %%d\", islocked_%s, %d);\n", name, argname[i], argname[i], lockstate[i]);
    424      1.35   thorpej 			printf("#endif\n");
    425      1.35   thorpej 		}
    426      1.20   thorpej 	}
    427      1.46        ad 	printf("\tmpsafe = (%s%s->v_vflag & VV_MPSAFE);\n", argname[0], arg0special);
    428      1.46        ad 	printf("\tif (!mpsafe) { KERNEL_LOCK(1, curlwp); }\n");
    429      1.46        ad 	printf("\terror = (VCALL(%s%s, VOFFSET(%s), &a));\n",
    430      1.20   thorpej 		argname[0], arg0special, name);
    431      1.46        ad 	printf("\tif (!mpsafe) { KERNEL_UNLOCK_ONE(curlwp); }\n");
    432      1.44     pooka 	if (willmake != -1) {
    433      1.44     pooka 		printf("#ifdef DIAGNOSTIC\n");
    434      1.46        ad 		printf("\tif (error == 0)\n"				\
    435      1.44     pooka 		    "\t\tKASSERT((*%s)->v_size != VSIZENOTSET\n"	\
    436      1.44     pooka 		    "\t\t    && (*%s)->v_writesize != VSIZENOTSET);\n",
    437      1.44     pooka 		    argname[willmake], argname[willmake]);
    438      1.44     pooka 		printf("#endif /* DIAGNOSTIC */\n");
    439      1.44     pooka 	}
    440      1.46        ad 	printf("\treturn error;\n}\n");
    441      1.20   thorpej }
    442  1.53.4.1     rmind 
    443  1.53.4.1     rmind function doit() {
    444  1.53.4.1     rmind 	printf("\n");
    445  1.53.4.1     rmind 	if (!rump)
    446  1.53.4.1     rmind 		offsets();
    447  1.53.4.1     rmind 
    448  1.53.4.1     rmind 	if (rump)
    449  1.53.4.1     rmind 		extname = "RUMP_" toupper(name);
    450  1.53.4.1     rmind 	else
    451  1.53.4.1     rmind 		extname = toupper(name);
    452  1.53.4.1     rmind 
    453  1.53.4.1     rmind 	# Define function.
    454  1.53.4.1     rmind 	printf("int\n%s(", extname);
    455  1.53.4.1     rmind 	for (i=0; i<argc; i++) {
    456  1.53.4.1     rmind 		printf("%s %s", argtype[i], argname[i]);
    457  1.53.4.1     rmind 		if (i < (argc-1)) printf(",\n    ");
    458  1.53.4.1     rmind 	}
    459  1.53.4.1     rmind 	printf(")\n");
    460  1.53.4.1     rmind 
    461  1.53.4.1     rmind 	if (rump)
    462  1.53.4.1     rmind 		bodyrump();
    463  1.53.4.1     rmind 	else
    464  1.53.4.1     rmind 		bodynorm();
    465  1.53.4.1     rmind }
    466      1.20   thorpej BEGIN	{
    467       1.2       gwr 	printf("\n/* Special cases: */\n");
    468      1.28  jdolecek 	# start from 1 (vop_default is at 0)
    469       1.2       gwr 	argc=1;
    470      1.44     pooka 	willmake=-1;
    471       1.2       gwr 	argdir[0]="IN";
    472       1.2       gwr 	argtype[0]="struct buf *";
    473       1.2       gwr 	argname[0]="bp";
    474      1.35   thorpej 	lockstate[0] = -1;
    475      1.20   thorpej 	arg0special="->b_vp";
    476       1.2       gwr 	willrele[0]=0;
    477  1.53.4.1     rmind 	name="vop_bwrite";
    478       1.2       gwr 	doit();
    479      1.28  jdolecek 	printf("\n/* End of special cases */\n");
    480      1.28  jdolecek 
    481      1.28  jdolecek 	arg0special="";
    482       1.1   mycroft }
    483       1.7       cgd '"$awk_parser" | sed -e "$anal_retentive"
    484       1.1   mycroft 
    485       1.2       gwr # End stuff
    486  1.53.4.1     rmind [ -n "${rump}" ] && return
    487       1.1   mycroft 
    488       1.2       gwr # Add the vfs_op_descs array to the C file.
    489       1.2       gwr # Begin stuff
    490      1.50     pooka echo "
    491      1.50     pooka const struct vnodeop_desc * const ${rump}vfs_op_descs[] = {
    492      1.50     pooka 	&${rump}vop_default_desc,	/* MUST BE FIRST */
    493      1.50     pooka 	&${rump}vop_bwrite_desc,	/* XXX: SPECIAL CASE */
    494      1.50     pooka "
    495       1.2       gwr 
    496       1.2       gwr # Body stuff
    497      1.50     pooka sed -e "$sed_prep" $src | $awk -v rump=${rump} '
    498       1.2       gwr function doit() {
    499       1.2       gwr 	printf("\t&%s_desc,\n", name);
    500       1.1   mycroft }
    501       1.2       gwr '"$awk_parser"
    502       1.1   mycroft 
    503       1.2       gwr # End stuff
    504       1.2       gwr echo '	NULL
    505  1.53.4.1     rmind };'
    506      1.50     pooka }
    507      1.50     pooka do_cfile $out_c ''
    508      1.50     pooka do_cfile $out_rumpc 'rump_'
    509       1.1   mycroft 
    510       1.2       gwr exit 0
    511       1.1   mycroft 
    512       1.2       gwr # Local Variables:
    513       1.2       gwr # tab-width: 4
    514       1.2       gwr # End:
    515