summaryrefslogtreecommitdiff
path: root/bdb/os
diff options
context:
space:
mode:
Diffstat (limited to 'bdb/os')
-rw-r--r--bdb/os/os_abs.c4
-rw-r--r--bdb/os/os_alloc.c308
-rw-r--r--bdb/os/os_clock.c92
-rw-r--r--bdb/os/os_config.c31
-rw-r--r--bdb/os/os_dir.c26
-rw-r--r--bdb/os/os_errno.c36
-rw-r--r--bdb/os/os_fid.c22
-rw-r--r--bdb/os/os_finit.c111
-rw-r--r--bdb/os/os_fsync.c15
-rw-r--r--bdb/os/os_handle.c60
-rw-r--r--bdb/os/os_id.c47
-rw-r--r--bdb/os/os_map.c45
-rw-r--r--bdb/os/os_method.c140
-rw-r--r--bdb/os/os_oflags.c20
-rw-r--r--bdb/os/os_open.c47
-rw-r--r--bdb/os/os_region.c17
-rw-r--r--bdb/os/os_rename.c27
-rw-r--r--bdb/os/os_root.c4
-rw-r--r--bdb/os/os_rpath.c4
-rw-r--r--bdb/os/os_rw.c23
-rw-r--r--bdb/os/os_seek.c15
-rw-r--r--bdb/os/os_sleep.c15
-rw-r--r--bdb/os/os_spin.c38
-rw-r--r--bdb/os/os_stat.c41
-rw-r--r--bdb/os/os_tmpdir.c10
-rw-r--r--bdb/os/os_unlink.c83
26 files changed, 803 insertions, 478 deletions
diff --git a/bdb/os/os_abs.c b/bdb/os/os_abs.c
index 04be9873360..cd7d0a5d2be 100644
--- a/bdb/os/os_abs.c
+++ b/bdb/os/os_abs.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_abs.c,v 11.3 2000/02/14 03:00:04 bostic Exp $";
+static const char revid[] = "$Id: os_abs.c,v 11.5 2002/01/11 15:52:58 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
diff --git a/bdb/os/os_alloc.c b/bdb/os/os_alloc.c
index ee4a0f3c91f..5b38cc7d6f1 100644
--- a/bdb/os/os_alloc.c
+++ b/bdb/os/os_alloc.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_alloc.c,v 11.18 2000/11/30 00:58:42 ubell Exp $";
+static const char revid[] = "$Id: os_alloc.c,v 11.32 2002/08/06 04:57:07 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -19,10 +19,14 @@ static const char revid[] = "$Id: os_alloc.c,v 11.18 2000/11/30 00:58:42 ubell E
#endif
#include "db_int.h"
-#include "os_jump.h"
#ifdef DIAGNOSTIC
-static void __os_guard __P((void));
+static void __os_guard __P((DB_ENV *));
+
+union __db_alloc {
+ size_t size;
+ double align;
+};
#endif
/*
@@ -37,12 +41,150 @@ static void __os_guard __P((void));
* !!!
* Correct for systems that don't set errno when malloc and friends fail.
*
+ * !!!
+ * There is no circumstance in which we can call __os_umalloc, __os_urealloc
+ * or __os_ufree without an environment handle, as we need one to determine
+ * whether or not to use an application-specified malloc function. If we
+ * don't have an environment handle, we should be calling __os_XXX instead.
+ * Make DIAGNOSTIC blow up if we get this wrong.
+ *
* Out of memory.
* We wish to hold the whole sky,
* But we never will.
*/
/*
+ * __os_umalloc --
+ * A malloc(3) function that will use, in order of preference,
+ * the allocation function specified to the DB handle, the DB_ENV
+ * handle, or __os_malloc.
+ *
+ * PUBLIC: int __os_umalloc __P((DB_ENV *, size_t, void *));
+ */
+int
+__os_umalloc(dbenv, size, storep)
+ DB_ENV *dbenv;
+ size_t size;
+ void *storep;
+{
+ int ret;
+
+ /* Require an environment handle. */
+ DB_ASSERT(dbenv != NULL);
+
+ /* Never allocate 0 bytes -- some C libraries don't like it. */
+ if (size == 0)
+ ++size;
+
+ if (dbenv == NULL || dbenv->db_malloc == NULL) {
+ if (DB_GLOBAL(j_malloc) != NULL)
+ *(void **)storep = DB_GLOBAL(j_malloc)(size);
+ else
+ *(void **)storep = malloc(size);
+ if (*(void **)storep == NULL) {
+ /*
+ * Correct error return, see __os_malloc.
+ */
+ if ((ret = __os_get_errno()) == 0) {
+ ret = ENOMEM;
+ __os_set_errno(ENOMEM);
+ }
+ __db_err(dbenv,
+ "malloc: %s: %lu", strerror(ret), (u_long)size);
+ return (ret);
+ }
+ return (0);
+ }
+
+ if ((*(void **)storep = dbenv->db_malloc(size)) == NULL) {
+ __db_err(dbenv, "User-specified malloc function returned NULL");
+ return (ENOMEM);
+ }
+
+ return (0);
+}
+
+/*
+ * __os_urealloc --
+ * realloc(3) counterpart to __os_umalloc.
+ *
+ * PUBLIC: int __os_urealloc __P((DB_ENV *, size_t, void *));
+ */
+int
+__os_urealloc(dbenv, size, storep)
+ DB_ENV *dbenv;
+ size_t size;
+ void *storep;
+{
+ int ret;
+ void *ptr;
+
+ ptr = *(void **)storep;
+
+ /* Require an environment handle. */
+ DB_ASSERT(dbenv != NULL);
+
+ /* Never allocate 0 bytes -- some C libraries don't like it. */
+ if (size == 0)
+ ++size;
+
+ if (dbenv == NULL || dbenv->db_realloc == NULL) {
+ if (ptr == NULL)
+ return (__os_umalloc(dbenv, size, storep));
+
+ if (DB_GLOBAL(j_realloc) != NULL)
+ *(void **)storep = DB_GLOBAL(j_realloc)(ptr, size);
+ else
+ *(void **)storep = realloc(ptr, size);
+ if (*(void **)storep == NULL) {
+ /*
+ * Correct errno, see __os_realloc.
+ */
+ if ((ret = __os_get_errno()) == 0) {
+ ret = ENOMEM;
+ __os_set_errno(ENOMEM);
+ }
+ __db_err(dbenv,
+ "realloc: %s: %lu", strerror(ret), (u_long)size);
+ return (ret);
+ }
+ return (0);
+ }
+
+ if ((*(void **)storep = dbenv->db_realloc(ptr, size)) == NULL) {
+ __db_err(dbenv,
+ "User-specified realloc function returned NULL");
+ return (ENOMEM);
+ }
+
+ return (0);
+}
+
+/*
+ * __os_ufree --
+ * free(3) counterpart to __os_umalloc.
+ *
+ * PUBLIC: int __os_ufree __P((DB_ENV *, void *));
+ */
+int
+__os_ufree(dbenv, ptr)
+ DB_ENV *dbenv;
+ void *ptr;
+{
+ /* Require an environment handle. */
+ DB_ASSERT(dbenv != NULL);
+
+ if (dbenv != NULL && dbenv->db_free != NULL)
+ dbenv->db_free(ptr);
+ else if (DB_GLOBAL(j_free) != NULL)
+ DB_GLOBAL(j_free)(ptr);
+ else
+ free(ptr);
+
+ return (0);
+}
+
+/*
* __os_strdup --
* The strdup(3) function for DB.
*
@@ -61,7 +203,7 @@ __os_strdup(dbenv, str, storep)
*(void **)storep = NULL;
size = strlen(str) + 1;
- if ((ret = __os_malloc(dbenv, size, NULL, &p)) != 0)
+ if ((ret = __os_malloc(dbenv, size, &p)) != 0)
return (ret);
memcpy(p, str, size);
@@ -86,7 +228,7 @@ __os_calloc(dbenv, num, size, storep)
int ret;
size *= num;
- if ((ret = __os_malloc(dbenv, size, NULL, &p)) != 0)
+ if ((ret = __os_malloc(dbenv, size, &p)) != 0)
return (ret);
memset(p, 0, size);
@@ -99,13 +241,13 @@ __os_calloc(dbenv, num, size, storep)
* __os_malloc --
* The malloc(3) function for DB.
*
- * PUBLIC: int __os_malloc __P((DB_ENV *, size_t, void *(*)(size_t), void *));
+ * PUBLIC: int __os_malloc __P((DB_ENV *, size_t, void *));
*/
int
-__os_malloc(dbenv, size, db_malloc, storep)
+__os_malloc(dbenv, size, storep)
DB_ENV *dbenv;
size_t size;
- void *(*db_malloc) __P((size_t)), *storep;
+ void *storep;
{
int ret;
void *p;
@@ -115,24 +257,26 @@ __os_malloc(dbenv, size, db_malloc, storep)
/* Never allocate 0 bytes -- some C libraries don't like it. */
if (size == 0)
++size;
+
#ifdef DIAGNOSTIC
- else
- ++size; /* Add room for a guard byte. */
+ /* Add room for size and a guard byte. */
+ size += sizeof(union __db_alloc) + 1;
#endif
- /* Some C libraries don't correctly set errno when malloc(3) fails. */
- __os_set_errno(0);
- if (db_malloc != NULL)
- p = db_malloc(size);
- else if (__db_jump.j_malloc != NULL)
- p = __db_jump.j_malloc(size);
+ if (DB_GLOBAL(j_malloc) != NULL)
+ p = DB_GLOBAL(j_malloc)(size);
else
p = malloc(size);
if (p == NULL) {
- ret = __os_get_errno();
- if (ret == 0) {
- __os_set_errno(ENOMEM);
+ /*
+ * Some C libraries don't correctly set errno when malloc(3)
+ * fails. We'd like to 0 out errno before calling malloc,
+ * but it turns out that setting errno is quite expensive on
+ * Windows/NT in an MT environment.
+ */
+ if ((ret = __os_get_errno()) == 0) {
ret = ENOMEM;
+ __os_set_errno(ENOMEM);
}
__db_err(dbenv,
"malloc: %s: %lu", strerror(ret), (u_long)size);
@@ -143,15 +287,12 @@ __os_malloc(dbenv, size, db_malloc, storep)
/*
* Guard bytes: if #DIAGNOSTIC is defined, we allocate an additional
* byte after the memory and set it to a special value that we check
- * for when the memory is free'd. This is fine for structures, but
- * not quite so fine for strings. There are places in DB where memory
- * is allocated sufficient to hold the largest possible string that
- * we'll see, and then only some subset of the memory is used. To
- * support this usage, the __os_freestr() function checks the byte
- * after the string's nul, which may or may not be the last byte in
- * the originally allocated memory.
+ * for when the memory is free'd.
*/
- memset(p, CLEAR_BYTE, size); /* Initialize guard byte. */
+ ((u_int8_t *)p)[size - 1] = CLEAR_BYTE;
+
+ ((union __db_alloc *)p)->size = size;
+ p = &((union __db_alloc *)p)[1];
#endif
*(void **)storep = p;
@@ -162,46 +303,50 @@ __os_malloc(dbenv, size, db_malloc, storep)
* __os_realloc --
* The realloc(3) function for DB.
*
- * PUBLIC: int __os_realloc __P((DB_ENV *,
- * PUBLIC: size_t, void *(*)(void *, size_t), void *));
+ * PUBLIC: int __os_realloc __P((DB_ENV *, size_t, void *));
*/
int
-__os_realloc(dbenv, size, db_realloc, storep)
+__os_realloc(dbenv, size, storep)
DB_ENV *dbenv;
size_t size;
- void *(*db_realloc) __P((void *, size_t)), *storep;
+ void *storep;
{
int ret;
void *p, *ptr;
ptr = *(void **)storep;
- /* If we haven't yet allocated anything yet, simply call malloc. */
- if (ptr == NULL && db_realloc == NULL)
- return (__os_malloc(dbenv, size, NULL, storep));
-
/* Never allocate 0 bytes -- some C libraries don't like it. */
if (size == 0)
++size;
+
+ /* If we haven't yet allocated anything yet, simply call malloc. */
+ if (ptr == NULL)
+ return (__os_malloc(dbenv, size, storep));
+
#ifdef DIAGNOSTIC
- else
- ++size; /* Add room for a guard byte. */
+ /* Add room for size and a guard byte. */
+ size += sizeof(union __db_alloc) + 1;
+
+ /* Back up to the real begining */
+ ptr = &((union __db_alloc *)ptr)[-1];
#endif
/*
- * Some C libraries don't correctly set errno when realloc(3) fails.
- *
* Don't overwrite the original pointer, there are places in DB we
* try to continue after realloc fails.
*/
- __os_set_errno(0);
- if (db_realloc != NULL)
- p = db_realloc(ptr, size);
- else if (__db_jump.j_realloc != NULL)
- p = __db_jump.j_realloc(ptr, size);
+ if (DB_GLOBAL(j_realloc) != NULL)
+ p = DB_GLOBAL(j_realloc)(ptr, size);
else
p = realloc(ptr, size);
if (p == NULL) {
+ /*
+ * Some C libraries don't correctly set errno when malloc(3)
+ * fails. We'd like to 0 out errno before calling malloc,
+ * but it turns out that setting errno is quite expensive on
+ * Windows/NT in an MT environment.
+ */
if ((ret = __os_get_errno()) == 0) {
ret = ENOMEM;
__os_set_errno(ENOMEM);
@@ -212,6 +357,9 @@ __os_realloc(dbenv, size, db_realloc, storep)
}
#ifdef DIAGNOSTIC
((u_int8_t *)p)[size - 1] = CLEAR_BYTE; /* Initialize guard byte. */
+
+ ((union __db_alloc *)p)->size = size;
+ p = &((union __db_alloc *)p)[1];
#endif
*(void **)storep = p;
@@ -223,64 +371,35 @@ __os_realloc(dbenv, size, db_realloc, storep)
* __os_free --
* The free(3) function for DB.
*
- * PUBLIC: void __os_free __P((void *, size_t));
- */
-void
-__os_free(ptr, size)
- void *ptr;
- size_t size;
-{
-#ifdef DIAGNOSTIC
- if (size != 0) {
- /*
- * Check that the guard byte (one past the end of the memory) is
- * still CLEAR_BYTE.
- */
- if (((u_int8_t *)ptr)[size] != CLEAR_BYTE)
- __os_guard();
-
- /* Clear memory. */
- if (size != 0)
- memset(ptr, CLEAR_BYTE, size);
- }
-#else
- COMPQUIET(size, 0);
-#endif
-
- if (__db_jump.j_free != NULL)
- __db_jump.j_free(ptr);
- else
- free(ptr);
-}
-
-/*
- * __os_freestr --
- * The free(3) function for DB, freeing a string.
- *
- * PUBLIC: void __os_freestr __P((void *));
+ * PUBLIC: void __os_free __P((DB_ENV *, void *));
*/
void
-__os_freestr(ptr)
+__os_free(dbenv, ptr)
+ DB_ENV *dbenv;
void *ptr;
{
#ifdef DIAGNOSTIC
- size_t size;
-
- size = strlen(ptr) + 1;
-
+ int size;
/*
* Check that the guard byte (one past the end of the memory) is
* still CLEAR_BYTE.
*/
- if (((u_int8_t *)ptr)[size] != CLEAR_BYTE)
- __os_guard();
+ if (ptr == NULL)
+ return;
+
+ ptr = &((union __db_alloc *)ptr)[-1];
+ size = ((union __db_alloc *)ptr)->size;
+ if (((u_int8_t *)ptr)[size - 1] != CLEAR_BYTE)
+ __os_guard(dbenv);
/* Clear memory. */
- memset(ptr, CLEAR_BYTE, size);
+ if (size != 0)
+ memset(ptr, CLEAR_BYTE, size);
#endif
+ COMPQUIET(dbenv, NULL);
- if (__db_jump.j_free != NULL)
- __db_jump.j_free(ptr);
+ if (DB_GLOBAL(j_free) != NULL)
+ DB_GLOBAL(j_free)(ptr);
else
free(ptr);
}
@@ -291,13 +410,10 @@ __os_freestr(ptr)
* Complain and abort.
*/
static void
-__os_guard()
+__os_guard(dbenv)
+ DB_ENV *dbenv;
{
- /*
- * Eventually, once we push a DB_ENV handle down to these
- * routines, we should use the standard output channels.
- */
- fprintf(stderr, "Guard byte incorrect during free.\n");
+ __db_err(dbenv, "Guard byte incorrect during free");
abort();
/* NOTREACHED */
}
diff --git a/bdb/os/os_clock.c b/bdb/os/os_clock.c
new file mode 100644
index 00000000000..8da02cf6f9c
--- /dev/null
+++ b/bdb/os/os_clock.c
@@ -0,0 +1,92 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 2001-2002
+ * Sleepycat Software. All rights reserved.
+ */
+
+#include "db_config.h"
+
+#ifndef lint
+static const char revid[] = "$Id: os_clock.c,v 1.9 2002/03/29 20:46:44 bostic Exp $";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+
+#if TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#else
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif /* HAVE_SYS_TIME_H */
+#endif /* TIME_WITH SYS_TIME */
+
+#include <string.h>
+#endif
+
+#include "db_int.h"
+
+/*
+ * __os_clock --
+ * Return the current time-of-day clock in seconds and microseconds.
+ *
+ * PUBLIC: int __os_clock __P((DB_ENV *, u_int32_t *, u_int32_t *));
+ */
+int
+__os_clock(dbenv, secsp, usecsp)
+ DB_ENV *dbenv;
+ u_int32_t *secsp, *usecsp; /* Seconds and microseconds. */
+{
+#if defined(HAVE_GETTIMEOFDAY)
+ struct timeval tp;
+ int ret;
+
+retry: if (gettimeofday(&tp, NULL) != 0) {
+ if ((ret = __os_get_errno()) == EINTR)
+ goto retry;
+ __db_err(dbenv, "gettimeofday: %s", strerror(ret));
+ return (ret);
+ }
+
+ if (secsp != NULL)
+ *secsp = tp.tv_sec;
+ if (usecsp != NULL)
+ *usecsp = tp.tv_usec;
+#endif
+#if !defined(HAVE_GETTIMEOFDAY) && defined(HAVE_CLOCK_GETTIME)
+ struct timespec tp;
+ int ret;
+
+retry: if (clock_gettime(CLOCK_REALTIME, &tp) != 0) {
+ if ((ret = __os_get_errno()) == EINTR)
+ goto retry;
+ __db_err(dbenv, "clock_gettime: %s", strerror(ret));
+ return (ret);
+ }
+
+ if (secsp != NULL)
+ *secsp = tp.tv_sec;
+ if (usecsp != NULL)
+ *usecsp = tp.tv_nsec / 1000;
+#endif
+#if !defined(HAVE_GETTIMEOFDAY) && !defined(HAVE_CLOCK_GETTIME)
+ time_t now;
+ int ret;
+
+ if (time(&now) == (time_t)-1) {
+ ret = __os_get_errno();
+ __db_err(dbenv, "time: %s", strerror(ret));
+ return (ret);
+ }
+
+ if (secsp != NULL)
+ *secsp = now;
+ if (usecsp != NULL)
+ *usecsp = 0;
+#endif
+ return (0);
+}
diff --git a/bdb/os/os_config.c b/bdb/os/os_config.c
new file mode 100644
index 00000000000..b64952a8302
--- /dev/null
+++ b/bdb/os/os_config.c
@@ -0,0 +1,31 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1998-2002
+ * Sleepycat Software. All rights reserved.
+ */
+
+#include "db_config.h"
+
+#ifndef lint
+static const char revid[] = "$Id: os_config.c,v 11.13 2002/01/31 19:54:12 bostic Exp $";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+#endif
+
+#include "db_int.h"
+
+/*
+ * __os_fs_notzero --
+ * Return 1 if allocated filesystem blocks are not zeroed.
+ *
+ * PUBLIC: int __os_fs_notzero __P((void));
+ */
+int
+__os_fs_notzero()
+{
+ /* Most filesystems zero out implicitly created pages. */
+ return (0);
+}
diff --git a/bdb/os/os_dir.c b/bdb/os/os_dir.c
index 50d00a5562f..3f59a23d963 100644
--- a/bdb/os/os_dir.c
+++ b/bdb/os/os_dir.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_dir.c,v 11.8 2000/06/27 17:29:52 sue Exp $";
+static const char revid[] = "$Id: os_dir.c,v 11.14 2002/07/12 18:56:50 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -34,7 +34,6 @@ static const char revid[] = "$Id: os_dir.c,v 11.8 2000/06/27 17:29:52 sue Exp $"
#endif
#include "db_int.h"
-#include "os_jump.h"
/*
* __os_dirlist --
@@ -54,8 +53,8 @@ __os_dirlist(dbenv, dir, namesp, cntp)
int arraysz, cnt, ret;
char **names;
- if (__db_jump.j_dirlist != NULL)
- return (__db_jump.j_dirlist(dir, namesp, cntp));
+ if (DB_GLOBAL(j_dirlist) != NULL)
+ return (DB_GLOBAL(j_dirlist)(dir, namesp, cntp));
#ifdef HAVE_VXWORKS
if ((dirp = opendir((char *)dir)) == NULL)
@@ -68,7 +67,7 @@ __os_dirlist(dbenv, dir, namesp, cntp)
if (cnt >= arraysz) {
arraysz += 100;
if ((ret = __os_realloc(dbenv,
- arraysz * sizeof(names[0]), NULL, &names)) != 0)
+ arraysz * sizeof(names[0]), &names)) != 0)
goto nomem;
}
if ((ret = __os_strdup(dbenv, dp->d_name, &names[cnt])) != 0)
@@ -81,7 +80,7 @@ __os_dirlist(dbenv, dir, namesp, cntp)
return (0);
nomem: if (names != NULL)
- __os_dirfree(names, cnt);
+ __os_dirfree(dbenv, names, cnt);
if (dirp != NULL)
(void)closedir(dirp);
return (ret);
@@ -91,18 +90,19 @@ nomem: if (names != NULL)
* __os_dirfree --
* Free the list of files.
*
- * PUBLIC: void __os_dirfree __P((char **, int));
+ * PUBLIC: void __os_dirfree __P((DB_ENV *, char **, int));
*/
void
-__os_dirfree(names, cnt)
+__os_dirfree(dbenv, names, cnt)
+ DB_ENV *dbenv;
char **names;
int cnt;
{
- if (__db_jump.j_dirfree != NULL)
- __db_jump.j_dirfree(names, cnt);
+ if (DB_GLOBAL(j_dirfree) != NULL)
+ DB_GLOBAL(j_dirfree)(names, cnt);
else {
while (cnt > 0)
- __os_free(names[--cnt], 0);
- __os_free(names, 0);
+ __os_free(dbenv, names[--cnt]);
+ __os_free(dbenv, names);
}
}
diff --git a/bdb/os/os_errno.c b/bdb/os/os_errno.c
index f9b60f6354e..4b40f88d177 100644
--- a/bdb/os/os_errno.c
+++ b/bdb/os/os_errno.c
@@ -1,32 +1,52 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999, 2000
+ * Copyright (c) 1999-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_errno.c,v 11.3 2000/02/14 03:00:05 bostic Exp $";
+static const char revid[] = "$Id: os_errno.c,v 11.8 2002/01/11 15:52:59 bostic Exp $";
#endif /* not lint */
-#ifndef NO_SYSTEM_INCLUDES
-#include <errno.h>
-#endif
-
#include "db_int.h"
/*
+ * __os_get_errno_ret_zero --
+ * Return the value of errno, even if it's zero.
+ *
+ * PUBLIC: int __os_get_errno_ret_zero __P((void));
+ */
+int
+__os_get_errno_ret_zero()
+{
+ /* This routine must be able to return the same value repeatedly. */
+ return (errno);
+}
+
+/*
* __os_get_errno --
- * Return the value of errno.
+ * Return the value of errno, or EAGAIN if errno is zero.
*
* PUBLIC: int __os_get_errno __P((void));
*/
int
__os_get_errno()
{
- /* This routine must be able to return the same value repeatedly. */
+ /*
+ * This routine must be able to return the same value repeatedly.
+ *
+ * We've seen cases where system calls failed but errno was never set.
+ * This version of __os_get_errno() sets errno to EAGAIN if it's not
+ * already set, to work around that problem. For obvious reasons, we
+ * can only call this function if we know an error has occurred, that
+ * is, we can't test errno for a non-zero value after this call.
+ */
+ if (errno == 0)
+ __os_set_errno(EAGAIN);
+
return (errno);
}
diff --git a/bdb/os/os_fid.c b/bdb/os/os_fid.c
index f853f6a8dba..125e6f0712c 100644
--- a/bdb/os/os_fid.c
+++ b/bdb/os/os_fid.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996, 1997, 1998, 1999, 2000
+ * Copyright (c) 1996-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_fid.c,v 11.7 2000/10/26 14:17:05 bostic Exp $";
+static const char revid[] = "$Id: os_fid.c,v 11.14 2002/08/26 14:37:38 margo Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -26,6 +26,7 @@ static const char revid[] = "$Id: os_fid.c,v 11.7 2000/10/26 14:17:05 bostic Exp
#endif
#endif
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#endif
@@ -37,7 +38,12 @@ static u_int32_t fid_serial = SERIAL_INIT;
/*
* __os_fileid --
- * Return a unique identifier for a file.
+ * Return a unique identifier for a file. The structure
+ * of a fileid is: ino(4) dev(4) time(4) pid(4) extra(4).
+ * For real files, which have a backing inode and device, the first
+ * 16 bytes are filled in and the extra bytes are left 0. For
+ * temporary files, the inode and device fields are left blank and
+ * the extra four bytes are filled in with a random value.
*
* PUBLIC: int __os_fileid __P((DB_ENV *, const char *, int, u_int8_t *));
*/
@@ -58,12 +64,14 @@ __os_fileid(dbenv, fname, unique_okay, fidp)
memset(fidp, 0, DB_FILE_ID_LEN);
/* On POSIX/UNIX, use a dev/inode pair. */
+retry:
#ifdef HAVE_VXWORKS
- if (stat((char *)fname, &sb)) {
+ if (stat((char *)fname, &sb) != 0) {
#else
- if (stat(fname, &sb)) {
+ if (stat(fname, &sb) != 0) {
#endif
- ret = __os_get_errno();
+ if ((ret = __os_get_errno()) == EINTR)
+ goto retry;
__db_err(dbenv, "%s: %s", fname, strerror(ret));
return (ret);
}
@@ -83,7 +91,7 @@ __os_fileid(dbenv, fname, unique_okay, fidp)
* interesting properties in base 2.
*/
if (fid_serial == SERIAL_INIT)
- fid_serial = (u_int32_t)getpid();
+ __os_id(&fid_serial);
else
fid_serial += 100000;
diff --git a/bdb/os/os_finit.c b/bdb/os/os_finit.c
deleted file mode 100644
index 23b606ecb2c..00000000000
--- a/bdb/os/os_finit.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*-
- * See the file LICENSE for redistribution information.
- *
- * Copyright (c) 1998, 1999, 2000
- * Sleepycat Software. All rights reserved.
- */
-
-#include "db_config.h"
-
-#ifndef lint
-static const char revid[] = "$Id: os_finit.c,v 11.8 2000/11/30 00:58:42 ubell Exp $";
-#endif /* not lint */
-
-#ifndef NO_SYSTEM_INCLUDES
-#include <sys/types.h>
-
-#include <string.h>
-#endif
-
-#include "db_int.h"
-
-/*
- * __os_finit --
- * Initialize a regular file, optionally zero-filling it as well.
- *
- * PUBLIC: int __os_finit __P((DB_ENV *, DB_FH *, size_t, int));
- */
-int
-__os_finit(dbenv, fhp, size, zerofill)
- DB_ENV *dbenv;
- DB_FH *fhp;
- size_t size;
- int zerofill;
-{
- db_pgno_t pages;
- size_t i;
- size_t nw;
- u_int32_t relative;
- int ret;
- char buf[OS_VMPAGESIZE];
-
- /* Write nuls to the new bytes. */
- memset(buf, 0, sizeof(buf));
-
- /*
- * Extend the region by writing the last page. If the region is >4Gb,
- * increment may be larger than the maximum possible seek "relative"
- * argument, as it's an unsigned 32-bit value. Break the offset into
- * pages of 1MB each so that we don't overflow (2^20 + 2^32 is bigger
- * than any memory I expect to see for awhile).
- */
- if ((ret = __os_seek(dbenv, fhp, 0, 0, 0, 0, DB_OS_SEEK_END)) != 0)
- return (ret);
- pages = (size - OS_VMPAGESIZE) / MEGABYTE;
- relative = (size - OS_VMPAGESIZE) % MEGABYTE;
- if ((ret = __os_seek(dbenv,
- fhp, MEGABYTE, pages, relative, 0, DB_OS_SEEK_CUR)) != 0)
- return (ret);
- if ((ret = __os_write(dbenv, fhp, buf, sizeof(buf), &nw)) != 0)
- return (ret);
- if (nw != sizeof(buf))
- return (EIO);
-
- /*
- * We may want to guarantee that there is enough disk space for the
- * file, so we also write a byte to each page. We write the byte
- * because reading it is insufficient on systems smart enough not to
- * instantiate disk pages to satisfy a read (e.g., Solaris).
- */
- if (zerofill) {
- pages = size / MEGABYTE;
- relative = size % MEGABYTE;
- if ((ret = __os_seek(dbenv, fhp,
- MEGABYTE, pages, relative, 1, DB_OS_SEEK_END)) != 0)
- return (ret);
-
- /* Write a byte to each page. */
- for (i = 0; i < size; i += OS_VMPAGESIZE) {
- if ((ret = __os_write(dbenv, fhp, buf, 1, &nw)) != 0)
- return (ret);
- if (nw != 1)
- return (EIO);
- if ((ret = __os_seek(dbenv, fhp,
- 0, 0, OS_VMPAGESIZE - 1, 0, DB_OS_SEEK_CUR)) != 0)
- return (ret);
- }
- }
- return (0);
-}
-
-/*
- * __os_fpinit --
- * Initialize a page in a regular file.
- *
- * PUBLIC: int __os_fpinit __P((DB_ENV *, DB_FH *, db_pgno_t, int, int));
- */
-int
-__os_fpinit(dbenv, fhp, pgno, pagecount, pagesize)
- DB_ENV *dbenv;
- DB_FH *fhp;
- db_pgno_t pgno;
- int pagecount, pagesize;
-{
- COMPQUIET(dbenv, NULL);
- COMPQUIET(fhp, NULL);
- COMPQUIET(pgno, 0);
- COMPQUIET(pagecount, 0);
- COMPQUIET(pagesize, 0);
-
- return (0);
-}
diff --git a/bdb/os/os_fsync.c b/bdb/os/os_fsync.c
index f5fd5f56abd..46ab4885a16 100644
--- a/bdb/os/os_fsync.c
+++ b/bdb/os/os_fsync.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_fsync.c,v 11.9 2000/04/04 23:29:20 ubell Exp $";
+static const char revid[] = "$Id: os_fsync.c,v 11.14 2002/07/12 18:56:50 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -20,7 +20,6 @@ static const char revid[] = "$Id: os_fsync.c,v 11.9 2000/04/04 23:29:20 ubell Ex
#endif
#include "db_int.h"
-#include "os_jump.h"
#ifdef HAVE_VXWORKS
#include "ioLib.h"
@@ -79,12 +78,12 @@ __os_fsync(dbenv, fhp)
if (F_ISSET(fhp, DB_FH_NOSYNC))
return (0);
- ret = __db_jump.j_fsync != NULL ?
- __db_jump.j_fsync(fhp->fd) : fsync(fhp->fd);
+ do {
+ ret = DB_GLOBAL(j_fsync) != NULL ?
+ DB_GLOBAL(j_fsync)(fhp->fd) : fsync(fhp->fd);
+ } while (ret != 0 && (ret = __os_get_errno()) == EINTR);
- if (ret != 0) {
- ret = __os_get_errno();
+ if (ret != 0)
__db_err(dbenv, "fsync %s", strerror(ret));
- }
return (ret);
}
diff --git a/bdb/os/os_handle.c b/bdb/os/os_handle.c
index b127c5ff506..19a337f7d22 100644
--- a/bdb/os/os_handle.c
+++ b/bdb/os/os_handle.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1998, 1999, 2000
+ * Copyright (c) 1998-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_handle.c,v 11.19 2000/11/30 00:58:42 ubell Exp $";
+static const char revid[] = "$Id: os_handle.c,v 11.28 2002/07/12 18:56:50 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -20,7 +20,6 @@ static const char revid[] = "$Id: os_handle.c,v 11.19 2000/11/30 00:58:42 ubell
#endif
#include "db_int.h"
-#include "os_jump.h"
/*
* __os_openhandle --
@@ -43,29 +42,32 @@ __os_openhandle(dbenv, name, flags, mode, fhp)
memset(fhp, 0, sizeof(*fhp));
/* If the application specified an interface, use it. */
- if (__db_jump.j_open != NULL) {
- if ((fhp->fd = __db_jump.j_open(name, flags, mode)) == -1)
+ if (DB_GLOBAL(j_open) != NULL) {
+ if ((fhp->fd = DB_GLOBAL(j_open)(name, flags, mode)) == -1)
return (__os_get_errno());
F_SET(fhp, DB_FH_VALID);
return (0);
}
- for (ret = 0, nrepeat = 1; nrepeat < 4; ++nrepeat) {
+ for (nrepeat = 1; nrepeat < 4; ++nrepeat) {
+ ret = 0;
#ifdef HAVE_VXWORKS
/*
* VxWorks does not support O_CREAT on open, you have to use
* creat() instead. (It does not support O_EXCL or O_TRUNC
* either, even though they are defined "for future support".)
- * If O_EXCL is specified, single thread and try to open the
- * file. If successful, return EEXIST. Otherwise, call creat
- * and then end single threading.
+ * We really want the POSIX behavior that if O_CREAT is set,
+ * we open if it exists, or create it if it doesn't exist.
+ * If O_CREAT is specified, single thread and try to open the
+ * file. If successful, and O_EXCL return EEXIST. If
+ * unsuccessful call creat and then end single threading.
*/
if (LF_ISSET(O_CREAT)) {
DB_BEGIN_SINGLE_THREAD;
newflags = flags & ~(O_CREAT | O_EXCL);
- if (LF_ISSET(O_EXCL)) {
- if ((fhp->fd =
- open(name, newflags, mode)) != -1) {
+ if ((fhp->fd =
+ open(name, newflags, mode)) != -1) {
+ if (LF_ISSET(O_EXCL)) {
/*
* If we get here, we want O_EXCL
* create, and it exists. Close and
@@ -84,8 +86,8 @@ __os_openhandle(dbenv, name, flags, mode, fhp)
* verify we truly got the equivalent of
* ENOENT.
*/
- }
- fhp->fd = creat(name, newflags);
+ } else
+ fhp->fd = creat(name, newflags);
DB_END_SINGLE_THREAD;
} else
@@ -118,6 +120,15 @@ __os_openhandle(dbenv, name, flags, mode, fhp)
(void)__os_sleep(dbenv, nrepeat * 2, 0);
continue;
}
+
+ /*
+ * If it was an EINTR it's reasonable to retry
+ * immediately, and arbitrarily often.
+ */
+ if (ret == EINTR) {
+ --nrepeat;
+ continue;
+ }
} else {
#if defined(HAVE_FCNTL_F_SETFD)
/* Deny file descriptor access to any child process. */
@@ -125,7 +136,7 @@ __os_openhandle(dbenv, name, flags, mode, fhp)
ret = __os_get_errno();
__db_err(dbenv, "fcntl(F_SETFD): %s",
strerror(ret));
- (void)__os_closehandle(fhp);
+ (void)__os_closehandle(dbenv, fhp);
} else
#endif
F_SET(fhp, DB_FH_VALID);
@@ -140,10 +151,11 @@ __os_openhandle(dbenv, name, flags, mode, fhp)
* __os_closehandle --
* Close a file.
*
- * PUBLIC: int __os_closehandle __P((DB_FH *));
+ * PUBLIC: int __os_closehandle __P((DB_ENV *, DB_FH *));
*/
int
-__os_closehandle(fhp)
+__os_closehandle(dbenv, fhp)
+ DB_ENV *dbenv;
DB_FH *fhp;
{
int ret;
@@ -151,8 +163,16 @@ __os_closehandle(fhp)
/* Don't close file descriptors that were never opened. */
DB_ASSERT(F_ISSET(fhp, DB_FH_VALID) && fhp->fd != -1);
- ret = __db_jump.j_close != NULL ?
- __db_jump.j_close(fhp->fd) : close(fhp->fd);
+ do {
+ ret = DB_GLOBAL(j_close) != NULL ?
+ DB_GLOBAL(j_close)(fhp->fd) : close(fhp->fd);
+ } while (ret != 0 && (ret = __os_get_errno()) == EINTR);
+
+ /* Unlink the file if we haven't already done so. */
+ if (F_ISSET(fhp, DB_FH_UNLINK)) {
+ (void)__os_unlink(dbenv, fhp->name);
+ (void)__os_free(dbenv, fhp->name);
+ }
/*
* Smash the POSIX file descriptor -- it's never tested, but we want
@@ -161,5 +181,5 @@ __os_closehandle(fhp)
fhp->fd = -1;
F_CLR(fhp, DB_FH_VALID);
- return (ret == 0 ? 0 : __os_get_errno());
+ return (ret);
}
diff --git a/bdb/os/os_id.c b/bdb/os/os_id.c
new file mode 100644
index 00000000000..c242bb12e23
--- /dev/null
+++ b/bdb/os/os_id.c
@@ -0,0 +1,47 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 2001-2002
+ * Sleepycat Software. All rights reserved.
+ */
+
+#include "db_config.h"
+
+#ifndef lint
+static const char revid[] = "$Id: os_id.c,v 1.2 2002/01/11 15:52:59 bostic Exp $";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+
+#include <unistd.h>
+#endif
+
+#include "db_int.h"
+
+/*
+ * __os_id --
+ * Return a 32-bit value identifying the current thread of control.
+ *
+ * PUBLIC: void __os_id __P((u_int32_t *));
+ */
+void
+__os_id(idp)
+ u_int32_t *idp;
+{
+ /*
+ * By default, use the process ID.
+ *
+ * getpid() returns a pid_t which we convert to a u_int32_t. I have
+ * not yet seen a system where a pid_t has 64-bits, but I'm sure they
+ * exist. Since we're returning only the bottom 32-bits, you cannot
+ * use the return of __os_id to reference a process (for example, you
+ * cannot send a signal to the value returned by __os_id). To send a
+ * signal to the current process, use raise(3) instead.
+ */
+#ifdef HAVE_VXWORKS
+ *idp = taskIdSelf();
+#else
+ *idp = getpid();
+#endif
+}
diff --git a/bdb/os/os_map.c b/bdb/os/os_map.c
index bb96a917d87..6d385b6a84d 100644
--- a/bdb/os/os_map.c
+++ b/bdb/os/os_map.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996, 1997, 1998, 1999, 2000
+ * Copyright (c) 1996-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_map.c,v 11.32 2000/11/30 00:58:42 ubell Exp $";
+static const char revid[] = "$Id: os_map.c,v 11.44 2002/07/12 18:56:51 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -26,9 +26,6 @@ static const char revid[] = "$Id: os_map.c,v 11.32 2000/11/30 00:58:42 ubell Exp
#endif
#include "db_int.h"
-#include "db_page.h"
-#include "db_ext.h"
-#include "os_jump.h"
#ifdef HAVE_MMAP
static int __os_map __P((DB_ENV *, char *, DB_FH *, size_t, int, int, void **));
@@ -143,12 +140,13 @@ __os_r_sysattach(dbenv, infop, rp)
int ret;
/*
- * Try to open/create the shared region file. We DO NOT need to
- * ensure that multiple threads/processes attempting to
- * simultaneously create the region are properly ordered,
- * our caller has already taken care of that.
+ * Try to open/create the shared region file. We DO NOT need to ensure
+ * that multiple threads/processes attempting to simultaneously create
+ * the region are properly ordered, our caller has already taken care
+ * of that.
*/
- if ((ret = __os_open(dbenv, infop->name, DB_OSO_REGION |
+ if ((ret = __os_open(dbenv, infop->name,
+ DB_OSO_REGION | DB_OSO_DIRECT |
(F_ISSET(infop, REGION_CREATE_OK) ? DB_OSO_CREATE : 0),
infop->mode, &fh)) != 0)
__db_err(dbenv, "%s: %s", infop->name, db_strerror(ret));
@@ -161,15 +159,16 @@ __os_r_sysattach(dbenv, infop, rp)
* point, *badly* merged VM/buffer cache systems.
*/
if (ret == 0 && F_ISSET(infop, REGION_CREATE))
- ret = __os_finit(dbenv,
- &fh, rp->size, DB_GLOBAL(db_region_init));
+ ret = __db_fileinit(dbenv,
+ &fh, rp->size, F_ISSET(dbenv, DB_ENV_REGION_INIT) ? 1 : 0);
/* Map the file in. */
if (ret == 0)
ret = __os_map(dbenv,
infop->name, &fh, rp->size, 1, 0, &infop->addr);
- (void)__os_closehandle(&fh);
+ if (F_ISSET(&fh, DB_FH_VALID))
+ (void)__os_closehandle(dbenv, &fh);
return (ret);
}
@@ -295,17 +294,25 @@ __os_unmapfile(dbenv, addr, len)
size_t len;
{
/* If the user replaced the map call, call through their interface. */
- if (__db_jump.j_unmap != NULL)
- return (__db_jump.j_unmap(addr, len));
+ if (DB_GLOBAL(j_unmap) != NULL)
+ return (DB_GLOBAL(j_unmap)(addr, len));
#ifdef HAVE_MMAP
#ifdef HAVE_MUNLOCK
if (F_ISSET(dbenv, DB_ENV_LOCKDOWN))
- (void)munlock(addr, len);
+ while (munlock(addr, len) != 0 && __os_get_errno() == EINTR)
+ ;
#else
COMPQUIET(dbenv, NULL);
#endif
- return (munmap(addr, len) ? __os_get_errno() : 0);
+ {
+ int ret;
+
+ while ((ret = munmap(addr, len)) != 0 &&
+ __os_get_errno() == EINTR)
+ ;
+ return (ret ? __os_get_errno() : 0);
+ }
#else
COMPQUIET(dbenv, NULL);
@@ -331,8 +338,8 @@ __os_map(dbenv, path, fhp, len, is_region, is_rdonly, addrp)
int flags, prot, ret;
/* If the user replaced the map call, call through their interface. */
- if (__db_jump.j_map != NULL)
- return (__db_jump.j_map
+ if (DB_GLOBAL(j_map) != NULL)
+ return (DB_GLOBAL(j_map)
(path, len, is_region, is_rdonly, addrp));
/*
diff --git a/bdb/os/os_method.c b/bdb/os/os_method.c
index 0e2bd394792..04367654efa 100644
--- a/bdb/os/os_method.c
+++ b/bdb/os/os_method.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999, 2000
+ * Copyright (c) 1999-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_method.c,v 11.6 2000/11/15 19:25:39 sue Exp $";
+static const char revid[] = "$Id: os_method.c,v 11.15 2002/07/12 18:56:51 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -16,191 +16,219 @@ static const char revid[] = "$Id: os_method.c,v 11.6 2000/11/15 19:25:39 sue Exp
#endif
#include "db_int.h"
-#include "os_jump.h"
-
-struct __db_jumptab __db_jump;
+/*
+ * EXTERN: int db_env_set_func_close __P((int (*)(int)));
+ */
int
db_env_set_func_close(func_close)
int (*func_close) __P((int));
{
- __db_jump.j_close = func_close;
+ DB_GLOBAL(j_close) = func_close;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_dirfree __P((void (*)(char **, int)));
+ */
int
db_env_set_func_dirfree(func_dirfree)
void (*func_dirfree) __P((char **, int));
{
- __db_jump.j_dirfree = func_dirfree;
+ DB_GLOBAL(j_dirfree) = func_dirfree;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_dirlist
+ * EXTERN: __P((int (*)(const char *, char ***, int *)));
+ */
int
db_env_set_func_dirlist(func_dirlist)
int (*func_dirlist) __P((const char *, char ***, int *));
{
- __db_jump.j_dirlist = func_dirlist;
+ DB_GLOBAL(j_dirlist) = func_dirlist;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_exists __P((int (*)(const char *, int *)));
+ */
int
db_env_set_func_exists(func_exists)
int (*func_exists) __P((const char *, int *));
{
- __db_jump.j_exists = func_exists;
+ DB_GLOBAL(j_exists) = func_exists;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_free __P((void (*)(void *)));
+ */
int
db_env_set_func_free(func_free)
void (*func_free) __P((void *));
{
- __db_jump.j_free = func_free;
+ DB_GLOBAL(j_free) = func_free;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_fsync __P((int (*)(int)));
+ */
int
db_env_set_func_fsync(func_fsync)
int (*func_fsync) __P((int));
{
- __db_jump.j_fsync = func_fsync;
+ DB_GLOBAL(j_fsync) = func_fsync;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_ioinfo __P((int (*)(const char *,
+ * EXTERN: int, u_int32_t *, u_int32_t *, u_int32_t *)));
+ */
int
db_env_set_func_ioinfo(func_ioinfo)
int (*func_ioinfo)
__P((const char *, int, u_int32_t *, u_int32_t *, u_int32_t *));
{
- __db_jump.j_ioinfo = func_ioinfo;
+ DB_GLOBAL(j_ioinfo) = func_ioinfo;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_malloc __P((void *(*)(size_t)));
+ */
int
db_env_set_func_malloc(func_malloc)
void *(*func_malloc) __P((size_t));
{
- __db_jump.j_malloc = func_malloc;
+ DB_GLOBAL(j_malloc) = func_malloc;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_map
+ * EXTERN: __P((int (*)(char *, size_t, int, int, void **)));
+ */
int
db_env_set_func_map(func_map)
int (*func_map) __P((char *, size_t, int, int, void **));
{
- __db_jump.j_map = func_map;
+ DB_GLOBAL(j_map) = func_map;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_open __P((int (*)(const char *, int, ...)));
+ */
int
db_env_set_func_open(func_open)
int (*func_open) __P((const char *, int, ...));
{
- __db_jump.j_open = func_open;
+ DB_GLOBAL(j_open) = func_open;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_read __P((ssize_t (*)(int, void *, size_t)));
+ */
int
db_env_set_func_read(func_read)
ssize_t (*func_read) __P((int, void *, size_t));
{
- __db_jump.j_read = func_read;
+ DB_GLOBAL(j_read) = func_read;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_realloc __P((void *(*)(void *, size_t)));
+ */
int
db_env_set_func_realloc(func_realloc)
void *(*func_realloc) __P((void *, size_t));
{
- __db_jump.j_realloc = func_realloc;
+ DB_GLOBAL(j_realloc) = func_realloc;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_rename
+ * EXTERN: __P((int (*)(const char *, const char *)));
+ */
int
db_env_set_func_rename(func_rename)
int (*func_rename) __P((const char *, const char *));
{
- __db_jump.j_rename = func_rename;
+ DB_GLOBAL(j_rename) = func_rename;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_seek
+ * EXTERN: __P((int (*)(int, size_t, db_pgno_t, u_int32_t, int, int)));
+ */
int
db_env_set_func_seek(func_seek)
int (*func_seek) __P((int, size_t, db_pgno_t, u_int32_t, int, int));
{
- __db_jump.j_seek = func_seek;
+ DB_GLOBAL(j_seek) = func_seek;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_sleep __P((int (*)(u_long, u_long)));
+ */
int
db_env_set_func_sleep(func_sleep)
int (*func_sleep) __P((u_long, u_long));
{
- __db_jump.j_sleep = func_sleep;
+ DB_GLOBAL(j_sleep) = func_sleep;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_unlink __P((int (*)(const char *)));
+ */
int
db_env_set_func_unlink(func_unlink)
int (*func_unlink) __P((const char *));
{
- __db_jump.j_unlink = func_unlink;
+ DB_GLOBAL(j_unlink) = func_unlink;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_unmap __P((int (*)(void *, size_t)));
+ */
int
db_env_set_func_unmap(func_unmap)
int (*func_unmap) __P((void *, size_t));
{
- __db_jump.j_unmap = func_unmap;
+ DB_GLOBAL(j_unmap) = func_unmap;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_write
+ * EXTERN: __P((ssize_t (*)(int, const void *, size_t)));
+ */
int
db_env_set_func_write(func_write)
ssize_t (*func_write) __P((int, const void *, size_t));
{
- __db_jump.j_write = func_write;
+ DB_GLOBAL(j_write) = func_write;
return (0);
}
+/*
+ * EXTERN: int db_env_set_func_yield __P((int (*)(void)));
+ */
int
db_env_set_func_yield(func_yield)
int (*func_yield) __P((void));
{
- __db_jump.j_yield = func_yield;
- return (0);
-}
-
-int
-db_env_set_pageyield(onoff)
- int onoff;
-{
- DB_GLOBAL(db_pageyield) = onoff;
- return (0);
-}
-
-int
-db_env_set_panicstate(onoff)
- int onoff;
-{
- DB_GLOBAL(db_panic) = onoff;
- return (0);
-}
-
-int
-db_env_set_region_init(onoff)
- int onoff;
-{
- DB_GLOBAL(db_region_init) = onoff;
- return (0);
-}
-
-int
-db_env_set_tas_spins(tas_spins)
- u_int32_t tas_spins;
-{
- DB_GLOBAL(db_tas_spins) = tas_spins;
+ DB_GLOBAL(j_yield) = func_yield;
return (0);
}
diff --git a/bdb/os/os_oflags.c b/bdb/os/os_oflags.c
index fd413bdacbe..f75178de75e 100644
--- a/bdb/os/os_oflags.c
+++ b/bdb/os/os_oflags.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_oflags.c,v 11.6 2000/10/27 20:32:02 dda Exp $";
+static const char revid[] = "$Id: os_oflags.c,v 11.9 2002/01/11 15:53:00 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -72,23 +72,35 @@ __db_omode(perm)
{
int mode;
-#ifndef S_IRUSR
#ifdef DB_WIN32
+#ifndef S_IRUSR
#define S_IRUSR S_IREAD /* R for owner */
+#endif
+#ifndef S_IWUSR
#define S_IWUSR S_IWRITE /* W for owner */
+#endif
+#ifndef S_IRGRP
#define S_IRGRP 0 /* R for group */
+#endif
+#ifndef S_IWGRP
#define S_IWGRP 0 /* W for group */
+#endif
+#ifndef S_IROTH
#define S_IROTH 0 /* R for other */
+#endif
+#ifndef S_IWOTH
#define S_IWOTH 0 /* W for other */
+#endif
#else
+#ifndef S_IRUSR
#define S_IRUSR 0000400 /* R for owner */
#define S_IWUSR 0000200 /* W for owner */
#define S_IRGRP 0000040 /* R for group */
#define S_IWGRP 0000020 /* W for group */
#define S_IROTH 0000004 /* R for other */
#define S_IWOTH 0000002 /* W for other */
-#endif /* DB_WIN32 */
#endif
+#endif /* DB_WIN32 */
mode = 0;
if (perm[0] == 'r')
mode |= S_IRUSR;
diff --git a/bdb/os/os_open.c b/bdb/os/os_open.c
index cdc75cd737b..0a4dbadc6e8 100644
--- a/bdb/os/os_open.c
+++ b/bdb/os/os_open.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_open.c,v 11.21 2001/01/11 18:19:53 bostic Exp $";
+static const char revid[] = "$Id: os_open.c,v 11.37 2002/06/21 20:35:16 sandstro Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -42,6 +42,15 @@ __os_open(dbenv, name, flags, mode, fhp)
oflags = 0;
+#ifdef DIAGNOSTIC
+#define OKFLAGS \
+ (DB_OSO_CREATE | DB_OSO_DIRECT | DB_OSO_EXCL | DB_OSO_LOG | \
+ DB_OSO_RDONLY | DB_OSO_REGION | DB_OSO_SEQ | DB_OSO_TEMP | \
+ DB_OSO_TRUNC)
+ if ((ret = __db_fchk(dbenv, "__os_open", flags, OKFLAGS)) != 0)
+ return (ret);
+#endif
+
#if defined(O_BINARY)
/*
* If there's a binary-mode open flag, set it, we never want any
@@ -84,6 +93,11 @@ __os_open(dbenv, name, flags, mode, fhp)
if (LF_ISSET(DB_OSO_TRUNC))
oflags |= O_TRUNC;
+#ifdef HAVE_O_DIRECT
+ if (LF_ISSET(DB_OSO_DIRECT))
+ oflags |= O_DIRECT;
+#endif
+
#ifdef HAVE_QNX
if (LF_ISSET(DB_OSO_REGION))
return (__os_region_open(dbenv, name, oflags, mode, fhp));
@@ -92,6 +106,11 @@ __os_open(dbenv, name, flags, mode, fhp)
if ((ret = __os_openhandle(dbenv, name, oflags, mode, fhp)) != 0)
return (ret);
+#ifdef HAVE_DIRECTIO
+ if (LF_ISSET(DB_OSO_DIRECT))
+ (void)directio(fhp->fd, DIRECTIO_ON);
+#endif
+
/*
* Delete any temporary file.
*
@@ -102,8 +121,18 @@ __os_open(dbenv, name, flags, mode, fhp)
* reasonable way to avoid the race (playing signal games isn't worth
* the portability nightmare), so we just live with it.
*/
- if (LF_ISSET(DB_OSO_TEMP))
+ if (LF_ISSET(DB_OSO_TEMP)) {
+#if defined(HAVE_UNLINK_WITH_OPEN_FAILURE) || defined(CONFIG_TEST)
+ if ((ret = __os_strdup(dbenv, name, &fhp->name)) != 0) {
+ (void)__os_closehandle(dbenv, fhp);
+ (void)__os_unlink(dbenv, name);
+ return (ret);
+ }
+ F_SET(fhp, DB_FH_UNLINK);
+#else
(void)__os_unlink(dbenv, name);
+#endif
+ }
return (0);
}
@@ -136,7 +165,7 @@ __os_region_open(dbenv, name, oflags, mode, fhp)
if (fcntl(fhp->fd, F_SETFD, 1) == -1) {
ret = __os_get_errno();
__db_err(dbenv, "fcntl(F_SETFD): %s", strerror(ret));
- __os_closehandle(fhp);
+ __os_closehandle(dbenv, fhp);
} else
#endif
F_SET(fhp, DB_FH_VALID);
@@ -147,7 +176,7 @@ __os_region_open(dbenv, name, oflags, mode, fhp)
*/
err:
if (newname != NULL)
- __os_free(newname, 0);
+ __os_free(dbenv, newname);
return (ret);
}
@@ -155,7 +184,9 @@ err:
* __os_shmname --
* Translate a pathname into a shm_open memory object name.
*
+ * PUBLIC: #ifdef HAVE_QNX
* PUBLIC: int __os_shmname __P((DB_ENV *, const char *, char **));
+ * PUBLIC: #endif
*/
int
__os_shmname(dbenv, name, newnamep)
@@ -206,7 +237,7 @@ __os_shmname(dbenv, name, newnamep)
* If we have a path component, copy and return it.
*/
ret = __os_strdup(dbenv, p, newnamep);
- __os_free(tmpname, 0);
+ __os_free(dbenv, tmpname);
return (ret);
}
@@ -215,11 +246,11 @@ __os_shmname(dbenv, name, newnamep)
* Add a leading slash, and copy the remainder.
*/
size = strlen(tmpname) + 2;
- if ((ret = __os_malloc(dbenv, size, NULL, &p)) != 0)
+ if ((ret = __os_malloc(dbenv, size, &p)) != 0)
return (ret);
p[0] = '/';
memcpy(&p[1], tmpname, size-1);
- __os_free(tmpname, 0);
+ __os_free(dbenv, tmpname);
*newnamep = p;
return (0);
}
diff --git a/bdb/os/os_region.c b/bdb/os/os_region.c
index 1e36fc2cbe0..6529f708b2c 100644
--- a/bdb/os/os_region.c
+++ b/bdb/os/os_region.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996, 1997, 1998, 1999, 2000
+ * Copyright (c) 1996-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_region.c,v 11.9 2000/11/30 00:58:42 ubell Exp $";
+static const char revid[] = "$Id: os_region.c,v 11.15 2002/07/12 18:56:51 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -17,7 +17,6 @@ static const char revid[] = "$Id: os_region.c,v 11.9 2000/11/30 00:58:42 ubell E
#endif
#include "db_int.h"
-#include "os_jump.h"
/*
* __os_r_attach --
@@ -70,7 +69,7 @@ __os_r_attach(dbenv, infop, rp)
}
#endif
if ((ret =
- __os_malloc(dbenv, rp->size, NULL, &infop->addr)) != 0)
+ __os_malloc(dbenv, rp->size, &infop->addr)) != 0)
return (ret);
#if defined(UMRW) && !defined(DIAGNOSTIC)
memset(infop->addr, CLEAR_BYTE, rp->size);
@@ -79,8 +78,8 @@ __os_r_attach(dbenv, infop, rp)
}
/* If the user replaced the map call, call through their interface. */
- if (__db_jump.j_map != NULL)
- return (__db_jump.j_map(infop->name,
+ if (DB_GLOBAL(j_map) != NULL)
+ return (DB_GLOBAL(j_map)(infop->name,
rp->size, 1, 0, &infop->addr));
return (__os_r_sysattach(dbenv, infop, rp));
@@ -104,13 +103,13 @@ __os_r_detach(dbenv, infop, destroy)
/* If a region is private, free the memory. */
if (F_ISSET(dbenv, DB_ENV_PRIVATE)) {
- __os_free(infop->addr, rp->size);
+ __os_free(dbenv, infop->addr);
return (0);
}
/* If the user replaced the map call, call through their interface. */
- if (__db_jump.j_unmap != NULL)
- return (__db_jump.j_unmap(infop->addr, rp->size));
+ if (DB_GLOBAL(j_unmap) != NULL)
+ return (DB_GLOBAL(j_unmap)(infop->addr, rp->size));
return (__os_r_sysdetach(dbenv, infop, destroy));
}
diff --git a/bdb/os/os_rename.c b/bdb/os/os_rename.c
index 8108bba67d9..2569a9c3186 100644
--- a/bdb/os/os_rename.c
+++ b/bdb/os/os_rename.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_rename.c,v 11.6 2000/04/14 16:56:33 ubell Exp $";
+static const char revid[] = "$Id: os_rename.c,v 11.12 2002/07/12 18:56:52 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -19,28 +19,29 @@ static const char revid[] = "$Id: os_rename.c,v 11.6 2000/04/14 16:56:33 ubell E
#endif
#include "db_int.h"
-#include "os_jump.h"
/*
* __os_rename --
- * Rename a file.
+ * Rename a file. If flags is non-zero, then errors are OK and we
+ * should not output an error message.
*
- * PUBLIC: int __os_rename __P((DB_ENV *, const char *, const char *));
+ * PUBLIC: int __os_rename __P((DB_ENV *,
+ * PUBLIC: const char *, const char *, u_int32_t));
*/
int
-__os_rename(dbenv, old, new)
+__os_rename(dbenv, old, new, flags)
DB_ENV *dbenv;
const char *old, *new;
+ u_int32_t flags;
{
int ret;
- ret = __db_jump.j_rename != NULL ?
- __db_jump.j_rename(old, new) : rename(old, new);
-
- if (ret == -1) {
- ret = __os_get_errno();
- __db_err(dbenv, "Rename %s %s: %s", old, new, strerror(ret));
- }
+ do {
+ ret = DB_GLOBAL(j_rename) != NULL ?
+ DB_GLOBAL(j_rename)(old, new) : rename(old, new);
+ } while (ret != 0 && (ret = __os_get_errno()) == EINTR);
+ if (ret != 0 && flags == 0)
+ __db_err(dbenv, "rename %s %s: %s", old, new, strerror(ret));
return (ret);
}
diff --git a/bdb/os/os_root.c b/bdb/os/os_root.c
index 753285c1be6..cd5bfc352e9 100644
--- a/bdb/os/os_root.c
+++ b/bdb/os/os_root.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999, 2000
+ * Copyright (c) 1999-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_root.c,v 11.4 2000/02/14 03:00:05 bostic Exp $";
+static const char revid[] = "$Id: os_root.c,v 11.6 2002/01/11 15:53:01 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
diff --git a/bdb/os/os_rpath.c b/bdb/os/os_rpath.c
index 75d394ef210..b9ccba01bd5 100644
--- a/bdb/os/os_rpath.c
+++ b/bdb/os/os_rpath.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_rpath.c,v 11.5 2000/06/30 13:40:30 sue Exp $";
+static const char revid[] = "$Id: os_rpath.c,v 11.7 2002/01/11 15:53:01 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
diff --git a/bdb/os/os_rw.c b/bdb/os/os_rw.c
index 7e8e1255d6b..9a79342c7b8 100644
--- a/bdb/os/os_rw.c
+++ b/bdb/os/os_rw.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_rw.c,v 11.15 2000/11/15 19:25:39 sue Exp $";
+static const char revid[] = "$Id: os_rw.c,v 11.24 2002/07/12 18:56:52 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -19,7 +19,6 @@ static const char revid[] = "$Id: os_rw.c,v 11.15 2000/11/15 19:25:39 sue Exp $"
#endif
#include "db_int.h"
-#include "os_jump.h"
/*
* __os_io --
@@ -39,13 +38,13 @@ __os_io(dbenv, db_iop, op, niop)
#if defined(HAVE_PREAD) && defined(HAVE_PWRITE)
switch (op) {
case DB_IO_READ:
- if (__db_jump.j_read != NULL)
+ if (DB_GLOBAL(j_read) != NULL)
goto slow;
*niop = pread(db_iop->fhp->fd, db_iop->buf,
db_iop->bytes, (off_t)db_iop->pgno * db_iop->pagesize);
break;
case DB_IO_WRITE:
- if (__db_jump.j_write != NULL)
+ if (DB_GLOBAL(j_write) != NULL)
goto slow;
*niop = pwrite(db_iop->fhp->fd, db_iop->buf,
db_iop->bytes, (off_t)db_iop->pgno * db_iop->pagesize);
@@ -98,10 +97,11 @@ __os_read(dbenv, fhp, addr, len, nrp)
for (taddr = addr,
offset = 0; offset < len; taddr += nr, offset += nr) {
- if ((nr = __db_jump.j_read != NULL ?
- __db_jump.j_read(fhp->fd, taddr, len - offset) :
+retry: if ((nr = DB_GLOBAL(j_read) != NULL ?
+ DB_GLOBAL(j_read)(fhp->fd, taddr, len - offset) :
read(fhp->fd, taddr, len - offset)) < 0) {
- ret = __os_get_errno();
+ if ((ret = __os_get_errno()) == EINTR)
+ goto retry;
__db_err(dbenv, "read: 0x%x, %lu: %s", taddr,
(u_long)len-offset, strerror(ret));
return (ret);
@@ -134,10 +134,11 @@ __os_write(dbenv, fhp, addr, len, nwp)
for (taddr = addr,
offset = 0; offset < len; taddr += nw, offset += nw)
- if ((nw = __db_jump.j_write != NULL ?
- __db_jump.j_write(fhp->fd, taddr, len - offset) :
+retry: if ((nw = DB_GLOBAL(j_write) != NULL ?
+ DB_GLOBAL(j_write)(fhp->fd, taddr, len - offset) :
write(fhp->fd, taddr, len - offset)) < 0) {
- ret = __os_get_errno();
+ if ((ret = __os_get_errno()) == EINTR)
+ goto retry;
__db_err(dbenv, "write: 0x%x, %lu: %s", taddr,
(u_long)len-offset, strerror(ret));
return (ret);
diff --git a/bdb/os/os_seek.c b/bdb/os/os_seek.c
index 1c4dc2238e1..5b2aa45d5dd 100644
--- a/bdb/os/os_seek.c
+++ b/bdb/os/os_seek.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_seek.c,v 11.12 2000/11/30 00:58:42 ubell Exp $";
+static const char revid[] = "$Id: os_seek.c,v 11.18 2002/07/12 18:56:52 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -20,7 +20,6 @@ static const char revid[] = "$Id: os_seek.c,v 11.12 2000/11/30 00:58:42 ubell Ex
#endif
#include "db_int.h"
-#include "os_jump.h"
/*
* __os_seek --
@@ -56,15 +55,17 @@ __os_seek(dbenv, fhp, pgsize, pageno, relative, isrewind, db_whence)
return (EINVAL);
}
- if (__db_jump.j_seek != NULL)
- ret = __db_jump.j_seek(fhp->fd,
+ if (DB_GLOBAL(j_seek) != NULL)
+ ret = DB_GLOBAL(j_seek)(fhp->fd,
pgsize, pageno, relative, isrewind, whence);
else {
offset = (off_t)pgsize * pageno + relative;
if (isrewind)
offset = -offset;
- ret =
- lseek(fhp->fd, offset, whence) == -1 ? __os_get_errno() : 0;
+ do {
+ ret = lseek(fhp->fd, offset, whence) == -1 ?
+ __os_get_errno() : 0;
+ } while (ret == EINTR);
}
if (ret != 0)
diff --git a/bdb/os/os_sleep.c b/bdb/os/os_sleep.c
index 137cd73b708..42d496dbae7 100644
--- a/bdb/os/os_sleep.c
+++ b/bdb/os/os_sleep.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_sleep.c,v 11.7 2000/04/07 14:26:36 bostic Exp $";
+static const char revid[] = "$Id: os_sleep.c,v 11.15 2002/07/12 18:56:52 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -21,6 +21,7 @@ static const char revid[] = "$Id: os_sleep.c,v 11.7 2000/04/07 14:26:36 bostic E
#ifdef HAVE_VXWORKS
#include <sys/times.h>
#include <time.h>
+#include <selectLib.h>
#else
#if TIME_WITH_SYS_TIME
#include <sys/time.h>
@@ -39,7 +40,6 @@ static const char revid[] = "$Id: os_sleep.c,v 11.7 2000/04/07 14:26:36 bostic E
#endif
#include "db_int.h"
-#include "os_jump.h"
/*
* __os_sleep --
@@ -59,8 +59,8 @@ __os_sleep(dbenv, secs, usecs)
for (; usecs >= 1000000; usecs -= 1000000)
++secs;
- if (__db_jump.j_sleep != NULL)
- return (__db_jump.j_sleep(secs, usecs));
+ if (DB_GLOBAL(j_sleep) != NULL)
+ return (DB_GLOBAL(j_sleep)(secs, usecs));
/*
* It's important that we yield the processor here so that other
@@ -68,7 +68,10 @@ __os_sleep(dbenv, secs, usecs)
*/
t.tv_sec = secs;
t.tv_usec = usecs;
- ret = select(0, NULL, NULL, NULL, &t) == -1 ? __os_get_errno() : 0;
+ do {
+ ret = select(0, NULL, NULL, NULL, &t) == -1 ?
+ __os_get_errno() : 0;
+ } while (ret == EINTR);
if (ret != 0)
__db_err(dbenv, "select: %s", strerror(ret));
diff --git a/bdb/os/os_spin.c b/bdb/os/os_spin.c
index b0800b98830..fb36977cb44 100644
--- a/bdb/os/os_spin.c
+++ b/bdb/os/os_spin.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_spin.c,v 11.5 2000/03/30 01:46:42 ubell Exp $";
+static const char revid[] = "$Id: os_spin.c,v 11.13 2002/08/07 02:02:07 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -22,9 +22,10 @@ static const char revid[] = "$Id: os_spin.c,v 11.5 2000/03/30 01:46:42 ubell Exp
#endif
#include "db_int.h"
-#include "os_jump.h"
#if defined(HAVE_PSTAT_GETDYNAMIC)
+static int __os_pstat_getdynamic __P((void));
+
/*
* __os_pstat_getdynamic --
* HP/UX.
@@ -40,6 +41,8 @@ __os_pstat_getdynamic()
#endif
#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
+static int __os_sysconf __P((void));
+
/*
* __os_sysconf --
* Solaris, Linux.
@@ -47,9 +50,9 @@ __os_pstat_getdynamic()
static int
__os_sysconf()
{
- int nproc;
+ long nproc;
- return ((nproc = sysconf(_SC_NPROCESSORS_ONLN)) > 1 ? nproc : 1);
+ return ((nproc = sysconf(_SC_NPROCESSORS_ONLN)) > 1 ? (int)nproc : 1);
}
#endif
@@ -57,10 +60,11 @@ __os_sysconf()
* __os_spin --
* Return the number of default spins before blocking.
*
- * PUBLIC: int __os_spin __P((void));
+ * PUBLIC: int __os_spin __P((DB_ENV *));
*/
int
-__os_spin()
+__os_spin(dbenv)
+ DB_ENV *dbenv;
{
/*
* If the application specified a value or we've already figured it
@@ -71,25 +75,25 @@ __os_spin()
* it can be expensive (e.g., requiring multiple filesystem accesses
* under Debian Linux).
*/
- if (DB_GLOBAL(db_tas_spins) != 0)
- return (DB_GLOBAL(db_tas_spins));
+ if (dbenv->tas_spins != 0)
+ return (dbenv->tas_spins);
- DB_GLOBAL(db_tas_spins) = 1;
+ dbenv->tas_spins = 1;
#if defined(HAVE_PSTAT_GETDYNAMIC)
- DB_GLOBAL(db_tas_spins) = __os_pstat_getdynamic();
+ dbenv->tas_spins = __os_pstat_getdynamic();
#endif
#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
- DB_GLOBAL(db_tas_spins) = __os_sysconf();
+ dbenv->tas_spins = __os_sysconf();
#endif
/*
* Spin 50 times per processor, we have anecdotal evidence that this
* is a reasonable value.
*/
- if (DB_GLOBAL(db_tas_spins) != 1)
- DB_GLOBAL(db_tas_spins) *= 50;
+ if (dbenv->tas_spins != 1)
+ dbenv->tas_spins *= 50;
- return (DB_GLOBAL(db_tas_spins));
+ return (dbenv->tas_spins);
}
/*
@@ -103,7 +107,7 @@ __os_yield(dbenv, usecs)
DB_ENV *dbenv;
u_long usecs;
{
- if (__db_jump.j_yield != NULL && __db_jump.j_yield() == 0)
+ if (DB_GLOBAL(j_yield) != NULL && DB_GLOBAL(j_yield)() == 0)
return;
- __os_sleep(dbenv, 0, usecs);
+ (void)__os_sleep(dbenv, 0, usecs);
}
diff --git a/bdb/os/os_stat.c b/bdb/os/os_stat.c
index 1590e8ecd77..c3510e36f5d 100644
--- a/bdb/os/os_stat.c
+++ b/bdb/os/os_stat.c
@@ -1,24 +1,24 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_stat.c,v 11.8 2000/10/27 20:32:02 dda Exp $";
+static const char revid[] = "$Id: os_stat.c,v 11.20 2002/07/12 18:56:53 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <sys/stat.h>
+
#include <string.h>
#endif
#include "db_int.h"
-#include "os_jump.h"
/*
* __os_exists --
@@ -31,20 +31,29 @@ __os_exists(path, isdirp)
const char *path;
int *isdirp;
{
+ int ret;
struct stat sb;
- if (__db_jump.j_exists != NULL)
- return (__db_jump.j_exists(path, isdirp));
+ if (DB_GLOBAL(j_exists) != NULL)
+ return (DB_GLOBAL(j_exists)(path, isdirp));
+ do {
+ ret =
#ifdef HAVE_VXWORKS
- if (stat((char *)path, &sb) != 0)
+ stat((char *)path, &sb);
#else
- if (stat(path, &sb) != 0)
+ stat(path, &sb);
#endif
- return (__os_get_errno());
+ if (ret != 0)
+ ret = __os_get_errno();
+ } while (ret == EINTR);
+
+ if (ret != 0)
+ return (ret);
#if !defined(S_ISDIR) || defined(STAT_MACROS_BROKEN)
-#ifdef DB_WIN32
+#undef S_ISDIR
+#ifdef _S_IFDIR
#define S_ISDIR(m) (_S_IFDIR & (m))
#else
#define S_ISDIR(m) (((m) & 0170000) == 0040000)
@@ -74,21 +83,23 @@ __os_ioinfo(dbenv, path, fhp, mbytesp, bytesp, iosizep)
int ret;
struct stat sb;
- if (__db_jump.j_ioinfo != NULL)
- return (__db_jump.j_ioinfo(path,
+ if (DB_GLOBAL(j_ioinfo) != NULL)
+ return (DB_GLOBAL(j_ioinfo)(path,
fhp->fd, mbytesp, bytesp, iosizep));
+retry:
if (fstat(fhp->fd, &sb) == -1) {
- ret = __os_get_errno();
+ if ((ret = __os_get_errno()) == EINTR)
+ goto retry;
__db_err(dbenv, "fstat: %s", strerror(ret));
return (ret);
}
/* Return the size of the file. */
if (mbytesp != NULL)
- *mbytesp = sb.st_size / MEGABYTE;
+ *mbytesp = (u_int32_t)(sb.st_size / MEGABYTE);
if (bytesp != NULL)
- *bytesp = sb.st_size % MEGABYTE;
+ *bytesp = (u_int32_t)(sb.st_size % MEGABYTE);
/*
* Return the underlying filesystem blocksize, if available.
@@ -97,7 +108,7 @@ __os_ioinfo(dbenv, path, fhp, mbytesp, bytesp, iosizep)
* Check for a 0 size -- the HP MPE/iX architecture has st_blksize,
* but it's always 0.
*/
-#ifdef HAVE_ST_BLKSIZE
+#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
if (iosizep != NULL && (*iosizep = sb.st_blksize) == 0)
*iosizep = DB_DEF_IOSIZE;
#else
diff --git a/bdb/os/os_tmpdir.c b/bdb/os/os_tmpdir.c
index 0dff5c5b7f0..94645af5e71 100644
--- a/bdb/os/os_tmpdir.c
+++ b/bdb/os/os_tmpdir.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1998, 1999, 2000
+ * Copyright (c) 1998-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_tmpdir.c,v 11.16 2001/01/08 20:42:06 bostic Exp $";
+static const char revid[] = "$Id: os_tmpdir.c,v 11.19 2002/01/11 15:53:02 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -37,6 +37,8 @@ __os_tmpdir(dbenv, flags)
DB_ENV *dbenv;
u_int32_t flags;
{
+ int isdir;
+
/*
* !!!
* Don't change this to:
@@ -96,7 +98,7 @@ __os_tmpdir(dbenv, flags)
#endif
#ifdef DB_WIN32
/* Get the path to the temporary directory. */
- {int isdir, len;
+ {int len;
char *eos, temp[MAXPATHLEN + 1];
if ((len = GetTempPath(sizeof(temp) - 1, temp)) > 2) {
@@ -113,7 +115,7 @@ __os_tmpdir(dbenv, flags)
/* Step through the static list looking for a possibility. */
for (lp = list; *lp != NULL; ++lp)
- if (__os_exists(*lp, NULL) == 0)
+ if (__os_exists(*lp, &isdir) == 0 && isdir != 0)
return (__os_strdup(dbenv, *lp, &dbenv->db_tmp_dir));
return (0);
}
diff --git a/bdb/os/os_unlink.c b/bdb/os/os_unlink.c
index 56c401fe342..28b03afd1aa 100644
--- a/bdb/os/os_unlink.c
+++ b/bdb/os/os_unlink.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: os_unlink.c,v 11.13 2000/11/30 00:58:42 ubell Exp $";
+static const char revid[] = "$Id: os_unlink.c,v 11.24 2002/07/12 18:56:53 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -19,7 +19,42 @@ static const char revid[] = "$Id: os_unlink.c,v 11.13 2000/11/30 00:58:42 ubell
#endif
#include "db_int.h"
-#include "os_jump.h"
+
+/*
+ * __os_region_unlink --
+ * Remove a shared memory object file.
+ *
+ * PUBLIC: int __os_region_unlink __P((DB_ENV *, const char *));
+ */
+int
+__os_region_unlink(dbenv, path)
+ DB_ENV *dbenv;
+ const char *path;
+{
+#ifdef HAVE_QNX
+ int ret;
+ char *newname;
+
+ if ((ret = __os_shmname(dbenv, path, &newname)) != 0)
+ goto err;
+
+ if ((ret = shm_unlink(newname)) != 0) {
+ ret = __os_get_errno();
+ if (ret != ENOENT)
+ __db_err(dbenv, "shm_unlink: %s: %s",
+ newname, strerror(ret));
+ }
+err:
+ if (newname != NULL)
+ __os_free(dbenv, newname);
+ return (ret);
+#else
+ if (F_ISSET(dbenv, DB_ENV_OVERWRITE))
+ (void)__db_overwrite(dbenv, path);
+
+ return (__os_unlink(dbenv, path));
+#endif
+}
/*
* __os_unlink --
@@ -34,15 +69,16 @@ __os_unlink(dbenv, path)
{
int ret;
- ret = __db_jump.j_unlink != NULL ?
- __db_jump.j_unlink(path) :
+retry: ret = DB_GLOBAL(j_unlink) != NULL ?
+ DB_GLOBAL(j_unlink)(path) :
#ifdef HAVE_VXWORKS
unlink((char *)path);
#else
unlink(path);
#endif
if (ret == -1) {
- ret = __os_get_errno();
+ if ((ret = __os_get_errno()) == EINTR)
+ goto retry;
/*
* XXX
* We really shouldn't be looking at this value ourselves,
@@ -66,41 +102,8 @@ __os_unlink(dbenv, path)
/* FALLTHROUGH */
#endif
if (ret != ENOENT)
- __db_err(dbenv, "Unlink: %s: %s", path, strerror(ret));
+ __db_err(dbenv, "unlink: %s: %s", path, strerror(ret));
}
return (ret);
}
-
-/*
- * __os_region_unlink --
- * Remove a shared memory object file.
- *
- * PUBLIC: int __os_region_unlink __P((DB_ENV *, const char *));
- */
-int
-__os_region_unlink(dbenv, path)
- DB_ENV *dbenv;
- const char *path;
-{
-#ifdef HAVE_QNX
- int ret;
- char *newname;
-
- if ((ret = __os_shmname(dbenv, path, &newname)) != 0)
- goto err;
-
- if ((ret = shm_unlink(newname)) != 0) {
- ret = __os_get_errno();
- if (ret != ENOENT)
- __db_err(dbenv, "Shm_unlink: %s: %s",
- newname, strerror(ret));
- }
-err:
- if (newname != NULL)
- __os_free(newname, 0);
- return (ret);
-#else
- return (__os_unlink(dbenv, path));
-#endif
-}