2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <linux/capability.h>
23 #include "xfs_types.h"
27 #include "xfs_trans.h"
31 #include "xfs_dmapi.h"
32 #include "xfs_mount.h"
33 #include "xfs_da_btree.h"
34 #include "xfs_bmap_btree.h"
35 #include "xfs_alloc_btree.h"
36 #include "xfs_ialloc_btree.h"
37 #include "xfs_dir2_sf.h"
38 #include "xfs_attr_sf.h"
39 #include "xfs_dinode.h"
40 #include "xfs_inode.h"
41 #include "xfs_alloc.h"
42 #include "xfs_btree.h"
43 #include "xfs_inode_item.h"
46 #include "xfs_attr_leaf.h"
47 #include "xfs_error.h"
48 #include "xfs_quota.h"
49 #include "xfs_trans_space.h"
56 * Provide the external interfaces to manage attribute lists.
59 #define ATTR_SYSCOUNT 2
60 static struct attrnames posix_acl_access;
61 static struct attrnames posix_acl_default;
62 static struct attrnames *attr_system_names[ATTR_SYSCOUNT];
64 /*========================================================================
65 * Function prototypes for the kernel.
66 *========================================================================*/
69 * Internal routines when attribute list fits inside the inode.
71 STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
74 * Internal routines when attribute list is one block.
76 STATIC int xfs_attr_leaf_get(xfs_da_args_t *args);
77 STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args);
78 STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
79 STATIC int xfs_attr_leaf_list(xfs_attr_list_context_t *context);
82 * Internal routines when attribute list is more than one block.
84 STATIC int xfs_attr_node_get(xfs_da_args_t *args);
85 STATIC int xfs_attr_node_addname(xfs_da_args_t *args);
86 STATIC int xfs_attr_node_removename(xfs_da_args_t *args);
87 STATIC int xfs_attr_node_list(xfs_attr_list_context_t *context);
88 STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
89 STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
92 * Routines to manipulate out-of-line attribute values.
94 STATIC int xfs_attr_rmtval_set(xfs_da_args_t *args);
95 STATIC int xfs_attr_rmtval_remove(xfs_da_args_t *args);
97 #define ATTR_RMTVALUE_MAPSIZE 1 /* # of map entries at once */
99 #if defined(XFS_ATTR_TRACE)
100 ktrace_t *xfs_attr_trace_buf;
104 /*========================================================================
105 * Overall external interface routines.
106 *========================================================================*/
109 xfs_attr_fetch(xfs_inode_t *ip, const char *name, int namelen,
110 char *value, int *valuelenp, int flags, struct cred *cred)
115 if ((XFS_IFORK_Q(ip) == 0) ||
116 (ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
117 ip->i_d.di_anextents == 0))
121 * Fill in the arg structure for this request.
123 memset((char *)&args, 0, sizeof(args));
125 args.namelen = namelen;
127 args.valuelen = *valuelenp;
129 args.hashval = xfs_da_hashname(args.name, args.namelen);
131 args.whichfork = XFS_ATTR_FORK;
134 * Decide on what work routines to call based on the inode size.
136 if (XFS_IFORK_Q(ip) == 0 ||
137 (ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
138 ip->i_d.di_anextents == 0)) {
139 error = XFS_ERROR(ENOATTR);
140 } else if (ip->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
141 error = xfs_attr_shortform_getvalue(&args);
142 } else if (xfs_bmap_one_block(ip, XFS_ATTR_FORK)) {
143 error = xfs_attr_leaf_get(&args);
145 error = xfs_attr_node_get(&args);
149 * Return the number of bytes in the value to the caller.
151 *valuelenp = args.valuelen;
169 XFS_STATS_INC(xs_attr_get);
173 namelen = strlen(name);
174 if (namelen >= MAXNAMELEN)
175 return(EFAULT); /* match IRIX behaviour */
177 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
180 xfs_ilock(ip, XFS_ILOCK_SHARED);
181 error = xfs_attr_fetch(ip, name, namelen, value, valuelenp, flags, cred);
182 xfs_iunlock(ip, XFS_ILOCK_SHARED);
187 xfs_attr_set_int(xfs_inode_t *dp, const char *name, int namelen,
188 char *value, int valuelen, int flags)
191 xfs_fsblock_t firstblock;
192 xfs_bmap_free_t flist;
193 int error, err2, committed;
196 xfs_mount_t *mp = dp->i_mount;
197 int rsvd = (flags & ATTR_ROOT) != 0;
200 * Attach the dquots to the inode.
202 if ((error = XFS_QM_DQATTACH(mp, dp, 0)))
206 * If the inode doesn't have an attribute fork, add one.
207 * (inode must not be locked when we call this routine)
209 if (XFS_IFORK_Q(dp) == 0) {
210 int sf_size = sizeof(xfs_attr_sf_hdr_t) +
211 XFS_ATTR_SF_ENTSIZE_BYNAME(namelen, valuelen);
213 if ((error = xfs_bmap_add_attrfork(dp, sf_size, rsvd)))
218 * Fill in the arg structure for this request.
220 memset((char *)&args, 0, sizeof(args));
222 args.namelen = namelen;
224 args.valuelen = valuelen;
226 args.hashval = xfs_da_hashname(args.name, args.namelen);
228 args.firstblock = &firstblock;
230 args.whichfork = XFS_ATTR_FORK;
235 * Determine space new attribute will use, and if it would be
236 * "local" or "remote" (note: local != inline).
238 size = xfs_attr_leaf_newentsize(namelen, valuelen,
239 mp->m_sb.sb_blocksize, &local);
241 nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK);
243 if (size > (mp->m_sb.sb_blocksize >> 1)) {
244 /* Double split possible */
248 uint dblocks = XFS_B_TO_FSB(mp, valuelen);
249 /* Out of line attribute, cannot double split, but make
250 * room for the attribute value itself.
253 nblks += XFS_NEXTENTADD_SPACE_RES(mp, dblocks, XFS_ATTR_FORK);
256 /* Size is now blocks for attribute data */
260 * Start our first transaction of the day.
262 * All future transactions during this code must be "chained" off
263 * this one via the trans_dup() call. All transactions will contain
264 * the inode, and the inode will always be marked with trans_ihold().
265 * Since the inode will be locked in all transactions, we must log
266 * the inode in every transaction to let it float upward through
269 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_SET);
272 * Root fork attributes can use reserved data blocks for this
273 * operation if necessary
277 args.trans->t_flags |= XFS_TRANS_RESERVE;
279 if ((error = xfs_trans_reserve(args.trans, (uint) nblks,
280 XFS_ATTRSET_LOG_RES(mp, nblks),
281 0, XFS_TRANS_PERM_LOG_RES,
282 XFS_ATTRSET_LOG_COUNT))) {
283 xfs_trans_cancel(args.trans, 0);
286 xfs_ilock(dp, XFS_ILOCK_EXCL);
288 error = XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, args.trans, dp, nblks, 0,
289 rsvd ? XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES :
290 XFS_QMOPT_RES_REGBLKS);
292 xfs_iunlock(dp, XFS_ILOCK_EXCL);
293 xfs_trans_cancel(args.trans, XFS_TRANS_RELEASE_LOG_RES);
297 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
298 xfs_trans_ihold(args.trans, dp);
301 * If the attribute list is non-existent or a shortform list,
302 * upgrade it to a single-leaf-block attribute list.
304 if ((dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
305 ((dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS) &&
306 (dp->i_d.di_anextents == 0))) {
309 * Build initial attribute list (if required).
311 if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
312 xfs_attr_shortform_create(&args);
315 * Try to add the attr to the attribute list in
318 error = xfs_attr_shortform_addname(&args);
319 if (error != ENOSPC) {
321 * Commit the shortform mods, and we're done.
322 * NOTE: this is also the error path (EEXIST, etc).
324 ASSERT(args.trans != NULL);
327 * If this is a synchronous mount, make sure that
328 * the transaction goes to disk before returning
331 if (mp->m_flags & XFS_MOUNT_WSYNC) {
332 xfs_trans_set_sync(args.trans);
334 err2 = xfs_trans_commit(args.trans,
335 XFS_TRANS_RELEASE_LOG_RES);
336 xfs_iunlock(dp, XFS_ILOCK_EXCL);
339 * Hit the inode change time.
341 if (!error && (flags & ATTR_KERNOTIME) == 0) {
342 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
344 return(error == 0 ? err2 : error);
348 * It won't fit in the shortform, transform to a leaf block.
349 * GROT: another possible req'mt for a double-split btree op.
351 XFS_BMAP_INIT(args.flist, args.firstblock);
352 error = xfs_attr_shortform_to_leaf(&args);
354 error = xfs_bmap_finish(&args.trans, args.flist,
360 xfs_bmap_cancel(&flist);
365 * bmap_finish() may have committed the last trans and started
366 * a new one. We need the inode to be in all transactions.
369 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
370 xfs_trans_ihold(args.trans, dp);
374 * Commit the leaf transformation. We'll need another (linked)
375 * transaction to add the new attribute to the leaf.
377 if ((error = xfs_attr_rolltrans(&args.trans, dp)))
382 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
383 error = xfs_attr_leaf_addname(&args);
385 error = xfs_attr_node_addname(&args);
392 * If this is a synchronous mount, make sure that the
393 * transaction goes to disk before returning to the user.
395 if (mp->m_flags & XFS_MOUNT_WSYNC) {
396 xfs_trans_set_sync(args.trans);
400 * Commit the last in the sequence of transactions.
402 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
403 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES);
404 xfs_iunlock(dp, XFS_ILOCK_EXCL);
407 * Hit the inode change time.
409 if (!error && (flags & ATTR_KERNOTIME) == 0) {
410 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
417 xfs_trans_cancel(args.trans,
418 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
419 xfs_iunlock(dp, XFS_ILOCK_EXCL);
433 namelen = strlen(name);
434 if (namelen >= MAXNAMELEN)
435 return EFAULT; /* match IRIX behaviour */
437 XFS_STATS_INC(xs_attr_set);
439 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
442 return xfs_attr_set_int(dp, name, namelen, value, valuelen, flags);
446 * Generic handler routine to remove a name from an attribute list.
447 * Transitions attribute list from Btree to shortform as necessary.
450 xfs_attr_remove_int(xfs_inode_t *dp, const char *name, int namelen, int flags)
453 xfs_fsblock_t firstblock;
454 xfs_bmap_free_t flist;
456 xfs_mount_t *mp = dp->i_mount;
459 * Fill in the arg structure for this request.
461 memset((char *)&args, 0, sizeof(args));
463 args.namelen = namelen;
465 args.hashval = xfs_da_hashname(args.name, args.namelen);
467 args.firstblock = &firstblock;
470 args.whichfork = XFS_ATTR_FORK;
473 * Attach the dquots to the inode.
475 if ((error = XFS_QM_DQATTACH(mp, dp, 0)))
479 * Start our first transaction of the day.
481 * All future transactions during this code must be "chained" off
482 * this one via the trans_dup() call. All transactions will contain
483 * the inode, and the inode will always be marked with trans_ihold().
484 * Since the inode will be locked in all transactions, we must log
485 * the inode in every transaction to let it float upward through
488 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_RM);
491 * Root fork attributes can use reserved data blocks for this
492 * operation if necessary
495 if (flags & ATTR_ROOT)
496 args.trans->t_flags |= XFS_TRANS_RESERVE;
498 if ((error = xfs_trans_reserve(args.trans,
499 XFS_ATTRRM_SPACE_RES(mp),
500 XFS_ATTRRM_LOG_RES(mp),
501 0, XFS_TRANS_PERM_LOG_RES,
502 XFS_ATTRRM_LOG_COUNT))) {
503 xfs_trans_cancel(args.trans, 0);
507 xfs_ilock(dp, XFS_ILOCK_EXCL);
509 * No need to make quota reservations here. We expect to release some
510 * blocks not allocate in the common case.
512 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
513 xfs_trans_ihold(args.trans, dp);
516 * Decide on what work routines to call based on the inode size.
518 if (XFS_IFORK_Q(dp) == 0 ||
519 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
520 dp->i_d.di_anextents == 0)) {
521 error = XFS_ERROR(ENOATTR);
524 if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
525 ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
526 error = xfs_attr_shortform_remove(&args);
530 } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
531 error = xfs_attr_leaf_removename(&args);
533 error = xfs_attr_node_removename(&args);
540 * If this is a synchronous mount, make sure that the
541 * transaction goes to disk before returning to the user.
543 if (mp->m_flags & XFS_MOUNT_WSYNC) {
544 xfs_trans_set_sync(args.trans);
548 * Commit the last in the sequence of transactions.
550 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
551 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES);
552 xfs_iunlock(dp, XFS_ILOCK_EXCL);
555 * Hit the inode change time.
557 if (!error && (flags & ATTR_KERNOTIME) == 0) {
558 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
565 xfs_trans_cancel(args.trans,
566 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
567 xfs_iunlock(dp, XFS_ILOCK_EXCL);
579 namelen = strlen(name);
580 if (namelen >= MAXNAMELEN)
581 return EFAULT; /* match IRIX behaviour */
583 XFS_STATS_INC(xs_attr_remove);
585 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
588 xfs_ilock(dp, XFS_ILOCK_SHARED);
589 if (XFS_IFORK_Q(dp) == 0 ||
590 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
591 dp->i_d.di_anextents == 0)) {
592 xfs_iunlock(dp, XFS_ILOCK_SHARED);
593 return(XFS_ERROR(ENOATTR));
595 xfs_iunlock(dp, XFS_ILOCK_SHARED);
597 return xfs_attr_remove_int(dp, name, namelen, flags);
601 xfs_attr_list_int(xfs_attr_list_context_t *context)
604 xfs_inode_t *dp = context->dp;
607 * Decide on what work routines to call based on the inode size.
609 if (XFS_IFORK_Q(dp) == 0 ||
610 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
611 dp->i_d.di_anextents == 0)) {
613 } else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
614 error = xfs_attr_shortform_list(context);
615 } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
616 error = xfs_attr_leaf_list(context);
618 error = xfs_attr_node_list(context);
623 #define ATTR_ENTBASESIZE /* minimum bytes used by an attr */ \
624 (((struct attrlist_ent *) 0)->a_name - (char *) 0)
625 #define ATTR_ENTSIZE(namelen) /* actual bytes used by an attr */ \
626 ((ATTR_ENTBASESIZE + (namelen) + 1 + sizeof(u_int32_t)-1) \
627 & ~(sizeof(u_int32_t)-1))
630 * Format an attribute and copy it out to the user's buffer.
631 * Take care to check values and protect against them changing later,
632 * we may be reading them directly out of a user buffer.
636 xfs_attr_put_listent(xfs_attr_list_context_t *context, attrnames_t *namesp,
637 char *name, int namelen,
638 int valuelen, char *value)
643 ASSERT(!(context->flags & ATTR_KERNOVAL));
644 ASSERT(context->count >= 0);
645 ASSERT(context->count < (ATTR_MAX_VALUELEN/8));
646 ASSERT(context->firstu >= sizeof(*context->alist));
647 ASSERT(context->firstu <= context->bufsize);
649 arraytop = sizeof(*context->alist) +
650 context->count * sizeof(context->alist->al_offset[0]);
651 context->firstu -= ATTR_ENTSIZE(namelen);
652 if (context->firstu < arraytop) {
653 xfs_attr_trace_l_c("buffer full", context);
654 context->alist->al_more = 1;
655 context->seen_enough = 1;
659 aep = (attrlist_ent_t *)&(((char *)context->alist)[ context->firstu ]);
660 aep->a_valuelen = valuelen;
661 memcpy(aep->a_name, name, namelen);
662 aep->a_name[ namelen ] = 0;
663 context->alist->al_offset[ context->count++ ] = context->firstu;
664 context->alist->al_count = context->count;
665 xfs_attr_trace_l_c("add", context);
670 xfs_attr_kern_list(xfs_attr_list_context_t *context, attrnames_t *namesp,
671 char *name, int namelen,
672 int valuelen, char *value)
677 ASSERT(context->count >= 0);
679 arraytop = context->count + namesp->attr_namelen + namelen + 1;
680 if (arraytop > context->firstu) {
681 context->count = -1; /* insufficient space */
684 offset = (char *)context->alist + context->count;
685 strncpy(offset, namesp->attr_name, namesp->attr_namelen);
686 offset += namesp->attr_namelen;
687 strncpy(offset, name, namelen); /* real name */
690 context->count += namesp->attr_namelen + namelen + 1;
696 xfs_attr_kern_list_sizes(xfs_attr_list_context_t *context, attrnames_t *namesp,
697 char *name, int namelen,
698 int valuelen, char *value)
700 context->count += namesp->attr_namelen + namelen + 1;
705 * Generate a list of extended attribute names and optionally
706 * also value lengths. Positive return value follows the XFS
707 * convention of being an error, zero or negative return code
708 * is the length of the buffer returned (negated), indicating
717 attrlist_cursor_kern_t *cursor)
719 xfs_attr_list_context_t context;
722 XFS_STATS_INC(xs_attr_list);
725 * Validate the cursor.
727 if (cursor->pad1 || cursor->pad2)
728 return(XFS_ERROR(EINVAL));
729 if ((cursor->initted == 0) &&
730 (cursor->hashval || cursor->blkno || cursor->offset))
731 return XFS_ERROR(EINVAL);
734 * Check for a properly aligned buffer.
736 if (((long)buffer) & (sizeof(int)-1))
737 return XFS_ERROR(EFAULT);
738 if (flags & ATTR_KERNOVAL)
742 * Initialize the output buffer.
745 context.cursor = cursor;
749 context.flags = flags;
750 context.seen_enough = 0;
751 context.alist = (attrlist_t *)buffer;
752 context.put_value = 0;
754 if (flags & ATTR_KERNAMELS) {
755 context.bufsize = bufsize;
756 context.firstu = context.bufsize;
757 if (flags & ATTR_KERNOVAL)
758 context.put_listent = xfs_attr_kern_list_sizes;
760 context.put_listent = xfs_attr_kern_list;
762 context.bufsize = (bufsize & ~(sizeof(int)-1)); /* align */
763 context.firstu = context.bufsize;
764 context.alist->al_count = 0;
765 context.alist->al_more = 0;
766 context.alist->al_offset[0] = context.bufsize;
767 context.put_listent = xfs_attr_put_listent;
770 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
773 xfs_ilock(dp, XFS_ILOCK_SHARED);
774 xfs_attr_trace_l_c("syscall start", &context);
776 error = xfs_attr_list_int(&context);
778 xfs_iunlock(dp, XFS_ILOCK_SHARED);
779 xfs_attr_trace_l_c("syscall end", &context);
781 if (context.flags & (ATTR_KERNOVAL|ATTR_KERNAMELS)) {
782 /* must return negated buffer size or the error */
783 if (context.count < 0)
784 error = XFS_ERROR(ERANGE);
786 error = -context.count;
794 xfs_attr_inactive(xfs_inode_t *dp)
801 ASSERT(! XFS_NOT_DQATTACHED(mp, dp));
803 xfs_ilock(dp, XFS_ILOCK_SHARED);
804 if ((XFS_IFORK_Q(dp) == 0) ||
805 (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
806 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
807 dp->i_d.di_anextents == 0)) {
808 xfs_iunlock(dp, XFS_ILOCK_SHARED);
811 xfs_iunlock(dp, XFS_ILOCK_SHARED);
814 * Start our first transaction of the day.
816 * All future transactions during this code must be "chained" off
817 * this one via the trans_dup() call. All transactions will contain
818 * the inode, and the inode will always be marked with trans_ihold().
819 * Since the inode will be locked in all transactions, we must log
820 * the inode in every transaction to let it float upward through
823 trans = xfs_trans_alloc(mp, XFS_TRANS_ATTRINVAL);
824 if ((error = xfs_trans_reserve(trans, 0, XFS_ATTRINVAL_LOG_RES(mp), 0,
825 XFS_TRANS_PERM_LOG_RES,
826 XFS_ATTRINVAL_LOG_COUNT))) {
827 xfs_trans_cancel(trans, 0);
830 xfs_ilock(dp, XFS_ILOCK_EXCL);
833 * No need to make quota reservations here. We expect to release some
834 * blocks, not allocate, in the common case.
836 xfs_trans_ijoin(trans, dp, XFS_ILOCK_EXCL);
837 xfs_trans_ihold(trans, dp);
840 * Decide on what work routines to call based on the inode size.
842 if ((XFS_IFORK_Q(dp) == 0) ||
843 (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
844 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
845 dp->i_d.di_anextents == 0)) {
849 error = xfs_attr_root_inactive(&trans, dp);
853 * signal synchronous inactive transactions unless this
854 * is a synchronous mount filesystem in which case we
855 * know that we're here because we've been called out of
856 * xfs_inactive which means that the last reference is gone
857 * and the unlink transaction has already hit the disk so
858 * async inactive transactions are safe.
860 if ((error = xfs_itruncate_finish(&trans, dp, 0LL, XFS_ATTR_FORK,
861 (!(mp->m_flags & XFS_MOUNT_WSYNC)
866 * Commit the last in the sequence of transactions.
868 xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE);
869 error = xfs_trans_commit(trans, XFS_TRANS_RELEASE_LOG_RES);
870 xfs_iunlock(dp, XFS_ILOCK_EXCL);
875 xfs_trans_cancel(trans, XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
876 xfs_iunlock(dp, XFS_ILOCK_EXCL);
882 /*========================================================================
883 * External routines when attribute list is inside the inode
884 *========================================================================*/
887 * Add a name to the shortform attribute list structure
888 * This is the external routine.
891 xfs_attr_shortform_addname(xfs_da_args_t *args)
893 int newsize, forkoff, retval;
895 retval = xfs_attr_shortform_lookup(args);
896 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
898 } else if (retval == EEXIST) {
899 if (args->flags & ATTR_CREATE)
901 retval = xfs_attr_shortform_remove(args);
905 if (args->namelen >= XFS_ATTR_SF_ENTSIZE_MAX ||
906 args->valuelen >= XFS_ATTR_SF_ENTSIZE_MAX)
907 return(XFS_ERROR(ENOSPC));
909 newsize = XFS_ATTR_SF_TOTSIZE(args->dp);
910 newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen);
912 forkoff = xfs_attr_shortform_bytesfit(args->dp, newsize);
914 return(XFS_ERROR(ENOSPC));
916 xfs_attr_shortform_add(args, forkoff);
921 /*========================================================================
922 * External routines when attribute list is one block
923 *========================================================================*/
926 * Add a name to the leaf attribute list structure
928 * This leaf block cannot have a "remote" value, we only call this routine
929 * if bmap_one_block() says there is only one block (ie: no remote blks).
932 xfs_attr_leaf_addname(xfs_da_args_t *args)
936 int retval, error, committed, forkoff;
939 * Read the (only) block in the attribute list in.
943 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
950 * Look up the given attribute in the leaf block. Figure out if
951 * the given flags produce an error or call for an atomic rename.
953 retval = xfs_attr_leaf_lookup_int(bp, args);
954 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
955 xfs_da_brelse(args->trans, bp);
957 } else if (retval == EEXIST) {
958 if (args->flags & ATTR_CREATE) { /* pure create op */
959 xfs_da_brelse(args->trans, bp);
962 args->rename = 1; /* an atomic rename */
963 args->blkno2 = args->blkno; /* set 2nd entry info*/
964 args->index2 = args->index;
965 args->rmtblkno2 = args->rmtblkno;
966 args->rmtblkcnt2 = args->rmtblkcnt;
970 * Add the attribute to the leaf block, transitioning to a Btree
973 retval = xfs_attr_leaf_add(bp, args);
975 if (retval == ENOSPC) {
977 * Promote the attribute list to the Btree format, then
978 * Commit that transaction so that the node_addname() call
979 * can manage its own transactions.
981 XFS_BMAP_INIT(args->flist, args->firstblock);
982 error = xfs_attr_leaf_to_node(args);
984 error = xfs_bmap_finish(&args->trans, args->flist,
990 xfs_bmap_cancel(args->flist);
995 * bmap_finish() may have committed the last trans and started
996 * a new one. We need the inode to be in all transactions.
999 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1000 xfs_trans_ihold(args->trans, dp);
1004 * Commit the current trans (including the inode) and start
1007 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1011 * Fob the whole rest of the problem off on the Btree code.
1013 error = xfs_attr_node_addname(args);
1018 * Commit the transaction that added the attr name so that
1019 * later routines can manage their own transactions.
1021 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1025 * If there was an out-of-line value, allocate the blocks we
1026 * identified for its storage and copy the value. This is done
1027 * after we create the attribute so that we don't overflow the
1028 * maximum size of a transaction and/or hit a deadlock.
1030 if (args->rmtblkno > 0) {
1031 error = xfs_attr_rmtval_set(args);
1037 * If this is an atomic rename operation, we must "flip" the
1038 * incomplete flags on the "new" and "old" attribute/value pairs
1039 * so that one disappears and one appears atomically. Then we
1040 * must remove the "old" attribute/value pair.
1044 * In a separate transaction, set the incomplete flag on the
1045 * "old" attr and clear the incomplete flag on the "new" attr.
1047 error = xfs_attr_leaf_flipflags(args);
1052 * Dismantle the "old" attribute/value pair by removing
1053 * a "remote" value (if it exists).
1055 args->index = args->index2;
1056 args->blkno = args->blkno2;
1057 args->rmtblkno = args->rmtblkno2;
1058 args->rmtblkcnt = args->rmtblkcnt2;
1059 if (args->rmtblkno) {
1060 error = xfs_attr_rmtval_remove(args);
1066 * Read in the block containing the "old" attr, then
1067 * remove the "old" attr from that block (neat, huh!)
1069 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1,
1070 &bp, XFS_ATTR_FORK);
1074 (void)xfs_attr_leaf_remove(bp, args);
1077 * If the result is small enough, shrink it all into the inode.
1079 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1080 XFS_BMAP_INIT(args->flist, args->firstblock);
1081 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1082 /* bp is gone due to xfs_da_shrink_inode */
1084 error = xfs_bmap_finish(&args->trans,
1091 xfs_bmap_cancel(args->flist);
1096 * bmap_finish() may have committed the last trans
1097 * and started a new one. We need the inode to be
1098 * in all transactions.
1101 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1102 xfs_trans_ihold(args->trans, dp);
1105 xfs_da_buf_done(bp);
1108 * Commit the remove and start the next trans in series.
1110 error = xfs_attr_rolltrans(&args->trans, dp);
1112 } else if (args->rmtblkno > 0) {
1114 * Added a "remote" value, just clear the incomplete flag.
1116 error = xfs_attr_leaf_clearflag(args);
1122 * Remove a name from the leaf attribute list structure
1124 * This leaf block cannot have a "remote" value, we only call this routine
1125 * if bmap_one_block() says there is only one block (ie: no remote blks).
1128 xfs_attr_leaf_removename(xfs_da_args_t *args)
1132 int error, committed, forkoff;
1135 * Remove the attribute.
1139 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1146 error = xfs_attr_leaf_lookup_int(bp, args);
1147 if (error == ENOATTR) {
1148 xfs_da_brelse(args->trans, bp);
1152 (void)xfs_attr_leaf_remove(bp, args);
1155 * If the result is small enough, shrink it all into the inode.
1157 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1158 XFS_BMAP_INIT(args->flist, args->firstblock);
1159 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1160 /* bp is gone due to xfs_da_shrink_inode */
1162 error = xfs_bmap_finish(&args->trans, args->flist,
1168 xfs_bmap_cancel(args->flist);
1173 * bmap_finish() may have committed the last trans and started
1174 * a new one. We need the inode to be in all transactions.
1177 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1178 xfs_trans_ihold(args->trans, dp);
1181 xfs_da_buf_done(bp);
1186 * Look up a name in a leaf attribute list structure.
1188 * This leaf block cannot have a "remote" value, we only call this routine
1189 * if bmap_one_block() says there is only one block (ie: no remote blks).
1192 xfs_attr_leaf_get(xfs_da_args_t *args)
1198 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1204 error = xfs_attr_leaf_lookup_int(bp, args);
1205 if (error != EEXIST) {
1206 xfs_da_brelse(args->trans, bp);
1209 error = xfs_attr_leaf_getvalue(bp, args);
1210 xfs_da_brelse(args->trans, bp);
1211 if (!error && (args->rmtblkno > 0) && !(args->flags & ATTR_KERNOVAL)) {
1212 error = xfs_attr_rmtval_get(args);
1218 * Copy out attribute entries for attr_list(), for leaf attribute lists.
1221 xfs_attr_leaf_list(xfs_attr_list_context_t *context)
1223 xfs_attr_leafblock_t *leaf;
1227 context->cursor->blkno = 0;
1228 error = xfs_da_read_buf(NULL, context->dp, 0, -1, &bp, XFS_ATTR_FORK);
1230 return XFS_ERROR(error);
1233 if (unlikely(be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR_LEAF_MAGIC)) {
1234 XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW,
1235 context->dp->i_mount, leaf);
1236 xfs_da_brelse(NULL, bp);
1237 return XFS_ERROR(EFSCORRUPTED);
1240 error = xfs_attr_leaf_list_int(bp, context);
1241 xfs_da_brelse(NULL, bp);
1242 return XFS_ERROR(error);
1246 /*========================================================================
1247 * External routines when attribute list size > XFS_LBSIZE(mp).
1248 *========================================================================*/
1251 * Add a name to a Btree-format attribute list.
1253 * This will involve walking down the Btree, and may involve splitting
1254 * leaf nodes and even splitting intermediate nodes up to and including
1255 * the root node (a special case of an intermediate node).
1257 * "Remote" attribute values confuse the issue and atomic rename operations
1258 * add a whole extra layer of confusion on top of that.
1261 xfs_attr_node_addname(xfs_da_args_t *args)
1263 xfs_da_state_t *state;
1264 xfs_da_state_blk_t *blk;
1267 int committed, retval, error;
1270 * Fill in bucket of arguments/results/context to carry around.
1275 state = xfs_da_state_alloc();
1278 state->blocksize = state->mp->m_sb.sb_blocksize;
1279 state->node_ents = state->mp->m_attr_node_ents;
1282 * Search to see if name already exists, and get back a pointer
1283 * to where it should go.
1285 error = xfs_da_node_lookup_int(state, &retval);
1288 blk = &state->path.blk[ state->path.active-1 ];
1289 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1290 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
1292 } else if (retval == EEXIST) {
1293 if (args->flags & ATTR_CREATE)
1295 args->rename = 1; /* atomic rename op */
1296 args->blkno2 = args->blkno; /* set 2nd entry info*/
1297 args->index2 = args->index;
1298 args->rmtblkno2 = args->rmtblkno;
1299 args->rmtblkcnt2 = args->rmtblkcnt;
1301 args->rmtblkcnt = 0;
1304 retval = xfs_attr_leaf_add(blk->bp, state->args);
1305 if (retval == ENOSPC) {
1306 if (state->path.active == 1) {
1308 * Its really a single leaf node, but it had
1309 * out-of-line values so it looked like it *might*
1310 * have been a b-tree.
1312 xfs_da_state_free(state);
1313 XFS_BMAP_INIT(args->flist, args->firstblock);
1314 error = xfs_attr_leaf_to_node(args);
1316 error = xfs_bmap_finish(&args->trans,
1323 xfs_bmap_cancel(args->flist);
1328 * bmap_finish() may have committed the last trans
1329 * and started a new one. We need the inode to be
1330 * in all transactions.
1333 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1334 xfs_trans_ihold(args->trans, dp);
1338 * Commit the node conversion and start the next
1339 * trans in the chain.
1341 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1348 * Split as many Btree elements as required.
1349 * This code tracks the new and old attr's location
1350 * in the index/blkno/rmtblkno/rmtblkcnt fields and
1351 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
1353 XFS_BMAP_INIT(args->flist, args->firstblock);
1354 error = xfs_da_split(state);
1356 error = xfs_bmap_finish(&args->trans, args->flist,
1362 xfs_bmap_cancel(args->flist);
1367 * bmap_finish() may have committed the last trans and started
1368 * a new one. We need the inode to be in all transactions.
1371 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1372 xfs_trans_ihold(args->trans, dp);
1376 * Addition succeeded, update Btree hashvals.
1378 xfs_da_fixhashpath(state, &state->path);
1382 * Kill the state structure, we're done with it and need to
1383 * allow the buffers to come back later.
1385 xfs_da_state_free(state);
1389 * Commit the leaf addition or btree split and start the next
1390 * trans in the chain.
1392 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1396 * If there was an out-of-line value, allocate the blocks we
1397 * identified for its storage and copy the value. This is done
1398 * after we create the attribute so that we don't overflow the
1399 * maximum size of a transaction and/or hit a deadlock.
1401 if (args->rmtblkno > 0) {
1402 error = xfs_attr_rmtval_set(args);
1408 * If this is an atomic rename operation, we must "flip" the
1409 * incomplete flags on the "new" and "old" attribute/value pairs
1410 * so that one disappears and one appears atomically. Then we
1411 * must remove the "old" attribute/value pair.
1415 * In a separate transaction, set the incomplete flag on the
1416 * "old" attr and clear the incomplete flag on the "new" attr.
1418 error = xfs_attr_leaf_flipflags(args);
1423 * Dismantle the "old" attribute/value pair by removing
1424 * a "remote" value (if it exists).
1426 args->index = args->index2;
1427 args->blkno = args->blkno2;
1428 args->rmtblkno = args->rmtblkno2;
1429 args->rmtblkcnt = args->rmtblkcnt2;
1430 if (args->rmtblkno) {
1431 error = xfs_attr_rmtval_remove(args);
1437 * Re-find the "old" attribute entry after any split ops.
1438 * The INCOMPLETE flag means that we will find the "old"
1439 * attr, not the "new" one.
1441 args->flags |= XFS_ATTR_INCOMPLETE;
1442 state = xfs_da_state_alloc();
1445 state->blocksize = state->mp->m_sb.sb_blocksize;
1446 state->node_ents = state->mp->m_attr_node_ents;
1448 error = xfs_da_node_lookup_int(state, &retval);
1453 * Remove the name and update the hashvals in the tree.
1455 blk = &state->path.blk[ state->path.active-1 ];
1456 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1457 error = xfs_attr_leaf_remove(blk->bp, args);
1458 xfs_da_fixhashpath(state, &state->path);
1461 * Check to see if the tree needs to be collapsed.
1463 if (retval && (state->path.active > 1)) {
1464 XFS_BMAP_INIT(args->flist, args->firstblock);
1465 error = xfs_da_join(state);
1467 error = xfs_bmap_finish(&args->trans,
1474 xfs_bmap_cancel(args->flist);
1479 * bmap_finish() may have committed the last trans
1480 * and started a new one. We need the inode to be
1481 * in all transactions.
1484 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1485 xfs_trans_ihold(args->trans, dp);
1490 * Commit and start the next trans in the chain.
1492 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1495 } else if (args->rmtblkno > 0) {
1497 * Added a "remote" value, just clear the incomplete flag.
1499 error = xfs_attr_leaf_clearflag(args);
1507 xfs_da_state_free(state);
1514 * Remove a name from a B-tree attribute list.
1516 * This will involve walking down the Btree, and may involve joining
1517 * leaf nodes and even joining intermediate nodes up to and including
1518 * the root node (a special case of an intermediate node).
1521 xfs_attr_node_removename(xfs_da_args_t *args)
1523 xfs_da_state_t *state;
1524 xfs_da_state_blk_t *blk;
1527 int retval, error, committed, forkoff;
1530 * Tie a string around our finger to remind us where we are.
1533 state = xfs_da_state_alloc();
1535 state->mp = dp->i_mount;
1536 state->blocksize = state->mp->m_sb.sb_blocksize;
1537 state->node_ents = state->mp->m_attr_node_ents;
1540 * Search to see if name exists, and get back a pointer to it.
1542 error = xfs_da_node_lookup_int(state, &retval);
1543 if (error || (retval != EEXIST)) {
1550 * If there is an out-of-line value, de-allocate the blocks.
1551 * This is done before we remove the attribute so that we don't
1552 * overflow the maximum size of a transaction and/or hit a deadlock.
1554 blk = &state->path.blk[ state->path.active-1 ];
1555 ASSERT(blk->bp != NULL);
1556 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1557 if (args->rmtblkno > 0) {
1559 * Fill in disk block numbers in the state structure
1560 * so that we can get the buffers back after we commit
1561 * several transactions in the following calls.
1563 error = xfs_attr_fillstate(state);
1568 * Mark the attribute as INCOMPLETE, then bunmapi() the
1571 error = xfs_attr_leaf_setflag(args);
1574 error = xfs_attr_rmtval_remove(args);
1579 * Refill the state structure with buffers, the prior calls
1580 * released our buffers.
1582 error = xfs_attr_refillstate(state);
1588 * Remove the name and update the hashvals in the tree.
1590 blk = &state->path.blk[ state->path.active-1 ];
1591 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1592 retval = xfs_attr_leaf_remove(blk->bp, args);
1593 xfs_da_fixhashpath(state, &state->path);
1596 * Check to see if the tree needs to be collapsed.
1598 if (retval && (state->path.active > 1)) {
1599 XFS_BMAP_INIT(args->flist, args->firstblock);
1600 error = xfs_da_join(state);
1602 error = xfs_bmap_finish(&args->trans, args->flist,
1608 xfs_bmap_cancel(args->flist);
1613 * bmap_finish() may have committed the last trans and started
1614 * a new one. We need the inode to be in all transactions.
1617 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1618 xfs_trans_ihold(args->trans, dp);
1622 * Commit the Btree join operation and start a new trans.
1624 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1629 * If the result is small enough, push it all into the inode.
1631 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
1633 * Have to get rid of the copy of this dabuf in the state.
1635 ASSERT(state->path.active == 1);
1636 ASSERT(state->path.blk[0].bp);
1637 xfs_da_buf_done(state->path.blk[0].bp);
1638 state->path.blk[0].bp = NULL;
1640 error = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp,
1644 ASSERT(be16_to_cpu(((xfs_attr_leafblock_t *)
1645 bp->data)->hdr.info.magic)
1646 == XFS_ATTR_LEAF_MAGIC);
1648 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1649 XFS_BMAP_INIT(args->flist, args->firstblock);
1650 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1651 /* bp is gone due to xfs_da_shrink_inode */
1653 error = xfs_bmap_finish(&args->trans,
1660 xfs_bmap_cancel(args->flist);
1665 * bmap_finish() may have committed the last trans
1666 * and started a new one. We need the inode to be
1667 * in all transactions.
1670 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1671 xfs_trans_ihold(args->trans, dp);
1674 xfs_da_brelse(args->trans, bp);
1679 xfs_da_state_free(state);
1684 * Fill in the disk block numbers in the state structure for the buffers
1685 * that are attached to the state structure.
1686 * This is done so that we can quickly reattach ourselves to those buffers
1687 * after some set of transaction commits have released these buffers.
1690 xfs_attr_fillstate(xfs_da_state_t *state)
1692 xfs_da_state_path_t *path;
1693 xfs_da_state_blk_t *blk;
1697 * Roll down the "path" in the state structure, storing the on-disk
1698 * block number for those buffers in the "path".
1700 path = &state->path;
1701 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1702 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1704 blk->disk_blkno = xfs_da_blkno(blk->bp);
1705 xfs_da_buf_done(blk->bp);
1708 blk->disk_blkno = 0;
1713 * Roll down the "altpath" in the state structure, storing the on-disk
1714 * block number for those buffers in the "altpath".
1716 path = &state->altpath;
1717 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1718 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1720 blk->disk_blkno = xfs_da_blkno(blk->bp);
1721 xfs_da_buf_done(blk->bp);
1724 blk->disk_blkno = 0;
1732 * Reattach the buffers to the state structure based on the disk block
1733 * numbers stored in the state structure.
1734 * This is done after some set of transaction commits have released those
1735 * buffers from our grip.
1738 xfs_attr_refillstate(xfs_da_state_t *state)
1740 xfs_da_state_path_t *path;
1741 xfs_da_state_blk_t *blk;
1745 * Roll down the "path" in the state structure, storing the on-disk
1746 * block number for those buffers in the "path".
1748 path = &state->path;
1749 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1750 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1751 if (blk->disk_blkno) {
1752 error = xfs_da_read_buf(state->args->trans,
1754 blk->blkno, blk->disk_blkno,
1755 &blk->bp, XFS_ATTR_FORK);
1764 * Roll down the "altpath" in the state structure, storing the on-disk
1765 * block number for those buffers in the "altpath".
1767 path = &state->altpath;
1768 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1769 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1770 if (blk->disk_blkno) {
1771 error = xfs_da_read_buf(state->args->trans,
1773 blk->blkno, blk->disk_blkno,
1774 &blk->bp, XFS_ATTR_FORK);
1786 * Look up a filename in a node attribute list.
1788 * This routine gets called for any attribute fork that has more than one
1789 * block, ie: both true Btree attr lists and for single-leaf-blocks with
1790 * "remote" values taking up more blocks.
1793 xfs_attr_node_get(xfs_da_args_t *args)
1795 xfs_da_state_t *state;
1796 xfs_da_state_blk_t *blk;
1800 state = xfs_da_state_alloc();
1802 state->mp = args->dp->i_mount;
1803 state->blocksize = state->mp->m_sb.sb_blocksize;
1804 state->node_ents = state->mp->m_attr_node_ents;
1807 * Search to see if name exists, and get back a pointer to it.
1809 error = xfs_da_node_lookup_int(state, &retval);
1812 } else if (retval == EEXIST) {
1813 blk = &state->path.blk[ state->path.active-1 ];
1814 ASSERT(blk->bp != NULL);
1815 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1818 * Get the value, local or "remote"
1820 retval = xfs_attr_leaf_getvalue(blk->bp, args);
1821 if (!retval && (args->rmtblkno > 0)
1822 && !(args->flags & ATTR_KERNOVAL)) {
1823 retval = xfs_attr_rmtval_get(args);
1828 * If not in a transaction, we have to release all the buffers.
1830 for (i = 0; i < state->path.active; i++) {
1831 xfs_da_brelse(args->trans, state->path.blk[i].bp);
1832 state->path.blk[i].bp = NULL;
1835 xfs_da_state_free(state);
1839 STATIC int /* error */
1840 xfs_attr_node_list(xfs_attr_list_context_t *context)
1842 attrlist_cursor_kern_t *cursor;
1843 xfs_attr_leafblock_t *leaf;
1844 xfs_da_intnode_t *node;
1845 xfs_da_node_entry_t *btree;
1849 cursor = context->cursor;
1850 cursor->initted = 1;
1853 * Do all sorts of validation on the passed-in cursor structure.
1854 * If anything is amiss, ignore the cursor and look up the hashval
1855 * starting from the btree root.
1858 if (cursor->blkno > 0) {
1859 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1860 &bp, XFS_ATTR_FORK);
1861 if ((error != 0) && (error != EFSCORRUPTED))
1865 switch (be16_to_cpu(node->hdr.info.magic)) {
1866 case XFS_DA_NODE_MAGIC:
1867 xfs_attr_trace_l_cn("wrong blk", context, node);
1868 xfs_da_brelse(NULL, bp);
1871 case XFS_ATTR_LEAF_MAGIC:
1873 if (cursor->hashval > be32_to_cpu(leaf->entries[
1874 be16_to_cpu(leaf->hdr.count)-1].hashval)) {
1875 xfs_attr_trace_l_cl("wrong blk",
1877 xfs_da_brelse(NULL, bp);
1879 } else if (cursor->hashval <=
1880 be32_to_cpu(leaf->entries[0].hashval)) {
1881 xfs_attr_trace_l_cl("maybe wrong blk",
1883 xfs_da_brelse(NULL, bp);
1888 xfs_attr_trace_l_c("wrong blk - ??", context);
1889 xfs_da_brelse(NULL, bp);
1896 * We did not find what we expected given the cursor's contents,
1897 * so we start from the top and work down based on the hash value.
1898 * Note that start of node block is same as start of leaf block.
1903 error = xfs_da_read_buf(NULL, context->dp,
1904 cursor->blkno, -1, &bp,
1908 if (unlikely(bp == NULL)) {
1909 XFS_ERROR_REPORT("xfs_attr_node_list(2)",
1911 context->dp->i_mount);
1912 return(XFS_ERROR(EFSCORRUPTED));
1915 if (be16_to_cpu(node->hdr.info.magic)
1916 == XFS_ATTR_LEAF_MAGIC)
1918 if (unlikely(be16_to_cpu(node->hdr.info.magic)
1919 != XFS_DA_NODE_MAGIC)) {
1920 XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
1922 context->dp->i_mount,
1924 xfs_da_brelse(NULL, bp);
1925 return(XFS_ERROR(EFSCORRUPTED));
1927 btree = node->btree;
1928 for (i = 0; i < be16_to_cpu(node->hdr.count);
1931 <= be32_to_cpu(btree->hashval)) {
1932 cursor->blkno = be32_to_cpu(btree->before);
1933 xfs_attr_trace_l_cb("descending",
1938 if (i == be16_to_cpu(node->hdr.count)) {
1939 xfs_da_brelse(NULL, bp);
1942 xfs_da_brelse(NULL, bp);
1948 * Roll upward through the blocks, processing each leaf block in
1949 * order. As long as there is space in the result buffer, keep
1950 * adding the information.
1954 if (unlikely(be16_to_cpu(leaf->hdr.info.magic)
1955 != XFS_ATTR_LEAF_MAGIC)) {
1956 XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
1958 context->dp->i_mount, leaf);
1959 xfs_da_brelse(NULL, bp);
1960 return(XFS_ERROR(EFSCORRUPTED));
1962 error = xfs_attr_leaf_list_int(bp, context);
1964 xfs_da_brelse(NULL, bp);
1967 if (context->seen_enough || leaf->hdr.info.forw == 0)
1969 cursor->blkno = be32_to_cpu(leaf->hdr.info.forw);
1970 xfs_da_brelse(NULL, bp);
1971 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1972 &bp, XFS_ATTR_FORK);
1975 if (unlikely((bp == NULL))) {
1976 XFS_ERROR_REPORT("xfs_attr_node_list(5)",
1978 context->dp->i_mount);
1979 return(XFS_ERROR(EFSCORRUPTED));
1982 xfs_da_brelse(NULL, bp);
1987 /*========================================================================
1988 * External routines for manipulating out-of-line attribute values.
1989 *========================================================================*/
1992 * Read the value associated with an attribute from the out-of-line buffer
1993 * that we stored it in.
1996 xfs_attr_rmtval_get(xfs_da_args_t *args)
1998 xfs_bmbt_irec_t map[ATTR_RMTVALUE_MAPSIZE];
2003 int nmap, error, tmp, valuelen, blkcnt, i;
2006 ASSERT(!(args->flags & ATTR_KERNOVAL));
2008 mp = args->dp->i_mount;
2010 valuelen = args->valuelen;
2011 lblkno = args->rmtblkno;
2012 while (valuelen > 0) {
2013 nmap = ATTR_RMTVALUE_MAPSIZE;
2014 error = xfs_bmapi(args->trans, args->dp, (xfs_fileoff_t)lblkno,
2016 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2017 NULL, 0, map, &nmap, NULL, NULL);
2022 for (i = 0; (i < nmap) && (valuelen > 0); i++) {
2023 ASSERT((map[i].br_startblock != DELAYSTARTBLOCK) &&
2024 (map[i].br_startblock != HOLESTARTBLOCK));
2025 dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
2026 blkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
2027 error = xfs_read_buf(mp, mp->m_ddev_targp, dblkno,
2028 blkcnt, XFS_BUF_LOCK, &bp);
2032 tmp = (valuelen < XFS_BUF_SIZE(bp))
2033 ? valuelen : XFS_BUF_SIZE(bp);
2034 xfs_biomove(bp, 0, tmp, dst, XFS_B_READ);
2039 lblkno += map[i].br_blockcount;
2042 ASSERT(valuelen == 0);
2047 * Write the value associated with an attribute into the out-of-line buffer
2048 * that we have defined for it.
2051 xfs_attr_rmtval_set(xfs_da_args_t *args)
2054 xfs_fileoff_t lfileoff;
2056 xfs_bmbt_irec_t map;
2061 int blkcnt, valuelen, nmap, error, tmp, committed;
2068 * Find a "hole" in the attribute address space large enough for
2069 * us to drop the new attribute's value into.
2071 blkcnt = XFS_B_TO_FSB(mp, args->valuelen);
2073 error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff,
2078 args->rmtblkno = lblkno = (xfs_dablk_t)lfileoff;
2079 args->rmtblkcnt = blkcnt;
2082 * Roll through the "value", allocating blocks on disk as required.
2084 while (blkcnt > 0) {
2086 * Allocate a single extent, up to the size of the value.
2088 XFS_BMAP_INIT(args->flist, args->firstblock);
2090 error = xfs_bmapi(args->trans, dp, (xfs_fileoff_t)lblkno,
2092 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA |
2094 args->firstblock, args->total, &map, &nmap,
2097 error = xfs_bmap_finish(&args->trans, args->flist,
2103 xfs_bmap_cancel(args->flist);
2108 * bmap_finish() may have committed the last trans and started
2109 * a new one. We need the inode to be in all transactions.
2112 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
2113 xfs_trans_ihold(args->trans, dp);
2117 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2118 (map.br_startblock != HOLESTARTBLOCK));
2119 lblkno += map.br_blockcount;
2120 blkcnt -= map.br_blockcount;
2123 * Start the next trans in the chain.
2125 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
2130 * Roll through the "value", copying the attribute value to the
2131 * already-allocated blocks. Blocks are written synchronously
2132 * so that we can know they are all on disk before we turn off
2133 * the INCOMPLETE flag.
2135 lblkno = args->rmtblkno;
2136 valuelen = args->valuelen;
2137 while (valuelen > 0) {
2139 * Try to remember where we decided to put the value.
2141 XFS_BMAP_INIT(args->flist, args->firstblock);
2143 error = xfs_bmapi(NULL, dp, (xfs_fileoff_t)lblkno,
2145 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2146 args->firstblock, 0, &map, &nmap,
2152 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2153 (map.br_startblock != HOLESTARTBLOCK));
2155 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2156 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2158 bp = xfs_buf_get_flags(mp->m_ddev_targp, dblkno,
2159 blkcnt, XFS_BUF_LOCK);
2161 ASSERT(!XFS_BUF_GETERROR(bp));
2163 tmp = (valuelen < XFS_BUF_SIZE(bp)) ? valuelen :
2165 xfs_biomove(bp, 0, tmp, src, XFS_B_WRITE);
2166 if (tmp < XFS_BUF_SIZE(bp))
2167 xfs_biozero(bp, tmp, XFS_BUF_SIZE(bp) - tmp);
2168 if ((error = xfs_bwrite(mp, bp))) {/* GROT: NOTE: synchronous write */
2174 lblkno += map.br_blockcount;
2176 ASSERT(valuelen == 0);
2181 * Remove the value associated with an attribute by deleting the
2182 * out-of-line buffer that it is stored on.
2185 xfs_attr_rmtval_remove(xfs_da_args_t *args)
2188 xfs_bmbt_irec_t map;
2192 int valuelen, blkcnt, nmap, error, done, committed;
2194 mp = args->dp->i_mount;
2197 * Roll through the "value", invalidating the attribute value's
2200 lblkno = args->rmtblkno;
2201 valuelen = args->rmtblkcnt;
2202 while (valuelen > 0) {
2204 * Try to remember where we decided to put the value.
2206 XFS_BMAP_INIT(args->flist, args->firstblock);
2208 error = xfs_bmapi(NULL, args->dp, (xfs_fileoff_t)lblkno,
2210 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2211 args->firstblock, 0, &map, &nmap,
2217 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2218 (map.br_startblock != HOLESTARTBLOCK));
2220 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2221 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2224 * If the "remote" value is in the cache, remove it.
2226 bp = xfs_incore(mp->m_ddev_targp, dblkno, blkcnt,
2227 XFS_INCORE_TRYLOCK);
2230 XFS_BUF_UNDELAYWRITE(bp);
2235 valuelen -= map.br_blockcount;
2237 lblkno += map.br_blockcount;
2241 * Keep de-allocating extents until the remote-value region is gone.
2243 lblkno = args->rmtblkno;
2244 blkcnt = args->rmtblkcnt;
2247 XFS_BMAP_INIT(args->flist, args->firstblock);
2248 error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
2249 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2250 1, args->firstblock, args->flist,
2253 error = xfs_bmap_finish(&args->trans, args->flist,
2259 xfs_bmap_cancel(args->flist);
2264 * bmap_finish() may have committed the last trans and started
2265 * a new one. We need the inode to be in all transactions.
2268 xfs_trans_ijoin(args->trans, args->dp, XFS_ILOCK_EXCL);
2269 xfs_trans_ihold(args->trans, args->dp);
2273 * Close out trans and start the next one in the chain.
2275 if ((error = xfs_attr_rolltrans(&args->trans, args->dp)))
2281 #if defined(XFS_ATTR_TRACE)
2283 * Add a trace buffer entry for an attr_list context structure.
2286 xfs_attr_trace_l_c(char *where, struct xfs_attr_list_context *context)
2288 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_C, where,
2289 (__psunsigned_t)context->dp,
2290 (__psunsigned_t)context->cursor->hashval,
2291 (__psunsigned_t)context->cursor->blkno,
2292 (__psunsigned_t)context->cursor->offset,
2293 (__psunsigned_t)context->alist,
2294 (__psunsigned_t)context->bufsize,
2295 (__psunsigned_t)context->count,
2296 (__psunsigned_t)context->firstu,
2298 ((context->count > 0) &&
2299 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2300 ? (ATTR_ENTRY(context->alist,
2301 context->count-1)->a_valuelen)
2303 (__psunsigned_t)context->dupcnt,
2304 (__psunsigned_t)context->flags,
2305 (__psunsigned_t)NULL,
2306 (__psunsigned_t)NULL,
2307 (__psunsigned_t)NULL);
2311 * Add a trace buffer entry for a context structure and a Btree node.
2314 xfs_attr_trace_l_cn(char *where, struct xfs_attr_list_context *context,
2315 struct xfs_da_intnode *node)
2317 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CN, where,
2318 (__psunsigned_t)context->dp,
2319 (__psunsigned_t)context->cursor->hashval,
2320 (__psunsigned_t)context->cursor->blkno,
2321 (__psunsigned_t)context->cursor->offset,
2322 (__psunsigned_t)context->alist,
2323 (__psunsigned_t)context->bufsize,
2324 (__psunsigned_t)context->count,
2325 (__psunsigned_t)context->firstu,
2327 ((context->count > 0) &&
2328 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2329 ? (ATTR_ENTRY(context->alist,
2330 context->count-1)->a_valuelen)
2332 (__psunsigned_t)context->dupcnt,
2333 (__psunsigned_t)context->flags,
2334 (__psunsigned_t)be16_to_cpu(node->hdr.count),
2335 (__psunsigned_t)be32_to_cpu(node->btree[0].hashval),
2336 (__psunsigned_t)be32_to_cpu(node->btree[
2337 be16_to_cpu(node->hdr.count)-1].hashval));
2341 * Add a trace buffer entry for a context structure and a Btree element.
2344 xfs_attr_trace_l_cb(char *where, struct xfs_attr_list_context *context,
2345 struct xfs_da_node_entry *btree)
2347 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CB, where,
2348 (__psunsigned_t)context->dp,
2349 (__psunsigned_t)context->cursor->hashval,
2350 (__psunsigned_t)context->cursor->blkno,
2351 (__psunsigned_t)context->cursor->offset,
2352 (__psunsigned_t)context->alist,
2353 (__psunsigned_t)context->bufsize,
2354 (__psunsigned_t)context->count,
2355 (__psunsigned_t)context->firstu,
2357 ((context->count > 0) &&
2358 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2359 ? (ATTR_ENTRY(context->alist,
2360 context->count-1)->a_valuelen)
2362 (__psunsigned_t)context->dupcnt,
2363 (__psunsigned_t)context->flags,
2364 (__psunsigned_t)be32_to_cpu(btree->hashval),
2365 (__psunsigned_t)be32_to_cpu(btree->before),
2366 (__psunsigned_t)NULL);
2370 * Add a trace buffer entry for a context structure and a leaf block.
2373 xfs_attr_trace_l_cl(char *where, struct xfs_attr_list_context *context,
2374 struct xfs_attr_leafblock *leaf)
2376 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CL, where,
2377 (__psunsigned_t)context->dp,
2378 (__psunsigned_t)context->cursor->hashval,
2379 (__psunsigned_t)context->cursor->blkno,
2380 (__psunsigned_t)context->cursor->offset,
2381 (__psunsigned_t)context->alist,
2382 (__psunsigned_t)context->bufsize,
2383 (__psunsigned_t)context->count,
2384 (__psunsigned_t)context->firstu,
2386 ((context->count > 0) &&
2387 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2388 ? (ATTR_ENTRY(context->alist,
2389 context->count-1)->a_valuelen)
2391 (__psunsigned_t)context->dupcnt,
2392 (__psunsigned_t)context->flags,
2393 (__psunsigned_t)be16_to_cpu(leaf->hdr.count),
2394 (__psunsigned_t)be32_to_cpu(leaf->entries[0].hashval),
2395 (__psunsigned_t)be32_to_cpu(leaf->entries[
2396 be16_to_cpu(leaf->hdr.count)-1].hashval));
2400 * Add a trace buffer entry for the arguments given to the routine,
2404 xfs_attr_trace_enter(int type, char *where,
2405 __psunsigned_t a2, __psunsigned_t a3,
2406 __psunsigned_t a4, __psunsigned_t a5,
2407 __psunsigned_t a6, __psunsigned_t a7,
2408 __psunsigned_t a8, __psunsigned_t a9,
2409 __psunsigned_t a10, __psunsigned_t a11,
2410 __psunsigned_t a12, __psunsigned_t a13,
2411 __psunsigned_t a14, __psunsigned_t a15)
2413 ASSERT(xfs_attr_trace_buf);
2414 ktrace_enter(xfs_attr_trace_buf, (void *)((__psunsigned_t)type),
2416 (void *)a2, (void *)a3, (void *)a4,
2417 (void *)a5, (void *)a6, (void *)a7,
2418 (void *)a8, (void *)a9, (void *)a10,
2419 (void *)a11, (void *)a12, (void *)a13,
2420 (void *)a14, (void *)a15);
2422 #endif /* XFS_ATTR_TRACE */
2425 /*========================================================================
2426 * System (pseudo) namespace attribute interface routines.
2427 *========================================================================*/
2430 posix_acl_access_set(
2431 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2433 return xfs_acl_vset(vp, data, size, _ACL_TYPE_ACCESS);
2437 posix_acl_access_remove(
2438 bhv_vnode_t *vp, char *name, int xflags)
2440 return xfs_acl_vremove(vp, _ACL_TYPE_ACCESS);
2444 posix_acl_access_get(
2445 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2447 return xfs_acl_vget(vp, data, size, _ACL_TYPE_ACCESS);
2451 posix_acl_access_exists(
2454 return xfs_acl_vhasacl_access(vp);
2458 posix_acl_default_set(
2459 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2461 return xfs_acl_vset(vp, data, size, _ACL_TYPE_DEFAULT);
2465 posix_acl_default_get(
2466 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2468 return xfs_acl_vget(vp, data, size, _ACL_TYPE_DEFAULT);
2472 posix_acl_default_remove(
2473 bhv_vnode_t *vp, char *name, int xflags)
2475 return xfs_acl_vremove(vp, _ACL_TYPE_DEFAULT);
2479 posix_acl_default_exists(
2482 return xfs_acl_vhasacl_default(vp);
2485 static struct attrnames posix_acl_access = {
2486 .attr_name = "posix_acl_access",
2487 .attr_namelen = sizeof("posix_acl_access") - 1,
2488 .attr_get = posix_acl_access_get,
2489 .attr_set = posix_acl_access_set,
2490 .attr_remove = posix_acl_access_remove,
2491 .attr_exists = posix_acl_access_exists,
2494 static struct attrnames posix_acl_default = {
2495 .attr_name = "posix_acl_default",
2496 .attr_namelen = sizeof("posix_acl_default") - 1,
2497 .attr_get = posix_acl_default_get,
2498 .attr_set = posix_acl_default_set,
2499 .attr_remove = posix_acl_default_remove,
2500 .attr_exists = posix_acl_default_exists,
2503 static struct attrnames *attr_system_names[] =
2504 { &posix_acl_access, &posix_acl_default };
2507 /*========================================================================
2508 * Namespace-prefix-style attribute name interface routines.
2509 *========================================================================*/
2513 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2515 return -bhv_vop_attr_set(vp, name, data, size, xflags, NULL);
2520 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2522 int error, asize = size;
2524 error = bhv_vop_attr_get(vp, name, data, &asize, xflags, NULL);
2531 attr_generic_remove(
2532 bhv_vnode_t *vp, char *name, int xflags)
2534 return -bhv_vop_attr_remove(vp, name, xflags, NULL);
2538 attr_generic_listadd(
2539 attrnames_t *prefix,
2540 attrnames_t *namesp,
2545 char *p = data + *result;
2547 *result += prefix->attr_namelen;
2548 *result += namesp->attr_namelen + 1;
2553 strcpy(p, prefix->attr_name);
2554 p += prefix->attr_namelen;
2555 strcpy(p, namesp->attr_name);
2556 p += namesp->attr_namelen + 1;
2567 attrnames_t *namesp;
2570 for (i = 0; i < ATTR_SYSCOUNT; i++) {
2571 namesp = attr_system_names[i];
2572 if (!namesp->attr_exists || !namesp->attr_exists(vp))
2574 error = attr_generic_listadd(&attr_system, namesp,
2575 data, size, result);
2584 bhv_vnode_t *vp, void *data, size_t size, int xflags, ssize_t *result)
2586 attrlist_cursor_kern_t cursor = { 0 };
2589 error = bhv_vop_attr_list(vp, data, size, xflags, &cursor, NULL);
2593 return attr_system_list(vp, data, size, result);
2597 attr_lookup_namespace(
2599 struct attrnames **names,
2604 for (i = 0; i < nnames; i++)
2605 if (!strncmp(name, names[i]->attr_name, names[i]->attr_namelen))
2611 * Some checks to prevent people abusing EAs to get over quota:
2612 * - Don't allow modifying user EAs on devices/symlinks;
2613 * - Don't allow modifying user EAs if sticky bit set;
2620 struct inode *inode = vn_to_inode(vp);
2622 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2624 if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode) &&
2625 !capable(CAP_SYS_ADMIN))
2627 if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) &&
2628 (current_fsuid(cred) != inode->i_uid) && !capable(CAP_FOWNER))
2634 attr_trusted_capable(
2638 struct inode *inode = vn_to_inode(vp);
2640 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2642 if (!capable(CAP_SYS_ADMIN))
2648 attr_secure_capable(
2652 return -ENOSECURITY;
2657 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2659 attrnames_t *namesp;
2662 if (xflags & ATTR_CREATE)
2665 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2668 error = namesp->attr_set(vp, name, data, size, xflags);
2670 error = vn_revalidate(vp);
2676 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2678 attrnames_t *namesp;
2680 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2683 return namesp->attr_get(vp, name, data, size, xflags);
2688 bhv_vnode_t *vp, char *name, int xflags)
2690 attrnames_t *namesp;
2692 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2695 return namesp->attr_remove(vp, name, xflags);
2698 struct attrnames attr_system = {
2699 .attr_name = "system.",
2700 .attr_namelen = sizeof("system.") - 1,
2701 .attr_flag = ATTR_SYSTEM,
2702 .attr_get = attr_system_get,
2703 .attr_set = attr_system_set,
2704 .attr_remove = attr_system_remove,
2705 .attr_capable = (attrcapable_t)fs_noerr,
2708 struct attrnames attr_trusted = {
2709 .attr_name = "trusted.",
2710 .attr_namelen = sizeof("trusted.") - 1,
2711 .attr_flag = ATTR_ROOT,
2712 .attr_get = attr_generic_get,
2713 .attr_set = attr_generic_set,
2714 .attr_remove = attr_generic_remove,
2715 .attr_capable = attr_trusted_capable,
2718 struct attrnames attr_secure = {
2719 .attr_name = "security.",
2720 .attr_namelen = sizeof("security.") - 1,
2721 .attr_flag = ATTR_SECURE,
2722 .attr_get = attr_generic_get,
2723 .attr_set = attr_generic_set,
2724 .attr_remove = attr_generic_remove,
2725 .attr_capable = attr_secure_capable,
2728 struct attrnames attr_user = {
2729 .attr_name = "user.",
2730 .attr_namelen = sizeof("user.") - 1,
2731 .attr_get = attr_generic_get,
2732 .attr_set = attr_generic_set,
2733 .attr_remove = attr_generic_remove,
2734 .attr_capable = attr_user_capable,
2737 struct attrnames *attr_namespaces[] =
2738 { &attr_system, &attr_trusted, &attr_secure, &attr_user };