xref: /original-bsd/sys/kern/vnode_if.sh (revision 0ac4996f)
1#!/bin/sh -
2copyright='
3/*
4 * Copyright (c) 1992, 1993, 1994, 1995
5 *	The Regents of the University of California.  All rights reserved.
6 *
7 * %sccs.include.redist.sh%
8 *
9 * from: NetBSD: vnode_if.sh,v 1.7 1994/08/25 03:04:28 cgd Exp $
10 */
11'
12SCRIPT_ID='@(#)vnode_if.sh	8.7 (Berkeley) 05/11/95'
13
14# Script to produce VFS front-end sugar.
15#
16# usage: vnode_if.sh srcfile
17#	(where srcfile is currently /sys/kern/vnode_if.src)
18#
19
20if [ $# -ne 1 ] ; then
21	echo 'usage: vnode_if.sh srcfile'
22	exit 1
23fi
24
25# Name of the source file.
26src=$1
27
28# Names of the created files.
29out_c=vnode_if.c
30out_h=vnode_if.h
31
32# Awk program (must support nawk extensions)
33# Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
34awk=${AWK:-awk}
35
36# Does this awk have a "toupper" function? (i.e. is it GNU awk)
37isgawk=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
38
39# If this awk does not define "toupper" then define our own.
40if [ "$isgawk" = TRUE ] ; then
41	# GNU awk provides it.
42	toupper=
43else
44	# Provide our own toupper()
45	toupper='
46function toupper(str) {
47	_toupper_cmd = "echo "str" |tr a-z A-Z"
48	_toupper_cmd | getline _toupper_str;
49	close(_toupper_cmd);
50	return _toupper_str;
51}'
52fi
53
54#
55# This is the common part of all awk programs that read $src
56# This parses the input for one function into the arrays:
57#	argdir, argtype, argname, willrele
58# and calls "doit()" to generate output for the function.
59#
60# Input to this parser is pre-processed slightly by sed
61# so this awk parser doesn't have to work so hard.  The
62# changes done by the sed pre-processing step are:
63#	insert a space beween * and pointer name
64#	replace semicolons with spaces
65#
66sed_prep='s:\*\([^\*/]\):\* \1:g
67s/;/ /'
68awk_parser='
69# Comment line
70/^#/	{ next; }
71# First line of description
72/^vop_/	{
73	name=$1;
74	argc=0;
75	next;
76}
77# Last line of description
78/^}/	{
79	doit();
80	next;
81}
82# Middle lines of description
83{
84	argdir[argc] = $1; i=2;
85	if ($2 == "WILLRELE") {
86		willrele[argc] = 1;
87		i++;
88	} else
89		willrele[argc] = 0;
90	argtype[argc] = $i; i++;
91	while (i < NF) {
92		argtype[argc] = argtype[argc]" "$i;
93		i++;
94	}
95	argname[argc] = $i;
96	argc++;
97	next;
98}
99'
100
101# This is put after the copyright on each generated file.
102warning="
103/*
104 * Warning: This file is generated automatically.
105 * (Modifications made here may easily be lost!)
106 *
107 * Created by the script:
108 *	${SCRIPT_ID}
109 */
110"
111
112# Get rid of ugly spaces
113space_elim='s:\([^/]\*\) :\1:g'
114
115#
116# Redirect stdout to the H file.
117#
118echo "$0: Creating $out_h" 1>&2
119exec > $out_h
120
121# Begin stuff
122echo "$copyright"
123echo "$warning"
124echo '
125extern struct vnodeop_desc vop_default_desc;
126'
127
128# Body stuff
129# This awk program needs toupper() so define it if necessary.
130sed -e "$sed_prep" $src | $awk "$toupper"'
131function doit() {
132	# Declare arg struct, descriptor.
133	printf("\nstruct %s_args {\n", name);
134	printf("\tstruct vnodeop_desc * a_desc;\n");
135	for (i=0; i<argc; i++) {
136		printf("\t%s a_%s;\n", argtype[i], argname[i]);
137	}
138	printf("};\n");
139	printf("extern struct vnodeop_desc %s_desc;\n", name);
140	# Define inline function.
141	printf("#define %s(", toupper(name));
142	for (i=0; i<argc; i++) {
143		printf("%s", argname[i]);
144		if (i < (argc-1)) printf(", ");
145	}
146	printf(") _%s(", toupper(name));
147	for (i=0; i<argc; i++) {
148		printf("%s", argname[i]);
149		if (i < (argc-1)) printf(", ");
150	}
151	printf(")\n");
152	printf("static __inline int _%s(", toupper(name));
153	for (i=0; i<argc; i++) {
154		printf("%s", argname[i]);
155		if (i < (argc-1)) printf(", ");
156	}
157	printf(")\n");
158	for (i=0; i<argc; i++) {
159		printf("\t%s %s;\n", argtype[i], argname[i]);
160	}
161	printf("{\n\tstruct %s_args a;\n", name);
162	printf("\ta.a_desc = VDESC(%s);\n", name);
163	for (i=0; i<argc; i++) {
164		printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
165	}
166	printf("\treturn (VCALL(%s%s, VOFFSET(%s), &a));\n}\n",
167		argname[0], arg0special, name);
168}
169BEGIN	{
170	arg0special="";
171}
172END	{
173	printf("\n/* Special cases: */\n#include <sys/buf.h>\n");
174	argc=1;
175	argtype[0]="struct buf *";
176	argname[0]="bp";
177	arg0special="->b_vp";
178	name="vop_strategy";
179	doit();
180	name="vop_bwrite";
181	doit();
182}
183'"$awk_parser" | sed -e "$space_elim"
184
185# End stuff
186echo '
187/* End of special cases. */'
188
189
190#
191# Redirect stdout to the C file.
192#
193echo "$0: Creating $out_c" 1>&2
194exec > $out_c
195
196# Begin stuff
197echo "$copyright"
198echo "$warning"
199echo '
200#include <sys/param.h>
201#include <sys/mount.h>
202#include <sys/vnode.h>
203
204struct vnodeop_desc vop_default_desc = {
205	0,
206	"default",
207	0,
208	NULL,
209	VDESC_NO_OFFSET,
210	VDESC_NO_OFFSET,
211	VDESC_NO_OFFSET,
212	VDESC_NO_OFFSET,
213	NULL,
214};
215'
216
217# Body stuff
218sed -e "$sed_prep" $src | $awk '
219function do_offset(typematch) {
220	for (i=0; i<argc; i++) {
221		if (argtype[i] == typematch) {
222			printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n",
223				name, argname[i]);
224			return i;
225		};
226	};
227	print "\tVDESC_NO_OFFSET,";
228	return -1;
229}
230
231function doit() {
232	# Define offsets array
233	printf("\nint %s_vp_offsets[] = {\n", name);
234	for (i=0; i<argc; i++) {
235		if (argtype[i] == "struct vnode *") {
236			printf ("\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
237				name, argname[i]);
238		}
239	}
240	print "\tVDESC_NO_OFFSET";
241	print "};";
242	# Define F_desc
243	printf("struct vnodeop_desc %s_desc = {\n", name);
244	# offset
245	printf ("\t0,\n");
246	# printable name
247	printf ("\t\"%s\",\n", name);
248	# flags
249	printf("\t0");
250	vpnum = 0;
251	for (i=0; i<argc; i++) {
252		if (willrele[i]) {
253			if (argdir[i] ~ /OUT/) {
254				printf(" | VDESC_VPP_WILLRELE");
255			} else {
256				printf(" | VDESC_VP%s_WILLRELE", vpnum);
257			};
258			vpnum++;
259		}
260	}
261	print ",";
262	# vp offsets
263	printf ("\t%s_vp_offsets,\n", name);
264	# vpp (if any)
265	do_offset("struct vnode **");
266	# cred (if any)
267	do_offset("struct ucred *");
268	# proc (if any)
269	do_offset("struct proc *");
270	# componentname
271	do_offset("struct componentname *");
272	# transport layer information
273	printf ("\tNULL,\n};\n");
274}
275END	{
276	printf("\n/* Special cases: */\n");
277	argc=1;
278	argdir[0]="IN";
279	argtype[0]="struct buf *";
280	argname[0]="bp";
281	willrele[0]=0;
282	name="vop_strategy";
283	doit();
284	name="vop_bwrite";
285	doit();
286}
287'"$awk_parser" | sed -e "$space_elim"
288
289# End stuff
290echo '
291/* End of special cases. */'
292
293# Add the vfs_op_descs array to the C file.
294# Begin stuff
295echo '
296struct vnodeop_desc *vfs_op_descs[] = {
297	&vop_default_desc,	/* MUST BE FIRST */
298	&vop_strategy_desc,	/* XXX: SPECIAL CASE */
299	&vop_bwrite_desc,	/* XXX: SPECIAL CASE */
300'
301
302# Body stuff
303sed -e "$sed_prep" $src | $awk '
304function doit() {
305	printf("\t&%s_desc,\n", name);
306}
307'"$awk_parser"
308
309# End stuff
310echo '	NULL
311};
312'
313
314exit 0
315
316# Local Variables:
317# tab-width: 4
318# End:
319