2 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
6 # Copyright (c) 1992, 1993
7 # The Regents of the University of California. All rights reserved.
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 # 3. All advertising materials mentioning features or use of this software
18 # must display the following acknowledgement:
19 # This product includes software developed by the University of
20 # California, Berkeley and its contributors.
21 # 4. Neither the name of the University nor the names of its contributors
22 # may be used to endorse or promote products derived from this software
23 # without specific prior written permission.
25 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 # @(#)vnode_if.sh 8.1 (Berkeley) 6/10/93
40 # Script to produce VFS front-end sugar.
42 # usage: vnode_if.sh srcfile
43 # (where srcfile is currently /sys/kern/vnode_if.src)
50 print "usage: vnode_if.sh srcfile\n";
54 # Name of the source file.
57 # Names of the created files.
61 open(HEADER, ">$HEADER") || die "Unable to create $HEADER";
62 open(CFILE, ">$CFILE") || die "Unable to create $CFILE";
63 open(SRC, "<$SRC") || die "Unable to open input file";
65 # Print out header information for vnode_if.h.
66 print HEADER <<END_OF_LEADING_COMMENT
68 * This file is produced automatically.
69 * Do not modify anything in here by hand.
71 * Created from @(#)vnode_if.sh 8.1 (Berkeley) 6/10/93
74 extern struct vnodeop_desc vop_default_desc;
75 END_OF_LEADING_COMMENT
78 # Print out header information for vnode_if.c.
79 print CFILE <<END_OF_LEADING_COMMENT
81 * This file is produced automatically.
82 * Do not modify anything in here by hand.
84 * Created from @(#)vnode_if.sh 8.1 (Berkeley) 6/10/93
87 #include <sys/param.h>
88 #include <sys/vnode.h>
90 struct vnodeop_desc vop_default_desc = {
91 1, /* special case, vop_default => 1 */
102 END_OF_LEADING_COMMENT
105 line: while (<SRC>) {
106 chop; # strip record separator
112 if (!/^#%\s+([a-z]+)\s+([a-z]+)\s+(.)\s(.)\s(.)/) {
115 if (!defined($lockdata{"vop_$1"})) {
116 $lockdata{"vop_$1"} = {};
118 $lockdata{"vop_$1"}->{$2} = {
126 # Get the function name.
130 # Get the function arguments.
131 for ($numargs = 0; ; ++$numargs) {
135 die "Unable to read through the arguments for \"$name\"";
140 # For the header file
143 # The rest of this loop is for the C file
144 # Delete comments, if any.
145 $ln =~ s/\/\*.*\*\///g;
147 # Delete leading/trailing space.
148 $ln =~ s/^\s*(.*?)\s*$/$1/;
150 # Pick off direction.
151 if ($ln =~ s/^INOUT\s+//) {
153 } elsif ($ln =~ s/^IN\s+//) {
155 } elsif ($ln =~ s/^OUT\s+//) {
158 die "No IN/OUT direction for \"$ln\".";
160 if ($ln =~ s/^WILLRELE\s+//) {
168 &bail("Missing end-of-line ; in \"$ln\".");
171 # pick off variable name
172 if ($ln !~ s/([A-Za-z0-9_]+)$//) {
173 &bail("Missing var name \"a_foo\" in \"$ln\".");
177 # what is left must be type
178 # (put clean it up some)
180 # condense whitespace
182 $type =~ s/^\s*(.*?)\s*$/$1/;
184 $dirs{$numargs} = $dir;
185 $reles{$numargs} = $rele;
186 $types{$numargs} = $type;
187 $args{$numargs} = $arg;
190 # Print out the vop_F_args structure.
191 print HEADER "struct ${name}_args {\n\tstruct vnodeop_desc *a_desc;\n";
192 for ($c2 = 0; $c2 < $numargs; ++$c2) {
193 $a{$c2} =~ /^\s*(INOUT|OUT|IN)(\s+WILLRELE)?\s+(.*?)\s+(\**)(\S*\;)/;
194 print HEADER "\t$3 $4a_$5\n",
198 # Print out extern declaration.
199 print HEADER "extern struct vnodeop_desc ${name}_desc;\n";
201 # Print out prototype.
202 print HEADER "static __inline int ${uname} __P((\n";
203 for ($c2 = 0; $c2 < $numargs; ++$c2) {
204 $a{$c2} =~ /^\s*(INOUT|OUT|IN)(\s+WILLRELE)?\s+(.*?)\s+(\**\S*)\;/;
205 print HEADER "\t$3 $4" .
206 ($c2 < $numargs-1 ? "," : "));") . "\n";
209 # Print out function.
210 print HEADER "static __inline int ${uname}(";
211 for ($c2 = 0; $c2 < $numargs; ++$c2) {
212 $a{$c2} =~ /\**([^;\s]*)\;[^\s]*$/;
213 print HEADER "$1" . ($c2 < $numargs - 1 ? ', ' : ")\n");
215 for ($c2 = 0; $c2 < $numargs; ++$c2) {
216 $a{$c2} =~ /^\s*(INOUT|OUT|IN)(\s+WILLRELE)?\s+(.*?)\s+(\**\S*\;)/;
217 print HEADER "\t$3 $4\n";
219 print HEADER "{\n\tstruct ${name}_args a;\n";
220 print HEADER "\tint rc;\n";
221 print HEADER "\ta.a_desc = VDESC(${name});\n";
222 for ($c2 = 0; $c2 < $numargs; ++$c2) {
223 $a{$c2} =~ /(\**)([^;\s]*)([^\s]*)$/;
224 print HEADER "\ta.a_$2 = $2$3\n",
226 for ($c2 = 0; $c2 < $numargs; ++$c2) {
227 if (!exists($args{$c2})) {
228 die "Internal error";
230 if (exists($lockdata{$name}) &&
231 exists($lockdata{$name}->{$args{$c2}})) {
232 if ($ENV{'DEBUG_ALL_VFS_LOCKS'} =~ /yes/i) {
233 # Add assertions for locking
234 if ($lockdata{$name}->{$args{$c2}}->{Entry} eq "L") {
236 "\tASSERT_VOP_LOCKED($args{$c2}, \"$uname\");\n";
237 } elsif ($lockdata{$name}->{$args{$c2}}->{Entry} eq "U") {
239 "\tASSERT_VOP_UNLOCKED($args{$c2}, \"$uname\");\n";
246 $a{0} =~ /\s\**([^;\s]*);/;
247 print HEADER "\trc = VCALL($1, VOFFSET(${name}), &a);\n";
248 print HEADER "\treturn (rc);\n";
252 # Print out the vop_F_vp_offsets structure. This all depends
253 # on naming conventions and nothing else.
254 printf CFILE "static int %s_vp_offsets[] = {\n", $name;
255 # as a side effect, figure out the releflags
258 for ($i = 0; $i < $numargs; $i++) {
259 if ($types{$i} eq 'struct vnode *') {
260 printf CFILE "\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
262 if ($reles{$i} eq 'WILLRELE') {
263 $releflags = $releflags . '|VDESC_VP' . $vpnum . '_WILLRELE';
270 $releflags =~ s/^\|//;
271 print CFILE "\tVDESC_NO_OFFSET\n";
274 # Print out the vnodeop_desc structure.
275 print CFILE "struct vnodeop_desc ${name}_desc = {\n";
277 print CFILE "\t0,\n";
279 printf CFILE "\t\"%s\",\n", $name;
282 for ($i = 0; $i < $numargs; $i++) {
283 if ($types{$i} eq 'struct vnode **' &&
284 ($reles{$i} eq 'WILLRELE')) {
285 $vppwillrele = '|VDESC_VPP_WILLRELE';
289 if ($releflags eq '') {
290 printf CFILE "\t0%s,\n", $vppwillrele;
293 printf CFILE "\t%s%s,\n", $releflags, $vppwillrele;
297 printf CFILE "\t%s_vp_offsets,\n", $name;
299 printf CFILE "\t%s,\n", &find_arg_with_type('struct vnode **');
301 printf CFILE "\t%s,\n", &find_arg_with_type('struct ucred *');
303 printf CFILE "\t%s,\n", &find_arg_with_type('struct proc *');
305 printf CFILE "\t%s,\n", &find_arg_with_type('struct componentname *');
306 # transport layer information
307 print CFILE "\tNULL,\n};\n\n";
310 close(HEADER) || die "Unable to close $HEADER";
311 close(CFILE) || die "Unable to close $CFILE";
316 sub find_arg_with_type {
320 for ($i=0; $i < $numargs; $i++) {
321 if ($types{$i} eq $type) {
322 return "VOPARG_OFFSETOF(struct ${name}_args,a_" . $args{$i} . ")";
326 return "VDESC_NO_OFFSET";