diff --git a/libsysio/Makefile.am b/libsysio/Makefile.am
index 11e6e3d9db4522a701c40964ac048d265989b431..dfa4f9ebfca47ceb9fe467b89b71a3654737c907 100644
--- a/libsysio/Makefile.am
+++ b/libsysio/Makefile.am
@@ -48,16 +48,14 @@ OPTIONAL_YOD_SRCS =
 endif
 
 if WITH_LUSTRE_HACK
-OPTIONAL_LUSTRE_SRCDIR_SRCS = $(LUSTRE_SRCDIR_SRCS)
 # it would be better that let configure script check this
-AM_CFLAGS = -fPIC
-else
-OPTIONAL_LUSTRE_SRCDIR_SRCS = 
+OPTIONAL_LUSTRE_CFLAGS = -fPIC
 endif
 
+AM_CFLAGS = $(OPTIONAL_LUSTRE_CFLAGS)
+
 __LIBBUILD_DIR__libsysio_a_SOURCES = \
 	$(SRCDIR_SRCS) \
-	$(OPTIONAL_LUSTRE_SRCDIR_SRCS) \
 	$(OPTIONAL_STDFD_SRCS) \
 	$(OPTIONAL_INCORE_SRCS) \
 	$(OPTIONAL_SOCKETS_SRCS) \
diff --git a/libsysio/Rules.make b/libsysio/Rules.make
index 45db68c220fc896139849285a9e93f8ac6f44ed4..057611bba4ebdb68e7768cf63cc7306c5ab50e12 100644
--- a/libsysio/Rules.make
+++ b/libsysio/Rules.make
@@ -14,5 +14,6 @@ endif
 DEV_CPPFLAGS = $(STDFD_DEV_CPPFLAGS)
 
 AM_CPPFLAGS = \
+	-D_POSIX_C_SOURCE=199506L -D_XOPEN_SOURCE=600 \
 	$(AUTOMOUNT) $(ZERO_SUM_MEMORY) $(DEV_CPPFLAGS) $(SOCKETS_CPPFLAGS) \
 	-I$(top_srcdir)/include 
diff --git a/libsysio/dev/stdfd/stdfd.c b/libsysio/dev/stdfd/stdfd.c
index 5a14e8ba1b65050138ba7f5a073f36ea253a7d15..aa6bf85ea06dd2ef9c8d1b99234e0e6b62468f09 100644
--- a/libsysio/dev/stdfd/stdfd.c
+++ b/libsysio/dev/stdfd/stdfd.c
@@ -48,10 +48,10 @@
 #include <errno.h>
 #include <sys/syscall.h>
 #include <unistd.h>
-#include <sys/uio.h>
 #include <sys/types.h>
 #include <sys/queue.h>
 
+#include "xtio.h"
 #include "sysio.h"
 #include "inode.h"
 #include "dev.h"
diff --git a/libsysio/drivers/incore/fs_incore.c b/libsysio/drivers/incore/fs_incore.c
index b6eb1c06ccbc40846db5203e2e594c74b8e8ad8d..ca10b4fa531c4a2cc22ebf284626328324961fbe 100644
--- a/libsysio/drivers/incore/fs_incore.c
+++ b/libsysio/drivers/incore/fs_incore.c
@@ -61,6 +61,7 @@
 #endif
 #include <sys/queue.h>
 
+#include "xtio.h"
 #include "sysio.h"
 #include "fs.h"
 #include "mount.h"
@@ -147,7 +148,8 @@ static int _sysio_incore_filop_write(struct inode *ino, struct ioctx *ioctx);
 static _SYSIO_OFF_T _sysio_incore_filop_pos(struct inode *ino,
 					    _SYSIO_OFF_T off);
 static int _sysio_incore_filop_iodone(struct ioctx *ioctx);
