isam_impl.h 22 KB

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