Merge branch 'master' into cde-next
[oweals/cde.git] / cde / lib / tt / mini_isam / isam_impl.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
24 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
25 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
26 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
27 /*%%  $TOG: isam_impl.h /main/4 1998/03/16 14:41:21 mgreess $                                                    */
28 /* @(#)isam_impl.h      1.11 93/09/07 */
29
30 /*
31  * Copyright (c) 1988 by Sun Microsystems, Inc.
32  */
33
34 /*
35  * isam_impl.h
36  *
37  * Description:
38  *      NetISAM implementation specific definitions
39  *
40  */
41
42 #ifndef _ISAM_IMPL_H
43 #define _ISAM_IMPL_H
44
45 #include <assert.h> 
46 #include <stdio.h>
47 #include <fcntl.h>
48 #include <setjmp.h>
49 #include <string.h>
50 #include <errno.h>
51 #include <sys/types.h>
52 #include <sys/param.h>
53 #include <sys/time.h>
54 /* AIX does not define FD_SETSIZE in sys/types.h. */
55 #if !defined(FD_SETSIZE)
56 #include <sys/select.h>
57 #endif
58
59 /*
60  * #include sys/types.h is to get u_long, u_short, dev_t
61  *
62  * #include sys/param.h is to get MAXHOSTNAMELEN
63  */
64
65 #include "isam.h"
66
67 /*
68  * Static is used in definitions of local functions. It is defined to 
69  * "static" normally, but to an empty string when compiled for profiling
70  * purposes (-p or -pg options to the cc compiler). If a function is
71  * defined as static, then the profiling tools account the time spent in
72  * this function to the physically previous global function which is
73  * incorrect and makes the output of the profiler tools useless.
74  */
75 #if defined(PROF) || defined(GPROF)
76 #define Static  
77 #else
78 #define Static static
79 #endif
80
81 extern int isdupl;
82
83 typedef long Recno;                          /* record numbers */
84 typedef long Blkno;                          /* block numbers */
85 typedef long Time;                           /* standard UNIX time */
86 typedef int  Isfd;                           /* ISAM file descriptor */
87
88 typedef int  Bool;
89 #ifndef FALSE
90 #define FALSE   0
91 #define TRUE    1
92 #endif
93
94 #define ISOPENMODE      0xff                 /* Mask to get ISINPUT/ISOUTPUT */
95                                              /* or ISINOUT */
96 #define ISLOCKMODE      0xff00               /* Mask to get lock mode */
97 #define ISREADMODE      0xff                 /* Mask to get ISFIRST, etc. */
98
99 #define ISLENMODE       0x10000              /* Mask to get FIX/VAR length */
100
101 #define ISPAGESIZE      1024                 /* page size */
102
103 #define N_CNTL_PAGES    2                    /* 
104                                               * Number of control pages 
105                                               * at the beg. of .rec file 
106                                               */
107 #define ISCNTLSIZE      (ISPAGESIZE * N_CNTL_PAGES)
108
109
110 #define ISMAGIC         "NetISAM"            /* 'magic number' in ISAM files */
111
112 #ifndef ISVERSION
113 #define ISVERSION       "Unknown"
114 #endif
115
116 #define MAXFCB_UNIXFD   30                   /* Maximum number of UNIX fd
117                                               * used by the FCB module
118                                               */
119
120 #define ISLEAFSLACK     10                   /* Default slack in leaves */
121
122 /* Default RPC timeout values */
123 #define ISRPCS_TO_DEF   60                   /* secs for short oper. */
124 #define ISRPCL_TO_DEF  (120 * 60)            /* secs for long oper. */
125 #define ISTCP_TO_DEF   (3 * 60)              /* secs to reconnect TCP/IP */
126 #define ISRPC_POLL_TO_DEF 30                 /* interval to hear from polled client */
127 #define ISTCP_RETRY_SLEEP 5                  /* time between tries to
128                                               * establish a connection 
129                                               */
130
131 /* 
132  * The X/OPEN ISAM internal data representations.
133  * The #define statements are used to declare type lengths and offsets
134  * in structures in order for the definitions to be compiler independent.
135  */
136
137 #define TIMETYPE        LONGTYPE             /* standard UNIX time */
138 #define TIMESIZE        LONGSIZE        
139
140 #define BLKNOTYPE       LONGTYPE             /* block (page) numbers */
141 #define BLKNOSIZE       LONGSIZE
142
143 #define RECNOTYPE       LONGTYPE             /* record numbers */
144 #define RECNOSIZE       LONGSIZE
145
146 /* 
147  * SHORTTYPE is a safeguard - if the X/OPEN ISAM changes INTTYPE to 4 bytes 
148  * all the internals of NetISAM will work. The only change will be
149  * re-defining SHORTTYPE.       
150  */
151
152 #define SHORTTYPE       INTTYPE              
153 #define SHORTSIZE       INTSIZE
154
155 /* The following defines are used in isstart() */
156 #define WHOLEKEY        0
157 #define USE_PHYS_ORDER(keydesc)  (keydesc->k_nparts == 0)
158
159 /* Structure for storing and passing variable length byte array data */
160 typedef struct bytearray {
161     u_short     length;
162     char        *data;
163 } Bytearray;
164
165 extern Bytearray _bytearr_getempty(), _bytearr_dup();
166 extern Bytearray _bytearr_new(u_short len, char *data);
167 extern void _bytearr_free();
168
169
170 /* Client identification - used to identify owners of locks */
171 /*
172    #define IPADDRLEN    4
173 */
174
175 /* Definitions related to ISAM file descriptor (isfd.c file) */
176 #define MAXISFD         FD_SETSIZE
177 #define NOISFD          (-1)                 /* Not a valid file descriptor */
178
179 extern struct fab *_isfd_find();
180 extern void _isfd_delete();
181 extern Isfd _isfd_insert();
182
183 /* Definitions related to File access block (isfab.c file */
184
185 /* File open mode */
186 enum openmode  { OM_INPUT = 0, OM_OUTPUT = 1, OM_INOUT = 2, OM_BADMODE = 3};
187 enum lockmode  { LM_FAST = 0, LM_EXCL = 1, LM_AUTOMATIC = 2, LM_MANUAL = 3, LM_BADMODE = 4}; 
188
189 /* isread() read modes */
190 enum readmode { RM_FIRST = 0, RM_LAST = 1, RM_NEXT = 2, RM_PREV = 3, 
191                     RM_CURR = 4, RM_EQUAL = 5, RM_GREAT = 6, RM_GTEQ = 7,
192                     RM_LESS = 8, RM_LTEQ = 9, RM_BADMODE = 10 };
193
194 /* lock flag is passed to Access Method module for every record oriented op. */
195 /* Bit position in the lock flag: */
196
197 enum openmode _getopenmode();
198 enum readmode _getreadmode();
199
200 /* Error code structure */
201 struct errcode {
202     int         iserrno;
203     char        isstat [4];
204 };
205
206 typedef struct fab {
207     Isfd                isfd;                /* ISAM file descriptor */
208     enum openmode       openmode;            /* File access mode */
209     enum lockmode       lockmode;            /* File lock mode */
210     Bool                locked;              /* TRUE if file is locked */
211     Bool                varlength;           /* TRUE if variable length records
212                                               * supported by this ISAM file */
213     int                 minreclen;           /* Minimum record length */
214     int                 maxreclen;           /* Maximum record length */
215     char                *isamhost;           /* IP host name */
216     char                *isfname;            /* ISAM file local pathname */
217     Bytearray           isfhandle;           /* ISAM file handle */
218     Bytearray           curpos;              /* Current record position */
219     struct errcode      errcode;             /* Error codes structure */
220 } Fab;
221
222 /* values for filemode */
223 #define LOCAL_FILE      0
224 #define REMOTE_FILE     1
225 #define NFS_FILE        2                    /* File is remote, but is
226                                               * accessed via NFS
227                                               */
228
229 #define FAB_ISFDSET(fab, isfd) (fab->isfd = isfd)
230
231 extern Fab *_fab_new();
232 void _fab_destroy();
233
234 /* ISAM file identification for locking purposes. */
235 typedef struct lckfid {
236     dev_t               diskid;              /* Disk device id */
237     ino_t               inode;               /* .rec file inode number */
238 } Lckfid; 
239
240 /* File Control Block */
241 typedef struct fcb {
242     char                *isfname;            /* ISAM file name */
243     int                 blocksize;           /* Block size */
244     Bool                rdonly;              /* file is read-only */
245     Lckfid              lckfid;              /* File id for locking */
246     int                 datfd;               /* UNIX file descr. of .rec file */
247     int                 indfd;               /* UNIX file descr. of .ind file */
248     int                 varfd;               /* UNIX file descr. of .var file */
249     Blkno               datsize;             /* dat file size in blocks */
250     Blkno               indsize;             /* ind file size in blocks */
251     Blkno               varsize;             /* var file size in blocks */
252     Bool                varflag;             /* TRUE if variable length*/
253     long                nrecords;            /* Number of records */
254     int                 minreclen;           /* Minimum record length */
255     int                 maxreclen;           /* Maximum record length */
256     Recno               lastrecno;           /* Last recno in use */
257     Recno               freerecno;           /* Pointer to first free record */
258     int                 lastkeyid;           /* Last key identifier used */
259     int                 changestamp1;        /* Stamp 1 of last change */
260     int                 changestamp2;        /* Stamp 2 of last change */
261     Blkno               indfreelist;         /* Head of freepage list of .ind */
262
263     int                 nkeys;               /* Number of keys */
264     struct keydesc2     *keys;               /* Key descriptors */
265     long                varend;              /* Offset of the last byte */
266                                              /* in .var file */
267     int                 lockfd;        /* lock file fd for locking .rec for 5.0 */
268 } Fcb;
269
270 #define FCB_NOPRIMARY_KEY(fcb) ((fcb)->keys[0].k2_nparts == 0)
271
272 /* Current Record Position (interpreted only by Access Method) */
273 enum crpflag { CRP_UNDEF = 0, CRP_ON = 1, CRP_AFTER = 2, CRP_BEFORE = 3,
274                CRP_BEFOREANY = 4, CRP_AFTERANY = 5};
275 typedef struct crp {
276     int                 keyid;               /* Key index */
277     enum crpflag        flag;                /* ON/BEFORE/AFTER/UNDEF */
278     Recno               recno;               /* Record number */
279     int                 matchkeylen;         /* match so many bytes of key */
280     char                key[1];              /* Index position */
281 } Crp;
282
283 #define PHYS_ORDER   (-1)                    /* value for keyid when physical
284                                               order is used*/
285
286 /* 
287  * keydesc2 is the 'internal copy'of keydesc. 
288  * keydesc2 contains all information needed by internally by NetISAM,
289  * whereas keydesc conforms to the X/OPEN ISAM. 
290  */
291
292 #define NPARTS2 (NPARTS+2)                   /* duplid and recno */
293 #define DUPSMASK   001                       /* Mask to get ISDUPS/ISNODUPS */
294 #define ISPRIMKEY       040                  /* this is primary key */
295 #define ALLOWS_DUPS2(pkdesc2) (((pkdesc2)->k2_flags & DUPSMASK) == ISDUPS)
296 #define ALLOWS_DUPS(pkdesc) (((pkdesc)->k_flags & DUPSMASK) == ISDUPS)
297
298 /* serial number of duplicate keys */
299 #define DUPIDTYPE       LONGTYPE
300 #define DUPIDSIZE       LONGSIZE
301
302 #define KEY_RECNO_OFF   0
303 #define KEY_DUPS_OFF    RECNOSIZE
304
305 #define stdupser(n, b) stlong((long)(n), (b))
306 #define lddupser(b)  ((int)ldlong(b))
307
308 struct keypart2 {
309     u_short     kp2_start;                   /* starting byte of key part */
310     short       kp2_leng;                    /* length in bytes */
311     short       kp2_type;                    /* type of key part */
312     u_short     kp2_offset;                  /* offset in key buffer */
313 };
314
315 typedef struct keydesc2 {
316     short       k2_flags;                    /* flags */
317     short       k2_nparts;                   /* number of parts in key */
318     short       k2_len;                      /* length of the whole key */
319     Blkno       k2_rootnode;                 /* pointer to root node */
320     int         k2_keyid;                    /* Key identifier */
321     struct keypart2 k2_part[NPARTS2];        /* each part */
322 } Keydesc2;
323
324 typedef unsigned long rel_addr;
325 /* Double linked list element */
326 struct dlink {
327     rel_addr     dln_forward;                /* Forward link */
328     rel_addr     dln_backward;               /* Backward link */
329 };
330
331 /* Disk buffer management definitions */
332
333 /* cache buffer header */
334 typedef struct bufhdr {
335     Fcb         *isb_fcb;                    /* Pointer to FCB */
336     int         isb_unixfd;                  /* UNIX file descriptor */
337     Blkno       isb_blkno;                   /* block number */
338     struct dlink isb_hash;                   /* hashed list*/
339     struct dlink isb_aclist;                 /* available or changed list */
340     struct dlink isb_flist;                  /* list of fixed blocks */
341     char        *isb_buf_w;                  /* malloc() buffer with dirty data */
342     char        *isb_buf_r;                  /* points to mapped segment */
343     char        *isb_buffer;                 /* set to isb_buf_r or isb_buf_w */
344     char        isb_flags;                   /* flags - defs. see below */
345     struct bufhdr *isb_oldcopy;              /* pointer to old copy */
346 } Bufhdr;
347
348 /* mapped segment header */
349 typedef struct maphdr {
350     Fcb         *m_fcb;                      /* Pointer to FCB */
351     int         m_unixfd;                    /* UNIX file descriptor */
352     char        *m_addr;                     /* Pointer to beginning of seg. */
353     int         m_segm_num;                  /* Segment number in the file */
354     unsigned long m_stamp;                   /* Assigned when touched */
355 } Maphdr;
356
357
358 /* values of isb_flags */
359 #define ISB_NODATA      00                   /* block has no data */
360 #define ISB_READ        01                   /* page has valid data */
361 #define ISB_CHANGE      02                   /* page must be flushed */
362 #define ISB_RFIXED      04                   /* block is fixed for read*/
363 #define ISB_WFIXED     010                   /* block is fixed for write*/
364 #define ISB_OLDCOPY    020                   /* block is old copy */
365
366 /* mode values to is__cache_fix() */
367 #define ISFIXREAD       1                    /* fix for read */
368 #define ISFIXWRITE      2                    /* fix for update */
369 #define ISFIXNOREAD     3                    /* fix for update, don't read */
370
371
372 /* 
373  * Macro to get pointer to structure if pointer to some element is known 
374  */
375 #define GETBASE(p,s,e) ((struct s *) ((char *)(p) - (char *)&((struct s *)0)->e))
376
377 /* In memory sorting object */
378 typedef struct issort {
379     int         ist_reclength;               /* record length in bytes */
380     int         ist_allocrecs;               /* memory allocated for so */
381                                              /* many records */
382     int         ist_nrecs;                   /* number of records inserted */
383     int         ist_currec;                  /* current position */
384     int         (*ist_compf) ();             /* comparison function */
385     char        *ist_array;                  /* array of records */
386 } Issort;
387
388
389 /* btree is object used for processing B-tree operations */
390
391 #define ISMAXBTRLEVEL   12                   /* Maximum level of B-tree */
392
393 typedef struct btree {
394     Fcb         *fcb;
395     Keydesc2    *keydesc2;
396     int         depth;                       /* depth of the B-tree */
397     Bufhdr      *bufhdr[ISMAXBTRLEVEL];      /* fixed blocks buf. headers */
398     int         curpos[ISMAXBTRLEVEL];       /* current position on block */
399 } Btree;
400
401 /* Lock manager related definitions. */
402 /* Entry in lock table */
403
404 /* Number of buckets for hashing by clientid. Must be a power of 2*/
405 #ifndef HASHPROCSIZE
406 #define HASHPROCSIZE    64
407 #endif
408
409 /* 
410  * Number of buckets for hashing by record number and fileid.
411  * Must be a power of 2 
412  */
413 #ifndef HASHENTSIZE
414 #define HASHENTSIZE     1024
415 #endif
416
417 /* Pseudo record numbers used by file locking. */
418 #define AVAIL_RECNO     (0L)                 /* Entry is available */
419 #define ALLFILE_RECNO   (-1L)                /* Entire file lock */
420 #define OPENFILE_RECNO  (-2L)                /* Used by isopen() */
421
422 /* Lock table file header */
423 struct lockfilehdr {
424     int                 size;                /* size of LOCKTABLEFILE 
425                                               * set to 0 forces reinitialization
426                                               * at next lock request.
427                                               */
428     int                 prochdsn;            /* Number of lists hashed by 
429                                               * clientid */
430     int                 enthdsn;             /* Number of list hashed by
431                                               * record number */
432     int                 lockentriesn;        /* total number of lock entries */
433     struct dlink        avail;               /* Double linked list of 
434                                               * available lock entries */
435 };
436
437 /* Exported filesystem options structure and constants*/
438  
439 #define RW_CLIENTS_SIZE 1     /* Not currently needed */
440 #define UID_SIZE 10           /* Big enough to hold a Unix UID */
441 #define ROOT_OPT_SIZE 240     /* List of hosts for which root access
442                                  is allowed -- can be quite long */
443 #define SHARE_BUFFER_SIZE 400
444  
445 struct export_opts {
446   int read_write; /* 0 => read-only, 1 => read/write */
447   char rw_clients[1]; /* Not interesting, len=1 to save space */
448   char export_dir[1]; /* ditto here */
449   char anon[UID_SIZE];
450   char root[ROOT_OPT_SIZE];
451   int secure; /* RPC authentication flag: 0 => AUTH_UNIX, 1 => AUTH_DES */
452 };
453
454
455
456 #define DAT_SUFFIX      ".rec"
457 #define IND_SUFFIX      ".ind"
458 #define VAR_SUFFIX      ".var"
459 #define LOCK_SUFFIX     ".lock"         /* yh: lock file for .rec to solve mmap in 5.0 */
460
461 /* Values of deleted flag for fixed length records */
462 #define FL_RECDELETED   0
463 #define FL_RECEXISTS    1
464
465 /* Special values of tail pointer for variable length records */
466 #define VL_RECDELETED   ((long ) -1L)
467 #define VL_RECNOTAIL    ((long ) -2L)
468
469 /*------------ Prototype definitions ---------------------------------------*/
470 #include "isam_prototypes.h"
471
472 #define stshort(n,p) stint((n), (p))
473 #define ldshort(p) ldint(p)
474
475 #define strecno(n,p) stlong((long)(n), (p))
476 #define ldrecno(p) ((Recno)ldlong(p))
477
478 #define stblkno(n,p) stlong((long)(n), (p))
479 #define ldblkno(p) ((Blkno)ldlong(p))
480
481
482 /*------------ UNIX file formats ---------------------------------------------*/
483
484 #define ISCNTLPGOFF     ((Blkno) 0)          /* offset of Control Page */
485
486 /* internal key descriptor */
487
488 #define KP2_START_OFF   0                    /* see struct keypart2 */
489 #define KP2_LENGTH_OFF  SHORTSIZE
490 #define KP2_TYPE_OFF    (2*SHORTSIZE)
491 #define KP2_OFFSET_OFF  (3*SHORTSIZE)
492 #define KP2_LEN         (4*SHORTSIZE)
493
494 #define K2_FLAGS_OFF    0                    /* see struct keydesc2 */
495 #define K2_NPARTS_OFF   SHORTSIZE       
496 #define K2_LEN_OFF      (2*SHORTSIZE)
497 #define K2_ROOT_OFF     (3*SHORTSIZE)
498 #define K2_KEYID_OFF    (3*SHORTSIZE+BLKNOSIZE)
499 #define K2_KEYPART_OFF  (3*SHORTSIZE+2*BLKNOSIZE)
500 #define K2_LEN          (3*SHORTSIZE+2*BLKNOSIZE+ NPARTS2*KP2_LEN)
501
502 #define NULL_BLKNO      0L
503 #define NULL_RECNO      0L
504 #define PAGE1_BLKNO     0                    /* Block number of control page */
505 /*------------------------- Control Page  layout -----------------------------*/
506
507 /* Magic number (must be equal to "NetISAM") */
508 #define CP_MAGIC_OFF    0
509 #define CP_MAGIC_LEN    8
510
511 /* Version stamp */
512 #define CP_VERSION_OFF (CP_MAGIC_OFF+CP_MAGIC_LEN)
513 #define CP_VERSION_LEN 8
514
515 /* Application stamp */
516 #define CP_APPLMAGIC_OFF (CP_VERSION_OFF+ CP_VERSION_LEN)
517 #define CP_APPLMAGIC_LEN ISAPPLMAGICLEN
518
519 /* Block size */
520 #define CP_BLOCKSIZE_OFF (CP_APPLMAGIC_OFF+CP_APPLMAGIC_LEN)
521 #define CP_BLOCKSIZE_LEN SHORTSIZE
522
523 /* file size in blocks */
524 #define CP_DATSIZE_OFF  (CP_BLOCKSIZE_OFF+CP_BLOCKSIZE_LEN)     
525 #define CP_DATSIZE_LEN  BLKNOSIZE
526
527 /* file size in blocks */
528 #define CP_INDSIZE_OFF  (CP_DATSIZE_OFF+CP_DATSIZE_LEN) 
529 #define CP_INDSIZE_LEN  BLKNOSIZE
530
531 /* file size in blocks */
532 #define CP_VARSIZE_OFF  (CP_INDSIZE_OFF+CP_INDSIZE_LEN)
533 #define CP_VARSIZE_LEN  BLKNOSIZE
534
535 /* 0/1 flag telling whether file supports variable length records. */
536 #define CP_VARFLAG_OFF  (CP_VARSIZE_OFF+CP_VARSIZE_LEN)
537 #define CP_VARFLAG_LEN  SHORTSIZE
538
539 /* number of record in the file */
540 #define CP_NRECORDS_OFF (CP_VARFLAG_OFF+CP_VARFLAG_LEN)
541 #define CP_NRECORDS_LEN LONGSIZE
542
543 /*  minimum record length */
544 #define CP_MINRECLEN_OFF (CP_NRECORDS_OFF+CP_NRECORDS_LEN)
545 #define CP_MINRECLEN_LEN  SHORTSIZE
546
547 /*  maximum record length */
548 #define CP_MAXRECLEN_OFF (CP_MINRECLEN_OFF+CP_MINRECLEN_LEN)
549 #define CP_MAXRECLEN_LEN  SHORTSIZE
550
551 /* 
552  * Left 0 and not used in NetISAM 1.0.
553  * Will be set at restructuring to some optimal value x 
554  * (minreclen <= x <= maxreclen).
555  * Record with length will be stored in .rec file only. 
556  * In NetISAM 1.0  x == minreclen.
557  */
558 /*  split record record length */
559 #define CP_SPLITRECLEN_OFF (CP_MAXRECLEN_OFF+CP_MAXRECLEN_LEN)
560 #define CP_SPLITRECLEN_LEN  SHORTSIZE
561
562 /* Recno of last record */
563 #define CP_LASTRECNO_OFF  (CP_SPLITRECLEN_OFF+CP_SPLITRECLEN_LEN)
564 #define CP_LASTRECNO_LEN  RECNOSIZE
565
566 /* Head of deleted records list */
567 #define CP_FREERECNO_OFF  (CP_LASTRECNO_OFF+CP_LASTRECNO_LEN)
568 #define CP_FREERECNO_LEN  RECNOSIZE
569
570 /* 0/1 flag telling whether file has a primary key */
571 #define CP_HASPRIMKEY_OFF (CP_FREERECNO_OFF+CP_FREERECNO_LEN)
572 #define CP_HASPRIMKEY_LEN SHORTSIZE
573
574 /* Last key indentifier. */
575 #define CP_LASTKEYID_OFF (CP_HASPRIMKEY_OFF+CP_HASPRIMKEY_LEN)
576 #define CP_LASTKEYID_LEN  LONGSIZE      
577
578 /* Stamp 1 of last change */
579 #define CP_CHANGESTAMP1_OFF (CP_LASTKEYID_OFF+CP_LASTKEYID_LEN)
580 #define CP_CHANGESTAMP1_LEN  LONGSIZE   
581
582 /* Stamp 2 of last change */
583 #define CP_CHANGESTAMP2_OFF (CP_CHANGESTAMP1_OFF+CP_CHANGESTAMP1_LEN)
584 #define CP_CHANGESTAMP2_LEN  LONGSIZE   
585
586 /* .ind file free list */
587 #define CP_INDFREELIST_OFF (CP_CHANGESTAMP2_OFF+CP_CHANGESTAMP2_LEN)
588 #define CP_INDFREELIST_LEN  BLKNOSIZE
589
590 /* number of keys */
591 #define CP_NKEYS_OFF    (CP_INDFREELIST_OFF+CP_INDFREELIST_LEN)
592 #define CP_NKEYS_LEN    SHORTSIZE
593
594 /* use 4 bytes of reserved space */
595 #define CP_VAREND_OFF   (CP_NKEYS_OFF+CP_NKEYS_LEN)
596 #define CP_VAREND_LEN   LONGSIZE
597
598 /* use 4 bytes of reserved space for time stamp*/
599 #define CP_UNIQUE_OFF   (CP_VAREND_OFF+CP_VAREND_LEN)
600 #define CP_UNIQUE_LEN   LONGSIZE
601
602 /* reserve some space for future */
603 #define CP_RESERVE_OFF  (CP_UNIQUE_OFF+CP_UNIQUE_LEN)
604 #define CP_RESERVE_LEN   120                 /* 128 was reserved originally */
605
606 /* table of key descriptors */
607 #define CP_KEYS_OFF     (CP_RESERVE_OFF+CP_RESERVE_LEN)
608
609 #define MAXNKEYS2 ((ISCNTLSIZE - CP_KEYS_OFF) / K2_LEN)
610 #define MAXNKEYS        17
611
612 #if (MAXNKEYS2 < MAXNKEYS)
613 Cause a compiler error here. There is not enought space in the control
614 page to hold MAXNKEYS.
615 #endif
616
617 /*------ page type indicator values -------------*/
618 #define PT_INDEX        1                    /* B-tree page */
619 #define PT_FREELIST     2                    /* free list */
620
621 /*-------------- B-Tree page layout -----------------------------------*/
622 /* page type */
623 #define BT_TYPE_OFF     0
624 #define BT_TYPE_LEN     SHORTSIZE
625
626 /* level (leaves have level 0) */
627 #define BT_LEVEL_OFF    (BT_TYPE_OFF+BT_TYPE_LEN)
628 #define BT_LEVEL_LEN    SHORTSIZE
629
630 /* page capacity */
631 #define BT_CAPAC_OFF    (BT_LEVEL_OFF+BT_LEVEL_LEN)
632 #define BT_CAPAC_LEN    SHORTSIZE
633
634 /* current number of keys */
635 #define BT_NKEYS_OFF    (BT_CAPAC_OFF+BT_CAPAC_LEN)
636 #define BT_NKEYS_LEN    SHORTSIZE
637
638 /* array of key entries */
639 #define BT_KEYS_OFF     (BT_NKEYS_OFF+BT_NKEYS_LEN)
640
641 /* down pointers are stored at the end of the page */
642
643 /*----------- Free List Page Layout --------------------------------------*/
644 /* page type */
645 #define FL_TYPE_OFF     0
646 #define FL_TYPE_LEN     SHORTSIZE
647
648 /* pointer to next block in the list */
649 #define FL_NEXT_OFF     (FL_TYPE_OFF + FL_TYPE_LEN)
650 #define FL_NEXT_LEN     BLKNOSIZE
651
652 /* number of free page pointers */
653 #define FL_NPOINTERS_OFF  (FL_NEXT_OFF + FL_NEXT_LEN)
654 #define FL_NPOINTERS_LEN  SHORTSIZE
655
656 /* free page pointers table */
657 #define FL_POINTERS_OFF   (FL_NPOINTERS_OFF + FL_NPOINTERS_LEN)
658
659 /* maximum number of pointers that can be stored in a page */
660 #define FL_MAXNPOINTERS ((ISPAGESIZE - FL_POINTERS_OFF) / BLKNOSIZE)
661
662 #define FREELIST_NOPAGE ((Blkno) -1)
663
664 /* .var file related defines */
665 #define VR_FRAMELEN_OFF  0
666 #define VR_TAILLEN_OFF   2
667
668
669 /* maximum and minimum values are in B-tree seaches */
670 #if LONG_BIT == 64
671 #define ISMAXLONG   { 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
672 #define ISMINLONG   { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
673 #else
674 #define ISMAXLONG       { 0x7f, 0xff, 0xff, 0xff }
675 #define ISMINLONG       { 0x80, 0x00, 0x00, 0x00 }
676 #endif
677
678 #define ISMAXSHORT      { 0x7f, 0xff }
679 #define ISMINSHORT      { 0x80, 0x00 }
680
681 #define ISMINCHAR       ('\0')
682 #define ISMAXCHAR       ('\377')
683
684 #define ISMINBIN        ('\0')
685 #define ISMAXBIN        ('\377')
686
687 /* double and float are declared using IEEE bit paterns */
688
689 #define ISMAXDOUBLE      { 0x7f, 0xf0, 0, /* rest is 0 */ }
690 #define ISMINDOUBLE      { 0xff, 0xf0, 0, /* rest is 0 */ }
691
692 #define ISMAXFLOAT       { 0x7f, 0x80, 0, /* rest is 0 */ }
693 #define ISMINFLOAT       { 0xff, 0x80, 0, /* rest is 0 */ }
694
695
696 /* Hide these from user till we return error code */
697 extern char     isstat3;
698 extern char     isstat4;
699
700 #define OP_BUILD                0
701 #define OP_OPEN                 1
702
703 #endif
704