|
|
1.1 ! root 1: #ifdef TEST ! 2: #define NDSZ 64 ! 3: #else ! 4: #define NDSZ 1024/* for real systems (larger may be slower) */ ! 5: #endif ! 6: #define MAXKLEN (NDSZ/4)-8 ! 7: #if MAXKLEN > 255 ! 8: #undef MAXKLEN ! 9: #define MAXKLEN 255 ! 10: #endif ! 11: #define MXHT 5 ! 12: typedef long ndaddr; ! 13: /* for communication with users */ ! 14: typedef struct { ! 15: char *mdata; ! 16: unsigned short mlen; ! 17: } mbuf; ! 18: typedef struct bfile { ! 19: struct bfile *next; ! 20: struct hdr *path[MXHT + 1]; ! 21: char height, advnc, rdwrt, flag[MXHT + 1]; ! 22: ndaddr loc[MXHT + 1]; ! 23: int tfd, dfd; ! 24: char *fname, *altname; ! 25: struct rdptr { ! 26: struct dkey *rptr; /* current dkey */ ! 27: short rnum; /* its ordinal */ ! 28: char rpref[MAXKLEN]; /* first dcom bytes of its key */ ! 29: } rdptr; ! 30: char fatal; /* this bfile can't be used */ ! 31: } bfile; ! 32: extern bfile *bopen(); ! 33: extern mbuf bkey(); ! 34: ! 35: #define BERROR 100 /* first btree value of errno */ ! 36: #define BUTRAN BERROR + 0 /* user caused tran abort */ ! 37: #define BNOWRITE BERROR + 1 /* not opened for writing */ ! 38: #define BIOWRT BERROR + 2 /* wrote short record */ ! 39: #define BNOMEM BERROR + 3 /* no mem from malloc */ ! 40: #define BFATAL BERROR + 4 /* last chance for user */ ! 41: #define BTALL BERROR + 5 /* tree becoming taller than MXHT */ ! 42: #define BRDERR BERROR + 6 /* read short record or read error */ ! 43: #define BLASTE BERROR + 7 /* one past last btree value of errno */ ! 44: extern int errno; ! 45: ! 46: /* users can ignore the rest of this stuff */ ! 47: /* keys in nodes */ ! 48: typedef struct dkey { ! 49: unsigned char dlen; /* total size of structure */ ! 50: char dcom; /* bytes in common with preceding */ ! 51: char dkey[MAXKLEN]; /* rest of key */ ! 52: } dkey; ! 53: #define DKEYSZ 2 /* overhead in dkey */ ! 54: /* node header */ ! 55: typedef struct hdr { ! 56: long hstamp; /* for owning process */ ! 57: short kcnt; /* keys in node */ ! 58: char htype; ! 59: char hlev; ! 60: } hdr; ! 61: typedef struct { ! 62: short tfree; /* free bytes in node, at end for triv checking */ ! 63: } trailer; ! 64: #define nfree(p) ((trailer *)((char *)(p) + NDSZ - sizeof(trailer)))->tfree ! 65: #define SHARED 1 ! 66: #define INDEX 2 ! 67: #define READONLY 4 ! 68: #define bf_type(b, t) ((b)->path[0]->htype & (t)) ! 69: #define treeonly(b) bf_type(b, INDEX) ! 70: #define shared(b) bf_type(b, SHARED) ! 71: #define readonly(b) bf_type(b, READONLY) ! 72: /* disk addresses */ ! 73: typedef struct { ! 74: long lloc; ! 75: unsigned short llen; ! 76: } lfaddr; ! 77: #define ndadr(b, j) ((ndaddr *)((char *)(b) + NDSZ - sizeof(trailer)) - (j) - 1) ! 78: #define lfadr(b, j) ((lfaddr *)((char *)(b) + NDSZ - sizeof(trailer)) - (j) - 1) ! 79: #define mustwrite(bf, n) bf->flag[n] /* for getincore */ ! 80: /* node format: ! 81: * hdr, dkey, dkey, dkey, ..., space, adr, adrn, ..., adr0, trailer ! 82: */ ! 83: extern int bdump; /* dump on first fatal error */ ! 84: extern long tranid, getlpid(); /* unique transaction id */ ! 85: #ifndef EOF ! 86: #ifndef NULL ! 87: #define NULL 0 ! 88: #endif ! 89: #define EOF -1 ! 90: #endif ! 91: #define NOTFOUND 0 ! 92: #define FOUND 1 ! 93: ! 94: #define alloc(x) (x *)malloc(sizeof(x)) ! 95: #define stamped(b) b->hstamp == tranid ! 96: /*1000001111101111*/
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.