Home | History | Annotate | Line # | Download | only in kern
vnode_if.sh revision 1.29
      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.29 2001/05/07 08:46:02 lukem 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 echo '#ifdef _KERNEL'
    165 echo '#if defined(_LKM) || defined(LKM)'
    166 echo '/* LKMs always use non-inlined vnode ops. */'
    167 echo '#define	VNODE_OP_NOINLINE'
    168 echo '#else'
    169 echo '#include "opt_vnode_op_noinline.h"'
    170 echo '#endif'
    171 echo '#endif /* _KERNEL */'
    172 echo '
    173 extern const struct vnodeop_desc vop_default_desc;
    174 '
    175 
    176 # Body stuff
    177 # This awk program needs toupper() so define it if necessary.
    178 sed -e "$sed_prep" $src | $awk "$toupper"'
    179 function doit() {
    180 	# Declare arg struct, descriptor.
    181 	printf("\nstruct %s_args {\n", name);
    182 	printf("\tconst struct vnodeop_desc * a_desc;\n");
    183 	for (i=0; i<argc; i++) {
    184 		printf("\t%s a_%s;\n", argtype[i], argname[i]);
    185 	}
    186 	printf("};\n");
    187 	printf("extern const struct vnodeop_desc %s_desc;\n", name);
    188 	# Prototype it.
    189 	printf("#ifndef VNODE_OP_NOINLINE\n");
    190 	printf("static __inline\n");
    191 	printf("#endif\n");
    192 	protoarg = sprintf("int %s(", toupper(name));
    193 	protolen = length(protoarg);
    194 	printf("%s", protoarg);
    195 	for (i=0; i<argc; i++) {
    196 		protoarg = sprintf("%s", argtype[i]);
    197 		if (i < (argc-1)) protoarg = (protoarg ", ");
    198 		arglen = length(protoarg);
    199 		if ((protolen + arglen) > 77) {
    200 			protoarg = ("\n    " protoarg);
    201 			arglen += 4;
    202 			protolen = 0;
    203 		}
    204 		printf("%s", protoarg);
    205 		protolen += arglen;
    206 	}
    207 	printf(")\n");
    208 	printf("#ifndef VNODE_OP_NOINLINE\n");
    209 	printf("__attribute__((__unused__))\n");
    210 	printf("#endif\n");
    211 	printf(";\n");
    212 	# Define inline function.
    213 	printf("#ifndef VNODE_OP_NOINLINE\n");
    214 	printf("static __inline int %s(", toupper(name));
    215 	for (i=0; i<argc; i++) {
    216 		printf("%s", argname[i]);
    217 		if (i < (argc-1)) printf(", ");
    218 	}
    219 	printf(")\n");
    220 	for (i=0; i<argc; i++) {
    221 		printf("\t%s %s;\n", argtype[i], argname[i]);
    222 	}
    223 	printf("{\n\tstruct %s_args a;\n", name);
    224 	printf("\ta.a_desc = VDESC(%s);\n", name);
    225 	for (i=0; i<argc; i++) {
    226 		printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
    227 	}
    228 	printf("\treturn (VCALL(%s%s, VOFFSET(%s), &a));\n}\n",
    229 		argname[0], arg0special, name);
    230 	printf("#endif\n");
    231 	vops++;
    232 }
    233 BEGIN	{
    234 	arg0special="";
    235 	vops = 1; # start at 1, to count the 'default' op
    236 }
    237 END	{
    238 	printf("\n/* Special cases: */\n#include <sys/buf.h>\n");
    239 	argc=1;
    240 	argtype[0]="struct buf *";
    241 	argname[0]="bp";
    242 	arg0special="->b_vp";
    243 	name="vop_strategy";
    244 	doit();
    245 	name="vop_bwrite";
    246 	doit();
    247 
    248 	printf("\n#define VNODE_OPS_COUNT\t%d\n", vops);
    249 }
    250 '"$awk_parser" | sed -e "$anal_retentive"
    251 
    252 # End stuff
    253 echo '
    254 /* End of special cases. */'
    255 echo ''
    256 echo '#endif /* !_SYS_VNODE_IF_H_ */'
    257 
    258 #
    259 # Redirect stdout to the C file.
    260 #
    261 echo "$0: Creating $out_c" 1>&2
    262 exec > $out_c
    263 
    264 # Begin stuff
    265 echo -n "$warning" | sed -e 's/\$//g;s/@/\$/g'
    266 echo ""
    267 echo -n "$copyright"
    268 echo '
    269 /*
    270  * If we have LKM support, always include the non-inline versions for
    271  * LKMs.  Otherwise, do it based on the option.
    272  */
    273 #ifdef LKM
    274 #define	VNODE_OP_NOINLINE
    275 #else
    276 #include "opt_vnode_op_noinline.h"
    277 #endif'
    278 echo '
    279 #include <sys/param.h>
    280 #include <sys/mount.h>
    281 #include <sys/buf.h>
    282 #include <sys/vnode.h>
    283 
    284 const struct vnodeop_desc vop_default_desc = {
    285 	0,
    286 	"default",
    287 	0,
    288 	NULL,
    289 	VDESC_NO_OFFSET,
    290 	VDESC_NO_OFFSET,
    291 	VDESC_NO_OFFSET,
    292 	VDESC_NO_OFFSET,
    293 	NULL,
    294 };
    295 '
    296 
    297 # Body stuff
    298 sed -e "$sed_prep" $src | $awk '
    299 function do_offset(typematch) {
    300 	for (i=0; i<argc; i++) {
    301 		if (argtype[i] == typematch) {
    302 			printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n",
    303 				name, argname[i]);
    304 			return i;
    305 		};
    306 	};
    307 	print "\tVDESC_NO_OFFSET,";
    308 	return -1;
    309 }
    310 
    311 function doit() {
    312 	# Define offsets array
    313 	printf("\nconst int %s_vp_offsets[] = {\n", name);
    314 	for (i=0; i<argc; i++) {
    315 		if (argtype[i] == "struct vnode *") {
    316 			printf ("\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
    317 				name, argname[i]);
    318 		}
    319 	}
    320 	print "\tVDESC_NO_OFFSET";
    321 	print "};";
    322 	# Define F_desc
    323 	printf("const struct vnodeop_desc %s_desc = {\n", name);
    324 	# offset
    325 	printf ("\t%d,\n", vop_offset++);
    326 	# printable name
    327 	printf ("\t\"%s\",\n", name);
    328 	# flags
    329 	printf("\t0");
    330 	vpnum = 0;
    331 	for (i=0; i<argc; i++) {
    332 		if (willrele[i]) {
    333 			if (willrele[i] == 2) {
    334 				word = "UNLOCK";
    335 			} else if (willrele[i] == 3) {
    336 				word = "PUT";
    337 			} else {
    338 				word = "RELE";
    339 			}
    340 			if (argdir[i] ~ /OUT/) {
    341 				printf(" | VDESC_VPP_WILL%s", word);
    342 			} else {
    343 				printf(" | VDESC_VP%s_WILL%s", vpnum, word);
    344 			};
    345 			vpnum++;
    346 		}
    347 	}
    348 	print ",";
    349 	# vp offsets
    350 	printf ("\t%s_vp_offsets,\n", name);
    351 	# vpp (if any)
    352 	do_offset("struct vnode **");
    353 	# cred (if any)
    354 	do_offset("struct ucred *");
    355 	# proc (if any)
    356 	do_offset("struct proc *");
    357 	# componentname
    358 	do_offset("struct componentname *");
    359 	# transport layer information
    360 	printf ("\tNULL,\n};\n");
    361 
    362 	# Define function.
    363 	printf("#ifdef VNODE_OP_NOINLINE\n");
    364 	printf("int\n%s(", toupper(name));
    365 	for (i=0; i<argc; i++) {
    366 		printf("%s", argname[i]);
    367 		if (i < (argc-1)) printf(", ");
    368 	}
    369 	printf(")\n");
    370 	for (i=0; i<argc; i++) {
    371 		printf("\t%s %s;\n", argtype[i], argname[i]);
    372 	}
    373 	printf("{\n\tstruct %s_args a;\n", name);
    374 	printf("\ta.a_desc = VDESC(%s);\n", name);
    375 	for (i=0; i<argc; i++) {
    376 		printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
    377 	}
    378 	printf("\treturn (VCALL(%s%s, VOFFSET(%s), &a));\n}\n",
    379 		argname[0], arg0special, name);
    380 	printf("#endif\n");
    381 }
    382 BEGIN	{
    383 	printf("\n/* Special cases: */\n");
    384 	# start from 1 (vop_default is at 0)
    385 	vop_offset=1;
    386 	argc=1;
    387 	argdir[0]="IN";
    388 	argtype[0]="struct buf *";
    389 	argname[0]="bp";
    390 	arg0special="->b_vp";
    391 	willrele[0]=0;
    392 	name="vop_strategy";
    393 	doit();
    394 	name="vop_bwrite";
    395 	doit();
    396 	printf("\n/* End of special cases */\n");
    397 
    398 	arg0special="";
    399 }
    400 '"$awk_parser" | sed -e "$anal_retentive"
    401 
    402 # End stuff
    403 echo '
    404 /* End of special cases. */'
    405 
    406 # Add the vfs_op_descs array to the C file.
    407 # Begin stuff
    408 echo '
    409 const struct vnodeop_desc * const vfs_op_descs[] = {
    410 	&vop_default_desc,	/* MUST BE FIRST */
    411 	&vop_strategy_desc,	/* XXX: SPECIAL CASE */
    412 	&vop_bwrite_desc,	/* XXX: SPECIAL CASE */
    413 '
    414 
    415 # Body stuff
    416 sed -e "$sed_prep" $src | $awk '
    417 function doit() {
    418 	printf("\t&%s_desc,\n", name);
    419 }
    420 '"$awk_parser"
    421 
    422 # End stuff
    423 echo '	NULL
    424 };
    425 '
    426 
    427 exit 0
    428 
    429 # Local Variables:
    430 # tab-width: 4
    431 # End:
    432