Whamcloud - gitweb
Branch b1_4
[fs/lustre-release.git] / libsysio / src / rw.c
index edc308b..328f076 100644 (file)
@@ -50,8 +50,8 @@
 #include <sys/uio.h>
 #include <sys/queue.h>
 
-#include "xtio.h"
 #include "sysio.h"
+#include "xtio.h"
 #include "file.h"
 #include "inode.h"
 
@@ -105,9 +105,7 @@ _sysio_iiox(int (*f)(struct inode *, struct ioctx *),
        /*
         * Check that it was opened with flags supporting the operation.
         */
-       if (!(wr
-               ? (fil->f_flags & (O_RDWR | O_WRONLY))
-               : !(fil->f_flags & O_WRONLY)))
+       if (!F_CHKRW(fil, wr ? 'w' : 'r'))
                return -EBADF;
 
        ino = fil->f_ino;
@@ -682,9 +680,13 @@ PREPEND(_, SYSIO_INTERFACE_NAME(ireadx))(int fd,
 
        SYSIO_INTERFACE_ENTER;
        fil = _sysio_fd_find(fd);
-       if (!(fil && xtv_count))
+       if (!fil)
                SYSIO_INTERFACE_RETURN(IOID_FAIL, -EBADF);
 
+       /* Perform a check on the iov_count and xtv_count */
+       if ((iov_count == 0) || (xtv_count == 0))
+               SYSIO_INTERFACE_RETURN(IOID_FAIL, -EINVAL);
+
        err =
            _sysio_iiox(IIOXOP_READ(fil->f_ino),
                        fil,
@@ -717,9 +719,14 @@ SYSIO_INTERFACE_NAME(ireadx)(int fd,
 
        SYSIO_INTERFACE_ENTER;
        fil = _sysio_fd_find(fd);
-       if (!(fil && xtv_count))
+       if (!fil)
                SYSIO_INTERFACE_RETURN(IOID_FAIL, -EBADF);
 
+
+       /* Perform a check on the iov_count and xtv_count */
+       if ((iov_count == 0) || (xtv_count == 0))
+               SYSIO_INTERFACE_RETURN(IOID_FAIL, -EINVAL);
+
        ixtv = ixtvent = malloc(xtv_count * sizeof(struct intnl_xtvec));
        if (!ixtv)
                SYSIO_INTERFACE_RETURN(IOID_FAIL, -ENOMEM);
@@ -764,7 +771,7 @@ SYSIO_INTERFACE_NAME(readx)(int fd,
                                                 xtv, 
                                                 xtv_count)) == IOID_FAIL)
                return -1;
-       return iowait(ioid);
+       return SYSIO_INTERFACE_NAME(iowait)(ioid);
 }
 
 #if _LARGEFILE64_SOURCE
@@ -782,7 +789,7 @@ SYSIO_INTERFACE_NAME(read64x)(int fd,
                                                   xtv, 
                                                   xtv_count)) == IOID_FAIL)
                return -1;
-       return iowait(ioid);
+       return SYSIO_INTERFACE_NAME(iowait)(ioid);
 }
 #endif
 
@@ -1236,9 +1243,13 @@ SYSIO_INTERFACE_NAME(iwritex)(int fd,
 
        SYSIO_INTERFACE_ENTER;
        fil = _sysio_fd_find(fd);
-       if (!(fil && xtv_count))
+       if (!fil)
                SYSIO_INTERFACE_RETURN(IOID_FAIL, -EBADF);
 
+       /* Perform a check on the iov_count and xtv_count */
+       if ((iov_count == 0) || (xtv_count == 0))
+               SYSIO_INTERFACE_RETURN(IOID_FAIL, -EINVAL);
+
        ixtv = ixtvent = malloc(xtv_count * sizeof(struct intnl_xtvec));
        if (!ixtv)
                SYSIO_INTERFACE_RETURN(IOID_FAIL, -ENOMEM);
@@ -1285,7 +1296,7 @@ SYSIO_INTERFACE_NAME(writex)(int fd,
                                           xtv, 
                                           xtv_count)) == IOID_FAIL)
                return -1;
-       return iowait(ioid);
+       return SYSIO_INTERFACE_NAME(iowait)(ioid);
 }
 
 #if _LARGEFILE64_SOURCE
@@ -1303,7 +1314,7 @@ SYSIO_INTERFACE_NAME(write64x)(int fd,
                                                    xtv, 
                                                    xtv_count)) == IOID_FAIL)
                return -1;
-       return iowait(ioid);
+       return SYSIO_INTERFACE_NAME(iowait)(ioid);
 }
 #endif