michael@0: /*- michael@0: * Copyright (c) 1991, 1993 michael@0: * The Regents of the University of California. All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * 1. Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * 2. Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in the michael@0: * documentation and/or other materials provided with the distribution. michael@0: * 3. ***REMOVED*** - see michael@0: * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change michael@0: * 4. Neither the name of the University nor the names of its contributors michael@0: * may be used to endorse or promote products derived from this software michael@0: * without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND michael@0: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE michael@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE michael@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE michael@0: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL michael@0: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS michael@0: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) michael@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT michael@0: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY michael@0: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF michael@0: * SUCH DAMAGE. michael@0: */ michael@0: michael@0: #if defined(LIBC_SCCS) && !defined(lint) michael@0: static char sccsid[] = "@(#)db.c 8.4 (Berkeley) 2/21/94"; michael@0: #endif /* LIBC_SCCS and not lint */ michael@0: michael@0: #ifndef __DBINTERFACE_PRIVATE michael@0: #define __DBINTERFACE_PRIVATE michael@0: #endif michael@0: #ifdef macintosh michael@0: #include michael@0: #else michael@0: #include michael@0: #endif michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "mcom_db.h" michael@0: michael@0: /* a global flag that locks closed all databases */ michael@0: int all_databases_locked_closed = 0; michael@0: michael@0: /* set or unset a global lock flag to disable the michael@0: * opening of any DBM file michael@0: */ michael@0: void michael@0: dbSetOrClearDBLock(DBLockFlagEnum type) michael@0: { michael@0: if(type == LockOutDatabase) michael@0: all_databases_locked_closed = 1; michael@0: else michael@0: all_databases_locked_closed = 0; michael@0: } michael@0: michael@0: DB * michael@0: dbopen(const char *fname, int flags,int mode, DBTYPE type, const void *openinfo) michael@0: { michael@0: michael@0: /* lock out all file databases. Let in-memory databases through michael@0: */ michael@0: if(all_databases_locked_closed && fname) michael@0: { michael@0: errno = EINVAL; michael@0: return(NULL); michael@0: } michael@0: michael@0: #define DB_FLAGS (DB_LOCK | DB_SHMEM | DB_TXN) michael@0: michael@0: michael@0: #if 0 /* most systems don't have EXLOCK and SHLOCK */ michael@0: #define USE_OPEN_FLAGS \ michael@0: (O_CREAT | O_EXCL | O_EXLOCK | O_NONBLOCK | O_RDONLY | \ michael@0: O_RDWR | O_SHLOCK | O_TRUNC) michael@0: #else michael@0: #define USE_OPEN_FLAGS \ michael@0: (O_CREAT | O_EXCL | O_RDONLY | \ michael@0: O_RDWR | O_TRUNC) michael@0: #endif michael@0: michael@0: if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0) michael@0: switch (type) { michael@0: /* we don't need btree and recno right now */ michael@0: #if 0 michael@0: case DB_BTREE: michael@0: return (__bt_open(fname, flags & USE_OPEN_FLAGS, michael@0: mode, openinfo, flags & DB_FLAGS)); michael@0: case DB_RECNO: michael@0: return (__rec_open(fname, flags & USE_OPEN_FLAGS, michael@0: mode, openinfo, flags & DB_FLAGS)); michael@0: #endif michael@0: michael@0: case DB_HASH: michael@0: return (__hash_open(fname, flags & USE_OPEN_FLAGS, michael@0: mode, (const HASHINFO *)openinfo, flags & DB_FLAGS)); michael@0: default: michael@0: break; michael@0: } michael@0: errno = EINVAL; michael@0: return (NULL); michael@0: } michael@0: michael@0: static int michael@0: __dberr() michael@0: { michael@0: return (RET_ERROR); michael@0: } michael@0: michael@0: /* michael@0: * __DBPANIC -- Stop. michael@0: * michael@0: * Parameters: michael@0: * dbp: pointer to the DB structure. michael@0: */ michael@0: void michael@0: __dbpanic(DB *dbp) michael@0: { michael@0: /* The only thing that can succeed is a close. */ michael@0: dbp->del = (int (*)(const struct __db *, const DBT *, uint))__dberr; michael@0: dbp->fd = (int (*)(const struct __db *))__dberr; michael@0: dbp->get = (int (*)(const struct __db *, const DBT *, DBT *, uint))__dberr; michael@0: dbp->put = (int (*)(const struct __db *, DBT *, const DBT *, uint))__dberr; michael@0: dbp->seq = (int (*)(const struct __db *, DBT *, DBT *, uint))__dberr; michael@0: dbp->sync = (int (*)(const struct __db *, uint))__dberr; michael@0: }