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