about summary refs log tree commit diff
path: root/db2/os
diff options
context:
space:
mode:
Diffstat (limited to 'db2/os')
-rw-r--r--db2/os/db_os_abs.c82
-rw-r--r--db2/os/db_os_dir.c138
-rw-r--r--db2/os/db_os_lseek.c60
-rw-r--r--db2/os/db_os_mmap.c106
-rw-r--r--db2/os/os_abs.c31
-rw-r--r--db2/os/os_dir.c100
-rw-r--r--db2/os/os_fid.c (renamed from db2/os/db_os_fid.c)55
-rw-r--r--db2/os/os_fsync.c34
-rw-r--r--db2/os/os_func.c153
-rw-r--r--db2/os/os_map.c71
-rw-r--r--db2/os/os_oflags.c48
-rw-r--r--db2/os/os_open.c (renamed from db2/os/db_os_open.c)58
-rw-r--r--db2/os/os_rpath.c42
-rw-r--r--db2/os/os_rw.c (renamed from db2/os/db_os_rw.c)7
-rw-r--r--db2/os/os_seek.c42
-rw-r--r--db2/os/os_sleep.c (renamed from db2/os/db_os_sleep.c)16
-rw-r--r--db2/os/os_stat.c (renamed from db2/os/db_os_stat.c)20
-rw-r--r--db2/os/os_unlink.c (renamed from db2/os/db_os_unlink.c)5
18 files changed, 549 insertions, 519 deletions
diff --git a/db2/os/db_os_abs.c b/db2/os/db_os_abs.c
deleted file mode 100644
index 8795205839..0000000000
--- a/db2/os/db_os_abs.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*-
- * See the file LICENSE for redistribution information.
- *
- * Copyright (c) 1997
- *	Sleepycat Software.  All rights reserved.
- */
-
-#include "config.h"
-
-#ifndef lint
-static const char sccsid[] = "@(#)db_os_abs.c	10.5 (Sleepycat) 7/5/97";
-#endif /* not lint */
-
-#ifndef NO_SYSTEM_INCLUDES
-#include <string.h>
-#endif
-
-#include "db_int.h"
-#include "os_ext.h"
-
-/*
- * __db_abspath --
- *	Return if a path is an absolute path.
- *
- * PUBLIC: int __db_abspath __P((const char *));
- */
-int
-__db_abspath(path)
-	const char *path;
-{
-#ifdef _WIN32
-	/*
-	 * !!!
-	 * Check for drive specifications, e.g., "C:".  In addition, the path
-	 * separator used by the win32 DB (PATH_SEPARATOR) is \; look for both
-	 * / and \ since these are user-input paths.
-	 */
-	if (isalpha(path[0]) && path[1] == ':')
-		path += 2;
-	return (path[0] == '/' || path[0] == '\\');
-#else
-#ifdef macintosh
-	/*
-	 * !!!
-	 * Absolute pathnames always start with a volume name, which must be
-	 * followed by a colon, thus they are of the form:
-	 *	volume: or volume:dir1:dir2:file
-	 *
-	 * Relative pathnames are either a single name without colons or a
-	 * path starting with a colon, thus of the form:
-	 *	file or :file or :dir1:dir2:file
-	 */
-	return (strchr(path, ':') != NULL && path[0] != ':');
-#else
-	return (path[0] == '/');
-#endif
-#endif
-}
-
-/*
- * __db_rpath --
- *	Return the last path separator in the path or NULL if none found.
- *
- * PUBLIC: char *__db_rpath __P((const char *));
- */
-char *
-__db_rpath(path)
-	const char *path;
-{
-	const char *s, *last;
-
-	last = NULL;
-	if (PATH_SEPARATOR[1] != '\0') {
-		for (s = path; s[0] != '\0'; ++s)
-			if (strchr(PATH_SEPARATOR, s[0]) != NULL)
-				last = s;
-	} else
-		for (s = path; s[0] != '\0'; ++s)
-			if (s[0] == PATH_SEPARATOR[0])
-				last = s;
-	return ((char *)last);
-}
diff --git a/db2/os/db_os_dir.c b/db2/os/db_os_dir.c
deleted file mode 100644
index 1206e3faa7..0000000000
--- a/db2/os/db_os_dir.c
+++ /dev/null
@@ -1,138 +0,0 @@
-/*-
- * See the file LICENSE for redistribution information.
- *
- * Copyright (c) 1997
- *	Sleepycat Software.  All rights reserved.
- */
-
-#include "config.h"
-
-#ifndef lint
-static const char sccsid[] = "@(#)db_os_dir.c	10.10 (Sleepycat) 9/17/97";
-#endif /* not lint */
-
-#ifndef NO_SYSTEM_INCLUDES
-#include <sys/types.h>
-
-#if HAVE_DIRENT_H
-# include <dirent.h>
-# define NAMLEN(dirent) strlen((dirent)->d_name)
-#else
-# define dirent direct
-# define NAMLEN(dirent) (dirent)->d_namlen
-# if HAVE_SYS_NDIR_H
-#  include <sys/ndir.h>
-# endif
-# if HAVE_SYS_DIR_H
-#  include <sys/dir.h>
-# endif
-# if HAVE_NDIR_H
-#  include <ndir.h>
-# endif
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#endif
-
-#include "db_int.h"
-#include "os_ext.h"
-#include "common_ext.h"
-
-/*
- * __db_dir --
- *	Return a list of the files in a directory.
- *
- * PUBLIC: int __db_dir __P((DB_ENV *, const char *, char ***, int *));
- */
-int
-__db_dir(dbenv, dir, namesp, cntp)
-	DB_ENV *dbenv;
-	const char *dir;
-	char ***namesp;
-	int *cntp;
-{
-	int arraysz, cnt;
-	char **names;
-#ifdef _WIN32
-	struct _finddata_t fdata;
-	long dirhandle;
-	int finished;
-	char filespec[MAX_PATH];
-
-	(void)snprintf(filespec, sizeof(filespec), "%s/*", dir);
-	if ((dirhandle = _findfirst(filespec, &fdata)) == -1) {
-		__db_err(dbenv, "%s: %s", filespec, strerror(errno));
-		return (errno);
-	}
-
-	names = NULL;
-	finished = 0;
-	for (arraysz = cnt = 0; finished != 1; ++cnt) {
-		if (cnt >= arraysz) {
-			arraysz += 100;
-			names = (char **)(names == NULL ?
-			    malloc(arraysz * sizeof(names[0])) :
-			    realloc(names, arraysz * sizeof(names[0])));
-			if (names == NULL)
-				goto nomem;
-		}
-		if ((names[cnt] = (char *)strdup(fdata.name)) == NULL)
-			goto nomem;
-		if (_findnext(dirhandle,&fdata) != 0)
-			finished = 1;
-	}
-	_findclose(dirhandle);
-#else /* !_WIN32 */
-	struct dirent *dp;
-	DIR *dirp;
-
-	if ((dirp = opendir(dir)) == NULL) {
-		__db_err(dbenv, "%s: %s", dir, strerror(errno));
-		return (errno);
-	}
-	names = NULL;
-	for (arraysz = cnt = 0; (dp = readdir(dirp)) != NULL; ++cnt) {
-		if (cnt >= arraysz) {
-			arraysz += 100;
-			names = (char **)(names == NULL ?
-			    malloc(arraysz * sizeof(names[0])) :
-			    realloc(names, arraysz * sizeof(names[0])));
-			if (names == NULL)
-				goto nomem;
-		}
-		if ((names[cnt] = (char *)strdup(dp->d_name)) == NULL)
-			goto nomem;
-	}
-	(void)closedir(dirp);
-#endif /* !_WIN32 */
-
-	*namesp = names;
-	*cntp = cnt;
-	return (0);
-
-nomem:	if (names != NULL)
-		__db_dirf(dbenv, names, cnt);
-	__db_err(dbenv, "%s", strerror(ENOMEM));
-	return (ENOMEM);
-}
-
-/*
- * __db_dirf --
- *	Free the list of files.
- *
- * PUBLIC: void __db_dirf __P((DB_ENV *, char **, int));
- */
-void
-__db_dirf(dbenv, names, cnt)
-	DB_ENV *dbenv;
-	char **names;
-	int cnt;
-{
-	dbenv = dbenv;			/* XXX: Shut the compiler up. */
-	while (cnt > 0)
-		free(names[--cnt]);
-	free (names);
-}
diff --git a/db2/os/db_os_lseek.c b/db2/os/db_os_lseek.c
deleted file mode 100644
index cecf0e156b..0000000000
--- a/db2/os/db_os_lseek.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-
- * See the file LICENSE for redistribution information.
- *
- * Copyright (c) 1997
- *	Sleepycat Software.  All rights reserved.
- */
-
-#include "config.h"
-
-#ifndef lint
-static const char sccsid[] = "@(#)db_os_lseek.c	10.3 (Sleepycat) 6/28/97";
-#endif /* not lint */
-
-#ifndef NO_SYSTEM_INCLUDES
-#include <sys/types.h>
-
-#include <errno.h>
-#include <unistd.h>
-#endif
-
-#include "db_int.h"
-#include "os_ext.h"
-
-/*
- * __db_lseek --
- *	Seek to a page/byte offset in the file.
- *
- * PUBLIC: int __db_lseek __P((int, size_t, db_pgno_t, u_long, int));
- */
-int
-__db_lseek(fd, pgsize, pageno, relative, whence)
-	int fd;
-	size_t pgsize;
-	db_pgno_t pageno;
-	u_long relative;
-	int whence;
-{
-	/* 64-bit offsets are done differently by different vendors. */
-#undef	__LSEEK_SET
-#ifdef	HAVE_LLSEEK
-#define	__LSEEK_SET
-	offset_t offset;			/* Solaris. */
-
-	offset = pgsize * pageno + relative;
-	return (llseek(fd, offset, whence) == -1 ? errno : 0);
-#endif
-#ifdef	HAVE_LSEEKI
-#define	__LSEEK_SET
-	__int64 offset;				/* WNT */
-
-	offset = pgsize * pageno + relative;
-	return (_lseeki64(fd, offset, whence) == -1 ? errno : 0);
-#endif
-#ifndef	__LSEEK_SET
-	off_t offset;				/* Default. */
-
-	offset = pgsize * pageno + relative;
-	return (lseek(fd, offset, whence) == -1 ? errno : 0);
-#endif
-}
diff --git a/db2/os/db_os_mmap.c b/db2/os/db_os_mmap.c
deleted file mode 100644
index 0cd8fad0b0..0000000000
--- a/db2/os/db_os_mmap.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*-
- * See the file LICENSE for redistribution information.
- *
- * Copyright (c) 1996, 1997
- *	Sleepycat Software.  All rights reserved.
- */
-
-#include "config.h"
-
-#ifndef lint
-static const char sccsid[] = "@(#)db_os_mmap.c	10.4 (Sleepycat) 6/28/97";
-#endif /* not lint */
-
-#ifndef NO_SYSTEM_INCLUDES
-#include <sys/types.h>
-#include <sys/mman.h>
-
-#include <errno.h>
-#endif
-
-#include "db_int.h"
-#include "os_ext.h"
-
-/*
- * __db_mmap --
- *	Map in some shared memory backed by a file descriptor.
- *
- * PUBLIC: int __db_mmap __P((int, size_t, int, int, void *));
- */
-int
-__db_mmap(fd, len, is_private, rdonly, addr)
-	int fd, is_private, rdonly;
-	size_t len;
-	void *addr;
-{
-#ifdef _WIN32
-	/* We have not implemented copy-on-write here */
-	void * pMemory = 0;
-	HANDLE hFile = (HANDLE)_get_osfhandle(fd);
-	HANDLE hMemory = CreateFileMapping(
-	      hFile,
-	      0,
-	      (rdonly ? PAGE_READONLY : PAGE_READWRITE),
-	      0,
-	      len, /* This code fails if the library is ever compiled on a 64-bit machine */
-	      0
-	      );
-	if (NULL == hMemory)
-	{
-	      return errno;
-	}
-	pMemory = MapViewOfFile(
-	      hMemory,
-	      (rdonly ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS),
-	      0,
-	      0,
-	      len
-	      );
-	CloseHandle(hMemory);
-	*(void **)addr = pMemory;
-	return 0;
-
-#else /* !_WIN32 */
-
-	void *p;
-	int flags, prot;
-
-	flags = is_private ? MAP_PRIVATE : MAP_SHARED;
-#ifdef MAP_HASSEMAPHORE
-	flags += MAP_HASSEMAPHORE;
-#endif
-	prot = PROT_READ | (rdonly ? 0 : PROT_WRITE);
-
-#ifndef MAP_FAILED			/* XXX: Mmap(2) failure return. */
-#define	MAP_FAILED	-1
-#endif
-	if ((p =
-	    mmap(NULL, len, prot, flags, fd, (off_t)0)) == (void *)MAP_FAILED)
-		return (errno);
-
-	*(void **)addr = p;
-	return (0);
-#endif /* _WIN32 */
-}
-
-/*
- * __db_unmap --
- *	Release the specified shared memory.
- *
- * PUBLIC: int __db_munmap __P((void *, size_t));
- */
-int
-__db_munmap(addr, len)
-	void *addr;
-	size_t len;
-{
-	/*
-	 * !!!
-	 * The argument len is always the same length as was mapped.
-	 */
-#ifdef _WIN32
-	return (!UnmapViewOfFile(addr) ? errno : 0);
-#else
-	return (munmap(addr, len) ? errno : 0);
-#endif
-}
diff --git a/db2/os/os_abs.c b/db2/os/os_abs.c
new file mode 100644
index 0000000000..872e46d058
--- /dev/null
+++ b/db2/os/os_abs.c
@@ -0,0 +1,31 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997
+ *	Sleepycat Software.  All rights reserved.
+ */
+
+#include "config.h"
+
+#ifndef lint
+static const char sccsid[] = "@(#)os_abs.c	10.7 (Sleepycat) 10/24/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+#endif
+
+#include "db_int.h"
+
+/*
+ * __db_abspath --
+ *	Return if a path is an absolute path.
+ *
+ * PUBLIC: int __db_abspath __P((const char *));
+ */
+int
+__db_abspath(path)
+	const char *path;
+{
+	return (path[0] == '/');
+}
diff --git a/db2/os/os_dir.c b/db2/os/os_dir.c
new file mode 100644
index 0000000000..10fb8b6739
--- /dev/null
+++ b/db2/os/os_dir.c
@@ -0,0 +1,100 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997
+ *	Sleepycat Software.  All rights reserved.
+ */
+
+#include "config.h"
+
+#ifndef lint
+static const char sccsid[] = "@(#)os_dir.c	10.13 (Sleepycat) 10/28/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+
+#if HAVE_DIRENT_H
+# include <dirent.h>
+# define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# if HAVE_SYS_NDIR_H
+#  include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+#  include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+#  include <ndir.h>
+# endif
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#endif
+
+#include "db_int.h"
+#include "common_ext.h"
+
+/*
+ * __os_dirlist --
+ *	Return a list of the files in a directory.
+ *
+ * PUBLIC: int __os_dirlist __P((const char *, char ***, int *));
+ */
+int
+__os_dirlist(dir, namesp, cntp)
+	const char *dir;
+	char ***namesp;
+	int *cntp;
+{
+	struct dirent *dp;
+	DIR *dirp;
+	int arraysz, cnt;
+	char **names;
+
+	if ((dirp = opendir(dir)) == NULL)
+		return (errno);
+	names = NULL;
+	for (arraysz = cnt = 0; (dp = readdir(dirp)) != NULL; ++cnt) {
+		if (cnt >= arraysz) {
+			arraysz += 100;
+			names = (char **)(names == NULL ?
+			    __db_malloc(arraysz * sizeof(names[0])) :
+			    __db_realloc(names, arraysz * sizeof(names[0])));
+			if (names == NULL)
+				goto nomem;
+		}
+		if ((names[cnt] = (char *)__db_strdup(dp->d_name)) == NULL)
+			goto nomem;
+	}
+	(void)closedir(dirp);
+
+	*namesp = names;
+	*cntp = cnt;
+	return (0);
+
+nomem:	if (names != NULL)
+		__os_dirfree(names, cnt);
+	return (ENOMEM);
+}
+
+/*
+ * __os_dirfree --
+ *	Free the list of files.
+ *
+ * PUBLIC: void __os_dirfree __P((char **, int));
+ */
+void
+__os_dirfree(names, cnt)
+	char **names;
+	int cnt;
+{
+	while (cnt > 0)
+		__db_free(names[--cnt]);
+	__db_free(names);
+}
diff --git a/db2/os/db_os_fid.c b/db2/os/os_fid.c
index 960d580bad..6820b88786 100644
--- a/db2/os/db_os_fid.c
+++ b/db2/os/os_fid.c
@@ -8,7 +8,7 @@
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "@(#)db_os_fid.c	10.8 (Sleepycat) 8/27/97";
+static const char sccsid[] = "@(#)os_fid.c	10.9 (Sleepycat) 10/24/97";
 #endif /* not lint */
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -22,8 +22,6 @@ static const char sccsid[] = "@(#)db_os_fid.c	10.8 (Sleepycat) 8/27/97";
 #endif
 
 #include "db_int.h"
