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"
52 #include "xfs_vnodeops.h"
57 * Provide the external interfaces to manage attribute lists.
60 #define ATTR_SYSCOUNT 2
61 static struct attrnames posix_acl_access
;
62 static struct attrnames posix_acl_default
;
63 static struct attrnames
*attr_system_names
[ATTR_SYSCOUNT
];
65 /*========================================================================
66 * Function prototypes for the kernel.
67 *========================================================================*/
70 * Internal routines when attribute list fits inside the inode.
72 STATIC
int xfs_attr_shortform_addname(xfs_da_args_t
*args
);
75 * Internal routines when attribute list is one block.
77 STATIC
int xfs_attr_leaf_get(xfs_da_args_t
*args
);
78 STATIC
int xfs_attr_leaf_addname(xfs_da_args_t
*args
);
79 STATIC
int xfs_attr_leaf_removename(xfs_da_args_t
*args
);
80 STATIC
int xfs_attr_leaf_list(xfs_attr_list_context_t
*context
);
83 * Internal routines when attribute list is more than one block.
85 STATIC
int xfs_attr_node_get(xfs_da_args_t
*args
);
86 STATIC
int xfs_attr_node_addname(xfs_da_args_t
*args
);
87 STATIC
int xfs_attr_node_removename(xfs_da_args_t
*args
);
88 STATIC
int xfs_attr_node_list(xfs_attr_list_context_t
*context
);
89 STATIC
int xfs_attr_fillstate(xfs_da_state_t
*state
);
90 STATIC
int xfs_attr_refillstate(xfs_da_state_t
*state
);
93 * Routines to manipulate out-of-line attribute values.
95 STATIC
int xfs_attr_rmtval_set(xfs_da_args_t
*args
);
96 STATIC
int xfs_attr_rmtval_remove(xfs_da_args_t
*args
);
98 #define ATTR_RMTVALUE_MAPSIZE 1 /* # of map entries at once */
100 #if defined(XFS_ATTR_TRACE)
101 ktrace_t
*xfs_attr_trace_buf
;
105 /*========================================================================
106 * Overall external interface routines.
107 *========================================================================*/
110 xfs_attr_fetch(xfs_inode_t
*ip
, const char *name
, int namelen
,
111 char *value
, int *valuelenp
, int flags
, struct cred
*cred
)
116 if ((XFS_IFORK_Q(ip
) == 0) ||
117 (ip
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
118 ip
->i_d
.di_anextents
== 0))
122 * Fill in the arg structure for this request.
124 memset((char *)&args
, 0, sizeof(args
));
126 args
.namelen
= namelen
;
128 args
.valuelen
= *valuelenp
;
130 args
.hashval
= xfs_da_hashname(args
.name
, args
.namelen
);
132 args
.whichfork
= XFS_ATTR_FORK
;
135 * Decide on what work routines to call based on the inode size.
137 if (XFS_IFORK_Q(ip
) == 0 ||
138 (ip
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
139 ip
->i_d
.di_anextents
== 0)) {
140 error
= XFS_ERROR(ENOATTR
);
141 } else if (ip
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) {
142 error
= xfs_attr_shortform_getvalue(&args
);
143 } else if (xfs_bmap_one_block(ip
, XFS_ATTR_FORK
)) {
144 error
= xfs_attr_leaf_get(&args
);
146 error
= xfs_attr_node_get(&args
);
150 * Return the number of bytes in the value to the caller.
152 *valuelenp
= args
.valuelen
;
170 XFS_STATS_INC(xs_attr_get
);
174 namelen
= strlen(name
);
175 if (namelen
>= MAXNAMELEN
)
176 return(EFAULT
); /* match IRIX behaviour */
178 if (XFS_FORCED_SHUTDOWN(ip
->i_mount
))
181 xfs_ilock(ip
, XFS_ILOCK_SHARED
);
182 error
= xfs_attr_fetch(ip
, name
, namelen
, value
, valuelenp
, flags
, cred
);
183 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
188 xfs_attr_set_int(xfs_inode_t
*dp
, const char *name
, int namelen
,
189 char *value
, int valuelen
, int flags
)
192 xfs_fsblock_t firstblock
;
193 xfs_bmap_free_t flist
;
194 int error
, err2
, committed
;
197 xfs_mount_t
*mp
= dp
->i_mount
;
198 int rsvd
= (flags
& ATTR_ROOT
) != 0;
201 * Attach the dquots to the inode.
203 if ((error
= XFS_QM_DQATTACH(mp
, dp
, 0)))
207 * If the inode doesn't have an attribute fork, add one.
208 * (inode must not be locked when we call this routine)
210 if (XFS_IFORK_Q(dp
) == 0) {
211 int sf_size
= sizeof(xfs_attr_sf_hdr_t
) +
212 XFS_ATTR_SF_ENTSIZE_BYNAME(namelen
, valuelen
);
214 if ((error
= xfs_bmap_add_attrfork(dp
, sf_size
, rsvd
)))
219 * Fill in the arg structure for this request.
221 memset((char *)&args
, 0, sizeof(args
));
223 args
.namelen
= namelen
;
225 args
.valuelen
= valuelen
;
227 args
.hashval
= xfs_da_hashname(args
.name
, args
.namelen
);
229 args
.firstblock
= &firstblock
;
231 args
.whichfork
= XFS_ATTR_FORK
;
236 * Determine space new attribute will use, and if it would be
237 * "local" or "remote" (note: local != inline).
239 size
= xfs_attr_leaf_newentsize(namelen
, valuelen
,
240 mp
->m_sb
.sb_blocksize
, &local
);
242 nblks
= XFS_DAENTER_SPACE_RES(mp
, XFS_ATTR_FORK
);
244 if (size
> (mp
->m_sb
.sb_blocksize
>> 1)) {
245 /* Double split possible */
249 uint dblocks
= XFS_B_TO_FSB(mp
, valuelen
);
250 /* Out of line attribute, cannot double split, but make
251 * room for the attribute value itself.
254 nblks
+= XFS_NEXTENTADD_SPACE_RES(mp
, dblocks
, XFS_ATTR_FORK
);
257 /* Size is now blocks for attribute data */
261 * Start our first transaction of the day.
263 * All future transactions during this code must be "chained" off
264 * this one via the trans_dup() call. All transactions will contain
265 * the inode, and the inode will always be marked with trans_ihold().
266 * Since the inode will be locked in all transactions, we must log
267 * the inode in every transaction to let it float upward through
270 args
.trans
= xfs_trans_alloc(mp
, XFS_TRANS_ATTR_SET
);
273 * Root fork attributes can use reserved data blocks for this
274 * operation if necessary
278 args
.trans
->t_flags
|= XFS_TRANS_RESERVE
;
280 if ((error
= xfs_trans_reserve(args
.trans
, (uint
) nblks
,
281 XFS_ATTRSET_LOG_RES(mp
, nblks
),
282 0, XFS_TRANS_PERM_LOG_RES
,
283 XFS_ATTRSET_LOG_COUNT
))) {
284 xfs_trans_cancel(args
.trans
, 0);
287 xfs_ilock(dp
, XFS_ILOCK_EXCL
);
289 error
= XFS_TRANS_RESERVE_QUOTA_NBLKS(mp
, args
.trans
, dp
, nblks
, 0,
290 rsvd
? XFS_QMOPT_RES_REGBLKS
| XFS_QMOPT_FORCE_RES
:
291 XFS_QMOPT_RES_REGBLKS
);
293 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
294 xfs_trans_cancel(args
.trans
, XFS_TRANS_RELEASE_LOG_RES
);
298 xfs_trans_ijoin(args
.trans
, dp
, XFS_ILOCK_EXCL
);
299 xfs_trans_ihold(args
.trans
, dp
);
302 * If the attribute list is non-existent or a shortform list,
303 * upgrade it to a single-leaf-block attribute list.
305 if ((dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
306 ((dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
) &&
307 (dp
->i_d
.di_anextents
== 0))) {
310 * Build initial attribute list (if required).
312 if (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
)
313 xfs_attr_shortform_create(&args
);
316 * Try to add the attr to the attribute list in
319 error
= xfs_attr_shortform_addname(&args
);
320 if (error
!= ENOSPC
) {
322 * Commit the shortform mods, and we're done.
323 * NOTE: this is also the error path (EEXIST, etc).
325 ASSERT(args
.trans
!= NULL
);
328 * If this is a synchronous mount, make sure that
329 * the transaction goes to disk before returning
332 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
333 xfs_trans_set_sync(args
.trans
);
335 err2
= xfs_trans_commit(args
.trans
,
336 XFS_TRANS_RELEASE_LOG_RES
);
337 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
340 * Hit the inode change time.
342 if (!error
&& (flags
& ATTR_KERNOTIME
) == 0) {
343 xfs_ichgtime(dp
, XFS_ICHGTIME_CHG
);
345 return(error
== 0 ? err2
: error
);
349 * It won't fit in the shortform, transform to a leaf block.
350 * GROT: another possible req'mt for a double-split btree op.
352 XFS_BMAP_INIT(args
.flist
, args
.firstblock
);
353 error
= xfs_attr_shortform_to_leaf(&args
);
355 error
= xfs_bmap_finish(&args
.trans
, args
.flist
,
361 xfs_bmap_cancel(&flist
);
366 * bmap_finish() may have committed the last trans and started
367 * a new one. We need the inode to be in all transactions.
370 xfs_trans_ijoin(args
.trans
, dp
, XFS_ILOCK_EXCL
);
371 xfs_trans_ihold(args
.trans
, dp
);
375 * Commit the leaf transformation. We'll need another (linked)
376 * transaction to add the new attribute to the leaf.
378 if ((error
= xfs_attr_rolltrans(&args
.trans
, dp
)))
383 if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
384 error
= xfs_attr_leaf_addname(&args
);
386 error
= xfs_attr_node_addname(&args
);
393 * If this is a synchronous mount, make sure that the
394 * transaction goes to disk before returning to the user.
396 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
397 xfs_trans_set_sync(args
.trans
);
401 * Commit the last in the sequence of transactions.
403 xfs_trans_log_inode(args
.trans
, dp
, XFS_ILOG_CORE
);
404 error
= xfs_trans_commit(args
.trans
, XFS_TRANS_RELEASE_LOG_RES
);
405 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
408 * Hit the inode change time.
410 if (!error
&& (flags
& ATTR_KERNOTIME
) == 0) {
411 xfs_ichgtime(dp
, XFS_ICHGTIME_CHG
);
418 xfs_trans_cancel(args
.trans
,
419 XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
420 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
434 namelen
= strlen(name
);
435 if (namelen
>= MAXNAMELEN
)
436 return EFAULT
; /* match IRIX behaviour */
438 XFS_STATS_INC(xs_attr_set
);
440 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
443 return xfs_attr_set_int(dp
, name
, namelen
, value
, valuelen
, flags
);
447 * Generic handler routine to remove a name from an attribute list.
448 * Transitions attribute list from Btree to shortform as necessary.
451 xfs_attr_remove_int(xfs_inode_t
*dp
, const char *name
, int namelen
, int flags
)
454 xfs_fsblock_t firstblock
;
455 xfs_bmap_free_t flist
;
457 xfs_mount_t
*mp
= dp
->i_mount
;
460 * Fill in the arg structure for this request.
462 memset((char *)&args
, 0, sizeof(args
));
464 args
.namelen
= namelen
;
466 args
.hashval
= xfs_da_hashname(args
.name
, args
.namelen
);
468 args
.firstblock
= &firstblock
;
471 args
.whichfork
= XFS_ATTR_FORK
;
474 * Attach the dquots to the inode.
476 if ((error
= XFS_QM_DQATTACH(mp
, dp
, 0)))
480 * Start our first transaction of the day.
482 * All future transactions during this code must be "chained" off
483 * this one via the trans_dup() call. All transactions will contain
484 * the inode, and the inode will always be marked with trans_ihold().
485 * Since the inode will be locked in all transactions, we must log
486 * the inode in every transaction to let it float upward through
489 args
.trans
= xfs_trans_alloc(mp
, XFS_TRANS_ATTR_RM
);
492 * Root fork attributes can use reserved data blocks for this
493 * operation if necessary
496 if (flags
& ATTR_ROOT
)
497 args
.trans
->t_flags
|= XFS_TRANS_RESERVE
;
499 if ((error
= xfs_trans_reserve(args
.trans
,
500 XFS_ATTRRM_SPACE_RES(mp
),
501 XFS_ATTRRM_LOG_RES(mp
),
502 0, XFS_TRANS_PERM_LOG_RES
,
503 XFS_ATTRRM_LOG_COUNT
))) {
504 xfs_trans_cancel(args
.trans
, 0);
508 xfs_ilock(dp
, XFS_ILOCK_EXCL
);
510 * No need to make quota reservations here. We expect to release some
511 * blocks not allocate in the common case.
513 xfs_trans_ijoin(args
.trans
, dp
, XFS_ILOCK_EXCL
);
514 xfs_trans_ihold(args
.trans
, dp
);
517 * Decide on what work routines to call based on the inode size.
519 if (XFS_IFORK_Q(dp
) == 0 ||
520 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
521 dp
->i_d
.di_anextents
== 0)) {
522 error
= XFS_ERROR(ENOATTR
);
525 if (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) {
526 ASSERT(dp
->i_afp
->if_flags
& XFS_IFINLINE
);
527 error
= xfs_attr_shortform_remove(&args
);
531 } else if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
532 error
= xfs_attr_leaf_removename(&args
);
534 error
= xfs_attr_node_removename(&args
);
541 * If this is a synchronous mount, make sure that the
542 * transaction goes to disk before returning to the user.
544 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
545 xfs_trans_set_sync(args
.trans
);
549 * Commit the last in the sequence of transactions.
551 xfs_trans_log_inode(args
.trans
, dp
, XFS_ILOG_CORE
);
552 error
= xfs_trans_commit(args
.trans
, XFS_TRANS_RELEASE_LOG_RES
);
553 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
556 * Hit the inode change time.
558 if (!error
&& (flags
& ATTR_KERNOTIME
) == 0) {
559 xfs_ichgtime(dp
, XFS_ICHGTIME_CHG
);
566 xfs_trans_cancel(args
.trans
,
567 XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
568 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
580 namelen
= strlen(name
);
581 if (namelen
>= MAXNAMELEN
)
582 return EFAULT
; /* match IRIX behaviour */
584 XFS_STATS_INC(xs_attr_remove
);
586 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
589 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
590 if (XFS_IFORK_Q(dp
) == 0 ||
591 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
592 dp
->i_d
.di_anextents
== 0)) {
593 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
594 return(XFS_ERROR(ENOATTR
));
596 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
598 return xfs_attr_remove_int(dp
, name
, namelen
, flags
);
602 xfs_attr_list_int(xfs_attr_list_context_t
*context
)
605 xfs_inode_t
*dp
= context
->dp
;
608 * Decide on what work routines to call based on the inode size.
610 if (XFS_IFORK_Q(dp
) == 0 ||
611 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
612 dp
->i_d
.di_anextents
== 0)) {
614 } else if (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) {
615 error
= xfs_attr_shortform_list(context
);
616 } else if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
617 error
= xfs_attr_leaf_list(context
);
619 error
= xfs_attr_node_list(context
);
624 #define ATTR_ENTBASESIZE /* minimum bytes used by an attr */ \
625 (((struct attrlist_ent *) 0)->a_name - (char *) 0)
626 #define ATTR_ENTSIZE(namelen) /* actual bytes used by an attr */ \
627 ((ATTR_ENTBASESIZE + (namelen) + 1 + sizeof(u_int32_t)-1) \
628 & ~(sizeof(u_int32_t)-1))
631 * Format an attribute and copy it out to the user's buffer.
632 * Take care to check values and protect against them changing later,
633 * we may be reading them directly out of a user buffer.
637 xfs_attr_put_listent(xfs_attr_list_context_t
*context
, attrnames_t
*namesp
,
638 char *name
, int namelen
,
639 int valuelen
, char *value
)
644 ASSERT(!(context
->flags
& ATTR_KERNOVAL
));
645 ASSERT(context
->count
>= 0);
646 ASSERT(context
->count
< (ATTR_MAX_VALUELEN
/8));
647 ASSERT(context
->firstu
>= sizeof(*context
->alist
));
648 ASSERT(context
->firstu
<= context
->bufsize
);
650 arraytop
= sizeof(*context
->alist
) +
651 context
->count
* sizeof(context
->alist
->al_offset
[0]);
652 context
->firstu
-= ATTR_ENTSIZE(namelen
);
653 if (context
->firstu
< arraytop
) {
654 xfs_attr_trace_l_c("buffer full", context
);
655 context
->alist
->al_more
= 1;
656 context
->seen_enough
= 1;
660 aep
= (attrlist_ent_t
*)&(((char *)context
->alist
)[ context
->firstu
]);
661 aep
->a_valuelen
= valuelen
;
662 memcpy(aep
->a_name
, name
, namelen
);
663 aep
->a_name
[ namelen
] = 0;
664 context
->alist
->al_offset
[ context
->count
++ ] = context
->firstu
;
665 context
->alist
->al_count
= context
->count
;
666 xfs_attr_trace_l_c("add", context
);
671 xfs_attr_kern_list(xfs_attr_list_context_t
*context
, attrnames_t
*namesp
,
672 char *name
, int namelen
,
673 int valuelen
, char *value
)
678 ASSERT(context
->count
>= 0);
680 arraytop
= context
->count
+ namesp
->attr_namelen
+ namelen
+ 1;
681 if (arraytop
> context
->firstu
) {
682 context
->count
= -1; /* insufficient space */
685 offset
= (char *)context
->alist
+ context
->count
;
686 strncpy(offset
, namesp
->attr_name
, namesp
->attr_namelen
);
687 offset
+= namesp
->attr_namelen
;
688 strncpy(offset
, name
, namelen
); /* real name */
691 context
->count
+= namesp
->attr_namelen
+ namelen
+ 1;
697 xfs_attr_kern_list_sizes(xfs_attr_list_context_t
*context
, attrnames_t
*namesp
,
698 char *name
, int namelen
,
699 int valuelen
, char *value
)
701 context
->count
+= namesp
->attr_namelen
+ namelen
+ 1;
706 * Generate a list of extended attribute names and optionally
707 * also value lengths. Positive return value follows the XFS
708 * convention of being an error, zero or negative return code
709 * is the length of the buffer returned (negated), indicating
718 attrlist_cursor_kern_t
*cursor
)
720 xfs_attr_list_context_t context
;
723 XFS_STATS_INC(xs_attr_list
);
726 * Validate the cursor.
728 if (cursor
->pad1
|| cursor
->pad2
)
729 return(XFS_ERROR(EINVAL
));
730 if ((cursor
->initted
== 0) &&
731 (cursor
->hashval
|| cursor
->blkno
|| cursor
->offset
))
732 return XFS_ERROR(EINVAL
);
735 * Check for a properly aligned buffer.
737 if (((long)buffer
) & (sizeof(int)-1))
738 return XFS_ERROR(EFAULT
);
739 if (flags
& ATTR_KERNOVAL
)
743 * Initialize the output buffer.
746 context
.cursor
= cursor
;
750 context
.flags
= flags
;
751 context
.seen_enough
= 0;
752 context
.alist
= (attrlist_t
*)buffer
;
753 context
.put_value
= 0;
755 if (flags
& ATTR_KERNAMELS
) {
756 context
.bufsize
= bufsize
;
757 context
.firstu
= context
.bufsize
;
758 if (flags
& ATTR_KERNOVAL
)
759 context
.put_listent
= xfs_attr_kern_list_sizes
;
761 context
.put_listent
= xfs_attr_kern_list
;
763 context
.bufsize
= (bufsize
& ~(sizeof(int)-1)); /* align */
764 context
.firstu
= context
.bufsize
;
765 context
.alist
->al_count
= 0;
766 context
.alist
->al_more
= 0;
767 context
.alist
->al_offset
[0] = context
.bufsize
;
768 context
.put_listent
= xfs_attr_put_listent
;
771 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
774 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
775 xfs_attr_trace_l_c("syscall start", &context
);
777 error
= xfs_attr_list_int(&context
);
779 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
780 xfs_attr_trace_l_c("syscall end", &context
);
782 if (context
.flags
& (ATTR_KERNOVAL
|ATTR_KERNAMELS
)) {
783 /* must return negated buffer size or the error */
784 if (context
.count
< 0)
785 error
= XFS_ERROR(ERANGE
);
787 error
= -context
.count
;
795 xfs_attr_inactive(xfs_inode_t
*dp
)
802 ASSERT(! XFS_NOT_DQATTACHED(mp
, dp
));
804 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
805 if ((XFS_IFORK_Q(dp
) == 0) ||
806 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
807 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
808 dp
->i_d
.di_anextents
== 0)) {
809 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
812 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
815 * Start our first transaction of the day.
817 * All future transactions during this code must be "chained" off
818 * this one via the trans_dup() call. All transactions will contain
819 * the inode, and the inode will always be marked with trans_ihold().
820 * Since the inode will be locked in all transactions, we must log
821 * the inode in every transaction to let it float upward through
824 trans
= xfs_trans_alloc(mp
, XFS_TRANS_ATTRINVAL
);
825 if ((error
= xfs_trans_reserve(trans
, 0, XFS_ATTRINVAL_LOG_RES(mp
), 0,
826 XFS_TRANS_PERM_LOG_RES
,
827 XFS_ATTRINVAL_LOG_COUNT
))) {
828 xfs_trans_cancel(trans
, 0);
831 xfs_ilock(dp
, XFS_ILOCK_EXCL
);
834 * No need to make quota reservations here. We expect to release some
835 * blocks, not allocate, in the common case.
837 xfs_trans_ijoin(trans
, dp
, XFS_ILOCK_EXCL
);
838 xfs_trans_ihold(trans
, dp
);
841 * Decide on what work routines to call based on the inode size.
843 if ((XFS_IFORK_Q(dp
) == 0) ||
844 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
845 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
846 dp
->i_d
.di_anextents
== 0)) {
850 error
= xfs_attr_root_inactive(&trans
, dp
);
854 * signal synchronous inactive transactions unless this
855 * is a synchronous mount filesystem in which case we
856 * know that we're here because we've been called out of
857 * xfs_inactive which means that the last reference is gone
858 * and the unlink transaction has already hit the disk so
859 * async inactive transactions are safe.
861 if ((error
= xfs_itruncate_finish(&trans
, dp
, 0LL, XFS_ATTR_FORK
,
862 (!(mp
->m_flags
& XFS_MOUNT_WSYNC
)
867 * Commit the last in the sequence of transactions.
869 xfs_trans_log_inode(trans
, dp
, XFS_ILOG_CORE
);
870 error
= xfs_trans_commit(trans
, XFS_TRANS_RELEASE_LOG_RES
);
871 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
876 xfs_trans_cancel(trans
, XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
877 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
883 /*========================================================================
884 * External routines when attribute list is inside the inode
885 *========================================================================*/
888 * Add a name to the shortform attribute list structure
889 * This is the external routine.
892 xfs_attr_shortform_addname(xfs_da_args_t
*args
)
894 int newsize
, forkoff
, retval
;
896 retval
= xfs_attr_shortform_lookup(args
);
897 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
899 } else if (retval
== EEXIST
) {
900 if (args
->flags
& ATTR_CREATE
)
902 retval
= xfs_attr_shortform_remove(args
);
906 if (args
->namelen
>= XFS_ATTR_SF_ENTSIZE_MAX
||
907 args
->valuelen
>= XFS_ATTR_SF_ENTSIZE_MAX
)
908 return(XFS_ERROR(ENOSPC
));
910 newsize
= XFS_ATTR_SF_TOTSIZE(args
->dp
);
911 newsize
+= XFS_ATTR_SF_ENTSIZE_BYNAME(args
->namelen
, args
->valuelen
);
913 forkoff
= xfs_attr_shortform_bytesfit(args
->dp
, newsize
);
915 return(XFS_ERROR(ENOSPC
));
917 xfs_attr_shortform_add(args
, forkoff
);
922 /*========================================================================
923 * External routines when attribute list is one block
924 *========================================================================*/
927 * Add a name to the leaf attribute list structure
929 * This leaf block cannot have a "remote" value, we only call this routine
930 * if bmap_one_block() says there is only one block (ie: no remote blks).
933 xfs_attr_leaf_addname(xfs_da_args_t
*args
)
937 int retval
, error
, committed
, forkoff
;
940 * Read the (only) block in the attribute list in.
944 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
951 * Look up the given attribute in the leaf block. Figure out if
952 * the given flags produce an error or call for an atomic rename.
954 retval
= xfs_attr_leaf_lookup_int(bp
, args
);
955 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
956 xfs_da_brelse(args
->trans
, bp
);
958 } else if (retval
== EEXIST
) {
959 if (args
->flags
& ATTR_CREATE
) { /* pure create op */
960 xfs_da_brelse(args
->trans
, bp
);
963 args
->rename
= 1; /* an atomic rename */
964 args
->blkno2
= args
->blkno
; /* set 2nd entry info*/
965 args
->index2
= args
->index
;
966 args
->rmtblkno2
= args
->rmtblkno
;
967 args
->rmtblkcnt2
= args
->rmtblkcnt
;
971 * Add the attribute to the leaf block, transitioning to a Btree
974 retval
= xfs_attr_leaf_add(bp
, args
);
976 if (retval
== ENOSPC
) {
978 * Promote the attribute list to the Btree format, then
979 * Commit that transaction so that the node_addname() call
980 * can manage its own transactions.
982 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
983 error
= xfs_attr_leaf_to_node(args
);
985 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
991 xfs_bmap_cancel(args
->flist
);
996 * bmap_finish() may have committed the last trans and started
997 * a new one. We need the inode to be in all transactions.
1000 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1001 xfs_trans_ihold(args
->trans
, dp
);
1005 * Commit the current trans (including the inode) and start
1008 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1012 * Fob the whole rest of the problem off on the Btree code.
1014 error
= xfs_attr_node_addname(args
);
1019 * Commit the transaction that added the attr name so that
1020 * later routines can manage their own transactions.
1022 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1026 * If there was an out-of-line value, allocate the blocks we
1027 * identified for its storage and copy the value. This is done
1028 * after we create the attribute so that we don't overflow the
1029 * maximum size of a transaction and/or hit a deadlock.
1031 if (args
->rmtblkno
> 0) {
1032 error
= xfs_attr_rmtval_set(args
);
1038 * If this is an atomic rename operation, we must "flip" the
1039 * incomplete flags on the "new" and "old" attribute/value pairs
1040 * so that one disappears and one appears atomically. Then we
1041 * must remove the "old" attribute/value pair.
1045 * In a separate transaction, set the incomplete flag on the
1046 * "old" attr and clear the incomplete flag on the "new" attr.
1048 error
= xfs_attr_leaf_flipflags(args
);
1053 * Dismantle the "old" attribute/value pair by removing
1054 * a "remote" value (if it exists).
1056 args
->index
= args
->index2
;
1057 args
->blkno
= args
->blkno2
;
1058 args
->rmtblkno
= args
->rmtblkno2
;
1059 args
->rmtblkcnt
= args
->rmtblkcnt2
;
1060 if (args
->rmtblkno
) {
1061 error
= xfs_attr_rmtval_remove(args
);
1067 * Read in the block containing the "old" attr, then
1068 * remove the "old" attr from that block (neat, huh!)
1070 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1,
1071 &bp
, XFS_ATTR_FORK
);
1075 (void)xfs_attr_leaf_remove(bp
, args
);
1078 * If the result is small enough, shrink it all into the inode.
1080 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1081 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1082 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1083 /* bp is gone due to xfs_da_shrink_inode */
1085 error
= xfs_bmap_finish(&args
->trans
,
1092 xfs_bmap_cancel(args
->flist
);
1097 * bmap_finish() may have committed the last trans
1098 * and started a new one. We need the inode to be
1099 * in all transactions.
1102 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1103 xfs_trans_ihold(args
->trans
, dp
);
1106 xfs_da_buf_done(bp
);
1109 * Commit the remove and start the next trans in series.
1111 error
= xfs_attr_rolltrans(&args
->trans
, dp
);
1113 } else if (args
->rmtblkno
> 0) {
1115 * Added a "remote" value, just clear the incomplete flag.
1117 error
= xfs_attr_leaf_clearflag(args
);
1123 * Remove a name from the leaf attribute list structure
1125 * This leaf block cannot have a "remote" value, we only call this routine
1126 * if bmap_one_block() says there is only one block (ie: no remote blks).
1129 xfs_attr_leaf_removename(xfs_da_args_t
*args
)
1133 int error
, committed
, forkoff
;
1136 * Remove the attribute.
1140 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
1147 error
= xfs_attr_leaf_lookup_int(bp
, args
);
1148 if (error
== ENOATTR
) {
1149 xfs_da_brelse(args
->trans
, bp
);
1153 (void)xfs_attr_leaf_remove(bp
, args
);
1156 * If the result is small enough, shrink it all into the inode.
1158 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1159 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1160 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1161 /* bp is gone due to xfs_da_shrink_inode */
1163 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1169 xfs_bmap_cancel(args
->flist
);
1174 * bmap_finish() may have committed the last trans and started
1175 * a new one. We need the inode to be in all transactions.
1178 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1179 xfs_trans_ihold(args
->trans
, dp
);
1182 xfs_da_buf_done(bp
);
1187 * Look up a name in a leaf attribute list structure.
1189 * This leaf block cannot have a "remote" value, we only call this routine
1190 * if bmap_one_block() says there is only one block (ie: no remote blks).
1193 xfs_attr_leaf_get(xfs_da_args_t
*args
)
1199 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
1205 error
= xfs_attr_leaf_lookup_int(bp
, args
);
1206 if (error
!= EEXIST
) {
1207 xfs_da_brelse(args
->trans
, bp
);
1210 error
= xfs_attr_leaf_getvalue(bp
, args
);
1211 xfs_da_brelse(args
->trans
, bp
);
1212 if (!error
&& (args
->rmtblkno
> 0) && !(args
->flags
& ATTR_KERNOVAL
)) {
1213 error
= xfs_attr_rmtval_get(args
);
1219 * Copy out attribute entries for attr_list(), for leaf attribute lists.
1222 xfs_attr_leaf_list(xfs_attr_list_context_t
*context
)
1224 xfs_attr_leafblock_t
*leaf
;
1228 context
->cursor
->blkno
= 0;
1229 error
= xfs_da_read_buf(NULL
, context
->dp
, 0, -1, &bp
, XFS_ATTR_FORK
);
1231 return XFS_ERROR(error
);
1234 if (unlikely(be16_to_cpu(leaf
->hdr
.info
.magic
) != XFS_ATTR_LEAF_MAGIC
)) {
1235 XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW
,
1236 context
->dp
->i_mount
, leaf
);
1237 xfs_da_brelse(NULL
, bp
);
1238 return XFS_ERROR(EFSCORRUPTED
);
1241 error
= xfs_attr_leaf_list_int(bp
, context
);
1242 xfs_da_brelse(NULL
, bp
);
1243 return XFS_ERROR(error
);
1247 /*========================================================================
1248 * External routines when attribute list size > XFS_LBSIZE(mp).
1249 *========================================================================*/
1252 * Add a name to a Btree-format attribute list.
1254 * This will involve walking down the Btree, and may involve splitting
1255 * leaf nodes and even splitting intermediate nodes up to and including
1256 * the root node (a special case of an intermediate node).
1258 * "Remote" attribute values confuse the issue and atomic rename operations
1259 * add a whole extra layer of confusion on top of that.
1262 xfs_attr_node_addname(xfs_da_args_t
*args
)
1264 xfs_da_state_t
*state
;
1265 xfs_da_state_blk_t
*blk
;
1268 int committed
, retval
, error
;
1271 * Fill in bucket of arguments/results/context to carry around.
1276 state
= xfs_da_state_alloc();
1279 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1280 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1283 * Search to see if name already exists, and get back a pointer
1284 * to where it should go.
1286 error
= xfs_da_node_lookup_int(state
, &retval
);
1289 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1290 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1291 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
1293 } else if (retval
== EEXIST
) {
1294 if (args
->flags
& ATTR_CREATE
)
1296 args
->rename
= 1; /* atomic rename op */
1297 args
->blkno2
= args
->blkno
; /* set 2nd entry info*/
1298 args
->index2
= args
->index
;
1299 args
->rmtblkno2
= args
->rmtblkno
;
1300 args
->rmtblkcnt2
= args
->rmtblkcnt
;
1302 args
->rmtblkcnt
= 0;
1305 retval
= xfs_attr_leaf_add(blk
->bp
, state
->args
);
1306 if (retval
== ENOSPC
) {
1307 if (state
->path
.active
== 1) {
1309 * Its really a single leaf node, but it had
1310 * out-of-line values so it looked like it *might*
1311 * have been a b-tree.
1313 xfs_da_state_free(state
);
1314 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1315 error
= xfs_attr_leaf_to_node(args
);
1317 error
= xfs_bmap_finish(&args
->trans
,
1324 xfs_bmap_cancel(args
->flist
);
1329 * bmap_finish() may have committed the last trans
1330 * and started a new one. We need the inode to be
1331 * in all transactions.
1334 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1335 xfs_trans_ihold(args
->trans
, dp
);
1339 * Commit the node conversion and start the next
1340 * trans in the chain.
1342 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1349 * Split as many Btree elements as required.
1350 * This code tracks the new and old attr's location
1351 * in the index/blkno/rmtblkno/rmtblkcnt fields and
1352 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
1354 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1355 error
= xfs_da_split(state
);
1357 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1363 xfs_bmap_cancel(args
->flist
);
1368 * bmap_finish() may have committed the last trans and started
1369 * a new one. We need the inode to be in all transactions.
1372 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1373 xfs_trans_ihold(args
->trans
, dp
);
1377 * Addition succeeded, update Btree hashvals.
1379 xfs_da_fixhashpath(state
, &state
->path
);
1383 * Kill the state structure, we're done with it and need to
1384 * allow the buffers to come back later.
1386 xfs_da_state_free(state
);
1390 * Commit the leaf addition or btree split and start the next
1391 * trans in the chain.
1393 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1397 * If there was an out-of-line value, allocate the blocks we
1398 * identified for its storage and copy the value. This is done
1399 * after we create the attribute so that we don't overflow the
1400 * maximum size of a transaction and/or hit a deadlock.
1402 if (args
->rmtblkno
> 0) {
1403 error
= xfs_attr_rmtval_set(args
);
1409 * If this is an atomic rename operation, we must "flip" the
1410 * incomplete flags on the "new" and "old" attribute/value pairs
1411 * so that one disappears and one appears atomically. Then we
1412 * must remove the "old" attribute/value pair.
1416 * In a separate transaction, set the incomplete flag on the
1417 * "old" attr and clear the incomplete flag on the "new" attr.
1419 error
= xfs_attr_leaf_flipflags(args
);
1424 * Dismantle the "old" attribute/value pair by removing
1425 * a "remote" value (if it exists).
1427 args
->index
= args
->index2
;
1428 args
->blkno
= args
->blkno2
;
1429 args
->rmtblkno
= args
->rmtblkno2
;
1430 args
->rmtblkcnt
= args
->rmtblkcnt2
;
1431 if (args
->rmtblkno
) {
1432 error
= xfs_attr_rmtval_remove(args
);
1438 * Re-find the "old" attribute entry after any split ops.
1439 * The INCOMPLETE flag means that we will find the "old"
1440 * attr, not the "new" one.
1442 args
->flags
|= XFS_ATTR_INCOMPLETE
;
1443 state
= xfs_da_state_alloc();
1446 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1447 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1449 error
= xfs_da_node_lookup_int(state
, &retval
);
1454 * Remove the name and update the hashvals in the tree.
1456 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1457 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1458 error
= xfs_attr_leaf_remove(blk
->bp
, args
);
1459 xfs_da_fixhashpath(state
, &state
->path
);
1462 * Check to see if the tree needs to be collapsed.
1464 if (retval
&& (state
->path
.active
> 1)) {
1465 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1466 error
= xfs_da_join(state
);
1468 error
= xfs_bmap_finish(&args
->trans
,
1475 xfs_bmap_cancel(args
->flist
);
1480 * bmap_finish() may have committed the last trans
1481 * and started a new one. We need the inode to be
1482 * in all transactions.
1485 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1486 xfs_trans_ihold(args
->trans
, dp
);
1491 * Commit and start the next trans in the chain.
1493 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1496 } else if (args
->rmtblkno
> 0) {
1498 * Added a "remote" value, just clear the incomplete flag.
1500 error
= xfs_attr_leaf_clearflag(args
);
1508 xfs_da_state_free(state
);
1515 * Remove a name from a B-tree attribute list.
1517 * This will involve walking down the Btree, and may involve joining
1518 * leaf nodes and even joining intermediate nodes up to and including
1519 * the root node (a special case of an intermediate node).
1522 xfs_attr_node_removename(xfs_da_args_t
*args
)
1524 xfs_da_state_t
*state
;
1525 xfs_da_state_blk_t
*blk
;
1528 int retval
, error
, committed
, forkoff
;
1531 * Tie a string around our finger to remind us where we are.
1534 state
= xfs_da_state_alloc();
1536 state
->mp
= dp
->i_mount
;
1537 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1538 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1541 * Search to see if name exists, and get back a pointer to it.
1543 error
= xfs_da_node_lookup_int(state
, &retval
);
1544 if (error
|| (retval
!= EEXIST
)) {
1551 * If there is an out-of-line value, de-allocate the blocks.
1552 * This is done before we remove the attribute so that we don't
1553 * overflow the maximum size of a transaction and/or hit a deadlock.
1555 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1556 ASSERT(blk
->bp
!= NULL
);
1557 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1558 if (args
->rmtblkno
> 0) {
1560 * Fill in disk block numbers in the state structure
1561 * so that we can get the buffers back after we commit
1562 * several transactions in the following calls.
1564 error
= xfs_attr_fillstate(state
);
1569 * Mark the attribute as INCOMPLETE, then bunmapi() the
1572 error
= xfs_attr_leaf_setflag(args
);
1575 error
= xfs_attr_rmtval_remove(args
);
1580 * Refill the state structure with buffers, the prior calls
1581 * released our buffers.
1583 error
= xfs_attr_refillstate(state
);
1589 * Remove the name and update the hashvals in the tree.
1591 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1592 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1593 retval
= xfs_attr_leaf_remove(blk
->bp
, args
);
1594 xfs_da_fixhashpath(state
, &state
->path
);
1597 * Check to see if the tree needs to be collapsed.
1599 if (retval
&& (state
->path
.active
> 1)) {
1600 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1601 error
= xfs_da_join(state
);
1603 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1609 xfs_bmap_cancel(args
->flist
);
1614 * bmap_finish() may have committed the last trans and started
1615 * a new one. We need the inode to be in all transactions.
1618 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1619 xfs_trans_ihold(args
->trans
, dp
);
1623 * Commit the Btree join operation and start a new trans.
1625 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1630 * If the result is small enough, push it all into the inode.
1632 if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
1634 * Have to get rid of the copy of this dabuf in the state.
1636 ASSERT(state
->path
.active
== 1);
1637 ASSERT(state
->path
.blk
[0].bp
);
1638 xfs_da_buf_done(state
->path
.blk
[0].bp
);
1639 state
->path
.blk
[0].bp
= NULL
;
1641 error
= xfs_da_read_buf(args
->trans
, args
->dp
, 0, -1, &bp
,
1645 ASSERT(be16_to_cpu(((xfs_attr_leafblock_t
*)
1646 bp
->data
)->hdr
.info
.magic
)
1647 == XFS_ATTR_LEAF_MAGIC
);
1649 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1650 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1651 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1652 /* bp is gone due to xfs_da_shrink_inode */
1654 error
= xfs_bmap_finish(&args
->trans
,
1661 xfs_bmap_cancel(args
->flist
);
1666 * bmap_finish() may have committed the last trans
1667 * and started a new one. We need the inode to be
1668 * in all transactions.
1671 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1672 xfs_trans_ihold(args
->trans
, dp
);
1675 xfs_da_brelse(args
->trans
, bp
);
1680 xfs_da_state_free(state
);
1685 * Fill in the disk block numbers in the state structure for the buffers
1686 * that are attached to the state structure.
1687 * This is done so that we can quickly reattach ourselves to those buffers
1688 * after some set of transaction commits have released these buffers.
1691 xfs_attr_fillstate(xfs_da_state_t
*state
)
1693 xfs_da_state_path_t
*path
;
1694 xfs_da_state_blk_t
*blk
;
1698 * Roll down the "path" in the state structure, storing the on-disk
1699 * block number for those buffers in the "path".
1701 path
= &state
->path
;
1702 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1703 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1705 blk
->disk_blkno
= xfs_da_blkno(blk
->bp
);
1706 xfs_da_buf_done(blk
->bp
);
1709 blk
->disk_blkno
= 0;
1714 * Roll down the "altpath" in the state structure, storing the on-disk
1715 * block number for those buffers in the "altpath".
1717 path
= &state
->altpath
;
1718 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1719 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1721 blk
->disk_blkno
= xfs_da_blkno(blk
->bp
);
1722 xfs_da_buf_done(blk
->bp
);
1725 blk
->disk_blkno
= 0;
1733 * Reattach the buffers to the state structure based on the disk block
1734 * numbers stored in the state structure.
1735 * This is done after some set of transaction commits have released those
1736 * buffers from our grip.
1739 xfs_attr_refillstate(xfs_da_state_t
*state
)
1741 xfs_da_state_path_t
*path
;
1742 xfs_da_state_blk_t
*blk
;
1746 * Roll down the "path" in the state structure, storing the on-disk
1747 * block number for those buffers in the "path".
1749 path
= &state
->path
;
1750 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1751 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1752 if (blk
->disk_blkno
) {
1753 error
= xfs_da_read_buf(state
->args
->trans
,
1755 blk
->blkno
, blk
->disk_blkno
,
1756 &blk
->bp
, XFS_ATTR_FORK
);
1765 * Roll down the "altpath" in the state structure, storing the on-disk
1766 * block number for those buffers in the "altpath".
1768 path
= &state
->altpath
;
1769 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1770 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1771 if (blk
->disk_blkno
) {
1772 error
= xfs_da_read_buf(state
->args
->trans
,
1774 blk
->blkno
, blk
->disk_blkno
,
1775 &blk
->bp
, XFS_ATTR_FORK
);
1787 * Look up a filename in a node attribute list.
1789 * This routine gets called for any attribute fork that has more than one
1790 * block, ie: both true Btree attr lists and for single-leaf-blocks with
1791 * "remote" values taking up more blocks.
1794 xfs_attr_node_get(xfs_da_args_t
*args
)
1796 xfs_da_state_t
*state
;
1797 xfs_da_state_blk_t
*blk
;
1801 state
= xfs_da_state_alloc();
1803 state
->mp
= args
->dp
->i_mount
;
1804 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1805 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1808 * Search to see if name exists, and get back a pointer to it.
1810 error
= xfs_da_node_lookup_int(state
, &retval
);
1813 } else if (retval
== EEXIST
) {
1814 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1815 ASSERT(blk
->bp
!= NULL
);
1816 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1819 * Get the value, local or "remote"
1821 retval
= xfs_attr_leaf_getvalue(blk
->bp
, args
);
1822 if (!retval
&& (args
->rmtblkno
> 0)
1823 && !(args
->flags
& ATTR_KERNOVAL
)) {
1824 retval
= xfs_attr_rmtval_get(args
);
1829 * If not in a transaction, we have to release all the buffers.
1831 for (i
= 0; i
< state
->path
.active
; i
++) {
1832 xfs_da_brelse(args
->trans
, state
->path
.blk
[i
].bp
);
1833 state
->path
.blk
[i
].bp
= NULL
;
1836 xfs_da_state_free(state
);
1840 STATIC
int /* error */
1841 xfs_attr_node_list(xfs_attr_list_context_t
*context
)
1843 attrlist_cursor_kern_t
*cursor
;
1844 xfs_attr_leafblock_t
*leaf
;
1845 xfs_da_intnode_t
*node
;
1846 xfs_da_node_entry_t
*btree
;
1850 cursor
= context
->cursor
;
1851 cursor
->initted
= 1;
1854 * Do all sorts of validation on the passed-in cursor structure.
1855 * If anything is amiss, ignore the cursor and look up the hashval
1856 * starting from the btree root.
1859 if (cursor
->blkno
> 0) {
1860 error
= xfs_da_read_buf(NULL
, context
->dp
, cursor
->blkno
, -1,
1861 &bp
, XFS_ATTR_FORK
);
1862 if ((error
!= 0) && (error
!= EFSCORRUPTED
))
1866 switch (be16_to_cpu(node
->hdr
.info
.magic
)) {
1867 case XFS_DA_NODE_MAGIC
:
1868 xfs_attr_trace_l_cn("wrong blk", context
, node
);
1869 xfs_da_brelse(NULL
, bp
);
1872 case XFS_ATTR_LEAF_MAGIC
:
1874 if (cursor
->hashval
> be32_to_cpu(leaf
->entries
[
1875 be16_to_cpu(leaf
->hdr
.count
)-1].hashval
)) {
1876 xfs_attr_trace_l_cl("wrong blk",
1878 xfs_da_brelse(NULL
, bp
);
1880 } else if (cursor
->hashval
<=
1881 be32_to_cpu(leaf
->entries
[0].hashval
)) {
1882 xfs_attr_trace_l_cl("maybe wrong blk",
1884 xfs_da_brelse(NULL
, bp
);
1889 xfs_attr_trace_l_c("wrong blk - ??", context
);
1890 xfs_da_brelse(NULL
, bp
);
1897 * We did not find what we expected given the cursor's contents,
1898 * so we start from the top and work down based on the hash value.
1899 * Note that start of node block is same as start of leaf block.
1904 error
= xfs_da_read_buf(NULL
, context
->dp
,
1905 cursor
->blkno
, -1, &bp
,
1909 if (unlikely(bp
== NULL
)) {
1910 XFS_ERROR_REPORT("xfs_attr_node_list(2)",
1912 context
->dp
->i_mount
);
1913 return(XFS_ERROR(EFSCORRUPTED
));
1916 if (be16_to_cpu(node
->hdr
.info
.magic
)
1917 == XFS_ATTR_LEAF_MAGIC
)
1919 if (unlikely(be16_to_cpu(node
->hdr
.info
.magic
)
1920 != XFS_DA_NODE_MAGIC
)) {
1921 XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
1923 context
->dp
->i_mount
,
1925 xfs_da_brelse(NULL
, bp
);
1926 return(XFS_ERROR(EFSCORRUPTED
));
1928 btree
= node
->btree
;
1929 for (i
= 0; i
< be16_to_cpu(node
->hdr
.count
);
1932 <= be32_to_cpu(btree
->hashval
)) {
1933 cursor
->blkno
= be32_to_cpu(btree
->before
);
1934 xfs_attr_trace_l_cb("descending",
1939 if (i
== be16_to_cpu(node
->hdr
.count
)) {
1940 xfs_da_brelse(NULL
, bp
);
1943 xfs_da_brelse(NULL
, bp
);
1949 * Roll upward through the blocks, processing each leaf block in
1950 * order. As long as there is space in the result buffer, keep
1951 * adding the information.
1955 if (unlikely(be16_to_cpu(leaf
->hdr
.info
.magic
)
1956 != XFS_ATTR_LEAF_MAGIC
)) {
1957 XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
1959 context
->dp
->i_mount
, leaf
);
1960 xfs_da_brelse(NULL
, bp
);
1961 return(XFS_ERROR(EFSCORRUPTED
));
1963 error
= xfs_attr_leaf_list_int(bp
, context
);
1965 xfs_da_brelse(NULL
, bp
);
1968 if (context
->seen_enough
|| leaf
->hdr
.info
.forw
== 0)
1970 cursor
->blkno
= be32_to_cpu(leaf
->hdr
.info
.forw
);
1971 xfs_da_brelse(NULL
, bp
);
1972 error
= xfs_da_read_buf(NULL
, context
->dp
, cursor
->blkno
, -1,
1973 &bp
, XFS_ATTR_FORK
);
1976 if (unlikely((bp
== NULL
))) {
1977 XFS_ERROR_REPORT("xfs_attr_node_list(5)",
1979 context
->dp
->i_mount
);
1980 return(XFS_ERROR(EFSCORRUPTED
));
1983 xfs_da_brelse(NULL
, bp
);
1988 /*========================================================================
1989 * External routines for manipulating out-of-line attribute values.
1990 *========================================================================*/
1993 * Read the value associated with an attribute from the out-of-line buffer
1994 * that we stored it in.
1997 xfs_attr_rmtval_get(xfs_da_args_t
*args
)
1999 xfs_bmbt_irec_t map
[ATTR_RMTVALUE_MAPSIZE
];
2004 int nmap
, error
, tmp
, valuelen
, blkcnt
, i
;
2007 ASSERT(!(args
->flags
& ATTR_KERNOVAL
));
2009 mp
= args
->dp
->i_mount
;
2011 valuelen
= args
->valuelen
;
2012 lblkno
= args
->rmtblkno
;
2013 while (valuelen
> 0) {
2014 nmap
= ATTR_RMTVALUE_MAPSIZE
;
2015 error
= xfs_bmapi(args
->trans
, args
->dp
, (xfs_fileoff_t
)lblkno
,
2017 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2018 NULL
, 0, map
, &nmap
, NULL
, NULL
);
2023 for (i
= 0; (i
< nmap
) && (valuelen
> 0); i
++) {
2024 ASSERT((map
[i
].br_startblock
!= DELAYSTARTBLOCK
) &&
2025 (map
[i
].br_startblock
!= HOLESTARTBLOCK
));
2026 dblkno
= XFS_FSB_TO_DADDR(mp
, map
[i
].br_startblock
);
2027 blkcnt
= XFS_FSB_TO_BB(mp
, map
[i
].br_blockcount
);
2028 error
= xfs_read_buf(mp
, mp
->m_ddev_targp
, dblkno
,
2029 blkcnt
, XFS_BUF_LOCK
, &bp
);
2033 tmp
= (valuelen
< XFS_BUF_SIZE(bp
))
2034 ? valuelen
: XFS_BUF_SIZE(bp
);
2035 xfs_biomove(bp
, 0, tmp
, dst
, XFS_B_READ
);
2040 lblkno
+= map
[i
].br_blockcount
;
2043 ASSERT(valuelen
== 0);
2048 * Write the value associated with an attribute into the out-of-line buffer
2049 * that we have defined for it.
2052 xfs_attr_rmtval_set(xfs_da_args_t
*args
)
2055 xfs_fileoff_t lfileoff
;
2057 xfs_bmbt_irec_t map
;
2062 int blkcnt
, valuelen
, nmap
, error
, tmp
, committed
;
2069 * Find a "hole" in the attribute address space large enough for
2070 * us to drop the new attribute's value into.
2072 blkcnt
= XFS_B_TO_FSB(mp
, args
->valuelen
);
2074 error
= xfs_bmap_first_unused(args
->trans
, args
->dp
, blkcnt
, &lfileoff
,
2079 args
->rmtblkno
= lblkno
= (xfs_dablk_t
)lfileoff
;
2080 args
->rmtblkcnt
= blkcnt
;
2083 * Roll through the "value", allocating blocks on disk as required.
2085 while (blkcnt
> 0) {
2087 * Allocate a single extent, up to the size of the value.
2089 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2091 error
= xfs_bmapi(args
->trans
, dp
, (xfs_fileoff_t
)lblkno
,
2093 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
|
2095 args
->firstblock
, args
->total
, &map
, &nmap
,
2098 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
2104 xfs_bmap_cancel(args
->flist
);
2109 * bmap_finish() may have committed the last trans and started
2110 * a new one. We need the inode to be in all transactions.
2113 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
2114 xfs_trans_ihold(args
->trans
, dp
);
2118 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2119 (map
.br_startblock
!= HOLESTARTBLOCK
));
2120 lblkno
+= map
.br_blockcount
;
2121 blkcnt
-= map
.br_blockcount
;
2124 * Start the next trans in the chain.
2126 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
2131 * Roll through the "value", copying the attribute value to the
2132 * already-allocated blocks. Blocks are written synchronously
2133 * so that we can know they are all on disk before we turn off
2134 * the INCOMPLETE flag.
2136 lblkno
= args
->rmtblkno
;
2137 valuelen
= args
->valuelen
;
2138 while (valuelen
> 0) {
2140 * Try to remember where we decided to put the value.
2142 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2144 error
= xfs_bmapi(NULL
, dp
, (xfs_fileoff_t
)lblkno
,
2146 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2147 args
->firstblock
, 0, &map
, &nmap
,
2153 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2154 (map
.br_startblock
!= HOLESTARTBLOCK
));
2156 dblkno
= XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
2157 blkcnt
= XFS_FSB_TO_BB(mp
, map
.br_blockcount
);
2159 bp
= xfs_buf_get_flags(mp
->m_ddev_targp
, dblkno
,
2160 blkcnt
, XFS_BUF_LOCK
);
2162 ASSERT(!XFS_BUF_GETERROR(bp
));
2164 tmp
= (valuelen
< XFS_BUF_SIZE(bp
)) ? valuelen
:
2166 xfs_biomove(bp
, 0, tmp
, src
, XFS_B_WRITE
);
2167 if (tmp
< XFS_BUF_SIZE(bp
))
2168 xfs_biozero(bp
, tmp
, XFS_BUF_SIZE(bp
) - tmp
);
2169 if ((error
= xfs_bwrite(mp
, bp
))) {/* GROT: NOTE: synchronous write */
2175 lblkno
+= map
.br_blockcount
;
2177 ASSERT(valuelen
== 0);
2182 * Remove the value associated with an attribute by deleting the
2183 * out-of-line buffer that it is stored on.
2186 xfs_attr_rmtval_remove(xfs_da_args_t
*args
)
2189 xfs_bmbt_irec_t map
;
2193 int valuelen
, blkcnt
, nmap
, error
, done
, committed
;
2195 mp
= args
->dp
->i_mount
;
2198 * Roll through the "value", invalidating the attribute value's
2201 lblkno
= args
->rmtblkno
;
2202 valuelen
= args
->rmtblkcnt
;
2203 while (valuelen
> 0) {
2205 * Try to remember where we decided to put the value.
2207 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2209 error
= xfs_bmapi(NULL
, args
->dp
, (xfs_fileoff_t
)lblkno
,
2211 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2212 args
->firstblock
, 0, &map
, &nmap
,
2218 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2219 (map
.br_startblock
!= HOLESTARTBLOCK
));
2221 dblkno
= XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
2222 blkcnt
= XFS_FSB_TO_BB(mp
, map
.br_blockcount
);
2225 * If the "remote" value is in the cache, remove it.
2227 bp
= xfs_incore(mp
->m_ddev_targp
, dblkno
, blkcnt
,
2228 XFS_INCORE_TRYLOCK
);
2231 XFS_BUF_UNDELAYWRITE(bp
);
2236 valuelen
-= map
.br_blockcount
;
2238 lblkno
+= map
.br_blockcount
;
2242 * Keep de-allocating extents until the remote-value region is gone.
2244 lblkno
= args
->rmtblkno
;
2245 blkcnt
= args
->rmtblkcnt
;
2248 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2249 error
= xfs_bunmapi(args
->trans
, args
->dp
, lblkno
, blkcnt
,
2250 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2251 1, args
->firstblock
, args
->flist
,
2254 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
2260 xfs_bmap_cancel(args
->flist
);
2265 * bmap_finish() may have committed the last trans and started
2266 * a new one. We need the inode to be in all transactions.
2269 xfs_trans_ijoin(args
->trans
, args
->dp
, XFS_ILOCK_EXCL
);
2270 xfs_trans_ihold(args
->trans
, args
->dp
);
2274 * Close out trans and start the next one in the chain.
2276 if ((error
= xfs_attr_rolltrans(&args
->trans
, args
->dp
)))
2282 #if defined(XFS_ATTR_TRACE)
2284 * Add a trace buffer entry for an attr_list context structure.
2287 xfs_attr_trace_l_c(char *where
, struct xfs_attr_list_context
*context
)
2289 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_C
, where
,
2290 (__psunsigned_t
)context
->dp
,
2291 (__psunsigned_t
)context
->cursor
->hashval
,
2292 (__psunsigned_t
)context
->cursor
->blkno
,
2293 (__psunsigned_t
)context
->cursor
->offset
,
2294 (__psunsigned_t
)context
->alist
,
2295 (__psunsigned_t
)context
->bufsize
,
2296 (__psunsigned_t
)context
->count
,
2297 (__psunsigned_t
)context
->firstu
,
2299 ((context
->count
> 0) &&
2300 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2301 ? (ATTR_ENTRY(context
->alist
,
2302 context
->count
-1)->a_valuelen
)
2304 (__psunsigned_t
)context
->dupcnt
,
2305 (__psunsigned_t
)context
->flags
,
2306 (__psunsigned_t
)NULL
,
2307 (__psunsigned_t
)NULL
,
2308 (__psunsigned_t
)NULL
);
2312 * Add a trace buffer entry for a context structure and a Btree node.
2315 xfs_attr_trace_l_cn(char *where
, struct xfs_attr_list_context
*context
,
2316 struct xfs_da_intnode
*node
)
2318 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CN
, where
,
2319 (__psunsigned_t
)context
->dp
,
2320 (__psunsigned_t
)context
->cursor
->hashval
,
2321 (__psunsigned_t
)context
->cursor
->blkno
,
2322 (__psunsigned_t
)context
->cursor
->offset
,
2323 (__psunsigned_t
)context
->alist
,
2324 (__psunsigned_t
)context
->bufsize
,
2325 (__psunsigned_t
)context
->count
,
2326 (__psunsigned_t
)context
->firstu
,
2328 ((context
->count
> 0) &&
2329 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2330 ? (ATTR_ENTRY(context
->alist
,
2331 context
->count
-1)->a_valuelen
)
2333 (__psunsigned_t
)context
->dupcnt
,
2334 (__psunsigned_t
)context
->flags
,
2335 (__psunsigned_t
)be16_to_cpu(node
->hdr
.count
),
2336 (__psunsigned_t
)be32_to_cpu(node
->btree
[0].hashval
),
2337 (__psunsigned_t
)be32_to_cpu(node
->btree
[
2338 be16_to_cpu(node
->hdr
.count
)-1].hashval
));
2342 * Add a trace buffer entry for a context structure and a Btree element.
2345 xfs_attr_trace_l_cb(char *where
, struct xfs_attr_list_context
*context
,
2346 struct xfs_da_node_entry
*btree
)
2348 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CB
, where
,
2349 (__psunsigned_t
)context
->dp
,
2350 (__psunsigned_t
)context
->cursor
->hashval
,
2351 (__psunsigned_t
)context
->cursor
->blkno
,
2352 (__psunsigned_t
)context
->cursor
->offset
,
2353 (__psunsigned_t
)context
->alist
,
2354 (__psunsigned_t
)context
->bufsize
,
2355 (__psunsigned_t
)context
->count
,
2356 (__psunsigned_t
)context
->firstu
,
2358 ((context
->count
> 0) &&
2359 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2360 ? (ATTR_ENTRY(context
->alist
,
2361 context
->count
-1)->a_valuelen
)
2363 (__psunsigned_t
)context
->dupcnt
,
2364 (__psunsigned_t
)context
->flags
,
2365 (__psunsigned_t
)be32_to_cpu(btree
->hashval
),
2366 (__psunsigned_t
)be32_to_cpu(btree
->before
),
2367 (__psunsigned_t
)NULL
);
2371 * Add a trace buffer entry for a context structure and a leaf block.
2374 xfs_attr_trace_l_cl(char *where
, struct xfs_attr_list_context
*context
,
2375 struct xfs_attr_leafblock
*leaf
)
2377 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CL
, where
,
2378 (__psunsigned_t
)context
->dp
,
2379 (__psunsigned_t
)context
->cursor
->hashval
,
2380 (__psunsigned_t
)context
->cursor
->blkno
,
2381 (__psunsigned_t
)context
->cursor
->offset
,
2382 (__psunsigned_t
)context
->alist
,
2383 (__psunsigned_t
)context
->bufsize
,
2384 (__psunsigned_t
)context
->count
,
2385 (__psunsigned_t
)context
->firstu
,
2387 ((context
->count
> 0) &&
2388 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2389 ? (ATTR_ENTRY(context
->alist
,
2390 context
->count
-1)->a_valuelen
)
2392 (__psunsigned_t
)context
->dupcnt
,
2393 (__psunsigned_t
)context
->flags
,
2394 (__psunsigned_t
)be16_to_cpu(leaf
->hdr
.count
),
2395 (__psunsigned_t
)be32_to_cpu(leaf
->entries
[0].hashval
),
2396 (__psunsigned_t
)be32_to_cpu(leaf
->entries
[
2397 be16_to_cpu(leaf
->hdr
.count
)-1].hashval
));
2401 * Add a trace buffer entry for the arguments given to the routine,
2405 xfs_attr_trace_enter(int type
, char *where
,
2406 __psunsigned_t a2
, __psunsigned_t a3
,
2407 __psunsigned_t a4
, __psunsigned_t a5
,
2408 __psunsigned_t a6
, __psunsigned_t a7
,
2409 __psunsigned_t a8
, __psunsigned_t a9
,
2410 __psunsigned_t a10
, __psunsigned_t a11
,
2411 __psunsigned_t a12
, __psunsigned_t a13
,
2412 __psunsigned_t a14
, __psunsigned_t a15
)
2414 ASSERT(xfs_attr_trace_buf
);
2415 ktrace_enter(xfs_attr_trace_buf
, (void *)((__psunsigned_t
)type
),
2417 (void *)a2
, (void *)a3
, (void *)a4
,
2418 (void *)a5
, (void *)a6
, (void *)a7
,
2419 (void *)a8
, (void *)a9
, (void *)a10
,
2420 (void *)a11
, (void *)a12
, (void *)a13
,
2421 (void *)a14
, (void *)a15
);
2423 #endif /* XFS_ATTR_TRACE */
2426 /*========================================================================
2427 * System (pseudo) namespace attribute interface routines.
2428 *========================================================================*/
2431 posix_acl_access_set(
2432 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2434 return xfs_acl_vset(vp
, data
, size
, _ACL_TYPE_ACCESS
);
2438 posix_acl_access_remove(
2439 bhv_vnode_t
*vp
, char *name
, int xflags
)
2441 return xfs_acl_vremove(vp
, _ACL_TYPE_ACCESS
);
2445 posix_acl_access_get(
2446 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2448 return xfs_acl_vget(vp
, data
, size
, _ACL_TYPE_ACCESS
);
2452 posix_acl_access_exists(
2455 return xfs_acl_vhasacl_access(vp
);
2459 posix_acl_default_set(
2460 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2462 return xfs_acl_vset(vp
, data
, size
, _ACL_TYPE_DEFAULT
);
2466 posix_acl_default_get(
2467 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2469 return xfs_acl_vget(vp
, data
, size
, _ACL_TYPE_DEFAULT
);
2473 posix_acl_default_remove(
2474 bhv_vnode_t
*vp
, char *name
, int xflags
)
2476 return xfs_acl_vremove(vp
, _ACL_TYPE_DEFAULT
);
2480 posix_acl_default_exists(
2483 return xfs_acl_vhasacl_default(vp
);
2486 static struct attrnames posix_acl_access
= {
2487 .attr_name
= "posix_acl_access",
2488 .attr_namelen
= sizeof("posix_acl_access") - 1,
2489 .attr_get
= posix_acl_access_get
,
2490 .attr_set
= posix_acl_access_set
,
2491 .attr_remove
= posix_acl_access_remove
,
2492 .attr_exists
= posix_acl_access_exists
,
2495 static struct attrnames posix_acl_default
= {
2496 .attr_name
= "posix_acl_default",
2497 .attr_namelen
= sizeof("posix_acl_default") - 1,
2498 .attr_get
= posix_acl_default_get
,
2499 .attr_set
= posix_acl_default_set
,
2500 .attr_remove
= posix_acl_default_remove
,
2501 .attr_exists
= posix_acl_default_exists
,
2504 static struct attrnames
*attr_system_names
[] =
2505 { &posix_acl_access
, &posix_acl_default
};
2508 /*========================================================================
2509 * Namespace-prefix-style attribute name interface routines.
2510 *========================================================================*/
2514 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2516 return -xfs_attr_set(xfs_vtoi(vp
), name
, data
, size
, xflags
);
2521 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2523 int error
, asize
= size
;
2525 error
= xfs_attr_get(xfs_vtoi(vp
), name
, data
,
2526 &asize
, xflags
, NULL
);
2533 attr_generic_remove(
2534 bhv_vnode_t
*vp
, char *name
, int xflags
)
2536 return -xfs_attr_remove(xfs_vtoi(vp
), name
, xflags
);
2540 attr_generic_listadd(
2541 attrnames_t
*prefix
,
2542 attrnames_t
*namesp
,
2547 char *p
= data
+ *result
;
2549 *result
+= prefix
->attr_namelen
;
2550 *result
+= namesp
->attr_namelen
+ 1;
2555 strcpy(p
, prefix
->attr_name
);
2556 p
+= prefix
->attr_namelen
;
2557 strcpy(p
, namesp
->attr_name
);
2558 p
+= namesp
->attr_namelen
+ 1;
2569 attrnames_t
*namesp
;
2572 for (i
= 0; i
< ATTR_SYSCOUNT
; i
++) {
2573 namesp
= attr_system_names
[i
];
2574 if (!namesp
->attr_exists
|| !namesp
->attr_exists(vp
))
2576 error
= attr_generic_listadd(&attr_system
, namesp
,
2577 data
, size
, result
);
2586 bhv_vnode_t
*vp
, void *data
, size_t size
, int xflags
, ssize_t
*result
)
2588 attrlist_cursor_kern_t cursor
= { 0 };
2591 error
= xfs_attr_list(xfs_vtoi(vp
), data
, size
, xflags
, &cursor
);
2595 return attr_system_list(vp
, data
, size
, result
);
2599 attr_lookup_namespace(
2601 struct attrnames
**names
,
2606 for (i
= 0; i
< nnames
; i
++)
2607 if (!strncmp(name
, names
[i
]->attr_name
, names
[i
]->attr_namelen
))
2613 * Some checks to prevent people abusing EAs to get over quota:
2614 * - Don't allow modifying user EAs on devices/symlinks;
2615 * - Don't allow modifying user EAs if sticky bit set;
2622 struct inode
*inode
= vn_to_inode(vp
);
2624 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
2626 if (!S_ISREG(inode
->i_mode
) && !S_ISDIR(inode
->i_mode
) &&
2627 !capable(CAP_SYS_ADMIN
))
2629 if (S_ISDIR(inode
->i_mode
) && (inode
->i_mode
& S_ISVTX
) &&
2630 (current_fsuid(cred
) != inode
->i_uid
) && !capable(CAP_FOWNER
))
2636 attr_trusted_capable(
2640 struct inode
*inode
= vn_to_inode(vp
);
2642 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
2644 if (!capable(CAP_SYS_ADMIN
))
2650 attr_secure_capable(
2654 return -ENOSECURITY
;
2659 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2661 attrnames_t
*namesp
;
2664 if (xflags
& ATTR_CREATE
)
2667 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2670 error
= namesp
->attr_set(vp
, name
, data
, size
, xflags
);
2672 error
= vn_revalidate(vp
);
2678 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2680 attrnames_t
*namesp
;
2682 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2685 return namesp
->attr_get(vp
, name
, data
, size
, xflags
);
2690 bhv_vnode_t
*vp
, char *name
, int xflags
)
2692 attrnames_t
*namesp
;
2694 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2697 return namesp
->attr_remove(vp
, name
, xflags
);
2700 struct attrnames attr_system
= {
2701 .attr_name
= "system.",
2702 .attr_namelen
= sizeof("system.") - 1,
2703 .attr_flag
= ATTR_SYSTEM
,
2704 .attr_get
= attr_system_get
,
2705 .attr_set
= attr_system_set
,
2706 .attr_remove
= attr_system_remove
,
2707 .attr_capable
= (attrcapable_t
)fs_noerr
,
2710 struct attrnames attr_trusted
= {
2711 .attr_name
= "trusted.",
2712 .attr_namelen
= sizeof("trusted.") - 1,
2713 .attr_flag
= ATTR_ROOT
,
2714 .attr_get
= attr_generic_get
,
2715 .attr_set
= attr_generic_set
,
2716 .attr_remove
= attr_generic_remove
,
2717 .attr_capable
= attr_trusted_capable
,
2720 struct attrnames attr_secure
= {
2721 .attr_name
= "security.",
2722 .attr_namelen
= sizeof("security.") - 1,
2723 .attr_flag
= ATTR_SECURE
,
2724 .attr_get
= attr_generic_get
,
2725 .attr_set
= attr_generic_set
,
2726 .attr_remove
= attr_generic_remove
,
2727 .attr_capable
= attr_secure_capable
,
2730 struct attrnames attr_user
= {
2731 .attr_name
= "user.",
2732 .attr_namelen
= sizeof("user.") - 1,
2733 .attr_get
= attr_generic_get
,
2734 .attr_set
= attr_generic_set
,
2735 .attr_remove
= attr_generic_remove
,
2736 .attr_capable
= attr_user_capable
,
2739 struct attrnames
*attr_namespaces
[] =
2740 { &attr_system
, &attr_trusted
, &attr_secure
, &attr_user
};