glibc/db2/db185/db185.c
Ulrich Drepper bf7997b65c Update.
1998-06-09  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/unix/sysv/linux/netinet/ip.h (struct ip_options): Define
	__data member only for gcc.  Reported by ak@muc.de.

	* misc/mntent.h: Undo last patch.
	* sysdeps/unix/sysv/linux/fstatvfs.c (fstatvfs): Undo last patch.
	* misc/tst/mntent.c: Adjust code for this change.

	* io/fts.c: Updated from a slightly more recent BSD version.
	* io/fts.h: Likewise.

	* libc.map: Add __libc_stack_end.

	* db2/Makefile (routines): Add lock_region.
	* db2/config.h: Update from db-2.4.14.
	* db2/db.h: Likewise.
	* db2/db_185.h: Likewise.
	* db2/db_int.h: Likewise.
	* db2/bt_close.c: Likewise.
	* db2/bt_compare.c: Likewise.
	* db2/bt_conv.c: Likewise.
	* db2/bt_cursor.c: Likewise.
	* db2/bt_delete.c: Likewise.
	* db2/bt_open.c: Likewise.
	* db2/bt_page.c: Likewise.
	* db2/bt_put.c: Likewise.
	* db2/bt_rec.c: Likewise.
	* db2/bt_recno.c: Likewise.
	* db2/bt_rsearch.c: Likewise.
	* db2/bt_search.c: Likewise.
	* db2/bt_split.c: Likewise.
	* db2/bt_stat.c: Likewise.
	* db2/btree.src: Likewise.
	* db2/btree_auto.c: Likewise.
	* db2/getlong.c: Likewise.
	* db2/db_appinit.c: Likewise.
	* db2/db_apprec.c: Likewise.
	* db2/db_byteorder.c: Likewise.
	* db2/db_err.c: Likewise.
	* db2/db_log2.c: Likewise.
	* db2/db_region.c: Likewise.
	* db2/db_salloc.c: Likewise.
	* db2/db_shash.c: Likewise.
	* db2/db.c: Likewise.
	* db2/db.src: Likewise.
	* db2/db_auto.c: Likewise.
	* db2/db_conv.c: Likewise.
	* db2/db_dispatch.c: Likewise.
	* db2/db_dup.c: Likewise.
	* db2/db_overflow.c: Likewise.
	* db2/db_pr.c: Likewise.
	* db2/db_rec.c: Likewise.
	* db2/db_ret.c: Likewise.
	* db2/db_thread.c: Likewise.
	* db2/db185.c: Likewise.
	* db2/db185_int.h: Likewise.
	* db2/dbm.c: Likewise.
	* db2/hash.c: Likewise.
	* db2/hash.src: Likewise.
	* db2/hash_auto.c: Likewise.
	* db2/hash_conv.c: Likewise.
	* db2/hash_debug.c: Likewise.
	* db2/hash_dup.c: Likewise.
	* db2/hash_func.c: Likewise.
	* db2/hash_page.c: Likewise.
	* db2/hash_rec.c: Likewise.
	* db2/hash_stat.c: Likewise.
	* db2/btree.h: Likewise.
	* db2/btree_ext.h: Likewise.
	* db2/clib_ext.h: Likewise.
	* db2/common_ext.h: Likewise.
	* db2/cxx_int.h: Likewise.
	* db2/db.h.src: Likewise.
	* db2/db_185.h.src: Likewise.
	* db2/db_am.h: Likewise.
	* db2/db_auto.h: Likewise.
	* db2/db_cxx.h: Likewise.
	* db2/db_dispatch.h: Likewise.
	* db2/db_ext.h: Likewise.
	* db2/db_int.h.src: Likewise.
	* db2/db_page.h: Likewise.
	* db2/db_shash.h: Likewise.
	* db2/db_swap.h: Likewise.
	* db2/hash.h: Likewise.
	* db2/hash_ext.h: Likewise.
	* db2/lock.h: Likewise.
	* db2/lock_ext.h: Likewise.
	* db2/log.h: Likewise.
	* db2/log_ext.h: Likewise.
	* db2/mp.h: Likewise.
	* db2/mp_ext.h: Likewise.
	* db2/mutex_ext.h: Likewise.
	* db2/os_ext.h: Likewise.
	* db2/os_func.h: Likewise.
	* db2/queue.h: Likewise.
	* db2/shqueue.h: Likewise.
	* db2/txn.h: Likewise.
	* db2/lock.c: Likewise.
	* db2/lock_conflict.c: Likewise.
	* db2/lock_deadlock.c: Likewise.
	* db2/lock_region.c: Likewise.
	* db2/lock_util.c: Likewise.
	* db2/log.c: Likewise.
	* db2/log.src: Likewise.
	* db2/log_archive.c: Likewise.
	* db2/log_auto.c: Likewise.
	* db2/log_compare.c: Likewise.
	* db2/log_findckp.c: Likewise.
	* db2/log_get.c: Likewise.
	* db2/log_put.c: Likewise.
	* db2/log_rec.c: Likewise.
	* db2/log_register.c: Likewise.
	* db2/mp_bh.c: Likewise.
	* db2/mp_fget.c: Likewise.
	* db2/mp_fopen.c: Likewise.
	* db2/mp_fput.c: Likewise.
	* db2/mp_fset.c: Likewise.
	* db2/mp_open.c: Likewise.
	* db2/mp_pr.c: Likewise.
	* db2/mp_region.c: Likewise.
	* db2/mp_sync.c: Likewise.
	* db2/68020.gcc: Likewise.
	* db2/mutex.c: Likewise.
	* db2/parisc.gcc: Likewise.
	* db2/parisc.hp: Likewise.
	* db2/sco.cc: Likewise.
	* db2/os_abs.c: Likewise.
	* db2/os_alloc.c: Likewise.
	* db2/os_config.c: Likewise.
	* db2/os_dir.c: Likewise.
	* db2/os_fid.c: Likewise.
	* db2/os_fsync.c: Likewise.
	* db2/os_map.c: Likewise.
	* db2/os_oflags.c: Likewise.
	* db2/os_open.c: Likewise.
	* db2/os_rpath.c: Likewise.
	* db2/os_rw.c: Likewise.
	* db2/os_seek.c: Likewise.
	* db2/os_sleep.c: Likewise.
	* db2/os_spin.c: Likewise.
	* db2/os_stat.c: Likewise.
	* db2/os_unlink.c: Likewise.
	* db2/db_archive.c: Likewise.
	* db2/db_checkpoint.c: Likewise.
	* db2/db_deadlock.c: Likewise.
	* db2/db_dump.c: Likewise.
	* db2/db_dump185.c: Likewise.
	* db2/db_load.c: Likewise.
	* db2/db_printlog.c: Likewise.
	* db2/db_recover.c: Likewise.
	* db2/db_stat.c: Likewise.
	* db2/txn.c: Likewise.
	* db2/txn.src: Likewise.
	* db2/txn_auto.c: Likewise.
	* db2/txn_rec.c: Likewise.

	* elf/rtld.c: Move definition of __libc_stack_end to ...
	* sysdeps/generic/dl-sysdep.h: ...here.

	* sysdeps/unix/sysv/linux/fstatvfs.c: Handle nodiratime option.
	* sysdeps/unix/sysv/linux/bits/statvfs.h: Define ST_NODIRATIME.
	* sysdeps/unix/sysv/linux/sys/mount.h: Define MS_NODIRATIME.

