Skip to contentSkip to conversation

make the feature checks in ->fallocate future proof

PATCH In review Christoph Hellwig 2 participants 2 messages Jan 14, 2011

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 make the feature checks in ->fallocate future proof

Instead of various home grown checks that might need updates for new flags just check for any bit outside the mask of the features supported by the filesystem. This makes the check future proof for any newly added flag.

fs/btrfs/inode.c +1 -1
Index: linux-2.6/fs/btrfs/inode.c
===================================================================
@@ -7116,7 +7116,7 @@ static long btrfs_fallocate(struct inode
 	alloc_end =  (offset + len + mask) & ~mask;
 
 	/* We only support the FALLOC_FL_KEEP_SIZE mode */
-	if (mode && (mode != FALLOC_FL_KEEP_SIZE))
+	if (mode & ~FALLOC_FL_KEEP_SIZE)
 		return -EOPNOTSUPP;
 
 	/*
fs/ext4/extents.c +1 -1
Index: linux-2.6/fs/ext4/extents.c
===================================================================
@@ -3645,7 +3645,7 @@ long ext4_fallocate(struct inode *inode,
 	unsigned int credits, blkbits = inode->i_blkbits;
 
 	/* We only support the FALLOC_FL_KEEP_SIZE mode */
-	if (mode && (mode != FALLOC_FL_KEEP_SIZE))
+	if (mode & ~FALLOC_FL_KEEP_SIZE)
 		return -EOPNOTSUPP;
 
 	/*
fs/gfs2/ops_inode.c +1 -1
Index: linux-2.6/fs/gfs2/ops_inode.c
===================================================================
@@ -1426,7 +1426,7 @@ static long gfs2_fallocate(struct inode
 	next = (next + 1) << sdp->sd_sb.sb_bsize_shift;
 
 	/* We only support the FALLOC_FL_KEEP_SIZE mode */
-	if (mode && (mode != FALLOC_FL_KEEP_SIZE))
+	if (mode & ~FALLOC_FL_KEEP_SIZE)
 		return -EOPNOTSUPP;
 
 	offset = (offset >> sdp->sd_sb.sb_bsize_shift) <<
fs/ocfs2/file.c +2 -0
Index: linux-2.6/fs/ocfs2/file.c
===================================================================
@@ -1997,6 +1997,8 @@ static long ocfs2_fallocate(struct inode
 	int change_size = 1;
 	int cmd = OCFS2_IOC_RESVSP64;
 
+	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
+		return -EOPNOTSUPP;
 	if (!ocfs2_writes_unwritten_extents(osb))
 		return -EOPNOTSUPP;
 
fs/xfs/linux-2.6/xfs_iops.c +3 -0
Index: linux-2.6/fs/xfs/linux-2.6/xfs_iops.c
===================================================================
@@ -518,6 +518,9 @@ xfs_vn_fallocate(
 	xfs_inode_t	*ip = XFS_I(inode);
 	int		cmd = XFS_IOC_RESVSP;
 
+	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
+		return -EOPNOTSUPP;
+
 	/* preallocation on directories not yet supported */
 	error = -ENODEV;
 	if (S_ISDIR(inode->i_mode))