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