-#include "db_page.h"
-#include "os_ext.h"
 #include "common_ext.h"
 
 /*
@@ -39,58 +37,11 @@ __db_fileid(dbenv, fname, timestamp, fidp)
 	int timestamp;
 	u_int8_t *fidp;
 {
+	struct stat sb;
 	size_t i;
 	time_t now;
 	u_int8_t *p;
 
-#ifdef _WIN32
-	/*
-	 * The documentation for GetFileInformationByHandle() states that the
-	 * inode-type numbers are not constant between processes.  Actually,
-	 * they are, they're the NTFS MFT indexes.  So, this works on NTFS,
-	 * but perhaps not on other platforms, and perhaps not over a network.
-	 * Can't think of a better solution right now.
-	 */
-	int fd = 0;
-	HANDLE fh = 0;
-	BY_HANDLE_FILE_INFORMATION fi;
-	BOOL retval = FALSE;
-
-	/* Clear the buffer. */
-	memset(fidp, 0, DB_FILE_ID_LEN);
-
-	/* first we open the file, because we're not given a handle to it */
-	fd = open(fname,_O_RDONLY,_S_IREAD);
-	if (-1 == fd) {
-		/* If we can't open it, we're in trouble */
-		return (errno);
-	}
-
-	/* File open, get its info */
-	fh = (HANDLE)_get_osfhandle(fd);
-	if ((HANDLE)(-1) != fh) {
-		retval = GetFileInformationByHandle(fh,&fi);
-	}
-	close(fd);
-
-	/*
-	 * We want the three 32-bit words which tell us the volume ID and
-	 * the file ID.  We make a crude attempt to copy the bytes over to
-	 * the callers buffer.
-	 *
-	 * DBDB: really we should ensure that the bytes get packed the same
-	 * way on all compilers, platforms etc.
-	 */
-	if ( ((HANDLE)(-1) != fh) && (TRUE == retval) ) {
-		memcpy(fidp, &fi.nFileIndexLow, sizeof(u_int32_t));
-		fidp += sizeof(u_int32_t);
-		memcpy(fidp, &fi.nFileIndexHigh, sizeof(u_int32_t));
-		fidp += sizeof(u_int32_t);
-		memcpy(fidp, &fi.dwVolumeSerialNumber, sizeof(u_int32_t));
-	}
-#else
-	struct stat sb;
-
 	/* Clear the buffer. */
 	memset(fidp, 0, DB_FILE_ID_LEN);
 
