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) 67{ 68 if (debug_all_vfs_locks && lockdata[name, arg, "Entry"]) { 69 # Add assertions for locking 70 if (lockdata[name, arg, "Entry"] == "L") 71 printh("\tASSERT_VOP_LOCKED("arg", \""uname"\");"); 72 else if (lockdata[name, arg, "Entry"] == "U") 73 printh("\tASSERT_VOP_UNLOCKED("arg", \""uname"\");"); 74 else if (0) { 75 # XXX More checks! 76 } 77 } 78} 79 80function find_arg_with_type (type) 81{ 82 for (jj = 0; jj < numargs; jj++) { 83 if (types[jj] == type) { 84 return "VOPARG_OFFSETOF(struct " \ 85 name "_args,a_" args[jj] ")"; 86 } 87 } 88 89 return "VDESC_NO_OFFSET"; 90} 91 92BEGIN{ 93 94# Process the command line 95for (i = 1; i < ARGC; i++) { 96 arg = ARGV[i]; 97 if (arg !~ /^-[ch]+$/ && arg !~ /\.src$/) 98 usage(); 99 if (arg ~ /^-.*c/) 100 cfile = "vnode_if.c"; 101 if (arg ~ /^-.*h/) 102 hfile = "vnode_if.h"; 103 if (arg ~ /\.src$/) 104 srcfile = arg; 105} 106ARGC = 1; 107 108if (!cfile && !hfile) 109 exit 0; 110 111if (!srcfile) 112 usage(); 113 114debug_all_vfs_locks = (ENVIRON["DEBUG_ALL_VFS_LOCKS"] ~ /[Yy][Ee][Ss]/); 115 116common_head = \ 117 "/*\n" \ 118 " * This file is produced automatically.\n" \ 119 " * Do not modify anything in here by hand.\n" \ 120 " *\n" \ 121 " * Created from $FreeBSD$\n" \ 122 " */\n" \ 123 "\n"; 124 125if (hfile) 126 printh(common_head "extern struct vnodeop_desc vop_default_desc;"); 127 128if (cfile) { 129 printc(common_head \ 130 "#include <sys/param.h>\n" \ 131 "#include <sys/vnode.h>\n" \ 132 "\n" \ 133 "struct vnodeop_desc vop_default_desc = {\n" \ 134 " 1,\t\t\t/* special case, vop_default => 1 */\n" \ 135 " \"default\",\n" \ 136 " 0,\n" \ 137 " NULL,\n" \ 138 " VDESC_NO_OFFSET,\n" \ 139 " VDESC_NO_OFFSET,\n" \ 140 " VDESC_NO_OFFSET,\n" \ 141 " VDESC_NO_OFFSET,\n" \ 142 " NULL,\n" \ 143 "};\n"); 144} 145 146while ((getline < srcfile) > 0) { 147 if (NF == 0) 148 continue; 149 if ($1 ~ /^#/) { 150 if (NF != 6 || $1 != "#%" || \ 151 $2 !~ /^[a-z]+$/ || $3 !~ /^[a-z]+$/ || \ 152 $4 !~ /^.$/ || $5 !~ /^.$/ || $6 !~ /^.$/) 153 continue; 154 lockdata["vop_" $2, $3, "Entry"] = $4; 155 lockdata["vop_" $2, $3, "OK"] = $5; 156 lockdata["vop_" $2, $3, "Error"] = $6; 157 continue; 158 } 159 160 # Get the function name. 161 name = $1; 162 uname = toupper(name); 163 # Get the function arguments. 164 for (numargs = 0; ; ++numargs) { 165 if ((getline < srcfile) <= 0) { 166 die("Unable to read through the arguments for \"%s\"", 167 name); 168 } 169 if ($1 ~ /^\};/) 170 break; 171 172 # Delete comments, if any. 173 gsub (/\/\*.*\*\//, ""); 174 175 # Condense whitespace and delete leading/trailing space. 176 gsub(/[[:space:]]+/, " "); 177 sub(/^ /, ""); 178 sub(/ $/, ""); 179 180 # Pick off direction. 181 if ($1 != "INOUT" && $1 != "IN" && $1 != "OUT") 182 die("No IN/OUT direction for \"%s\".", $0); 183 dirs[numargs] = $1; 184 sub(/^[A-Z]* /, ""); 185 186 if ((reles[numargs] = $1) == "WILLRELE") 187 sub(/^[A-Z]* /, ""); 188 else 189 reles[numargs] = "WONTRELE"; 190 191 # kill trailing ; 192 if (sub(/;$/, "") < 1) 193 die("Missing end-of-line ; in \"%s\".", $0); 194 195 # pick off variable name 196 if ((argp = match($0, /[A-Za-z0-9_]+$/)) < 1) 197 die("Missing var name \"a_foo\" in \"%s\".", $0); 198 args[numargs] = substr($0, argp); 199 $0 = substr($0, 1, argp - 1); 200 201 # what is left must be type 202 # remove trailing space (if any) 203 sub(/ $/, ""); 204 types[numargs] = $0; 205 } 206 207 if (hfile) { 208 # Print out the vop_F_args structure. 209 printh("struct "name"_args {\n\tstruct vnodeop_desc *a_desc;"); 210 for (i = 0; i < numargs; ++i) 211 printh("\t" t_spc(types[i]) "a_" args[i] ";"); 212 printh("};"); 213 214 # Print out extern declaration. 215 printh("extern struct vnodeop_desc " name "_desc;"); 216 217 # Print out function. 218 printh("static __inline int " uname "("); 219 for (i = 0; i < numargs; ++i) { 220 printh("\t" t_spc(types[i]) args[i] \ 221 (i < numargs - 1 ? "," : ")")); 222 } 223 printh("{\n\tstruct " name "_args a;"); 224 printh("\tint rc;"); 225 printh("\ta.a_desc = VDESC(" name ");"); 226 for (i = 0; i < numargs; ++i) 227 printh("\ta.a_" args[i] " = " args[i] ";"); 228 for (i = 0; i < numargs; ++i) 229 add_debug_code(name, args[i]); 230 printh("\trc = VCALL(" args[0] ", VOFFSET(" name "), &a);"); 231 printh("\treturn (rc);\n}"); 232 } 233 234 if (cfile) { 235 # Print out the vop_F_vp_offsets structure. This all depends 236 # on naming conventions and nothing else. 237 printc("static int " name "_vp_offsets[] = {"); 238 # as a side effect, figure out the releflags 239 releflags = ""; 240 vpnum = 0; 241 for (i = 0; i < numargs; i++) { 242 if (types[i] == "struct vnode *") { 243 printc("\tVOPARG_OFFSETOF(struct " name \ 244 "_args,a_" args[i] "),"); 245 if (reles[i] == "WILLRELE") { 246 releflags = releflags \ 247 "|VDESC_VP" vpnum "_WILLRELE"; 248 } 249 vpnum++; 250 } 251 } 252 253 sub(/^\|/, "", releflags); 254 printc("\tVDESC_NO_OFFSET"); 255 printc("};"); 256 257 # Print out the vnodeop_desc structure. 258 printc("struct vnodeop_desc " name "_desc = {"); 259 # offset 260 printc("\t0,"); 261 # printable name 262 printc("\t\"" name "\","); 263 # flags 264 vppwillrele = ""; 265 for (i = 0; i < numargs; i++) { 266 if (types[i] == "struct vnode **" && \ 267 reles[i] == "WILLRELE") { 268 vppwillrele = "|VDESC_VPP_WILLRELE"; 269 } 270 } 271 272 if (!releflags) 273 releflags = "0"; 274 printc("\t" releflags vppwillrele ","); 275 276 # vp offsets 277 printc("\t" name "_vp_offsets,"); 278 # vpp (if any) 279 printc("\t" find_arg_with_type("struct vnode **") ","); 280 # cred (if any) 281 printc("\t" find_arg_with_type("struct ucred *") ","); 282 # thread (if any) 283 printc("\t" find_arg_with_type("struct thread *") ","); 284 # componentname 285 printc("\t" find_arg_with_type("struct componentname *") ","); 286 # transport layer information 287 printc("\tNULL,\n};\n"); 288 } 289} 290 291if (hfile) 292 close(hfile); 293if (cfile) 294 close(cfile); 295close(srcfile); 296 297exit 0; 298 299} 300