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.c136
-rw-r--r--db2/os/db_os_fid.c126
-rw-r--r--db2/os/db_os_lseek.c60
-rw-r--r--db2/os/db_os_mmap.c106
-rw-r--r--db2/os/db_os_open.c147
-rw-r--r--db2/os/db_os_rw.c75
-rw-r--r--db2/os/db_os_sleep.c62
-rw-r--r--db2/os/db_os_stat.c84
-rw-r--r--db2/os/db_os_unlink.c35
10 files changed, 913 insertions, 0 deletions
diff --git a/db2/os/db_os_abs.c b/db2/os/db_os_abs.c
new file mode 100644
index 0000000000..8795205839
--- /dev/null
+++ b/db2/os/db_os_abs.c
@@ -0,0 +1,82 @@
+/*-
+ * 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
new file mode 100644
index 0000000000..23a6a45919
--- /dev/null
+++ b/db2/os/db_os_dir.c
@@ -0,0 +1,136 @@
+/*-
+ * 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.7 (Sleepycat) 8/23/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 *, 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;
+
+	if ((dirhandle = _findfirst(dir,&fdata)) == -1) {
+		__db_err(dbenv, "%s: %s", dir, 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_fid.c b/db2/os/db_os_fid.c
new file mode 100644
index 0000000000..8fa55fa56c
--- /dev/null
+++ b/db2/os/db_os_fid.c
@@ -0,0 +1,126 @@
+/*-
+ * 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_fid.c	10.7 (Sleepycat) 8/21/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#endif
+
+#include "db_int.h"
+#include "db_page.h"
+#include "os_ext.h"
+#include "common_ext.h"
+
+/*
+ * __db_fileid --
+ *	Return a unique identifier for a file.
+ *
+ * PUBLIC: int __db_fileid __P((DB_ENV *, const char *, int, u_int8_t *));
+ */
+int
+__db_fileid(dbenv, fname, timestamp, fidp)
+	DB_ENV *dbenv;
+	const char *fname;
+	int timestamp;
+	u_int8_t *fidp;
+{
+	time_t now;
+	u_int8_t *p;
+	unsigned int i;
+
+#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);
+
+	/* Check for the unthinkable. */
+	if (sizeof(sb.st_ino) +
+	    sizeof(sb.st_dev) + sizeof(time_t) > DB_FILE_ID_LEN)
+		return (EINVAL);
+
+	/* On UNIX, use a dev/inode pair. */
+	if (stat(fname, &sb)) {
+		__db_err(dbenv, "%s: %s", fname, strerror(errno));
+		return (errno);
+	}
+
+	/*
+	 * Use the inode first and in reverse order, hopefully putting the
+	 * distinguishing information early in the string.
+	 */
+	for (p = (u_int8_t *)&sb.st_ino +
+	    sizeof(sb.st_ino), i = 0; i < sizeof(sb.st_ino); ++i)
+		*fidp++ = *--p;
+	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 +
+		    sizeof(now), i = 0; i < sizeof(now); ++i)
+			*fidp++ = *--p;
+	}
+	return (0);
+}
diff --git a/db2/os/db_os_lseek.c b/db2/os/db_os_lseek.c
new file mode 100644
index 0000000000..cecf0e156b
--- /dev/null
+++ b/db2/os/db_os_lseek.c
@@ -0,0 +1,60 @@
+/*-
+ * 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
new file mode 100644
index 0000000000..0cd8fad0b0
--- /dev/null
+++ b/db2/os/db_os_mmap.c
@@ -0,0 +1,106 @@
+/*-
+ * 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/db_os_open.c b/db2/os/db_os_open.c
new file mode 100644
index 0000000000..1d67ef9508
--- /dev/null
+++ b/db2/os/db_os_open.c
@@ -0,0 +1,147 @@
+/*-
+ * 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_open.c	10.14 (Sleepycat) 7/5/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#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 --
+ *	Open a file descriptor.
+ *
+ * PUBLIC: int __db_fdopen __P((const char *, int, int, int, int *));
+ */
+int
+__db_fdopen(name, arg_flags, ok_flags, mode, fdp)
+	const char *name;
+	int arg_flags, ok_flags, mode, *fdp;
+{
+	int fd, flags;
+
+	if (arg_flags & ~ok_flags)
+		return (EINVAL);
+
+	flags = 0;
+	if (arg_flags & DB_CREATE)
+		flags |= O_CREAT;
+
+	if (arg_flags & DB_EXCL)
+		flags |= O_EXCL;
+
+	if (arg_flags & DB_RDONLY)
+		flags |= O_RDONLY;
+	else
+		flags |= O_RDWR;
+
+#ifdef _WIN32
+#ifdef _MSC_VER
+	if (arg_flags & DB_SEQUENTIAL)
+		flags |= _O_SEQUENTIAL;
+	else
+		flags |= _O_RANDOM;
+
+	if (arg_flags & DB_TEMPORARY)
+		flags |= _O_TEMPORARY;
+#endif
+	flags |= O_BINARY | O_NOINHERIT;
+#endif
+
+	if (arg_flags & DB_TRUNCATE)
+		flags |= O_TRUNC;
+
+	/* Open the file. */
+	if ((fd = 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);
+#endif
+
+#if !defined(_WIN32) && !defined(macintosh)
+	/*
+	 * Deny access to any child process; done for Win32 by O_NOINHERIT,
+	 * MacOS has neither child processes nor fd inheritance.
+	 */
+	if (fcntl(fd, F_SETFD, 1) == -1) {
+		int ret = errno;
+
+		(void)__db_close(fd);
+		return (ret);
+	}
+#endif
+	*fdp = fd;
+	return (0);
+}
+
+/*
+ * __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.
+ *
+ * PUBLIC: int __db_close __P((int));
+ */
+int
+__db_close(fd)
+	int fd;
+{
+	return (close(fd) ? errno : 0);
+}
diff --git a/db2/os/db_os_rw.c b/db2/os/db_os_rw.c
new file mode 100644
index 0000000000..5a6c2196fd
--- /dev/null
+++ b/db2/os/db_os_rw.c
@@ -0,0 +1,75 @@
+/*-
+ * 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_rw.c	10.4 (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_read --
+ *	Read from a file handle.
+ *
+ * PUBLIC: int __db_read __P((int, void *, size_t, ssize_t *));
+ */
+int
+__db_read(fd, addr, len, nrp)
+	int fd;
+	void *addr;
+	size_t len;
+	ssize_t *nrp;
+{
+	size_t offset;
+	ssize_t nr;
+	u_int8_t *taddr;
+
+	for (taddr = addr,
+	    offset = 0; offset < len; taddr += nr, offset += nr) {
+		if ((nr = read(fd, taddr, len - offset)) < 0)
+			return (errno);
+		if (nr == 0)
+			break;
+	}
+	*nrp = taddr - (u_int8_t *)addr;
+	return (0);
+}
+
+/*
+ * __db_write --
+ *	Write to a file handle.
+ *
+ * PUBLIC: int __db_write __P((int, void *, size_t, ssize_t *));
+ */
+int
+__db_write(fd, addr, len, nwp)
+	int fd;
+	void *addr;
+	size_t len;
+	ssize_t *nwp;
+{
+	size_t offset;
+	ssize_t nw;
+	u_int8_t *taddr;
+
+	for (taddr = addr,
+	    offset = 0; offset < len; taddr += nw, offset += nw)
+		if ((nw = write(fd, taddr, len - offset)) < 0)
+			return (errno);
+	*nwp = len;
+	return (0);
+}
diff --git a/db2/os/db_os_sleep.c b/db2/os/db_os_sleep.c
new file mode 100644
index 0000000000..5591789f51
--- /dev/null
+++ b/db2/os/db_os_sleep.c
@@ -0,0 +1,62 @@
+/*-
+ * 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_sleep.c	10.6 (Sleepycat) 6/28/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+
+#include <errno.h>
+#ifndef HAVE_SYS_TIME_H
+#include <time.h>
+#endif
+#include <unistd.h>
+#endif
+
+#include "db_int.h"
+#include "os_ext.h"
+
+/*
+ * __db_sleep --
+ *	Yield the processor for a period of time.
+ *
+ * PUBLIC: int __db_sleep __P((u_long, u_long));
+ */
+int
+__db_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);
+
+	/*
+	 * 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/db_os_stat.c
new file mode 100644
index 0000000000..7929b6b754
--- /dev/null
+++ b/db2/os/db_os_stat.c
@@ -0,0 +1,84 @@
+/*-
+ * 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_stat.c	10.6 (Sleepycat) 7/2/97";
+#endif /* not lint */
+
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <string.h>
+#endif
+
+#include "db_int.h"
+#include "os_ext.h"
+#include "common_ext.h"
+
+/*
+ * __db_exists --
+ *	Return if the file exists.
+ *
+ * PUBLIC: int __db_exists __P((const char *, int *));
+ */
+int
+__db_exists(path, isdirp)
+	const char *path;
+	int *isdirp;
+{
+	struct stat sb;
+
+	if (stat(path, &sb) != 0)
+		return (errno);
+	if (isdirp != NULL)
+		*isdirp = S_ISDIR(sb.st_mode);
+	return (0);
+}
+
+/*
+ * __db_stat --
+ *	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 *));
+ */
+int
+__db_stat(dbenv, path, fd, sizep, iop)
+	DB_ENV *dbenv;
+	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));
+		return (errno);
+	}
+
+	/* Return the size of the file. */
+	if (sizep != NULL)
+		*sizep = sb.st_size;
+
+	/*
+	 * Return the underlying filesystem blocksize, if available.  Default
+	 * to 8K on the grounds that most OS's use less than 8K as their VM
+	 * page size.
+	 */
+#ifdef HAVE_ST_BLKSIZE
+	if (iop != NULL)
+		*iop = sb.st_blksize;
+#else
+	if (iop != NULL)
+		*iop = 8 * 1024;
+#endif
+	return (0);
+}
diff --git a/db2/os/db_os_unlink.c b/db2/os/db_os_unlink.c
new file mode 100644
index 0000000000..872beba3cf
--- /dev/null
+++ b/db2/os/db_os_unlink.c
@@ -0,0 +1,35 @@
+/*-
+ * 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_unlink.c	10.2 (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_unlink --
+ *	Remove a file.
+ *
+ * PUBLIC: int __db_unlink __P((const char *));
+ */
+int
+__db_unlink(path)
+	const char *path;
+{
+	return (unlink(path) == -1 ? errno : 0);
+}