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)
51 # Process the command line
53 while ($arg = shift @ARGV) {
56 } elsif ($arg eq '-h') {
58 } elsif ($arg eq '-ch' || $arg eq '-hc') {
61 } elsif ($arg =~ m/\.src$/) {
64 print "usage: vnode_if.sh [-c] [-h] srcfile\n";
68 if (!$cfile and !$hfile) {
69 exit(0); # nothing asked for..
72 # Names of the created files.
76 open(SRC, "<$SRC") || die "Unable to open input file";
79 open(HEADER, ">$HEADER") || die "Unable to create $HEADER";
80 # Print out header information for vnode_if.h.
81 print HEADER <<END_OF_LEADING_COMMENT
83 * This file is produced automatically.
84 * Do not modify anything in here by hand.
86 * Created from @(#)vnode_if.sh 8.1 (Berkeley) 6/10/93
89 extern struct vnodeop_desc vop_default_desc;
90 END_OF_LEADING_COMMENT
95 open(CFILE, ">$CFILE") || die "Unable to create $CFILE";
96 # Print out header information for vnode_if.c.
97 print CFILE <<END_OF_LEADING_COMMENT
99 * This file is produced automatically.
100 * Do not modify anything in here by hand.
102 * Created from @(#)vnode_if.sh 8.1 (Berkeley) 6/10/93
105 #include <sys/param.h>
106 #include <sys/vnode.h>
108 struct vnodeop_desc vop_default_desc = {
109 1, /* special case, vop_default => 1 */
120 END_OF_LEADING_COMMENT
124 line: while (<SRC>) {
125 chop; # strip record separator
131 if (!/^#%\s+([a-z]+)\s+([a-z]+)\s+(.)\s(.)\s(.)/) {
134 if (!defined($lockdata{"vop_$1"})) {
135 $lockdata{"vop_$1"} = {};
137 $lockdata{"vop_$1"}->{$2} = {
145 # Get the function name.
149 # Get the function arguments.
150 for ($numargs = 0; ; ++$numargs) {
154 die "Unable to read through the arguments for \"$name\"";
159 # For the header file
162 # The rest of this loop is for the C file
163 # Delete comments, if any.
164 $ln =~ s/\/\*.*\*\///g;
166 # Delete leading/trailing space.
167 $ln =~ s/^\s*(.*?)\s*$/$1/;
169 # Pick off direction.
170 if ($ln =~ s/^INOUT\s+//) {
172 } elsif ($ln =~ s/^IN\s+//) {
174 } elsif ($ln =~ s/^OUT\s+//) {
177 die "No IN/OUT direction for \"$ln\".";
179 if ($ln =~ s/^WILLRELE\s+//) {
187 &bail("Missing end-of-line ; in \"$ln\".");
190 # pick off variable name
191 if ($ln !~ s/([A-Za-z0-9_]+)$//) {
192 &bail("Missing var name \"a_foo\" in \"$ln\".");
196 # what is left must be type
197 # (put clean it up some)
199 # condense whitespace
201 $type =~ s/^\s*(.*?)\s*$/$1/;
203 $dirs{$numargs} = $dir;
204 $reles{$numargs} = $rele;
205 $types{$numargs} = $type;
206 $args{$numargs} = $arg;
210 # Print out the vop_F_args structure.
211 print HEADER "struct ${name}_args {\n\tstruct vnodeop_desc *a_desc;\n";
212 for ($c2 = 0; $c2 < $numargs; ++$c2) {
213 $a{$c2} =~ /^\s*(INOUT|OUT|IN)(\s+WILLRELE)?\s+(.*?)\s+(\**)(\S*\;)/;
214 print HEADER "\t$3 $4a_$5\n",
218 # Print out extern declaration.
219 print HEADER "extern struct vnodeop_desc ${name}_desc;\n";
221 # Print out prototype.
222 print HEADER "static __inline int ${uname} __P((\n";
223 for ($c2 = 0; $c2 < $numargs; ++$c2) {
224 $a{$c2} =~ /^\s*(INOUT|OUT|IN)(\s+WILLRELE)?\s+(.*?)\s+(\**\S*)\;/;
225 print HEADER "\t$3 $4" .
226 ($c2 < $numargs-1 ? "," : "));") . "\n";
229 # Print out function.
230 print HEADER "static __inline int ${uname}(";
231 for ($c2 = 0; $c2 < $numargs; ++$c2) {
232 $a{$c2} =~ /\**([^;\s]*)\;[^\s]*$/;
233 print HEADER "$1" . ($c2 < $numargs - 1 ? ', ' : ")\n");
235 for ($c2 = 0; $c2 < $numargs; ++$c2) {
236 $a{$c2} =~ /^\s*(INOUT|OUT|IN)(\s+WILLRELE)?\s+(.*?)\s+(\**\S*\;)/;
237 print HEADER "\t$3 $4\n";
239 print HEADER "{\n\tstruct ${name}_args a;\n";
240 print HEADER "\tint rc;\n";
241 print HEADER "\ta.a_desc = VDESC(${name});\n";
242 for ($c2 = 0; $c2 < $numargs; ++$c2) {
243 $a{$c2} =~ /(\**)([^;\s]*)([^\s]*)$/;
244 print HEADER "\ta.a_$2 = $2$3\n",
246 for ($c2 = 0; $c2 < $numargs; ++$c2) {
247 if (!exists($args{$c2})) {
248 die "Internal error";
250 if (exists($lockdata{$name}) &&
251 exists($lockdata{$name}->{$args{$c2}})) {
252 if ($ENV{'DEBUG_ALL_VFS_LOCKS'} =~ /yes/i) {
253 # Add assertions for locking
254 if ($lockdata{$name}->{$args{$c2}}->{Entry} eq "L") {
256 "\tASSERT_VOP_LOCKED($args{$c2}, \"$uname\");\n";
257 } elsif ($lockdata{$name}->{$args{$c2}}->{Entry} eq "U") {
259 "\tASSERT_VOP_UNLOCKED($args{$c2}, \"$uname\");\n";
266 $a{0} =~ /\s\**([^;\s]*);/;
267 print HEADER "\trc = VCALL($1, VOFFSET(${name}), &a);\n";
268 print HEADER "\treturn (rc);\n";
274 # Print out the vop_F_vp_offsets structure. This all depends
275 # on naming conventions and nothing else.
276 printf CFILE "static int %s_vp_offsets[] = {\n", $name;
277 # as a side effect, figure out the releflags
280 for ($i = 0; $i < $numargs; $i++) {
281 if ($types{$i} eq 'struct vnode *') {
282 printf CFILE "\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
284 if ($reles{$i} eq 'WILLRELE') {
285 $releflags = $releflags . '|VDESC_VP' . $vpnum . '_WILLRELE';
292 $releflags =~ s/^\|//;
293 print CFILE "\tVDESC_NO_OFFSET\n";
296 # Print out the vnodeop_desc structure.
297 print CFILE "struct vnodeop_desc ${name}_desc = {\n";
299 print CFILE "\t0,\n";
301 printf CFILE "\t\"%s\",\n", $name;
304 for ($i = 0; $i < $numargs; $i++) {
305 if ($types{$i} eq 'struct vnode **' &&
306 ($reles{$i} eq 'WILLRELE')) {
307 $vppwillrele = '|VDESC_VPP_WILLRELE';
311 if ($releflags eq '') {
312 printf CFILE "\t0%s,\n", $vppwillrele;
315 printf CFILE "\t%s%s,\n", $releflags, $vppwillrele;
319 printf CFILE "\t%s_vp_offsets,\n", $name;
321 printf CFILE "\t%s,\n", &find_arg_with_type('struct vnode **');
323 printf CFILE "\t%s,\n", &find_arg_with_type('struct ucred *');
325 printf CFILE "\t%s,\n", &find_arg_with_type('struct proc *');
327 printf CFILE "\t%s,\n", &find_arg_with_type('struct componentname *');
328 # transport layer information
329 print CFILE "\tNULL,\n};\n\n";
334 close(HEADER) || die "Unable to close $HEADER";
337 close(CFILE) || die "Unable to close $CFILE";
343 sub find_arg_with_type {
347 for ($i=0; $i < $numargs; $i++) {
348 if ($types{$i} eq $type) {
349 return "VOPARG_OFFSETOF(struct ${name}_args,a_" . $args{$i} . ")";
353 return "VDESC_NO_OFFSET";