2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "xfs_types.h"
24 #include "xfs_trans.h"
29 #include "xfs_dmapi.h"
30 #include "xfs_mount.h"
31 #include "xfs_da_btree.h"
32 #include "xfs_bmap_btree.h"
33 #include "xfs_alloc_btree.h"
34 #include "xfs_ialloc_btree.h"
35 #include "xfs_dir_sf.h"
36 #include "xfs_dir2_sf.h"
37 #include "xfs_attr_sf.h"
38 #include "xfs_dinode.h"
39 #include "xfs_inode.h"
40 #include "xfs_alloc.h"
41 #include "xfs_btree.h"
42 #include "xfs_inode_item.h"
45 #include "xfs_attr_leaf.h"
46 #include "xfs_error.h"
47 #include "xfs_quota.h"
48 #include "xfs_trans_space.h"
55 * Provide the external interfaces to manage attribute lists.
58 #define ATTR_SYSCOUNT 2
59 STATIC struct attrnames posix_acl_access;
60 STATIC struct attrnames posix_acl_default;
61 STATIC struct attrnames *attr_system_names[ATTR_SYSCOUNT];
63 /*========================================================================
64 * Function prototypes for the kernel.
65 *========================================================================*/
68 * Internal routines when attribute list fits inside the inode.
70 STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
73 * Internal routines when attribute list is one block.
75 STATIC int xfs_attr_leaf_get(xfs_da_args_t *args);
76 STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args);
77 STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
78 STATIC int xfs_attr_leaf_list(xfs_attr_list_context_t *context);
81 * Internal routines when attribute list is more than one block.
83 STATIC int xfs_attr_node_get(xfs_da_args_t *args);
84 STATIC int xfs_attr_node_addname(xfs_da_args_t *args);
85 STATIC int xfs_attr_node_removename(xfs_da_args_t *args);
86 STATIC int xfs_attr_node_list(xfs_attr_list_context_t *context);
87 STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
88 STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
91 * Routines to manipulate out-of-line attribute values.
93 STATIC int xfs_attr_rmtval_get(xfs_da_args_t *args);
94 STATIC int xfs_attr_rmtval_set(xfs_da_args_t *args);
95 STATIC int xfs_attr_rmtval_remove(xfs_da_args_t *args);
97 #define ATTR_RMTVALUE_MAPSIZE 1 /* # of map entries at once */
99 #if defined(XFS_ATTR_TRACE)
100 ktrace_t *xfs_attr_trace_buf;
104 /*========================================================================
105 * Overall external interface routines.
106 *========================================================================*/
109 xfs_attr_fetch(xfs_inode_t *ip, const char *name, int namelen,
110 char *value, int *valuelenp, int flags, struct cred *cred)
115 if ((XFS_IFORK_Q(ip) == 0) ||
116 (ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
117 ip->i_d.di_anextents == 0))
120 if (!(flags & (ATTR_KERNACCESS|ATTR_SECURE))) {
121 if ((error = xfs_iaccess(ip, S_IRUSR, cred)))
122 return(XFS_ERROR(error));
126 * Fill in the arg structure for this request.
128 memset((char *)&args, 0, sizeof(args));
130 args.namelen = namelen;
132 args.valuelen = *valuelenp;
134 args.hashval = xfs_da_hashname(args.name, args.namelen);
136 args.whichfork = XFS_ATTR_FORK;
139 * Decide on what work routines to call based on the inode size.
141 if (XFS_IFORK_Q(ip) == 0 ||
142 (ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
143 ip->i_d.di_anextents == 0)) {
144 error = XFS_ERROR(ENOATTR);
145 } else if (ip->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
146 error = xfs_attr_shortform_getvalue(&args);
147 } else if (xfs_bmap_one_block(ip, XFS_ATTR_FORK)) {
148 error = xfs_attr_leaf_get(&args);
150 error = xfs_attr_node_get(&args);
154 * Return the number of bytes in the value to the caller.
156 *valuelenp = args.valuelen;
164 xfs_attr_get(bhv_desc_t *bdp, const char *name, char *value, int *valuelenp,
165 int flags, struct cred *cred)
167 xfs_inode_t *ip = XFS_BHVTOI(bdp);
170 XFS_STATS_INC(xs_attr_get);
174 namelen = strlen(name);
175 if (namelen >= MAXNAMELEN)
176 return(EFAULT); /* match IRIX behaviour */
178 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
181 xfs_ilock(ip, XFS_ILOCK_SHARED);
182 error = xfs_attr_fetch(ip, name, namelen, value, valuelenp, flags, cred);
183 xfs_iunlock(ip, XFS_ILOCK_SHARED);
188 xfs_attr_set_int(xfs_inode_t *dp, const char *name, int namelen,
189 char *value, int valuelen, int flags)
192 xfs_fsblock_t firstblock;
193 xfs_bmap_free_t flist;
194 int error, err2, committed;
197 xfs_mount_t *mp = dp->i_mount;
198 int rsvd = (flags & ATTR_ROOT) != 0;
201 * Attach the dquots to the inode.
203 if ((error = XFS_QM_DQATTACH(mp, dp, 0)))
207 * Determine space new attribute will use, and if it would be
208 * "local" or "remote" (note: local != inline).
210 size = xfs_attr_leaf_newentsize(namelen, valuelen,
211 mp->m_sb.sb_blocksize, &local);
214 * If the inode doesn't have an attribute fork, add one.
215 * (inode must not be locked when we call this routine)
217 if (XFS_IFORK_Q(dp) == 0) {
218 if ((error = xfs_bmap_add_attrfork(dp, size, rsvd)))
223 * Fill in the arg structure for this request.
225 memset((char *)&args, 0, sizeof(args));
227 args.namelen = namelen;
229 args.valuelen = valuelen;
231 args.hashval = xfs_da_hashname(args.name, args.namelen);
233 args.firstblock = &firstblock;
235 args.whichfork = XFS_ATTR_FORK;
239 nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK);
241 if (size > (mp->m_sb.sb_blocksize >> 1)) {
242 /* Double split possible */
246 uint dblocks = XFS_B_TO_FSB(mp, valuelen);
247 /* Out of line attribute, cannot double split, but make
248 * room for the attribute value itself.
251 nblks += XFS_NEXTENTADD_SPACE_RES(mp, dblocks, XFS_ATTR_FORK);
254 /* Size is now blocks for attribute data */
258 * Start our first transaction of the day.
260 * All future transactions during this code must be "chained" off
261 * this one via the trans_dup() call. All transactions will contain
262 * the inode, and the inode will always be marked with trans_ihold().
263 * Since the inode will be locked in all transactions, we must log
264 * the inode in every transaction to let it float upward through
267 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_SET);
270 * Root fork attributes can use reserved data blocks for this
271 * operation if necessary
275 args.trans->t_flags |= XFS_TRANS_RESERVE;
277 if ((error = xfs_trans_reserve(args.trans, (uint) nblks,
278 XFS_ATTRSET_LOG_RES(mp, nblks),
279 0, XFS_TRANS_PERM_LOG_RES,
280 XFS_ATTRSET_LOG_COUNT))) {
281 xfs_trans_cancel(args.trans, 0);
284 xfs_ilock(dp, XFS_ILOCK_EXCL);
286 error = XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, args.trans, dp, nblks, 0,
287 rsvd ? XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES :
288 XFS_QMOPT_RES_REGBLKS);
290 xfs_iunlock(dp, XFS_ILOCK_EXCL);
291 xfs_trans_cancel(args.trans, XFS_TRANS_RELEASE_LOG_RES);
295 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
296 xfs_trans_ihold(args.trans, dp);
299 * If the attribute list is non-existant or a shortform list,
300 * upgrade it to a single-leaf-block attribute list.
302 if ((dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
303 ((dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS) &&
304 (dp->i_d.di_anextents == 0))) {
307 * Build initial attribute list (if required).
309 if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
310 xfs_attr_shortform_create(&args);
313 * Try to add the attr to the attribute list in
316 error = xfs_attr_shortform_addname(&args);
317 if (error != ENOSPC) {
319 * Commit the shortform mods, and we're done.
320 * NOTE: this is also the error path (EEXIST, etc).
322 ASSERT(args.trans != NULL);
325 * If this is a synchronous mount, make sure that
326 * the transaction goes to disk before returning
329 if (mp->m_flags & XFS_MOUNT_WSYNC) {
330 xfs_trans_set_sync(args.trans);
332 err2 = xfs_trans_commit(args.trans,
333 XFS_TRANS_RELEASE_LOG_RES,
335 xfs_iunlock(dp, XFS_ILOCK_EXCL);
338 * Hit the inode change time.
340 if (!error && (flags & ATTR_KERNOTIME) == 0) {
341 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
343 return(error == 0 ? err2 : error);
347 * It won't fit in the shortform, transform to a leaf block.
348 * GROT: another possible req'mt for a double-split btree op.
350 XFS_BMAP_INIT(args.flist, args.firstblock);
351 error = xfs_attr_shortform_to_leaf(&args);
353 error = xfs_bmap_finish(&args.trans, args.flist,
354 *args.firstblock, &committed);
359 xfs_bmap_cancel(&flist);
364 * bmap_finish() may have committed the last trans and started
365 * a new one. We need the inode to be in all transactions.
368 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
369 xfs_trans_ihold(args.trans, dp);
373 * Commit the leaf transformation. We'll need another (linked)
374 * transaction to add the new attribute to the leaf.
376 if ((error = xfs_attr_rolltrans(&args.trans, dp)))
381 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
382 error = xfs_attr_leaf_addname(&args);
384 error = xfs_attr_node_addname(&args);
391 * If this is a synchronous mount, make sure that the
392 * transaction goes to disk before returning to the user.
394 if (mp->m_flags & XFS_MOUNT_WSYNC) {
395 xfs_trans_set_sync(args.trans);
399 * Commit the last in the sequence of transactions.
401 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
402 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES,
404 xfs_iunlock(dp, XFS_ILOCK_EXCL);
407 * Hit the inode change time.
409 if (!error && (flags & ATTR_KERNOTIME) == 0) {
410 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
417 xfs_trans_cancel(args.trans,
418 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
419 xfs_iunlock(dp, XFS_ILOCK_EXCL);
424 xfs_attr_set(bhv_desc_t *bdp, const char *name, char *value, int valuelen, int flags,
430 namelen = strlen(name);
431 if (namelen >= MAXNAMELEN)
432 return EFAULT; /* match IRIX behaviour */
434 XFS_STATS_INC(xs_attr_set);
436 dp = XFS_BHVTOI(bdp);
437 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
440 xfs_ilock(dp, XFS_ILOCK_SHARED);
441 if (!(flags & ATTR_SECURE) &&
442 (error = xfs_iaccess(dp, S_IWUSR, cred))) {
443 xfs_iunlock(dp, XFS_ILOCK_SHARED);
444 return(XFS_ERROR(error));
446 xfs_iunlock(dp, XFS_ILOCK_SHARED);
448 return xfs_attr_set_int(dp, name, namelen, value, valuelen, flags);
452 * Generic handler routine to remove a name from an attribute list.
453 * Transitions attribute list from Btree to shortform as necessary.
456 xfs_attr_remove_int(xfs_inode_t *dp, const char *name, int namelen, int flags)
459 xfs_fsblock_t firstblock;
460 xfs_bmap_free_t flist;
462 xfs_mount_t *mp = dp->i_mount;
465 * Fill in the arg structure for this request.
467 memset((char *)&args, 0, sizeof(args));
469 args.namelen = namelen;
471 args.hashval = xfs_da_hashname(args.name, args.namelen);
473 args.firstblock = &firstblock;
476 args.whichfork = XFS_ATTR_FORK;
479 * Attach the dquots to the inode.
481 if ((error = XFS_QM_DQATTACH(mp, dp, 0)))
485 * Start our first transaction of the day.
487 * All future transactions during this code must be "chained" off
488 * this one via the trans_dup() call. All transactions will contain
489 * the inode, and the inode will always be marked with trans_ihold().
490 * Since the inode will be locked in all transactions, we must log
491 * the inode in every transaction to let it float upward through
494 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_RM);
497 * Root fork attributes can use reserved data blocks for this
498 * operation if necessary
501 if (flags & ATTR_ROOT)
502 args.trans->t_flags |= XFS_TRANS_RESERVE;
504 if ((error = xfs_trans_reserve(args.trans,
505 XFS_ATTRRM_SPACE_RES(mp),
506 XFS_ATTRRM_LOG_RES(mp),
507 0, XFS_TRANS_PERM_LOG_RES,
508 XFS_ATTRRM_LOG_COUNT))) {
509 xfs_trans_cancel(args.trans, 0);
513 xfs_ilock(dp, XFS_ILOCK_EXCL);
515 * No need to make quota reservations here. We expect to release some
516 * blocks not allocate in the common case.
518 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
519 xfs_trans_ihold(args.trans, dp);
522 * Decide on what work routines to call based on the inode size.
524 if (XFS_IFORK_Q(dp) == 0 ||
525 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
526 dp->i_d.di_anextents == 0)) {
527 error = XFS_ERROR(ENOATTR);
530 if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
531 ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
532 error = xfs_attr_shortform_remove(&args);
536 } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
537 error = xfs_attr_leaf_removename(&args);
539 error = xfs_attr_node_removename(&args);
546 * If this is a synchronous mount, make sure that the
547 * transaction goes to disk before returning to the user.
549 if (mp->m_flags & XFS_MOUNT_WSYNC) {
550 xfs_trans_set_sync(args.trans);
554 * Commit the last in the sequence of transactions.
556 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
557 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES,
559 xfs_iunlock(dp, XFS_ILOCK_EXCL);
562 * Hit the inode change time.
564 if (!error && (flags & ATTR_KERNOTIME) == 0) {
565 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
572 xfs_trans_cancel(args.trans,
573 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
574 xfs_iunlock(dp, XFS_ILOCK_EXCL);
579 xfs_attr_remove(bhv_desc_t *bdp, const char *name, int flags, struct cred *cred)
584 namelen = strlen(name);
585 if (namelen >= MAXNAMELEN)
586 return EFAULT; /* match IRIX behaviour */
588 XFS_STATS_INC(xs_attr_remove);
590 dp = XFS_BHVTOI(bdp);
591 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
594 xfs_ilock(dp, XFS_ILOCK_SHARED);
595 if (!(flags & ATTR_SECURE) &&
596 (error = xfs_iaccess(dp, S_IWUSR, cred))) {
597 xfs_iunlock(dp, XFS_ILOCK_SHARED);
598 return(XFS_ERROR(error));
599 } else if (XFS_IFORK_Q(dp) == 0 ||
600 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
601 dp->i_d.di_anextents == 0)) {
602 xfs_iunlock(dp, XFS_ILOCK_SHARED);
603 return(XFS_ERROR(ENOATTR));
605 xfs_iunlock(dp, XFS_ILOCK_SHARED);
607 return xfs_attr_remove_int(dp, name, namelen, flags);
611 * Generate a list of extended attribute names and optionally
612 * also value lengths. Positive return value follows the XFS
613 * convention of being an error, zero or negative return code
614 * is the length of the buffer returned (negated), indicating
618 xfs_attr_list(bhv_desc_t *bdp, char *buffer, int bufsize, int flags,
619 attrlist_cursor_kern_t *cursor, struct cred *cred)
621 xfs_attr_list_context_t context;
625 XFS_STATS_INC(xs_attr_list);
628 * Validate the cursor.
630 if (cursor->pad1 || cursor->pad2)
631 return(XFS_ERROR(EINVAL));
632 if ((cursor->initted == 0) &&
633 (cursor->hashval || cursor->blkno || cursor->offset))
634 return(XFS_ERROR(EINVAL));
637 * Check for a properly aligned buffer.
639 if (((long)buffer) & (sizeof(int)-1))
640 return(XFS_ERROR(EFAULT));
641 if (flags & ATTR_KERNOVAL)
645 * Initialize the output buffer.
647 context.dp = dp = XFS_BHVTOI(bdp);
648 context.cursor = cursor;
652 context.flags = flags;
653 if (!(flags & ATTR_KERNAMELS)) {
654 context.bufsize = (bufsize & ~(sizeof(int)-1)); /* align */
655 context.firstu = context.bufsize;
656 context.alist = (attrlist_t *)buffer;
657 context.alist->al_count = 0;
658 context.alist->al_more = 0;
659 context.alist->al_offset[0] = context.bufsize;
662 context.bufsize = bufsize;
663 context.firstu = context.bufsize;
664 context.alist = (attrlist_t *)buffer;
667 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
670 xfs_ilock(dp, XFS_ILOCK_SHARED);
671 if (!(flags & ATTR_SECURE) &&
672 (error = xfs_iaccess(dp, S_IRUSR, cred))) {
673 xfs_iunlock(dp, XFS_ILOCK_SHARED);
674 return(XFS_ERROR(error));
678 * Decide on what work routines to call based on the inode size.
680 xfs_attr_trace_l_c("syscall start", &context);
681 if (XFS_IFORK_Q(dp) == 0 ||
682 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
683 dp->i_d.di_anextents == 0)) {
685 } else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
686 error = xfs_attr_shortform_list(&context);
687 } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
688 error = xfs_attr_leaf_list(&context);
690 error = xfs_attr_node_list(&context);
692 xfs_iunlock(dp, XFS_ILOCK_SHARED);
693 xfs_attr_trace_l_c("syscall end", &context);
695 if (!(context.flags & (ATTR_KERNOVAL|ATTR_KERNAMELS))) {
698 else { /* must return negated buffer size or the error */
699 if (context.count < 0)
700 error = XFS_ERROR(ERANGE);
702 error = -context.count;
709 xfs_attr_inactive(xfs_inode_t *dp)
716 ASSERT(! XFS_NOT_DQATTACHED(mp, dp));
718 xfs_ilock(dp, XFS_ILOCK_SHARED);
719 if ((XFS_IFORK_Q(dp) == 0) ||
720 (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
721 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
722 dp->i_d.di_anextents == 0)) {
723 xfs_iunlock(dp, XFS_ILOCK_SHARED);
726 xfs_iunlock(dp, XFS_ILOCK_SHARED);
729 * Start our first transaction of the day.
731 * All future transactions during this code must be "chained" off
732 * this one via the trans_dup() call. All transactions will contain
733 * the inode, and the inode will always be marked with trans_ihold().
734 * Since the inode will be locked in all transactions, we must log
735 * the inode in every transaction to let it float upward through
738 trans = xfs_trans_alloc(mp, XFS_TRANS_ATTRINVAL);
739 if ((error = xfs_trans_reserve(trans, 0, XFS_ATTRINVAL_LOG_RES(mp), 0,
740 XFS_TRANS_PERM_LOG_RES,
741 XFS_ATTRINVAL_LOG_COUNT))) {
742 xfs_trans_cancel(trans, 0);
745 xfs_ilock(dp, XFS_ILOCK_EXCL);
748 * No need to make quota reservations here. We expect to release some
749 * blocks, not allocate, in the common case.
751 xfs_trans_ijoin(trans, dp, XFS_ILOCK_EXCL);
752 xfs_trans_ihold(trans, dp);
755 * Decide on what work routines to call based on the inode size.
757 if ((XFS_IFORK_Q(dp) == 0) ||
758 (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
759 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
760 dp->i_d.di_anextents == 0)) {
764 error = xfs_attr_root_inactive(&trans, dp);
768 * signal synchronous inactive transactions unless this
769 * is a synchronous mount filesystem in which case we
770 * know that we're here because we've been called out of
771 * xfs_inactive which means that the last reference is gone
772 * and the unlink transaction has already hit the disk so
773 * async inactive transactions are safe.
775 if ((error = xfs_itruncate_finish(&trans, dp, 0LL, XFS_ATTR_FORK,
776 (!(mp->m_flags & XFS_MOUNT_WSYNC)
781 * Commit the last in the sequence of transactions.
783 xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE);
784 error = xfs_trans_commit(trans, XFS_TRANS_RELEASE_LOG_RES,
786 xfs_iunlock(dp, XFS_ILOCK_EXCL);
791 xfs_trans_cancel(trans, XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
792 xfs_iunlock(dp, XFS_ILOCK_EXCL);
798 /*========================================================================
799 * External routines when attribute list is inside the inode
800 *========================================================================*/
803 * Add a name to the shortform attribute list structure
804 * This is the external routine.
807 xfs_attr_shortform_addname(xfs_da_args_t *args)
809 int newsize, forkoff, retval;
811 retval = xfs_attr_shortform_lookup(args);
812 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
814 } else if (retval == EEXIST) {
815 if (args->flags & ATTR_CREATE)
817 retval = xfs_attr_shortform_remove(args);
821 if (args->namelen >= XFS_ATTR_SF_ENTSIZE_MAX ||
822 args->valuelen >= XFS_ATTR_SF_ENTSIZE_MAX)
823 return(XFS_ERROR(ENOSPC));
825 newsize = XFS_ATTR_SF_TOTSIZE(args->dp);
826 newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen);
828 forkoff = xfs_attr_shortform_bytesfit(args->dp, newsize);
830 return(XFS_ERROR(ENOSPC));
832 xfs_attr_shortform_add(args, forkoff);
837 /*========================================================================
838 * External routines when attribute list is one block
839 *========================================================================*/
842 * Add a name to the leaf attribute list structure
844 * This leaf block cannot have a "remote" value, we only call this routine
845 * if bmap_one_block() says there is only one block (ie: no remote blks).
848 xfs_attr_leaf_addname(xfs_da_args_t *args)
852 int retval, error, committed, forkoff;
855 * Read the (only) block in the attribute list in.
859 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
866 * Look up the given attribute in the leaf block. Figure out if
867 * the given flags produce an error or call for an atomic rename.
869 retval = xfs_attr_leaf_lookup_int(bp, args);
870 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
871 xfs_da_brelse(args->trans, bp);
873 } else if (retval == EEXIST) {
874 if (args->flags & ATTR_CREATE) { /* pure create op */
875 xfs_da_brelse(args->trans, bp);
878 args->rename = 1; /* an atomic rename */
879 args->blkno2 = args->blkno; /* set 2nd entry info*/
880 args->index2 = args->index;
881 args->rmtblkno2 = args->rmtblkno;
882 args->rmtblkcnt2 = args->rmtblkcnt;
886 * Add the attribute to the leaf block, transitioning to a Btree
889 retval = xfs_attr_leaf_add(bp, args);
891 if (retval == ENOSPC) {
893 * Promote the attribute list to the Btree format, then
894 * Commit that transaction so that the node_addname() call
895 * can manage its own transactions.
897 XFS_BMAP_INIT(args->flist, args->firstblock);
898 error = xfs_attr_leaf_to_node(args);
900 error = xfs_bmap_finish(&args->trans, args->flist,
901 *args->firstblock, &committed);
906 xfs_bmap_cancel(args->flist);
911 * bmap_finish() may have committed the last trans and started
912 * a new one. We need the inode to be in all transactions.
915 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
916 xfs_trans_ihold(args->trans, dp);
920 * Commit the current trans (including the inode) and start
923 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
927 * Fob the whole rest of the problem off on the Btree code.
929 error = xfs_attr_node_addname(args);
934 * Commit the transaction that added the attr name so that
935 * later routines can manage their own transactions.
937 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
941 * If there was an out-of-line value, allocate the blocks we
942 * identified for its storage and copy the value. This is done
943 * after we create the attribute so that we don't overflow the
944 * maximum size of a transaction and/or hit a deadlock.
946 if (args->rmtblkno > 0) {
947 error = xfs_attr_rmtval_set(args);
953 * If this is an atomic rename operation, we must "flip" the
954 * incomplete flags on the "new" and "old" attribute/value pairs
955 * so that one disappears and one appears atomically. Then we
956 * must remove the "old" attribute/value pair.
960 * In a separate transaction, set the incomplete flag on the
961 * "old" attr and clear the incomplete flag on the "new" attr.
963 error = xfs_attr_leaf_flipflags(args);
968 * Dismantle the "old" attribute/value pair by removing
969 * a "remote" value (if it exists).
971 args->index = args->index2;
972 args->blkno = args->blkno2;
973 args->rmtblkno = args->rmtblkno2;
974 args->rmtblkcnt = args->rmtblkcnt2;
975 if (args->rmtblkno) {
976 error = xfs_attr_rmtval_remove(args);
982 * Read in the block containing the "old" attr, then
983 * remove the "old" attr from that block (neat, huh!)
985 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1,
990 (void)xfs_attr_leaf_remove(bp, args);
993 * If the result is small enough, shrink it all into the inode.
995 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
996 XFS_BMAP_INIT(args->flist, args->firstblock);
997 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
998 /* bp is gone due to xfs_da_shrink_inode */
1000 error = xfs_bmap_finish(&args->trans,
1008 xfs_bmap_cancel(args->flist);
1013 * bmap_finish() may have committed the last trans
1014 * and started a new one. We need the inode to be
1015 * in all transactions.
1018 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1019 xfs_trans_ihold(args->trans, dp);
1022 xfs_da_buf_done(bp);
1025 * Commit the remove and start the next trans in series.
1027 error = xfs_attr_rolltrans(&args->trans, dp);
1029 } else if (args->rmtblkno > 0) {
1031 * Added a "remote" value, just clear the incomplete flag.
1033 error = xfs_attr_leaf_clearflag(args);
1039 * Remove a name from the leaf attribute list structure
1041 * This leaf block cannot have a "remote" value, we only call this routine
1042 * if bmap_one_block() says there is only one block (ie: no remote blks).
1045 xfs_attr_leaf_removename(xfs_da_args_t *args)
1049 int error, committed, forkoff;
1052 * Remove the attribute.
1056 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1063 error = xfs_attr_leaf_lookup_int(bp, args);
1064 if (error == ENOATTR) {
1065 xfs_da_brelse(args->trans, bp);
1069 (void)xfs_attr_leaf_remove(bp, args);
1072 * If the result is small enough, shrink it all into the inode.
1074 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1075 XFS_BMAP_INIT(args->flist, args->firstblock);
1076 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1077 /* bp is gone due to xfs_da_shrink_inode */
1079 error = xfs_bmap_finish(&args->trans, args->flist,
1080 *args->firstblock, &committed);
1085 xfs_bmap_cancel(args->flist);
1090 * bmap_finish() may have committed the last trans and started
1091 * a new one. We need the inode to be in all transactions.
1094 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1095 xfs_trans_ihold(args->trans, dp);
1098 xfs_da_buf_done(bp);
1103 * Look up a name in a leaf attribute list structure.
1105 * This leaf block cannot have a "remote" value, we only call this routine
1106 * if bmap_one_block() says there is only one block (ie: no remote blks).
1109 xfs_attr_leaf_get(xfs_da_args_t *args)
1115 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1121 error = xfs_attr_leaf_lookup_int(bp, args);
1122 if (error != EEXIST) {
1123 xfs_da_brelse(args->trans, bp);
1126 error = xfs_attr_leaf_getvalue(bp, args);
1127 xfs_da_brelse(args->trans, bp);
1128 if (!error && (args->rmtblkno > 0) && !(args->flags & ATTR_KERNOVAL)) {
1129 error = xfs_attr_rmtval_get(args);
1135 * Copy out attribute entries for attr_list(), for leaf attribute lists.
1138 xfs_attr_leaf_list(xfs_attr_list_context_t *context)
1140 xfs_attr_leafblock_t *leaf;
1144 context->cursor->blkno = 0;
1145 error = xfs_da_read_buf(NULL, context->dp, 0, -1, &bp, XFS_ATTR_FORK);
1150 if (unlikely(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
1151 != XFS_ATTR_LEAF_MAGIC)) {
1152 XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW,
1153 context->dp->i_mount, leaf);
1154 xfs_da_brelse(NULL, bp);
1155 return(XFS_ERROR(EFSCORRUPTED));
1158 (void)xfs_attr_leaf_list_int(bp, context);
1159 xfs_da_brelse(NULL, bp);
1164 /*========================================================================
1165 * External routines when attribute list size > XFS_LBSIZE(mp).
1166 *========================================================================*/
1169 * Add a name to a Btree-format attribute list.
1171 * This will involve walking down the Btree, and may involve splitting
1172 * leaf nodes and even splitting intermediate nodes up to and including
1173 * the root node (a special case of an intermediate node).
1175 * "Remote" attribute values confuse the issue and atomic rename operations
1176 * add a whole extra layer of confusion on top of that.
1179 xfs_attr_node_addname(xfs_da_args_t *args)
1181 xfs_da_state_t *state;
1182 xfs_da_state_blk_t *blk;
1185 int committed, retval, error;
1188 * Fill in bucket of arguments/results/context to carry around.
1193 state = xfs_da_state_alloc();
1196 state->blocksize = state->mp->m_sb.sb_blocksize;
1197 state->node_ents = state->mp->m_attr_node_ents;
1200 * Search to see if name already exists, and get back a pointer
1201 * to where it should go.
1203 error = xfs_da_node_lookup_int(state, &retval);
1206 blk = &state->path.blk[ state->path.active-1 ];
1207 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1208 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
1210 } else if (retval == EEXIST) {
1211 if (args->flags & ATTR_CREATE)
1213 args->rename = 1; /* atomic rename op */
1214 args->blkno2 = args->blkno; /* set 2nd entry info*/
1215 args->index2 = args->index;
1216 args->rmtblkno2 = args->rmtblkno;
1217 args->rmtblkcnt2 = args->rmtblkcnt;
1219 args->rmtblkcnt = 0;
1222 retval = xfs_attr_leaf_add(blk->bp, state->args);
1223 if (retval == ENOSPC) {
1224 if (state->path.active == 1) {
1226 * Its really a single leaf node, but it had
1227 * out-of-line values so it looked like it *might*
1228 * have been a b-tree.
1230 xfs_da_state_free(state);
1231 XFS_BMAP_INIT(args->flist, args->firstblock);
1232 error = xfs_attr_leaf_to_node(args);
1234 error = xfs_bmap_finish(&args->trans,
1242 xfs_bmap_cancel(args->flist);
1247 * bmap_finish() may have committed the last trans
1248 * and started a new one. We need the inode to be
1249 * in all transactions.
1252 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1253 xfs_trans_ihold(args->trans, dp);
1257 * Commit the node conversion and start the next
1258 * trans in the chain.
1260 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1267 * Split as many Btree elements as required.
1268 * This code tracks the new and old attr's location
1269 * in the index/blkno/rmtblkno/rmtblkcnt fields and
1270 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
1272 XFS_BMAP_INIT(args->flist, args->firstblock);
1273 error = xfs_da_split(state);
1275 error = xfs_bmap_finish(&args->trans, args->flist,
1276 *args->firstblock, &committed);
1281 xfs_bmap_cancel(args->flist);
1286 * bmap_finish() may have committed the last trans and started
1287 * a new one. We need the inode to be in all transactions.
1290 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1291 xfs_trans_ihold(args->trans, dp);
1295 * Addition succeeded, update Btree hashvals.
1297 xfs_da_fixhashpath(state, &state->path);
1301 * Kill the state structure, we're done with it and need to
1302 * allow the buffers to come back later.
1304 xfs_da_state_free(state);
1308 * Commit the leaf addition or btree split and start the next
1309 * trans in the chain.
1311 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1315 * If there was an out-of-line value, allocate the blocks we
1316 * identified for its storage and copy the value. This is done
1317 * after we create the attribute so that we don't overflow the
1318 * maximum size of a transaction and/or hit a deadlock.
1320 if (args->rmtblkno > 0) {
1321 error = xfs_attr_rmtval_set(args);
1327 * If this is an atomic rename operation, we must "flip" the
1328 * incomplete flags on the "new" and "old" attribute/value pairs
1329 * so that one disappears and one appears atomically. Then we
1330 * must remove the "old" attribute/value pair.
1334 * In a separate transaction, set the incomplete flag on the
1335 * "old" attr and clear the incomplete flag on the "new" attr.
1337 error = xfs_attr_leaf_flipflags(args);
1342 * Dismantle the "old" attribute/value pair by removing
1343 * a "remote" value (if it exists).
1345 args->index = args->index2;
1346 args->blkno = args->blkno2;
1347 args->rmtblkno = args->rmtblkno2;
1348 args->rmtblkcnt = args->rmtblkcnt2;
1349 if (args->rmtblkno) {
1350 error = xfs_attr_rmtval_remove(args);
1356 * Re-find the "old" attribute entry after any split ops.
1357 * The INCOMPLETE flag means that we will find the "old"
1358 * attr, not the "new" one.
1360 args->flags |= XFS_ATTR_INCOMPLETE;
1361 state = xfs_da_state_alloc();
1364 state->blocksize = state->mp->m_sb.sb_blocksize;
1365 state->node_ents = state->mp->m_attr_node_ents;
1367 error = xfs_da_node_lookup_int(state, &retval);
1372 * Remove the name and update the hashvals in the tree.
1374 blk = &state->path.blk[ state->path.active-1 ];
1375 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1376 error = xfs_attr_leaf_remove(blk->bp, args);
1377 xfs_da_fixhashpath(state, &state->path);
1380 * Check to see if the tree needs to be collapsed.
1382 if (retval && (state->path.active > 1)) {
1383 XFS_BMAP_INIT(args->flist, args->firstblock);
1384 error = xfs_da_join(state);
1386 error = xfs_bmap_finish(&args->trans,
1394 xfs_bmap_cancel(args->flist);
1399 * bmap_finish() may have committed the last trans
1400 * and started a new one. We need the inode to be
1401 * in all transactions.
1404 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1405 xfs_trans_ihold(args->trans, dp);
1410 * Commit and start the next trans in the chain.
1412 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1415 } else if (args->rmtblkno > 0) {
1417 * Added a "remote" value, just clear the incomplete flag.
1419 error = xfs_attr_leaf_clearflag(args);
1427 xfs_da_state_free(state);
1434 * Remove a name from a B-tree attribute list.
1436 * This will involve walking down the Btree, and may involve joining
1437 * leaf nodes and even joining intermediate nodes up to and including
1438 * the root node (a special case of an intermediate node).
1441 xfs_attr_node_removename(xfs_da_args_t *args)
1443 xfs_da_state_t *state;
1444 xfs_da_state_blk_t *blk;
1447 int retval, error, committed, forkoff;
1450 * Tie a string around our finger to remind us where we are.
1453 state = xfs_da_state_alloc();
1455 state->mp = dp->i_mount;
1456 state->blocksize = state->mp->m_sb.sb_blocksize;
1457 state->node_ents = state->mp->m_attr_node_ents;
1460 * Search to see if name exists, and get back a pointer to it.
1462 error = xfs_da_node_lookup_int(state, &retval);
1463 if (error || (retval != EEXIST)) {
1470 * If there is an out-of-line value, de-allocate the blocks.
1471 * This is done before we remove the attribute so that we don't
1472 * overflow the maximum size of a transaction and/or hit a deadlock.
1474 blk = &state->path.blk[ state->path.active-1 ];
1475 ASSERT(blk->bp != NULL);
1476 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1477 if (args->rmtblkno > 0) {
1479 * Fill in disk block numbers in the state structure
1480 * so that we can get the buffers back after we commit
1481 * several transactions in the following calls.
1483 error = xfs_attr_fillstate(state);
1488 * Mark the attribute as INCOMPLETE, then bunmapi() the
1491 error = xfs_attr_leaf_setflag(args);
1494 error = xfs_attr_rmtval_remove(args);
1499 * Refill the state structure with buffers, the prior calls
1500 * released our buffers.
1502 error = xfs_attr_refillstate(state);
1508 * Remove the name and update the hashvals in the tree.
1510 blk = &state->path.blk[ state->path.active-1 ];
1511 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1512 retval = xfs_attr_leaf_remove(blk->bp, args);
1513 xfs_da_fixhashpath(state, &state->path);
1516 * Check to see if the tree needs to be collapsed.
1518 if (retval && (state->path.active > 1)) {
1519 XFS_BMAP_INIT(args->flist, args->firstblock);
1520 error = xfs_da_join(state);
1522 error = xfs_bmap_finish(&args->trans, args->flist,
1523 *args->firstblock, &committed);
1528 xfs_bmap_cancel(args->flist);
1533 * bmap_finish() may have committed the last trans and started
1534 * a new one. We need the inode to be in all transactions.
1537 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1538 xfs_trans_ihold(args->trans, dp);
1542 * Commit the Btree join operation and start a new trans.
1544 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1549 * If the result is small enough, push it all into the inode.
1551 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
1553 * Have to get rid of the copy of this dabuf in the state.
1555 ASSERT(state->path.active == 1);
1556 ASSERT(state->path.blk[0].bp);
1557 xfs_da_buf_done(state->path.blk[0].bp);
1558 state->path.blk[0].bp = NULL;
1560 error = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp,
1564 ASSERT(INT_GET(((xfs_attr_leafblock_t *)
1565 bp->data)->hdr.info.magic, ARCH_CONVERT)
1566 == XFS_ATTR_LEAF_MAGIC);
1568 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1569 XFS_BMAP_INIT(args->flist, args->firstblock);
1570 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1571 /* bp is gone due to xfs_da_shrink_inode */
1573 error = xfs_bmap_finish(&args->trans,
1581 xfs_bmap_cancel(args->flist);
1586 * bmap_finish() may have committed the last trans
1587 * and started a new one. We need the inode to be
1588 * in all transactions.
1591 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1592 xfs_trans_ihold(args->trans, dp);
1595 xfs_da_brelse(args->trans, bp);
1600 xfs_da_state_free(state);
1605 * Fill in the disk block numbers in the state structure for the buffers
1606 * that are attached to the state structure.
1607 * This is done so that we can quickly reattach ourselves to those buffers
1608 * after some set of transaction commit's has released these buffers.
1611 xfs_attr_fillstate(xfs_da_state_t *state)
1613 xfs_da_state_path_t *path;
1614 xfs_da_state_blk_t *blk;
1618 * Roll down the "path" in the state structure, storing the on-disk
1619 * block number for those buffers in the "path".
1621 path = &state->path;
1622 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1623 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1625 blk->disk_blkno = xfs_da_blkno(blk->bp);
1626 xfs_da_buf_done(blk->bp);
1629 blk->disk_blkno = 0;
1634 * Roll down the "altpath" in the state structure, storing the on-disk
1635 * block number for those buffers in the "altpath".
1637 path = &state->altpath;
1638 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1639 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1641 blk->disk_blkno = xfs_da_blkno(blk->bp);
1642 xfs_da_buf_done(blk->bp);
1645 blk->disk_blkno = 0;
1653 * Reattach the buffers to the state structure based on the disk block
1654 * numbers stored in the state structure.
1655 * This is done after some set of transaction commit's has released those
1656 * buffers from our grip.
1659 xfs_attr_refillstate(xfs_da_state_t *state)
1661 xfs_da_state_path_t *path;
1662 xfs_da_state_blk_t *blk;
1666 * Roll down the "path" in the state structure, storing the on-disk
1667 * block number for those buffers in the "path".
1669 path = &state->path;
1670 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1671 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1672 if (blk->disk_blkno) {
1673 error = xfs_da_read_buf(state->args->trans,
1675 blk->blkno, blk->disk_blkno,
1676 &blk->bp, XFS_ATTR_FORK);
1685 * Roll down the "altpath" in the state structure, storing the on-disk
1686 * block number for those buffers in the "altpath".
1688 path = &state->altpath;
1689 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1690 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1691 if (blk->disk_blkno) {
1692 error = xfs_da_read_buf(state->args->trans,
1694 blk->blkno, blk->disk_blkno,
1695 &blk->bp, XFS_ATTR_FORK);
1707 * Look up a filename in a node attribute list.
1709 * This routine gets called for any attribute fork that has more than one
1710 * block, ie: both true Btree attr lists and for single-leaf-blocks with
1711 * "remote" values taking up more blocks.
1714 xfs_attr_node_get(xfs_da_args_t *args)
1716 xfs_da_state_t *state;
1717 xfs_da_state_blk_t *blk;
1721 state = xfs_da_state_alloc();
1723 state->mp = args->dp->i_mount;
1724 state->blocksize = state->mp->m_sb.sb_blocksize;
1725 state->node_ents = state->mp->m_attr_node_ents;
1728 * Search to see if name exists, and get back a pointer to it.
1730 error = xfs_da_node_lookup_int(state, &retval);
1733 } else if (retval == EEXIST) {
1734 blk = &state->path.blk[ state->path.active-1 ];
1735 ASSERT(blk->bp != NULL);
1736 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1739 * Get the value, local or "remote"
1741 retval = xfs_attr_leaf_getvalue(blk->bp, args);
1742 if (!retval && (args->rmtblkno > 0)
1743 && !(args->flags & ATTR_KERNOVAL)) {
1744 retval = xfs_attr_rmtval_get(args);
1749 * If not in a transaction, we have to release all the buffers.
1751 for (i = 0; i < state->path.active; i++) {
1752 xfs_da_brelse(args->trans, state->path.blk[i].bp);
1753 state->path.blk[i].bp = NULL;
1756 xfs_da_state_free(state);
1760 STATIC int /* error */
1761 xfs_attr_node_list(xfs_attr_list_context_t *context)
1763 attrlist_cursor_kern_t *cursor;
1764 xfs_attr_leafblock_t *leaf;
1765 xfs_da_intnode_t *node;
1766 xfs_da_node_entry_t *btree;
1770 cursor = context->cursor;
1771 cursor->initted = 1;
1774 * Do all sorts of validation on the passed-in cursor structure.
1775 * If anything is amiss, ignore the cursor and look up the hashval
1776 * starting from the btree root.
1779 if (cursor->blkno > 0) {
1780 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1781 &bp, XFS_ATTR_FORK);
1782 if ((error != 0) && (error != EFSCORRUPTED))
1786 switch (INT_GET(node->hdr.info.magic, ARCH_CONVERT)) {
1787 case XFS_DA_NODE_MAGIC:
1788 xfs_attr_trace_l_cn("wrong blk", context, node);
1789 xfs_da_brelse(NULL, bp);
1792 case XFS_ATTR_LEAF_MAGIC:
1794 if (cursor->hashval >
1795 INT_GET(leaf->entries[
1796 INT_GET(leaf->hdr.count,
1797 ARCH_CONVERT)-1].hashval,
1799 xfs_attr_trace_l_cl("wrong blk",
1801 xfs_da_brelse(NULL, bp);
1803 } else if (cursor->hashval <=
1804 INT_GET(leaf->entries[0].hashval,
1806 xfs_attr_trace_l_cl("maybe wrong blk",
1808 xfs_da_brelse(NULL, bp);
1813 xfs_attr_trace_l_c("wrong blk - ??", context);
1814 xfs_da_brelse(NULL, bp);
1821 * We did not find what we expected given the cursor's contents,
1822 * so we start from the top and work down based on the hash value.
1823 * Note that start of node block is same as start of leaf block.
1828 error = xfs_da_read_buf(NULL, context->dp,
1829 cursor->blkno, -1, &bp,
1833 if (unlikely(bp == NULL)) {
1834 XFS_ERROR_REPORT("xfs_attr_node_list(2)",
1836 context->dp->i_mount);
1837 return(XFS_ERROR(EFSCORRUPTED));
1840 if (INT_GET(node->hdr.info.magic, ARCH_CONVERT)
1841 == XFS_ATTR_LEAF_MAGIC)
1843 if (unlikely(INT_GET(node->hdr.info.magic, ARCH_CONVERT)
1844 != XFS_DA_NODE_MAGIC)) {
1845 XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
1847 context->dp->i_mount,
1849 xfs_da_brelse(NULL, bp);
1850 return(XFS_ERROR(EFSCORRUPTED));
1852 btree = node->btree;
1854 i < INT_GET(node->hdr.count, ARCH_CONVERT);
1857 <= INT_GET(btree->hashval,
1859 cursor->blkno = INT_GET(btree->before, ARCH_CONVERT);
1860 xfs_attr_trace_l_cb("descending",
1865 if (i == INT_GET(node->hdr.count, ARCH_CONVERT)) {
1866 xfs_da_brelse(NULL, bp);
1869 xfs_da_brelse(NULL, bp);
1875 * Roll upward through the blocks, processing each leaf block in
1876 * order. As long as there is space in the result buffer, keep
1877 * adding the information.
1881 if (unlikely(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
1882 != XFS_ATTR_LEAF_MAGIC)) {
1883 XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
1885 context->dp->i_mount, leaf);
1886 xfs_da_brelse(NULL, bp);
1887 return(XFS_ERROR(EFSCORRUPTED));
1889 error = xfs_attr_leaf_list_int(bp, context);
1890 if (error || !leaf->hdr.info.forw)
1891 break; /* not really an error, buffer full or EOF */
1892 cursor->blkno = INT_GET(leaf->hdr.info.forw, ARCH_CONVERT);
1893 xfs_da_brelse(NULL, bp);
1894 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1895 &bp, XFS_ATTR_FORK);
1898 if (unlikely((bp == NULL))) {
1899 XFS_ERROR_REPORT("xfs_attr_node_list(5)",
1901 context->dp->i_mount);
1902 return(XFS_ERROR(EFSCORRUPTED));
1905 xfs_da_brelse(NULL, bp);
1910 /*========================================================================
1911 * External routines for manipulating out-of-line attribute values.
1912 *========================================================================*/
1915 * Read the value associated with an attribute from the out-of-line buffer
1916 * that we stored it in.
1919 xfs_attr_rmtval_get(xfs_da_args_t *args)
1921 xfs_bmbt_irec_t map[ATTR_RMTVALUE_MAPSIZE];
1926 int nmap, error, tmp, valuelen, blkcnt, i;
1929 ASSERT(!(args->flags & ATTR_KERNOVAL));
1931 mp = args->dp->i_mount;
1933 valuelen = args->valuelen;
1934 lblkno = args->rmtblkno;
1935 while (valuelen > 0) {
1936 nmap = ATTR_RMTVALUE_MAPSIZE;
1937 error = xfs_bmapi(args->trans, args->dp, (xfs_fileoff_t)lblkno,
1939 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
1940 NULL, 0, map, &nmap, NULL);
1945 for (i = 0; (i < nmap) && (valuelen > 0); i++) {
1946 ASSERT((map[i].br_startblock != DELAYSTARTBLOCK) &&
1947 (map[i].br_startblock != HOLESTARTBLOCK));
1948 dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
1949 blkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
1950 error = xfs_read_buf(mp, mp->m_ddev_targp, dblkno,
1951 blkcnt, XFS_BUF_LOCK, &bp);
1955 tmp = (valuelen < XFS_BUF_SIZE(bp))
1956 ? valuelen : XFS_BUF_SIZE(bp);
1957 xfs_biomove(bp, 0, tmp, dst, XFS_B_READ);
1962 lblkno += map[i].br_blockcount;
1965 ASSERT(valuelen == 0);
1970 * Write the value associated with an attribute into the out-of-line buffer
1971 * that we have defined for it.
1974 xfs_attr_rmtval_set(xfs_da_args_t *args)
1977 xfs_fileoff_t lfileoff;
1979 xfs_bmbt_irec_t map;
1984 int blkcnt, valuelen, nmap, error, tmp, committed;
1991 * Find a "hole" in the attribute address space large enough for
1992 * us to drop the new attribute's value into.
1994 blkcnt = XFS_B_TO_FSB(mp, args->valuelen);
1996 error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff,
2001 args->rmtblkno = lblkno = (xfs_dablk_t)lfileoff;
2002 args->rmtblkcnt = blkcnt;
2005 * Roll through the "value", allocating blocks on disk as required.
2007 while (blkcnt > 0) {
2009 * Allocate a single extent, up to the size of the value.
2011 XFS_BMAP_INIT(args->flist, args->firstblock);
2013 error = xfs_bmapi(args->trans, dp, (xfs_fileoff_t)lblkno,
2015 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA |
2017 args->firstblock, args->total, &map, &nmap,
2020 error = xfs_bmap_finish(&args->trans, args->flist,
2021 *args->firstblock, &committed);
2026 xfs_bmap_cancel(args->flist);
2031 * bmap_finish() may have committed the last trans and started
2032 * a new one. We need the inode to be in all transactions.
2035 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
2036 xfs_trans_ihold(args->trans, dp);
2040 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2041 (map.br_startblock != HOLESTARTBLOCK));
2042 lblkno += map.br_blockcount;
2043 blkcnt -= map.br_blockcount;
2046 * Start the next trans in the chain.
2048 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
2053 * Roll through the "value", copying the attribute value to the
2054 * already-allocated blocks. Blocks are written synchronously
2055 * so that we can know they are all on disk before we turn off
2056 * the INCOMPLETE flag.
2058 lblkno = args->rmtblkno;
2059 valuelen = args->valuelen;
2060 while (valuelen > 0) {
2062 * Try to remember where we decided to put the value.
2064 XFS_BMAP_INIT(args->flist, args->firstblock);
2066 error = xfs_bmapi(NULL, dp, (xfs_fileoff_t)lblkno,
2068 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2069 args->firstblock, 0, &map, &nmap, NULL);
2074 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2075 (map.br_startblock != HOLESTARTBLOCK));
2077 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2078 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2080 bp = xfs_buf_get_flags(mp->m_ddev_targp, dblkno,
2081 blkcnt, XFS_BUF_LOCK);
2083 ASSERT(!XFS_BUF_GETERROR(bp));
2085 tmp = (valuelen < XFS_BUF_SIZE(bp)) ? valuelen :
2087 xfs_biomove(bp, 0, tmp, src, XFS_B_WRITE);
2088 if (tmp < XFS_BUF_SIZE(bp))
2089 xfs_biozero(bp, tmp, XFS_BUF_SIZE(bp) - tmp);
2090 if ((error = xfs_bwrite(mp, bp))) {/* GROT: NOTE: synchronous write */
2096 lblkno += map.br_blockcount;
2098 ASSERT(valuelen == 0);
2103 * Remove the value associated with an attribute by deleting the
2104 * out-of-line buffer that it is stored on.
2107 xfs_attr_rmtval_remove(xfs_da_args_t *args)
2110 xfs_bmbt_irec_t map;
2114 int valuelen, blkcnt, nmap, error, done, committed;
2116 mp = args->dp->i_mount;
2119 * Roll through the "value", invalidating the attribute value's
2122 lblkno = args->rmtblkno;
2123 valuelen = args->rmtblkcnt;
2124 while (valuelen > 0) {
2126 * Try to remember where we decided to put the value.
2128 XFS_BMAP_INIT(args->flist, args->firstblock);
2130 error = xfs_bmapi(NULL, args->dp, (xfs_fileoff_t)lblkno,
2132 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2133 args->firstblock, 0, &map, &nmap,
2139 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2140 (map.br_startblock != HOLESTARTBLOCK));
2142 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2143 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2146 * If the "remote" value is in the cache, remove it.
2148 bp = xfs_incore(mp->m_ddev_targp, dblkno, blkcnt,
2149 XFS_INCORE_TRYLOCK);
2152 XFS_BUF_UNDELAYWRITE(bp);
2157 valuelen -= map.br_blockcount;
2159 lblkno += map.br_blockcount;
2163 * Keep de-allocating extents until the remote-value region is gone.
2165 lblkno = args->rmtblkno;
2166 blkcnt = args->rmtblkcnt;
2169 XFS_BMAP_INIT(args->flist, args->firstblock);
2170 error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
2171 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2172 1, args->firstblock, args->flist, &done);
2174 error = xfs_bmap_finish(&args->trans, args->flist,
2175 *args->firstblock, &committed);
2180 xfs_bmap_cancel(args->flist);
2185 * bmap_finish() may have committed the last trans and started
2186 * a new one. We need the inode to be in all transactions.
2189 xfs_trans_ijoin(args->trans, args->dp, XFS_ILOCK_EXCL);
2190 xfs_trans_ihold(args->trans, args->dp);
2194 * Close out trans and start the next one in the chain.
2196 if ((error = xfs_attr_rolltrans(&args->trans, args->dp)))
2202 #if defined(XFS_ATTR_TRACE)
2204 * Add a trace buffer entry for an attr_list context structure.
2207 xfs_attr_trace_l_c(char *where, struct xfs_attr_list_context *context)
2209 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_C, where,
2210 (__psunsigned_t)context->dp,
2211 (__psunsigned_t)context->cursor->hashval,
2212 (__psunsigned_t)context->cursor->blkno,
2213 (__psunsigned_t)context->cursor->offset,
2214 (__psunsigned_t)context->alist,
2215 (__psunsigned_t)context->bufsize,
2216 (__psunsigned_t)context->count,
2217 (__psunsigned_t)context->firstu,
2219 ((context->count > 0) &&
2220 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2221 ? (ATTR_ENTRY(context->alist,
2222 context->count-1)->a_valuelen)
2224 (__psunsigned_t)context->dupcnt,
2225 (__psunsigned_t)context->flags,
2226 (__psunsigned_t)NULL,
2227 (__psunsigned_t)NULL,
2228 (__psunsigned_t)NULL);
2232 * Add a trace buffer entry for a context structure and a Btree node.
2235 xfs_attr_trace_l_cn(char *where, struct xfs_attr_list_context *context,
2236 struct xfs_da_intnode *node)
2238 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CN, where,
2239 (__psunsigned_t)context->dp,
2240 (__psunsigned_t)context->cursor->hashval,
2241 (__psunsigned_t)context->cursor->blkno,
2242 (__psunsigned_t)context->cursor->offset,
2243 (__psunsigned_t)context->alist,
2244 (__psunsigned_t)context->bufsize,
2245 (__psunsigned_t)context->count,
2246 (__psunsigned_t)context->firstu,
2248 ((context->count > 0) &&
2249 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2250 ? (ATTR_ENTRY(context->alist,
2251 context->count-1)->a_valuelen)
2253 (__psunsigned_t)context->dupcnt,
2254 (__psunsigned_t)context->flags,
2255 (__psunsigned_t)INT_GET(node->hdr.count, ARCH_CONVERT),
2256 (__psunsigned_t)INT_GET(node->btree[0].hashval, ARCH_CONVERT),
2257 (__psunsigned_t)INT_GET(node->btree[INT_GET(node->hdr.count, ARCH_CONVERT)-1].hashval, ARCH_CONVERT));
2261 * Add a trace buffer entry for a context structure and a Btree element.
2264 xfs_attr_trace_l_cb(char *where, struct xfs_attr_list_context *context,
2265 struct xfs_da_node_entry *btree)
2267 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CB, where,
2268 (__psunsigned_t)context->dp,
2269 (__psunsigned_t)context->cursor->hashval,
2270 (__psunsigned_t)context->cursor->blkno,
2271 (__psunsigned_t)context->cursor->offset,
2272 (__psunsigned_t)context->alist,
2273 (__psunsigned_t)context->bufsize,
2274 (__psunsigned_t)context->count,
2275 (__psunsigned_t)context->firstu,
2277 ((context->count > 0) &&
2278 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2279 ? (ATTR_ENTRY(context->alist,
2280 context->count-1)->a_valuelen)
2282 (__psunsigned_t)context->dupcnt,
2283 (__psunsigned_t)context->flags,
2284 (__psunsigned_t)INT_GET(btree->hashval, ARCH_CONVERT),
2285 (__psunsigned_t)INT_GET(btree->before, ARCH_CONVERT),
2286 (__psunsigned_t)NULL);
2290 * Add a trace buffer entry for a context structure and a leaf block.
2293 xfs_attr_trace_l_cl(char *where, struct xfs_attr_list_context *context,
2294 struct xfs_attr_leafblock *leaf)
2296 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CL, where,
2297 (__psunsigned_t)context->dp,
2298 (__psunsigned_t)context->cursor->hashval,
2299 (__psunsigned_t)context->cursor->blkno,
2300 (__psunsigned_t)context->cursor->offset,
2301 (__psunsigned_t)context->alist,
2302 (__psunsigned_t)context->bufsize,
2303 (__psunsigned_t)context->count,
2304 (__psunsigned_t)context->firstu,
2306 ((context->count > 0) &&
2307 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2308 ? (ATTR_ENTRY(context->alist,
2309 context->count-1)->a_valuelen)
2311 (__psunsigned_t)context->dupcnt,
2312 (__psunsigned_t)context->flags,
2313 (__psunsigned_t)INT_GET(leaf->hdr.count, ARCH_CONVERT),
2314 (__psunsigned_t)INT_GET(leaf->entries[0].hashval, ARCH_CONVERT),
2315 (__psunsigned_t)INT_GET(leaf->entries[INT_GET(leaf->hdr.count, ARCH_CONVERT)-1].hashval, ARCH_CONVERT));
2319 * Add a trace buffer entry for the arguments given to the routine,
2323 xfs_attr_trace_enter(int type, char *where,
2324 __psunsigned_t a2, __psunsigned_t a3,
2325 __psunsigned_t a4, __psunsigned_t a5,
2326 __psunsigned_t a6, __psunsigned_t a7,
2327 __psunsigned_t a8, __psunsigned_t a9,
2328 __psunsigned_t a10, __psunsigned_t a11,
2329 __psunsigned_t a12, __psunsigned_t a13,
2330 __psunsigned_t a14, __psunsigned_t a15)
2332 ASSERT(xfs_attr_trace_buf);
2333 ktrace_enter(xfs_attr_trace_buf, (void *)((__psunsigned_t)type),
2335 (void *)a2, (void *)a3, (void *)a4,
2336 (void *)a5, (void *)a6, (void *)a7,
2337 (void *)a8, (void *)a9, (void *)a10,
2338 (void *)a11, (void *)a12, (void *)a13,
2339 (void *)a14, (void *)a15);
2341 #endif /* XFS_ATTR_TRACE */
2344 /*========================================================================
2345 * System (pseudo) namespace attribute interface routines.
2346 *========================================================================*/
2349 posix_acl_access_set(
2350 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2352 return xfs_acl_vset(vp, data, size, _ACL_TYPE_ACCESS);
2356 posix_acl_access_remove(
2357 struct vnode *vp, char *name, int xflags)
2359 return xfs_acl_vremove(vp, _ACL_TYPE_ACCESS);
2363 posix_acl_access_get(
2364 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2366 return xfs_acl_vget(vp, data, size, _ACL_TYPE_ACCESS);
2370 posix_acl_access_exists(
2373 return xfs_acl_vhasacl_access(vp);
2377 posix_acl_default_set(
2378 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2380 return xfs_acl_vset(vp, data, size, _ACL_TYPE_DEFAULT);
2384 posix_acl_default_get(
2385 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2387 return xfs_acl_vget(vp, data, size, _ACL_TYPE_DEFAULT);
2391 posix_acl_default_remove(
2392 struct vnode *vp, char *name, int xflags)
2394 return xfs_acl_vremove(vp, _ACL_TYPE_DEFAULT);
2398 posix_acl_default_exists(
2401 return xfs_acl_vhasacl_default(vp);
2404 STATIC struct attrnames posix_acl_access = {
2405 .attr_name = "posix_acl_access",
2406 .attr_namelen = sizeof("posix_acl_access") - 1,
2407 .attr_get = posix_acl_access_get,
2408 .attr_set = posix_acl_access_set,
2409 .attr_remove = posix_acl_access_remove,
2410 .attr_exists = posix_acl_access_exists,
2413 STATIC struct attrnames posix_acl_default = {
2414 .attr_name = "posix_acl_default",
2415 .attr_namelen = sizeof("posix_acl_default") - 1,
2416 .attr_get = posix_acl_default_get,
2417 .attr_set = posix_acl_default_set,
2418 .attr_remove = posix_acl_default_remove,
2419 .attr_exists = posix_acl_default_exists,
2422 STATIC struct attrnames *attr_system_names[] =
2423 { &posix_acl_access, &posix_acl_default };
2426 /*========================================================================
2427 * Namespace-prefix-style attribute name interface routines.
2428 *========================================================================*/
2432 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2436 VOP_ATTR_SET(vp, name, data, size, xflags, NULL, error);
2442 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2444 int error, asize = size;
2446 VOP_ATTR_GET(vp, name, data, &asize, xflags, NULL, error);
2453 attr_generic_remove(
2454 struct vnode *vp, char *name, int xflags)
2458 VOP_ATTR_REMOVE(vp, name, xflags, NULL, error);
2463 attr_generic_listadd(
2464 attrnames_t *prefix,
2465 attrnames_t *namesp,
2470 char *p = data + *result;
2472 *result += prefix->attr_namelen;
2473 *result += namesp->attr_namelen + 1;
2478 strcpy(p, prefix->attr_name);
2479 p += prefix->attr_namelen;
2480 strcpy(p, namesp->attr_name);
2481 p += namesp->attr_namelen + 1;
2492 attrnames_t *namesp;
2495 for (i = 0; i < ATTR_SYSCOUNT; i++) {
2496 namesp = attr_system_names[i];
2497 if (!namesp->attr_exists || !namesp->attr_exists(vp))
2499 error = attr_generic_listadd(&attr_system, namesp,
2500 data, size, result);
2509 struct vnode *vp, void *data, size_t size, int xflags, ssize_t *result)
2511 attrlist_cursor_kern_t cursor = { 0 };
2514 VOP_ATTR_LIST(vp, data, size, xflags, &cursor, NULL, error);
2518 return attr_system_list(vp, data, size, result);
2522 attr_lookup_namespace(
2524 struct attrnames **names,
2529 for (i = 0; i < nnames; i++)
2530 if (!strncmp(name, names[i]->attr_name, names[i]->attr_namelen))
2536 * Some checks to prevent people abusing EAs to get over quota:
2537 * - Don't allow modifying user EAs on devices/symlinks;
2538 * - Don't allow modifying user EAs if sticky bit set;
2545 struct inode *inode = LINVFS_GET_IP(vp);
2547 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2549 if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode) &&
2550 !capable(CAP_SYS_ADMIN))
2552 if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) &&
2553 (current_fsuid(cred) != inode->i_uid) && !capable(CAP_FOWNER))
2559 attr_trusted_capable(
2563 struct inode *inode = LINVFS_GET_IP(vp);
2565 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2567 if (!capable(CAP_SYS_ADMIN))
2573 attr_secure_capable(
2577 return -ENOSECURITY;
2582 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2584 attrnames_t *namesp;
2587 if (xflags & ATTR_CREATE)
2590 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2593 error = namesp->attr_set(vp, name, data, size, xflags);
2595 error = vn_revalidate(vp);
2601 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2603 attrnames_t *namesp;
2605 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2608 return namesp->attr_get(vp, name, data, size, xflags);
2613 struct vnode *vp, char *name, int xflags)
2615 attrnames_t *namesp;
2617 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2620 return namesp->attr_remove(vp, name, xflags);
2623 struct attrnames attr_system = {
2624 .attr_name = "system.",
2625 .attr_namelen = sizeof("system.") - 1,
2626 .attr_flag = ATTR_SYSTEM,
2627 .attr_get = attr_system_get,
2628 .attr_set = attr_system_set,
2629 .attr_remove = attr_system_remove,
2630 .attr_capable = (attrcapable_t)fs_noerr,
2633 struct attrnames attr_trusted = {
2634 .attr_name = "trusted.",
2635 .attr_namelen = sizeof("trusted.") - 1,
2636 .attr_flag = ATTR_ROOT,
2637 .attr_get = attr_generic_get,
2638 .attr_set = attr_generic_set,
2639 .attr_remove = attr_generic_remove,
2640 .attr_capable = attr_trusted_capable,
2643 struct attrnames attr_secure = {
2644 .attr_name = "security.",
2645 .attr_namelen = sizeof("security.") - 1,
2646 .attr_flag = ATTR_SECURE,
2647 .attr_get = attr_generic_get,
2648 .attr_set = attr_generic_set,
2649 .attr_remove = attr_generic_remove,
2650 .attr_capable = attr_secure_capable,
2653 struct attrnames attr_user = {
2654 .attr_name = "user.",
2655 .attr_namelen = sizeof("user.") - 1,
2656 .attr_get = attr_generic_get,
2657 .attr_set = attr_generic_set,
2658 .attr_remove = attr_generic_remove,
2659 .attr_capable = attr_user_capable,
2662 struct attrnames *attr_namespaces[] =
2663 { &attr_system, &attr_trusted, &attr_secure, &attr_user };