Whamcloud - gitweb
Branch b1_4
[fs/lustre-release.git] / libsysio / src / truncate.c
index abecb42..5846ad3 100644 (file)
@@ -43,6 +43,7 @@
 
 #include <unistd.h>
 #include <string.h>
+#include <fcntl.h>
 #include <errno.h>
 #include <assert.h>
 #include <sys/types.h>
@@ -52,6 +53,8 @@
 #include "sysio.h"
 #include "inode.h"
 #include "file.h"
+#include "fs.h"
+#include "mount.h"
 
 #include "sysio-symbols.h"
 
@@ -133,6 +136,10 @@ PREPEND(_, SYSIO_INTERFACE_NAME(ftruncate))(int fd, _SYSIO_OFF_T length)
                err = -EBADF;
                goto out;
        }
+       if (!F_CHKRW(fil, 'w')) {
+               err = -EBADF;
+               goto out;
+       }
        err = do_truncate(NULL, fil->f_ino, length);
 out:
        SYSIO_INTERFACE_RETURN(err ? -1 : 0, err);