]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - fs/attr.c
drivers/infiniband: Remove unnecessary casts of private_data
[net-next-2.6.git] / fs / attr.c
index 0815e93bb487e0651619d942b6bd78d7fe6a2e89..7ca41811afa1147ad764acbd1fe5b5957c883f5d 100644 (file)
--- a/fs/attr.c
+++ b/fs/attr.c
 #include <linux/fcntl.h>
 #include <linux/security.h>
 
-/* Taken over from the old code... */
-
-/* POSIX UID/GID verification for setting inode attributes. */
+/**
+ * inode_change_ok - check if attribute changes to an inode are allowed
+ * @inode:     inode to check
+ * @attr:      attributes to change
+ *
+ * Check if we are allowed to change the attributes contained in @attr
+ * in the given inode.  This includes the normal unix access permission
+ * checks, as well as checks for rlimits and others.
+ *
+ * Should be called as the first thing in ->setattr implementations,
+ * possibly after taking additional locks.
+ */
 int inode_change_ok(const struct inode *inode, struct iattr *attr)
 {
-       int retval = -EPERM;
        unsigned int ia_valid = attr->ia_valid;
 
+       /*
+        * First check size constraints.  These can't be overriden using
+        * ATTR_FORCE.
+        */
+       if (ia_valid & ATTR_SIZE) {
+               int error = inode_newsize_ok(inode, attr->ia_size);
+               if (error)
+                       return error;
+       }
+
        /* If force is set do it anyway. */
        if (ia_valid & ATTR_FORCE)
-               goto fine;
+               return 0;
 
        /* Make sure a caller can chown. */
        if ((ia_valid & ATTR_UID) &&
            (current_fsuid() != inode->i_uid ||
             attr->ia_uid != inode->i_uid) && !capable(CAP_CHOWN))
-               goto error;
+               return -EPERM;
 
        /* Make sure caller can chgrp. */
        if ((ia_valid & ATTR_GID) &&
            (current_fsuid() != inode->i_uid ||
            (!in_group_p(attr->ia_gid) && attr->ia_gid != inode->i_gid)) &&
            !capable(CAP_CHOWN))
-               goto error;
+               return -EPERM;
 
        /* Make sure a caller can chmod. */
        if (ia_valid & ATTR_MODE) {
                if (!is_owner_or_cap(inode))
-                       goto error;
+                       return -EPERM;
                /* Also check the setgid bit! */
                if (!in_group_p((ia_valid & ATTR_GID) ? attr->ia_gid :
                                inode->i_gid) && !capable(CAP_FSETID))
@@ -52,12 +70,10 @@ int inode_change_ok(const struct inode *inode, struct iattr *attr)
        /* Check for setting the inode time. */
        if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)) {
                if (!is_owner_or_cap(inode))
-                       goto error;
+                       return -EPERM;
        }
-fine:
-       retval = 0;
-error:
-       return retval;
+
+       return 0;
 }
 EXPORT_SYMBOL(inode_change_ok);
 
@@ -67,14 +83,14 @@ EXPORT_SYMBOL(inode_change_ok);
  * @offset:    the new size to assign to the inode
  * @Returns:   0 on success, -ve errno on failure
  *
+ * inode_newsize_ok must be called with i_mutex held.
+ *
  * inode_newsize_ok will check filesystem limits and ulimits to check that the
  * new inode size is within limits. inode_newsize_ok will also send SIGXFSZ
  * when necessary. Caller must not proceed with inode size change if failure is
  * returned. @inode must be a file (not directory), with appropriate
  * permissions to allow truncate (inode_newsize_ok does NOT check these
  * conditions).
- *
- * inode_newsize_ok must be called with i_mutex held.
  */
 int inode_newsize_ok(const struct inode *inode, loff_t offset)
 {
@@ -104,17 +120,25 @@ out_big:
 }
 EXPORT_SYMBOL(inode_newsize_ok);
 
-int inode_setattr(struct inode * inode, struct iattr * attr)
+/**
+ * setattr_copy - copy simple metadata updates into the generic inode
+ * @inode:     the inode to be updated
+ * @attr:      the new attributes
+ *
+ * setattr_copy must be called with i_mutex held.
+ *
+ * setattr_copy updates the inode's metadata with that specified
+ * in attr. Noticably missing is inode size update, which is more complex
+ * as it requires pagecache updates.
+ *
+ * The inode is not marked as dirty after this operation. The rationale is
+ * that for "simple" filesystems, the struct inode is the inode storage.
+ * The caller is free to mark the inode dirty afterwards if needed.
+ */
+void setattr_copy(struct inode *inode, const struct iattr *attr)
 {
        unsigned int ia_valid = attr->ia_valid;
 
-       if (ia_valid & ATTR_SIZE &&
-           attr->ia_size != i_size_read(inode)) {
-               int error = vmtruncate(inode, attr->ia_size);
-               if (error)
-                       return error;
-       }
-
        if (ia_valid & ATTR_UID)
                inode->i_uid = attr->ia_uid;
        if (ia_valid & ATTR_GID)
@@ -135,11 +159,8 @@ int inode_setattr(struct inode * inode, struct iattr * attr)
                        mode &= ~S_ISGID;
                inode->i_mode = mode;
        }
-       mark_inode_dirty(inode);
-
-       return 0;
 }
-EXPORT_SYMBOL(inode_setattr);
+EXPORT_SYMBOL(setattr_copy);
 
 int notify_change(struct dentry * dentry, struct iattr * attr)
 {
@@ -207,13 +228,10 @@ int notify_change(struct dentry * dentry, struct iattr * attr)
        if (ia_valid & ATTR_SIZE)
                down_write(&dentry->d_inode->i_alloc_sem);
 
-       if (inode->i_op && inode->i_op->setattr) {
+       if (inode->i_op->setattr)
                error = inode->i_op->setattr(dentry, attr);
-       } else {
-               error = inode_change_ok(inode, attr);
-               if (!error)
-                       error = inode_setattr(inode, attr);
-       }
+       else
+               error = simple_setattr(dentry, attr);
 
        if (ia_valid & ATTR_SIZE)
                up_write(&dentry->d_inode->i_alloc_sem);