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

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

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