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