-static int _sysio_incore_filop_fcntl(struct inode *ino, int cmd, va_list ap);
+static int _sysio_incore_filop_fcntl(struct inode *ino, 
+				     int cmd, va_list ap, int *rtn);
 static int _sysio_incore_inop_sync(struct inode *ino);
 static int _sysio_incore_filop_ioctl(struct inode *ino,
 				    unsigned long int request,
@@ -176,7 +178,7 @@ static void _sysio_incore_inop_gone(struct inode *ino);
 #define _sysio_incore_dirop_iodone \
 	(int (*)(struct ioctx *))_sysio_do_illop
 #define _sysio_incore_dirop_fcntl \
-	(int (*)(struct inode *, int, va_list))_sysio_do_eisdir
+	(int (*)(struct inode *, int, va_list, int *))_sysio_do_eisdir
 #define _sysio_incore_dirop_ioctl \
 	(int (*)(struct inode *, \
 		 unsigned long int, \
@@ -1573,12 +1575,14 @@ _sysio_incore_filop_iodone(struct ioctx *iocp __IS_UNUSED)
 static int
 _sysio_incore_filop_fcntl(struct inode *ino __IS_UNUSED,
 			  int cmd __IS_UNUSED,
-			  va_list ap __IS_UNUSED)
+			  va_list ap __IS_UNUSED,
+			  int *rtn)
 {
 
 	/*
 	 * No fcntl's supported.
 	 */
+	*rtn = -1;
 	return -ENOTTY;
 }
 
diff --git a/libsysio/drivers/native/fs_native.c b/libsysio/drivers/native/fs_native.c
index c66c1edc26a5f53cc763a5bb4dc4e4ffd3a3e53c..446d61e124d13aaa7776c8b71e697d96ebed54e5 100644
--- a/libsysio/drivers/native/fs_native.c
+++ b/libsysio/drivers/native/fs_native.c
@@ -51,6 +51,9 @@
 #include <string.h>
 #endif
 #include <unistd.h>
+#if !(defined(REDSTORM) || defined(MAX_IOVEC))
+#include <limits.h>
+#endif
 #include <errno.h>
 #include <assert.h>
 #include <syscall.h>
@@ -65,16 +68,14 @@
 #include <sys/statfs.h>
 #endif
 #include <utime.h>
+#include <sys/uio.h>
 #include <sys/queue.h>
-#if !(defined(REDSTORM) || defined(MAX_IOVEC))
-#include <limits.h>
-#endif
 
+#include "xtio.h"
 #include "sysio.h"
 #include "fs.h"
 #include "mount.h"
 #include "inode.h"
-#include "xtio.h"
 
 #include "fs_native.h"
 
@@ -209,6 +210,7 @@ struct native_inode {
 	int	ni_oflags;				/* flags, from open */
 	unsigned ni_nopens;				/* soft ref count */
 	_SYSIO_OFF_T ni_fpos;				/* current pos */
+	struct intnl_stat ni_stat;			/* cached attrs */
 };
 
 /*
@@ -247,7 +249,7 @@ static int native_inop_read(struct inode *ino, struct ioctx *ioctx);
 static int native_inop_write(struct inode *ino, struct ioctx *ioctx);
 static _SYSIO_OFF_T native_inop_pos(struct inode *ino, _SYSIO_OFF_T off);
 static int native_inop_iodone(struct ioctx *ioctx);
-static int native_inop_fcntl(struct inode *ino, int cmd, va_list ap);
+static int native_inop_fcntl(struct inode *ino, int cmd, va_list ap, int *rtn);
 static int native_inop_sync(struct inode *ino);
 static int native_inop_datasync(struct inode *ino);
 static int native_inop_ioctl(struct inode *ino,
@@ -327,16 +329,25 @@ static struct mount *native_internal_mount = NULL;
  * stat -- by path.
  */
 static int
-native_stat(const char *path, struct intnl_stat *buf)
+native_stat(const char *path, struct native_inode *nino, struct intnl_stat *buf)
 {
 	int	err;
 	struct __native_stat stbuf;
 
 	err = syscall(__SYS_STAT, path, &stbuf);
-	if (err)
+	if (err) {
 		err = -errno;
-	COPY_STAT(&stbuf, buf);
+		goto out;
+	}
+	if (!nino) {
+		COPY_STAT(&stbuf, buf);
+		goto out;
+	}
+	COPY_STAT(&stbuf, &nino->ni_stat);
+	if (&nino->ni_stat != buf)
+		(void )memcpy(buf, &nino->ni_stat, sizeof(struct intnl_stat));
 
+out:
 	return err;
 }
 
@@ -344,16 +355,25 @@ native_stat(const char *path, struct intnl_stat *buf)
  * stat -- by fildes
  */
 static int
-native_fstat(int fd, struct intnl_stat *buf)
+native_fstat(int fd, struct native_inode *nino, struct intnl_stat *buf)
 {
 	int	err;
 	struct __native_stat stbuf;
 
 	err = syscall(__SYS_FSTAT, fd, &stbuf);
-	if (err)
+	if (err) {
 		err = -errno;
-	COPY_STAT(&stbuf, buf);
+		goto out;
+	}
+	if (!nino) {
+		COPY_STAT(&stbuf, buf);
+		goto out;
+	}
+	COPY_STAT(&stbuf, &nino->ni_stat);
+	if (&nino->ni_stat != buf)
+		(void )memcpy(buf, &nino->ni_stat, sizeof(struct intnl_stat));
 
+out:
 	return err;
 }
 
@@ -381,6 +401,7 @@ native_i_new(struct filesys *fs, struct intnl_stat *buf)
 	nino->ni_oflags = 0;
 	nino->ni_nopens = 0;
 	nino->ni_fpos = 0;
+	(void )memcpy(&nino->ni_stat, buf, sizeof(struct intnl_stat));
 	ino =
 	    _sysio_i_new(fs,
 			 &nino->ni_fileid,
@@ -389,7 +410,7 @@ native_i_new(struct filesys *fs, struct intnl_stat *buf)
 #else
 			 buf->st_mode,			/* all of the bits! */
 #endif
-			 0,
+			 buf->st_rdev,
 			 0,
 			 &native_i_ops,
 			 nino);
@@ -453,7 +474,7 @@ create_internal_namespace()
 	/*
 	 * Get root i-node.
 	 */
-	err = native_stat("/", &stbuf);
+	err = native_stat("/", NULL, &stbuf);
 	if (err)
 		goto error;
 	rootino = native_i_new(fs, &stbuf);
@@ -596,7 +617,7 @@ native_iget(struct filesys *fs,
 	/*
 	 * Get file status.
 	 */
-	err = native_stat(path, &stbuf);
+	err = native_stat(path, *inop ? I2NI(*inop) : NULL, &stbuf);
 	if (err) {
 		*inop = NULL;
 		return err;
@@ -626,9 +647,10 @@ native_iget(struct filesys *fs,
 	fileid.fid_data = &ident;
 	fileid.fid_len = sizeof(ident);
 	ino = _sysio_i_find(fs, &fileid);
-	if (ino && forced) {
+	if (ino &&
+	    (forced || (ino->i_mode & S_IFMT) != (stbuf.st_mode & S_IFMT))) {
 		/*
-		 * Insertion was forced but it's already present!
+		 * Insertion was forced or dup inum but it's already present!
 		 */
 		if (native_i_invalid(ino, stbuf)) {
 			/* 
@@ -709,23 +731,36 @@ native_inop_lookup(struct pnode *pno,
 }
 
 static int
-native_inop_getattr(struct pnode *pno, struct inode *ino, struct intnl_stat *stbuf)
+native_inop_getattr(struct pnode *pno,
+		    struct inode *ino,
+		    struct intnl_stat *stbuf)
 {
 	char	*path;
+	struct native_inode *nino;
 	int	err;
 
-	path = NULL;
-	if (!ino || I2NI(ino)->ni_fd < 0) {
+	nino = ino ? I2NI(ino) : NULL;
+	err = 0;					/* compiler cookie */
+	if (!ino) {
 		path = _sysio_pb_path(pno->p_base, '/');
 		if (!path)
 			return -ENOMEM;
-	}
-	err =
-	    path
-	      ? native_stat(path, stbuf)
-	      : native_fstat(I2NI(ino)->ni_fd, stbuf);
-	if (path)
+		err = native_stat(path, nino, stbuf);
 		free(path);
+	} else if (nino->ni_fd >= 0)
+		err = native_fstat(nino->ni_fd, nino, stbuf);
+	else {
+		/*
+		 * Dev inodes don't open in this driver. We won't have
+		 * a file descriptor with which to do the deed then. Satisfy
+		 * the request from the cached copy of the attributes.
+		 */
+		(void )memcpy(stbuf,
+			      &nino->ni_stat,
+			      sizeof(struct intnl_stat));
+		err = 0;
+	}
+	
 	return err;
 }
 
@@ -736,12 +771,19 @@ native_inop_setattr(struct pnode *pno,
 		    struct intnl_stat *stbuf)
 {
 	char	*path;
+	struct native_inode *nino;
 	int	fd;
-	struct intnl_stat st;
+	struct intnl_stat *stbp, _stbuf;
 	int	err;
 
 	path = NULL;
-	fd = ino ? I2NI(ino)->ni_fd : -1;
+	nino = ino ? I2NI(ino) : NULL;
+	fd = -1;
+	stbp = &_stbuf;
+	if (nino) {
+		fd = nino->ni_fd;
+		stbp = &nino->ni_stat;
+	}
 	if (fd < 0 || mask & (SETATTR_MTIME|SETATTR_ATIME)) {
 		if (!pno)
 			return -EEXIST;
@@ -755,8 +797,8 @@ native_inop_setattr(struct pnode *pno,
 	 */
 	err =
 	    fd < 0
-	      ? native_stat(path, &st)
-	      : native_fstat(fd, &st);
+	      ? native_stat(path, nino, stbp)
+	      : native_fstat(fd, nino, stbp);
 	if (err)
 		goto out;
 
@@ -782,8 +824,8 @@ native_inop_setattr(struct pnode *pno,
 		/*
 		 * Alter access and/or modify time attributes.
 		 */
-		ut.actime = st.st_atime;
-		ut.modtime = st.st_mtime;
+		ut.actime = stbuf->st_atime;
+		ut.modtime = stbuf->st_mtime;
 		if (mask & SETATTR_MTIME)
 			ut.modtime = stbuf->st_mtime;
 		if (mask & SETATTR_ATIME)
@@ -841,33 +883,40 @@ native_inop_setattr(struct pnode *pno,
 			   ? syscall(SYS_chown,
 				     path,
 				     mask & SETATTR_UID
-				       ? st.st_uid
+				       ? stbp->st_uid
 				       : (uid_t )-1,
 				     mask & SETATTR_GID
-				       ? st.st_gid
+				       ? stbp->st_gid
 				       : (gid_t )-1)
 			   : syscall(SYS_fchown,
 				     fd,
 				     mask & SETATTR_UID
-				       ? st.st_uid
+				       ? stbp->st_uid
 				       : (uid_t )-1,
 				     mask & SETATTR_GID
-				       ? st.st_gid
+				       ? stbp->st_gid
 				       : (gid_t )-1));
 	}
 	if (mask & (SETATTR_MTIME|SETATTR_ATIME)) {
 		struct utimbuf ut;
 
-		ut.actime = st.st_atime;
-		ut.modtime = st.st_mtime;
+		ut.actime = stbp->st_atime;
+		ut.modtime = stbp->st_mtime;
 		(void )syscall(__SYS_UTIME, path, &ut);
 	}
 	if (mask & SETATTR_MODE) {
 		fd < 0
-		  ? syscall(SYS_chmod, path, st.st_mode & 07777)
-		  : syscall(SYS_fchmod, fd, st.st_mode & 07777);
+		  ? syscall(SYS_chmod, path, stbp->st_mode & 07777)
+		  : syscall(SYS_fchmod, stbp->st_mode & 07777);
 	}
 out:
+	/*
+	 * We must refresh the cached attributes on success.
+	 */
+	if (!err && (fd < 0
+		       ? native_stat(path, nino, stbp)
+		       : native_fstat(fd, nino, stbp)) != 0)
+		abort();
 	if (path)
 		free(path);
 	return err;
@@ -1565,7 +1614,8 @@ native_inop_iodone(struct ioctx *ioctxp __IS_UNUSED)
 static int
 native_inop_fcntl(struct inode *ino,
 		  int cmd,
-		  va_list ap)
+		  va_list ap,
+		  int *rtn)
 {
 	struct native_inode *nino = I2NI(ino);
 	long	arg;
@@ -1574,25 +1624,33 @@ native_inop_fcntl(struct inode *ino,
 	if (nino->ni_fd < 0)
 		abort();
 
+	err = 0;
 	switch (cmd) {
 	case F_GETFD:
 	case F_GETFL:
+#ifdef F_GETOWN
 	case F_GETOWN:
-		err = syscall(SYS_fcntl, nino->ni_fd, cmd);
-		if (err < 0)
+#endif
+		*rtn = syscall(SYS_fcntl, nino->ni_fd, cmd);
+		if (*rtn == -1)
 			err = -errno;
+		break;
 	case F_DUPFD:
 	case F_SETFD:
 	case F_SETFL:
 	case F_GETLK:
 	case F_SETLK:
 	case F_SETLKW:
+#ifdef F_SETOWN
 	case F_SETOWN:
+#endif
 		arg = va_arg(ap, long);
-		err = syscall(SYS_fcntl, nino->ni_fd, cmd, arg);
-		if (err)
+		*rtn = syscall(SYS_fcntl, nino->ni_fd, cmd, arg);
+		if (*rtn == -1)
 			err = -errno;
+		break;
 	default:
+		*rtn = -1;
 		err = -EINVAL;
 	}
 	return err;
@@ -1688,6 +1746,25 @@ native_inop_datasync(struct inode *ino)
 	return err;
 }
 
+#ifdef HAVE_LUSTRE_HACK
+static int
+native_inop_ioctl(struct inode *ino,
+		  unsigned long int request,
+		  va_list ap)
+{
+	long arg1, arg2, arg3, arg4;
+
+	assert(I2NI(ino)->ni_fd >= 0);
+
+	arg1 = va_arg(ap, long);
+	arg2 = va_arg(ap, long);
+	arg3 = va_arg(ap, long);
+	arg4 = va_arg(ap, long);
+
+	return syscall(SYS_ioctl, I2NI(ino)->ni_fd, request,
+		       arg1, arg2, arg3, arg4);
+}
+#else
 static int
 native_inop_ioctl(struct inode *ino __IS_UNUSED,
 		  unsigned long int request __IS_UNUSED,
@@ -1700,6 +1777,7 @@ native_inop_ioctl(struct inode *ino __IS_UNUSED,
 	errno = ENOTTY;
 	return -1;
 }
+#endif
 
 static void
 native_inop_gone(struct inode *ino)
@@ -1708,6 +1786,7 @@ native_inop_gone(struct inode *ino)
 
 	if (nino->ni_fd >= 0)
 		(void )syscall(SYS_close, nino->ni_fd);
+
 	free(ino->i_private);
 }
 
diff --git a/libsysio/drivers/sockets/sockets.c b/libsysio/drivers/sockets/sockets.c
index b8da195f7491096b69b620bd1515d480c1bf00ac..b037e609375e922793f6da18a13c47ef8edc2af0 100644
--- a/libsysio/drivers/sockets/sockets.c
+++ b/libsysio/drivers/sockets/sockets.c
@@ -57,11 +57,13 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/fcntl.h>
-#include <sys/queue.h>
 #include <sys/syscall.h>
 #include <sys/socket.h>
 #include <linux/net.h>
+#include <sys/uio.h>
+#include <sys/queue.h>
 
+#include "xtio.h"
 #include "sysio.h"
 #include "fs.h"
 #include "inode.h"
@@ -98,7 +100,7 @@ static _SYSIO_OFF_T sockets_inop_pos(struct inode *ino,
 static int sockets_inop_iodone(struct ioctx *ioctx);
 static int sockets_inop_sync(struct inode *ino);
 static int sockets_inop_datasync(struct inode *ino);
-static int sockets_inop_fcntl(struct inode *ino, int cmd, va_list ap);
+static int sockets_inop_fcntl(struct inode *ino, int cmd, va_list ap, int *rtn);
 static int sockets_inop_ioctl(struct inode *ino,
 			     unsigned long int request,
 			     va_list ap);
@@ -234,7 +236,7 @@ sockets_inop_write(struct inode *ino,
 }
 
 static _SYSIO_OFF_T
-sockets_inop_pos(struct inode *ino, _SYSIO_OFF_T off)
+sockets_inop_pos(struct inode *ino __IS_UNUSED, _SYSIO_OFF_T off __IS_UNUSED)
 {
 	return -EINVAL;
 }
@@ -252,7 +254,8 @@ sockets_inop_iodone(struct ioctx *ioctxp __IS_UNUSED)
 static int
 sockets_inop_fcntl(struct inode *ino __IS_UNUSED,
 		  int cmd __IS_UNUSED,
-		  va_list ap __IS_UNUSED)
+		  va_list ap __IS_UNUSED,
+		  int *rtn)
 {
 	long arg;
 
@@ -262,7 +265,8 @@ sockets_inop_fcntl(struct inode *ino __IS_UNUSED,
 	case F_GETFD:
 	case F_GETFL:
 	case F_GETOWN:
-		return syscall(SYS_fcntl, I2SKI(ino)->ski_fd, cmd);
+		*rtn = syscall(SYS_fcntl, I2SKI(ino)->ski_fd, cmd);
+		break;
 	case F_DUPFD:
 	case F_SETFD:
 	case F_SETFL:
@@ -271,12 +275,13 @@ sockets_inop_fcntl(struct inode *ino __IS_UNUSED,
 	case F_SETLKW:
 	case F_SETOWN:
 		arg = va_arg(ap, long);
-		return syscall(SYS_fcntl, I2SKI(ino)->ski_fd, cmd, arg);
+		*rtn = syscall(SYS_fcntl, I2SKI(ino)->ski_fd, cmd, arg);
+		break;
 	default:
-		printf("uncatched cmd %d\n", cmd);
-		abort();
+		*rtn = -1;
+		errno = EINVAL;
 	}
-	return -1;
+	return *rtn == -1 ? -errno : 0;
 }
 
 static int
@@ -297,6 +302,29 @@ sockets_inop_datasync(struct inode *ino)
 	return syscall(SYS_fdatasync, I2SKI(ino)->ski_fd);
 }
 
+#ifdef HAVE_LUSTRE_HACK
+/*
+ * we blindly extract 4 params and pass to host kernel, the stack
+ * should be ok. hope no ioctl will consume more then 4 params...
+ */
+static int
+sockets_inop_ioctl(struct inode *ino,
+		  unsigned long int request,
+		  va_list ap)
+{
+	long arg1, arg2, arg3, arg4;
+
+	assert(I2SKI(ino)->ski_fd >= 0);
+
+	arg1 = va_arg(ap, long);
+	arg2 = va_arg(ap, long);
+	arg3 = va_arg(ap, long);
+	arg4 = va_arg(ap, long);
+
+	return syscall(SYS_ioctl, I2SKI(ino)->ski_fd, request,
+		       arg1, arg2, arg3, arg4);
+}
+#else
 static int
 sockets_inop_ioctl(struct inode *ino __IS_UNUSED,
 		  unsigned long int request __IS_UNUSED,
@@ -307,6 +335,7 @@ sockets_inop_ioctl(struct inode *ino __IS_UNUSED,
 	 */
 	return -ENOTTY;
 }
+#endif
 
 static void
 sockets_inop_gone(struct inode *ino)
@@ -389,7 +418,11 @@ socket(int domain, int type, int protocol)
 		goto error;
 	}
 
-	err = _sysio_fd_set(fil, ski->ski_fd);
+#ifdef HAVE_LUSTRE_HACK
+	err = _sysio_fd_set(fil, ski->ski_fd, 1);
+#else
+	err = _sysio_fd_set(fil, -1, 0);
+#endif
 	if (err < 0)
 		goto error;
 
@@ -453,7 +486,11 @@ accept(int s, struct sockaddr *addr, socklen_t *addrlen)
 		goto error;
 	}
 
-	err = _sysio_fd_set(nfil, ski->ski_fd);
+#ifdef HAVE_LUSTRE_HACK
+	err = _sysio_fd_set(nfil, ski->ski_fd, 1);
+#else
+	err = _sysio_fd_set(nfil, -1, 0);
+#endif
 	if (err < 0)
 		goto error;
 
diff --git a/libsysio/drivers/yod/fs_yod.c b/libsysio/drivers/yod/fs_yod.c
index d651b885be0654637a89685d8032e698fa408b91..62eb9f23ff6e1a501a79c63d814ea1afee16c502 100644
--- a/libsysio/drivers/yod/fs_yod.c
+++ b/libsysio/drivers/yod/fs_yod.c
@@ -65,8 +65,8 @@
 #endif
 #include <utime.h>
 #include <sys/queue.h>
-#include <sys/uio.h>
 
+#include "xtio.h"
 #include "sysio.h"
 #include "fs.h"
 #include "mount.h"
@@ -177,7 +177,7 @@ static _SYSIO_OFF_T yod_inop_pos (struct inode *ino, _SYSIO_OFF_T off);
 static int yod_inop_read(struct inode *ino, struct ioctx *ioctx);
 static int yod_inop_write(struct inode *ino, struct ioctx *ioctx);
 static int yod_inop_iodone(struct ioctx *ioctx);
-static int yod_inop_fcntl(struct inode *ino, int cmd, va_list ap);
+static int yod_inop_fcntl(struct inode *ino, int cmd, va_list ap, int *rtn);
 static int yod_inop_sync(struct inode *ino);
 static int yod_inop_datasync(struct inode *ino);
 static int yod_inop_ioctl(struct inode *ino,
@@ -1101,18 +1101,45 @@ yod_inop_iodone(struct ioctx *ioctxp __IS_UNUSED)
 }
 
 static int
-yod_inop_fcntl(struct inode *ino __IS_UNUSED, int cmd, va_list ap __IS_UNUSED)
+yod_inop_fcntl(struct inode *ino, int cmd, va_list ap, int *rtn)
 {
-	switch (cmd) 
-	{
-	case F_DUPFD: /* do something to the ino */
+	struct yod_inode *nino = I2NI(ino);
+	long	arg;
+	int	err;
+
+	if (nino->ni_fd < 0)
+		abort();
+
+	err = 0;
+	switch (cmd) {
+	case F_GETFD:
+	case F_GETFL:
+#ifdef F_GETOWN
+	case F_GETOWN:
+#endif
+		*rtn = syscall(SYS_fcntl, nino->ni_fd, cmd);
+		if (*rtn == -1)
+			err = -errno;
+		break;
+	case F_DUPFD:
+	case F_SETFD:
+	case F_SETFL:
+	case F_GETLK:
+	case F_SETLK:
+	case F_SETLKW:
+#ifdef F_SETOWN
+	case F_SETOWN:
+#endif
+		arg = va_arg(ap, long);
+		*rtn = syscall(SYS_fcntl, nino->ni_fd, cmd, arg);
+		if (*rtn == -1)
+			err = -errno;
 		break;
 	default:
-		errno = EINVAL; 
-		return -1;
+		*rtn = -1;
+		err = -EINVAL;
 	}
-	return 0;
-		
+	return err;
 }
 
 static int
diff --git a/libsysio/include/dev.h b/libsysio/include/dev.h
index 0fe459b0afef3780b433c5203033476dec3937d0..a62f581f7556b0465bbe8dc39d309dcf5d0e758c 100644
--- a/libsysio/include/dev.h
+++ b/libsysio/include/dev.h
@@ -100,7 +100,7 @@ extern const struct inode_ops _sysio_nodev_ops;
 #define _sysio_nodev_inop_open \
 	(int (*)(struct pnode *, \
 		 int, \
-		 mode_t))_sysio_do_enoent
+		 mode_t))_sysio_do_enodev
 #define _sysio_nodev_inop_close \
 	(int (*)(struct inode *))_sysio_do_ebadf
 #define _sysio_nodev_inop_link \
@@ -122,7 +122,8 @@ extern const struct inode_ops _sysio_nodev_ops;
 #define _sysio_nodev_inop_fcntl \
 	(int (*)(struct inode *, \
 		 int, \
-		 va_list))_sysio_do_ebadf
+		 va_list, \
+		 int *))_sysio_do_ebadf
 #define _sysio_nodev_inop_sync \
 	(int (*)(struct inode *))_sysio_do_ebadf
 #define _sysio_nodev_inop_datasync \
diff --git a/libsysio/include/file.h b/libsysio/include/file.h
index ed15f6bb33b36fe887d93d69a08b1a3ebcab7af8..82317d57693524110ce35938533744905eadcfba 100644
--- a/libsysio/include/file.h
+++ b/libsysio/include/file.h
@@ -102,8 +102,8 @@ extern void _sysio_fgone(struct file *fil);
 extern void _sysio_fcompletio(struct ioctx *ioctx, struct file *fil);
 extern int _sysio_fd_close(int fd);
 extern struct file *_sysio_fd_find(int fd);
-extern int _sysio_fd_set(struct file *fil, int fd);
-extern int _sysio_fd_dup2(int oldfd, int newfd);
+extern int _sysio_fd_set(struct file *fil, int fd, int force);
+extern int _sysio_fd_dup(int oldfd, int newfd, int force);
 extern int _sysio_fd_close_all(void);
 #if ZERO_SUM_MEMORY
 extern void _sysio_fd_shutdown(void);
diff --git a/libsysio/include/inode.h b/libsysio/include/inode.h
index d6ee2ffeacb2dcd74a70467cd4e6440fc6381995..9431734c15eccf18aac49d126ce8e785d3f4e707 100644
--- a/libsysio/include/inode.h
+++ b/libsysio/include/inode.h
@@ -103,7 +103,7 @@ struct inode_ops {
     int (*inop_write)(struct inode *ino, struct ioctx *ioctx);
     _SYSIO_OFF_T (*inop_pos)(struct inode *ino, _SYSIO_OFF_T off);
     int (*inop_iodone)(struct ioctx *iocp);
-    int (*inop_fcntl)(struct inode *ino, int cmd, va_list ap);
+    int (*inop_fcntl)(struct inode *ino, int cmd, va_list ap, int *rtn);
     int (*inop_sync)(struct inode *ino);
     int (*inop_datasync)(struct inode *ino);
     int (*inop_ioctl)(struct inode *ino, unsigned long int request, va_list ap);
@@ -370,7 +370,6 @@ struct ioctx {
         ioctx_fast                      : 1,		/* from stack space */
 	ioctx_done			: 1,		/* transfer complete */
 	ioctx_write			: 1;		/* op is a write */
-    ioid_t  ioctx_id;                                   /* unique ident */
     struct inode *ioctx_ino;                            /* i-node */
     const struct iovec *ioctx_iov;                      /* scatter/gather vec */
     size_t  ioctx_iovlen;                               /* iovec length */
@@ -385,12 +384,11 @@ struct ioctx {
 /*
  * Init IO context record.
  */
-#define IOCTX_INIT(ioctx, fast, id, wr, ino, iov, iovlen, xtv, xtvlen) \
+#define IOCTX_INIT(ioctx, fast, wr, ino, iov, iovlen, xtv, xtvlen) \
     do { \
 	(ioctx)->ioctx_fast = (fast); \
 	(ioctx)->ioctx_done = 0; \
 	(ioctx)->ioctx_write = (wr) ? 1 : 0; \
-        (ioctx)->ioctx_id = (id); \
         (ioctx)->ioctx_ino = (ino); \
         (ioctx)->ioctx_iov = (iov); \
         (ioctx)->ioctx_iovlen = (iovlen); \
@@ -460,6 +458,7 @@ extern void _sysio_do_illop(void);
 extern int _sysio_do_ebadf(void);
 extern int _sysio_do_einval(void);
 extern int _sysio_do_enoent(void);
+extern int _sysio_do_enodev(void);
 extern int _sysio_do_espipe(void);
 extern int _sysio_do_eisdir(void);
 extern int _sysio_do_enosys(void);
@@ -485,7 +484,7 @@ extern int _sysio_ioctx_cb(struct ioctx *ioctx,
 			   void (*f)(struct ioctx *, void *),
 			   void *data);
 extern void _sysio_ioctx_cb_free(struct ioctx_callback *cb);
-extern struct ioctx *_sysio_ioctx_find(ioid_t id);
+extern struct ioctx *_sysio_ioctx_find(void *id);
 extern ssize_t _sysio_ioctx_wait(struct ioctx *ioctx);
 extern void _sysio_ioctx_complete(struct ioctx *ioctx);
 extern ssize_t _sysio_validx(const struct intnl_xtvec *xtv, size_t xtvlen,
diff --git a/libsysio/include/sysio.h b/libsysio/include/sysio.h
index fb05d75ced0d5d862feec5319f936e580cfa8709..bd3136591158814ffa011c4e82c1fc5ead7543b6 100644
--- a/libsysio/include/sysio.h
+++ b/libsysio/include/sysio.h
@@ -48,18 +48,6 @@
 #include <limits.h>
 #include <stdarg.h>
 
-#ifndef _IOID_T_DEFINED
-#define _IOID_T_DEFINED
-/*
- * FIXME:
- *
- * This section about ioid_t and it's failure belong in <sys/types.h>
- */
-typedef void *ioid_t;
-
-#define IOID_FAIL			0
-#endif
-
 #if !defined(__IS_UNUSED) && defined(__GNUC__)
 #define __IS_UNUSED	__attribute__ ((unused))
 #else
@@ -259,71 +247,6 @@ extern int SYSIO_INTERFACE_NAME(rename)(const char *oldpath,
 extern int SYSIO_INTERFACE_NAME(fdatasync)(int fd);
 extern int SYSIO_INTERFACE_NAME(ioctl)(int fd, unsigned long request, ...);
 extern mode_t SYSIO_INTERFACE_NAME(umask)(mode_t mask);
-extern int SYSIO_INTERFACE_NAME(iodone)(ioid_t ioid);
-extern ssize_t SYSIO_INTERFACE_NAME(iowait)(ioid_t ioid);
-extern ioid_t SYSIO_INTERFACE_NAME(ipreadv)(int fd, const struct iovec *iov, 
-				   size_t count, off_t offset);
-#if _LARGEFILE64_SOURCE
-extern ioid_t SYSIO_INTERFACE_NAME(ipread64v)(int fd, const struct iovec *iov, 
-					      size_t count, off64_t offset);
-#endif
-extern ioid_t SYSIO_INTERFACE_NAME(ipread)(int fd, void *buf, size_t count, 
-					   off_t offset);
-#if _LARGEFILE64_SOURCE
-extern ioid_t SYSIO_INTERFACE_NAME(ipread64)(int fd, void *buf, size_t count, 
-					     off64_t offset);
-#endif
-extern ssize_t SYSIO_INTERFACE_NAME(preadv)(int fd, const struct iovec *iov, 
-					    size_t count, off_t offset);
-#if _LARGEFILE64_SOURCE
-extern ssize_t SYSIO_INTERFACE_NAME(pread64v)(int fd, const struct iovec *iov, 
-					      size_t count, off64_t offset);
-#endif
-extern ssize_t SYSIO_INTERFACE_NAME(pread)(int fd, void *buf, size_t count, 
-					   off_t offset);
-#if _LARGEFILE64_SOURCE
-extern ssize_t SYSIO_INTERFACE_NAME(pread64)(int fd, void *buf, size_t count, 
-					     off64_t offset);
-#endif
-extern ioid_t SYSIO_INTERFACE_NAME(ireadv)(int fd, const struct iovec *iov, 
-					   int count);
-extern ioid_t SYSIO_INTERFACE_NAME(iread)(int fd, void *buf, size_t count);
-extern ssize_t SYSIO_INTERFACE_NAME(readv)(int fd, const struct iovec *iov, 
-					   int count);
-extern ssize_t SYSIO_INTERFACE_NAME(read)(int fd, void *buf, size_t count);
-extern ioid_t SYSIO_INTERFACE_NAME(ipwritev)(int fd, const struct iovec *iov, 
-					     size_t count, off_t offset);
-#if _LARGEFILE64_SOURCE
-extern ioid_t SYSIO_INTERFACE_NAME(ipwrite64v)(int fd, const struct iovec *iov, 
-					       size_t count, off64_t offset);
-#endif
-extern ioid_t SYSIO_INTERFACE_NAME(ipwrite)(int fd, const void *buf, 
-					    size_t count, off_t offset);
-#if _LARGEFILE64_SOURCE
-extern ioid_t SYSIO_INTERFACE_NAME(ipwrite64)(int fd, const void *buf, 
-					      size_t count, off64_t offset);
-#endif
-extern ssize_t SYSIO_INTERFACE_NAME(pwritev)(int fd, const struct iovec *iov, 
-					     size_t count, off_t offset);
-#if _LARGEFILE64_SOURCE
-extern ssize_t SYSIO_INTERFACE_NAME(pwrite64v)(int fd, const struct iovec *iov, 
-					       size_t count, off64_t offset);
-#endif
-extern ssize_t SYSIO_INTERFACE_NAME(pwrite)(int fd, const void *buf, 
-					    size_t count, off_t offset);
-#if _LARGEFILE64_SOURCE
-extern ssize_t SYSIO_INTERFACE_NAME(pwrite64)(int fd, const void *buf, 
-					      size_t count, off64_t offset);
-#endif
-extern ioid_t SYSIO_INTERFACE_NAME(iwritev)(int fd, 
-					    const struct iovec *iov, 
-					    int count);
-extern ioid_t SYSIO_INTERFACE_NAME(iwrite)(int fd, const void *buf, 
-					   size_t count);
-extern ssize_t SYSIO_INTERFACE_NAME(writev)(int fd, const struct iovec *iov, 
-					    int count);
-extern ssize_t SYSIO_INTERFACE_NAME(write)(int fd, const void *buf, 
-					   size_t count);
 extern int SYSIO_INTERFACE_NAME(mknod)(const char *path, 
 				       mode_t mode, dev_t dev);
 extern int SYSIO_INTERFACE_NAME(utime)(const char *path, 
@@ -398,3 +321,18 @@ extern void _sysio_sysleave();
 #define SYSIO_LEAVE
 
 #endif
+
+/* accounting for IO stats read and write char count */
+#if defined(REDSTORM)
+#define _SYSIO_UPDACCT(w, cc) \
+	do { \
+		if ((cc) < 0) \
+			break; \
+		if (!w) \
+			_add_iostats(0, (size_t )(cc)); \
+		else \
+			_add_iostats((size_t )(cc), 0); \
+	} while(0)
+#else
+#define _SYSIO_UPDACCT(w, cc)
+#endif
diff --git a/libsysio/include/xtio.h b/libsysio/include/xtio.h
index 765aaf87c624df6a9b11e793dc9ffcba602b000b..87cf9810d19a2ca4b980e7256af36bd93a13defd 100644
--- a/libsysio/include/xtio.h
+++ b/libsysio/include/xtio.h
@@ -41,6 +41,21 @@
  * lee@sandia.gov
  */
 
+/*
+ * Extended application programmers interface for IO as found on Cray RedStorm
+ * and the other current SUNMos/Puma/Cougar/Catamount systems.
+ */
+
+#ifndef _XTIO_H_
+#define _XTIO_H_
+
+#ifndef _IOID_T_DEFINED
+#define _IOID_T_DEFINED
+typedef void *ioid_t;
+
+#define IOID_FAIL			0
+#endif
+
 /*
  * Structure for strided I/O.
  */
@@ -60,51 +75,254 @@ struct xtvec64 {
 };
 #endif
 
-extern ioid_t SYSIO_INTERFACE_NAME(ireadx)(int fd,
-					   const struct iovec *iov, 
-					   size_t iov_count,
-					   const struct xtvec *xtv, 
-					   size_t xtv_count);
+struct iovec;
+
+/*
+ * Get status of previously posted async file IO operation.
+ */
+extern int iodone(ioid_t ioid);
+
+/*
+ * Wait for completion of a previously posted asynch file IO request.
+ */
+extern ssize_t iowait(ioid_t ioid);
+
+/*
+ * Post asynch read into buffers mapped by an iovec from file at given offset.
+ */
+extern ioid_t ipreadv(int fd,
+		      const struct iovec *iov,
+		      size_t count,
+		      off_t offset);
+
+#if _LARGEFILE64_SOURCE
+/*
+ * Post asynch read into buffers mapped by an iovec from file at given offset.
+ */
+extern ioid_t ipread64v(int fd,
+			const struct iovec *iov, 
+			size_t count,
+			off64_t offset);
+#endif
+
+/*
+ * Post asynch read into buffer from file at given offset.
+ */
+extern ioid_t ipread(int fd,
+		     void *buf,
+		     size_t count, 
+		     off_t offset);
+
+#if _LARGEFILE64_SOURCE
+/*
+ * Post asynch read into buffer from file at given offset.
+ */
+extern ioid_t ipread64(int fd,
+		       void *buf,
+		       size_t count, 
+		       off64_t offset);
+#endif
+
+/*
+ * Read into buffers mapped by an iovec from file at given offset.
+ */
+extern ssize_t preadv(int fd,
+		      const struct iovec *iov,
+		      size_t count,
+		      off_t offset);
+
+#if _LARGEFILE64_SOURCE
+/*
+ * Read into buffers mapped by an iovec from file at given offset.
+ */
+extern ssize_t pread64v(int fd,
+			const struct iovec *iov, 
+			size_t count,
+			off64_t offset);
+#endif
+
+/*
+ * Post asynch read into buffers mapped by an iovec.
+ */
+extern ioid_t ireadv(int fd,
+		     const struct iovec *iov, 
+		     int count);
+
+/*
+ * Read into buffer.
+ */
+extern ioid_t iread(int fd,
+		    void *buf,
+		    size_t count);
+
+/*
+ * Post async read into buffers mapped by iovec from regions mapped
+ * by xtvec.
+ *
+ * NB: An adaptation of "listio" from Argonne's PVFS.
+ */
+extern ioid_t ireadx(int fd,
+		     const struct iovec *iov, 
+		     size_t iov_count,
+		     const struct xtvec *xtv,
+		     size_t xtv_count);
+
 #ifdef __USE_LARGEFILE64
-extern ioid_t SYSIO_INTERFACE_NAME(iread64x)(int fd,
-					     const struct iovec *iov, 
-					     size_t iov_count,
-					     const struct xtvec64 *xtv, 
-					     size_t xtv_count);
+/*
+ * Post async read into buffers mapped by iovec from regions mapped
+ * by xtvec.
+ *
+ * NB: An adaptation of "listio" from Argonne's PVFS.
+ */
+extern ioid_t iread64x(int fd,
+		       const struct iovec *iov, 
+		       size_t iov_count,
+		       const struct xtvec64 *xtv, 
+		       size_t xtv_count);
 #endif
-extern ssize_t SYSIO_INTERFACE_NAME(readx)(int fd,
-					   const struct iovec *iov, 
-					   size_t iov_count,
-					   const struct xtvec *xtv, 
-					   size_t xtv_count);
+
+/*
+ * Read into buffers mapped by iovec from regions mapped
+ * by xtvec.
+ *
+ * NB: An adaptation of "listio" from Argonne's PVFS.
+ */
+extern ssize_t readx(int fd,
+		     const struct iovec *iov, 
+		     size_t iov_count,
+		     const struct xtvec *xtv, 
+		     size_t xtv_count);
+
 #ifdef __USE_LARGEFILE64
-extern ssize_t SYSIO_INTERFACE_NAME(read64x)(int fd,
-					     const struct iovec *iov, 
-					     size_t iov_count,
-					     const struct xtvec64 *xtv, 
-					     size_t xtv_count);
+/*
+ * Read into buffers mapped by iovec from regions mapped
+ * by xtvec.
+ *
+ * NB: An adaptation of "listio" from Argonne's PVFS.
+ */
+extern ssize_t read64x(int fd,
+		       const struct iovec *iov, 
+		       size_t iov_count,
+		       const struct xtvec64 *xtv, 
+		       size_t xtv_count);
+#endif
+
+/*
+ * Post asynch write from buffers mapped by an iovec to file at given offset.
+ */
+extern ioid_t ipwritev(int fd,
+		       const struct iovec *iov, 
+		       size_t count,
+		       off_t offset);
+#if _LARGEFILE64_SOURCE
+/*
+ * Post asynch write from buffers mapped by an iovec to file at given offset.
+ */
+extern ioid_t ipwrite64v(int fd,
+			 const struct iovec *iov, 
+			 size_t count,
+			 off64_t offset);
 #endif
-extern ioid_t SYSIO_INTERFACE_NAME(iwritex)(int fd,
-					    const struct iovec *iov, 
-					    size_t iov_count,
-					    const struct xtvec *xtv, 
-					    size_t xtv_count);
+
+/*
+ * Post asynch write from buffer to file at given offset.
+ */
+extern ioid_t ipwrite(int fd,
+		      const void *buf, 
+		      size_t count,
+		      off_t offset);
+
+#if _LARGEFILE64_SOURCE
+/*
+ * Post asynch write from buffer to file at given offset.
+ */
+extern ioid_t ipwrite64(int fd,
+			const void *buf, 
+			size_t count,
+			off64_t offset);
+#endif
+
+/*
+ * Write from buffers mapped by an iovec to file at given offset.
+ */
+extern ssize_t pwritev(int fd,
+		       const struct iovec *iov,
+		       size_t count,
+		       off_t offset);
+
+#if _LARGEFILE64_SOURCE
+/*
+ * Write from buffers mapped by an iovec to file at given offset.
+ */
+extern ssize_t pwrite64v(int fd,
+			 const struct iovec *iov,
+			 size_t count,
+			 off64_t offset);
+#endif
+
+/*
+ * Post asynch write from buffer to file at given offset.
+ */
+extern ioid_t iwritev(int fd,
+		      const struct iovec *iov,
+		      int count);
+
+/*
+ * Write from buffer to file at given offset.
+ */
+extern ioid_t iwrite(int fd,
+		     const void *buf,
+		     size_t count);
+
+/*
+ * Post async write from buffers mapped by iovec to regions mapped
+ * by xtvec.
+ *
+ * NB: An adaptation of "listio" from Argonne's PVFS.
+ */
+extern ioid_t iwritex(int fd,
+		      const struct iovec *iov, 
+		      size_t iov_count,
+		      const struct xtvec *xtv, 
+		      size_t xtv_count);
+
 #ifdef __USE_LARGEFILE64
-extern ioid_t SYSIO_INTERFACE_NAME(iwrite64x)(int fd,
-					      const struct iovec *iov, 
-					      size_t iov_count,
-					      const struct xtvec64 *xtv, 
-					      size_t xtv_count);
+/*
+ * Post async write from buffers mapped by iovec to regions mapped
+ * by xtvec.
+ *
+ * NB: An adaptation of "listio" from Argonne's PVFS.
+ */
+extern ioid_t iwrite64x(int fd,
+			const struct iovec *iov, 
+			size_t iov_count,
+			const struct xtvec64 *xtv, 
+			size_t xtv_count);
 #endif
-extern ssize_t SYSIO_INTERFACE_NAME(writex)(int fd,
-					    const struct iovec *iov, 
-					    size_t iov_count,
-					    const struct xtvec *xtv, 
-					    size_t xtv_count);
+
+/*
+ * Write from buffers mapped by iovec to regions mapped
+ * by xtvec.
+ *
+ * NB: An adaptation of "listio" from Argonne's PVFS.
+ */
+extern ssize_t writex(int fd,
+		      const struct iovec *iov, 
+		      size_t iov_count,
+		      const struct xtvec *xtv, 
+		      size_t xtv_count);
+
 #ifdef __USE_LARGEFILE64
-extern ssize_t SYSIO_INTERFACE_NAME(write64x)(int fd,
-					      const struct iovec *iov, 
-					      size_t iov_count,
-					      const struct xtvec64 *xtv, 
-					      size_t xtv_count);
+/*
+ * Write from buffers mapped by iovec to regions mapped
+ * by xtvec.
+ *
+ * NB: An adaptation of "listio" from Argonne's PVFS.
+ */
+extern ssize_t write64x(int fd,
+			const struct iovec *iov, 
+			size_t iov_count,
+			const struct xtvec64 *xtv,
+			size_t xtv_count);
 #endif
+#endif /* ! _XTIO_H_ */
diff --git a/libsysio/misc/init-env.sh b/libsysio/misc/init-env.sh
index 167f4216f18cd5d8f15a54a044e55ed055c5d1a7..3e9861e1829389406aed4fbc56d4e0bd988b621d 100644
--- a/libsysio/misc/init-env.sh
+++ b/libsysio/misc/init-env.sh
@@ -29,8 +29,11 @@ export SYSIO_NAMESPACE="\
 	{creat,	ft=chr,nm=\"/dev/stderr\",pm=0200,mm=0+2} \
 	{creat,	ft=dir,nm=\"/dev/fd\",pm=0755,ow=0,gr=0} \
 	{creat,	ft=chr,nm=\"/dev/fd/0\",pm=0400,mm=0+0} \
+	{open,	nm=\"/dev/fd/0\",fd=0,m=0} \
 	{creat,	ft=chr,nm=\"/dev/fd/1\",pm=0200,mm=0+1} \
+	{open,	nm=\"/dev/fd/1\",fd=1,m=1} \
 	{creat,	ft=chr,nm=\"/dev/fd/2\",pm=0200,mm=0+2} \
+	{open,	nm=\"/dev/fd/2\",fd=2,m=1} \
 	{cd,	dir=\"$HOME\"} \
 	${_extras} \
 "
diff --git a/libsysio/src/access.c b/libsysio/src/access.c
index e2f621158e0e0d26a5542f59e3c470f5dc19b88f..9d2664f280c33511096b5bca69661841056d6cde 100644
--- a/libsysio/src/access.c
+++ b/libsysio/src/access.c
@@ -43,12 +43,13 @@
 
 #include <stdlib.h>
 #include <errno.h>
+#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <unistd.h>
+#include <sys/queue.h>
 
-#include "sysio-symbols.h"
 #include "sysio.h"
+#include "sysio-symbols.h"
 
 int
 SYSIO_INTERFACE_NAME(access)(const char *path, int amode)
@@ -63,6 +64,12 @@ SYSIO_INTERFACE_NAME(access)(const char *path, int amode)
 	SYSIO_INTERFACE_ENTER;
 	err = 0;
 
+	/*
+	 * Check amode.
+	 */
+	if ((amode & (R_OK|W_OK|X_OK)) != amode)
+		SYSIO_INTERFACE_RETURN(-1, -EINVAL);
+
 	n = getgroups(0, NULL);
 	list = NULL;
 	if (n) {
@@ -81,6 +88,9 @@ SYSIO_INTERFACE_NAME(access)(const char *path, int amode)
 		err = -errno;
 		goto out;
 	}
+	if (!amode)
+		SYSIO_INTERFACE_RETURN(0, 0);
+
 
 	mask = 0;
 	if (amode & R_OK)
diff --git a/libsysio/src/dup.c b/libsysio/src/dup.c
index 9226a5a856ffa31845ae86e8fc81059510366b14..947d7f0df1c1e2795b25ca163a793eeea397eb12 100644
--- a/libsysio/src/dup.c
+++ b/libsysio/src/dup.c
@@ -69,7 +69,7 @@ SYSIO_INTERFACE_NAME(dup2)(int oldfd, int newfd)
 		SYSIO_INTERFACE_RETURN(newfd, 0);
 	}
 
-	fd = _sysio_fd_dup2(oldfd, newfd);
+	fd = _sysio_fd_dup(oldfd, newfd, 1);
 	SYSIO_INTERFACE_RETURN(fd < 0 ? -1 : fd, fd < 0 ? fd : 0);
 }
 
@@ -86,7 +86,7 @@ SYSIO_INTERFACE_NAME(dup)(int oldfd)
 	SYSIO_INTERFACE_DISPLAY_BLOCK;
 
 	SYSIO_INTERFACE_ENTER;
-	fd = _sysio_fd_dup2(oldfd, -1);
+	fd = _sysio_fd_dup(oldfd, -1, 0);
 	SYSIO_INTERFACE_RETURN(fd < 0 ? -1 : fd, fd < 0 ? fd : 0);
 }
 
diff --git a/libsysio/src/fcntl.c b/libsysio/src/fcntl.c
index 63fb920bc12b8df8a3e2ece995b4d3393fa43d08..c8a801a2fd6a491d16e2dfe9bc97a5e7eb5e774c 100644
--- a/libsysio/src/fcntl.c
+++ b/libsysio/src/fcntl.c
@@ -57,29 +57,12 @@
 #include <syscall.h>
 
 static int
-_sysio_fcntl(int fd, int cmd, va_list ap)
+_sysio_fcntl(int fd, int cmd, va_list ap, int *rtn)
 {
-	int	err;
-	long	arg;
-
-	switch (cmd) {
-	case F_GETFD:
-	case F_GETFL:
-	case F_GETOWN:
-		return syscall(SYS_fcntl, fd, cmd);
-	case F_DUPFD:
-	case F_SETFD:
-	case F_SETFL:
-	case F_GETLK:
-	case F_SETLK:
-	case F_SETLKW:
-	case F_SETOWN:
-		arg = va_arg(ap, long);
-		return syscall(SYS_fcntl, fd, cmd, arg);
-	}
+	long arg = va_arg(ap, long);
 
-	errno = ENOSYS;
-	return -1;
+	*rtn = syscall(SYS_fcntl, fd, cmd, arg);
+	return *rtn == -1 ? -errno : 0;
 }
 #endif
 
@@ -87,6 +70,7 @@ int
 SYSIO_INTERFACE_NAME(fcntl)(int fd, int cmd, ...)
 {
 	int	err;
+	int	rtn;
 	struct file *fil;
 	va_list	ap;
 	SYSIO_INTERFACE_DISPLAY_BLOCK;
@@ -97,12 +81,12 @@ SYSIO_INTERFACE_NAME(fcntl)(int fd, int cmd, ...)
 	if (!fil) {
 #ifdef HAVE_LUSTRE_HACK
 		va_start(ap, cmd);
-		err = _sysio_fcntl(fd, cmd, ap);
+		err = _sysio_fcntl(fd, cmd, ap, &rtn);
 		va_end(ap);
-		if (err == -1)
-			err = -errno;
 		goto out;
 #else
+
+		rtn = -1;
 		err = -EBADF;
 		goto out;
 #endif
@@ -118,21 +102,26 @@ SYSIO_INTERFACE_NAME(fcntl)(int fd, int cmd, ...)
 			newfd = va_arg(ap, long);
 			va_end(ap);
 			if (newfd != (int )newfd || newfd < 0) {
+				rtn = -1;
 				err = -EBADF;
 				goto out;
 			}
-			err = _sysio_fd_dup2(fd, (int )newfd);
+			rtn = _sysio_fd_dup(fd, (int )newfd, 0);
+			if (rtn < 0) {
+				err = rtn;
+				rtn = -1;
+			}
 		}
 		break;
 	    default:
 		va_start(ap, cmd);
-		err = fil->f_ino->i_ops.inop_fcntl(fil->f_ino, cmd, ap);
+		err = fil->f_ino->i_ops.inop_fcntl(fil->f_ino, cmd, ap, &rtn);
 		va_end(ap);
 		break;
 	}
 
 out:
-	SYSIO_INTERFACE_RETURN(err ? -1 : 0, err);
+	SYSIO_INTERFACE_RETURN(rtn, err);
 }
 
 #ifdef __GLIBC__
diff --git a/libsysio/src/file.c b/libsysio/src/file.c
index 8d2c3a8880d4c3821e1e9faae24c75cb7ca9e621..bffc3fd61c00fef9311904a7eb1bb60515f1c869 100644
--- a/libsysio/src/file.c
+++ b/libsysio/src/file.c
@@ -50,7 +50,6 @@
 #include "sysio.h"
 #include "file.h"
 #include "inode.h"
-#include "xtio.h"
 
 /*
  * Support for file IO.
@@ -119,29 +118,27 @@ _sysio_fcompletio(struct ioctx *ioctx, struct file *fil)
 static int
 fd_grow(size_t n)
 {
-	int	fd;
 	size_t	count;
 	struct file **noftab, **filp;
 
 	/*
 	 * Sanity check the new size.
 	 */
-	fd = (int )n;
-	if ((size_t )fd != n)
+	if ((int )n < 0)
 		return -EMFILE;
 
-	if (n < 8)
-		n = 8;
-	if (n >= _sysio_oftab_size && n - _sysio_oftab_size < _sysio_oftab_size)
-		n = (n + 1) * 2;
+	/*
+	 * We never shrink the table.
+	 */
+	if (n <= _sysio_oftab_size)
+		return 0;
+
 	noftab = realloc(_sysio_oftab, n * sizeof(struct file *));
 	if (!noftab)
 		return -ENOMEM;
 	_sysio_oftab = noftab;
 	count = _sysio_oftab_size;
 	_sysio_oftab_size = n;
-	if (n < count)
-		return 0;
 	filp = _sysio_oftab + count;
 	n -= count;
 	while (n--)
@@ -160,21 +157,24 @@ _sysio_fd_shutdown()
 #endif
 
 /*
- * Find a free slot in the open files table.
+ * Find a free slot in the open files table greater than or equal to the
+ * argument.
  */
 static int
-find_free_fildes()
+find_free_fildes(int low)
 {
-	size_t	n;
+	int	n;
 	int	err;
 	struct file **filp;
 
-	for (n = 0, filp = _sysio_oftab;
-	     n < _sysio_oftab_size && *filp;
+	for (n = low, filp = _sysio_oftab + low;
+	     n >= 0 && (unsigned )n < _sysio_oftab_size && *filp;
 	     n++, filp++)
 		;
-	if (n >= _sysio_oftab_size) {
-		err = fd_grow(n);
+	if (n < 0)
+		return -ENFILE;
+	if ((unsigned )n >= _sysio_oftab_size) {
+		err = fd_grow((unsigned )n + 1);
 		if (err)
 			return err;
 		filp = &_sysio_oftab[n];
@@ -216,26 +216,29 @@ _sysio_fd_close(int fd)
 }
 
 /*
- * Associate open file record with given file descriptor or any available
- * file descriptor if less than zero.
+ * Associate open file record with given file descriptor (if forced), or any
+ * available file descriptor if less than zero, or any available descriptor
+ * greater than or equal to the given one if not forced.
  */
 int
-_sysio_fd_set(struct file *fil, int fd)
+_sysio_fd_set(struct file *fil, int fd, int force)
 {
 	int	err;
 	struct file *ofil;
 
 	/*
-	 * New fd < 0 => any available descriptor.
+	 * Search for a free descriptor if needed.
 	 */
-	if (fd < 0) {
-		fd = find_free_fildes();
+	if (fd < 0 || !force) {
+		if (fd < 0)
+			fd = 0;
+		fd = find_free_fildes(fd);
 		if (fd < 0)
 			return fd;
 	}
 
 	if ((unsigned )fd >= _sysio_oftab_size) {
-		err = fd_grow(fd);
+		err = fd_grow((unsigned )fd + 1);
 		if (err)
 			return err;
 	}
@@ -258,22 +261,24 @@ _sysio_fd_set(struct file *fil, int fd)
  * Duplicate old file descriptor.
  *
  * If the new file descriptor is less than zero, the new file descriptor
- * is chosen freely.
+ * is chosen freely. Otherwise, choose an available descriptor greater
+ * than or equal to the new, if not forced. Otherwise, if forced, (re)use
+ * the new.
  */
 int
-_sysio_fd_dup2(int oldfd, int newfd)
+_sysio_fd_dup(int oldfd, int newfd, int force)
 {
 	struct file *fil;
 	int	fd;
 
 	if (oldfd == newfd)
-		return 0;
+		return newfd;
 
 	fil = _sysio_fd_find(oldfd);
 	if (!fil)
 		return -EBADF;
 
-	fd = _sysio_fd_set(fil, newfd);
+	fd = _sysio_fd_set(fil, newfd, force);
 	if (fd >= 0)
 		F_REF(fil);
 	return fd;
diff --git a/libsysio/src/file_hack.c b/libsysio/src/file_hack.c
index bad70bee153fa2018d20f73d6b15b7c5ded65f50..524fb55e3bf207a62071f4a4ce4bb9c9a3e625e1 100644
--- a/libsysio/src/file_hack.c
+++ b/libsysio/src/file_hack.c
@@ -51,7 +51,6 @@
 #include "sysio.h"
 #include "file.h"
 #include "inode.h"
-#include "xtio.h"
 
 /*
  * Support for file IO.
@@ -204,24 +203,27 @@ _sysio_fd_shutdown()
 #endif
 
 /*
- * Find a free slot in the open files table.
- * target < 0: any free slot
- * target >= 0: get slot [target]
+ * Find a free slot in the open files table which >= @low
+ * low < 0 means any
  */
 static int
-find_free_fildes(oftab_t *oftab, int target)
+find_free_fildes(oftab_t *oftab, int low)
  {
 	int	n;
  	int	err;
  	struct file **filp;
  
-	if (target < 0) {
-		for (n = 0, filp = oftab->table;
-		     n < oftab->size && *filp;
-		     n++, filp++)
-			;
-	} else
-		n = target - oftab->offset;
+	if (low < 0)
+		low = oftab->offset;
+
+	n = low - oftab->offset;
+	if (n < 0)
+		return -ENFILE;
+
+	for (filp = oftab->table + n;
+	     n < oftab->size && *filp;
+	     n++, filp++)
+		;
 
 	if (n >= oftab->size) {
 		err = fd_grow(oftab, n);
@@ -231,18 +233,6 @@ find_free_fildes(oftab_t *oftab, int target)
  		assert(!*filp);
  	}
  
-#ifdef HAVE_LUSTRE_HACK
-	/* FIXME sometimes we could intercept open/socket to create
-	 * a fd, but missing close()? currently we have this problem
-         * with resolv lib. as a workaround simply destroy the file
-	 * struct here.
-	 */
-	if (oftab->table[n]) {
-		free(oftab->table[n]);
-		oftab->table[n] = NULL;
-	}
-#endif
-
 	return oftab->offset + n;
 }
 
@@ -299,35 +289,55 @@ _sysio_fd_close(int fd)
 }
 
 /*
- * Associate open file record with given file descriptor or any available
- * file descriptor if less than zero.
+ * Associate open file record with given file descriptor (if forced), or any
+ * available file descriptor if less than zero, or any available descriptor
+ * greater than or equal to the given one if not forced.
  */
 int
-_sysio_fd_set(struct file *fil, int fd)
+_sysio_fd_set(struct file *fil, int fd, int force)
 {
 	int	err;
 	struct file *ofil;
 	oftab_t *oftab;
 
+	if (force && fd < 0)
+		abort();
+
 	init_oftab();
 
 	oftab = select_oftab(fd);
 
 	/*
-	 * New fd < 0 => any available descriptor.
+	 * Search for a free descriptor if needed.
 	 */
-	fd = find_free_fildes(oftab, fd);
-	if (fd < 0)
-		return fd;
+	if (!force) {
+		fd = find_free_fildes(oftab, fd);
+		if (fd < 0)
+			return fd;
+	}
 
-	assert(fd < oftab->offset + oftab->size);
+	if (fd - oftab->offset >= oftab->size) {
+		err = fd_grow(oftab, fd - oftab->offset);
+		if (err)
+			return err;
+	}
 
 	/*
 	 * Remember old.
 	 */
 	ofil = __sysio_fd_get(fd, 1);
-	if (ofil)
-		F_RELE(ofil);
+	if (ofil) {
+		/* FIXME sometimes we could intercept open/socket to create
+		 * a fd, but missing close()? currently we have this problem
+		 * with resolv lib. as a workaround simply destroy the file
+		 * struct here. And this hack will break the behavior of
+		 * DUPFD.
+		 */
+		if (fd >= 0 && oftab == &_sysio_oftab[0])
+			free(ofil);
+		else
+			F_RELE(ofil);
+	}
 
 	oftab->table[fd - oftab->offset] = fil;
 
@@ -338,10 +348,12 @@ _sysio_fd_set(struct file *fil, int fd)
  * Duplicate old file descriptor.
  *
  * If the new file descriptor is less than zero, the new file descriptor
- * is chosen freely.
+ * is chosen freely. Otherwise, choose an available descriptor greater
+ * than or equal to the new, if not forced. Otherwise, if forced, (re)use
+ * the new.
  */
 int
-_sysio_fd_dup2(int oldfd, int newfd)
+_sysio_fd_dup(int oldfd, int newfd, int force)
 {
 	struct file *fil;
 	int	fd;
@@ -359,7 +371,7 @@ _sysio_fd_dup2(int oldfd, int newfd)
 	if (select_oftab(oldfd) != select_oftab(newfd))
 		return -EINVAL;
 
-	fd = _sysio_fd_set(fil, newfd);
+	fd = _sysio_fd_set(fil, newfd, force);
 	if (fd >= 0)
 		F_REF(fil);
 	return fd;
diff --git a/libsysio/src/init.c b/libsysio/src/init.c
index 38d0794a566369f8d2188ff15e5807f8151f0743..5e3e793d79a517c564aded13ee52acd775fbdc16 100644
--- a/libsysio/src/init.c
+++ b/libsysio/src/init.c
@@ -50,20 +50,18 @@
 #include <limits.h>
 #include <assert.h>
 #include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/queue.h>
-#include <sys/uio.h>
-
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <sys/uio.h>
+#include <sys/queue.h>
 
+#include "xtio.h"
 #include "sysio.h"
 #include "inode.h"
 #include "fs.h"
 #include "mount.h"
 #include "file.h"
 #include "dev.h"
-#include "xtio.h"
 
 #ifdef STDFD_DEV
 #include "stdfd.h"
@@ -394,7 +392,6 @@ do_creat(char *args)
 			xtvec.xtv_len = iovec.iov_len;
 			IOCTX_INIT(&io_context,
 				   1,
-				   (ioid_t )&io_context,
 				   1,
 				   ino,
 				   &iovec, 1,
@@ -549,6 +546,69 @@ do_chmd(char *args)
 	return err;
 }
 
+static int
+do_open(char *args)
+{
+	size_t	len;
+	struct named_argument v[] = {
+		{ "nm",	NULL },			/* path */
+		{ "fd",		NULL },			/* fildes */
+		{ "m",		NULL },			/* mode */
+		{ NULL,		NULL }
+	};
+	char	*cp;
+	int	fd;
+	mode_t	m;
+	struct pnode *dir, *pno;
+	struct intent intent;
+	int	err;
+	struct file *fil;
+
+	len = strlen(args);
+	if (get_args(args, v) - args != (ssize_t )len ||
+	    !(v[0].value && v[1].value && v[2].value))
+		return -EINVAL;
+	fd = strtol(v[1].value, (char **)&cp, 0);
+	if (*cp ||
+	    (((fd == LONG_MIN || fd == LONG_MAX) && errno == ERANGE)) ||
+	     fd < 0)
+		return -EINVAL;
+	m = strtoul(v[1].value, (char **)&cp, 0);
+	if (*cp ||
+	    (m == LONG_MAX && errno == ERANGE))
+		return -EINVAL;
+	m &= O_RDONLY|O_WRONLY|O_RDWR;
+
+	if (!(dir = _sysio_cwd) && !(dir = _sysio_root))
+		return -ENOENT;
+	INTENT_INIT(&intent, INT_OPEN, &m, NULL);
+	pno = NULL;
+	err = _sysio_namei(dir, v[0].value, 0, &intent, &pno);
+	if (err)
+		return err;
+	fil = NULL;
+	do {
+		err = _sysio_open(pno, m, 0);
+		if (err)
+			break;
+		fil = _sysio_fnew(pno->p_base->pb_ino, m);
+		if (!fil) {
+			err = -ENOMEM;
+			break;
+		}
+		err = _sysio_fd_set(fil, fd, 1);
+		if (err < 0)
+			break;
+		P_RELE(pno);
+		return 0;
+	} while (0);
+	if (fil)
+		F_RELE(fil);
+	if (pno)
+		P_RELE(pno);
+	return err;
+}
+
 /*
  * Execute the given cmd.
  *
@@ -571,6 +631,8 @@ do_command(char *buf)
 			return do_cd(args);
 		if (strcmp("chmd", cmd) == 0)
 			return do_chmd(args);
+		if (strcmp("open", cmd) == 0)
+			return do_open(args);
 	}
 	return -EINVAL;
 }
diff --git a/libsysio/src/inode.c b/libsysio/src/inode.c
index 6615918e2b6f7fcef9d5d0652af85ead925b516f..0fa2cd095f52575f5a3a2bbaf43dd95576b5d0c7 100644
--- a/libsysio/src/inode.c
+++ b/libsysio/src/inode.c
@@ -45,9 +45,9 @@
 #include <string.h>
 #include <errno.h>
 #include <assert.h>
-#include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/queue.h>
 
 #include "sysio.h"
 #include "fs.h"
@@ -956,3 +956,14 @@ _sysio_do_enosys()
 
 	return -ENOSYS;
 }
+
+
+/*
+ * Return -ENODEV
+ */
+int
+_sysio_do_enodev()
+{
+
+	return -ENODEV;
+}
diff --git a/libsysio/src/ioctx.c b/libsysio/src/ioctx.c
index 70c1b3e4d17737a40d8d60ed4185d7ecd73ab44d..4daaf32c998527ed2bcd12848832dd06bd5bfbb0 100644
--- a/libsysio/src/ioctx.c
+++ b/libsysio/src/ioctx.c
@@ -45,13 +45,19 @@
 #include <string.h>
 #include <errno.h>
 #include <assert.h>
-#include <sys/types.h>
 #include <sys/uio.h>
+#include <sys/types.h>
 #include <sys/queue.h>
 
+#include "xtio.h"
 #include "sysio.h"
 #include "inode.h"
-#include "xtio.h"
+
+
+#if defined(REDSTORM)
+#include <catamount/do_iostats.h>
+#endif
+
 
 /*
  * Asynchronous IO context support.
@@ -119,7 +125,6 @@ _sysio_ioctx_new(struct inode *ino,
 
 	IOCTX_INIT(ioctx,
 		   0,
-		   (ioid_t )ioctx,
 		   wr,
 		   ino,
 		   iov, iovlen,
@@ -166,12 +171,12 @@ _sysio_ioctx_cb(struct ioctx *ioctx,
  * this implementation.
  */
 struct ioctx *
-_sysio_ioctx_find(ioid_t id)
+_sysio_ioctx_find(void *id)
 {
 	struct ioctx *ioctx;
 
 	for (ioctx = aioq.lh_first; ioctx; ioctx = ioctx->ioctx_link.le_next)
-		if (ioctx->ioctx_id == id)
+		if (ioctx == id)
 			return ioctx;
 
 	return NULL;
@@ -229,6 +234,10 @@ _sysio_ioctx_complete(struct ioctx *ioctx)
 {
 	struct ioctx_callback *entry;
 
+
+	/* update IO stats */
+	_SYSIO_UPDACCT(ioctx->ioctx_write, ioctx);
+
 	/*
 	 * Run the call-back queue.
 	 */
@@ -375,9 +384,8 @@ _sysio_enumerate_extents(const struct intnl_xtvec *xtv, size_t xtvlen,
 		while (xtvec.xtv_len) {
 			if (iovec.iov_len) {
 				tmp = iovec.iov_len; 
-				if (iovec.iov_len > xtvec.xtv_len) {
+				if (iovec.iov_len > xtvec.xtv_len)
 					iovec.iov_len = xtvec.xtv_len;
-				} 
 				cc =
 				    (*f)(&iovec, 1,
 					 xtvec.xtv_off,
@@ -394,7 +402,7 @@ _sysio_enumerate_extents(const struct intnl_xtvec *xtv, size_t xtvlen,
 				if (acc && tmp <= acc)
 					abort();		/* paranoia */
 				acc = tmp;
-			} else {
+			} else if (iovlen) {
 				start = iov;
 				n = xtvec.xtv_len;
 				do {
@@ -409,18 +417,14 @@ _sysio_enumerate_extents(const struct intnl_xtvec *xtv, size_t xtvlen,
 				} while (--iovlen);
 				if (iov == start) {
 					iovec = *iov++;
-#if 0
-					if (iovec.iov_len > n) {
-						iovec.iov_len = n;
-					} 
-#endif
+					iovlen--;
 					continue;
 				}
 				remain = xtvec.xtv_len - n;
 				cc =
 				    (*f)(start, iov - start,
-								 xtvec.xtv_off,
-								 xtvec.xtv_len - n,
+					 xtvec.xtv_off,
+					 remain,
 					 arg);
 				if (cc <= 0) {
 					if (acc)
@@ -432,14 +436,12 @@ _sysio_enumerate_extents(const struct intnl_xtvec *xtv, size_t xtvlen,
 				if (acc && tmp <= acc)
 					abort();		/* paranoia */
 				acc = tmp;
-				
-				if (remain && !iovlen) 
-					return acc;
-				
+
 				remain -= cc;
 				if (remain)
 					return acc;		/* short */
-			}
+			} else
+				return acc;			/* short out */
 			xtvec.xtv_off += cc;
 			xtvec.xtv_len -= cc;
 		}
diff --git a/libsysio/src/iowait.c b/libsysio/src/iowait.c
index 28035e3ef8eac5b2387808701753707122cece9b..e52ec2fbbb113176bc070c6d389251b46fe902f6 100644
--- a/libsysio/src/iowait.c
+++ b/libsysio/src/iowait.c
@@ -56,7 +56,7 @@
  * Poll status of asynch IO request.
  */
 int
-SYSIO_INTERFACE_NAME(iodone)(ioid_t ioid)
+SYSIO_INTERFACE_NAME(iodone)(void *ioid)
 {
 	struct ioctx *ioctx;
 	int rc;
@@ -81,7 +81,7 @@ SYSIO_INTERFACE_NAME(iodone)(ioid_t ioid)
  * The identifier is no longer valid after return.
  */
 ssize_t
-SYSIO_INTERFACE_NAME(iowait)(ioid_t ioid)
+SYSIO_INTERFACE_NAME(iowait)(void *ioid)
 {
 	struct ioctx *ioctx;
 	ssize_t	cc;
diff --git a/libsysio/src/lseek.c b/libsysio/src/lseek.c
index d16efc49d9e21fdfbceb6e8d9fc27c6cd6021551..b046ec46c365718bda9d84821f540fafc3b26424 100644
--- a/libsysio/src/lseek.c
+++ b/libsysio/src/lseek.c
@@ -60,9 +60,7 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset, int whence)
 	struct file *fil;
 	_SYSIO_OFF_T off, pos;
 	struct intnl_stat stbuf;
-	SYSIO_INTERFACE_DISPLAY_BLOCK;
 
-	SYSIO_INTERFACE_ENTER;
 	fil = _sysio_fd_find(fd);
 	if (!fil)
 		return -EBADF;
@@ -85,7 +83,7 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset, int whence)
 							      fil->f_ino,
 							      &stbuf);
 			if (err)
-				SYSIO_INTERFACE_RETURN((off_t )-1, (int )err);
+				return err;
 	
 		}
 		off = stbuf.st_size;
@@ -95,32 +93,48 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset, int whence)
 	}
 	pos = off + offset;
 	if ((offset < 0 && -offset > off) || (offset > 0 && pos <= off))
-		SYSIO_INTERFACE_RETURN((off_t )-1, -EINVAL);
+		return -EINVAL;
 
 #ifdef O_LARGEFILE
 	if (pos >= ((fil->f_flags & O_LARGEFILE) ? _SYSIO_OFF_T_MAX : LONG_MAX))
-		SYSIO_INTERFACE_RETURN((off_t )-1, -EOVERFLOW);
+		return -EOVERFLOW;
 #else
 	if (pos >= _SYSIO_OFF_T_MAX)
-		SYSIO_INTERFACE_RETURN((off_t )-1, -EOVERFLOW);
+		return -EOVERFLOW;
 #endif
 	pos = (fil->f_ino->i_ops.inop_pos)(fil->f_ino, pos);
 	if (pos < 0)
-		SYSIO_INTERFACE_RETURN((off_t )-1, (int )pos);
+		return pos;
 	fil->f_pos = pos;
-	SYSIO_INTERFACE_RETURN((off_t )pos, 0);
+	return pos;
 }
 
 #if _LARGEFILE64_SOURCE
 #undef lseek64
-sysio_sym_weak_alias(_sysio_lseek, SYSIO_INTERFACE_NAME(lseek64))
+
+extern off64_t
+SYSIO_INTERFACE_NAME(lseek64)(int fd, off64_t offset, int whence)
+{
+	_SYSIO_OFF_T off;
+	off_t	rtn;
+	SYSIO_INTERFACE_DISPLAY_BLOCK;
+
+	SYSIO_INTERFACE_ENTER;
+	off = _sysio_lseek(fd, offset, whence);
+	if (off < 0)
+		SYSIO_INTERFACE_RETURN((off_t )-1, (int )off);
+	rtn = (off64_t )off;
+	assert(rtn == off);
+	SYSIO_INTERFACE_RETURN(rtn, 0);
+}
 #ifdef __GLIBC__
 #undef __lseek64
-sysio_sym_weak_alias(_sysio_lseek, PREPEND(__, SYSIO_INTERFACE_NAME(lseek64)))
+sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(lseek64),
+		     PREPEND(__, SYSIO_INTERFACE_NAME(lseek64)))
 #endif
 #ifdef REDSTORM
 #undef __libc_lseek64
-sysio_sym_weak_alias(_sysio_lseek, 
+sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(lseek64),
 		     PREPEND(__, SYSIO_INTERFACE_NAME(libc_lseek64)))
 #endif
 #endif
diff --git a/libsysio/src/module.mk b/libsysio/src/module.mk
index 306d18f1dd879b0163d2fb37041896899f709aa2..fc3208b3758ffa910204adf3b89ea71612b8917b 100644
--- a/libsysio/src/module.mk
+++ b/libsysio/src/module.mk
@@ -26,6 +26,6 @@ SRCDIR_SRCS = src/access.c src/chdir.c src/chmod.c \
 	src/rmdir.c src/stat64.c src/stat.c \
 	src/symlink.c src/readlink.c \
 	src/truncate.c src/unlink.c src/utime.c \
-	$(FILE_SUPPORT) $(LUSTRE_SRCDIR_SOURCES)
+	$(FILE_SUPPORT) $(LUSTRE_SRCDIR_SRCS)
 
 SRCDIR_EXTRA = src/module.mk
diff --git a/libsysio/src/mount.c b/libsysio/src/mount.c
index 3e738328aaab2d80871254c761007026e122f6d2..8785bb06086130453b15c09937d552c7e53dfa37 100644
--- a/libsysio/src/mount.c
+++ b/libsysio/src/mount.c
@@ -53,13 +53,11 @@
 #endif
 #include <sys/queue.h>
 
+#include "xtio.h"
 #include "sysio.h"
 #include "fs.h"
 #include "mount.h"
 #include "inode.h"
-#ifdef AUTOMOUNT_FILE_NAME
-#include "xtio.h"
-#endif
 
 /*
  * File system and volume mount support.
@@ -618,7 +616,6 @@ _sysio_automount(struct pnode *mntpno)
 	xtvec.xtv_len = stbuf.st_size;
 	IOCTX_INIT(&iocontext,
 		   1,
-		   (ioid_t )&iocontext,
 		   0,
 		   ino,
 		   &iovec, 1,
diff --git a/libsysio/src/namei.c b/libsysio/src/namei.c
index 2d2e905e3243e2dbd4e4a337d64f3b5b387958ae..b4d856997ef05a6d4afb0e7e400846f66cdfac2a 100644
--- a/libsysio/src/namei.c
+++ b/libsysio/src/namei.c
@@ -50,9 +50,9 @@
 #include <errno.h>
 #include <assert.h>
 #include <sys/param.h>
-#include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/queue.h>
 
 #include "sysio.h"
 #include "mount.h"
diff --git a/libsysio/src/open.c b/libsysio/src/open.c
index a7c31276de452e4cd14f4ae12167056ab19f948e..58450096b833ab35125f40d0abcc23b485513e46 100644
--- a/libsysio/src/open.c
+++ b/libsysio/src/open.c
@@ -62,8 +62,6 @@
 #include "mount.h"
 #include "sysio-symbols.h"
 
-#include "sysio-symbols.h"
-
 /*
  * Open file support.
  */
@@ -200,7 +198,7 @@ SYSIO_INTERFACE_NAME(open)(const char *path, int flags, ...)
 		rtn = -ENOMEM;
 		goto error;
 	}
-	rtn = _sysio_fd_set(fil, -1);
+	rtn = _sysio_fd_set(fil, -1, 0);
 	if (rtn < 0)
 		goto error;
 
diff --git a/libsysio/src/rename.c b/libsysio/src/rename.c
index 167c74fa0111b1c20ed5aaa2815b9e429c613187..23e97b1d41acf4f5e7622c2f05dfd5a78a4ab2b3 100644
--- a/libsysio/src/rename.c
+++ b/libsysio/src/rename.c
@@ -77,7 +77,7 @@ SYSIO_INTERFACE_NAME(rename)(const char *oldpath, const char *newpath)
 	 */
 	INTENT_INIT(&intent, INT_UPDPARENT, NULL, NULL);
 	err = _sysio_namei(_sysio_cwd, newpath, ND_NEGOK, &intent, &new);
-	if (err && !new)
+	if (err)
 		goto error2;
 
 	if (old->p_mount->mnt_root == old || old->p_cover ||
diff --git a/libsysio/src/rw.c b/libsysio/src/rw.c
index ad103b8a04a0601c02f1e9d7dca17221506eaa24..edc308bacc1d2150aef5d4510011fd4dae352a62 100644
--- a/libsysio/src/rw.c
+++ b/libsysio/src/rw.c
@@ -50,10 +50,10 @@
 #include <sys/uio.h>
 #include <sys/queue.h>
 
+#include "xtio.h"
 #include "sysio.h"
 #include "file.h"
 #include "inode.h"
-#include "xtio.h"
 
 #include "sysio-symbols.h"
 
@@ -267,7 +267,7 @@ SYSIO_INTERFACE_NAME(ireadv)(int fd, const struct iovec *iov, int count)
 		free(xtv);
 		SYSIO_INTERFACE_RETURN(IOID_FAIL, err);
 	}
-	SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0);
+	SYSIO_INTERFACE_RETURN(ioctx, 0);
 }
 
 ssize_t
@@ -351,7 +351,7 @@ SYSIO_INTERFACE_NAME(iread)(int fd, void *buf, size_t count)
 		free(iov);
 		SYSIO_INTERFACE_RETURN(IOID_FAIL, err);
 	}
-	SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0);
+	SYSIO_INTERFACE_RETURN(ioctx, 0);
 }
 
 ssize_t
@@ -464,7 +464,7 @@ PREPEND(_, SYSIO_INTERFACE_NAME(ipreadv))(int fd,
 		free(xtv);
 		SYSIO_INTERFACE_RETURN(IOID_FAIL, err);
 	}
-	SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0);
+	SYSIO_INTERFACE_RETURN(ioctx, 0);
 }
 
 #if _LARGEFILE64_SOURCE
@@ -578,7 +578,7 @@ error:
 			free(xtv);
 		SYSIO_INTERFACE_RETURN(IOID_FAIL, err);
 	}
-	SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0);
+	SYSIO_INTERFACE_RETURN(ioctx, 0);
 }
 
 #if _LARGEFILE64_SOURCE
@@ -693,7 +693,7 @@ PREPEND(_, SYSIO_INTERFACE_NAME(ireadx))(int fd,
 			NULL,
 			&ioctx);
 
-	SYSIO_INTERFACE_RETURN(err ? IOID_FAIL : ioctx->ioctx_id, err);
+	SYSIO_INTERFACE_RETURN(err ? IOID_FAIL : ioctx, err);
 }
 
 #if _LARGEFILE64_SOURCE
@@ -743,7 +743,7 @@ SYSIO_INTERFACE_NAME(ireadx)(int fd,
 		free(ixtv);
 		SYSIO_INTERFACE_RETURN(IOID_FAIL, err);
 	}
-	SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0);
+	SYSIO_INTERFACE_RETURN(ioctx, 0);
 }
 #else
 #undef ireadx
@@ -833,7 +833,7 @@ SYSIO_INTERFACE_NAME(iwritev)(int fd,
 		free(xtv);
 		SYSIO_INTERFACE_RETURN(IOID_FAIL, err);
 	}
-	SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0);
+	SYSIO_INTERFACE_RETURN(ioctx, 0);
 }
 
 ssize_t
