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 xfs_attr_name_to_xname(
106 struct xfs_name
*xname
,
112 xname
->len
= strlen(aname
);
113 if (xname
->len
>= MAXNAMELEN
)
114 return EFAULT
; /* match IRIX behaviour */
119 /*========================================================================
120 * Overall external interface routines.
121 *========================================================================*/
124 xfs_attr_fetch(xfs_inode_t
*ip
, struct xfs_name
*name
,
125 char *value
, int *valuelenp
, int flags
)
130 if ((XFS_IFORK_Q(ip
) == 0) ||
131 (ip
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
132 ip
->i_d
.di_anextents
== 0))
136 * Fill in the arg structure for this request.
138 memset((char *)&args
, 0, sizeof(args
));
139 args
.name
= name
->name
;
140 args
.namelen
= name
->len
;
142 args
.valuelen
= *valuelenp
;
144 args
.hashval
= xfs_da_hashname(args
.name
, args
.namelen
);
146 args
.whichfork
= XFS_ATTR_FORK
;
149 * Decide on what work routines to call based on the inode size.
151 if (XFS_IFORK_Q(ip
) == 0 ||
152 (ip
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
153 ip
->i_d
.di_anextents
== 0)) {
154 error
= XFS_ERROR(ENOATTR
);
155 } else if (ip
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) {
156 error
= xfs_attr_shortform_getvalue(&args
);
157 } else if (xfs_bmap_one_block(ip
, XFS_ATTR_FORK
)) {
158 error
= xfs_attr_leaf_get(&args
);
160 error
= xfs_attr_node_get(&args
);
164 * Return the number of bytes in the value to the caller.
166 *valuelenp
= args
.valuelen
;
182 struct xfs_name xname
;
184 XFS_STATS_INC(xs_attr_get
);
186 if (XFS_FORCED_SHUTDOWN(ip
->i_mount
))
189 error
= xfs_attr_name_to_xname(&xname
, name
);
193 xfs_ilock(ip
, XFS_ILOCK_SHARED
);
194 error
= xfs_attr_fetch(ip
, &xname
, value
, valuelenp
, flags
);
195 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
200 xfs_attr_set_int(xfs_inode_t
*dp
, struct xfs_name
*name
,
201 char *value
, int valuelen
, int flags
)
204 xfs_fsblock_t firstblock
;
205 xfs_bmap_free_t flist
;
206 int error
, err2
, committed
;
209 xfs_mount_t
*mp
= dp
->i_mount
;
210 int rsvd
= (flags
& ATTR_ROOT
) != 0;
213 * Attach the dquots to the inode.
215 if ((error
= XFS_QM_DQATTACH(mp
, dp
, 0)))
219 * If the inode doesn't have an attribute fork, add one.
220 * (inode must not be locked when we call this routine)
222 if (XFS_IFORK_Q(dp
) == 0) {
223 int sf_size
= sizeof(xfs_attr_sf_hdr_t
) +
224 XFS_ATTR_SF_ENTSIZE_BYNAME(name
->len
, valuelen
);
226 if ((error
= xfs_bmap_add_attrfork(dp
, sf_size
, rsvd
)))
231 * Fill in the arg structure for this request.
233 memset((char *)&args
, 0, sizeof(args
));
234 args
.name
= name
->name
;
235 args
.namelen
= name
->len
;
237 args
.valuelen
= valuelen
;
239 args
.hashval
= xfs_da_hashname(args
.name
, args
.namelen
);
241 args
.firstblock
= &firstblock
;
243 args
.whichfork
= XFS_ATTR_FORK
;
248 * Determine space new attribute will use, and if it would be
249 * "local" or "remote" (note: local != inline).
251 size
= xfs_attr_leaf_newentsize(name
->len
, valuelen
,
252 mp
->m_sb
.sb_blocksize
, &local
);
254 nblks
= XFS_DAENTER_SPACE_RES(mp
, XFS_ATTR_FORK
);
256 if (size
> (mp
->m_sb
.sb_blocksize
>> 1)) {
257 /* Double split possible */
261 uint dblocks
= XFS_B_TO_FSB(mp
, valuelen
);
262 /* Out of line attribute, cannot double split, but make
263 * room for the attribute value itself.
266 nblks
+= XFS_NEXTENTADD_SPACE_RES(mp
, dblocks
, XFS_ATTR_FORK
);
269 /* Size is now blocks for attribute data */
273 * Start our first transaction of the day.
275 * All future transactions during this code must be "chained" off
276 * this one via the trans_dup() call. All transactions will contain
277 * the inode, and the inode will always be marked with trans_ihold().
278 * Since the inode will be locked in all transactions, we must log
279 * the inode in every transaction to let it float upward through
282 args
.trans
= xfs_trans_alloc(mp
, XFS_TRANS_ATTR_SET
);
285 * Root fork attributes can use reserved data blocks for this
286 * operation if necessary
290 args
.trans
->t_flags
|= XFS_TRANS_RESERVE
;
292 if ((error
= xfs_trans_reserve(args
.trans
, (uint
) nblks
,
293 XFS_ATTRSET_LOG_RES(mp
, nblks
),
294 0, XFS_TRANS_PERM_LOG_RES
,
295 XFS_ATTRSET_LOG_COUNT
))) {
296 xfs_trans_cancel(args
.trans
, 0);
299 xfs_ilock(dp
, XFS_ILOCK_EXCL
);
301 error
= XFS_TRANS_RESERVE_QUOTA_NBLKS(mp
, args
.trans
, dp
, nblks
, 0,
302 rsvd
? XFS_QMOPT_RES_REGBLKS
| XFS_QMOPT_FORCE_RES
:
303 XFS_QMOPT_RES_REGBLKS
);
305 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
306 xfs_trans_cancel(args
.trans
, XFS_TRANS_RELEASE_LOG_RES
);
310 xfs_trans_ijoin(args
.trans
, dp
, XFS_ILOCK_EXCL
);
311 xfs_trans_ihold(args
.trans
, dp
);
314 * If the attribute list is non-existent or a shortform list,
315 * upgrade it to a single-leaf-block attribute list.
317 if ((dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
318 ((dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
) &&
319 (dp
->i_d
.di_anextents
== 0))) {
322 * Build initial attribute list (if required).
324 if (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
)
325 xfs_attr_shortform_create(&args
);
328 * Try to add the attr to the attribute list in
331 error
= xfs_attr_shortform_addname(&args
);
332 if (error
!= ENOSPC
) {
334 * Commit the shortform mods, and we're done.
335 * NOTE: this is also the error path (EEXIST, etc).
337 ASSERT(args
.trans
!= NULL
);
340 * If this is a synchronous mount, make sure that
341 * the transaction goes to disk before returning
344 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
345 xfs_trans_set_sync(args
.trans
);
347 err2
= xfs_trans_commit(args
.trans
,
348 XFS_TRANS_RELEASE_LOG_RES
);
349 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
352 * Hit the inode change time.
354 if (!error
&& (flags
& ATTR_KERNOTIME
) == 0) {
355 xfs_ichgtime(dp
, XFS_ICHGTIME_CHG
);
357 return(error
== 0 ? err2
: error
);
361 * It won't fit in the shortform, transform to a leaf block.
362 * GROT: another possible req'mt for a double-split btree op.
364 XFS_BMAP_INIT(args
.flist
, args
.firstblock
);
365 error
= xfs_attr_shortform_to_leaf(&args
);
367 error
= xfs_bmap_finish(&args
.trans
, args
.flist
,
373 xfs_bmap_cancel(&flist
);
378 * bmap_finish() may have committed the last trans and started
379 * a new one. We need the inode to be in all transactions.
382 xfs_trans_ijoin(args
.trans
, dp
, XFS_ILOCK_EXCL
);
383 xfs_trans_ihold(args
.trans
, dp
);
387 * Commit the leaf transformation. We'll need another (linked)
388 * transaction to add the new attribute to the leaf.
390 if ((error
= xfs_attr_rolltrans(&args
.trans
, dp
)))
395 if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
396 error
= xfs_attr_leaf_addname(&args
);
398 error
= xfs_attr_node_addname(&args
);
405 * If this is a synchronous mount, make sure that the
406 * transaction goes to disk before returning to the user.
408 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
409 xfs_trans_set_sync(args
.trans
);
413 * Commit the last in the sequence of transactions.
415 xfs_trans_log_inode(args
.trans
, dp
, XFS_ILOG_CORE
);
416 error
= xfs_trans_commit(args
.trans
, XFS_TRANS_RELEASE_LOG_RES
);
417 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
420 * Hit the inode change time.
422 if (!error
&& (flags
& ATTR_KERNOTIME
) == 0) {
423 xfs_ichgtime(dp
, XFS_ICHGTIME_CHG
);
430 xfs_trans_cancel(args
.trans
,
431 XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
432 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
445 struct xfs_name xname
;
447 XFS_STATS_INC(xs_attr_set
);
449 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
452 error
= xfs_attr_name_to_xname(&xname
, name
);
456 return xfs_attr_set_int(dp
, &xname
, value
, valuelen
, flags
);
460 * Generic handler routine to remove a name from an attribute list.
461 * Transitions attribute list from Btree to shortform as necessary.
464 xfs_attr_remove_int(xfs_inode_t
*dp
, struct xfs_name
*name
, int flags
)
467 xfs_fsblock_t firstblock
;
468 xfs_bmap_free_t flist
;
470 xfs_mount_t
*mp
= dp
->i_mount
;
473 * Fill in the arg structure for this request.
475 memset((char *)&args
, 0, sizeof(args
));
476 args
.name
= name
->name
;
477 args
.namelen
= name
->len
;
479 args
.hashval
= xfs_da_hashname(args
.name
, args
.namelen
);
481 args
.firstblock
= &firstblock
;
484 args
.whichfork
= XFS_ATTR_FORK
;
487 * Attach the dquots to the inode.
489 if ((error
= XFS_QM_DQATTACH(mp
, dp
, 0)))
493 * Start our first transaction of the day.
495 * All future transactions during this code must be "chained" off
496 * this one via the trans_dup() call. All transactions will contain
497 * the inode, and the inode will always be marked with trans_ihold().
498 * Since the inode will be locked in all transactions, we must log
499 * the inode in every transaction to let it float upward through
502 args
.trans
= xfs_trans_alloc(mp
, XFS_TRANS_ATTR_RM
);
505 * Root fork attributes can use reserved data blocks for this
506 * operation if necessary
509 if (flags
& ATTR_ROOT
)
510 args
.trans
->t_flags
|= XFS_TRANS_RESERVE
;
512 if ((error
= xfs_trans_reserve(args
.trans
,
513 XFS_ATTRRM_SPACE_RES(mp
),
514 XFS_ATTRRM_LOG_RES(mp
),
515 0, XFS_TRANS_PERM_LOG_RES
,
516 XFS_ATTRRM_LOG_COUNT
))) {
517 xfs_trans_cancel(args
.trans
, 0);
521 xfs_ilock(dp
, XFS_ILOCK_EXCL
);
523 * No need to make quota reservations here. We expect to release some
524 * blocks not allocate in the common case.
526 xfs_trans_ijoin(args
.trans
, dp
, XFS_ILOCK_EXCL
);
527 xfs_trans_ihold(args
.trans
, dp
);
530 * Decide on what work routines to call based on the inode size.
532 if (XFS_IFORK_Q(dp
) == 0 ||
533 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
534 dp
->i_d
.di_anextents
== 0)) {
535 error
= XFS_ERROR(ENOATTR
);
538 if (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) {
539 ASSERT(dp
->i_afp
->if_flags
& XFS_IFINLINE
);
540 error
= xfs_attr_shortform_remove(&args
);
544 } else if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
545 error
= xfs_attr_leaf_removename(&args
);
547 error
= xfs_attr_node_removename(&args
);
554 * If this is a synchronous mount, make sure that the
555 * transaction goes to disk before returning to the user.
557 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
558 xfs_trans_set_sync(args
.trans
);
562 * Commit the last in the sequence of transactions.
564 xfs_trans_log_inode(args
.trans
, dp
, XFS_ILOG_CORE
);
565 error
= xfs_trans_commit(args
.trans
, XFS_TRANS_RELEASE_LOG_RES
);
566 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
569 * Hit the inode change time.
571 if (!error
&& (flags
& ATTR_KERNOTIME
) == 0) {
572 xfs_ichgtime(dp
, XFS_ICHGTIME_CHG
);
579 xfs_trans_cancel(args
.trans
,
580 XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
581 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
592 struct xfs_name xname
;
594 XFS_STATS_INC(xs_attr_remove
);
596 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
599 error
= xfs_attr_name_to_xname(&xname
, name
);
603 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
604 if (XFS_IFORK_Q(dp
) == 0 ||
605 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
606 dp
->i_d
.di_anextents
== 0)) {
607 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
608 return(XFS_ERROR(ENOATTR
));
610 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
612 return xfs_attr_remove_int(dp
, &xname
, flags
);
616 xfs_attr_list_int(xfs_attr_list_context_t
*context
)
619 xfs_inode_t
*dp
= context
->dp
;
622 * Decide on what work routines to call based on the inode size.
624 if (XFS_IFORK_Q(dp
) == 0 ||
625 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
626 dp
->i_d
.di_anextents
== 0)) {
628 } else if (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) {
629 error
= xfs_attr_shortform_list(context
);
630 } else if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
631 error
= xfs_attr_leaf_list(context
);
633 error
= xfs_attr_node_list(context
);
638 #define ATTR_ENTBASESIZE /* minimum bytes used by an attr */ \
639 (((struct attrlist_ent *) 0)->a_name - (char *) 0)
640 #define ATTR_ENTSIZE(namelen) /* actual bytes used by an attr */ \
641 ((ATTR_ENTBASESIZE + (namelen) + 1 + sizeof(u_int32_t)-1) \
642 & ~(sizeof(u_int32_t)-1))
645 * Format an attribute and copy it out to the user's buffer.
646 * Take care to check values and protect against them changing later,
647 * we may be reading them directly out of a user buffer.
651 xfs_attr_put_listent(xfs_attr_list_context_t
*context
, attrnames_t
*namesp
,
652 char *name
, int namelen
,
653 int valuelen
, char *value
)
658 ASSERT(!(context
->flags
& ATTR_KERNOVAL
));
659 ASSERT(context
->count
>= 0);
660 ASSERT(context
->count
< (ATTR_MAX_VALUELEN
/8));
661 ASSERT(context
->firstu
>= sizeof(*context
->alist
));
662 ASSERT(context
->firstu
<= context
->bufsize
);
664 arraytop
= sizeof(*context
->alist
) +
665 context
->count
* sizeof(context
->alist
->al_offset
[0]);
666 context
->firstu
-= ATTR_ENTSIZE(namelen
);
667 if (context
->firstu
< arraytop
) {
668 xfs_attr_trace_l_c("buffer full", context
);
669 context
->alist
->al_more
= 1;
670 context
->seen_enough
= 1;
674 aep
= (attrlist_ent_t
*)&(((char *)context
->alist
)[ context
->firstu
]);
675 aep
->a_valuelen
= valuelen
;
676 memcpy(aep
->a_name
, name
, namelen
);
677 aep
->a_name
[ namelen
] = 0;
678 context
->alist
->al_offset
[ context
->count
++ ] = context
->firstu
;
679 context
->alist
->al_count
= context
->count
;
680 xfs_attr_trace_l_c("add", context
);
685 xfs_attr_kern_list(xfs_attr_list_context_t
*context
, attrnames_t
*namesp
,
686 char *name
, int namelen
,
687 int valuelen
, char *value
)
692 ASSERT(context
->count
>= 0);
694 arraytop
= context
->count
+ namesp
->attr_namelen
+ namelen
+ 1;
695 if (arraytop
> context
->firstu
) {
696 context
->count
= -1; /* insufficient space */
699 offset
= (char *)context
->alist
+ context
->count
;
700 strncpy(offset
, namesp
->attr_name
, namesp
->attr_namelen
);
701 offset
+= namesp
->attr_namelen
;
702 strncpy(offset
, name
, namelen
); /* real name */
705 context
->count
+= namesp
->attr_namelen
+ namelen
+ 1;
711 xfs_attr_kern_list_sizes(xfs_attr_list_context_t
*context
, attrnames_t
*namesp
,
712 char *name
, int namelen
,
713 int valuelen
, char *value
)
715 context
->count
+= namesp
->attr_namelen
+ namelen
+ 1;
720 * Generate a list of extended attribute names and optionally
721 * also value lengths. Positive return value follows the XFS
722 * convention of being an error, zero or negative return code
723 * is the length of the buffer returned (negated), indicating
732 attrlist_cursor_kern_t
*cursor
)
734 xfs_attr_list_context_t context
;
737 XFS_STATS_INC(xs_attr_list
);
740 * Validate the cursor.
742 if (cursor
->pad1
|| cursor
->pad2
)
743 return(XFS_ERROR(EINVAL
));
744 if ((cursor
->initted
== 0) &&
745 (cursor
->hashval
|| cursor
->blkno
|| cursor
->offset
))
746 return XFS_ERROR(EINVAL
);
749 * Check for a properly aligned buffer.
751 if (((long)buffer
) & (sizeof(int)-1))
752 return XFS_ERROR(EFAULT
);
753 if (flags
& ATTR_KERNOVAL
)
757 * Initialize the output buffer.
760 context
.cursor
= cursor
;
764 context
.flags
= flags
;
765 context
.seen_enough
= 0;
766 context
.alist
= (attrlist_t
*)buffer
;
767 context
.put_value
= 0;
769 if (flags
& ATTR_KERNAMELS
) {
770 context
.bufsize
= bufsize
;
771 context
.firstu
= context
.bufsize
;
772 if (flags
& ATTR_KERNOVAL
)
773 context
.put_listent
= xfs_attr_kern_list_sizes
;
775 context
.put_listent
= xfs_attr_kern_list
;
777 context
.bufsize
= (bufsize
& ~(sizeof(int)-1)); /* align */
778 context
.firstu
= context
.bufsize
;
779 context
.alist
->al_count
= 0;
780 context
.alist
->al_more
= 0;
781 context
.alist
->al_offset
[0] = context
.bufsize
;
782 context
.put_listent
= xfs_attr_put_listent
;
785 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
788 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
789 xfs_attr_trace_l_c("syscall start", &context
);
791 error
= xfs_attr_list_int(&context
);
793 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
794 xfs_attr_trace_l_c("syscall end", &context
);
796 if (context
.flags
& (ATTR_KERNOVAL
|ATTR_KERNAMELS
)) {
797 /* must return negated buffer size or the error */
798 if (context
.count
< 0)
799 error
= XFS_ERROR(ERANGE
);
801 error
= -context
.count
;
809 xfs_attr_inactive(xfs_inode_t
*dp
)
816 ASSERT(! XFS_NOT_DQATTACHED(mp
, dp
));
818 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
819 if ((XFS_IFORK_Q(dp
) == 0) ||
820 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
821 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
822 dp
->i_d
.di_anextents
== 0)) {
823 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
826 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
829 * Start our first transaction of the day.
831 * All future transactions during this code must be "chained" off
832 * this one via the trans_dup() call. All transactions will contain
833 * the inode, and the inode will always be marked with trans_ihold().
834 * Since the inode will be locked in all transactions, we must log
835 * the inode in every transaction to let it float upward through
838 trans
= xfs_trans_alloc(mp
, XFS_TRANS_ATTRINVAL
);
839 if ((error
= xfs_trans_reserve(trans
, 0, XFS_ATTRINVAL_LOG_RES(mp
), 0,
840 XFS_TRANS_PERM_LOG_RES
,
841 XFS_ATTRINVAL_LOG_COUNT
))) {
842 xfs_trans_cancel(trans
, 0);
845 xfs_ilock(dp
, XFS_ILOCK_EXCL
);
848 * No need to make quota reservations here. We expect to release some
849 * blocks, not allocate, in the common case.
851 xfs_trans_ijoin(trans
, dp
, XFS_ILOCK_EXCL
);
852 xfs_trans_ihold(trans
, dp
);
855 * Decide on what work routines to call based on the inode size.
857 if ((XFS_IFORK_Q(dp
) == 0) ||
858 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
859 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
860 dp
->i_d
.di_anextents
== 0)) {
864 error
= xfs_attr_root_inactive(&trans
, dp
);
868 * signal synchronous inactive transactions unless this
869 * is a synchronous mount filesystem in which case we
870 * know that we're here because we've been called out of
871 * xfs_inactive which means that the last reference is gone
872 * and the unlink transaction has already hit the disk so
873 * async inactive transactions are safe.
875 if ((error
= xfs_itruncate_finish(&trans
, dp
, 0LL, XFS_ATTR_FORK
,
876 (!(mp
->m_flags
& XFS_MOUNT_WSYNC
)
881 * Commit the last in the sequence of transactions.
883 xfs_trans_log_inode(trans
, dp
, XFS_ILOG_CORE
);
884 error
= xfs_trans_commit(trans
, XFS_TRANS_RELEASE_LOG_RES
);
885 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
890 xfs_trans_cancel(trans
, XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
891 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
897 /*========================================================================
898 * External routines when attribute list is inside the inode
899 *========================================================================*/
902 * Add a name to the shortform attribute list structure
903 * This is the external routine.
906 xfs_attr_shortform_addname(xfs_da_args_t
*args
)
908 int newsize
, forkoff
, retval
;
910 retval
= xfs_attr_shortform_lookup(args
);
911 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
913 } else if (retval
== EEXIST
) {
914 if (args
->flags
& ATTR_CREATE
)
916 retval
= xfs_attr_shortform_remove(args
);
920 if (args
->namelen
>= XFS_ATTR_SF_ENTSIZE_MAX
||
921 args
->valuelen
>= XFS_ATTR_SF_ENTSIZE_MAX
)
922 return(XFS_ERROR(ENOSPC
));
924 newsize
= XFS_ATTR_SF_TOTSIZE(args
->dp
);
925 newsize
+= XFS_ATTR_SF_ENTSIZE_BYNAME(args
->namelen
, args
->valuelen
);
927 forkoff
= xfs_attr_shortform_bytesfit(args
->dp
, newsize
);
929 return(XFS_ERROR(ENOSPC
));
931 xfs_attr_shortform_add(args
, forkoff
);
936 /*========================================================================
937 * External routines when attribute list is one block
938 *========================================================================*/
941 * Add a name to the leaf attribute list structure
943 * This leaf block cannot have a "remote" value, we only call this routine
944 * if bmap_one_block() says there is only one block (ie: no remote blks).
947 xfs_attr_leaf_addname(xfs_da_args_t
*args
)
951 int retval
, error
, committed
, forkoff
;
954 * Read the (only) block in the attribute list in.
958 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
965 * Look up the given attribute in the leaf block. Figure out if
966 * the given flags produce an error or call for an atomic rename.
968 retval
= xfs_attr_leaf_lookup_int(bp
, args
);
969 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
970 xfs_da_brelse(args
->trans
, bp
);
972 } else if (retval
== EEXIST
) {
973 if (args
->flags
& ATTR_CREATE
) { /* pure create op */
974 xfs_da_brelse(args
->trans
, bp
);
977 args
->rename
= 1; /* an atomic rename */
978 args
->blkno2
= args
->blkno
; /* set 2nd entry info*/
979 args
->index2
= args
->index
;
980 args
->rmtblkno2
= args
->rmtblkno
;
981 args
->rmtblkcnt2
= args
->rmtblkcnt
;
985 * Add the attribute to the leaf block, transitioning to a Btree
988 retval
= xfs_attr_leaf_add(bp
, args
);
990 if (retval
== ENOSPC
) {
992 * Promote the attribute list to the Btree format, then
993 * Commit that transaction so that the node_addname() call
994 * can manage its own transactions.
996 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
997 error
= xfs_attr_leaf_to_node(args
);
999 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1005 xfs_bmap_cancel(args
->flist
);
1010 * bmap_finish() may have committed the last trans and started
1011 * a new one. We need the inode to be in all transactions.
1014 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1015 xfs_trans_ihold(args
->trans
, dp
);
1019 * Commit the current trans (including the inode) and start
1022 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1026 * Fob the whole rest of the problem off on the Btree code.
1028 error
= xfs_attr_node_addname(args
);
1033 * Commit the transaction that added the attr name so that
1034 * later routines can manage their own transactions.
1036 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1040 * If there was an out-of-line value, allocate the blocks we
1041 * identified for its storage and copy the value. This is done
1042 * after we create the attribute so that we don't overflow the
1043 * maximum size of a transaction and/or hit a deadlock.
1045 if (args
->rmtblkno
> 0) {
1046 error
= xfs_attr_rmtval_set(args
);
1052 * If this is an atomic rename operation, we must "flip" the
1053 * incomplete flags on the "new" and "old" attribute/value pairs
1054 * so that one disappears and one appears atomically. Then we
1055 * must remove the "old" attribute/value pair.
1059 * In a separate transaction, set the incomplete flag on the
1060 * "old" attr and clear the incomplete flag on the "new" attr.
1062 error
= xfs_attr_leaf_flipflags(args
);
1067 * Dismantle the "old" attribute/value pair by removing
1068 * a "remote" value (if it exists).
1070 args
->index
= args
->index2
;
1071 args
->blkno
= args
->blkno2
;
1072 args
->rmtblkno
= args
->rmtblkno2
;
1073 args
->rmtblkcnt
= args
->rmtblkcnt2
;
1074 if (args
->rmtblkno
) {
1075 error
= xfs_attr_rmtval_remove(args
);
1081 * Read in the block containing the "old" attr, then
1082 * remove the "old" attr from that block (neat, huh!)
1084 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1,
1085 &bp
, XFS_ATTR_FORK
);
1089 (void)xfs_attr_leaf_remove(bp
, args
);
1092 * If the result is small enough, shrink it all into the inode.
1094 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1095 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1096 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1097 /* bp is gone due to xfs_da_shrink_inode */
1099 error
= xfs_bmap_finish(&args
->trans
,
1106 xfs_bmap_cancel(args
->flist
);
1111 * bmap_finish() may have committed the last trans
1112 * and started a new one. We need the inode to be
1113 * in all transactions.
1116 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1117 xfs_trans_ihold(args
->trans
, dp
);
1120 xfs_da_buf_done(bp
);
1123 * Commit the remove and start the next trans in series.
1125 error
= xfs_attr_rolltrans(&args
->trans
, dp
);
1127 } else if (args
->rmtblkno
> 0) {
1129 * Added a "remote" value, just clear the incomplete flag.
1131 error
= xfs_attr_leaf_clearflag(args
);
1137 * Remove a name from the leaf attribute list structure
1139 * This leaf block cannot have a "remote" value, we only call this routine
1140 * if bmap_one_block() says there is only one block (ie: no remote blks).
1143 xfs_attr_leaf_removename(xfs_da_args_t
*args
)
1147 int error
, committed
, forkoff
;
1150 * Remove the attribute.
1154 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
1161 error
= xfs_attr_leaf_lookup_int(bp
, args
);
1162 if (error
== ENOATTR
) {
1163 xfs_da_brelse(args
->trans
, bp
);
1167 (void)xfs_attr_leaf_remove(bp
, args
);
1170 * If the result is small enough, shrink it all into the inode.
1172 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1173 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1174 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1175 /* bp is gone due to xfs_da_shrink_inode */
1177 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1183 xfs_bmap_cancel(args
->flist
);
1188 * bmap_finish() may have committed the last trans and started
1189 * a new one. We need the inode to be in all transactions.
1192 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1193 xfs_trans_ihold(args
->trans
, dp
);
1196 xfs_da_buf_done(bp
);
1201 * Look up a name in a leaf attribute list structure.
1203 * This leaf block cannot have a "remote" value, we only call this routine
1204 * if bmap_one_block() says there is only one block (ie: no remote blks).
1207 xfs_attr_leaf_get(xfs_da_args_t
*args
)
1213 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
1219 error
= xfs_attr_leaf_lookup_int(bp
, args
);
1220 if (error
!= EEXIST
) {
1221 xfs_da_brelse(args
->trans
, bp
);
1224 error
= xfs_attr_leaf_getvalue(bp
, args
);
1225 xfs_da_brelse(args
->trans
, bp
);
1226 if (!error
&& (args
->rmtblkno
> 0) && !(args
->flags
& ATTR_KERNOVAL
)) {
1227 error
= xfs_attr_rmtval_get(args
);
1233 * Copy out attribute entries for attr_list(), for leaf attribute lists.
1236 xfs_attr_leaf_list(xfs_attr_list_context_t
*context
)
1238 xfs_attr_leafblock_t
*leaf
;
1242 context
->cursor
->blkno
= 0;
1243 error
= xfs_da_read_buf(NULL
, context
->dp
, 0, -1, &bp
, XFS_ATTR_FORK
);
1245 return XFS_ERROR(error
);
1248 if (unlikely(be16_to_cpu(leaf
->hdr
.info
.magic
) != XFS_ATTR_LEAF_MAGIC
)) {
1249 XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW
,
1250 context
->dp
->i_mount
, leaf
);
1251 xfs_da_brelse(NULL
, bp
);
1252 return XFS_ERROR(EFSCORRUPTED
);
1255 error
= xfs_attr_leaf_list_int(bp
, context
);
1256 xfs_da_brelse(NULL
, bp
);
1257 return XFS_ERROR(error
);
1261 /*========================================================================
1262 * External routines when attribute list size > XFS_LBSIZE(mp).
1263 *========================================================================*/
1266 * Add a name to a Btree-format attribute list.
1268 * This will involve walking down the Btree, and may involve splitting
1269 * leaf nodes and even splitting intermediate nodes up to and including
1270 * the root node (a special case of an intermediate node).
1272 * "Remote" attribute values confuse the issue and atomic rename operations
1273 * add a whole extra layer of confusion on top of that.
1276 xfs_attr_node_addname(xfs_da_args_t
*args
)
1278 xfs_da_state_t
*state
;
1279 xfs_da_state_blk_t
*blk
;
1282 int committed
, retval
, error
;
1285 * Fill in bucket of arguments/results/context to carry around.
1290 state
= xfs_da_state_alloc();
1293 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1294 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1297 * Search to see if name already exists, and get back a pointer
1298 * to where it should go.
1300 error
= xfs_da_node_lookup_int(state
, &retval
);
1303 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1304 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1305 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
1307 } else if (retval
== EEXIST
) {
1308 if (args
->flags
& ATTR_CREATE
)
1310 args
->rename
= 1; /* atomic rename op */
1311 args
->blkno2
= args
->blkno
; /* set 2nd entry info*/
1312 args
->index2
= args
->index
;
1313 args
->rmtblkno2
= args
->rmtblkno
;
1314 args
->rmtblkcnt2
= args
->rmtblkcnt
;
1316 args
->rmtblkcnt
= 0;
1319 retval
= xfs_attr_leaf_add(blk
->bp
, state
->args
);
1320 if (retval
== ENOSPC
) {
1321 if (state
->path
.active
== 1) {
1323 * Its really a single leaf node, but it had
1324 * out-of-line values so it looked like it *might*
1325 * have been a b-tree.
1327 xfs_da_state_free(state
);
1328 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1329 error
= xfs_attr_leaf_to_node(args
);
1331 error
= xfs_bmap_finish(&args
->trans
,
1338 xfs_bmap_cancel(args
->flist
);
1343 * bmap_finish() may have committed the last trans
1344 * and started a new one. We need the inode to be
1345 * in all transactions.
1348 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1349 xfs_trans_ihold(args
->trans
, dp
);
1353 * Commit the node conversion and start the next
1354 * trans in the chain.
1356 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1363 * Split as many Btree elements as required.
1364 * This code tracks the new and old attr's location
1365 * in the index/blkno/rmtblkno/rmtblkcnt fields and
1366 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
1368 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1369 error
= xfs_da_split(state
);
1371 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1377 xfs_bmap_cancel(args
->flist
);
1382 * bmap_finish() may have committed the last trans and started
1383 * a new one. We need the inode to be in all transactions.
1386 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1387 xfs_trans_ihold(args
->trans
, dp
);
1391 * Addition succeeded, update Btree hashvals.
1393 xfs_da_fixhashpath(state
, &state
->path
);
1397 * Kill the state structure, we're done with it and need to
1398 * allow the buffers to come back later.
1400 xfs_da_state_free(state
);
1404 * Commit the leaf addition or btree split and start the next
1405 * trans in the chain.
1407 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1411 * If there was an out-of-line value, allocate the blocks we
1412 * identified for its storage and copy the value. This is done
1413 * after we create the attribute so that we don't overflow the
1414 * maximum size of a transaction and/or hit a deadlock.
1416 if (args
->rmtblkno
> 0) {
1417 error
= xfs_attr_rmtval_set(args
);
1423 * If this is an atomic rename operation, we must "flip" the
1424 * incomplete flags on the "new" and "old" attribute/value pairs
1425 * so that one disappears and one appears atomically. Then we
1426 * must remove the "old" attribute/value pair.
1430 * In a separate transaction, set the incomplete flag on the
1431 * "old" attr and clear the incomplete flag on the "new" attr.
1433 error
= xfs_attr_leaf_flipflags(args
);
1438 * Dismantle the "old" attribute/value pair by removing
1439 * a "remote" value (if it exists).
1441 args
->index
= args
->index2
;
1442 args
->blkno
= args
->blkno2
;
1443 args
->rmtblkno
= args
->rmtblkno2
;
1444 args
->rmtblkcnt
= args
->rmtblkcnt2
;
1445 if (args
->rmtblkno
) {
1446 error
= xfs_attr_rmtval_remove(args
);
1452 * Re-find the "old" attribute entry after any split ops.
1453 * The INCOMPLETE flag means that we will find the "old"
1454 * attr, not the "new" one.
1456 args
->flags
|= XFS_ATTR_INCOMPLETE
;
1457 state
= xfs_da_state_alloc();
1460 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1461 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1463 error
= xfs_da_node_lookup_int(state
, &retval
);
1468 * Remove the name and update the hashvals in the tree.
1470 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1471 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1472 error
= xfs_attr_leaf_remove(blk
->bp
, args
);
1473 xfs_da_fixhashpath(state
, &state
->path
);
1476 * Check to see if the tree needs to be collapsed.
1478 if (retval
&& (state
->path
.active
> 1)) {
1479 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1480 error
= xfs_da_join(state
);
1482 error
= xfs_bmap_finish(&args
->trans
,
1489 xfs_bmap_cancel(args
->flist
);
1494 * bmap_finish() may have committed the last trans
1495 * and started a new one. We need the inode to be
1496 * in all transactions.
1499 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1500 xfs_trans_ihold(args
->trans
, dp
);
1505 * Commit and start the next trans in the chain.
1507 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1510 } else if (args
->rmtblkno
> 0) {
1512 * Added a "remote" value, just clear the incomplete flag.
1514 error
= xfs_attr_leaf_clearflag(args
);
1522 xfs_da_state_free(state
);
1529 * Remove a name from a B-tree attribute list.
1531 * This will involve walking down the Btree, and may involve joining
1532 * leaf nodes and even joining intermediate nodes up to and including
1533 * the root node (a special case of an intermediate node).
1536 xfs_attr_node_removename(xfs_da_args_t
*args
)
1538 xfs_da_state_t
*state
;
1539 xfs_da_state_blk_t
*blk
;
1542 int retval
, error
, committed
, forkoff
;
1545 * Tie a string around our finger to remind us where we are.
1548 state
= xfs_da_state_alloc();
1550 state
->mp
= dp
->i_mount
;
1551 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1552 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1555 * Search to see if name exists, and get back a pointer to it.
1557 error
= xfs_da_node_lookup_int(state
, &retval
);
1558 if (error
|| (retval
!= EEXIST
)) {
1565 * If there is an out-of-line value, de-allocate the blocks.
1566 * This is done before we remove the attribute so that we don't
1567 * overflow the maximum size of a transaction and/or hit a deadlock.
1569 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1570 ASSERT(blk
->bp
!= NULL
);
1571 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1572 if (args
->rmtblkno
> 0) {
1574 * Fill in disk block numbers in the state structure
1575 * so that we can get the buffers back after we commit
1576 * several transactions in the following calls.
1578 error
= xfs_attr_fillstate(state
);
1583 * Mark the attribute as INCOMPLETE, then bunmapi() the
1586 error
= xfs_attr_leaf_setflag(args
);
1589 error
= xfs_attr_rmtval_remove(args
);
1594 * Refill the state structure with buffers, the prior calls
1595 * released our buffers.
1597 error
= xfs_attr_refillstate(state
);
1603 * Remove the name and update the hashvals in the tree.
1605 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1606 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1607 retval
= xfs_attr_leaf_remove(blk
->bp
, args
);
1608 xfs_da_fixhashpath(state
, &state
->path
);
1611 * Check to see if the tree needs to be collapsed.
1613 if (retval
&& (state
->path
.active
> 1)) {
1614 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1615 error
= xfs_da_join(state
);
1617 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1623 xfs_bmap_cancel(args
->flist
);
1628 * bmap_finish() may have committed the last trans and started
1629 * a new one. We need the inode to be in all transactions.
1632 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1633 xfs_trans_ihold(args
->trans
, dp
);
1637 * Commit the Btree join operation and start a new trans.
1639 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1644 * If the result is small enough, push it all into the inode.
1646 if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
1648 * Have to get rid of the copy of this dabuf in the state.
1650 ASSERT(state
->path
.active
== 1);
1651 ASSERT(state
->path
.blk
[0].bp
);
1652 xfs_da_buf_done(state
->path
.blk
[0].bp
);
1653 state
->path
.blk
[0].bp
= NULL
;
1655 error
= xfs_da_read_buf(args
->trans
, args
->dp
, 0, -1, &bp
,
1659 ASSERT(be16_to_cpu(((xfs_attr_leafblock_t
*)
1660 bp
->data
)->hdr
.info
.magic
)
1661 == XFS_ATTR_LEAF_MAGIC
);
1663 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1664 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1665 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1666 /* bp is gone due to xfs_da_shrink_inode */
1668 error
= xfs_bmap_finish(&args
->trans
,
1675 xfs_bmap_cancel(args
->flist
);
1680 * bmap_finish() may have committed the last trans
1681 * and started a new one. We need the inode to be
1682 * in all transactions.
1685 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1686 xfs_trans_ihold(args
->trans
, dp
);
1689 xfs_da_brelse(args
->trans
, bp
);
1694 xfs_da_state_free(state
);
1699 * Fill in the disk block numbers in the state structure for the buffers
1700 * that are attached to the state structure.
1701 * This is done so that we can quickly reattach ourselves to those buffers
1702 * after some set of transaction commits have released these buffers.
1705 xfs_attr_fillstate(xfs_da_state_t
*state
)
1707 xfs_da_state_path_t
*path
;
1708 xfs_da_state_blk_t
*blk
;
1712 * Roll down the "path" in the state structure, storing the on-disk
1713 * block number for those buffers in the "path".
1715 path
= &state
->path
;
1716 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1717 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1719 blk
->disk_blkno
= xfs_da_blkno(blk
->bp
);
1720 xfs_da_buf_done(blk
->bp
);
1723 blk
->disk_blkno
= 0;
1728 * Roll down the "altpath" in the state structure, storing the on-disk
1729 * block number for those buffers in the "altpath".
1731 path
= &state
->altpath
;
1732 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1733 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1735 blk
->disk_blkno
= xfs_da_blkno(blk
->bp
);
1736 xfs_da_buf_done(blk
->bp
);
1739 blk
->disk_blkno
= 0;
1747 * Reattach the buffers to the state structure based on the disk block
1748 * numbers stored in the state structure.
1749 * This is done after some set of transaction commits have released those
1750 * buffers from our grip.
1753 xfs_attr_refillstate(xfs_da_state_t
*state
)
1755 xfs_da_state_path_t
*path
;
1756 xfs_da_state_blk_t
*blk
;
1760 * Roll down the "path" in the state structure, storing the on-disk
1761 * block number for those buffers in the "path".
1763 path
= &state
->path
;
1764 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1765 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1766 if (blk
->disk_blkno
) {
1767 error
= xfs_da_read_buf(state
->args
->trans
,
1769 blk
->blkno
, blk
->disk_blkno
,
1770 &blk
->bp
, XFS_ATTR_FORK
);
1779 * Roll down the "altpath" in the state structure, storing the on-disk
1780 * block number for those buffers in the "altpath".
1782 path
= &state
->altpath
;
1783 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1784 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1785 if (blk
->disk_blkno
) {
1786 error
= xfs_da_read_buf(state
->args
->trans
,
1788 blk
->blkno
, blk
->disk_blkno
,
1789 &blk
->bp
, XFS_ATTR_FORK
);
1801 * Look up a filename in a node attribute list.
1803 * This routine gets called for any attribute fork that has more than one
1804 * block, ie: both true Btree attr lists and for single-leaf-blocks with
1805 * "remote" values taking up more blocks.
1808 xfs_attr_node_get(xfs_da_args_t
*args
)
1810 xfs_da_state_t
*state
;
1811 xfs_da_state_blk_t
*blk
;
1815 state
= xfs_da_state_alloc();
1817 state
->mp
= args
->dp
->i_mount
;
1818 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1819 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1822 * Search to see if name exists, and get back a pointer to it.
1824 error
= xfs_da_node_lookup_int(state
, &retval
);
1827 } else if (retval
== EEXIST
) {
1828 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1829 ASSERT(blk
->bp
!= NULL
);
1830 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1833 * Get the value, local or "remote"
1835 retval
= xfs_attr_leaf_getvalue(blk
->bp
, args
);
1836 if (!retval
&& (args
->rmtblkno
> 0)
1837 && !(args
->flags
& ATTR_KERNOVAL
)) {
1838 retval
= xfs_attr_rmtval_get(args
);
1843 * If not in a transaction, we have to release all the buffers.
1845 for (i
= 0; i
< state
->path
.active
; i
++) {
1846 xfs_da_brelse(args
->trans
, state
->path
.blk
[i
].bp
);
1847 state
->path
.blk
[i
].bp
= NULL
;
1850 xfs_da_state_free(state
);
1854 STATIC
int /* error */
1855 xfs_attr_node_list(xfs_attr_list_context_t
*context
)
1857 attrlist_cursor_kern_t
*cursor
;
1858 xfs_attr_leafblock_t
*leaf
;
1859 xfs_da_intnode_t
*node
;
1860 xfs_da_node_entry_t
*btree
;
1864 cursor
= context
->cursor
;
1865 cursor
->initted
= 1;
1868 * Do all sorts of validation on the passed-in cursor structure.
1869 * If anything is amiss, ignore the cursor and look up the hashval
1870 * starting from the btree root.
1873 if (cursor
->blkno
> 0) {
1874 error
= xfs_da_read_buf(NULL
, context
->dp
, cursor
->blkno
, -1,
1875 &bp
, XFS_ATTR_FORK
);
1876 if ((error
!= 0) && (error
!= EFSCORRUPTED
))
1880 switch (be16_to_cpu(node
->hdr
.info
.magic
)) {
1881 case XFS_DA_NODE_MAGIC
:
1882 xfs_attr_trace_l_cn("wrong blk", context
, node
);
1883 xfs_da_brelse(NULL
, bp
);
1886 case XFS_ATTR_LEAF_MAGIC
:
1888 if (cursor
->hashval
> be32_to_cpu(leaf
->entries
[
1889 be16_to_cpu(leaf
->hdr
.count
)-1].hashval
)) {
1890 xfs_attr_trace_l_cl("wrong blk",
1892 xfs_da_brelse(NULL
, bp
);
1894 } else if (cursor
->hashval
<=
1895 be32_to_cpu(leaf
->entries
[0].hashval
)) {
1896 xfs_attr_trace_l_cl("maybe wrong blk",
1898 xfs_da_brelse(NULL
, bp
);
1903 xfs_attr_trace_l_c("wrong blk - ??", context
);
1904 xfs_da_brelse(NULL
, bp
);
1911 * We did not find what we expected given the cursor's contents,
1912 * so we start from the top and work down based on the hash value.
1913 * Note that start of node block is same as start of leaf block.
1918 error
= xfs_da_read_buf(NULL
, context
->dp
,
1919 cursor
->blkno
, -1, &bp
,
1923 if (unlikely(bp
== NULL
)) {
1924 XFS_ERROR_REPORT("xfs_attr_node_list(2)",
1926 context
->dp
->i_mount
);
1927 return(XFS_ERROR(EFSCORRUPTED
));
1930 if (be16_to_cpu(node
->hdr
.info
.magic
)
1931 == XFS_ATTR_LEAF_MAGIC
)
1933 if (unlikely(be16_to_cpu(node
->hdr
.info
.magic
)
1934 != XFS_DA_NODE_MAGIC
)) {
1935 XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
1937 context
->dp
->i_mount
,
1939 xfs_da_brelse(NULL
, bp
);
1940 return(XFS_ERROR(EFSCORRUPTED
));
1942 btree
= node
->btree
;
1943 for (i
= 0; i
< be16_to_cpu(node
->hdr
.count
);
1946 <= be32_to_cpu(btree
->hashval
)) {
1947 cursor
->blkno
= be32_to_cpu(btree
->before
);
1948 xfs_attr_trace_l_cb("descending",
1953 if (i
== be16_to_cpu(node
->hdr
.count
)) {
1954 xfs_da_brelse(NULL
, bp
);
1957 xfs_da_brelse(NULL
, bp
);
1963 * Roll upward through the blocks, processing each leaf block in
1964 * order. As long as there is space in the result buffer, keep
1965 * adding the information.
1969 if (unlikely(be16_to_cpu(leaf
->hdr
.info
.magic
)
1970 != XFS_ATTR_LEAF_MAGIC
)) {
1971 XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
1973 context
->dp
->i_mount
, leaf
);
1974 xfs_da_brelse(NULL
, bp
);
1975 return(XFS_ERROR(EFSCORRUPTED
));
1977 error
= xfs_attr_leaf_list_int(bp
, context
);
1979 xfs_da_brelse(NULL
, bp
);
1982 if (context
->seen_enough
|| leaf
->hdr
.info
.forw
== 0)
1984 cursor
->blkno
= be32_to_cpu(leaf
->hdr
.info
.forw
);
1985 xfs_da_brelse(NULL
, bp
);
1986 error
= xfs_da_read_buf(NULL
, context
->dp
, cursor
->blkno
, -1,
1987 &bp
, XFS_ATTR_FORK
);
1990 if (unlikely((bp
== NULL
))) {
1991 XFS_ERROR_REPORT("xfs_attr_node_list(5)",
1993 context
->dp
->i_mount
);
1994 return(XFS_ERROR(EFSCORRUPTED
));
1997 xfs_da_brelse(NULL
, bp
);
2002 /*========================================================================
2003 * External routines for manipulating out-of-line attribute values.
2004 *========================================================================*/
2007 * Read the value associated with an attribute from the out-of-line buffer
2008 * that we stored it in.
2011 xfs_attr_rmtval_get(xfs_da_args_t
*args
)
2013 xfs_bmbt_irec_t map
[ATTR_RMTVALUE_MAPSIZE
];
2018 int nmap
, error
, tmp
, valuelen
, blkcnt
, i
;
2021 ASSERT(!(args
->flags
& ATTR_KERNOVAL
));
2023 mp
= args
->dp
->i_mount
;
2025 valuelen
= args
->valuelen
;
2026 lblkno
= args
->rmtblkno
;
2027 while (valuelen
> 0) {
2028 nmap
= ATTR_RMTVALUE_MAPSIZE
;
2029 error
= xfs_bmapi(args
->trans
, args
->dp
, (xfs_fileoff_t
)lblkno
,
2031 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2032 NULL
, 0, map
, &nmap
, NULL
, NULL
);
2037 for (i
= 0; (i
< nmap
) && (valuelen
> 0); i
++) {
2038 ASSERT((map
[i
].br_startblock
!= DELAYSTARTBLOCK
) &&
2039 (map
[i
].br_startblock
!= HOLESTARTBLOCK
));
2040 dblkno
= XFS_FSB_TO_DADDR(mp
, map
[i
].br_startblock
);
2041 blkcnt
= XFS_FSB_TO_BB(mp
, map
[i
].br_blockcount
);
2042 error
= xfs_read_buf(mp
, mp
->m_ddev_targp
, dblkno
,
2043 blkcnt
, XFS_BUF_LOCK
, &bp
);
2047 tmp
= (valuelen
< XFS_BUF_SIZE(bp
))
2048 ? valuelen
: XFS_BUF_SIZE(bp
);
2049 xfs_biomove(bp
, 0, tmp
, dst
, XFS_B_READ
);
2054 lblkno
+= map
[i
].br_blockcount
;
2057 ASSERT(valuelen
== 0);
2062 * Write the value associated with an attribute into the out-of-line buffer
2063 * that we have defined for it.
2066 xfs_attr_rmtval_set(xfs_da_args_t
*args
)
2069 xfs_fileoff_t lfileoff
;
2071 xfs_bmbt_irec_t map
;
2076 int blkcnt
, valuelen
, nmap
, error
, tmp
, committed
;
2083 * Find a "hole" in the attribute address space large enough for
2084 * us to drop the new attribute's value into.
2086 blkcnt
= XFS_B_TO_FSB(mp
, args
->valuelen
);
2088 error
= xfs_bmap_first_unused(args
->trans
, args
->dp
, blkcnt
, &lfileoff
,
2093 args
->rmtblkno
= lblkno
= (xfs_dablk_t
)lfileoff
;
2094 args
->rmtblkcnt
= blkcnt
;
2097 * Roll through the "value", allocating blocks on disk as required.
2099 while (blkcnt
> 0) {
2101 * Allocate a single extent, up to the size of the value.
2103 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2105 error
= xfs_bmapi(args
->trans
, dp
, (xfs_fileoff_t
)lblkno
,
2107 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
|
2109 args
->firstblock
, args
->total
, &map
, &nmap
,
2112 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
2118 xfs_bmap_cancel(args
->flist
);
2123 * bmap_finish() may have committed the last trans and started
2124 * a new one. We need the inode to be in all transactions.
2127 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
2128 xfs_trans_ihold(args
->trans
, dp
);
2132 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2133 (map
.br_startblock
!= HOLESTARTBLOCK
));
2134 lblkno
+= map
.br_blockcount
;
2135 blkcnt
-= map
.br_blockcount
;
2138 * Start the next trans in the chain.
2140 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
2145 * Roll through the "value", copying the attribute value to the
2146 * already-allocated blocks. Blocks are written synchronously
2147 * so that we can know they are all on disk before we turn off
2148 * the INCOMPLETE flag.
2150 lblkno
= args
->rmtblkno
;
2151 valuelen
= args
->valuelen
;
2152 while (valuelen
> 0) {
2154 * Try to remember where we decided to put the value.
2156 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2158 error
= xfs_bmapi(NULL
, dp
, (xfs_fileoff_t
)lblkno
,
2160 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2161 args
->firstblock
, 0, &map
, &nmap
,
2167 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2168 (map
.br_startblock
!= HOLESTARTBLOCK
));
2170 dblkno
= XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
2171 blkcnt
= XFS_FSB_TO_BB(mp
, map
.br_blockcount
);
2173 bp
= xfs_buf_get_flags(mp
->m_ddev_targp
, dblkno
,
2174 blkcnt
, XFS_BUF_LOCK
);
2176 ASSERT(!XFS_BUF_GETERROR(bp
));
2178 tmp
= (valuelen
< XFS_BUF_SIZE(bp
)) ? valuelen
:
2180 xfs_biomove(bp
, 0, tmp
, src
, XFS_B_WRITE
);
2181 if (tmp
< XFS_BUF_SIZE(bp
))
2182 xfs_biozero(bp
, tmp
, XFS_BUF_SIZE(bp
) - tmp
);
2183 if ((error
= xfs_bwrite(mp
, bp
))) {/* GROT: NOTE: synchronous write */
2189 lblkno
+= map
.br_blockcount
;
2191 ASSERT(valuelen
== 0);
2196 * Remove the value associated with an attribute by deleting the
2197 * out-of-line buffer that it is stored on.
2200 xfs_attr_rmtval_remove(xfs_da_args_t
*args
)
2203 xfs_bmbt_irec_t map
;
2207 int valuelen
, blkcnt
, nmap
, error
, done
, committed
;
2209 mp
= args
->dp
->i_mount
;
2212 * Roll through the "value", invalidating the attribute value's
2215 lblkno
= args
->rmtblkno
;
2216 valuelen
= args
->rmtblkcnt
;
2217 while (valuelen
> 0) {
2219 * Try to remember where we decided to put the value.
2221 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2223 error
= xfs_bmapi(NULL
, args
->dp
, (xfs_fileoff_t
)lblkno
,
2225 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2226 args
->firstblock
, 0, &map
, &nmap
,
2232 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2233 (map
.br_startblock
!= HOLESTARTBLOCK
));
2235 dblkno
= XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
2236 blkcnt
= XFS_FSB_TO_BB(mp
, map
.br_blockcount
);
2239 * If the "remote" value is in the cache, remove it.
2241 bp
= xfs_incore(mp
->m_ddev_targp
, dblkno
, blkcnt
,
2242 XFS_INCORE_TRYLOCK
);
2245 XFS_BUF_UNDELAYWRITE(bp
);
2250 valuelen
-= map
.br_blockcount
;
2252 lblkno
+= map
.br_blockcount
;
2256 * Keep de-allocating extents until the remote-value region is gone.
2258 lblkno
= args
->rmtblkno
;
2259 blkcnt
= args
->rmtblkcnt
;
2262 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2263 error
= xfs_bunmapi(args
->trans
, args
->dp
, lblkno
, blkcnt
,
2264 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2265 1, args
->firstblock
, args
->flist
,
2268 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
2274 xfs_bmap_cancel(args
->flist
);
2279 * bmap_finish() may have committed the last trans and started
2280 * a new one. We need the inode to be in all transactions.
2283 xfs_trans_ijoin(args
->trans
, args
->dp
, XFS_ILOCK_EXCL
);
2284 xfs_trans_ihold(args
->trans
, args
->dp
);
2288 * Close out trans and start the next one in the chain.
2290 if ((error
= xfs_attr_rolltrans(&args
->trans
, args
->dp
)))
2296 #if defined(XFS_ATTR_TRACE)
2298 * Add a trace buffer entry for an attr_list context structure.
2301 xfs_attr_trace_l_c(char *where
, struct xfs_attr_list_context
*context
)
2303 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_C
, where
,
2304 (__psunsigned_t
)context
->dp
,
2305 (__psunsigned_t
)context
->cursor
->hashval
,
2306 (__psunsigned_t
)context
->cursor
->blkno
,
2307 (__psunsigned_t
)context
->cursor
->offset
,
2308 (__psunsigned_t
)context
->alist
,
2309 (__psunsigned_t
)context
->bufsize
,
2310 (__psunsigned_t
)context
->count
,
2311 (__psunsigned_t
)context
->firstu
,
2313 ((context
->count
> 0) &&
2314 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2315 ? (ATTR_ENTRY(context
->alist
,
2316 context
->count
-1)->a_valuelen
)
2318 (__psunsigned_t
)context
->dupcnt
,
2319 (__psunsigned_t
)context
->flags
,
2320 (__psunsigned_t
)NULL
,
2321 (__psunsigned_t
)NULL
,
2322 (__psunsigned_t
)NULL
);
2326 * Add a trace buffer entry for a context structure and a Btree node.
2329 xfs_attr_trace_l_cn(char *where
, struct xfs_attr_list_context
*context
,
2330 struct xfs_da_intnode
*node
)
2332 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CN
, where
,
2333 (__psunsigned_t
)context
->dp
,
2334 (__psunsigned_t
)context
->cursor
->hashval
,
2335 (__psunsigned_t
)context
->cursor
->blkno
,
2336 (__psunsigned_t
)context
->cursor
->offset
,
2337 (__psunsigned_t
)context
->alist
,
2338 (__psunsigned_t
)context
->bufsize
,
2339 (__psunsigned_t
)context
->count
,
2340 (__psunsigned_t
)context
->firstu
,
2342 ((context
->count
> 0) &&
2343 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2344 ? (ATTR_ENTRY(context
->alist
,
2345 context
->count
-1)->a_valuelen
)
2347 (__psunsigned_t
)context
->dupcnt
,
2348 (__psunsigned_t
)context
->flags
,
2349 (__psunsigned_t
)be16_to_cpu(node
->hdr
.count
),
2350 (__psunsigned_t
)be32_to_cpu(node
->btree
[0].hashval
),
2351 (__psunsigned_t
)be32_to_cpu(node
->btree
[
2352 be16_to_cpu(node
->hdr
.count
)-1].hashval
));
2356 * Add a trace buffer entry for a context structure and a Btree element.
2359 xfs_attr_trace_l_cb(char *where
, struct xfs_attr_list_context
*context
,
2360 struct xfs_da_node_entry
*btree
)
2362 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CB
, where
,
2363 (__psunsigned_t
)context
->dp
,
2364 (__psunsigned_t
)context
->cursor
->hashval
,
2365 (__psunsigned_t
)context
->cursor
->blkno
,
2366 (__psunsigned_t
)context
->cursor
->offset
,
2367 (__psunsigned_t
)context
->alist
,
2368 (__psunsigned_t
)context
->bufsize
,
2369 (__psunsigned_t
)context
->count
,
2370 (__psunsigned_t
)context
->firstu
,
2372 ((context
->count
> 0) &&
2373 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2374 ? (ATTR_ENTRY(context
->alist
,
2375 context
->count
-1)->a_valuelen
)
2377 (__psunsigned_t
)context
->dupcnt
,
2378 (__psunsigned_t
)context
->flags
,
2379 (__psunsigned_t
)be32_to_cpu(btree
->hashval
),
2380 (__psunsigned_t
)be32_to_cpu(btree
->before
),
2381 (__psunsigned_t
)NULL
);
2385 * Add a trace buffer entry for a context structure and a leaf block.
2388 xfs_attr_trace_l_cl(char *where
, struct xfs_attr_list_context
*context
,
2389 struct xfs_attr_leafblock
*leaf
)
2391 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CL
, where
,
2392 (__psunsigned_t
)context
->dp
,
2393 (__psunsigned_t
)context
->cursor
->hashval
,
2394 (__psunsigned_t
)context
->cursor
->blkno
,
2395 (__psunsigned_t
)context
->cursor
->offset
,
2396 (__psunsigned_t
)context
->alist
,
2397 (__psunsigned_t
)context
->bufsize
,
2398 (__psunsigned_t
)context
->count
,
2399 (__psunsigned_t
)context
->firstu
,
2401 ((context
->count
> 0) &&
2402 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2403 ? (ATTR_ENTRY(context
->alist
,
2404 context
->count
-1)->a_valuelen
)
2406 (__psunsigned_t
)context
->dupcnt
,
2407 (__psunsigned_t
)context
->flags
,
2408 (__psunsigned_t
)be16_to_cpu(leaf
->hdr
.count
),
2409 (__psunsigned_t
)be32_to_cpu(leaf
->entries
[0].hashval
),
2410 (__psunsigned_t
)be32_to_cpu(leaf
->entries
[
2411 be16_to_cpu(leaf
->hdr
.count
)-1].hashval
));
2415 * Add a trace buffer entry for the arguments given to the routine,
2419 xfs_attr_trace_enter(int type
, char *where
,
2420 __psunsigned_t a2
, __psunsigned_t a3
,
2421 __psunsigned_t a4
, __psunsigned_t a5
,
2422 __psunsigned_t a6
, __psunsigned_t a7
,
2423 __psunsigned_t a8
, __psunsigned_t a9
,
2424 __psunsigned_t a10
, __psunsigned_t a11
,
2425 __psunsigned_t a12
, __psunsigned_t a13
,
2426 __psunsigned_t a14
, __psunsigned_t a15
)
2428 ASSERT(xfs_attr_trace_buf
);
2429 ktrace_enter(xfs_attr_trace_buf
, (void *)((__psunsigned_t
)type
),
2431 (void *)a2
, (void *)a3
, (void *)a4
,
2432 (void *)a5
, (void *)a6
, (void *)a7
,
2433 (void *)a8
, (void *)a9
, (void *)a10
,
2434 (void *)a11
, (void *)a12
, (void *)a13
,
2435 (void *)a14
, (void *)a15
);
2437 #endif /* XFS_ATTR_TRACE */
2440 /*========================================================================
2441 * System (pseudo) namespace attribute interface routines.
2442 *========================================================================*/
2445 posix_acl_access_set(
2446 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2448 return xfs_acl_vset(vp
, data
, size
, _ACL_TYPE_ACCESS
);
2452 posix_acl_access_remove(
2453 bhv_vnode_t
*vp
, char *name
, int xflags
)
2455 return xfs_acl_vremove(vp
, _ACL_TYPE_ACCESS
);
2459 posix_acl_access_get(
2460 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2462 return xfs_acl_vget(vp
, data
, size
, _ACL_TYPE_ACCESS
);
2466 posix_acl_access_exists(
2469 return xfs_acl_vhasacl_access(vp
);
2473 posix_acl_default_set(
2474 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2476 return xfs_acl_vset(vp
, data
, size
, _ACL_TYPE_DEFAULT
);
2480 posix_acl_default_get(
2481 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2483 return xfs_acl_vget(vp
, data
, size
, _ACL_TYPE_DEFAULT
);
2487 posix_acl_default_remove(
2488 bhv_vnode_t
*vp
, char *name
, int xflags
)
2490 return xfs_acl_vremove(vp
, _ACL_TYPE_DEFAULT
);
2494 posix_acl_default_exists(
2497 return xfs_acl_vhasacl_default(vp
);
2500 static struct attrnames posix_acl_access
= {
2501 .attr_name
= "posix_acl_access",
2502 .attr_namelen
= sizeof("posix_acl_access") - 1,
2503 .attr_get
= posix_acl_access_get
,
2504 .attr_set
= posix_acl_access_set
,
2505 .attr_remove
= posix_acl_access_remove
,
2506 .attr_exists
= posix_acl_access_exists
,
2509 static struct attrnames posix_acl_default
= {
2510 .attr_name
= "posix_acl_default",
2511 .attr_namelen
= sizeof("posix_acl_default") - 1,
2512 .attr_get
= posix_acl_default_get
,
2513 .attr_set
= posix_acl_default_set
,
2514 .attr_remove
= posix_acl_default_remove
,
2515 .attr_exists
= posix_acl_default_exists
,
2518 static struct attrnames
*attr_system_names
[] =
2519 { &posix_acl_access
, &posix_acl_default
};
2522 /*========================================================================
2523 * Namespace-prefix-style attribute name interface routines.
2524 *========================================================================*/
2528 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2530 return -xfs_attr_set(xfs_vtoi(vp
), name
, data
, size
, xflags
);
2535 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2537 int error
, asize
= size
;
2539 error
= xfs_attr_get(xfs_vtoi(vp
), name
, data
, &asize
, xflags
);
2546 attr_generic_remove(
2547 bhv_vnode_t
*vp
, char *name
, int xflags
)
2549 return -xfs_attr_remove(xfs_vtoi(vp
), name
, xflags
);
2553 attr_generic_listadd(
2554 attrnames_t
*prefix
,
2555 attrnames_t
*namesp
,
2560 char *p
= data
+ *result
;
2562 *result
+= prefix
->attr_namelen
;
2563 *result
+= namesp
->attr_namelen
+ 1;
2568 strcpy(p
, prefix
->attr_name
);
2569 p
+= prefix
->attr_namelen
;
2570 strcpy(p
, namesp
->attr_name
);
2571 p
+= namesp
->attr_namelen
+ 1;
2582 attrnames_t
*namesp
;
2585 for (i
= 0; i
< ATTR_SYSCOUNT
; i
++) {
2586 namesp
= attr_system_names
[i
];
2587 if (!namesp
->attr_exists
|| !namesp
->attr_exists(vp
))
2589 error
= attr_generic_listadd(&attr_system
, namesp
,
2590 data
, size
, result
);
2599 bhv_vnode_t
*vp
, void *data
, size_t size
, int xflags
, ssize_t
*result
)
2601 attrlist_cursor_kern_t cursor
= { 0 };
2604 error
= xfs_attr_list(xfs_vtoi(vp
), data
, size
, xflags
, &cursor
);
2608 return attr_system_list(vp
, data
, size
, result
);
2612 attr_lookup_namespace(
2614 struct attrnames
**names
,
2619 for (i
= 0; i
< nnames
; i
++)
2620 if (!strncmp(name
, names
[i
]->attr_name
, names
[i
]->attr_namelen
))
2626 * Some checks to prevent people abusing EAs to get over quota:
2627 * - Don't allow modifying user EAs on devices/symlinks;
2628 * - Don't allow modifying user EAs if sticky bit set;
2635 struct inode
*inode
= vn_to_inode(vp
);
2637 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
2639 if (!S_ISREG(inode
->i_mode
) && !S_ISDIR(inode
->i_mode
) &&
2640 !capable(CAP_SYS_ADMIN
))
2642 if (S_ISDIR(inode
->i_mode
) && (inode
->i_mode
& S_ISVTX
) &&
2643 (current_fsuid(cred
) != inode
->i_uid
) && !capable(CAP_FOWNER
))
2649 attr_trusted_capable(
2653 struct inode
*inode
= vn_to_inode(vp
);
2655 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
2657 if (!capable(CAP_SYS_ADMIN
))
2664 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2666 attrnames_t
*namesp
;
2669 if (xflags
& ATTR_CREATE
)
2672 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2675 error
= namesp
->attr_set(vp
, name
, data
, size
, xflags
);
2677 error
= vn_revalidate(vp
);
2683 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2685 attrnames_t
*namesp
;
2687 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2690 return namesp
->attr_get(vp
, name
, data
, size
, xflags
);
2695 bhv_vnode_t
*vp
, char *name
, int xflags
)
2697 attrnames_t
*namesp
;
2699 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2702 return namesp
->attr_remove(vp
, name
, xflags
);
2705 struct attrnames attr_system
= {
2706 .attr_name
= "system.",
2707 .attr_namelen
= sizeof("system.") - 1,
2708 .attr_flag
= ATTR_SYSTEM
,
2709 .attr_get
= attr_system_get
,
2710 .attr_set
= attr_system_set
,
2711 .attr_remove
= attr_system_remove
,
2712 .attr_capable
= (attrcapable_t
)fs_noerr
,
2715 struct attrnames attr_trusted
= {
2716 .attr_name
= "trusted.",
2717 .attr_namelen
= sizeof("trusted.") - 1,
2718 .attr_flag
= ATTR_ROOT
,
2719 .attr_get
= attr_generic_get
,
2720 .attr_set
= attr_generic_set
,
2721 .attr_remove
= attr_generic_remove
,
2722 .attr_capable
= attr_trusted_capable
,
2725 struct attrnames attr_secure
= {
2726 .attr_name
= "security.",
2727 .attr_namelen
= sizeof("security.") - 1,
2728 .attr_flag
= ATTR_SECURE
,
2729 .attr_get
= attr_generic_get
,
2730 .attr_set
= attr_generic_set
,
2731 .attr_remove
= attr_generic_remove
,
2732 .attr_capable
= (attrcapable_t
)fs_noerr
,
2735 struct attrnames attr_user
= {
2736 .attr_name
= "user.",
2737 .attr_namelen
= sizeof("user.") - 1,
2738 .attr_get
= attr_generic_get
,
2739 .attr_set
= attr_generic_set
,
2740 .attr_remove
= attr_generic_remove
,
2741 .attr_capable
= attr_user_capable
,
2744 struct attrnames
*attr_namespaces
[] =
2745 { &attr_system
, &attr_trusted
, &attr_secure
, &attr_user
};