about summary refs log tree commit diff
path: root/db2/os/os_rw.c
diff options
context:
space:
mode:
Diffstat (limited to 'db2/os/os_rw.c')
-rw-r--r--db2/os/os_rw.c82
1 files changed, 72 insertions, 10 deletions
diff --git a/db2/os/os_rw.c b/db2/os/os_rw.c
index 7591041981..38f5b9473a 100644
--- a/db2/os/os_rw.c
+++ b/db2/os/os_rw.c
@@ -8,7 +8,7 @@
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "@(#)os_rw.c	10.7 (Sleepycat) 4/10/98";
+static const char sccsid[] = "@(#)os_rw.c	10.11 (Sleepycat) 10/12/98";
 #endif /* not lint */
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -19,15 +19,73 @@ static const char sccsid[] = "@(#)os_rw.c	10.7 (Sleepycat) 4/10/98";
 #endif
 
 #include "db_int.h"
+#include "os_jump.h"
 
 /*
- * __db_read --
+ * __os_io --
+ *	Do an I/O.
+ *
+ * PUBLIC: int __os_io __P((DB_IO *, int, ssize_t *));
+ */
+int
+__os_io(db_iop, op, niop)
+	DB_IO *db_iop;
+	int op;
+	ssize_t *niop;
+{
+	int ret;
+
+#ifdef HAVE_PREAD
+	switch (op) {
+	case DB_IO_READ:
+		if (__db_jump.j_read != NULL)
+			goto slow;
+		*niop = pread(db_iop->fd_io, 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)
+			goto slow;
+		*niop = pwrite(db_iop->fd_io, db_iop->buf,
+		    db_iop->bytes, (off_t)db_iop->pgno * db_iop->pagesize);
+		break;
+	}
+	if (*niop == db_iop->bytes)
+		return (0);
+slow:
+#endif
+	if (db_iop->mutexp != NULL)
+		(void)__db_mutex_lock(db_iop->mutexp, db_iop->fd_lock);
+
+	if ((ret = __os_seek(db_iop->fd_io,
+	    db_iop->pagesize, db_iop->pgno, 0, 0, SEEK_SET)) != 0)
+		goto err;
+	switch (op) {
+	case DB_IO_READ:
+		ret =
+		    __os_read(db_iop->fd_io, db_iop->buf, db_iop->bytes, niop);
+		break;
+	case DB_IO_WRITE:
+		ret =
+		    __os_write(db_iop->fd_io, db_iop->buf, db_iop->bytes, niop);
+		break;
+	}
+
+err:	if (db_iop->mutexp != NULL)
+		(void)__db_mutex_unlock(db_iop->mutexp, db_iop->fd_lock);
+
+	return (ret);
+
+}
+
+/*
+ * __os_read --
  *	Read from a file handle.
  *
- * PUBLIC: int __db_read __P((int, void *, size_t, ssize_t *));
+ * PUBLIC: int __os_read __P((int, void *, size_t, ssize_t *));
  */
 int
-__db_read(fd, addr, len, nrp)
+__os_read(fd, addr, len, nrp)
 	int fd;
 	void *addr;
 	size_t len;
@@ -39,7 +97,9 @@ __db_read(fd, addr, len, nrp)
 
 	for (taddr = addr,
 	    offset = 0; offset < len; taddr += nr, offset += nr) {
-		if ((nr = __os_read(fd, taddr, len - offset)) < 0)
+		if ((nr = __db_jump.j_read != NULL ?
+		    __db_jump.j_read(fd, taddr, len - offset) :
+		    read(fd, taddr, len - offset)) < 0)
 			return (errno);
 		if (nr == 0)
 			break;
@@ -49,15 +109,15 @@ __db_read(fd, addr, len, nrp)
 }
 
 /*
- * __db_write --
+ * __os_write --
  *	Write to a file handle.
  *
- * PUBLIC: int __db_write __P((int, void *, size_t, ssize_t *));
+ * PUBLIC: int __os_write __P((int, void *, size_t, ssize_t *));
  */
 int
-__db_write(fd, addr, len, nwp)
+__os_write(fd, addr, len, nwp)
 	int fd;
-	void *addr;
+	const void *addr;
 	size_t len;
 	ssize_t *nwp;
 {
@@ -67,7 +127,9 @@ __db_write(fd, addr, len, nwp)
 
 	for (taddr = addr,
 	    offset = 0; offset < len; taddr += nw, offset += nw)
-		if ((nw = __os_write(fd, taddr, len - offset)) < 0)
+		if ((nw = __db_jump.j_write != NULL ?
+		    __db_jump.j_write(fd, taddr, len - offset) :
+		    write(fd, taddr, len - offset)) < 0)
 			return (errno);
 	*nwp = len;
 	return (0);