@@ -909,7 +909,7 @@ SYSIO_INTERFACE_NAME(iwrite)(int fd, const void *buf, size_t count)
 		free(iov);
 		SYSIO_INTERFACE_RETURN(IOID_FAIL, err);
 	}
-	SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0);
+	SYSIO_INTERFACE_RETURN(ioctx, 0);
 }
 
 ssize_t
@@ -983,7 +983,7 @@ PREPEND(_, SYSIO_INTERFACE_NAME(ipwritev))(int fd,
 		free(xtv);
 		SYSIO_INTERFACE_RETURN(IOID_FAIL, err);
 	}
-	SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0);
+	SYSIO_INTERFACE_RETURN(ioctx, 0);
 }
 
 #if _LARGEFILE64_SOURCE
@@ -1097,7 +1097,7 @@ error:
 			free(xtv);
 		SYSIO_INTERFACE_RETURN(IOID_FAIL, err);
 	}
-	SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0);
+	SYSIO_INTERFACE_RETURN(ioctx, 0);
 }
 
 #if _LARGEFILE64_SOURCE
@@ -1212,7 +1212,7 @@ PREPEND(_, SYSIO_INTERFACE_NAME(iwritex))(int fd,
 			NULL,
 			&ioctx);
 
-	SYSIO_INTERFACE_RETURN(err ? IOID_FAIL : ioctx->ioctx_id, err);
+	SYSIO_INTERFACE_RETURN(err ? IOID_FAIL : ioctx, err);
 }
 
 #if _LARGEFILE64_SOURCE
