home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / armlinux / alpha / PARTITIONS / USR_GZ / usr / include / db.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-14  |  8.3 KB  |  247 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 <features.h>
  40. #include <sys/types.h>
  41.  
  42. #include <limits.h>
  43.  
  44. #ifdef __DBINTERFACE_PRIVATE
  45. #ifndef O_EXLOCK                        /* 4.4BSD extension. */
  46. #define O_EXLOCK        0
  47. #endif
  48.  
  49. #ifndef O_SHLOCK                        /* 4.4BSD extension. */
  50. #define O_SHLOCK        0
  51. #endif
  52.  
  53. #ifndef EFTYPE
  54. #define EFTYPE          EINVAL          /* POSIX 1003.1 format errno. */
  55. #endif
  56. #endif
  57.  
  58. #define    RET_ERROR    -1        /* Return values. */
  59. #define    RET_SUCCESS     0
  60. #define    RET_SPECIAL     1
  61.  
  62. #ifndef    __BIT_TYPES_DEFINED__
  63. #define    __BIT_TYPES_DEFINED__
  64. typedef    __signed char           int8_t;
  65. typedef    unsigned char         u_int8_t;
  66. typedef    short              int16_t;
  67. typedef    unsigned short        u_int16_t;
  68. typedef    int              int32_t;
  69. typedef    unsigned int        u_int32_t;
  70. #ifdef WE_DONT_NEED_QUADS
  71. typedef    long long          int64_t;
  72. typedef    unsigned long long    u_int64_t;
  73. #endif
  74. #endif
  75.  
  76. #define    MAX_PAGE_NUMBER    0xffffffff    /* >= # of pages in a file */
  77. typedef u_int32_t    pgno_t;
  78. #define    MAX_PAGE_OFFSET    65535        /* >= # of bytes in a page */
  79. typedef u_int16_t    indx_t;
  80. #define    MAX_REC_NUMBER    0xffffffff    /* >= # of records in a tree */
  81. typedef u_int32_t    recno_t;
  82.  
  83. /* Key/data structure -- a Data-Base Thang. */
  84. typedef struct {
  85.     void    *data;            /* data */
  86.     size_t     size;            /* data length */
  87. } DBT;
  88.  
  89. /* Routine flags. */
  90. #define    R_CURSOR    1        /* del, put, seq */
  91. #define    __R_UNUSED    2        /* UNUSED */
  92. #define    R_FIRST        3        /* seq */
  93. #define    R_IAFTER    4        /* put (RECNO) */
  94. #define    R_IBEFORE    5        /* put (RECNO) */
  95. #define    R_LAST        6        /* seq (BTREE, RECNO) */
  96. #define    R_NEXT        7        /* seq */
  97. #define    R_NOOVERWRITE    8        /* put */
  98. #define    R_PREV        9        /* seq (BTREE, RECNO) */
  99. #define    R_SETCURSOR    10        /* put (RECNO) */
  100. #define    R_RECNOSYNC    11        /* sync (RECNO) */
  101.  
  102. typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
  103.  
  104. /*
  105.  * !!!
  106.  * The following flags are included in the dbopen(3) call as part of the
  107.  * open(2) flags.  In order to avoid conflicts with the open flags, start
  108.  * at the top of the 16 or 32-bit number space and work our way down.  If
  109.  * the open flags were significantly expanded in the future, it could be
  110.  * a problem.  Wish I'd left another flags word in the dbopen call.
  111.  *
  112.  * !!!
  113.  * None of this stuff is implemented yet.  The only reason that it's here
  114.  * is so that the access methods can skip copying the key/data pair when
  115.  * the DB_LOCK flag isn't set.
  116.  */
  117. #if UINT_MAX > 65535
  118. #define    DB_LOCK        0x20000000    /* Do locking. */
  119. #define    DB_SHMEM    0x40000000    /* Use shared memory. */
  120. #define    DB_TXN        0x80000000    /* Do transactions. */
  121. #else
  122. #define    DB_LOCK            0x2000    /* Do locking. */
  123. #define    DB_SHMEM        0x4000    /* Use shared memory. */
  124. #define    DB_TXN            0x8000    /* Do transactions. */
  125. #endif
  126.  
  127. /* Access method description structure. */
  128. typedef struct __db {
  129.     DBTYPE type;            /* Underlying db type. */
  130.     int (*close)    __P((struct __db *));
  131.     int (*del)    __P((const struct __db *, const DBT *, u_int));
  132.     int (*get)    __P((const struct __db *, const DBT *, DBT *, u_int));
  133.     int (*put)    __P((const struct __db *, DBT *, const DBT *, u_int));
  134.     int (*seq)    __P((const struct __db *, DBT *, DBT *, u_int));
  135.     int (*sync)    __P((const struct __db *, u_int));
  136.     void *internal;            /* Access method private. */
  137.     int (*fd)    __P((const struct __db *));
  138. } DB;
  139.  
  140. #define    BTREEMAGIC    0x053162
  141. #define    BTREEVERSION    3
  142.  
  143. /* Structure used to pass parameters to the btree routines. */
  144. typedef struct {
  145. #define    R_DUP        0x01    /* duplicate keys */
  146.     u_long    flags;
  147.     u_int    cachesize;    /* bytes to cache */
  148.     int    maxkeypage;    /* maximum keys per page */
  149.     int    minkeypage;    /* minimum keys per page */
  150.     u_int    psize;        /* page size */
  151.     int    (*compare)    /* comparison function */
  152.         __P((const DBT *, const DBT *));
  153.     size_t    (*prefix)    /* prefix function */
  154.         __P((const DBT *, const DBT *));
  155.     int    lorder;        /* byte order */
  156. } BTREEINFO;
  157.  
  158. #define    HASHMAGIC    0x061561
  159. #define    HASHVERSION    2
  160.  
  161. /* Structure used to pass parameters to the hashing routines. */
  162. typedef struct {
  163.     u_int    bsize;        /* bucket size */
  164.     u_int    ffactor;    /* fill factor */
  165.     u_int    nelem;        /* number of elements */
  166.     u_int    cachesize;    /* bytes to cache */
  167.     u_int32_t        /* hash function */
  168.         (*hash) __P((const void *, size_t));
  169.     int    lorder;        /* byte order */
  170. } HASHINFO;
  171.  
  172. /* Structure used to pass parameters to the record routines. */
  173. typedef struct {
  174. #define    R_FIXEDLEN    0x01    /* fixed-length records */
  175. #define    R_NOKEY        0x02    /* key not required */
  176. #define    R_SNAPSHOT    0x04    /* snapshot the input */
  177.     u_long    flags;
  178.     u_int    cachesize;    /* bytes to cache */
  179.     u_int    psize;        /* page size */
  180.     int    lorder;        /* byte order */
  181.     size_t    reclen;        /* record length (fixed-length records) */
  182.     u_char    bval;        /* delimiting byte (variable-length records */
  183.     char    *bfname;    /* btree file name */ 
  184. } RECNOINFO;
  185.  
  186. #ifdef __DBINTERFACE_PRIVATE
  187. /*
  188.  * Little endian <==> big endian 32-bit swap macros.
  189.  *    M_32_SWAP    swap a memory location
  190.  *    P_32_SWAP    swap a referenced memory location
  191.  *    P_32_COPY    swap from one location to another
  192.  */
  193. #define    M_32_SWAP(a) {                            \
  194.     u_int32_t _tmp = a;                        \
  195.     ((char *)&a)[0] = ((char *)&_tmp)[3];                \
  196.     ((char *)&a)[1] = ((char *)&_tmp)[2];                \
  197.     ((char *)&a)[2] = ((char *)&_tmp)[1];                \
  198.     ((char *)&a)[3] = ((char *)&_tmp)[0];                \
  199. }
  200. #define    P_32_SWAP(a) {                            \
  201.     u_int32_t _tmp = *(u_int32_t *)a;                \
  202.     ((char *)a)[0] = ((char *)&_tmp)[3];                \
  203.     ((char *)a)[1] = ((char *)&_tmp)[2];                \
  204.     ((char *)a)[2] = ((char *)&_tmp)[1];                \
  205.     ((char *)a)[3] = ((char *)&_tmp)[0];                \
  206. }
  207. #define    P_32_COPY(a, b) {                        \
  208.     ((char *)&(b))[0] = ((char *)&(a))[3];                \
  209.     ((char *)&(b))[1] = ((char *)&(a))[2];                \
  210.     ((char *)&(b))[2] = ((char *)&(a))[1];                \
  211.     ((char *)&(b))[3] = ((char *)&(a))[0];                \
  212. }
  213.  
  214. /*
  215.  * Little endian <==> big endian 16-bit swap macros.
  216.  *    M_16_SWAP    swap a memory location
  217.  *    P_16_SWAP    swap a referenced memory location
  218.  *    P_16_COPY    swap from one location to another
  219.  */
  220. #define    M_16_SWAP(a) {                            \
  221.     u_int16_t _tmp = a;                        \
  222.     ((char *)&a)[0] = ((char *)&_tmp)[1];                \
  223.     ((char *)&a)[1] = ((char *)&_tmp)[0];                \
  224. }
  225. #define    P_16_SWAP(a) {                            \
  226.     u_int16_t _tmp = *(u_int16_t *)a;                \
  227.     ((char *)a)[0] = ((char *)&_tmp)[1];                \
  228.     ((char *)a)[1] = ((char *)&_tmp)[0];                \
  229. }
  230. #define    P_16_COPY(a, b) {                        \
  231.     ((char *)&(b))[0] = ((char *)&(a))[1];                \
  232.     ((char *)&(b))[1] = ((char *)&(a))[0];                \
  233. }
  234. #endif
  235.  
  236. __BEGIN_DECLS
  237. DB *dbopen __P((const char *, int, int, DBTYPE, const void *));
  238.  
  239. #ifdef __DBINTERFACE_PRIVATE
  240. DB    *__bt_open __P((const char *, int, int, const BTREEINFO *, int));
  241. DB    *__hash_open __P((const char *, int, int, const HASHINFO *, int));
  242. DB    *__rec_open __P((const char *, int, int, const RECNOINFO *, int));
  243. void     __dbpanic __P((DB *dbp));
  244. #endif
  245. __END_DECLS
  246. #endif /* !_DB_H_ */
  247.