1#!/bin/sh - 2copyright=' 3/* 4 * Copyright (c) 1992, 1993, 1994 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.6 (Berkeley) 02/14/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("static __inline int %s(", toupper(name)); 142 for (i=0; i<argc; i++) { 143 printf("%s", argname[i]); 144 if (i < (argc-1)) printf(", "); 145 } 146 printf(")\n"); 147 for (i=0; i<argc; i++) { 148 printf("\t%s %s;\n", argtype[i], argname[i]); 149 } 150 printf("{\n\tstruct %s_args a;\n", name); 151 printf("\ta.a_desc = VDESC(%s);\n", name); 152 for (i=0; i<argc; i++) { 153 printf("\ta.a_%s = %s;\n", argname[i], argname[i]); 154 } 155 printf("\treturn (VCALL(%s%s, VOFFSET(%s), &a));\n}\n", 156 argname[0], arg0special, name); 157} 158BEGIN { 159 arg0special=""; 160} 161END { 162 printf("\n/* Special cases: */\n#include <sys/buf.h>\n"); 163 argc=1; 164 argtype[0]="struct buf *"; 165 argname[0]="bp"; 166 arg0special="->b_vp"; 167 name="vop_strategy"; 168 doit(); 169 name="vop_bwrite"; 170 doit(); 171} 172'"$awk_parser" | sed -e "$space_elim" 173 174# End stuff 175echo ' 176/* End of special cases. */' 177 178 179# 180# Redirect stdout to the C file. 181# 182echo "$0: Creating $out_c" 1>&2 183exec > $out_c 184 185# Begin stuff 186echo "$copyright" 187echo "$warning" 188echo ' 189#include <sys/param.h> 190#include <sys/mount.h> 191#include <sys/vnode.h> 192 193struct vnodeop_desc vop_default_desc = { 194 0, 195 "default", 196 0, 197 NULL, 198 VDESC_NO_OFFSET, 199 VDESC_NO_OFFSET, 200 VDESC_NO_OFFSET, 201 VDESC_NO_OFFSET, 202 NULL, 203}; 204' 205 206# Body stuff 207sed -e "$sed_prep" $src | $awk ' 208function do_offset(typematch) { 209 for (i=0; i<argc; i++) { 210 if (argtype[i] == typematch) { 211 printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n", 212 name, argname[i]); 213 return i; 214 }; 215 }; 216 print "\tVDESC_NO_OFFSET,"; 217 return -1; 218} 219 220function doit() { 221 # Define offsets array 222 printf("\nint %s_vp_offsets[] = {\n", name); 223 for (i=0; i<argc; i++) { 224 if (argtype[i] == "struct vnode *") { 225 printf ("\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n", 226 name, argname[i]); 227 } 228 } 229 print "\tVDESC_NO_OFFSET"; 230 print "};"; 231 # Define F_desc 232 printf("struct vnodeop_desc %s_desc = {\n", name); 233 # offset 234 printf ("\t0,\n"); 235 # printable name 236 printf ("\t\"%s\",\n", name); 237 # flags 238 printf("\t0"); 239 vpnum = 0; 240 for (i=0; i<argc; i++) { 241 if (willrele[i]) { 242 if (argdir[i] ~ /OUT/) { 243 printf(" | VDESC_VPP_WILLRELE"); 244 } else { 245 printf(" | VDESC_VP%s_WILLRELE", vpnum); 246 }; 247 vpnum++; 248 } 249 } 250 print ","; 251 # vp offsets 252 printf ("\t%s_vp_offsets,\n", name); 253 # vpp (if any) 254 do_offset("struct vnode **"); 255 # cred (if any) 256 do_offset("struct ucred *"); 257 # proc (if any) 258 do_offset("struct proc *"); 259 # componentname 260 do_offset("struct componentname *"); 261 # transport layer information 262 printf ("\tNULL,\n};\n"); 263} 264END { 265 printf("\n/* Special cases: */\n"); 266 argc=1; 267 argdir[0]="IN"; 268 argtype[0]="struct buf *"; 269 argname[0]="bp"; 270 willrele[0]=0; 271 name="vop_strategy"; 272 doit(); 273 name="vop_bwrite"; 274 doit(); 275} 276'"$awk_parser" | sed -e "$space_elim" 277 278# End stuff 279echo ' 280/* End of special cases. */' 281 282# Add the vfs_op_descs array to the C file. 283# Begin stuff 284echo ' 285struct vnodeop_desc *vfs_op_descs[] = { 286 &vop_default_desc, /* MUST BE FIRST */ 287 &vop_strategy_desc, /* XXX: SPECIAL CASE */ 288 &vop_bwrite_desc, /* XXX: SPECIAL CASE */ 289' 290 291# Body stuff 292sed -e "$sed_prep" $src | $awk ' 293function doit() { 294 printf("\t&%s_desc,\n", name); 295} 296'"$awk_parser" 297 298# End stuff 299echo ' NULL 300}; 301' 302 303exit 0 304 305# Local Variables: 306# tab-width: 4 307# End: 308