fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / fs / jfs / xattr.c
index cba307d..b05b369 100644 (file)
@@ -4,16 +4,16 @@
  *
  *   This program is free software;  you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or 
+ *   the Free Software Foundation; either version 2 of the License, or
  *   (at your option) any later version.
- * 
+ *
  *   This program is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
  *   the GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software 
+ *   along with this program;  if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
@@ -58,7 +58,7 @@
  *
  *   0            4                   4 + EA_SIZE(ea1)
  *   +------------+-------------------+--------------------+-----
- *   | Overall EA | First FEA Element | Second FEA Element | ..... 
+ *   | Overall EA | First FEA Element | Second FEA Element | .....
  *   | List Size  |                   |                    |
  *   +------------+-------------------+--------------------+-----
  *
@@ -98,26 +98,26 @@ static inline int is_os2_xattr(struct jfs_ea *ea)
         */
        if ((ea->namelen >= XATTR_SYSTEM_PREFIX_LEN) &&
            !strncmp(ea->name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
-               return FALSE;
+               return false;
        /*
         * Check for "user."
         */
        if ((ea->namelen >= XATTR_USER_PREFIX_LEN) &&
            !strncmp(ea->name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN))
-               return FALSE;
+               return false;
        /*
         * Check for "security."
         */
        if ((ea->namelen >= XATTR_SECURITY_PREFIX_LEN) &&
            !strncmp(ea->name, XATTR_SECURITY_PREFIX,
                     XATTR_SECURITY_PREFIX_LEN))
-               return FALSE;
+               return false;
        /*
         * Check for "trusted."
         */
        if ((ea->namelen >= XATTR_TRUSTED_PREFIX_LEN) &&
            !strncmp(ea->name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
-               return FALSE;
+               return false;
        /*
         * Add any other valid namespace prefixes here
         */
@@ -125,7 +125,7 @@ static inline int is_os2_xattr(struct jfs_ea *ea)
        /*
         * We assume it's OS/2's flat namespace
         */
-       return TRUE;
+       return true;
 }
 
 static inline int name_size(struct jfs_ea *ea)
@@ -156,9 +156,9 @@ static void ea_release(struct inode *inode, struct ea_buffer *ea_buf);
 
 /*
  * NAME: ea_write_inline
- *                                                                    
+ *
  * FUNCTION: Attempt to write an EA inline if area is available
- *                                                                    
+ *
  * PRE CONDITIONS:
  *     Already verified that the specified EA is small enough to fit inline
  *
@@ -217,10 +217,10 @@ static int ea_write_inline(struct inode *ip, struct jfs_ea_list *ealist,
 
 /*
  * NAME: ea_write
- *                                                                    
+ *
  * FUNCTION: Write an EA for an inode
- *                                                                    
- * PRE CONDITIONS: EA has been verified 
+ *
+ * PRE CONDITIONS: EA has been verified
  *
  * PARAMETERS:
  *     ip      - Inode pointer
@@ -350,9 +350,9 @@ static int ea_write(struct inode *ip, struct jfs_ea_list *ealist, int size,
 
 /*
  * NAME: ea_read_inline
- *                                                                    
+ *
  * FUNCTION: Read an inlined EA into user's buffer
- *                                                                    
+ *
  * PARAMETERS:
  *     ip      - Inode pointer
  *     ealist  - Pointer to buffer to fill in with EA
@@ -382,9 +382,9 @@ static int ea_read_inline(struct inode *ip, struct jfs_ea_list *ealist)
 
 /*
  * NAME: ea_read
- *                                                                    
+ *
  * FUNCTION: copy EA data into user's buffer
- *                                                                    
+ *
  * PARAMETERS:
  *     ip      - Inode pointer
  *     ealist  - Pointer to buffer to fill in with EA
@@ -416,7 +416,7 @@ static int ea_read(struct inode *ip, struct jfs_ea_list *ealist)
                return -EIO;
        }
 
-       /* 
+       /*
         * Figure out how many blocks were allocated when this EA list was
         * originally written to disk.
         */
@@ -453,14 +453,14 @@ static int ea_read(struct inode *ip, struct jfs_ea_list *ealist)
 
 /*
  * NAME: ea_get
- *                                                                    
+ *
  * FUNCTION: Returns buffer containing existing extended attributes.
  *          The size of the buffer will be the larger of the existing
  *          attributes size, or min_size.
  *
  *          The buffer, which may be inlined in the inode or in the
- *          page cache must be release by calling ea_release or ea_put
- *                                                                    
+ *          page cache must be release by calling ea_release or ea_put
+ *
  * PARAMETERS:
  *     inode   - Inode pointer
  *     ea_buf  - Structure to be populated with ealist and its metadata
@@ -778,6 +778,11 @@ static int can_set_system_xattr(struct inode *inode, const char *name,
        return -EOPNOTSUPP;
 }
 
+/*
+ * Most of the permission checking is done by xattr_permission in the vfs.
+ * The local file system is responsible for handling the system.* namespace.
+ * We also need to verify that this is a namespace that we recognize.
+ */
 static int can_set_xattr(struct inode *inode, const char *name,
                         const void *value, size_t value_len)
 {
@@ -793,10 +798,6 @@ static int can_set_xattr(struct inode *inode, const char *name,
            strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN))
                return -EOPNOTSUPP;
 
-       if (!S_ISREG(inode->i_mode) &&
-           (!S_ISDIR(inode->i_mode) || inode->i_mode &S_ISVTX))
-               return -EPERM;
-
        return 0;
 }
 
@@ -956,13 +957,13 @@ int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
        }
 
        tid = txBegin(inode->i_sb, 0);
-       down(&ji->commit_sem);
+       mutex_lock(&ji->commit_mutex);
        rc = __jfs_setxattr(tid, dentry->d_inode, name, value, value_len,
                            flags);
        if (!rc)
                rc = txCommit(tid, 1, &inode, 0);
        txEnd(tid);
-       up(&ji->commit_sem);
+       mutex_unlock(&ji->commit_mutex);
 
        return rc;
 }
@@ -1076,7 +1077,7 @@ ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size)
 
        /* compute required size of list */
        for (ea = FIRST_EA(ealist); ea < END_EALIST(ealist); ea = NEXT_EA(ea)) {
-               if (can_list(ea))
+               if (can_list(ea))
                        size += name_size(ea) + 1;
        }
 
@@ -1091,7 +1092,7 @@ ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size)
        /* Copy attribute names to buffer */
        buffer = data;
        for (ea = FIRST_EA(ealist); ea < END_EALIST(ealist); ea = NEXT_EA(ea)) {
-               if (can_list(ea)) {
+               if (can_list(ea)) {
                        int namelen = copy_name(buffer, ea);
                        buffer += namelen + 1;
                }
@@ -1115,12 +1116,12 @@ int jfs_removexattr(struct dentry *dentry, const char *name)
                return rc;
 
        tid = txBegin(inode->i_sb, 0);
-       down(&ji->commit_sem);
+       mutex_lock(&ji->commit_mutex);
        rc = __jfs_setxattr(tid, dentry->d_inode, name, NULL, 0, XATTR_REPLACE);
        if (!rc)
                rc = txCommit(tid, 1, &inode, 0);
        txEnd(tid);
-       up(&ji->commit_sem);
+       mutex_unlock(&ji->commit_mutex);
 
        return rc;
 }