Annotation of 42BSD/ingres/source/iutil/openr.c, revision 1.1

1.1     ! root        1: # include      <ingres.h>
        !             2: # include      <aux.h>
        !             3: # include      <access.h>
        !             4: # include      <symbol.h>
        !             5: # include      <sccs.h>
        !             6: 
        !             7: SCCSID(@(#)openr.c     7.1     2/5/81)
        !             8: 
        !             9: /*
        !            10: **  OPENR -- Open a relation into a descriptor
        !            11: **
        !            12: **     Openr will open the named relation into the given descriptor
        !            13: **     according to the mode specified. When searching for a name,
        !            14: **     a relation owner by the current user will be searched for first.
        !            15: **     If none is found then one owned by the DBA will be search for.
        !            16: **
        !            17: **     There are several available modes for opening a relation. The
        !            18: **     most common are
        !            19: **             mode 0 -- open for reading
        !            20: **             mode 2 -- open for writing (mode 1 works identically).
        !            21: **     Other modes which can be used to optimize performance:
        !            22: **             mode -1 -- get relation-relation tuple and tid only.
        !            23: **                             Does not open the relation.
        !            24: **             mode -2 -- open relation for reading after a previous
        !            25: **                             call of mode -1.
        !            26: **             mode -3 -- open relation for writing after a previous
        !            27: **                             call of mode -1.
        !            28: **             mode -4 -- open relation for reading. Assumes that relation
        !            29: **                             was previously open (eg relation & attributed
        !            30: **                             have been filled) and file was closed by closer.
        !            31: **             mode -5 -- open relation for writing. Same assumptions as
        !            32: **                             mode -4.
        !            33: **
        !            34: **     Parameters:
        !            35: **             dx - a pointer to a struct descriptor (defined in ingres.h)
        !            36: **             mode - can be 2,0,-1,-2,-3,-4,-5
        !            37: **             name - a null terminated name (only first 12 chars looked at)
        !            38: **
        !            39: **     Returns:
        !            40: **             1 - relation does not exist
        !            41: **             0 - ok
        !            42: **             <0 - error. Refer to the error codes in access.h
        !            43: **
        !            44: **     Side Effects:
        !            45: **             Opens the physical file if required. Fill the
        !            46: **             descriptor structure. Initializes the access methods
        !            47: **             if necessary.
        !            48: **
        !            49: **     Trace Flags:
        !            50: **             90
        !            51: */
        !            52: 
        !            53: 
        !            54: openr(d, mode, name)
        !            55: register DESC  *d;
        !            56: int            mode;
        !            57: char           *name;
        !            58: {
        !            59:        register int    retval, filemode;
        !            60:        char            filename[MAXNAME+3];
        !            61: 
        !            62: #      ifdef xATR1
        !            63:        if (tTf(21, 0))
        !            64:                printf("openr:%.12s,%d\n", name, mode);
        !            65: #      endif
        !            66: #      ifdef xATM
        !            67:        if (tTf(76, 2))
        !            68:                timtrace(21, 0);
        !            69: #      endif
        !            70: 
        !            71:        /* init admin */
        !            72:        acc_init();
        !            73: 
        !            74:        /* process according to mode */
        !            75: 
        !            76:        filemode = 0;
        !            77:        switch (mode)
        !            78:        {
        !            79: 
        !            80:          case -1:
        !            81:                retval = get_reltup(d, name);
        !            82:                break;
        !            83: 
        !            84:          case 1:
        !            85:          case 2:
        !            86:                filemode = 2;
        !            87: 
        !            88:          case 0:
        !            89:                if (retval = get_reltup(d, name))
        !            90:                        break;
        !            91: 
        !            92:          case -2:
        !            93:          case -3:
        !            94:                if (retval = get_attuples(d))
        !            95:                        break;
        !            96: 
        !            97:          case -5:
        !            98:                if (mode == -3 || mode == -5)
        !            99:                        filemode = 2;
        !           100: 
        !           101:          case -4:
        !           102:                clearkeys(d);
        !           103:                /* descriptor is filled. open file */
        !           104:                ingresname(d->reldum.relid, d->reldum.relowner, filename);
        !           105:                /* can't open a view */
        !           106:                if (d->reldum.relstat & S_VIEW)
        !           107:                {
        !           108:                        retval = acc_err(AMOPNVIEW_ERR);        /* view */
        !           109:                        break;
        !           110:                }
        !           111:                if ((d->relfp = open(filename, filemode)) < 0)
        !           112:                {
        !           113:                        retval = acc_err(AMNOFILE_ERR); /* can't open file */
        !           114:                        break;
        !           115:                }
        !           116:                d->relopn = (d->relfp + 1) * 5;
        !           117:                if (filemode == 2)
        !           118:                        d->relopn = -d->relopn;
        !           119:                d->reladds = 0;
        !           120:                retval = 0;
        !           121:                break;
        !           122: 
        !           123:          default:
        !           124:                syserr("openr:bd md=%d", mode);
        !           125:        }
        !           126: 
        !           127:        /* return */
        !           128: 
        !           129: #      ifdef xATR1
        !           130:        if (tTf(21, 4) && mode != -1 && retval != 1)
        !           131:                printdesc(d);
        !           132:        if (tTf(21, 0))
        !           133:                printf("openr rets %d\n", retval);
        !           134: #      endif
        !           135: 
        !           136: #      ifdef xATM
        !           137:        if (tTf(76, 2))
        !           138:                timtrace(22, 0);
        !           139: #      endif
        !           140:        return (retval);
        !           141: }
        !           142: /*
        !           143: **  GET_ATTUPLES -- get tuples from attribute relation for this relation
        !           144: */
        !           145: 
        !           146: get_attuples(d)
        !           147: register DESC  *d;
        !           148: {
        !           149:        struct attribute        attr, attkey;
        !           150:        register int            i, dom;
        !           151:        int                     numatts;
        !           152:        TID                     tid1, tid2;
        !           153: 
        !           154:        clearkeys(&Admin.adattd);
        !           155: 
        !           156:        /* zero all format types */
        !           157:        for (i = 0; i <= d->reldum.relatts; i++)
        !           158:                d->relfrmt[i] = 0;
        !           159: 
        !           160:        /* prepare to scan attribute relation */
        !           161:        setkey(&Admin.adattd, (char *) &attkey, d->reldum.relid, ATTRELID);
        !           162:        setkey(&Admin.adattd, (char *) &attkey, d->reldum.relowner, ATTOWNER);
        !           163:        if (i = find(&Admin.adattd, EXACTKEY, &tid1, &tid2, &attkey))
        !           164:                return (i);
        !           165: 
        !           166:        numatts = d->reldum.relatts;
        !           167: 
        !           168:        while (numatts && !get(&Admin.adattd, &tid1, &tid2, &attr, TRUE))
        !           169:        {
        !           170: 
        !           171:                /* does this attribute belong? */
        !           172:                if (bequal(&attr, &attkey, MAXNAME + 2))
        !           173:                {
        !           174: 
        !           175:                        /* this attribute belongs */
        !           176:                        dom = attr.attid;       /* get domain number */
        !           177: 
        !           178:                        if (d->relfrmt[dom])
        !           179:                                break;  /* duplicate attribute. force error */
        !           180: 
        !           181:                        numatts--;
        !           182:                        d->reloff[dom] = attr.attoff;
        !           183:                        d->relfrmt[dom] = attr.attfrmt;
        !           184:                        d->relfrml[dom] = attr.attfrml;
        !           185:                        d->relxtra[dom] = attr.attxtra;
        !           186:                }
        !           187:        }
        !           188: 
        !           189:        d->relfrmt[0] = INT;
        !           190:        d->relfrml[0] = 4;
        !           191:        /* make sure all the atributes were there */
        !           192:        for (dom = 1; dom <= d->reldum.relatts; dom++)
        !           193:                if (d->relfrmt[dom] == 0)
        !           194:                        numatts = 1;    /* force an error */
        !           195:        if (numatts)
        !           196:                i = acc_err(AMNOATTS_ERR);
        !           197: 
        !           198:        flush_rel(&Admin.adattd, TRUE);
        !           199: 
        !           200: #      ifdef xATR1
        !           201:        if (tTf(21, 3))
        !           202:                printf("get_attr ret %d\n", i);
        !           203: #      endif
        !           204: 
        !           205:        return (i);
        !           206: }

unix.superglobalmegacorp.com

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