1: # include   "../ingres.h"
   2: # include   "../aux.h"
   3: # include   "../unix.h"
   4: # include   "../access.h"
   5: 
   6: /*
   7: **  OPENCATALOG -- open system catalog
   8: **
   9: **	This routine opens a system catalog into a predetermined
  10: **	cache.  If the catalog is already open, it is not reopened.
  11: **
  12: **	The 'Desxx' struct defines which relations may be opened
  13: **	in this manner and is defined in .../source/aux.h.
  14: **
  15: **	The relation should not be closed after use (except in
  16: **	special cases); however, it should be noclose'd after use
  17: **	if the number of tuples in the catalog may have changed.
  18: **
  19: **	The Desxx structure has an alias field which
  20: **	is the address of the 'Admin' structure cache which holds
  21: **	the relation descriptor.  Thus, an openr need never actually
  22: **	occur.
  23: **
  24: **	The actual desxx structure definition is in the file
  25: **
  26: **		catalog_desc.c
  27: **
  28: **	which defines which relations can be cached and if any
  29: **	alias descriptors exist for the relations. That file
  30: **	can be redefined to include various caching.
  31: **
  32: **
  33: **	Parameters:
  34: **		name -- the name of the relation to open.  It must
  35: **			match one of the names in the Desxx
  36: **			structure.
  37: **		mode -- just like 'mode' to openr.  If zero, it
  38: **			is opened read-only; if two, it is opened
  39: **			read/write.  In fact, the catalog is always
  40: **			opened read/write, but the flags are set
  41: **			right for concurrency to think that you are
  42: **			using it as you have declared.
  43: **
  44: **	Returns:
  45: **		none
  46: **
  47: **	Side Effects:
  48: **		A relation is (may be) opened.
  49: **
  50: **	Requires:
  51: **		Desxx -- a structure which defines the relations which
  52: **			may be opened. A default structure is defined in
  53: **			catalog_desc.c
  54: **
  55: **	Called By:
  56: **		most dbu routines.
  57: **		qrymod.
  58: **		parser.
  59: **		creatdb.
  60: **
  61: **	Trace Flags:
  62: **		none
  63: **
  64: **	Diagnostics:
  65: **		none
  66: **
  67: **	Syserrs:
  68: **		opencatalog: (%s)
  69: **			The indicated relation was not present in
  70: **			the Desxx structure.
  71: **		opencatalog: open(%s)
  72: **			The indicated physical file could not be
  73: **			opened.
  74: **		opencatalog(%s): mode %d
  75: **			You specified a bad mode (not 0 or 2).
  76: **
  77: **	History:
  78: **		12/19/78 (epa) -- added a call to 'acc_init' if the
  79: **			aliased form (avoiding an openr) is used.
  80: **		12/12/78 (rse) -- structure definition moved to aux.h
  81: **		10/6/78 (rse) -- catalog_desc.c broken off, and the
  82: **			whole routine was moved to the utility library.
  83: **		8/23/78 (eric) -- physical open of files dropped,
  84: **			since we can reuse the file descriptors
  85: **			from the Admin struct.
  86: */
  87: 
  88: int         Files[MAXFILES];
  89: 
  90: opencatalog(name, mode)
  91: char    *name;
  92: int mode;
  93: {
  94:     int             i;
  95:     register struct descriptor  *d;
  96:     register char           *n;
  97:     register struct desxx       *p;
  98:     extern struct desxx     Desxx[];
  99: 
 100:     n = name;
 101: 
 102:     /* find out which descriptor it is */
 103:     for (p = Desxx; p->cach_relname; p++)
 104:         if (sequal(n, p->cach_relname))
 105:             break;
 106:     if (!p->cach_relname)
 107:         syserr("opencatalog: (%s)", n);
 108: 
 109:     d = p->cach_desc;
 110: 
 111:     /* if it's already open, just return */
 112:     if (d->relopn)
 113:     {
 114:         clearkeys(d);
 115:     }
 116:     else
 117:     {
 118:         /* not open, open it */
 119:         if (p->cach_alias)
 120:         {
 121:             acc_init();
 122:             bmove(p->cach_alias, d, sizeof (*d));
 123:         }
 124:         else
 125:         {
 126:             if ((i = openr(d, 2, n)) != 0)
 127:                 syserr("opencatalog: openr(%s) %d", n, i);
 128:         }
 129: 
 130:         /* mark it as an open file */
 131:         Files[d->relfp] = 0;
 132:     }
 133: 
 134:     /* determine the mode to mark it as for concurrency */
 135:     switch (mode)
 136:     {
 137:       case 0:   /* read only */
 138:         d->relopn = abs(d->relopn);
 139:         break;
 140: 
 141:       case 2:   /* read-write */
 142:         d->relopn = -abs(d->relopn);
 143:         break;
 144: 
 145:       default:
 146:         syserr("opencatalog(%s): mode %d", n, mode);
 147:     }
 148: 
 149:     return;
 150: }

Defined functions

opencatalog defined in line 90; used 64 times

Defined variables

Files defined in line 88; used 6 times
Last modified: 1980-12-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2561
Valid CSS Valid XHTML 1.0 Strict