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;
159 xfs_attr_get(bhv_desc_t *bdp, const char *name, char *value, int *valuelenp,
160 int flags, struct cred *cred)
162 xfs_inode_t *ip = XFS_BHVTOI(bdp);
165 XFS_STATS_INC(xs_attr_get);
169 namelen = strlen(name);
170 if (namelen >= MAXNAMELEN)
171 return(EFAULT); /* match IRIX behaviour */
173 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
176 xfs_ilock(ip, XFS_ILOCK_SHARED);
177 error = xfs_attr_fetch(ip, name, namelen, value, valuelenp, flags, cred);
178 xfs_iunlock(ip, XFS_ILOCK_SHARED);
183 xfs_attr_set_int(xfs_inode_t *dp, const char *name, int namelen,
184 char *value, int valuelen, int flags)
187 xfs_fsblock_t firstblock;
188 xfs_bmap_free_t flist;
189 int error, err2, committed;
192 xfs_mount_t *mp = dp->i_mount;
193 int rsvd = (flags & ATTR_ROOT) != 0;
196 * Attach the dquots to the inode.
198 if ((error = XFS_QM_DQATTACH(mp, dp, 0)))
202 * Determine space new attribute will use, and if it would be
203 * "local" or "remote" (note: local != inline).
205 size = xfs_attr_leaf_newentsize(namelen, valuelen,
206 mp->m_sb.sb_blocksize, &local);
209 * If the inode doesn't have an attribute fork, add one.
210 * (inode must not be locked when we call this routine)
212 if (XFS_IFORK_Q(dp) == 0) {
213 if ((error = xfs_bmap_add_attrfork(dp, 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;
234 nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK);
236 if (size > (mp->m_sb.sb_blocksize >> 1)) {
237 /* Double split possible */
241 uint dblocks = XFS_B_TO_FSB(mp, valuelen);
242 /* Out of line attribute, cannot double split, but make
243 * room for the attribute value itself.
246 nblks += XFS_NEXTENTADD_SPACE_RES(mp, dblocks, XFS_ATTR_FORK);
249 /* Size is now blocks for attribute data */
253 * Start our first transaction of the day.
255 * All future transactions during this code must be "chained" off
256 * this one via the trans_dup() call. All transactions will contain
257 * the inode, and the inode will always be marked with trans_ihold().
258 * Since the inode will be locked in all transactions, we must log
259 * the inode in every transaction to let it float upward through
262 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_SET);
265 * Root fork attributes can use reserved data blocks for this
266 * operation if necessary
270 args.trans->t_flags |= XFS_TRANS_RESERVE;
272 if ((error = xfs_trans_reserve(args.trans, (uint) nblks,
273 XFS_ATTRSET_LOG_RES(mp, nblks),
274 0, XFS_TRANS_PERM_LOG_RES,
275 XFS_ATTRSET_LOG_COUNT))) {
276 xfs_trans_cancel(args.trans, 0);
279 xfs_ilock(dp, XFS_ILOCK_EXCL);
281 error = XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, args.trans, dp, nblks, 0,
282 rsvd ? XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES :
283 XFS_QMOPT_RES_REGBLKS);
285 xfs_iunlock(dp, XFS_ILOCK_EXCL);
286 xfs_trans_cancel(args.trans, XFS_TRANS_RELEASE_LOG_RES);
290 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
291 xfs_trans_ihold(args.trans, dp);
294 * If the attribute list is non-existent or a shortform list,
295 * upgrade it to a single-leaf-block attribute list.
297 if ((dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
298 ((dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS) &&
299 (dp->i_d.di_anextents == 0))) {
302 * Build initial attribute list (if required).
304 if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
305 xfs_attr_shortform_create(&args);
308 * Try to add the attr to the attribute list in
311 error = xfs_attr_shortform_addname(&args);
312 if (error != ENOSPC) {
314 * Commit the shortform mods, and we're done.
315 * NOTE: this is also the error path (EEXIST, etc).
317 ASSERT(args.trans != NULL);
320 * If this is a synchronous mount, make sure that
321 * the transaction goes to disk before returning
324 if (mp->m_flags & XFS_MOUNT_WSYNC) {
325 xfs_trans_set_sync(args.trans);
327 err2 = xfs_trans_commit(args.trans,
328 XFS_TRANS_RELEASE_LOG_RES,
330 xfs_iunlock(dp, XFS_ILOCK_EXCL);
333 * Hit the inode change time.
335 if (!error && (flags & ATTR_KERNOTIME) == 0) {
336 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
338 return(error == 0 ? err2 : error);
342 * It won't fit in the shortform, transform to a leaf block.
343 * GROT: another possible req'mt for a double-split btree op.
345 XFS_BMAP_INIT(args.flist, args.firstblock);
346 error = xfs_attr_shortform_to_leaf(&args);
348 error = xfs_bmap_finish(&args.trans, args.flist,
349 *args.firstblock, &committed);
354 xfs_bmap_cancel(&flist);
359 * bmap_finish() may have committed the last trans and started
360 * a new one. We need the inode to be in all transactions.
363 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
364 xfs_trans_ihold(args.trans, dp);
368 * Commit the leaf transformation. We'll need another (linked)
369 * transaction to add the new attribute to the leaf.
371 if ((error = xfs_attr_rolltrans(&args.trans, dp)))
376 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
377 error = xfs_attr_leaf_addname(&args);
379 error = xfs_attr_node_addname(&args);
386 * If this is a synchronous mount, make sure that the
387 * transaction goes to disk before returning to the user.
389 if (mp->m_flags & XFS_MOUNT_WSYNC) {
390 xfs_trans_set_sync(args.trans);
394 * Commit the last in the sequence of transactions.
396 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
397 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES,
399 xfs_iunlock(dp, XFS_ILOCK_EXCL);
402 * Hit the inode change time.
404 if (!error && (flags & ATTR_KERNOTIME) == 0) {
405 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
412 xfs_trans_cancel(args.trans,
413 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
414 xfs_iunlock(dp, XFS_ILOCK_EXCL);
419 xfs_attr_set(bhv_desc_t *bdp, const char *name, char *value, int valuelen, int flags,
425 namelen = strlen(name);
426 if (namelen >= MAXNAMELEN)
427 return EFAULT; /* match IRIX behaviour */
429 XFS_STATS_INC(xs_attr_set);
431 dp = XFS_BHVTOI(bdp);
432 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
435 return xfs_attr_set_int(dp, name, namelen, value, valuelen, flags);
439 * Generic handler routine to remove a name from an attribute list.
440 * Transitions attribute list from Btree to shortform as necessary.
443 xfs_attr_remove_int(xfs_inode_t *dp, const char *name, int namelen, int flags)
446 xfs_fsblock_t firstblock;
447 xfs_bmap_free_t flist;
449 xfs_mount_t *mp = dp->i_mount;
452 * Fill in the arg structure for this request.
454 memset((char *)&args, 0, sizeof(args));
456 args.namelen = namelen;
458 args.hashval = xfs_da_hashname(args.name, args.namelen);
460 args.firstblock = &firstblock;
463 args.whichfork = XFS_ATTR_FORK;
466 * Attach the dquots to the inode.
468 if ((error = XFS_QM_DQATTACH(mp, dp, 0)))
472 * Start our first transaction of the day.
474 * All future transactions during this code must be "chained" off
475 * this one via the trans_dup() call. All transactions will contain
476 * the inode, and the inode will always be marked with trans_ihold().
477 * Since the inode will be locked in all transactions, we must log
478 * the inode in every transaction to let it float upward through
481 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_RM);
484 * Root fork attributes can use reserved data blocks for this
485 * operation if necessary
488 if (flags & ATTR_ROOT)
489 args.trans->t_flags |= XFS_TRANS_RESERVE;
491 if ((error = xfs_trans_reserve(args.trans,
492 XFS_ATTRRM_SPACE_RES(mp),
493 XFS_ATTRRM_LOG_RES(mp),
494 0, XFS_TRANS_PERM_LOG_RES,
495 XFS_ATTRRM_LOG_COUNT))) {
496 xfs_trans_cancel(args.trans, 0);
500 xfs_ilock(dp, XFS_ILOCK_EXCL);
502 * No need to make quota reservations here. We expect to release some
503 * blocks not allocate in the common case.
505 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
506 xfs_trans_ihold(args.trans, dp);
509 * Decide on what work routines to call based on the inode size.
511 if (XFS_IFORK_Q(dp) == 0 ||
512 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
513 dp->i_d.di_anextents == 0)) {
514 error = XFS_ERROR(ENOATTR);
517 if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
518 ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
519 error = xfs_attr_shortform_remove(&args);
523 } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
524 error = xfs_attr_leaf_removename(&args);
526 error = xfs_attr_node_removename(&args);
533 * If this is a synchronous mount, make sure that the
534 * transaction goes to disk before returning to the user.
536 if (mp->m_flags & XFS_MOUNT_WSYNC) {
537 xfs_trans_set_sync(args.trans);
541 * Commit the last in the sequence of transactions.
543 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
544 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES,
546 xfs_iunlock(dp, XFS_ILOCK_EXCL);
549 * Hit the inode change time.
551 if (!error && (flags & ATTR_KERNOTIME) == 0) {
552 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
559 xfs_trans_cancel(args.trans,
560 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
561 xfs_iunlock(dp, XFS_ILOCK_EXCL);
566 xfs_attr_remove(bhv_desc_t *bdp, const char *name, int flags, struct cred *cred)
571 namelen = strlen(name);
572 if (namelen >= MAXNAMELEN)
573 return EFAULT; /* match IRIX behaviour */
575 XFS_STATS_INC(xs_attr_remove);
577 dp = XFS_BHVTOI(bdp);
578 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
581 xfs_ilock(dp, XFS_ILOCK_SHARED);
582 if (XFS_IFORK_Q(dp) == 0 ||
583 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
584 dp->i_d.di_anextents == 0)) {
585 xfs_iunlock(dp, XFS_ILOCK_SHARED);
586 return(XFS_ERROR(ENOATTR));
588 xfs_iunlock(dp, XFS_ILOCK_SHARED);
590 return xfs_attr_remove_int(dp, name, namelen, flags);
594 xfs_attr_list_int(xfs_attr_list_context_t *context)
597 xfs_inode_t *dp = context->dp;
600 * Decide on what work routines to call based on the inode size.
602 if (XFS_IFORK_Q(dp) == 0 ||
603 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
604 dp->i_d.di_anextents == 0)) {
606 } else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
607 error = xfs_attr_shortform_list(context);
608 } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
609 error = xfs_attr_leaf_list(context);
611 error = xfs_attr_node_list(context);
616 #define ATTR_ENTBASESIZE /* minimum bytes used by an attr */ \
617 (((struct attrlist_ent *) 0)->a_name - (char *) 0)
618 #define ATTR_ENTSIZE(namelen) /* actual bytes used by an attr */ \
619 ((ATTR_ENTBASESIZE + (namelen) + 1 + sizeof(u_int32_t)-1) \
620 & ~(sizeof(u_int32_t)-1))
623 * Format an attribute and copy it out to the user's buffer.
624 * Take care to check values and protect against them changing later,
625 * we may be reading them directly out of a user buffer.
629 xfs_attr_put_listent(xfs_attr_list_context_t *context, attrnames_t *namesp,
630 char *name, int namelen,
631 int valuelen, char *value)
636 ASSERT(!(context->flags & ATTR_KERNOVAL));
637 ASSERT(context->count >= 0);
638 ASSERT(context->count < (ATTR_MAX_VALUELEN/8));
639 ASSERT(context->firstu >= sizeof(*context->alist));
640 ASSERT(context->firstu <= context->bufsize);
642 arraytop = sizeof(*context->alist) +
643 context->count * sizeof(context->alist->al_offset[0]);
644 context->firstu -= ATTR_ENTSIZE(namelen);
645 if (context->firstu < arraytop) {
646 xfs_attr_trace_l_c("buffer full", context);
647 context->alist->al_more = 1;
648 context->seen_enough = 1;
652 aep = (attrlist_ent_t *)&(((char *)context->alist)[ context->firstu ]);
653 aep->a_valuelen = valuelen;
654 memcpy(aep->a_name, name, namelen);
655 aep->a_name[ namelen ] = 0;
656 context->alist->al_offset[ context->count++ ] = context->firstu;
657 context->alist->al_count = context->count;
658 xfs_attr_trace_l_c("add", context);
663 xfs_attr_kern_list(xfs_attr_list_context_t *context, attrnames_t *namesp,
664 char *name, int namelen,
665 int valuelen, char *value)
670 ASSERT(context->count >= 0);
672 arraytop = context->count + namesp->attr_namelen + namelen + 1;
673 if (arraytop > context->firstu) {
674 context->count = -1; /* insufficient space */
677 offset = (char *)context->alist + context->count;
678 strncpy(offset, namesp->attr_name, namesp->attr_namelen);
679 offset += namesp->attr_namelen;
680 strncpy(offset, name, namelen); /* real name */
683 context->count += namesp->attr_namelen + namelen + 1;
689 xfs_attr_kern_list_sizes(xfs_attr_list_context_t *context, attrnames_t *namesp,
690 char *name, int namelen,
691 int valuelen, char *value)
693 context->count += namesp->attr_namelen + namelen + 1;
698 * Generate a list of extended attribute names and optionally
699 * also value lengths. Positive return value follows the XFS
700 * convention of being an error, zero or negative return code
701 * is the length of the buffer returned (negated), indicating
705 xfs_attr_list(bhv_desc_t *bdp, char *buffer, int bufsize, int flags,
706 attrlist_cursor_kern_t *cursor, struct cred *cred)
708 xfs_attr_list_context_t context;
712 XFS_STATS_INC(xs_attr_list);
715 * Validate the cursor.
717 if (cursor->pad1 || cursor->pad2)
718 return(XFS_ERROR(EINVAL));
719 if ((cursor->initted == 0) &&
720 (cursor->hashval || cursor->blkno || cursor->offset))
721 return XFS_ERROR(EINVAL);
724 * Check for a properly aligned buffer.
726 if (((long)buffer) & (sizeof(int)-1))
727 return XFS_ERROR(EFAULT);
728 if (flags & ATTR_KERNOVAL)
732 * Initialize the output buffer.
734 context.dp = dp = XFS_BHVTOI(bdp);
735 context.cursor = cursor;
739 context.flags = flags;
740 context.seen_enough = 0;
741 context.alist = (attrlist_t *)buffer;
742 context.put_value = 0;
744 if (flags & ATTR_KERNAMELS) {
745 context.bufsize = bufsize;
746 context.firstu = context.bufsize;
747 if (flags & ATTR_KERNOVAL)
748 context.put_listent = xfs_attr_kern_list_sizes;
750 context.put_listent = xfs_attr_kern_list;
752 context.bufsize = (bufsize & ~(sizeof(int)-1)); /* align */
753 context.firstu = context.bufsize;
754 context.alist->al_count = 0;
755 context.alist->al_more = 0;
756 context.alist->al_offset[0] = context.bufsize;
757 context.put_listent = xfs_attr_put_listent;
760 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
763 xfs_ilock(dp, XFS_ILOCK_SHARED);
764 xfs_attr_trace_l_c("syscall start", &context);
766 error = xfs_attr_list_int(&context);
768 xfs_iunlock(dp, XFS_ILOCK_SHARED);
769 xfs_attr_trace_l_c("syscall end", &context);
771 if (context.flags & (ATTR_KERNOVAL|ATTR_KERNAMELS)) {
772 /* must return negated buffer size or the error */
773 if (context.count < 0)
774 error = XFS_ERROR(ERANGE);
776 error = -context.count;
784 xfs_attr_inactive(xfs_inode_t *dp)
791 ASSERT(! XFS_NOT_DQATTACHED(mp, dp));
793 xfs_ilock(dp, XFS_ILOCK_SHARED);
794 if ((XFS_IFORK_Q(dp) == 0) ||
795 (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
796 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
797 dp->i_d.di_anextents == 0)) {
798 xfs_iunlock(dp, XFS_ILOCK_SHARED);
801 xfs_iunlock(dp, XFS_ILOCK_SHARED);
804 * Start our first transaction of the day.
806 * All future transactions during this code must be "chained" off
807 * this one via the trans_dup() call. All transactions will contain
808 * the inode, and the inode will always be marked with trans_ihold().
809 * Since the inode will be locked in all transactions, we must log
810 * the inode in every transaction to let it float upward through
813 trans = xfs_trans_alloc(mp, XFS_TRANS_ATTRINVAL);
814 if ((error = xfs_trans_reserve(trans, 0, XFS_ATTRINVAL_LOG_RES(mp), 0,
815 XFS_TRANS_PERM_LOG_RES,
816 XFS_ATTRINVAL_LOG_COUNT))) {
817 xfs_trans_cancel(trans, 0);
820 xfs_ilock(dp, XFS_ILOCK_EXCL);
823 * No need to make quota reservations here. We expect to release some
824 * blocks, not allocate, in the common case.
826 xfs_trans_ijoin(trans, dp, XFS_ILOCK_EXCL);
827 xfs_trans_ihold(trans, dp);
830 * Decide on what work routines to call based on the inode size.
832 if ((XFS_IFORK_Q(dp) == 0) ||
833 (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
834 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
835 dp->i_d.di_anextents == 0)) {
839 error = xfs_attr_root_inactive(&trans, dp);
843 * signal synchronous inactive transactions unless this
844 * is a synchronous mount filesystem in which case we
845 * know that we're here because we've been called out of
846 * xfs_inactive which means that the last reference is gone
847 * and the unlink transaction has already hit the disk so
848 * async inactive transactions are safe.
850 if ((error = xfs_itruncate_finish(&trans, dp, 0LL, XFS_ATTR_FORK,
851 (!(mp->m_flags & XFS_MOUNT_WSYNC)
856 * Commit the last in the sequence of transactions.
858 xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE);
859 error = xfs_trans_commit(trans, XFS_TRANS_RELEASE_LOG_RES,
861 xfs_iunlock(dp, XFS_ILOCK_EXCL);
866 xfs_trans_cancel(trans, XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
867 xfs_iunlock(dp, XFS_ILOCK_EXCL);
873 /*========================================================================
874 * External routines when attribute list is inside the inode
875 *========================================================================*/
878 * Add a name to the shortform attribute list structure
879 * This is the external routine.
882 xfs_attr_shortform_addname(xfs_da_args_t *args)
884 int newsize, forkoff, retval;
886 retval = xfs_attr_shortform_lookup(args);
887 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
889 } else if (retval == EEXIST) {
890 if (args->flags & ATTR_CREATE)
892 retval = xfs_attr_shortform_remove(args);
896 if (args->namelen >= XFS_ATTR_SF_ENTSIZE_MAX ||
897 args->valuelen >= XFS_ATTR_SF_ENTSIZE_MAX)
898 return(XFS_ERROR(ENOSPC));
900 newsize = XFS_ATTR_SF_TOTSIZE(args->dp);
901 newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen);
903 forkoff = xfs_attr_shortform_bytesfit(args->dp, newsize);
905 return(XFS_ERROR(ENOSPC));
907 xfs_attr_shortform_add(args, forkoff);
912 /*========================================================================
913 * External routines when attribute list is one block
914 *========================================================================*/
917 * Add a name to the leaf attribute list structure
919 * This leaf block cannot have a "remote" value, we only call this routine
920 * if bmap_one_block() says there is only one block (ie: no remote blks).
923 xfs_attr_leaf_addname(xfs_da_args_t *args)
927 int retval, error, committed, forkoff;
930 * Read the (only) block in the attribute list in.
934 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
941 * Look up the given attribute in the leaf block. Figure out if
942 * the given flags produce an error or call for an atomic rename.
944 retval = xfs_attr_leaf_lookup_int(bp, args);
945 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
946 xfs_da_brelse(args->trans, bp);
948 } else if (retval == EEXIST) {
949 if (args->flags & ATTR_CREATE) { /* pure create op */
950 xfs_da_brelse(args->trans, bp);
953 args->rename = 1; /* an atomic rename */
954 args->blkno2 = args->blkno; /* set 2nd entry info*/
955 args->index2 = args->index;
956 args->rmtblkno2 = args->rmtblkno;
957 args->rmtblkcnt2 = args->rmtblkcnt;
961 * Add the attribute to the leaf block, transitioning to a Btree
964 retval = xfs_attr_leaf_add(bp, args);
966 if (retval == ENOSPC) {
968 * Promote the attribute list to the Btree format, then
969 * Commit that transaction so that the node_addname() call
970 * can manage its own transactions.
972 XFS_BMAP_INIT(args->flist, args->firstblock);
973 error = xfs_attr_leaf_to_node(args);
975 error = xfs_bmap_finish(&args->trans, args->flist,
976 *args->firstblock, &committed);
981 xfs_bmap_cancel(args->flist);
986 * bmap_finish() may have committed the last trans and started
987 * a new one. We need the inode to be in all transactions.
990 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
991 xfs_trans_ihold(args->trans, dp);
995 * Commit the current trans (including the inode) and start
998 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1002 * Fob the whole rest of the problem off on the Btree code.
1004 error = xfs_attr_node_addname(args);
1009 * Commit the transaction that added the attr name so that
1010 * later routines can manage their own transactions.
1012 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1016 * If there was an out-of-line value, allocate the blocks we
1017 * identified for its storage and copy the value. This is done
1018 * after we create the attribute so that we don't overflow the
1019 * maximum size of a transaction and/or hit a deadlock.
1021 if (args->rmtblkno > 0) {
1022 error = xfs_attr_rmtval_set(args);
1028 * If this is an atomic rename operation, we must "flip" the
1029 * incomplete flags on the "new" and "old" attribute/value pairs
1030 * so that one disappears and one appears atomically. Then we
1031 * must remove the "old" attribute/value pair.
1035 * In a separate transaction, set the incomplete flag on the
1036 * "old" attr and clear the incomplete flag on the "new" attr.
1038 error = xfs_attr_leaf_flipflags(args);
1043 * Dismantle the "old" attribute/value pair by removing
1044 * a "remote" value (if it exists).
1046 args->index = args->index2;
1047 args->blkno = args->blkno2;
1048 args->rmtblkno = args->rmtblkno2;
1049 args->rmtblkcnt = args->rmtblkcnt2;
1050 if (args->rmtblkno) {
1051 error = xfs_attr_rmtval_remove(args);
1057 * Read in the block containing the "old" attr, then
1058 * remove the "old" attr from that block (neat, huh!)
1060 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1,
1061 &bp, XFS_ATTR_FORK);
1065 (void)xfs_attr_leaf_remove(bp, args);
1068 * If the result is small enough, shrink it all into the inode.
1070 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1071 XFS_BMAP_INIT(args->flist, args->firstblock);
1072 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1073 /* bp is gone due to xfs_da_shrink_inode */
1075 error = xfs_bmap_finish(&args->trans,
1083 xfs_bmap_cancel(args->flist);
1088 * bmap_finish() may have committed the last trans
1089 * and started a new one. We need the inode to be
1090 * in all transactions.
1093 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1094 xfs_trans_ihold(args->trans, dp);
1097 xfs_da_buf_done(bp);
1100 * Commit the remove and start the next trans in series.
1102 error = xfs_attr_rolltrans(&args->trans, dp);
1104 } else if (args->rmtblkno > 0) {
1106 * Added a "remote" value, just clear the incomplete flag.
1108 error = xfs_attr_leaf_clearflag(args);
1114 * Remove a name from the leaf attribute list structure
1116 * This leaf block cannot have a "remote" value, we only call this routine
1117 * if bmap_one_block() says there is only one block (ie: no remote blks).
1120 xfs_attr_leaf_removename(xfs_da_args_t *args)
1124 int error, committed, forkoff;
1127 * Remove the attribute.
1131 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1138 error = xfs_attr_leaf_lookup_int(bp, args);
1139 if (error == ENOATTR) {
1140 xfs_da_brelse(args->trans, bp);
1144 (void)xfs_attr_leaf_remove(bp, args);
1147 * If the result is small enough, shrink it all into the inode.
1149 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1150 XFS_BMAP_INIT(args->flist, args->firstblock);
1151 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1152 /* bp is gone due to xfs_da_shrink_inode */
1154 error = xfs_bmap_finish(&args->trans, args->flist,
1155 *args->firstblock, &committed);
1160 xfs_bmap_cancel(args->flist);
1165 * bmap_finish() may have committed the last trans and started
1166 * a new one. We need the inode to be in all transactions.
1169 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1170 xfs_trans_ihold(args->trans, dp);
1173 xfs_da_buf_done(bp);
1178 * Look up a name in a leaf attribute list structure.
1180 * This leaf block cannot have a "remote" value, we only call this routine
1181 * if bmap_one_block() says there is only one block (ie: no remote blks).
1184 xfs_attr_leaf_get(xfs_da_args_t *args)
1190 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1196 error = xfs_attr_leaf_lookup_int(bp, args);
1197 if (error != EEXIST) {
1198 xfs_da_brelse(args->trans, bp);
1201 error = xfs_attr_leaf_getvalue(bp, args);
1202 xfs_da_brelse(args->trans, bp);
1203 if (!error && (args->rmtblkno > 0) && !(args->flags & ATTR_KERNOVAL)) {
1204 error = xfs_attr_rmtval_get(args);
1210 * Copy out attribute entries for attr_list(), for leaf attribute lists.
1213 xfs_attr_leaf_list(xfs_attr_list_context_t *context)
1215 xfs_attr_leafblock_t *leaf;
1219 context->cursor->blkno = 0;
1220 error = xfs_da_read_buf(NULL, context->dp, 0, -1, &bp, XFS_ATTR_FORK);
1222 return XFS_ERROR(error);
1225 if (unlikely(be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR_LEAF_MAGIC)) {
1226 XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW,
1227 context->dp->i_mount, leaf);
1228 xfs_da_brelse(NULL, bp);
1229 return XFS_ERROR(EFSCORRUPTED);
1232 error = xfs_attr_leaf_list_int(bp, context);
1233 xfs_da_brelse(NULL, bp);
1234 return XFS_ERROR(error);
1238 /*========================================================================
1239 * External routines when attribute list size > XFS_LBSIZE(mp).
1240 *========================================================================*/
1243 * Add a name to a Btree-format attribute list.
1245 * This will involve walking down the Btree, and may involve splitting
1246 * leaf nodes and even splitting intermediate nodes up to and including
1247 * the root node (a special case of an intermediate node).
1249 * "Remote" attribute values confuse the issue and atomic rename operations
1250 * add a whole extra layer of confusion on top of that.
1253 xfs_attr_node_addname(xfs_da_args_t *args)
1255 xfs_da_state_t *state;
1256 xfs_da_state_blk_t *blk;
1259 int committed, retval, error;
1262 * Fill in bucket of arguments/results/context to carry around.
1267 state = xfs_da_state_alloc();
1270 state->blocksize = state->mp->m_sb.sb_blocksize;
1271 state->node_ents = state->mp->m_attr_node_ents;
1274 * Search to see if name already exists, and get back a pointer
1275 * to where it should go.
1277 error = xfs_da_node_lookup_int(state, &retval);
1280 blk = &state->path.blk[ state->path.active-1 ];
1281 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1282 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
1284 } else if (retval == EEXIST) {
1285 if (args->flags & ATTR_CREATE)
1287 args->rename = 1; /* atomic rename op */
1288 args->blkno2 = args->blkno; /* set 2nd entry info*/
1289 args->index2 = args->index;
1290 args->rmtblkno2 = args->rmtblkno;
1291 args->rmtblkcnt2 = args->rmtblkcnt;
1293 args->rmtblkcnt = 0;
1296 retval = xfs_attr_leaf_add(blk->bp, state->args);
1297 if (retval == ENOSPC) {
1298 if (state->path.active == 1) {
1300 * Its really a single leaf node, but it had
1301 * out-of-line values so it looked like it *might*
1302 * have been a b-tree.
1304 xfs_da_state_free(state);
1305 XFS_BMAP_INIT(args->flist, args->firstblock);
1306 error = xfs_attr_leaf_to_node(args);
1308 error = xfs_bmap_finish(&args->trans,
1316 xfs_bmap_cancel(args->flist);
1321 * bmap_finish() may have committed the last trans
1322 * and started a new one. We need the inode to be
1323 * in all transactions.
1326 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1327 xfs_trans_ihold(args->trans, dp);
1331 * Commit the node conversion and start the next
1332 * trans in the chain.
1334 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1341 * Split as many Btree elements as required.
1342 * This code tracks the new and old attr's location
1343 * in the index/blkno/rmtblkno/rmtblkcnt fields and
1344 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
1346 XFS_BMAP_INIT(args->flist, args->firstblock);
1347 error = xfs_da_split(state);
1349 error = xfs_bmap_finish(&args->trans, args->flist,
1350 *args->firstblock, &committed);
1355 xfs_bmap_cancel(args->flist);
1360 * bmap_finish() may have committed the last trans and started
1361 * a new one. We need the inode to be in all transactions.
1364 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1365 xfs_trans_ihold(args->trans, dp);
1369 * Addition succeeded, update Btree hashvals.
1371 xfs_da_fixhashpath(state, &state->path);
1375 * Kill the state structure, we're done with it and need to
1376 * allow the buffers to come back later.
1378 xfs_da_state_free(state);
1382 * Commit the leaf addition or btree split and start the next
1383 * trans in the chain.
1385 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1389 * If there was an out-of-line value, allocate the blocks we
1390 * identified for its storage and copy the value. This is done
1391 * after we create the attribute so that we don't overflow the
1392 * maximum size of a transaction and/or hit a deadlock.
1394 if (args->rmtblkno > 0) {
1395 error = xfs_attr_rmtval_set(args);
1401 * If this is an atomic rename operation, we must "flip" the
1402 * incomplete flags on the "new" and "old" attribute/value pairs
1403 * so that one disappears and one appears atomically. Then we
1404 * must remove the "old" attribute/value pair.
1408 * In a separate transaction, set the incomplete flag on the
1409 * "old" attr and clear the incomplete flag on the "new" attr.
1411 error = xfs_attr_leaf_flipflags(args);
1416 * Dismantle the "old" attribute/value pair by removing
1417 * a "remote" value (if it exists).
1419 args->index = args->index2;
1420 args->blkno = args->blkno2;
1421 args->rmtblkno = args->rmtblkno2;
1422 args->rmtblkcnt = args->rmtblkcnt2;
1423 if (args->rmtblkno) {
1424 error = xfs_attr_rmtval_remove(args);
1430 * Re-find the "old" attribute entry after any split ops.
1431 * The INCOMPLETE flag means that we will find the "old"
1432 * attr, not the "new" one.
1434 args->flags |= XFS_ATTR_INCOMPLETE;
1435 state = xfs_da_state_alloc();
1438 state->blocksize = state->mp->m_sb.sb_blocksize;
1439 state->node_ents = state->mp->m_attr_node_ents;
1441 error = xfs_da_node_lookup_int(state, &retval);
1446 * Remove the name and update the hashvals in the tree.
1448 blk = &state->path.blk[ state->path.active-1 ];
1449 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1450 error = xfs_attr_leaf_remove(blk->bp, args);
1451 xfs_da_fixhashpath(state, &state->path);
1454 * Check to see if the tree needs to be collapsed.
1456 if (retval && (state->path.active > 1)) {
1457 XFS_BMAP_INIT(args->flist, args->firstblock);
1458 error = xfs_da_join(state);
1460 error = xfs_bmap_finish(&args->trans,
1468 xfs_bmap_cancel(args->flist);
1473 * bmap_finish() may have committed the last trans
1474 * and started a new one. We need the inode to be
1475 * in all transactions.
1478 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1479 xfs_trans_ihold(args->trans, dp);
1484 * Commit and start the next trans in the chain.
1486 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1489 } else if (args->rmtblkno > 0) {
1491 * Added a "remote" value, just clear the incomplete flag.
1493 error = xfs_attr_leaf_clearflag(args);
1501 xfs_da_state_free(state);
1508 * Remove a name from a B-tree attribute list.
1510 * This will involve walking down the Btree, and may involve joining
1511 * leaf nodes and even joining intermediate nodes up to and including
1512 * the root node (a special case of an intermediate node).
1515 xfs_attr_node_removename(xfs_da_args_t *args)
1517 xfs_da_state_t *state;
1518 xfs_da_state_blk_t *blk;
1521 int retval, error, committed, forkoff;
1524 * Tie a string around our finger to remind us where we are.
1527 state = xfs_da_state_alloc();
1529 state->mp = dp->i_mount;
1530 state->blocksize = state->mp->m_sb.sb_blocksize;
1531 state->node_ents = state->mp->m_attr_node_ents;
1534 * Search to see if name exists, and get back a pointer to it.
1536 error = xfs_da_node_lookup_int(state, &retval);
1537 if (error || (retval != EEXIST)) {
1544 * If there is an out-of-line value, de-allocate the blocks.
1545 * This is done before we remove the attribute so that we don't
1546 * overflow the maximum size of a transaction and/or hit a deadlock.
1548 blk = &state->path.blk[ state->path.active-1 ];
1549 ASSERT(blk->bp != NULL);
1550 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1551 if (args->rmtblkno > 0) {
1553 * Fill in disk block numbers in the state structure
1554 * so that we can get the buffers back after we commit
1555 * several transactions in the following calls.
1557 error = xfs_attr_fillstate(state);
1562 * Mark the attribute as INCOMPLETE, then bunmapi() the
1565 error = xfs_attr_leaf_setflag(args);
1568 error = xfs_attr_rmtval_remove(args);
1573 * Refill the state structure with buffers, the prior calls
1574 * released our buffers.
1576 error = xfs_attr_refillstate(state);
1582 * Remove the name and update the hashvals in the tree.
1584 blk = &state->path.blk[ state->path.active-1 ];
1585 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1586 retval = xfs_attr_leaf_remove(blk->bp, args);
1587 xfs_da_fixhashpath(state, &state->path);
1590 * Check to see if the tree needs to be collapsed.
1592 if (retval && (state->path.active > 1)) {
1593 XFS_BMAP_INIT(args->flist, args->firstblock);
1594 error = xfs_da_join(state);
1596 error = xfs_bmap_finish(&args->trans, args->flist,
1597 *args->firstblock, &committed);
1602 xfs_bmap_cancel(args->flist);
1607 * bmap_finish() may have committed the last trans and started
1608 * a new one. We need the inode to be in all transactions.
1611 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1612 xfs_trans_ihold(args->trans, dp);
1616 * Commit the Btree join operation and start a new trans.
1618 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1623 * If the result is small enough, push it all into the inode.
1625 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
1627 * Have to get rid of the copy of this dabuf in the state.
1629 ASSERT(state->path.active == 1);
1630 ASSERT(state->path.blk[0].bp);
1631 xfs_da_buf_done(state->path.blk[0].bp);
1632 state->path.blk[0].bp = NULL;
1634 error = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp,
1638 ASSERT(be16_to_cpu(((xfs_attr_leafblock_t *)
1639 bp->data)->hdr.info.magic)
1640 == XFS_ATTR_LEAF_MAGIC);
1642 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1643 XFS_BMAP_INIT(args->flist, args->firstblock);
1644 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1645 /* bp is gone due to xfs_da_shrink_inode */
1647 error = xfs_bmap_finish(&args->trans,
1655 xfs_bmap_cancel(args->flist);
1660 * bmap_finish() may have committed the last trans
1661 * and started a new one. We need the inode to be
1662 * in all transactions.
1665 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1666 xfs_trans_ihold(args->trans, dp);
1669 xfs_da_brelse(args->trans, bp);
1674 xfs_da_state_free(state);
1679 * Fill in the disk block numbers in the state structure for the buffers
1680 * that are attached to the state structure.
1681 * This is done so that we can quickly reattach ourselves to those buffers
1682 * after some set of transaction commits have released these buffers.
1685 xfs_attr_fillstate(xfs_da_state_t *state)
1687 xfs_da_state_path_t *path;
1688 xfs_da_state_blk_t *blk;
1692 * Roll down the "path" in the state structure, storing the on-disk
1693 * block number for those buffers in the "path".
1695 path = &state->path;
1696 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1697 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1699 blk->disk_blkno = xfs_da_blkno(blk->bp);
1700 xfs_da_buf_done(blk->bp);
1703 blk->disk_blkno = 0;
1708 * Roll down the "altpath" in the state structure, storing the on-disk
1709 * block number for those buffers in the "altpath".
1711 path = &state->altpath;
1712 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1713 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1715 blk->disk_blkno = xfs_da_blkno(blk->bp);
1716 xfs_da_buf_done(blk->bp);
1719 blk->disk_blkno = 0;
1727 * Reattach the buffers to the state structure based on the disk block
1728 * numbers stored in the state structure.
1729 * This is done after some set of transaction commits have released those
1730 * buffers from our grip.
1733 xfs_attr_refillstate(xfs_da_state_t *state)
1735 xfs_da_state_path_t *path;
1736 xfs_da_state_blk_t *blk;
1740 * Roll down the "path" in the state structure, storing the on-disk
1741 * block number for those buffers in the "path".
1743 path = &state->path;
1744 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1745 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1746 if (blk->disk_blkno) {
1747 error = xfs_da_read_buf(state->args->trans,
1749 blk->blkno, blk->disk_blkno,
1750 &blk->bp, XFS_ATTR_FORK);
1759 * Roll down the "altpath" in the state structure, storing the on-disk
1760 * block number for those buffers in the "altpath".
1762 path = &state->altpath;
1763 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1764 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1765 if (blk->disk_blkno) {
1766 error = xfs_da_read_buf(state->args->trans,
1768 blk->blkno, blk->disk_blkno,
1769 &blk->bp, XFS_ATTR_FORK);
1781 * Look up a filename in a node attribute list.
1783 * This routine gets called for any attribute fork that has more than one
1784 * block, ie: both true Btree attr lists and for single-leaf-blocks with
1785 * "remote" values taking up more blocks.
1788 xfs_attr_node_get(xfs_da_args_t *args)
1790 xfs_da_state_t *state;
1791 xfs_da_state_blk_t *blk;
1795 state = xfs_da_state_alloc();
1797 state->mp = args->dp->i_mount;
1798 state->blocksize = state->mp->m_sb.sb_blocksize;
1799 state->node_ents = state->mp->m_attr_node_ents;
1802 * Search to see if name exists, and get back a pointer to it.
1804 error = xfs_da_node_lookup_int(state, &retval);
1807 } else if (retval == EEXIST) {
1808 blk = &state->path.blk[ state->path.active-1 ];
1809 ASSERT(blk->bp != NULL);
1810 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1813 * Get the value, local or "remote"
1815 retval = xfs_attr_leaf_getvalue(blk->bp, args);
1816 if (!retval && (args->rmtblkno > 0)
1817 && !(args->flags & ATTR_KERNOVAL)) {
1818 retval = xfs_attr_rmtval_get(args);
1823 * If not in a transaction, we have to release all the buffers.
1825 for (i = 0; i < state->path.active; i++) {
1826 xfs_da_brelse(args->trans, state->path.blk[i].bp);
1827 state->path.blk[i].bp = NULL;
1830 xfs_da_state_free(state);
1834 STATIC int /* error */
1835 xfs_attr_node_list(xfs_attr_list_context_t *context)
1837 attrlist_cursor_kern_t *cursor;
1838 xfs_attr_leafblock_t *leaf;
1839 xfs_da_intnode_t *node;
1840 xfs_da_node_entry_t *btree;
1844 cursor = context->cursor;
1845 cursor->initted = 1;
1848 * Do all sorts of validation on the passed-in cursor structure.
1849 * If anything is amiss, ignore the cursor and look up the hashval
1850 * starting from the btree root.
1853 if (cursor->blkno > 0) {
1854 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1855 &bp, XFS_ATTR_FORK);
1856 if ((error != 0) && (error != EFSCORRUPTED))
1860 switch (be16_to_cpu(node->hdr.info.magic)) {
1861 case XFS_DA_NODE_MAGIC:
1862 xfs_attr_trace_l_cn("wrong blk", context, node);
1863 xfs_da_brelse(NULL, bp);
1866 case XFS_ATTR_LEAF_MAGIC:
1868 if (cursor->hashval > be32_to_cpu(leaf->entries[
1869 be16_to_cpu(leaf->hdr.count)-1].hashval)) {
1870 xfs_attr_trace_l_cl("wrong blk",
1872 xfs_da_brelse(NULL, bp);
1874 } else if (cursor->hashval <=
1875 be32_to_cpu(leaf->entries[0].hashval)) {
1876 xfs_attr_trace_l_cl("maybe wrong blk",
1878 xfs_da_brelse(NULL, bp);
1883 xfs_attr_trace_l_c("wrong blk - ??", context);
1884 xfs_da_brelse(NULL, bp);
1891 * We did not find what we expected given the cursor's contents,
1892 * so we start from the top and work down based on the hash value.
1893 * Note that start of node block is same as start of leaf block.
1898 error = xfs_da_read_buf(NULL, context->dp,
1899 cursor->blkno, -1, &bp,
1903 if (unlikely(bp == NULL)) {
1904 XFS_ERROR_REPORT("xfs_attr_node_list(2)",
1906 context->dp->i_mount);
1907 return(XFS_ERROR(EFSCORRUPTED));
1910 if (be16_to_cpu(node->hdr.info.magic)
1911 == XFS_ATTR_LEAF_MAGIC)
1913 if (unlikely(be16_to_cpu(node->hdr.info.magic)
1914 != XFS_DA_NODE_MAGIC)) {
1915 XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
1917 context->dp->i_mount,
1919 xfs_da_brelse(NULL, bp);
1920 return(XFS_ERROR(EFSCORRUPTED));
1922 btree = node->btree;
1923 for (i = 0; i < be16_to_cpu(node->hdr.count);
1926 <= be32_to_cpu(btree->hashval)) {
1927 cursor->blkno = be32_to_cpu(btree->before);
1928 xfs_attr_trace_l_cb("descending",
1933 if (i == be16_to_cpu(node->hdr.count)) {
1934 xfs_da_brelse(NULL, bp);
1937 xfs_da_brelse(NULL, bp);
1943 * Roll upward through the blocks, processing each leaf block in
1944 * order. As long as there is space in the result buffer, keep
1945 * adding the information.
1949 if (unlikely(be16_to_cpu(leaf->hdr.info.magic)
1950 != XFS_ATTR_LEAF_MAGIC)) {
1951 XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
1953 context->dp->i_mount, leaf);
1954 xfs_da_brelse(NULL, bp);
1955 return(XFS_ERROR(EFSCORRUPTED));
1957 error = xfs_attr_leaf_list_int(bp, context);
1959 xfs_da_brelse(NULL, bp);
1962 if (context->seen_enough || leaf->hdr.info.forw == 0)
1964 cursor->blkno = be32_to_cpu(leaf->hdr.info.forw);
1965 xfs_da_brelse(NULL, bp);
1966 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1967 &bp, XFS_ATTR_FORK);
1970 if (unlikely((bp == NULL))) {
1971 XFS_ERROR_REPORT("xfs_attr_node_list(5)",
1973 context->dp->i_mount);
1974 return(XFS_ERROR(EFSCORRUPTED));
1977 xfs_da_brelse(NULL, bp);
1982 /*========================================================================
1983 * External routines for manipulating out-of-line attribute values.
1984 *========================================================================*/
1987 * Read the value associated with an attribute from the out-of-line buffer
1988 * that we stored it in.
1991 xfs_attr_rmtval_get(xfs_da_args_t *args)
1993 xfs_bmbt_irec_t map[ATTR_RMTVALUE_MAPSIZE];
1998 int nmap, error, tmp, valuelen, blkcnt, i;
2001 ASSERT(!(args->flags & ATTR_KERNOVAL));
2003 mp = args->dp->i_mount;
2005 valuelen = args->valuelen;
2006 lblkno = args->rmtblkno;
2007 while (valuelen > 0) {
2008 nmap = ATTR_RMTVALUE_MAPSIZE;
2009 error = xfs_bmapi(args->trans, args->dp, (xfs_fileoff_t)lblkno,
2011 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2012 NULL, 0, map, &nmap, NULL, NULL);
2017 for (i = 0; (i < nmap) && (valuelen > 0); i++) {
2018 ASSERT((map[i].br_startblock != DELAYSTARTBLOCK) &&
2019 (map[i].br_startblock != HOLESTARTBLOCK));
2020 dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
2021 blkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
2022 error = xfs_read_buf(mp, mp->m_ddev_targp, dblkno,
2023 blkcnt, XFS_BUF_LOCK, &bp);
2027 tmp = (valuelen < XFS_BUF_SIZE(bp))
2028 ? valuelen : XFS_BUF_SIZE(bp);
2029 xfs_biomove(bp, 0, tmp, dst, XFS_B_READ);
2034 lblkno += map[i].br_blockcount;
2037 ASSERT(valuelen == 0);
2042 * Write the value associated with an attribute into the out-of-line buffer
2043 * that we have defined for it.
2046 xfs_attr_rmtval_set(xfs_da_args_t *args)
2049 xfs_fileoff_t lfileoff;
2051 xfs_bmbt_irec_t map;
2056 int blkcnt, valuelen, nmap, error, tmp, committed;
2063 * Find a "hole" in the attribute address space large enough for
2064 * us to drop the new attribute's value into.
2066 blkcnt = XFS_B_TO_FSB(mp, args->valuelen);
2068 error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff,
2073 args->rmtblkno = lblkno = (xfs_dablk_t)lfileoff;
2074 args->rmtblkcnt = blkcnt;
2077 * Roll through the "value", allocating blocks on disk as required.
2079 while (blkcnt > 0) {
2081 * Allocate a single extent, up to the size of the value.
2083 XFS_BMAP_INIT(args->flist, args->firstblock);
2085 error = xfs_bmapi(args->trans, dp, (xfs_fileoff_t)lblkno,
2087 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA |
2089 args->firstblock, args->total, &map, &nmap,
2092 error = xfs_bmap_finish(&args->trans, args->flist,
2093 *args->firstblock, &committed);
2098 xfs_bmap_cancel(args->flist);
2103 * bmap_finish() may have committed the last trans and started
2104 * a new one. We need the inode to be in all transactions.
2107 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
2108 xfs_trans_ihold(args->trans, dp);
2112 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2113 (map.br_startblock != HOLESTARTBLOCK));
2114 lblkno += map.br_blockcount;
2115 blkcnt -= map.br_blockcount;
2118 * Start the next trans in the chain.
2120 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
2125 * Roll through the "value", copying the attribute value to the
2126 * already-allocated blocks. Blocks are written synchronously
2127 * so that we can know they are all on disk before we turn off
2128 * the INCOMPLETE flag.
2130 lblkno = args->rmtblkno;
2131 valuelen = args->valuelen;
2132 while (valuelen > 0) {
2134 * Try to remember where we decided to put the value.
2136 XFS_BMAP_INIT(args->flist, args->firstblock);
2138 error = xfs_bmapi(NULL, dp, (xfs_fileoff_t)lblkno,
2140 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2141 args->firstblock, 0, &map, &nmap,
2147 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2148 (map.br_startblock != HOLESTARTBLOCK));
2150 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2151 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2153 bp = xfs_buf_get_flags(mp->m_ddev_targp, dblkno,
2154 blkcnt, XFS_BUF_LOCK);
2156 ASSERT(!XFS_BUF_GETERROR(bp));
2158 tmp = (valuelen < XFS_BUF_SIZE(bp)) ? valuelen :
2160 xfs_biomove(bp, 0, tmp, src, XFS_B_WRITE);
2161 if (tmp < XFS_BUF_SIZE(bp))
2162 xfs_biozero(bp, tmp, XFS_BUF_SIZE(bp) - tmp);
2163 if ((error = xfs_bwrite(mp, bp))) {/* GROT: NOTE: synchronous write */
2169 lblkno += map.br_blockcount;
2171 ASSERT(valuelen == 0);
2176 * Remove the value associated with an attribute by deleting the
2177 * out-of-line buffer that it is stored on.
2180 xfs_attr_rmtval_remove(xfs_da_args_t *args)
2183 xfs_bmbt_irec_t map;
2187 int valuelen, blkcnt, nmap, error, done, committed;
2189 mp = args->dp->i_mount;
2192 * Roll through the "value", invalidating the attribute value's
2195 lblkno = args->rmtblkno;
2196 valuelen = args->rmtblkcnt;
2197 while (valuelen > 0) {
2199 * Try to remember where we decided to put the value.
2201 XFS_BMAP_INIT(args->flist, args->firstblock);
2203 error = xfs_bmapi(NULL, args->dp, (xfs_fileoff_t)lblkno,
2205 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2206 args->firstblock, 0, &map, &nmap,
2212 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2213 (map.br_startblock != HOLESTARTBLOCK));
2215 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2216 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2219 * If the "remote" value is in the cache, remove it.
2221 bp = xfs_incore(mp->m_ddev_targp, dblkno, blkcnt,
2222 XFS_INCORE_TRYLOCK);
2225 XFS_BUF_UNDELAYWRITE(bp);
2230 valuelen -= map.br_blockcount;
2232 lblkno += map.br_blockcount;
2236 * Keep de-allocating extents until the remote-value region is gone.
2238 lblkno = args->rmtblkno;
2239 blkcnt = args->rmtblkcnt;
2242 XFS_BMAP_INIT(args->flist, args->firstblock);
2243 error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
2244 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2245 1, args->firstblock, args->flist,
2248 error = xfs_bmap_finish(&args->trans, args->flist,
2249 *args->firstblock, &committed);
2254 xfs_bmap_cancel(args->flist);
2259 * bmap_finish() may have committed the last trans and started
2260 * a new one. We need the inode to be in all transactions.
2263 xfs_trans_ijoin(args->trans, args->dp, XFS_ILOCK_EXCL);
2264 xfs_trans_ihold(args->trans, args->dp);
2268 * Close out trans and start the next one in the chain.
2270 if ((error = xfs_attr_rolltrans(&args->trans, args->dp)))
2276 #if defined(XFS_ATTR_TRACE)
2278 * Add a trace buffer entry for an attr_list context structure.
2281 xfs_attr_trace_l_c(char *where, struct xfs_attr_list_context *context)
2283 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_C, where,
2284 (__psunsigned_t)context->dp,
2285 (__psunsigned_t)context->cursor->hashval,
2286 (__psunsigned_t)context->cursor->blkno,
2287 (__psunsigned_t)context->cursor->offset,
2288 (__psunsigned_t)context->alist,
2289 (__psunsigned_t)context->bufsize,
2290 (__psunsigned_t)context->count,
2291 (__psunsigned_t)context->firstu,
2293 ((context->count > 0) &&
2294 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2295 ? (ATTR_ENTRY(context->alist,
2296 context->count-1)->a_valuelen)
2298 (__psunsigned_t)context->dupcnt,
2299 (__psunsigned_t)context->flags,
2300 (__psunsigned_t)NULL,
2301 (__psunsigned_t)NULL,
2302 (__psunsigned_t)NULL);
2306 * Add a trace buffer entry for a context structure and a Btree node.
2309 xfs_attr_trace_l_cn(char *where, struct xfs_attr_list_context *context,
2310 struct xfs_da_intnode *node)
2312 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CN, where,
2313 (__psunsigned_t)context->dp,
2314 (__psunsigned_t)context->cursor->hashval,
2315 (__psunsigned_t)context->cursor->blkno,
2316 (__psunsigned_t)context->cursor->offset,
2317 (__psunsigned_t)context->alist,
2318 (__psunsigned_t)context->bufsize,
2319 (__psunsigned_t)context->count,
2320 (__psunsigned_t)context->firstu,
2322 ((context->count > 0) &&
2323 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2324 ? (ATTR_ENTRY(context->alist,
2325 context->count-1)->a_valuelen)
2327 (__psunsigned_t)context->dupcnt,
2328 (__psunsigned_t)context->flags,
2329 (__psunsigned_t)be16_to_cpu(node->hdr.count),
2330 (__psunsigned_t)be32_to_cpu(node->btree[0].hashval),
2331 (__psunsigned_t)be32_to_cpu(node->btree[
2332 be16_to_cpu(node->hdr.count)-1].hashval));
2336 * Add a trace buffer entry for a context structure and a Btree element.
2339 xfs_attr_trace_l_cb(char *where, struct xfs_attr_list_context *context,
2340 struct xfs_da_node_entry *btree)
2342 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CB, where,
2343 (__psunsigned_t)context->dp,
2344 (__psunsigned_t)context->cursor->hashval,
2345 (__psunsigned_t)context->cursor->blkno,
2346 (__psunsigned_t)context->cursor->offset,
2347 (__psunsigned_t)context->alist,
2348 (__psunsigned_t)context->bufsize,
2349 (__psunsigned_t)context->count,
2350 (__psunsigned_t)context->firstu,
2352 ((context->count > 0) &&
2353 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2354 ? (ATTR_ENTRY(context->alist,
2355 context->count-1)->a_valuelen)
2357 (__psunsigned_t)context->dupcnt,
2358 (__psunsigned_t)context->flags,
2359 (__psunsigned_t)be32_to_cpu(btree->hashval),
2360 (__psunsigned_t)be32_to_cpu(btree->before),
2361 (__psunsigned_t)NULL);
2365 * Add a trace buffer entry for a context structure and a leaf block.
2368 xfs_attr_trace_l_cl(char *where, struct xfs_attr_list_context *context,
2369 struct xfs_attr_leafblock *leaf)
2371 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CL, where,
2372 (__psunsigned_t)context->dp,
2373 (__psunsigned_t)context->cursor->hashval,
2374 (__psunsigned_t)context->cursor->blkno,
2375 (__psunsigned_t)context->cursor->offset,
2376 (__psunsigned_t)context->alist,
2377 (__psunsigned_t)context->bufsize,
2378 (__psunsigned_t)context->count,
2379 (__psunsigned_t)context->firstu,
2381 ((context->count > 0) &&
2382 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2383 ? (ATTR_ENTRY(context->alist,
2384 context->count-1)->a_valuelen)
2386 (__psunsigned_t)context->dupcnt,
2387 (__psunsigned_t)context->flags,
2388 (__psunsigned_t)be16_to_cpu(leaf->hdr.count),
2389 (__psunsigned_t)be32_to_cpu(leaf->entries[0].hashval),
2390 (__psunsigned_t)be32_to_cpu(leaf->entries[
2391 be16_to_cpu(leaf->hdr.count)-1].hashval));
2395 * Add a trace buffer entry for the arguments given to the routine,
2399 xfs_attr_trace_enter(int type, char *where,
2400 __psunsigned_t a2, __psunsigned_t a3,
2401 __psunsigned_t a4, __psunsigned_t a5,
2402 __psunsigned_t a6, __psunsigned_t a7,
2403 __psunsigned_t a8, __psunsigned_t a9,
2404 __psunsigned_t a10, __psunsigned_t a11,
2405 __psunsigned_t a12, __psunsigned_t a13,
2406 __psunsigned_t a14, __psunsigned_t a15)
2408 ASSERT(xfs_attr_trace_buf);
2409 ktrace_enter(xfs_attr_trace_buf, (void *)((__psunsigned_t)type),
2411 (void *)a2, (void *)a3, (void *)a4,
2412 (void *)a5, (void *)a6, (void *)a7,
2413 (void *)a8, (void *)a9, (void *)a10,
2414 (void *)a11, (void *)a12, (void *)a13,
2415 (void *)a14, (void *)a15);
2417 #endif /* XFS_ATTR_TRACE */
2420 /*========================================================================
2421 * System (pseudo) namespace attribute interface routines.
2422 *========================================================================*/
2425 posix_acl_access_set(
2426 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2428 return xfs_acl_vset(vp, data, size, _ACL_TYPE_ACCESS);
2432 posix_acl_access_remove(
2433 bhv_vnode_t *vp, char *name, int xflags)
2435 return xfs_acl_vremove(vp, _ACL_TYPE_ACCESS);
2439 posix_acl_access_get(
2440 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2442 return xfs_acl_vget(vp, data, size, _ACL_TYPE_ACCESS);
2446 posix_acl_access_exists(
2449 return xfs_acl_vhasacl_access(vp);
2453 posix_acl_default_set(
2454 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2456 return xfs_acl_vset(vp, data, size, _ACL_TYPE_DEFAULT);
2460 posix_acl_default_get(
2461 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2463 return xfs_acl_vget(vp, data, size, _ACL_TYPE_DEFAULT);
2467 posix_acl_default_remove(
2468 bhv_vnode_t *vp, char *name, int xflags)
2470 return xfs_acl_vremove(vp, _ACL_TYPE_DEFAULT);
2474 posix_acl_default_exists(
2477 return xfs_acl_vhasacl_default(vp);
2480 STATIC struct attrnames posix_acl_access = {
2481 .attr_name = "posix_acl_access",
2482 .attr_namelen = sizeof("posix_acl_access") - 1,
2483 .attr_get = posix_acl_access_get,
2484 .attr_set = posix_acl_access_set,
2485 .attr_remove = posix_acl_access_remove,
2486 .attr_exists = posix_acl_access_exists,
2489 STATIC struct attrnames posix_acl_default = {
2490 .attr_name = "posix_acl_default",
2491 .attr_namelen = sizeof("posix_acl_default") - 1,
2492 .attr_get = posix_acl_default_get,
2493 .attr_set = posix_acl_default_set,
2494 .attr_remove = posix_acl_default_remove,
2495 .attr_exists = posix_acl_default_exists,
2498 STATIC struct attrnames *attr_system_names[] =
2499 { &posix_acl_access, &posix_acl_default };
2502 /*========================================================================
2503 * Namespace-prefix-style attribute name interface routines.
2504 *========================================================================*/
2508 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2510 return -bhv_vop_attr_set(vp, name, data, size, xflags, NULL);
2515 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2517 int error, asize = size;
2519 error = bhv_vop_attr_get(vp, name, data, &asize, xflags, NULL);
2526 attr_generic_remove(
2527 bhv_vnode_t *vp, char *name, int xflags)
2529 return -bhv_vop_attr_remove(vp, name, xflags, NULL);
2533 attr_generic_listadd(
2534 attrnames_t *prefix,
2535 attrnames_t *namesp,
2540 char *p = data + *result;
2542 *result += prefix->attr_namelen;
2543 *result += namesp->attr_namelen + 1;
2548 strcpy(p, prefix->attr_name);
2549 p += prefix->attr_namelen;
2550 strcpy(p, namesp->attr_name);
2551 p += namesp->attr_namelen + 1;
2562 attrnames_t *namesp;
2565 for (i = 0; i < ATTR_SYSCOUNT; i++) {
2566 namesp = attr_system_names[i];
2567 if (!namesp->attr_exists || !namesp->attr_exists(vp))
2569 error = attr_generic_listadd(&attr_system, namesp,
2570 data, size, result);
2579 bhv_vnode_t *vp, void *data, size_t size, int xflags, ssize_t *result)
2581 attrlist_cursor_kern_t cursor = { 0 };
2584 error = bhv_vop_attr_list(vp, data, size, xflags, &cursor, NULL);
2588 return attr_system_list(vp, data, size, result);
2592 attr_lookup_namespace(
2594 struct attrnames **names,
2599 for (i = 0; i < nnames; i++)
2600 if (!strncmp(name, names[i]->attr_name, names[i]->attr_namelen))
2606 * Some checks to prevent people abusing EAs to get over quota:
2607 * - Don't allow modifying user EAs on devices/symlinks;
2608 * - Don't allow modifying user EAs if sticky bit set;
2615 struct inode *inode = vn_to_inode(vp);
2617 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2619 if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode) &&
2620 !capable(CAP_SYS_ADMIN))
2622 if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) &&
2623 (current_fsuid(cred) != inode->i_uid) && !capable(CAP_FOWNER))
2629 attr_trusted_capable(
2633 struct inode *inode = vn_to_inode(vp);
2635 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2637 if (!capable(CAP_SYS_ADMIN))
2643 attr_secure_capable(
2647 return -ENOSECURITY;
2652 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2654 attrnames_t *namesp;
2657 if (xflags & ATTR_CREATE)
2660 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2663 error = namesp->attr_set(vp, name, data, size, xflags);
2665 error = vn_revalidate(vp);
2671 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2673 attrnames_t *namesp;
2675 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2678 return namesp->attr_get(vp, name, data, size, xflags);
2683 bhv_vnode_t *vp, char *name, int xflags)
2685 attrnames_t *namesp;
2687 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2690 return namesp->attr_remove(vp, name, xflags);
2693 struct attrnames attr_system = {
2694 .attr_name = "system.",
2695 .attr_namelen = sizeof("system.") - 1,
2696 .attr_flag = ATTR_SYSTEM,
2697 .attr_get = attr_system_get,
2698 .attr_set = attr_system_set,
2699 .attr_remove = attr_system_remove,
2700 .attr_capable = (attrcapable_t)fs_noerr,
2703 struct attrnames attr_trusted = {
2704 .attr_name = "trusted.",
2705 .attr_namelen = sizeof("trusted.") - 1,
2706 .attr_flag = ATTR_ROOT,
2707 .attr_get = attr_generic_get,
2708 .attr_set = attr_generic_set,
2709 .attr_remove = attr_generic_remove,
2710 .attr_capable = attr_trusted_capable,
2713 struct attrnames attr_secure = {
2714 .attr_name = "security.",
2715 .attr_namelen = sizeof("security.") - 1,
2716 .attr_flag = ATTR_SECURE,
2717 .attr_get = attr_generic_get,
2718 .attr_set = attr_generic_set,
2719 .attr_remove = attr_generic_remove,
2720 .attr_capable = attr_secure_capable,
2723 struct attrnames attr_user = {
2724 .attr_name = "user.",
2725 .attr_namelen = sizeof("user.") - 1,
2726 .attr_get = attr_generic_get,
2727 .attr_set = attr_generic_set,
2728 .attr_remove = attr_generic_remove,
2729 .attr_capable = attr_user_capable,
2732 struct attrnames *attr_namespaces[] =
2733 { &attr_system, &attr_trusted, &attr_secure, &attr_user };