[Libsysio-commit] strided-io: libsysio/src ioctx.c lseek.c rw.c
Brought to you by:
lward
|
From: Lee W. <lw...@us...> - 2004-01-26 07:11:59
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1014/src Modified Files: Tag: strided-io ioctx.c lseek.c rw.c Log Message: Use O_LARGEFILE or we don't get 64-bit file address space. Fix lots of seek/position checks. Add artificial limit check to _sysio_validx and remove the test for overflow of INT_MAX there. Index: ioctx.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/ioctx.c,v retrieving revision 1.6.6.5 retrieving revision 1.6.6.6 diff -u -w -b -B -p -r1.6.6.5 -r1.6.6.6 --- ioctx.c 23 Jan 2004 17:04:00 -0000 1.6.6.5 +++ ioctx.c 26 Jan 2004 07:10:57 -0000 1.6.6.6 @@ -44,7 +44,6 @@ #include <stdlib.h> #include <string.h> #include <errno.h> -#include <limits.h> #include <assert.h> #include <sys/types.h> #include <sys/uio.h> @@ -257,7 +256,8 @@ _sysio_ioctx_complete(struct ioctx *ioct */ ssize_t _sysio_validx(const struct intnl_xtvec *xtv, size_t xtvlen, - const struct iovec *iov, size_t iovlen) + const struct iovec *iov, size_t iovlen, + _SYSIO_OFF_T limit) { ssize_t acc, cc; struct iovec iovec; @@ -305,18 +305,12 @@ _sysio_validx(const struct intnl_xtvec * off = xtvec.xtv_off + cc; if (xtvec.xtv_off && off <= xtvec.xtv_off) return off < 0 ? -EINVAL : -EOVERFLOW; + if (off > limit) + return -EFBIG; xtvec.xtv_off = off; cc += acc; - if (acc && cc <= acc) + if (acc && (cc <= acc)) return -EINVAL; - if (acc > INT_MAX) { - /* - * Artificially limit the transfer size to - * INT_MAX bytes so we don't overflow - * the 32-bit callers return values. - */ - return -EINVAL; - } acc = cc; } while (xtvec.xtv_len && iovlen); } while ((xtvlen || xtvec.xtv_len) && iovlen); @@ -334,17 +328,13 @@ _sysio_enumerate_extents(const struct in void *), void *arg) { - ssize_t cc, acc; + ssize_t acc, cc; struct iovec iovec; struct intnl_xtvec xtvec; const struct iovec *start; _SYSIO_OFF_T off; size_t n; - cc = _sysio_validx(xtv, xtvlen, iov, iovlen); - if (cc < 0) - return cc; - acc = 0; iovec.iov_len = 0; while (xtvlen) { @@ -458,14 +448,6 @@ _sysio_enumerate_iovec(const struct iove cc += acc; if (acc && cc <= acc) return -EINVAL; - if (acc > INT_MAX) { - /* - * Artificially limit the transfer size to - * INT_MAX bytes so we don't overflow - * the 32-bit callers return values. - */ - return -EINVAL; - } acc = cc; } if (!acc) Index: lseek.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/lseek.c,v retrieving revision 1.9.6.1 retrieving revision 1.9.6.2 diff -u -w -b -B -p -r1.9.6.1 -r1.9.6.2 --- lseek.c 23 Jan 2004 13:59:46 -0000 1.9.6.1 +++ lseek.c 26 Jan 2004 07:10:57 -0000 1.9.6.2 @@ -69,8 +69,7 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset switch (whence) { case SEEK_SET: - off = offset; - offset = 0; + off = 0; break; case SEEK_CUR: off = fil->f_pos; @@ -91,10 +90,16 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset default: return -EINVAL; } - assert(off >= 0); /* paranoia */ pos = off + offset; - if ((offset < 0 && -offset > off) || (offset > 0 && off && pos <= off)) + if (pos < 0 || (off && 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) + return -EOVERFLOW; +#endif return fil->f_pos = pos; } @@ -116,13 +121,12 @@ lseek(int fd, off_t offset, int whence) off_t rtn; off = _sysio_lseek(fd, offset, whence); - if (off < 0) - return -1; - rtn = (off_t )off; - if ((_SYSIO_OFF_T )rtn != off) { - errno = EINVAL; + if (off < 0) { + errno = -off; return -1; } + rtn = (off_t )off; + assert(rtn == off); return rtn; } Index: rw.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/Attic/rw.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -w -b -B -p -r1.1.2.1 -r1.1.2.2 --- rw.c 23 Jan 2004 15:23:02 -0000 1.1.2.1 +++ rw.c 26 Jan 2004 07:10:57 -0000 1.1.2.2 @@ -58,11 +58,27 @@ #include "sysio-symbols.h" /* + * Decoding the interface routine names: + * + * Much of this carries legacy from the POSIX world and the Intel ASCI + * Red programming environment. Routine names are composed of prefix, + * basic POSIX names, and postfix. The basic POSIX names are read and write. + * Prefixes, left-to-right: + * + * - 'i' -- asynchronous operation (from ASCI Red) + * - 'p' -- positional (POSIX) + * Posfixes, only one: + * - 'v' -- vectored (POSIX) + * - 'x' -- extent-based (new for Red Storm) + * + * All valid combinations are available and symmetric. + */ + +/* * Post op using iovec with regions specified by the passed extent vector. * - * Note; No checking if performed on the two vectors. They can do any or - * all of; underflow/overflow position or overflow ssize_t for result. The - * driver should check for these. + * NOTE: There are enough parameters that we should really consider + * passing them in a structure. */ static int _sysio_iiox(ssize_t (*f)(struct inode *, struct ioctx *), @@ -77,6 +93,7 @@ _sysio_iiox(ssize_t (*f)(struct inode *, struct ioctx **ioctxp) { struct inode *ino; + ssize_t cc; struct ioctx *ioctx; int err; struct ioctx_callback *cb; @@ -88,6 +105,17 @@ _sysio_iiox(ssize_t (*f)(struct inode *, */ return -EBADF; } + cc = + _sysio_validx(xtv, xtv_count, + iov, iov_count, +#if _LARGEFILE64_SOURCE && defined(O_LARGEFILE) + (fil->f_flags & O_LARGEFILE) == 0 + ? LONG_MAX + : +#endif + _SYSIO_OFF_T_MAX); + if (cc < 0) + return cc; ioctx = _sysio_ioctx_new(ino, iov, iov_count, xtv, xtv_count); if (!ioctx) { errno = ENOMEM; @@ -256,7 +284,7 @@ readv(int fd, const struct iovec *iov, i fil = _sysio_fd_find_capable(fd, O_WRONLY); if (!fil) { errno = EBADF; - return IOID_FAIL; + return -1; } err = @@ -307,7 +335,11 @@ iread(int fd, void *buf, size_t count) iov->iov_len = count; xtv = malloc(sizeof(struct intnl_xtvec)); if (!xtv) { + int oerrno; + + oerrno = errno; free(iov); + errno = oerrno; return IOID_FAIL; } err = @@ -337,7 +369,7 @@ read(int fd, void *buf, size_t count) fil = _sysio_fd_find_capable(fd, O_WRONLY); if (!fil) { errno = EBADF; - return IOID_FAIL; + return -1; } iovector.iov_base = buf; @@ -454,7 +486,7 @@ _preadv(int fd, const struct iovec *iov, fil = _sysio_fd_find_capable(fd, O_WRONLY); if (!fil) { errno = EBADF; - return IOID_FAIL; + return -1; } err = @@ -501,7 +533,7 @@ _ipread(int fd, void *buf, size_t count, xtv = malloc(sizeof(struct intnl_xtvec)); iov = malloc(sizeof(struct iovec)); if (!(xtv && iov)) { - err = ENOMEM; + err = -errno; goto error; } xtv->xtv_off = offset; @@ -550,7 +582,7 @@ _pread(int fd, void *buf, size_t count, fil = _sysio_fd_find_capable(fd, O_WRONLY); if (!fil) { errno = EBADF; - return IOID_FAIL; + return -1; } xtvec.xtv_off = offset; @@ -565,7 +597,7 @@ _pread(int fd, void *buf, size_t count, &ioctx); if (err) { errno = -err; - return IOID_FAIL; + return -1; } return _sysio_ioctx_wait(ioctx); } @@ -749,7 +781,7 @@ writev(int fd, const struct iovec *iov, fil = _sysio_fd_find_capable(fd, O_RDONLY); if (!fil) { errno = EBADF; - return IOID_FAIL; + return -1; } err = @@ -792,7 +824,11 @@ iwrite(int fd, const void *buf, size_t c iov->iov_len = count; xtv = malloc(sizeof(struct intnl_xtvec)); if (!xtv) { + int oerrno; + + oerrno = errno; free(iov); + errno = oerrno; return IOID_FAIL; } err = @@ -822,7 +858,7 @@ write(int fd, const void *buf, size_t co fil = _sysio_fd_find_capable(fd, O_RDONLY); if (!fil) { errno = EBADF; - return IOID_FAIL; + return -1; } iovector.iov_base = (void *)buf; @@ -905,7 +941,7 @@ _pwritev(int fd, const struct iovec *iov fil = _sysio_fd_find_capable(fd, O_RDONLY); if (!fil) { errno = EBADF; - return IOID_FAIL; + return -1; } err = @@ -943,7 +979,7 @@ _ipwrite(int fd, const void *buf, size_t struct ioctx *ioctx; int err; - fil = _sysio_fd_find_capable(fd, O_WRONLY); + fil = _sysio_fd_find_capable(fd, O_RDONLY); if (!fil) { errno = EBADF; return IOID_FAIL; @@ -952,7 +988,7 @@ _ipwrite(int fd, const void *buf, size_t xtv = malloc(sizeof(struct intnl_xtvec)); iov = malloc(sizeof(struct iovec)); if (!(xtv && iov)) { - err = ENOMEM; + err = -errno; goto error; } xtv->xtv_off = offset; @@ -998,10 +1034,10 @@ _pwrite(int fd, const void *buf, size_t struct ioctx *ioctx; int err; - fil = _sysio_fd_find_capable(fd, O_WRONLY); + fil = _sysio_fd_find_capable(fd, O_RDONLY); if (!fil) { errno = EBADF; - return IOID_FAIL; + return -1; } xtvec.xtv_off = offset; @@ -1016,7 +1052,7 @@ _pwrite(int fd, const void *buf, size_t &ioctx); if (err) { errno = -err; - return IOID_FAIL; + return -1; } return _sysio_ioctx_wait(ioctx); } |