patch-2.3.10 linux/fs/ext2/ioctl.c

Next file: linux/fs/fat/dir.c
Previous file: linux/fs/exec.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.9/linux/fs/ext2/ioctl.c linux/fs/ext2/ioctl.c
@@ -27,28 +27,35 @@
 	case EXT2_IOC_GETFLAGS:
 		flags = inode->u.ext2_i.i_flags & EXT2_FL_USER_VISIBLE;
 		return put_user(inode->u.ext2_i.i_flags, (int *) arg);
-	case EXT2_IOC_SETFLAGS:
+	case EXT2_IOC_SETFLAGS: {
+		unsigned int oldflags;
+
+		if (IS_RDONLY(inode))
+			return -EROFS;
+
+		if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
+			return -EPERM;
+
 		if (get_user(flags, (int *) arg))
 			return -EFAULT;
-		flags = flags & EXT2_FL_USER_MODIFIABLE;
+
+		oldflags = inode->u.ext2_i.i_flags;
+
 		/*
 		 * The IMMUTABLE and APPEND_ONLY flags can only be changed by
-		 * the super user when the security level is zero.
+		 * the relevant capability.
+		 *
+		 * This test looks nicer. Thanks to Pauline Middelink
 		 */
-		if ((flags & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) ^
-		    (inode->u.ext2_i.i_flags &
-		     (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL))) {
-			/* This test looks nicer. Thanks to Pauline Middelink */
+		if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
 			if (!capable(CAP_LINUX_IMMUTABLE))
 				return -EPERM;
-		} else
-			if ((current->fsuid != inode->i_uid) && 
-			    !capable(CAP_FOWNER))
-				return -EPERM;
-		if (IS_RDONLY(inode))
-			return -EROFS;
-		inode->u.ext2_i.i_flags = (inode->u.ext2_i.i_flags &
-					   ~EXT2_FL_USER_MODIFIABLE) | flags;
+		}
+
+		flags = flags & EXT2_FL_USER_MODIFIABLE;
+		flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
+		inode->u.ext2_i.i_flags = flags;
+
 		if (flags & EXT2_SYNC_FL)
 			inode->i_flags |= MS_SYNCHRONOUS;
 		else
@@ -68,6 +75,7 @@
 		inode->i_ctime = CURRENT_TIME;
 		mark_inode_dirty(inode);
 		return 0;
+	}
 	case EXT2_IOC_GETVERSION:
 		return put_user(inode->i_generation, (int *) arg);
 	case EXT2_IOC_SETVERSION:

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)