home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / EDITOR / NVI179B / NVI179B.ZIP / db / include / db.h next >
C/C++ Source or Header  |  1996-03-18  |  9KB  |  267 lines

  1. /*-
  2.  * Copyright (c) 1990, 1993, 1994
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)db.h    8.7 (Berkeley) 6/16/94
  34.  */
  35.  
  36. #ifndef _DB_H_
  37. #define    _DB_H_
  38.  
  39. #include <sys/types.h>
  40.  
  41. #ifdef __DBINTERFACE_PRIVATE
  42. #include "config.h"
  43. #include "port.h"
  44. #endif
  45.  
  46. /*
  47.  * XXX
  48.  * We don't want to collide with an existing DB implementation in the
  49.  * local libraries.  Some of them have diverged, and we don't include
  50.  * the hash routines in any case.
  51.  */
  52. #define    __bt_close    nvi__bt_close
  53. #define    __bt_cmp    nvi__bt_cmp
  54. #define    __bt_defcmp    nvi__bt_defcmp
  55. #define    __bt_defpfx    nvi__bt_defpfx
  56. #define    __bt_delete    nvi__bt_delete
  57. #define    __bt_dleaf    nvi__bt_dleaf
  58. #define    __bt_dmpage    nvi__bt_dmpage
  59. #define    __bt_dnpage    nvi__bt_dnpage
  60. #define    __bt_dpage    nvi__bt_dpage
  61. #define    __bt_dump    nvi__bt_dump
  62. #define    __bt_fd        nvi__bt_fd
  63. #define    __bt_free    nvi__bt_free
  64. #define    __bt_get    nvi__bt_get
  65. #define    __bt_new    nvi__bt_new
  66. #define    __bt_open    nvi__bt_open
  67. #define    __bt_pgin    nvi__bt_pgin
  68. #define    __bt_pgout    nvi__bt_pgout
  69. #define    __bt_put    nvi__bt_put
  70. #define    __bt_ret    nvi__bt_ret
  71. #define    __bt_search    nvi__bt_search
  72. #define    __bt_seq    nvi__bt_seq
  73. #define    __bt_setcur    nvi__bt_setcur
  74. #define    __bt_split    nvi__bt_split
  75. #define    __bt_stat    nvi__bt_stat
  76. #define    __bt_sync    nvi__bt_sync
  77. #define    __dbpanic    nvi__dbpanic
  78. #define    __ovfl_delete    nvi__ovfl_delete
  79. #define    __ovfl_get    nvi__ovfl_get
  80. #define    __ovfl_put    nvi__ovfl_put
  81. #define    __rec_close    nvi__rec_close
  82. #define    __rec_delete    nvi__rec_delete
  83. #define    __rec_dleaf    nvi__rec_dleaf
  84. #define    __rec_fd    nvi__rec_fd
  85. #define    __rec_fmap    nvi__rec_fmap
  86. #define    __rec_fpipe    nvi__rec_fpipe
  87. #define    __rec_get    nvi__rec_get
  88. #define    __rec_iput    nvi__rec_iput
  89. #define    __rec_open    nvi__rec_open
  90. #define    __rec_put    nvi__rec_put
  91. #define    __rec_ret    nvi__rec_ret
  92. #define    __rec_search    nvi__rec_search
  93. #define    __rec_seq    nvi__rec_seq
  94. #define    __rec_sync    nvi__rec_sync
  95. #define    __rec_vmap    nvi__rec_vmap
  96. #define    __rec_vpipe    nvi__rec_vpipe
  97. #define    dbopen        nvidbopen
  98. #define    mpool_close    nvimpool_close
  99. #define    mpool_filter    nvimpool_filter
  100. #define    mpool_get    nvimpool_get
  101. #define    mpool_new    nvimpool_new
  102. #define    mpool_open    nvimpool_open
  103. #define    mpool_put    nvimpool_put
  104. #define    mpool_stat    nvimpool_stat
  105. #define    mpool_sync    nvimpool_sync
  106.  
  107. #define    RET_ERROR    -1        /* Return values. */
  108. #define    RET_SUCCESS     0
  109. #define    RET_SPECIAL     1
  110.  
  111. #define    MAX_PAGE_NUMBER    0xffffffff    /* >= # of pages in a file */
  112. typedef u_int32_t    pgno_t;
  113. #define    MAX_PAGE_OFFSET    65535        /* >= # of bytes in a page */
  114. typedef u_int16_t    indx_t;
  115. #define    MAX_REC_NUMBER    0xffffffff    /* >= # of records in a tree */
  116. typedef u_int32_t    recno_t;
  117.  
  118. /* Key/data structure -- a Data-Base Thang. */
  119. typedef struct {
  120.     void    *data;            /* data */
  121.     size_t     size;            /* data length */
  122. } DBT;
  123.  
  124. /* Routine flags. */
  125. #define    R_CURSOR    1        /* del, put, seq */
  126. #define    __R_UNUSED    2        /* UNUSED */
  127. #define    R_FIRST        3        /* seq */
  128. #define    R_IAFTER    4        /* put (RECNO) */
  129. #define    R_IBEFORE    5        /* put (RECNO) */
  130. #define    R_LAST        6        /* seq (BTREE, RECNO) */
  131. #define    R_NEXT        7        /* seq */
  132. #define    R_NOOVERWRITE    8        /* put */
  133. #define    R_PREV        9        /* seq (BTREE, RECNO) */
  134. #define    R_SETCURSOR    10        /* put (RECNO) */
  135. #define    R_RECNOSYNC    11        /* sync (RECNO) */
  136.  
  137. typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
  138.  
  139. /*
  140.  * !!!
  141.  * None of this stuff is implemented yet.  The only reason that it's here
  142.  * is so that the access methods can skip copying the key/data pair when
  143.  * the DB_LOCK flag isn't set.
  144.  */
  145. #define    DB_LOCK            0x2000    /* Do locking. */
  146. #define    DB_SHMEM        0x4000    /* Use shared memory. */
  147. #define    DB_TXN            0x8000    /* Do transactions. */
  148.  
  149. /* Access method description structure. */
  150. typedef struct __db {
  151.     DBTYPE type;            /* Underlying db type. */
  152.     int (*close)    __P((struct __db *));
  153.     int (*del)    __P((const struct __db *, const DBT *, u_int));
  154.     int (*get)    __P((const struct __db *, const DBT *, DBT *, u_int));
  155.     int (*put)    __P((const struct __db *, DBT *, const DBT *, u_int));
  156.     int (*seq)    __P((const struct __db *, DBT *, DBT *, u_int));
  157.     int (*sync)    __P((const struct __db *, u_int));
  158.     void *internal;            /* Access method private. */
  159.     int (*fd)    __P((const struct __db *));
  160. } DB;
  161.  
  162. #define    BTREEMAGIC    0x053162
  163. #define    BTREEVERSION    3
  164.  
  165. /* Structure used to pass parameters to the btree routines. */
  166. typedef struct {
  167. #define    R_DUP        0x01    /* duplicate keys */
  168.     u_long    flags;
  169.     u_int    cachesize;    /* bytes to cache */
  170.     int    maxkeypage;    /* maximum keys per page */
  171.     int    minkeypage;    /* minimum keys per page */
  172.     u_int    psize;        /* page size */
  173.     int    (*compare)    /* comparison function */
  174.         __P((const DBT *, const DBT *));
  175.     size_t    (*prefix)    /* prefix function */
  176.         __P((const DBT *, const DBT *));
  177.     int    lorder;        /* byte order */
  178. } BTREEINFO;
  179.  
  180. #define    HASHMAGIC    0x061561
  181. #define    HASHVERSION    2
  182.  
  183. /* Structure used to pass parameters to the hashing routines. */
  184. typedef struct {
  185.     u_int    bsize;        /* bucket size */
  186.     u_int    ffactor;    /* fill factor */
  187.     u_int    nelem;        /* number of elements */
  188.     u_int    cachesize;    /* bytes to cache */
  189.     u_int32_t        /* hash function */
  190.         (*hash) __P((const void *, size_t));
  191.     int    lorder;        /* byte order */
  192. } HASHINFO;
  193.  
  194. /* Structure used to pass parameters to the record routines. */
  195. typedef struct {
  196. #define    R_FIXEDLEN    0x01    /* fixed-length records */
  197. #define    R_NOKEY        0x02    /* key not required */
  198. #define    R_SNAPSHOT    0x04    /* snapshot the input */
  199.     u_long    flags;
  200.     u_int    cachesize;    /* bytes to cache */
  201.     u_int    psize;        /* page size */
  202.     int    lorder;        /* byte order */
  203.     size_t    reclen;        /* record length (fixed-length records) */
  204.     u_char    bval;        /* delimiting byte (variable-length records */
  205.     char    *bfname;    /* btree file name */ 
  206. } RECNOINFO;
  207.  
  208. #ifdef __DBINTERFACE_PRIVATE
  209. /*
  210.  * Little endian <==> big endian 32-bit swap macros.
  211.  *    M_32_SWAP    swap a memory location
  212.  *    P_32_SWAP    swap a referenced memory location
  213.  *    P_32_COPY    swap from one location to another
  214.  */
  215. #define    M_32_SWAP(a) {                            \
  216.     u_int32_t _tmp = a;                        \
  217.     ((char *)&a)[0] = ((char *)&_tmp)[3];                \
  218.     ((char *)&a)[1] = ((char *)&_tmp)[2];                \
  219.     ((char *)&a)[2] = ((char *)&_tmp)[1];                \
  220.     ((char *)&a)[3] = ((char *)&_tmp)[0];                \
  221. }
  222. #define    P_32_SWAP(a) {                            \
  223.     u_int32_t _tmp = *(u_int32_t *)a;                \
  224.     ((char *)a)[0] = ((char *)&_tmp)[3];                \
  225.     ((char *)a)[1] = ((char *)&_tmp)[2];                \
  226.     ((char *)a)[2] = ((char *)&_tmp)[1];                \
  227.     ((char *)a)[3] = ((char *)&_tmp)[0];                \
  228. }
  229. #define    P_32_COPY(a, b) {                        \
  230.     ((char *)&(b))[0] = ((char *)&(a))[3];                \
  231.     ((char *)&(b))[1] = ((char *)&(a))[2];                \
  232.     ((char *)&(b))[2] = ((char *)&(a))[1];                \
  233.     ((char *)&(b))[3] = ((char *)&(a))[0];                \
  234. }
  235.  
  236. /*
  237.  * Little endian <==> big endian 16-bit swap macros.
  238.  *    M_16_SWAP    swap a memory location
  239.  *    P_16_SWAP    swap a referenced memory location
  240.  *    P_16_COPY    swap from one location to another
  241.  */
  242. #define    M_16_SWAP(a) {                            \
  243.     u_int16_t _tmp = a;                        \
  244.     ((char *)&a)[0] = ((char *)&_tmp)[1];                \
  245.     ((char *)&a)[1] = ((char *)&_tmp)[0];                \
  246. }
  247. #define    P_16_SWAP(a) {                            \
  248.     u_int16_t _tmp = *(u_int16_t *)a;                \
  249.     ((char *)a)[0] = ((char *)&_tmp)[1];                \
  250.     ((char *)a)[1] = ((char *)&_tmp)[0];                \
  251. }
  252. #define    P_16_COPY(a, b) {                        \
  253.     ((char *)&(b))[0] = ((char *)&(a))[1];                \
  254.     ((char *)&(b))[1] = ((char *)&(a))[0];                \
  255. }
  256. #endif
  257.  
  258. DB *dbopen __P((const char *, int, int, DBTYPE, const void *));
  259.  
  260. #ifdef __DBINTERFACE_PRIVATE
  261. DB    *__bt_open __P((const char *, int, int, const BTREEINFO *, int));
  262. DB    *__hash_open __P((const char *, int, int, const HASHINFO *, int));
  263. DB    *__rec_open __P((const char *, int, int, const RECNOINFO *, int));
  264. void     __dbpanic __P((DB *dbp));
  265. #endif
  266. #endif /* !_DB_H_ */
  267.