[Libsysio-commit] HEAD: libsysio/src truncate.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2006-04-10 23:25:58
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6661/src Modified Files: truncate.c Log Message: Add a new macro, F_CHKRW, that given a pointer to an open file table entry and one of 'r' or 'w' will return: 0 if the access is permitted against the open file -EBADF if not opened for the desired access -EROFS if 'w' and the file system was mounted read-only Then, using the new macro, implemented a check for the truncate/ftruncate calls to assure the file and mount will permit the operation before attempting it against the lower-level driver. Index: truncate.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/truncate.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -w -b -B -p -r1.13 -r1.14 --- truncate.c 21 Sep 2004 16:18:31 -0000 1.13 +++ truncate.c 10 Apr 2006 23:25:54 -0000 1.14 @@ -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,9 @@ PREPEND(_, SYSIO_INTERFACE_NAME(ftruncat err = -EBADF; goto out; } + err = F_CHKRW(fil, 'w'); + if (err) + goto out; err = do_truncate(NULL, fil->f_ino, length); out: SYSIO_INTERFACE_RETURN(err ? -1 : 0, err); |