17c478bd9Sstevel@tonic-gate /*- 27c478bd9Sstevel@tonic-gate * Copyright (c) 1990, 1993, 1994 37c478bd9Sstevel@tonic-gate * The Regents of the University of California. All rights reserved. 47c478bd9Sstevel@tonic-gate * 57c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 67c478bd9Sstevel@tonic-gate * modification, are permitted provided that the following conditions 77c478bd9Sstevel@tonic-gate * are met: 87c478bd9Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 97c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 107c478bd9Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 117c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 127c478bd9Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 137c478bd9Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software 147c478bd9Sstevel@tonic-gate * must display the following acknowledgement: 157c478bd9Sstevel@tonic-gate * This product includes software developed by the University of 167c478bd9Sstevel@tonic-gate * California, Berkeley and its contributors. 177c478bd9Sstevel@tonic-gate * 4. Neither the name of the University nor the names of its contributors 187c478bd9Sstevel@tonic-gate * may be used to endorse or promote products derived from this software 197c478bd9Sstevel@tonic-gate * without specific prior written permission. 207c478bd9Sstevel@tonic-gate * 217c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 227c478bd9Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 237c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 247c478bd9Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 257c478bd9Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 267c478bd9Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 277c478bd9Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 287c478bd9Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 297c478bd9Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 307c478bd9Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 317c478bd9Sstevel@tonic-gate * SUCH DAMAGE. 327c478bd9Sstevel@tonic-gate * 337c478bd9Sstevel@tonic-gate * @(#)db.h 8.8 (Berkeley) 11/2/95 347c478bd9Sstevel@tonic-gate */ 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #ifndef _DB_H_ 377c478bd9Sstevel@tonic-gate #define _DB_H_ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <db-config.h> 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #include <sys/types.h> 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #define RET_ERROR -1 /* Return values. */ 447c478bd9Sstevel@tonic-gate #define RET_SUCCESS 0 457c478bd9Sstevel@tonic-gate #define RET_SPECIAL 1 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* Key/data structure -- a Data-Base Thang. */ 487c478bd9Sstevel@tonic-gate typedef struct { 497c478bd9Sstevel@tonic-gate void *data; /* data */ 507c478bd9Sstevel@tonic-gate size_t size; /* data length */ 517c478bd9Sstevel@tonic-gate } DBT; 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* Routine flags. */ 547c478bd9Sstevel@tonic-gate #define R_CURSOR 1 /* del, put, seq */ 557c478bd9Sstevel@tonic-gate #define __R_UNUSED 2 /* UNUSED */ 567c478bd9Sstevel@tonic-gate #define R_FIRST 3 /* seq */ 577c478bd9Sstevel@tonic-gate #define R_IAFTER 4 /* put (RECNO) */ 587c478bd9Sstevel@tonic-gate #define R_IBEFORE 5 /* put (RECNO) */ 597c478bd9Sstevel@tonic-gate #define R_LAST 6 /* seq (BTREE, RECNO) */ 607c478bd9Sstevel@tonic-gate #define R_NEXT 7 /* seq */ 617c478bd9Sstevel@tonic-gate #define R_NOOVERWRITE 8 /* put */ 627c478bd9Sstevel@tonic-gate #define R_PREV 9 /* seq (BTREE, RECNO) */ 637c478bd9Sstevel@tonic-gate #define R_SETCURSOR 10 /* put (RECNO) */ 647c478bd9Sstevel@tonic-gate #define R_RECNOSYNC 11 /* sync (RECNO) */ 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE; 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* 697c478bd9Sstevel@tonic-gate * !!! 707c478bd9Sstevel@tonic-gate * The following flags are included in the dbopen(3) call as part of the 717c478bd9Sstevel@tonic-gate * open(2) flags. In order to avoid conflicts with the open flags, start 727c478bd9Sstevel@tonic-gate * at the top of the 16 or 32-bit number space and work our way down. If 737c478bd9Sstevel@tonic-gate * the open flags were significantly expanded in the future, it could be 747c478bd9Sstevel@tonic-gate * a problem. Wish I'd left another flags word in the dbopen call. 757c478bd9Sstevel@tonic-gate * 767c478bd9Sstevel@tonic-gate * !!! 777c478bd9Sstevel@tonic-gate * None of this stuff is implemented yet. The only reason that it's here 787c478bd9Sstevel@tonic-gate * is so that the access methods can skip copying the key/data pair when 797c478bd9Sstevel@tonic-gate * the DB_LOCK flag isn't set. 807c478bd9Sstevel@tonic-gate */ 81*159d09a2SMark Phalan #if UINT_MAX >= 0xffffffffUL 827c478bd9Sstevel@tonic-gate #define DB_LOCK 0x20000000 /* Do locking. */ 837c478bd9Sstevel@tonic-gate #define DB_SHMEM 0x40000000 /* Use shared memory. */ 847c478bd9Sstevel@tonic-gate #define DB_TXN 0x80000000 /* Do transactions. */ 857c478bd9Sstevel@tonic-gate #else 867c478bd9Sstevel@tonic-gate #define DB_LOCK 0x2000 /* Do locking. */ 877c478bd9Sstevel@tonic-gate #define DB_SHMEM 0x4000 /* Use shared memory. */ 887c478bd9Sstevel@tonic-gate #define DB_TXN 0x8000 /* Do transactions. */ 897c478bd9Sstevel@tonic-gate #endif 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* deal with turning prototypes on and off */ 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate #ifndef __P 947c478bd9Sstevel@tonic-gate #if defined(__STDC__) || defined(__cplusplus) 957c478bd9Sstevel@tonic-gate #define __P(protos) protos /* full-blown ANSI C */ 967c478bd9Sstevel@tonic-gate #else /* !(__STDC__ || __cplusplus) */ 977c478bd9Sstevel@tonic-gate #define __P(protos) () /* traditional C preprocessor */ 987c478bd9Sstevel@tonic-gate #endif 997c478bd9Sstevel@tonic-gate #endif /* no __P from system */ 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate /* Access method description structure. */ 1027c478bd9Sstevel@tonic-gate typedef struct __db { 1037c478bd9Sstevel@tonic-gate DBTYPE type; /* Underlying db type. */ 1047c478bd9Sstevel@tonic-gate int (*close) __P((struct __db *)); 1057c478bd9Sstevel@tonic-gate int (*del) __P((const struct __db *, const DBT *, u_int)); 1067c478bd9Sstevel@tonic-gate int (*get) __P((const struct __db *, const DBT *, DBT *, u_int)); 1077c478bd9Sstevel@tonic-gate int (*put) __P((const struct __db *, DBT *, const DBT *, u_int)); 1087c478bd9Sstevel@tonic-gate int (*seq) __P((const struct __db *, DBT *, DBT *, u_int)); 1097c478bd9Sstevel@tonic-gate int (*sync) __P((const struct __db *, u_int)); 1107c478bd9Sstevel@tonic-gate void *internal; /* Access method private. */ 1117c478bd9Sstevel@tonic-gate int (*fd) __P((const struct __db *)); 1127c478bd9Sstevel@tonic-gate } DB; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate #define BTREEMAGIC 0x053162 1157c478bd9Sstevel@tonic-gate #define BTREEVERSION 3 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* Structure used to pass parameters to the btree routines. */ 1187c478bd9Sstevel@tonic-gate typedef struct { 1197c478bd9Sstevel@tonic-gate #define R_DUP 0x01 /* duplicate keys */ 1207c478bd9Sstevel@tonic-gate u_long flags; 1217c478bd9Sstevel@tonic-gate u_int cachesize; /* bytes to cache */ 1227c478bd9Sstevel@tonic-gate int maxkeypage; /* maximum keys per page */ 1237c478bd9Sstevel@tonic-gate int minkeypage; /* minimum keys per page */ 1247c478bd9Sstevel@tonic-gate u_int psize; /* page size */ 1257c478bd9Sstevel@tonic-gate int (*compare) /* comparison function */ 1267c478bd9Sstevel@tonic-gate __P((const DBT *, const DBT *)); 1277c478bd9Sstevel@tonic-gate size_t (*prefix) /* prefix function */ 1287c478bd9Sstevel@tonic-gate __P((const DBT *, const DBT *)); 1297c478bd9Sstevel@tonic-gate int lorder; /* byte order */ 1307c478bd9Sstevel@tonic-gate } BTREEINFO; 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate #define HASHMAGIC 0x061561 1337c478bd9Sstevel@tonic-gate #define HASHVERSION 3 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate /* Structure used to pass parameters to the hashing routines. */ 1367c478bd9Sstevel@tonic-gate typedef struct { 1377c478bd9Sstevel@tonic-gate u_int bsize; /* bucket size */ 1387c478bd9Sstevel@tonic-gate u_int ffactor; /* fill factor */ 1397c478bd9Sstevel@tonic-gate u_int nelem; /* number of elements */ 1407c478bd9Sstevel@tonic-gate u_int cachesize; /* bytes to cache */ 1417c478bd9Sstevel@tonic-gate u_int32_t /* hash function */ 1427c478bd9Sstevel@tonic-gate (*hash) __P((const void *, size_t)); 1437c478bd9Sstevel@tonic-gate int lorder; /* byte order */ 1447c478bd9Sstevel@tonic-gate } HASHINFO; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate /* Structure used to pass parameters to the record routines. */ 1477c478bd9Sstevel@tonic-gate typedef struct { 1487c478bd9Sstevel@tonic-gate #define R_FIXEDLEN 0x01 /* fixed-length records */ 1497c478bd9Sstevel@tonic-gate #define R_NOKEY 0x02 /* key not required */ 1507c478bd9Sstevel@tonic-gate #define R_SNAPSHOT 0x04 /* snapshot the input */ 1517c478bd9Sstevel@tonic-gate u_long flags; 1527c478bd9Sstevel@tonic-gate u_int cachesize; /* bytes to cache */ 1537c478bd9Sstevel@tonic-gate u_int psize; /* page size */ 1547c478bd9Sstevel@tonic-gate int lorder; /* byte order */ 1557c478bd9Sstevel@tonic-gate size_t reclen; /* record length (fixed-length records) */ 1567c478bd9Sstevel@tonic-gate u_char bval; /* delimiting byte (variable-length records */ 1577c478bd9Sstevel@tonic-gate char *bfname; /* btree file name */ 1587c478bd9Sstevel@tonic-gate } RECNOINFO; 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate #if defined(__cplusplus) 1617c478bd9Sstevel@tonic-gate #define __BEGIN_DECLS extern "C" { 1627c478bd9Sstevel@tonic-gate #define __END_DECLS }; 1637c478bd9Sstevel@tonic-gate #else 1647c478bd9Sstevel@tonic-gate #define __BEGIN_DECLS 1657c478bd9Sstevel@tonic-gate #define __END_DECLS 1667c478bd9Sstevel@tonic-gate #endif 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate #define dbopen kdb2_dbopen 1697c478bd9Sstevel@tonic-gate #define bt_rseq kdb2_bt_rseq /* XXX kludge */ 1707c478bd9Sstevel@tonic-gate __BEGIN_DECLS 1717c478bd9Sstevel@tonic-gate DB *dbopen __P((const char *, int, int, DBTYPE, const void *)); 1727c478bd9Sstevel@tonic-gate int bt_rseq(const DB*, DBT *, DBT *, void **, u_int); /* XXX kludge */ 1737c478bd9Sstevel@tonic-gate __END_DECLS 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate #endif /* !_DB_H_ */ 176