FreeBSD/Linux Kernel Cross Reference
sys/kern/vnode_if.pl
1 #!/usr/bin/perl
2 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
4
5 #
6 # Copyright (c) 1992, 1993
7 # The Regents of the University of California. All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
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.
24 #
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
35 # SUCH DAMAGE.
36 #
37 # @(#)vnode_if.sh 8.1 (Berkeley) 6/10/93
38 # $FreeBSD$
39 #
40 # Script to produce VFS front-end sugar.
41 #
42 # usage: vnode_if.pl srcfile
43 # (where srcfile is currently /sys/kern/vnode_if.src)
44 #
45
46 my %lockdata;
47
48 $cfile = 0;
49 $hfile = 0;
50
51 # Process the command line
52 #
53 while ($arg = shift @ARGV) {
54 if ($arg eq '-c') {
55 $cfile = 1;
56 } elsif ($arg eq '-h') {
57 $hfile = 1;
58 } elsif ($arg eq '-ch' || $arg eq '-hc') {
59 $cfile = 1;
60 $hfile = 1;
61 } elsif ($arg =~ m/\.src$/) {
62 $SRC = $arg;
63 } else {
64 print "usage: vnode_if.pl [-c] [-h] srcfile\n";
65 exit(1);
66 }
67 }
68 if (!$cfile and !$hfile) {
69 exit(0); # nothing asked for..
70 }
71
72 # Names of the created files.
73 $CFILE='vnode_if.c';
74 $HEADER='vnode_if.h';
75
76 open(SRC, "<$SRC") || die "Unable to open input file";
77
78 if ($hfile) {
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'
82 /*
83 * This file is produced automatically.
84 * Do not modify anything in here by hand.
85 *
86 * Created from $FreeBSD$
87 */
88
89 extern struct vnodeop_desc vop_default_desc;
90 END_OF_LEADING_COMMENT
91 ;
92 }
93
94 if ($cfile) {
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'
98 /*
99 * This file is produced automatically.
100 * Do not modify anything in here by hand.
101 *
102 * Created from $FreeBSD$
103 */
104
105 #include <sys/param.h>
106 #include <sys/vnode.h>
107
108 struct vnodeop_desc vop_default_desc = {
109 1, /* special case, vop_default => 1 */
110 "default",
111 0,
112 NULL,
113 VDESC_NO_OFFSET,
114 VDESC_NO_OFFSET,
115 VDESC_NO_OFFSET,
116 VDESC_NO_OFFSET,
117 NULL,
118 };
119
120 END_OF_LEADING_COMMENT
121 ;
122 }
123
124 line: while (<SRC>) {
125 chop; # strip record separator
126 @Fld = split ' ';
127 if (@Fld == 0) {
128 next line;
129 }
130 if (/^#/) {
131 if (!/^#%\s+([a-z]+)\s+([a-z]+)\s+(.)\s(.)\s(.)/) {
132 next;
133 }
134 if (!defined($lockdata{"vop_$1"})) {
135 $lockdata{"vop_$1"} = {};
136 }
137 $lockdata{"vop_$1"}->{$2} = {
138 'Entry' => $3,
139 'OK' => $4,
140 'Error' => $5,
141 };
142 next;
143 }
144
145 # Get the function name.
146 $name = $Fld[0];
147 $uname = uc($name);
148
149 # Get the function arguments.
150 for ($numargs = 0; ; ++$numargs) {
151 if ($ln = <SRC>) {
152 chomp;
153 } else {
154 die "Unable to read through the arguments for \"$name\"";
155 }
156 if ($ln =~ /^\};/) {
157 last;
158 }
159 # For the header file
160 $a{$numargs} = $ln;
161
162 # The rest of this loop is for the C file
163 # Delete comments, if any.
164 $ln =~ s/\/\*.*\*\///g;
165
166 # Delete leading/trailing space.
167 $ln =~ s/^\s*(.*?)\s*$/$1/;
168
169 # Pick off direction.
170 if ($ln =~ s/^INOUT\s+//) {
171 $dir = 'INOUT';
172 } elsif ($ln =~ s/^IN\s+//) {
173 $dir = 'IN';
174 } elsif ($ln =~ s/^OUT\s+//) {
175 $dir = 'OUT';
176 } else {
177 die "No IN/OUT direction for \"$ln\".";
178 }
179 if ($ln =~ s/^WILLRELE\s+//) {
180 $rele = 'WILLRELE';
181 } else {
182 $rele = 'WONTRELE';
183 }
184
185 # kill trailing ;
186 if ($ln !~ s/;$//) {
187 &bail("Missing end-of-line ; in \"$ln\".");
188 }
189
190 # pick off variable name
191 if ($ln !~ s/([A-Za-z0-9_]+)$//) {
192 &bail("Missing var name \"a_foo\" in \"$ln\".");
193 }
194 $arg = $1;
195
196 # what is left must be type
197 # (put clean it up some)
198 $type = $ln;
199 # condense whitespace
200 $type =~ s/\s+/ /g;
201 $type =~ s/^\s*(.*?)\s*$/$1/;
202
203 $dirs{$numargs} = $dir;
204 $reles{$numargs} = $rele;
205 $types{$numargs} = $type;
206 $args{$numargs} = $arg;
207 }
208
209 if ($hfile) {
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",
215 }
216 print HEADER "};\n";
217
218 # Print out extern declaration.
219 print HEADER "extern struct vnodeop_desc ${name}_desc;\n";
220
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";
227 }
228
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");
234 }
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";
238 }
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",
245 }
246 for ($c2 = 0; $c2 < $numargs; ++$c2) {
247 if (!exists($args{$c2})) {
248 die "Internal error";
249 }
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") {
255 print HEADER
256 "\tASSERT_VOP_LOCKED($args{$c2}, \"$uname\");\n";
257 } elsif ($lockdata{$name}->{$args{$c2}}->{Entry} eq "U") {
258 print HEADER
259 "\tASSERT_VOP_UNLOCKED($args{$c2}, \"$uname\");\n";
260 } elsif (0) {
261 # XXX More checks!
262 }
263 }
264 }
265 }
266 $a{0} =~ /\s\**([^;\s]*);/;
267 print HEADER "\trc = VCALL($1, VOFFSET(${name}), &a);\n";
268 print HEADER "\treturn (rc);\n";
269 print HEADER "}\n";
270 }
271
272
273 if ($cfile) {
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
278 $releflags = '';
279 $vpnum = 0;
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",
283 $name, $args{$i};
284 if ($reles{$i} eq 'WILLRELE') {
285 $releflags = $releflags . '|VDESC_VP' . $vpnum . '_WILLRELE';
286 }
287
288 $vpnum++;
289 }
290 }
291
292 $releflags =~ s/^\|//;
293 print CFILE "\tVDESC_NO_OFFSET\n";
294 print CFILE "};\n";
295
296 # Print out the vnodeop_desc structure.
297 print CFILE "struct vnodeop_desc ${name}_desc = {\n";
298 # offset
299 print CFILE "\t0,\n";
300 # printable name
301 printf CFILE "\t\"%s\",\n", $name;
302 # flags
303 $vppwillrele = '';
304 for ($i = 0; $i < $numargs; $i++) {
305 if ($types{$i} eq 'struct vnode **' &&
306 ($reles{$i} eq 'WILLRELE')) {
307 $vppwillrele = '|VDESC_VPP_WILLRELE';
308 }
309 }
310
311 if ($releflags eq '') {
312 printf CFILE "\t0%s,\n", $vppwillrele;
313 }
314 else {
315 printf CFILE "\t%s%s,\n", $releflags, $vppwillrele;
316 }
317
318 # vp offsets
319 printf CFILE "\t%s_vp_offsets,\n", $name;
320 # vpp (if any)
321 printf CFILE "\t%s,\n", &find_arg_with_type('struct vnode **');
322 # cred (if any)
323 printf CFILE "\t%s,\n", &find_arg_with_type('struct ucred *');
324 # proc (if any)
325 printf CFILE "\t%s,\n", &find_arg_with_type('struct proc *');
326 # componentname
327 printf CFILE "\t%s,\n", &find_arg_with_type('struct componentname *');
328 # transport layer information
329 print CFILE "\tNULL,\n};\n\n";
330 }
331 }
332
333 if ($hfile) {
334 close(HEADER) || die "Unable to close $HEADER";
335 }
336 if ($cfile) {
337 close(CFILE) || die "Unable to close $CFILE";
338 }
339 close(SRC) || die;
340
341 exit 0;
342
343 sub find_arg_with_type {
344 my $type = shift;
345 my $i;
346
347 for ($i=0; $i < $numargs; $i++) {
348 if ($types{$i} eq $type) {
349 return "VOPARG_OFFSETOF(struct ${name}_args,a_" . $args{$i} . ")";
350 }
351 }
352
353 return "VDESC_NO_OFFSET";
354 }
Cache object: c3388bc7dbb6ac1eeb09c71e23591164
|