2 * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
35 #include "xfs_macros.h"
36 #include "xfs_types.h"
39 #include "xfs_trans.h"
44 #include "xfs_dmapi.h"
45 #include "xfs_mount.h"
46 #include "xfs_alloc_btree.h"
47 #include "xfs_bmap_btree.h"
48 #include "xfs_ialloc_btree.h"
49 #include "xfs_alloc.h"
50 #include "xfs_btree.h"
51 #include "xfs_attr_sf.h"
52 #include "xfs_dir_sf.h"
53 #include "xfs_dir2_sf.h"
54 #include "xfs_dinode.h"
55 #include "xfs_inode_item.h"
56 #include "xfs_inode.h"
58 #include "xfs_da_btree.h"
60 #include "xfs_attr_leaf.h"
61 #include "xfs_error.h"
63 #include "xfs_quota.h"
65 #include "xfs_trans_space.h"
71 * Provide the external interfaces to manage attribute lists.
74 #define ATTR_SYSCOUNT 2
75 STATIC struct attrnames posix_acl_access;
76 STATIC struct attrnames posix_acl_default;
77 STATIC struct attrnames *attr_system_names[ATTR_SYSCOUNT];
79 /*========================================================================
80 * Function prototypes for the kernel.
81 *========================================================================*/
84 * Internal routines when attribute list fits inside the inode.
86 STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);
89 * Internal routines when attribute list is one block.
91 STATIC int xfs_attr_leaf_get(xfs_da_args_t *args);
92 STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args);
93 STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args);
94 STATIC int xfs_attr_leaf_list(xfs_attr_list_context_t *context);
97 * Internal routines when attribute list is more than one block.
99 STATIC int xfs_attr_node_get(xfs_da_args_t *args);
100 STATIC int xfs_attr_node_addname(xfs_da_args_t *args);
101 STATIC int xfs_attr_node_removename(xfs_da_args_t *args);
102 STATIC int xfs_attr_node_list(xfs_attr_list_context_t *context);
103 STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
104 STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
107 * Routines to manipulate out-of-line attribute values.
109 STATIC int xfs_attr_rmtval_get(xfs_da_args_t *args);
110 STATIC int xfs_attr_rmtval_set(xfs_da_args_t *args);
111 STATIC int xfs_attr_rmtval_remove(xfs_da_args_t *args);
113 #define ATTR_RMTVALUE_MAPSIZE 1 /* # of map entries at once */
115 #if defined(XFS_ATTR_TRACE)
116 ktrace_t *xfs_attr_trace_buf;
120 /*========================================================================
121 * Overall external interface routines.
122 *========================================================================*/
125 xfs_attr_fetch(xfs_inode_t *ip, char *name, int namelen,
126 char *value, int *valuelenp, int flags, struct cred *cred)
131 if ((XFS_IFORK_Q(ip) == 0) ||
132 (ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
133 ip->i_d.di_anextents == 0))
136 if (!(flags & (ATTR_KERNACCESS|ATTR_SECURE))) {
137 if ((error = xfs_iaccess(ip, S_IRUSR, cred)))
138 return(XFS_ERROR(error));
142 * Fill in the arg structure for this request.
144 memset((char *)&args, 0, sizeof(args));
146 args.namelen = namelen;
148 args.valuelen = *valuelenp;
150 args.hashval = xfs_da_hashname(args.name, args.namelen);
152 args.whichfork = XFS_ATTR_FORK;
155 * Decide on what work routines to call based on the inode size.
157 if (XFS_IFORK_Q(ip) == 0 ||
158 (ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
159 ip->i_d.di_anextents == 0)) {
160 error = XFS_ERROR(ENOATTR);
161 } else if (ip->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
162 error = xfs_attr_shortform_getvalue(&args);
163 } else if (xfs_bmap_one_block(ip, XFS_ATTR_FORK)) {
164 error = xfs_attr_leaf_get(&args);
166 error = xfs_attr_node_get(&args);
170 * Return the number of bytes in the value to the caller.
172 *valuelenp = args.valuelen;
180 xfs_attr_get(bhv_desc_t *bdp, char *name, char *value, int *valuelenp,
181 int flags, struct cred *cred)
183 xfs_inode_t *ip = XFS_BHVTOI(bdp);
186 XFS_STATS_INC(xs_attr_get);
190 namelen = strlen(name);
191 if (namelen >= MAXNAMELEN)
192 return(EFAULT); /* match IRIX behaviour */
194 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
197 xfs_ilock(ip, XFS_ILOCK_SHARED);
198 error = xfs_attr_fetch(ip, name, namelen, value, valuelenp, flags, cred);
199 xfs_iunlock(ip, XFS_ILOCK_SHARED);
205 xfs_attr_set(bhv_desc_t *bdp, char *name, char *value, int valuelen, int flags,
210 xfs_fsblock_t firstblock;
211 xfs_bmap_free_t flist;
212 int error, err2, committed;
216 int rsvd = (flags & ATTR_ROOT) != 0;
219 namelen = strlen(name);
220 if (namelen >= MAXNAMELEN)
221 return EFAULT; /* match IRIX behaviour */
223 XFS_STATS_INC(xs_attr_set);
225 dp = XFS_BHVTOI(bdp);
227 if (XFS_FORCED_SHUTDOWN(mp))
230 xfs_ilock(dp, XFS_ILOCK_SHARED);
231 if (!(flags & ATTR_SECURE) &&
232 (error = xfs_iaccess(dp, S_IWUSR, cred))) {
233 xfs_iunlock(dp, XFS_ILOCK_SHARED);
234 return(XFS_ERROR(error));
236 xfs_iunlock(dp, XFS_ILOCK_SHARED);
239 * Attach the dquots to the inode.
241 if ((error = XFS_QM_DQATTACH(mp, dp, 0)))
245 * If the inode doesn't have an attribute fork, add one.
246 * (inode must not be locked when we call this routine)
248 if (XFS_IFORK_Q(dp) == 0) {
249 error = xfs_bmap_add_attrfork(dp, rsvd);
255 * Fill in the arg structure for this request.
257 memset((char *)&args, 0, sizeof(args));
259 args.namelen = namelen;
261 args.valuelen = valuelen;
263 args.hashval = xfs_da_hashname(args.name, args.namelen);
265 args.firstblock = &firstblock;
267 args.whichfork = XFS_ATTR_FORK;
270 /* Determine space new attribute will use, and if it will be inline
273 size = xfs_attr_leaf_newentsize(&args, mp->m_sb.sb_blocksize, &local);
275 nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK);
277 if (size > (mp->m_sb.sb_blocksize >> 1)) {
278 /* Double split possible */
282 uint dblocks = XFS_B_TO_FSB(mp, valuelen);
283 /* Out of line attribute, cannot double split, but make
284 * room for the attribute value itself.
287 nblks += XFS_NEXTENTADD_SPACE_RES(mp, dblocks, XFS_ATTR_FORK);
290 /* Size is now blocks for attribute data */
294 * Start our first transaction of the day.
296 * All future transactions during this code must be "chained" off
297 * this one via the trans_dup() call. All transactions will contain
298 * the inode, and the inode will always be marked with trans_ihold().
299 * Since the inode will be locked in all transactions, we must log
300 * the inode in every transaction to let it float upward through
303 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_SET);
306 * Root fork attributes can use reserved data blocks for this
307 * operation if necessary
311 args.trans->t_flags |= XFS_TRANS_RESERVE;
313 if ((error = xfs_trans_reserve(args.trans, (uint) nblks,
314 XFS_ATTRSET_LOG_RES(mp, nblks),
315 0, XFS_TRANS_PERM_LOG_RES,
316 XFS_ATTRSET_LOG_COUNT))) {
317 xfs_trans_cancel(args.trans, 0);
320 xfs_ilock(dp, XFS_ILOCK_EXCL);
322 error = XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, args.trans, dp, nblks, 0,
323 rsvd ? XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_FORCE_RES :
324 XFS_QMOPT_RES_REGBLKS);
326 xfs_iunlock(dp, XFS_ILOCK_EXCL);
327 xfs_trans_cancel(args.trans, XFS_TRANS_RELEASE_LOG_RES);
331 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
332 xfs_trans_ihold(args.trans, dp);
335 * If the attribute list is non-existant or a shortform list,
336 * upgrade it to a single-leaf-block attribute list.
338 if ((dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
339 ((dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS) &&
340 (dp->i_d.di_anextents == 0))) {
343 * Build initial attribute list (if required).
345 if (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS)
346 (void)xfs_attr_shortform_create(&args);
349 * Try to add the attr to the attribute list in
352 error = xfs_attr_shortform_addname(&args);
353 if (error != ENOSPC) {
355 * Commit the shortform mods, and we're done.
356 * NOTE: this is also the error path (EEXIST, etc).
358 ASSERT(args.trans != NULL);
361 * If this is a synchronous mount, make sure that
362 * the transaction goes to disk before returning
365 if (mp->m_flags & XFS_MOUNT_WSYNC) {
366 xfs_trans_set_sync(args.trans);
368 err2 = xfs_trans_commit(args.trans,
369 XFS_TRANS_RELEASE_LOG_RES,
371 xfs_iunlock(dp, XFS_ILOCK_EXCL);
374 * Hit the inode change time.
376 if (!error && (flags & ATTR_KERNOTIME) == 0) {
377 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
379 return(error == 0 ? err2 : error);
383 * It won't fit in the shortform, transform to a leaf block.
384 * GROT: another possible req'mt for a double-split btree op.
386 XFS_BMAP_INIT(args.flist, args.firstblock);
387 error = xfs_attr_shortform_to_leaf(&args);
389 error = xfs_bmap_finish(&args.trans, args.flist,
390 *args.firstblock, &committed);
395 xfs_bmap_cancel(&flist);
400 * bmap_finish() may have committed the last trans and started
401 * a new one. We need the inode to be in all transactions.
404 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
405 xfs_trans_ihold(args.trans, dp);
409 * Commit the leaf transformation. We'll need another (linked)
410 * transaction to add the new attribute to the leaf.
412 if ((error = xfs_attr_rolltrans(&args.trans, dp)))
417 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
418 error = xfs_attr_leaf_addname(&args);
420 error = xfs_attr_node_addname(&args);
427 * If this is a synchronous mount, make sure that the
428 * transaction goes to disk before returning to the user.
430 if (mp->m_flags & XFS_MOUNT_WSYNC) {
431 xfs_trans_set_sync(args.trans);
435 * Commit the last in the sequence of transactions.
437 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
438 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES,
440 xfs_iunlock(dp, XFS_ILOCK_EXCL);
443 * Hit the inode change time.
445 if (!error && (flags & ATTR_KERNOTIME) == 0) {
446 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
453 xfs_trans_cancel(args.trans,
454 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
455 xfs_iunlock(dp, XFS_ILOCK_EXCL);
460 * Generic handler routine to remove a name from an attribute list.
461 * Transitions attribute list from Btree to shortform as necessary.
465 xfs_attr_remove(bhv_desc_t *bdp, char *name, int flags, struct cred *cred)
469 xfs_fsblock_t firstblock;
470 xfs_bmap_free_t flist;
475 ASSERT(MAXNAMELEN-1<=0xff); /* length is stored in uint8 */
476 namelen = strlen(name);
477 if (namelen>=MAXNAMELEN)
478 return EFAULT; /* match irix behaviour */
480 XFS_STATS_INC(xs_attr_remove);
482 dp = XFS_BHVTOI(bdp);
484 if (XFS_FORCED_SHUTDOWN(mp))
487 xfs_ilock(dp, XFS_ILOCK_SHARED);
488 if (!(flags & ATTR_SECURE) &&
489 (error = xfs_iaccess(dp, S_IWUSR, cred))) {
490 xfs_iunlock(dp, XFS_ILOCK_SHARED);
491 return(XFS_ERROR(error));
492 } else if (XFS_IFORK_Q(dp) == 0 ||
493 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
494 dp->i_d.di_anextents == 0)) {
495 xfs_iunlock(dp, XFS_ILOCK_SHARED);
496 return(XFS_ERROR(ENOATTR));
498 xfs_iunlock(dp, XFS_ILOCK_SHARED);
501 * Fill in the arg structure for this request.
503 memset((char *)&args, 0, sizeof(args));
505 args.namelen = namelen;
507 args.hashval = xfs_da_hashname(args.name, args.namelen);
509 args.firstblock = &firstblock;
512 args.whichfork = XFS_ATTR_FORK;
515 * Attach the dquots to the inode.
517 if ((error = XFS_QM_DQATTACH(mp, dp, 0)))
521 * Start our first transaction of the day.
523 * All future transactions during this code must be "chained" off
524 * this one via the trans_dup() call. All transactions will contain
525 * the inode, and the inode will always be marked with trans_ihold().
526 * Since the inode will be locked in all transactions, we must log
527 * the inode in every transaction to let it float upward through
530 args.trans = xfs_trans_alloc(mp, XFS_TRANS_ATTR_RM);
533 * Root fork attributes can use reserved data blocks for this
534 * operation if necessary
537 if (flags & ATTR_ROOT)
538 args.trans->t_flags |= XFS_TRANS_RESERVE;
540 if ((error = xfs_trans_reserve(args.trans,
541 XFS_ATTRRM_SPACE_RES(mp),
542 XFS_ATTRRM_LOG_RES(mp),
543 0, XFS_TRANS_PERM_LOG_RES,
544 XFS_ATTRRM_LOG_COUNT))) {
545 xfs_trans_cancel(args.trans, 0);
550 xfs_ilock(dp, XFS_ILOCK_EXCL);
552 * No need to make quota reservations here. We expect to release some
553 * blocks not allocate in the common case.
555 xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
556 xfs_trans_ihold(args.trans, dp);
559 * Decide on what work routines to call based on the inode size.
561 if (XFS_IFORK_Q(dp) == 0 ||
562 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
563 dp->i_d.di_anextents == 0)) {
564 error = XFS_ERROR(ENOATTR);
567 if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
568 ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
569 error = xfs_attr_shortform_remove(&args);
573 } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
574 error = xfs_attr_leaf_removename(&args);
576 error = xfs_attr_node_removename(&args);
583 * If this is a synchronous mount, make sure that the
584 * transaction goes to disk before returning to the user.
586 if (mp->m_flags & XFS_MOUNT_WSYNC) {
587 xfs_trans_set_sync(args.trans);
591 * Commit the last in the sequence of transactions.
593 xfs_trans_log_inode(args.trans, dp, XFS_ILOG_CORE);
594 error = xfs_trans_commit(args.trans, XFS_TRANS_RELEASE_LOG_RES,
596 xfs_iunlock(dp, XFS_ILOCK_EXCL);
599 * Hit the inode change time.
601 if (!error && (flags & ATTR_KERNOTIME) == 0) {
602 xfs_ichgtime(dp, XFS_ICHGTIME_CHG);
609 xfs_trans_cancel(args.trans,
610 XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
611 xfs_iunlock(dp, XFS_ILOCK_EXCL);
616 * Generate a list of extended attribute names and optionally
617 * also value lengths. Positive return value follows the XFS
618 * convention of being an error, zero or negative return code
619 * is the length of the buffer returned (negated), indicating
623 xfs_attr_list(bhv_desc_t *bdp, char *buffer, int bufsize, int flags,
624 attrlist_cursor_kern_t *cursor, struct cred *cred)
626 xfs_attr_list_context_t context;
630 XFS_STATS_INC(xs_attr_list);
633 * Validate the cursor.
635 if (cursor->pad1 || cursor->pad2)
636 return(XFS_ERROR(EINVAL));
637 if ((cursor->initted == 0) &&
638 (cursor->hashval || cursor->blkno || cursor->offset))
639 return(XFS_ERROR(EINVAL));
642 * Check for a properly aligned buffer.
644 if (((long)buffer) & (sizeof(int)-1))
645 return(XFS_ERROR(EFAULT));
646 if (flags & ATTR_KERNOVAL)
650 * Initialize the output buffer.
652 context.dp = dp = XFS_BHVTOI(bdp);
653 context.cursor = cursor;
657 context.flags = flags;
658 if (!(flags & ATTR_KERNAMELS)) {
659 context.bufsize = (bufsize & ~(sizeof(int)-1)); /* align */
660 context.firstu = context.bufsize;
661 context.alist = (attrlist_t *)buffer;
662 context.alist->al_count = 0;
663 context.alist->al_more = 0;
664 context.alist->al_offset[0] = context.bufsize;
667 context.bufsize = bufsize;
668 context.firstu = context.bufsize;
669 context.alist = (attrlist_t *)buffer;
672 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
675 xfs_ilock(dp, XFS_ILOCK_SHARED);
676 if (!(flags & ATTR_SECURE) &&
677 (error = xfs_iaccess(dp, S_IRUSR, cred))) {
678 xfs_iunlock(dp, XFS_ILOCK_SHARED);
679 return(XFS_ERROR(error));
683 * Decide on what work routines to call based on the inode size.
685 xfs_attr_trace_l_c("syscall start", &context);
686 if (XFS_IFORK_Q(dp) == 0 ||
687 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
688 dp->i_d.di_anextents == 0)) {
690 } else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
691 error = xfs_attr_shortform_list(&context);
692 } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
693 error = xfs_attr_leaf_list(&context);
695 error = xfs_attr_node_list(&context);
697 xfs_iunlock(dp, XFS_ILOCK_SHARED);
698 xfs_attr_trace_l_c("syscall end", &context);
700 if (!(context.flags & (ATTR_KERNOVAL|ATTR_KERNAMELS))) {
703 else { /* must return negated buffer size or the error */
704 if (context.count < 0)
705 error = XFS_ERROR(ERANGE);
707 error = -context.count;
714 xfs_attr_inactive(xfs_inode_t *dp)
721 ASSERT(! XFS_NOT_DQATTACHED(mp, dp));
723 xfs_ilock(dp, XFS_ILOCK_SHARED);
724 if ((XFS_IFORK_Q(dp) == 0) ||
725 (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
726 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
727 dp->i_d.di_anextents == 0)) {
728 xfs_iunlock(dp, XFS_ILOCK_SHARED);
731 xfs_iunlock(dp, XFS_ILOCK_SHARED);
734 * Start our first transaction of the day.
736 * All future transactions during this code must be "chained" off
737 * this one via the trans_dup() call. All transactions will contain
738 * the inode, and the inode will always be marked with trans_ihold().
739 * Since the inode will be locked in all transactions, we must log
740 * the inode in every transaction to let it float upward through
743 trans = xfs_trans_alloc(mp, XFS_TRANS_ATTRINVAL);
744 if ((error = xfs_trans_reserve(trans, 0, XFS_ATTRINVAL_LOG_RES(mp), 0,
745 XFS_TRANS_PERM_LOG_RES,
746 XFS_ATTRINVAL_LOG_COUNT))) {
747 xfs_trans_cancel(trans, 0);
750 xfs_ilock(dp, XFS_ILOCK_EXCL);
753 * No need to make quota reservations here. We expect to release some
754 * blocks, not allocate, in the common case.
756 xfs_trans_ijoin(trans, dp, XFS_ILOCK_EXCL);
757 xfs_trans_ihold(trans, dp);
760 * Decide on what work routines to call based on the inode size.
762 if ((XFS_IFORK_Q(dp) == 0) ||
763 (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) ||
764 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
765 dp->i_d.di_anextents == 0)) {
769 error = xfs_attr_root_inactive(&trans, dp);
773 * signal synchronous inactive transactions unless this
774 * is a synchronous mount filesystem in which case we
775 * know that we're here because we've been called out of
776 * xfs_inactive which means that the last reference is gone
777 * and the unlink transaction has already hit the disk so
778 * async inactive transactions are safe.
780 if ((error = xfs_itruncate_finish(&trans, dp, 0LL, XFS_ATTR_FORK,
781 (!(mp->m_flags & XFS_MOUNT_WSYNC)
786 * Commit the last in the sequence of transactions.
788 xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE);
789 error = xfs_trans_commit(trans, XFS_TRANS_RELEASE_LOG_RES,
791 xfs_iunlock(dp, XFS_ILOCK_EXCL);
796 xfs_trans_cancel(trans, XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
797 xfs_iunlock(dp, XFS_ILOCK_EXCL);
803 /*========================================================================
804 * External routines when attribute list is inside the inode
805 *========================================================================*/
808 * Add a name to the shortform attribute list structure
809 * This is the external routine.
812 xfs_attr_shortform_addname(xfs_da_args_t *args)
816 retval = xfs_attr_shortform_lookup(args);
817 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
819 } else if (retval == EEXIST) {
820 if (args->flags & ATTR_CREATE)
822 retval = xfs_attr_shortform_remove(args);
826 newsize = XFS_ATTR_SF_TOTSIZE(args->dp);
827 newsize += XFS_ATTR_SF_ENTSIZE_BYNAME(args->namelen, args->valuelen);
828 if ((newsize <= XFS_IFORK_ASIZE(args->dp)) &&
829 (args->namelen < XFS_ATTR_SF_ENTSIZE_MAX) &&
830 (args->valuelen < XFS_ATTR_SF_ENTSIZE_MAX)) {
831 retval = xfs_attr_shortform_add(args);
834 return(XFS_ERROR(ENOSPC));
840 /*========================================================================
841 * External routines when attribute list is one block
842 *========================================================================*/
845 * Add a name to the leaf attribute list structure
847 * This leaf block cannot have a "remote" value, we only call this routine
848 * if bmap_one_block() says there is only one block (ie: no remote blks).
851 xfs_attr_leaf_addname(xfs_da_args_t *args)
855 int retval, error, committed;
858 * Read the (only) block in the attribute list in.
862 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
869 * Look up the given attribute in the leaf block. Figure out if
870 * the given flags produce an error or call for an atomic rename.
872 retval = xfs_attr_leaf_lookup_int(bp, args);
873 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
874 xfs_da_brelse(args->trans, bp);
876 } else if (retval == EEXIST) {
877 if (args->flags & ATTR_CREATE) { /* pure create op */
878 xfs_da_brelse(args->trans, bp);
881 args->rename = 1; /* an atomic rename */
882 args->blkno2 = args->blkno; /* set 2nd entry info*/
883 args->index2 = args->index;
884 args->rmtblkno2 = args->rmtblkno;
885 args->rmtblkcnt2 = args->rmtblkcnt;
889 * Add the attribute to the leaf block, transitioning to a Btree
892 retval = xfs_attr_leaf_add(bp, args);
894 if (retval == ENOSPC) {
896 * Promote the attribute list to the Btree format, then
897 * Commit that transaction so that the node_addname() call
898 * can manage its own transactions.
900 XFS_BMAP_INIT(args->flist, args->firstblock);
901 error = xfs_attr_leaf_to_node(args);
903 error = xfs_bmap_finish(&args->trans, args->flist,
904 *args->firstblock, &committed);
909 xfs_bmap_cancel(args->flist);
914 * bmap_finish() may have committed the last trans and started
915 * a new one. We need the inode to be in all transactions.
918 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
919 xfs_trans_ihold(args->trans, dp);
923 * Commit the current trans (including the inode) and start
926 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
930 * Fob the whole rest of the problem off on the Btree code.
932 error = xfs_attr_node_addname(args);
937 * Commit the transaction that added the attr name so that
938 * later routines can manage their own transactions.
940 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
944 * If there was an out-of-line value, allocate the blocks we
945 * identified for its storage and copy the value. This is done
946 * after we create the attribute so that we don't overflow the
947 * maximum size of a transaction and/or hit a deadlock.
949 if (args->rmtblkno > 0) {
950 error = xfs_attr_rmtval_set(args);
956 * If this is an atomic rename operation, we must "flip" the
957 * incomplete flags on the "new" and "old" attribute/value pairs
958 * so that one disappears and one appears atomically. Then we
959 * must remove the "old" attribute/value pair.
963 * In a separate transaction, set the incomplete flag on the
964 * "old" attr and clear the incomplete flag on the "new" attr.
966 error = xfs_attr_leaf_flipflags(args);
971 * Dismantle the "old" attribute/value pair by removing
972 * a "remote" value (if it exists).
974 args->index = args->index2;
975 args->blkno = args->blkno2;
976 args->rmtblkno = args->rmtblkno2;
977 args->rmtblkcnt = args->rmtblkcnt2;
978 if (args->rmtblkno) {
979 error = xfs_attr_rmtval_remove(args);
985 * Read in the block containing the "old" attr, then
986 * remove the "old" attr from that block (neat, huh!)
988 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1,
993 (void)xfs_attr_leaf_remove(bp, args);
996 * If the result is small enough, shrink it all into the inode.
998 if (xfs_attr_shortform_allfit(bp, dp)) {
999 XFS_BMAP_INIT(args->flist, args->firstblock);
1000 error = xfs_attr_leaf_to_shortform(bp, args);
1001 /* bp is gone due to xfs_da_shrink_inode */
1003 error = xfs_bmap_finish(&args->trans,
1011 xfs_bmap_cancel(args->flist);
1016 * bmap_finish() may have committed the last trans
1017 * and started a new one. We need the inode to be
1018 * in all transactions.
1021 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1022 xfs_trans_ihold(args->trans, dp);
1025 xfs_da_buf_done(bp);
1028 * Commit the remove and start the next trans in series.
1030 error = xfs_attr_rolltrans(&args->trans, dp);
1032 } else if (args->rmtblkno > 0) {
1034 * Added a "remote" value, just clear the incomplete flag.
1036 error = xfs_attr_leaf_clearflag(args);
1042 * Remove a name from the leaf attribute list structure
1044 * This leaf block cannot have a "remote" value, we only call this routine
1045 * if bmap_one_block() says there is only one block (ie: no remote blks).
1048 xfs_attr_leaf_removename(xfs_da_args_t *args)
1056 * Remove the attribute.
1060 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1067 error = xfs_attr_leaf_lookup_int(bp, args);
1068 if (error == ENOATTR) {
1069 xfs_da_brelse(args->trans, bp);
1073 (void)xfs_attr_leaf_remove(bp, args);
1076 * If the result is small enough, shrink it all into the inode.
1078 if (xfs_attr_shortform_allfit(bp, dp)) {
1079 XFS_BMAP_INIT(args->flist, args->firstblock);
1080 error = xfs_attr_leaf_to_shortform(bp, args);
1081 /* bp is gone due to xfs_da_shrink_inode */
1083 error = xfs_bmap_finish(&args->trans, args->flist,
1084 *args->firstblock, &committed);
1089 xfs_bmap_cancel(args->flist);
1094 * bmap_finish() may have committed the last trans and started
1095 * a new one. We need the inode to be in all transactions.
1098 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1099 xfs_trans_ihold(args->trans, dp);
1102 xfs_da_buf_done(bp);
1107 * Look up a name in a leaf attribute list structure.
1109 * This leaf block cannot have a "remote" value, we only call this routine
1110 * if bmap_one_block() says there is only one block (ie: no remote blks).
1113 xfs_attr_leaf_get(xfs_da_args_t *args)
1119 error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
1125 error = xfs_attr_leaf_lookup_int(bp, args);
1126 if (error != EEXIST) {
1127 xfs_da_brelse(args->trans, bp);
1130 error = xfs_attr_leaf_getvalue(bp, args);
1131 xfs_da_brelse(args->trans, bp);
1132 if (!error && (args->rmtblkno > 0) && !(args->flags & ATTR_KERNOVAL)) {
1133 error = xfs_attr_rmtval_get(args);
1139 * Copy out attribute entries for attr_list(), for leaf attribute lists.
1142 xfs_attr_leaf_list(xfs_attr_list_context_t *context)
1144 xfs_attr_leafblock_t *leaf;
1148 context->cursor->blkno = 0;
1149 error = xfs_da_read_buf(NULL, context->dp, 0, -1, &bp, XFS_ATTR_FORK);
1154 if (unlikely(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
1155 != XFS_ATTR_LEAF_MAGIC)) {
1156 XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW,
1157 context->dp->i_mount, leaf);
1158 xfs_da_brelse(NULL, bp);
1159 return(XFS_ERROR(EFSCORRUPTED));
1162 (void)xfs_attr_leaf_list_int(bp, context);
1163 xfs_da_brelse(NULL, bp);
1168 /*========================================================================
1169 * External routines when attribute list size > XFS_LBSIZE(mp).
1170 *========================================================================*/
1173 * Add a name to a Btree-format attribute list.
1175 * This will involve walking down the Btree, and may involve splitting
1176 * leaf nodes and even splitting intermediate nodes up to and including
1177 * the root node (a special case of an intermediate node).
1179 * "Remote" attribute values confuse the issue and atomic rename operations
1180 * add a whole extra layer of confusion on top of that.
1183 xfs_attr_node_addname(xfs_da_args_t *args)
1185 xfs_da_state_t *state;
1186 xfs_da_state_blk_t *blk;
1189 int committed, retval, error;
1192 * Fill in bucket of arguments/results/context to carry around.
1197 state = xfs_da_state_alloc();
1200 state->blocksize = state->mp->m_sb.sb_blocksize;
1201 state->node_ents = state->mp->m_attr_node_ents;
1204 * Search to see if name already exists, and get back a pointer
1205 * to where it should go.
1207 error = xfs_da_node_lookup_int(state, &retval);
1210 blk = &state->path.blk[ state->path.active-1 ];
1211 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1212 if ((args->flags & ATTR_REPLACE) && (retval == ENOATTR)) {
1214 } else if (retval == EEXIST) {
1215 if (args->flags & ATTR_CREATE)
1217 args->rename = 1; /* atomic rename op */
1218 args->blkno2 = args->blkno; /* set 2nd entry info*/
1219 args->index2 = args->index;
1220 args->rmtblkno2 = args->rmtblkno;
1221 args->rmtblkcnt2 = args->rmtblkcnt;
1223 args->rmtblkcnt = 0;
1226 retval = xfs_attr_leaf_add(blk->bp, state->args);
1227 if (retval == ENOSPC) {
1228 if (state->path.active == 1) {
1230 * Its really a single leaf node, but it had
1231 * out-of-line values so it looked like it *might*
1232 * have been a b-tree.
1234 xfs_da_state_free(state);
1235 XFS_BMAP_INIT(args->flist, args->firstblock);
1236 error = xfs_attr_leaf_to_node(args);
1238 error = xfs_bmap_finish(&args->trans,
1246 xfs_bmap_cancel(args->flist);
1251 * bmap_finish() may have committed the last trans
1252 * and started a new one. We need the inode to be
1253 * in all transactions.
1256 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1257 xfs_trans_ihold(args->trans, dp);
1261 * Commit the node conversion and start the next
1262 * trans in the chain.
1264 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1271 * Split as many Btree elements as required.
1272 * This code tracks the new and old attr's location
1273 * in the index/blkno/rmtblkno/rmtblkcnt fields and
1274 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
1276 XFS_BMAP_INIT(args->flist, args->firstblock);
1277 error = xfs_da_split(state);
1279 error = xfs_bmap_finish(&args->trans, args->flist,
1280 *args->firstblock, &committed);
1285 xfs_bmap_cancel(args->flist);
1290 * bmap_finish() may have committed the last trans and started
1291 * a new one. We need the inode to be in all transactions.
1294 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1295 xfs_trans_ihold(args->trans, dp);
1299 * Addition succeeded, update Btree hashvals.
1301 xfs_da_fixhashpath(state, &state->path);
1305 * Kill the state structure, we're done with it and need to
1306 * allow the buffers to come back later.
1308 xfs_da_state_free(state);
1312 * Commit the leaf addition or btree split and start the next
1313 * trans in the chain.
1315 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1319 * If there was an out-of-line value, allocate the blocks we
1320 * identified for its storage and copy the value. This is done
1321 * after we create the attribute so that we don't overflow the
1322 * maximum size of a transaction and/or hit a deadlock.
1324 if (args->rmtblkno > 0) {
1325 error = xfs_attr_rmtval_set(args);
1331 * If this is an atomic rename operation, we must "flip" the
1332 * incomplete flags on the "new" and "old" attribute/value pairs
1333 * so that one disappears and one appears atomically. Then we
1334 * must remove the "old" attribute/value pair.
1338 * In a separate transaction, set the incomplete flag on the
1339 * "old" attr and clear the incomplete flag on the "new" attr.
1341 error = xfs_attr_leaf_flipflags(args);
1346 * Dismantle the "old" attribute/value pair by removing
1347 * a "remote" value (if it exists).
1349 args->index = args->index2;
1350 args->blkno = args->blkno2;
1351 args->rmtblkno = args->rmtblkno2;
1352 args->rmtblkcnt = args->rmtblkcnt2;
1353 if (args->rmtblkno) {
1354 error = xfs_attr_rmtval_remove(args);
1360 * Re-find the "old" attribute entry after any split ops.
1361 * The INCOMPLETE flag means that we will find the "old"
1362 * attr, not the "new" one.
1364 args->flags |= XFS_ATTR_INCOMPLETE;
1365 state = xfs_da_state_alloc();
1368 state->blocksize = state->mp->m_sb.sb_blocksize;
1369 state->node_ents = state->mp->m_attr_node_ents;
1371 error = xfs_da_node_lookup_int(state, &retval);
1376 * Remove the name and update the hashvals in the tree.
1378 blk = &state->path.blk[ state->path.active-1 ];
1379 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1380 error = xfs_attr_leaf_remove(blk->bp, args);
1381 xfs_da_fixhashpath(state, &state->path);
1384 * Check to see if the tree needs to be collapsed.
1386 if (retval && (state->path.active > 1)) {
1387 XFS_BMAP_INIT(args->flist, args->firstblock);
1388 error = xfs_da_join(state);
1390 error = xfs_bmap_finish(&args->trans,
1398 xfs_bmap_cancel(args->flist);
1403 * bmap_finish() may have committed the last trans
1404 * and started a new one. We need the inode to be
1405 * in all transactions.
1408 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1409 xfs_trans_ihold(args->trans, dp);
1414 * Commit and start the next trans in the chain.
1416 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1419 } else if (args->rmtblkno > 0) {
1421 * Added a "remote" value, just clear the incomplete flag.
1423 error = xfs_attr_leaf_clearflag(args);
1431 xfs_da_state_free(state);
1438 * Remove a name from a B-tree attribute list.
1440 * This will involve walking down the Btree, and may involve joining
1441 * leaf nodes and even joining intermediate nodes up to and including
1442 * the root node (a special case of an intermediate node).
1445 xfs_attr_node_removename(xfs_da_args_t *args)
1447 xfs_da_state_t *state;
1448 xfs_da_state_blk_t *blk;
1451 int retval, error, committed;
1454 * Tie a string around our finger to remind us where we are.
1457 state = xfs_da_state_alloc();
1459 state->mp = dp->i_mount;
1460 state->blocksize = state->mp->m_sb.sb_blocksize;
1461 state->node_ents = state->mp->m_attr_node_ents;
1464 * Search to see if name exists, and get back a pointer to it.
1466 error = xfs_da_node_lookup_int(state, &retval);
1467 if (error || (retval != EEXIST)) {
1474 * If there is an out-of-line value, de-allocate the blocks.
1475 * This is done before we remove the attribute so that we don't
1476 * overflow the maximum size of a transaction and/or hit a deadlock.
1478 blk = &state->path.blk[ state->path.active-1 ];
1479 ASSERT(blk->bp != NULL);
1480 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1481 if (args->rmtblkno > 0) {
1483 * Fill in disk block numbers in the state structure
1484 * so that we can get the buffers back after we commit
1485 * several transactions in the following calls.
1487 error = xfs_attr_fillstate(state);
1492 * Mark the attribute as INCOMPLETE, then bunmapi() the
1495 error = xfs_attr_leaf_setflag(args);
1498 error = xfs_attr_rmtval_remove(args);
1503 * Refill the state structure with buffers, the prior calls
1504 * released our buffers.
1506 error = xfs_attr_refillstate(state);
1512 * Remove the name and update the hashvals in the tree.
1514 blk = &state->path.blk[ state->path.active-1 ];
1515 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1516 retval = xfs_attr_leaf_remove(blk->bp, args);
1517 xfs_da_fixhashpath(state, &state->path);
1520 * Check to see if the tree needs to be collapsed.
1522 if (retval && (state->path.active > 1)) {
1523 XFS_BMAP_INIT(args->flist, args->firstblock);
1524 error = xfs_da_join(state);
1526 error = xfs_bmap_finish(&args->trans, args->flist,
1527 *args->firstblock, &committed);
1532 xfs_bmap_cancel(args->flist);
1537 * bmap_finish() may have committed the last trans and started
1538 * a new one. We need the inode to be in all transactions.
1541 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1542 xfs_trans_ihold(args->trans, dp);
1546 * Commit the Btree join operation and start a new trans.
1548 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
1553 * If the result is small enough, push it all into the inode.
1555 if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
1557 * Have to get rid of the copy of this dabuf in the state.
1559 ASSERT(state->path.active == 1);
1560 ASSERT(state->path.blk[0].bp);
1561 xfs_da_buf_done(state->path.blk[0].bp);
1562 state->path.blk[0].bp = NULL;
1564 error = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp,
1568 ASSERT(INT_GET(((xfs_attr_leafblock_t *)
1569 bp->data)->hdr.info.magic, ARCH_CONVERT)
1570 == XFS_ATTR_LEAF_MAGIC);
1572 if (xfs_attr_shortform_allfit(bp, dp)) {
1573 XFS_BMAP_INIT(args->flist, args->firstblock);
1574 error = xfs_attr_leaf_to_shortform(bp, args);
1575 /* bp is gone due to xfs_da_shrink_inode */
1577 error = xfs_bmap_finish(&args->trans,
1585 xfs_bmap_cancel(args->flist);
1590 * bmap_finish() may have committed the last trans
1591 * and started a new one. We need the inode to be
1592 * in all transactions.
1595 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
1596 xfs_trans_ihold(args->trans, dp);
1599 xfs_da_brelse(args->trans, bp);
1604 xfs_da_state_free(state);
1609 * Fill in the disk block numbers in the state structure for the buffers
1610 * that are attached to the state structure.
1611 * This is done so that we can quickly reattach ourselves to those buffers
1612 * after some set of transaction commit's has released these buffers.
1615 xfs_attr_fillstate(xfs_da_state_t *state)
1617 xfs_da_state_path_t *path;
1618 xfs_da_state_blk_t *blk;
1622 * Roll down the "path" in the state structure, storing the on-disk
1623 * block number for those buffers in the "path".
1625 path = &state->path;
1626 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1627 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1629 blk->disk_blkno = xfs_da_blkno(blk->bp);
1630 xfs_da_buf_done(blk->bp);
1633 blk->disk_blkno = 0;
1638 * Roll down the "altpath" in the state structure, storing the on-disk
1639 * block number for those buffers in the "altpath".
1641 path = &state->altpath;
1642 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1643 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1645 blk->disk_blkno = xfs_da_blkno(blk->bp);
1646 xfs_da_buf_done(blk->bp);
1649 blk->disk_blkno = 0;
1657 * Reattach the buffers to the state structure based on the disk block
1658 * numbers stored in the state structure.
1659 * This is done after some set of transaction commit's has released those
1660 * buffers from our grip.
1663 xfs_attr_refillstate(xfs_da_state_t *state)
1665 xfs_da_state_path_t *path;
1666 xfs_da_state_blk_t *blk;
1670 * Roll down the "path" in the state structure, storing the on-disk
1671 * block number for those buffers in the "path".
1673 path = &state->path;
1674 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1675 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1676 if (blk->disk_blkno) {
1677 error = xfs_da_read_buf(state->args->trans,
1679 blk->blkno, blk->disk_blkno,
1680 &blk->bp, XFS_ATTR_FORK);
1689 * Roll down the "altpath" in the state structure, storing the on-disk
1690 * block number for those buffers in the "altpath".
1692 path = &state->altpath;
1693 ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
1694 for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
1695 if (blk->disk_blkno) {
1696 error = xfs_da_read_buf(state->args->trans,
1698 blk->blkno, blk->disk_blkno,
1699 &blk->bp, XFS_ATTR_FORK);
1711 * Look up a filename in a node attribute list.
1713 * This routine gets called for any attribute fork that has more than one
1714 * block, ie: both true Btree attr lists and for single-leaf-blocks with
1715 * "remote" values taking up more blocks.
1718 xfs_attr_node_get(xfs_da_args_t *args)
1720 xfs_da_state_t *state;
1721 xfs_da_state_blk_t *blk;
1725 state = xfs_da_state_alloc();
1727 state->mp = args->dp->i_mount;
1728 state->blocksize = state->mp->m_sb.sb_blocksize;
1729 state->node_ents = state->mp->m_attr_node_ents;
1732 * Search to see if name exists, and get back a pointer to it.
1734 error = xfs_da_node_lookup_int(state, &retval);
1737 } else if (retval == EEXIST) {
1738 blk = &state->path.blk[ state->path.active-1 ];
1739 ASSERT(blk->bp != NULL);
1740 ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1743 * Get the value, local or "remote"
1745 retval = xfs_attr_leaf_getvalue(blk->bp, args);
1746 if (!retval && (args->rmtblkno > 0)
1747 && !(args->flags & ATTR_KERNOVAL)) {
1748 retval = xfs_attr_rmtval_get(args);
1753 * If not in a transaction, we have to release all the buffers.
1755 for (i = 0; i < state->path.active; i++) {
1756 xfs_da_brelse(args->trans, state->path.blk[i].bp);
1757 state->path.blk[i].bp = NULL;
1760 xfs_da_state_free(state);
1764 STATIC int /* error */
1765 xfs_attr_node_list(xfs_attr_list_context_t *context)
1767 attrlist_cursor_kern_t *cursor;
1768 xfs_attr_leafblock_t *leaf;
1769 xfs_da_intnode_t *node;
1770 xfs_da_node_entry_t *btree;
1774 cursor = context->cursor;
1775 cursor->initted = 1;
1778 * Do all sorts of validation on the passed-in cursor structure.
1779 * If anything is amiss, ignore the cursor and look up the hashval
1780 * starting from the btree root.
1783 if (cursor->blkno > 0) {
1784 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1785 &bp, XFS_ATTR_FORK);
1786 if ((error != 0) && (error != EFSCORRUPTED))
1790 switch (INT_GET(node->hdr.info.magic, ARCH_CONVERT)) {
1791 case XFS_DA_NODE_MAGIC:
1792 xfs_attr_trace_l_cn("wrong blk", context, node);
1793 xfs_da_brelse(NULL, bp);
1796 case XFS_ATTR_LEAF_MAGIC:
1798 if (cursor->hashval >
1799 INT_GET(leaf->entries[
1800 INT_GET(leaf->hdr.count,
1801 ARCH_CONVERT)-1].hashval,
1803 xfs_attr_trace_l_cl("wrong blk",
1805 xfs_da_brelse(NULL, bp);
1807 } else if (cursor->hashval <=
1808 INT_GET(leaf->entries[0].hashval,
1810 xfs_attr_trace_l_cl("maybe wrong blk",
1812 xfs_da_brelse(NULL, bp);
1817 xfs_attr_trace_l_c("wrong blk - ??", context);
1818 xfs_da_brelse(NULL, bp);
1825 * We did not find what we expected given the cursor's contents,
1826 * so we start from the top and work down based on the hash value.
1827 * Note that start of node block is same as start of leaf block.
1832 error = xfs_da_read_buf(NULL, context->dp,
1833 cursor->blkno, -1, &bp,
1837 if (unlikely(bp == NULL)) {
1838 XFS_ERROR_REPORT("xfs_attr_node_list(2)",
1840 context->dp->i_mount);
1841 return(XFS_ERROR(EFSCORRUPTED));
1844 if (INT_GET(node->hdr.info.magic, ARCH_CONVERT)
1845 == XFS_ATTR_LEAF_MAGIC)
1847 if (unlikely(INT_GET(node->hdr.info.magic, ARCH_CONVERT)
1848 != XFS_DA_NODE_MAGIC)) {
1849 XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
1851 context->dp->i_mount,
1853 xfs_da_brelse(NULL, bp);
1854 return(XFS_ERROR(EFSCORRUPTED));
1856 btree = node->btree;
1858 i < INT_GET(node->hdr.count, ARCH_CONVERT);
1861 <= INT_GET(btree->hashval,
1863 cursor->blkno = INT_GET(btree->before, ARCH_CONVERT);
1864 xfs_attr_trace_l_cb("descending",
1869 if (i == INT_GET(node->hdr.count, ARCH_CONVERT)) {
1870 xfs_da_brelse(NULL, bp);
1873 xfs_da_brelse(NULL, bp);
1879 * Roll upward through the blocks, processing each leaf block in
1880 * order. As long as there is space in the result buffer, keep
1881 * adding the information.
1885 if (unlikely(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)
1886 != XFS_ATTR_LEAF_MAGIC)) {
1887 XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
1889 context->dp->i_mount, leaf);
1890 xfs_da_brelse(NULL, bp);
1891 return(XFS_ERROR(EFSCORRUPTED));
1893 error = xfs_attr_leaf_list_int(bp, context);
1894 if (error || !leaf->hdr.info.forw)
1895 break; /* not really an error, buffer full or EOF */
1896 cursor->blkno = INT_GET(leaf->hdr.info.forw, ARCH_CONVERT);
1897 xfs_da_brelse(NULL, bp);
1898 error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
1899 &bp, XFS_ATTR_FORK);
1902 if (unlikely((bp == NULL))) {
1903 XFS_ERROR_REPORT("xfs_attr_node_list(5)",
1905 context->dp->i_mount);
1906 return(XFS_ERROR(EFSCORRUPTED));
1909 xfs_da_brelse(NULL, bp);
1914 /*========================================================================
1915 * External routines for manipulating out-of-line attribute values.
1916 *========================================================================*/
1919 * Read the value associated with an attribute from the out-of-line buffer
1920 * that we stored it in.
1923 xfs_attr_rmtval_get(xfs_da_args_t *args)
1925 xfs_bmbt_irec_t map[ATTR_RMTVALUE_MAPSIZE];
1930 int nmap, error, tmp, valuelen, blkcnt, i;
1933 ASSERT(!(args->flags & ATTR_KERNOVAL));
1935 mp = args->dp->i_mount;
1937 valuelen = args->valuelen;
1938 lblkno = args->rmtblkno;
1939 while (valuelen > 0) {
1940 nmap = ATTR_RMTVALUE_MAPSIZE;
1941 error = xfs_bmapi(args->trans, args->dp, (xfs_fileoff_t)lblkno,
1943 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
1944 NULL, 0, map, &nmap, NULL);
1949 for (i = 0; (i < nmap) && (valuelen > 0); i++) {
1950 ASSERT((map[i].br_startblock != DELAYSTARTBLOCK) &&
1951 (map[i].br_startblock != HOLESTARTBLOCK));
1952 dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
1953 blkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
1954 error = xfs_read_buf(mp, mp->m_ddev_targp, dblkno,
1955 blkcnt, XFS_BUF_LOCK, &bp);
1959 tmp = (valuelen < XFS_BUF_SIZE(bp))
1960 ? valuelen : XFS_BUF_SIZE(bp);
1961 xfs_biomove(bp, 0, tmp, dst, XFS_B_READ);
1966 lblkno += map[i].br_blockcount;
1969 ASSERT(valuelen == 0);
1974 * Write the value associated with an attribute into the out-of-line buffer
1975 * that we have defined for it.
1978 xfs_attr_rmtval_set(xfs_da_args_t *args)
1981 xfs_fileoff_t lfileoff;
1983 xfs_bmbt_irec_t map;
1988 int blkcnt, valuelen, nmap, error, tmp, committed;
1995 * Find a "hole" in the attribute address space large enough for
1996 * us to drop the new attribute's value into.
1998 blkcnt = XFS_B_TO_FSB(mp, args->valuelen);
2000 error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff,
2005 args->rmtblkno = lblkno = (xfs_dablk_t)lfileoff;
2006 args->rmtblkcnt = blkcnt;
2009 * Roll through the "value", allocating blocks on disk as required.
2011 while (blkcnt > 0) {
2013 * Allocate a single extent, up to the size of the value.
2015 XFS_BMAP_INIT(args->flist, args->firstblock);
2017 error = xfs_bmapi(args->trans, dp, (xfs_fileoff_t)lblkno,
2019 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA |
2021 args->firstblock, args->total, &map, &nmap,
2024 error = xfs_bmap_finish(&args->trans, args->flist,
2025 *args->firstblock, &committed);
2030 xfs_bmap_cancel(args->flist);
2035 * bmap_finish() may have committed the last trans and started
2036 * a new one. We need the inode to be in all transactions.
2039 xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
2040 xfs_trans_ihold(args->trans, dp);
2044 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2045 (map.br_startblock != HOLESTARTBLOCK));
2046 lblkno += map.br_blockcount;
2047 blkcnt -= map.br_blockcount;
2050 * Start the next trans in the chain.
2052 if ((error = xfs_attr_rolltrans(&args->trans, dp)))
2057 * Roll through the "value", copying the attribute value to the
2058 * already-allocated blocks. Blocks are written synchronously
2059 * so that we can know they are all on disk before we turn off
2060 * the INCOMPLETE flag.
2062 lblkno = args->rmtblkno;
2063 valuelen = args->valuelen;
2064 while (valuelen > 0) {
2066 * Try to remember where we decided to put the value.
2068 XFS_BMAP_INIT(args->flist, args->firstblock);
2070 error = xfs_bmapi(NULL, dp, (xfs_fileoff_t)lblkno,
2072 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2073 args->firstblock, 0, &map, &nmap, NULL);
2078 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2079 (map.br_startblock != HOLESTARTBLOCK));
2081 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2082 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2084 bp = xfs_buf_get_flags(mp->m_ddev_targp, dblkno,
2085 blkcnt, XFS_BUF_LOCK);
2087 ASSERT(!XFS_BUF_GETERROR(bp));
2089 tmp = (valuelen < XFS_BUF_SIZE(bp)) ? valuelen :
2091 xfs_biomove(bp, 0, tmp, src, XFS_B_WRITE);
2092 if (tmp < XFS_BUF_SIZE(bp))
2093 xfs_biozero(bp, tmp, XFS_BUF_SIZE(bp) - tmp);
2094 if ((error = xfs_bwrite(mp, bp))) {/* GROT: NOTE: synchronous write */
2100 lblkno += map.br_blockcount;
2102 ASSERT(valuelen == 0);
2107 * Remove the value associated with an attribute by deleting the
2108 * out-of-line buffer that it is stored on.
2111 xfs_attr_rmtval_remove(xfs_da_args_t *args)
2114 xfs_bmbt_irec_t map;
2118 int valuelen, blkcnt, nmap, error, done, committed;
2120 mp = args->dp->i_mount;
2123 * Roll through the "value", invalidating the attribute value's
2126 lblkno = args->rmtblkno;
2127 valuelen = args->rmtblkcnt;
2128 while (valuelen > 0) {
2130 * Try to remember where we decided to put the value.
2132 XFS_BMAP_INIT(args->flist, args->firstblock);
2134 error = xfs_bmapi(NULL, args->dp, (xfs_fileoff_t)lblkno,
2136 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2137 args->firstblock, 0, &map, &nmap,
2143 ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
2144 (map.br_startblock != HOLESTARTBLOCK));
2146 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2147 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2150 * If the "remote" value is in the cache, remove it.
2152 bp = xfs_incore(mp->m_ddev_targp, dblkno, blkcnt,
2153 XFS_INCORE_TRYLOCK);
2156 XFS_BUF_UNDELAYWRITE(bp);
2161 valuelen -= map.br_blockcount;
2163 lblkno += map.br_blockcount;
2167 * Keep de-allocating extents until the remote-value region is gone.
2169 lblkno = args->rmtblkno;
2170 blkcnt = args->rmtblkcnt;
2173 XFS_BMAP_INIT(args->flist, args->firstblock);
2174 error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
2175 XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
2176 1, args->firstblock, args->flist, &done);
2178 error = xfs_bmap_finish(&args->trans, args->flist,
2179 *args->firstblock, &committed);
2184 xfs_bmap_cancel(args->flist);
2189 * bmap_finish() may have committed the last trans and started
2190 * a new one. We need the inode to be in all transactions.
2193 xfs_trans_ijoin(args->trans, args->dp, XFS_ILOCK_EXCL);
2194 xfs_trans_ihold(args->trans, args->dp);
2198 * Close out trans and start the next one in the chain.
2200 if ((error = xfs_attr_rolltrans(&args->trans, args->dp)))
2206 #if defined(XFS_ATTR_TRACE)
2208 * Add a trace buffer entry for an attr_list context structure.
2211 xfs_attr_trace_l_c(char *where, struct xfs_attr_list_context *context)
2213 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_C, where,
2214 (__psunsigned_t)context->dp,
2215 (__psunsigned_t)context->cursor->hashval,
2216 (__psunsigned_t)context->cursor->blkno,
2217 (__psunsigned_t)context->cursor->offset,
2218 (__psunsigned_t)context->alist,
2219 (__psunsigned_t)context->bufsize,
2220 (__psunsigned_t)context->count,
2221 (__psunsigned_t)context->firstu,
2223 ((context->count > 0) &&
2224 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2225 ? (ATTR_ENTRY(context->alist,
2226 context->count-1)->a_valuelen)
2228 (__psunsigned_t)context->dupcnt,
2229 (__psunsigned_t)context->flags,
2230 (__psunsigned_t)NULL,
2231 (__psunsigned_t)NULL,
2232 (__psunsigned_t)NULL);
2236 * Add a trace buffer entry for a context structure and a Btree node.
2239 xfs_attr_trace_l_cn(char *where, struct xfs_attr_list_context *context,
2240 struct xfs_da_intnode *node)
2242 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CN, where,
2243 (__psunsigned_t)context->dp,
2244 (__psunsigned_t)context->cursor->hashval,
2245 (__psunsigned_t)context->cursor->blkno,
2246 (__psunsigned_t)context->cursor->offset,
2247 (__psunsigned_t)context->alist,
2248 (__psunsigned_t)context->bufsize,
2249 (__psunsigned_t)context->count,
2250 (__psunsigned_t)context->firstu,
2252 ((context->count > 0) &&
2253 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2254 ? (ATTR_ENTRY(context->alist,
2255 context->count-1)->a_valuelen)
2257 (__psunsigned_t)context->dupcnt,
2258 (__psunsigned_t)context->flags,
2259 (__psunsigned_t)INT_GET(node->hdr.count, ARCH_CONVERT),
2260 (__psunsigned_t)INT_GET(node->btree[0].hashval, ARCH_CONVERT),
2261 (__psunsigned_t)INT_GET(node->btree[INT_GET(node->hdr.count, ARCH_CONVERT)-1].hashval, ARCH_CONVERT));
2265 * Add a trace buffer entry for a context structure and a Btree element.
2268 xfs_attr_trace_l_cb(char *where, struct xfs_attr_list_context *context,
2269 struct xfs_da_node_entry *btree)
2271 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CB, where,
2272 (__psunsigned_t)context->dp,
2273 (__psunsigned_t)context->cursor->hashval,
2274 (__psunsigned_t)context->cursor->blkno,
2275 (__psunsigned_t)context->cursor->offset,
2276 (__psunsigned_t)context->alist,
2277 (__psunsigned_t)context->bufsize,
2278 (__psunsigned_t)context->count,
2279 (__psunsigned_t)context->firstu,
2281 ((context->count > 0) &&
2282 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2283 ? (ATTR_ENTRY(context->alist,
2284 context->count-1)->a_valuelen)
2286 (__psunsigned_t)context->dupcnt,
2287 (__psunsigned_t)context->flags,
2288 (__psunsigned_t)INT_GET(btree->hashval, ARCH_CONVERT),
2289 (__psunsigned_t)INT_GET(btree->before, ARCH_CONVERT),
2290 (__psunsigned_t)NULL);
2294 * Add a trace buffer entry for a context structure and a leaf block.
2297 xfs_attr_trace_l_cl(char *where, struct xfs_attr_list_context *context,
2298 struct xfs_attr_leafblock *leaf)
2300 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CL, where,
2301 (__psunsigned_t)context->dp,
2302 (__psunsigned_t)context->cursor->hashval,
2303 (__psunsigned_t)context->cursor->blkno,
2304 (__psunsigned_t)context->cursor->offset,
2305 (__psunsigned_t)context->alist,
2306 (__psunsigned_t)context->bufsize,
2307 (__psunsigned_t)context->count,
2308 (__psunsigned_t)context->firstu,
2310 ((context->count > 0) &&
2311 !(context->flags & (ATTR_KERNAMELS|ATTR_KERNOVAL)))
2312 ? (ATTR_ENTRY(context->alist,
2313 context->count-1)->a_valuelen)
2315 (__psunsigned_t)context->dupcnt,
2316 (__psunsigned_t)context->flags,
2317 (__psunsigned_t)INT_GET(leaf->hdr.count, ARCH_CONVERT),
2318 (__psunsigned_t)INT_GET(leaf->entries[0].hashval, ARCH_CONVERT),
2319 (__psunsigned_t)INT_GET(leaf->entries[INT_GET(leaf->hdr.count, ARCH_CONVERT)-1].hashval, ARCH_CONVERT));
2323 * Add a trace buffer entry for the arguments given to the routine,
2327 xfs_attr_trace_enter(int type, char *where,
2328 __psunsigned_t a2, __psunsigned_t a3,
2329 __psunsigned_t a4, __psunsigned_t a5,
2330 __psunsigned_t a6, __psunsigned_t a7,
2331 __psunsigned_t a8, __psunsigned_t a9,
2332 __psunsigned_t a10, __psunsigned_t a11,
2333 __psunsigned_t a12, __psunsigned_t a13,
2334 __psunsigned_t a14, __psunsigned_t a15)
2336 ASSERT(xfs_attr_trace_buf);
2337 ktrace_enter(xfs_attr_trace_buf, (void *)((__psunsigned_t)type),
2339 (void *)a2, (void *)a3, (void *)a4,
2340 (void *)a5, (void *)a6, (void *)a7,
2341 (void *)a8, (void *)a9, (void *)a10,
2342 (void *)a11, (void *)a12, (void *)a13,
2343 (void *)a14, (void *)a15);
2345 #endif /* XFS_ATTR_TRACE */
2348 /*========================================================================
2349 * System (pseudo) namespace attribute interface routines.
2350 *========================================================================*/
2353 posix_acl_access_set(
2354 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2356 return xfs_acl_vset(vp, data, size, _ACL_TYPE_ACCESS);
2360 posix_acl_access_remove(
2361 struct vnode *vp, char *name, int xflags)
2363 return xfs_acl_vremove(vp, _ACL_TYPE_ACCESS);
2367 posix_acl_access_get(
2368 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2370 return xfs_acl_vget(vp, data, size, _ACL_TYPE_ACCESS);
2374 posix_acl_access_exists(
2377 return xfs_acl_vhasacl_access(vp);
2381 posix_acl_default_set(
2382 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2384 return xfs_acl_vset(vp, data, size, _ACL_TYPE_DEFAULT);
2388 posix_acl_default_get(
2389 vnode_t *vp, char *name, void *data, size_t size, int xflags)
2391 return xfs_acl_vget(vp, data, size, _ACL_TYPE_DEFAULT);
2395 posix_acl_default_remove(
2396 struct vnode *vp, char *name, int xflags)
2398 return xfs_acl_vremove(vp, _ACL_TYPE_DEFAULT);
2402 posix_acl_default_exists(
2405 return xfs_acl_vhasacl_default(vp);
2408 STATIC struct attrnames posix_acl_access = {
2409 .attr_name = "posix_acl_access",
2410 .attr_namelen = sizeof("posix_acl_access") - 1,
2411 .attr_get = posix_acl_access_get,
2412 .attr_set = posix_acl_access_set,
2413 .attr_remove = posix_acl_access_remove,
2414 .attr_exists = posix_acl_access_exists,
2417 STATIC struct attrnames posix_acl_default = {
2418 .attr_name = "posix_acl_default",
2419 .attr_namelen = sizeof("posix_acl_default") - 1,
2420 .attr_get = posix_acl_default_get,
2421 .attr_set = posix_acl_default_set,
2422 .attr_remove = posix_acl_default_remove,
2423 .attr_exists = posix_acl_default_exists,
2426 STATIC struct attrnames *attr_system_names[] =
2427 { &posix_acl_access, &posix_acl_default };
2430 /*========================================================================
2431 * Namespace-prefix-style attribute name interface routines.
2432 *========================================================================*/
2436 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2440 VOP_ATTR_SET(vp, name, data, size, xflags, NULL, error);
2446 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2448 int error, asize = size;
2450 VOP_ATTR_GET(vp, name, data, &asize, xflags, NULL, error);
2457 attr_generic_remove(
2458 struct vnode *vp, char *name, int xflags)
2462 VOP_ATTR_REMOVE(vp, name, xflags, NULL, error);
2467 attr_generic_listadd(
2468 attrnames_t *prefix,
2469 attrnames_t *namesp,
2474 char *p = data + *result;
2476 *result += prefix->attr_namelen;
2477 *result += namesp->attr_namelen + 1;
2482 strcpy(p, prefix->attr_name);
2483 p += prefix->attr_namelen;
2484 strcpy(p, namesp->attr_name);
2485 p += namesp->attr_namelen + 1;
2496 attrnames_t *namesp;
2499 for (i = 0; i < ATTR_SYSCOUNT; i++) {
2500 namesp = attr_system_names[i];
2501 if (!namesp->attr_exists || !namesp->attr_exists(vp))
2503 error = attr_generic_listadd(&attr_system, namesp,
2504 data, size, result);
2513 struct vnode *vp, void *data, size_t size, int xflags, ssize_t *result)
2515 attrlist_cursor_kern_t cursor = { 0 };
2518 VOP_ATTR_LIST(vp, data, size, xflags, &cursor, NULL, error);
2522 return attr_system_list(vp, data, size, result);
2526 attr_lookup_namespace(
2528 struct attrnames **names,
2533 for (i = 0; i < nnames; i++)
2534 if (!strncmp(name, names[i]->attr_name, names[i]->attr_namelen))
2540 * Some checks to prevent people abusing EAs to get over quota:
2541 * - Don't allow modifying user EAs on devices/symlinks;
2542 * - Don't allow modifying user EAs if sticky bit set;
2549 struct inode *inode = LINVFS_GET_IP(vp);
2551 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2553 if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode) &&
2554 !capable(CAP_SYS_ADMIN))
2556 if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) &&
2557 (current_fsuid(cred) != inode->i_uid) && !capable(CAP_FOWNER))
2563 attr_trusted_capable(
2567 struct inode *inode = LINVFS_GET_IP(vp);
2569 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2571 if (!capable(CAP_SYS_ADMIN))
2577 attr_secure_capable(
2581 return -ENOSECURITY;
2586 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2588 attrnames_t *namesp;
2591 if (xflags & ATTR_CREATE)
2594 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2597 error = namesp->attr_set(vp, name, data, size, xflags);
2599 error = vn_revalidate(vp);
2605 struct vnode *vp, char *name, void *data, size_t size, int xflags)
2607 attrnames_t *namesp;
2609 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2612 return namesp->attr_get(vp, name, data, size, xflags);
2617 struct vnode *vp, char *name, int xflags)
2619 attrnames_t *namesp;
2621 namesp = attr_lookup_namespace(name, attr_system_names, ATTR_SYSCOUNT);
2624 return namesp->attr_remove(vp, name, xflags);
2627 struct attrnames attr_system = {
2628 .attr_name = "system.",
2629 .attr_namelen = sizeof("system.") - 1,
2630 .attr_flag = ATTR_SYSTEM,
2631 .attr_get = attr_system_get,
2632 .attr_set = attr_system_set,
2633 .attr_remove = attr_system_remove,
2634 .attr_capable = (attrcapable_t)fs_noerr,
2637 struct attrnames attr_trusted = {
2638 .attr_name = "trusted.",
2639 .attr_namelen = sizeof("trusted.") - 1,
2640 .attr_flag = ATTR_ROOT,
2641 .attr_get = attr_generic_get,
2642 .attr_set = attr_generic_set,
2643 .attr_remove = attr_generic_remove,
2644 .attr_capable = attr_trusted_capable,
2647 struct attrnames attr_secure = {
2648 .attr_name = "security.",
2649 .attr_namelen = sizeof("security.") - 1,
2650 .attr_flag = ATTR_SECURE,
2651 .attr_get = attr_generic_get,
2652 .attr_set = attr_generic_set,
2653 .attr_remove = attr_generic_remove,
2654 .attr_capable = attr_secure_capable,
2657 struct attrnames attr_user = {
2658 .attr_name = "user.",
2659 .attr_namelen = sizeof("user.") - 1,
2660 .attr_get = attr_generic_get,
2661 .attr_set = attr_generic_set,
2662 .attr_remove = attr_generic_remove,
2663 .attr_capable = attr_user_capable,
2666 struct attrnames *attr_namespaces[] =
2667 { &attr_system, &attr_trusted, &attr_secure, &attr_user };