2 * Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
35 #include "xfs_macros.h"
36 #include "xfs_types.h"
39 #include "xfs_trans.h"
44 #include "xfs_dmapi.h"
45 #include "xfs_mount.h"
46 #include "xfs_alloc_btree.h"
47 #include "xfs_bmap_btree.h"
48 #include "xfs_ialloc_btree.h"
49 #include "xfs_alloc.h"
50 #include "xfs_btree.h"
51 #include "xfs_attr_sf.h"
52 #include "xfs_dir_sf.h"
53 #include "xfs_dir2_sf.h"
54 #include "xfs_dinode.h"
55 #include "xfs_inode_item.h"
56 #include "xfs_inode.h"
58 #include "xfs_da_btree.h"
60 #include "xfs_attr_leaf.h"
61 #include "xfs_error.h"
63 #include "xfs_quota.h"
65 #include "xfs_trans_space.h"
71 * Provide the external interfaces to manage attribute lists.
74 #define ATTR_SYSCOUNT 2
75 STATIC struct attrnames posix_acl_access;
76 STATIC struct attrnames posix_acl_default;
77 STATIC struct attrnames *attr_system_names[ATTR_SYSCOUNT];
79 /*========================================================================
80 * Function prototypes for the kernel.
81 *========================================================================*/
84 * Internal routines when attribute list fits inside the inode.
86 STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
89 * Internal routines when attribute list is one block.
91 STATIC int xfs_attr_leaf_get(xfs_da_args_t *args);
92 STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args);
93 STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
94 STATIC int xfs_attr_leaf_list(xfs_attr_list_context_t *context);
97 * Internal routines when attribute list is more than one block.
99 STATIC int xfs_attr_node_get(xfs_da_args_t *args);
100 STATIC int xfs_attr_node_addname(xfs_da_args_t *args);
101 STATIC int xfs_attr_node_removename(xfs_da_args_t *args);
102 STATIC int xfs_attr_node_list(xfs_attr_list_context_t *context);
103 STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
104 STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
107 * Routines to manipulate out-of-line attribute values.
109 STATIC int xfs_attr_rmtval_get(xfs_da_args_t *args);
110 STATIC int xfs_attr_rmtval_set(xfs_da_args_t *args);
111 STATIC int xfs_attr_rmtval_remove(xfs_da_args_t *args);
113 #define ATTR_RMTVALUE_MAPSIZE 1 /* # of map entries at once */
115 #if defined(XFS_ATTR_TRACE)
116 ktrace_t *xfs_attr_trace_buf;
120 /*========================================================================
121 * Overall external interface routines.
122 *========================================================================*/
125 xfs_attr_fetch(xfs_inode_t *ip, const char *name, int namelen,
126 char *value, int *valuelenp, int flags, struct cred *cred)
131 if ((XFS_IFORK_Q(ip) == 0) ||
132 (ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
133 ip->i_d.di_anextents == 0))
136 if (!(flags & (ATTR_KERNACCESS|ATTR_SECURE))) {
137 if ((error = xfs_iaccess(ip, S_IRUSR, cred)))
138 return(XFS_ERROR(error));
142 * Fill in the arg structure for this request.
144 memset((char *)&args, 0, sizeof(args));
146 args.namelen = namelen;
148 args.valuelen = *valuelenp;
150 args.hashval = xfs_da_hashname(args.name, args.namelen);
152 args.whichfork = XFS_ATTR_FORK;
155 * Decide on what work routines to call based on the inode size.
157 if (XFS_IFORK_Q(ip) == 0 ||
158 (ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
159 ip->i_d.di_anextents == 0)) {
160 error = XFS_ERROR(ENOATTR);
161 } else if (ip->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
162 error = xfs_attr_shortform_getvalue(&args);
163 } else if (xfs_bmap_one_block(ip, XFS_ATTR_FORK)) {
164 error = xfs_attr_leaf_get(&args);
166 error = xfs_attr_node_get(&args);
170 * Return the number of bytes in the value to the caller.
172 *valuelenp = args.valuelen;
180 xfs_attr_get(bhv_desc_t *bdp, const char *name, char *value, int *valuelenp,
181 int flags, struct cred *cred)
183 xfs_inode_t *ip = XFS_BHVTOI(bdp);
186 XFS_STATS_INC(xs_attr_get);
190 namelen = strlen(name);
191 if (namelen >= MAXNAMELEN)
192 return(EFAULT); /* match IRIX behaviour */
194 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
197 xfs_ilock(ip, XFS_ILOCK_SHARED);
198 error = xfs_attr_fetch(ip, name, namelen, value, valuelenp, flags, cred);
199 xfs_iunlock(ip, XFS_ILOCK_SHARED);
204 xfs_attr_set_int(xfs_inode_t *dp, const char *name, int namelen,
205 char *value, int valuelen, int flags)
208 xfs_fsblock_t firstblock;
209 xfs_bmap_free_t flist;
210 int error, err2, committed;
213 xfs_mount_t *mp = dp->i_mount;
214 int rsvd = (flags & ATTR_ROOT) != 0;
217 * Attach the dquots to the inode.
219 if ((error = XFS_QM_DQATTACH(mp, dp, 0)))
223 * Determine space new attribute will use, and if it would be
224 * "local" or "remote" (note: local != inline).
226 size = xfs_attr_leaf_newentsize(namelen, valuelen,
227 mp->m_sb.sb_blocksize, &local);
230 * If the inode doesn't have an attribute fork, add one.
231 * (inode must not be locked when we call this routine)
233 if (XFS_IFORK_Q(dp) == 0) {
234 if ((error = xfs_bmap_add_attrfork(dp, size, rsvd)))
239 * Fill in the arg structure for this request.
241 memset((char *)&args, 0, sizeof(args));
243 args.namelen = namelen;
245 args.valuelen = valuelen;
247 args.hashval = xfs_da_hashname(args.name, args.namelen);
249 args.firstblock = &firstblock;
251 args.whichfork = XFS_ATTR_FORK;
255 nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK);
257 if (size > (mp->m_sb.sb_blocksize >> 1)) {
258 /* Double split possible */
262 uint dblocks = XFS_B_TO_FSB(mp, valuelen);
263 /* Out of line attribute, cannot double split, but make
264 * room for the attribute value itself.
267 nblks += XFS_NEXTENTADD_SPACE_RES(mp, dblocks, XFS_ATTR_FORK);
270 /* Size is now blocks for attribute data */
274 * Start our first transaction of the day.
276 * All future transactions during this code must be "chained" off
277 * this one via the trans_dup() call. All transactions will contain
278 * the inode, and the inode will always be marked with trans_ihold().
279 * Since the inode will be locked in all transactions, we must log
280 * the inode in every transaction to let it float upward through
283 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_SET);
286 * Root fork attributes can use reserved data blocks for this
287 * operation if necessary
291 args.trans->t_flags |= XFS_TRANS_RESERVE;
293 if ((error = xfs_trans_reserve(args.trans, (uint) nblks,
294 XFS_ATTRSET_LOG_RES(mp, nblks),
295 0, XFS_TRANS_PERM_LOG_RES,
296 XFS_ATTRSET_LOG_COUNT))) {
297 xfs_trans_cancel(args.trans, 0);
300 xfs_ilock(dp, XFS_ILOCK_EXCL);
302 error = XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, args.trans, dp, nblks, 0,
303 rsvd ? XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES :
304 XFS_QMOPT_RES_REGBLKS);
306 xfs_iunlock(dp, XFS_ILOCK_EXCL);
307 xfs_trans_cancel(args.trans, XFS_TRANS_RELEASE_LOG_RES);
311 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
312 xfs_trans_ihold(args.trans, dp);
315 * If the attribute list is non-existant or a shortform list,
316 * upgrade it to a single-leaf-block attribute list.
318 if ((dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
319 ((dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS) &&
320 (dp->i_d.di_anextents == 0))) {
323 * Build initial attribute list (if required).
325 if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
326 xfs_attr_shortform_create(&args);
329 * Try to add the attr to the attribute list in
332 error = xfs_attr_shortform_addname(&args);
333 if (error != ENOSPC) {
335 * Commit the shortform mods, and we're done.
336 * NOTE: this is also the error path (EEXIST, etc).
338 ASSERT(args.trans != NULL);
341 * If this is a synchronous mount, make sure that
342 * the transaction goes to disk before returning
345 if (mp->m_flags & XFS_MOUNT_WSYNC) {
346 xfs_trans_set_sync(args.trans);
348 err2 = xfs_trans_commit(args.trans,
349 XFS_TRANS_RELEASE_LOG_RES,
351 xfs_iunlock(dp, XFS_ILOCK_EXCL);
354 * Hit the inode change time.
356 if (!error && (flags & ATTR_KERNOTIME) == 0) {
357 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
359 return(error == 0 ? err2 : error);
363 * It won't fit in the shortform, transform to a leaf block.
364 * GROT: another possible req'mt for a double-split btree op.
366 XFS_BMAP_INIT(args.flist, args.firstblock);
367 error = xfs_attr_shortform_to_leaf(&args);
369 error = xfs_bmap_finish(&args.trans, args.flist,
370 *args.firstblock, &committed);
375 xfs_bmap_cancel(&flist);
380 * bmap_finish() may have committed the last trans and started
381 * a new one. We need the inode to be in all transactions.
384 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
385 xfs_trans_ihold(args.trans, dp);
389 * Commit the leaf transformation. We'll need another (linked)
390 * transaction to add the new attribute to the leaf.
392 if ((error = xfs_attr_rolltrans(&args.trans, dp)))
397 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
398 error = xfs_attr_leaf_addname(&args);
400 error = xfs_attr_node_addname(&args);
407 * If this is a synchronous mount, make sure that the
408 * transaction goes to disk before returning to the user.
410 if (mp->m_flags & XFS_MOUNT_WSYNC) {
411 xfs_trans_set_sync(args.trans);
415 * Commit the last in the sequence of transactions.
417 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
418 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES,
420 xfs_iunlock(dp, XFS_ILOCK_EXCL);
423 * Hit the inode change time.
425 if (!error && (flags & ATTR_KERNOTIME) == 0) {
426 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
433 xfs_trans_cancel(args.trans,
434 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
435 xfs_iunlock(dp, XFS_ILOCK_EXCL);
440 xfs_attr_set(bhv_desc_t *bdp, const char *name, char *value, int valuelen, int flags,
446 namelen = strlen(name);
447 if (namelen >= MAXNAMELEN)
448 return EFAULT; /* match IRIX behaviour */
450 XFS_STATS_INC(xs_attr_set);
452 dp = XFS_BHVTOI(bdp);
453 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
456 xfs_ilock(dp, XFS_ILOCK_SHARED);
457 if (!(flags & ATTR_SECURE) &&
458 (error = xfs_iaccess(dp, S_IWUSR, cred))) {
459 xfs_iunlock(dp, XFS_ILOCK_SHARED);
460 return(XFS_ERROR(error));
462 xfs_iunlock(dp, XFS_ILOCK_SHARED);
464 return xfs_attr_set_int(dp, name, namelen, value, valuelen, flags);
468 * Generic handler routine to remove a name from an attribute list.
469 * Transitions attribute list from Btree to shortform as necessary.
472 xfs_attr_remove_int(xfs_inode_t *dp, const char *name, int namelen, int flags)
475 xfs_fsblock_t firstblock;
476 xfs_bmap_free_t flist;
478 xfs_mount_t *mp = dp->i_mount;
481 * Fill in the arg structure for this request.
483 memset((char *)&args, 0, sizeof(args));
485 args.namelen = namelen;
487 args.hashval = xfs_da_hashname(args.name, args.namelen);
489 args.firstblock = &firstblock;
492 args.whichfork = XFS_ATTR_FORK;
495 * Attach the dquots to the inode.
497 if ((error = XFS_QM_DQATTACH(mp, dp, 0)))
501 * Start our first transaction of the day.
503 * All future transactions during this code must be "chained" off
504 * this one via the trans_dup() call. All transactions will contain
505 * the inode, and the inode will always be marked with trans_ihold().
506 * Since the inode will be locked in all transactions, we must log
507 * the inode in every transaction to let it float upward through
510 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_RM);
513 * Root fork attributes can use reserved data blocks for this
514 * operation if necessary
517 if (flags & ATTR_ROOT)
518 args.trans->t_flags |= XFS_TRANS_RESERVE;
520 if ((error = xfs_trans_reserve(args.trans,
521 XFS_ATTRRM_SPACE_RES(mp),
522 XFS_ATTRRM_LOG_RES(mp),
523 0, XFS_TRANS_PERM_LOG_RES,
524 XFS_ATTRRM_LOG_COUNT))) {
525 xfs_trans_cancel(args.trans, 0);
529 xfs_ilock(dp, XFS_ILOCK_EXCL);
531 * No need to make quota reservations here. We expect to release some
532 * blocks not allocate in the common case.
534 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
535 xfs_trans_ihold(args.trans, dp);
538 * Decide on what work routines to call based on the inode size.
540 if (XFS_IFORK_Q(dp) == 0 ||
541 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
542 dp->i_d.di_anextents == 0)) {
543 error = XFS_ERROR(ENOATTR);
546 if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
547 ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
548 error = xfs_attr_shortform_remove(&args);
552 } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
553 error = xfs_attr_leaf_removename(&args);
555 error = xfs_attr_node_removename(&args);
562 * If this is a synchronous mount, make sure that the
563 * transaction goes to disk before returning to the user.
565 if (mp->m_flags & XFS_MOUNT_WSYNC) {
566 xfs_trans_set_sync(args.trans);
570 * Commit the last in the sequence of transactions.
572 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
573 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES,
575 xfs_iunlock(dp, XFS_ILOCK_EXCL);
578 * Hit the inode change time.
580 if (!error && (flags & ATTR_KERNOTIME) == 0) {
581 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
588 xfs_trans_cancel(args.trans,
589 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
590 xfs_iunlock(dp, XFS_ILOCK_EXCL);
595 xfs_attr_remove(bhv_desc_t *bdp, const char *name, int flags, struct cred *cred)
600 namelen = strlen(name);
601 if (namelen >= MAXNAMELEN)
602 return EFAULT; /* match IRIX behaviour */
604 XFS_STATS_INC(xs_attr_remove);
606 dp = XFS_BHVTOI(bdp);
607 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
610 xfs_ilock(dp, XFS_ILOCK_SHARED);
611 if (!(flags & ATTR_SECURE) &&
612 (error = xfs_iaccess(dp, S_IWUSR, cred))) {
613 xfs_iunlock(dp, XFS_ILOCK_SHARED);
614 return(XFS_ERROR(error));
615 } else if (XFS_IFORK_Q(dp) == 0 ||
616 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
617 dp->i_d.di_anextents == 0)) {
618 xfs_iunlock(dp, XFS_ILOCK_SHARED);
619 return(XFS_ERROR(ENOATTR));
621 xfs_iunlock(dp, XFS_ILOCK_SHARED);
623 return xfs_attr_remove_int(dp, name, namelen, flags);
627 * Generate a list of extended attribute names and optionally
628 * also value lengths. Positive return value follows the XFS
629 * convention of being an error, zero or negative return code
630 * is the length of the buffer returned (negated), indicating
634 xfs_attr_list(bhv_desc_t *bdp, char *buffer, int bufsize, int flags,
635 attrlist_cursor_kern_t *cursor, struct cred *cred)
637 xfs_attr_list_context_t context;
641 XFS_STATS_INC(xs_attr_list);
644 * Validate the cursor.
646 if (cursor->pad1 || cursor->pad2)
647 return(XFS_ERROR(EINVAL));
648 if ((cursor->initted == 0) &&
649 (cursor->hashval || cursor->blkno || cursor->offset))
650 return(XFS_ERROR(EINVAL));
653 * Check for a properly aligned buffer.
655 if (((long)buffer) & (sizeof(int)-1))
656 return(XFS_ERROR(EFAULT));
657 if (flags & ATTR_KERNOVAL)
661 * Initialize the output buffer.
663 context.dp = dp = XFS_BHVTOI(bdp);
664 context.cursor = cursor;
668 context.flags = flags;
669 if (!(flags & ATTR_KERNAMELS)) {
670 context.bufsize = (bufsize & ~(sizeof(int)-1)); /* align */
671 context.firstu = context.bufsize;
672 context.alist = (attrlist_t *)buffer;
673 context.alist->al_count = 0;
674 context.alist->al_more = 0;
675 context.alist->al_offset[0] = context.bufsize;
678 context.bufsize = bufsize;
679 context.firstu = context.bufsize;
680 context.alist = (attrlist_t *)buffer;
683 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
686 xfs_ilock(dp, XFS_ILOCK_SHARED);
687 if (!(flags & ATTR_SECURE) &&
688 (error = xfs_iaccess(dp, S_IRUSR, cred))) {
689 xfs_iunlock(dp, XFS_ILOCK_SHARED);
690 return(XFS_ERROR(error));
694 * Decide on what work routines to call based on the inode size.
696 xfs_attr_trace_l_c("syscall start", &context);
697 if (XFS_IFORK_Q(dp) == 0 ||
698 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
699 dp->i_d.di_anextents == 0)) {
701 } else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
702 error = xfs_attr_shortform_list(&context);
703 } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
704 error = xfs_attr_leaf_list(&context);
706 error = xfs_attr_node_list(&context);
708 xfs_iunlock(dp, XFS_ILOCK_SHARED);
709 xfs_attr_trace_l_c("syscall end", &context);
711 if (!(context.flags & (ATTR_KERNOVAL|ATTR_KERNAMELS))) {
714 else { /* must return negated buffer size or the error */
715 if (context.count < 0)
716 error = XFS_ERROR(ERANGE);
718 error = -context.count;
725 xfs_attr_inactive(xfs_inode_t *dp)
732 ASSERT(! XFS_NOT_DQATTACHED(mp, dp));
734 xfs_ilock(dp, XFS_ILOCK_SHARED);
735 if ((XFS_IFORK_Q(dp) == 0) ||
736 (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
737 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
738 dp->i_d.di_anextents == 0)) {
739 xfs_iunlock(dp, XFS_ILOCK_SHARED);
742 xfs_iunlock(dp, XFS_ILOCK_SHARED);
745 * Start our first transaction of the day.
747 * All future transactions during this code must be "chained" off
748 * this one via the trans_dup() call. All transactions will contain
749 * the inode, and the inode will always be marked with trans_ihold().
750 * Since the inode will be locked in all transactions, we must log
751 * the inode in every transaction to let it float upward through
754 trans = xfs_trans_alloc(mp, XFS_TRANS_ATTRINVAL);
755 if ((error = xfs_trans_reserve(trans, 0, XFS_ATTRINVAL_LOG_RES(mp), 0,
756 XFS_TRANS_PERM_LOG_RES,
757 XFS_ATTRINVAL_LOG_COUNT))) {
758 xfs_trans_cancel(trans, 0);
761 xfs_ilock(dp, XFS_ILOCK_EXCL);
764 * No need to make quota reservations here. We expect to release some
765 * blocks, not allocate, in the common case.
767 xfs_trans_ijoin(trans, dp, XFS_ILOCK_EXCL);
768 xfs_trans_ihold(trans, dp);
771 * Decide on what work routines to call based on the inode size.
773 if ((XFS_IFORK_Q(dp) == 0) ||
774 (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
775 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
776 dp->i_d.di_anextents == 0)) {
780 error = xfs_attr_root_inactive(&trans, dp);
784 * signal synchronous inactive transactions unless this
785 * is a synchronous mount filesystem in which case we
786 * know that we're here because we've been called out of
787 * xfs_inactive which means that the last reference is gone
788 * and the unlink transaction has already hit the disk so
789 * async inactive transactions are safe.
791 if ((error = xfs_itruncate_finish(&trans, dp, 0LL, XFS_ATTR_FORK,
792 (!(mp->m_flags & XFS_MOUNT_WSYNC)
797 * Commit the last in the sequence of transactions.
799 xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE);
800 error = xfs_trans_commit(trans, XFS_TRANS_RELEASE_LOG_RES,
802 xfs_iunlock(dp, XFS_ILOCK_EXCL);
807 xfs_trans_cancel(trans, XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
808 xfs_iunlock(dp, XFS_ILOCK_EXCL);
814 /*========================================================================
815 * External routines when attribute list is inside the inode
816 *========================================================================*/
819 * Add a name to the shortform attribute list structure
820 * This is the external routine.
823 xfs_attr_shortform_addname(xfs_da_args_t *args)
825 int newsize, forkoff, retval;
827 retval = xfs_attr_shortform_lookup(args);
828 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
830 } else if (retval == EEXIST) {
831 if (args->flags & ATTR_CREATE)
833 retval = xfs_attr_shortform_remove(args);
837 if (args->namelen >= XFS_ATTR_SF_ENTSIZE_MAX ||
838 args->valuelen >= XFS_ATTR_SF_ENTSIZE_MAX)
839 return(XFS_ERROR(ENOSPC));
841 newsize = XFS_ATTR_SF_TOTSIZE(args->dp);
842 newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen);
844 forkoff = xfs_attr_shortform_bytesfit(args->dp, newsize);
846 return(XFS_ERROR(ENOSPC));
848 xfs_attr_shortform_add(args, forkoff);
853 /*========================================================================
854 * External routines when attribute list is one block
855 *========================================================================*/
858 * Add a name to the leaf attribute list structure
860 * This leaf block cannot have a "remote" value, we only call this routine
861 * if bmap_one_block() says there is only one block (ie: no remote blks).
864 xfs_attr_leaf_addname(xfs_da_args_t *args)
868 int retval, error, committed, forkoff;
871 * Read the (only) block in the attribute list in.
875 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
882 * Look up the given attribute in the leaf block. Figure out if
883 * the given flags produce an error or call for an atomic rename.
885 retval = xfs_attr_leaf_lookup_int(bp, args);
886 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
887 xfs_da_brelse(args->trans, bp);
889 } else if (retval == EEXIST) {
890 if (args->flags & ATTR_CREATE) { /* pure create op */
891 xfs_da_brelse(args->trans, bp);
894 args->rename = 1; /* an atomic rename */
895 args->blkno2 = args->blkno; /* set 2nd entry info*/
896 args->index2 = args->index;
897 args->rmtblkno2 = args->rmtblkno;
898 args->rmtblkcnt2 = args->rmtblkcnt;
902 * Add the attribute to the leaf block, transitioning to a Btree
905 retval = xfs_attr_leaf_add(bp, args);
907 if (retval == ENOSPC) {
909 * Promote the attribute list to the Btree format, then
910 * Commit that transaction so that the node_addname() call
911 * can manage its own transactions.
913 XFS_BMAP_INIT(args->flist, args->firstblock);
914 error = xfs_attr_leaf_to_node(args);
916 error = xfs_bmap_finish(&args->trans, args->flist,
917 *args->firstblock, &committed);
922 xfs_bmap_cancel(args->flist);
927 * bmap_finish() may have committed the last trans and started
928 * a new one. We need the inode to be in all transactions.
931 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
932 xfs_trans_ihold(args->trans, dp);
936 * Commit the current trans (including the inode) and start
939 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
943 * Fob the whole rest of the problem off on the Btree code.
945 error = xfs_attr_node_addname(args);
950 * Commit the transaction that added the attr name so that
951 * later routines can manage their own transactions.
953 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
957 * If there was an out-of-line value, allocate the blocks we
958 * identified for its storage and copy the value. This is done
959 * after we create the attribute so that we don't overflow the
960 * maximum size of a transaction and/or hit a deadlock.
962 if (args->rmtblkno > 0) {
963 error = xfs_attr_rmtval_set(args);
969 * If this is an atomic rename operation, we must "flip" the
970 * incomplete flags on the "new" and "old" attribute/value pairs
971 * so that one disappears and one appears atomically. Then we
972 * must remove the "old" attribute/value pair.
976 * In a separate transaction, set the incomplete flag on the
977 * "old" attr and clear the incomplete flag on the "new" attr.
979 error = xfs_attr_leaf_flipflags(args);
984 * Dismantle the "old" attribute/value pair by removing
985 * a "remote" value (if it exists).
987 args->index = args->index2;
988 args->blkno = args->blkno2;
989 args->rmtblkno = args->rmtblkno2;
990 args->rmtblkcnt = args->rmtblkcnt2;
991 if (args->rmtblkno) {
992 error = xfs_attr_rmtval_remove(args);
998 * Read in the block containing the "old" attr, then
999 * remove the "old" attr from that block (neat, huh!)
1001 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1,
1002 &bp, XFS_ATTR_FORK);
1006 (void)xfs_attr_leaf_remove(bp, args);
1009 * If the result is small enough, shrink it all into the inode.
1011 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1012 XFS_BMAP_INIT(args->flist, args->firstblock);
1013 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1014 /* bp is gone due to xfs_da_shrink_inode */
1016 error = xfs_bmap_finish(&args->trans,
1024 xfs_bmap_cancel(args->flist);
1029 * bmap_finish() may have committed the last trans
1030 * and started a new one. We need the inode to be
1031 * in all transactions.
1034 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1035 xfs_trans_ihold(args->trans, dp);
1038 xfs_da_buf_done(bp);
1041 * Commit the remove and start the next trans in series.
1043 error = xfs_attr_rolltrans(&args->trans, dp);
1045 } else if (args->rmtblkno > 0) {
1047 * Added a "remote" value, just clear the incomplete flag.
1049 error = xfs_attr_leaf_clearflag(args);
1055 * Remove a name from the leaf attribute list structure
1057 * This leaf block cannot have a "remote" value, we only call this routine
1058 * if bmap_one_block() says there is only one block (ie: no remote blks).
1061 xfs_attr_leaf_removename(xfs_da_args_t *args)
1065 int error, committed, forkoff;
1068 * Remove the attribute.
1072 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1079 error = xfs_attr_leaf_lookup_int(bp, args);
1080 if (error == ENOATTR) {
1081 xfs_da_brelse(args->trans, bp);
1085 (void)xfs_attr_leaf_remove(bp, args);
1088 * If the result is small enough, shrink it all into the inode.
1090 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1091 XFS_BMAP_INIT(args->flist, args->firstblock);
1092 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1093 /* bp is gone due to xfs_da_shrink_inode */
1095 error = xfs_bmap_finish(&args->trans, args->flist,
1096 *args->firstblock, &committed);
1101 xfs_bmap_cancel(args->flist);
1106 * bmap_finish() may have committed the last trans and started
1107 * a new one. We need the inode to be in all transactions.
1110 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1111 xfs_trans_ihold(args->trans, dp);
1114 xfs_da_buf_done(bp);
1119 * Look up a name in a leaf attribute list structure.
1121 * This leaf block cannot have a "remote" value, we only call this routine
1122 * if bmap_one_block() says there is only one block (ie: no remote blks).
1125 xfs_attr_leaf_get(xfs_da_args_t *args)
1131 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1137 error = xfs_attr_leaf_lookup_int(bp, args);
1138 if (error != EEXIST) {
1139 xfs_da_brelse(args->trans, bp);
1142 error = xfs_attr_leaf_getvalue(bp, args);
1143 xfs_da_brelse(args->trans, bp);
1144 if (!error && (args->rmtblkno > 0) && !(args->flags & ATTR_KERNOVAL)) {
1145 error = xfs_attr_rmtval_get(args);
1151 * Copy out attribute entries for attr_list(), for leaf attribute lists.
1154 xfs_attr_leaf_list(xfs_attr_list_context_t *context)
1156 xfs_attr_leafblock_t *leaf;
1160 context->cursor->blkno = 0;
1161 error = xfs_da_read_buf(NULL, context->dp, 0, -1, &bp, XFS_ATTR_FORK);
1166 if (unlikely(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
1167 != XFS_ATTR_LEAF_MAGIC)) {
1168 XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW,
1169 context->dp->i_mount, leaf);
1170 xfs_da_brelse(NULL, bp);
1171 return(XFS_ERROR(EFSCORRUPTED));
1174 (void)xfs_attr_leaf_list_int(bp, context);
1175 xfs_da_brelse(NULL, bp);
1180 /*========================================================================
1181 * External routines when attribute list size > XFS_LBSIZE(mp).
1182 *========================================================================*/
1185 * Add a name to a Btree-format attribute list.
1187 * This will involve walking down the Btree, and may involve splitting
1188 * leaf nodes and even splitting intermediate nodes up to and including
1189 * the root node (a special case of an intermediate node).
1191 * "Remote" attribute values confuse the issue and atomic rename operations
1192 * add a whole extra layer of confusion on top of that.
1195 xfs_attr_node_addname(xfs_da_args_t *args)
1197 xfs_da_state_t *state;
1198 xfs_da_state_blk_t *blk;
1201 int committed, retval, error;
1204 * Fill in bucket of arguments/results/context to carry around.
1209 state = xfs_da_state_alloc();
1212 state->blocksize = state->mp->m_sb.sb_blocksize;
1213 state->node_ents = state->mp->m_attr_node_ents;
1216 * Search to see if name already exists, and get back a pointer
1217 * to where it should go.
1219 error = xfs_da_node_lookup_int(state, &retval);
1222 blk = &state->path.blk[ state->path.active-1 ];
1223 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1224 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
1226 } else if (retval == EEXIST) {
1227 if (args->flags & ATTR_CREATE)
1229 args->rename = 1; /* atomic rename op */
1230 args->blkno2 = args->blkno; /* set 2nd entry info*/
1231 args->index2 = args->index;
1232 args->rmtblkno2 = args->rmtblkno;
1233 args->rmtblkcnt2 = args->rmtblkcnt;
1235 args->rmtblkcnt = 0;
1238 retval = xfs_attr_leaf_add(blk->bp, state->args);
1239 if (retval == ENOSPC) {
1240 if (state->path.active == 1) {
1242 * Its really a single leaf node, but it had
1243 * out-of-line values so it looked like it *might*
1244 * have been a b-tree.
1246 xfs_da_state_free(state);
1247 XFS_BMAP_INIT(args->flist, args->firstblock);
1248 error = xfs_attr_leaf_to_node(args);
1250 error = xfs_bmap_finish(&args->trans,
1258 xfs_bmap_cancel(args->flist);
1263 * bmap_finish() may have committed the last trans
1264 * and started a new one. We need the inode to be
1265 * in all transactions.
1268 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1269 xfs_trans_ihold(args->trans, dp);
1273 * Commit the node conversion and start the next
1274 * trans in the chain.
1276 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1283 * Split as many Btree elements as required.
1284 * This code tracks the new and old attr's location
1285 * in the index/blkno/rmtblkno/rmtblkcnt fields and
1286 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
1288 XFS_BMAP_INIT(args->flist, args->firstblock);
1289 error = xfs_da_split(state);
1291 error = xfs_bmap_finish(&args->trans, args->flist,
1292 *args->firstblock, &committed);
1297 xfs_bmap_cancel(args->flist);
1302 * bmap_finish() may have committed the last trans and started
1303 * a new one. We need the inode to be in all transactions.
1306 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1307 xfs_trans_ihold(args->trans, dp);
1311 * Addition succeeded, update Btree hashvals.
1313 xfs_da_fixhashpath(state, &state->path);
1317 * Kill the state structure, we're done with it and need to
1318 * allow the buffers to come back later.
1320 xfs_da_state_free(state);
1324 * Commit the leaf addition or btree split and start the next
1325 * trans in the chain.
1327 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1331 * If there was an out-of-line value, allocate the blocks we
1332 * identified for its storage and copy the value. This is done
1333 * after we create the attribute so that we don't overflow the
1334 * maximum size of a transaction and/or hit a deadlock.
1336 if (args->rmtblkno > 0) {
1337 error = xfs_attr_rmtval_set(args);
1343 * If this is an atomic rename operation, we must "flip" the
1344 * incomplete flags on the "new" and "old" attribute/value pairs
1345 * so that one disappears and one appears atomically. Then we
1346 * must remove the "old" attribute/value pair.
1350 * In a separate transaction, set the incomplete flag on the
1351 * "old" attr and clear the incomplete flag on the "new" attr.
1353 error = xfs_attr_leaf_flipflags(args);
1358 * Dismantle the "old" attribute/value pair by removing
1359 * a "remote" value (if it exists).
1361 args->index = args->index2;
1362 args->blkno = args->blkno2;
1363 args->rmtblkno = args->rmtblkno2;
1364 args->rmtblkcnt = args->rmtblkcnt2;
1365 if (args->rmtblkno) {
1366 error = xfs_attr_rmtval_remove(args);
1372 * Re-find the "old" attribute entry after any split ops.
1373 * The INCOMPLETE flag means that we will find the "old"
1374 * attr, not the "new" one.
1376 args->flags |= XFS_ATTR_INCOMPLETE;
1377 state = xfs_da_state_alloc();
1380 state->blocksize = state->mp->m_sb.sb_blocksize;
1381 state->node_ents = state->mp->m_attr_node_ents;
1383 error = xfs_da_node_lookup_int(state, &retval);
1388 * Remove the name and update the hashvals in the tree.
1390 blk = &state->path.blk[ state->path.active-1 ];
1391 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1392 error = xfs_attr_leaf_remove(blk->bp, args);
1393 xfs_da_fixhashpath(state, &state->path);
1396 * Check to see if the tree needs to be collapsed.
1398 if (retval && (state->path.active > 1)) {
1399 XFS_BMAP_INIT(args->flist, args->firstblock);
1400 error = xfs_da_join(state);
1402 error = xfs_bmap_finish(&args->trans,
1410 xfs_bmap_cancel(args->flist);
1415 * bmap_finish() may have committed the last trans
1416 * and started a new one. We need the inode to be
1417 * in all transactions.
1420 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1421 xfs_trans_ihold(args->trans, dp);
1426 * Commit and start the next trans in the chain.
1428 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1431 } else if (args->rmtblkno > 0) {
1433 * Added a "remote" value, just clear the incomplete flag.
1435 error = xfs_attr_leaf_clearflag(args);
1443 xfs_da_state_free(state);
1450 * Remove a name from a B-tree attribute list.
1452 * This will involve walking down the Btree, and may involve joining
1453 * leaf nodes and even joining intermediate nodes up to and including
1454 * the root node (a special case of an intermediate node).
1457 xfs_attr_node_removename(xfs_da_args_t *args)
1459 xfs_da_state_t *state;
1460 xfs_da_state_blk_t *blk;
1463 int retval, error, committed, forkoff;
1466 * Tie a string around our finger to remind us where we are.
1469 state = xfs_da_state_alloc();
1471 state->mp = dp->i_mount;
1472 state->blocksize = state->mp->m_sb.sb_blocksize;
1473 state->node_ents = state->mp->m_attr_node_ents;
1476 * Search to see if name exists, and get back a pointer to it.
1478 error = xfs_da_node_lookup_int(state, &retval);
1479 if (error || (retval != EEXIST)) {
1486 * If there is an out-of-line value, de-allocate the blocks.
1487 * This is done before we remove the attribute so that we don't
1488 * overflow the maximum size of a transaction and/or hit a deadlock.
1490 blk = &state->path.blk[ state->path.active-1 ];
1491 ASSERT(blk->bp != NULL);
1492 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1493 if (args->rmtblkno > 0) {
1495 * Fill in disk block numbers in the state structure
1496 * so that we can get the buffers back after we commit
1497 * several transactions in the following calls.
1499 error = xfs_attr_fillstate(state);
1504 * Mark the attribute as INCOMPLETE, then bunmapi() the
1507 error = xfs_attr_leaf_setflag(args);
1510 error = xfs_attr_rmtval_remove(args);
1515 * Refill the state structure with buffers, the prior calls
1516 * released our buffers.
1518 error = xfs_attr_refillstate(state);
1524 * Remove the name and update the hashvals in the tree.
1526 blk = &state->path.blk[ state->path.active-1 ];
1527 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1528 retval = xfs_attr_leaf_remove(blk->bp, args);
1529 xfs_da_fixhashpath(state, &state->path);
1532 * Check to see if the tree needs to be collapsed.
1534 if (retval && (state->path.active > 1)) {
1535 XFS_BMAP_INIT(args->flist, args->firstblock);
1536 error = xfs_da_join(state);
1538 error = xfs_bmap_finish(&args->trans, args->flist,
1539 *args->firstblock, &committed);
1544 xfs_bmap_cancel(args->flist);
1549 * bmap_finish() may have committed the last trans and started
1550 * a new one. We need the inode to be in all transactions.
1553 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1554 xfs_trans_ihold(args->trans, dp);
1558 * Commit the Btree join operation and start a new trans.
1560 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1565 * If the result is small enough, push it all into the inode.
1567 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
1569 * Have to get rid of the copy of this dabuf in the state.
1571 ASSERT(state->path.active == 1);
1572 ASSERT(state->path.blk[0].bp);
1573 xfs_da_buf_done(state->path.blk[0].bp);
1574 state->path.blk[0].bp = NULL;
1576 error = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp,
1580 ASSERT(INT_GET(((xfs_attr_leafblock_t *)
1581 bp->data)->hdr.info.magic, ARCH_CONVERT)
1582 == XFS_ATTR_LEAF_MAGIC);
1584 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1585 XFS_BMAP_INIT(args->flist, args->firstblock);
1586 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1587 /* bp is gone due to xfs_da_shrink_inode */
1589 error = xfs_bmap_finish(&args->trans,
1597 xfs_bmap_cancel(args->flist);
1602 * bmap_finish() may have committed the last trans
1603 * and started a new one. We need the inode to be
1604 * in all transactions.
1607 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1608 xfs_trans_ihold(args->trans, dp);
1611 xfs_da_brelse(args->trans, bp);
1616 xfs_da_state_free(state);
1621 * Fill in the disk block numbers in the state structure for the buffers
1622 * that are attached to the state structure.
1623 * This is done so that we can quickly reattach ourselves to those buffers
1624 * after some set of transaction commit's has released these buffers.
1627 xfs_attr_fillstate(xfs_da_state_t *state)
1629 xfs_da_state_path_t *path;
1630 xfs_da_state_blk_t *blk;
1634 * Roll down the "path" in the state structure, storing the on-disk
1635 * block number for those buffers in the "path".
1637 path = &state->path;
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;
1650 * Roll down the "altpath" in the state structure, storing the on-disk
1651 * block number for those buffers in the "altpath".
1653 path = &state->altpath;
1654 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1655 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1657 blk->disk_blkno = xfs_da_blkno(blk->bp);
1658 xfs_da_buf_done(blk->bp);
1661 blk->disk_blkno = 0;
1669 * Reattach the buffers to the state structure based on the disk block
1670 * numbers stored in the state structure.
1671 * This is done after some set of transaction commit's has released those
1672 * buffers from our grip.
1675 xfs_attr_refillstate(xfs_da_state_t *state)
1677 xfs_da_state_path_t *path;
1678 xfs_da_state_blk_t *blk;
1682 * Roll down the "path" in the state structure, storing the on-disk
1683 * block number for those buffers in the "path".
1685 path = &state->path;
1686 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1687 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1688 if (blk->disk_blkno) {
1689 error = xfs_da_read_buf(state->args->trans,
1691 blk->blkno, blk->disk_blkno,
1692 &blk->bp, XFS_ATTR_FORK);
1701 * Roll down the "altpath" in the state structure, storing the on-disk
1702 * block number for those buffers in the "altpath".
1704 path = &state->altpath;
1705 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1706 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1707 if (blk->disk_blkno) {
1708 error = xfs_da_read_buf(state->args->trans,
1710 blk->blkno, blk->disk_blkno,
1711 &blk->bp, XFS_ATTR_FORK);
1723 * Look up a filename in a node attribute list.
1725 * This routine gets called for any attribute fork that has more than one
1726 * block, ie: both true Btree attr lists and for single-leaf-blocks with
1727 * "remote" values taking up more blocks.
1730 xfs_attr_node_get(xfs_da_args_t *args)
1732 xfs_da_state_t *state;
1733 xfs_da_state_blk_t *blk;
1737 state = xfs_da_state_alloc();
1739 state->mp = args->dp->i_mount;
1740 state->blocksize = state->mp->m_sb.sb_blocksize;
1741 state->node_ents = state->mp->m_attr_node_ents;
1744 * Search to see if name exists, and get back a pointer to it.
1746 error = xfs_da_node_lookup_int(state, &retval);
1749 } else if (retval == EEXIST) {
1750 blk = &state->path.blk[ state->path.active-1 ];
1751 ASSERT(blk->bp != NULL);
1752 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1755 * Get the value, local or "remote"
1757 retval = xfs_attr_leaf_getvalue(blk->bp, args);
1758 if (!retval && (args->rmtblkno > 0)
1759 && !(args->flags & ATTR_KERNOVAL)) {
1760 retval = xfs_attr_rmtval_get(args);
1765 * If not in a transaction, we have to release all the buffers.
1767 for (i = 0; i < state->path.active; i++) {
1768 xfs_da_brelse(args->trans, state->path.blk[i].bp);
1769 state->path.blk[i].bp = NULL;
1772 xfs_da_state_free(state);
1776 STATIC int /* error */
1777 xfs_attr_node_list(xfs_attr_list_context_t *context)
1779 attrlist_cursor_kern_t *cursor;
1780 xfs_attr_leafblock_t *leaf;
1781 xfs_da_intnode_t *node;
1782 xfs_da_node_entry_t *btree;
1786 cursor = context->cursor;
1787 cursor->initted = 1;
1790 * Do all sorts of validation on the passed-in cursor structure.
1791 * If anything is amiss, ignore the cursor and look up the hashval
1792 * starting from the btree root.
1795 if (cursor->blkno > 0) {
1796 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1797 &bp, XFS_ATTR_FORK);
1798 if ((error != 0) && (error != EFSCORRUPTED))
1802 switch (INT_GET(node->hdr.info.magic, ARCH_CONVERT)) {
1803 case XFS_DA_NODE_MAGIC:
1804 xfs_attr_trace_l_cn("wrong blk", context, node);
1805 xfs_da_brelse(NULL, bp);
1808 case XFS_ATTR_LEAF_MAGIC:
1810 if (cursor->hashval >
1811 INT_GET(leaf->entries[
1812 INT_GET(leaf->hdr.count,
1813 ARCH_CONVERT)-1].hashval,
1815 xfs_attr_trace_l_cl("wrong blk",
1817 xfs_da_brelse(NULL, bp);
1819 } else if (cursor->hashval <=
1820 INT_GET(leaf->entries[0].hashval,
1822 xfs_attr_trace_l_cl("maybe wrong blk",
1824 xfs_da_brelse(NULL, bp);
1829 xfs_attr_trace_l_c("wrong blk - ??", context);
1830 xfs_da_brelse(NULL, bp);
1837 * We did not find what we expected given the cursor's contents,
1838 * so we start from the top and work down based on the hash value.
1839 * Note that start of node block is same as start of leaf block.
1844 error = xfs_da_read_buf(NULL, context->dp,
1845 cursor->blkno, -1, &bp,
1849 if (unlikely(bp == NULL)) {
1850 XFS_ERROR_REPORT("xfs_attr_node_list(2)",
1852 context->dp->i_mount);
1853 return(XFS_ERROR(EFSCORRUPTED));
1856 if (INT_GET(node->hdr.info.magic, ARCH_CONVERT)
1857 == XFS_ATTR_LEAF_MAGIC)
1859 if (unlikely(INT_GET(node->hdr.info.magic, ARCH_CONVERT)
1860 != XFS_DA_NODE_MAGIC)) {
1861 XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
1863 context->dp->i_mount,
1865 xfs_da_brelse(NULL, bp);
1866 return(XFS_ERROR(EFSCORRUPTED));
1868 btree = node->btree;
1870 i < INT_GET(node->hdr.count, ARCH_CONVERT);
1873 <= INT_GET(btree->hashval,
1875 cursor->blkno = INT_GET(btree->before, ARCH_CONVERT);
1876 xfs_attr_trace_l_cb("descending",
1881 if (i == INT_GET(node->hdr.count, ARCH_CONVERT)) {
1882 xfs_da_brelse(NULL, bp);
1885 xfs_da_brelse(NULL, bp);
1891 * Roll upward through the blocks, processing each leaf block in
1892 * order. As long as there is space in the result buffer, keep
1893 * adding the information.
1897 if (unlikely(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
1898 != XFS_ATTR_LEAF_MAGIC)) {
1899 XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
1901 context->dp->i_mount, leaf);
1902 xfs_da_brelse(NULL, bp);
1903 return(XFS_ERROR(EFSCORRUPTED));
1905 error = xfs_attr_leaf_list_int(bp, context);
1906 if (error || !leaf->hdr.info.forw)
1907 break; /* not really an error, buffer full or EOF */
1908 cursor->blkno = INT_GET(leaf->hdr.info.forw, ARCH_CONVERT);
1909 xfs_da_brelse(NULL, bp);
1910 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1911 &bp, XFS_ATTR_FORK);
1914 if (unlikely((bp == NULL))) {
1915 XFS_ERROR_REPORT("xfs_attr_node_list(5)",
1917 context->dp->i_mount);
1918 return(XFS_ERROR(EFSCORRUPTED));
1921 xfs_da_brelse(NULL, bp);
1926 /*========================================================================
1927 * External routines for manipulating out-of-line attribute values.
1928 *========================================================================*/
1931 * Read the value associated with an attribute from the out-of-line buffer
1932 * that we stored it in.
1935 xfs_attr_rmtval_get(xfs_da_args_t *args)
1937 xfs_bmbt_irec_t map[ATTR_RMTVALUE_MAPSIZE];
1942 int nmap, error, tmp, valuelen, blkcnt, i;
1945 ASSERT(!(args->flags & ATTR_KERNOVAL));
1947 mp = args->dp->i_mount;
1949 valuelen = args->valuelen;
1950 lblkno = args->rmtblkno;
1951 while (valuelen > 0) {
1952 nmap = ATTR_RMTVALUE_MAPSIZE;
1953 error = xfs_bmapi(args->trans, args->dp, (xfs_fileoff_t)lblkno,
1955 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
1956 NULL, 0, map, &nmap, NULL);
1961 for (i = 0; (i < nmap) && (valuelen > 0); i++) {
1962 ASSERT((map[i].br_startblock != DELAYSTARTBLOCK) &&
1963 (map[i].br_startblock != HOLESTARTBLOCK));
1964 dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
1965 blkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
1966 error = xfs_read_buf(mp, mp->m_ddev_targp, dblkno,
1967 blkcnt, XFS_BUF_LOCK, &bp);
1971 tmp = (valuelen < XFS_BUF_SIZE(bp))
1972 ? valuelen : XFS_BUF_SIZE(bp);
1973 xfs_biomove(bp, 0, tmp, dst, XFS_B_READ);
1978 lblkno += map[i].br_blockcount;
1981 ASSERT(valuelen == 0);
1986 * Write the value associated with an attribute into the out-of-line buffer
1987 * that we have defined for it.
1990 xfs_attr_rmtval_set(xfs_da_args_t *args)
1993 xfs_fileoff_t lfileoff;
1995 xfs_bmbt_irec_t map;
2000 int blkcnt, valuelen, nmap, error, tmp, committed;
2007 * Find a "hole" in the attribute address space large enough for
2008 * us to drop the new attribute's value into.
2010 blkcnt = XFS_B_TO_FSB(mp, args->valuelen);
2012 error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff,
2017 args->rmtblkno = lblkno = (xfs_dablk_t)lfileoff;
2018 args->rmtblkcnt = blkcnt;
2021 * Roll through the "value", allocating blocks on disk as required.
2023 while (blkcnt > 0) {
2025 * Allocate a single extent, up to the size of the value.
2027 XFS_BMAP_INIT(args->flist, args->firstblock);
2029 error = xfs_bmapi(args->trans, dp, (xfs_fileoff_t)lblkno,
2031 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA |
2033 args->firstblock, args->total, &map, &nmap,
2036 error = xfs_bmap_finish(&args->trans, args->flist,
2037 *args->firstblock, &committed);
2042 xfs_bmap_cancel(args->flist);
2047 * bmap_finish() may have committed the last trans and started
2048 * a new one. We need the inode to be in all transactions.
2051 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
2052 xfs_trans_ihold(args->trans, dp);
2056 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2057 (map.br_startblock != HOLESTARTBLOCK));
2058 lblkno += map.br_blockcount;
2059 blkcnt -= map.br_blockcount;
2062 * Start the next trans in the chain.
2064 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
2069 * Roll through the "value", copying the attribute value to the
2070 * already-allocated blocks. Blocks are written synchronously
2071 * so that we can know they are all on disk before we turn off
2072 * the INCOMPLETE flag.
2074 lblkno = args->rmtblkno;
2075 valuelen = args->valuelen;
2076 while (valuelen > 0) {
2078 * Try to remember where we decided to put the value.
2080 XFS_BMAP_INIT(args->flist, args->firstblock);
2082 error = xfs_bmapi(NULL, dp, (xfs_fileoff_t)lblkno,
2084 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2085 args->firstblock, 0, &map, &nmap, NULL);
2090 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2091 (map.br_startblock != HOLESTARTBLOCK));
2093 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2094 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2096 bp = xfs_buf_get_flags(mp->m_ddev_targp, dblkno,
2097 blkcnt, XFS_BUF_LOCK);
2099 ASSERT(!XFS_BUF_GETERROR(bp));
2101 tmp = (valuelen < XFS_BUF_SIZE(bp)) ? valuelen :
2103 xfs_biomove(bp, 0, tmp, src, XFS_B_WRITE);
2104 if (tmp < XFS_BUF_SIZE(bp))
2105 xfs_biozero(bp, tmp, XFS_BUF_SIZE(bp) - tmp);
2106 if ((error = xfs_bwrite(mp, bp))) {/* GROT: NOTE: synchronous write */
2112 lblkno += map.br_blockcount;
2114 ASSERT(valuelen == 0);
2119 * Remove the value associated with an attribute by deleting the
2120 * out-of-line buffer that it is stored on.
2123 xfs_attr_rmtval_remove(xfs_da_args_t *args)
2126 xfs_bmbt_irec_t map;
2130 int valuelen, blkcnt, nmap, error, done, committed;
2132 mp = args->dp->i_mount;
2135 * Roll through the "value", invalidating the attribute value's
2138 lblkno = args->rmtblkno;
2139 valuelen = args->rmtblkcnt;
2140 while (valuelen > 0) {
2142 * Try to remember where we decided to put the value.
2144 XFS_BMAP_INIT(args->flist, args->firstblock);
2146 error = xfs_bmapi(NULL, args->dp, (xfs_fileoff_t)lblkno,
2148 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2149 args->firstblock, 0, &map, &nmap,
2155 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2156 (map.br_startblock != HOLESTARTBLOCK));
2158 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2159 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2162 * If the "remote" value is in the cache, remove it.
2164 bp = xfs_incore(mp->m_ddev_targp, dblkno, blkcnt,
2165 XFS_INCORE_TRYLOCK);
2168 XFS_BUF_UNDELAYWRITE(bp);
2173 valuelen -= map.br_blockcount;
2175 lblkno += map.br_blockcount;
2179 * Keep de-allocating extents until the remote-value region is gone.
2181 lblkno = args->rmtblkno;
2182 blkcnt = args->rmtblkcnt;
2185 XFS_BMAP_INIT(args->flist, args->firstblock);
2186 error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
2187 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2188 1, args->firstblock, args->flist, &done);
2190 error = xfs_bmap_finish(&args->trans, args->flist,
2191 *args->firstblock, &committed);
2196 xfs_bmap_cancel(args->flist);
2201 * bmap_finish() may have committed the last trans and started
2202 * a new one. We need the inode to be in all transactions.
2205 xfs_trans_ijoin(args->trans, args->dp, XFS_ILOCK_EXCL);
2206 xfs_trans_ihold(args->trans, args->dp);
2210 * Close out trans and start the next one in the chain.
2212 if ((error = xfs_attr_rolltrans(&args->trans, args->dp)))
2218 #if defined(XFS_ATTR_TRACE)
2220 * Add a trace buffer entry for an attr_list context structure.
2223 xfs_attr_trace_l_c(char *where, struct xfs_attr_list_context *context)
2225 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_C, where,
2226 (__psunsigned_t)context->dp,
2227 (__psunsigned_t)context->cursor->hashval,
2228 (__psunsigned_t)context->cursor->blkno,
2229 (__psunsigned_t)context->cursor->offset,
2230 (__psunsigned_t)context->alist,
2231 (__psunsigned_t)context->bufsize,
2232 (__psunsigned_t)context->count,
2233 (__psunsigned_t)context->firstu,
2235 ((context->count > 0) &&
2236 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2237 ? (ATTR_ENTRY(context->alist,
2238 context->count-1)->a_valuelen)
2240 (__psunsigned_t)context->dupcnt,
2241 (__psunsigned_t)context->flags,
2242 (__psunsigned_t)NULL,
2243 (__psunsigned_t)NULL,
2244 (__psunsigned_t)NULL);
2248 * Add a trace buffer entry for a context structure and a Btree node.
2251 xfs_attr_trace_l_cn(char *where, struct xfs_attr_list_context *context,
2252 struct xfs_da_intnode *node)
2254 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CN, where,
2255 (__psunsigned_t)context->dp,
2256 (__psunsigned_t)context->cursor->hashval,
2257 (__psunsigned_t)context->cursor->blkno,
2258 (__psunsigned_t)context->cursor->offset,
2259 (__psunsigned_t)context->alist,
2260 (__psunsigned_t)context->bufsize,
2261 (__psunsigned_t)context->count,
2262 (__psunsigned_t)context->firstu,
2264 ((context->count > 0) &&
2265 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2266 ? (ATTR_ENTRY(context->alist,
2267 context->count-1)->a_valuelen)
2269 (__psunsigned_t)context->dupcnt,
2270 (__psunsigned_t)context->flags,
2271 (__psunsigned_t)INT_GET(node->hdr.count, ARCH_CONVERT),
2272 (__psunsigned_t)INT_GET(node->btree[0].hashval, ARCH_CONVERT),
2273 (__psunsigned_t)INT_GET(node->btree[INT_GET(node->hdr.count, ARCH_CONVERT)-1].hashval, ARCH_CONVERT));
2277 * Add a trace buffer entry for a context structure and a Btree element.
2280 xfs_attr_trace_l_cb(char *where, struct xfs_attr_list_context *context,
2281 struct xfs_da_node_entry *btree)
2283 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CB, where,
2284 (__psunsigned_t)context->dp,
2285 (__psunsigned_t)context->cursor->hashval,
2286 (__psunsigned_t)context->cursor->blkno,
2287 (__psunsigned_t)context->cursor->offset,
2288 (__psunsigned_t)context->alist,
2289 (__psunsigned_t)context->bufsize,
2290 (__psunsigned_t)context->count,
2291 (__psunsigned_t)context->firstu,
2293 ((context->count > 0) &&
2294 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2295 ? (ATTR_ENTRY(context->alist,
2296 context->count-1)->a_valuelen)
2298 (__psunsigned_t)context->dupcnt,
2299 (__psunsigned_t)context->flags,
2300 (__psunsigned_t)INT_GET(btree->hashval, ARCH_CONVERT),
2301 (__psunsigned_t)INT_GET(btree->before, ARCH_CONVERT),
2302 (__psunsigned_t)NULL);
2306 * Add a trace buffer entry for a context structure and a leaf block.
2309 xfs_attr_trace_l_cl(char *where, struct xfs_attr_list_context *context,
2310 struct xfs_attr_leafblock *leaf)
2312 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CL, where,
2313 (__psunsigned_t)context->dp,
2314 (__psunsigned_t)context->cursor->hashval,
2315 (__psunsigned_t)context->cursor->blkno,
2316 (__psunsigned_t)context->cursor->offset,
2317 (__psunsigned_t)context->alist,
2318 (__psunsigned_t)context->bufsize,
2319 (__psunsigned_t)context->count,
2320 (__psunsigned_t)context->firstu,
2322 ((context->count > 0) &&
2323 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2324 ? (ATTR_ENTRY(context->alist,
2325 context->count-1)->a_valuelen)
2327 (__psunsigned_t)context->dupcnt,
2328 (__psunsigned_t)context->flags,
2329 (__psunsigned_t)INT_GET(leaf->hdr.count, ARCH_CONVERT),
2330 (__psunsigned_t)INT_GET(leaf->entries[0].hashval, ARCH_CONVERT),
2331 (__psunsigned_t)INT_GET(leaf->entries[INT_GET(leaf->hdr.count, ARCH_CONVERT)-1].hashval, ARCH_CONVERT));
2335 * Add a trace buffer entry for the arguments given to the routine,
2339 xfs_attr_trace_enter(int type, char *where,
2340 __psunsigned_t a2, __psunsigned_t a3,
2341 __psunsigned_t a4, __psunsigned_t a5,
2342 __psunsigned_t a6, __psunsigned_t a7,
2343 __psunsigned_t a8, __psunsigned_t a9,
2344 __psunsigned_t a10, __psunsigned_t a11,
2345 __psunsigned_t a12, __psunsigned_t a13,
2346 __psunsigned_t a14, __psunsigned_t a15)
2348 ASSERT(xfs_attr_trace_buf);
2349 ktrace_enter(xfs_attr_trace_buf, (void *)((__psunsigned_t)type),
2351 (void *)a2, (void *)a3, (void *)a4,
2352 (void *)a5, (void *)a6, (void *)a7,
2353 (void *)a8, (void *)a9, (void *)a10,
2354 (void *)a11, (void *)a12, (void *)a13,
2355 (void *)a14, (void *)a15);
2357 #endif /* XFS_ATTR_TRACE */
2360 /*========================================================================
2361 * System (pseudo) namespace attribute interface routines.
2362 *========================================================================*/
2365 posix_acl_access_set(
2366 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2368 return xfs_acl_vset(vp, data, size, _ACL_TYPE_ACCESS);
2372 posix_acl_access_remove(
2373 struct vnode *vp, char *name, int xflags)
2375 return xfs_acl_vremove(vp, _ACL_TYPE_ACCESS);
2379 posix_acl_access_get(
2380 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2382 return xfs_acl_vget(vp, data, size, _ACL_TYPE_ACCESS);
2386 posix_acl_access_exists(
2389 return xfs_acl_vhasacl_access(vp);
2393 posix_acl_default_set(
2394 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2396 return xfs_acl_vset(vp, data, size, _ACL_TYPE_DEFAULT);
2400 posix_acl_default_get(
2401 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2403 return xfs_acl_vget(vp, data, size, _ACL_TYPE_DEFAULT);
2407 posix_acl_default_remove(
2408 struct vnode *vp, char *name, int xflags)
2410 return xfs_acl_vremove(vp, _ACL_TYPE_DEFAULT);
2414 posix_acl_default_exists(
2417 return xfs_acl_vhasacl_default(vp);
2420 STATIC struct attrnames posix_acl_access = {
2421 .attr_name = "posix_acl_access",
2422 .attr_namelen = sizeof("posix_acl_access") - 1,
2423 .attr_get = posix_acl_access_get,
2424 .attr_set = posix_acl_access_set,
2425 .attr_remove = posix_acl_access_remove,
2426 .attr_exists = posix_acl_access_exists,
2429 STATIC struct attrnames posix_acl_default = {
2430 .attr_name = "posix_acl_default",
2431 .attr_namelen = sizeof("posix_acl_default") - 1,
2432 .attr_get = posix_acl_default_get,
2433 .attr_set = posix_acl_default_set,
2434 .attr_remove = posix_acl_default_remove,
2435 .attr_exists = posix_acl_default_exists,
2438 STATIC struct attrnames *attr_system_names[] =
2439 { &posix_acl_access, &posix_acl_default };
2442 /*========================================================================
2443 * Namespace-prefix-style attribute name interface routines.
2444 *========================================================================*/
2448 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2452 VOP_ATTR_SET(vp, name, data, size, xflags, NULL, error);
2458 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2460 int error, asize = size;
2462 VOP_ATTR_GET(vp, name, data, &asize, xflags, NULL, error);
2469 attr_generic_remove(
2470 struct vnode *vp, char *name, int xflags)
2474 VOP_ATTR_REMOVE(vp, name, xflags, NULL, error);
2479 attr_generic_listadd(
2480 attrnames_t *prefix,
2481 attrnames_t *namesp,
2486 char *p = data + *result;
2488 *result += prefix->attr_namelen;
2489 *result += namesp->attr_namelen + 1;
2494 strcpy(p, prefix->attr_name);
2495 p += prefix->attr_namelen;
2496 strcpy(p, namesp->attr_name);
2497 p += namesp->attr_namelen + 1;
2508 attrnames_t *namesp;
2511 for (i = 0; i < ATTR_SYSCOUNT; i++) {
2512 namesp = attr_system_names[i];
2513 if (!namesp->attr_exists || !namesp->attr_exists(vp))
2515 error = attr_generic_listadd(&attr_system, namesp,
2516 data, size, result);
2525 struct vnode *vp, void *data, size_t size, int xflags, ssize_t *result)
2527 attrlist_cursor_kern_t cursor = { 0 };
2530 VOP_ATTR_LIST(vp, data, size, xflags, &cursor, NULL, error);
2534 return attr_system_list(vp, data, size, result);
2538 attr_lookup_namespace(
2540 struct attrnames **names,
2545 for (i = 0; i < nnames; i++)
2546 if (!strncmp(name, names[i]->attr_name, names[i]->attr_namelen))
2552 * Some checks to prevent people abusing EAs to get over quota:
2553 * - Don't allow modifying user EAs on devices/symlinks;
2554 * - Don't allow modifying user EAs if sticky bit set;
2561 struct inode *inode = LINVFS_GET_IP(vp);
2563 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2565 if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode) &&
2566 !capable(CAP_SYS_ADMIN))
2568 if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) &&
2569 (current_fsuid(cred) != inode->i_uid) && !capable(CAP_FOWNER))
2575 attr_trusted_capable(
2579 struct inode *inode = LINVFS_GET_IP(vp);
2581 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2583 if (!capable(CAP_SYS_ADMIN))
2589 attr_secure_capable(
2593 return -ENOSECURITY;
2598 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2600 attrnames_t *namesp;
2603 if (xflags & ATTR_CREATE)
2606 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2609 error = namesp->attr_set(vp, name, data, size, xflags);
2611 error = vn_revalidate(vp);
2617 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2619 attrnames_t *namesp;
2621 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2624 return namesp->attr_get(vp, name, data, size, xflags);
2629 struct vnode *vp, char *name, int xflags)
2631 attrnames_t *namesp;
2633 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2636 return namesp->attr_remove(vp, name, xflags);
2639 struct attrnames attr_system = {
2640 .attr_name = "system.",
2641 .attr_namelen = sizeof("system.") - 1,
2642 .attr_flag = ATTR_SYSTEM,
2643 .attr_get = attr_system_get,
2644 .attr_set = attr_system_set,
2645 .attr_remove = attr_system_remove,
2646 .attr_capable = (attrcapable_t)fs_noerr,
2649 struct attrnames attr_trusted = {
2650 .attr_name = "trusted.",
2651 .attr_namelen = sizeof("trusted.") - 1,
2652 .attr_flag = ATTR_ROOT,
2653 .attr_get = attr_generic_get,
2654 .attr_set = attr_generic_set,
2655 .attr_remove = attr_generic_remove,
2656 .attr_capable = attr_trusted_capable,
2659 struct attrnames attr_secure = {
2660 .attr_name = "security.",
2661 .attr_namelen = sizeof("security.") - 1,
2662 .attr_flag = ATTR_SECURE,
2663 .attr_get = attr_generic_get,
2664 .attr_set = attr_generic_set,
2665 .attr_remove = attr_generic_remove,
2666 .attr_capable = attr_secure_capable,
2669 struct attrnames attr_user = {
2670 .attr_name = "user.",
2671 .attr_namelen = sizeof("user.") - 1,
2672 .attr_get = attr_generic_get,
2673 .attr_set = attr_generic_set,
2674 .attr_remove = attr_generic_remove,
2675 .attr_capable = attr_user_capable,
2678 struct attrnames *attr_namespaces[] =
2679 { &attr_system, &attr_trusted, &attr_secure, &attr_user };