Annotation of XNU/bsd/vfs/vnode_if.sh, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.