@@ -1262,7 +1262,7 @@ SYSIO_INTERFACE_NAME(iwritex)(int fd,
 		free(ixtv);
 		SYSIO_INTERFACE_RETURN(IOID_FAIL, err);
 	}
-	SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0);
+	SYSIO_INTERFACE_RETURN(ioctx, 0);
 }
 #else
 #undef iwritex
diff --git a/libsysio/src/stdlib.c b/libsysio/src/stdlib.c
index 7446f357f77f197294c6cdba4403bb50c084e7c7..fcd463a9cb3b41bccf18717015a5dcfcac46e20a 100644
--- a/libsysio/src/stdlib.c
+++ b/libsysio/src/stdlib.c
@@ -215,6 +215,7 @@ void rewinddir(DIR *dir)
 	dir->effective = 0;
 }
 
+#if 0
 int scandir(const char *dir, struct dirent ***namelist,
             int(*select)(const struct dirent *),
             int(*compar)(const void *, const void *))
@@ -230,6 +231,7 @@ int scandir64(const char *dir, struct dirent64 ***namelist,
 	errno = ENOSYS;
 	return -1;
 }
+#endif
 
 /***********************************************************
  * FIXME workaround for linux only                         *
diff --git a/libsysio/tests/helper.pm b/libsysio/tests/helper.pm
index 306c40e273e337f3238c1ef8020ea4138501e23f..f656867f32dcc32b5838d059b89c6f495a7c70a8 100644
--- a/libsysio/tests/helper.pm
+++ b/libsysio/tests/helper.pm
@@ -26,7 +26,10 @@ sub print_and_exit
   print $cmdfh $cmdstr;
 
   my $res = <$outfh>;
-  chop($res);
+	if (defined $res) {
+		chop($res);
+	} 
+
 
   print $cmdfh "exit\n";
   close $outfh;
@@ -47,7 +50,12 @@ sub send_cmd
   print $cmdfh $cmdstr;
 
   my $res = <$outfh>;
-  chop($res);
+	if (defined $res) {
+		chop($res);
+	} else {
+		print_and_exit($cmdfh, $outfh, 1, "ERROR! Cmd $cmdstr returned null value!\n");
+	}
+
   if ($res ne "0000 ") {
     print_and_exit($cmdfh, $outfh, 1, "ERROR! Command $cmd failed with code $res\n");
   }
@@ -65,7 +73,11 @@ sub verify_cmd
   send_cmd($cmdfh, $outfh, "PRINT", $cmdstr);  
 
   my $res = <$outfh>;
-  chop($res);
+	if (defined $res) {
+		chop($res);
+	} else {
+		print_and_exit($cmdfh, $outfh, 1, "ERROR! Cmd $cmdstr returned null value!\n");
+	}
 
   if ($res eq "0xffffffff") {
      
@@ -75,7 +87,12 @@ sub verify_cmd
     send_cmd($cmdfh, $outfh, "PRINT", $cmdstr);
     
     my $err = <$outfh>;
-    chop($err);
+		if (defined $err) {
+			chop($err);
+		} else {
+			print_and_exit($cmdfh, $outfh, 1, "ERROR! Cmd $cmdstr returned null value!\n");
+		}
+
     print_and_exit($cmdfh, $outfh, 1, "ERROR!  $cmd returned $err\n");
   }
   return $res;
diff --git a/libsysio/tests/startup.c b/libsysio/tests/startup.c
index 54c56d12fa9cf50ad5416224bf67d6e6ce2201ef..82a92cbea557574faf66be5a4f6f90fc8375c0d8 100644
--- a/libsysio/tests/startup.c
+++ b/libsysio/tests/startup.c
@@ -1,12 +1,14 @@
 #include <stdlib.h>
+#include <string.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/queue.h>
 
-#include "sysio.h"
-
+#include "xtio.h"
 #include "test.h"
 
+#include "sysio.h"
+
 int
 _test_sysio_startup()
 {
@@ -20,8 +22,30 @@ _test_sysio_startup()
 	if (err)
 		return err;
 	s = getenv("SYSIO_NAMESPACE");
-	err = s ? _sysio_boot(s) : -ENOTTY;
+	if (s)
+		err = _sysio_boot(s);
+	else if (!(s = getenv("SYSIO_MANUAL"))) {
+		/*
+		 * Assume a native mount at root.
+		 */
+		err = _sysio_boot("{mnt,dev=\"native:/\",dir=/,fl=0}");
+	}
 	if (err)
 		return err;
