patch-2.1.52 linux/fs/attr.c

Next file: linux/fs/binfmt_misc.c
Previous file: linux/drivers/scsi/scsi_ioctl.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.51/linux/fs/attr.c linux/fs/attr.c
@@ -17,83 +17,87 @@
 /* POSIX UID/GID verification for setting inode attributes. */
 int inode_change_ok(struct inode *inode, struct iattr *attr)
 {
+	int retval = -EPERM;
+	unsigned int ia_valid = attr->ia_valid;
+
 	/* If force is set do it anyway. */
-	if (attr->ia_valid & ATTR_FORCE)
-		return 0;
+	if (ia_valid & ATTR_FORCE)
+		goto fine;
 
 	/* Make sure a caller can chown. */
-	if ((attr->ia_valid & ATTR_UID) &&
+	if ((ia_valid & ATTR_UID) &&
 	    (current->fsuid != inode->i_uid ||
 	     attr->ia_uid != inode->i_uid) && !fsuser())
-		return -EPERM;
+		goto error;
 
 	/* Make sure caller can chgrp. */
-	if ((attr->ia_valid & ATTR_GID) &&
+	if ((ia_valid & ATTR_GID) &&
 	    (!in_group_p(attr->ia_gid) && attr->ia_gid != inode->i_gid) &&
 	    !fsuser())
-		return -EPERM;
+		goto error;
 
 	/* Make sure a caller can chmod. */
-	if (attr->ia_valid & ATTR_MODE) {
+	if (ia_valid & ATTR_MODE) {
 		if ((current->fsuid != inode->i_uid) && !fsuser())
-			return -EPERM;
+			goto error;
 		/* Also check the setgid bit! */
-		if (!fsuser() && !in_group_p((attr->ia_valid & ATTR_GID) ? attr->ia_gid :
+		if (!fsuser() && !in_group_p((ia_valid & ATTR_GID) ? attr->ia_gid :
 					     inode->i_gid))
 			attr->ia_mode &= ~S_ISGID;
 	}
 
 	/* Check for setting the inode time. */
-	if ((attr->ia_valid & ATTR_ATIME_SET) &&
-	    ((current->fsuid != inode->i_uid) && !fsuser()))
-		return -EPERM;
-	if ((attr->ia_valid & ATTR_MTIME_SET) &&
-	    ((current->fsuid != inode->i_uid) && !fsuser()))
-		return -EPERM;
-	return 0;
+	if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
+		if (current->fsuid != inode->i_uid && !fsuser())
+			goto error;
+	}
+fine:
+	retval = 0;
+error:
+	return retval;
 }
 
 void inode_setattr(struct inode * inode, struct iattr * attr)
 {
-	if(attr->ia_valid &
-	   (ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_ATIME|ATTR_MTIME|ATTR_CTIME|ATTR_MODE)) {
-		if (attr->ia_valid & ATTR_UID)
-			inode->i_uid = attr->ia_uid;
-		if (attr->ia_valid & ATTR_GID)
-			inode->i_gid = attr->ia_gid;
-		if (attr->ia_valid & ATTR_SIZE)
-			inode->i_size = attr->ia_size;
-		if (attr->ia_valid & ATTR_ATIME)
-			inode->i_atime = attr->ia_atime;
-		if (attr->ia_valid & ATTR_MTIME)
-			inode->i_mtime = attr->ia_mtime;
-		if (attr->ia_valid & ATTR_CTIME)
-			inode->i_ctime = attr->ia_ctime;
-		if (attr->ia_valid & ATTR_MODE) {
-			inode->i_mode = attr->ia_mode;
-			if (!fsuser() && !in_group_p(inode->i_gid))
-				inode->i_mode &= ~S_ISGID;
-		}
-		mark_inode_dirty(inode);
+	unsigned int ia_valid = attr->ia_valid;
+
+	if (ia_valid & ATTR_UID)
+		inode->i_uid = attr->ia_uid;
+	if (ia_valid & ATTR_GID)
+		inode->i_gid = attr->ia_gid;
+	if (ia_valid & ATTR_SIZE)
+		inode->i_size = attr->ia_size;
+	if (ia_valid & ATTR_ATIME)
+		inode->i_atime = attr->ia_atime;
+	if (ia_valid & ATTR_MTIME)
+		inode->i_mtime = attr->ia_mtime;
+	if (ia_valid & ATTR_CTIME)
+		inode->i_ctime = attr->ia_ctime;
+	if (ia_valid & ATTR_MODE) {
+		inode->i_mode = attr->ia_mode;
+		if (!fsuser() && !in_group_p(inode->i_gid))
+			inode->i_mode &= ~S_ISGID;
 	}
+	mark_inode_dirty(inode);
 }
 
 int notify_change(struct inode * inode, struct iattr * attr)
 {
 	int error;
 	time_t now = CURRENT_TIME;
+	unsigned int ia_valid = attr->ia_valid;
 
 	attr->ia_ctime = now;
-	if ((attr->ia_valid & (ATTR_ATIME | ATTR_ATIME_SET)) == ATTR_ATIME)
+	if (!(ia_valid & ATTR_ATIME_SET))
 		attr->ia_atime = now;
-	if ((attr->ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) == ATTR_MTIME)
+	if (!(ia_valid & ATTR_MTIME_SET))
 		attr->ia_mtime = now;
-	attr->ia_valid &= ~(ATTR_CTIME);
+
 	if (inode->i_sb && inode->i_sb->s_op && inode->i_sb->s_op->notify_change) 
 		return inode->i_sb->s_op->notify_change(inode, attr);
+
 	error = inode_change_ok(inode, attr);
-	if(!error)
+	if (!error)
 		inode_setattr(inode, attr);
 	return error;
 }
-

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov