home *** CD-ROM | disk | FTP | other *** search
- /*
- * common utility routines
- *
- * This program is the CONFIDENTIAL and PROPRIETARY property
- * of FairCom(R) Corporation. Any unauthorized use, reproduction or
- * transfer of this program is strictly prohibited.
- *
- * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989 FairCom Corporation
- * (Subject to limited distribution and
- * restricted disclosure only.)
- * *** ALL RIGHTS RESERVED ***
- *
- * 4006 West Broadway
- * Columbia, MO 65203
- *
- *
- * c-tree(R) Version 4.3
- * Release C
- * February 7, 1989 17:30
- *
- */
-
- /*
- * **** Remove the following define statement
- */
-
- #define NO_SPARSE
-
- /*
- * **** to allow sparse files on file extension.
- */
-
-
- #include "ctstdr.h" /* standard i/o header */
- #include "ctoptn.h" /* c-tree configuration options */
- #include "cterrc.h" /* c-tree error codes */
- #include "ctstrc.h" /* c-tree data structures */
- #include "ctgvar.h" /* c-tree global variables */
-
- #ifdef KEYTEST
- #undef KEYTEST
- #endif
- #ifndef VARLKEYS
- #define KEYTEST
- #endif
- #ifndef FLOATKEY
- #ifndef KEYTEST
- #define KEYTEST
- #endif
- #endif
-
-
- #ifdef CTSERVER
- #include "ctcomm.h"
-
- extern TEXT *srvmsg,*srvdat;
- extern UCOUNT srvsiz;
- extern MESSAGE omsg;
-
- #ifndef NO_SPARSE
- #define NO_SPARSE
- #endif
-
- #endif
-
- RNDFILE mbopen();
- COUNT mbclos(),ctio(),mbsave();
- VOID terr();
-
- /*
- * see if update on read only file
- */
-
- chkredf( ctnum)
- FAST CTFILE *ctnum;
- {
- #ifdef CTSERVER
- ctnum = ctnum->hmem;
- #else
- ctnum -= ctnum->kmem;
- #endif
- if (ctnum->flmode & READFIL)
- return(uerr_cod = REDF_ERR);
- else
- return(NO_ERROR);
- }
-
- /*
- ** find available ct file control blocks
- */
-
- POINTER SERIALNUM(datno)
- PFAST COUNT datno;
- {
- #ifdef FPUTFGET
- COUNT redhdr();
- #endif
- CTFILE *tstfnm();
- FAST CTFILE *dnum;
-
- uerr_cod = 0;
- if ((dnum = tstfnm(datno)) == NULL) /* then error condition */
- return(DRNZERO);
-
- #ifdef FPUTFGET
- if ((dnum->flmode & SHARED) && redhdr(dnum)) /* then error */
- return(DRNZERO);
- #endif
- return(dnum->sernum);
- }
-
-
- #ifdef CTSERVER
-
- COUNT avlfil;
-
- COUNT getctf()
- {
- FAST CTFILE *ctnum;
-
- if (avlfil <= 0)
- return(-1);
-
- for (ctnum = ct_key; ctnum < ct_key + ct_mxfil; ctnum++)
- if (ctnum->chnacs == 'n') {
- avlfil--;
- ctnum->chnacs = 'c';
- ctnum->hmem = ctnum;
- ctnum->xmem = NULL;
- return((COUNT) (ctnum - ct_key));
- }
-
- terr(997);
- }
-
- COUNT getctm(blocks,btnum)
- COUNT blocks;
- CTFILE *btnum;
- {
- FAST CTFILE *ctnum;
- CTFILE *ltnum;
- FAST COUNT i;
- COUNT j;
-
- if (blocks > avlfil)
- return(-1);
-
- ltnum = btnum;
- for (i = j = 0, ctnum = ct_key; i++ < ct_mxfil && j < blocks; ctnum++) {
- if (ctnum->chnacs == 'n') {
- ctnum->hmem = btnum;
- ltnum->xmem = ctnum;
- ltnum = ctnum;
- ctnum->chnacs = 'c';
- j++;
- }
- }
-
- if (j < blocks)
- terr(998);
-
- ltnum->xmem = NULL;
- avlfil -= blocks;
-
- return(0);
- }
-
- VOID retctf(filno)
- COUNT filno;
- {
- FAST CTFILE *ctnum;
-
- ctnum = ct_key + filno;
- do {
- ctnum->chnacs = 'n';
- ctnum = ctnum->xmem;
- avlfil++;
- } while (ctnum != (CTFILE *) NULL);
- }
-
- #else
-
- COUNT STPUSR()
- {
- return(uerr_cod = NO_ERROR);
- }
- COUNT TRANSACTION(mode)
- COUNT mode;
- {
- return(uerr_cod = NO_ERROR);
- }
-
- #endif
-
- /* --------------------------------------------------------------------
- routine to initialize buffer space and status variables
- */
-
- COUNT INTREE(bufs,fils,sect)
-
- COUNT bufs,fils,sect;
-
- {
- FAST COUNT i;
- TREEBUFF *buf;
- CTFILE *ctnum;
- COUNT valsiz;
- TEXT *buforg,*valoff;
-
- TEXT *mballc();
- COUNT uerr();
-
- /*
- * be sure that one and only one of each mutually
- * exclusive choice has been selected and compose
- * version byte for header records.
- */
-
-
- #ifndef LOW_HIGH
- #ifdef UNIFRMAT
- ct_ver = (LH_VER | CT_V4E);
- #else
- ct_ver = (HL_VER | CT_V4E);
- #endif
- #ifndef HIGH_LOW
- terr(200);
- #endif
- #else
- ct_ver = (LH_VER | CT_V4E);
- #ifdef HIGH_LOW
- terr(201);
- #endif
- #endif
-
- /* ******************** */
-
- #ifndef NOTFORCE
- #ifndef FPUTFGET
- #ifndef FPUTONLY
- terr(202);
- #endif
- #endif
- #endif
-
- #ifdef NOTFORCE
- #ifdef FPUTFGET
- terr(203);
- #endif
- #ifdef FPUTONLY
- terr(203);
- #endif
- #else
- #ifdef FPUTFGET
- #ifdef FPUTONLY
- terr(203);
- #endif
- #endif
- #endif
-
-
- /* ******************** */
-
- uerr_cod = 0;
- if (bufs < 3 || sect < 1 || fils < 0)
- return(uerr(SPRM_ERR));
- if (ct_key != NULL)
- return(uerr(IINT_ERR));
-
- if ((ct_btree = (TREEBUFF *) mballc(bufs,sizeof(TREEBUFF))) == NULL)
- return(uerr(SPAC_ERR));
- if ((ct_key = (CTFILE *) mballc(fils,sizeof(CTFILE))) == NULL) {
- mbfree(ct_btree);
- return(uerr(SPAC_ERR));
- }
- ct_dat = ct_key;
- ct_vat = ct_key;
-
- valsiz = sect * SECSIZ + MAXLEN + sizeof(POINTER);
- if ((ct_origin = (TEXT *) mballc(bufs,valsiz)) == NULL) {
- mbfree(ct_key);
- ct_key = NULL;
- mbfree(ct_btree);
- return(uerr(SPAC_ERR));
- }
- valoff = (buforg = ct_origin) + STATUS;
-
- ct_mxbuf = bufs;
- #ifdef CTSERVER
- ct_mxfil = avlfil = fils;
- #else
- ct_mxfil = fils;
- #endif
- ct_ndsec = sect;
- ct_lacs = ct_lfil = ct_numvfil = ct_npath[0] = 0;
-
- for (i = 0,buf = ct_btree; i++ < ct_mxbuf; buf++) {
- buf->keyid = -1;
- buf->update = 'n';
- buf->nodacs = 0;
- buf->nodorg = buforg;
- buf->ct_kyval = valoff;
- buforg += valsiz;
- valoff += valsiz;
- }
-
- for (i = 0,ctnum = ct_key; i++ < ct_mxfil; ctnum++) {
- ctnum->usecnt = 0;
- ctnum->chnacs = 'n';
- }
-
- return(NO_ERROR);
- }
-
-
- /* ------------------------------------------------------------------
- extend file size
- */
-
- POINTER extfil(ctnum,rsize)
- PFAST CTFILE *ctnum;
- unsigned int rsize;
-
- { /* extfil assumes that (in multi-user system) header is locked */
- POINTER retval,oldval;
- #ifdef NO_SPARSE
- POINTER oldphy;
- FAST COUNT i;
- #endif
-
- COUNT uerr();
-
- #ifdef CTSERVER
- omsg.mseqn = 0;
- ctnum = ctnum->hmem;
- #else
- ctnum -= ctnum->kmem;
- #endif
-
- retval = (oldval = ctnum->numrec) + 1;
- ctnum->numrec += rsize;
- #ifdef NO_SPARSE
- oldphy = ctnum->phyrec;
- #endif
- if (oldval > ctnum->numrec) {
- uerr(FULL_ERR);
- return(DRNZERO);
- } else if (ctnum->numrec <= ctnum->phyrec)
- return(retval);
- else if (ctnum->extsiz <= rsize) {
- ctnum->phyrec = ctnum->numrec;
- return(retval);
- } else { /* extend file by chunk and save directory contents */
- if (ctnum->phyrec < (ctnum->extsiz - 1))
- ctnum->phyrec = ctnum->extsiz - 1;
- else
- ctnum->phyrec += ctnum->extsiz;
-
- if (ctnum->phyrec < ctnum->numrec) {
- /* overflow */
- ctnum->phyrec = ctnum->numrec;
- return(retval);
- }
- #ifdef NO_SPARSE
- for (i = 0; i < CTBUFSIZ; i++)
- ct_buf[i] = DELFLG;
- for (i = (ctnum->phyrec - oldphy++) / CTBUFSIZ; i-- > 0; ) {
- if (ctio(CTWRITE,ctnum,oldphy,ct_buf,CTBUFSIZ))
- break;
- oldphy += CTBUFSIZ;
- }
- if (i = ctnum->phyrec - oldphy + 1) {
- if (uerr_cod || ctio(CTWRITE,ctnum,oldphy,ct_buf,i)) {
- /* couldn't extend by a chunk */
- uerr_cod = 0;
- ctnum->phyrec = ctnum->numrec;
- return(retval);
- }
- }
- #else /* sparse */
- ct_buf[0] = DELFLG;
- if (ctnum->clstyp == DAT_CLOSE) /* fill-in delete flags */
- for (oldval = retval; oldval < ctnum->phyrec;
- oldval += ctnum->reclen)
- if (ctio(CTWRITE,ctnum,oldval,ct_buf,1))
- break;
- if (uerr_cod || ctio(CTWRITE,ctnum,ctnum->phyrec,ct_buf,1)) {
- /* couldn't extend by a chunk */
- uerr_cod = 0;
- ctnum->phyrec = ctnum->numrec;
- return(retval);
- }
- #endif
- if (mbsave(ctnum))
- return(DRNZERO);
- return(retval);
- }
- }
-
-
- /* --------------------------------------------------------------------
- utility to test for valid file number and determine if file
- corresponding to ctnum has been activated. returns NULL ptr if error.
- */
-
- CTFILE *tstfnm(filno)
- COUNT filno;
-
- {
- FAST CTFILE *retval,*ctnum;
- COUNT nomemb;
-
- COUNT uerr();
- UCOUNT inrfil();
-
- uerr_cod = NO_ERROR;
- #ifndef CTSERVER
- if (ct_mxfil == 0) {
- uerr(FINT_ERR);
- return(NULL);
- } else
- #endif
- if (filno < 0 || ct_mxfil <= filno) { /* filno out of range */
- uerr(FNUM_ERR);
- return(NULL);
- } else
- retval = ct_key + filno;
-
- switch (retval->chnacs) {
- case 'n':
- uerr_cod = FACS_ERR;
- return(NULL);
- case 'y':
- retval->usecnt = inrfil(retval);
- return(retval);
- case 'v':
- case 'w':
- #ifdef CTSERVER
- ctnum = retval->hmem;
- #else
- ctnum = retval - retval->kmem;
- #endif
- nomemb = ctnum->nmem;
- ctnum->usecnt = 0;
- #ifdef CT_ANSI
- if ((ctnum->fd = mbopen(ctnum,ctnum->flmode)) ==
- (RNDFILE) NULL) {
- #else
- if ((ctnum->fd = mbopen(ctnum,ctnum->flmode)) < 0) {
- #endif
- uerr_cod = VRTO_ERR;
- return(NULL);
- } else {
- ctnum->usecnt = inrfil(retval);
- #ifdef CTSERVER
- for (filno = 0; filno++ <= nomemb; ctnum = ctnum->xmem)
- #else
- for (filno = 0; filno++ <= nomemb; ctnum++)
- #endif
- ctnum->chnacs = ctnum->chnacs == 'w' ? 'm' : 'y';
- return(retval);
- }
- default:
- terr(222);
- }
- }
-
-
- /* ------------------------------------------------------------ */
-
- COUNT vtclose()
-
- {
- FAST CTFILE *ctnum;
- CTFILE *fndnum;
- FAST COUNT i;
- UCOUNT lstusd;
-
- COUNT CLSFIL();
-
- for (i = 0, ctnum = ct_key, fndnum = NULL, lstusd = MAXAGE;
- i++ < ct_mxfil; ctnum++)
- if (ctnum->usecnt && ctnum->usecnt <= lstusd &&
- ctnum->chnacs == 'y' && ctnum->kmem < 1 &&
- !(ctnum->flmode & PERMANENT) && !ctnum->lokcnt)
- lstusd = (fndnum = ctnum)->usecnt;
-
- if ((ctnum = fndnum) == NULL)
- return(NO);
- else {
- if (CLSFIL(ctnum->filnum,ctnum->flmode))
- return(NO);
-
- ctnum->usecnt = 0;
- #ifdef CTSERVER
- for (i = 0; i++ <= fndnum->nmem; ctnum = ctnum->xmem)
- #else
- for (i = 0; i++ <= fndnum->nmem; ctnum++)
- #endif
- ctnum->chnacs = ctnum->chnacs == 'm' ? 'w' : 'v';
- return(YES);
- }
- }
-
- /* ---------------------------------------------------------------- */
-
- UCOUNT inrfil(ctnum)
- PFAST CTFILE *ctnum;
-
- {
- CTFILE *calnum;
- FAST COUNT i;
- UCOUNT minage;
-
- #ifdef CTSERVER
- ctnum = (calnum = ctnum)->hmem;
- #else
- ctnum -= (calnum = ctnum)->kmem;
- #endif
- if (ctnum->flmode & PERMANENT) /* not a virtual file */
- return(0);
- else if (++ct_lfil) /* then file age did not rollover */
- return(calnum->usecnt = ct_lfil);
-
- for (i = 0, ctnum = ct_key, minage = MAXAGE; i++ < ct_mxfil; ctnum++)
- if (ctnum->usecnt && ctnum->usecnt <= minage &&
- ctnum->kmem < 1)
- minage = ctnum->usecnt;
-
- ct_lfil = MAXAGE - (--minage);
- for (i = 0, ctnum = ct_key; i++ < ct_mxfil; ctnum++)
- if (ctnum->usecnt)
- ctnum->usecnt -= minage;
- return(calnum->usecnt = ++ct_lfil);
- }
-
- /* --------------------------------------------------------------------
- test to see if update flag is set. if not, set it.
- */
-
- COUNT tstupd(ctnum)
- PFAST CTFILE *ctnum;
-
- {
- #ifdef NOTFORCE
-
- COUNT wrthdr();
-
- #ifdef CTSERVER
- ctnum = ctnum->hmem;
- #else
- ctnum -= ctnum->kmem;
- #endif
- if (!(ctnum->updflg)) {
- ctnum->updflg = UPDATED;
- if (wrthdr(ctnum))
- return(uerr_cod);
- }
- #endif
- return(NO_ERROR);
- }
-
- #ifdef UNIFRMAT
-
- VOID revwrd(tp,wrdcnt)
- PFAST TEXT *tp;
- PFAST COUNT wrdcnt;
- { /* assumes that revbyt alraedy called */
- TEXT ch1,ch2;
-
- while (wrdcnt-- > 0) {
- ch1 = *tp++;
- ch2 = *tp++;
- *(tp - 2) = *tp;
- *tp++ = ch1;
- *(tp - 2) = *tp;
- *tp++ = ch2;
- }
- }
-
- VOID revhdr(ctnum)
- PFAST CTFILE *ctnum;
- {
- revbyt(ctnum,8);
- revbyt(&ctnum->nument,22);
- revwrd(&ctnum->nument,7);
- }
-
- #endif
-
- /* --------------------------------------------------------------------
- read file header record
- */
-
- COUNT redhdr(ctnum)
- PFAST CTFILE *ctnum;
- {
- FAST COUNT i;
- COUNT nomemb;
- POINTER recbyt;
- #ifdef CTSERVER
- CTFILE *mtnum;
- COUNT uerr();
-
- mtnum = ctnum;
- #endif
-
- if (ctio(CTREAD,ctnum,recbyt = DRNZERO,ctnum,HDRSIZ))
- return(uerr_cod);
- #ifdef UNIFRMAT
- revhdr(ctnum);
- #endif
- if (ctnum->clstyp == IDX_CLOSE) {
- nomemb = ctnum->nmem;
- #ifdef CTSERVER
- if (getctm(nomemb,ctnum) < 0)
- return(uerr(SNMC_ERR));
- #endif
- for (i = 1; i <= nomemb; i++) {
- recbyt += HDRSIZ;
- #ifdef CTSERVER
- mtnum = mtnum->xmem;
- if (ctio(CTREAD,ctnum,recbyt,mtnum,HDRSIZ))
- #else
- if (ctio(CTREAD,ctnum,recbyt,ctnum + i,HDRSIZ))
- #endif
- return(uerr_cod);
- #ifdef UNIFRMAT
- #ifdef CTSERVER
- revhdr(mtnum);
- #else
- revhdr(ctnum + i);
- #endif
- #endif
- }
- }
- return(NO_ERROR);
- }
-
-
- /* --------------------------------------------------------------------
- write file header record
- */
-
- COUNT wrthdr(ctnum)
- PFAST CTFILE *ctnum;
- {
- FAST COUNT i;
- COUNT nomemb;
- POINTER recbyt;
- #ifdef CTSERVER
- FAST CTFILE *mtnum;
-
- mtnum = ctnum = ctnum->hmem;
- #else
- ctnum -= ctnum->kmem;
- #endif
- nomemb = ctnum->nmem;
- for (i = 0,recbyt = 0; i <= nomemb; i++,recbyt += HDRSIZ) {
- #ifdef UNIFRMAT
- #ifdef CTSERVER
- cpybuf(ct_buf,mtnum,HDRSIZ);
- #else
- cpybuf(ct_buf,ctnum + i,HDRSIZ);
- #endif
- revhdr(ct_buf);
- if (ctio(CTWRITE,ctnum,recbyt,ct_buf,HDRSIZ))
- return(uerr_cod);
- #else
- #ifdef CTSERVER
- if (ctio(CTWRITE,ctnum,recbyt,mtnum,HDRSIZ))
- #else
- if (ctio(CTWRITE,ctnum,recbyt,ctnum + i,HDRSIZ))
- #endif
- return(uerr_cod);
- #endif
- #ifdef CTSERVER
- mtnum = mtnum->xmem;
- #endif
- }
-
- return(NO_ERROR);
- }
-
-
- COUNT OPNFIL(filno,filnam,filmod)
- COUNT filno; /* data number temporary assigned to file */
- TEXT *filnam; /* pointer to file name */
- COUNT filmod; /* EXCLUSIVE/SHARED VIRTUAL/PERMANENT */
- {
- FAST CTFILE *ctnum,*knum;
- COUNT opnflg;
- #ifdef KEYTEST
- COUNT i;
- #endif
- COUNT wrthdr(),redhdr(),uerr();
-
- uerr_cod = opnflg = NO;
- ctnum = ct_key + filno;
- if (filno < 0 || ct_mxfil <= filno)
- uerr_cod = FNUM_ERR;
- #ifdef CTSERVER
- else if (ctnum->chnacs != 'c')
- terr(996);
- #else
- else if (ctnum->chnacs != 'n')
- uerr_cod = FUSE_ERR;
- #endif
- else {
- if ((filmod & NONEXCLUSIVE) == NONEXCLUSIVE)
- /* set READFIL flag if SHARED & READFIL both on */
- filmod &= ~SHARED;
- strcpy(ctnum->flname,filnam);
- ctnum->usecnt = 0;
- #ifdef CT_ANSI
- if ((ctnum->fd = mbopen(ctnum,filmod)) == (RNDFILE) NULL)
- #else
- if ((ctnum->fd = mbopen(ctnum,filmod)) < 0)
- #endif
- /* does not exist */
- uerr_cod = FNOP_ERR;
- else {
- opnflg = YES;
- if (redhdr(ctnum))
- /* no further action */ ;
- else if (ctnum->clstyp < DAT_CLOSE ||
- ctnum->clstyp > VAT_CLOSE)
- uerr_cod = FUNK_ERR;
- else if (ctnum->recsiz > (ct_ndsec * SECSIZ))
- uerr_cod = KSIZ_ERR;
- else if (ctnum->verson != ct_ver)
- uerr_cod = FVER_ERR;
- else if (ctnum->length > MAXLEN)
- uerr_cod = KLEN_ERR;
- else if (ctnum->updflg == COMPACT)
- uerr_cod = FCMP_ERR;
- else if (ctnum->nmem > MAXMEMB || ctnum->kmem > 0)
- uerr_cod = KMEM_ERR;
- else if (ctnum->updflg || (ctnum->clstyp != IDX_CLOSE &&
- ctnum->nmem > 0))
- uerr_cod = FCRP_ERR;
- #ifndef VARLDATA
- else if (ctnum->clstyp == VAT_CLOSE)
- uerr_cod = FTYP_ERR;
- #endif
-
- #ifdef KEYTEST
- #ifdef CTSERVER
- else for (knum = ctnum, i = 0; i <= ctnum->nmem; i++,
- knum = knum->xmem) {
- #else
- else for (knum = ctnum, i = 0; i <= ctnum->nmem; i++,
- knum++) {
- #endif
- #ifndef VARLKEYS
- if (knum->ktype & COL_BOTH)
- uerr_cod = KTYP_ERR;
- #endif
- #ifndef FLOATKEY
- if (knum->ktype == SFLOATKEY ||
- knum->ktype == DFLOATKEY)
- uerr_cod = KTYP_ERR;
- #endif
- }
- #endif
- }
- }
-
- if (uerr_cod) {
- if (opnflg)
- mbclos(ctnum,COMPLETE);
- return(uerr_cod);
- } else {
- if (ctnum->clstyp == VAT_CLOSE)
- filmod |= VLENGTH;
- if (ctnum->flmode != filmod) {
- if (!((ctnum->flmode = filmod) & READFIL) &&
- wrthdr(ctnum)) {
- opnflg = uerr_cod;
- mbclos(ctnum,COMPLETE);
- return(uerr(opnflg));
- }
- }
- ctnum->filnum = filno;
- ctnum->usecnt = inrfil(ctnum);
- ctnum->srlpos = 0;
- #ifdef CTSERVER
- for (knum = ctnum, filno = 0; filno <= ctnum->nmem; filno++,
- knum = knum->xmem) {
- if (knum->chnacs != 'c')
- terr(994);
- knum->filnum = (COUNT) (knum - ct_key);
- if (filno != 0)
- #ifdef CT_ANSI
- knum->fd = (RNDFILE) NULL;
- #else
- knum->fd = -1;
- #endif
- #else
- for (knum = ctnum; filno <= (ctnum->filnum + ctnum->nmem);
- filno++,knum++) {
- if (knum->chnacs != 'n' && knum->chnacs != 'm') {
- mbclos(ctnum,COMPLETE);
- return(uerr(FUSE_ERR));
- }
- knum->filnum = filno;
- if (filno > ctnum->filnum)
- #ifdef CT_ANSI
- knum->fd = (RNDFILE) NULL;
- #else
- knum->fd = -1;
- #endif
- #endif
- knum->chnacs = 'y';
- knum->retelm = knum->lokcnt = 0;
- knum->retnod = NODEZERO;
- }
- return(NO_ERROR);
- }
- }
-
- /* --------------------------------------------------------------------
- write node contained in buffer to disk file. returns non-zero value if
- error.
- */
-
- COUNT wrtnod( buffer)
- PFAST TREEBUFF *buffer; /* pointer to buffer containing node to be
- written to disk */
- {
- FAST KEYFILE *knum; /* key number pointer */
- COUNT membno;
-
- /* set file pointer & member # */
-
- membno = (knum = ct_key + buffer->keyid)->kmem;
- if (membno > 0)
- #ifdef CTSERVER
- knum = knum->hmem;
- #else
- knum -= membno;
- #endif
-
- /* check member number */
-
- if (buffer->bmem != membno)
- terr(230);
-
- /* move node status info to i/o buffer */
-
- cpybuf(buffer->nodorg,&buffer->sucesr,STATUS);
-
- #ifdef UNIFRMAT
- revbyt(buffer->nodorg,6);
- revwrd(buffer->nodorg,2);
- #endif
-
- /* write node to disk */
-
- if (ctio(CTWRITE,knum,buffer->nodeid,buffer->nodorg,knum->recsiz))
- return(uerr_cod);
-
- buffer->update = 'n';
-
- #ifdef FPUTFGET
-
- /* clobber buffer status information so that subsequent calls to getnod
- will not think that buffer contains a valid node
- */
- if (knum->flmode & SHARED) {
- buffer->keyid = -1;
- buffer->nodeid = -1;
- }
- #endif
-
- return(NO_ERROR);
- }
-
-
- /* --------------------------------------------------------------------
- routine to close files
- */
-
- COUNT CLSFIL(filno,filmod)
- COUNT filno;
- COUNT filmod; /* COMPLETE or PARTIAL */
- {
- FAST COUNT i;
- FAST CTFILE *ctnum;
- FAST TREEBUFF *buf;
- CTFILE *knum;
- COUNT lowi,hghi;
-
- COUNT wrthdr(),wrtnod(),uerr();
-
- uerr_cod = 0;
- ctnum = ct_key + filno;
- if (filno < 0 || ct_mxfil <= filno)
- return(uerr(FNUM_ERR));
- else if (ctnum->chnacs == 'n')
- return(uerr(FACS_ERR));
- else if (ctnum->kmem > 0)
- return(uerr(KMEM_ERR));
- else if (ctnum->chnacs == 'v') {
- #ifdef CTSERVER
- for (i = 0, knum = ctnum; i++ <= ctnum->nmem; knum = knum->xmem)
- #else
- for (i = 0, knum = ctnum; i++ <= ctnum->nmem; knum++)
- #endif
- knum->chnacs = 'n';
- return(NO_ERROR);
- }
-
-
- if (ctnum->clstyp != DAT_CLOSE) {
- #ifdef CTSERVER
- #ifdef EXTRABFR
- if clsxbuf(filno))
- return(uerr_cod);
- #endif
- for (i = 0, buf = ct_btree; i < ct_mxbuf; i++, buf++) {
- if (buf->keyid >= 0 && (ct_key + buf->keyid)->hmem == ctnum) {
- #else
- lowi = ctnum->filnum;
- hghi = lowi + ctnum->nmem;
- for (i = 0, buf = ct_btree; i < ct_mxbuf; i++, buf++) {
- if (buf->keyid >= lowi && buf->keyid <= hghi) {
- #endif
- if (buf->update == 'y') {
- if (ctnum->updflg) {
- if (wrtnod(buf))
- return(uerr_cod);
- } else
- terr(206);
- }
- buf->keyid = -1;
- }
- }
- }
-
- #ifdef CTSERVER
- for (i = 0,knum = ctnum; i++ <= ctnum->nmem; knum = knum->xmem)
- #else
- for (i = 0,knum = ctnum; i++ <= ctnum->nmem; knum++)
- #endif
- if (knum->chnacs != 'm') knum->chnacs = 'n';
-
- if (ctnum->updflg) {
- ctnum->updflg = NO;
- if (wrthdr(ctnum))
- return(uerr_cod);
- }
-
- if (mbclos(ctnum,filmod) < 0)
- return(uerr(FCLS_ERR));
- return(NO_ERROR);
- }
-
- /* end of ctinit.c */
-