]>
git.saurik.com Git - apple/xnu.git/blob - bsd/vfs/vnode_if.sh
4 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
6 * @APPLE_LICENSE_HEADER_START@
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.
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
22 * @APPLE_LICENSE_HEADER_END@
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.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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.
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
58 SCRIPT_ID
='@(#)vnode_if.sh 8.7 (Berkeley) 5/11/95'
60 # Script to produce VFS front-end sugar.
62 # usage: vnode_if.sh srcfile
63 # (where srcfile is currently bsd/vfs/vnode_if.src)
66 if [ $# -ne 1 ] ; then
67 echo 'usage: vnode_if.sh srcfile'
71 # Name of the source file.
74 # Names of the created files.
78 # Awk program (must support nawk extensions)
79 # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
83 # Does this awk have a "toupper" function? (i.e. is it GNU awk)
84 isgawk
=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
86 # If this awk does not define "toupper" then define our own.
87 if [ "$isgawk" = TRUE
] ; then
88 # GNU awk provides it.
91 # Provide our own toupper()
93 function toupper(str) {
94 _toupper_cmd = "echo "str" |tr a-z A-Z"
95 _toupper_cmd | getline _toupper_str;
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.
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
113 sed_prep
='s:\*\([^\*/]\):\* \1:g
118 # First line of description
125 # Last line of description
130 # Middle lines of description
132 argdir[argc] = $1; i=2;
133 if ($2 == "WILLRELE") {
138 argtype[argc] = $i; i++;
140 argtype[argc] = argtype[argc]" "$i;
149 # This is put after the copyright on each generated file.
152 * Warning: This file is generated automatically.
153 * (Modifications made here may easily be lost!)
155 * Created by the script:
160 # Get rid of ugly spaces
161 space_elim
='s:\([^/]\*\) :\1:g'
164 # Redirect stdout to the H file.
166 echo "$0: Creating $out_h" 1>&2
173 #ifndef _SYS_VNODE_IF_H_
174 #define _SYS_VNODE_IF_H_
176 #include <sys/appleapiopts.h>
178 #ifdef __APPLE_API_UNSTABLE
179 extern struct vnodeop_desc vop_default_desc;
183 # This awk program needs toupper() so define it if necessary.
184 sed -e "$sed_prep" $src | $awk "$toupper"'
186 # Declare arg struct, descriptor.
187 printf("\nstruct %s_args {\n", name);
188 printf("\tstruct vnodeop_desc * a_desc;\n");
189 for (i=0; i<argc; i++) {
190 printf("\t%s a_%s;\n", argtype[i], argname[i]);
193 printf("extern struct vnodeop_desc %s_desc;\n", name);
194 # Define inline function.
195 printf("#define %s(", toupper(name));
196 for (i=0; i<argc; i++) {
197 printf("%s", argname[i]);
198 if (i < (argc-1)) printf(", ");
200 printf(") _%s(", toupper(name));
201 for (i=0; i<argc; i++) {
202 printf("%s", argname[i]);
203 if (i < (argc-1)) printf(", ");
206 printf("static __inline int _%s(", toupper(name));
207 for (i=0; i<argc; i++) {
208 # generate ANSI protoypes now, hurrah!
209 printf("%s %s", argtype[i], argname[i]);
210 if (i < (argc-1)) printf(", ");
213 printf("{\n\tstruct %s_args a;\n", name);
214 printf("\ta.a_desc = VDESC(%s);\n", name);
215 for (i=0; i<argc; i++) {
216 printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
218 if (toupper(ubc) == "UBC") {
219 printf("\t{\n\t\tint _err;\n\t\t" \
220 "extern int ubc_hold(struct vnode *vp);\n\t\t" \
221 "extern void ubc_rele(struct vnode *vp);\n\t\t" \
222 "int _didhold = ubc_hold(%s);\n\t\t" \
223 "_err = VCALL(%s%s, VOFFSET(%s), &a);\n\t\t" \
224 "if (_didhold)\n\t\t\tubc_rele(%s);\n\t\t" \
225 "return (_err);\n\t}\n}\n",
226 argname[0], argname[0], arg0special, name, argname[0]);
228 printf("\treturn (VCALL(%s%s, VOFFSET(%s), &a));\n}\n",
229 argname[0], arg0special, name);
236 printf("\n/* Special cases: */\n#include <sys/buf.h>\n#include <sys/vm.h>\n");
238 argtype[0]="struct buf *";
240 arg0special="->b_vp";
246 '"$awk_parser" | sed -e "$space_elim"
250 /* End of special cases. */
252 #endif /* __APPLE_API_UNSTABLE */
253 #endif /* !_SYS_VNODE_IF_H_ */'
256 # Redirect stdout to the C file.
258 echo "$0: Creating $out_c" 1>&2
265 #include <sys/param.h>
266 #include <sys/mount.h>
268 #include <sys/vnode.h>
270 struct vnodeop_desc vop_default_desc = {
284 sed -e "$sed_prep" $src | $awk '
285 function do_offset(typematch) {
286 for (i=0; i<argc; i++) {
287 if (argtype[i] == typematch) {
288 printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n",
293 print "\tVDESC_NO_OFFSET,";
298 # Define offsets array
299 printf("\nint %s_vp_offsets[] = {\n", name);
300 for (i=0; i<argc; i++) {
301 if (argtype[i] == "struct vnode *") {
302 printf ("\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
306 print "\tVDESC_NO_OFFSET";
309 printf("struct vnodeop_desc %s_desc = {\n", name);
313 printf ("\t\"%s\",\n", name);
317 for (i=0; i<argc; i++) {
318 if (match(argtype[i], "struct vnode *") == 1) {
320 if (argdir[i] ~ /OUT/) {
321 printf(" | VDESC_VPP_WILLRELE");
323 printf(" | VDESC_VP%s_WILLRELE", vpnum);
331 printf ("\t%s_vp_offsets,\n", name);
333 do_offset("struct vnode **");
335 do_offset("struct ucred *");
337 do_offset("struct proc *");
339 do_offset("struct componentname *");
340 # transport layer information
341 printf ("\tNULL,\n};\n");
344 printf("\n/* Special cases: */\n");
347 argtype[0]="struct buf *";
355 '"$awk_parser" | sed -e "$space_elim"
359 /* End of special cases. */'
361 # Add the vfs_op_descs array to the C file.
364 struct vnodeop_desc *vfs_op_descs[] = {
365 &vop_default_desc, /* MUST BE FIRST */
366 &vop_strategy_desc, /* XXX: SPECIAL CASE */
367 &vop_bwrite_desc, /* XXX: SPECIAL CASE */
371 sed -e "$sed_prep" $src | $awk '
373 printf("\t&%s_desc,\n", name);