[Libsysio-commit] RedStorm: libsysio/drivers/native fs_native.c
Brought to you by:
lward
|
From: Lee W. <lw...@us...> - 2003-05-12 11:48:48
|
Update of /cvsroot/libsysio/libsysio/drivers/native
In directory sc8-pr-cvs1:/tmp/cvs-serv27060/drivers/native
Modified Files:
Tag: RedStorm
fs_native.c
Log Message:
Modifications for the Cray RedStorm compute node operating system. This is
a BSD-based libc.
Index: fs_native.c
===================================================================
RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v
retrieving revision 1.11
retrieving revision 1.11.4.1
diff -u -w -b -B -p -r1.11 -r1.11.4.1
--- fs_native.c 23 Apr 2003 18:18:38 -0000 1.11
+++ fs_native.c 12 May 2003 11:48:45 -0000 1.11.4.1
@@ -57,8 +57,12 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
+#if 0
#include <sys/vfs.h>
+#endif
+#ifdef _HAVE_STATVFS
#include <sys/statvfs.h>
+#endif
#include <utime.h>
#include <sys/queue.h>
@@ -133,12 +137,6 @@ do {
#define __SYS_FTRUNCATE SYS_ftruncate64
#endif
-#if defined(USE_NATIVE_FDATASYNC)
-#define __SYS_FDATASYNC SYS_osf_fdatasync
-#else
-#define __SYS_FDATASYNC SYS_fdatasync
-#endif
-
#if defined(USE_NATIVE_UTIME)
#define __SYS_UTIME SYS_utimes
#else
@@ -182,7 +180,7 @@ static int native_inop_setattr(struct pn
static ssize_t native_getdirentries(struct inode *ino,
char *buf,
size_t nbytes,
- off64_t *basep);
+ _SYSIO_OFF_T *basep);
static int native_inop_mkdir(struct pnode *pno, mode_t mode);
static int native_inop_rmdir(struct pnode *pno);
static int native_inop_symlink(struct pnode *pno, const char *data);
@@ -204,9 +202,11 @@ static int native_inop_ioctl(struct inod
unsigned long int request,
va_list ap);
static int native_inop_mknod(struct pnode *pno, mode_t mode, dev_t dev);
+#ifdef _HAVE_STATVFS
static int native_inop_statvfs(struct pnode *pno,
struct inode *ino,
struct intnl_statvfs *buf);
+#endif
static void native_inop_gone(struct inode *ino);
static struct inode_ops native_i_ops = {
@@ -229,7 +229,9 @@ static struct inode_ops native_i_ops = {
native_inop_datasync,
native_inop_ioctl,
native_inop_mknod,
+#ifdef _HAVE_STATVFS
native_inop_statvfs,
+#endif
native_inop_gone
};
@@ -774,28 +776,75 @@ out:
return err;
}
+static int
+native_pos(int fd,
+#ifdef _LARGEFILE64_SOURCE
+ loff_t *offset
+#else
+ _SYSIO_OFF_T *offset
+#endif
+ )
+{
+
+ assert(fd >= 0);
+ assert(*offset >= 0);
+
+#ifdef _LARGEFILE64_SOURCE
+ {
+ int err;
+ err =
+ syscall(SYS_llseek,
+ (unsigned int)nino->ni_fd,
+ (unsigned int)*offset >> 32,
+ (unsigned int)*offset,
+ offset,
+ SEEK_SET);
+ if (err == -1)
+ return -errno;
+ }
+#else
+ *offset =
+ syscall(SYS_lseek,
+ fd,
+ *offset,
+ SEEK_SET);
+ if (*offset == -1)
+ return -errno;
+#endif
+
+ return 0;
+}
+
+
static ssize_t
native_getdirentries(struct inode *ino,
char *buf,
size_t nbytes,
- off64_t *basep)
+ _SYSIO_OFF_T *basep)
{
struct native_inode *nino = I2NI(ino);
+ int err;
+#ifdef _LARGEFILE64_SOURCE
loff_t result;
+#else
+ _SYSIO_OFF_T result;
+#endif
ssize_t cc;
assert(nino->ni_fd >= 0);
result = *basep;
- if (*basep != nino->ni_fpos &&
- syscall(SYS_lseek,
- nino->ni_fd,
- *basep,
- &result,
- SEEK_SET) == -1)
- return -errno;
+ if (*basep != nino->ni_fpos) {
+ err = native_pos(nino->ni_fd, &result);
+ if (err)
+ return err;
+ }
nino->ni_fpos = result;
+#ifndef USE_NATURAL_GETDENTS
cc = syscall(SYS_getdents64, nino->ni_fd, buf, nbytes);
+#else
+ cc = syscall(SYS_getdents, nino->ni_fd, buf, nbytes);
+#endif
if (cc < 0)
return -errno;
nino->ni_fpos += cc;
@@ -1002,13 +1051,14 @@ doio(ssize_t (*f)(int, const struct iove
{
struct native_inode *nino = I2NI(ino);
struct ioctx *ioctx;
+#ifdef _LARGEFILE64_SOURCE
loff_t result;
+#else
+ _SYSIO_OFF_T result;
+#endif
assert(nino->ni_fd >= 0);
- if (ioargs->ioarg_iovlen && (int )ioargs->ioarg_iovlen < 0)
- return -EINVAL;
-
/*
* Get a new IO context.
*/
@@ -1016,9 +1066,15 @@ doio(ssize_t (*f)(int, const struct iove
if (!ioctx)
return -ENOMEM;
+ if ((ioargs->ioarg_iovlen && (int )ioargs->ioarg_iovlen < 0) ||
+ !(S_ISCHR(ino->i_mode) ||
+ S_ISSOCK(ino->i_mode) ||
+ S_ISFIFO(ino->i_mode)))
+ return -EINVAL;
+
/*
* This implementation first positions the real system descriptor, then
- * performs the operation. This is silly because it's not atomic.
+ * performs the operation. This is not atomic.
*
* An alternative, more complex, less efficient but atomic,
* implementation might consider each entry of the iovec separately.
@@ -1029,18 +1085,17 @@ doio(ssize_t (*f)(int, const struct iove
* Allows us to access pipes and fifos.
*/
result = nino->ni_fpos;
- if (ioctx->ioctx_offset != nino->ni_fpos &&
- !(S_ISCHR(ino->i_mode) ||
- S_ISSOCK(ino->i_mode) ||
- S_ISFIFO(ino->i_mode)) &&
- syscall(SYS_lseek,
- nino->ni_fd,
- ioctx->ioctx_offset,
- &result,
- SEEK_SET) == -1) {
+ if (ioctx->ioctx_offset != nino->ni_fpos) {
+ int err;
+
+ err = native_pos(nino->ni_fd, &result);
+ if (err) {
ioctx->ioctx_cc = -1;
- ioctx->ioctx_errno = errno;
- } else {
+ ioctx->ioctx_errno = -err;
+ goto out;
+ }
+ }
+
/*
* Call the appropriate (read/write) IO function to
* transfer the data now.
@@ -1052,9 +1107,9 @@ doio(ssize_t (*f)(int, const struct iove
ioctx->ioctx_errno = errno;
if (ioctx->ioctx_cc > 0)
nino->ni_fpos += ioctx->ioctx_cc;
- }
*ioctxp = ioctx;
+out:
return 0;
}
@@ -1128,6 +1183,7 @@ native_inop_mknod(struct pnode *pno __IS
return -ENOSYS;
}
+#ifdef _HAVE_STATVFS
static int
native_inop_statvfs(struct pnode *pno,
struct inode *ino,
@@ -1173,6 +1229,7 @@ native_inop_statvfs(struct pnode *pno,
buf->f_namemax = fs.f_namelen;
return 0;
}
+#endif
static int
native_inop_sync(struct inode *ino)
@@ -1189,7 +1246,12 @@ native_inop_datasync(struct inode *ino)
assert(I2NI(ino)->ni_fd >= 0);
- return syscall(__SYS_FDATASYNC, I2NI(ino)->ni_fd);
+#ifdef NATIVE_FDATASYNC
+ return syscall(NATIVE_FDATASYNC, I2NI(ino)->ni_fd);
+#else
+#warning No fdatasync system call -- Using fsync instead!
+ return syscall(SYS_fsync, I2NI(ino)->ni_fd);
+#endif
}
static int
|