# Copyright (c) 1992, 1993, 1994
# The Regents of the University of California. All rights reserved.
# %sccs.include.redist.sh%
# from: $NetBSD: vnode_if.sh,v 1.7 1994/08/25 03:04:28 cgd Exp $
SCRIPT_ID
='@(#)vnode_if.sh 8.5 (Berkeley) %G%'
# Script to produce VFS front-end sugar.
# usage: vnode_if.sh srcfile
# (where srcfile is currently /sys/kern/vnode_if.src)
echo 'usage: vnode_if.sh srcfile'
# Name of the source file.
# Names of the created files.
# Awk program (must support nawk extensions)
# Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
# Does this awk have a "toupper" function? (i.e. is it GNU awk)
isgawk
=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
# If this awk does not define "toupper" then define our own.
if [ "$isgawk" = TRUE
] ; then
# Provide our own toupper()
_toupper_cmd = "echo "str" |tr a-z A-Z"
_toupper_cmd | getline _toupper_str;
# This is the common part of all awk programs that read $src
# This parses the input for one function into the arrays:
# argdir, argtype, argname, willrele
# and calls "doit()" to generate output for the function.
# Input to this parser is pre-processed slightly by sed
# so this awk parser doesn't have to work so hard. The
# changes done by the sed pre-processing step are:
# insert a space beween * and pointer name
# replace semicolons with spaces
sed_prep
='s:\*\([^\*/]\):\* \1:g
# First line of description
# Last line of description
# Middle lines of description
argtype[argc] = argtype[argc]" "$i;
# This is put after the copyright on each generated file.
* Warning: This file is generated automatically.
* (Modifications made here may easily be lost!)
space_elim
='s:\([^/]\*\) :\1:g'
# Redirect stdout to the H file.
echo "$0: Creating $out_h" 1>&2
extern struct vnodeop_desc vop_default_desc;
# This awk program needs toupper() so define it if necessary.
sed -e "$sed_prep" $src |
$awk "$toupper"'
# Declare arg struct, descriptor.
printf("\nstruct %s_args {\n", name);
printf("\tstruct vnodeop_desc * a_desc;\n");
printf("\t%s a_%s;\n", argtype[i], argname[i]);
printf("extern struct vnodeop_desc %s_desc;\n", name);
# Define inline function.
printf("static __inline int %s(", toupper(name));
printf("%s", argname[i]);
if (i < (argc-1)) printf(", ");
printf("\t%s %s;\n", argtype[i], argname[i]);
printf("{\n\tstruct %s_args a;\n", name);
printf("\ta.a_desc = VDESC(%s);\n", name);
printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
printf("\treturn (VCALL(%s%s, VOFFSET(%s), &a));\n}\n",
argname[0], arg0special, name);
printf("\n/* Special cases: */\n#include <sys/buf.h>\n");
argtype[0]="struct buf *";
'"$awk_parser" |
sed -e "$space_elim"
/* End of special cases. */'
# Redirect stdout to the C file.
echo "$0: Creating $out_c" 1>&2
struct vnodeop_desc vop_default_desc = {
sed -e "$sed_prep" $src |
$awk '
function do_offset(typematch) {
if (argtype[i] == typematch) {
printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n",
print "\tVDESC_NO_OFFSET,";
printf("\nint %s_vp_offsets[] = {\n", name);
if (argtype[i] == "struct vnode *") {
printf ("\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
print "\tVDESC_NO_OFFSET";
printf("struct vnodeop_desc %s_desc = {\n", name);
printf ("\t\"%s\",\n", name);
printf(" | VDESC_VPP_WILLRELE");
printf(" | VDESC_VP%s_WILLRELE", vpnum);
printf ("\t%s_vp_offsets,\n", name);
do_offset("struct vnode **");
do_offset("struct ucred *");
do_offset("struct proc *");
do_offset("struct componentname *");
# transport layer information
printf ("\tNULL,\n};\n");
printf("\n/* Special cases: */\n");
argtype[0]="struct buf *";
'"$awk_parser" |
sed -e "$space_elim"
/* End of special cases. */'
# Add the vfs_op_descs array to the C file.
struct vnodeop_desc *vfs_op_descs[] = {
&vop_default_desc, /* MUST BE FIRST */
&vop_strategy_desc, /* XXX: SPECIAL CASE */
&vop_bwrite_desc, /* XXX: SPECIAL CASE */
sed -e "$sed_prep" $src |
$awk '
printf("\t&%s_desc,\n", name);