1: # include   "../ingres.h"
   2: # include   "../access.h"
   3: # include   "../aux.h"
   4: # include   "../lock.h"
   5: 
   6: /*
   7: **  READADMIN -- read admin file into 'Admin' cache
   8: **
   9: **	The admin file in the current directory is opened and read
  10: **	into the 'Admin' cache.  The admin file contains the following
  11: **	information:
  12: **
  13: **	A header block, containing the owner of the database (that is,
  14: **	the DBA), and a set of status bits for the database as a whole.
  15: **	These bits are defined in aux.h.
  16: **
  17: **	Descriptors for the relation and attribute relations.  These
  18: **	descriptors should be completely correct except for the
  19: **	relfp and relopn fields.  These are required so that the
  20: **	process of opening a relation is not recursive.
  21: **
  22: **	After the admin file is read in, the relation and attribute
  23: **	files are opened, and the relfp and relopn fields in both
  24: **	descriptors are correctly initialized.  Both catalogs are
  25: **	opened read/write.
  26: **
  27: **	Finally, the relation catalog is scanned for the entries
  28: **	of both catalogs, and the reltid field in both descriptors
  29: **	are filled in from this.  This is because of a bug in an
  30: **	earlier version of creatdb, which failed to initialize
  31: **	these fields correctly.  In fact, it is critical that these
  32: **	fields are correct in this implementation, since the reltid
  33: **	field is what uniquely identifies the cache buffer in the
  34: **	low-level routines.
  35: **
  36: **	WARNING:  This routine is redefined by creatdb.  If this
  37: **		routine is changed, check that program also!!
  38: **
  39: **	Parameters:
  40: **		none
  41: **
  42: **	Returns:
  43: **		none
  44: **
  45: **	Side Effects:
  46: **		The 'Admin' struct is filled in from the 'admin' file
  47: **			in the current directory.
  48: **		The 'relation....xx' and 'attribute...xx' files are
  49: **			opened.
  50: **
  51: **	Defined Constants:
  52: **		none
  53: **
  54: **	Defines:
  55: **		readadmin()
  56: **
  57: **	Requires:
  58: **		ingresname() -- to make the physical file name.
  59: **		get_reltuple() -- to read the tuples from the
  60: **			relation relation.
  61: **		'Admin' structure (see ../aux.h).
  62: **
  63: **	Called By:
  64: **		acc_init (in accbuf.c)
  65: **
  66: **	Files:
  67: **		./admin
  68: **			The bootstrap description of the database,
  69: **			described above.
  70: **
  71: **	Compilation Flags:
  72: **		none
  73: **
  74: **	Trace Flags:
  75: **		none
  76: **
  77: **	Diagnostics:
  78: **		none
  79: **
  80: **	Syserrs:
  81: **		open admin
  82: **			It was not possible to open the 'admin' file.
  83: **			This is virtually a total disaster.
  84: **		open rel
  85: **			It was not possible to open the 'relation...xx'
  86: **			file.
  87: **		open att
  88: **			It was not possible to open the 'attribute..xx'
  89: **			file.
  90: **		get_reltuple rel
  91: **			It was not possible to get the relation
  92: **			relation tuple for the relation relation.
  93: **			That is, it was not possible to get the
  94: **			"relation" tuple from the relation catalog.
  95: **		get_reltuple att
  96: **			Ditto, for the "attribute" tuple.
  97: **
  98: **	History:
  99: **		12/13/78 (rse) -- get_reltuple isn't called if relation
 100: **			is hashed. This always worked even in 6.0
 101: **		8/2/78 (eric) -- changed 'admin' read to be a single
 102: **			read, by combining all the admin info into
 103: **			one large struct (instead of three small
 104: **			ones).  See also access.h, accbuf.c,
 105: **			noclose.c, openr.c, dbu/modify.c,
 106: **			dbu/modupdate.c, ovqp/interp.c, and printr.
 107: **
 108: **		8/21/78 (michael) -- changed so that "attribute" opened
 109: **			r/w. relopen is left ro.
 110: */
 111: 
 112: readadmin()
 113: {
 114:     register int        i;
 115:     register int        retval;
 116:     struct descriptor   desc;
 117:     char            relname[MAXNAME + 4];
 118: 
 119:     /* read the stuff from the admin file */
 120:     i = open("admin", 0);
 121:     if (i < 0)
 122:         syserr("readadmin: open admin %d", i);
 123:     if (read(i, &Admin, sizeof Admin) != sizeof Admin)
 124:         syserr("readadmin: read err admin");
 125:     close(i);
 126: 
 127:     /* open the physical files for 'relation' and 'attribute' */
 128:     ingresname(Admin.adreld.relid, Admin.adreld.relowner, relname);
 129:     if ((Admin.adreld.relfp = open(relname, 2)) < 0)
 130:         syserr("readadmin: open rel %d", Admin.adreld.relfp);
 131:     ingresname(Admin.adattd.relid, Admin.adattd.relowner, relname);
 132:     if ((Admin.adattd.relfp = open(relname, 2)) < 0)
 133:         syserr("readadmin: open att %d", Admin.adattd.relfp);
 134:     Admin.adreld.relopn = (Admin.adreld.relfp + 1) * -5;
 135:     /* we just want to read here create, modify and destroy fix it up */
 136:     Admin.adattd.relopn = (Admin.adattd.relfp + 1) * 5;
 137: 
 138:     /* get the correct tid's (actually, should already be correct) */
 139:     /* (for compatability with 6.0 databases) */
 140:     if (Admin.adreld.relspec == M_HEAP)
 141:     {
 142:         if (retval = get_reltuple(&desc, "relation"))
 143:             syserr("readadmin: get_reltuple rel %d", retval);
 144:         bmove(&desc.reltid, &Admin.adreld.reltid, sizeof Admin.adreld.reltid);
 145:     }
 146:     if (Admin.adattd.relspec == M_HEAP)
 147:     {
 148:         if (retval = get_reltuple(&desc, "attribute"))
 149:             syserr("readadmin: get_reltuple att %d", retval);
 150:         bmove(&desc.reltid, &Admin.adattd.reltid, sizeof Admin.adattd.reltid);
 151:     }
 152: 
 153:     return (0);
 154: }

Defined functions

readadmin defined in line 112; used 1 times
Last modified: 1980-12-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2355
Valid CSS Valid XHTML 1.0 Strict