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