Annotation of kernel/bsd/include/db.h, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.