]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/xfs/xfs_attr.c
[XFS] Make some extended attributes routines take const parameters, for
[linux-2.6-omap-h63xx.git] / fs / xfs / xfs_attr.c
index ee8b5904ec7ccd7e7fb0a15ec3470cd1336e2c45..c2c14b2103f1d59ea7a8e68f538960e0f5bbea3c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of version 2 of the GNU General Public License as
  * Provide the external interfaces to manage attribute lists.
  */
 
+#define ATTR_SYSCOUNT  2
+STATIC struct attrnames posix_acl_access;
+STATIC struct attrnames posix_acl_default;
+STATIC struct attrnames *attr_system_names[ATTR_SYSCOUNT];
+
 /*========================================================================
  * Function prototypes for the kernel.
  *========================================================================*/
@@ -83,6 +88,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
 /*
  * Internal routines when attribute list is one block.
  */
+STATIC int xfs_attr_leaf_get(xfs_da_args_t *args);
 STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args);
 STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
 STATIC int xfs_attr_leaf_list(xfs_attr_list_context_t *context);
@@ -90,6 +96,7 @@ STATIC int xfs_attr_leaf_list(xfs_attr_list_context_t *context);
 /*
  * Internal routines when attribute list is more than one block.
  */
+STATIC int xfs_attr_node_get(xfs_da_args_t *args);
 STATIC int xfs_attr_node_addname(xfs_da_args_t *args);
 STATIC int xfs_attr_node_removename(xfs_da_args_t *args);
 STATIC int xfs_attr_node_list(xfs_attr_list_context_t *context);
@@ -115,7 +122,7 @@ ktrace_t *xfs_attr_trace_buf;
  *========================================================================*/
 
 int
