Home | History | Annotate | Line # | Download | only in kern
vnode_if.sh revision 1.20
      1 #!/bin/sh -
      2 copyright="\
      3 /*
      4  * Copyright (c) 1992, 1993, 1994, 1995
      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  * 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.
     22  *
     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
     33  * SUCH DAMAGE.
     34  */
     35 "
     36 SCRIPT_ID='$NetBSD: vnode_if.sh,v 1.20 2000/09/13 15:50:26 thorpej Exp $'
     37 
     38 # Script to produce VFS front-end sugar.
     39 #
     40 # usage: vnode_if.sh srcfile
     41 #	(where srcfile is currently /sys/kern/vnode_if.src)
     42 #
     43 
     44 if [ $# -ne 1 ] ; then
     45 	echo 'usage: vnode_if.sh srcfile'
     46 	exit 1
     47 fi
     48 
     49 # Name and revision of the source file.
     50 src=$1
     51 SRC_ID=`head -1 $src | sed -e 's/.*\$\(.*\)\$.*/\1/'`
     52 
     53 # Names of the created files.
     54 out_c=vnode_if.c
     55 out_h=../sys/vnode_if.h
     56 
     57 # Awk program (must support nawk extensions)
     58 # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
     59 awk=${AWK:-awk}
     60 
     61 # Does this awk have a "toupper" function? (i.e. is it GNU awk)
     62 isgawk=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
     63 
     64 # If this awk does not define "toupper" then define our own.
     65 if [ "$isgawk" = TRUE ] ; then
     66 	# GNU awk provides it.
     67 	toupper=
     68 else
     69 	# Provide our own toupper()
     70 	toupper='
     71 function toupper(str) {
     72 	_toupper_cmd = "echo "str" |tr a-z A-Z"
     73 	_toupper_cmd | getline _toupper_str;
     74 	close(_toupper_cmd);
     75 	return _toupper_str;
     76 }'
     77 fi
     78 
     79 #
     80 # This is the common part of all awk programs that read $src
     81 # This parses the input for one function into the arrays:
     82 #	argdir, argtype, argname, willrele
     83 # and calls "doit()" to generate output for the function.
     84 #
     85 # Input to this parser is pre-processed slightly by sed
     86 # so this awk parser doesn't have to work so hard.  The
     87 # changes done by the sed pre-processing step are:
     88 #	insert a space beween * and pointer name
     89 #	replace semicolons with spaces
     90 #
     91 sed_prep='s:\*\([^\*/]\):\* \1:g
     92 s/;/ /'
     93 awk_parser='
     94 # Comment line
     95 /^#/	{ next; }
     96 # First line of description
     97 /^vop_/	{
     98 	name=$1;
     99 	argc=0;
    100 	next;
    101 }
    102 # Last line of description
    103 /^}/	{
    104 	doit();
    105 	next;
    106 }
    107 # Middle lines of description
    108 {
    109 	argdir[argc] = $1; i=2;
    110 	if ($2 == "WILLRELE") {
    111 		willrele[argc] = 1;
    112 		i++;
    113 	} else if ($2 == "WILLUNLOCK") {
    114 		willrele[argc] = 2;
    115 		i++;
    116 	} else if ($2 == "WILLPUT") {
    117 		willrele[argc] = 3;
    118 		i++;
    119 	} else
    120 		willrele[argc] = 0;
    121 	argtype[argc] = $i; i++;
    122 	while (i < NF) {
    123 		argtype[argc] = argtype[argc]" "$i;
    124 		i++;
    125 	}
    126 	argname[argc] = $i;
    127 	argc++;
    128 	next;
    129 }
    130 '
    131 
    132 # This is put before the copyright on each generated file.
    133 warning="\
    134 /*	@NetBSD@	*/
    135 
    136 /*
    137  * Warning: This file is generated automatically.
    138  * (Modifications made here may easily be lost!)
    139  *
    140  * Created from the file:
    141  *	${SRC_ID}
    142  * by the script:
    143  *	${SCRIPT_ID}
    144  */
    145 " 
    146 
    147 # This is to satisfy McKusick (get rid of evil spaces 8^)
    148 anal_retentive='s:\([^/]\*\) :\1:g'
    149 
    150 #
    151 # Redirect stdout to the H file.
    152 #
    153 echo "$0: Creating $out_h" 1>&2
    154 exec > $out_h
    155 
    156 # Begin stuff
    157 echo -n "$warning" | sed -e 's/\$//g;s/@/\$/g'
    158 echo ""
    159 echo -n "$copyright"
    160 echo ''
    161 echo '#ifndef _SYS_VNODE_IF_H_'
    162 echo '#define _SYS_VNODE_IF_H_'
    163 echo '
    164 extern struct vnodeop_desc vop_default_desc;
    165 '
    166 
    167 # Body stuff
    168 # This awk program needs toupper() so define it if necessary.
    169 sed -e "$sed_prep" $src | $awk "$toupper"'
    170 function doit() {
    171 	# Declare arg struct, descriptor.
    172 	printf("\nstruct %s_args {\n", name);
    173 	printf("\tstruct vnodeop_desc * a_desc;\n");
    174 	for (i=0; i<argc; i++) {
    175 		printf("\t%s a_%s;\n", argtype[i], argname[i]);
    176 	}
    177 	printf("};\n");
    178 	printf("extern struct vnodeop_desc %s_desc;\n", name);
    179 	# Prototype it.
    180 	printf("#ifndef VNODE_OP_NOINLINE\n");
    181 	printf("static __inline\n");
    182 	printf("#endif\n");
    183 	protoarg = sprintf("int %s(", toupper(name));
    184 	protolen = length(protoarg);
    185 	printf("%s", protoarg);
    186 	for (i=0; i<argc; i++) {
    187 		protoarg = sprintf("%s", argtype[i]);
    188 		if (i < (argc-1)) protoarg = (protoarg ", ");
    189 		arglen = length(protoarg);
    190 		if ((protolen + arglen) > 77) {
    191 			protoarg = ("\n    " protoarg);
    192 			arglen += 4;
    193 			protolen = 0;
    194 		}
    195 		printf("%s", protoarg);
    196 		protolen += arglen;
    197 	}
    198 	printf(")\n");
    199 	printf("#ifndef VNODE_OP_NOINLINE\n");
    200 	printf("__attribute__((__unused__))\n");
    201 	printf("#endif\n");
    202 	printf(";\n");
    203 	# Define inline function.
    204 	printf("#ifndef VNODE_OP_NOINLINE\n");
    205 	printf("static __inline int %s(", toupper(name));
    206 	for (i=0; i<argc; i++) {
    207 		printf("%s", argname[i]);
    208 		if (i < (argc-1)) printf(", ");
    209 	}
    210 	printf(")\n");
    211 	for (i=0; i<argc; i++) {
    212 		printf("\t%s %s;\n", argtype[i], argname[i]);
    213 	}
    214 	printf("{\n\tstruct %s_args a;\n", name);
    215 	printf("\ta.a_desc = VDESC(%s);\n", name);
    216 	for (i=0; i<argc; i++) {
    217 		printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
    218 	}
    219 	printf("\treturn (VCALL(%s%s, VOFFSET(%s), &a));\n}\n",
    220 		argname[0], arg0special, name);
    221 	printf("#endif\n");
    222 }
    223 BEGIN	{
    224 	arg0special="";
    225 }
    226 END	{
    227 	printf("\n/* Special cases: */\n#include <sys/buf.h>\n");
    228 	argc=1;
    229 	argtype[0]="struct buf *";
    230 	argname[0]="bp";
    231 	arg0special="->b_vp";
    232 	name="vop_strategy";
    233 	doit();
    234 	name="vop_bwrite";
    235 	doit();
    236 }
    237 '"$awk_parser" | sed -e "$anal_retentive"
    238 
    239 # End stuff
    240 echo '
    241 /* End of special cases. */'
    242 echo ''
    243 echo '#endif /* !_SYS_VNODE_IF_H_ */'
    244 
    245 #
    246 # Redirect stdout to the C file.
    247 #
    248 echo "$0: Creating $out_c" 1>&2
    249 exec > $out_c
    250 
    251 # Begin stuff
    252 echo -n "$warning" | sed -e 's/\$//g;s/@/\$/g'
    253 echo ""
    254 echo -n "$copyright"
    255 echo '
    256 #include <sys/param.h>
    257 #include <sys/mount.h>
    258 #include <sys/buf.h>
    259 #include <sys/vnode.h>
    260 
    261 struct vnodeop_desc vop_default_desc = {
    262 	0,
    263 	"default",
    264 	0,
    265 	NULL,
    266 	VDESC_NO_OFFSET,
    267 	VDESC_NO_OFFSET,
    268 	VDESC_NO_OFFSET,
    269 	VDESC_NO_OFFSET,
    270 	NULL,
    271 };
    272 '
    273 
    274 # Body stuff
    275 sed -e "$sed_prep" $src | $awk '
    276 function do_offset(typematch) {
    277 	for (i=0; i<argc; i++) {
    278 		if (argtype[i] == typematch) {
    279 			printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n",
    280 				name, argname[i]);
    281 			return i;
    282 		};
    283 	};
    284 	print "\tVDESC_NO_OFFSET,";
    285 	return -1;
    286 }
    287 
    288 function doit() {
    289 	# Define offsets array
    290 	printf("\nint %s_vp_offsets[] = {\n", name);
    291 	for (i=0; i<argc; i++) {
    292 		if (argtype[i] == "struct vnode *") {
    293 			printf ("\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
    294 				name, argname[i]);
    295 		}
    296 	}
    297 	print "\tVDESC_NO_OFFSET";
    298 	print "};";
    299 	# Define F_desc
    300 	printf("struct vnodeop_desc %s_desc = {\n", name);
    301 	# offset
    302 	printf ("\t0,\n");
    303 	# printable name
    304 	printf ("\t\"%s\",\n", name);
    305 	# flags
    306 	printf("\t0");
    307 	vpnum = 0;
    308 	for (i=0; i<argc; i++) {
    309 		if (willrele[i]) {
    310 			if (willrele[i] == 2) {
    311 				word = "UNLOCK";
    312 			} else if (willrele[i] == 3) {
    313 				word = "PUT";
    314 			} else {
    315 				word = "RELE";
    316 			}
    317 			if (argdir[i] ~ /OUT/) {
    318 				printf(" | VDESC_VPP_WILL%s", word);
    319 			} else {
    320 				printf(" | VDESC_VP%s_WILL%s", vpnum, word);
    321 			};
    322 			vpnum++;
    323 		}
    324 	}
    325 	print ",";
    326 	# vp offsets
    327 	printf ("\t%s_vp_offsets,\n", name);
    328 	# vpp (if any)
    329 	do_offset("struct vnode **");
    330 	# cred (if any)
    331 	do_offset("struct ucred *");
    332 	# proc (if any)
    333 	do_offset("struct proc *");
    334 	# componentname
    335 	do_offset("struct componentname *");
    336 	# transport layer information
    337 	printf ("\tNULL,\n};\n");
    338 
    339 	# Define function.
    340 	printf("#ifdef VNODE_OP_NOINLINE\n");
    341 	printf("int\n%s(", toupper(name));
    342 	for (i=0; i<argc; i++) {
    343 		printf("%s", argname[i]);
    344 		if (i < (argc-1)) printf(", ");
    345 	}
    346 	printf(")\n");
    347 	for (i=0; i<argc; i++) {
    348 		printf("\t%s %s;\n", argtype[i], argname[i]);
    349 	}
    350 	printf("{\n\tstruct %s_args a;\n", name);
    351 	printf("\ta.a_desc = VDESC(%s);\n", name);
    352 	for (i=0; i<argc; i++) {
    353 		printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
    354 	}
    355 	printf("\treturn (VCALL(%s%s, VOFFSET(%s), &a));\n}\n",
    356 		argname[0], arg0special, name);
    357 	printf("#endif\n");
    358 }
    359 BEGIN	{
    360 	arg0special="";
    361 }
    362 END	{
    363 	printf("\n/* Special cases: */\n");
    364 	argc=1;
    365 	argdir[0]="IN";
    366 	argtype[0]="struct buf *";
    367 	argname[0]="bp";
    368 	arg0special="->b_vp";
    369 	willrele[0]=0;
    370 	name="vop_strategy";
    371 	doit();
    372 	name="vop_bwrite";
    373 	doit();
    374 }
    375 '"$awk_parser" | sed -e "$anal_retentive"
    376 
    377 # End stuff
    378 echo '
    379 /* End of special cases. */'
    380 
    381 # Add the vfs_op_descs array to the C file.
    382 # Begin stuff
    383 echo '
    384 struct vnodeop_desc *vfs_op_descs[] = {
    385 	&vop_default_desc,	/* MUST BE FIRST */
    386 	&vop_strategy_desc,	/* XXX: SPECIAL CASE */
    387 	&vop_bwrite_desc,	/* XXX: SPECIAL CASE */
    388 '
    389 
    390 # Body stuff
    391 sed -e "$sed_prep" $src | $awk '
    392 function doit() {
    393 	printf("\t&%s_desc,\n", name);
    394 }
    395 '"$awk_parser"
    396 
    397 # End stuff
    398 echo '	NULL
    399 };
    400 '
    401 
    402 exit 0
    403 
    404 # Local Variables:
    405 # tab-width: 4
    406 # End:
    407