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 * If the inode doesn't have an attribute fork, add one.
203 * (inode must not be locked when we call this routine)
205 if (XFS_IFORK_Q(dp) == 0) {
206 int sf_size = sizeof(xfs_attr_sf_hdr_t) +
207 XFS_ATTR_SF_ENTSIZE_BYNAME(namelen, valuelen);
209 if ((error = xfs_bmap_add_attrfork(dp, sf_size, rsvd)))
214 * Fill in the arg structure for this request.
216 memset((char *)&args, 0, sizeof(args));
218 args.namelen = namelen;
220 args.valuelen = valuelen;
222 args.hashval = xfs_da_hashname(args.name, args.namelen);
224 args.firstblock = &firstblock;
226 args.whichfork = XFS_ATTR_FORK;
231 * Determine space new attribute will use, and if it would be
232 * "local" or "remote" (note: local != inline).
234 size = xfs_attr_leaf_newentsize(namelen, valuelen,
235 mp->m_sb.sb_blocksize, &local);
237 nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK);
239 if (size > (mp->m_sb.sb_blocksize >> 1)) {
240 /* Double split possible */
244 uint dblocks = XFS_B_TO_FSB(mp, valuelen);
245 /* Out of line attribute, cannot double split, but make
246 * room for the attribute value itself.
249 nblks += XFS_NEXTENTADD_SPACE_RES(mp, dblocks, XFS_ATTR_FORK);
252 /* Size is now blocks for attribute data */
256 * Start our first transaction of the day.
258 * All future transactions during this code must be "chained" off
259 * this one via the trans_dup() call. All transactions will contain
260 * the inode, and the inode will always be marked with trans_ihold().
261 * Since the inode will be locked in all transactions, we must log
262 * the inode in every transaction to let it float upward through
265 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_SET);
268 * Root fork attributes can use reserved data blocks for this
269 * operation if necessary
273 args.trans->t_flags |= XFS_TRANS_RESERVE;
275 if ((error = xfs_trans_reserve(args.trans, (uint) nblks,
276 XFS_ATTRSET_LOG_RES(mp, nblks),
277 0, XFS_TRANS_PERM_LOG_RES,
278 XFS_ATTRSET_LOG_COUNT))) {
279 xfs_trans_cancel(args.trans, 0);
282 xfs_ilock(dp, XFS_ILOCK_EXCL);
284 error = XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, args.trans, dp, nblks, 0,
285 rsvd ? XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES :
286 XFS_QMOPT_RES_REGBLKS);
288 xfs_iunlock(dp, XFS_ILOCK_EXCL);
289 xfs_trans_cancel(args.trans, XFS_TRANS_RELEASE_LOG_RES);
293 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
294 xfs_trans_ihold(args.trans, dp);
297 * If the attribute list is non-existent or a shortform list,
298 * upgrade it to a single-leaf-block attribute list.
300 if ((dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
301 ((dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS) &&
302 (dp->i_d.di_anextents == 0))) {
305 * Build initial attribute list (if required).
307 if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
308 xfs_attr_shortform_create(&args);
311 * Try to add the attr to the attribute list in
314 error = xfs_attr_shortform_addname(&args);
315 if (error != ENOSPC) {
317 * Commit the shortform mods, and we're done.
318 * NOTE: this is also the error path (EEXIST, etc).
320 ASSERT(args.trans != NULL);
323 * If this is a synchronous mount, make sure that
324 * the transaction goes to disk before returning
327 if (mp->m_flags & XFS_MOUNT_WSYNC) {
328 xfs_trans_set_sync(args.trans);
330 err2 = xfs_trans_commit(args.trans,
331 XFS_TRANS_RELEASE_LOG_RES,
333 xfs_iunlock(dp, XFS_ILOCK_EXCL);
336 * Hit the inode change time.
338 if (!error && (flags & ATTR_KERNOTIME) == 0) {
339 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
341 return(error == 0 ? err2 : error);
345 * It won't fit in the shortform, transform to a leaf block.
346 * GROT: another possible req'mt for a double-split btree op.
348 XFS_BMAP_INIT(args.flist, args.firstblock);
349 error = xfs_attr_shortform_to_leaf(&args);
351 error = xfs_bmap_finish(&args.trans, args.flist,
352 *args.firstblock, &committed);
357 xfs_bmap_cancel(&flist);
362 * bmap_finish() may have committed the last trans and started
363 * a new one. We need the inode to be in all transactions.
366 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
367 xfs_trans_ihold(args.trans, dp);
371 * Commit the leaf transformation. We'll need another (linked)
372 * transaction to add the new attribute to the leaf.
374 if ((error = xfs_attr_rolltrans(&args.trans, dp)))
379 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
380 error = xfs_attr_leaf_addname(&args);
382 error = xfs_attr_node_addname(&args);
389 * If this is a synchronous mount, make sure that the
390 * transaction goes to disk before returning to the user.
392 if (mp->m_flags & XFS_MOUNT_WSYNC) {
393 xfs_trans_set_sync(args.trans);
397 * Commit the last in the sequence of transactions.
399 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
400 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES,
402 xfs_iunlock(dp, XFS_ILOCK_EXCL);
405 * Hit the inode change time.
407 if (!error && (flags & ATTR_KERNOTIME) == 0) {
408 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
415 xfs_trans_cancel(args.trans,
416 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
417 xfs_iunlock(dp, XFS_ILOCK_EXCL);
422 xfs_attr_set(bhv_desc_t *bdp, const char *name, char *value, int valuelen, int flags,
428 namelen = strlen(name);
429 if (namelen >= MAXNAMELEN)
430 return EFAULT; /* match IRIX behaviour */
432 XFS_STATS_INC(xs_attr_set);
434 dp = XFS_BHVTOI(bdp);
435 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
438 return xfs_attr_set_int(dp, name, namelen, value, valuelen, flags);
442 * Generic handler routine to remove a name from an attribute list.
443 * Transitions attribute list from Btree to shortform as necessary.
446 xfs_attr_remove_int(xfs_inode_t *dp, const char *name, int namelen, int flags)
449 xfs_fsblock_t firstblock;
450 xfs_bmap_free_t flist;
452 xfs_mount_t *mp = dp->i_mount;
455 * Fill in the arg structure for this request.
457 memset((char *)&args, 0, sizeof(args));
459 args.namelen = namelen;
461 args.hashval = xfs_da_hashname(args.name, args.namelen);
463 args.firstblock = &firstblock;
466 args.whichfork = XFS_ATTR_FORK;
469 * Attach the dquots to the inode.
471 if ((error = XFS_QM_DQATTACH(mp, dp, 0)))
475 * Start our first transaction of the day.
477 * All future transactions during this code must be "chained" off
478 * this one via the trans_dup() call. All transactions will contain
479 * the inode, and the inode will always be marked with trans_ihold().
480 * Since the inode will be locked in all transactions, we must log
481 * the inode in every transaction to let it float upward through
484 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_RM);
487 * Root fork attributes can use reserved data blocks for this
488 * operation if necessary
491 if (flags & ATTR_ROOT)
492 args.trans->t_flags |= XFS_TRANS_RESERVE;
494 if ((error = xfs_trans_reserve(args.trans,
495 XFS_ATTRRM_SPACE_RES(mp),
496 XFS_ATTRRM_LOG_RES(mp),
497 0, XFS_TRANS_PERM_LOG_RES,
498 XFS_ATTRRM_LOG_COUNT))) {
499 xfs_trans_cancel(args.trans, 0);
503 xfs_ilock(dp, XFS_ILOCK_EXCL);
505 * No need to make quota reservations here. We expect to release some
506 * blocks not allocate in the common case.
508 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
509 xfs_trans_ihold(args.trans, dp);
512 * Decide on what work routines to call based on the inode size.
514 if (XFS_IFORK_Q(dp) == 0 ||
515 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
516 dp->i_d.di_anextents == 0)) {
517 error = XFS_ERROR(ENOATTR);
520 if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
521 ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
522 error = xfs_attr_shortform_remove(&args);
526 } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
527 error = xfs_attr_leaf_removename(&args);
529 error = xfs_attr_node_removename(&args);
536 * If this is a synchronous mount, make sure that the
537 * transaction goes to disk before returning to the user.
539 if (mp->m_flags & XFS_MOUNT_WSYNC) {
540 xfs_trans_set_sync(args.trans);
544 * Commit the last in the sequence of transactions.
546 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
547 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES,
549 xfs_iunlock(dp, XFS_ILOCK_EXCL);
552 * Hit the inode change time.
554 if (!error && (flags & ATTR_KERNOTIME) == 0) {
555 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
562 xfs_trans_cancel(args.trans,
563 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
564 xfs_iunlock(dp, XFS_ILOCK_EXCL);
569 xfs_attr_remove(bhv_desc_t *bdp, const char *name, int flags, struct cred *cred)
574 namelen = strlen(name);
575 if (namelen >= MAXNAMELEN)
576 return EFAULT; /* match IRIX behaviour */
578 XFS_STATS_INC(xs_attr_remove);
580 dp = XFS_BHVTOI(bdp);
581 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
584 xfs_ilock(dp, XFS_ILOCK_SHARED);
585 if (XFS_IFORK_Q(dp) == 0 ||
586 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
587 dp->i_d.di_anextents == 0)) {
588 xfs_iunlock(dp, XFS_ILOCK_SHARED);
589 return(XFS_ERROR(ENOATTR));
591 xfs_iunlock(dp, XFS_ILOCK_SHARED);
593 return xfs_attr_remove_int(dp, name, namelen, flags);
597 xfs_attr_list_int(xfs_attr_list_context_t *context)
600 xfs_inode_t *dp = context->dp;
603 * Decide on what work routines to call based on the inode size.
605 if (XFS_IFORK_Q(dp) == 0 ||
606 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
607 dp->i_d.di_anextents == 0)) {
609 } else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
610 error = xfs_attr_shortform_list(context);
611 } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
612 error = xfs_attr_leaf_list(context);
614 error = xfs_attr_node_list(context);
619 #define ATTR_ENTBASESIZE /* minimum bytes used by an attr */ \
620 (((struct attrlist_ent *) 0)->a_name - (char *) 0)
621 #define ATTR_ENTSIZE(namelen) /* actual bytes used by an attr */ \
622 ((ATTR_ENTBASESIZE + (namelen) + 1 + sizeof(u_int32_t)-1) \
623 & ~(sizeof(u_int32_t)-1))
626 * Format an attribute and copy it out to the user's buffer.
627 * Take care to check values and protect against them changing later,
628 * we may be reading them directly out of a user buffer.
632 xfs_attr_put_listent(xfs_attr_list_context_t *context, attrnames_t *namesp,
633 char *name, int namelen,
634 int valuelen, char *value)
639 ASSERT(!(context->flags & ATTR_KERNOVAL));
640 ASSERT(context->count >= 0);
641 ASSERT(context->count < (ATTR_MAX_VALUELEN/8));
642 ASSERT(context->firstu >= sizeof(*context->alist));
643 ASSERT(context->firstu <= context->bufsize);
645 arraytop = sizeof(*context->alist) +
646 context->count * sizeof(context->alist->al_offset[0]);
647 context->firstu -= ATTR_ENTSIZE(namelen);
648 if (context->firstu < arraytop) {
649 xfs_attr_trace_l_c("buffer full", context);
650 context->alist->al_more = 1;
651 context->seen_enough = 1;
655 aep = (attrlist_ent_t *)&(((char *)context->alist)[ context->firstu ]);
656 aep->a_valuelen = valuelen;
657 memcpy(aep->a_name, name, namelen);
658 aep->a_name[ namelen ] = 0;
659 context->alist->al_offset[ context->count++ ] = context->firstu;
660 context->alist->al_count = context->count;
661 xfs_attr_trace_l_c("add", context);
666 xfs_attr_kern_list(xfs_attr_list_context_t *context, attrnames_t *namesp,
667 char *name, int namelen,
668 int valuelen, char *value)
673 ASSERT(context->count >= 0);
675 arraytop = context->count + namesp->attr_namelen + namelen + 1;
676 if (arraytop > context->firstu) {
677 context->count = -1; /* insufficient space */
680 offset = (char *)context->alist + context->count;
681 strncpy(offset, namesp->attr_name, namesp->attr_namelen);
682 offset += namesp->attr_namelen;
683 strncpy(offset, name, namelen); /* real name */
686 context->count += namesp->attr_namelen + namelen + 1;
692 xfs_attr_kern_list_sizes(xfs_attr_list_context_t *context, attrnames_t *namesp,
693 char *name, int namelen,
694 int valuelen, char *value)
696 context->count += namesp->attr_namelen + namelen + 1;
701 * Generate a list of extended attribute names and optionally
702 * also value lengths. Positive return value follows the XFS
703 * convention of being an error, zero or negative return code
704 * is the length of the buffer returned (negated), indicating
708 xfs_attr_list(bhv_desc_t *bdp, char *buffer, int bufsize, int flags,
709 attrlist_cursor_kern_t *cursor, struct cred *cred)
711 xfs_attr_list_context_t context;
715 XFS_STATS_INC(xs_attr_list);
718 * Validate the cursor.
720 if (cursor->pad1 || cursor->pad2)
721 return(XFS_ERROR(EINVAL));
722 if ((cursor->initted == 0) &&
723 (cursor->hashval || cursor->blkno || cursor->offset))
724 return XFS_ERROR(EINVAL);
727 * Check for a properly aligned buffer.
729 if (((long)buffer) & (sizeof(int)-1))
730 return XFS_ERROR(EFAULT);
731 if (flags & ATTR_KERNOVAL)
735 * Initialize the output buffer.
737 context.dp = dp = XFS_BHVTOI(bdp);
738 context.cursor = cursor;
742 context.flags = flags;
743 context.seen_enough = 0;
744 context.alist = (attrlist_t *)buffer;
745 context.put_value = 0;
747 if (flags & ATTR_KERNAMELS) {
748 context.bufsize = bufsize;
749 context.firstu = context.bufsize;
750 if (flags & ATTR_KERNOVAL)
751 context.put_listent = xfs_attr_kern_list_sizes;
753 context.put_listent = xfs_attr_kern_list;
755 context.bufsize = (bufsize & ~(sizeof(int)-1)); /* align */
756 context.firstu = context.bufsize;
757 context.alist->al_count = 0;
758 context.alist->al_more = 0;
759 context.alist->al_offset[0] = context.bufsize;
760 context.put_listent = xfs_attr_put_listent;
763 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
766 xfs_ilock(dp, XFS_ILOCK_SHARED);
767 xfs_attr_trace_l_c("syscall start", &context);
769 error = xfs_attr_list_int(&context);
771 xfs_iunlock(dp, XFS_ILOCK_SHARED);
772 xfs_attr_trace_l_c("syscall end", &context);
774 if (context.flags & (ATTR_KERNOVAL|ATTR_KERNAMELS)) {
775 /* must return negated buffer size or the error */
776 if (context.count < 0)
777 error = XFS_ERROR(ERANGE);
779 error = -context.count;
787 xfs_attr_inactive(xfs_inode_t *dp)
794 ASSERT(! XFS_NOT_DQATTACHED(mp, dp));
796 xfs_ilock(dp, XFS_ILOCK_SHARED);
797 if ((XFS_IFORK_Q(dp) == 0) ||
798 (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
799 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
800 dp->i_d.di_anextents == 0)) {
801 xfs_iunlock(dp, XFS_ILOCK_SHARED);
804 xfs_iunlock(dp, XFS_ILOCK_SHARED);
807 * Start our first transaction of the day.
809 * All future transactions during this code must be "chained" off
810 * this one via the trans_dup() call. All transactions will contain
811 * the inode, and the inode will always be marked with trans_ihold().
812 * Since the inode will be locked in all transactions, we must log
813 * the inode in every transaction to let it float upward through
816 trans = xfs_trans_alloc(mp, XFS_TRANS_ATTRINVAL);
817 if ((error = xfs_trans_reserve(trans, 0, XFS_ATTRINVAL_LOG_RES(mp), 0,
818 XFS_TRANS_PERM_LOG_RES,
819 XFS_ATTRINVAL_LOG_COUNT))) {
820 xfs_trans_cancel(trans, 0);
823 xfs_ilock(dp, XFS_ILOCK_EXCL);
826 * No need to make quota reservations here. We expect to release some
827 * blocks, not allocate, in the common case.
829 xfs_trans_ijoin(trans, dp, XFS_ILOCK_EXCL);
830 xfs_trans_ihold(trans, dp);
833 * Decide on what work routines to call based on the inode size.
835 if ((XFS_IFORK_Q(dp) == 0) ||
836 (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
837 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
838 dp->i_d.di_anextents == 0)) {
842 error = xfs_attr_root_inactive(&trans, dp);
846 * signal synchronous inactive transactions unless this
847 * is a synchronous mount filesystem in which case we
848 * know that we're here because we've been called out of
849 * xfs_inactive which means that the last reference is gone
850 * and the unlink transaction has already hit the disk so
851 * async inactive transactions are safe.
853 if ((error = xfs_itruncate_finish(&trans, dp, 0LL, XFS_ATTR_FORK,
854 (!(mp->m_flags & XFS_MOUNT_WSYNC)
859 * Commit the last in the sequence of transactions.
861 xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE);
862 error = xfs_trans_commit(trans, XFS_TRANS_RELEASE_LOG_RES,
864 xfs_iunlock(dp, XFS_ILOCK_EXCL);
869 xfs_trans_cancel(trans, XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
870 xfs_iunlock(dp, XFS_ILOCK_EXCL);
876 /*========================================================================
877 * External routines when attribute list is inside the inode
878 *========================================================================*/
881 * Add a name to the shortform attribute list structure
882 * This is the external routine.
885 xfs_attr_shortform_addname(xfs_da_args_t *args)
887 int newsize, forkoff, retval;
889 retval = xfs_attr_shortform_lookup(args);
890 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
892 } else if (retval == EEXIST) {
893 if (args->flags & ATTR_CREATE)
895 retval = xfs_attr_shortform_remove(args);
899 if (args->namelen >= XFS_ATTR_SF_ENTSIZE_MAX ||
900 args->valuelen >= XFS_ATTR_SF_ENTSIZE_MAX)
901 return(XFS_ERROR(ENOSPC));
903 newsize = XFS_ATTR_SF_TOTSIZE(args->dp);
904 newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen);
906 forkoff = xfs_attr_shortform_bytesfit(args->dp, newsize);
908 return(XFS_ERROR(ENOSPC));
910 xfs_attr_shortform_add(args, forkoff);
915 /*========================================================================
916 * External routines when attribute list is one block
917 *========================================================================*/
920 * Add a name to the leaf attribute list structure
922 * This leaf block cannot have a "remote" value, we only call this routine
923 * if bmap_one_block() says there is only one block (ie: no remote blks).
926 xfs_attr_leaf_addname(xfs_da_args_t *args)
930 int retval, error, committed, forkoff;
933 * Read the (only) block in the attribute list in.
937 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
944 * Look up the given attribute in the leaf block. Figure out if
945 * the given flags produce an error or call for an atomic rename.
947 retval = xfs_attr_leaf_lookup_int(bp, args);
948 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
949 xfs_da_brelse(args->trans, bp);
951 } else if (retval == EEXIST) {
952 if (args->flags & ATTR_CREATE) { /* pure create op */
953 xfs_da_brelse(args->trans, bp);
956 args->rename = 1; /* an atomic rename */
957 args->blkno2 = args->blkno; /* set 2nd entry info*/
958 args->index2 = args->index;
959 args->rmtblkno2 = args->rmtblkno;
960 args->rmtblkcnt2 = args->rmtblkcnt;
964 * Add the attribute to the leaf block, transitioning to a Btree
967 retval = xfs_attr_leaf_add(bp, args);
969 if (retval == ENOSPC) {
971 * Promote the attribute list to the Btree format, then
972 * Commit that transaction so that the node_addname() call
973 * can manage its own transactions.
975 XFS_BMAP_INIT(args->flist, args->firstblock);
976 error = xfs_attr_leaf_to_node(args);
978 error = xfs_bmap_finish(&args->trans, args->flist,
979 *args->firstblock, &committed);
984 xfs_bmap_cancel(args->flist);
989 * bmap_finish() may have committed the last trans and started
990 * a new one. We need the inode to be in all transactions.
993 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
994 xfs_trans_ihold(args->trans, dp);
998 * Commit the current trans (including the inode) and start
1001 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1005 * Fob the whole rest of the problem off on the Btree code.
1007 error = xfs_attr_node_addname(args);
1012 * Commit the transaction that added the attr name so that
1013 * later routines can manage their own transactions.
1015 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1019 * If there was an out-of-line value, allocate the blocks we
1020 * identified for its storage and copy the value. This is done
1021 * after we create the attribute so that we don't overflow the
1022 * maximum size of a transaction and/or hit a deadlock.
1024 if (args->rmtblkno > 0) {
1025 error = xfs_attr_rmtval_set(args);
1031 * If this is an atomic rename operation, we must "flip" the
1032 * incomplete flags on the "new" and "old" attribute/value pairs
1033 * so that one disappears and one appears atomically. Then we
1034 * must remove the "old" attribute/value pair.
1038 * In a separate transaction, set the incomplete flag on the
1039 * "old" attr and clear the incomplete flag on the "new" attr.
1041 error = xfs_attr_leaf_flipflags(args);
1046 * Dismantle the "old" attribute/value pair by removing
1047 * a "remote" value (if it exists).
1049 args->index = args->index2;
1050 args->blkno = args->blkno2;
1051 args->rmtblkno = args->rmtblkno2;
1052 args->rmtblkcnt = args->rmtblkcnt2;
1053 if (args->rmtblkno) {
1054 error = xfs_attr_rmtval_remove(args);
1060 * Read in the block containing the "old" attr, then
1061 * remove the "old" attr from that block (neat, huh!)
1063 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1,
1064 &bp, XFS_ATTR_FORK);
1068 (void)xfs_attr_leaf_remove(bp, args);
1071 * If the result is small enough, shrink it all into the inode.
1073 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1074 XFS_BMAP_INIT(args->flist, args->firstblock);
1075 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1076 /* bp is gone due to xfs_da_shrink_inode */
1078 error = xfs_bmap_finish(&args->trans,
1086 xfs_bmap_cancel(args->flist);
1091 * bmap_finish() may have committed the last trans
1092 * and started a new one. We need the inode to be
1093 * in all transactions.
1096 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1097 xfs_trans_ihold(args->trans, dp);
1100 xfs_da_buf_done(bp);
1103 * Commit the remove and start the next trans in series.
1105 error = xfs_attr_rolltrans(&args->trans, dp);
1107 } else if (args->rmtblkno > 0) {
1109 * Added a "remote" value, just clear the incomplete flag.
1111 error = xfs_attr_leaf_clearflag(args);
1117 * Remove a name from the leaf attribute list structure
1119 * This leaf block cannot have a "remote" value, we only call this routine
1120 * if bmap_one_block() says there is only one block (ie: no remote blks).
1123 xfs_attr_leaf_removename(xfs_da_args_t *args)
1127 int error, committed, forkoff;
1130 * Remove the attribute.
1134 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1141 error = xfs_attr_leaf_lookup_int(bp, args);
1142 if (error == ENOATTR) {
1143 xfs_da_brelse(args->trans, bp);
1147 (void)xfs_attr_leaf_remove(bp, args);
1150 * If the result is small enough, shrink it all into the inode.
1152 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1153 XFS_BMAP_INIT(args->flist, args->firstblock);
1154 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1155 /* bp is gone due to xfs_da_shrink_inode */
1157 error = xfs_bmap_finish(&args->trans, args->flist,
1158 *args->firstblock, &committed);
1163 xfs_bmap_cancel(args->flist);
1168 * bmap_finish() may have committed the last trans and started
1169 * a new one. We need the inode to be in all transactions.
1172 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1173 xfs_trans_ihold(args->trans, dp);
1176 xfs_da_buf_done(bp);
1181 * Look up a name in a leaf attribute list structure.
1183 * This leaf block cannot have a "remote" value, we only call this routine
1184 * if bmap_one_block() says there is only one block (ie: no remote blks).
1187 xfs_attr_leaf_get(xfs_da_args_t *args)
1193 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1199 error = xfs_attr_leaf_lookup_int(bp, args);
1200 if (error != EEXIST) {
1201 xfs_da_brelse(args->trans, bp);
1204 error = xfs_attr_leaf_getvalue(bp, args);
1205 xfs_da_brelse(args->trans, bp);
1206 if (!error && (args->rmtblkno > 0) && !(args->flags & ATTR_KERNOVAL)) {
1207 error = xfs_attr_rmtval_get(args);
1213 * Copy out attribute entries for attr_list(), for leaf attribute lists.
1216 xfs_attr_leaf_list(xfs_attr_list_context_t *context)
1218 xfs_attr_leafblock_t *leaf;
1222 context->cursor->blkno = 0;
1223 error = xfs_da_read_buf(NULL, context->dp, 0, -1, &bp, XFS_ATTR_FORK);
1225 return XFS_ERROR(error);
1228 if (unlikely(be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR_LEAF_MAGIC)) {
1229 XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW,
1230 context->dp->i_mount, leaf);
1231 xfs_da_brelse(NULL, bp);
1232 return XFS_ERROR(EFSCORRUPTED);
1235 error = xfs_attr_leaf_list_int(bp, context);
1236 xfs_da_brelse(NULL, bp);
1237 return XFS_ERROR(error);
1241 /*========================================================================
1242 * External routines when attribute list size > XFS_LBSIZE(mp).
1243 *========================================================================*/
1246 * Add a name to a Btree-format attribute list.
1248 * This will involve walking down the Btree, and may involve splitting
1249 * leaf nodes and even splitting intermediate nodes up to and including
1250 * the root node (a special case of an intermediate node).
1252 * "Remote" attribute values confuse the issue and atomic rename operations
1253 * add a whole extra layer of confusion on top of that.
1256 xfs_attr_node_addname(xfs_da_args_t *args)
1258 xfs_da_state_t *state;
1259 xfs_da_state_blk_t *blk;
1262 int committed, retval, error;
1265 * Fill in bucket of arguments/results/context to carry around.
1270 state = xfs_da_state_alloc();
1273 state->blocksize = state->mp->m_sb.sb_blocksize;
1274 state->node_ents = state->mp->m_attr_node_ents;
1277 * Search to see if name already exists, and get back a pointer
1278 * to where it should go.
1280 error = xfs_da_node_lookup_int(state, &retval);
1283 blk = &state->path.blk[ state->path.active-1 ];
1284 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1285 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
1287 } else if (retval == EEXIST) {
1288 if (args->flags & ATTR_CREATE)
1290 args->rename = 1; /* atomic rename op */
1291 args->blkno2 = args->blkno; /* set 2nd entry info*/
1292 args->index2 = args->index;
1293 args->rmtblkno2 = args->rmtblkno;
1294 args->rmtblkcnt2 = args->rmtblkcnt;
1296 args->rmtblkcnt = 0;
1299 retval = xfs_attr_leaf_add(blk->bp, state->args);
1300 if (retval == ENOSPC) {
1301 if (state->path.active == 1) {
1303 * Its really a single leaf node, but it had
1304 * out-of-line values so it looked like it *might*
1305 * have been a b-tree.
1307 xfs_da_state_free(state);
1308 XFS_BMAP_INIT(args->flist, args->firstblock);
1309 error = xfs_attr_leaf_to_node(args);
1311 error = xfs_bmap_finish(&args->trans,
1319 xfs_bmap_cancel(args->flist);
1324 * bmap_finish() may have committed the last trans
1325 * and started a new one. We need the inode to be
1326 * in all transactions.
1329 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1330 xfs_trans_ihold(args->trans, dp);
1334 * Commit the node conversion and start the next
1335 * trans in the chain.
1337 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1344 * Split as many Btree elements as required.
1345 * This code tracks the new and old attr's location
1346 * in the index/blkno/rmtblkno/rmtblkcnt fields and
1347 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
1349 XFS_BMAP_INIT(args->flist, args->firstblock);
1350 error = xfs_da_split(state);
1352 error = xfs_bmap_finish(&args->trans, args->flist,
1353 *args->firstblock, &committed);
1358 xfs_bmap_cancel(args->flist);
1363 * bmap_finish() may have committed the last trans and started
1364 * a new one. We need the inode to be in all transactions.
1367 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1368 xfs_trans_ihold(args->trans, dp);
1372 * Addition succeeded, update Btree hashvals.
1374 xfs_da_fixhashpath(state, &state->path);
1378 * Kill the state structure, we're done with it and need to
1379 * allow the buffers to come back later.
1381 xfs_da_state_free(state);
1385 * Commit the leaf addition or btree split and start the next
1386 * trans in the chain.
1388 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1392 * If there was an out-of-line value, allocate the blocks we
1393 * identified for its storage and copy the value. This is done
1394 * after we create the attribute so that we don't overflow the
1395 * maximum size of a transaction and/or hit a deadlock.
1397 if (args->rmtblkno > 0) {
1398 error = xfs_attr_rmtval_set(args);
1404 * If this is an atomic rename operation, we must "flip" the
1405 * incomplete flags on the "new" and "old" attribute/value pairs
1406 * so that one disappears and one appears atomically. Then we
1407 * must remove the "old" attribute/value pair.
1411 * In a separate transaction, set the incomplete flag on the
1412 * "old" attr and clear the incomplete flag on the "new" attr.
1414 error = xfs_attr_leaf_flipflags(args);
1419 * Dismantle the "old" attribute/value pair by removing
1420 * a "remote" value (if it exists).
1422 args->index = args->index2;
1423 args->blkno = args->blkno2;
1424 args->rmtblkno = args->rmtblkno2;
1425 args->rmtblkcnt = args->rmtblkcnt2;
1426 if (args->rmtblkno) {
1427 error = xfs_attr_rmtval_remove(args);
1433 * Re-find the "old" attribute entry after any split ops.
1434 * The INCOMPLETE flag means that we will find the "old"
1435 * attr, not the "new" one.
1437 args->flags |= XFS_ATTR_INCOMPLETE;
1438 state = xfs_da_state_alloc();
1441 state->blocksize = state->mp->m_sb.sb_blocksize;
1442 state->node_ents = state->mp->m_attr_node_ents;
1444 error = xfs_da_node_lookup_int(state, &retval);
1449 * Remove the name and update the hashvals in the tree.
1451 blk = &state->path.blk[ state->path.active-1 ];
1452 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1453 error = xfs_attr_leaf_remove(blk->bp, args);
1454 xfs_da_fixhashpath(state, &state->path);
1457 * Check to see if the tree needs to be collapsed.
1459 if (retval && (state->path.active > 1)) {
1460 XFS_BMAP_INIT(args->flist, args->firstblock);
1461 error = xfs_da_join(state);
1463 error = xfs_bmap_finish(&args->trans,
1471 xfs_bmap_cancel(args->flist);
1476 * bmap_finish() may have committed the last trans
1477 * and started a new one. We need the inode to be
1478 * in all transactions.
1481 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1482 xfs_trans_ihold(args->trans, dp);
1487 * Commit and start the next trans in the chain.
1489 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1492 } else if (args->rmtblkno > 0) {
1494 * Added a "remote" value, just clear the incomplete flag.
1496 error = xfs_attr_leaf_clearflag(args);
1504 xfs_da_state_free(state);
1511 * Remove a name from a B-tree attribute list.
1513 * This will involve walking down the Btree, and may involve joining
1514 * leaf nodes and even joining intermediate nodes up to and including
1515 * the root node (a special case of an intermediate node).
1518 xfs_attr_node_removename(xfs_da_args_t *args)
1520 xfs_da_state_t *state;
1521 xfs_da_state_blk_t *blk;
1524 int retval, error, committed, forkoff;
1527 * Tie a string around our finger to remind us where we are.
1530 state = xfs_da_state_alloc();
1532 state->mp = dp->i_mount;
1533 state->blocksize = state->mp->m_sb.sb_blocksize;
1534 state->node_ents = state->mp->m_attr_node_ents;
1537 * Search to see if name exists, and get back a pointer to it.
1539 error = xfs_da_node_lookup_int(state, &retval);
1540 if (error || (retval != EEXIST)) {
1547 * If there is an out-of-line value, de-allocate the blocks.
1548 * This is done before we remove the attribute so that we don't
1549 * overflow the maximum size of a transaction and/or hit a deadlock.
1551 blk = &state->path.blk[ state->path.active-1 ];
1552 ASSERT(blk->bp != NULL);
1553 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1554 if (args->rmtblkno > 0) {
1556 * Fill in disk block numbers in the state structure
1557 * so that we can get the buffers back after we commit
1558 * several transactions in the following calls.
1560 error = xfs_attr_fillstate(state);
1565 * Mark the attribute as INCOMPLETE, then bunmapi() the
1568 error = xfs_attr_leaf_setflag(args);
1571 error = xfs_attr_rmtval_remove(args);
1576 * Refill the state structure with buffers, the prior calls
1577 * released our buffers.
1579 error = xfs_attr_refillstate(state);
1585 * Remove the name and update the hashvals in the tree.
1587 blk = &state->path.blk[ state->path.active-1 ];
1588 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1589 retval = xfs_attr_leaf_remove(blk->bp, args);
1590 xfs_da_fixhashpath(state, &state->path);
1593 * Check to see if the tree needs to be collapsed.
1595 if (retval && (state->path.active > 1)) {
1596 XFS_BMAP_INIT(args->flist, args->firstblock);
1597 error = xfs_da_join(state);
1599 error = xfs_bmap_finish(&args->trans, args->flist,
1600 *args->firstblock, &committed);
1605 xfs_bmap_cancel(args->flist);
1610 * bmap_finish() may have committed the last trans and started
1611 * a new one. We need the inode to be in all transactions.
1614 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1615 xfs_trans_ihold(args->trans, dp);
1619 * Commit the Btree join operation and start a new trans.
1621 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1626 * If the result is small enough, push it all into the inode.
1628 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
1630 * Have to get rid of the copy of this dabuf in the state.
1632 ASSERT(state->path.active == 1);
1633 ASSERT(state->path.blk[0].bp);
1634 xfs_da_buf_done(state->path.blk[0].bp);
1635 state->path.blk[0].bp = NULL;
1637 error = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp,
1641 ASSERT(be16_to_cpu(((xfs_attr_leafblock_t *)
1642 bp->data)->hdr.info.magic)
1643 == XFS_ATTR_LEAF_MAGIC);
1645 if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1646 XFS_BMAP_INIT(args->flist, args->firstblock);
1647 error = xfs_attr_leaf_to_shortform(bp, args, forkoff);
1648 /* bp is gone due to xfs_da_shrink_inode */
1650 error = xfs_bmap_finish(&args->trans,
1658 xfs_bmap_cancel(args->flist);
1663 * bmap_finish() may have committed the last trans
1664 * and started a new one. We need the inode to be
1665 * in all transactions.
1668 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1669 xfs_trans_ihold(args->trans, dp);
1672 xfs_da_brelse(args->trans, bp);
1677 xfs_da_state_free(state);
1682 * Fill in the disk block numbers in the state structure for the buffers
1683 * that are attached to the state structure.
1684 * This is done so that we can quickly reattach ourselves to those buffers
1685 * after some set of transaction commits have released these buffers.
1688 xfs_attr_fillstate(xfs_da_state_t *state)
1690 xfs_da_state_path_t *path;
1691 xfs_da_state_blk_t *blk;
1695 * Roll down the "path" in the state structure, storing the on-disk
1696 * block number for those buffers in the "path".
1698 path = &state->path;
1699 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1700 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1702 blk->disk_blkno = xfs_da_blkno(blk->bp);
1703 xfs_da_buf_done(blk->bp);
1706 blk->disk_blkno = 0;
1711 * Roll down the "altpath" in the state structure, storing the on-disk
1712 * block number for those buffers in the "altpath".
1714 path = &state->altpath;
1715 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1716 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1718 blk->disk_blkno = xfs_da_blkno(blk->bp);
1719 xfs_da_buf_done(blk->bp);
1722 blk->disk_blkno = 0;
1730 * Reattach the buffers to the state structure based on the disk block
1731 * numbers stored in the state structure.
1732 * This is done after some set of transaction commits have released those
1733 * buffers from our grip.
1736 xfs_attr_refillstate(xfs_da_state_t *state)
1738 xfs_da_state_path_t *path;
1739 xfs_da_state_blk_t *blk;
1743 * Roll down the "path" in the state structure, storing the on-disk
1744 * block number for those buffers in the "path".
1746 path = &state->path;
1747 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1748 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1749 if (blk->disk_blkno) {
1750 error = xfs_da_read_buf(state->args->trans,
1752 blk->blkno, blk->disk_blkno,
1753 &blk->bp, XFS_ATTR_FORK);
1762 * Roll down the "altpath" in the state structure, storing the on-disk
1763 * block number for those buffers in the "altpath".
1765 path = &state->altpath;
1766 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1767 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1768 if (blk->disk_blkno) {
1769 error = xfs_da_read_buf(state->args->trans,
1771 blk->blkno, blk->disk_blkno,
1772 &blk->bp, XFS_ATTR_FORK);
1784 * Look up a filename in a node attribute list.
1786 * This routine gets called for any attribute fork that has more than one
1787 * block, ie: both true Btree attr lists and for single-leaf-blocks with
1788 * "remote" values taking up more blocks.
1791 xfs_attr_node_get(xfs_da_args_t *args)
1793 xfs_da_state_t *state;
1794 xfs_da_state_blk_t *blk;
1798 state = xfs_da_state_alloc();
1800 state->mp = args->dp->i_mount;
1801 state->blocksize = state->mp->m_sb.sb_blocksize;
1802 state->node_ents = state->mp->m_attr_node_ents;
1805 * Search to see if name exists, and get back a pointer to it.
1807 error = xfs_da_node_lookup_int(state, &retval);
1810 } else if (retval == EEXIST) {
1811 blk = &state->path.blk[ state->path.active-1 ];
1812 ASSERT(blk->bp != NULL);
1813 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1816 * Get the value, local or "remote"
1818 retval = xfs_attr_leaf_getvalue(blk->bp, args);
1819 if (!retval && (args->rmtblkno > 0)
1820 && !(args->flags & ATTR_KERNOVAL)) {
1821 retval = xfs_attr_rmtval_get(args);
1826 * If not in a transaction, we have to release all the buffers.
1828 for (i = 0; i < state->path.active; i++) {
1829 xfs_da_brelse(args->trans, state->path.blk[i].bp);
1830 state->path.blk[i].bp = NULL;
1833 xfs_da_state_free(state);
1837 STATIC int /* error */
1838 xfs_attr_node_list(xfs_attr_list_context_t *context)
1840 attrlist_cursor_kern_t *cursor;
1841 xfs_attr_leafblock_t *leaf;
1842 xfs_da_intnode_t *node;
1843 xfs_da_node_entry_t *btree;
1847 cursor = context->cursor;
1848 cursor->initted = 1;
1851 * Do all sorts of validation on the passed-in cursor structure.
1852 * If anything is amiss, ignore the cursor and look up the hashval
1853 * starting from the btree root.
1856 if (cursor->blkno > 0) {
1857 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1858 &bp, XFS_ATTR_FORK);
1859 if ((error != 0) && (error != EFSCORRUPTED))
1863 switch (be16_to_cpu(node->hdr.info.magic)) {
1864 case XFS_DA_NODE_MAGIC:
1865 xfs_attr_trace_l_cn("wrong blk", context, node);
1866 xfs_da_brelse(NULL, bp);
1869 case XFS_ATTR_LEAF_MAGIC:
1871 if (cursor->hashval > be32_to_cpu(leaf->entries[
1872 be16_to_cpu(leaf->hdr.count)-1].hashval)) {
1873 xfs_attr_trace_l_cl("wrong blk",
1875 xfs_da_brelse(NULL, bp);
1877 } else if (cursor->hashval <=
1878 be32_to_cpu(leaf->entries[0].hashval)) {
1879 xfs_attr_trace_l_cl("maybe wrong blk",
1881 xfs_da_brelse(NULL, bp);
1886 xfs_attr_trace_l_c("wrong blk - ??", context);
1887 xfs_da_brelse(NULL, bp);
1894 * We did not find what we expected given the cursor's contents,
1895 * so we start from the top and work down based on the hash value.
1896 * Note that start of node block is same as start of leaf block.
1901 error = xfs_da_read_buf(NULL, context->dp,
1902 cursor->blkno, -1, &bp,
1906 if (unlikely(bp == NULL)) {
1907 XFS_ERROR_REPORT("xfs_attr_node_list(2)",
1909 context->dp->i_mount);
1910 return(XFS_ERROR(EFSCORRUPTED));
1913 if (be16_to_cpu(node->hdr.info.magic)
1914 == XFS_ATTR_LEAF_MAGIC)
1916 if (unlikely(be16_to_cpu(node->hdr.info.magic)
1917 != XFS_DA_NODE_MAGIC)) {
1918 XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
1920 context->dp->i_mount,
1922 xfs_da_brelse(NULL, bp);
1923 return(XFS_ERROR(EFSCORRUPTED));
1925 btree = node->btree;
1926 for (i = 0; i < be16_to_cpu(node->hdr.count);
1929 <= be32_to_cpu(btree->hashval)) {
1930 cursor->blkno = be32_to_cpu(btree->before);
1931 xfs_attr_trace_l_cb("descending",
1936 if (i == be16_to_cpu(node->hdr.count)) {
1937 xfs_da_brelse(NULL, bp);
1940 xfs_da_brelse(NULL, bp);
1946 * Roll upward through the blocks, processing each leaf block in
1947 * order. As long as there is space in the result buffer, keep
1948 * adding the information.
1952 if (unlikely(be16_to_cpu(leaf->hdr.info.magic)
1953 != XFS_ATTR_LEAF_MAGIC)) {
1954 XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
1956 context->dp->i_mount, leaf);
1957 xfs_da_brelse(NULL, bp);
1958 return(XFS_ERROR(EFSCORRUPTED));
1960 error = xfs_attr_leaf_list_int(bp, context);
1962 xfs_da_brelse(NULL, bp);
1965 if (context->seen_enough || leaf->hdr.info.forw == 0)
1967 cursor->blkno = be32_to_cpu(leaf->hdr.info.forw);
1968 xfs_da_brelse(NULL, bp);
1969 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1970 &bp, XFS_ATTR_FORK);
1973 if (unlikely((bp == NULL))) {
1974 XFS_ERROR_REPORT("xfs_attr_node_list(5)",
1976 context->dp->i_mount);
1977 return(XFS_ERROR(EFSCORRUPTED));
1980 xfs_da_brelse(NULL, bp);
1985 /*========================================================================
1986 * External routines for manipulating out-of-line attribute values.
1987 *========================================================================*/
1990 * Read the value associated with an attribute from the out-of-line buffer
1991 * that we stored it in.
1994 xfs_attr_rmtval_get(xfs_da_args_t *args)
1996 xfs_bmbt_irec_t map[ATTR_RMTVALUE_MAPSIZE];
2001 int nmap, error, tmp, valuelen, blkcnt, i;
2004 ASSERT(!(args->flags & ATTR_KERNOVAL));
2006 mp = args->dp->i_mount;
2008 valuelen = args->valuelen;
2009 lblkno = args->rmtblkno;
2010 while (valuelen > 0) {
2011 nmap = ATTR_RMTVALUE_MAPSIZE;
2012 error = xfs_bmapi(args->trans, args->dp, (xfs_fileoff_t)lblkno,
2014 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2015 NULL, 0, map, &nmap, NULL, NULL);
2020 for (i = 0; (i < nmap) && (valuelen > 0); i++) {
2021 ASSERT((map[i].br_startblock != DELAYSTARTBLOCK) &&
2022 (map[i].br_startblock != HOLESTARTBLOCK));
2023 dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
2024 blkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
2025 error = xfs_read_buf(mp, mp->m_ddev_targp, dblkno,
2026 blkcnt, XFS_BUF_LOCK, &bp);
2030 tmp = (valuelen < XFS_BUF_SIZE(bp))
2031 ? valuelen : XFS_BUF_SIZE(bp);
2032 xfs_biomove(bp, 0, tmp, dst, XFS_B_READ);
2037 lblkno += map[i].br_blockcount;
2040 ASSERT(valuelen == 0);
2045 * Write the value associated with an attribute into the out-of-line buffer
2046 * that we have defined for it.
2049 xfs_attr_rmtval_set(xfs_da_args_t *args)
2052 xfs_fileoff_t lfileoff;
2054 xfs_bmbt_irec_t map;
2059 int blkcnt, valuelen, nmap, error, tmp, committed;
2066 * Find a "hole" in the attribute address space large enough for
2067 * us to drop the new attribute's value into.
2069 blkcnt = XFS_B_TO_FSB(mp, args->valuelen);
2071 error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff,
2076 args->rmtblkno = lblkno = (xfs_dablk_t)lfileoff;
2077 args->rmtblkcnt = blkcnt;
2080 * Roll through the "value", allocating blocks on disk as required.
2082 while (blkcnt > 0) {
2084 * Allocate a single extent, up to the size of the value.
2086 XFS_BMAP_INIT(args->flist, args->firstblock);
2088 error = xfs_bmapi(args->trans, dp, (xfs_fileoff_t)lblkno,
2090 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA |
2092 args->firstblock, args->total, &map, &nmap,
2095 error = xfs_bmap_finish(&args->trans, args->flist,
2096 *args->firstblock, &committed);
2101 xfs_bmap_cancel(args->flist);
2106 * bmap_finish() may have committed the last trans and started
2107 * a new one. We need the inode to be in all transactions.
2110 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
2111 xfs_trans_ihold(args->trans, dp);
2115 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2116 (map.br_startblock != HOLESTARTBLOCK));
2117 lblkno += map.br_blockcount;
2118 blkcnt -= map.br_blockcount;
2121 * Start the next trans in the chain.
2123 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
2128 * Roll through the "value", copying the attribute value to the
2129 * already-allocated blocks. Blocks are written synchronously
2130 * so that we can know they are all on disk before we turn off
2131 * the INCOMPLETE flag.
2133 lblkno = args->rmtblkno;
2134 valuelen = args->valuelen;
2135 while (valuelen > 0) {
2137 * Try to remember where we decided to put the value.
2139 XFS_BMAP_INIT(args->flist, args->firstblock);
2141 error = xfs_bmapi(NULL, dp, (xfs_fileoff_t)lblkno,
2143 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2144 args->firstblock, 0, &map, &nmap,
2150 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2151 (map.br_startblock != HOLESTARTBLOCK));
2153 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2154 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2156 bp = xfs_buf_get_flags(mp->m_ddev_targp, dblkno,
2157 blkcnt, XFS_BUF_LOCK);
2159 ASSERT(!XFS_BUF_GETERROR(bp));
2161 tmp = (valuelen < XFS_BUF_SIZE(bp)) ? valuelen :
2163 xfs_biomove(bp, 0, tmp, src, XFS_B_WRITE);
2164 if (tmp < XFS_BUF_SIZE(bp))
2165 xfs_biozero(bp, tmp, XFS_BUF_SIZE(bp) - tmp);
2166 if ((error = xfs_bwrite(mp, bp))) {/* GROT: NOTE: synchronous write */
2172 lblkno += map.br_blockcount;
2174 ASSERT(valuelen == 0);
2179 * Remove the value associated with an attribute by deleting the
2180 * out-of-line buffer that it is stored on.
2183 xfs_attr_rmtval_remove(xfs_da_args_t *args)
2186 xfs_bmbt_irec_t map;
2190 int valuelen, blkcnt, nmap, error, done, committed;
2192 mp = args->dp->i_mount;
2195 * Roll through the "value", invalidating the attribute value's
2198 lblkno = args->rmtblkno;
2199 valuelen = args->rmtblkcnt;
2200 while (valuelen > 0) {
2202 * Try to remember where we decided to put the value.
2204 XFS_BMAP_INIT(args->flist, args->firstblock);
2206 error = xfs_bmapi(NULL, args->dp, (xfs_fileoff_t)lblkno,
2208 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2209 args->firstblock, 0, &map, &nmap,
2215 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2216 (map.br_startblock != HOLESTARTBLOCK));
2218 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2219 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2222 * If the "remote" value is in the cache, remove it.
2224 bp = xfs_incore(mp->m_ddev_targp, dblkno, blkcnt,
2225 XFS_INCORE_TRYLOCK);
2228 XFS_BUF_UNDELAYWRITE(bp);
2233 valuelen -= map.br_blockcount;
2235 lblkno += map.br_blockcount;
2239 * Keep de-allocating extents until the remote-value region is gone.
2241 lblkno = args->rmtblkno;
2242 blkcnt = args->rmtblkcnt;
2245 XFS_BMAP_INIT(args->flist, args->firstblock);
2246 error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
2247 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2248 1, args->firstblock, args->flist,
2251 error = xfs_bmap_finish(&args->trans, args->flist,
2252 *args->firstblock, &committed);
2257 xfs_bmap_cancel(args->flist);
2262 * bmap_finish() may have committed the last trans and started
2263 * a new one. We need the inode to be in all transactions.
2266 xfs_trans_ijoin(args->trans, args->dp, XFS_ILOCK_EXCL);
2267 xfs_trans_ihold(args->trans, args->dp);
2271 * Close out trans and start the next one in the chain.
2273 if ((error = xfs_attr_rolltrans(&args->trans, args->dp)))
2279 #if defined(XFS_ATTR_TRACE)
2281 * Add a trace buffer entry for an attr_list context structure.
2284 xfs_attr_trace_l_c(char *where, struct xfs_attr_list_context *context)
2286 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_C, where,
2287 (__psunsigned_t)context->dp,
2288 (__psunsigned_t)context->cursor->hashval,
2289 (__psunsigned_t)context->cursor->blkno,
2290 (__psunsigned_t)context->cursor->offset,
2291 (__psunsigned_t)context->alist,
2292 (__psunsigned_t)context->bufsize,
2293 (__psunsigned_t)context->count,
2294 (__psunsigned_t)context->firstu,
2296 ((context->count > 0) &&
2297 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2298 ? (ATTR_ENTRY(context->alist,
2299 context->count-1)->a_valuelen)
2301 (__psunsigned_t)context->dupcnt,
2302 (__psunsigned_t)context->flags,
2303 (__psunsigned_t)NULL,
2304 (__psunsigned_t)NULL,
2305 (__psunsigned_t)NULL);
2309 * Add a trace buffer entry for a context structure and a Btree node.
2312 xfs_attr_trace_l_cn(char *where, struct xfs_attr_list_context *context,
2313 struct xfs_da_intnode *node)
2315 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CN, where,
2316 (__psunsigned_t)context->dp,
2317 (__psunsigned_t)context->cursor->hashval,
2318 (__psunsigned_t)context->cursor->blkno,
2319 (__psunsigned_t)context->cursor->offset,
2320 (__psunsigned_t)context->alist,
2321 (__psunsigned_t)context->bufsize,
2322 (__psunsigned_t)context->count,
2323 (__psunsigned_t)context->firstu,
2325 ((context->count > 0) &&
2326 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2327 ? (ATTR_ENTRY(context->alist,
2328 context->count-1)->a_valuelen)
2330 (__psunsigned_t)context->dupcnt,
2331 (__psunsigned_t)context->flags,
2332 (__psunsigned_t)be16_to_cpu(node->hdr.count),
2333 (__psunsigned_t)be32_to_cpu(node->btree[0].hashval),
2334 (__psunsigned_t)be32_to_cpu(node->btree[
2335 be16_to_cpu(node->hdr.count)-1].hashval));
2339 * Add a trace buffer entry for a context structure and a Btree element.
2342 xfs_attr_trace_l_cb(char *where, struct xfs_attr_list_context *context,
2343 struct xfs_da_node_entry *btree)
2345 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CB, where,
2346 (__psunsigned_t)context->dp,
2347 (__psunsigned_t)context->cursor->hashval,
2348 (__psunsigned_t)context->cursor->blkno,
2349 (__psunsigned_t)context->cursor->offset,
2350 (__psunsigned_t)context->alist,
2351 (__psunsigned_t)context->bufsize,
2352 (__psunsigned_t)context->count,
2353 (__psunsigned_t)context->firstu,
2355 ((context->count > 0) &&
2356 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2357 ? (ATTR_ENTRY(context->alist,
2358 context->count-1)->a_valuelen)
2360 (__psunsigned_t)context->dupcnt,
2361 (__psunsigned_t)context->flags,
2362 (__psunsigned_t)be32_to_cpu(btree->hashval),
2363 (__psunsigned_t)be32_to_cpu(btree->before),
2364 (__psunsigned_t)NULL);
2368 * Add a trace buffer entry for a context structure and a leaf block.
2371 xfs_attr_trace_l_cl(char *where, struct xfs_attr_list_context *context,
2372 struct xfs_attr_leafblock *leaf)
2374 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CL, where,
2375 (__psunsigned_t)context->dp,
2376 (__psunsigned_t)context->cursor->hashval,
2377 (__psunsigned_t)context->cursor->blkno,
2378 (__psunsigned_t)context->cursor->offset,
2379 (__psunsigned_t)context->alist,
2380 (__psunsigned_t)context->bufsize,
2381 (__psunsigned_t)context->count,
2382 (__psunsigned_t)context->firstu,
2384 ((context->count > 0) &&
2385 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2386 ? (ATTR_ENTRY(context->alist,
2387 context->count-1)->a_valuelen)
2389 (__psunsigned_t)context->dupcnt,
2390 (__psunsigned_t)context->flags,
2391 (__psunsigned_t)be16_to_cpu(leaf->hdr.count),
2392 (__psunsigned_t)be32_to_cpu(leaf->entries[0].hashval),
2393 (__psunsigned_t)be32_to_cpu(leaf->entries[
2394 be16_to_cpu(leaf->hdr.count)-1].hashval));
2398 * Add a trace buffer entry for the arguments given to the routine,
2402 xfs_attr_trace_enter(int type, char *where,
2403 __psunsigned_t a2, __psunsigned_t a3,
2404 __psunsigned_t a4, __psunsigned_t a5,
2405 __psunsigned_t a6, __psunsigned_t a7,
2406 __psunsigned_t a8, __psunsigned_t a9,
2407 __psunsigned_t a10, __psunsigned_t a11,
2408 __psunsigned_t a12, __psunsigned_t a13,
2409 __psunsigned_t a14, __psunsigned_t a15)
2411 ASSERT(xfs_attr_trace_buf);
2412 ktrace_enter(xfs_attr_trace_buf, (void *)((__psunsigned_t)type),
2414 (void *)a2, (void *)a3, (void *)a4,
2415 (void *)a5, (void *)a6, (void *)a7,
2416 (void *)a8, (void *)a9, (void *)a10,
2417 (void *)a11, (void *)a12, (void *)a13,
2418 (void *)a14, (void *)a15);
2420 #endif /* XFS_ATTR_TRACE */
2423 /*========================================================================
2424 * System (pseudo) namespace attribute interface routines.
2425 *========================================================================*/
2428 posix_acl_access_set(
2429 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2431 return xfs_acl_vset(vp, data, size, _ACL_TYPE_ACCESS);
2435 posix_acl_access_remove(
2436 bhv_vnode_t *vp, char *name, int xflags)
2438 return xfs_acl_vremove(vp, _ACL_TYPE_ACCESS);
2442 posix_acl_access_get(
2443 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2445 return xfs_acl_vget(vp, data, size, _ACL_TYPE_ACCESS);
2449 posix_acl_access_exists(
2452 return xfs_acl_vhasacl_access(vp);
2456 posix_acl_default_set(
2457 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2459 return xfs_acl_vset(vp, data, size, _ACL_TYPE_DEFAULT);
2463 posix_acl_default_get(
2464 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2466 return xfs_acl_vget(vp, data, size, _ACL_TYPE_DEFAULT);
2470 posix_acl_default_remove(
2471 bhv_vnode_t *vp, char *name, int xflags)
2473 return xfs_acl_vremove(vp, _ACL_TYPE_DEFAULT);
2477 posix_acl_default_exists(
2480 return xfs_acl_vhasacl_default(vp);
2483 static struct attrnames posix_acl_access = {
2484 .attr_name = "posix_acl_access",
2485 .attr_namelen = sizeof("posix_acl_access") - 1,
2486 .attr_get = posix_acl_access_get,
2487 .attr_set = posix_acl_access_set,
2488 .attr_remove = posix_acl_access_remove,
2489 .attr_exists = posix_acl_access_exists,
2492 static struct attrnames posix_acl_default = {
2493 .attr_name = "posix_acl_default",
2494 .attr_namelen = sizeof("posix_acl_default") - 1,
2495 .attr_get = posix_acl_default_get,
2496 .attr_set = posix_acl_default_set,
2497 .attr_remove = posix_acl_default_remove,
2498 .attr_exists = posix_acl_default_exists,
2501 static struct attrnames *attr_system_names[] =
2502 { &posix_acl_access, &posix_acl_default };
2505 /*========================================================================
2506 * Namespace-prefix-style attribute name interface routines.
2507 *========================================================================*/
2511 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2513 return -bhv_vop_attr_set(vp, name, data, size, xflags, NULL);
2518 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2520 int error, asize = size;
2522 error = bhv_vop_attr_get(vp, name, data, &asize, xflags, NULL);
2529 attr_generic_remove(
2530 bhv_vnode_t *vp, char *name, int xflags)
2532 return -bhv_vop_attr_remove(vp, name, xflags, NULL);
2536 attr_generic_listadd(
2537 attrnames_t *prefix,
2538 attrnames_t *namesp,
2543 char *p = data + *result;
2545 *result += prefix->attr_namelen;
2546 *result += namesp->attr_namelen + 1;
2551 strcpy(p, prefix->attr_name);
2552 p += prefix->attr_namelen;
2553 strcpy(p, namesp->attr_name);
2554 p += namesp->attr_namelen + 1;
2565 attrnames_t *namesp;
2568 for (i = 0; i < ATTR_SYSCOUNT; i++) {
2569 namesp = attr_system_names[i];
2570 if (!namesp->attr_exists || !namesp->attr_exists(vp))
2572 error = attr_generic_listadd(&attr_system, namesp,
2573 data, size, result);
2582 bhv_vnode_t *vp, void *data, size_t size, int xflags, ssize_t *result)
2584 attrlist_cursor_kern_t cursor = { 0 };
2587 error = bhv_vop_attr_list(vp, data, size, xflags, &cursor, NULL);
2591 return attr_system_list(vp, data, size, result);
2595 attr_lookup_namespace(
2597 struct attrnames **names,
2602 for (i = 0; i < nnames; i++)
2603 if (!strncmp(name, names[i]->attr_name, names[i]->attr_namelen))
2609 * Some checks to prevent people abusing EAs to get over quota:
2610 * - Don't allow modifying user EAs on devices/symlinks;
2611 * - Don't allow modifying user EAs if sticky bit set;
2618 struct inode *inode = vn_to_inode(vp);
2620 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2622 if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode) &&
2623 !capable(CAP_SYS_ADMIN))
2625 if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) &&
2626 (current_fsuid(cred) != inode->i_uid) && !capable(CAP_FOWNER))
2632 attr_trusted_capable(
2636 struct inode *inode = vn_to_inode(vp);
2638 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2640 if (!capable(CAP_SYS_ADMIN))
2646 attr_secure_capable(
2650 return -ENOSECURITY;
2655 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2657 attrnames_t *namesp;
2660 if (xflags & ATTR_CREATE)
2663 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2666 error = namesp->attr_set(vp, name, data, size, xflags);
2668 error = vn_revalidate(vp);
2674 bhv_vnode_t *vp, char *name, void *data, size_t size, int xflags)
2676 attrnames_t *namesp;
2678 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2681 return namesp->attr_get(vp, name, data, size, xflags);
2686 bhv_vnode_t *vp, char *name, int xflags)
2688 attrnames_t *namesp;
2690 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2693 return namesp->attr_remove(vp, name, xflags);
2696 struct attrnames attr_system = {
2697 .attr_name = "system.",
2698 .attr_namelen = sizeof("system.") - 1,
2699 .attr_flag = ATTR_SYSTEM,
2700 .attr_get = attr_system_get,
2701 .attr_set = attr_system_set,
2702 .attr_remove = attr_system_remove,
2703 .attr_capable = (attrcapable_t)fs_noerr,
2706 struct attrnames attr_trusted = {
2707 .attr_name = "trusted.",
2708 .attr_namelen = sizeof("trusted.") - 1,
2709 .attr_flag = ATTR_ROOT,
2710 .attr_get = attr_generic_get,
2711 .attr_set = attr_generic_set,
2712 .attr_remove = attr_generic_remove,
2713 .attr_capable = attr_trusted_capable,
2716 struct attrnames attr_secure = {
2717 .attr_name = "security.",
2718 .attr_namelen = sizeof("security.") - 1,
2719 .attr_flag = ATTR_SECURE,
2720 .attr_get = attr_generic_get,
2721 .attr_set = attr_generic_set,
2722 .attr_remove = attr_generic_remove,
2723 .attr_capable = attr_secure_capable,
2726 struct attrnames attr_user = {
2727 .attr_name = "user.",
2728 .attr_namelen = sizeof("user.") - 1,
2729 .attr_get = attr_generic_get,
2730 .attr_set = attr_generic_set,
2731 .attr_remove = attr_generic_remove,
2732 .attr_capable = attr_user_capable,
2735 struct attrnames *attr_namespaces[] =
2736 { &attr_system, &attr_trusted, &attr_secure, &attr_user };