[BACK]Return to vnode_if.sh CVS log [TXT][DIR] Up to [local] / sys / kern

Annotation of sys/kern/vnode_if.sh, Revision 1.1.1.1

1.1       nbrk        1: #!/bin/sh -
                      2: copyright="\
                      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. Neither the name of the University nor the names of its contributors
                     16:  *    may be used to endorse or promote products derived from this software
                     17:  *    without specific prior written permission.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     20:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     21:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     22:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     23:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     24:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     25:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     26:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     27:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     28:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     29:  * SUCH DAMAGE.
                     30:  */
                     31: "
                     32: SCRIPT_ID='$OpenBSD: vnode_if.sh,v 1.15 2006/01/02 05:05:11 jsg Exp $'
                     33: # SCRIPT_ID='$NetBSD: vnode_if.sh,v 1.9 1996/02/29 20:58:22 cgd Exp $'
                     34:
                     35: # Script to produce VFS front-end sugar.
                     36: #
                     37: # usage: vnode_if.sh srcfile
                     38: #      (where srcfile is currently /sys/kern/vnode_if.src)
                     39: #
                     40:
                     41: if [ $# -ne 1 ] ; then
                     42:        echo 'usage: vnode_if.sh srcfile'
                     43:        exit 1
                     44: fi
                     45:
                     46: # Name and revision of the source file.
                     47: src=$1
                     48: SRC_ID=`head -1 $src | sed -e 's/.*\$\(.*\)\$.*/\1/'`
                     49:
                     50: # Names of the created files.
                     51: out_c=vnode_if.c
                     52: out_h=../sys/vnode_if.h
                     53:
                     54: # Awk program (must support nawk extensions)
                     55: # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
                     56: awk=${AWK:-awk}
                     57:
                     58: # Does this awk have a "toupper" function? (i.e. is it GNU awk)
                     59: isgawk=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
                     60:
                     61: # If this awk does not define "toupper" then define our own.
                     62: if [ "$isgawk" = TRUE ] ; then
                     63:        # GNU awk provides it.
                     64:        toupper=
                     65: else
                     66:        # Provide our own toupper()
                     67:        toupper='
                     68: function toupper(str) {
                     69:        _toupper_cmd = "echo "str" |tr a-z A-Z"
                     70:        _toupper_cmd | getline _toupper_str;
                     71:        close(_toupper_cmd);
                     72:        return _toupper_str;
                     73: }'
                     74: fi
                     75:
                     76: #
                     77: # This is the common part of all awk programs that read $src
                     78: # This parses the input for one function into the arrays:
                     79: #      argdir, argtype, argname, willrele
                     80: # and calls "doit()" to generate output for the function.
                     81: #
                     82: # Input to this parser is pre-processed slightly by sed
                     83: # so this awk parser doesn't have to work so hard.  The
                     84: # changes done by the sed pre-processing step are:
                     85: #      insert a space beween * and pointer name
                     86: #      replace semicolons with spaces
                     87: #
                     88: sed_prep='s:\*\([^\*/]\):\* \1:g
                     89: s/;/ /'
                     90: awk_parser='
                     91: # Comment line
                     92: /^#/   { next; }
                     93: # First line of description
                     94: /^vop_/        {
                     95:        name=$1;
                     96:        argc=0;
                     97:        next;
                     98: }
                     99: # Last line of description
                    100: /^}/   {
                    101:        doit();
                    102:        next;
                    103: }
                    104: # Middle lines of description
                    105: {
                    106:        argdir[argc] = $1; i=2;
                    107:        if ($2 == "WILLRELE" ||
                    108:            $3 == "WILLRELE") {
                    109:                willrele[argc] = 1;
                    110:                i++;
                    111:        } else if ($2 == "WILLUNLOCK" ||
                    112:            $3 == "WILLUNLOCK") {
                    113:                willrele[argc] = 2;
                    114:                i++;
                    115:        } else if ($2 == "WILLPUT" ||
                    116:            $3 == "WILLPUT") {
                    117:                willrele[argc] = 3;
                    118:                i++;
                    119:        } else
                    120:                willrele[argc] = 0;
                    121:
                    122:        if ($2 == "SHOULDBELOCKED") {
                    123:           shouldbelocked[argc] = 1;
                    124:           i++;
                    125:        } else
                    126:           shouldbelocked[argc] = 0;
                    127:
                    128:        argtype[argc] = $i; i++;
                    129:        while (i < NF) {
                    130:                argtype[argc] = argtype[argc]" "$i;
                    131:                i++;
                    132:        }
                    133:        argname[argc] = $i;
                    134:        argc++;
                    135:        next;
                    136: }
                    137: '
                    138:
                    139: # This is put after the copyright on each generated file.
                    140: warning="\
                    141: /*
                    142:  * Warning: This file is generated automatically.
                    143:  * (Modifications made here may easily be lost!)
                    144:  *
                    145:  * Created from the file:
                    146:  *     ${SRC_ID}
                    147:  * by the script:
                    148:  *     ${SCRIPT_ID}
                    149:  */
                    150: "
                    151:
                    152: # This is to satisfy McKusick (get rid of evil spaces 8^)
                    153: anal_retentive='s:\([^/]\*\) :\1:g'
                    154:
                    155: #
                    156: # Redirect stdout to the H file.
                    157: #
                    158: echo "$0: Creating $out_h" 1>&2
                    159: exec > $out_h
                    160:
                    161: # Begin stuff
                    162: echo -n "$warning" | sed -e 's/\$//g'
                    163: echo ""
                    164: echo -n "$copyright"
                    165: echo '
                    166: extern struct vnodeop_desc vop_default_desc;
                    167: '
                    168:
                    169: echo '#include "systm.h"'
                    170:
                    171: # Body stuff
                    172: # This awk program needs toupper() so define it if necessary.
                    173: sed -e "$sed_prep" $src | $awk "$toupper"'
                    174: function doit() {
                    175:        # Declare arg struct, descriptor.
                    176:        printf("\nstruct %s_args {\n", name);
                    177:        printf("\tstruct vnodeop_desc * a_desc;\n");
                    178:        for (i=0; i<argc; i++) {
                    179:                printf("\t%s a_%s;\n", argtype[i], argname[i]);
                    180:        }
                    181:        printf("};\n");
                    182:        printf("extern struct vnodeop_desc %s_desc;\n", name);
                    183:        # Prototype it.
                    184:        protoarg = sprintf("int %s(", toupper(name));
                    185:        protolen = length(protoarg);
                    186:        printf("%s", protoarg);
                    187:        for (i=0; i<argc; i++) {
                    188:                protoarg = sprintf("%s", argtype[i]);
                    189:                if (i < (argc-1)) protoarg = (protoarg ", ");
                    190:                arglen = length(protoarg);
                    191:                if ((protolen + arglen) > 77) {
                    192:                        protoarg = ("\n    " protoarg);
                    193:                        arglen += 4;
                    194:                        protolen = 0;
                    195:                }
                    196:                printf("%s", protoarg);
                    197:                protolen += arglen;
                    198:        }
                    199:        printf(");\n");
                    200: }
                    201: BEGIN  {
                    202:        arg0special="";
                    203: }
                    204: END    {
                    205:        printf("\n/* Special cases: */\n#include <sys/buf.h>\n");
                    206:        argc=1;
                    207:        argtype[0]="struct buf *";
                    208:        argname[0]="bp";
                    209:        shouldbelocked[0] = 0;
                    210:        arg0special="->b_vp";
                    211:        name="vop_strategy";
                    212:        doit();
                    213:        name="vop_bwrite";
                    214:        doit();
                    215: }
                    216: '"$awk_parser" | sed -e "$anal_retentive"
                    217:
                    218: # End stuff
                    219: echo '
                    220: /* End of special cases. */'
                    221:
                    222:
                    223: #
                    224: # Redirect stdout to the C file.
                    225: #
                    226: echo "$0: Creating $out_c" 1>&2
                    227: exec > $out_c
                    228:
                    229: # Begin stuff
                    230: echo -n "$warning" | sed -e 's/\$//g'
                    231: echo ""
                    232: echo -n "$copyright"
                    233: echo '
                    234: #include <sys/param.h>
                    235: #include <sys/mount.h>
                    236: #include <sys/vnode.h>
                    237:
                    238: struct vnodeop_desc vop_default_desc = {
                    239:        0,
                    240:        "default",
                    241:        0,
                    242:        NULL,
                    243:        VDESC_NO_OFFSET,
                    244:        VDESC_NO_OFFSET,
                    245:        VDESC_NO_OFFSET,
                    246:        VDESC_NO_OFFSET,
                    247:        NULL,
                    248: };
                    249: '
                    250:
                    251: # Body stuff
                    252: sed -e "$sed_prep" $src | $awk '
                    253: function do_offset(typematch) {
                    254:        for (i=0; i<argc; i++) {
                    255:                if (argtype[i] == typematch) {
                    256:                        printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n",
                    257:                                name, argname[i]);
                    258:                        return i;
                    259:                };
                    260:        };
                    261:        print "\tVDESC_NO_OFFSET,";
                    262:        return -1;
                    263: }
                    264:
                    265: function doit() {
                    266:        # Define offsets array
                    267:        printf("\nint %s_vp_offsets[] = {\n", name);
                    268:        for (i=0; i<argc; i++) {
                    269:                if (argtype[i] == "struct vnode *") {
                    270:                        printf ("\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
                    271:                                name, argname[i]);
                    272:                }
                    273:        }
                    274:        print "\tVDESC_NO_OFFSET";
                    275:        print "};";
                    276:        # Define F_desc
                    277:        printf("struct vnodeop_desc %s_desc = {\n", name);
                    278:        # offset
                    279:        printf ("\t0,\n");
                    280:        # printable name
                    281:        printf ("\t\"%s\",\n", name);
                    282:        # flags
                    283:        printf("\t0");
                    284:        vpnum = 0;
                    285:        for (i=0; i<argc; i++) {
                    286:                if (willrele[i]) {
                    287:                        if (willrele[i] == 2) {
                    288:                                word = "UNLOCK";
                    289:                        } else if (willrele[i] == 3) {
                    290:                                word = "PUT";
                    291:                        } else {
                    292:                                word = "RELE";
                    293:                        }
                    294:                        if (argdir[i] ~ /OUT/) {
                    295:                                printf(" | VDESC_VPP_WILL%s", word);
                    296:                        } else {
                    297:                                printf(" | VDESC_VP%s_WILL%s", vpnum, word);
                    298:                        };
                    299:                        vpnum++;
                    300:                }
                    301:        }
                    302:        print ",";
                    303:        # vp offsets
                    304:        printf ("\t%s_vp_offsets,\n", name);
                    305:        # vpp (if any)
                    306:        do_offset("struct vnode **");
                    307:        # cred (if any)
                    308:        do_offset("struct ucred *");
                    309:        # proc (if any)
                    310:        do_offset("struct proc *");
                    311:        # componentname
                    312:        do_offset("struct componentname *");
                    313:        # transport layer information
                    314:        printf ("\tNULL,\n};\n");
                    315:
                    316:        # Define inline function.
                    317:        printf("\nint %s(", toupper(name));
                    318:        desclen = 5 + length(name);
                    319:        for (i=0; i<argc; i++) {
                    320:                arglen = length(argtype[i]) + length(argname[i]);
                    321:
                    322:                if (arglen + desclen > 77) {
                    323:                        printf("\n    ");
                    324:                        arglen += 4;
                    325:                        desclen = 0;
                    326:                }
                    327:                printf("%s %s", argtype[i], argname[i]);
                    328:                if (i < (argc-1)) {
                    329:                        printf(", ");
                    330:                        desclen += 2;
                    331:                }
                    332:                desclen += arglen;
                    333:        }
                    334:        printf(")\n");
                    335:        printf("{\n\tstruct %s_args a;\n", name);
                    336:        printf("\ta.a_desc = VDESC(%s);\n", name);
                    337:        for (i=0; i<argc; i++) {
                    338:                printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
                    339:                if (shouldbelocked[i]) {
                    340:                        printf ("#ifdef VFSDEBUG\n");
                    341:                        printf ("\tif ((%s->v_flag & VLOCKSWORK) && !VOP_ISLOCKED(%s))\n", argname[i], argname[i]);
                    342:                        printf ("\t\tpanic(\"%s: %s\");\n", name, argname[i]);
                    343:                        printf ("#endif\n");
                    344:                }
                    345:        }
                    346:        printf("\treturn (VCALL(%s%s, VOFFSET(%s), &a));\n}\n",
                    347:                argname[0], arg0special, name);
                    348:
                    349: }
                    350: BEGIN  {
                    351:        arg0special="";
                    352: }
                    353: END    {
                    354:        printf("\n/* Special cases: */\n");
                    355:        argc=1;
                    356:        argtype[0]="struct buf *";
                    357:        argdir[0]="IN";
                    358:        argname[0]="bp";
                    359:        shouldbelocked[0] = 0;
                    360:        arg0special="->b_vp";
                    361:        willrele[0]=0;
                    362:        name="vop_strategy";
                    363:        doit();
                    364:        name="vop_bwrite";
                    365:        doit();
                    366: }
                    367: '"$awk_parser" | sed -e "$anal_retentive"
                    368:
                    369: # End stuff
                    370: echo '
                    371: /* End of special cases. */'
                    372:
                    373: # Add the vfs_op_descs array to the C file.
                    374: # Begin stuff
                    375: echo '
                    376: struct vnodeop_desc *vfs_op_descs[] = {
                    377:        &vop_default_desc,      /* MUST BE FIRST */
                    378:        &vop_strategy_desc,     /* XXX: SPECIAL CASE */
                    379:        &vop_bwrite_desc,       /* XXX: SPECIAL CASE */
                    380: '
                    381:
                    382: # Body stuff
                    383: sed -e "$sed_prep" $src | $awk '
                    384: function doit() {
                    385:        printf("\t&%s_desc,\n", name);
                    386: }
                    387: '"$awk_parser"
                    388:
                    389: # End stuff
                    390: echo ' NULL
                    391: };
                    392: '
                    393:
                    394: exit 0
                    395:
                    396: # Local Variables:
                    397: # tab-width: 4
                    398: # End:

CVSweb