+
+	s = getenv("SYSIO_CWD");
+	if (s) {
+		err = chdir(s);
+		if (err)
+			return err;
+	}
+
 	return 0;
 }
+
+void
+_test_sysio_shutdown()
+{
+
+	_sysio_shutdown();
+}
diff --git a/libsysio/tests/sysio_stubs.c b/libsysio/tests/sysio_stubs.c
index 2fc50462ea43b4d21683760f13496cbce1529542..439804d6e64faf7f778d8626b0346812ff0ecc18 100644
--- a/libsysio/tests/sysio_stubs.c
+++ b/libsysio/tests/sysio_stubs.c
@@ -10,10 +10,11 @@
 #include <sys/mount.h>
 #include <sys/stat.h>
 #include <sys/statvfs.h>
+#include <sys/queue.h>
 
-#include "test_driver.h"
-#include "sysio.h"
 #include "xtio.h"
+#include "sysio.h"
+#include "test_driver.h"
 
 /*
  * ################################################
diff --git a/libsysio/tests/sysio_tests.c b/libsysio/tests/sysio_tests.c
index 8f2f30145130fbe3be38e46afe5d1a8015bf3a1b..4077996f5e9ea0619fa576714aaa8902df5c5456 100644
--- a/libsysio/tests/sysio_tests.c
+++ b/libsysio/tests/sysio_tests.c
@@ -11,9 +11,11 @@
 #include <sys/statvfs.h>
 #include <fcntl.h>
 #include <sys/queue.h>
+#include <unistd.h>
 #include <dirent.h>
+#include <sys/mount.h>
 
-#include "sysio.h"
+#include "xtio.h"
 #include "mount.h"
 #include "test.h"
 #include "test_driver.h"
diff --git a/libsysio/tests/test.h b/libsysio/tests/test.h
index 335780289e63582bd446236ff45f3fc6685abd10..781d59b88b2af4424896b0eec428cba96cb03319 100644
--- a/libsysio/tests/test.h
+++ b/libsysio/tests/test.h
@@ -44,3 +44,5 @@
 extern int (*drvinits[])(void);
 
 extern int drv_init_all(void);
+extern int _test_sysio_startup(void);
+extern void _test_sysio_shutdown(void);
diff --git a/libsysio/tests/test_all.pl b/libsysio/tests/test_all.pl
index 25586ba844ec89b74aa1d2ccce67df5f00707c09..65bf40e94e4f9ddd00ea81e1114c3e2948b927e6 100755
--- a/libsysio/tests/test_all.pl
+++ b/libsysio/tests/test_all.pl
@@ -62,8 +62,11 @@ $ENV{$namespace_env} = "\
 	{creat,	ft=chr,nm=\"/dev/stderr\",pm=0200,mm=0+2} \
 	{creat,	ft=dir,nm=\"/dev/fd\",pm=0755,ow=0,gr=0} \
 	{creat,	ft=chr,nm=\"/dev/fd/0\",pm=0400,mm=0+0} \
+	{open,  nm=\"/dev/fd/0\",fd=0,m=0} \
 	{creat,	ft=chr,nm=\"/dev/fd/1\",pm=0200,mm=0+1} \
+	{open,  nm=\"/dev/fd/1\",fd=1,m=1} \
 	{creat,	ft=chr,nm=\"/dev/fd/2\",pm=0200,mm=0+2} \
+	{open,  nm=\"/dev/fd/2\",fd=2,m=1} \
 	{cd,	dir=\"$home\"} \
 	$extras ";
 
diff --git a/libsysio/tests/test_copy.c b/libsysio/tests/test_copy.c
index bda0bd2483a22d89f4e8335ded7491dffccf7c66..9ac97b170ca6665781e477d98d6834f5732ec0e4 100644
--- a/libsysio/tests/test_copy.c
+++ b/libsysio/tests/test_copy.c
@@ -46,20 +46,14 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#ifndef REDSTORM
-#include <getopt.h>
-#endif
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <sys/uio.h>
 #include <sys/queue.h>
 
-#include "sysio.h"
-#include "mount.h"
-
-#include "fs_native.h"
-
+#include "xtio.h"
 #include "test.h"
 
 /*
@@ -81,7 +75,6 @@ main(int argc, char * const argv[])
 	int	i;
 	int	err;
 	const char *spath, *dpath;
-	extern int _test_sysio_startup(void);
 
 	/*
 	 * Parse command-line args.
@@ -123,7 +116,7 @@ main(int argc, char * const argv[])
 
 	err = copy_file(spath, dpath);
 
-	_sysio_shutdown();
+	_test_sysio_shutdown();
 
 	return err;
 }
diff --git a/libsysio/tests/test_driver.c b/libsysio/tests/test_driver.c
index 943cd8532c603373eefedad9a27a9c98371b8481..cbc6415856833428745c842d8ae7a18c25874649 100644
--- a/libsysio/tests/test_driver.c
+++ b/libsysio/tests/test_driver.c
@@ -1,5 +1,9 @@
+#ifndef _BSD_SOURCE
 #define _BSD_SOURCE
-#define _XOPEN_SOURCE 600
+#endif
+#ifndef _XOPEN_SOURCE
+#define _XOPEN_SOURCE 500
+#endif
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -11,12 +15,13 @@
 #include <sys/uio.h>
 #include <sys/statvfs.h>
 #include <fcntl.h>
-#include <sys/queue.h>
 #include <dirent.h>
 #include <unistd.h>
 #include <ctype.h>
+#include <sys/uio.h>
+#include <sys/queue.h>
 
-#include "sysio.h"
+#include "xtio.h"
 #include "mount.h"
 #include "test.h"
 #include "test_driver.h"
@@ -968,11 +973,6 @@ int main(int argc, char *argv[])
    */
   err = _test_sysio_startup();
   