@@ -115,7 +66,7 @@ __db_fileid(dbenv, fname, timestamp, fidp)
 	for (p = (u_int8_t *)&sb.st_dev +
 	    sizeof(sb.st_dev), i = 0; i < sizeof(sb.st_dev); ++i)
 		*fidp++ = *--p;
-#endif
+
 	if (timestamp) {
 		(void)time(&now);
 		for (p = (u_int8_t *)&now +
diff --git a/db2/os/os_fsync.c b/db2/os/os_fsync.c
new file mode 100644
index 0000000000..7b001ceeb0
--- /dev/null
+++ b/db2/os/os_fsync.c
@@ -0,0 +1,34 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997
+ *	Sleepycat Software.  All rights reserved.
+ */
+
+#include "config.h"
+
+#ifndef lint
+static const char sccsid[] = "@(#)os_fsync.c	10.3 (Sleepycat) 10/25/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+
+#include <errno.h>
+#include <unistd.h>
+#endif
+
+#include "db_int.h"
+
+/*
+ * __db_fsync --
+ *	Flush a file descriptor.
+ *
+ * PUBLIC: int __db_fsync __P((int));
+ */
+int
+__db_fsync(fd)
+	int fd;
+{
+	return (__os_fsync(fd) ? errno : 0);
+}
diff --git a/db2/os/os_func.c b/db2/os/os_func.c
new file mode 100644
index 0000000000..afd40f4624
--- /dev/null
+++ b/db2/os/os_func.c
@@ -0,0 +1,153 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997
+ *	Sleepycat Software.  All rights reserved.
+ */
+
+#include "config.h"
+
+#ifndef lint
+static const char sccsid[] = "@(#)os_func.c	10.4 (Sleepycat) 10/28/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+
+#include <errno.h>
+#endif
+
+#include "db_int.h"
+
+/*
+ * XXX
+ * We provide our own extern declarations so that we don't collide with
+ * systems that get them wrong, e.g., SunOS.
+ */
+#ifdef _WIN32
+#define fsync		_commit
+#define imported	__declspec(dllimport)
+#else
+#define imported
+#endif
+
+imported extern void    *calloc __P((size_t, size_t));
+imported extern int	 close __P((int));
+imported extern void	 free __P((void *));
+imported extern int	 fsync __P((int));
+imported extern void    *malloc __P((size_t));
+imported extern int	 open __P((const char *, int, ...));
+imported extern ssize_t	 read __P((int, void *, size_t));
+imported extern char	*strdup __P((const char *));
+imported extern void    *realloc __P((void *, size_t));
+imported extern int	 unlink __P((const char *));
+imported extern ssize_t	 write __P((int, const void *, size_t));
+
+/*
+ * __db_jump --
+ *	This list of interfaces that applications can replace.  In some
+ *	cases, the user is permitted to replace the standard ANSI C or
+ *	POSIX 1003.1 call, e.g., calloc or read.  In others, we provide
+ *	a local interface to the functionality, e.g., __os_map.
+ */
+struct __db_jumptab __db_jump = {
+	calloc,				/* DB_FUNC_CALLOC */
+	close,				/* DB_FUNC_CLOSE */
+	__os_dirfree,			/* DB_FUNC_DIRFREE */
+	__os_dirlist,			/* DB_FUNC_DIRLIST */
+	__os_exists,			/* DB_FUNC_EXISTS */
+	free,				/* DB_FUNC_FREE */
+	fsync,				/* DB_FUNC_FSYNC */
+	__os_ioinfo,			/* DB_FUNC_IOINFO */
+	malloc,				/* DB_FUNC_MALLOC */
+	__os_map,			/* DB_FUNC_MAP */
+	open,				/* DB_FUNC_OPEN */
+	read,				/* DB_FUNC_READ */
+	realloc,			/* DB_FUNC_REALLOC */
+	__os_seek,			/* DB_FUNC_SEEK */
+	__os_sleep,			/* DB_FUNC_SLEEP */
+	strdup,				/* DB_FUNC_STRDUP */
+	unlink,				/* DB_FUNC_UNLINK */
+	__os_unmap,			/* DB_FUNC_UNMAP */
+	write,				/* DB_FUNC_WRITE */
+	NULL				/* DB_FUNC_YIELD */
+};
+
+/*
+ * db_jump_set --
+ *	Replace an interface.
+ */
+int
+db_jump_set(func, which)
+	void *func;
+	int which;
+{
+	switch (which) {
+	case DB_FUNC_CALLOC:
+		__db_calloc = (void *(*) __P((size_t, size_t)))func;
+		break;
+	case DB_FUNC_CLOSE:
+		__os_close = (int (*) __P((int)))func;
+		break;
+	case DB_FUNC_DIRFREE:
+		__db_dirfree = (void (*) __P((char **, int)))func;
+		break;
+	case DB_FUNC_DIRLIST:
+		__db_dirlist =
+		    (int (*) __P((const char *, char ***, int *)))func;
+		break;
+	case DB_FUNC_EXISTS:
+		__db_exists = (int (*) __P((const char *, int *)))func;
+		break;
+	case DB_FUNC_FREE:
+		__db_free = (void (*) __P((void *)))func;
+		break;
+	case DB_FUNC_FSYNC:
+		__os_fsync = (int (*) __P((int)))func;
+		break;
+	case DB_FUNC_IOINFO:
+		__db_ioinfo =
+		    (int (*) __P((const char *, int, off_t *, off_t *)))func;
+		break;
+	case DB_FUNC_MALLOC:
+		__db_malloc = (void *(*) __P((size_t)))func;
+		break;
+	case DB_FUNC_MAP:
+		__db_map = (int (*) __P((int, size_t, int, int, void **)))func;
+		break;
+	case DB_FUNC_OPEN:
+		__os_open = (int (*) __P((const char *, int, ...)))func;
+		break;
+	case DB_FUNC_READ:
+		__os_read = (ssize_t (*) __P((int, void *, size_t)))func;
+		break;
+	case DB_FUNC_REALLOC:
+		__db_realloc = (void *(*) __P((void *, size_t)))func;
+		break;
+	case DB_FUNC_SEEK:
+		__db_seek =
+		    (int (*) __P((int, size_t, db_pgno_t, u_long, int)))func;
+		break;
+	case DB_FUNC_SLEEP:
+		__db_sleep = (int (*) __P((u_long, u_long)))func;
+		break;
+	case DB_FUNC_STRDUP:
+		__db_strdup = (char *(*) __P((const char *)))func;
+		break;
+	case DB_FUNC_UNLINK:
+		__os_unlink = (int (*) __P((const char *)))func;
+		break;
+	case DB_FUNC_UNMAP:
+		__db_unmap = (int (*) __P((void *, size_t)))func;
+		break;
+	case DB_FUNC_WRITE:
+		__os_write = (ssize_t (*) __P((int, const void *, size_t)))func;
+		break;
+	case DB_FUNC_YIELD:
+		__db_yield = (int (*) __P((void)))func;
+		break;
+	default:
+		return (EINVAL);
+	}
+	return (0);
+}
diff --git a/db2/os/os_map.c b/db2/os/os_map.c
new file mode 100644
index 0000000000..b1553188dc
--- /dev/null
+++ b/db2/os/os_map.c
@@ -0,0 +1,71 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1996, 1997
+ *	Sleepycat Software.  All rights reserved.
+ */
+
+#include "config.h"
+
+#ifndef lint
+static const char sccsid[] = "@(#)os_map.c	10.7 (Sleepycat) 10/25/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+#include <sys/mman.h>
+
+#include <errno.h>
+#endif
+
+#include "db_int.h"
+
+/*
+ * __os_map --
+ *	Map in some shared memory backed by a file descriptor.
+ *
+ * PUBLIC: int __os_map __P((int, size_t, int, int, void **));
+ */
+int
+__os_map(fd, len, is_private, is_rdonly, addr)
+	int fd, is_private, is_rdonly;
+	size_t len;
+	void **addr;
+{
+	void *p;
+	int flags, prot;
+
+	flags = is_private ? MAP_PRIVATE : MAP_SHARED;
+#ifdef MAP_HASSEMAPHORE
+	flags |= MAP_HASSEMAPHORE;
+#endif
+	prot = PROT_READ | (is_rdonly ? 0 : PROT_WRITE);
+
+#ifndef MAP_FAILED			/* XXX: Mmap(2) failure return. */
+#define	MAP_FAILED	-1
+#endif
+	if ((p =
+	    mmap(NULL, len, prot, flags, fd, (off_t)0)) == (void *)MAP_FAILED)
+		return (errno);
+
+	*addr = p;
+	return (0);
+}
+
+/*
+ * __os_unmap --
+ *	Release the specified shared memory.
+ *
+ * PUBLIC: int __os_unmap __P((void *, size_t));
+ */
+int
+__os_unmap(addr, len)
+	void *addr;
+	size_t len;
+{
+	/*
+	 * !!!
+	 * The argument len is always the same length as was mapped.
+	 */
+	return (munmap(addr, len) ? errno : 0);
+}
diff --git a/db2/os/os_oflags.c b/db2/os/os_oflags.c
new file mode 100644
index 0000000000..3656eef1c4
--- /dev/null
+++ b/db2/os/os_oflags.c
@@ -0,0 +1,48 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997
+ *	Sleepycat Software.  All rights reserved.
+ */
+
+#include "config.h"
+
+#ifndef lint
+static const char sccsid[] = "@(#)os_oflags.c	10.2 (Sleepycat) 10/24/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+
+#include <fcntl.h>
+#endif
+
+#include "db_int.h"
+
+/*
+ * __db_oflags --
+ *	Convert open(2) flags to DB flags.
+ *
+ * PUBLIC: int __db_oflags __P((int));
+ */
+int
+__db_oflags(oflags)
+	int oflags;
+{
+	int dbflags;
+
+	/*
+	 * XXX
+	 * Convert POSIX 1003.1 open(2) flags to DB flags.  Not an exact
+	 * science as most POSIX implementations don't have a flag value
+	 * for O_RDONLY, it's simply the lack of a write flag.
+	 */
+	dbflags = 0;
+	if (oflags & O_CREAT)
+		dbflags |= DB_CREATE;
+	if (!(oflags & (O_RDWR | O_WRONLY)) || oflags & O_RDONLY)
+		dbflags |= DB_RDONLY;
+	if (oflags & O_TRUNC)
+		dbflags |= DB_TRUNCATE;
+	return (dbflags);
+}
diff --git a/db2/os/db_os_open.c b/db2/os/os_open.c
index 1d67ef9508..05784e4810 100644
--- a/db2/os/db_os_open.c
+++ b/db2/os/os_open.c
@@ -8,7 +8,7 @@
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "@(#)db_os_open.c	10.14 (Sleepycat) 7/5/97";
+static const char sccsid[] = "@(#)os_open.c	10.19 (Sleepycat) 10/28/97";
 #endif /* not lint */
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -20,44 +20,15 @@ static const char sccsid[] = "@(#)db_os_open.c	10.14 (Sleepycat) 7/5/97";
 #endif
 
 #include "db_int.h"
-#include "os_ext.h"
 
 /*
- * __db_oflags --
- *	Convert open(2) flags to DB flags.
- *
- * PUBLIC: int __db_oflags __P((int));
- */
-int
-__db_oflags(oflags)
-	int oflags;
-{
-	int dbflags;
-
-	/*
-	 * XXX
-	 * Convert POSIX 1003.1 open(2) flags to DB flags.  Not an exact
-	 * science as most POSIX implementations don't have a flag value
-	 * for O_RDONLY, it's simply the lack of a write flag.
-	 */
-	dbflags = 0;
-	if (oflags & O_CREAT)
-		dbflags |= DB_CREATE;
-	if (!(oflags & (O_RDWR | O_WRONLY)) || oflags & O_RDONLY)
-		dbflags |= DB_RDONLY;
-	if (oflags & O_TRUNC)
-		dbflags |= DB_TRUNCATE;
-	return (dbflags);
-}
-
-/*
- * __db_fdopen --
+ * __db_open --
  *	Open a file descriptor.
  *
- * PUBLIC: int __db_fdopen __P((const char *, int, int, int, int *));
+ * PUBLIC: int __db_open __P((const char *, int, int, int, int *));
  */
 int
-__db_fdopen(name, arg_flags, ok_flags, mode, fdp)
+__db_open(name, arg_flags, ok_flags, mode, fdp)
 	const char *name;
 	int arg_flags, ok_flags, mode, *fdp;
 {
@@ -95,13 +66,13 @@ __db_fdopen(name, arg_flags, ok_flags, mode, fdp)
 		flags |= O_TRUNC;
 
 	/* Open the file. */
-	if ((fd = open(name, flags, mode)) == -1)
+	if ((fd = __os_open(name, flags, mode)) == -1)
 		return (errno);
 
 #ifndef _WIN32
 	/* Delete any temporary file; done for Win32 by _O_TEMPORARY. */
 	if (arg_flags & DB_TEMPORARY)
-		(void)unlink(name);
+		(void)__os_unlink(name);
 #endif
 
 #if !defined(_WIN32) && !defined(macintosh)
@@ -112,7 +83,7 @@ __db_fdopen(name, arg_flags, ok_flags, mode, fdp)
 	if (fcntl(fd, F_SETFD, 1) == -1) {
 		int ret = errno;
 
-		(void)__db_close(fd);
+		(void)__os_close(fd);
 		return (ret);
 	}
 #endif
@@ -121,19 +92,6 @@ __db_fdopen(name, arg_flags, ok_flags, mode, fdp)
 }
 
 /*
- * __db_fsync --
- *	Flush a file descriptor.
- *
- * PUBLIC: int __db_fsync __P((int));
- */
-int
-__db_fsync(fd)
-	int fd;
-{
-	return (fsync(fd) ? errno : 0);
-}
-
-/*
  * __db_close --
  *	Close a file descriptor.
  *
@@ -143,5 +101,5 @@ int
 __db_close(fd)
 	int fd;
 {
-	return (close(fd) ? errno : 0);
+	return (__os_close(fd) ? errno : 0);
 }
diff --git a/db2/os/os_rpath.c b/db2/os/os_rpath.c
new file mode 100644
index 0000000000..44fd4ec9f4
--- /dev/null
+++ b/db2/os/os_rpath.c
@@ -0,0 +1,42 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997
+ *	Sleepycat Software.  All rights reserved.
+ */
+
+#include "config.h"
+
+#ifndef lint
+static const char sccsid[] = "@(#)os_rpath.c	10.2 (Sleepycat) 10/24/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <string.h>
+#endif
+
+#include "db_int.h"
+
+/*
+ * __db_rpath --
+ *	Return the last path separator in the path or NULL if none found.
+ *
+ * PUBLIC: char *__db_rpath __P((const char *));
+ */
+char *
+__db_rpath(path)
+	const char *path;
+{
+	const char *s, *last;
+
+	last = NULL;
+	if (PATH_SEPARATOR[1] != '\0') {
+		for (s = path; s[0] != '\0'; ++s)
+			if (strchr(PATH_SEPARATOR, s[0]) != NULL)
+				last = s;
+	} else
+		for (s = path; s[0] != '\0'; ++s)
+			if (s[0] == PATH_SEPARATOR[0])
+				last = s;
+	return ((char *)last);
+}
diff --git a/db2/os/db_os_rw.c b/db2/os/os_rw.c
index 5a6c2196fd..48f7fdc5b1 100644
--- a/db2/os/db_os_rw.c
+++ b/db2/os/os_rw.c
@@ -8,7 +8,7 @@
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "@(#)db_os_rw.c	10.4 (Sleepycat) 6/28/97";
+static const char sccsid[] = "@(#)os_rw.c	10.6 (Sleepycat) 10/25/97";
 #endif /* not lint */
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -19,7 +19,6 @@ static const char sccsid[] = "@(#)db_os_rw.c	10.4 (Sleepycat) 6/28/97";
 #endif
 
 #include "db_int.h"
-#include "os_ext.h"
 
 /*
  * __db_read --
@@ -40,7 +39,7 @@ __db_read(fd, addr, len, nrp)
 
 	for (taddr = addr,
 	    offset = 0; offset < len; taddr += nr, offset += nr) {
-		if ((nr = read(fd, taddr, len - offset)) < 0)
+		if ((nr = __os_read(fd, taddr, len - offset)) < 0)
 			return (errno);
 		if (nr == 0)
 			break;
@@ -68,7 +67,7 @@ __db_write(fd, addr, len, nwp)
 
 	for (taddr = addr,
 	    offset = 0; offset < len; taddr += nw, offset += nw)
-		if ((nw = write(fd, taddr, len - offset)) < 0)
+		if ((nw = __os_write(fd, taddr, len - offset)) < 0)
 			return (errno);
 	*nwp = len;
 	return (0);
diff --git a/db2/os/os_seek.c b/db2/os/os_seek.c
new file mode 100644
index 0000000000..e27044b626
--- /dev/null
+++ b/db2/os/os_seek.c
@@ -0,0 +1,42 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 1997
+ *	Sleepycat Software.  All rights reserved.
+ */
+
+#include "config.h"
+
+#ifndef lint
+static const char sccsid[] = "@(#)os_seek.c	10.6 (Sleepycat) 10/25/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+
+#include <errno.h>
+#include <unistd.h>
+#endif
+
+#include "db_int.h"
+
+/*
+ * __os_seek --
+ *	Seek to a page/byte offset in the file.
+ *
+ * PUBLIC: int __os_seek __P((int, size_t, db_pgno_t, u_long, int));
+ */
+int
+__os_seek(fd, pgsize, pageno, relative, whence)
+	int fd;
+	size_t pgsize;
+	db_pgno_t pageno;
+	u_long relative;
+	int whence;
+{
+	off_t offset;
+
+	offset = pgsize * pageno + relative;
+
+	return (lseek(fd, offset, whence) == -1 ? errno : 0);
+}
diff --git a/db2/os/db_os_sleep.c b/db2/os/os_sleep.c
index 5591789f51..2d2cb71f6d 100644
--- a/db2/os/db_os_sleep.c
+++ b/db2/os/os_sleep.c
@@ -8,7 +8,7 @@
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "@(#)db_os_sleep.c	10.6 (Sleepycat) 6/28/97";
+static const char sccsid[] = "@(#)os_sleep.c	10.8 (Sleepycat) 10/25/97";
 #endif /* not lint */
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -28,21 +28,18 @@ static const char sccsid[] = "@(#)db_os_sleep.c	10.6 (Sleepycat) 6/28/97";
 #endif
 
 #include "db_int.h"
-#include "os_ext.h"
 
 /*
- * __db_sleep --
+ * __os_sleep --
  *	Yield the processor for a period of time.
  *
- * PUBLIC: int __db_sleep __P((u_long, u_long));
+ * PUBLIC: int __os_sleep __P((u_long, u_long));
  */
 int
-__db_sleep(secs, usecs)
+__os_sleep(secs, usecs)
 	u_long secs, usecs;		/* Seconds and microseconds. */
 {
-#ifndef _WIN32
 	struct timeval t;
-#endif
 
 	/* Don't require that the values be normalized. */
 	for (; usecs >= 1000000; ++secs, usecs -= 1000000);
@@ -51,12 +48,7 @@ __db_sleep(secs, usecs)
 	 * It's important that we yield the processor here so that other
 	 * processes or threads are permitted to run.
 	 */
-#ifdef _WIN32
-	Sleep(secs * 1000 + usecs / 1000);
-	return (0);
-#else
 	t.tv_sec = secs;
 	t.tv_usec = usecs;
 	return (select(0, NULL, NULL, NULL, &t) == -1 ? errno : 0);
-#endif
 }
diff --git a/db2/os/db_os_stat.c b/db2/os/os_stat.c
index 7929b6b754..ee84ab0588 100644
--- a/db2/os/db_os_stat.c
+++ b/db2/os/os_stat.c
@@ -8,7 +8,7 @@
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "@(#)db_os_stat.c	10.6 (Sleepycat) 7/2/97";
+static const char sccsid[] = "@(#)os_stat.c	10.8 (Sleepycat) 10/25/97";
 #endif /* not lint */
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -20,17 +20,16 @@ static const char sccsid[] = "@(#)db_os_stat.c	10.6 (Sleepycat) 7/2/97";
 #endif
 
 #include "db_int.h"
-#include "os_ext.h"
 #include "common_ext.h"
 
 /*
- * __db_exists --
+ * __os_exists --
  *	Return if the file exists.
  *
- * PUBLIC: int __db_exists __P((const char *, int *));
+ * PUBLIC: int __os_exists __P((const char *, int *));
  */
 int
-__db_exists(path, isdirp)
+__os_exists(path, isdirp)
 	const char *path;
 	int *isdirp;
 {
@@ -44,25 +43,22 @@ __db_exists(path, isdirp)
 }
 
 /*
- * __db_stat --
+ * __os_ioinfo --
  *	Return file size and I/O size; abstracted to make it easier
  *	to replace.
  *
- * PUBLIC: int __db_stat __P((DB_ENV *, const char *, int, off_t *, off_t *));
+ * PUBLIC: int __os_ioinfo __P((const char *, int, off_t *, off_t *));
  */
 int
-__db_stat(dbenv, path, fd, sizep, iop)
-	DB_ENV *dbenv;
+__os_ioinfo(path, fd, sizep, iop)
 	const char *path;
 	int fd;
 	off_t *sizep, *iop;
 {
 	struct stat sb;
 
-	if (fstat(fd, &sb) == -1) {
-		__db_err(dbenv, "%s: fstat: %s", path, strerror(errno));
+	if (fstat(fd, &sb) == -1)
 		return (errno);
-	}
 
 	/* Return the size of the file. */
 	if (sizep != NULL)
diff --git a/db2/os/db_os_unlink.c b/db2/os/os_unlink.c
index 872beba3cf..473ce77d39 100644
--- a/db2/os/db_os_unlink.c
+++ b/db2/os/os_unlink.c
@@ -8,7 +8,7 @@
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "@(#)db_os_unlink.c	10.2 (Sleepycat) 6/28/97";
+static const char sccsid[] = "@(#)os_unlink.c	10.4 (Sleepycat) 10/28/97";
 #endif /* not lint */
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -19,7 +19,6 @@ static const char sccsid[] = "@(#)db_os_unlink.c	10.2 (Sleepycat) 6/28/97";
 #endif
 
 #include "db_int.h"
-#include "os_ext.h"
 
 /*
  * __db_unlink --
@@ -31,5 +30,5 @@ int
 __db_unlink(path)
 	const char *path;
 {
-	return (unlink(path) == -1 ? errno : 0);
+	return (__os_unlink(path) == -1 ? errno : 0);
 }