Annotation of XNU/bsd/include/db.h, revision 1.1

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