-	/* Temp. hack until I do the right thing to fix this...*/
-	open("/dev/stdin",O_RDONLY); 
-	open("/dev/stdout",O_WRONLY); 
-	open("/dev/stderr",O_WRONLY);
- 
   infp = stdin;
   outfp = stdout;
 
diff --git a/libsysio/tests/test_getcwd.c b/libsysio/tests/test_getcwd.c
index 340180eea48d9c8fb5d0fae4fb79afa17c23d093..8cd160d95c8eb24403b31af5d62cd2fb58009d5e 100644
--- a/libsysio/tests/test_getcwd.c
+++ b/libsysio/tests/test_getcwd.c
@@ -44,19 +44,16 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifndef REDSTORM
-#include <getopt.h>
-#else
 #include <unistd.h>
-#endif
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <sys/uio.h>
 #include <sys/queue.h>
 #include <dirent.h>
 
-#include "sysio.h"
+#include "xtio.h"
 #include "mount.h"
 
 #include "test.h"
@@ -137,7 +134,7 @@ main(int argc, char *const argv[])
 	/*
 	 * Clean up.
 	 */
-	_sysio_shutdown();
+	_test_sysio_shutdown();
 
 	return 0;
 }
diff --git a/libsysio/tests/test_getcwd.pl b/libsysio/tests/test_getcwd.pl
index 94f33a3a533a96a04b69d79b889fb3c834098b0f..4255a328fa8f8a00c5095cb5ba26ef6f9f996fd1 100755
--- a/libsysio/tests/test_getcwd.pl
+++ b/libsysio/tests/test_getcwd.pl
@@ -6,7 +6,7 @@ use strict;
 use FindBin;
 use lib "$FindBin::Bin";
 use helper;
