public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/4] stop re-checking permissions in xfs_swapext
@ 2007-12-21  6:22 Christoph Hellwig
  0 siblings, 0 replies; only message in thread
From: Christoph Hellwig @ 2007-12-21  6:22 UTC (permalink / raw)
  To: xfs

xfs_swapext should simplify check if we have a writeable file descriptor
instead of re-checking the permissions using xfs_iaccess.   Add an
additional check to refuse O_APPEND file descriptors because swapext is
not an append-only write operation.


Signed-off-by: Christoph Hellwig <hch@lst.de>

Index: linux-2.6-xfs/fs/xfs/xfs_dfrag.c
===================================================================
--- linux-2.6-xfs.orig/fs/xfs/xfs_dfrag.c	2007-12-19 16:57:18.000000000 +0100
+++ linux-2.6-xfs/fs/xfs/xfs_dfrag.c	2007-12-19 16:57:29.000000000 +0100
@@ -74,12 +74,23 @@ xfs_swapext(
 		goto out_free_sxp;
 	}
 
+	if (!(file->f_mode & FMODE_WRITE) || (file->f_flags & O_APPEND)) {
+		error = XFS_ERROR(EBADF);
+		goto out_put_file;
+	}
+
 	target_file = fget((int)sxp->sx_fdtmp);
 	if (!target_file) {
 		error = XFS_ERROR(EINVAL);
 		goto out_put_file;
 	}
 
+	if (!(target_file->f_mode & FMODE_WRITE) ||
+	    (target_file->f_flags & O_APPEND)) {
+		error = XFS_ERROR(EBADF);
+		goto out_put_target_file;
+	}
+
 	ip = XFS_I(file->f_path.dentry->d_inode);
 	tip = XFS_I(target_file->f_path.dentry->d_inode);
 
@@ -154,15 +165,6 @@ xfs_swap_extents(
 	xfs_lock_inodes(ips, 2, 0, lock_flags);
 	locked = 1;
 
-	/* Check permissions */
-	error = xfs_iaccess(ip, S_IWUSR, NULL);
-	if (error)
-		goto error0;
-
-	error = xfs_iaccess(tip, S_IWUSR, NULL);
-	if (error)
-		goto error0;
-
 	/* Verify that both files have the same format */
 	if ((ip->i_d.di_mode & S_IFMT) != (tip->i_d.di_mode & S_IFMT)) {
 		error = XFS_ERROR(EINVAL);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-12-21  6:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-21  6:22 [PATCH 3/4] stop re-checking permissions in xfs_swapext Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox