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