-use Fcntl ':mode';
+use Fcntl;
 
 
 sub usage
diff --git a/libsysio/tests/test_link.c b/libsysio/tests/test_link.c
index ab4106f0d9aac1232e126726be2105c5a34c4300..218dd49e7cab703f872816ade70c1111b04aee7c 100644
--- a/libsysio/tests/test_link.c
+++ b/libsysio/tests/test_link.c
@@ -44,21 +44,17 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifndef REDSTORM
-#include <getopt.h>
-#endif
 #include <unistd.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/queue.h>
 #if 0
 #include <dirent.h>
 #endif
+#include <sys/uio.h>
+#include <sys/queue.h>
 
-#include "sysio.h"
-#include "mount.h"
-
+#include "xtio.h"
 #include "test.h"
 
 /*
@@ -123,7 +119,7 @@ main(int argc, char *const argv[])
 	/*
 	 * Clean up.
 	 */
-	_sysio_shutdown();
+	_test_sysio_shutdown();
 
 	return err ? -1 : 0;
 }
diff --git a/libsysio/tests/test_list.c b/libsysio/tests/test_list.c
index 4dc0a82a720c33e3fb774ebbbcf938bf6a8a3b26..292bb5447b30ee779640cf43a6838e430fe76162 100644
--- a/libsysio/tests/test_list.c
+++ b/libsysio/tests/test_list.c
@@ -41,24 +41,21 @@
  * lee@sandia.gov
  */
 
