1#!/usr/bin/awk -f 2 3# 4# Copyright (c) 1992, 1993 5# The Regents of the University of California. All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 3. All advertising materials mentioning features or use of this software 16# must display the following acknowledgement: 17# This product includes software developed by the University of 18# California, Berkeley and its contributors. 19# 4. Neither the name of the University nor the names of its contributors 20# may be used to endorse or promote products derived from this software 21# without specific prior written permission. 22# 23# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33# SUCH DAMAGE. 34# 35# @(#)vnode_if.sh 8.1 (Berkeley) 6/10/93 36# $FreeBSD$ 37# 38# Script to produce VFS front-end sugar. 39# 40# usage: vnode_if.awk <srcfile> [-c | -h] 41# (where <srcfile> is currently /sys/kern/vnode_if.src) 42# 43 44function usage() 45{ 46 print "usage: vnode_if.awk <srcfile> [-c|-h]"; 47 exit 1; 48} 49 50function die(msg, what) 51{ 52 printf msg "\n", what > "/dev/stderr"; 53 exit 1; 54} 55 56function t_spc(type) 57{ 58 # Append a space if the type is not a pointer 59 return (type ~ /\*$/) ? type : type " "; 60} 61 62# These are just for convenience ... 63function printc(s) {print s > cfile;} 64function printh(s) {print s > hfile;} 65 66function add_debug_code(name, arg, pos) 67{ 68 if (lockdata[name, arg, pos]) { 69 # Add assertions for locking 70 if (lockdata[name, arg, pos] == "L") 71 printh("\tASSERT_VOP_LOCKED("arg", \""uname"\");"); 72 else if (lockdata[name, arg, pos] == "U") 73 printh("\tASSERT_VOP_UNLOCKED("arg", \""uname"\");"); 74 else if (0) { 75 # XXX More checks! 76 } 77 } 78} 79 80function add_debug_pre(name) 81{ 82 if (lockdata[name, "pre"]) { 83 printh("#ifdef DEBUG_VFS_LOCKS"); 84 printh("\t"lockdata[name, "pre"]"(&a);"); 85 printh("#endif"); 86 } 87} 88 89function add_debug_post(name) 90{ 91 if (lockdata[name, "post"]) { 92 printh("#ifdef DEBUG_VFS_LOCKS"); 93 printh("\t"lockdata[name, "post"]"(&a, rc);"); 94 printh("#endif"); 95 } 96} 97 98function find_arg_with_type (type) 99{ 100 for (jj = 0; jj < numargs; jj++) { 101 if (types[jj] == type) { 102 return "VOPARG_OFFSETOF(struct " \ 103 name "_args,a_" args[jj] ")"; 104 } 105 } 106 107 return "VDESC_NO_OFFSET"; 108} 109 110BEGIN{ 111 112# Process the command line 113for (i = 1; i < ARGC; i++) { 114 arg = ARGV[i]; 115 if (arg !~ /^-[ch]+$/ && arg !~ /\.src$/) 116 usage(); 117 if (arg ~ /^-.*c/) 118 cfile = "vnode_if.c"; 119 if (arg ~ /^-.*h/) 120 hfile = "vnode_if.h"; 121 if (arg ~ /\.src$/) 122 srcfile = arg; 123} 124ARGC = 1; 125 126if (!cfile && !hfile) 127 exit 0; 128 129if (!srcfile) 130 usage(); 131 132common_head = \ 133 "/*\n" \ 134 " * This file is produced automatically.\n" \ 135 " * Do not modify anything in here by hand.\n" \ 136 " *\n" \ 137 " * Created from $FreeBSD$\n" \ 138 " */\n" \ 139 "\n"; 140 141if (hfile) 142 printh(common_head "extern struct vnodeop_desc vop_default_desc;"); 143 144if (cfile) { 145 printc(common_head \ 146 "#include <sys/param.h>\n" \ 147 "#include <sys/systm.h>\n" \ 148 "#include <sys/vnode.h>\n" \ 149 "\n" \ 150 "struct vnodeop_desc vop_default_desc = {\n" \ 151 " 1,\t\t\t/* special case, vop_default => 1 */\n" \ 152 " \"default\",\n" \ 153 " 0,\n" \ 154 " NULL,\n" \ 155 " VDESC_NO_OFFSET,\n" \ 156 " VDESC_NO_OFFSET,\n" \ 157 " VDESC_NO_OFFSET,\n" \ 158 " VDESC_NO_OFFSET,\n" \ 159 " NULL,\n" \ 160 "};\n"); 161} 162 163while ((getline < srcfile) > 0) { 164 if (NF == 0) 165 continue; 166 if ($1 ~ /^#%/) { 167 if (NF != 6 || $1 != "#%" || \ 168 $2 !~ /^[a-z]+$/ || $3 !~ /^[a-z]+$/ || \ 169 $4 !~ /^.$/ || $5 !~ /^.$/ || $6 !~ /^.$/) 170 continue; 171 if ($3 == "vpp") 172 $3 = "*vpp"; 173 lockdata["vop_" $2, $3, "Entry"] = $4; 174 lockdata["vop_" $2, $3, "OK"] = $5; 175 lockdata["vop_" $2, $3, "Error"] = $6; 176 continue; 177 } 178 179 if ($1 ~ /^#!/) { 180 if (NF != 4 || $1 != "#!") 181 continue; 182 if ($3 != "pre" && $3 != "post") 183 continue; 184 lockdata["vop_" $2, $3] = $4; 185 continue; 186 } 187 if ($1 ~ /^#/) 188 continue; 189 190 # Get the function name. 191 name = $1; 192 uname = toupper(name); 193 # Get the function arguments. 194 for (numargs = 0; ; ++numargs) { 195 if ((getline < srcfile) <= 0) { 196 die("Unable to read through the arguments for \"%s\"", 197 name); 198 } 199 if ($1 ~ /^\};/) 200 break; 201 202 # Delete comments, if any. 203 gsub (/\/\*.*\*\//, ""); 204 205 # Condense whitespace and delete leading/trailing space. 206 gsub(/[[:space:]]+/, " "); 207 sub(/^ /, ""); 208 sub(/ $/, ""); 209 210 # Pick off direction. 211 if ($1 != "INOUT" && $1 != "IN" && $1 != "OUT") 212 die("No IN/OUT direction for \"%s\".", $0); 213 dirs[numargs] = $1; 214 sub(/^[A-Z]* /, ""); 215 216 if ((reles[numargs] = $1) == "WILLRELE") 217 sub(/^[A-Z]* /, ""); 218 else 219 reles[numargs] = "WONTRELE"; 220 221 # kill trailing ; 222 if (sub(/;$/, "") < 1) 223 die("Missing end-of-line ; in \"%s\".", $0); 224 225 # pick off variable name 226 if ((argp = match($0, /[A-Za-z0-9_]+$/)) < 1) 227 die("Missing var name \"a_foo\" in \"%s\".", $0); 228 args[numargs] = substr($0, argp); 229 $0 = substr($0, 1, argp - 1); 230 231 # what is left must be type 232 # remove trailing space (if any) 233 sub(/ $/, ""); 234 types[numargs] = $0; 235 } 236 237 if (hfile) { 238 # Print out the vop_F_args structure. 239 printh("struct "name"_args {\n\tstruct vnodeop_desc *a_desc;"); 240 for (i = 0; i < numargs; ++i) 241 printh("\t" t_spc(types[i]) "a_" args[i] ";"); 242 printh("};"); 243 244 # Print out extern declaration. 245 printh("extern struct vnodeop_desc " name "_desc;"); 246 247 # Print out function. 248 printh("static __inline int " uname "("); 249 for (i = 0; i < numargs; ++i) { 250 printh("\t" t_spc(types[i]) args[i] \ 251 (i < numargs - 1 ? "," : ")")); 252 } 253 printh("{\n\tstruct " name "_args a;"); 254 printh("\tint rc;"); 255 printh("\ta.a_desc = VDESC(" name ");"); 256 for (i = 0; i < numargs; ++i) 257 printh("\ta.a_" args[i] " = " args[i] ";"); 258 for (i = 0; i < numargs; ++i) 259 add_debug_code(name, args[i], "Entry"); 260 add_debug_pre(name); 261 printh("\trc = VCALL(" args[0] ", VOFFSET(" name "), &a);"); 262 printh("if (rc == 0) {"); 263 for (i = 0; i < numargs; ++i) 264 add_debug_code(name, args[i], "OK"); 265 printh("} else {"); 266 for (i = 0; i < numargs; ++i) 267 add_debug_code(name, args[i], "Error"); 268 printh("}"); 269 add_debug_post(name); 270 printh("\treturn (rc);\n}"); 271 } 272 273 if (cfile) { 274 # Print out the vop_F_vp_offsets structure. This all depends 275 # on naming conventions and nothing else. 276 printc("static int " name "_vp_offsets[] = {"); 277 # as a side effect, figure out the releflags 278 releflags = ""; 279 vpnum = 0; 280 for (i = 0; i < numargs; i++) { 281 if (types[i] == "struct vnode *") { 282 printc("\tVOPARG_OFFSETOF(struct " name \ 283 "_args,a_" args[i] "),"); 284 if (reles[i] == "WILLRELE") { 285 releflags = releflags \ 286 "|VDESC_VP" vpnum "_WILLRELE"; 287 } 288 vpnum++; 289 } 290 } 291 292 sub(/^\|/, "", releflags); 293 printc("\tVDESC_NO_OFFSET"); 294 printc("};"); 295 296 # Print out the vnodeop_desc structure. 297 printc("struct vnodeop_desc " name "_desc = {"); 298 # offset 299 printc("\t0,"); 300 # printable name 301 printc("\t\"" name "\","); 302 # flags 303 vppwillrele = ""; 304 for (i = 0; i < numargs; i++) { 305 if (types[i] == "struct vnode **" && \ 306 reles[i] == "WILLRELE") { 307 vppwillrele = "|VDESC_VPP_WILLRELE"; 308 } 309 } 310 311 if (!releflags) 312 releflags = "0"; 313 printc("\t" releflags vppwillrele ","); 314 315 # vp offsets 316 printc("\t" name "_vp_offsets,"); 317 # vpp (if any) 318 printc("\t" find_arg_with_type("struct vnode **") ","); 319 # cred (if any) 320 printc("\t" find_arg_with_type("struct ucred *") ","); 321 # thread (if any) 322 printc("\t" find_arg_with_type("struct thread *") ","); 323 # componentname 324 printc("\t" find_arg_with_type("struct componentname *") ","); 325 # transport layer information 326 printc("\tNULL,\n};\n"); 327 } 328} 329 330if (hfile) 331 close(hfile); 332if (cfile) 333 close(cfile); 334close(srcfile); 335 336exit 0; 337 338} 339