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