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, 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, 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, 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 * If the inode doesn't have an attribute fork, add one.
224 * (inode must not be locked when we call this routine)
226 if (XFS_IFORK_Q(dp) == 0) {
227 error = xfs_bmap_add_attrfork(dp, rsvd);
233 * Fill in the arg structure for this request.
235 memset((char *)&args, 0, sizeof(args));
237 args.namelen = namelen;
239 args.valuelen = valuelen;
241 args.hashval = xfs_da_hashname(args.name, args.namelen);
243 args.firstblock = &firstblock;
245 args.whichfork = XFS_ATTR_FORK;
248 /* Determine space new attribute will use, and if it will be inline
251 size = xfs_attr_leaf_newentsize(namelen, valuelen,
252 mp->m_sb.sb_blocksize, &local);
254 nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK);
256 if (size > (mp->m_sb.sb_blocksize >> 1)) {
257 /* Double split possible */
261 uint dblocks = XFS_B_TO_FSB(mp, valuelen);
262 /* Out of line attribute, cannot double split, but make
263 * room for the attribute value itself.
266 nblks += XFS_NEXTENTADD_SPACE_RES(mp, dblocks, XFS_ATTR_FORK);
269 /* Size is now blocks for attribute data */
273 * Start our first transaction of the day.
275 * All future transactions during this code must be "chained" off
276 * this one via the trans_dup() call. All transactions will contain
277 * the inode, and the inode will always be marked with trans_ihold().
278 * Since the inode will be locked in all transactions, we must log
279 * the inode in every transaction to let it float upward through
282 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_SET);
285 * Root fork attributes can use reserved data blocks for this
286 * operation if necessary
290 args.trans->t_flags |= XFS_TRANS_RESERVE;
292 if ((error = xfs_trans_reserve(args.trans, (uint) nblks,
293 XFS_ATTRSET_LOG_RES(mp, nblks),
294 0, XFS_TRANS_PERM_LOG_RES,
295 XFS_ATTRSET_LOG_COUNT))) {
296 xfs_trans_cancel(args.trans, 0);
299 xfs_ilock(dp, XFS_ILOCK_EXCL);
301 error = XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, args.trans, dp, nblks, 0,
302 rsvd ? XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES :
303 XFS_QMOPT_RES_REGBLKS);
305 xfs_iunlock(dp, XFS_ILOCK_EXCL);
306 xfs_trans_cancel(args.trans, XFS_TRANS_RELEASE_LOG_RES);
310 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
311 xfs_trans_ihold(args.trans, dp);
314 * If the attribute list is non-existant or a shortform list,
315 * upgrade it to a single-leaf-block attribute list.
317 if ((dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
318 ((dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS) &&
319 (dp->i_d.di_anextents == 0))) {
322 * Build initial attribute list (if required).
324 if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
325 (void)xfs_attr_shortform_create(&args);
328 * Try to add the attr to the attribute list in
331 error = xfs_attr_shortform_addname(&args);
332 if (error != ENOSPC) {
334 * Commit the shortform mods, and we're done.
335 * NOTE: this is also the error path (EEXIST, etc).
337 ASSERT(args.trans != NULL);
340 * If this is a synchronous mount, make sure that
341 * the transaction goes to disk before returning
344 if (mp->m_flags & XFS_MOUNT_WSYNC) {
345 xfs_trans_set_sync(args.trans);
347 err2 = xfs_trans_commit(args.trans,
348 XFS_TRANS_RELEASE_LOG_RES,
350 xfs_iunlock(dp, XFS_ILOCK_EXCL);
353 * Hit the inode change time.
355 if (!error && (flags & ATTR_KERNOTIME) == 0) {
356 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
358 return(error == 0 ? err2 : error);
362 * It won't fit in the shortform, transform to a leaf block.
363 * GROT: another possible req'mt for a double-split btree op.
365 XFS_BMAP_INIT(args.flist, args.firstblock);
366 error = xfs_attr_shortform_to_leaf(&args);
368 error = xfs_bmap_finish(&args.trans, args.flist,
369 *args.firstblock, &committed);
374 xfs_bmap_cancel(&flist);
379 * bmap_finish() may have committed the last trans and started
380 * a new one. We need the inode to be in all transactions.
383 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
384 xfs_trans_ihold(args.trans, dp);
388 * Commit the leaf transformation. We'll need another (linked)
389 * transaction to add the new attribute to the leaf.
391 if ((error = xfs_attr_rolltrans(&args.trans, dp)))
396 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
397 error = xfs_attr_leaf_addname(&args);
399 error = xfs_attr_node_addname(&args);
406 * If this is a synchronous mount, make sure that the
407 * transaction goes to disk before returning to the user.
409 if (mp->m_flags & XFS_MOUNT_WSYNC) {
410 xfs_trans_set_sync(args.trans);
414 * Commit the last in the sequence of transactions.
416 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
417 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES,
419 xfs_iunlock(dp, XFS_ILOCK_EXCL);
422 * Hit the inode change time.
424 if (!error && (flags & ATTR_KERNOTIME) == 0) {
425 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
432 xfs_trans_cancel(args.trans,
433 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
434 xfs_iunlock(dp, XFS_ILOCK_EXCL);
439 xfs_attr_set(bhv_desc_t *bdp, char *name, char *value, int valuelen, int flags,
445 namelen = strlen(name);
446 if (namelen >= MAXNAMELEN)
447 return EFAULT; /* match IRIX behaviour */
449 XFS_STATS_INC(xs_attr_set);
451 dp = XFS_BHVTOI(bdp);
452 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
455 xfs_ilock(dp, XFS_ILOCK_SHARED);
456 if (!(flags & ATTR_SECURE) &&
457 (error = xfs_iaccess(dp, S_IWUSR, cred))) {
458 xfs_iunlock(dp, XFS_ILOCK_SHARED);
459 return(XFS_ERROR(error));
461 xfs_iunlock(dp, XFS_ILOCK_SHARED);
463 return xfs_attr_set_int(dp, name, namelen, value, valuelen, flags);
467 * Generic handler routine to remove a name from an attribute list.
468 * Transitions attribute list from Btree to shortform as necessary.
471 xfs_attr_remove_int(xfs_inode_t *dp, char *name, int namelen, int flags)
474 xfs_fsblock_t firstblock;
475 xfs_bmap_free_t flist;
477 xfs_mount_t *mp = dp->i_mount;
480 * Fill in the arg structure for this request.
482 memset((char *)&args, 0, sizeof(args));
484 args.namelen = namelen;
486 args.hashval = xfs_da_hashname(args.name, args.namelen);
488 args.firstblock = &firstblock;
491 args.whichfork = XFS_ATTR_FORK;
494 * Attach the dquots to the inode.
496 if ((error = XFS_QM_DQATTACH(mp, dp, 0)))
500 * Start our first transaction of the day.
502 * All future transactions during this code must be "chained" off
503 * this one via the trans_dup() call. All transactions will contain
504 * the inode, and the inode will always be marked with trans_ihold().
505 * Since the inode will be locked in all transactions, we must log
506 * the inode in every transaction to let it float upward through
509 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_RM);
512 * Root fork attributes can use reserved data blocks for this
513 * operation if necessary
516 if (flags & ATTR_ROOT)
517 args.trans->t_flags |= XFS_TRANS_RESERVE;
519 if ((error = xfs_trans_reserve(args.trans,
520 XFS_ATTRRM_SPACE_RES(mp),
521 XFS_ATTRRM_LOG_RES(mp),
522 0, XFS_TRANS_PERM_LOG_RES,
523 XFS_ATTRRM_LOG_COUNT))) {
524 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, 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)
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 newsize = XFS_ATTR_SF_TOTSIZE(args->dp);
838 newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen);
839 if ((newsize <= XFS_IFORK_ASIZE(args->dp)) &&
840 (args->namelen < XFS_ATTR_SF_ENTSIZE_MAX) &&
841 (args->valuelen < XFS_ATTR_SF_ENTSIZE_MAX)) {
842 retval = xfs_attr_shortform_add(args);
845 return(XFS_ERROR(ENOSPC));
851 /*========================================================================
852 * External routines when attribute list is one block
853 *========================================================================*/
856 * Add a name to the leaf attribute list structure
858 * This leaf block cannot have a "remote" value, we only call this routine
859 * if bmap_one_block() says there is only one block (ie: no remote blks).
862 xfs_attr_leaf_addname(xfs_da_args_t *args)
866 int retval, error, committed;
869 * Read the (only) block in the attribute list in.
873 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
880 * Look up the given attribute in the leaf block. Figure out if
881 * the given flags produce an error or call for an atomic rename.
883 retval = xfs_attr_leaf_lookup_int(bp, args);
884 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
885 xfs_da_brelse(args->trans, bp);
887 } else if (retval == EEXIST) {
888 if (args->flags & ATTR_CREATE) { /* pure create op */
889 xfs_da_brelse(args->trans, bp);
892 args->rename = 1; /* an atomic rename */
893 args->blkno2 = args->blkno; /* set 2nd entry info*/
894 args->index2 = args->index;
895 args->rmtblkno2 = args->rmtblkno;
896 args->rmtblkcnt2 = args->rmtblkcnt;
900 * Add the attribute to the leaf block, transitioning to a Btree
903 retval = xfs_attr_leaf_add(bp, args);
905 if (retval == ENOSPC) {
907 * Promote the attribute list to the Btree format, then
908 * Commit that transaction so that the node_addname() call
909 * can manage its own transactions.
911 XFS_BMAP_INIT(args->flist, args->firstblock);
912 error = xfs_attr_leaf_to_node(args);
914 error = xfs_bmap_finish(&args->trans, args->flist,
915 *args->firstblock, &committed);
920 xfs_bmap_cancel(args->flist);
925 * bmap_finish() may have committed the last trans and started
926 * a new one. We need the inode to be in all transactions.
929 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
930 xfs_trans_ihold(args->trans, dp);
934 * Commit the current trans (including the inode) and start
937 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
941 * Fob the whole rest of the problem off on the Btree code.
943 error = xfs_attr_node_addname(args);
948 * Commit the transaction that added the attr name so that
949 * later routines can manage their own transactions.
951 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
955 * If there was an out-of-line value, allocate the blocks we
956 * identified for its storage and copy the value. This is done
957 * after we create the attribute so that we don't overflow the
958 * maximum size of a transaction and/or hit a deadlock.
960 if (args->rmtblkno > 0) {
961 error = xfs_attr_rmtval_set(args);
967 * If this is an atomic rename operation, we must "flip" the
968 * incomplete flags on the "new" and "old" attribute/value pairs
969 * so that one disappears and one appears atomically. Then we
970 * must remove the "old" attribute/value pair.
974 * In a separate transaction, set the incomplete flag on the
975 * "old" attr and clear the incomplete flag on the "new" attr.
977 error = xfs_attr_leaf_flipflags(args);
982 * Dismantle the "old" attribute/value pair by removing
983 * a "remote" value (if it exists).
985 args->index = args->index2;
986 args->blkno = args->blkno2;
987 args->rmtblkno = args->rmtblkno2;
988 args->rmtblkcnt = args->rmtblkcnt2;
989 if (args->rmtblkno) {
990 error = xfs_attr_rmtval_remove(args);
996 * Read in the block containing the "old" attr, then
997 * remove the "old" attr from that block (neat, huh!)
999 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1,
1000 &bp, XFS_ATTR_FORK);
1004 (void)xfs_attr_leaf_remove(bp, args);
1007 * If the result is small enough, shrink it all into the inode.
1009 if (xfs_attr_shortform_allfit(bp, dp)) {
1010 XFS_BMAP_INIT(args->flist, args->firstblock);
1011 error = xfs_attr_leaf_to_shortform(bp, args);
1012 /* bp is gone due to xfs_da_shrink_inode */
1014 error = xfs_bmap_finish(&args->trans,
1022 xfs_bmap_cancel(args->flist);
1027 * bmap_finish() may have committed the last trans
1028 * and started a new one. We need the inode to be
1029 * in all transactions.
1032 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1033 xfs_trans_ihold(args->trans, dp);
1036 xfs_da_buf_done(bp);
1039 * Commit the remove and start the next trans in series.
1041 error = xfs_attr_rolltrans(&args->trans, dp);
1043 } else if (args->rmtblkno > 0) {
1045 * Added a "remote" value, just clear the incomplete flag.
1047 error = xfs_attr_leaf_clearflag(args);
1053 * Remove a name from the leaf attribute list structure
1055 * This leaf block cannot have a "remote" value, we only call this routine
1056 * if bmap_one_block() says there is only one block (ie: no remote blks).
1059 xfs_attr_leaf_removename(xfs_da_args_t *args)
1067 * Remove the attribute.
1071 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1078 error = xfs_attr_leaf_lookup_int(bp, args);
1079 if (error == ENOATTR) {
1080 xfs_da_brelse(args->trans, bp);
1084 (void)xfs_attr_leaf_remove(bp, args);
1087 * If the result is small enough, shrink it all into the inode.
1089 if (xfs_attr_shortform_allfit(bp, dp)) {
1090 XFS_BMAP_INIT(args->flist, args->firstblock);
1091 error = xfs_attr_leaf_to_shortform(bp, args);
1092 /* bp is gone due to xfs_da_shrink_inode */
1094 error = xfs_bmap_finish(&args->trans, args->flist,
1095 *args->firstblock, &committed);
1100 xfs_bmap_cancel(args->flist);
1105 * bmap_finish() may have committed the last trans and started
1106 * a new one. We need the inode to be in all transactions.
1109 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1110 xfs_trans_ihold(args->trans, dp);
1113 xfs_da_buf_done(bp);
1118 * Look up a name in a leaf attribute list structure.
1120 * This leaf block cannot have a "remote" value, we only call this routine
1121 * if bmap_one_block() says there is only one block (ie: no remote blks).
1124 xfs_attr_leaf_get(xfs_da_args_t *args)
1130 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1136 error = xfs_attr_leaf_lookup_int(bp, args);
1137 if (error != EEXIST) {
1138 xfs_da_brelse(args->trans, bp);
1141 error = xfs_attr_leaf_getvalue(bp, args);
1142 xfs_da_brelse(args->trans, bp);
1143 if (!error && (args->rmtblkno > 0) && !(args->flags & ATTR_KERNOVAL)) {
1144 error = xfs_attr_rmtval_get(args);
1150 * Copy out attribute entries for attr_list(), for leaf attribute lists.
1153 xfs_attr_leaf_list(xfs_attr_list_context_t *context)
1155 xfs_attr_leafblock_t *leaf;
1159 context->cursor->blkno = 0;
1160 error = xfs_da_read_buf(NULL, context->dp, 0, -1, &bp, XFS_ATTR_FORK);
1165 if (unlikely(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
1166 != XFS_ATTR_LEAF_MAGIC)) {
1167 XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW,
1168 context->dp->i_mount, leaf);
1169 xfs_da_brelse(NULL, bp);
1170 return(XFS_ERROR(EFSCORRUPTED));
1173 (void)xfs_attr_leaf_list_int(bp, context);
1174 xfs_da_brelse(NULL, bp);
1179 /*========================================================================
1180 * External routines when attribute list size > XFS_LBSIZE(mp).
1181 *========================================================================*/
1184 * Add a name to a Btree-format attribute list.
1186 * This will involve walking down the Btree, and may involve splitting
1187 * leaf nodes and even splitting intermediate nodes up to and including
1188 * the root node (a special case of an intermediate node).
1190 * "Remote" attribute values confuse the issue and atomic rename operations
1191 * add a whole extra layer of confusion on top of that.
1194 xfs_attr_node_addname(xfs_da_args_t *args)
1196 xfs_da_state_t *state;
1197 xfs_da_state_blk_t *blk;
1200 int committed, retval, error;
1203 * Fill in bucket of arguments/results/context to carry around.
1208 state = xfs_da_state_alloc();
1211 state->blocksize = state->mp->m_sb.sb_blocksize;
1212 state->node_ents = state->mp->m_attr_node_ents;
1215 * Search to see if name already exists, and get back a pointer
1216 * to where it should go.
1218 error = xfs_da_node_lookup_int(state, &retval);
1221 blk = &state->path.blk[ state->path.active-1 ];
1222 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1223 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
1225 } else if (retval == EEXIST) {
1226 if (args->flags & ATTR_CREATE)
1228 args->rename = 1; /* atomic rename op */
1229 args->blkno2 = args->blkno; /* set 2nd entry info*/
1230 args->index2 = args->index;
1231 args->rmtblkno2 = args->rmtblkno;
1232 args->rmtblkcnt2 = args->rmtblkcnt;
1234 args->rmtblkcnt = 0;
1237 retval = xfs_attr_leaf_add(blk->bp, state->args);
1238 if (retval == ENOSPC) {
1239 if (state->path.active == 1) {
1241 * Its really a single leaf node, but it had
1242 * out-of-line values so it looked like it *might*
1243 * have been a b-tree.
1245 xfs_da_state_free(state);
1246 XFS_BMAP_INIT(args->flist, args->firstblock);
1247 error = xfs_attr_leaf_to_node(args);
1249 error = xfs_bmap_finish(&args->trans,
1257 xfs_bmap_cancel(args->flist);
1262 * bmap_finish() may have committed the last trans
1263 * and started a new one. We need the inode to be
1264 * in all transactions.
1267 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1268 xfs_trans_ihold(args->trans, dp);
1272 * Commit the node conversion and start the next
1273 * trans in the chain.
1275 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1282 * Split as many Btree elements as required.
1283 * This code tracks the new and old attr's location
1284 * in the index/blkno/rmtblkno/rmtblkcnt fields and
1285 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
1287 XFS_BMAP_INIT(args->flist, args->firstblock);
1288 error = xfs_da_split(state);
1290 error = xfs_bmap_finish(&args->trans, args->flist,
1291 *args->firstblock, &committed);
1296 xfs_bmap_cancel(args->flist);
1301 * bmap_finish() may have committed the last trans and started
1302 * a new one. We need the inode to be in all transactions.
1305 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1306 xfs_trans_ihold(args->trans, dp);
1310 * Addition succeeded, update Btree hashvals.
1312 xfs_da_fixhashpath(state, &state->path);
1316 * Kill the state structure, we're done with it and need to
1317 * allow the buffers to come back later.
1319 xfs_da_state_free(state);
1323 * Commit the leaf addition or btree split and start the next
1324 * trans in the chain.
1326 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1330 * If there was an out-of-line value, allocate the blocks we
1331 * identified for its storage and copy the value. This is done
1332 * after we create the attribute so that we don't overflow the
1333 * maximum size of a transaction and/or hit a deadlock.
1335 if (args->rmtblkno > 0) {
1336 error = xfs_attr_rmtval_set(args);
1342 * If this is an atomic rename operation, we must "flip" the
1343 * incomplete flags on the "new" and "old" attribute/value pairs
1344 * so that one disappears and one appears atomically. Then we
1345 * must remove the "old" attribute/value pair.
1349 * In a separate transaction, set the incomplete flag on the
1350 * "old" attr and clear the incomplete flag on the "new" attr.
1352 error = xfs_attr_leaf_flipflags(args);
1357 * Dismantle the "old" attribute/value pair by removing
1358 * a "remote" value (if it exists).
1360 args->index = args->index2;
1361 args->blkno = args->blkno2;
1362 args->rmtblkno = args->rmtblkno2;
1363 args->rmtblkcnt = args->rmtblkcnt2;
1364 if (args->rmtblkno) {
1365 error = xfs_attr_rmtval_remove(args);
1371 * Re-find the "old" attribute entry after any split ops.
1372 * The INCOMPLETE flag means that we will find the "old"
1373 * attr, not the "new" one.
1375 args->flags |= XFS_ATTR_INCOMPLETE;
1376 state = xfs_da_state_alloc();
1379 state->blocksize = state->mp->m_sb.sb_blocksize;
1380 state->node_ents = state->mp->m_attr_node_ents;
1382 error = xfs_da_node_lookup_int(state, &retval);
1387 * Remove the name and update the hashvals in the tree.
1389 blk = &state->path.blk[ state->path.active-1 ];
1390 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1391 error = xfs_attr_leaf_remove(blk->bp, args);
1392 xfs_da_fixhashpath(state, &state->path);
1395 * Check to see if the tree needs to be collapsed.
1397 if (retval && (state->path.active > 1)) {
1398 XFS_BMAP_INIT(args->flist, args->firstblock);
1399 error = xfs_da_join(state);
1401 error = xfs_bmap_finish(&args->trans,
1409 xfs_bmap_cancel(args->flist);
1414 * bmap_finish() may have committed the last trans
1415 * and started a new one. We need the inode to be
1416 * in all transactions.
1419 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1420 xfs_trans_ihold(args->trans, dp);
1425 * Commit and start the next trans in the chain.
1427 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1430 } else if (args->rmtblkno > 0) {
1432 * Added a "remote" value, just clear the incomplete flag.
1434 error = xfs_attr_leaf_clearflag(args);
1442 xfs_da_state_free(state);
1449 * Remove a name from a B-tree attribute list.
1451 * This will involve walking down the Btree, and may involve joining
1452 * leaf nodes and even joining intermediate nodes up to and including
1453 * the root node (a special case of an intermediate node).
1456 xfs_attr_node_removename(xfs_da_args_t *args)
1458 xfs_da_state_t *state;
1459 xfs_da_state_blk_t *blk;
1462 int retval, error, committed;
1465 * Tie a string around our finger to remind us where we are.
1468 state = xfs_da_state_alloc();
1470 state->mp = dp->i_mount;
1471 state->blocksize = state->mp->m_sb.sb_blocksize;
1472 state->node_ents = state->mp->m_attr_node_ents;
1475 * Search to see if name exists, and get back a pointer to it.
1477 error = xfs_da_node_lookup_int(state, &retval);
1478 if (error || (retval != EEXIST)) {
1485 * If there is an out-of-line value, de-allocate the blocks.
1486 * This is done before we remove the attribute so that we don't
1487 * overflow the maximum size of a transaction and/or hit a deadlock.
1489 blk = &state->path.blk[ state->path.active-1 ];
1490 ASSERT(blk->bp != NULL);
1491 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1492 if (args->rmtblkno > 0) {
1494 * Fill in disk block numbers in the state structure
1495 * so that we can get the buffers back after we commit
1496 * several transactions in the following calls.
1498 error = xfs_attr_fillstate(state);
1503 * Mark the attribute as INCOMPLETE, then bunmapi() the
1506 error = xfs_attr_leaf_setflag(args);
1509 error = xfs_attr_rmtval_remove(args);
1514 * Refill the state structure with buffers, the prior calls
1515 * released our buffers.
1517 error = xfs_attr_refillstate(state);
1523 * Remove the name and update the hashvals in the tree.
1525 blk = &state->path.blk[ state->path.active-1 ];
1526 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1527 retval = xfs_attr_leaf_remove(blk->bp, args);
1528 xfs_da_fixhashpath(state, &state->path);
1531 * Check to see if the tree needs to be collapsed.
1533 if (retval && (state->path.active > 1)) {
1534 XFS_BMAP_INIT(args->flist, args->firstblock);
1535 error = xfs_da_join(state);
1537 error = xfs_bmap_finish(&args->trans, args->flist,
1538 *args->firstblock, &committed);
1543 xfs_bmap_cancel(args->flist);
1548 * bmap_finish() may have committed the last trans and started
1549 * a new one. We need the inode to be in all transactions.
1552 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1553 xfs_trans_ihold(args->trans, dp);
1557 * Commit the Btree join operation and start a new trans.
1559 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1564 * If the result is small enough, push it all into the inode.
1566 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
1568 * Have to get rid of the copy of this dabuf in the state.
1570 ASSERT(state->path.active == 1);
1571 ASSERT(state->path.blk[0].bp);
1572 xfs_da_buf_done(state->path.blk[0].bp);
1573 state->path.blk[0].bp = NULL;
1575 error = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp,
1579 ASSERT(INT_GET(((xfs_attr_leafblock_t *)
1580 bp->data)->hdr.info.magic, ARCH_CONVERT)
1581 == XFS_ATTR_LEAF_MAGIC);
1583 if (xfs_attr_shortform_allfit(bp, dp)) {
1584 XFS_BMAP_INIT(args->flist, args->firstblock);
1585 error = xfs_attr_leaf_to_shortform(bp, args);
1586 /* bp is gone due to xfs_da_shrink_inode */
1588 error = xfs_bmap_finish(&args->trans,
1596 xfs_bmap_cancel(args->flist);
1601 * bmap_finish() may have committed the last trans
1602 * and started a new one. We need the inode to be
1603 * in all transactions.
1606 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1607 xfs_trans_ihold(args->trans, dp);
1610 xfs_da_brelse(args->trans, bp);
1615 xfs_da_state_free(state);
1620 * Fill in the disk block numbers in the state structure for the buffers
1621 * that are attached to the state structure.
1622 * This is done so that we can quickly reattach ourselves to those buffers
1623 * after some set of transaction commit's has released these buffers.
1626 xfs_attr_fillstate(xfs_da_state_t *state)
1628 xfs_da_state_path_t *path;
1629 xfs_da_state_blk_t *blk;
1633 * Roll down the "path" in the state structure, storing the on-disk
1634 * block number for those buffers in the "path".
1636 path = &state->path;
1637 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1638 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1640 blk->disk_blkno = xfs_da_blkno(blk->bp);
1641 xfs_da_buf_done(blk->bp);
1644 blk->disk_blkno = 0;
1649 * Roll down the "altpath" in the state structure, storing the on-disk
1650 * block number for those buffers in the "altpath".
1652 path = &state->altpath;
1653 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1654 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1656 blk->disk_blkno = xfs_da_blkno(blk->bp);
1657 xfs_da_buf_done(blk->bp);
1660 blk->disk_blkno = 0;
1668 * Reattach the buffers to the state structure based on the disk block
1669 * numbers stored in the state structure.
1670 * This is done after some set of transaction commit's has released those
1671 * buffers from our grip.
1674 xfs_attr_refillstate(xfs_da_state_t *state)
1676 xfs_da_state_path_t *path;
1677 xfs_da_state_blk_t *blk;
1681 * Roll down the "path" in the state structure, storing the on-disk
1682 * block number for those buffers in the "path".
1684 path = &state->path;
1685 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1686 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1687 if (blk->disk_blkno) {
1688 error = xfs_da_read_buf(state->args->trans,
1690 blk->blkno, blk->disk_blkno,
1691 &blk->bp, XFS_ATTR_FORK);
1700 * Roll down the "altpath" in the state structure, storing the on-disk
1701 * block number for those buffers in the "altpath".
1703 path = &state->altpath;
1704 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1705 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1706 if (blk->disk_blkno) {
1707 error = xfs_da_read_buf(state->args->trans,
1709 blk->blkno, blk->disk_blkno,
1710 &blk->bp, XFS_ATTR_FORK);
1722 * Look up a filename in a node attribute list.
1724 * This routine gets called for any attribute fork that has more than one
1725 * block, ie: both true Btree attr lists and for single-leaf-blocks with
1726 * "remote" values taking up more blocks.
1729 xfs_attr_node_get(xfs_da_args_t *args)
1731 xfs_da_state_t *state;
1732 xfs_da_state_blk_t *blk;
1736 state = xfs_da_state_alloc();
1738 state->mp = args->dp->i_mount;
1739 state->blocksize = state->mp->m_sb.sb_blocksize;
1740 state->node_ents = state->mp->m_attr_node_ents;
1743 * Search to see if name exists, and get back a pointer to it.
1745 error = xfs_da_node_lookup_int(state, &retval);
1748 } else if (retval == EEXIST) {
1749 blk = &state->path.blk[ state->path.active-1 ];
1750 ASSERT(blk->bp != NULL);
1751 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1754 * Get the value, local or "remote"
1756 retval = xfs_attr_leaf_getvalue(blk->bp, args);
1757 if (!retval && (args->rmtblkno > 0)
1758 && !(args->flags & ATTR_KERNOVAL)) {
1759 retval = xfs_attr_rmtval_get(args);
1764 * If not in a transaction, we have to release all the buffers.
1766 for (i = 0; i < state->path.active; i++) {
1767 xfs_da_brelse(args->trans, state->path.blk[i].bp);
1768 state->path.blk[i].bp = NULL;
1771 xfs_da_state_free(state);
1775 STATIC int /* error */
1776 xfs_attr_node_list(xfs_attr_list_context_t *context)
1778 attrlist_cursor_kern_t *cursor;
1779 xfs_attr_leafblock_t *leaf;
1780 xfs_da_intnode_t *node;
1781 xfs_da_node_entry_t *btree;
1785 cursor = context->cursor;
1786 cursor->initted = 1;
1789 * Do all sorts of validation on the passed-in cursor structure.
1790 * If anything is amiss, ignore the cursor and look up the hashval
1791 * starting from the btree root.
1794 if (cursor->blkno > 0) {
1795 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1796 &bp, XFS_ATTR_FORK);
1797 if ((error != 0) && (error != EFSCORRUPTED))
1801 switch (INT_GET(node->hdr.info.magic, ARCH_CONVERT)) {
1802 case XFS_DA_NODE_MAGIC:
1803 xfs_attr_trace_l_cn("wrong blk", context, node);
1804 xfs_da_brelse(NULL, bp);
1807 case XFS_ATTR_LEAF_MAGIC:
1809 if (cursor->hashval >
1810 INT_GET(leaf->entries[
1811 INT_GET(leaf->hdr.count,
1812 ARCH_CONVERT)-1].hashval,
1814 xfs_attr_trace_l_cl("wrong blk",
1816 xfs_da_brelse(NULL, bp);
1818 } else if (cursor->hashval <=
1819 INT_GET(leaf->entries[0].hashval,
1821 xfs_attr_trace_l_cl("maybe wrong blk",
1823 xfs_da_brelse(NULL, bp);
1828 xfs_attr_trace_l_c("wrong blk - ??", context);
1829 xfs_da_brelse(NULL, bp);
1836 * We did not find what we expected given the cursor's contents,
1837 * so we start from the top and work down based on the hash value.
1838 * Note that start of node block is same as start of leaf block.
1843 error = xfs_da_read_buf(NULL, context->dp,
1844 cursor->blkno, -1, &bp,
1848 if (unlikely(bp == NULL)) {
1849 XFS_ERROR_REPORT("xfs_attr_node_list(2)",
1851 context->dp->i_mount);
1852 return(XFS_ERROR(EFSCORRUPTED));
1855 if (INT_GET(node->hdr.info.magic, ARCH_CONVERT)
1856 == XFS_ATTR_LEAF_MAGIC)
1858 if (unlikely(INT_GET(node->hdr.info.magic, ARCH_CONVERT)
1859 != XFS_DA_NODE_MAGIC)) {
1860 XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
1862 context->dp->i_mount,
1864 xfs_da_brelse(NULL, bp);
1865 return(XFS_ERROR(EFSCORRUPTED));
1867 btree = node->btree;
1869 i < INT_GET(node->hdr.count, ARCH_CONVERT);
1872 <= INT_GET(btree->hashval,
1874 cursor->blkno = INT_GET(btree->before, ARCH_CONVERT);
1875 xfs_attr_trace_l_cb("descending",
1880 if (i == INT_GET(node->hdr.count, ARCH_CONVERT)) {
1881 xfs_da_brelse(NULL, bp);
1884 xfs_da_brelse(NULL, bp);
1890 * Roll upward through the blocks, processing each leaf block in
1891 * order. As long as there is space in the result buffer, keep
1892 * adding the information.
1896 if (unlikely(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
1897 != XFS_ATTR_LEAF_MAGIC)) {
1898 XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
1900 context->dp->i_mount, leaf);
1901 xfs_da_brelse(NULL, bp);
1902 return(XFS_ERROR(EFSCORRUPTED));
1904 error = xfs_attr_leaf_list_int(bp, context);
1905 if (error || !leaf->hdr.info.forw)
1906 break; /* not really an error, buffer full or EOF */
1907 cursor->blkno = INT_GET(leaf->hdr.info.forw, ARCH_CONVERT);
1908 xfs_da_brelse(NULL, bp);
1909 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1910 &bp, XFS_ATTR_FORK);
1913 if (unlikely((bp == NULL))) {
1914 XFS_ERROR_REPORT("xfs_attr_node_list(5)",
1916 context->dp->i_mount);
1917 return(XFS_ERROR(EFSCORRUPTED));
1920 xfs_da_brelse(NULL, bp);
1925 /*========================================================================
1926 * External routines for manipulating out-of-line attribute values.
1927 *========================================================================*/
1930 * Read the value associated with an attribute from the out-of-line buffer
1931 * that we stored it in.
1934 xfs_attr_rmtval_get(xfs_da_args_t *args)
1936 xfs_bmbt_irec_t map[ATTR_RMTVALUE_MAPSIZE];
1941 int nmap, error, tmp, valuelen, blkcnt, i;
1944 ASSERT(!(args->flags & ATTR_KERNOVAL));
1946 mp = args->dp->i_mount;
1948 valuelen = args->valuelen;
1949 lblkno = args->rmtblkno;
1950 while (valuelen > 0) {
1951 nmap = ATTR_RMTVALUE_MAPSIZE;
1952 error = xfs_bmapi(args->trans, args->dp, (xfs_fileoff_t)lblkno,
1954 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
1955 NULL, 0, map, &nmap, NULL);
1960 for (i = 0; (i < nmap) && (valuelen > 0); i++) {
1961 ASSERT((map[i].br_startblock != DELAYSTARTBLOCK) &&
1962 (map[i].br_startblock != HOLESTARTBLOCK));
1963 dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
1964 blkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
1965 error = xfs_read_buf(mp, mp->m_ddev_targp, dblkno,
1966 blkcnt, XFS_BUF_LOCK, &bp);
1970 tmp = (valuelen < XFS_BUF_SIZE(bp))
1971 ? valuelen : XFS_BUF_SIZE(bp);
1972 xfs_biomove(bp, 0, tmp, dst, XFS_B_READ);
1977 lblkno += map[i].br_blockcount;
1980 ASSERT(valuelen == 0);
1985 * Write the value associated with an attribute into the out-of-line buffer
1986 * that we have defined for it.
1989 xfs_attr_rmtval_set(xfs_da_args_t *args)
1992 xfs_fileoff_t lfileoff;
1994 xfs_bmbt_irec_t map;
1999 int blkcnt, valuelen, nmap, error, tmp, committed;
2006 * Find a "hole" in the attribute address space large enough for
2007 * us to drop the new attribute's value into.
2009 blkcnt = XFS_B_TO_FSB(mp, args->valuelen);
2011 error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff,
2016 args->rmtblkno = lblkno = (xfs_dablk_t)lfileoff;
2017 args->rmtblkcnt = blkcnt;
2020 * Roll through the "value", allocating blocks on disk as required.
2022 while (blkcnt > 0) {
2024 * Allocate a single extent, up to the size of the value.
2026 XFS_BMAP_INIT(args->flist, args->firstblock);
2028 error = xfs_bmapi(args->trans, dp, (xfs_fileoff_t)lblkno,
2030 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA |
2032 args->firstblock, args->total, &map, &nmap,
2035 error = xfs_bmap_finish(&args->trans, args->flist,
2036 *args->firstblock, &committed);
2041 xfs_bmap_cancel(args->flist);
2046 * bmap_finish() may have committed the last trans and started
2047 * a new one. We need the inode to be in all transactions.
2050 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
2051 xfs_trans_ihold(args->trans, dp);
2055 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2056 (map.br_startblock != HOLESTARTBLOCK));
2057 lblkno += map.br_blockcount;
2058 blkcnt -= map.br_blockcount;
2061 * Start the next trans in the chain.
2063 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
2068 * Roll through the "value", copying the attribute value to the
2069 * already-allocated blocks. Blocks are written synchronously
2070 * so that we can know they are all on disk before we turn off
2071 * the INCOMPLETE flag.
2073 lblkno = args->rmtblkno;
2074 valuelen = args->valuelen;
2075 while (valuelen > 0) {
2077 * Try to remember where we decided to put the value.
2079 XFS_BMAP_INIT(args->flist, args->firstblock);
2081 error = xfs_bmapi(NULL, dp, (xfs_fileoff_t)lblkno,
2083 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2084 args->firstblock, 0, &map, &nmap, NULL);
2089 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2090 (map.br_startblock != HOLESTARTBLOCK));
2092 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2093 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2095 bp = xfs_buf_get_flags(mp->m_ddev_targp, dblkno,
2096 blkcnt, XFS_BUF_LOCK);
2098 ASSERT(!XFS_BUF_GETERROR(bp));
2100 tmp = (valuelen < XFS_BUF_SIZE(bp)) ? valuelen :
2102 xfs_biomove(bp, 0, tmp, src, XFS_B_WRITE);
2103 if (tmp < XFS_BUF_SIZE(bp))
2104 xfs_biozero(bp, tmp, XFS_BUF_SIZE(bp) - tmp);
2105 if ((error = xfs_bwrite(mp, bp))) {/* GROT: NOTE: synchronous write */
2111 lblkno += map.br_blockcount;
2113 ASSERT(valuelen == 0);
2118 * Remove the value associated with an attribute by deleting the
2119 * out-of-line buffer that it is stored on.
2122 xfs_attr_rmtval_remove(xfs_da_args_t *args)
2125 xfs_bmbt_irec_t map;
2129 int valuelen, blkcnt, nmap, error, done, committed;
2131 mp = args->dp->i_mount;
2134 * Roll through the "value", invalidating the attribute value's
2137 lblkno = args->rmtblkno;
2138 valuelen = args->rmtblkcnt;
2139 while (valuelen > 0) {
2141 * Try to remember where we decided to put the value.
2143 XFS_BMAP_INIT(args->flist, args->firstblock);
2145 error = xfs_bmapi(NULL, args->dp, (xfs_fileoff_t)lblkno,
2147 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2148 args->firstblock, 0, &map, &nmap,
2154 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2155 (map.br_startblock != HOLESTARTBLOCK));
2157 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2158 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2161 * If the "remote" value is in the cache, remove it.
2163 bp = xfs_incore(mp->m_ddev_targp, dblkno, blkcnt,
2164 XFS_INCORE_TRYLOCK);
2167 XFS_BUF_UNDELAYWRITE(bp);
2172 valuelen -= map.br_blockcount;
2174 lblkno += map.br_blockcount;
2178 * Keep de-allocating extents until the remote-value region is gone.
2180 lblkno = args->rmtblkno;
2181 blkcnt = args->rmtblkcnt;
2184 XFS_BMAP_INIT(args->flist, args->firstblock);
2185 error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
2186 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2187 1, args->firstblock, args->flist, &done);
2189 error = xfs_bmap_finish(&args->trans, args->flist,
2190 *args->firstblock, &committed);
2195 xfs_bmap_cancel(args->flist);
2200 * bmap_finish() may have committed the last trans and started
2201 * a new one. We need the inode to be in all transactions.
2204 xfs_trans_ijoin(args->trans, args->dp, XFS_ILOCK_EXCL);
2205 xfs_trans_ihold(args->trans, args->dp);
2209 * Close out trans and start the next one in the chain.
2211 if ((error = xfs_attr_rolltrans(&args->trans, args->dp)))
2217 #if defined(XFS_ATTR_TRACE)
2219 * Add a trace buffer entry for an attr_list context structure.
2222 xfs_attr_trace_l_c(char *where, struct xfs_attr_list_context *context)
2224 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_C, where,
2225 (__psunsigned_t)context->dp,
2226 (__psunsigned_t)context->cursor->hashval,
2227 (__psunsigned_t)context->cursor->blkno,
2228 (__psunsigned_t)context->cursor->offset,
2229 (__psunsigned_t)context->alist,
2230 (__psunsigned_t)context->bufsize,
2231 (__psunsigned_t)context->count,
2232 (__psunsigned_t)context->firstu,
2234 ((context->count > 0) &&
2235 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2236 ? (ATTR_ENTRY(context->alist,
2237 context->count-1)->a_valuelen)
2239 (__psunsigned_t)context->dupcnt,
2240 (__psunsigned_t)context->flags,
2241 (__psunsigned_t)NULL,
2242 (__psunsigned_t)NULL,
2243 (__psunsigned_t)NULL);
2247 * Add a trace buffer entry for a context structure and a Btree node.
2250 xfs_attr_trace_l_cn(char *where, struct xfs_attr_list_context *context,
2251 struct xfs_da_intnode *node)
2253 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CN, where,
2254 (__psunsigned_t)context->dp,
2255 (__psunsigned_t)context->cursor->hashval,
2256 (__psunsigned_t)context->cursor->blkno,
2257 (__psunsigned_t)context->cursor->offset,
2258 (__psunsigned_t)context->alist,
2259 (__psunsigned_t)context->bufsize,
2260 (__psunsigned_t)context->count,
2261 (__psunsigned_t)context->firstu,
2263 ((context->count > 0) &&
2264 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2265 ? (ATTR_ENTRY(context->alist,
2266 context->count-1)->a_valuelen)
2268 (__psunsigned_t)context->dupcnt,
2269 (__psunsigned_t)context->flags,
2270 (__psunsigned_t)INT_GET(node->hdr.count, ARCH_CONVERT),
2271 (__psunsigned_t)INT_GET(node->btree[0].hashval, ARCH_CONVERT),
2272 (__psunsigned_t)INT_GET(node->btree[INT_GET(node->hdr.count, ARCH_CONVERT)-1].hashval, ARCH_CONVERT));
2276 * Add a trace buffer entry for a context structure and a Btree element.
2279 xfs_attr_trace_l_cb(char *where, struct xfs_attr_list_context *context,
2280 struct xfs_da_node_entry *btree)
2282 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CB, where,
2283 (__psunsigned_t)context->dp,
2284 (__psunsigned_t)context->cursor->hashval,
2285 (__psunsigned_t)context->cursor->blkno,
2286 (__psunsigned_t)context->cursor->offset,
2287 (__psunsigned_t)context->alist,
2288 (__psunsigned_t)context->bufsize,
2289 (__psunsigned_t)context->count,
2290 (__psunsigned_t)context->firstu,
2292 ((context->count > 0) &&
2293 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2294 ? (ATTR_ENTRY(context->alist,
2295 context->count-1)->a_valuelen)
2297 (__psunsigned_t)context->dupcnt,
2298 (__psunsigned_t)context->flags,
2299 (__psunsigned_t)INT_GET(btree->hashval, ARCH_CONVERT),
2300 (__psunsigned_t)INT_GET(btree->before, ARCH_CONVERT),
2301 (__psunsigned_t)NULL);
2305 * Add a trace buffer entry for a context structure and a leaf block.
2308 xfs_attr_trace_l_cl(char *where, struct xfs_attr_list_context *context,
2309 struct xfs_attr_leafblock *leaf)
2311 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CL, where,
2312 (__psunsigned_t)context->dp,
2313 (__psunsigned_t)context->cursor->hashval,
2314 (__psunsigned_t)context->cursor->blkno,
2315 (__psunsigned_t)context->cursor->offset,
2316 (__psunsigned_t)context->alist,
2317 (__psunsigned_t)context->bufsize,
2318 (__psunsigned_t)context->count,
2319 (__psunsigned_t)context->firstu,
2321 ((context->count > 0) &&
2322 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2323 ? (ATTR_ENTRY(context->alist,
2324 context->count-1)->a_valuelen)
2326 (__psunsigned_t)context->dupcnt,
2327 (__psunsigned_t)context->flags,
2328 (__psunsigned_t)INT_GET(leaf->hdr.count, ARCH_CONVERT),
2329 (__psunsigned_t)INT_GET(leaf->entries[0].hashval, ARCH_CONVERT),
2330 (__psunsigned_t)INT_GET(leaf->entries[INT_GET(leaf->hdr.count, ARCH_CONVERT)-1].hashval, ARCH_CONVERT));
2334 * Add a trace buffer entry for the arguments given to the routine,
2338 xfs_attr_trace_enter(int type, char *where,
2339 __psunsigned_t a2, __psunsigned_t a3,
2340 __psunsigned_t a4, __psunsigned_t a5,
2341 __psunsigned_t a6, __psunsigned_t a7,
2342 __psunsigned_t a8, __psunsigned_t a9,
2343 __psunsigned_t a10, __psunsigned_t a11,
2344 __psunsigned_t a12, __psunsigned_t a13,
2345 __psunsigned_t a14, __psunsigned_t a15)
2347 ASSERT(xfs_attr_trace_buf);
2348 ktrace_enter(xfs_attr_trace_buf, (void *)((__psunsigned_t)type),
2350 (void *)a2, (void *)a3, (void *)a4,
2351 (void *)a5, (void *)a6, (void *)a7,
2352 (void *)a8, (void *)a9, (void *)a10,
2353 (void *)a11, (void *)a12, (void *)a13,
2354 (void *)a14, (void *)a15);
2356 #endif /* XFS_ATTR_TRACE */
2359 /*========================================================================
2360 * System (pseudo) namespace attribute interface routines.
2361 *========================================================================*/
2364 posix_acl_access_set(
2365 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2367 return xfs_acl_vset(vp, data, size, _ACL_TYPE_ACCESS);
2371 posix_acl_access_remove(
2372 struct vnode *vp, char *name, int xflags)
2374 return xfs_acl_vremove(vp, _ACL_TYPE_ACCESS);
2378 posix_acl_access_get(
2379 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2381 return xfs_acl_vget(vp, data, size, _ACL_TYPE_ACCESS);
2385 posix_acl_access_exists(
2388 return xfs_acl_vhasacl_access(vp);
2392 posix_acl_default_set(
2393 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2395 return xfs_acl_vset(vp, data, size, _ACL_TYPE_DEFAULT);
2399 posix_acl_default_get(
2400 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2402 return xfs_acl_vget(vp, data, size, _ACL_TYPE_DEFAULT);
2406 posix_acl_default_remove(
2407 struct vnode *vp, char *name, int xflags)
2409 return xfs_acl_vremove(vp, _ACL_TYPE_DEFAULT);
2413 posix_acl_default_exists(
2416 return xfs_acl_vhasacl_default(vp);
2419 STATIC struct attrnames posix_acl_access = {
2420 .attr_name = "posix_acl_access",
2421 .attr_namelen = sizeof("posix_acl_access") - 1,
2422 .attr_get = posix_acl_access_get,
2423 .attr_set = posix_acl_access_set,
2424 .attr_remove = posix_acl_access_remove,
2425 .attr_exists = posix_acl_access_exists,
2428 STATIC struct attrnames posix_acl_default = {
2429 .attr_name = "posix_acl_default",
2430 .attr_namelen = sizeof("posix_acl_default") - 1,
2431 .attr_get = posix_acl_default_get,
2432 .attr_set = posix_acl_default_set,
2433 .attr_remove = posix_acl_default_remove,
2434 .attr_exists = posix_acl_default_exists,
2437 STATIC struct attrnames *attr_system_names[] =
2438 { &posix_acl_access, &posix_acl_default };
2441 /*========================================================================
2442 * Namespace-prefix-style attribute name interface routines.
2443 *========================================================================*/
2447 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2451 VOP_ATTR_SET(vp, name, data, size, xflags, NULL, error);
2457 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2459 int error, asize = size;
2461 VOP_ATTR_GET(vp, name, data, &asize, xflags, NULL, error);
2468 attr_generic_remove(
2469 struct vnode *vp, char *name, int xflags)
2473 VOP_ATTR_REMOVE(vp, name, xflags, NULL, error);
2478 attr_generic_listadd(
2479 attrnames_t *prefix,
2480 attrnames_t *namesp,
2485 char *p = data + *result;
2487 *result += prefix->attr_namelen;
2488 *result += namesp->attr_namelen + 1;
2493 strcpy(p, prefix->attr_name);
2494 p += prefix->attr_namelen;
2495 strcpy(p, namesp->attr_name);
2496 p += namesp->attr_namelen + 1;
2507 attrnames_t *namesp;
2510 for (i = 0; i < ATTR_SYSCOUNT; i++) {
2511 namesp = attr_system_names[i];
2512 if (!namesp->attr_exists || !namesp->attr_exists(vp))
2514 error = attr_generic_listadd(&attr_system, namesp,
2515 data, size, result);
2524 struct vnode *vp, void *data, size_t size, int xflags, ssize_t *result)
2526 attrlist_cursor_kern_t cursor = { 0 };
2529 VOP_ATTR_LIST(vp, data, size, xflags, &cursor, NULL, error);
2533 return attr_system_list(vp, data, size, result);
2537 attr_lookup_namespace(
2539 struct attrnames **names,
2544 for (i = 0; i < nnames; i++)
2545 if (!strncmp(name, names[i]->attr_name, names[i]->attr_namelen))
2551 * Some checks to prevent people abusing EAs to get over quota:
2552 * - Don't allow modifying user EAs on devices/symlinks;
2553 * - Don't allow modifying user EAs if sticky bit set;
2560 struct inode *inode = LINVFS_GET_IP(vp);
2562 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2564 if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode) &&
2565 !capable(CAP_SYS_ADMIN))
2567 if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) &&
2568 (current_fsuid(cred) != inode->i_uid) && !capable(CAP_FOWNER))
2574 attr_trusted_capable(
2578 struct inode *inode = LINVFS_GET_IP(vp);
2580 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2582 if (!capable(CAP_SYS_ADMIN))
2588 attr_secure_capable(
2592 return -ENOSECURITY;
2597 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2599 attrnames_t *namesp;
2602 if (xflags & ATTR_CREATE)
2605 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2608 error = namesp->attr_set(vp, name, data, size, xflags);
2610 error = vn_revalidate(vp);
2616 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2618 attrnames_t *namesp;
2620 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2623 return namesp->attr_get(vp, name, data, size, xflags);
2628 struct vnode *vp, char *name, int xflags)
2630 attrnames_t *namesp;
2632 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2635 return namesp->attr_remove(vp, name, xflags);
2638 struct attrnames attr_system = {
2639 .attr_name = "system.",
2640 .attr_namelen = sizeof("system.") - 1,
2641 .attr_flag = ATTR_SYSTEM,
2642 .attr_get = attr_system_get,
2643 .attr_set = attr_system_set,
2644 .attr_remove = attr_system_remove,
2645 .attr_capable = (attrcapable_t)fs_noerr,
2648 struct attrnames attr_trusted = {
2649 .attr_name = "trusted.",
2650 .attr_namelen = sizeof("trusted.") - 1,
2651 .attr_flag = ATTR_ROOT,
2652 .attr_get = attr_generic_get,
2653 .attr_set = attr_generic_set,
2654 .attr_remove = attr_generic_remove,
2655 .attr_capable = attr_trusted_capable,
2658 struct attrnames attr_secure = {
2659 .attr_name = "security.",
2660 .attr_namelen = sizeof("security.") - 1,
2661 .attr_flag = ATTR_SECURE,
2662 .attr_get = attr_generic_get,
2663 .attr_set = attr_generic_set,
2664 .attr_remove = attr_generic_remove,
2665 .attr_capable = attr_secure_capable,
2668 struct attrnames attr_user = {
2669 .attr_name = "user.",
2670 .attr_namelen = sizeof("user.") - 1,
2671 .attr_get = attr_generic_get,
2672 .attr_set = attr_generic_set,
2673 .attr_remove = attr_generic_remove,
2674 .attr_capable = attr_user_capable,
2677 struct attrnames *attr_namespaces[] =
2678 { &attr_system, &attr_trusted, &attr_secure, &attr_user };