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