[BACK]Return to db.h CVS log [TXT][DIR] Up to [local] / src / include

Annotation of src/include/db.h, Revision 1.7

1.7     ! millert     1: /*     $OpenBSD: db.h,v 1.6 2002/05/31 20:42:34 itojun Exp $   */
1.1       deraadt     2: /*     $NetBSD: db.h,v 1.13 1994/10/26 00:55:48 cgd Exp $      */
                      3:
                      4: /*-
                      5:  * Copyright (c) 1990, 1993, 1994
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
1.7     ! millert    16:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    17:  *    may be used to endorse or promote products derived from this software
                     18:  *    without specific prior written permission.
                     19:  *
                     20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30:  * SUCH DAMAGE.
                     31:  *
                     32:  *     @(#)db.h        8.7 (Berkeley) 6/16/94
                     33:  */
                     34:
                     35: #ifndef _DB_H_
                     36: #define        _DB_H_
                     37:
                     38: #include <sys/types.h>
                     39: #include <sys/cdefs.h>
                     40:
                     41: #include <limits.h>
                     42:
                     43: #define        RET_ERROR       -1              /* Return values. */
                     44: #define        RET_SUCCESS      0
                     45: #define        RET_SPECIAL      1
                     46:
                     47: #define        MAX_PAGE_NUMBER 0xffffffff      /* >= # of pages in a file */
                     48: typedef u_int32_t      pgno_t;
                     49: #define        MAX_PAGE_OFFSET 65535           /* >= # of bytes in a page */
                     50: typedef u_int16_t      indx_t;
                     51: #define        MAX_REC_NUMBER  0xffffffff      /* >= # of records in a tree */
                     52: typedef u_int32_t      recno_t;
                     53:
                     54: /* Key/data structure -- a Data-Base Thang. */
                     55: typedef struct {
                     56:        void    *data;                  /* data */
                     57:        size_t   size;                  /* data length */
                     58: } DBT;
                     59:
                     60: /* Routine flags. */
                     61: #define        R_CURSOR        1               /* del, put, seq */
                     62: #define        __R_UNUSED      2               /* UNUSED */
                     63: #define        R_FIRST         3               /* seq */
                     64: #define        R_IAFTER        4               /* put (RECNO) */
                     65: #define        R_IBEFORE       5               /* put (RECNO) */
                     66: #define        R_LAST          6               /* seq (BTREE, RECNO) */
                     67: #define        R_NEXT          7               /* seq */
                     68: #define        R_NOOVERWRITE   8               /* put */
                     69: #define        R_PREV          9               /* seq (BTREE, RECNO) */
                     70: #define        R_SETCURSOR     10              /* put (RECNO) */
                     71: #define        R_RECNOSYNC     11              /* sync (RECNO) */
                     72:
                     73: typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
                     74:
                     75: /*
                     76:  * !!!
                     77:  * The following flags are included in the dbopen(3) call as part of the
                     78:  * open(2) flags.  In order to avoid conflicts with the open flags, start
                     79:  * at the top of the 16 or 32-bit number space and work our way down.  If
                     80:  * the open flags were significantly expanded in the future, it could be
                     81:  * a problem.  Wish I'd left another flags word in the dbopen call.
                     82:  *
                     83:  * !!!
                     84:  * None of this stuff is implemented yet.  The only reason that it's here
                     85:  * is so that the access methods can skip copying the key/data pair when
                     86:  * the DB_LOCK flag isn't set.
                     87:  */
                     88: #if UINT_MAX > 65535
                     89: #define        DB_LOCK         0x20000000      /* Do locking. */
                     90: #define        DB_SHMEM        0x40000000      /* Use shared memory. */
                     91: #define        DB_TXN          0x80000000      /* Do transactions. */
                     92: #else
                     93: #define        DB_LOCK             0x2000      /* Do locking. */
                     94: #define        DB_SHMEM            0x4000      /* Use shared memory. */
                     95: #define        DB_TXN              0x8000      /* Do transactions. */
                     96: #endif
                     97:
                     98: /* Access method description structure. */
                     99: typedef struct __db {
                    100:        DBTYPE type;                    /* Underlying db type. */
1.5       millert   101:        int (*close)(struct __db *);
                    102:        int (*del)(const struct __db *, const DBT *, u_int);
                    103:        int (*get)(const struct __db *, const DBT *, DBT *, u_int);
                    104:        int (*put)(const struct __db *, DBT *, const DBT *, u_int);
                    105:        int (*seq)(const struct __db *, DBT *, DBT *, u_int);
                    106:        int (*sync)(const struct __db *, u_int);
1.1       deraadt   107:        void *internal;                 /* Access method private. */
1.5       millert   108:        int (*fd)(const struct __db *);
1.1       deraadt   109: } DB;
                    110:
                    111: #define        BTREEMAGIC      0x053162
                    112: #define        BTREEVERSION    3
                    113:
                    114: /* Structure used to pass parameters to the btree routines. */
                    115: typedef struct {
                    116: #define        R_DUP           0x01    /* duplicate keys */
                    117:        u_long  flags;
                    118:        u_int   cachesize;      /* bytes to cache */
                    119:        int     maxkeypage;     /* maximum keys per page */
                    120:        int     minkeypage;     /* minimum keys per page */
                    121:        u_int   psize;          /* page size */
                    122:        int     (*compare)      /* comparison function */
1.5       millert   123: (const DBT *, const DBT *);
1.1       deraadt   124:        size_t  (*prefix)       /* prefix function */
1.5       millert   125: (const DBT *, const DBT *);
1.1       deraadt   126:        int     lorder;         /* byte order */
                    127: } BTREEINFO;
                    128:
                    129: #define        HASHMAGIC       0x061561
                    130: #define        HASHVERSION     2
                    131:
                    132: /* Structure used to pass parameters to the hashing routines. */
                    133: typedef struct {
                    134:        u_int   bsize;          /* bucket size */
                    135:        u_int   ffactor;        /* fill factor */
                    136:        u_int   nelem;          /* number of elements */
                    137:        u_int   cachesize;      /* bytes to cache */
                    138:        u_int32_t               /* hash function */
1.5       millert   139:                (*hash)(const void *, size_t);
1.1       deraadt   140:        int     lorder;         /* byte order */
                    141: } HASHINFO;
                    142:
                    143: /* Structure used to pass parameters to the record routines. */
                    144: typedef struct {
                    145: #define        R_FIXEDLEN      0x01    /* fixed-length records */
                    146: #define        R_NOKEY         0x02    /* key not required */
                    147: #define        R_SNAPSHOT      0x04    /* snapshot the input */
                    148:        u_long  flags;
                    149:        u_int   cachesize;      /* bytes to cache */
                    150:        u_int   psize;          /* page size */
                    151:        int     lorder;         /* byte order */
                    152:        size_t  reclen;         /* record length (fixed-length records) */
1.4       aaron     153:        u_char  bval;           /* delimiting byte (variable-length records) */
1.1       deraadt   154:        char    *bfname;        /* btree file name */
                    155: } RECNOINFO;
                    156:
                    157: #ifdef __DBINTERFACE_PRIVATE
                    158: /*
                    159:  * Little endian <==> big endian 32-bit swap macros.
                    160:  *     M_32_SWAP       swap a memory location
                    161:  *     P_32_SWAP       swap a referenced memory location
                    162:  *     P_32_COPY       swap from one location to another
                    163:  */
                    164: #define        M_32_SWAP(a) {                                                  \
                    165:        u_int32_t _tmp = a;                                             \
                    166:        ((char *)&a)[0] = ((char *)&_tmp)[3];                           \
                    167:        ((char *)&a)[1] = ((char *)&_tmp)[2];                           \
                    168:        ((char *)&a)[2] = ((char *)&_tmp)[1];                           \
                    169:        ((char *)&a)[3] = ((char *)&_tmp)[0];                           \
                    170: }
                    171: #define        P_32_SWAP(a) {                                                  \
                    172:        u_int32_t _tmp = *(u_int32_t *)a;                               \
                    173:        ((char *)a)[0] = ((char *)&_tmp)[3];                            \
                    174:        ((char *)a)[1] = ((char *)&_tmp)[2];                            \
                    175:        ((char *)a)[2] = ((char *)&_tmp)[1];                            \
                    176:        ((char *)a)[3] = ((char *)&_tmp)[0];                            \
                    177: }
                    178: #define        P_32_COPY(a, b) {                                               \
                    179:        ((char *)&(b))[0] = ((char *)&(a))[3];                          \
                    180:        ((char *)&(b))[1] = ((char *)&(a))[2];                          \
                    181:        ((char *)&(b))[2] = ((char *)&(a))[1];                          \
                    182:        ((char *)&(b))[3] = ((char *)&(a))[0];                          \
                    183: }
                    184:
                    185: /*
                    186:  * Little endian <==> big endian 16-bit swap macros.
                    187:  *     M_16_SWAP       swap a memory location
                    188:  *     P_16_SWAP       swap a referenced memory location
                    189:  *     P_16_COPY       swap from one location to another
                    190:  */
                    191: #define        M_16_SWAP(a) {                                                  \
                    192:        u_int16_t _tmp = a;                                             \
                    193:        ((char *)&a)[0] = ((char *)&_tmp)[1];                           \
                    194:        ((char *)&a)[1] = ((char *)&_tmp)[0];                           \
                    195: }
                    196: #define        P_16_SWAP(a) {                                                  \
                    197:        u_int16_t _tmp = *(u_int16_t *)a;                               \
                    198:        ((char *)a)[0] = ((char *)&_tmp)[1];                            \
                    199:        ((char *)a)[1] = ((char *)&_tmp)[0];                            \
                    200: }
                    201: #define        P_16_COPY(a, b) {                                               \
                    202:        ((char *)&(b))[0] = ((char *)&(a))[1];                          \
                    203:        ((char *)&(b))[1] = ((char *)&(a))[0];                          \
                    204: }
                    205: #endif
                    206:
                    207: __BEGIN_DECLS
1.5       millert   208: DB *dbopen(const char *, int, int, DBTYPE, const void *);
1.1       deraadt   209:
                    210: #ifdef __DBINTERFACE_PRIVATE
1.5       millert   211: DB     *__bt_open(const char *, int, int, const BTREEINFO *, int);
                    212: DB     *__hash_open(const char *, int, int, const HASHINFO *, int);
                    213: DB     *__rec_open(const char *, int, int, const RECNOINFO *, int);
                    214: void    __dbpanic(DB *dbp);
1.1       deraadt   215: #endif
                    216: __END_DECLS
                    217: #endif /* !_DB_H_ */