1: # include   <ingres.h>
   2: # include   <access.h>
   3: # include   <aux.h>
   4: # include   <lock.h>
   5: # include   <sccs.h>
   6: 
   7: SCCSID(@(#)page.c	8.3	2/8/85)
   8: 
   9: /*
  10: **	UNIX read/write counters
  11: */
  12: 
  13: long    Accuread, Accuwrite;
  14: long    Accusread;
  15: 
  16: /*
  17: **	GETPAGE - get the page on which tid is found
  18: **
  19: **
  20: **	Parameters:
  21: **		d - descriptor for relation
  22: **		tid - tid which specifies the page
  23: **
  24: **	Return Codes:
  25: **		0 - success
  26: **		-1, -2 - AMREAD_ERR, AMWRITE_ERR
  27: **
  28: **	Trace Flags:
  29: **		26.9, 26.10
  30: **
  31: **	Called by:
  32: **		fill_rel(), add_ovflo(), bndxsearch(), delete(),
  33: **		get(), getequal(), ndxsearch(), noclose(), replace()
  34: **		scan_dups()
  35: **
  36: */
  37: get_page(d, tid)
  38: register DESC   *d;
  39: TID     *tid;
  40: {
  41:     register int        i;
  42:     long            pageid;
  43:     register struct accbuf  *b;
  44:     struct accbuf       *b1;
  45:     int         lk;     /* lock condition*/
  46:     extern struct accbuf    *choose_buf();
  47:     extern long     lseek();
  48: 
  49: #	ifdef xATR3
  50:     if (tTf(26, 9))
  51:     {
  52:         printf("GET_PAGE: %.14s,", d->reldum.relid);
  53:         dumptid(tid);
  54:     }
  55: #	endif
  56: 
  57:     pluck_page(tid, &pageid);
  58:     if ((b = choose_buf(d, pageid)) == NULL)
  59:         return (-1);
  60:     top_acc(b);
  61:     lk = Acclock && (d->reldum.relstat & S_CONCUR) && (d->relopn < 0);
  62:     if ((b->thispage != pageid) || (lk && !(b->bufstatus & BUF_LOCKED)))
  63:     {
  64:         if (i = pageflush(b))
  65:             return (i);
  66: #		ifdef xATR1
  67:         if (tTf(26, 10))
  68:         {
  69:             printf("GET_PAGE: rdg pg %ld", pageid);
  70:             printf(",relid ");
  71:             dumptid((TID *) &d->reltid);
  72:         }
  73: #		endif
  74:         b->thispage = pageid;
  75:         if (lk)
  76:         {
  77:             b1 = Acc_head;
  78:             for (; b1 != 0; b1 = b1->modf)
  79:                 if (b1->bufstatus & BUF_LOCKED)
  80:                     pageflush(b1);  /*  */
  81:             if (setpgl(b) < 0)
  82:                 syserr("get-page: lk err");
  83:         }
  84:         if ((lseek(d->relfp, (long)(pageid * PGSIZE), 0) == -1) ||
  85:             (read(d->relfp, (char *) b, PGSIZE) != PGSIZE))
  86:         {
  87:             resetacc(b);
  88:             return (acc_err(AMREAD_ERR));
  89:         }
  90:         Accuread++;
  91:         if (d->reldum.relstat & S_CATALOG)
  92:         {
  93:             Accusread++;
  94:         }
  95:     }
  96:     return (0);
  97: }
  98: 
  99: /*
 100: **	PAGEFLUSH - flush the buffered page to disk
 101: **
 102: **	Parameters:
 103: **		buf - the buffer
 104: **
 105: **	Return Codes:
 106: **		0 -- successful
 107: **		AMWRITE_ERR - error in writing
 108: **
 109: **	Trace Flags:
 110: **		29.2, 29.3
 111: **
 112: */
 113: pageflush(buf)
 114: struct accbuf   *buf;
 115: {
 116:     register struct accbuf  *b;
 117:     register int        allbufs;
 118:     int         err;
 119: 
 120:     b = buf;
 121: #	ifdef xATR3
 122:     if (tTf(29, 2))
 123:     {
 124:         printf("PAGEFLUSH: %x=", b);
 125:         if (b != NULL)
 126:             dumptid(&b->rel_tupid);
 127:         else
 128:             printf("all\n");
 129:     }
 130: #	endif
 131:     err = FALSE;
 132:     allbufs = FALSE;
 133:     if (b == 0)
 134:     {
 135:         b = Acc_buf;
 136:         allbufs = TRUE;
 137:     }
 138: 
 139:     do
 140:     {
 141:         if (b->bufstatus & BUF_DIRTY)
 142:         {
 143: #			ifdef xATR1
 144:             if (tTf(29, 3))
 145:             {
 146:                 printf("PAGEFLUSH: wr pg %ld", b->thispage);
 147:                 printf(",stat %d,relid ", b->bufstatus);
 148:                 dumptid((TID *) &b->rel_tupid);
 149:             }
 150: #			endif
 151: 
 152: 
 153:             b->bufstatus &= ~BUF_DIRTY;
 154:             if ((lseek(b->filedesc, (long)(b->thispage * PGSIZE), 0)== -1) ||
 155:                 (write(b->filedesc, (char *) b, PGSIZE) != PGSIZE))
 156:             {
 157:                 resetacc(b);
 158:                 err = TRUE;
 159:             }
 160:             Accuwrite++;
 161: 
 162:         }
 163:         if (Acclock && b->bufstatus & BUF_LOCKED)
 164:             unlpg(b);
 165: 
 166:     } while (allbufs && (b = b->modf) != NULL);
 167: 
 168:     if (err)
 169:         return (acc_err(AMWRITE_ERR));
 170: 
 171:     return (0);
 172: }
 173: /*
 174: **  ACC_ERR -- set global error indicator "Accerror"
 175: **
 176: **	Trace Flags:
 177: **		20.4-5
 178: */
 179: 
 180: acc_err(errnum)
 181: int errnum;
 182: {
 183:     Accerror = errnum;
 184: #	ifdef xATR1
 185:     tTfp(20, 4, "ACC_ERR: %d\n", Accerror);
 186: #	endif
 187:     return (Accerror);
 188: }
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1165
Valid CSS Valid XHTML 1.0 Strict