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