Home | History | Annotate | Line # | Download | only in kern
vnode_if.sh revision 1.5
      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.5 1994/07/15 22:29:22 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 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 
    137 #
    138 # Redirect stdout to the H file.
    139 #
    140 echo "$0: Creating $out_h" 1>&2
    141 exec > $out_h
    142 
    143 # Begin stuff
    144 echo "$copyright"
    145 echo "$warning"
    146 echo '
    147 extern struct vnodeop_desc vop_default_desc;
    148 '
    149 
    150 # Body stuff
    151 # This awk program needs toupper() so define it if necessary.
    152 sed -e "$sed_prep" $src | $awk "$toupper"'
    153 function doit() {
    154 	# Declare arg struct, descriptor.
    155 	printf("\nstruct %s_args {\n", name);
    156 	printf("\tstruct vnodeop_desc * a_desc;\n");
    157 	for (i=0; i<argc; i++) {
    158 		printf("\t%s a_%s;\n", argtype[i], argname[i]);
    159 	}
    160 	printf("};\n");
    161 	printf("extern struct vnodeop_desc %s_desc;\n", name);
    162 	# Define inline function.
    163 	printf("static __inline int %s(", toupper(name));
    164 	for (i=0; i<argc; i++) {
    165 		printf("%s", argname[i]);
    166 		if (i < (argc-1)) printf(", ");
    167 	}
    168 	printf(")\n");
    169 	for (i=0; i<argc; i++) {
    170 		printf("\t%s %s;\n", argtype[i], argname[i]);
    171 	}
    172 	printf("{\n\tstruct %s_args a;\n", name);
    173 	printf("\ta.a_desc = VDESC(%s);\n", name);
    174 	for (i=0; i<argc; i++) {
    175 		printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
    176 	}
    177 	printf("\treturn (VCALL(%s%s, VOFFSET(%s), &a));\n}\n",
    178 		argname[0], arg0special, name);
    179 }
    180 BEGIN	{
    181 	arg0special="";
    182 }
    183 END	{
    184 	printf("\n/* Special cases: */\n#include <sys/buf.h>\n");
    185 	argc=1;
    186 	argtype[0]="struct buf *";
    187 	argname[0]="bp";
    188 	arg0special="->b_vp";
    189 	name="vop_strategy";
    190 	doit();
    191 	name="vop_bwrite";
    192 	doit();
    193 }
    194 '"$awk_parser"
    195 
    196 # End stuff
    197 echo '
    198 /* End of special cases. */'
    199 
    200 
    201 #
    202 # Redirect stdout to the C file.
    203 #
    204 echo "$0: Creating $out_c" 1>&2
    205 exec > $out_c
    206 
    207 # Begin stuff
    208 echo "$copyright"
    209 echo "$warning"
    210 echo '
    211 #include <sys/param.h>
    212 #include <sys/mount.h>
    213 #include <sys/vnode.h>
    214 
    215 struct vnodeop_desc vop_default_desc = {
    216 	0,
    217 	"default",
    218 	0,
    219 	NULL,
    220 	VDESC_NO_OFFSET,
    221 	VDESC_NO_OFFSET,
    222 	VDESC_NO_OFFSET,
    223 	VDESC_NO_OFFSET,
    224 	NULL,
    225 };
    226 '
    227 
    228 # Body stuff
    229 sed -e "$sed_prep" $src | $awk '
    230 function do_offset(typematch) {
    231 	for (i=0; i<argc; i++) {
    232 		if (argtype[i] == typematch) {
    233 			printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n",
    234 				name, argname[i]);
    235 			return i;
    236 		};
    237 	};
    238 	print "\tVDESC_NO_OFFSET,";
    239 	return -1;
    240 }
    241 
    242 function doit() {
    243 	# Define offsets array
    244 	printf("\nint %s_vp_offsets[] = {\n", name);
    245 	for (i=0; i<argc; i++) {
    246 		if (argtype[i] == "struct vnode *") {
    247 			printf ("\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
    248 				name, argname[i]);
    249 		}
    250 	}
    251 	print "\tVDESC_NO_OFFSET";
    252 	print "};";
    253 	# Define F_desc
    254 	printf("struct vnodeop_desc %s_desc = {\n", name);
    255 	# offset
    256 	printf ("\t0,\n");
    257 	# printable name
    258 	printf ("\t\"%s\",\n", name);
    259 	# flags
    260 	printf("\t0");
    261 	vpnum = 0;
    262 	for (i=0; i<argc; i++) {
    263 		if (willrele[i]) {
    264 			if (argdir[i] ~ /OUT/) {
    265 				printf(" | VDESC_VPP_WILLRELE");
    266 			} else {
    267 				printf(" | VDESC_VP%s_WILLRELE", vpnum);
    268 			};
    269 			vpnum++;
    270 		}
    271 	}
    272 	print ",";
    273 	# vp offsets
    274 	printf ("\t%s_vp_offsets,\n", name);
    275 	# vpp (if any)
    276 	do_offset("struct vnode **");
    277 	# cred (if any)
    278 	do_offset("struct ucred *");
    279 	# proc (if any)
    280 	do_offset("struct proc *");
    281 	# componentname
    282 	do_offset("struct componentname *");
    283 	# transport layer information
    284 	printf ("\tNULL,\n};\n");
    285 }
    286 END	{
    287 	printf("\n/* Special cases: */\n");
    288 	argc=1;
    289 	argdir[0]="IN";
    290 	argtype[0]="struct buf *";
    291 	argname[0]="bp";
    292 	willrele[0]=0;
    293 	name="vop_strategy";
    294 	doit();
    295 	name="vop_bwrite";
    296 	doit();
    297 }
    298 '"$awk_parser"
    299 
    300 # End stuff
    301 echo '
    302 /* End of special cases. */'
    303 
    304 # Add the vfs_op_descs array to the C file.
    305 # Begin stuff
    306 echo '
    307 struct vnodeop_desc *vfs_op_descs[] = {
    308 	&vop_default_desc,	/* MUST BE FIRST */
    309 	&vop_strategy_desc,	/* XXX: SPECIAL CASE */
    310 	&vop_bwrite_desc,	/* XXX: SPECIAL CASE */
    311 '
    312 
    313 # Body stuff
    314 sed -e "$sed_prep" $src | $awk '
    315 function doit() {
    316 	printf("\t&%s_desc,\n", name);
    317 }
    318 '"$awk_parser"
    319 
    320 # End stuff
    321 echo '	NULL
    322 };
    323 '
    324 
    325 exit 0
    326 
    327 # Local Variables:
    328 # tab-width: 4
    329 # End:
    330