xref: /freebsd/sys/tools/vnode_if.awk (revision 3176a7fe12fbe5780328b2dfff80d094d71b9810)
13176a7feSEivind Eklund#!/usr/bin/perl
23176a7feSEivind Eklundeval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
33176a7feSEivind Eklund    if $running_under_some_shell;
43176a7feSEivind Eklund
5df8bae1dSRodney W. Grimes#
6df8bae1dSRodney W. Grimes# Copyright (c) 1992, 1993
7df8bae1dSRodney W. Grimes#	The Regents of the University of California.  All rights reserved.
8df8bae1dSRodney W. Grimes#
9df8bae1dSRodney W. Grimes# Redistribution and use in source and binary forms, with or without
10df8bae1dSRodney W. Grimes# modification, are permitted provided that the following conditions
11df8bae1dSRodney W. Grimes# are met:
12df8bae1dSRodney W. Grimes# 1. Redistributions of source code must retain the above copyright
13df8bae1dSRodney W. Grimes#    notice, this list of conditions and the following disclaimer.
14df8bae1dSRodney W. Grimes# 2. Redistributions in binary form must reproduce the above copyright
15df8bae1dSRodney W. Grimes#    notice, this list of conditions and the following disclaimer in the
16df8bae1dSRodney W. Grimes#    documentation and/or other materials provided with the distribution.
17df8bae1dSRodney W. Grimes# 3. All advertising materials mentioning features or use of this software
18df8bae1dSRodney W. Grimes#    must display the following acknowledgement:
19df8bae1dSRodney W. Grimes#	This product includes software developed by the University of
20df8bae1dSRodney W. Grimes#	California, Berkeley and its contributors.
21df8bae1dSRodney W. Grimes# 4. Neither the name of the University nor the names of its contributors
22df8bae1dSRodney W. Grimes#    may be used to endorse or promote products derived from this software
23df8bae1dSRodney W. Grimes#    without specific prior written permission.
24df8bae1dSRodney W. Grimes#
25df8bae1dSRodney W. Grimes# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26df8bae1dSRodney W. Grimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27df8bae1dSRodney W. Grimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28df8bae1dSRodney W. Grimes# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29df8bae1dSRodney W. Grimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30df8bae1dSRodney W. Grimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31df8bae1dSRodney W. Grimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32df8bae1dSRodney W. Grimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33df8bae1dSRodney W. Grimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34df8bae1dSRodney W. Grimes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35df8bae1dSRodney W. Grimes# SUCH DAMAGE.
36df8bae1dSRodney W. Grimes#
37df8bae1dSRodney W. Grimes#	@(#)vnode_if.sh	8.1 (Berkeley) 6/10/93
38c3aac50fSPeter Wemm# $FreeBSD$
39df8bae1dSRodney W. Grimes#
40df8bae1dSRodney W. Grimes# Script to produce VFS front-end sugar.
41df8bae1dSRodney W. Grimes#
42df8bae1dSRodney W. Grimes# usage: vnode_if.sh srcfile
43df8bae1dSRodney W. Grimes#	(where srcfile is currently /sys/kern/vnode_if.src)
44df8bae1dSRodney W. Grimes#
45df8bae1dSRodney W. Grimes
463176a7feSEivind Eklundmy %lockdata;
473176a7feSEivind Eklund
483176a7feSEivind Eklund
493176a7feSEivind Eklundif ($#ARGV != 0) {
503176a7feSEivind Eklund    print "usage: vnode_if.sh srcfile\n";
513176a7feSEivind Eklund    exit(1);
523176a7feSEivind Eklund}
53df8bae1dSRodney W. Grimes
54df8bae1dSRodney W. Grimes# Name of the source file.
553176a7feSEivind Eklund$SRC=$ARGV[0];
56df8bae1dSRodney W. Grimes
57df8bae1dSRodney W. Grimes# Names of the created files.
583176a7feSEivind Eklund$CFILE='vnode_if.c';
593176a7feSEivind Eklund$HEADER='vnode_if.h';
60df8bae1dSRodney W. Grimes
613176a7feSEivind Eklundopen(HEADER, ">$HEADER") || die "Unable to create $HEADER";
623176a7feSEivind Eklundopen(CFILE,   ">$CFILE") || die "Unable to create $CFILE";
633176a7feSEivind Eklundopen(SRC,     "<$SRC")   || die "Unable to open input file";
64df8bae1dSRodney W. Grimes
65df8bae1dSRodney W. Grimes# Print out header information for vnode_if.h.
663176a7feSEivind Eklundprint HEADER <<END_OF_LEADING_COMMENT
67df8bae1dSRodney W. Grimes/*
68df8bae1dSRodney W. Grimes * This file is produced automatically.
69df8bae1dSRodney W. Grimes * Do not modify anything in here by hand.
70df8bae1dSRodney W. Grimes *
71df8bae1dSRodney W. Grimes * Created from @(#)vnode_if.sh	8.1 (Berkeley) 6/10/93
72df8bae1dSRodney W. Grimes */
73df8bae1dSRodney W. Grimes
74df8bae1dSRodney W. Grimesextern struct vnodeop_desc vop_default_desc;
75df8bae1dSRodney W. GrimesEND_OF_LEADING_COMMENT
763176a7feSEivind Eklund		  ;
77df8bae1dSRodney W. Grimes
78df8bae1dSRodney W. Grimes# Print out header information for vnode_if.c.
793176a7feSEivind Eklundprint CFILE <<END_OF_LEADING_COMMENT
80df8bae1dSRodney W. Grimes/*
81df8bae1dSRodney W. Grimes * This file is produced automatically.
82df8bae1dSRodney W. Grimes * Do not modify anything in here by hand.
83df8bae1dSRodney W. Grimes *
84df8bae1dSRodney W. Grimes * Created from @(#)vnode_if.sh	8.1 (Berkeley) 6/10/93
85df8bae1dSRodney W. Grimes */
86df8bae1dSRodney W. Grimes
87df8bae1dSRodney W. Grimes#include <sys/param.h>
88df8bae1dSRodney W. Grimes#include <sys/vnode.h>
89df8bae1dSRodney W. Grimes
90df8bae1dSRodney W. Grimesstruct vnodeop_desc vop_default_desc = {
914e61198eSPeter Wemm	1,			/* special case, vop_default => 1 */
92df8bae1dSRodney W. Grimes	"default",
93df8bae1dSRodney W. Grimes	0,
94df8bae1dSRodney W. Grimes	NULL,
95df8bae1dSRodney W. Grimes	VDESC_NO_OFFSET,
96df8bae1dSRodney W. Grimes	VDESC_NO_OFFSET,
97df8bae1dSRodney W. Grimes	VDESC_NO_OFFSET,
98df8bae1dSRodney W. Grimes	VDESC_NO_OFFSET,
99df8bae1dSRodney W. Grimes	NULL,
100df8bae1dSRodney W. Grimes};
101df8bae1dSRodney W. Grimes
102df8bae1dSRodney W. GrimesEND_OF_LEADING_COMMENT
1033176a7feSEivind Eklund  ;
104df8bae1dSRodney W. Grimes
1053176a7feSEivind Eklundline: while (<SRC>) {
1063176a7feSEivind Eklund    chop;	# strip record separator
1073176a7feSEivind Eklund    @Fld = split ' ';
1083176a7feSEivind Eklund    if (@Fld == 0) {
1093176a7feSEivind Eklund	next line;
1103176a7feSEivind Eklund    }
1113176a7feSEivind Eklund    if (/^#/) {
1123176a7feSEivind Eklund	if (!/^#%\s+([a-z]+)\s+([a-z]+)\s+(.)\s(.)\s(.)/) {
1133176a7feSEivind Eklund	    next;
1143176a7feSEivind Eklund	}
1153176a7feSEivind Eklund	if (!defined($lockdata{"vop_$1"})) {
1163176a7feSEivind Eklund	    $lockdata{"vop_$1"} = {};
1173176a7feSEivind Eklund	}
1183176a7feSEivind Eklund	$lockdata{"vop_$1"}->{$2} = {
1193176a7feSEivind Eklund	    'Entry' => $3,
1203176a7feSEivind Eklund	    'OK'    => $4,
1213176a7feSEivind Eklund	    'Error' => $5,
1223176a7feSEivind Eklund	};
1233176a7feSEivind Eklund	next;
124df8bae1dSRodney W. Grimes    }
125df8bae1dSRodney W. Grimes
1263176a7feSEivind Eklund    # Get the function name.
1273176a7feSEivind Eklund    $name = $Fld[0];
1283176a7feSEivind Eklund    $uname = uc($name);
129df8bae1dSRodney W. Grimes
1303176a7feSEivind Eklund    # Get the function arguments.
1313176a7feSEivind Eklund    for ($numargs = 0; ; ++$numargs) {
1323176a7feSEivind Eklund	if ($ln = <SRC>) {
1333176a7feSEivind Eklund	    chomp;
1343176a7feSEivind Eklund	} else {
1353176a7feSEivind Eklund	    die "Unable to read through the arguments for \"$name\"";
1363176a7feSEivind Eklund	}
1373176a7feSEivind Eklund	if ($ln =~ /^\};/) {
1383176a7feSEivind Eklund	    last;
1393176a7feSEivind Eklund	}
1403176a7feSEivind Eklund        # For the header file
1413176a7feSEivind Eklund	$a{$numargs} = $ln;
1423176a7feSEivind Eklund
1433176a7feSEivind Eklund        # The rest of this loop is for the C file
144df8bae1dSRodney W. Grimes	# Delete comments, if any.
1453176a7feSEivind Eklund	$ln =~ s/\/\*.*\*\///g;
146df8bae1dSRodney W. Grimes
147df8bae1dSRodney W. Grimes	# Delete leading/trailing space.
1483176a7feSEivind Eklund	$ln =~ s/^\s*(.*?)\s*$/$1/;
149df8bae1dSRodney W. Grimes
150df8bae1dSRodney W. Grimes	# Pick off direction.
1513176a7feSEivind Eklund	if ($ln =~ s/^INOUT\s+//) {
1523176a7feSEivind Eklund	    $dir = 'INOUT';
1533176a7feSEivind Eklund	} elsif ($ln =~ s/^IN\s+//) {
1543176a7feSEivind Eklund	    $dir = 'IN';
1553176a7feSEivind Eklund	} elsif ($ln =~ s/^OUT\s+//) {
1563176a7feSEivind Eklund	    $dir = 'OUT';
157df8bae1dSRodney W. Grimes	} else {
1583176a7feSEivind Eklund	     die "No IN/OUT direction for \"$ln\".";
1593176a7feSEivind Eklund	}
1603176a7feSEivind Eklund	if ($ln =~ s/^WILLRELE\s+//) {
1613176a7feSEivind Eklund	    $rele = 'WILLRELE';
1623176a7feSEivind Eklund	} else {
1633176a7feSEivind Eklund	    $rele = 'WONTRELE';
1643176a7feSEivind Eklund	}
165df8bae1dSRodney W. Grimes
166df8bae1dSRodney W. Grimes	# kill trailing ;
1673176a7feSEivind Eklund	if ($ln !~ s/;$//) {
1683176a7feSEivind Eklund	    &bail("Missing end-of-line ; in \"$ln\".");
1693176a7feSEivind Eklund	}
170df8bae1dSRodney W. Grimes
171df8bae1dSRodney W. Grimes	# pick off variable name
1723176a7feSEivind Eklund	if ($ln !~ s/([A-Za-z0-9_]+)$//) {
1733176a7feSEivind Eklund	    &bail("Missing var name \"a_foo\" in \"$ln\".");
1743176a7feSEivind Eklund	}
1753176a7feSEivind Eklund	$arg = $1;
176df8bae1dSRodney W. Grimes
177df8bae1dSRodney W. Grimes	# what is left must be type
178df8bae1dSRodney W. Grimes	# (put clean it up some)
1793176a7feSEivind Eklund	$type = $ln;
1803176a7feSEivind Eklund	# condense whitespace
1813176a7feSEivind Eklund	$type =~ s/\s+/ /g;
1823176a7feSEivind Eklund	$type =~ s/^\s*(.*?)\s*$/$1/;
183df8bae1dSRodney W. Grimes
1843176a7feSEivind Eklund	$dirs{$numargs} = $dir;
1853176a7feSEivind Eklund	$reles{$numargs} = $rele;
1863176a7feSEivind Eklund	$types{$numargs} = $type;
1873176a7feSEivind Eklund	$args{$numargs} = $arg;
188df8bae1dSRodney W. Grimes    }
189df8bae1dSRodney W. Grimes
1903176a7feSEivind Eklund    # Print out the vop_F_args structure.
1913176a7feSEivind Eklund    print HEADER "struct ${name}_args {\n\tstruct vnodeop_desc *a_desc;\n";
1923176a7feSEivind Eklund    for ($c2 = 0; $c2 < $numargs; ++$c2) {
1933176a7feSEivind Eklund	$a{$c2} =~ /^\s*(INOUT|OUT|IN)(\s+WILLRELE)?\s+(.*?)\s+(\**)(\S*\;)/;
1943176a7feSEivind Eklund	print HEADER "\t$3 $4a_$5\n",
1953176a7feSEivind Eklund    }
1963176a7feSEivind Eklund    print HEADER "};\n";
1973176a7feSEivind Eklund
1983176a7feSEivind Eklund    # Print out extern declaration.
1993176a7feSEivind Eklund    print HEADER "extern struct vnodeop_desc ${name}_desc;\n";
2003176a7feSEivind Eklund
2013176a7feSEivind Eklund    # Print out prototype.
2023176a7feSEivind Eklund    print HEADER "static __inline int ${uname} __P((\n";
2033176a7feSEivind Eklund    for ($c2 = 0; $c2 < $numargs; ++$c2) {
2043176a7feSEivind Eklund	$a{$c2} =~ /^\s*(INOUT|OUT|IN)(\s+WILLRELE)?\s+(.*?)\s+(\**\S*)\;/;
2053176a7feSEivind Eklund	print HEADER "\t$3 $4" .
2063176a7feSEivind Eklund	    ($c2 < $numargs-1 ? "," : "));") . "\n";
207df8bae1dSRodney W. Grimes    }
208df8bae1dSRodney W. Grimes
2093176a7feSEivind Eklund    # Print out function.
2103176a7feSEivind Eklund    print HEADER "static __inline int ${uname}(";
2113176a7feSEivind Eklund    for ($c2 = 0; $c2 < $numargs; ++$c2) {
2123176a7feSEivind Eklund	$a{$c2} =~ /\**([^;\s]*)\;[^\s]*$/;
2133176a7feSEivind Eklund	print HEADER "$1" . ($c2 < $numargs - 1 ? ', ' : ")\n");
214df8bae1dSRodney W. Grimes    }
2153176a7feSEivind Eklund    for ($c2 = 0; $c2 < $numargs; ++$c2) {
2163176a7feSEivind Eklund	$a{$c2} =~ /^\s*(INOUT|OUT|IN)(\s+WILLRELE)?\s+(.*?)\s+(\**\S*\;)/;
2173176a7feSEivind Eklund	print HEADER "\t$3 $4\n";
218df8bae1dSRodney W. Grimes    }
2193176a7feSEivind Eklund    print HEADER "{\n\tstruct ${name}_args a;\n";
2203176a7feSEivind Eklund    print HEADER "\tint rc;\n";
2213176a7feSEivind Eklund    print HEADER "\ta.a_desc = VDESC(${name});\n";
2223176a7feSEivind Eklund    for ($c2 = 0; $c2 < $numargs; ++$c2) {
2233176a7feSEivind Eklund	$a{$c2} =~ /(\**)([^;\s]*)([^\s]*)$/;
2243176a7feSEivind Eklund	print HEADER "\ta.a_$2 = $2$3\n",
225df8bae1dSRodney W. Grimes    }
2263176a7feSEivind Eklund    for ($c2 = 0; $c2 < $numargs; ++$c2) {
2273176a7feSEivind Eklund	if (!exists($args{$c2})) {
2283176a7feSEivind Eklund	    die "Internal error";
2293176a7feSEivind Eklund	}
2303176a7feSEivind Eklund	if (exists($lockdata{$name}) &&
2313176a7feSEivind Eklund	    exists($lockdata{$name}->{$args{$c2}})) {
2323176a7feSEivind Eklund	    if ($ENV{'DEBUG_ALL_VFS_LOCKS'} =~ /yes/i) {
2333176a7feSEivind Eklund		# Add assertions for locking
2343176a7feSEivind Eklund		if ($lockdata{$name}->{$args{$c2}}->{Entry} eq "L") {
2353176a7feSEivind Eklund		    print HEADER
2363176a7feSEivind Eklund			"\tASSERT_VOP_LOCKED($args{$c2}, \"$uname\");\n";
2373176a7feSEivind Eklund		} elsif ($lockdata{$name}->{$args{$c2}}->{Entry} eq "U") {
2383176a7feSEivind Eklund		    print HEADER
2393176a7feSEivind Eklund			"\tASSERT_VOP_UNLOCKED($args{$c2}, \"$uname\");\n";
2403176a7feSEivind Eklund		} elsif (0) {
2413176a7feSEivind Eklund		    # XXX More checks!
2423176a7feSEivind Eklund		}
2433176a7feSEivind Eklund	    }
2443176a7feSEivind Eklund	}
2453176a7feSEivind Eklund    }
2463176a7feSEivind Eklund    $a{0} =~ /\s\**([^;\s]*);/;
2473176a7feSEivind Eklund    print HEADER "\trc = VCALL($1, VOFFSET(${name}), &a);\n";
2483176a7feSEivind Eklund    print HEADER "\treturn (rc);\n";
2493176a7feSEivind Eklund    print HEADER "}\n";
250df8bae1dSRodney W. Grimes
251df8bae1dSRodney W. Grimes
252df8bae1dSRodney W. Grimes    # Print out the vop_F_vp_offsets structure.  This all depends
253df8bae1dSRodney W. Grimes    # on naming conventions and nothing else.
2543176a7feSEivind Eklund    printf CFILE "static int %s_vp_offsets[] = {\n", $name;
2553176a7feSEivind Eklund    # as a side effect, figure out the releflags
2563176a7feSEivind Eklund    $releflags = '';
2573176a7feSEivind Eklund    $vpnum = 0;
2583176a7feSEivind Eklund    for ($i = 0; $i < $numargs; $i++) {
2593176a7feSEivind Eklund	if ($types{$i} eq 'struct vnode *') {
2603176a7feSEivind Eklund	    printf CFILE "\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
2613176a7feSEivind Eklund	    $name, $args{$i};
2623176a7feSEivind Eklund	    if ($reles{$i} eq 'WILLRELE') {
2633176a7feSEivind Eklund		$releflags = $releflags . '|VDESC_VP' . $vpnum . '_WILLRELE';
2643176a7feSEivind Eklund	    }
2653176a7feSEivind Eklund
2663176a7feSEivind Eklund	    $vpnum++;
2673176a7feSEivind Eklund	}
2683176a7feSEivind Eklund    }
2693176a7feSEivind Eklund
2703176a7feSEivind Eklund    $releflags =~ s/^\|//;
2713176a7feSEivind Eklund    print CFILE "\tVDESC_NO_OFFSET\n";
2723176a7feSEivind Eklund    print CFILE "};\n";
273df8bae1dSRodney W. Grimes
274df8bae1dSRodney W. Grimes    # Print out the vnodeop_desc structure.
2753176a7feSEivind Eklund    print CFILE "struct vnodeop_desc ${name}_desc = {\n";
2763176a7feSEivind Eklund    # offset
2773176a7feSEivind Eklund    print CFILE "\t0,\n";
2783176a7feSEivind Eklund    # printable name
2793176a7feSEivind Eklund    printf CFILE "\t\"%s\",\n", $name;
2803176a7feSEivind Eklund    # flags
2813176a7feSEivind Eklund    $vppwillrele = '';
2823176a7feSEivind Eklund    for ($i = 0; $i < $numargs; $i++) {
2833176a7feSEivind Eklund	if ($types{$i} eq 'struct vnode **' &&
2843176a7feSEivind Eklund	    ($reles{$i} eq 'WILLRELE')) {
2853176a7feSEivind Eklund	    $vppwillrele = '|VDESC_VPP_WILLRELE';
2863176a7feSEivind Eklund	}
2873176a7feSEivind Eklund    }
288df8bae1dSRodney W. Grimes
2893176a7feSEivind Eklund    if ($releflags eq '') {
2903176a7feSEivind Eklund	printf CFILE "\t0%s,\n", $vppwillrele;
2913176a7feSEivind Eklund    }
2923176a7feSEivind Eklund    else {
2933176a7feSEivind Eklund	printf CFILE "\t%s%s,\n", $releflags, $vppwillrele;
2943176a7feSEivind Eklund    }
295df8bae1dSRodney W. Grimes
2963176a7feSEivind Eklund    # vp offsets
2973176a7feSEivind Eklund    printf CFILE "\t%s_vp_offsets,\n", $name;
2983176a7feSEivind Eklund    # vpp (if any)
2993176a7feSEivind Eklund    printf CFILE "\t%s,\n", &find_arg_with_type('struct vnode **');
3003176a7feSEivind Eklund    # cred (if any)
3013176a7feSEivind Eklund    printf CFILE "\t%s,\n", &find_arg_with_type('struct ucred *');
3023176a7feSEivind Eklund    # proc (if any)
3033176a7feSEivind Eklund    printf CFILE "\t%s,\n", &find_arg_with_type('struct proc *');
3043176a7feSEivind Eklund    # componentname
3053176a7feSEivind Eklund    printf CFILE "\t%s,\n", &find_arg_with_type('struct componentname *');
3063176a7feSEivind Eklund    # transport layer information
3073176a7feSEivind Eklund    print CFILE "\tNULL,\n};\n\n";
3083176a7feSEivind Eklund}
3093176a7feSEivind Eklund
3103176a7feSEivind Eklundclose(HEADER) || die "Unable to close $HEADER";
3113176a7feSEivind Eklundclose(CFILE)  || die "Unable to close $CFILE";
3123176a7feSEivind Eklundclose(SRC) || die;
3133176a7feSEivind Eklund
3143176a7feSEivind Eklundexit 0;
3153176a7feSEivind Eklund
3163176a7feSEivind Eklundsub find_arg_with_type {
3173176a7feSEivind Eklund    my $type = shift;
3183176a7feSEivind Eklund    my $i;
3193176a7feSEivind Eklund
3203176a7feSEivind Eklund    for ($i=0; $i < $numargs; $i++) {
3213176a7feSEivind Eklund	if ($types{$i} eq $type) {
3223176a7feSEivind Eklund	    return "VOPARG_OFFSETOF(struct ${name}_args,a_" . $args{$i} . ")";
3233176a7feSEivind Eklund	}
3243176a7feSEivind Eklund    }
3253176a7feSEivind Eklund
3263176a7feSEivind Eklund    return "VDESC_NO_OFFSET";
3273176a7feSEivind Eklund}
328