db.h

Go to the documentation of this file.
00001 /*-
00002  * Copyright (c) 1990, 1993, 1994
00003  * The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. All advertising materials mentioning features or use of this software
00014  *    must display the following acknowledgement:
00015  * This product includes software developed by the University of
00016  * California, Berkeley and its contributors.
00017  * 4. Neither the name of the University nor the names of its contributors
00018  *    may be used to endorse or promote products derived from this software
00019  *    without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  * @(#)db.h 8.7 (Berkeley) 6/16/94
00034  */
00035 
00036 #ifndef _DB_H
00037 #define  _DB_H 1
00038 
00039 #include <sys/types.h>
00040 #include <sys/cdefs.h>
00041 
00042 #include <limits.h>
00043 
00044 #ifdef __DBINTERFACE_PRIVATE
00045 #include <compat.h>
00046 #endif
00047 
00048 #ifdef SOLARIS
00049 #include "solaris-compat/compat.h"
00050 #endif
00051 
00052 #define  RET_ERROR   -1    /* Return values. */
00053 #define  RET_SUCCESS  0
00054 #define  RET_SPECIAL  1
00055 
00056 #ifndef  __BIT_TYPES_DEFINED__
00057 #define  __BIT_TYPES_DEFINED__
00058 #if (!defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__APPLE__))
00059 typedef  __signed char        int8_t;
00060 typedef  short         int16_t;
00061 typedef  int           int32_t;
00062 typedef  unsigned char      u_int8_t;
00063 typedef  unsigned short    u_int16_t;
00064 typedef  unsigned int      u_int32_t;
00065 #ifdef WE_DONT_NEED_QUADS
00066 typedef  long long        int64_t;
00067 typedef  unsigned long long   u_int64_t;
00068 #endif
00069 #endif /* __FreeBSD__ */
00070 #endif
00071 
00072 #ifdef SOLARIS
00073 #define  __P(p) p
00074 #define __BEGIN_DECLS
00075 #define __END_DECLS
00076 #endif
00077 
00078 #define  MAX_PAGE_NUMBER   0xffffffff  /* >= # of pages in a file */
00079 typedef u_int32_t pgno_t;
00080 #define  MAX_PAGE_OFFSET   65535    /* >= # of bytes in a page */
00081 typedef u_int16_t indx_t;
00082 #define  MAX_REC_NUMBER 0xffffffff  /* >= # of records in a tree */
00083 typedef u_int32_t recno_t;
00084 
00085 /* Key/data structure -- a Data-Base Thang. */
00086 typedef struct {
00087    void  *data;         /* data */
00088    size_t    size;         /* data length */
00089 } DBT;
00090 
00091 /* Routine flags. */
00092 #define  R_CURSOR 1     /* del, put, seq */
00093 #define  __R_UNUSED  2     /* UNUSED */
00094 #define  R_FIRST     3     /* seq */
00095 #define  R_IAFTER 4     /* put (RECNO) */
00096 #define  R_IBEFORE   5     /* put (RECNO) */
00097 #define  R_LAST      6     /* seq (BTREE, RECNO) */
00098 #define  R_NEXT      7     /* seq */
00099 #define  R_NOOVERWRITE  8     /* put */
00100 #define  R_PREV      9     /* seq (BTREE, RECNO) */
00101 #define  R_SETCURSOR 10    /* put (RECNO) */
00102 #define  R_RECNOSYNC 11    /* sync (RECNO) */
00103 
00104 typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
00105 
00106 /*
00107  * !!!
00108  * The following flags are included in the dbopen(3) call as part of the
00109  * open(2) flags.  In order to avoid conflicts with the open flags, start
00110  * at the top of the 16 or 32-bit number space and work our way down.  If
00111  * the open flags were significantly expanded in the future, it could be
00112  * a problem.  Wish I'd left another flags word in the dbopen call.
00113  *
00114  * !!!
00115  * None of this stuff is implemented yet.  The only reason that it's here
00116  * is so that the access methods can skip copying the key/data pair when
00117  * the DB_LOCK flag isn't set.
00118  */
00119 #if UINT_MAX > 65535
00120 #define  DB_LOCK     0x20000000  /* Do locking. */
00121 #define  DB_SHMEM 0x40000000  /* Use shared memory. */
00122 #define  DB_TXN      0x80000000  /* Do transactions. */
00123 #else
00124 #define  DB_LOCK         0x2000  /* Do locking. */
00125 #define  DB_SHMEM     0x4000  /* Use shared memory. */
00126 #define  DB_TXN          0x8000  /* Do transactions. */
00127 #endif
00128 
00129 /* Access method description structure. */
00130 typedef struct __db {
00131    DBTYPE type;         /* Underlying db type. */
00132    int (*close)   __P((struct __db *));
00133    int (*del)  __P((const struct __db *, const DBT *, u_int));
00134    int (*get)  __P((const struct __db *, const DBT *, DBT *, u_int));
00135    int (*put)  __P((const struct __db *, DBT *, const DBT *, u_int));
00136    int (*seq)  __P((const struct __db *, DBT *, DBT *, u_int));
00137    int (*sync) __P((const struct __db *, u_int));
00138    void *internal;         /* Access method private. */
00139    int (*fd)   __P((const struct __db *));
00140 } DB;
00141 
00142 #define  BTREEMAGIC  0x053162
00143 #define  BTREEVERSION   3
00144 
00145 /* Structure used to pass parameters to the btree routines. */
00146 typedef struct {
00147 #define  R_DUP    0x01  /* duplicate keys */
00148    u_long   flags;
00149    u_int cachesize;  /* bytes to cache */
00150    int   maxkeypage; /* maximum keys per page */
00151    int   minkeypage; /* minimum keys per page */
00152    u_int psize;      /* page size */
00153    int   (*compare)  /* comparison function */
00154        __P((const DBT *, const DBT *));
00155    size_t   (*prefix)   /* prefix function */
00156        __P((const DBT *, const DBT *));
00157    int   lorder;     /* byte order */
00158 } BTREEINFO;
00159 
00160 #define  HASHMAGIC   0x061561
00161 #define  HASHVERSION 2
00162 
00163 /* Structure used to pass parameters to the hashing routines. */
00164 typedef struct {
00165    u_int bsize;      /* bucket size */
00166    u_int ffactor; /* fill factor */
00167    u_int nelem;      /* number of elements */
00168    u_int cachesize;  /* bytes to cache */
00169    u_int32_t      /* hash function */
00170       (*hash) __P((const void *, size_t));
00171    int   lorder;     /* byte order */
00172 } HASHINFO;
00173 
00174 /* Structure used to pass parameters to the record routines. */
00175 typedef struct {
00176 #define  R_FIXEDLEN  0x01  /* fixed-length records */
00177 #define  R_NOKEY     0x02  /* key not required */
00178 #define  R_SNAPSHOT  0x04  /* snapshot the input */
00179    u_long   flags;
00180    u_int cachesize;  /* bytes to cache */
00181    u_int psize;      /* page size */
00182    int   lorder;     /* byte order */
00183    size_t   reclen;     /* record length (fixed-length records) */
00184    u_char   bval;    /* delimiting byte (variable-length records */
00185    char  *bfname; /* btree file name */ 
00186 } RECNOINFO;
00187 
00188 #ifdef __DBINTERFACE_PRIVATE
00189 /*
00190  * Little endian <==> big endian 32-bit swap macros.
00191  * M_32_SWAP   swap a memory location
00192  * P_32_SWAP   swap a referenced memory location
00193  * P_32_COPY   swap from one location to another
00194  */
00195 #define  M_32_SWAP(a) {                   \
00196    u_int32_t _tmp = a;                 \
00197    ((char *)&a)[0] = ((char *)&_tmp)[3];           \
00198    ((char *)&a)[1] = ((char *)&_tmp)[2];           \
00199    ((char *)&a)[2] = ((char *)&_tmp)[1];           \
00200    ((char *)&a)[3] = ((char *)&_tmp)[0];           \
00201 }
00202 #define  P_32_SWAP(a) {                   \
00203    u_int32_t _tmp = *(u_int32_t *)a;            \
00204    ((char *)a)[0] = ((char *)&_tmp)[3];            \
00205    ((char *)a)[1] = ((char *)&_tmp)[2];            \
00206    ((char *)a)[2] = ((char *)&_tmp)[1];            \
00207    ((char *)a)[3] = ((char *)&_tmp)[0];            \
00208 }
00209 #define  P_32_COPY(a, b) {                \
00210    ((char *)&(b))[0] = ((char *)&(a))[3];          \
00211    ((char *)&(b))[1] = ((char *)&(a))[2];          \
00212    ((char *)&(b))[2] = ((char *)&(a))[1];          \
00213    ((char *)&(b))[3] = ((char *)&(a))[0];          \
00214 }
00215 
00216 /*
00217  * Little endian <==> big endian 16-bit swap macros.
00218  * M_16_SWAP   swap a memory location
00219  * P_16_SWAP   swap a referenced memory location
00220  * P_16_COPY   swap from one location to another
00221  */
00222 #define  M_16_SWAP(a) {                   \
00223    u_int16_t _tmp = a;                 \
00224    ((char *)&a)[0] = ((char *)&_tmp)[1];           \
00225    ((char *)&a)[1] = ((char *)&_tmp)[0];           \
00226 }
00227 #define  P_16_SWAP(a) {                   \
00228    u_int16_t _tmp = *(u_int16_t *)a;            \
00229    ((char *)a)[0] = ((char *)&_tmp)[1];            \
00230    ((char *)a)[1] = ((char *)&_tmp)[0];            \
00231 }
00232 #define  P_16_COPY(a, b) {                \
00233    ((char *)&(b))[0] = ((char *)&(a))[1];          \
00234    ((char *)&(b))[1] = ((char *)&(a))[0];          \
00235 }
00236 #endif
00237 
00238 __BEGIN_DECLS
00239 DB *__dbopen __P((const char *, int, int, DBTYPE, const void *));
00240 DB *dbopen __P((const char *, int, int, DBTYPE, const void *));
00241 
00242 #ifdef __DBINTERFACE_PRIVATE
00243 DB *__bt_open __P((const char *, int, int, const BTREEINFO *, int));
00244 DB *__hash_open __P((const char *, int, int, const HASHINFO *, int));
00245 DB *__rec_open __P((const char *, int, int, const RECNOINFO *, int));
00246 void   __dbpanic __P((DB *dbp));
00247 #endif
00248 __END_DECLS
00249 
00250 #endif /* db.h */

Generated on Thu Apr 16 06:27:32 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6