snmptag="HEAD"
portalstag="b_hd_newconfig"
lnettag="b_hd_newconfig"
+ # XXX temorary tag until b1_5* is updated from b1_4 liblustre
+ libsysiotag="HEAD_RELEASE_1_4_6_LAND_PARENT_20060223_1455"
;;
b_cmd*)
snmptag="HEAD"
portalstag="b_hd_newconfig"
lnettag="b_hd_newconfig"
+ # XXX temorary tag until b_iam* is updated from b1_4 liblustre
+ libsysiotag="HEAD_RELEASE_1_4_6_LAND_PARENT_20060223_1455"
;;
b_ioprovement)
#include <sys/stat.h>
#include <sys/queue.h>
-#include "xtio.h"
#include "sysio.h"
+#include "xtio.h"
#include "native.h"
#include "inode.h"
#include "dev.h"
#endif
#include <sys/queue.h>
-#include "xtio.h"
#include "sysio.h"
+#include "xtio.h"
#include "fs.h"
#include "mount.h"
#include "inode.h"
struct inode *ino,
unsigned mask,
struct intnl_stat *stbuf);
-static ssize_t _sysio_incore_dirop_getdirentries(struct inode *ino,
- char *buf,
- size_t nbytes,
- _SYSIO_OFF_T *basep);
+static ssize_t _sysio_incore_dirop_filldirentries(struct inode *ino,
+ _SYSIO_OFF_T *posp,
+ char *buf,
+ size_t nbytes);
static int _sysio_incore_dirop_mkdir(struct pnode *pno, mode_t mode);
static int _sysio_incore_dirop_rmdir(struct pnode *pno);
static int _sysio_incore_inop_open(struct pnode *pno, int flags, mode_t mode);
_sysio_incore_dirop_lookup,
_sysio_incore_inop_getattr,
_sysio_incore_inop_setattr,
- _sysio_incore_dirop_getdirentries,
+ _sysio_incore_dirop_filldirentries,
_sysio_incore_dirop_mkdir,
_sysio_incore_dirop_rmdir,
_sysio_incore_dirop_symlink,
struct inode **, \
struct intent *, \
const char *))_sysio_do_illop
-#define _sysio_incore_filop_getdirentries \
+#define _sysio_incore_filop_filldirentries \
(ssize_t (*)(struct inode *, \
- char *, \
- size_t, \
- _SYSIO_OFF_T *))_sysio_do_illop
+ _SYSIO_OFF_T *, \
+ char *, \
+ size_t))_sysio_do_illop
#define _sysio_incore_filop_mkdir \
(int (*)(struct pnode *, mode_t))_sysio_do_illop
#define _sysio_incore_filop_rmdir \
_sysio_incore_filop_lookup,
_sysio_incore_inop_getattr,
_sysio_incore_inop_setattr,
- _sysio_incore_filop_getdirentries,
+ _sysio_incore_filop_filldirentries,
_sysio_incore_filop_mkdir,
_sysio_incore_filop_rmdir,
_sysio_incore_filop_symlink,
_sysio_incore_filop_lookup,
_sysio_incore_inop_getattr,
_sysio_incore_inop_setattr,
- _sysio_incore_filop_getdirentries,
+ _sysio_incore_filop_filldirentries,
_sysio_incore_filop_mkdir,
_sysio_incore_filop_rmdir,
_sysio_incore_filop_symlink,
}
static ssize_t
-_sysio_incore_dirop_getdirentries(struct inode *ino,
- char *buf,
- size_t nbytes,
- _SYSIO_OFF_T *basep)
+_sysio_incore_dirop_filldirentries(struct inode *ino,
+ _SYSIO_OFF_T *posp,
+ char *buf,
+ size_t nbytes)
{
struct incore_inode *icino = I2IC(ino);
off_t off;
struct intnl_dirent *de;
struct copy_info copy_info;
- if (*basep > icino->ici_st.st_size)
+ if (*posp >= icino->ici_st.st_size)
return 0;
de =
incore_directory_probe(icino->ici_data,
icino->ici_st.st_size,
- *basep,
+ *posp,
(probe_ty )incore_directory_position,
NULL,
- (char *)icino->ici_data + *basep);
+ (char *)icino->ici_data + *posp);
if (!de) {
/*
* Past EOF.
*/
- *basep = 0;
return 0;
}
icino->ici_st.st_atime = time(NULL);
if (!nbytes)
return -EOVERFLOW;
- *basep = nbytes;
+ *posp += nbytes;
return (ssize_t )nbytes;
}
#include <sys/uio.h>
#include <sys/queue.h>
-#include "xtio.h"
#include "sysio.h"
+#include "xtio.h"
#include "native.h"
#include "fs.h"
#include "mount.h"
#endif
#if defined(SYSIO_SYS_getdirentries)
-#define DIR_STREAMED 0
#define DIR_CVT_64 0
#elif defined(SYSIO_SYS_getdents64)
-#define DIR_STREAMED 1
#define DIR_CVT_64 0
#elif defined(SYSIO_SYS_getdents)
-#define DIR_STREAMED 1
#if defined(_LARGEFILE64_SOURCE)
#define DIR_CVT_64 1
/*
struct native_inode {
unsigned
ni_seekok : 1, /* can seek? */
- ni_attrvalid : 1; /* cached attrs ok? */
+ ni_attrvalid : 1, /* cached attrs ok? */
+ ni_resetfpos : 1; /* reset fpos? */
struct native_inode_identifier ni_ident; /* unique identifier */
struct file_identifier ni_fileid; /* ditto */
int ni_fd; /* host fildes */
struct inode *ino,
unsigned mask,
struct intnl_stat *stbuf);
-static ssize_t native_getdirentries(struct inode *ino,
- char *buf,
- size_t nbytes,
- _SYSIO_OFF_T *basep);
+static ssize_t native_filldirentries(struct inode *ino,
+ _SYSIO_OFF_T *posp,
+ char *buf,
+ size_t nbytes);
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);
native_inop_lookup,
native_inop_getattr,
native_inop_setattr,
- native_getdirentries,
+ native_filldirentries,
native_inop_mkdir,
native_inop_rmdir,
native_inop_symlink,
return NULL;
bzero(&nino->ni_ident, sizeof(nino->ni_ident));
nino->ni_seekok = 0;
+ nino->ni_attrvalid = 0;
+ nino->ni_resetfpos = 0;
nino->ni_ident.dev = buf->st_dev;
nino->ni_ident.ino = buf->st_ino;
#ifdef HAVE_GENERATION
_sysio_pb_gone(rootpb);
if (fs) {
FS_RELE(fs);
- _sysio_fs_gone(fs);
nfs = NULL;
}
if (nfs)
}
static ssize_t
-native_filldirentries(struct native_inode *nino,
- char *buf,
- size_t nbytes,
- _SYSIO_OFF_T *basep)
+native_ifilldirentries(struct native_inode *nino,
+ _SYSIO_OFF_T *posp,
+ char *buf,
+ size_t nbytes)
{
int err;
ssize_t cc;
+#if defined(SYSIO_SYS_getdirentries)
+ _SYSIO_OFF_T waste;
+#endif
- if (*basep < 0)
+ if (*posp < 0)
return -EINVAL;
-#if DIR_STREAMED
/*
* Stream-oriented access requires that we reposition prior to the
* fill call.
*/
- if ((err = native_pos(nino->ni_fd, basep, SEEK_SET)) != 0)
- return err;
-#endif
- nino->ni_fpos = *basep;
+ assert(nino->ni_seekok);
+ if (*posp != nino->ni_fpos || nino->ni_resetfpos) {
+ nino->ni_fpos = *posp;
+ err = native_pos(nino->ni_fd, &nino->ni_fpos, SEEK_SET);
+ if (err) {
+ nino->ni_resetfpos = 1;
+ return err;
+ }
+ nino->ni_resetfpos = 0;
+ }
cc =
#if defined(SYSIO_SYS_getdirentries)
nino->ni_fd,
buf,
nbytes,
- basep);
+ &waste);
#elif defined(SYSIO_SYS_getdents64)
syscall(SYSIO_SYS_getdents64, nino->ni_fd, buf, nbytes);
#elif defined(SYSIO_SYS_getdents)
if (cc < 0)
return -errno;
-#if DIR_STREAMED
/*
* Stream-oriented access requires that we discover where we are
* after the call.
*/
- *basep = 0;
- if ((err = native_pos(nino->ni_fd, basep, SEEK_CUR)) != 0)
+ if ((err = native_pos(nino->ni_fd, &nino->ni_fpos, SEEK_CUR)) != 0) {
+ /*
+ * Leave the position at the old I suppose.
+ */
+ nino->ni_resetfpos = 1;
return err;
-#endif
- nino->ni_fpos = *basep;
+ }
+ *posp = nino->ni_fpos;
return cc;
}
static ssize_t
-native_getdirentries(struct inode *ino,
- char *buf,
- size_t nbytes,
- _SYSIO_OFF_T *basep)
+native_filldirentries(struct inode *ino,
+ _SYSIO_OFF_T *posp,
+ char *buf,
+ size_t nbytes)
{
struct native_inode *nino = I2NI(ino);
#if DIR_CVT_64
struct dirent64 *d64p;
size_t namlen;
size_t reclen;
- /*
- * Work-around for broken 64 bit basep update
- * Get value of basep to return from last directory
- * entry d_off value
- */
- _SYSIO_OFF_T last_offset = *basep;
#else
#define bp buf
#define count nbytes
return -ENOMEM;
}
#endif
- cc = native_filldirentries(nino, bp, count, basep);
+ cc = native_ifilldirentries(nino, posp, bp, count);
if (cc < 0) {
#if DIR_CVT_64
free(bp);
#if DIR_CVT_64
ldp = (struct linux_dirent *)bp;
d64p = (struct dirent64 *)buf;
- for (;;) {
- if (cc < 0 || (size_t )cc <= sizeof(*ldp))
- break;
+ while (cc) {
namlen = strlen(ldp->ld_name);
- reclen = sizeof(*d64p) - sizeof(d64p->d_name) + namlen + 1;
- if (nbytes < reclen)
+ reclen = sizeof(*d64p) - sizeof(d64p->d_name) + namlen;
+ if (nbytes <= reclen)
break;
d64p->d_ino = ldp->ld_ino;
- d64p->d_off = ldp->ld_off;
+ d64p->d_off = nino->ni_fpos = ldp->ld_off;
d64p->d_reclen =
- (((reclen + sizeof(long) - 1)) / sizeof(long)) *
- sizeof(long);
+ (((reclen + sizeof(long))) / sizeof(long)) * sizeof(long);
if (nbytes < d64p->d_reclen)
- d64p->d_reclen = reclen;
+ d64p->d_reclen = reclen + 1;
d64p->d_type = DT_UNKNOWN; /* you lose -- sorry. */
- (void )strncpy(d64p->d_name, ldp->ld_name, namlen);
- *(d64p->d_name + namlen) = '\0';
+ (void )memcpy(d64p->d_name, ldp->ld_name, namlen);
+ /*
+ * Zero pad the rest.
+ */
+ for (cp = d64p->d_name + namlen, n = d64p->d_reclen - reclen;
+ n;
+ n--)
+ *cp++ = 0;
cc -= ldp->ld_reclen;
ldp = (struct linux_dirent *)((char *)ldp + ldp->ld_reclen);
nbytes -= d64p->d_reclen;
- last_offset = d64p->d_off;
d64p = (struct dirent64 *)((char *)d64p + d64p->d_reclen);
}
- nino->ni_fpos = *basep = last_offset;
free(bp);
cc =
(d64p == (struct dirent64 *)buf && cc)
/*
* Invariant; First open. Must init.
*/
+ nino->ni_resetfpos = 0;
nino->ni_fpos = 0;
nino->ni_fd = fd;
/*
return -errno;
nino->ni_fd = -1;
+ nino->ni_resetfpos = 0;
nino->ni_fpos = 0;
return 0;
}
{
ssize_t cc;
- if (!(off == nio->nio_nino->ni_fpos || nio->nio_nino->ni_seekok))
- return -ESPIPE;
-
if (!nio->nio_nino->ni_seekok) {
if (off != nio->nio_nino->ni_fpos) {
/*
- * They've done a p{read,write} or somesuch. Can't
+ * They're trying to reposition. Can't
* seek on this descriptor so we err out now.
*/
errno = ESPIPE;
int err;
err = native_pos(nio->nio_nino->ni_fd, &off, SEEK_SET);
- if (err)
+ if (err) {
+ nio->nio_nino->ni_resetfpos = 1;
return err;
+ }
+ nio->nio_nino->ni_resetfpos = 0;
nio->nio_nino->ni_fpos = off;
}
{
struct native_inode *nino;
long arg1, arg2, arg3, arg4;
+ int rtn;
nino = I2NI(ino);
assert(nino->ni_fd >= 0);
arg3 = va_arg(ap, long);
arg4 = va_arg(ap, long);
- return syscall(SYSIO_SYS_ioctl, I2NI(ino)->ni_fd, request,
- arg1, arg2, arg3, arg4);
+ rtn =
+ syscall(SYSIO_SYS_ioctl, I2NI(ino)->ni_fd, request,
+ arg1, arg2, arg3, arg4);
+ if (rtn < 0)
+ rtn = -errno;
+ return rtn;
}
#else
static int
/*
* I'm lazy. Maybe implemented later.
*/
- errno = ENOTTY;
- return -1;
+ return -ENOTTY;
}
#endif
#include <sys/uio.h>
#include <sys/queue.h>
-#include "xtio.h"
#include "sysio.h"
+#include "xtio.h"
#include "native.h"
#include "fs.h"
#include "inode.h"
}
int
-socket(int domain, int type, int protocol)
+SYSIO_INTERFACE_NAME(socket)(int domain, int type, int protocol)
{
int err;
struct inode *ino;
}
int
-accept(int s, struct sockaddr *addr, socklen_t *addrlen)
+SYSIO_INTERFACE_NAME(accept)(int s, struct sockaddr *addr, socklen_t *addrlen)
{
int err;
struct inode *ino;
}
int
-bind(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen)
+SYSIO_INTERFACE_NAME(bind)(int sockfd,
+ const struct sockaddr *my_addr,
+ socklen_t addrlen)
{
int err;
struct file *fil;
}
int
-listen(int s, int backlog)
+SYSIO_INTERFACE_NAME(listen)(int s, int backlog)
{
int err;
struct file *fil;
}
int
-connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
+SYSIO_INTERFACE_NAME(connect)(int sockfd,
+ const struct sockaddr *serv_addr,
+ socklen_t addrlen)
{
int err;
struct file *fil;
struct inode *ino,
unsigned mask,
struct intnl_stat *stbuf);
-static ssize_t yod_getdirentries(struct inode *ino,
- char *buf,
- size_t nbytes,
- off64_t *basep);
+static ssize_t yod_filldirentries(struct inode *ino,
+ off64_t *posp,
+ char *buf,
+ size_t nbytes);
static int yod_inop_mkdir(struct pnode *pno, mode_t mode);
static int yod_inop_rmdir(struct pnode *pno);
static int yod_inop_symlink(struct pnode *pno, const char *data);
yod_inop_lookup,
yod_inop_getattr,
yod_inop_setattr,
- yod_getdirentries,
+ yod_filldirentries,
yod_inop_mkdir,
yod_inop_rmdir,
yod_inop_symlink,
_sysio_pb_gone(rootpb);
if (fs) {
FS_RELE(fs);
- _sysio_fs_gone(fs);
}
return err;
}
static ssize_t
-yod_getdirentries(struct inode *ino,
- char *buf,
- size_t nbytes,
- _SYSIO_OFF_T *basep)
+yod_filldirentries(struct inode *ino,
+ char *buf,
+ _SYSIO_OFF_T *posp,
+ size_t nbytes)
{
struct yod_inode *nino = I2NI(ino);
_SYSIO_OFF_T result;
result = *basep;
if (*basep != nino->ni_fpos &&
(result = lseek_yod(nino->ni_fd,
- *basep,
+ *posp,
SEEK_SET) == -1))
return -errno;
nino->ni_fpos = result;
memset(buf, 0, nbytes);
+ /*
+ * This is almost certainly broken. The resulting position parameter
+ * points to the block just filled, not the next.
+ */
cc = getdirentries_yod(nino->ni_fd, buf, nbytes, &result);
if (cc < 0)
return -errno;
- nino->ni_fpos = *basep = result;
+ nino->ni_fpos = *posp = result;
return cc;
}
struct inode *, \
unsigned , \
struct intnl_stat *))_sysio_do_ebadf
-#define _sysio_nodev_getdirentries \
+#define _sysio_nodev_filldirentries \
(ssize_t (*)(struct inode *, \
+ _SYSIO_OFF_T *, \
char *, \
- size_t , \
- _SYSIO_OFF_T *))_sysio_do_illop
+ size_t))_sysio_do_illop
#define _sysio_nodev_inop_mkdir \
(int (*)(struct pnode *, \
mode_t))_sysio_do_illop
* terms of the GNU Lesser General Public License
* (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html)
*
- * Cplant(TM) Copyright 1998-2003 Sandia Corporation.
+ * Cplant(TM) Copyright 1998-2005 Sandia Corporation.
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
* license for use of this work by or on behalf of the US Government.
* Export of this program may require a license from the United States
*/
/*
+ * Test whether large file support on this file.
+ */
+#ifdef O_LARGEFILE
+#define _F_LARGEFILE(fil) \
+ ((fil)->f_flags & O_LARGEFILE)
+#else
+#define _F_LARGEFILE(fil) \
+ (1)
+#endif
+/*
+ * Return max seek value for this file.
+ */
+#define _SEEK_MAX(fil) \
+ (_F_LARGEFILE(fil) ? _SYSIO_OFF_T_MAX : LONG_MAX)
+
+#if _LARGEFILE64_SOURCE
+#define _SYSIO_FLOCK flock64
+#else
+#define _SYSIO_FLOCK flock
+#endif
+
+/*
* A file record is maintained for each open file in the system. It holds
* all the info necessary to track the context and parameters for the
* operations that may be performed.
do { \
(fil)->f_ref++; \
assert((fil)->f_ref); \
- I_REF((fil)->f_ino); \
} while (0)
/*
*/
#define F_RELE(fil) \
do { \
- struct inode *ino; \
- \
assert((fil)->f_ref); \
(fil)->f_ref--; \
- ino = (fil)->f_ino; \
if (!(fil)->f_ref) \
_sysio_fgone(fil); \
- I_RELE(ino); \
} while (0)
/*
do { \
(fil)->f_ino = (ino); \
(fil)->f_pos = 0; \
- (fil)->f_ref = 1; \
+ (fil)->f_ref = 0; \
(fil)->f_flags = (flags); \
} while (0)
#if ZERO_SUM_MEMORY
extern void _sysio_fd_shutdown(void);
#endif
+extern _SYSIO_OFF_T _sysio_lseek_prepare(struct file *fil,
+ _SYSIO_OFF_T offset,
+ int whence,
+ _SYSIO_OFF_T max);
struct inode *ino,
unsigned mask,
struct intnl_stat *stbuf);
- ssize_t (*inop_getdirentries)(struct inode *ino,
- char *buf,
- size_t nbytes,
- _SYSIO_OFF_T *basep);
+ ssize_t (*inop_filldirentries)(struct inode *ino,
+ _SYSIO_OFF_T *posp,
+ char *buf,
+ size_t nbytes);
int (*inop_mkdir)(struct pnode *pno, mode_t mode);
int (*inop_rmdir)(struct pnode *pno);
int (*inop_symlink)(struct pnode *pno, const char *data);
void *data);
extern void _sysio_ioctx_cb_free(struct ioctx_callback *cb);
extern struct ioctx *_sysio_ioctx_find(void *id);
+extern int _sysio_ioctx_done(struct ioctx *ioctx);
extern ssize_t _sysio_ioctx_wait(struct ioctx *ioctx);
extern void _sysio_ioctx_complete(struct ioctx *ioctx);
extern int _sysio_open(struct pnode *pno, int flags, mode_t mode);
INCLUDE_EXTRA = include/dev.h include/file.h include/fs.h \
include/inode.h include/mount.h include/sysio.h include/sysio-cmn.h \
- include/sysio-symbols.h include/cplant-yod.h \
+ include/sysio-cmn.h include/sysio-symbols.h include/cplant-yod.h \
include/module.mk include/xtio.h include/stddir.h \
include/native.h
* terms of the GNU Lesser General Public License
* (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html)
*
- * Cplant(TM) Copyright 1998-2004 Sandia Corporation.
+ * Cplant(TM) Copyright 1998-2005 Sandia Corporation.
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
* license for use of this work by or on behalf of the US Government.
* Export of this program may require a license from the United States
struct iovec;
+
+#define _PREPEND_HELPER(p, x) \
+ p ## x
+#define PREPEND(p, x) \
+ _PREPEND_HELPER(p, x)
+
/*
* SYSIO name label macros
*/
-#define XPREPEND(p,x) p ## x
-#define PREPEND(p,x) XPREPEND(p,x)
-#define SYSIO_LABEL_NAMES 0
-#if SYSIO_LABEL_NAMES
-#define SYSIO_INTERFACE_NAME(x) PREPEND(sysio__, x)
+#ifdef SYSIO_LABEL_NAMES
+#define SYSIO_INTERFACE_NAME(x) \
+ PREPEND(SYSIO_LABEL_NAMES, x)
#else
#define SYSIO_INTERFACE_NAME(x) x
#endif
} while(0)
/* Interface enter/leave hook functions */
-#if 0
-extern void _sysio_sysenter();
-extern void _sysio_sysleave();
-
+#if SYSIO_TRACING
+extern void *_sysio_entry_trace_q;
+extern void *_sysio_exit_trace_q;
+
+extern void *_sysio_register_trace(void *q,
+ void (*)(const char *file,
+ const char *func,
+ int line));
+extern void _sysio_remove_trace(void *q, void *p);
+extern void _sysio_run_trace_q(void *q,
+ const char *file,
+ const char *func,
+ int line);
#define SYSIO_ENTER \
- do { \
- _sysio_sysenter(); \
- } while(0)
+ do { \
+ _sysio_run_trace_q(_sysio_entry_trace_q, \
+ __FILE__, __func__, __LINE__); \
+ } while (0)
+
#define SYSIO_LEAVE \
- do { \
- _sysio_sysleave(); \
- } while(0)
+ do { \
+ _sysio_run_trace_q(_sysio_exit_trace_q, \
+ __FILE__, __func__, __LINE__); \
+ } while (0)
#else
-#define SYSIO_ENTER
-#define SYSIO_LEAVE
-
+#define SYSIO_ENTER \
+ do { } while (0)
+#define SYSIO_LEAVE \
+ do { } while (0)
#endif
/* accounting for IO stats read and write char count */
#include "sysio-cmn.h"
+#if defined(_DIRENT_H) && _DIRENT_H
+/*
+ * Need directory access routines too.
+ */
+#define _DECLARE_DIR_ACCESS 1
+#else
+#define _DECLARE_DIR_ACCESS 0
+#endif
+
#ifndef PATH_SEPARATOR
/*
* Path separator.
extern int _sysio_init(void);
extern void _sysio_shutdown(void);
-#if DEFER_INIT_CWD
-extern int _sysio_boot(const char *buf, const char *path);
-#else
-extern int _sysio_boot(const char *buf);
+
+#if 0
+struct _sysio_boot_ctl {
+ const char *onam;
+ const char *oarg;
+};
#endif
+extern int _sysio_boot(const char *opt, const char *arg);
+
/*
* Option-value pair information.
*/
extern time_t _sysio_local_time(void);
+#if SYSIO_TRACING
+extern void _sysio_cprintf(const char *fmt, ...);
+#endif
+
/*
* The following should be defined by the system includes, and probably are,
* but it's not illegal to have multiple externs, so long as they are the
extern int SYSIO_INTERFACE_NAME(dup)(int oldfd);
extern int SYSIO_INTERFACE_NAME(dup2)(int oldfd, int newfd);
extern int SYSIO_INTERFACE_NAME(fcntl)(int fd, int cmd, ...);
+extern int SYSIO_INTERFACE_NAME(fcntl64)(int fd, int cmd, ...);
extern int SYSIO_INTERFACE_NAME(fstat)(int fd, struct stat *buf);
+#if _LARGEFILE64_SOURCE
+extern int SYSIO_INTERFACE_NAME(fstat64)(int fd, struct stat64 *buf);
+#endif
extern int SYSIO_INTERFACE_NAME(fsync)(int fd);
extern char *SYSIO_INTERFACE_NAME(getcwd)(char *buf, size_t size);
extern off_t SYSIO_INTERFACE_NAME(lseek)(int fd, off_t offset, int whence);
#if _LARGEFILE64_SOURCE
extern int SYSIO_INTERFACE_NAME(stat64)(const char *path, struct stat64 *buf);
#endif
+extern ssize_t SYSIO_INTERFACE_NAME(read)(int fd, void *buf, size_t count);
+extern ssize_t SYSIO_INTERFACE_NAME(pread)(int fd, void *buf, size_t count,
+ off_t offset);
+extern ssize_t SYSIO_INTERFACE_NAME(readv)(int fd,
+ const struct iovec *iov,
+ int count);
+extern ssize_t SYSIO_INTERFACE_NAME(write)(int fd,
+ const void *buf,
+ size_t count);
+extern ssize_t SYSIO_INTERFACE_NAME(pwrite)(int fd,
+ const void *buf,
+ size_t count,
+ off_t offset);
+extern ssize_t SYSIO_INTERFACE_NAME(writev)(int fd,
+ const struct iovec *iov,
+ int count);
#ifdef _HAVE_STATVFS
extern int SYSIO_INTERFACE_NAME(statvfs)(const char *path, struct statvfs *buf);
#if _LARGEFILE64_SOURCE
unsigned long mountflags,
const void *data);
extern int SYSIO_INTERFACE_NAME(umount)(const char *target);
+#if _DECLARE_DIR_ACCESS
+extern DIR *SYSIO_INTERFACE_NAME(opendir)(const char *name);
+extern int SYSIO_INTERFACE_NAME(closedir)(DIR *dir);
+extern struct dirent *SYSIO_INTERFACE_NAME(readdir)(DIR *dir);
+extern int SYSIO_INTERFACE_NAME(scandir)(const char *dir,
+ struct dirent ***namelist,
+ int(*filter)(const struct dirent *),
+ int(*compar)(const void *,
+ const void *));
+#if defined(_BSD_SOURCE) || defined(_SVID_SOURCE)
+extern ssize_t SYSIO_INTERFACE_NAME(getdirentries)(int fd,
+ char *buf,
+ size_t nbytes,
+ off_t *basep);
+#endif
+#endif /* _DECLARE_DIR_ACCESS */
+
+#undef _DECLARE_DIR_ACCESS
#ifndef _XTIO_H_
#define _XTIO_H_
+/*
+ * When compiled for use with libsysio, this allows one to move all the
+ * externals to a distinct namespace. When not, we want it to do nothing.
+ *
+ * NB: The choice of macro name here is dangerous. It's in the global
+ * namespace! We should fix that one of these days.
+ */
+#if !defined(SYSIO_INTERFACE_NAME)
+#define SYSIO_INTERFACE_NAME(_n) _n
+#endif
+
#ifndef _IOID_T_DEFINED
#define _IOID_T_DEFINED
typedef void *ioid_t;
/*
* Get status of previously posted async file IO operation.
*/
-extern int iodone(ioid_t ioid);
+extern int SYSIO_INTERFACE_NAME(iodone)(ioid_t ioid);
/*
* Wait for completion of a previously posted asynch file IO request.
*/
-extern ssize_t iowait(ioid_t ioid);
+extern ssize_t SYSIO_INTERFACE_NAME(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);
+extern ioid_t SYSIO_INTERFACE_NAME(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);
+extern ioid_t SYSIO_INTERFACE_NAME(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);
+extern ioid_t SYSIO_INTERFACE_NAME(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);
+extern ioid_t SYSIO_INTERFACE_NAME(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);
+extern ssize_t SYSIO_INTERFACE_NAME(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);
+extern ssize_t SYSIO_INTERFACE_NAME(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);
+extern ioid_t SYSIO_INTERFACE_NAME(ireadv)(int fd,
+ const struct iovec *iov,
+ int count);
/*
* Read into buffer.
*/
-extern ioid_t iread(int fd,
- void *buf,
- size_t count);
+extern ioid_t SYSIO_INTERFACE_NAME(iread)(int fd,
+ void *buf,
+ size_t count);
/*
* Post async read into buffers mapped by iovec from regions mapped
*
* 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);
+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);
#ifdef __USE_LARGEFILE64
/*
*
* 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);
+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);
#endif
/*
*
* 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);
+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);
#ifdef __USE_LARGEFILE64
/*
*
* 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);
+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);
#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);
+extern ioid_t SYSIO_INTERFACE_NAME(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);
+extern ioid_t SYSIO_INTERFACE_NAME(ipwrite64v)(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 ipwrite(int fd,
- const void *buf,
- size_t count,
- off_t offset);
+extern ioid_t SYSIO_INTERFACE_NAME(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);
+extern ioid_t SYSIO_INTERFACE_NAME(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);
+extern ssize_t SYSIO_INTERFACE_NAME(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);
+extern ssize_t SYSIO_INTERFACE_NAME(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);
+extern ioid_t SYSIO_INTERFACE_NAME(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);
+extern ioid_t SYSIO_INTERFACE_NAME(iwrite)(int fd,
+ const void *buf,
+ size_t count);
/*
* Post async write from buffers mapped by iovec to regions mapped
*
* 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);
+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);
#ifdef __USE_LARGEFILE64
/*
*
* 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);
+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);
#endif
/*
*
* 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);
+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);
#ifdef __USE_LARGEFILE64
/*
*
* 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);
+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);
#endif
#endif /* ! _XTIO_H_ */
_sysio_nodev_inop_lookup,
_sysio_nodev_inop_getattr,
_sysio_nodev_inop_setattr,
- _sysio_nodev_getdirentries,
+ _sysio_nodev_filldirentries,
_sysio_nodev_inop_mkdir,
_sysio_nodev_inop_rmdir,
_sysio_nodev_inop_symlink,
SYSIO_INTERFACE_ENTER;
if (newfd < 0)
SYSIO_INTERFACE_RETURN(-1, -EBADF);
-
- if (oldfd == newfd) {
- struct file *fil;
-
- fil = _sysio_fd_find(oldfd);
- if (!(fil && fil->f_ino))
- SYSIO_INTERFACE_RETURN(-1, -EBADF);
- SYSIO_INTERFACE_RETURN(newfd, 0);
- }
-
fd = _sysio_fd_dup(oldfd, newfd, 1);
SYSIO_INTERFACE_RETURN(fd < 0 ? -1 : fd, fd < 0 ? fd : 0);
}
* terms of the GNU Lesser General Public License
* (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html)
*
- * Cplant(TM) Copyright 1998-2003 Sandia Corporation.
+ * Cplant(TM) Copyright 1998-2005 Sandia Corporation.
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
* license for use of this work by or on behalf of the US Government.
* Export of this program may require a license from the United States
* lee@sandia.gov
*/
+#include <string.h>
#include <unistd.h>
+#include <stdlib.h>
#include <errno.h>
+#include <assert.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/queue.h>
#ifdef HAVE_LUSTRE_HACK
#include <syscall.h>
#include <native.h>
+#endif
+#ifdef HAVE_LUSTRE_HACK
static int
-_sysio_fcntl(int fd, int cmd, va_list ap, int *rtn)
+_sysio_lustre_fcntl(int fd, int cmd, va_list ap, int *rtn)
{
long arg = va_arg(ap, long);
}
#endif
-int
-SYSIO_INTERFACE_NAME(fcntl)(int fd, int cmd, ...)
+static int
+_sysio_fcntl_raw_call(struct inode *ino, int *r, int cmd, ...)
+{
+ va_list ap;
+ int err;
+
+ va_start(ap, cmd);
+ err = ino->i_ops.inop_fcntl(ino, cmd, ap, r);
+ va_end(ap);
+ return err;
+}
+
+/*
+ * Convert offsets to absolute, when appropriate, and call appropriate driver
+ * to complete the fcntl lock function. If successful, convert
+ * returned values back to appropriate form.
+ */
+static int
+_sysio_fcntl_lock(struct file *fil, int cmd, struct _SYSIO_FLOCK *fl)
+{
+ struct _SYSIO_FLOCK flock;
+ _SYSIO_OFF_T pos;
+ int err;
+ int rtn;
+
+ /*
+ * The drivers will not have a clue as to the
+ * current position of the file pointer. We need to
+ * convert relative whence values to absolute
+ * file adresses for them, then.
+ */
+ flock = *fl;
+ switch (flock.l_whence) {
+ case SEEK_SET:
+ /*
+ * At least parameter check this one, too.
+ */
+ case SEEK_CUR:
+ case SEEK_END:
+ pos =
+ _sysio_lseek_prepare(fil,
+ flock.l_start,
+ flock.l_whence,
+ _SEEK_MAX(fil));
+ if (pos < 0)
+ return (int )pos;
+ flock.l_start = pos;
+ flock.l_whence = SEEK_SET;
+ break;
+ default:
+ return -EINVAL;
+ }
+ err =
+ _sysio_fcntl_raw_call(fil->f_ino, &rtn, cmd, &flock);
+ if (err)
+ return err;
+ /*
+ * Ugh, convert back to relative form.
+ */
+ switch (fl->l_whence) {
+ case SEEK_SET:
+ break;
+ case SEEK_CUR:
+ fl->l_start = flock.l_start;
+ fl->l_start -= fil->f_pos;
+ break;
+ case SEEK_END:
+ fl->l_start = flock.l_start;
+ fl->l_start -=
+ fil->f_ino->i_stbuf.st_size;
+ break;
+ default:
+ abort();
+ }
+ /*
+ * Return success.
+ */
+ return 0;
+}
+
+static int
+_sysio_vfcntl(int fd, int cmd, va_list ap)
{
int err;
int rtn;
struct file *fil;
- va_list ap;
SYSIO_INTERFACE_DISPLAY_BLOCK;
SYSIO_INTERFACE_ENTER;
fil = _sysio_fd_find(fd);
if (!fil) {
#ifdef HAVE_LUSTRE_HACK
- va_start(ap, cmd);
- err = _sysio_fcntl(fd, cmd, ap, &rtn);
- va_end(ap);
+ err = _sysio_lustre_fcntl(fd, cmd, ap, &rtn);
goto out;
#else
-
rtn = -1;
err = -EBADF;
goto out;
{
long newfd;
- va_start(ap, cmd);
newfd = va_arg(ap, long);
- va_end(ap);
if (newfd != (int )newfd || newfd < 0) {
rtn = -1;
err = -EBADF;
}
}
break;
+#if !(_LARGEFILE64_SOURCE || F_GETLK64 == F_GETLK)
+ case F_GETLK:
+ case F_SETLK:
+ case F_SETLKW:
+ {
+ struct intnl_stat buf;
+ struct flock *fl;
+#if _LARGEFILE64_SOURCE
+ struct _SYSIO_FLOCK flock64;
+#endif
+
+ /*
+ * Refresh the cached attributes.
+ */
+ err =
+ fil->f_ino->i_ops.inop_getattr(NULL,
+ fil->f_ino,
+ &buf);
+ if (err) {
+ rtn = -1;
+ break;
+ }
+ /*
+ * Copy args to a temp and normalize.
+ */
+ fl = va_arg(ap, struct flock *);
+#if _LARGEFILE64_SOURCE
+ flock64.l_type = fl->l_type;
+ flock64.l_whence = fl->l_whence;
+ flock64.l_start = fl->l_start;
+ flock64.l_len = fl->l_len;
+ flock64.l_pid = fl->l_pid;
+ err = _sysio_fcntl_lock(fil, cmd, &flock64);
+#else
+ err = _sysio_fcntl_lock(fil, cmd, fl);
+#endif
+ if (err < 0) {
+ rtn = -1;
+ break;
+ }
+#if _LARGEFILE64_SOURCE
+ /*
+ * Copy back. Note that the fcntl_lock call
+ * should have ensured that no overflow was possible.
+ */
+ fl->l_type = flock64.l_type;
+ fl->l_whence = flock64.l_whence;
+ fl->l_start = flock64.l_start;
+ assert(fl->l_start == flock64.l_start);
+ fl->l_len = flock64.l_len;
+ assert(fl->l_len == flock64.l_len);
+ fl->l_pid = flock64.l_pid;
+#endif
+ rtn = 0;
+ }
+ break;
+#endif /* !(_LARGEFILE64_SOURCE || F_GETLK64 == F_GETLK) */
+#if _LARGEFILE64_SOURCE
+ case F_GETLK64:
+ case F_SETLK64:
+ case F_SETLKW64:
+ {
+ struct flock64 *fl64;
+
+ fl64 = va_arg(ap, struct flock64 *);
+ err = _sysio_fcntl_lock(fil, cmd, fl64);
+ if (err)
+ rtn = -1;
+ }
+ break;
+#endif
default:
- va_start(ap, cmd);
err = fil->f_ino->i_ops.inop_fcntl(fil->f_ino, cmd, ap, &rtn);
- va_end(ap);
break;
}
SYSIO_INTERFACE_RETURN(rtn, err);
}
+int
+SYSIO_INTERFACE_NAME(fcntl)(int fd, int cmd, ...)
+{
+ va_list ap;
+ int err;
+
+ va_start(ap, cmd);
+ err = _sysio_vfcntl(fd, cmd, ap);
+ va_end(ap);
+ return err;
+}
+
+sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(fcntl),
+ SYSIO_INTERFACE_NAME(fcntl64))
+
#ifdef __GLIBC__
#undef __fcntl
sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(fcntl),
return NULL;
_SYSIO_FINIT(fil, ino, flags);
- I_REF(ino);
+ F_REF(fil);
+ I_REF(fil->f_ino);
return fil;
}
assert(fil->f_ino);
err = (*fil->f_ino->i_ops.inop_close)(fil->f_ino);
assert(!err);
+ I_RELE(fil->f_ino);
free(fil);
}
struct file *fil;
int fd;
- if (oldfd == newfd)
+ if (oldfd == newfd && oldfd >= 0)
return newfd;
fil = _sysio_fd_find(oldfd);
return NULL;
_SYSIO_FINIT(fil, ino, flags);
+ F_REF(fil);
I_REF(ino);
return fil;
assert(!fil->f_ref);
assert(fil->f_ino);
err = (*fil->f_ino->i_ops.inop_close)(fil->f_ino);
+ I_RELE(fil->f_ino);
assert(!err);
free(fil);
}
init_oftab();
- if (oldfd == newfd)
- return 0;
+ if (oldfd == newfd && oldfd >= 0)
+ return newfd;
fil = _sysio_fd_find(oldfd);
if (!fil)
#endif
static ssize_t
+filldirents(struct file *fil,
+ char *buf, size_t nbytes,
+ _SYSIO_OFF_T *__restrict basep)
+{
+ _SYSIO_OFF_T opos;
+ ssize_t cc;
+
+ if (!S_ISDIR(fil->f_ino->i_stbuf.st_mode))
+ return -ENOTDIR;
+
+ opos = fil->f_pos;
+ cc =
+ (*fil->f_ino->i_ops.inop_filldirentries)(fil->f_ino,
+ &fil->f_pos,
+ buf, nbytes);
+ if (cc < 0)
+ return cc;
+ *basep = opos;
+ return cc;
+}
+
+static ssize_t
PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries64))(int fd,
char *buf,
size_t nbytes,
fil = _sysio_fd_find(fd);
if (!(fil && fil->f_ino))
- SYSIO_INTERFACE_RETURN(-1, -EBADF);
-
- if (!S_ISDIR(fil->f_ino->i_stbuf.st_mode))
- SYSIO_INTERFACE_RETURN(-1, -ENOTDIR);
+ return -EBADF;
- cc =
- (*fil->f_ino->i_ops.inop_getdirentries)(fil->f_ino,
- buf,
- nbytes,
- basep);
+ cc = filldirents(fil, buf, nbytes, basep);
SYSIO_INTERFACE_RETURN(cc < 0 ? -1 : cc, cc < 0 ? (int )cc : 0);
}
((((n) + (boundary) - 1 ) / (boundary)) * (boundary))
#endif
+#define _dbaselen ((size_t )&((struct dirent *)0)->d_name[0])
+
+#ifdef __GLIBC__
+#define _dreclen(namlen) \
+ ((_dbaselen + (namlen) + __alignof__ (struct dirent)) & \
+ ~(__alignof__ (struct dirent) - 1))
+#else /* !defined(__GLIBC__) */
+#define _dreclen(namlen) \
+ _rndup(_dbaselen + (namlen) + 1, sizeof(int))
+#endif
+
#ifndef BSD
ssize_t
SYSIO_INTERFACE_NAME(getdirentries)(int fd,
long * __restrict basep)
#endif
{
- size_t inbytes;
- void *ibuf;
- _SYSIO_OFF_T ibase;
- ssize_t cc;
- struct dirent *dp, *nxtdp;
-#if defined(BSD)
- int off;
-#endif
- struct intnl_dirent *od64p, *d64p;
- size_t n;
- size_t reclen;
+ struct file *fil;
+ _SYSIO_OFF_T b;
+ ssize_t cc, count;
+ struct dirent64 *d64p, d64;
+ struct dirent *dp;
+ size_t n, reclen;
+ void *p;
char *cp;
SYSIO_INTERFACE_DISPLAY_BLOCK;
-#define _dbaselen ((size_t )&((struct dirent *)0)->d_name[0])
-
-#ifdef __GLIBC__
-#define _dreclen(namlen) \
- ((_dbaselen + (namlen) + __alignof__ (struct dirent)) & \
- ~(__alignof__ (struct dirent) - 1))
-#else /* !defined(__GLIBC__) */
-#define _dreclen(namlen) \
- _rndup(_dbaselen + (namlen) + 1, sizeof(int))
-#endif
-
-#if defined(__GLIBC__)
-#define _fast_alloc(n) alloca(n)
-#define _fast_free(p)
-#else /* !defined(__GLIBC__) */
-#define _fast_alloc(n) malloc(n)
-#define _fast_free(p) free(p)
-#endif
-
SYSIO_INTERFACE_ENTER;
-#if defined(BSD)
- if (nbytes < 0)
- SYSIO_INTERFACE_RETURN(-1, -EINVAL);
-#endif
-
- inbytes = nbytes;
- if (inbytes > 8 * 1024) {
- /*
- * Limit stack use.
- */
- inbytes = 8 * 1024;
- }
- ibuf = _fast_alloc(inbytes);
- if (!ibuf)
- SYSIO_INTERFACE_RETURN(-1, -ENOMEM);
-
- dp = (struct dirent *)buf;
- ibase = *basep;
- cc =
- PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries64))(fd,
- ibuf,
- inbytes,
- &ibase);
- if (cc < 0) {
- cc = -errno;
- goto out;
- }
- *basep = (off_t )ibase;
- if (sizeof(*basep) != sizeof(ibase) && *basep != ibase) {
- cc = -EOVERFLOW;
- goto out;
- }
+ fil = _sysio_fd_find(fd);
+ if (!(fil && fil->f_ino))
+ return -EBADF;
-#if defined(BSD)
- off = *basep;
-#endif
- od64p = NULL;
- d64p = ibuf;
- for (;;) {
- if (!cc)
- break;
-#ifdef HAVE_D_NAMLEN
- n = d64p->d_namlen;
-#else
- n = strlen(d64p->d_name);
-#endif
+ count = cc = filldirents(fil, buf, nbytes, &b);
+ d64p = (void *)buf;
+ dp = (void *)buf;
+ reclen = 0;
+ while (cc > 0) {
+ n = _namlen(d64p);
reclen = _dreclen(n);
- if (reclen >= (unsigned )nbytes)
- break;
- dp->d_ino = (ino_t )d64p->d_ino;
-#if !(defined(BSD))
- dp->d_off = (off_t )d64p->d_off;
-#endif
- if ((sizeof(dp->d_ino) != sizeof(d64p->d_ino) &&
- dp->d_ino != d64p->d_ino)
- ||
-#if !(defined(BSD))
- (sizeof(dp->d_off) != sizeof(d64p->d_off) &&
- dp->d_off != d64p->d_off)
-#else
- (off + (int )reclen < off)
-#endif
- ) {
- cc = -EOVERFLOW;
+ d64.d_ino = d64p->d_ino;
+ d64.d_off = d64p->d_off;
+ d64.d_type = d64p->d_type;
+ d64.d_reclen = d64p->d_reclen;
+ /*
+ * Copy name first.
+ */
+ (void )memcpy(dp->d_name, d64p->d_name, n);
+ /*
+ * Then, the rest.
+ */
+ dp->d_ino = d64.d_ino;
+ dp->d_off = d64.d_off;
+ if (dp->d_ino != d64.d_ino ||
+ dp->d_off != d64.d_off) {
+ /*
+ * If conversion failure then we are done.
+ */
+ if (cc == count) {
+ /*
+ * Couldn't process any entries. We return
+ * the error now.
+ */
+ cc = - EOVERFLOW;
+ }
break;
}
- dp->d_type = d64p->d_type;
+ fil->f_pos = dp->d_off;
+ dp->d_type = d64.d_type;
dp->d_reclen = reclen;
- nxtdp = (struct dirent *)((char *)dp + dp->d_reclen);
- (void )memcpy(dp->d_name, d64p->d_name, n);
- for (cp = dp->d_name + n; cp < (char *)nxtdp; *cp++ = '\0')
- ;
- cc -= d64p->d_reclen;
- od64p = d64p;
- d64p = (struct dirent64 *)((char *)d64p + d64p->d_reclen);
- nbytes -= reclen;
-#if defined(BSD)
- off += reclen;
+ /*
+ * Fill the remainder with zeros.
+ */
+ p = (char *)dp + dp->d_reclen;
+#ifdef HAVE_D_NAMLEN
+ dp->d_namlen = n;
#endif
- dp = nxtdp;
+ cp = dp->d_name + n;
+ do {
+ *cp++ = 0;
+ } while (cp < (char *)p);
+ /*
+ * Advance.
+ */
+ dp = p;
+ cc -= d64.d_reclen;
+ d64p = (struct dirent64 *)((char *)d64p + d64.d_reclen);
}
-out:
- _fast_free(ibuf);
-
- if (dp == (struct dirent *)buf && cc < 0)
- SYSIO_INTERFACE_RETURN(-1, (int )cc);
+ if (cc < 0)
+ SYSIO_INTERFACE_RETURN(-1, cc);
cc = (char *)dp - buf;
- if (cc)
- *basep =
-#if !(defined(BSD))
- od64p->d_off;
-#else
- off;
-#endif
+ *basep = b;
SYSIO_INTERFACE_RETURN(cc, 0);
-
-#ifdef __GLIBC__
-#undef _fast_alloc
-#undef _fast_free
-#endif
-#undef _dreclen
-#undef _dbaselen
}
#else /* !defined(DIRENT64_IS_NATURAL) */
sysio_sym_strong_alias(PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries64),
* terms of the GNU Lesser General Public License
* (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html)
*
- * Cplant(TM) Copyright 1998-2004 Sandia Corporation.
+ * Cplant(TM) Copyright 1998-2005 Sandia Corporation.
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
* license for use of this work by or on behalf of the US Government.
* Export of this program may require a license from the United States
#define _BSD_SOURCE
+#if SYSIO_TRACING
+#include <stdio.h>
+#endif
#include <stdlib.h>
+#if SYSIO_TRACING
+#include <sys/syscall.h>
+#endif
#include <unistd.h>
#include <string.h>
#include <errno.h>
+#if SYSIO_TRACING
+#include <stdarg.h>
+#endif
#include <limits.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/queue.h>
-#include "xtio.h"
#include "sysio.h"
+#include "xtio.h"
+#if SYSIO_TRACING
+#include "native.h"
+#endif
#include "inode.h"
#include "fs.h"
#include "mount.h"
#include "stdfd.h"
#endif
+#if SYSIO_TRACING
+
+/*
+ * Tracing callback record.
+ */
+struct trace_callback {
+ TAILQ_ENTRY(trace_callback) links;
+ void (*f)(const char *file, const char *func, int line);
+};
+
+/*
+ * Initialize a tracing callback record.
+ */
+#define TCB_INIT(__tcb, __f) \
+ do { \
+ (__tcb)->f = (__f); \
+ } while (0);
+
+/*
+ * Trace queue head record.
+ */
+TAILQ_HEAD(trace_q, trace_callback);
+
+/*
+ * The entry and exit queue heads, and queue pointers.
+ */
+static struct trace_q _sysio_entry_trace_head;
+void *_sysio_entry_trace_q = &_sysio_entry_trace_head;
+static struct trace_q _sysio_exit_trace_head;
+void *_sysio_exit_trace_q = &_sysio_exit_trace_head;
+#endif
+
/*
* White space characters.
*/
#define IGNORE_WHITE " \t\r\n"
/*
+ * Check if long overflows integer range.
+ */
+#if LONG_MAX <= INT_MAX
+#define _irecheck(_l, _e) \
+ ((_l) == LONG_MAX && (_e) == ERANGE)
+#else
+#define _irecheck(_l, _e) \
+ ((_l) > INT_MAX)
+#endif
+
+/*
* Sysio library initialization. Must be called before anything else in the
* library.
*/
{
int err;
#ifdef WITH_SOCKETS
- int _sysio_sockets_init(void);
+ extern int _sysio_sockets_init(void);
+#endif
+
+#if SYSIO_TRACING
+ /*
+ * Initialize tracing callback queues.
+ */
+ TAILQ_INIT(&_sysio_entry_trace_head);
+ TAILQ_INIT(&_sysio_exit_trace_head);
#endif
err = _sysio_ioctx_init();
_sysio_fd_shutdown();
_sysio_i_shutdown();
_sysio_fssw_shutdown();
+#if SYSIO_TRACING
+ {
+ struct trace_callback *tcb;
+
+ /*
+ * Empty the trace queues and free the entries.
+ */
+ while ((tcb = _sysio_entry_trace_head.tqh_first) != NULL) {
+ TAILQ_REMOVE(&_sysio_entry_trace_head, tcb, links);
+ free(tcb);
+ }
+ while ((tcb = _sysio_exit_trace_head.tqh_first) != NULL) {
+ TAILQ_REMOVE(&_sysio_exit_trace_head, tcb, links);
+ free(tcb);
+ }
+ }
+#endif
#endif
}
+#if SYSIO_TRACING
+
+#if !(defined(_HAVE_ASPRINTF) && _HAVE_ASPRINTF)
+/*
+ * Print a string to allocated memory.
+ */
+static int
+vasprintf(char **strp, const char *fmt, va_list ap)
+{
+ size_t siz;
+ int oerrno;
+ char *s;
+ va_list aq;
+ int n;
+
+ siz = 50;
+ oerrno = errno;
+ if (!(s = malloc(siz))) {
+ errno = oerrno;
+ return -1;
+ }
+ for (;;) {
+ va_copy(aq, ap);
+ n = vsnprintf (s, siz, fmt, aq);
+ va_end(aq);
+ if (n > -1 && (size_t )n < siz)
+ break;
+ if (n > -1) /* glibc 2.1 */
+ siz = n+1; /* precise */
+ else /* glibc 2.0 */
+ siz *= 2; /* twice the old */
+ if (!(s = realloc (s, siz)))
+ break;
+ }
+ *strp = s;
+ errno = oerrno;
+ return n;
+}
+
+#if 0
+static int
+asprintf(char **strp, const char *fmt, ...)
+{
+ va_list ap;
+ int n;
+
+ va_start(ap, fmt);
+ n = vasprintf(strp, fmt, ap);
+ va_end(ap);
+ return n;
+}
+#endif
+#endif /* !(defined(_HAVE_ASPRINTF) && _HAVE_ASPRINTF) */
+
+static void
+_sysio_cwrite(const char *buf, size_t len)
+{
+ int oerrno;
+
+ oerrno = errno;
+ (void )syscall(SYSIO_SYS_write, STDERR_FILENO, buf, len);
+ errno = oerrno;
+}
+
+/*
+ * Console printf.
+ */
+void
+_sysio_cprintf(const char *fmt, ...)
+{
+ va_list ap;
+ int len;
+ char *buf;
+
+ va_start(ap, fmt);
+ buf = NULL;
+ len = vasprintf(&buf, fmt, ap);
+ va_end(ap);
+ if (len < 0)
+ return;
+ _sysio_cwrite(buf, len);
+ free(buf);
+}
+
+/*
+ * Register a trace callback.
+ *
+ * The pointer to the trace record is returned.
+ */
+void *
+_sysio_register_trace(void *q,
+ void (*f)(const char *file,
+ const char *func,
+ int line))
+{
+ struct trace_callback *tcb;
+
+ tcb = malloc(sizeof(struct trace_callback));
+ if (!tcb)
+ return NULL;
+ TCB_INIT(tcb, f);
+ TAILQ_INSERT_TAIL((struct trace_q *)q, tcb, links);
+ return tcb;
+}
+
+/*
+ * Remove a registered trace callback.
+ */
+void
+_sysio_remove_trace(void *q, void *p)
+{
+
+ TAILQ_REMOVE((struct trace_q *)q, (struct trace_callback *)p, links);
+ free(p);
+}
+
+void
+/*
+ * Run a trace queue, making all the callbacks.
+ */
+_sysio_run_trace_q(void *q,
+ const char *file,
+ const char *func,
+ int line)
+{
+ struct trace_callback *tcb;
+
+ tcb = ((struct trace_q *)q)->tqh_first;
+ while (tcb) {
+ (*tcb->f)(file, func, line);
+ tcb = tcb->links.tqe_next;
+ }
+}
+
+static void
+_sysio_trace_entry(const char *file __IS_UNUSED,
+ const char *func,
+ int line __IS_UNUSED)
+{
+
+ _sysio_cprintf("+ENTER+ %s\n", func);
+}
+
+static void
+_sysio_trace_exit(const char *file __IS_UNUSED,
+ const char *func,
+ int line __IS_UNUSED)
+{
+
+ _sysio_cprintf("+EXIT+ %s\n", func);
+}
+#endif /* defined(SYSIO_TRACING) */
+
/*
* (kind of)Duplicates strtok function.
*
int err;
struct file *fil;
-/*
- * Check if long overflows integer range.
- */
-#if LONG_MAX <= INT_MAX
-#define _irecheck(_l, _e) \
- ((_l) == LONG_MAX && (_e) == ERANGE)
-#else
-#define _irecheck(_l, _e) \
- ((_l) > INT_MAX)
-#endif
-
len = strlen(args);
if (_sysio_get_args(args, v) - args != (ssize_t )len ||
!(v[0].ovi_value && v[1].ovi_value && v[2].ovi_value))
if (pno)
P_RELE(pno);
return err;
-
-#undef _irecheck
}
/*
return -EINVAL;
}
+#if SYSIO_TRACING
/*
- * Given a command sequence buffer, parse it and run the given
- * commands
+ * Set/Unset tracing.
*/
-int
-_sysio_boot(const char *buf
-#if DEFER_INIT_CWD
- , const char *path
+static int
+_sysio_boot_tracing(const char *arg)
+{
+ long l;
+ char *cp;
+ static struct trace_callback
+ *entcb = NULL,
+ *exitcb = NULL;
+
+ l = 0;
+ if (arg) {
+ l = strtol(arg, (char **)&cp, 0);
+ if (*cp || !(l == 0 || l == 1))
+ return -EINVAL;
+ }
+ if (l) {
+ if (entcb == NULL)
+ entcb =
+ _sysio_register_trace(_sysio_entry_trace_q,
+ _sysio_trace_entry);
+ if (entcb == NULL)
+ return -errno;
+ if (exitcb == NULL)
+ exitcb =
+ _sysio_register_trace(_sysio_exit_trace_q,
+ _sysio_trace_exit);
+ if (exitcb == NULL)
+ return -errno;
+ } else {
+ if (entcb != NULL)
+ _sysio_remove_trace(_sysio_entry_trace_q, entcb);
+ entcb = NULL;
+ if (exitcb != NULL)
+ _sysio_remove_trace(_sysio_exit_trace_q, exitcb);
+ exitcb = NULL;
+ }
+ return 0;
+}
#endif
- )
+
+/*
+ * Initialize the namespace.
+ */
+static int
+_sysio_boot_namespace(const char *arg)
{
char c, *tok;
ssize_t len;
int err;
-
- if (!buf)
- buf = "";
+ unsigned count;
/*
* Allocate token buffer.
*/
- len = strlen(buf);
+ len = strlen(arg);
tok = malloc(len ? len : 1);
if (!tok)
return -ENOMEM;
err = 0;
+ count = 0;
while (1) {
/*
* Discard leading white space.
*/
- while ((c = *buf) != '\0' &&
+ while ((c = *arg) != '\0' &&
!(c == '{' || strchr(IGNORE_WHITE, c) == NULL))
- buf++;
+ arg++;
if (c == '\0')
break;
if (c != '{') {
/*
* Get the command.
*/
- buf =
- (char *)_sysio_get_token(buf + 1,
+ *tok = '\0';
+ arg =
+ (char *)_sysio_get_token(arg + 1,
0,
"}",
IGNORE_WHITE,
tok);
- if (!buf) {
+ if (!arg) {
err = -EINVAL;
break;
}
+ count++;
/*
* Perform.
*/
if (err)
break;
}
- free(tok);
-#if DEFER_INIT_CWD
+#if SYSIO_TRACING
if (err)
- return err;
- _sysio_init_cwd = path;
+ _sysio_cprintf("+NS init+ failed at expr %u (last = %s): %s\n",
+ count,
+ tok && *tok ? tok : "NULL",
+ strerror(-err));
#endif
+ free(tok);
return err;
}
+
+#if DEFER_INIT_CWD
+/*
+ * Set deferred initial working directory.
+ */
+static int
+_sysio_boot_cwd(const char *arg)
+{
+
+ _sysio_init_cwd = arg;
+ return 0;
+}
+#endif
+
+/*
+ * Given an identifier and it's arguments, perform optional initializations.
+ */
+int
+_sysio_boot(const char *opt, const char *arg)
+{
+ struct option_value_info vec[] = {
+#if SYSIO_TRACING
+ { "trace", NULL }, /* tracing? */
+#endif
+ { "namespace", NULL }, /* init namespace? */
+#if DEFER_INIT_CWD
+ { "cwd", NULL }, /* init working dir */
+#endif
+ { NULL, NULL }
+ };
+ struct option_value_info *v;
+ unsigned u;
+ static int (*f[])(const char *) = {
+#if SYSIO_TRACING
+ _sysio_boot_tracing,
+#endif
+ _sysio_boot_namespace,
+#if DEFER_INIT_CWD
+ _sysio_boot_cwd,
+#endif
+ NULL /* can't happen */
+ };
+
+ for (v = vec, u = 0; v->ovi_name; v++, u++)
+ if (strcmp(v->ovi_name, opt) == 0)
+ break;
+ if (!v->ovi_name)
+ return -EINVAL;
+ return (*f[u])(arg);
+}
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <sched.h>
#include <assert.h>
#include <sys/uio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/queue.h>
-#include "xtio.h"
#include "sysio.h"
+#include "xtio.h"
#include "inode.h"
#if defined(REDSTORM)
}
/*
+ * Check if asynchronous IO operation is complete.
+ */
+int
+_sysio_ioctx_done(struct ioctx *ioctx)
+{
+
+ if (ioctx->ioctx_done)
+ return 1;
+ if (!(*ioctx->ioctx_ino->i_ops.inop_iodone)(ioctx))
+ return 0;
+ ioctx->ioctx_done = 1;
+ return 1;
+}
+
+/*
* Wait for asynchronous IO operation to complete, return status
* and dispose of the context.
*
/*
* Wait for async operation to complete.
*/
- while (!(ioctx->ioctx_done ||
- (*ioctx->ioctx_ino->i_ops.inop_iodone)(ioctx)))
- ;
+ while (!_sysio_ioctx_done(ioctx)) {
+#ifdef POSIX_PRIORITY_SCHEDULING
+ (void )sched_yield();
+#endif
+ }
/*
* Get status.
/* update IO stats */
- _SYSIO_UPDACCT(ioctx->ioctx_write, ioctx);
+ _SYSIO_UPDACCT(ioctx->ioctx_write, ioctx->ioctx_cc);
/*
* Run the call-back queue.
if (!ioctx)
SYSIO_INTERFACE_RETURN(-1, -EINVAL);
- rc =
- (ioctx->ioctx_done ||
- (*ioctx->ioctx_ino->i_ops.inop_iodone)(ioctx));
-
+ rc = _sysio_ioctx_done(ioctx);
SYSIO_INTERFACE_RETURN(rc < 0 ? -1 : rc, rc < 0 ? rc : 0);
}
err = -EXDEV;
goto error2;
}
- err = old->p_base->pb_ino->i_ops.inop_link(old, new);
+ /*
+ * Use the parent node operations to request the task in case the
+ * driver is implemented using differentiated inode operations based
+ * on file type, such as incore does.
+ */
+ err = old->p_parent->p_base->pb_ino->i_ops.inop_link(old, new);
if (err)
goto error2;
/*
* terms of the GNU Lesser General Public License
* (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html)
*
- * Cplant(TM) Copyright 1998-2003 Sandia Corporation.
+ * Cplant(TM) Copyright 1998-2005 Sandia Corporation.
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
* license for use of this work by or on behalf of the US Government.
* Export of this program may require a license from the United States
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <fcntl.h>
#include <sys/queue.h>
#include "sysio.h"
#include "sysio-symbols.h"
-static _SYSIO_OFF_T
-_sysio_lseek(int fd, _SYSIO_OFF_T offset, int whence)
+_SYSIO_OFF_T
+_sysio_lseek_prepare(struct file *fil,
+ _SYSIO_OFF_T offset,
+ int whence,
+ _SYSIO_OFF_T max)
{
- struct file *fil;
_SYSIO_OFF_T off, pos;
struct intnl_stat stbuf;
- fil = _sysio_fd_find(fd);
- if (!fil)
- return -EBADF;
-
off = -1;
switch (whence) {
pos = off + offset;
if ((offset < 0 && -offset > off) || (offset > 0 && pos <= off))
return -EINVAL;
-
-#ifdef O_LARGEFILE
- if (pos >= ((fil->f_flags & O_LARGEFILE) ? _SYSIO_OFF_T_MAX : LONG_MAX))
- return -EOVERFLOW;
-#else
- if (pos >= _SYSIO_OFF_T_MAX)
+ if (pos >= max)
return -EOVERFLOW;
-#endif
+ return pos;
+}
+
+static _SYSIO_OFF_T
+_sysio_lseek(struct file *fil,
+ _SYSIO_OFF_T offset,
+ int whence,
+ _SYSIO_OFF_T max)
+{
+ _SYSIO_OFF_T pos;
+
+ pos = _sysio_lseek_prepare(fil, offset, whence, max);
+ if (pos < 0)
+ return pos;
pos = (fil->f_ino->i_ops.inop_pos)(fil->f_ino, pos);
if (pos < 0)
return pos;
extern off64_t
SYSIO_INTERFACE_NAME(lseek64)(int fd, off64_t offset, int whence)
{
- _SYSIO_OFF_T off;
- off64_t rtn;
+ struct file *fil;
+ off64_t off;
SYSIO_INTERFACE_DISPLAY_BLOCK;
SYSIO_INTERFACE_ENTER;
- off = _sysio_lseek(fd, offset, whence);
- if (off < 0)
- SYSIO_INTERFACE_RETURN((off64_t )-1, (int )off);
- rtn = (off64_t )off;
- assert(rtn == off);
- SYSIO_INTERFACE_RETURN(rtn, 0);
+ fil = _sysio_fd_find(fd);
+ if (!fil)
+ SYSIO_INTERFACE_RETURN((off64_t )-1, -EBADF);
+ off = _sysio_lseek(fil, offset, whence, _SEEK_MAX(fil));
+ SYSIO_INTERFACE_RETURN(off < 0 ? (off64_t )-1 : off,
+ off < 0 ? (int )off : 0);
+
}
#ifdef __GLIBC__
#undef __lseek64
extern off_t
SYSIO_INTERFACE_NAME(lseek)(int fd, off_t offset, int whence)
{
+ struct file *fil;
_SYSIO_OFF_T off;
off_t rtn;
SYSIO_INTERFACE_DISPLAY_BLOCK;
SYSIO_INTERFACE_ENTER;
- off = _sysio_lseek(fd, offset, whence);
+ fil = _sysio_fd_find(fd);
+ if (!fil)
+ SYSIO_INTERFACE_RETURN((off_t )-1, -EBADF);
+ off = _sysio_lseek(fil, offset, whence, LONG_MAX);
if (off < 0)
SYSIO_INTERFACE_RETURN((off_t )-1, (int )off);
rtn = (off_t )off;
loff_t *result __IS_UNUSED,
unsigned int whence __IS_UNUSED)
{
+ struct file *fil;
loff_t off;
SYSIO_INTERFACE_DISPLAY_BLOCK;
* This is just plain goofy.
*/
SYSIO_INTERFACE_ENTER;
+ fil = _sysio_fd_find(fd);
+ if (!fil)
+ SYSIO_INTERFACE_RETURN(-1, -EBADF);
#if !_LARGEFILE64_SOURCE
if (offset_high) {
/*
off <<= 32;
off |= offset_low;
#endif
- off = _sysio_lseek(fd, off, whence);
+ off = _sysio_lseek(fil, off, whence, _SEEK_MAX(fil));
if (off < 0)
SYSIO_INTERFACE_RETURN((off_t )-1, (int )off);
*result = off;
#endif
#include <sys/queue.h>
-#include "xtio.h"
#include "sysio.h"
+#include "xtio.h"
#include "fs.h"
#include "mount.h"
#include "inode.h"
if (!parent) {
const char *icwd;
- if (!_sysio_init_cwd)
+ if (!_sysio_init_cwd && !nd->nd_root)
abort();
/*
- * Finally have to set the curretn working directory. We can
+ * Finally have to set the current working directory. We can
* not tolerate errors here or else risk leaving the process
* in a very unexpected location. We abort then unless all goes
* well.
*/
icwd = _sysio_init_cwd;
_sysio_init_cwd = NULL;
- if (_sysio_namei(NULL, icwd, 0, NULL, &parent) != 0 ||
- _sysio_p_chdir(parent) != 0)
+ parent = nd->nd_root;
+ if (!parent)
+ abort();
+ (void )_sysio_namei(nd->nd_root, icwd, 0, NULL, &parent);
+ if (_sysio_p_chdir(parent) != 0)
abort();
}
#endif
lpath[cc] = '\0'; /* NUL term */
/*
* Handle symbolic links with recursion. Yuck!
- * Pass the NULL intent for recursive symlink
- * except the last component.
*/
ND_INIT(&nameidata,
(nd->nd_flags | ND_NEGOK),
err = -EEXIST;
else if (!ino)
err = _sysio_p_validate(pno, NULL, NULL);
+#ifdef O_NOFOLLOW
+ else if (flags & O_NOFOLLOW && S_ISLNK(ino->i_stbuf.st_mode))
+ err = -ELOOP;
+#endif
else {
/*
* Simple open of pre-existing file.
#endif
va_end(ap);
mode &= ~(_sysio_umask & 0777) | 07000; /* apply umask */
-
- if (flags & O_EXCL) {
- /*
- * Tell others we intend to create this file.
- */
- intent.int_opmask |= INT_CREAT;
- }
+ intent.int_opmask |= INT_CREAT;
}
#ifdef O_NOFOLLOW
if (flags & O_NOFOLLOW)
#ifdef __GLIBC__
#undef __open
-sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open), __open)
+sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open),
+ PREPEND(__, SYSIO_INTERFACE_NAME(open)))
#undef open64
sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open), SYSIO_INTERFACE_NAME(open64))
#undef __open64
-sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open), __open64)
+sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open),
+ PREPEND(__, SYSIO_INTERFACE_NAME(open64)))
#endif
#ifdef REDSTORM
#undef __libc_open64
-sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open), __libc_open64)
+sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open),
+ PREPEND(__, SYSIO_INTERFACE_NAME(libc_open64)))
#endif
#ifdef BSD
#undef _open
-sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open), _open)
+sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(open),
+ PREPEND(_, SYSIO_INTERFACE_NAME(open)))
#endif
int
#ifdef __GLIBC__
#undef __close
-sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(close), __close)
+sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(close),
+ PREPEND(__, SYSIO_INTERFACE_NAME(close)))
#endif
#ifdef BSD
#undef _close
-sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(close), _close)
+sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(close),
+ PREPEND(_, SYSIO_INTERFACE_NAME(close)))
#endif
int
SYSIO_INTERFACE_NAME(creat)(const char *path, mode_t mode)
{
- return open(path, O_CREAT|O_WRONLY|O_TRUNC, mode);
+ return SYSIO_INTERFACE_NAME(open)(path, O_CREAT|O_WRONLY|O_TRUNC, mode);
}
#ifdef __GLIBC__
#undef __creat
-sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat), __creat)
+sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat),
+ PREPEND(__, SYSIO_INTERFACE_NAME(creat)))
#undef creat64
#ifndef HAVE_LUSTRE_HACK
sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat), SYSIO_INTERFACE_NAME(creat64))
#else
/* XXX workaround SuSE SLES 8, glibc-2.2.5 */
-sysio_sym_strong_alias(SYSIO_INTERFACE_NAME(creat), SYSIO_INTERFACE_NAME(creat64))
+sysio_sym_strong_alias(SYSIO_INTERFACE_NAME(creat),
+ SYSIO_INTERFACE_NAME(creat64))
#endif
#undef __creat64
-sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat), __creat64)
+sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat),
+ PREPEND(__, SYSIO_INTERFACE_NAME(creat64)))
#endif
#ifdef REDSTORM
#undef __libc_creat
-sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat), __libc_creat)
+sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat),
+ PREPEND(__, SYSIO_INTERFACE_NAME(libc_creat)))
#endif
#ifdef BSD
#undef _creat
-sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat), _creat)
+sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(creat),
+ PREPEND(_, SYSIO_INTERFACE_NAME(creat)))
#endif
mode_t
#ifdef REDSTORM
#undef __umask
-sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(umask), __umask)
+sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(umask),
+ PREPEND(__, SYSIO_INTERFACE_NAME(umask)))
#endif
_SCANDIR(const char *dirname,
_DIRENT_T ***namelist,
int (*filter) (const _DIRENT_T *),
- int (*cmp) (const void *, const void *))
+ int (*compar) (const void *, const void *))
{
DIR *dir = NULL;
_DIRENT_T *de = NULL,
SYSIO_INTERFACE_ENTER;
- if ((dir = opendir(dirname)) == NULL)
+ if ((dir = SYSIO_INTERFACE_NAME(opendir)(dirname)) == NULL)
SYSIO_INTERFACE_RETURN(-1, -errno);
while ((de = _READDIR(dir)) != NULL) {
s[i++] = (_DIRENT_T *)memcpy(nextde, de, desize);
}
}
- if (cmp)
- qsort (s, i, sizeof (*s), cmp);
+ if (compar)
+ qsort (s,
+ i,
+ sizeof (*s),
+ (int (*)(const void *, const void *))compar);
*namelist = s;
- closedir(dir);
+ SYSIO_INTERFACE_NAME(closedir)(dir);
SYSIO_INTERFACE_RETURN(i, 0);
}
err = -EBUSY;
goto error1;
}
- err = old->p_base->pb_ino->i_ops.inop_rename(old, new);
+ /*
+ * Use the parent node operations to request the task in case the
+ * driver is implemented using differentiated inode operations based
+ * on file type, such as incore does.
+ */
+ err = old->p_parent->p_base->pb_ino->i_ops.inop_rename(old, new);
if (err)
goto error1;
/*
err = _sysio_namei(_sysio_cwd, path, 0, &intent, &pno);
if (err)
goto out;
+ if (!S_ISDIR(pno->p_base->pb_ino->i_stbuf.st_mode)) {
+ err = -ENOTDIR;
+ goto error;
+ }
if (IS_RDONLY(pno, pno->p_base->pb_ino)) {
err = -EROFS;
goto error;
err = -EBUSY;
goto error;
}
- err = pno->p_base->pb_ino->i_ops.inop_rmdir(pno);
+ /*
+ * Use the parent node operations to request the task in case the
+ * driver is implemented using differentiated inode operations based
+ * on file type, such as incore does.
+ */
+ err = pno->p_parent->p_base->pb_ino->i_ops.inop_rmdir(pno);
if (err)
goto error;
/*
#include <sys/uio.h>
#include <sys/queue.h>
-#include "xtio.h"
#include "sysio.h"
+#include "xtio.h"
#include "file.h"
#include "inode.h"
xtv,
xtv_count)) == IOID_FAIL)
return -1;
- return iowait(ioid);
+ return SYSIO_INTERFACE_NAME(iowait)(ioid);
}
#if _LARGEFILE64_SOURCE
xtv,
xtv_count)) == IOID_FAIL)
return -1;
- return iowait(ioid);
+ return SYSIO_INTERFACE_NAME(iowait)(ioid);
}
#endif
xtv,
xtv_count)) == IOID_FAIL)
return -1;
- return iowait(ioid);
+ return SYSIO_INTERFACE_NAME(iowait)(ioid);
}
#if _LARGEFILE64_SOURCE
xtv,
xtv_count)) == IOID_FAIL)
return -1;
- return iowait(ioid);
+ return SYSIO_INTERFACE_NAME(iowait)(ioid);
}
#endif
if (!dir)
SYSIO_INTERFACE_RETURN(NULL, -ENOMEM);
- dir->fd = open(name, O_RDONLY);
+ dir->fd = SYSIO_INTERFACE_NAME(open)(name, O_RDONLY);
if (dir->fd < 0) {
free(dir);
SYSIO_INTERFACE_RETURN(NULL, -errno);
return dir;
}
-sysio_sym_weak_alias(opendir, __opendir)
+sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(opendir),
+ PREPEND(__, SYSIO_INTERFACE_NAME(opendir)))
int
SYSIO_INTERFACE_NAME(closedir)(DIR *dir)
err = -EROFS;
goto error;
}
+ /*
+ * Use the parent node operations to request the task in case the
+ * driver is implemented using differentiated inode operations based
+ * on file type, such as incore does.
+ */
err =
(*pno->p_parent->p_base->pb_ino->i_ops.inop_symlink)(pno, oldpath);
error:
err = -EROFS;
goto error;
}
- err = (*ino->i_ops.inop_unlink)(pno);
+ /*
+ * Use the parent node operations to request the task in case the
+ * driver is implemented using differentiated inode operations based
+ * on file type, such as incore does.
+ */
+ err = (*pno->p_parent->p_base->pb_ino->i_ops.inop_unlink)(pno);
if (err)
goto error;
assert(pno->p_base->pb_ino);
noinst_PROGRAMS = test_copy test_stats test_path test_list \
test_getcwd test_link test_unlink test_rename \
- test_regions test_driver test_stddir
+ test_regions test_stddir test_fcntl_lock
CLEANFILES=drv_data.c
CMNSRC=startup.c drv_init_all.c drv_data.c
BUILT_SOURCES=drv_data.c
-check_PROGRAMS=test_driver
-if TEST_ALPHA_ARG
-TESTS_ENVIRONMENT=IS_ALPHA=yes
-else
-TESTS_ENVIRONMENT=IS_ALPHA=no
-endif
-TESTS=test_all.pl
CFL=$(AM_CFLAGS) $(AM_CPPFLAGS) \
$(NATIVE_DRIVER_CFLAGS) $(INCORE_DRIVER_CFLAGS) \
test_copy_SOURCES=test_copy.c $(CMNSRC)
test_copy_CFLAGS=$(CFL)
-test_copy_LDADD=$(LIBS)
test_copy_DEPENDENCIES=$(LIBS)
test_stats_SOURCES=test_stats.c $(CMNSRC)
test_stats_CFLAGS=$(CFL)
-test_stats_LDADD=$(LIBS)
test_stats_DEPENDENCIES=$(LIBS)
test_path_SOURCES=test_path.c $(CMNSRC)
test_path_CFLAGS=$(CFL)
-test_path_LDADD=$(LIBS)
test_path_DEPENDENCIES=$(LIBS)
test_list_SOURCES=test_list.c $(CMNSRC)
test_list_CFLAGS=$(CFL)
-test_list_LDADD=$(LIBS)
test_list_DEPENDENCIES=$(LIBS)
test_getcwd_SOURCES=test_getcwd.c $(CMNSRC)
test_getcwd_CFLAGS=$(CFL)
-test_getcwd_LDADD=$(LIBS)
test_getcwd_DEPENDENCIES=$(LIBS)
test_link_SOURCES=test_link.c $(CMNSRC)
test_link_CFLAGS=$(CFL)
-test_link_LDADD=$(LIBS)
test_link_DEPENDENCIES=$(LIBS)
test_unlink_SOURCES=test_unlink.c $(CMNSRC)
test_unlink_CFLAGS=$(CFL)
-test_unlink_LDADD=$(LIBS)
test_unlink_DEPENDENCIES=$(LIBS)
test_rename_SOURCES=test_rename.c $(CMNSRC)
test_rename_CFLAGS=$(CFL)
-test_rename_LDADD=$(LIBS)
test_rename_DEPENDENCIES=$(LIBS)
test_regions_SOURCES=test_regions.c $(CMNSRC)
test_regions_CFLAGS=$(CFL)
-test_regions_LDADD=$(LIBS)
test_regions_DEPENDENCIES=$(LIBS)
-test_driver_SOURCES=test_driver.c sysio_tests.c sysio_stubs.c help.c $(CMNSRC)
-test_driver_CFLAGS=$(CFL)
-test_driver_LDADD=$(LIBS)
-test_driver_DEPENDENCIES=$(LIBS)
-
test_stddir_SOURCES=test_stddir.c $(CMNSRC)
test_stddir_CFLAGS=$(CFL)
-test_stddir_LDADD=$(LIBS)
test_stddir_DEPENDENCIES=$(LIBS)
+test_fcntl_lock_SOURCES=test_fcntl_lock.c $(CMNSRC)
+test_fcntl_lock_CFLAGS=$(CFL)
+test_fcntl_lock_DEPENDENCIES=$(LIBS)
+
drv_data.c: $(CONFIG_DEPENDENCIES) $(top_srcdir)/tests/gendrvdata.sh
test -z "drv_data.c" && rm -f drv_data.c; \
$(SHELL) $(top_srcdir)/tests/gendrvdata.sh $(DRIVERS) > drv_data.c
-TESTS_EXTRA = $(shell ls tests/*.[ch] tests/*.sh tests/*.p[lm]) \
+TESTS_EXTRA = $(shell ls tests/*.[ch]) \
tests/Makefile.am tests/Makefile.in tests/module.mk
#include <sys/types.h>
#include <sys/queue.h>
-#include "xtio.h"
#include "test.h"
#include "sysio.h"
+#include "xtio.h"
int
_test_sysio_startup()
{
int err;
- const char *cwd;
- const char *s;
+ char *arg;
err = _sysio_init();
if (err)
err = drv_init_all();
if (err)
return err;
- s = getenv("SYSIO_NAMESPACE");
- if (!(s || (s = getenv("SYSIO_MANUAL")))) {
+#if SYSIO_TRACING
+ /*
+ * tracing
+ */
+ arg = getenv("SYSIO_TRACING");
+ err = _sysio_boot("trace", arg);
+ if (err)
+ return err;
+#endif
+ /*
+ * namespace
+ */
+ arg = getenv("SYSIO_NAMESPACE");
+ if (!(arg || (arg = getenv("SYSIO_MANUAL")))) {
/*
- * Assume a native mount at root.
+ * Assume a native mount at root with automounts enabled.
*/
- s = "{mnt,dev=\"native:/\",dir=/,fl=0}";
+ arg = "{mnt,dev=\"native:/\",dir=/,fl=2}";
}
- cwd = getenv("SYSIO_CWD");
-#if DEFER_INIT_CWD
- err = _sysio_boot(s, cwd ? cwd : "/");
-#else
- err = _sysio_boot(s);
-#endif
+ err = _sysio_boot("namespace", arg);
if (err)
return err;
-
-#if !DEFER_INIT_CWD
- if (!cwd)
- s = "/";
- err = chdir(s);
+#if DEFER_INIT_CWD
+ /*
+ * Current working directory.
+ */
+ arg = getenv("SYSIO_CWD");
+ if (!arg)
+ arg = "/";
+ err = _sysio_boot("cwd", arg);
if (err)
return err;
#endif
-
return 0;
}
if (err) {
errno = -err;
perror("sysio startup");
- exit(1);
+ abort();
}
if (atexit(_test_sysio_shutdown) != 0) {
perror("atexit");
- exit(1);
+ abort();
}
}
#include <sys/uio.h>
#include <sys/queue.h>
+#if defined(SYSIO_LABEL_NAMES)
+#include "sysio.h"
+#endif
#include "xtio.h"
#include "test.h"
{
int fd;
- fd = open(path, flags, mode);
+ fd = SYSIO_INTERFACE_NAME(open)(path, flags, mode);
if (fd < 0)
perror(path);
int sfd, dfd;
int flags;
int rtn;
- static char buf[1024];
+ struct stat stat;
+ char *buf;
+ size_t bufsiz;
ssize_t cc, wcc;
sfd = dfd = -1;
rtn = -1;
+ buf = NULL;
sfd = open_file(spath, O_RDONLY, 0);
if (sfd < 0)
if (dfd < 0)
goto out;
- while ((cc = read(sfd, buf, sizeof(buf))) > 0)
- if ((wcc = write(dfd, buf, cc)) != cc) {
+ rtn = SYSIO_INTERFACE_NAME(fstat)(dfd, &stat);
+ if (rtn != 0) {
+ perror(dpath);
+ goto out;
+ }
+ bufsiz = stat.st_blksize;
+ if (bufsiz < (64 * 1024))
+ bufsiz =
+ (((64 * 1024) / stat.st_blksize - 1) + 1) * (64 * 1024);
+ buf = malloc(bufsiz);
+ if (!buf) {
+ perror(dpath);
+ goto out;
+ }
+
+ while ((cc = SYSIO_INTERFACE_NAME(read)(sfd, buf, bufsiz)) > 0)
+ if ((wcc = SYSIO_INTERFACE_NAME(write)(dfd, buf, cc)) != cc) {
if (wcc < 0) {
perror(dpath);
break;
(unsigned )cc);
break;
}
- if (cc < 0)
+ if (cc < 0) {
perror(spath);
+ rtn = -1;
+ }
out:
- if (sfd >= 0 && close(sfd) != 0)
+ if (buf)
+ free(buf);
+ if (sfd >= 0 && SYSIO_INTERFACE_NAME(close)(sfd) != 0)
perror(spath);
- if (dfd >= 0 && (fsync(dfd) != 0 || close(dfd) != 0))
+ if (dfd >= 0 &&
+ (SYSIO_INTERFACE_NAME(fsync)(dfd) != 0 ||
+ SYSIO_INTERFACE_NAME(close)(dfd) != 0))
perror(dpath);
- return 0;
+ return rtn;
}
#include <sys/queue.h>
#include <dirent.h>
+#if defined(SYSIO_LABEL_NAMES)
+#include "sysio.h"
+#endif
#include "xtio.h"
#include "mount.h"
{
char *buf;
- if (chdir(path) != 0) {
+ if (SYSIO_INTERFACE_NAME(chdir)(path) != 0) {
perror(path);
return -1;
}
- buf = getcwd(NULL, 0);
+ buf = SYSIO_INTERFACE_NAME(getcwd)(NULL, 0);
if (!buf) {
perror(path);
return -1;
#include <sys/uio.h>
#include <sys/queue.h>
+#if defined(SYSIO_LABEL_NAMES)
+#include "sysio.h"
+#endif
#include "xtio.h"
#include "test.h"
old = argv[optind++];
new = argv[optind++];
- if ((err = link(old, new)) != 0) {
+ if ((err = SYSIO_INTERFACE_NAME(link)(old, new)) != 0) {
perror("link");
break;
}
- if ((err = lstat(new, &stbuf)) != 0) {
+ if ((err = SYSIO_INTERFACE_NAME(lstat)(new, &stbuf)) != 0) {
perror(new);
break;
}
#include <sys/uio.h>
#include <sys/queue.h>
+#if defined(SYSIO_LABEL_NAMES)
+#include "sysio.h"
+#endif
#include "xtio.h"
#include "test.h"
off_t base;
ssize_t cc;
- fd = open(path, O_RDONLY);
+ fd = SYSIO_INTERFACE_NAME(open)(path, O_RDONLY);
if (fd < 0) {
perror(path);
return -1;
goto out;
}
- base = 0;
- while ((cc = getdirentries(fd, (char *)buf, n, &base)) > 0) {
+ while ((cc = SYSIO_INTERFACE_NAME(getdirentries)(fd,
+ (char *)buf,
+ n,
+ &base)) > 0) {
dp = buf;
while (cc > 0) {
(void )printf("\t%s: ino %llu type %u\n",
cc -= dp->d_reclen;
dp = (struct dirent *)((char *)dp + dp->d_reclen);
}
- if (!base)
- break;
}
out:
{
int oerrno = errno;
- if (close(fd) != 0) {
+ if (SYSIO_INTERFACE_NAME(close)(fd) != 0) {
perror(path);
if (cc < 0)
errno = oerrno;
#include <unistd.h>
#include <sys/uio.h>
+#if defined(SYSIO_LABEL_NAMES)
+#include "sysio.h"
+#endif
#include "xtio.h"
#include "test.h"
/*
* Get file attrs.
*/
- err = lstat(path, &stbuf);
+ err = SYSIO_INTERFACE_NAME(lstat)(path, &stbuf);
if (err) {
perror(path);
return -1;
* Print path and type.
*/
if (S_ISLNK(stbuf.st_mode)) {
- cc = readlink(path, buf, sizeof(buf));
+ cc = SYSIO_INTERFACE_NAME(readlink)(path, buf, sizeof(buf));
if (cc < 0) {
perror(path);
return -1;
#include <fcntl.h>
#include <sys/uio.h>
+#if defined(SYSIO_LABEL_NAMES)
+#include "sysio.h"
+#endif
#include "xtio.h"
#include "test.h"
if (use64)
flags |= O_LARGEFILE;
#endif
- fd = open(path, flags, 0666);
+ fd = SYSIO_INTERFACE_NAME(open)(path, flags, 0666);
if (fd < 0) {
perror(path);
err = 1;
}
#ifdef GO64
if (use64)
- off64 = lseek64(fd, off64, SEEK_SET);
+ off64 = SYSIO_INTERFACE_NAME(lseek64)(fd, off64, SEEK_SET);
else
off64 =
#endif
- off = lseek(fd, off, SEEK_SET);
+ off = SYSIO_INTERFACE_NAME(lseek)(fd, off, SEEK_SET);
#ifdef GO64
if ((use64 && off64 < 0) || (!use64 && off < 0)) {
perror(use64 ? "lseek64" : "lseek");
}
#endif
if (which == 'r')
- cc = read(fd, buf, nbytes);
+ cc = SYSIO_INTERFACE_NAME(read)(fd, buf, nbytes);
else
- cc = write(fd, buf, nbytes);
+ cc = SYSIO_INTERFACE_NAME(write)(fd, buf, nbytes);
if (cc < 0) {
perror(path);
err = 1;
}
#ifdef GO64
if (use64) {
- off64 = lseek64(fd, 0, SEEK_CUR);
+ off64 = SYSIO_INTERFACE_NAME(lseek64)(fd, 0, SEEK_CUR);
} else
off64 =
#endif
- off = lseek(fd, 0, SEEK_CUR);
+ off = SYSIO_INTERFACE_NAME(lseek)(fd, 0, SEEK_CUR);
(void )printf(("%s%s@"
#ifdef GO64
"%lld"
);
error:
- if (fd > 0 && close(fd) != 0)
+ if (fd > 0 && SYSIO_INTERFACE_NAME(close)(fd) != 0)
perror(path);
free(buf);
out:
#include <fcntl.h>
#include <sys/uio.h>
+#if defined(SYSIO_LABEL_NAMES)
+#include "sysio.h"
+#endif
#include "xtio.h"
#include "test.h"
exit(1);
}
- (void )umask(022);
+ (void )SYSIO_INTERFACE_NAME(umask)(022);
/*
* Source
if (argc - optind)
usage();
- err = rename(spath, dpath);
+ err = SYSIO_INTERFACE_NAME(rename)(spath, dpath);
if (err)
perror("rename");
#endif
#include <sys/uio.h>
+#if defined(SYSIO_LABEL_NAMES)
+#include "sysio.h"
+#endif
#include "xtio.h"
#include "test.h"
exit(1);
}
- (void )umask(022);
+ (void )SYSIO_INTERFACE_NAME(umask)(022);
while (optind < argc)
do_stats(argv[optind++]);
struct statvfs stvfsbuf1, stvfsbuf2;
#endif
- fd = open(path, O_RDONLY);
+ fd = SYSIO_INTERFACE_NAME(open)(path, O_RDONLY);
if (fd < 0) {
perror(path);
return;
}
- err = fstat(fd, &stbuf1);
+ err = SYSIO_INTERFACE_NAME(fstat)(fd, &stbuf1);
if (!err)
- err = stat(path, &stbuf2);
+ err = SYSIO_INTERFACE_NAME(stat)(path, &stbuf2);
#ifdef notdef
if (!err)
- err = fstatvfs(fd, &stvfsbuf1);
+ err = SYSIO_INTERFACE_NAME(fstatvfs)(fd, &stvfsbuf1);
if (!err)
- err = statvfs(path, &stvfsbuf1);
+ err = SYSIO_INTERFACE_NAME(statvfs)(path, &stvfsbuf1);
#endif
if (err) {
perror(path);
(unsigned long )stbuf1.st_mtime,
(unsigned long )stbuf1.st_ctime);
out:
- if (close(fd) != 0)
+ if (SYSIO_INTERFACE_NAME(close)(fd) != 0)
perror("closing file");
}
#include <dirent.h>
#include <sys/types.h>
+#if defined(SYSIO_LABEL_NAMES)
+#include "sysio.h"
+#endif
#include "xtio.h"
#include "test.h"
printf("testing directory functions on %s\n", path);
- if ((d = opendir(path)) == NULL) {
+ if ((d = SYSIO_INTERFACE_NAME(opendir)(path)) == NULL) {
perror(path);
return errno;
}
- while ((de = readdir(d)) != NULL)
+ while ((de = SYSIO_INTERFACE_NAME(readdir)(d)) != NULL)
printf("\t %s: ino %lu off %lu type %u\n",
de->d_name, (unsigned long )de->d_ino,
(unsigned long )de->d_off, (int )de->d_type);
- if (closedir(d)) {
+ if (SYSIO_INTERFACE_NAME(closedir)(d)) {
perror("closedir");
return errno;
}
#endif
#include <sys/uio.h>
+#if defined(SYSIO_LABEL_NAMES)
+#include "sysio.h"
+#endif
#include "xtio.h"
#include "test.h"
unlinkit(const char *path)
{
- if (unlink(path) != 0) {
+ if (SYSIO_INTERFACE_NAME(unlink)(path) != 0) {
perror(path);
return -1;
}