[Libsysio-commit] HEAD: libsysio/include file.h
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2006-04-10 23:25:58
|
Update of /cvsroot/libsysio/libsysio/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6661/include Modified Files: file.h 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: file.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/file.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -w -b -B -p -r1.13 -r1.14 --- file.h 31 Oct 2005 19:47:42 -0000 1.13 +++ file.h 10 Apr 2006 23:25:54 -0000 1.14 @@ -112,6 +112,22 @@ struct file { (fil)->f_flags = (flags); \ } while (0) +/* + * Determine if a file may be read/written. + * + * Give it the open file table ptr and a character indicating read, 'r', or + * write 'w'. It will return 0 if that access is permitted or -EBADF, if not. + */ + +#define F_CHKRW(_fil, _c) \ + ((_c) == O_RDONLY \ + ? (((_fil)->f_flags & O_RDONLY || (_fil)->f_flags & O_RDWR) \ + ? 0 \ + : -EBADF) \ + : (((_fil)->f_flags & O_WRONLY || (_fil)->f_flags & O_RDWR) \ + ? (IS_RDONLY(NULL, (_fil)->f_ino) ? -EROFS : 0) \ + : -EBADF)) + struct ioctx; extern struct file *_sysio_fnew(struct inode *ino, int flags); |