+#define _BSD_SOURCE
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifndef REDSTORM
-#include <getopt.h>
-#else
 #include <unistd.h>
-#endif
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <sys/queue.h>
 #include <dirent.h>
+#include <sys/uio.h>
+#include <sys/queue.h>
 
-#include "sysio.h"
-#include "mount.h"
-
+#include "xtio.h"
 #include "test.h"
 
 /*
@@ -138,7 +135,7 @@ main(int argc, char *const argv[])
 	/*
 	 * Clean up.
 	 */
-	_sysio_shutdown();
+	_test_sysio_shutdown();
 
 	return 0;
 }
diff --git a/libsysio/tests/test_path.c b/libsysio/tests/test_path.c
index a7469b3749045db3750ad1712b5fbb02d42c44fc..80cc74e4a5ef46985568cd06f78cc02b052985e2 100644
--- a/libsysio/tests/test_path.c
+++ b/libsysio/tests/test_path.c
@@ -41,24 +41,18 @@
  * lee@sandia.gov
  */
 
+#define _BSD_SOURCE
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifndef REDSTORM
-#include <getopt.h>
-#else
-#include <unistd.h>
-#endif
 #include <errno.h>
-
-#include <assert.h>
-#include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <unistd.h>
+#include <sys/uio.h>
 
-#include "sysio.h"
-#include "mount.h"
-
+#include "xtio.h"
 #include "test.h"
 
 /*
@@ -138,7 +132,7 @@ main(int argc, char *const argv[])
 	/*
 	 * Clean up.
 	 */
-	_sysio_shutdown();
+	_test_sysio_shutdown();
 
 	return 0;
 }
diff --git a/libsysio/tests/test_path.pl b/libsysio/tests/test_path.pl
index c68fdc8e46220480b3be66354decbcd744b88080..67bdf737e64b70d12e89b7003fc5826e456694dc 100755
--- a/libsysio/tests/test_path.pl
+++ b/libsysio/tests/test_path.pl
@@ -12,7 +12,7 @@ use FindBin;
 use lib "$FindBin::Bin";
 use helper;
 use POSIX;
-use Fcntl ':mode';
+use Fcntl;
 
 sub usage
 {
diff --git a/libsysio/tests/test_regions.c b/libsysio/tests/test_regions.c
index c6120daa394e33b861f278f864609ea8c2d9c53b..ba78800a2799dc4d2feeab1957ac16e04a0c400c 100644
--- a/libsysio/tests/test_regions.c
+++ b/libsysio/tests/test_regions.c
@@ -58,19 +58,14 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#ifndef REDSTORM
-#include <getopt.h>
-#endif
 #include <limits.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <sys/queue.h>
-
-#include "sysio.h"
-#include "mount.h"
+#include <sys/uio.h>
 
+#include "xtio.h"
 #include "test.h"
 
 /*
@@ -278,7 +273,7 @@ error:
 		perror(path);
 	free(buf);
 out:
-	_sysio_shutdown();
+	_test_sysio_shutdown();
 
 	return err;
 }
diff --git a/libsysio/tests/test_rename.c b/libsysio/tests/test_rename.c
index 7b784294d184f477b97ca00f309e49ac13599ab6..8bc2ec821001a87c6b049972af47b10155bce6eb 100644
--- a/libsysio/tests/test_rename.c
+++ b/libsysio/tests/test_rename.c
@@ -46,20 +46,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#ifndef REDSTORM
-#include <getopt.h>
-#endif
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <sys/queue.h>
-
-#include "sysio.h"
-#include "mount.h"
-
-#include "fs_native.h"
+#include <sys/uio.h>
 
+#include "xtio.h"
 #include "test.h"
 
 /*
@@ -121,7 +114,7 @@ main(int argc, char * const argv[])
 	if (err)
 		perror("rename");
 
-	_sysio_shutdown();
+	_test_sysio_shutdown();
 
 	return err;
 }
diff --git a/libsysio/tests/test_stats.c b/libsysio/tests/test_stats.c
index 2865a02d2a0f4b7d85450992508d119775d96765..951e7cfbda3554f5170f5299dbba702d83896d0e 100644
--- a/libsysio/tests/test_stats.c
+++ b/libsysio/tests/test_stats.c
@@ -46,21 +46,16 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#ifndef REDSTORM
-#include <getopt.h>
-#endif
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <sys/queue.h>
 #ifdef notdef
 #include <sys/statvfs.h>
 #endif
+#include <sys/uio.h>
 
-#include "sysio.h"
-#include "mount.h"
-
+#include "xtio.h"
 #include "test.h"
 
 /*
@@ -104,7 +99,7 @@ main(int argc, char * const argv[])
 	/*
 	 * Clean up.
 	 */
-	_sysio_shutdown();
+	_test_sysio_shutdown();
 
 	return 0;
 }
diff --git a/libsysio/tests/test_unlink.c b/libsysio/tests/test_unlink.c
index 9d019d56bc7cc89d6726ba01c42c2ee89a2ebac6..d168b28ce1285a1d278a472a7053e4b8aa8dc271 100644
--- a/libsysio/tests/test_unlink.c
+++ b/libsysio/tests/test_unlink.c
@@ -44,21 +44,15 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifndef REDSTORM
-#include <getopt.h>
-#else
 #include <unistd.h>
-#endif
 #include <errno.h>
 #include <sys/types.h>
-#include <sys/queue.h>
 #if 0
 #include <dirent.h>
 #endif
+#include <sys/uio.h>
 
-#include "sysio.h"
-#include "mount.h"
-
+#include "xtio.h"
 #include "test.h"
 
 /*
@@ -138,7 +132,7 @@ main(int argc, char *const argv[])
 	/*
 	 * Clean up.
 	 */
-	_sysio_shutdown();
+	_test_sysio_shutdown();
 
 	return 0;
 }