Home | History | Annotate | Line # | Download | only in kern
vnode_if.sh revision 1.11
      1 #!/bin/sh -
      2 copyright="\
      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  * 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.11 1997/07/07 20:17:36 cgd 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
    114 		willrele[argc] = 0;
    115 	argtype[argc] = $i; i++;
    116 	while (i < NF) {
    117 		argtype[argc] = argtype[argc]" "$i;
    118 		i++;
    119 	}
    120 	argname[argc] = $i;
    121 	argc++;
    122 	next;
    123 }
    124 '
    125 
    126 # This is put after the copyright on each generated file.
    127 warning="\
    128 /*
    129  * Warning: This file is generated automatically.
    130  * (Modifications made here may easily be lost!)
    131  *
    132  * Created from the file:
    133  *	${SRC_ID}
    134  * by the script:
    135  *	${SCRIPT_ID}
    136  */
    137 " 
    138 
    139 # This is to satisfy McKusick (get rid of evil spaces 8^)
    140 anal_retentive='s:\([^/]\*\) :\1:g'
    141 
    142 #
    143 # Redirect stdout to the H file.
    144 #
    145 echo "$0: Creating $out_h" 1>&2
    146 exec > $out_h
    147 
    148 # Begin stuff
    149 echo -n "$warning" | sed -e 's/\$//g'
    150 echo ""
    151 echo -n "$copyright"
    152 echo ''
    153 echo '#ifndef _SYS_VNODE_IF_H_'
    154 echo '#define _SYS_VNODE_IF_H_'
    155 echo '
    156 extern struct vnodeop_desc vop_default_desc;
    157 '
    158 
    159 # Body stuff
    160 # This awk program needs toupper() so define it if necessary.
    161 sed -e "$sed_prep" $src | $awk "$toupper"'
    162 function doit() {
    163 	# Declare arg struct, descriptor.
    164 	printf("\nstruct %s_args {\n", name);
    165 	printf("\tstruct vnodeop_desc * a_desc;\n");
    166 	for (i=0; i<argc; i++) {
    167 		printf("\t%s a_%s;\n", argtype[i], argname[i]);
    168 	}
    169 	printf("};\n");
    170 	printf("extern struct vnodeop_desc %s_desc;\n", name);
    171 	# Prototype it.
    172 	protoarg = sprintf("static __inline int %s __P((", toupper(name));
    173 	protolen = length(protoarg);
    174 	printf("%s", protoarg);
    175 	for (i=0; i<argc; i++) {
    176 		protoarg = sprintf("%s", argtype[i]);
    177 		if (i < (argc-1)) protoarg = (protoarg ", ");
    178 		arglen = length(protoarg);
    179 		if (i == (argc-1))
    180 			arglen += length(" __attribute__ ((unused))");
    181 		if ((protolen + arglen) > 77) {
    182 			protoarg = ("\n    " protoarg);
    183 			arglen += 4;
    184 			protolen = 0;
    185 		}
    186 		printf("%s", protoarg);
    187 		protolen += arglen;
    188 	}
    189 	printf(")) __attribute__ ((unused));\n");
    190 	# Define inline function.
    191 	printf("static __inline int %s(", toupper(name));
    192 	for (i=0; i<argc; i++) {
    193 		printf("%s", argname[i]);
    194 		if (i < (argc-1)) printf(", ");
    195 	}
    196 	printf(")\n");
    197 	for (i=0; i<argc; i++) {
    198 		printf("\t%s %s;\n", argtype[i], argname[i]);
    199 	}
    200 	printf("{\n\tstruct %s_args a;\n", name);
    201 	printf("\ta.a_desc = VDESC(%s);\n", name);
    202 	for (i=0; i<argc; i++) {
    203 		printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
    204 	}
    205 	printf("\treturn (VCALL(%s%s, VOFFSET(%s), &a));\n}\n",
    206 		argname[0], arg0special, name);
    207 }
    208 BEGIN	{
    209 	arg0special="";
    210 }
    211 END	{
    212 	printf("\n/* Special cases: */\n#include <sys/buf.h>\n");
    213 	argc=1;
    214 	argtype[0]="struct buf *";
    215 	argname[0]="bp";
    216 	arg0special="->b_vp";
    217 	name="vop_strategy";
    218 	doit();
    219 	name="vop_bwrite";
    220 	doit();
    221 }
    222 '"$awk_parser" | sed -e "$anal_retentive"
    223 
    224 # End stuff
    225 echo '
    226 /* End of special cases. */'
    227 echo ''
    228 echo '#endif /* !_SYS_VNODE_IF_H_ */'
    229 
    230 #
    231 # Redirect stdout to the C file.
    232 #
    233 echo "$0: Creating $out_c" 1>&2
    234 exec > $out_c
    235 
    236 # Begin stuff
    237 echo -n "$warning" | sed -e 's/\$//g'
    238 echo ""
    239 echo -n "$copyright"
    240 echo '
    241 #include <sys/param.h>
    242 #include <sys/mount.h>
    243 #include <sys/vnode.h>
    244 
    245 struct vnodeop_desc vop_default_desc = {
    246 	0,
    247 	"default",
    248 	0,
    249 	NULL,
    250 	VDESC_NO_OFFSET,
    251 	VDESC_NO_OFFSET,
    252 	VDESC_NO_OFFSET,
    253 	VDESC_NO_OFFSET,
    254 	NULL,
    255 };
    256 '
    257 
    258 # Body stuff
    259 sed -e "$sed_prep" $src | $awk '
    260 function do_offset(typematch) {
    261 	for (i=0; i<argc; i++) {
    262 		if (argtype[i] == typematch) {
    263 			printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n",
    264 				name, argname[i]);
    265 			return i;
    266 		};
    267 	};
    268 	print "\tVDESC_NO_OFFSET,";
    269 	return -1;
    270 }
    271 
    272 function doit() {
    273 	# Define offsets array
    274 	printf("\nint %s_vp_offsets[] = {\n", name);
    275 	for (i=0; i<argc; i++) {
    276 		if (argtype[i] == "struct vnode *") {
    277 			printf ("\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
    278 				name, argname[i]);
    279 		}
    280 	}
    281 	print "\tVDESC_NO_OFFSET";
    282 	print "};";
    283 	# Define F_desc
    284 	printf("struct vnodeop_desc %s_desc = {\n", name);
    285 	# offset
    286 	printf ("\t0,\n");
    287 	# printable name
    288 	printf ("\t\"%s\",\n", name);
    289 	# flags
    290 	printf("\t0");
    291 	vpnum = 0;
    292 	for (i=0; i<argc; i++) {
    293 		if (willrele[i]) {
    294 			if (argdir[i] ~ /OUT/) {
    295 				printf(" | VDESC_VPP_WILLRELE");
    296 			} else {
    297 				printf(" | VDESC_VP%s_WILLRELE", vpnum);
    298 			};
    299 			vpnum++;
    300 		}
    301 	}
    302 	print ",";
    303 	# vp offsets
    304 	printf ("\t%s_vp_offsets,\n", name);
    305 	# vpp (if any)
    306 	do_offset("struct vnode **");
    307 	# cred (if any)
    308 	do_offset("struct ucred *");
    309 	# proc (if any)
    310 	do_offset("struct proc *");
    311 	# componentname
    312 	do_offset("struct componentname *");
    313 	# transport layer information
    314 	printf ("\tNULL,\n};\n");
    315 }
    316 END	{
    317 	printf("\n/* Special cases: */\n");
    318 	argc=1;
    319 	argdir[0]="IN";
    320 	argtype[0]="struct buf *";
    321 	argname[0]="bp";
    322 	willrele[0]=0;
    323 	name="vop_strategy";
    324 	doit();
    325 	name="vop_bwrite";
    326 	doit();
    327 }
    328 '"$awk_parser" | sed -e "$anal_retentive"
    329 
    330 # End stuff
    331 echo '
    332 /* End of special cases. */'
    333 
    334 # Add the vfs_op_descs array to the C file.
    335 # Begin stuff
    336 echo '
    337 struct vnodeop_desc *vfs_op_descs[] = {
    338 	&vop_default_desc,	/* MUST BE FIRST */
    339 	&vop_strategy_desc,	/* XXX: SPECIAL CASE */
    340 	&vop_bwrite_desc,	/* XXX: SPECIAL CASE */
    341 '
    342 
    343 # Body stuff
    344 sed -e "$sed_prep" $src | $awk '
    345 function doit() {
    346 	printf("\t&%s_desc,\n", name);
    347 }
    348 '"$awk_parser"
    349 
    350 # End stuff
    351 echo '	NULL
    352 };
    353 '
    354 
    355 exit 0
    356 
    357 # Local Variables:
    358 # tab-width: 4
    359 # End:
    360