The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/tools/vnode_if.awk

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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: releng/5.1/sys/tools/vnode_if.awk 103986 2002-09-26 04:48:44Z jeff $
   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 
   44 function usage()
   45 {
   46         print "usage: vnode_if.awk <srcfile> [-c|-h]";
   47         exit 1;
   48 }
   49 
   50 function die(msg, what)
   51 {
   52         printf msg "\n", what > "/dev/stderr";
   53         exit 1;
   54 }
   55 
   56 function 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 ...
   63 function printc(s) {print s > cfile;}
   64 function printh(s) {print s > hfile;}
   65 
   66 function add_debug_code(name, arg, pos)
   67 {
   68         if (lockdata[name, arg, pos]) {
   69                 printh("\tASSERT_VI_UNLOCKED("arg", \""uname"\");");
   70                 # Add assertions for locking
   71                 if (lockdata[name, arg, pos] == "L")
   72                         printh("\tASSERT_VOP_LOCKED("arg", \""uname"\");");
   73                 else if (lockdata[name, arg, pos] == "U")
   74                         printh("\tASSERT_VOP_UNLOCKED("arg", \""uname"\");");
   75                 else if (0) {
   76                         # XXX More checks!
   77                 }
   78         }
   79 }
   80 
   81 function add_debug_pre(name)
   82 {
   83         if (lockdata[name, "pre"]) {
   84                 printh("#ifdef  DEBUG_VFS_LOCKS");
   85                 printh("\t"lockdata[name, "pre"]"(&a);");
   86                 printh("#endif");
   87         }
   88 }
   89 
   90 function add_debug_post(name)
   91 {
   92         if (lockdata[name, "post"]) {
   93                 printh("#ifdef  DEBUG_VFS_LOCKS");
   94                 printh("\t"lockdata[name, "post"]"(&a, rc);");
   95                 printh("#endif");
   96         }
   97 }
   98 
   99 function find_arg_with_type (type)
  100 {
  101         for (jj = 0; jj < numargs; jj++) {
  102                 if (types[jj] == type) {
  103                         return "VOPARG_OFFSETOF(struct " \
  104                             name "_args,a_" args[jj] ")";
  105                 }
  106         }
  107 
  108         return "VDESC_NO_OFFSET";
  109 }
  110 
  111 BEGIN{
  112 
  113 # Process the command line
  114 for (i = 1; i < ARGC; i++) {
  115         arg = ARGV[i];
  116         if (arg !~ /^-[ch]+$/ && arg !~ /\.src$/)
  117                 usage();
  118         if (arg ~ /^-.*c/)
  119                 cfile = "vnode_if.c";
  120         if (arg ~ /^-.*h/)
  121                 hfile = "vnode_if.h";
  122         if (arg ~ /\.src$/)
  123                 srcfile = arg;
  124 }
  125 ARGC = 1;
  126 
  127 if (!cfile && !hfile)
  128         exit 0;
  129 
  130 if (!srcfile)
  131         usage();
  132 
  133 common_head = \
  134     "/*\n" \
  135     " * This file is produced automatically.\n" \
  136     " * Do not modify anything in here by hand.\n" \
  137     " *\n" \
  138     " * Created from $FreeBSD: releng/5.1/sys/tools/vnode_if.awk 103986 2002-09-26 04:48:44Z jeff $\n" \
  139     " */\n" \
  140     "\n";
  141 
  142 if (hfile)
  143         printh(common_head "extern struct vnodeop_desc vop_default_desc;");
  144 
  145 if (cfile) {
  146         printc(common_head \
  147             "#include <sys/param.h>\n" \
  148             "#include <sys/systm.h>\n" \
  149             "#include <sys/vnode.h>\n" \
  150             "\n" \
  151             "struct vnodeop_desc vop_default_desc = {\n" \
  152             "   1,\t\t\t/* special case, vop_default => 1 */\n" \
  153             "   \"default\",\n" \
  154             "   0,\n" \
  155             "   NULL,\n" \
  156             "   VDESC_NO_OFFSET,\n" \
  157             "   VDESC_NO_OFFSET,\n" \
  158             "   VDESC_NO_OFFSET,\n" \
  159             "   VDESC_NO_OFFSET,\n" \
  160             "   NULL,\n" \
  161             "};\n");
  162 }
  163 
  164 while ((getline < srcfile) > 0) {
  165         if (NF == 0)
  166                 continue;
  167         if ($1 ~ /^#%/) {
  168                 if (NF != 6  ||  $1 != "#%"  || \
  169                     $2 !~ /^[a-z]+$/  ||  $3 !~ /^[a-z]+$/  || \
  170                     $4 !~ /^.$/  ||  $5 !~ /^.$/  ||  $6 !~ /^.$/)
  171                         continue;
  172                 if ($3 == "vpp")
  173                         $3 = "*vpp";
  174                 lockdata["vop_" $2, $3, "Entry"] = $4;
  175                 lockdata["vop_" $2, $3, "OK"]    = $5;
  176                 lockdata["vop_" $2, $3, "Error"] = $6;                  
  177                 continue;
  178         }
  179 
  180         if ($1 ~ /^#!/) {
  181                 if (NF != 4 || $1 != "#!")
  182                         continue;
  183                 if ($3 != "pre" && $3 != "post")
  184                         continue;
  185                 lockdata["vop_" $2, $3] = $4;
  186                 continue;
  187         }
  188         if ($1 ~ /^#/)
  189                 continue;
  190 
  191         # Get the function name.
  192         name = $1;
  193         uname = toupper(name);
  194 
  195         # Start constructing a ktrpoint string
  196         ctrstr = "\"" uname;
  197         # Get the function arguments.
  198         for (numargs = 0; ; ++numargs) {
  199                 if ((getline < srcfile) <= 0) {
  200                         die("Unable to read through the arguments for \"%s\"",
  201                             name);
  202                 }
  203                 if ($1 ~ /^\};/)
  204                         break;
  205 
  206                 # Delete comments, if any.
  207                 gsub (/\/\*.*\*\//, "");
  208 
  209                 # Condense whitespace and delete leading/trailing space.
  210                 gsub(/[[:space:]]+/, " ");
  211                 sub(/^ /, "");
  212                 sub(/ $/, "");
  213 
  214                 # Pick off direction.
  215                 if ($1 != "INOUT" && $1 != "IN" && $1 != "OUT")
  216                         die("No IN/OUT direction for \"%s\".", $0);
  217                 dirs[numargs] = $1;
  218                 sub(/^[A-Z]* /, "");
  219 
  220                 if ((reles[numargs] = $1) == "WILLRELE")
  221                         sub(/^[A-Z]* /, "");
  222                 else
  223                         reles[numargs] = "WONTRELE";
  224 
  225                 # kill trailing ;
  226                 if (sub(/;$/, "") < 1)
  227                         die("Missing end-of-line ; in \"%s\".", $0);
  228 
  229                 # pick off variable name
  230                 if ((argp = match($0, /[A-Za-z0-9_]+$/)) < 1)
  231                         die("Missing var name \"a_foo\" in \"%s\".", $0);
  232                 args[numargs] = substr($0, argp);
  233                 $0 = substr($0, 1, argp - 1);
  234 
  235                 # what is left must be type
  236                 # remove trailing space (if any)
  237                 sub(/ $/, "");
  238                 types[numargs] = $0;
  239 
  240                 # We can do a maximum of 6 arguments to CTR*
  241                 if (numargs <= 6) {
  242                         if (numargs == 0)
  243                                 ctrstr = ctrstr "(" args[numargs];
  244                         else
  245                                 ctrstr = ctrstr ", " args[numargs];
  246                         if (types[numargs] ~ /\*/)
  247                                 ctrstr = ctrstr " 0x%lX";
  248                         else
  249                                 ctrstr = ctrstr " %ld";
  250                 }
  251         }
  252         if (numargs > 6)
  253                 ctrargs = 6;
  254         else
  255                 ctrargs = numargs;
  256         ctrstr = "\tCTR" ctrargs "(KTR_VOP, " ctrstr ")\"";
  257         for (i = 0; i < ctrargs; ++i)
  258                 ctrstr = ctrstr ", " args[i];
  259         ctrstr = ctrstr ");";
  260 
  261         if (hfile) {
  262                 # Print out the vop_F_args structure.
  263                 printh("struct "name"_args {\n\tstruct vnodeop_desc *a_desc;");
  264                 for (i = 0; i < numargs; ++i)
  265                         printh("\t" t_spc(types[i]) "a_" args[i] ";");
  266                 printh("};");
  267 
  268                 # Print out extern declaration.
  269                 printh("extern struct vnodeop_desc " name "_desc;");
  270 
  271                 # Print out function.
  272                 printh("static __inline int " uname "(");
  273                 for (i = 0; i < numargs; ++i) {
  274                         printh("\t" t_spc(types[i]) args[i] \
  275                             (i < numargs - 1 ? "," : ")"));
  276                 }
  277                 printh("{\n\tstruct " name "_args a;");
  278                 printh("\tint rc;");
  279                 printh("\ta.a_desc = VDESC(" name ");");
  280                 for (i = 0; i < numargs; ++i)
  281                         printh("\ta.a_" args[i] " = " args[i] ";");
  282                 for (i = 0; i < numargs; ++i)
  283                         add_debug_code(name, args[i], "Entry");
  284                 add_debug_pre(name);
  285                 printh("\trc = VCALL(" args[0] ", VOFFSET(" name "), &a);");
  286                 printh(ctrstr);
  287                 printh("if (rc == 0) {");
  288                 for (i = 0; i < numargs; ++i)
  289                         add_debug_code(name, args[i], "OK");
  290                 printh("} else {");
  291                 for (i = 0; i < numargs; ++i)
  292                         add_debug_code(name, args[i], "Error");
  293                 printh("}");
  294                 add_debug_post(name);
  295                 printh("\treturn (rc);\n}");
  296         }
  297 
  298         if (cfile) {
  299                 # Print out the vop_F_vp_offsets structure.  This all depends
  300                 # on naming conventions and nothing else.
  301                 printc("static int " name "_vp_offsets[] = {");
  302                 # as a side effect, figure out the releflags
  303                 releflags = "";
  304                 vpnum = 0;
  305                 for (i = 0; i < numargs; i++) {
  306                         if (types[i] == "struct vnode *") {
  307                                 printc("\tVOPARG_OFFSETOF(struct " name \
  308                                     "_args,a_" args[i] "),");
  309                                 if (reles[i] == "WILLRELE") {
  310                                         releflags = releflags \
  311                                             "|VDESC_VP" vpnum "_WILLRELE";
  312                                 }
  313                                 vpnum++;
  314                         }
  315                 }
  316 
  317                 sub(/^\|/, "", releflags);
  318                 printc("\tVDESC_NO_OFFSET");
  319                 printc("};");
  320 
  321                 # Print out the vnodeop_desc structure.
  322                 printc("struct vnodeop_desc " name "_desc = {");
  323                 # offset
  324                 printc("\t0,");
  325                 # printable name
  326                 printc("\t\"" name "\",");
  327                 # flags
  328                 vppwillrele = "";
  329                 for (i = 0; i < numargs; i++) {
  330                         if (types[i] == "struct vnode **" && \
  331                             reles[i] == "WILLRELE") {
  332                                 vppwillrele = "|VDESC_VPP_WILLRELE";
  333                         }
  334                 }
  335 
  336                 if (!releflags)
  337                         releflags = "0";
  338                 printc("\t" releflags vppwillrele ",");
  339 
  340                 # vp offsets
  341                 printc("\t" name "_vp_offsets,");
  342                 # vpp (if any)
  343                 printc("\t" find_arg_with_type("struct vnode **") ",");
  344                 # cred (if any)
  345                 printc("\t" find_arg_with_type("struct ucred *") ",");
  346                 # thread (if any)
  347                 printc("\t" find_arg_with_type("struct thread *") ",");
  348                 # componentname
  349                 printc("\t" find_arg_with_type("struct componentname *") ",");
  350                 # transport layer information
  351                 printc("\tNULL,\n};\n");
  352         }
  353 }
  354  
  355 if (hfile)
  356         close(hfile);
  357 if (cfile)
  358         close(cfile);
  359 close(srcfile);
  360 
  361 exit 0;
  362 
  363 }

Cache object: b3b2c1345f0757fe8f6f43141c926f99


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.