Thread: [Libsysio-commit] HEAD: libsysio/drivers/native fs_native.c
Brought to you by:
lward
From: Ruth K. <rk...@us...> - 2003-07-26 05:21:22
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv25000/drivers/native Modified Files: fs_native.c Log Message: Add capability of checking inode generation numbers, if a field for it exists in the stat struct. Bug fix for unlink/creat failure: Changes allow re-use of an inode which is no longer in use, but still exists in the inode cache. If the stat info for the new use matches cached info, the inode is re-used. If not, the old inode is marked 'zombie' and removed from the inode cache to make way for the new inode. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -w -b -B -p -r1.11 -r1.12 --- fs_native.c 23 Apr 2003 18:18:38 -0000 1.11 +++ fs_native.c 25 Jul 2003 14:45:34 -0000 1.12 @@ -151,6 +151,9 @@ do { struct native_inode_identifier { dev_t dev; /* device number */ ino_t ino; /* i-number */ +#ifdef HAVE_GENERATION + unsigned int gen; /* generation number */ +#endif }; /* @@ -310,8 +313,12 @@ native_i_new(struct filesys *fs, struct nino = malloc(sizeof(struct native_inode)); if (!nino) return NULL; + bzero(&nino->ni_ident, sizeof(nino->ni_ident)); nino->ni_ident.dev = buf->st_dev; nino->ni_ident.ino = buf->st_ino; +#ifdef HAVE_GENERATION + nino->ni_ident.gen = buf->st_gen; +#endif nino->ni_fileid.fid_data = &nino->ni_ident; nino->ni_fileid.fid_len = sizeof(nino->ni_ident); nino->ni_fd = -1; @@ -496,6 +503,27 @@ native_fsswop_mount(const char *source, return err; } +static int +native_i_validate(struct inode *inop, struct intnl_stat stbuf) +{ + /* + * Validate passed in inode against stat struct info + */ + struct native_inode *nino = I2NI(inop); + + if ((nino->ni_ident.dev == stbuf.st_dev && + nino->ni_ident.ino == stbuf.st_ino && +#ifdef HAVE_GENERATION + nino->ni_ident.gen == stbuf.st_gen && +#endif + ((inop)->i_mode & stbuf.st_mode) == (inop)->i_mode) && + ((!(S_ISCHR((inop)->i_mode) || S_ISBLK((inop)->i_mode)) || + (inop)->i_rdev == stbuf.st_rdev))) + return 0; + + return 1; +} + /* * Find, and validate, or create i-node by host-relative path. Returned i-node * is referenced. @@ -525,11 +553,7 @@ native_iget(struct filesys *fs, * Validate? */ if (*inop) { - struct native_inode *nino = I2NI(*inop); - - if (nino->ni_ident.dev == stbuf.st_dev && - nino->ni_ident.ino == stbuf.st_ino && - ((*inop)->i_mode & stbuf.st_mode) == (*inop)->i_mode) + if (!native_i_validate(*inop, stbuf)) return 0; /* * Invalidate. @@ -540,23 +564,40 @@ native_iget(struct filesys *fs, /* * I-node is not already known. Find or create it. */ + bzero(&ident, sizeof(ident)); ident.dev = stbuf.st_dev; ident.ino = stbuf.st_ino; +#ifdef HAVE_GENERATION + ident.gen = stbuf.st_gen; +#endif fileid.fid_data = &ident; fileid.fid_len = sizeof(ident); ino = _sysio_i_find(fs, stbuf.st_ino, &fileid); - if (!ino) { - ino = native_i_new(fs, &stbuf); - if (!ino) - err = -ENOMEM; - } else if (forced) { + if (ino && forced) { /* * Insertion was forced but it's already present! */ + if (native_i_validate(ino, stbuf)) { + /* + * Cached inode has stale attrs + * make way for the new one + */ I_RELE(ino); - err = -EEXIST; + _sysio_i_undead(ino); + ino = NULL; + } else + /* + * OK to reuse cached inode + */ + goto out; } + if (!ino) { + ino = native_i_new(fs, &stbuf); + if (!ino) + err = -ENOMEM; + } +out: if (!err) *inop = ino; return err; |
From: Ruth K. <rk...@us...> - 2003-07-29 18:46:25
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv1879 Modified Files: fs_native.c Log Message: correct error setting Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -w -b -B -p -r1.12 -r1.13 --- fs_native.c 25 Jul 2003 14:45:34 -0000 1.12 +++ fs_native.c 29 Jul 2003 18:29:32 -0000 1.13 @@ -1024,7 +1024,8 @@ native_inop_unlink(struct pnode *pno) * (usually .NFSXXXXXX, where the X's are replaced by the PID and some * unique characters) in order to simulate the proper semantic. */ - err = syscall(SYS_unlink, path); + if (!syscall(SYS_unlink, path)) + err = -errno; free(path); return err; } |
From: Ruth K. <rk...@us...> - 2003-08-01 18:05:10
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv2804 Modified Files: fs_native.c Log Message: fixed mode check, rename so the if's make sense Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -w -b -B -p -r1.13 -r1.14 --- fs_native.c 29 Jul 2003 18:29:32 -0000 1.13 +++ fs_native.c 1 Aug 2003 18:05:07 -0000 1.14 @@ -504,24 +504,24 @@ native_fsswop_mount(const char *source, } static int -native_i_validate(struct inode *inop, struct intnl_stat stbuf) +native_i_invalid(struct inode *inop, struct intnl_stat stbuf) { /* * Validate passed in inode against stat struct info */ struct native_inode *nino = I2NI(inop); - if ((nino->ni_ident.dev == stbuf.st_dev && - nino->ni_ident.ino == stbuf.st_ino && + if ((nino->ni_ident.dev != stbuf.st_dev || + nino->ni_ident.ino != stbuf.st_ino || #ifdef HAVE_GENERATION - nino->ni_ident.gen == stbuf.st_gen && + nino->ni_ident.gen != stbuf.st_gen || #endif - ((inop)->i_mode & stbuf.st_mode) == (inop)->i_mode) && - ((!(S_ISCHR((inop)->i_mode) || S_ISBLK((inop)->i_mode)) || - (inop)->i_rdev == stbuf.st_rdev))) - return 0; - + ((inop)->i_mode & S_IFMT) != (stbuf.st_mode & S_IFMT)) || + (((inop)->i_rdev != stbuf.st_rdev) && + (S_ISCHR((inop)->i_mode) || S_ISBLK((inop)->i_mode)))) return 1; + + return 0; } /* @@ -553,7 +553,7 @@ native_iget(struct filesys *fs, * Validate? */ if (*inop) { - if (!native_i_validate(*inop, stbuf)) + if (!native_i_invalid(*inop, stbuf)) return 0; /* * Invalidate. @@ -577,7 +577,7 @@ native_iget(struct filesys *fs, /* * Insertion was forced but it's already present! */ - if (native_i_validate(ino, stbuf)) { + if (native_i_invalid(ino, stbuf)) { /* * Cached inode has stale attrs * make way for the new one @@ -1006,7 +1006,7 @@ static int native_inop_unlink(struct pnode *pno) { char *path; - int err; + int err = 0; path = _sysio_pb_path(pno->p_base, '/'); if (!path) |
From: Ruth K. <rk...@us...> - 2003-08-04 15:30:30
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv21474 Modified Files: fs_native.c Log Message: error check Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -w -b -B -p -r1.14 -r1.15 --- fs_native.c 1 Aug 2003 18:05:07 -0000 1.14 +++ fs_native.c 4 Aug 2003 15:30:27 -0000 1.15 @@ -1024,7 +1024,7 @@ native_inop_unlink(struct pnode *pno) * (usually .NFSXXXXXX, where the X's are replaced by the PID and some * unique characters) in order to simulate the proper semantic. */ - if (!syscall(SYS_unlink, path)) + if (syscall(SYS_unlink, path) != 0) err = -errno; free(path); return err; |
From: Ruth K. <rk...@us...> - 2003-08-14 18:50:18
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv16191/drivers/native Modified Files: fs_native.c Log Message: merge cplant branch into head Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -w -b -B -p -r1.15 -r1.16 --- fs_native.c 4 Aug 2003 15:30:27 -0000 1.15 +++ fs_native.c 14 Aug 2003 18:39:33 -0000 1.16 @@ -116,9 +116,19 @@ do { (dest)->st_gen = (src)->st_gen; \ } while (0); +/* SYS_lseek has a different interface on alpha + */ +#define CALL_LSEEK(fd, off, rc, wh) \ + (rc = syscall(SYS_lseek, fd, off, wh)) + #else + #define __native_stat intnl_stat #define COPY_STAT(src, dest) *(dest) = *(src) + +#define CALL_LSEEK(fd, off, rc, wh) \ + (syscall(SYS_lseek, fd, off, &rc, wh)) + #endif #if defined(USE_NATIVE_STAT) @@ -293,10 +303,12 @@ static int native_fstat(int fd, struct intnl_stat *buf) { int err; + struct __native_stat stbuf; - err = syscall(__SYS_FSTAT, fd, buf); + err = syscall(__SYS_FSTAT, fd, &stbuf); if (err) err = -errno; + COPY_STAT(&stbuf, buf); return err; } @@ -829,10 +841,9 @@ native_getdirentries(struct inode *ino, result = *basep; if (*basep != nino->ni_fpos && - syscall(SYS_lseek, - nino->ni_fd, + CALL_LSEEK(nino->ni_fd, *basep, - &result, + result, SEEK_SET) == -1) return -errno; nino->ni_fpos = result; @@ -1075,10 +1086,9 @@ doio(ssize_t (*f)(int, const struct iove !(S_ISCHR(ino->i_mode) || S_ISSOCK(ino->i_mode) || S_ISFIFO(ino->i_mode)) && - syscall(SYS_lseek, - nino->ni_fd, + CALL_LSEEK(nino->ni_fd, ioctx->ioctx_offset, - &result, + result, SEEK_SET) == -1) { ioctx->ioctx_cc = -1; ioctx->ioctx_errno = errno; |
From: Lee W. <lw...@us...> - 2003-09-27 20:19:13
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv6348/drivers/native Modified Files: fs_native.c Log Message: - Better checking during chdir(). - Added _sysio_p_chdir() to call change working directory with a pnode. - test_path.c doesn't follow symlinks anymore. - sysio_stubs.c defined a bunch of disk ioctl's inappropriately. Removed. - Added fchmod(), fchown(), rename(), link(), utime(). Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -w -b -B -p -r1.16 -r1.17 --- fs_native.c 14 Aug 2003 18:39:33 -0000 1.16 +++ fs_native.c 27 Sep 2003 19:42:02 -0000 1.17 @@ -132,12 +132,12 @@ do { #endif #if defined(USE_NATIVE_STAT) -#define __SYS_STAT SYS_stat +#define __SYS_STAT SYS_lstat #define __SYS_FSTAT SYS_fstat #define __SYS_TRUNCATE SYS_truncate #define __SYS_FTRUNCATE SYS_ftruncate #else -#define __SYS_STAT SYS_stat64 +#define __SYS_STAT SYS_lstat64 #define __SYS_FSTAT SYS_fstat64 #define __SYS_TRUNCATE SYS_truncate64 #define __SYS_FTRUNCATE SYS_ftruncate64 @@ -202,7 +202,9 @@ static int native_inop_symlink(struct pn static int native_inop_readlink(struct pnode *pno, char *buf, size_t bufsiz); static int native_inop_open(struct pnode *pno, int flags, mode_t mode); static int native_inop_close(struct inode *ino); +static int native_inop_link(struct pnode *old, struct pnode *new); static int native_inop_unlink(struct pnode *pno); +static int native_inop_rename(struct pnode *old, struct pnode *new); static int native_inop_ipreadv(struct inode *ino, struct io_arguments *ioargs, struct ioctx **ioctxp); @@ -233,7 +235,9 @@ static struct inode_ops native_i_ops = { native_inop_readlink, native_inop_open, native_inop_close, + native_inop_link, native_inop_unlink, + native_inop_rename, native_inop_ipreadv, native_inop_ipwritev, native_inop_iodone, @@ -1014,6 +1018,32 @@ native_inop_close(struct inode *ino) } static int +native_inop_link(struct pnode *old, struct pnode *new) +{ + int err; + char *opath, *npath; + + err = 0; + + opath = _sysio_pb_path(old->p_base, '/'); + npath = _sysio_pb_path(new->p_base, '/'); + if (!(opath && npath)) { + err = -ENOMEM; + goto out; + } + + err = syscall(SYS_link, opath, npath); + +out: + if (opath) + free(opath); + if (npath) + free(npath); + + return err; +} + +static int native_inop_unlink(struct pnode *pno) { char *path; @@ -1118,6 +1148,30 @@ _readv(int fd, const struct iovec *vecto { return syscall(SYS_readv, fd, vector, count); +} + +static int +native_inop_rename(struct pnode *old, struct pnode *new) +{ + int err; + char *opath, *npath; + + opath = _sysio_pb_path(old->p_base, '/'); + npath = _sysio_pb_path(new->p_base, '/'); + if (!(opath && npath)) { + err = -ENOMEM; + goto out; + } + + err = syscall(SYS_rename, opath, npath); + +out: + if (opath) + free(opath); + if (npath) + free(npath); + + return err; } static int |
From: Lee W. <lw...@us...> - 2003-10-10 18:52:06
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv14350/drivers/native Modified Files: fs_native.c Log Message: Red Storm branch mega-merge. Please, no more changes to any of the Red Storm branches. We'll keep them for reference for awhile but then, they go away. Finally! Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -w -b -B -p -r1.17 -r1.18 --- fs_native.c 27 Sep 2003 19:42:02 -0000 1.17 +++ fs_native.c 10 Oct 2003 18:50:31 -0000 1.18 @@ -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> @@ -69,6 +73,21 @@ #include "fs_native.h" +#ifdef REDSTORM +#include <catamount/syscall.h> /* ! in sys include? */ +#endif + +#ifdef REDSTORM +/* + * The cnos IO routines on Red Storm can't do scatter/gather IO. We + * must use a different interface, then. The doio() routine will loop + * over the vector entries. + */ +typedef ssize_t (*iof)(int, void *, size_t, _SYSIO_OFF_T); +#else +typedef ssize_t (*iof)(int, const struct iovec *, int); +#endif + /* * Local host file system driver. */ @@ -126,9 +145,6 @@ do { #define __native_stat intnl_stat #define COPY_STAT(src, dest) *(dest) = *(src) -#define CALL_LSEEK(fd, off, rc, wh) \ - (syscall(SYS_lseek, fd, off, &rc, wh)) - #endif #if defined(USE_NATIVE_STAT) @@ -195,7 +211,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); @@ -219,9 +235,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 = { @@ -246,7 +264,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 }; @@ -831,30 +851,92 @@ out: return err; } +static int +native_pos(int fd, +#if _LARGEFILE64_SOURCE + loff_t *offset +#else + _SYSIO_OFF_T *offset +#endif + ) +{ + + assert(fd >= 0); + assert(*offset >= 0); + +#if _LARGEFILE64_SOURCE && defined(SYS__llseek) + { + int err; + err = + syscall(SYS__llseek, + (unsigned int)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; +#ifndef SYS_getdirentries +#if _LARGEFILE64_SOURCE loff_t result; +#else + _SYSIO_OFF_T result; +#endif +#endif ssize_t cc; assert(nino->ni_fd >= 0); +#ifndef SYS_getdirentries result = *basep; - if (*basep != nino->ni_fpos && - CALL_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; +#ifdef SYS_getdents64 cc = syscall(SYS_getdents64, nino->ni_fd, buf, nbytes); +#else + cc = syscall(SYS_getdents, nino->ni_fd, buf, nbytes); +#endif +#else /* defined(SYS_getdirentries) */ + cc = + syscall(SYS_getdirentries, + nino->ni_fd, + buf, + nbytes, + basep, + &nino->ni_fpos); +#endif /* !defined(SYS_getdirentries) */ if (cc < 0) return -errno; +#ifndef SYS_getdirentries nino->ni_fpos += cc; +#endif return cc; } @@ -1078,14 +1160,20 @@ native_inop_unlink(struct pnode *pno) * now. */ static int -doio(ssize_t (*f)(int, const struct iovec *, int), +doio(iof f, struct inode *ino, struct io_arguments *ioargs, struct ioctx **ioctxp) { struct native_inode *nino = I2NI(ino); struct ioctx *ioctx; +#ifndef REDSTORM +#if _LARGEFILE64_SOURCE loff_t result; +#else + _SYSIO_OFF_T result; +#endif +#endif assert(nino->ni_fd >= 0); @@ -1099,9 +1187,17 @@ doio(ssize_t (*f)(int, const struct iove if (!ioctx) return -ENOMEM; + if ((ioargs->ioarg_iovlen && (int )ioargs->ioarg_iovlen < 0) || + !(S_ISREG(ino->i_mode) || + S_ISCHR(ino->i_mode) || + S_ISSOCK(ino->i_mode) || + S_ISFIFO(ino->i_mode))) + return -EINVAL; + +#ifndef REDSTORM /* * 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. @@ -1111,44 +1207,81 @@ doio(ssize_t (*f)(int, const struct iove * Avoid the reposition call if we're already at the right place. * 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)) && - CALL_LSEEK(nino->ni_fd, - ioctx->ioctx_offset, - result, - SEEK_SET) == -1) { + result = ioctx->ioctx_offset; + 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; + } + nino->ni_fpos = result; + } +#endif + /* * Call the appropriate (read/write) IO function to * transfer the data now. */ - nino->ni_fpos = result; +#ifdef REDSTORM + { + size_t count = ioctx->ioctx_iovlen; + struct iovec *iov = ioctx->ioctx_iovec; + ssize_t cc; + + while (count) { + cc = + (*f)(nino->ni_fd, + iov->base, + iov->len, + nino->ni_fpos); + if (cc < 0) { + if (ioctx->ioctx_cc) { + /* + * No data written at all. Return + * error. + */ + ioctx->ioctx_cc = -1; + } + break; + } + count--, iov++; + } + } +#else /* !defined(REDSTORM) */ ioctx->ioctx_cc = (*f)(nino->ni_fd, ioctx->ioctx_iovec, ioctx->ioctx_iovlen); +#endif /* defined(REDSTORM) */ if (ioctx->ioctx_cc < 0) ioctx->ioctx_errno = errno; if (ioctx->ioctx_cc > 0) nino->ni_fpos += ioctx->ioctx_cc; - } *ioctxp = ioctx; +out: return 0; } /* * Helper function passed to doio(), above, to accomplish a real readv. */ +#ifdef REDSTORM +static ssize_t +native_read(int fd, void *buf, size_t count, _SYSIO_OFF_T offset) +{ + + return syscall(SYS_pread, fd, buf, count, offset); +} +#else static ssize_t -_readv(int fd, const struct iovec *vector, int count) +native_read(int fd, const struct iovec *vector, int count) { return syscall(SYS_readv, fd, vector, count); } +#endif static int native_inop_rename(struct pnode *old, struct pnode *new) @@ -1180,18 +1313,27 @@ native_inop_ipreadv(struct inode *ino, struct ioctx **ioctxp) { - return doio(_readv, ino, ioargs, ioctxp); + return doio(native_read, ino, ioargs, ioctxp); } /* * Helper function passed to doio(), above, to accomplish a real writev. */ +#ifdef REDSTORM static ssize_t -_writev(int fd, const struct iovec *vector, int count) +native_write(int fd, void *buf, size_t count, _SYSIO_OFF_T offset) +{ + + return syscall(SYS_pwrite, fd, buf, count, offset); +} +#else +static ssize_t +native_write(int fd, const struct iovec *vector, int count) { return syscall(SYS_writev, fd, vector, count); } +#endif static int native_inop_ipwritev(struct inode *ino, @@ -1199,7 +1341,7 @@ native_inop_ipwritev(struct inode *ino, struct ioctx **ioctxp) { - return doio(_writev, ino, ioargs, ioctxp); + return doio(native_write, ino, ioargs, ioctxp); } static int @@ -1234,6 +1376,7 @@ native_inop_mknod(struct pnode *pno __IS return -ENOSYS; } +#ifdef _HAVE_STATVFS static int native_inop_statvfs(struct pnode *pno, struct inode *ino, @@ -1279,6 +1422,7 @@ native_inop_statvfs(struct pnode *pno, buf->f_namemax = fs.f_namelen; return 0; } +#endif static int native_inop_sync(struct inode *ino) @@ -1295,7 +1439,14 @@ 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 +#if 0 +#warning No fdatasync system call -- Using fsync instead! +#endif + return syscall(SYS_fsync, I2NI(ino)->ni_fd); +#endif } static int |
From: Lee W. <lw...@us...> - 2003-10-13 01:04:43
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv31768/drivers/native Modified Files: fs_native.c Log Message: The IO context record supported one call-back. It now supports a chain. This was changed to accommodate the Sandia-PVFS driver. Also, it's needed for the, coming, {read,write}_strided calls. To add a callback to the chain use: _sysio_ioctx_cb(struct ioctx *ioctx, void (*func)(struct ioctx *, void *), void *data) Callbacks are added to the end of the existing chain. When called, by _sysio_io_complete, they are run in order. So... If you're freeing things using callbacks be careful not to depend on something in a later callback that you previously free'd. Also, _sysio_io_complete no longer waits for the driver. To call this, now, is to signal completion. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -w -b -B -p -r1.18 -r1.19 --- fs_native.c 10 Oct 2003 18:50:31 -0000 1.18 +++ fs_native.c 13 Oct 2003 01:04:34 -0000 1.19 @@ -222,11 +222,9 @@ static int native_inop_link(struct pnode static int native_inop_unlink(struct pnode *pno); static int native_inop_rename(struct pnode *old, struct pnode *new); static int native_inop_ipreadv(struct inode *ino, - struct io_arguments *ioargs, - struct ioctx **ioctxp); + struct ioctx *ioctx); static int native_inop_ipwritev(struct inode *ino, - struct io_arguments *ioargs, - struct ioctx **ioctxp); + struct ioctx *ioctx); 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_sync(struct inode *ino); @@ -1162,11 +1160,9 @@ native_inop_unlink(struct pnode *pno) static int doio(iof f, struct inode *ino, - struct io_arguments *ioargs, - struct ioctx **ioctxp) + struct ioctx *ioctx) { struct native_inode *nino = I2NI(ino); - struct ioctx *ioctx; #ifndef REDSTORM #if _LARGEFILE64_SOURCE loff_t result; @@ -1177,17 +1173,7 @@ doio(iof f, assert(nino->ni_fd >= 0); - if (ioargs->ioarg_iovlen && (int )ioargs->ioarg_iovlen < 0) - return -EINVAL; - - /* - * Get a new IO context. - */ - ioctx = _sysio_ioctx_new(ino, ioargs); - if (!ioctx) - return -ENOMEM; - - if ((ioargs->ioarg_iovlen && (int )ioargs->ioarg_iovlen < 0) || + if ((ioctx->ioctx_iovlen && (int )ioctx->ioctx_iovlen < 0) || !(S_ISREG(ino->i_mode) || S_ISCHR(ino->i_mode) || S_ISSOCK(ino->i_mode) || @@ -1259,7 +1245,6 @@ doio(iof f, if (ioctx->ioctx_cc > 0) nino->ni_fpos += ioctx->ioctx_cc; - *ioctxp = ioctx; out: return 0; } @@ -1309,11 +1294,10 @@ out: static int native_inop_ipreadv(struct inode *ino, - struct io_arguments *ioargs, - struct ioctx **ioctxp) + struct ioctx *ioctx) { - return doio(native_read, ino, ioargs, ioctxp); + return doio(native_read, ino, ioctx); } /* @@ -1337,11 +1321,10 @@ native_write(int fd, const struct iovec static int native_inop_ipwritev(struct inode *ino, - struct io_arguments *ioargs, - struct ioctx **ioctxp) + struct ioctx *ioctx) { - return doio(native_write, ino, ioargs, ioctxp); + return doio(native_write, ino, ioctx); } static int |
From: Lee W. <lw...@us...> - 2003-10-15 18:01:33
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv9577/drivers/native Modified Files: fs_native.c Log Message: Eliminated the i-node number field from the inode structure. We already carry the file identifier so it was redundant. Problematic too, in that it can be 32 or 64 bits in size. This forced _sysio_i_new() and _sysio_i_find() to change -- They no longer take the i-node number as an argument. Updated the driver calls to reflect the new usage. The i-node cache is now indexed by hashing the file identifier as opposed to just using the, no longer maintained, i-node number. This caused _sysio_i_find to become 2+ percent more expensive to use. Acceptable for me. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -w -b -B -p -r1.19 -r1.20 --- fs_native.c 13 Oct 2003 01:04:34 -0000 1.19 +++ fs_native.c 15 Oct 2003 18:00:54 -0000 1.20 @@ -363,7 +363,6 @@ native_i_new(struct filesys *fs, struct nino->ni_fpos = 0; ino = _sysio_i_new(fs, - buf->st_ino, &nino->ni_fileid, #ifndef AUTOMOUNT_FILE_NAME buf->st_mode & S_IFMT, @@ -606,7 +605,7 @@ native_iget(struct filesys *fs, #endif fileid.fid_data = &ident; fileid.fid_len = sizeof(ident); - ino = _sysio_i_find(fs, stbuf.st_ino, &fileid); + ino = _sysio_i_find(fs, &fileid); if (ino && forced) { /* * Insertion was forced but it's already present! |
From: Lee W. <lw...@us...> - 2003-10-17 21:30:33
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv10931/drivers/native Modified Files: fs_native.c Log Message: Added a done bit to the IO context record to *positively* signal completion. Also, added a driver private pointer to the dsame record for handy use. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -w -b -B -p -r1.20 -r1.21 --- fs_native.c 15 Oct 2003 18:00:54 -0000 1.20 +++ fs_native.c 17 Oct 2003 21:30:29 -0000 1.21 @@ -1245,6 +1245,7 @@ doio(iof f, nino->ni_fpos += ioctx->ioctx_cc; out: + ioctx->ioctx_done = 1; return 0; } |
From: Lee W. <lw...@us...> - 2003-10-20 17:06:40
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv9788/native Modified Files: fs_native.c Log Message: From Ruth Klundt; If a file is opened twice the first close destroys the file descriptor in the low-level driver. Further use by the second, then, will get EBADF or, on close, aborts. Why was the open ref count code ifdef'd out? I did it and can't for the life of me recall why. Anyway, it's back now. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -w -b -B -p -r1.21 -r1.22 --- fs_native.c 17 Oct 2003 21:30:29 -0000 1.21 +++ fs_native.c 20 Oct 2003 16:44:36 -0000 1.22 @@ -191,9 +191,7 @@ struct native_inode { struct file_identifier ni_fileid; /* ditto */ int ni_fd; /* host fildes */ int ni_oflags; /* flags, from open */ -#if 0 unsigned ni_nopens; /* soft ref count */ -#endif off_t ni_fpos; /* current pos */ }; @@ -357,9 +355,7 @@ native_i_new(struct filesys *fs, struct nino->ni_fileid.fid_len = sizeof(nino->ni_ident); nino->ni_fd = -1; nino->ni_oflags = 0; -#if 0 nino->ni_nopens = 0; -#endif nino->ni_fpos = 0; ino = _sysio_i_new(fs, @@ -1048,10 +1044,8 @@ native_inop_open(struct pnode *pno, int * Remember this new open. */ nino = I2NI(pno->p_base->pb_ino); -#if 0 nino->ni_nopens++; assert(nino->ni_nopens); -#endif if (nino->ni_fd >= 0) { if ((nino->ni_oflags & O_RDWR) || @@ -1082,15 +1076,21 @@ native_inop_close(struct inode *ino) if (nino->ni_fd < 0) abort(); -#if 0 - assert(nino->ni_nopens); - if (--nino->ni_nopens) - return 0; -#endif - err = syscall(SYS_close, nino->ni_fd); if (err) return -errno; + + assert(nino->ni_nopens); + if (--nino->ni_nopens) { + /* + * Hmmm. We really don't need anything else. However, some + * filesystems try to implement a sync-on-close semantic. + * As this appears now, that is lost. Might want to change + * it somehow in the future? + */ + return 0; + } + nino->ni_fd = -1; nino->ni_fpos = 0; return 0; |
From: Lee W. <lw...@us...> - 2003-10-20 17:08:21
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv15731/native Modified Files: fs_native.c Log Message: From patch supplied by Sue Kelly. The RedStorm integration contained numerous bugs. Fixed are: a) Include uio.h now that we reference members directly. b) Update position before looping over the IO vector. c) Update ioctx_cc member of IO context after each successful partial transfer. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -w -b -B -p -r1.22 -r1.23 --- fs_native.c 20 Oct 2003 16:44:36 -0000 1.22 +++ fs_native.c 20 Oct 2003 17:01:31 -0000 1.23 @@ -74,6 +74,7 @@ #include "fs_native.h" #ifdef REDSTORM +#include <sys/uio.h> #include <catamount/syscall.h> /* ! in sys include? */ #endif @@ -1216,11 +1217,12 @@ doio(iof f, struct iovec *iov = ioctx->ioctx_iovec; ssize_t cc; + nino->ni_fpos = ioctx->ioctx_offset; while (count) { cc = (*f)(nino->ni_fd, - iov->base, - iov->len, + iov->iov_base, + iov->iov_len, nino->ni_fpos); if (cc < 0) { if (ioctx->ioctx_cc) { @@ -1232,6 +1234,7 @@ doio(iof f, } break; } + ioctx->ioctx_cc += cc; count--, iov++; } } |
From: Lee W. <lw...@us...> - 2003-10-21 16:51:25
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv24724/drivers/native Modified Files: fs_native.c Log Message: Hmmm. Make statvfs/statvfs64 work again. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -w -b -B -p -r1.23 -r1.24 --- fs_native.c 20 Oct 2003 17:01:31 -0000 1.23 +++ fs_native.c 21 Oct 2003 13:38:47 -0000 1.24 @@ -62,6 +62,7 @@ #endif #ifdef _HAVE_STATVFS #include <sys/statvfs.h> +#include <sys/statfs.h> #endif #include <utime.h> #include <sys/queue.h> |
From: Ruth K. <rk...@us...> - 2003-10-22 16:54:36
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv5402 Modified Files: fs_native.c Log Message: close native fd once after all refs are gone Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -w -b -B -p -r1.24 -r1.25 --- fs_native.c 21 Oct 2003 13:38:47 -0000 1.24 +++ fs_native.c 22 Oct 2003 15:57:23 -0000 1.25 @@ -1078,10 +1078,6 @@ native_inop_close(struct inode *ino) if (nino->ni_fd < 0) abort(); - err = syscall(SYS_close, nino->ni_fd); - if (err) - return -errno; - assert(nino->ni_nopens); if (--nino->ni_nopens) { /* @@ -1092,6 +1088,10 @@ native_inop_close(struct inode *ino) */ return 0; } + + err = syscall(SYS_close, nino->ni_fd); + if (err) + return -errno; nino->ni_fd = -1; nino->ni_fpos = 0; |
From: Ruth K. <rk...@us...> - 2004-01-12 18:07:18
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv4575 Modified Files: fs_native.c Log Message: remove obsolete macro Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.25 retrieving revision 1.26 diff -u -w -b -B -p -r1.25 -r1.26 --- fs_native.c 22 Oct 2003 15:57:23 -0000 1.25 +++ fs_native.c 12 Jan 2004 18:07:16 -0000 1.26 @@ -137,11 +137,6 @@ do { (dest)->st_gen = (src)->st_gen; \ } while (0); -/* SYS_lseek has a different interface on alpha - */ -#define CALL_LSEEK(fd, off, rc, wh) \ - (rc = syscall(SYS_lseek, fd, off, wh)) - #else #define __native_stat intnl_stat |
From: Lee W. <lw...@us...> - 2004-01-21 14:44:57
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv23555/drivers/native Modified Files: fs_native.c Log Message: A roll-up patch from CFS (Eric Mei <er...@cl...>) - intent.diff small changes on intent related behavior. I simply follow the lustre kernel code here. - open() need to pass down param 'flags'. - 'setattr' related syscalls, like chown/chmod/utime/..., don't need intent during path resolution. - sockets.diff your socket driver. - nativefs.diff only add fcntl code into native driver. not sure whether it's complete, but ok for current testing. - trace.diff this patch add SYSIO_ENTER/SYSIO_LEAVE macros. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.26 retrieving revision 1.27 diff -u -w -b -B -p -r1.26 -r1.27 --- fs_native.c 12 Jan 2004 18:07:16 -0000 1.26 +++ fs_native.c 21 Jan 2004 14:44:53 -0000 1.27 @@ -1337,15 +1337,34 @@ native_inop_iodone(struct ioctx *ioctxp } static int -native_inop_fcntl(struct inode *ino __IS_UNUSED, - int cmd __IS_UNUSED, - va_list ap __IS_UNUSED) +native_inop_fcntl(struct inode *ino, + int cmd, + va_list ap) { + struct native_inode *nino = I2NI(ino); + long arg; - /* - * I'm lazy. Maybe implemented later. - */ - errno = ENOTTY; + if (nino->ni_fd < 0) + abort(); + + switch (cmd) { + case F_GETFD: + case F_GETFL: + case F_GETOWN: + return syscall(SYS_fcntl, nino->ni_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, nino->ni_fd, cmd, arg); + default: + printf("uncatched cmd %d\n", cmd); + abort(); + } return -1; } |
From: Lee W. <lw...@us...> - 2004-01-21 15:01:14
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv27523 Modified Files: fs_native.c Log Message: Removed the printf error message from the fcntl routine. We don't have printf and the symbol reference madness is bad enough without calling into the IO portions of glibc from here. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -w -b -B -p -r1.27 -r1.28 --- fs_native.c 21 Jan 2004 14:44:53 -0000 1.27 +++ fs_native.c 21 Jan 2004 15:01:11 -0000 1.28 @@ -1362,7 +1362,6 @@ native_inop_fcntl(struct inode *ino, arg = va_arg(ap, long); return syscall(SYS_fcntl, nino->ni_fd, cmd, arg); default: - printf("uncatched cmd %d\n", cmd); abort(); } return -1; |
From: Lee W. <lw...@us...> - 2004-01-26 16:35:51
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11610/drivers/native Modified Files: fs_native.c Log Message: Patches from Kevin Pedretti (kt...@sa...) allowing for the change from a BSD-based libc to glibc-based on Red Storm. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.28 retrieving revision 1.29 diff -u -w -b -B -p -r1.28 -r1.29 --- fs_native.c 21 Jan 2004 15:01:11 -0000 1.28 +++ fs_native.c 26 Jan 2004 16:34:53 -0000 1.29 @@ -76,7 +76,6 @@ #ifdef REDSTORM #include <sys/uio.h> -#include <catamount/syscall.h> /* ! in sys include? */ #endif #ifdef REDSTORM |
From: Lee W. <lw...@us...> - 2004-02-06 20:10:45
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29990/drivers/native Modified Files: fs_native.c Log Message: Merging strided-IO branch + Strided-IO infrastructure. Internals altered to move data base don multiple targeted regions in both the file address space and local memory. + Added [i]{read,write}x, calls to perform extent-based or strided-IO directly. + Many bug fixes + Many uocnfig fixes + --with-zero-sum-memory; A config option that causes the shutdown code to carefully release *all* memory acquired from the heap, by the library. Useful for debugging tasks such as leak detection. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.29 retrieving revision 1.30 diff -u -w -b -B -p -r1.29 -r1.30 --- fs_native.c 26 Jan 2004 16:34:53 -0000 1.29 +++ fs_native.c 6 Feb 2004 20:07:29 -0000 1.30 @@ -9,7 +9,7 @@ * 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-2004 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 @@ -66,11 +66,15 @@ #endif #include <utime.h> #include <sys/queue.h> +#if !(defined(REDSTORM) || defined(MAX_IOVEC)) +#include <limits.h> +#endif #include "sysio.h" #include "fs.h" #include "mount.h" #include "inode.h" +#include "xtio.h" #include "fs_native.h" @@ -78,17 +82,6 @@ #include <sys/uio.h> #endif -#ifdef REDSTORM -/* - * The cnos IO routines on Red Storm can't do scatter/gather IO. We - * must use a different interface, then. The doio() routine will loop - * over the vector entries. - */ -typedef ssize_t (*iof)(int, void *, size_t, _SYSIO_OFF_T); -#else -typedef ssize_t (*iof)(int, const struct iovec *, int); -#endif - /* * Local host file system driver. */ @@ -183,12 +176,22 @@ struct native_inode_identifier { * system objects. */ struct native_inode { + unsigned + ni_seekok : 1; /* can seek? */ struct native_inode_identifier ni_ident; /* unique identifier */ struct file_identifier ni_fileid; /* ditto */ int ni_fd; /* host fildes */ int ni_oflags; /* flags, from open */ unsigned ni_nopens; /* soft ref count */ - off_t ni_fpos; /* current pos */ + _SYSIO_OFF_T ni_fpos; /* current pos */ +}; + +/* + * Native IO path arguments. + */ +struct native_io { + char nio_op; /* 'r' or 'w' */ + struct native_inode *nio_nino; /* native ino */ }; static int native_inop_lookup(struct pnode *pno, @@ -215,10 +218,8 @@ static int native_inop_close(struct inod static int native_inop_link(struct pnode *old, struct pnode *new); static int native_inop_unlink(struct pnode *pno); static int native_inop_rename(struct pnode *old, struct pnode *new); -static int native_inop_ipreadv(struct inode *ino, - struct ioctx *ioctx); -static int native_inop_ipwritev(struct inode *ino, - struct ioctx *ioctx); +static int native_inop_read(struct inode *ino, struct ioctx *ioctx); +static int native_inop_write(struct inode *ino, struct ioctx *ioctx); 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_sync(struct inode *ino); @@ -248,8 +249,8 @@ static struct inode_ops native_i_ops = { native_inop_link, native_inop_unlink, native_inop_rename, - native_inop_ipreadv, - native_inop_ipwritev, + native_inop_read, + native_inop_write, native_inop_iodone, native_inop_fcntl, native_inop_sync, @@ -841,40 +842,37 @@ out: } static int -native_pos(int fd, -#if _LARGEFILE64_SOURCE - loff_t *offset -#else - _SYSIO_OFF_T *offset -#endif - ) +native_pos(int fd, _SYSIO_OFF_T *offset, int whence) { + _SYSIO_OFF_T off; assert(fd >= 0); assert(*offset >= 0); + off = *offset; #if _LARGEFILE64_SOURCE && defined(SYS__llseek) { int err; err = syscall(SYS__llseek, (unsigned int)fd, - (unsigned int)(*offset >> 32), - (unsigned int)*offset, - offset, - SEEK_SET); + (unsigned int)(off >> 32), + (unsigned int)off, + &off, + whence); if (err == -1) return -errno; } #else - *offset = + off = syscall(SYS_lseek, fd, - *offset, - SEEK_SET); - if (*offset == -1) + off, + whence); + if (off == -1) return -errno; #endif + *offset = off; return 0; } @@ -889,12 +886,8 @@ native_getdirentries(struct inode *ino, struct native_inode *nino = I2NI(ino); int err; #ifndef SYS_getdirentries -#if _LARGEFILE64_SOURCE - loff_t result; -#else _SYSIO_OFF_T result; #endif -#endif ssize_t cc; assert(nino->ni_fd >= 0); @@ -902,7 +895,7 @@ native_getdirentries(struct inode *ino, #ifndef SYS_getdirentries result = *basep; if (*basep != nino->ni_fpos) { - err = native_pos(nino->ni_fd, &result); + err = native_pos(nino->ni_fd, &result, SEEK_SET); if (err) return err; } @@ -1013,6 +1006,9 @@ native_inop_open(struct pnode *pno, int flags &= ~O_WRONLY; flags |= O_RDWR; } +#ifdef O_LARGEFILE + flags |= O_LARGEFILE; +#endif fd = syscall(SYS_open, path, flags, mode); if (!pno->p_base->pb_ino && fd >= 0) { int err; @@ -1059,6 +1055,12 @@ native_inop_open(struct pnode *pno, int */ nino->ni_fpos = 0; nino->ni_fd = fd; + /* + * Need to know whether we can seek on this + * descriptor. + */ + nino->ni_seekok = + native_pos(nino->ni_fd, &nino->ni_fpos, SEEK_CUR) != 0 ? 0 : 1; return 0; } @@ -1146,183 +1148,251 @@ native_inop_unlink(struct pnode *pno) return err; } -/* - * A helper function performing the real IO operation work. - * - * We don't really have async IO. We'll just perform the function - * now. - */ static int -doio(iof f, - struct inode *ino, - struct ioctx *ioctx) +native_inop_rename(struct pnode *old, struct pnode *new) { - struct native_inode *nino = I2NI(ino); -#ifndef REDSTORM -#if _LARGEFILE64_SOURCE - loff_t result; -#else - _SYSIO_OFF_T result; -#endif -#endif + int err; + char *opath, *npath; - assert(nino->ni_fd >= 0); + opath = _sysio_pb_path(old->p_base, '/'); + npath = _sysio_pb_path(new->p_base, '/'); + if (!(opath && npath)) { + err = -ENOMEM; + goto out; + } - if ((ioctx->ioctx_iovlen && (int )ioctx->ioctx_iovlen < 0) || - !(S_ISREG(ino->i_mode) || - S_ISCHR(ino->i_mode) || - S_ISSOCK(ino->i_mode) || - S_ISFIFO(ino->i_mode))) - return -EINVAL; + err = syscall(SYS_rename, opath, npath); + +out: + if (opath) + free(opath); + if (npath) + free(npath); + + return err; +} + +static ssize_t +dopio(void *buf, size_t count, _SYSIO_OFF_T off, struct native_io *nio) +{ -#ifndef REDSTORM /* - * This implementation first positions the real system descriptor, then - * performs the operation. This is not atomic. - * - * An alternative, more complex, less efficient but atomic, - * implementation might consider each entry of the iovec separately. - * Then, the system implementations of the POSIX p{reaad,write} calls - * could be used. - * * Avoid the reposition call if we're already at the right place. * Allows us to access pipes and fifos. */ - result = ioctx->ioctx_offset; - if (ioctx->ioctx_offset != nino->ni_fpos) { + if (off != nio->nio_nino->ni_fpos) { int err; - err = native_pos(nino->ni_fd, &result); - if (err) { - ioctx->ioctx_cc = -1; - ioctx->ioctx_errno = -err; - goto out; + err = native_pos(nio->nio_nino->ni_fd, &off, SEEK_SET); + if (err) + return err; + nio->nio_nino->ni_fpos = off; } - nino->ni_fpos = result; + + return syscall(nio->nio_op == 'r' ? SYS_read : SYS_write, + nio->nio_nino->ni_fd, + buf, + count); } -#endif - /* - * Call the appropriate (read/write) IO function to - * transfer the data now. - */ -#ifdef REDSTORM +static ssize_t +doiov(const struct iovec *iov, + int count, + _SYSIO_OFF_T off, + ssize_t limit, + struct native_io *nio) { - size_t count = ioctx->ioctx_iovlen; - struct iovec *iov = ioctx->ioctx_iovec; ssize_t cc; - nino->ni_fpos = ioctx->ioctx_offset; - while (count) { - cc = - (*f)(nino->ni_fd, - iov->iov_base, - iov->iov_len, - nino->ni_fpos); - if (cc < 0) { - if (ioctx->ioctx_cc) { +#if !(defined(REDSTORM) || defined(MAX_IOVEC)) +#define MAX_IOVEC INT_MAX +#endif + + if (count <= 0) + return -EINVAL; + /* - * No data written at all. Return - * error. + * Avoid the reposition call if we're already at the right place. + * Allows us to access pipes and fifos. */ - ioctx->ioctx_cc = -1; - } - break; - } - ioctx->ioctx_cc += cc; - count--, iov++; - } - } -#else /* !defined(REDSTORM) */ - ioctx->ioctx_cc = - (*f)(nino->ni_fd, ioctx->ioctx_iovec, ioctx->ioctx_iovlen); -#endif /* defined(REDSTORM) */ - if (ioctx->ioctx_cc < 0) - ioctx->ioctx_errno = errno; - if (ioctx->ioctx_cc > 0) - nino->ni_fpos += ioctx->ioctx_cc; + if (off != nio->nio_nino->ni_fpos) { + int err; -out: - ioctx->ioctx_done = 1; - return 0; + err = native_pos(nio->nio_nino->ni_fd, &off, SEEK_SET); + if (err) + return err; + nio->nio_nino->ni_fpos = off; } /* - * Helper function passed to doio(), above, to accomplish a real readv. + * The {read,write}v is safe as this routine is only ever called + * by _sysio_enumerate_extents() and that routine is exact. It never + * passes iovectors including tails. */ -#ifdef REDSTORM -static ssize_t -native_read(int fd, void *buf, size_t count, _SYSIO_OFF_T offset) -{ - - return syscall(SYS_pread, fd, buf, count, offset); -} -#else -static ssize_t -native_read(int fd, const struct iovec *vector, int count) -{ + cc = +#ifndef REDSTORM + count <= MAX_IOVEC + ? syscall(nio->nio_op == 'r' ? SYS_readv : SYS_writev, + nio->nio_nino->ni_fd, + iov, + count) + : +#endif + _sysio_enumerate_iovec(iov, + count, + off, + limit, + (ssize_t (*)(void *, + size_t, + _SYSIO_OFF_T, + void *))dopio, + nio); + if (cc > 0) + nio->nio_nino->ni_fpos += cc; + return cc; - return syscall(SYS_readv, fd, vector, count); -} +#if !(defined(REDSTORM) || defined(MAX_IOVEC)) +#undef MAX_IOVEC #endif +} +#if 0 static int -native_inop_rename(struct pnode *old, struct pnode *new) +lockop_all(struct native_inode *nino, + struct intnl_xtvec *xtv, + size_t count, + short op) { + struct flock flock; int err; - char *opath, *npath; - opath = _sysio_pb_path(old->p_base, '/'); - npath = _sysio_pb_path(new->p_base, '/'); - if (!(opath && npath)) { - err = -ENOMEM; - goto out; + if (!count) + return -EINVAL; + flock.l_type = op; + flock.l_whence = SEEK_SET; + while (count--) { + flock.l_start = xtv->xtv_off; + flock.l_len = xtv->xtv_len; + xtv++; + err = + syscall( +#if !_LARGEFILE64_SOURCE + SYS_fcntl64 +#else + SYS_fcntl +#endif + , + nino->ni_fd, + F_SETLK, + &flock); + if (err != 0) + return -errno; + } + return 0; } - err = syscall(SYS_rename, opath, npath); - -out: - if (opath) - free(opath); - if (npath) - free(npath); +static int +order_xtv(const struct intnl_xtvec *xtv1, const struct intnl_xtvec *xtv2) +{ - return err; + if (xtv1->xtv_off < xtv2->xtv_off) + return -1; + if (xtv1->xtv_off > xtv2->xtv_off) + return 1; + return 0; } +#endif static int -native_inop_ipreadv(struct inode *ino, - struct ioctx *ioctx) +doio(char op, struct ioctx *ioctx) { + struct native_inode *nino; +#if 0 + int dolocks; + struct intnl_xtvec *oxtv; + int err; +#endif + struct native_io arguments; + ssize_t cc; +#if 0 + struct intnl_xtvec *front, *rear, tmp; +#endif - return doio(native_read, ino, ioctx); + nino = I2NI(ioctx->ioctx_ino); +#if 0 + dolocks = ioctx->ioctx_xtvlen > 1 && nino->ni_seekok; + if (dolocks) { + /* + * Must lock the regions (in order!) since we can't do + * strided-IO as a single atomic operation. + */ + oxtv = malloc(ioctx->ioctx_xtvlen * sizeof(struct intnl_xtvec)); + if (!oxtv) + return -ENOMEM; + (void )memcpy(oxtv, + ioctx->ioctx_xtv, + ioctx->ioctx_xtvlen * sizeof(struct intnl_xtvec)); + qsort(oxtv, + ioctx->ioctx_xtvlen, + sizeof(struct intnl_xtvec), + (int (*)(const void *, const void *))order_xtv); + err = + lockop_all(nino, + oxtv, ioctx->ioctx_xtvlen, + op == 'r' ? F_RDLCK : F_WRLCK); + if (err) { + free(oxtv); + return err; } - + } +#endif + arguments.nio_op = op; + arguments.nio_nino = nino; + cc = + _sysio_enumerate_extents(ioctx->ioctx_xtv, ioctx->ioctx_xtvlen, + ioctx->ioctx_iov, ioctx->ioctx_iovlen, + (ssize_t (*)(const struct iovec *, + int, + _SYSIO_OFF_T, + ssize_t, + void *))doiov, + &arguments); +#if 0 + if (dolocks) { /* - * Helper function passed to doio(), above, to accomplish a real writev. + * Must unlock in reverse order. */ -#ifdef REDSTORM -static ssize_t -native_write(int fd, void *buf, size_t count, _SYSIO_OFF_T offset) -{ - - return syscall(SYS_pwrite, fd, buf, count, offset); + front = oxtv; + rear = front + ioctx->ioctx_xtvlen - 1; + while (front < rear) { + tmp = *front; + *front++ = *rear; + *rear-- = tmp; } -#else -static ssize_t -native_write(int fd, const struct iovec *vector, int count) + if (lockop_all(nino, oxtv, ioctx->ioctx_xtvlen, F_UNLCK) != 0) + abort(); + free(oxtv); + } +#endif + if ((ioctx->ioctx_cc = cc) < 0) { + ioctx->ioctx_errno = -ioctx->ioctx_cc; + ioctx->ioctx_cc = -1; + } + return 0; +} + +static int +native_inop_read(struct inode *ino __IS_UNUSED, struct ioctx *ioctx) { - return syscall(SYS_writev, fd, vector, count); + return doio('r', ioctx); } -#endif static int -native_inop_ipwritev(struct inode *ino, - struct ioctx *ioctx) +native_inop_write(struct inode *ino __IS_UNUSED, struct ioctx *ioctx) { - return doio(native_write, ino, ioctx); + return doio('w', ioctx); } static int @@ -1361,9 +1431,9 @@ native_inop_fcntl(struct inode *ino, arg = va_arg(ap, long); return syscall(SYS_fcntl, nino->ni_fd, cmd, arg); default: - abort(); + break; } - return -1; + return -EINVAL; } static int |
From: Lee W. <lw...@us...> - 2004-02-08 23:51:58
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14749/drivers/native Modified Files: fs_native.c Log Message: This driver was nearly perfectly forgetting to pass the error number on failure. Fixed -- I think. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -w -b -B -p -r1.30 -r1.31 --- fs_native.c 6 Feb 2004 20:07:29 -0000 1.30 +++ fs_native.c 8 Feb 2004 23:48:51 -0000 1.31 @@ -745,6 +745,8 @@ native_inop_setattr(struct pnode *pno, fd < 0 ? syscall(SYS_chmod, path, mode) : syscall(SYS_fchmod, fd, mode); + if (err) + err = -errno; } if (err) mask &= ~SETATTR_MODE; @@ -761,6 +763,8 @@ native_inop_setattr(struct pnode *pno, if (mask & SETATTR_ATIME) ut.actime = stbuf->st_atime; err = syscall(__SYS_UTIME, path, &ut); + if (err) + err = -errno; } if (err) mask &= ~(SETATTR_MTIME|SETATTR_ATIME); @@ -787,6 +791,8 @@ native_inop_setattr(struct pnode *pno, mask & SETATTR_GID ? stbuf->st_gid : (gid_t )-1); + if (err) + err = -errno; } if (err) mask &= ~(SETATTR_UID|SETATTR_GID); @@ -933,6 +939,8 @@ native_inop_mkdir(struct pnode *pno, mod return -ENOMEM; err = syscall(SYS_mkdir, path, mode); + if (err != 0) + err = -errno; free(path); return err; } @@ -948,6 +956,8 @@ native_inop_rmdir(struct pnode *pno) return -ENOMEM; err = syscall(SYS_rmdir, path); + if (err != 0) + err = -errno; free(path); return err; } @@ -963,6 +973,8 @@ native_inop_symlink(struct pnode *pno, c return -ENOMEM; err = syscall(SYS_symlink, data, path); + if (err != 0) + err = -errno; free(path); return err; } @@ -1110,6 +1122,8 @@ native_inop_link(struct pnode *old, stru } err = syscall(SYS_link, opath, npath); + if (err != 0) + err = -errno; out: if (opath) @@ -1162,6 +1176,8 @@ native_inop_rename(struct pnode *old, st } err = syscall(SYS_rename, opath, npath); + if (err != 0) + err = -errno; out: if (opath) @@ -1249,6 +1265,8 @@ doiov(const struct iovec *iov, nio); if (cc > 0) nio->nio_nino->ni_fpos += cc; + else + cc = -errno; return cc; #if !(defined(REDSTORM) || defined(MAX_IOVEC)) @@ -1412,6 +1430,7 @@ native_inop_fcntl(struct inode *ino, { struct native_inode *nino = I2NI(ino); long arg; + int err; if (nino->ni_fd < 0) abort(); @@ -1420,7 +1439,9 @@ native_inop_fcntl(struct inode *ino, case F_GETFD: case F_GETFL: case F_GETOWN: - return syscall(SYS_fcntl, nino->ni_fd, cmd); + err = syscall(SYS_fcntl, nino->ni_fd, cmd); + if (err < 0) + err = -errno; case F_DUPFD: case F_SETFD: case F_SETFL: @@ -1429,11 +1450,13 @@ native_inop_fcntl(struct inode *ino, case F_SETLKW: case F_SETOWN: arg = va_arg(ap, long); - return syscall(SYS_fcntl, nino->ni_fd, cmd, arg); + err = syscall(SYS_fcntl, nino->ni_fd, cmd, arg); + if (err) + err = -errno; default: - break; + err = -EINVAL; } - return -EINVAL; + return err; } static int @@ -1496,26 +1519,34 @@ native_inop_statvfs(struct pnode *pno, static int native_inop_sync(struct inode *ino) { + int err; assert(I2NI(ino)->ni_fd >= 0); - return syscall(SYS_fsync, I2NI(ino)->ni_fd); + err = syscall(SYS_fsync, I2NI(ino)->ni_fd); + if (err) + err = -errno; + return err; } static int native_inop_datasync(struct inode *ino) { + int err; assert(I2NI(ino)->ni_fd >= 0); #ifdef NATIVE_FDATASYNC - return syscall(NATIVE_FDATASYNC, I2NI(ino)->ni_fd); + err = syscall(NATIVE_FDATASYNC, I2NI(ino)->ni_fd); #else #if 0 #warning No fdatasync system call -- Using fsync instead! #endif - return syscall(SYS_fsync, I2NI(ino)->ni_fd); + err = syscall(SYS_fsync, I2NI(ino)->ni_fd); #endif + if (err) + err = -errno; + return err; } static int |
From: Lee W. <lw...@us...> - 2004-02-14 19:49:38
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16325/drivers/native Modified Files: fs_native.c Log Message: + Merged in changes from namespace_assembly branch (see .../misc/init-env.sh) This provoked a bunch of bugs. See below. + Fixed a bug in _sysio_enumerate_extents(). If the IO operation was short, it would go round the loop again, mistakenly trying to fill more of the extent. + In rw.c, fixed bugs in [p]{read,write}[vx] (all the synchronous routines) that improperly propagated error returns. They were returning -errno instead of setting errno and returning -1. + In fs_native.c:doiov, fixed a bug where a zero-length IO was improperly thought to be an error. + In lseek.c:_sysio_lseek, fixed final position check to properly determine {under,over}flow. + In link.c:link, fixed the existence check. No error is returned for nonexistent files when ND_NEGOK is specified. We're supposed to check whether it's a negative entry or not. + A new macro, I_GONE, was added to inode.h. This will *try* to kill an inode but if it can't, it becomes a zombie instead. + In unlink.c:unlink, link.c:link, rename.c:rename, the driver ops were being called but the actual operation in the internal path tree was not reflected. Also, for unlink and rename, use the new I_GONE macro on the destroyed inode. + In fs_native.c:native_inop_gone, close() was always called, even when the fildes was -1. + In fs_native.c:native_inop_gone, close() was called. We really meant to call syscal(SYS_close, ...); + In namei.c:_sysio_path_walk, fixed broken symlink handling. It wasn't following symlinks anywhere if ND_NOFOLLOW was set. That flag only means that the *last* component should not be followed. + In namei.c:_sysio_path_walk, fixed buffer overrun problem for very long symlinks. + In fs_incore.c, fixed dirop_{link,rename,unlink,rmdir} because they were manipulating the system path cache and shouldn't. + In mount.c:_sysio_unmount_all we were mistakenly releasing an FS root after a failed unmount attempt. + Fixes in test_regions.c free allocated memory at the end so valgrind doesn't show a leak. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.31 retrieving revision 1.32 diff -u -w -b -B -p -r1.31 -r1.32 --- fs_native.c 8 Feb 2004 23:48:51 -0000 1.31 +++ fs_native.c 14 Feb 2004 19:42:58 -0000 1.32 @@ -608,8 +608,7 @@ native_iget(struct filesys *fs, * Cached inode has stale attrs * make way for the new one */ - I_RELE(ino); - _sysio_i_undead(ino); + I_GONE(ino); ino = NULL; } else /* @@ -1263,10 +1262,10 @@ doiov(const struct iovec *iov, _SYSIO_OFF_T, void *))dopio, nio); - if (cc > 0) - nio->nio_nino->ni_fpos += cc; - else + if (cc < 0) cc = -errno; + else + nio->nio_nino->ni_fpos += cc; return cc; #if !(defined(REDSTORM) || defined(MAX_IOVEC)) @@ -1567,8 +1566,8 @@ native_inop_gone(struct inode *ino) { struct native_inode *nino = I2NI(ino); - if (nino->ni_fd) - (void )close(nino->ni_fd); + if (nino->ni_fd >= 0) + (void )syscall(SYS_close, nino->ni_fd); free(ino->i_private); } |
From: Lee W. <lw...@us...> - 2004-02-25 16:39:04
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23863/drivers/native Modified Files: fs_native.c Log Message: All mode bit masks were incorrect. Need to preserve ISUID, ISGID, ISVTX bits. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.32 retrieving revision 1.33 diff -u -w -b -B -p -r1.32 -r1.33 --- fs_native.c 14 Feb 2004 19:42:58 -0000 1.32 +++ fs_native.c 25 Feb 2004 16:23:58 -0000 1.33 @@ -739,7 +739,7 @@ native_inop_setattr(struct pnode *pno, /* * Alter permissions attribute. */ - mode = stbuf->st_mode & 0777; + mode = stbuf->st_mode & 07777; err = fd < 0 ? syscall(SYS_chmod, path, mode) @@ -837,8 +837,8 @@ native_inop_setattr(struct pnode *pno, } if (mask & SETATTR_MODE) { fd < 0 - ? syscall(SYS_chmod, path, st.st_mode & 0777) - : syscall(SYS_fchmod, fd, st.st_mode & 0777); + ? syscall(SYS_chmod, path, st.st_mode & 07777) + : syscall(SYS_fchmod, fd, st.st_mode & 07777); } out: if (path) |
From: Lee W. <lw...@us...> - 2004-04-14 17:26:00
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18582/drivers/native Modified Files: fs_native.c Log Message: Fixed the missing first letter of entry names returned by native_getdirentries. The x86_64 service node does not support getdents64. Only getdents. We had assumed, wrongly, that getdents == getdents64 on this platform (and ia64 too it seems) but the kernel structure used by getdents does not include a type field. Must convert now. The resulting type field in the internals structure, and that passed back to the user too of course, will be set to DT_UNKNOWN. There must be a Cray SPR filed for this but I'll be duurned if I can find a reference. Oh well, no association then. Just an out of the blue fix. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.33 retrieving revision 1.34 diff -u -w -b -B -p -r1.33 -r1.34 --- fs_native.c 25 Feb 2004 16:23:58 -0000 1.33 +++ fs_native.c 14 Apr 2004 17:25:43 -0000 1.34 @@ -82,6 +82,33 @@ #include <sys/uio.h> #endif +#if defined(SYS_getdirentries) +#define DIR_STREAMED 0 +#define DIR_CVT_64 0 +#elif defined(SYS_getdents64) +#define DIR_STREAMED 0 +#define DIR_CVT_64 0 +#elif defined(SYS_getdents) +#define DIR_STREAMED 0 +#if defined(_LARGEFILE64_SOURCE) +#define DIR_CVT_64 1 +/* + * Kernel version of directory entry. + */ +struct linux_dirent { + unsigned long ld_ino; + unsigned long ld_off; + unsigned short ld_reclen; + char ld_name[1]; +}; +#include <dirent.h> +#else /* !defined(_LARGEFILE64_SOURCE) */ +#define DIR_CVT_64 0 +#endif /* defined(_LARGEFILE64_SOURCE) */ +#else /* catch-none */ +#error No usable directory fill entries interface available +#endif + /* * Local host file system driver. */ @@ -883,34 +910,34 @@ native_pos(int fd, _SYSIO_OFF_T *offset, } static ssize_t -native_getdirentries(struct inode *ino, +native_filldirentries(struct native_inode *nino, char *buf, size_t nbytes, _SYSIO_OFF_T *basep) { - struct native_inode *nino = I2NI(ino); - int err; -#ifndef SYS_getdirentries +#if !DIR_STREAMED _SYSIO_OFF_T result; #endif ssize_t cc; - assert(nino->ni_fd >= 0); + if (*basep < 0) + return -EINVAL; -#ifndef SYS_getdirentries +#if !DIR_STREAMED + /* + * Stream-oriented access requires that we reposition prior to the + * fill call. + */ result = *basep; - if (*basep != nino->ni_fpos) { - err = native_pos(nino->ni_fd, &result, SEEK_SET); - if (err) - return err; - } + if (*basep != nino->ni_fpos && + (cc = native_pos(nino->ni_fd, &result, SEEK_SET)) != 0) + return cc; nino->ni_fpos = result; -#ifdef SYS_getdents64 - cc = syscall(SYS_getdents64, nino->ni_fd, buf, nbytes); #else - cc = syscall(SYS_getdents, nino->ni_fd, buf, nbytes); + nino->ni_fpos = *basep; #endif -#else /* defined(SYS_getdirentries) */ + +#if defined(SYS_getdirentries) cc = syscall(SYS_getdirentries, nino->ni_fd, @@ -918,11 +945,87 @@ native_getdirentries(struct inode *ino, nbytes, basep, &nino->ni_fpos); -#endif /* !defined(SYS_getdirentries) */ +#elif defined(SYS_getdents64) + cc = syscall(SYS_getdents64, nino->ni_fd, buf, nbytes); +#elif defined(SYS_getdents) + cc = syscall(SYS_getdents, nino->ni_fd, buf, nbytes); +#endif + if (cc < 0) return -errno; -#ifndef SYS_getdirentries nino->ni_fpos += cc; + return cc; +} + +static ssize_t +native_getdirentries(struct inode *ino, + char *buf, + size_t nbytes, + _SYSIO_OFF_T *basep) +{ + struct native_inode *nino = I2NI(ino); +#if DIR_CVT_64 + char *bp; + size_t count; + struct linux_dirent *ldp; + struct dirent64 *d64p; + size_t namlen; + size_t reclen; +#else +#define bp buf +#define count nbytes +#endif + ssize_t cc; + + assert(nino->ni_fd >= 0); + +#if DIR_CVT_64 + count = nbytes; + while (!(bp = malloc(count))) { + count /= 2; + if (count < sizeof(struct dirent)) + return -ENOMEM; + } +#endif + cc = native_filldirentries(nino, bp, count, basep); + if (cc < 0) { +#if DIR_CVT_64 + free(bp); +#endif + return cc; + } +#if DIR_CVT_64 + ldp = (struct linux_dirent *)bp; + d64p = (struct dirent64 *)buf; + for (;;) { + if (cc < 0 || (size_t )cc <= sizeof(*ldp)) + break; + namlen = strlen(ldp->ld_name); + reclen = sizeof(*d64p) - sizeof(d64p->d_name) + namlen + 1; + if (nbytes < reclen) + break; + d64p->d_ino = ldp->ld_ino; + d64p->d_off = ldp->ld_off; + d64p->d_reclen = + (((reclen + sizeof(long) - 1)) / sizeof(long)) * + sizeof(long); + if (nbytes < d64p->d_reclen) + d64p->d_reclen = reclen; + d64p->d_type = DT_UNKNOWN; /* you lose -- sorry. */ + (void )strncpy(d64p->d_name, ldp->ld_name, namlen); + *(d64p->d_name + namlen) = '\0'; + cc -= ldp->ld_reclen; + ldp = (struct linux_dirent *)((char *)ldp + ldp->ld_reclen); + nbytes -= d64p->d_reclen; + d64p = (struct dirent64 *)((char *)d64p + d64p->d_reclen); + } + free(bp); + if (d64p == (struct dirent64 *)buf && cc) + cc = -EINVAL; /* buf too small */ + cc = (char *)d64p - buf; +#else +#undef bp +#undef count #endif return cc; } |
From: Lee W. <lw...@us...> - 2004-04-16 20:38:42
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30430/drivers/native Modified Files: fs_native.c Log Message: New operation for the drivers to implement -- take note! The drivers now need to implement inop_pos which takes an inode and a _SYSIO_OFF_T and should return the resulting position as though it were lseek(FD2INO(fd), off, SEEK_SET). As usual a negative return value is the negated errno. Lseek is altered to use this. Changes in fs_native.c to utilize pread/pwrite whenever positioning is required instead of an lseek/io-op pair of calls. This addresses a race to yod. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.34 retrieving revision 1.35 diff -u -w -b -B -p -r1.34 -r1.35 --- fs_native.c 14 Apr 2004 17:25:43 -0000 1.34 +++ fs_native.c 16 Apr 2004 20:38:34 -0000 1.35 @@ -247,6 +247,7 @@ static int native_inop_unlink(struct pno static int native_inop_rename(struct pnode *old, struct pnode *new); 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_sync(struct inode *ino); @@ -278,6 +279,7 @@ static struct inode_ops native_i_ops = { native_inop_rename, native_inop_read, native_inop_write, + native_inop_pos, native_inop_iodone, native_inop_fcntl, native_inop_sync, @@ -1293,24 +1295,47 @@ out: static ssize_t dopio(void *buf, size_t count, _SYSIO_OFF_T off, struct native_io *nio) { +#ifdef _LARGEFILE64_SOURCE +#define _NATIVE_SYSCALL_PREAD SYS_pread64 +#define _NATIVE_SYSCALL_PWRITE SYS_pwrite64 +#else +#define _NATIVE_SYSCALL_PREAD SYS_pread +#define _NATIVE_SYSCALL_PWRITE SYS_pwrite +#endif + 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) { /* - * Avoid the reposition call if we're already at the right place. - * Allows us to access pipes and fifos. + * They've done a p{read,write} or somesuch. Can't + * seek on this descriptor so we err out now. */ - if (off != nio->nio_nino->ni_fpos) { - int err; - - err = native_pos(nio->nio_nino->ni_fd, &off, SEEK_SET); - if (err) - return err; - nio->nio_nino->ni_fpos = off; + errno = ESPIPE; + return -1; } - - return syscall(nio->nio_op == 'r' ? SYS_read : SYS_write, + cc = + syscall(nio->nio_op == 'r' ? SYS_read : SYS_write, nio->nio_nino->ni_fd, buf, count); + if (cc > 0) + nio->nio_nino->ni_fpos += cc; + } else + cc = + syscall((nio->nio_op == 'r' + ? _NATIVE_SYSCALL_PREAD + : _NATIVE_SYSCALL_PWRITE), + nio->nio_nino->ni_fd, + buf, + count, + off); + + return cc; +#undef _NATIVE_SYSCALL_PREAD +#undef _NATIVE_SYSCALL_PWRITE } static ssize_t @@ -1515,6 +1540,16 @@ native_inop_write(struct inode *ino __IS return doio('w', ioctx); } +static _SYSIO_OFF_T +native_inop_pos(struct inode *ino, _SYSIO_OFF_T off) +{ + struct native_inode *nino = I2NI(ino); + int err; + + err = native_pos(nino->ni_fd, &off, SEEK_SET); + return err < 0 ? err : off; +} + static int native_inop_iodone(struct ioctx *ioctxp __IS_UNUSED) { |
From: Lee W. <lw...@us...> - 2004-04-17 21:15:23
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17314/native Modified Files: fs_native.c Log Message: From Kevin Pedretti; Build is broken on Linux/Opteron. There is no p{read,write}64 system call but _LARGEFILE64_SOURCE is defined. Altered to check for the presence of these calls as well as _LARGEFILE64_SOURCE. If any are not found, it assumes p{read,write} system calls are present. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.35 retrieving revision 1.36 diff -u -w -b -B -p -r1.35 -r1.36 --- fs_native.c 16 Apr 2004 20:38:34 -0000 1.35 +++ fs_native.c 17 Apr 2004 21:15:03 -0000 1.36 @@ -1295,7 +1295,9 @@ out: static ssize_t dopio(void *buf, size_t count, _SYSIO_OFF_T off, struct native_io *nio) { -#ifdef _LARGEFILE64_SOURCE +#if defined(_LARGEFILE64_SOURCE) && \ + defined(SYS_pread64) && \ + defined(SYS_pwrite64) #define _NATIVE_SYSCALL_PREAD SYS_pread64 #define _NATIVE_SYSCALL_PWRITE SYS_pwrite64 #else |