1998-06-08 21:44  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/unix/sysv/linux/fstatvfs.c: Handle constant option string
	from mntent correctly.

1998-06-06  Andreas Jaeger  <aj@arthur.rhein-neckar.de>

	* sunrpc/Makefile (generated): Correct typo.

1998-06-04  Philip Blundell  <philb@gnu.org>

	* elf/elf.h (EM_ARM, et al.): New definitions.
	* sysdeps/arm/dl-machine.h: Update for new draft ARM ELF ABI.
1998-06-09 15:16:55 +00:00

487 lines
10 KiB
C

/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1996, 1997, 1998
* Sleepycat Software. All rights reserved.
*/
#include "config.h"
#ifndef lint
static const char copyright[] =
"@(#) Copyright (c) 1996, 1997, 1998\n\
Sleepycat Software Inc. All rights reserved.\n";
static const char sccsid[] = "@(#)db185.c 8.17 (Sleepycat) 5/7/98";
#endif
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#endif
#include "db_int.h"
#include "db185_int.h"
#include "common_ext.h"
static int db185_close __P((DB185 *));
static int db185_del __P((const DB185 *, const DBT185 *, u_int));
static int db185_fd __P((const DB185 *));
static int db185_get __P((const DB185 *, const DBT185 *, DBT185 *, u_int));
static int db185_put __P((const DB185 *, DBT185 *, const DBT185 *, u_int));
static int db185_seq __P((const DB185 *, DBT185 *, DBT185 *, u_int));
static int db185_sync __P((const DB185 *, u_int));
DB185 *
__dbopen(file, oflags, mode, type, openinfo)
const char *file;
int oflags, mode;
DBTYPE type;
const void *openinfo;
{
const BTREEINFO *bi;
const HASHINFO *hi;
const RECNOINFO *ri;
DB *dbp;
DB185 *db185p;
DB_INFO dbinfo, *dbinfop;
int s_errno;
if ((db185p = (DB185 *)__db_calloc(1, sizeof(DB185))) == NULL)
return (NULL);
dbinfop = NULL;
memset(&dbinfo, 0, sizeof(dbinfo));
/*
* !!!
* The DBTYPE enum wasn't initialized in DB 185, so it's off-by-one
* from DB 2.0.
*/
switch (type) {
case 0: /* DB_BTREE */
type = DB_BTREE;
if ((bi = openinfo) != NULL) {
dbinfop = &dbinfo;
if (bi->flags & ~R_DUP)
goto einval;
if (bi->flags & R_DUP)
dbinfop->flags |= DB_DUP;
dbinfop->db_cachesize = bi->cachesize;
dbinfop->bt_maxkey = bi->maxkeypage;
dbinfop->bt_minkey = bi->minkeypage;
dbinfop->db_pagesize = bi->psize;
/*
* !!!
* Comparisons and prefix calls work because the DBT
* structures in 1.85 and 2.0 have the same initial
* fields.
*/
dbinfop->bt_compare = bi->compare;
dbinfop->bt_prefix = bi->prefix;
dbinfop->db_lorder = bi->lorder;
}
break;
case 1: /* DB_HASH */
type = DB_HASH;
if ((hi = openinfo) != NULL) {
dbinfop = &dbinfo;
dbinfop->db_pagesize = hi->bsize;
dbinfop->h_ffactor = hi->ffactor;
dbinfop->h_nelem = hi->nelem;
dbinfop->db_cachesize = hi->cachesize;
dbinfop->h_hash = hi->hash;
dbinfop->db_lorder = hi->lorder;
}
break;
case 2: /* DB_RECNO */
type = DB_RECNO;
dbinfop = &dbinfo;
/* DB 1.85 did renumbering by default. */
dbinfop->flags |= DB_RENUMBER;
/*
* !!!
* The file name given to DB 1.85 recno is the name of the DB
* 2.0 backing file. If the file doesn't exist, create it if
* the user has the O_CREAT flag set, DB 1.85 did it for you,
* and DB 2.0 doesn't.
*
* !!!
* Setting the file name to NULL specifies that we're creating
* a temporary backing file, in DB 2.X. If we're opening the
* DB file read-only, change the flags to read-write, because
* temporary backing files cannot be opened read-only, and DB
* 2.X will return an error. We are cheating here -- if the
* application does a put on the database, it will succeed --
* although that would be a stupid thing for the application
* to do.
*
* !!!
* Note, the file name in DB 1.85 was a const -- we don't do
* that in DB 2.0, so do that cast.
*/
if (file != NULL) {
if (oflags & O_CREAT && __db_exists(file, NULL) != 0)
(void)__os_close(__os_open(file, oflags, mode));
dbinfop->re_source = (char *)file;
file = NULL;
if (O_RDONLY)
oflags &= ~O_RDONLY;
oflags |= O_RDWR;
}
if ((ri = openinfo) != NULL) {
/*
* !!!
* We can't support the bfname field.
*/
#define BFMSG "DB: DB 1.85's recno bfname field is not supported.\n"
if (ri->bfname != NULL) {
(void)__os_write(2, BFMSG, sizeof(BFMSG) - 1);
goto einval;
}
if (ri->flags & ~(R_FIXEDLEN | R_NOKEY | R_SNAPSHOT))
goto einval;
if (ri->flags & R_FIXEDLEN) {
dbinfop->flags |= DB_FIXEDLEN;
if (ri->bval != 0) {
dbinfop->flags |= DB_PAD;
dbinfop->re_pad = ri->bval;
}
} else
if (ri->bval != 0) {
dbinfop->flags |= DB_DELIMITER;
dbinfop->re_delim = ri->bval;
}
/*
* !!!
* We ignore the R_NOKEY flag, but that's okay, it was
* only an optimization that was never implemented.
*/
if (ri->flags & R_SNAPSHOT)
dbinfop->flags |= DB_SNAPSHOT;
dbinfop->db_cachesize = ri->cachesize;
dbinfop->db_pagesize = ri->psize;
dbinfop->db_lorder = ri->lorder;
dbinfop->re_len = ri->reclen;
}
break;
default:
goto einval;
}
db185p->close = db185_close;
db185p->del = db185_del;
db185p->fd = db185_fd;
db185p->get = db185_get;
db185p->put = db185_put;
db185p->seq = db185_seq;
db185p->sync = db185_sync;
/*
* !!!
* Store the returned pointer to the real DB 2.0 structure in the
* internal pointer. Ugly, but we're not going for pretty, here.
*/
if ((errno = db_open(file,
type, __db_oflags(oflags), mode, NULL, dbinfop, &dbp)) != 0) {
__db_free(db185p);
return (NULL);
}
/* Create the cursor used for sequential ops. */
if ((errno = dbp->cursor(dbp, NULL, &((DB185 *)db185p)->dbc)) != 0) {
s_errno = errno;
(void)dbp->close(dbp, 0);
__db_free(db185p);
__set_errno(s_errno);
return (NULL);
}
db185p->internal = dbp;
return (db185p);
einval: __db_free(db185p);
__set_errno(EINVAL);
return (NULL);
}
weak_alias (__dbopen, dbopen)
static int
db185_close(db185p)
DB185 *db185p;
{
DB *dbp;
dbp = (DB *)db185p->internal;
__set_errno(dbp->close(dbp, 0));
__db_free(db185p);
return (errno == 0 ? 0 : -1);
}
static int
db185_del(db185p, key185, flags)
const DB185 *db185p;
const DBT185 *key185;
u_int flags;
{
DB *dbp;
DBT key;
dbp = (DB *)db185p->internal;
memset(&key, 0, sizeof(key));
key.data = key185->data;
key.size = key185->size;
if (flags & ~R_CURSOR)
goto einval;
if (flags & R_CURSOR)
__set_errno(db185p->dbc->c_del(db185p->dbc, 0));
else
__set_errno(dbp->del(dbp, NULL, &key, 0));
switch (errno) {
case 0:
return (0);
case DB_NOTFOUND:
return (1);
}
return (-1);
einval: __set_errno(EINVAL);
return (-1);
}
static int
db185_fd(db185p)
const DB185 *db185p;
{
DB *dbp;
int fd;
dbp = (DB *)db185p->internal;
return ((__set_errno(dbp->fd(dbp, &fd))) == 0 ? fd : -1);
}
static int
db185_get(db185p, key185, data185, flags)
const DB185 *db185p;
const DBT185 *key185;
DBT185 *data185;
u_int flags;
{
DB *dbp;
DBT key, data;
dbp = (DB *)db185p->internal;
memset(&key, 0, sizeof(key));
key.data = key185->data;
key.size = key185->size;
memset(&data, 0, sizeof(data));
data.data = data185->data;
data.size = data185->size;
if (flags)
goto einval;
switch (__set_errno(dbp->get(dbp, NULL, &key, &data, 0))) {
case 0:
data185->data = data.data;
data185->size = data.size;
return (0);
case DB_NOTFOUND:
return (1);
}
return (-1);
einval: __set_errno(EINVAL);
return (-1);
}
static int
db185_put(db185p, key185, data185, flags)
const DB185 *db185p;
DBT185 *key185;
const DBT185 *data185;
u_int flags;
{
DB *dbp;
DBC *dbcp_put;
DBT key, data;
int s_errno;
dbp = (DB *)db185p->internal;
memset(&key, 0, sizeof(key));
key.data = key185->data;
key.size = key185->size;
memset(&data, 0, sizeof(data));
data.data = data185->data;
data.size = data185->size;
switch (flags) {
case 0:
__set_errno(dbp->put(dbp, NULL, &key, &data, 0));
break;
case R_CURSOR:
__set_errno(
db185p->dbc->c_put(db185p->dbc, &key, &data, DB_CURRENT));
break;
case R_IAFTER:
case R_IBEFORE:
if (dbp->type != DB_RECNO)
goto einval;
if ((__set_errno(dbp->cursor(dbp, NULL, &dbcp_put))) != 0)
return (-1);
if ((__set_errno(
dbcp_put->c_get(dbcp_put, &key, &data, DB_SET))) != 0) {
s_errno = errno;
(void)dbcp_put->c_close(dbcp_put);
__set_errno(s_errno);
return (-1);
}
memset(&data, 0, sizeof(data));
data.data = data185->data;
data.size = data185->size;
__set_errno(dbcp_put->c_put(dbcp_put,
&key, &data, flags == R_IAFTER ? DB_AFTER : DB_BEFORE));
s_errno = errno;
(void)dbcp_put->c_close(dbcp_put);
__set_errno(s_errno);
break;
case R_NOOVERWRITE:
__set_errno(dbp->put(dbp, NULL, &key, &data, DB_NOOVERWRITE));
break;
case R_SETCURSOR:
if (dbp->type != DB_BTREE && dbp->type != DB_RECNO)
goto einval;
if ((__set_errno(dbp->put(dbp, NULL, &key, &data, 0))) != 0)
break;
__set_errno(db185p->dbc->c_get(db185p->dbc,
&key, &data, DB_SET_RANGE));
break;
default:
goto einval;
}
switch (errno) {
case 0:
key185->data = key.data;
key185->size = key.size;
return (0);
case DB_KEYEXIST:
return (1);
}
return (-1);
einval: __set_errno(EINVAL);
return (-1);
}
static int
db185_seq(db185p, key185, data185, flags)
const DB185 *db185p;
DBT185 *key185, *data185;
u_int flags;
{
DB *dbp;
DBT key, data;
dbp = (DB *)db185p->internal;
memset(&key, 0, sizeof(key));
key.data = key185->data;
key.size = key185->size;
memset(&data, 0, sizeof(data));
data.data = data185->data;
data.size = data185->size;
switch (flags) {
case R_CURSOR:
flags = DB_SET_RANGE;
break;
case R_FIRST:
flags = DB_FIRST;
break;
case R_LAST:
if (dbp->type != DB_BTREE && dbp->type != DB_RECNO)
goto einval;
flags = DB_LAST;
break;
case R_NEXT:
flags = DB_NEXT;
break;
case R_PREV:
if (dbp->type != DB_BTREE && dbp->type != DB_RECNO)
goto einval;
flags = DB_PREV;
break;
default:
goto einval;
}
switch (__set_errno(db185p->dbc->c_get(db185p->dbc,
&key, &data, flags))) {
case 0:
key185->data = key.data;
key185->size = key.size;
data185->data = data.data;
data185->size = data.size;
return (0);
case DB_NOTFOUND:
return (1);
}
return (-1);
einval: __set_errno(EINVAL);
return (-1);
}
static int
db185_sync(db185p, flags)
const DB185 *db185p;
u_int flags;
{
DB *dbp;
dbp = (DB *)db185p->internal;
switch (flags) {
case 0:
break;
case R_RECNOSYNC:
/*
* !!!
* We can't support the R_RECNOSYNC flag.
*/
#define RSMSG "DB: DB 1.85's R_RECNOSYNC sync flag is not supported.\n"
(void)__os_write(2, RSMSG, sizeof(RSMSG) - 1);
goto einval;
default:
goto einval;
}
return ((__set_errno(dbp->sync(dbp, 0))) == 0 ? 0 : -1);
einval: __set_errno(EINVAL);
return (-1);
}