-xfs_attr_fetch(xfs_inode_t *ip, char *name, int namelen,
+xfs_attr_fetch(xfs_inode_t *ip, const char *name, int namelen,
               char *value, int *valuelenp, int flags, struct cred *cred)
 {
        xfs_da_args_t   args;
@@ -170,7 +177,7 @@ xfs_attr_fetch(xfs_inode_t *ip, char *name, int namelen,
 }
 
 int
-xfs_attr_get(bhv_desc_t *bdp, char *name, char *value, int *valuelenp,
+xfs_attr_get(bhv_desc_t *bdp, const char *name, char *value, int *valuelenp,
             int flags, struct cred *cred)
 {
        xfs_inode_t     *ip = XFS_BHVTOI(bdp);
@@ -193,40 +200,18 @@ xfs_attr_get(bhv_desc_t *bdp, char *name, char *value, int *valuelenp,
        return(error);
 }
 
-/*ARGSUSED*/
-int                                                            /* error */
-xfs_attr_set(bhv_desc_t *bdp, char *name, char *value, int valuelen, int flags,
-                    struct cred *cred)
+STATIC int
+xfs_attr_set_int(xfs_inode_t *dp, const char *name, int namelen,
+                char *value, int valuelen, int flags)
 {
        xfs_da_args_t   args;
-       xfs_inode_t     *dp;
        xfs_fsblock_t   firstblock;
        xfs_bmap_free_t flist;
        int             error, err2, committed;
        int             local, size;
        uint            nblks;
-       xfs_mount_t     *mp;
+       xfs_mount_t     *mp = dp->i_mount;
        int             rsvd = (flags & ATTR_ROOT) != 0;
-       int             namelen;
-
-       namelen = strlen(name);
-       if (namelen >= MAXNAMELEN)
-               return EFAULT;          /* match IRIX behaviour */
-
-       XFS_STATS_INC(xs_attr_set);
-
-       dp = XFS_BHVTOI(bdp);
-       mp = dp->i_mount;
-       if (XFS_FORCED_SHUTDOWN(mp))
-               return (EIO);
-
-       xfs_ilock(dp, XFS_ILOCK_SHARED);
-       if (!(flags & ATTR_SECURE) &&
-            (error = xfs_iaccess(dp, S_IWUSR, cred))) {
-               xfs_iunlock(dp, XFS_ILOCK_SHARED);
-               return(XFS_ERROR(error));
-       }
-       xfs_iunlock(dp, XFS_ILOCK_SHARED);
 
        /*
         * Attach the dquots to the inode.
@@ -234,13 +219,19 @@ xfs_attr_set(bhv_desc_t *bdp, char *name, char *value, int valuelen, int flags,
        if ((error = XFS_QM_DQATTACH(mp, dp, 0)))
                return (error);
 
+       /*
+        * Determine space new attribute will use, and if it would be
+        * "local" or "remote" (note: local != inline).
+        */
+       size = xfs_attr_leaf_newentsize(namelen, valuelen,
+                                       mp->m_sb.sb_blocksize, &local);
+
        /*
         * If the inode doesn't have an attribute fork, add one.
         * (inode must not be locked when we call this routine)
         */
        if (XFS_IFORK_Q(dp) == 0) {
-               error = xfs_bmap_add_attrfork(dp, rsvd);
-               if (error)
+               if ((error = xfs_bmap_add_attrfork(dp, size, rsvd)))
                        return(error);
        }
 
@@ -258,13 +249,9 @@ xfs_attr_set(bhv_desc_t *bdp, char *name, char *value, int valuelen, int flags,
        args.firstblock = &firstblock;
        args.flist = &flist;
        args.whichfork = XFS_ATTR_FORK;
+       args.addname = 1;
        args.oknoent = 1;
 
-       /* Determine space new attribute will use, and if it will be inline
-        * or out of line.
-        */
-       size = xfs_attr_leaf_newentsize(&args, mp->m_sb.sb_blocksize, &local);
-
        nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK);
        if (local) {
                if (size > (mp->m_sb.sb_blocksize >> 1)) {
@@ -336,7 +323,7 @@ xfs_attr_set(bhv_desc_t *bdp, char *name, char *value, int valuelen, int flags,
                 * Build initial attribute list (if required).
                 */
                if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
-                       (void)xfs_attr_shortform_create(&args);
+                       xfs_attr_shortform_create(&args);
 
                /*
                 * Try to add the attr to the attribute list in
@@ -449,32 +436,21 @@ out:
        return(error);
 }
 
-/*
- * Generic handler routine to remove a name from an attribute list.
- * Transitions attribute list from Btree to shortform as necessary.
- */
-/*ARGSUSED*/
-int                                                            /* error */
-xfs_attr_remove(bhv_desc_t *bdp, char *name, int flags, struct cred *cred)
+int
+xfs_attr_set(bhv_desc_t *bdp, const char *name, char *value, int valuelen, int flags,
+            struct cred *cred)
 {
-       xfs_da_args_t       args;
-       xfs_inode_t         *dp;
-       xfs_fsblock_t       firstblock;
-       xfs_bmap_free_t     flist;
-       int                 error;
-       xfs_mount_t         *mp;
-       int                 namelen;
+       xfs_inode_t     *dp;
+       int             namelen, error;
 
-       ASSERT(MAXNAMELEN-1<=0xff); /* length is stored in uint8 */
        namelen = strlen(name);
-       if (namelen>=MAXNAMELEN)
-               return EFAULT; /* match irix behaviour */
+       if (namelen >= MAXNAMELEN)
+               return EFAULT;          /* match IRIX behaviour */
 
-       XFS_STATS_INC(xs_attr_remove);
+       XFS_STATS_INC(xs_attr_set);
 
        dp = XFS_BHVTOI(bdp);
-       mp = dp->i_mount;
-       if (XFS_FORCED_SHUTDOWN(mp))
+       if (XFS_FORCED_SHUTDOWN(dp->i_mount))
                return (EIO);
 
        xfs_ilock(dp, XFS_ILOCK_SHARED);
@@ -482,14 +458,25 @@ xfs_attr_remove(bhv_desc_t *bdp, char *name, int flags, struct cred *cred)
             (error = xfs_iaccess(dp, S_IWUSR, cred))) {
                xfs_iunlock(dp, XFS_ILOCK_SHARED);
                return(XFS_ERROR(error));
-       } else if (XFS_IFORK_Q(dp) == 0 ||
-                  (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
-                   dp->i_d.di_anextents == 0)) {
-               xfs_iunlock(dp, XFS_ILOCK_SHARED);
-               return(XFS_ERROR(ENOATTR));
        }
        xfs_iunlock(dp, XFS_ILOCK_SHARED);
 
+       return xfs_attr_set_int(dp, name, namelen, value, valuelen, flags);
+}
+
+/*
+ * Generic handler routine to remove a name from an attribute list.
+ * Transitions attribute list from Btree to shortform as necessary.
+ */
+STATIC int
+xfs_attr_remove_int(xfs_inode_t *dp, const char *name, int namelen, int flags)
+{
+       xfs_da_args_t   args;
+       xfs_fsblock_t   firstblock;
+       xfs_bmap_free_t flist;
+       int             error;
+       xfs_mount_t     *mp = dp->i_mount;
+
        /*
         * Fill in the arg structure for this request.
         */
@@ -537,7 +524,6 @@ xfs_attr_remove(bhv_desc_t *bdp, char *name, int flags, struct cred *cred)
                                      XFS_ATTRRM_LOG_COUNT))) {
                xfs_trans_cancel(args.trans, 0);
                return(error);
-
        }
 
        xfs_ilock(dp, XFS_ILOCK_EXCL);
@@ -605,6 +591,38 @@ out:
        return(error);
 }
 
+int
+xfs_attr_remove(bhv_desc_t *bdp, const char *name, int flags, struct cred *cred)
+{
+       xfs_inode_t         *dp;
+       int                 namelen, error;
+
+       namelen = strlen(name);
+       if (namelen >= MAXNAMELEN)
+               return EFAULT;          /* match IRIX behaviour */
+
+       XFS_STATS_INC(xs_attr_remove);
+
+       dp = XFS_BHVTOI(bdp);
+       if (XFS_FORCED_SHUTDOWN(dp->i_mount))
+               return (EIO);
+
+       xfs_ilock(dp, XFS_ILOCK_SHARED);
+       if (!(flags & ATTR_SECURE) &&
+            (error = xfs_iaccess(dp, S_IWUSR, cred))) {
+               xfs_iunlock(dp, XFS_ILOCK_SHARED);
+               return(XFS_ERROR(error));
+       } else if (XFS_IFORK_Q(dp) == 0 ||
+                  (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
+                   dp->i_d.di_anextents == 0)) {
+               xfs_iunlock(dp, XFS_ILOCK_SHARED);
+               return(XFS_ERROR(ENOATTR));
+       }
+       xfs_iunlock(dp, XFS_ILOCK_SHARED);
+
+       return xfs_attr_remove_int(dp, name, namelen, flags);
+}
+
 /*
  * Generate a list of extended attribute names and optionally
  * also value lengths.  Positive return value follows the XFS
@@ -804,7 +822,7 @@ out:
 STATIC int
 xfs_attr_shortform_addname(xfs_da_args_t *args)
 {
-       int newsize, retval;
+       int newsize, forkoff, retval;
 
        retval = xfs_attr_shortform_lookup(args);
        if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
@@ -816,16 +834,18 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
                ASSERT(retval == 0);
        }
 
+       if (args->namelen >= XFS_ATTR_SF_ENTSIZE_MAX ||
+           args->valuelen >= XFS_ATTR_SF_ENTSIZE_MAX)
+               return(XFS_ERROR(ENOSPC));
+
        newsize = XFS_ATTR_SF_TOTSIZE(args->dp);
        newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen);
-       if ((newsize <= XFS_IFORK_ASIZE(args->dp)) &&
-           (args->namelen < XFS_ATTR_SF_ENTSIZE_MAX) &&
-           (args->valuelen < XFS_ATTR_SF_ENTSIZE_MAX)) {
-               retval = xfs_attr_shortform_add(args);
-               ASSERT(retval == 0);
-       } else {
+
+       forkoff = xfs_attr_shortform_bytesfit(args->dp, newsize);
+       if (!forkoff)
                return(XFS_ERROR(ENOSPC));
-       }
+
+       xfs_attr_shortform_add(args, forkoff);
        return(0);
 }
 
@@ -845,7 +865,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
 {
        xfs_inode_t *dp;
        xfs_dabuf_t *bp;
-       int retval, error, committed;
+       int retval, error, committed, forkoff;
 
        /*
         * Read the (only) block in the attribute list in.
@@ -988,9 +1008,9 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
                /*
                 * If the result is small enough, shrink it all into the inode.
                 */
-               if (xfs_attr_shortform_allfit(bp, dp)) {
+               if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
                        XFS_BMAP_INIT(args->flist, args->firstblock);
-                       error = xfs_attr_leaf_to_shortform(bp, args);
+                       error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
                        /* bp is gone due to xfs_da_shrink_inode */
                        if (!error) {
                                error = xfs_bmap_finish(&args->trans,
@@ -1042,8 +1062,7 @@ xfs_attr_leaf_removename(xfs_da_args_t *args)
 {
        xfs_inode_t *dp;
        xfs_dabuf_t *bp;
-       int committed;
-       int error;
+       int error, committed, forkoff;
 
        /*
         * Remove the attribute.
@@ -1068,9 +1087,9 @@ xfs_attr_leaf_removename(xfs_da_args_t *args)
        /*
         * If the result is small enough, shrink it all into the inode.
         */
-       if (xfs_attr_shortform_allfit(bp, dp)) {
+       if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
                XFS_BMAP_INIT(args->flist, args->firstblock);
-               error = xfs_attr_leaf_to_shortform(bp, args);
+               error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
                /* bp is gone due to xfs_da_shrink_inode */
                if (!error) {
                        error = xfs_bmap_finish(&args->trans, args->flist,
@@ -1102,7 +1121,7 @@ xfs_attr_leaf_removename(xfs_da_args_t *args)
  * This leaf block cannot have a "remote" value, we only call this routine
  * if bmap_one_block() says there is only one block (ie: no remote blks).
  */
-int
+STATIC int
 xfs_attr_leaf_get(xfs_da_args_t *args)
 {
        xfs_dabuf_t *bp;
@@ -1441,7 +1460,7 @@ xfs_attr_node_removename(xfs_da_args_t *args)
        xfs_da_state_blk_t *blk;
        xfs_inode_t *dp;
        xfs_dabuf_t *bp;
-       int retval, error, committed;
+       int retval, error, committed, forkoff;
 
        /*
         * Tie a string around our finger to remind us where we are.
@@ -1562,9 +1581,9 @@ xfs_attr_node_removename(xfs_da_args_t *args)
                                      bp->data)->hdr.info.magic, ARCH_CONVERT)
                                                       == XFS_ATTR_LEAF_MAGIC);
 
-               if (xfs_attr_shortform_allfit(bp, dp)) {
+               if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
                        XFS_BMAP_INIT(args->flist, args->firstblock);
-                       error = xfs_attr_leaf_to_shortform(bp, args);
+                       error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
                        /* bp is gone due to xfs_da_shrink_inode */
                        if (!error) {
                                error = xfs_bmap_finish(&args->trans,
@@ -1707,7 +1726,7 @@ xfs_attr_refillstate(xfs_da_state_t *state)
  * block, ie: both true Btree attr lists and for single-leaf-blocks with
  * "remote" values taking up more blocks.
  */
-int
+STATIC int
 xfs_attr_node_get(xfs_da_args_t *args)
 {
        xfs_da_state_t *state;
@@ -2398,7 +2417,7 @@ posix_acl_default_exists(
        return xfs_acl_vhasacl_default(vp);
 }
 
-struct attrnames posix_acl_access = {
+STATIC struct attrnames posix_acl_access = {
        .attr_name      = "posix_acl_access",
        .attr_namelen   = sizeof("posix_acl_access") - 1,
        .attr_get       = posix_acl_access_get,
@@ -2407,7 +2426,7 @@ struct attrnames posix_acl_access = {
        .attr_exists    = posix_acl_access_exists,
 };
 
-struct attrnames posix_acl_default = {
+STATIC struct attrnames posix_acl_default = {
        .attr_name      = "posix_acl_default",
        .attr_namelen   = sizeof("posix_acl_default") - 1,
        .attr_get       = posix_acl_default_get,
@@ -2416,7 +2435,7 @@ struct attrnames posix_acl_default = {
        .attr_exists    = posix_acl_default_exists,
 };
 
-struct attrnames *attr_system_names[] =
+STATIC struct attrnames *attr_system_names[] =
        { &posix_acl_access, &posix_acl_default };