2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <linux/capability.h>
23 #include "xfs_types.h"
27 #include "xfs_trans.h"
31 #include "xfs_dmapi.h"
32 #include "xfs_mount.h"
33 #include "xfs_da_btree.h"
34 #include "xfs_bmap_btree.h"
35 #include "xfs_alloc_btree.h"
36 #include "xfs_ialloc_btree.h"
37 #include "xfs_dir2_sf.h"
38 #include "xfs_attr_sf.h"
39 #include "xfs_dinode.h"
40 #include "xfs_inode.h"
41 #include "xfs_alloc.h"
42 #include "xfs_btree.h"
43 #include "xfs_inode_item.h"
46 #include "xfs_attr_leaf.h"
47 #include "xfs_error.h"
48 #include "xfs_quota.h"
49 #include "xfs_trans_space.h"
56 * Provide the external interfaces to manage attribute lists.
59 #define ATTR_SYSCOUNT 2
60 static struct attrnames posix_acl_access
;
61 static struct attrnames posix_acl_default
;
62 static struct attrnames
*attr_system_names
[ATTR_SYSCOUNT
];
64 /*========================================================================
65 * Function prototypes for the kernel.
66 *========================================================================*/
69 * Internal routines when attribute list fits inside the inode.
71 STATIC
int xfs_attr_shortform_addname(xfs_da_args_t
*args
);
74 * Internal routines when attribute list is one block.
76 STATIC
int xfs_attr_leaf_get(xfs_da_args_t
*args
);
77 STATIC
int xfs_attr_leaf_addname(xfs_da_args_t
*args
);
78 STATIC
int xfs_attr_leaf_removename(xfs_da_args_t
*args
);
79 STATIC
int xfs_attr_leaf_list(xfs_attr_list_context_t
*context
);
82 * Internal routines when attribute list is more than one block.
84 STATIC
int xfs_attr_node_get(xfs_da_args_t
*args
);
85 STATIC
int xfs_attr_node_addname(xfs_da_args_t
*args
);
86 STATIC
int xfs_attr_node_removename(xfs_da_args_t
*args
);
87 STATIC
int xfs_attr_node_list(xfs_attr_list_context_t
*context
);
88 STATIC
int xfs_attr_fillstate(xfs_da_state_t
*state
);
89 STATIC
int xfs_attr_refillstate(xfs_da_state_t
*state
);
92 * Routines to manipulate out-of-line attribute values.
94 STATIC
int xfs_attr_rmtval_set(xfs_da_args_t
*args
);
95 STATIC
int xfs_attr_rmtval_remove(xfs_da_args_t
*args
);
97 #define ATTR_RMTVALUE_MAPSIZE 1 /* # of map entries at once */
99 #if defined(XFS_ATTR_TRACE)
100 ktrace_t
*xfs_attr_trace_buf
;
104 /*========================================================================
105 * Overall external interface routines.
106 *========================================================================*/
109 xfs_attr_fetch(xfs_inode_t
*ip
, const char *name
, int namelen
,
110 char *value
, int *valuelenp
, int flags
, struct cred
*cred
)
115 if ((XFS_IFORK_Q(ip
) == 0) ||
116 (ip
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
117 ip
->i_d
.di_anextents
== 0))
121 * Fill in the arg structure for this request.
123 memset((char *)&args
, 0, sizeof(args
));
125 args
.namelen
= namelen
;
127 args
.valuelen
= *valuelenp
;
129 args
.hashval
= xfs_da_hashname(args
.name
, args
.namelen
);
131 args
.whichfork
= XFS_ATTR_FORK
;
134 * Decide on what work routines to call based on the inode size.
136 if (XFS_IFORK_Q(ip
) == 0 ||
137 (ip
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
138 ip
->i_d
.di_anextents
== 0)) {
139 error
= XFS_ERROR(ENOATTR
);
140 } else if (ip
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) {
141 error
= xfs_attr_shortform_getvalue(&args
);
142 } else if (xfs_bmap_one_block(ip
, XFS_ATTR_FORK
)) {
143 error
= xfs_attr_leaf_get(&args
);
145 error
= xfs_attr_node_get(&args
);
149 * Return the number of bytes in the value to the caller.
151 *valuelenp
= args
.valuelen
;
159 xfs_attr_get(bhv_desc_t
*bdp
, const char *name
, char *value
, int *valuelenp
,
160 int flags
, struct cred
*cred
)
162 xfs_inode_t
*ip
= XFS_BHVTOI(bdp
);
165 XFS_STATS_INC(xs_attr_get
);
169 namelen
= strlen(name
);
170 if (namelen
>= MAXNAMELEN
)
171 return(EFAULT
); /* match IRIX behaviour */
173 if (XFS_FORCED_SHUTDOWN(ip
->i_mount
))
176 xfs_ilock(ip
, XFS_ILOCK_SHARED
);
177 error
= xfs_attr_fetch(ip
, name
, namelen
, value
, valuelenp
, flags
, cred
);
178 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
183 xfs_attr_set_int(xfs_inode_t
*dp
, const char *name
, int namelen
,
184 char *value
, int valuelen
, int flags
)
187 xfs_fsblock_t firstblock
;
188 xfs_bmap_free_t flist
;
189 int error
, err2
, committed
;
192 xfs_mount_t
*mp
= dp
->i_mount
;
193 int rsvd
= (flags
& ATTR_ROOT
) != 0;
196 * Attach the dquots to the inode.
198 if ((error
= XFS_QM_DQATTACH(mp
, dp
, 0)))
202 * If the inode doesn't have an attribute fork, add one.
203 * (inode must not be locked when we call this routine)
205 if (XFS_IFORK_Q(dp
) == 0) {
206 int sf_size
= sizeof(xfs_attr_sf_hdr_t
) +
207 XFS_ATTR_SF_ENTSIZE_BYNAME(namelen
, valuelen
);
209 if ((error
= xfs_bmap_add_attrfork(dp
, sf_size
, rsvd
)))
214 * Fill in the arg structure for this request.
216 memset((char *)&args
, 0, sizeof(args
));
218 args
.namelen
= namelen
;
220 args
.valuelen
= valuelen
;
222 args
.hashval
= xfs_da_hashname(args
.name
, args
.namelen
);
224 args
.firstblock
= &firstblock
;
226 args
.whichfork
= XFS_ATTR_FORK
;
231 * Determine space new attribute will use, and if it would be
232 * "local" or "remote" (note: local != inline).
234 size
= xfs_attr_leaf_newentsize(namelen
, valuelen
,
235 mp
->m_sb
.sb_blocksize
, &local
);
237 nblks
= XFS_DAENTER_SPACE_RES(mp
, XFS_ATTR_FORK
);
239 if (size
> (mp
->m_sb
.sb_blocksize
>> 1)) {
240 /* Double split possible */
244 uint dblocks
= XFS_B_TO_FSB(mp
, valuelen
);
245 /* Out of line attribute, cannot double split, but make
246 * room for the attribute value itself.
249 nblks
+= XFS_NEXTENTADD_SPACE_RES(mp
, dblocks
, XFS_ATTR_FORK
);
252 /* Size is now blocks for attribute data */
256 * Start our first transaction of the day.
258 * All future transactions during this code must be "chained" off
259 * this one via the trans_dup() call. All transactions will contain
260 * the inode, and the inode will always be marked with trans_ihold().
261 * Since the inode will be locked in all transactions, we must log
262 * the inode in every transaction to let it float upward through
265 args
.trans
= xfs_trans_alloc(mp
, XFS_TRANS_ATTR_SET
);
268 * Root fork attributes can use reserved data blocks for this
269 * operation if necessary
273 args
.trans
->t_flags
|= XFS_TRANS_RESERVE
;
275 if ((error
= xfs_trans_reserve(args
.trans
, (uint
) nblks
,
276 XFS_ATTRSET_LOG_RES(mp
, nblks
),
277 0, XFS_TRANS_PERM_LOG_RES
,
278 XFS_ATTRSET_LOG_COUNT
))) {
279 xfs_trans_cancel(args
.trans
, 0);
282 xfs_ilock(dp
, XFS_ILOCK_EXCL
);
284 error
= XFS_TRANS_RESERVE_QUOTA_NBLKS(mp
, args
.trans
, dp
, nblks
, 0,
285 rsvd
? XFS_QMOPT_RES_REGBLKS
| XFS_QMOPT_FORCE_RES
:
286 XFS_QMOPT_RES_REGBLKS
);
288 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
289 xfs_trans_cancel(args
.trans
, XFS_TRANS_RELEASE_LOG_RES
);
293 xfs_trans_ijoin(args
.trans
, dp
, XFS_ILOCK_EXCL
);
294 xfs_trans_ihold(args
.trans
, dp
);
297 * If the attribute list is non-existent or a shortform list,
298 * upgrade it to a single-leaf-block attribute list.
300 if ((dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
301 ((dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
) &&
302 (dp
->i_d
.di_anextents
== 0))) {
305 * Build initial attribute list (if required).
307 if (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
)
308 xfs_attr_shortform_create(&args
);
311 * Try to add the attr to the attribute list in
314 error
= xfs_attr_shortform_addname(&args
);
315 if (error
!= ENOSPC
) {
317 * Commit the shortform mods, and we're done.
318 * NOTE: this is also the error path (EEXIST, etc).
320 ASSERT(args
.trans
!= NULL
);
323 * If this is a synchronous mount, make sure that
324 * the transaction goes to disk before returning
327 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
328 xfs_trans_set_sync(args
.trans
);
330 err2
= xfs_trans_commit(args
.trans
,
331 XFS_TRANS_RELEASE_LOG_RES
,
333 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
336 * Hit the inode change time.
338 if (!error
&& (flags
& ATTR_KERNOTIME
) == 0) {
339 xfs_ichgtime(dp
, XFS_ICHGTIME_CHG
);
341 return(error
== 0 ? err2
: error
);
345 * It won't fit in the shortform, transform to a leaf block.
346 * GROT: another possible req'mt for a double-split btree op.
348 XFS_BMAP_INIT(args
.flist
, args
.firstblock
);
349 error
= xfs_attr_shortform_to_leaf(&args
);
351 error
= xfs_bmap_finish(&args
.trans
, args
.flist
,
357 xfs_bmap_cancel(&flist
);
362 * bmap_finish() may have committed the last trans and started
363 * a new one. We need the inode to be in all transactions.
366 xfs_trans_ijoin(args
.trans
, dp
, XFS_ILOCK_EXCL
);
367 xfs_trans_ihold(args
.trans
, dp
);
371 * Commit the leaf transformation. We'll need another (linked)
372 * transaction to add the new attribute to the leaf.
374 if ((error
= xfs_attr_rolltrans(&args
.trans
, dp
)))
379 if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
380 error
= xfs_attr_leaf_addname(&args
);
382 error
= xfs_attr_node_addname(&args
);
389 * If this is a synchronous mount, make sure that the
390 * transaction goes to disk before returning to the user.
392 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
393 xfs_trans_set_sync(args
.trans
);
397 * Commit the last in the sequence of transactions.
399 xfs_trans_log_inode(args
.trans
, dp
, XFS_ILOG_CORE
);
400 error
= xfs_trans_commit(args
.trans
, XFS_TRANS_RELEASE_LOG_RES
,
402 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
405 * Hit the inode change time.
407 if (!error
&& (flags
& ATTR_KERNOTIME
) == 0) {
408 xfs_ichgtime(dp
, XFS_ICHGTIME_CHG
);
415 xfs_trans_cancel(args
.trans
,
416 XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
417 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
422 xfs_attr_set(bhv_desc_t
*bdp
, const char *name
, char *value
, int valuelen
, int flags
,
428 namelen
= strlen(name
);
429 if (namelen
>= MAXNAMELEN
)
430 return EFAULT
; /* match IRIX behaviour */
432 XFS_STATS_INC(xs_attr_set
);
434 dp
= XFS_BHVTOI(bdp
);
435 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
438 return xfs_attr_set_int(dp
, name
, namelen
, value
, valuelen
, flags
);
442 * Generic handler routine to remove a name from an attribute list.
443 * Transitions attribute list from Btree to shortform as necessary.
446 xfs_attr_remove_int(xfs_inode_t
*dp
, const char *name
, int namelen
, int flags
)
449 xfs_fsblock_t firstblock
;
450 xfs_bmap_free_t flist
;
452 xfs_mount_t
*mp
= dp
->i_mount
;
455 * Fill in the arg structure for this request.
457 memset((char *)&args
, 0, sizeof(args
));
459 args
.namelen
= namelen
;
461 args
.hashval
= xfs_da_hashname(args
.name
, args
.namelen
);
463 args
.firstblock
= &firstblock
;
466 args
.whichfork
= XFS_ATTR_FORK
;
469 * Attach the dquots to the inode.
471 if ((error
= XFS_QM_DQATTACH(mp
, dp
, 0)))
475 * Start our first transaction of the day.
477 * All future transactions during this code must be "chained" off
478 * this one via the trans_dup() call. All transactions will contain
479 * the inode, and the inode will always be marked with trans_ihold().
480 * Since the inode will be locked in all transactions, we must log
481 * the inode in every transaction to let it float upward through
484 args
.trans
= xfs_trans_alloc(mp
, XFS_TRANS_ATTR_RM
);
487 * Root fork attributes can use reserved data blocks for this
488 * operation if necessary
491 if (flags
& ATTR_ROOT
)
492 args
.trans
->t_flags
|= XFS_TRANS_RESERVE
;
494 if ((error
= xfs_trans_reserve(args
.trans
,
495 XFS_ATTRRM_SPACE_RES(mp
),
496 XFS_ATTRRM_LOG_RES(mp
),
497 0, XFS_TRANS_PERM_LOG_RES
,
498 XFS_ATTRRM_LOG_COUNT
))) {
499 xfs_trans_cancel(args
.trans
, 0);
503 xfs_ilock(dp
, XFS_ILOCK_EXCL
);
505 * No need to make quota reservations here. We expect to release some
506 * blocks not allocate in the common case.
508 xfs_trans_ijoin(args
.trans
, dp
, XFS_ILOCK_EXCL
);
509 xfs_trans_ihold(args
.trans
, dp
);
512 * Decide on what work routines to call based on the inode size.
514 if (XFS_IFORK_Q(dp
) == 0 ||
515 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
516 dp
->i_d
.di_anextents
== 0)) {
517 error
= XFS_ERROR(ENOATTR
);
520 if (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) {
521 ASSERT(dp
->i_afp
->if_flags
& XFS_IFINLINE
);
522 error
= xfs_attr_shortform_remove(&args
);
526 } else if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
527 error
= xfs_attr_leaf_removename(&args
);
529 error
= xfs_attr_node_removename(&args
);
536 * If this is a synchronous mount, make sure that the
537 * transaction goes to disk before returning to the user.
539 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
540 xfs_trans_set_sync(args
.trans
);
544 * Commit the last in the sequence of transactions.
546 xfs_trans_log_inode(args
.trans
, dp
, XFS_ILOG_CORE
);
547 error
= xfs_trans_commit(args
.trans
, XFS_TRANS_RELEASE_LOG_RES
,
549 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
552 * Hit the inode change time.
554 if (!error
&& (flags
& ATTR_KERNOTIME
) == 0) {
555 xfs_ichgtime(dp
, XFS_ICHGTIME_CHG
);
562 xfs_trans_cancel(args
.trans
,
563 XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
564 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
569 xfs_attr_remove(bhv_desc_t
*bdp
, const char *name
, int flags
, struct cred
*cred
)
574 namelen
= strlen(name
);
575 if (namelen
>= MAXNAMELEN
)
576 return EFAULT
; /* match IRIX behaviour */
578 XFS_STATS_INC(xs_attr_remove
);
580 dp
= XFS_BHVTOI(bdp
);
581 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
584 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
585 if (XFS_IFORK_Q(dp
) == 0 ||
586 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
587 dp
->i_d
.di_anextents
== 0)) {
588 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
589 return(XFS_ERROR(ENOATTR
));
591 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
593 return xfs_attr_remove_int(dp
, name
, namelen
, flags
);
597 xfs_attr_list_int(xfs_attr_list_context_t
*context
)
600 xfs_inode_t
*dp
= context
->dp
;
603 * Decide on what work routines to call based on the inode size.
605 if (XFS_IFORK_Q(dp
) == 0 ||
606 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
607 dp
->i_d
.di_anextents
== 0)) {
609 } else if (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) {
610 error
= xfs_attr_shortform_list(context
);
611 } else if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
612 error
= xfs_attr_leaf_list(context
);
614 error
= xfs_attr_node_list(context
);
619 #define ATTR_ENTBASESIZE /* minimum bytes used by an attr */ \
620 (((struct attrlist_ent *) 0)->a_name - (char *) 0)
621 #define ATTR_ENTSIZE(namelen) /* actual bytes used by an attr */ \
622 ((ATTR_ENTBASESIZE + (namelen) + 1 + sizeof(u_int32_t)-1) \
623 & ~(sizeof(u_int32_t)-1))
626 * Format an attribute and copy it out to the user's buffer.
627 * Take care to check values and protect against them changing later,
628 * we may be reading them directly out of a user buffer.
632 xfs_attr_put_listent(xfs_attr_list_context_t
*context
, attrnames_t
*namesp
,
633 char *name
, int namelen
,
634 int valuelen
, char *value
)
639 ASSERT(!(context
->flags
& ATTR_KERNOVAL
));
640 ASSERT(context
->count
>= 0);
641 ASSERT(context
->count
< (ATTR_MAX_VALUELEN
/8));
642 ASSERT(context
->firstu
>= sizeof(*context
->alist
));
643 ASSERT(context
->firstu
<= context
->bufsize
);
645 arraytop
= sizeof(*context
->alist
) +
646 context
->count
* sizeof(context
->alist
->al_offset
[0]);
647 context
->firstu
-= ATTR_ENTSIZE(namelen
);
648 if (context
->firstu
< arraytop
) {
649 xfs_attr_trace_l_c("buffer full", context
);
650 context
->alist
->al_more
= 1;
651 context
->seen_enough
= 1;
655 aep
= (attrlist_ent_t
*)&(((char *)context
->alist
)[ context
->firstu
]);
656 aep
->a_valuelen
= valuelen
;
657 memcpy(aep
->a_name
, name
, namelen
);
658 aep
->a_name
[ namelen
] = 0;
659 context
->alist
->al_offset
[ context
->count
++ ] = context
->firstu
;
660 context
->alist
->al_count
= context
->count
;
661 xfs_attr_trace_l_c("add", context
);
666 xfs_attr_kern_list(xfs_attr_list_context_t
*context
, attrnames_t
*namesp
,
667 char *name
, int namelen
,
668 int valuelen
, char *value
)
673 ASSERT(context
->count
>= 0);
675 arraytop
= context
->count
+ namesp
->attr_namelen
+ namelen
+ 1;
676 if (arraytop
> context
->firstu
) {
677 context
->count
= -1; /* insufficient space */
680 offset
= (char *)context
->alist
+ context
->count
;
681 strncpy(offset
, namesp
->attr_name
, namesp
->attr_namelen
);
682 offset
+= namesp
->attr_namelen
;
683 strncpy(offset
, name
, namelen
); /* real name */
686 context
->count
+= namesp
->attr_namelen
+ namelen
+ 1;
692 xfs_attr_kern_list_sizes(xfs_attr_list_context_t
*context
, attrnames_t
*namesp
,
693 char *name
, int namelen
,
694 int valuelen
, char *value
)
696 context
->count
+= namesp
->attr_namelen
+ namelen
+ 1;
701 * Generate a list of extended attribute names and optionally
702 * also value lengths. Positive return value follows the XFS
703 * convention of being an error, zero or negative return code
704 * is the length of the buffer returned (negated), indicating
708 xfs_attr_list(bhv_desc_t
*bdp
, char *buffer
, int bufsize
, int flags
,
709 attrlist_cursor_kern_t
*cursor
, struct cred
*cred
)
711 xfs_attr_list_context_t context
;
715 XFS_STATS_INC(xs_attr_list
);
718 * Validate the cursor.
720 if (cursor
->pad1
|| cursor
->pad2
)
721 return(XFS_ERROR(EINVAL
));
722 if ((cursor
->initted
== 0) &&
723 (cursor
->hashval
|| cursor
->blkno
|| cursor
->offset
))
724 return XFS_ERROR(EINVAL
);
727 * Check for a properly aligned buffer.
729 if (((long)buffer
) & (sizeof(int)-1))
730 return XFS_ERROR(EFAULT
);
731 if (flags
& ATTR_KERNOVAL
)
735 * Initialize the output buffer.
737 context
.dp
= dp
= XFS_BHVTOI(bdp
);
738 context
.cursor
= cursor
;
742 context
.flags
= flags
;
743 context
.seen_enough
= 0;
744 context
.alist
= (attrlist_t
*)buffer
;
745 context
.put_value
= 0;
747 if (flags
& ATTR_KERNAMELS
) {
748 context
.bufsize
= bufsize
;
749 context
.firstu
= context
.bufsize
;
750 if (flags
& ATTR_KERNOVAL
)
751 context
.put_listent
= xfs_attr_kern_list_sizes
;
753 context
.put_listent
= xfs_attr_kern_list
;
755 context
.bufsize
= (bufsize
& ~(sizeof(int)-1)); /* align */
756 context
.firstu
= context
.bufsize
;
757 context
.alist
->al_count
= 0;
758 context
.alist
->al_more
= 0;
759 context
.alist
->al_offset
[0] = context
.bufsize
;
760 context
.put_listent
= xfs_attr_put_listent
;
763 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
766 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
767 xfs_attr_trace_l_c("syscall start", &context
);
769 error
= xfs_attr_list_int(&context
);
771 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
772 xfs_attr_trace_l_c("syscall end", &context
);
774 if (context
.flags
& (ATTR_KERNOVAL
|ATTR_KERNAMELS
)) {
775 /* must return negated buffer size or the error */
776 if (context
.count
< 0)
777 error
= XFS_ERROR(ERANGE
);
779 error
= -context
.count
;
787 xfs_attr_inactive(xfs_inode_t
*dp
)
794 ASSERT(! XFS_NOT_DQATTACHED(mp
, dp
));
796 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
797 if ((XFS_IFORK_Q(dp
) == 0) ||
798 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
799 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
800 dp
->i_d
.di_anextents
== 0)) {
801 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
804 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
807 * Start our first transaction of the day.
809 * All future transactions during this code must be "chained" off
810 * this one via the trans_dup() call. All transactions will contain
811 * the inode, and the inode will always be marked with trans_ihold().
812 * Since the inode will be locked in all transactions, we must log
813 * the inode in every transaction to let it float upward through
816 trans
= xfs_trans_alloc(mp
, XFS_TRANS_ATTRINVAL
);
817 if ((error
= xfs_trans_reserve(trans
, 0, XFS_ATTRINVAL_LOG_RES(mp
), 0,
818 XFS_TRANS_PERM_LOG_RES
,
819 XFS_ATTRINVAL_LOG_COUNT
))) {
820 xfs_trans_cancel(trans
, 0);
823 xfs_ilock(dp
, XFS_ILOCK_EXCL
);
826 * No need to make quota reservations here. We expect to release some
827 * blocks, not allocate, in the common case.
829 xfs_trans_ijoin(trans
, dp
, XFS_ILOCK_EXCL
);
830 xfs_trans_ihold(trans
, dp
);
833 * Decide on what work routines to call based on the inode size.
835 if ((XFS_IFORK_Q(dp
) == 0) ||
836 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
837 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
838 dp
->i_d
.di_anextents
== 0)) {
842 error
= xfs_attr_root_inactive(&trans
, dp
);
846 * signal synchronous inactive transactions unless this
847 * is a synchronous mount filesystem in which case we
848 * know that we're here because we've been called out of
849 * xfs_inactive which means that the last reference is gone
850 * and the unlink transaction has already hit the disk so
851 * async inactive transactions are safe.
853 if ((error
= xfs_itruncate_finish(&trans
, dp
, 0LL, XFS_ATTR_FORK
,
854 (!(mp
->m_flags
& XFS_MOUNT_WSYNC
)
859 * Commit the last in the sequence of transactions.
861 xfs_trans_log_inode(trans
, dp
, XFS_ILOG_CORE
);
862 error
= xfs_trans_commit(trans
, XFS_TRANS_RELEASE_LOG_RES
,
864 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
869 xfs_trans_cancel(trans
, XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
870 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
876 /*========================================================================
877 * External routines when attribute list is inside the inode
878 *========================================================================*/
881 * Add a name to the shortform attribute list structure
882 * This is the external routine.
885 xfs_attr_shortform_addname(xfs_da_args_t
*args
)
887 int newsize
, forkoff
, retval
;
889 retval
= xfs_attr_shortform_lookup(args
);
890 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
892 } else if (retval
== EEXIST
) {
893 if (args
->flags
& ATTR_CREATE
)
895 retval
= xfs_attr_shortform_remove(args
);
899 if (args
->namelen
>= XFS_ATTR_SF_ENTSIZE_MAX
||
900 args
->valuelen
>= XFS_ATTR_SF_ENTSIZE_MAX
)
901 return(XFS_ERROR(ENOSPC
));
903 newsize
= XFS_ATTR_SF_TOTSIZE(args
->dp
);
904 newsize
+= XFS_ATTR_SF_ENTSIZE_BYNAME(args
->namelen
, args
->valuelen
);
906 forkoff
= xfs_attr_shortform_bytesfit(args
->dp
, newsize
);
908 return(XFS_ERROR(ENOSPC
));
910 xfs_attr_shortform_add(args
, forkoff
);
915 /*========================================================================
916 * External routines when attribute list is one block
917 *========================================================================*/
920 * Add a name to the leaf attribute list structure
922 * This leaf block cannot have a "remote" value, we only call this routine
923 * if bmap_one_block() says there is only one block (ie: no remote blks).
926 xfs_attr_leaf_addname(xfs_da_args_t
*args
)
930 int retval
, error
, committed
, forkoff
;
933 * Read the (only) block in the attribute list in.
937 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
944 * Look up the given attribute in the leaf block. Figure out if
945 * the given flags produce an error or call for an atomic rename.
947 retval
= xfs_attr_leaf_lookup_int(bp
, args
);
948 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
949 xfs_da_brelse(args
->trans
, bp
);
951 } else if (retval
== EEXIST
) {
952 if (args
->flags
& ATTR_CREATE
) { /* pure create op */
953 xfs_da_brelse(args
->trans
, bp
);
956 args
->rename
= 1; /* an atomic rename */
957 args
->blkno2
= args
->blkno
; /* set 2nd entry info*/
958 args
->index2
= args
->index
;
959 args
->rmtblkno2
= args
->rmtblkno
;
960 args
->rmtblkcnt2
= args
->rmtblkcnt
;
964 * Add the attribute to the leaf block, transitioning to a Btree
967 retval
= xfs_attr_leaf_add(bp
, args
);
969 if (retval
== ENOSPC
) {
971 * Promote the attribute list to the Btree format, then
972 * Commit that transaction so that the node_addname() call
973 * can manage its own transactions.
975 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
976 error
= xfs_attr_leaf_to_node(args
);
978 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
984 xfs_bmap_cancel(args
->flist
);
989 * bmap_finish() may have committed the last trans and started
990 * a new one. We need the inode to be in all transactions.
993 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
994 xfs_trans_ihold(args
->trans
, dp
);
998 * Commit the current trans (including the inode) and start
1001 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1005 * Fob the whole rest of the problem off on the Btree code.
1007 error
= xfs_attr_node_addname(args
);
1012 * Commit the transaction that added the attr name so that
1013 * later routines can manage their own transactions.
1015 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1019 * If there was an out-of-line value, allocate the blocks we
1020 * identified for its storage and copy the value. This is done
1021 * after we create the attribute so that we don't overflow the
1022 * maximum size of a transaction and/or hit a deadlock.
1024 if (args
->rmtblkno
> 0) {
1025 error
= xfs_attr_rmtval_set(args
);
1031 * If this is an atomic rename operation, we must "flip" the
1032 * incomplete flags on the "new" and "old" attribute/value pairs
1033 * so that one disappears and one appears atomically. Then we
1034 * must remove the "old" attribute/value pair.
1038 * In a separate transaction, set the incomplete flag on the
1039 * "old" attr and clear the incomplete flag on the "new" attr.
1041 error
= xfs_attr_leaf_flipflags(args
);
1046 * Dismantle the "old" attribute/value pair by removing
1047 * a "remote" value (if it exists).
1049 args
->index
= args
->index2
;
1050 args
->blkno
= args
->blkno2
;
1051 args
->rmtblkno
= args
->rmtblkno2
;
1052 args
->rmtblkcnt
= args
->rmtblkcnt2
;
1053 if (args
->rmtblkno
) {
1054 error
= xfs_attr_rmtval_remove(args
);
1060 * Read in the block containing the "old" attr, then
1061 * remove the "old" attr from that block (neat, huh!)
1063 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1,
1064 &bp
, XFS_ATTR_FORK
);
1068 (void)xfs_attr_leaf_remove(bp
, args
);
1071 * If the result is small enough, shrink it all into the inode.
1073 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1074 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1075 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1076 /* bp is gone due to xfs_da_shrink_inode */
1078 error
= xfs_bmap_finish(&args
->trans
,
1085 xfs_bmap_cancel(args
->flist
);
1090 * bmap_finish() may have committed the last trans
1091 * and started a new one. We need the inode to be
1092 * in all transactions.
1095 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1096 xfs_trans_ihold(args
->trans
, dp
);
1099 xfs_da_buf_done(bp
);
1102 * Commit the remove and start the next trans in series.
1104 error
= xfs_attr_rolltrans(&args
->trans
, dp
);
1106 } else if (args
->rmtblkno
> 0) {
1108 * Added a "remote" value, just clear the incomplete flag.
1110 error
= xfs_attr_leaf_clearflag(args
);
1116 * Remove a name from the leaf attribute list structure
1118 * This leaf block cannot have a "remote" value, we only call this routine
1119 * if bmap_one_block() says there is only one block (ie: no remote blks).
1122 xfs_attr_leaf_removename(xfs_da_args_t
*args
)
1126 int error
, committed
, forkoff
;
1129 * Remove the attribute.
1133 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
1140 error
= xfs_attr_leaf_lookup_int(bp
, args
);
1141 if (error
== ENOATTR
) {
1142 xfs_da_brelse(args
->trans
, bp
);
1146 (void)xfs_attr_leaf_remove(bp
, args
);
1149 * If the result is small enough, shrink it all into the inode.
1151 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1152 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1153 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1154 /* bp is gone due to xfs_da_shrink_inode */
1156 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1162 xfs_bmap_cancel(args
->flist
);
1167 * bmap_finish() may have committed the last trans and started
1168 * a new one. We need the inode to be in all transactions.
1171 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1172 xfs_trans_ihold(args
->trans
, dp
);
1175 xfs_da_buf_done(bp
);
1180 * Look up a name in a leaf attribute list structure.
1182 * This leaf block cannot have a "remote" value, we only call this routine
1183 * if bmap_one_block() says there is only one block (ie: no remote blks).
1186 xfs_attr_leaf_get(xfs_da_args_t
*args
)
1192 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
1198 error
= xfs_attr_leaf_lookup_int(bp
, args
);
1199 if (error
!= EEXIST
) {
1200 xfs_da_brelse(args
->trans
, bp
);
1203 error
= xfs_attr_leaf_getvalue(bp
, args
);
1204 xfs_da_brelse(args
->trans
, bp
);
1205 if (!error
&& (args
->rmtblkno
> 0) && !(args
->flags
& ATTR_KERNOVAL
)) {
1206 error
= xfs_attr_rmtval_get(args
);
1212 * Copy out attribute entries for attr_list(), for leaf attribute lists.
1215 xfs_attr_leaf_list(xfs_attr_list_context_t
*context
)
1217 xfs_attr_leafblock_t
*leaf
;
1221 context
->cursor
->blkno
= 0;
1222 error
= xfs_da_read_buf(NULL
, context
->dp
, 0, -1, &bp
, XFS_ATTR_FORK
);
1224 return XFS_ERROR(error
);
1227 if (unlikely(be16_to_cpu(leaf
->hdr
.info
.magic
) != XFS_ATTR_LEAF_MAGIC
)) {
1228 XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW
,
1229 context
->dp
->i_mount
, leaf
);
1230 xfs_da_brelse(NULL
, bp
);
1231 return XFS_ERROR(EFSCORRUPTED
);
1234 error
= xfs_attr_leaf_list_int(bp
, context
);
1235 xfs_da_brelse(NULL
, bp
);
1236 return XFS_ERROR(error
);
1240 /*========================================================================
1241 * External routines when attribute list size > XFS_LBSIZE(mp).
1242 *========================================================================*/
1245 * Add a name to a Btree-format attribute list.
1247 * This will involve walking down the Btree, and may involve splitting
1248 * leaf nodes and even splitting intermediate nodes up to and including
1249 * the root node (a special case of an intermediate node).
1251 * "Remote" attribute values confuse the issue and atomic rename operations
1252 * add a whole extra layer of confusion on top of that.
1255 xfs_attr_node_addname(xfs_da_args_t
*args
)
1257 xfs_da_state_t
*state
;
1258 xfs_da_state_blk_t
*blk
;
1261 int committed
, retval
, error
;
1264 * Fill in bucket of arguments/results/context to carry around.
1269 state
= xfs_da_state_alloc();
1272 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1273 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1276 * Search to see if name already exists, and get back a pointer
1277 * to where it should go.
1279 error
= xfs_da_node_lookup_int(state
, &retval
);
1282 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1283 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1284 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
1286 } else if (retval
== EEXIST
) {
1287 if (args
->flags
& ATTR_CREATE
)
1289 args
->rename
= 1; /* atomic rename op */
1290 args
->blkno2
= args
->blkno
; /* set 2nd entry info*/
1291 args
->index2
= args
->index
;
1292 args
->rmtblkno2
= args
->rmtblkno
;
1293 args
->rmtblkcnt2
= args
->rmtblkcnt
;
1295 args
->rmtblkcnt
= 0;
1298 retval
= xfs_attr_leaf_add(blk
->bp
, state
->args
);
1299 if (retval
== ENOSPC
) {
1300 if (state
->path
.active
== 1) {
1302 * Its really a single leaf node, but it had
1303 * out-of-line values so it looked like it *might*
1304 * have been a b-tree.
1306 xfs_da_state_free(state
);
1307 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1308 error
= xfs_attr_leaf_to_node(args
);
1310 error
= xfs_bmap_finish(&args
->trans
,
1317 xfs_bmap_cancel(args
->flist
);
1322 * bmap_finish() may have committed the last trans
1323 * and started a new one. We need the inode to be
1324 * in all transactions.
1327 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1328 xfs_trans_ihold(args
->trans
, dp
);
1332 * Commit the node conversion and start the next
1333 * trans in the chain.
1335 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1342 * Split as many Btree elements as required.
1343 * This code tracks the new and old attr's location
1344 * in the index/blkno/rmtblkno/rmtblkcnt fields and
1345 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
1347 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1348 error
= xfs_da_split(state
);
1350 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1356 xfs_bmap_cancel(args
->flist
);
1361 * bmap_finish() may have committed the last trans and started
1362 * a new one. We need the inode to be in all transactions.
1365 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1366 xfs_trans_ihold(args
->trans
, dp
);
1370 * Addition succeeded, update Btree hashvals.
1372 xfs_da_fixhashpath(state
, &state
->path
);
1376 * Kill the state structure, we're done with it and need to
1377 * allow the buffers to come back later.
1379 xfs_da_state_free(state
);
1383 * Commit the leaf addition or btree split and start the next
1384 * trans in the chain.
1386 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1390 * If there was an out-of-line value, allocate the blocks we
1391 * identified for its storage and copy the value. This is done
1392 * after we create the attribute so that we don't overflow the
1393 * maximum size of a transaction and/or hit a deadlock.
1395 if (args
->rmtblkno
> 0) {
1396 error
= xfs_attr_rmtval_set(args
);
1402 * If this is an atomic rename operation, we must "flip" the
1403 * incomplete flags on the "new" and "old" attribute/value pairs
1404 * so that one disappears and one appears atomically. Then we
1405 * must remove the "old" attribute/value pair.
1409 * In a separate transaction, set the incomplete flag on the
1410 * "old" attr and clear the incomplete flag on the "new" attr.
1412 error
= xfs_attr_leaf_flipflags(args
);
1417 * Dismantle the "old" attribute/value pair by removing
1418 * a "remote" value (if it exists).
1420 args
->index
= args
->index2
;
1421 args
->blkno
= args
->blkno2
;
1422 args
->rmtblkno
= args
->rmtblkno2
;
1423 args
->rmtblkcnt
= args
->rmtblkcnt2
;
1424 if (args
->rmtblkno
) {
1425 error
= xfs_attr_rmtval_remove(args
);
1431 * Re-find the "old" attribute entry after any split ops.
1432 * The INCOMPLETE flag means that we will find the "old"
1433 * attr, not the "new" one.
1435 args
->flags
|= XFS_ATTR_INCOMPLETE
;
1436 state
= xfs_da_state_alloc();
1439 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1440 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1442 error
= xfs_da_node_lookup_int(state
, &retval
);
1447 * Remove the name and update the hashvals in the tree.
1449 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1450 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1451 error
= xfs_attr_leaf_remove(blk
->bp
, args
);
1452 xfs_da_fixhashpath(state
, &state
->path
);
1455 * Check to see if the tree needs to be collapsed.
1457 if (retval
&& (state
->path
.active
> 1)) {
1458 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1459 error
= xfs_da_join(state
);
1461 error
= xfs_bmap_finish(&args
->trans
,
1468 xfs_bmap_cancel(args
->flist
);
1473 * bmap_finish() may have committed the last trans
1474 * and started a new one. We need the inode to be
1475 * in all transactions.
1478 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1479 xfs_trans_ihold(args
->trans
, dp
);
1484 * Commit and start the next trans in the chain.
1486 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1489 } else if (args
->rmtblkno
> 0) {
1491 * Added a "remote" value, just clear the incomplete flag.
1493 error
= xfs_attr_leaf_clearflag(args
);
1501 xfs_da_state_free(state
);
1508 * Remove a name from a B-tree attribute list.
1510 * This will involve walking down the Btree, and may involve joining
1511 * leaf nodes and even joining intermediate nodes up to and including
1512 * the root node (a special case of an intermediate node).
1515 xfs_attr_node_removename(xfs_da_args_t
*args
)
1517 xfs_da_state_t
*state
;
1518 xfs_da_state_blk_t
*blk
;
1521 int retval
, error
, committed
, forkoff
;
1524 * Tie a string around our finger to remind us where we are.
1527 state
= xfs_da_state_alloc();
1529 state
->mp
= dp
->i_mount
;
1530 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1531 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1534 * Search to see if name exists, and get back a pointer to it.
1536 error
= xfs_da_node_lookup_int(state
, &retval
);
1537 if (error
|| (retval
!= EEXIST
)) {
1544 * If there is an out-of-line value, de-allocate the blocks.
1545 * This is done before we remove the attribute so that we don't
1546 * overflow the maximum size of a transaction and/or hit a deadlock.
1548 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1549 ASSERT(blk
->bp
!= NULL
);
1550 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1551 if (args
->rmtblkno
> 0) {
1553 * Fill in disk block numbers in the state structure
1554 * so that we can get the buffers back after we commit
1555 * several transactions in the following calls.
1557 error
= xfs_attr_fillstate(state
);
1562 * Mark the attribute as INCOMPLETE, then bunmapi() the
1565 error
= xfs_attr_leaf_setflag(args
);
1568 error
= xfs_attr_rmtval_remove(args
);
1573 * Refill the state structure with buffers, the prior calls
1574 * released our buffers.
1576 error
= xfs_attr_refillstate(state
);
1582 * Remove the name and update the hashvals in the tree.
1584 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1585 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1586 retval
= xfs_attr_leaf_remove(blk
->bp
, args
);
1587 xfs_da_fixhashpath(state
, &state
->path
);
1590 * Check to see if the tree needs to be collapsed.
1592 if (retval
&& (state
->path
.active
> 1)) {
1593 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1594 error
= xfs_da_join(state
);
1596 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1602 xfs_bmap_cancel(args
->flist
);
1607 * bmap_finish() may have committed the last trans and started
1608 * a new one. We need the inode to be in all transactions.
1611 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1612 xfs_trans_ihold(args
->trans
, dp
);
1616 * Commit the Btree join operation and start a new trans.
1618 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1623 * If the result is small enough, push it all into the inode.
1625 if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
1627 * Have to get rid of the copy of this dabuf in the state.
1629 ASSERT(state
->path
.active
== 1);
1630 ASSERT(state
->path
.blk
[0].bp
);
1631 xfs_da_buf_done(state
->path
.blk
[0].bp
);
1632 state
->path
.blk
[0].bp
= NULL
;
1634 error
= xfs_da_read_buf(args
->trans
, args
->dp
, 0, -1, &bp
,
1638 ASSERT(be16_to_cpu(((xfs_attr_leafblock_t
*)
1639 bp
->data
)->hdr
.info
.magic
)
1640 == XFS_ATTR_LEAF_MAGIC
);
1642 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1643 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1644 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1645 /* bp is gone due to xfs_da_shrink_inode */
1647 error
= xfs_bmap_finish(&args
->trans
,
1654 xfs_bmap_cancel(args
->flist
);
1659 * bmap_finish() may have committed the last trans
1660 * and started a new one. We need the inode to be
1661 * in all transactions.
1664 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1665 xfs_trans_ihold(args
->trans
, dp
);
1668 xfs_da_brelse(args
->trans
, bp
);
1673 xfs_da_state_free(state
);
1678 * Fill in the disk block numbers in the state structure for the buffers
1679 * that are attached to the state structure.
1680 * This is done so that we can quickly reattach ourselves to those buffers
1681 * after some set of transaction commits have released these buffers.
1684 xfs_attr_fillstate(xfs_da_state_t
*state
)
1686 xfs_da_state_path_t
*path
;
1687 xfs_da_state_blk_t
*blk
;
1691 * Roll down the "path" in the state structure, storing the on-disk
1692 * block number for those buffers in the "path".
1694 path
= &state
->path
;
1695 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1696 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1698 blk
->disk_blkno
= xfs_da_blkno(blk
->bp
);
1699 xfs_da_buf_done(blk
->bp
);
1702 blk
->disk_blkno
= 0;
1707 * Roll down the "altpath" in the state structure, storing the on-disk
1708 * block number for those buffers in the "altpath".
1710 path
= &state
->altpath
;
1711 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1712 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1714 blk
->disk_blkno
= xfs_da_blkno(blk
->bp
);
1715 xfs_da_buf_done(blk
->bp
);
1718 blk
->disk_blkno
= 0;
1726 * Reattach the buffers to the state structure based on the disk block
1727 * numbers stored in the state structure.
1728 * This is done after some set of transaction commits have released those
1729 * buffers from our grip.
1732 xfs_attr_refillstate(xfs_da_state_t
*state
)
1734 xfs_da_state_path_t
*path
;
1735 xfs_da_state_blk_t
*blk
;
1739 * Roll down the "path" in the state structure, storing the on-disk
1740 * block number for those buffers in the "path".
1742 path
= &state
->path
;
1743 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1744 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1745 if (blk
->disk_blkno
) {
1746 error
= xfs_da_read_buf(state
->args
->trans
,
1748 blk
->blkno
, blk
->disk_blkno
,
1749 &blk
->bp
, XFS_ATTR_FORK
);
1758 * Roll down the "altpath" in the state structure, storing the on-disk
1759 * block number for those buffers in the "altpath".
1761 path
= &state
->altpath
;
1762 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1763 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1764 if (blk
->disk_blkno
) {
1765 error
= xfs_da_read_buf(state
->args
->trans
,
1767 blk
->blkno
, blk
->disk_blkno
,
1768 &blk
->bp
, XFS_ATTR_FORK
);
1780 * Look up a filename in a node attribute list.
1782 * This routine gets called for any attribute fork that has more than one
1783 * block, ie: both true Btree attr lists and for single-leaf-blocks with
1784 * "remote" values taking up more blocks.
1787 xfs_attr_node_get(xfs_da_args_t
*args
)
1789 xfs_da_state_t
*state
;
1790 xfs_da_state_blk_t
*blk
;
1794 state
= xfs_da_state_alloc();
1796 state
->mp
= args
->dp
->i_mount
;
1797 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1798 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1801 * Search to see if name exists, and get back a pointer to it.
1803 error
= xfs_da_node_lookup_int(state
, &retval
);
1806 } else if (retval
== EEXIST
) {
1807 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1808 ASSERT(blk
->bp
!= NULL
);
1809 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1812 * Get the value, local or "remote"
1814 retval
= xfs_attr_leaf_getvalue(blk
->bp
, args
);
1815 if (!retval
&& (args
->rmtblkno
> 0)
1816 && !(args
->flags
& ATTR_KERNOVAL
)) {
1817 retval
= xfs_attr_rmtval_get(args
);
1822 * If not in a transaction, we have to release all the buffers.
1824 for (i
= 0; i
< state
->path
.active
; i
++) {
1825 xfs_da_brelse(args
->trans
, state
->path
.blk
[i
].bp
);
1826 state
->path
.blk
[i
].bp
= NULL
;
1829 xfs_da_state_free(state
);
1833 STATIC
int /* error */
1834 xfs_attr_node_list(xfs_attr_list_context_t
*context
)
1836 attrlist_cursor_kern_t
*cursor
;
1837 xfs_attr_leafblock_t
*leaf
;
1838 xfs_da_intnode_t
*node
;
1839 xfs_da_node_entry_t
*btree
;
1843 cursor
= context
->cursor
;
1844 cursor
->initted
= 1;
1847 * Do all sorts of validation on the passed-in cursor structure.
1848 * If anything is amiss, ignore the cursor and look up the hashval
1849 * starting from the btree root.
1852 if (cursor
->blkno
> 0) {
1853 error
= xfs_da_read_buf(NULL
, context
->dp
, cursor
->blkno
, -1,
1854 &bp
, XFS_ATTR_FORK
);
1855 if ((error
!= 0) && (error
!= EFSCORRUPTED
))
1859 switch (be16_to_cpu(node
->hdr
.info
.magic
)) {
1860 case XFS_DA_NODE_MAGIC
:
1861 xfs_attr_trace_l_cn("wrong blk", context
, node
);
1862 xfs_da_brelse(NULL
, bp
);
1865 case XFS_ATTR_LEAF_MAGIC
:
1867 if (cursor
->hashval
> be32_to_cpu(leaf
->entries
[
1868 be16_to_cpu(leaf
->hdr
.count
)-1].hashval
)) {
1869 xfs_attr_trace_l_cl("wrong blk",
1871 xfs_da_brelse(NULL
, bp
);
1873 } else if (cursor
->hashval
<=
1874 be32_to_cpu(leaf
->entries
[0].hashval
)) {
1875 xfs_attr_trace_l_cl("maybe wrong blk",
1877 xfs_da_brelse(NULL
, bp
);
1882 xfs_attr_trace_l_c("wrong blk - ??", context
);
1883 xfs_da_brelse(NULL
, bp
);
1890 * We did not find what we expected given the cursor's contents,
1891 * so we start from the top and work down based on the hash value.
1892 * Note that start of node block is same as start of leaf block.
1897 error
= xfs_da_read_buf(NULL
, context
->dp
,
1898 cursor
->blkno
, -1, &bp
,
1902 if (unlikely(bp
== NULL
)) {
1903 XFS_ERROR_REPORT("xfs_attr_node_list(2)",
1905 context
->dp
->i_mount
);
1906 return(XFS_ERROR(EFSCORRUPTED
));
1909 if (be16_to_cpu(node
->hdr
.info
.magic
)
1910 == XFS_ATTR_LEAF_MAGIC
)
1912 if (unlikely(be16_to_cpu(node
->hdr
.info
.magic
)
1913 != XFS_DA_NODE_MAGIC
)) {
1914 XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
1916 context
->dp
->i_mount
,
1918 xfs_da_brelse(NULL
, bp
);
1919 return(XFS_ERROR(EFSCORRUPTED
));
1921 btree
= node
->btree
;
1922 for (i
= 0; i
< be16_to_cpu(node
->hdr
.count
);
1925 <= be32_to_cpu(btree
->hashval
)) {
1926 cursor
->blkno
= be32_to_cpu(btree
->before
);
1927 xfs_attr_trace_l_cb("descending",
1932 if (i
== be16_to_cpu(node
->hdr
.count
)) {
1933 xfs_da_brelse(NULL
, bp
);
1936 xfs_da_brelse(NULL
, bp
);
1942 * Roll upward through the blocks, processing each leaf block in
1943 * order. As long as there is space in the result buffer, keep
1944 * adding the information.
1948 if (unlikely(be16_to_cpu(leaf
->hdr
.info
.magic
)
1949 != XFS_ATTR_LEAF_MAGIC
)) {
1950 XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
1952 context
->dp
->i_mount
, leaf
);
1953 xfs_da_brelse(NULL
, bp
);
1954 return(XFS_ERROR(EFSCORRUPTED
));
1956 error
= xfs_attr_leaf_list_int(bp
, context
);
1958 xfs_da_brelse(NULL
, bp
);
1961 if (context
->seen_enough
|| leaf
->hdr
.info
.forw
== 0)
1963 cursor
->blkno
= be32_to_cpu(leaf
->hdr
.info
.forw
);
1964 xfs_da_brelse(NULL
, bp
);
1965 error
= xfs_da_read_buf(NULL
, context
->dp
, cursor
->blkno
, -1,
1966 &bp
, XFS_ATTR_FORK
);
1969 if (unlikely((bp
== NULL
))) {
1970 XFS_ERROR_REPORT("xfs_attr_node_list(5)",
1972 context
->dp
->i_mount
);
1973 return(XFS_ERROR(EFSCORRUPTED
));
1976 xfs_da_brelse(NULL
, bp
);
1981 /*========================================================================
1982 * External routines for manipulating out-of-line attribute values.
1983 *========================================================================*/
1986 * Read the value associated with an attribute from the out-of-line buffer
1987 * that we stored it in.
1990 xfs_attr_rmtval_get(xfs_da_args_t
*args
)
1992 xfs_bmbt_irec_t map
[ATTR_RMTVALUE_MAPSIZE
];
1997 int nmap
, error
, tmp
, valuelen
, blkcnt
, i
;
2000 ASSERT(!(args
->flags
& ATTR_KERNOVAL
));
2002 mp
= args
->dp
->i_mount
;
2004 valuelen
= args
->valuelen
;
2005 lblkno
= args
->rmtblkno
;
2006 while (valuelen
> 0) {
2007 nmap
= ATTR_RMTVALUE_MAPSIZE
;
2008 error
= xfs_bmapi(args
->trans
, args
->dp
, (xfs_fileoff_t
)lblkno
,
2010 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2011 NULL
, 0, map
, &nmap
, NULL
, NULL
);
2016 for (i
= 0; (i
< nmap
) && (valuelen
> 0); i
++) {
2017 ASSERT((map
[i
].br_startblock
!= DELAYSTARTBLOCK
) &&
2018 (map
[i
].br_startblock
!= HOLESTARTBLOCK
));
2019 dblkno
= XFS_FSB_TO_DADDR(mp
, map
[i
].br_startblock
);
2020 blkcnt
= XFS_FSB_TO_BB(mp
, map
[i
].br_blockcount
);
2021 error
= xfs_read_buf(mp
, mp
->m_ddev_targp
, dblkno
,
2022 blkcnt
, XFS_BUF_LOCK
, &bp
);
2026 tmp
= (valuelen
< XFS_BUF_SIZE(bp
))
2027 ? valuelen
: XFS_BUF_SIZE(bp
);
2028 xfs_biomove(bp
, 0, tmp
, dst
, XFS_B_READ
);
2033 lblkno
+= map
[i
].br_blockcount
;
2036 ASSERT(valuelen
== 0);
2041 * Write the value associated with an attribute into the out-of-line buffer
2042 * that we have defined for it.
2045 xfs_attr_rmtval_set(xfs_da_args_t
*args
)
2048 xfs_fileoff_t lfileoff
;
2050 xfs_bmbt_irec_t map
;
2055 int blkcnt
, valuelen
, nmap
, error
, tmp
, committed
;
2062 * Find a "hole" in the attribute address space large enough for
2063 * us to drop the new attribute's value into.
2065 blkcnt
= XFS_B_TO_FSB(mp
, args
->valuelen
);
2067 error
= xfs_bmap_first_unused(args
->trans
, args
->dp
, blkcnt
, &lfileoff
,
2072 args
->rmtblkno
= lblkno
= (xfs_dablk_t
)lfileoff
;
2073 args
->rmtblkcnt
= blkcnt
;
2076 * Roll through the "value", allocating blocks on disk as required.
2078 while (blkcnt
> 0) {
2080 * Allocate a single extent, up to the size of the value.
2082 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2084 error
= xfs_bmapi(args
->trans
, dp
, (xfs_fileoff_t
)lblkno
,
2086 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
|
2088 args
->firstblock
, args
->total
, &map
, &nmap
,
2091 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
2097 xfs_bmap_cancel(args
->flist
);
2102 * bmap_finish() may have committed the last trans and started
2103 * a new one. We need the inode to be in all transactions.
2106 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
2107 xfs_trans_ihold(args
->trans
, dp
);
2111 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2112 (map
.br_startblock
!= HOLESTARTBLOCK
));
2113 lblkno
+= map
.br_blockcount
;
2114 blkcnt
-= map
.br_blockcount
;
2117 * Start the next trans in the chain.
2119 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
2124 * Roll through the "value", copying the attribute value to the
2125 * already-allocated blocks. Blocks are written synchronously
2126 * so that we can know they are all on disk before we turn off
2127 * the INCOMPLETE flag.
2129 lblkno
= args
->rmtblkno
;
2130 valuelen
= args
->valuelen
;
2131 while (valuelen
> 0) {
2133 * Try to remember where we decided to put the value.
2135 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2137 error
= xfs_bmapi(NULL
, dp
, (xfs_fileoff_t
)lblkno
,
2139 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2140 args
->firstblock
, 0, &map
, &nmap
,
2146 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2147 (map
.br_startblock
!= HOLESTARTBLOCK
));
2149 dblkno
= XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
2150 blkcnt
= XFS_FSB_TO_BB(mp
, map
.br_blockcount
);
2152 bp
= xfs_buf_get_flags(mp
->m_ddev_targp
, dblkno
,
2153 blkcnt
, XFS_BUF_LOCK
);
2155 ASSERT(!XFS_BUF_GETERROR(bp
));
2157 tmp
= (valuelen
< XFS_BUF_SIZE(bp
)) ? valuelen
:
2159 xfs_biomove(bp
, 0, tmp
, src
, XFS_B_WRITE
);
2160 if (tmp
< XFS_BUF_SIZE(bp
))
2161 xfs_biozero(bp
, tmp
, XFS_BUF_SIZE(bp
) - tmp
);
2162 if ((error
= xfs_bwrite(mp
, bp
))) {/* GROT: NOTE: synchronous write */
2168 lblkno
+= map
.br_blockcount
;
2170 ASSERT(valuelen
== 0);
2175 * Remove the value associated with an attribute by deleting the
2176 * out-of-line buffer that it is stored on.
2179 xfs_attr_rmtval_remove(xfs_da_args_t
*args
)
2182 xfs_bmbt_irec_t map
;
2186 int valuelen
, blkcnt
, nmap
, error
, done
, committed
;
2188 mp
= args
->dp
->i_mount
;
2191 * Roll through the "value", invalidating the attribute value's
2194 lblkno
= args
->rmtblkno
;
2195 valuelen
= args
->rmtblkcnt
;
2196 while (valuelen
> 0) {
2198 * Try to remember where we decided to put the value.
2200 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2202 error
= xfs_bmapi(NULL
, args
->dp
, (xfs_fileoff_t
)lblkno
,
2204 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2205 args
->firstblock
, 0, &map
, &nmap
,
2211 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2212 (map
.br_startblock
!= HOLESTARTBLOCK
));
2214 dblkno
= XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
2215 blkcnt
= XFS_FSB_TO_BB(mp
, map
.br_blockcount
);
2218 * If the "remote" value is in the cache, remove it.
2220 bp
= xfs_incore(mp
->m_ddev_targp
, dblkno
, blkcnt
,
2221 XFS_INCORE_TRYLOCK
);
2224 XFS_BUF_UNDELAYWRITE(bp
);
2229 valuelen
-= map
.br_blockcount
;
2231 lblkno
+= map
.br_blockcount
;
2235 * Keep de-allocating extents until the remote-value region is gone.
2237 lblkno
= args
->rmtblkno
;
2238 blkcnt
= args
->rmtblkcnt
;
2241 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2242 error
= xfs_bunmapi(args
->trans
, args
->dp
, lblkno
, blkcnt
,
2243 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2244 1, args
->firstblock
, args
->flist
,
2247 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
2253 xfs_bmap_cancel(args
->flist
);
2258 * bmap_finish() may have committed the last trans and started
2259 * a new one. We need the inode to be in all transactions.
2262 xfs_trans_ijoin(args
->trans
, args
->dp
, XFS_ILOCK_EXCL
);
2263 xfs_trans_ihold(args
->trans
, args
->dp
);
2267 * Close out trans and start the next one in the chain.
2269 if ((error
= xfs_attr_rolltrans(&args
->trans
, args
->dp
)))
2275 #if defined(XFS_ATTR_TRACE)
2277 * Add a trace buffer entry for an attr_list context structure.
2280 xfs_attr_trace_l_c(char *where
, struct xfs_attr_list_context
*context
)
2282 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_C
, where
,
2283 (__psunsigned_t
)context
->dp
,
2284 (__psunsigned_t
)context
->cursor
->hashval
,
2285 (__psunsigned_t
)context
->cursor
->blkno
,
2286 (__psunsigned_t
)context
->cursor
->offset
,
2287 (__psunsigned_t
)context
->alist
,
2288 (__psunsigned_t
)context
->bufsize
,
2289 (__psunsigned_t
)context
->count
,
2290 (__psunsigned_t
)context
->firstu
,
2292 ((context
->count
> 0) &&
2293 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2294 ? (ATTR_ENTRY(context
->alist
,
2295 context
->count
-1)->a_valuelen
)
2297 (__psunsigned_t
)context
->dupcnt
,
2298 (__psunsigned_t
)context
->flags
,
2299 (__psunsigned_t
)NULL
,
2300 (__psunsigned_t
)NULL
,
2301 (__psunsigned_t
)NULL
);
2305 * Add a trace buffer entry for a context structure and a Btree node.
2308 xfs_attr_trace_l_cn(char *where
, struct xfs_attr_list_context
*context
,
2309 struct xfs_da_intnode
*node
)
2311 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CN
, where
,
2312 (__psunsigned_t
)context
->dp
,
2313 (__psunsigned_t
)context
->cursor
->hashval
,
2314 (__psunsigned_t
)context
->cursor
->blkno
,
2315 (__psunsigned_t
)context
->cursor
->offset
,
2316 (__psunsigned_t
)context
->alist
,
2317 (__psunsigned_t
)context
->bufsize
,
2318 (__psunsigned_t
)context
->count
,
2319 (__psunsigned_t
)context
->firstu
,
2321 ((context
->count
> 0) &&
2322 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2323 ? (ATTR_ENTRY(context
->alist
,
2324 context
->count
-1)->a_valuelen
)
2326 (__psunsigned_t
)context
->dupcnt
,
2327 (__psunsigned_t
)context
->flags
,
2328 (__psunsigned_t
)be16_to_cpu(node
->hdr
.count
),
2329 (__psunsigned_t
)be32_to_cpu(node
->btree
[0].hashval
),
2330 (__psunsigned_t
)be32_to_cpu(node
->btree
[
2331 be16_to_cpu(node
->hdr
.count
)-1].hashval
));
2335 * Add a trace buffer entry for a context structure and a Btree element.
2338 xfs_attr_trace_l_cb(char *where
, struct xfs_attr_list_context
*context
,
2339 struct xfs_da_node_entry
*btree
)
2341 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CB
, where
,
2342 (__psunsigned_t
)context
->dp
,
2343 (__psunsigned_t
)context
->cursor
->hashval
,
2344 (__psunsigned_t
)context
->cursor
->blkno
,
2345 (__psunsigned_t
)context
->cursor
->offset
,
2346 (__psunsigned_t
)context
->alist
,
2347 (__psunsigned_t
)context
->bufsize
,
2348 (__psunsigned_t
)context
->count
,
2349 (__psunsigned_t
)context
->firstu
,
2351 ((context
->count
> 0) &&
2352 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2353 ? (ATTR_ENTRY(context
->alist
,
2354 context
->count
-1)->a_valuelen
)
2356 (__psunsigned_t
)context
->dupcnt
,
2357 (__psunsigned_t
)context
->flags
,
2358 (__psunsigned_t
)be32_to_cpu(btree
->hashval
),
2359 (__psunsigned_t
)be32_to_cpu(btree
->before
),
2360 (__psunsigned_t
)NULL
);
2364 * Add a trace buffer entry for a context structure and a leaf block.
2367 xfs_attr_trace_l_cl(char *where
, struct xfs_attr_list_context
*context
,
2368 struct xfs_attr_leafblock
*leaf
)
2370 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CL
, where
,
2371 (__psunsigned_t
)context
->dp
,
2372 (__psunsigned_t
)context
->cursor
->hashval
,
2373 (__psunsigned_t
)context
->cursor
->blkno
,
2374 (__psunsigned_t
)context
->cursor
->offset
,
2375 (__psunsigned_t
)context
->alist
,
2376 (__psunsigned_t
)context
->bufsize
,
2377 (__psunsigned_t
)context
->count
,
2378 (__psunsigned_t
)context
->firstu
,
2380 ((context
->count
> 0) &&
2381 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2382 ? (ATTR_ENTRY(context
->alist
,
2383 context
->count
-1)->a_valuelen
)
2385 (__psunsigned_t
)context
->dupcnt
,
2386 (__psunsigned_t
)context
->flags
,
2387 (__psunsigned_t
)be16_to_cpu(leaf
->hdr
.count
),
2388 (__psunsigned_t
)be32_to_cpu(leaf
->entries
[0].hashval
),
2389 (__psunsigned_t
)be32_to_cpu(leaf
->entries
[
2390 be16_to_cpu(leaf
->hdr
.count
)-1].hashval
));
2394 * Add a trace buffer entry for the arguments given to the routine,
2398 xfs_attr_trace_enter(int type
, char *where
,
2399 __psunsigned_t a2
, __psunsigned_t a3
,
2400 __psunsigned_t a4
, __psunsigned_t a5
,
2401 __psunsigned_t a6
, __psunsigned_t a7
,
2402 __psunsigned_t a8
, __psunsigned_t a9
,
2403 __psunsigned_t a10
, __psunsigned_t a11
,
2404 __psunsigned_t a12
, __psunsigned_t a13
,
2405 __psunsigned_t a14
, __psunsigned_t a15
)
2407 ASSERT(xfs_attr_trace_buf
);
2408 ktrace_enter(xfs_attr_trace_buf
, (void *)((__psunsigned_t
)type
),
2410 (void *)a2
, (void *)a3
, (void *)a4
,
2411 (void *)a5
, (void *)a6
, (void *)a7
,
2412 (void *)a8
, (void *)a9
, (void *)a10
,
2413 (void *)a11
, (void *)a12
, (void *)a13
,
2414 (void *)a14
, (void *)a15
);
2416 #endif /* XFS_ATTR_TRACE */
2419 /*========================================================================
2420 * System (pseudo) namespace attribute interface routines.
2421 *========================================================================*/
2424 posix_acl_access_set(
2425 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2427 return xfs_acl_vset(vp
, data
, size
, _ACL_TYPE_ACCESS
);
2431 posix_acl_access_remove(
2432 bhv_vnode_t
*vp
, char *name
, int xflags
)
2434 return xfs_acl_vremove(vp
, _ACL_TYPE_ACCESS
);
2438 posix_acl_access_get(
2439 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2441 return xfs_acl_vget(vp
, data
, size
, _ACL_TYPE_ACCESS
);
2445 posix_acl_access_exists(
2448 return xfs_acl_vhasacl_access(vp
);
2452 posix_acl_default_set(
2453 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2455 return xfs_acl_vset(vp
, data
, size
, _ACL_TYPE_DEFAULT
);
2459 posix_acl_default_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_DEFAULT
);
2466 posix_acl_default_remove(
2467 bhv_vnode_t
*vp
, char *name
, int xflags
)
2469 return xfs_acl_vremove(vp
, _ACL_TYPE_DEFAULT
);
2473 posix_acl_default_exists(
2476 return xfs_acl_vhasacl_default(vp
);
2479 static struct attrnames posix_acl_access
= {
2480 .attr_name
= "posix_acl_access",
2481 .attr_namelen
= sizeof("posix_acl_access") - 1,
2482 .attr_get
= posix_acl_access_get
,
2483 .attr_set
= posix_acl_access_set
,
2484 .attr_remove
= posix_acl_access_remove
,
2485 .attr_exists
= posix_acl_access_exists
,
2488 static struct attrnames posix_acl_default
= {
2489 .attr_name
= "posix_acl_default",
2490 .attr_namelen
= sizeof("posix_acl_default") - 1,
2491 .attr_get
= posix_acl_default_get
,
2492 .attr_set
= posix_acl_default_set
,
2493 .attr_remove
= posix_acl_default_remove
,
2494 .attr_exists
= posix_acl_default_exists
,
2497 static struct attrnames
*attr_system_names
[] =
2498 { &posix_acl_access
, &posix_acl_default
};
2501 /*========================================================================
2502 * Namespace-prefix-style attribute name interface routines.
2503 *========================================================================*/
2507 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2509 return -bhv_vop_attr_set(vp
, name
, data
, size
, xflags
, NULL
);
2514 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2516 int error
, asize
= size
;
2518 error
= bhv_vop_attr_get(vp
, name
, data
, &asize
, xflags
, NULL
);
2525 attr_generic_remove(
2526 bhv_vnode_t
*vp
, char *name
, int xflags
)
2528 return -bhv_vop_attr_remove(vp
, name
, xflags
, NULL
);
2532 attr_generic_listadd(
2533 attrnames_t
*prefix
,
2534 attrnames_t
*namesp
,
2539 char *p
= data
+ *result
;
2541 *result
+= prefix
->attr_namelen
;
2542 *result
+= namesp
->attr_namelen
+ 1;
2547 strcpy(p
, prefix
->attr_name
);
2548 p
+= prefix
->attr_namelen
;
2549 strcpy(p
, namesp
->attr_name
);
2550 p
+= namesp
->attr_namelen
+ 1;
2561 attrnames_t
*namesp
;
2564 for (i
= 0; i
< ATTR_SYSCOUNT
; i
++) {
2565 namesp
= attr_system_names
[i
];
2566 if (!namesp
->attr_exists
|| !namesp
->attr_exists(vp
))
2568 error
= attr_generic_listadd(&attr_system
, namesp
,
2569 data
, size
, result
);
2578 bhv_vnode_t
*vp
, void *data
, size_t size
, int xflags
, ssize_t
*result
)
2580 attrlist_cursor_kern_t cursor
= { 0 };
2583 error
= bhv_vop_attr_list(vp
, data
, size
, xflags
, &cursor
, NULL
);
2587 return attr_system_list(vp
, data
, size
, result
);
2591 attr_lookup_namespace(
2593 struct attrnames
**names
,
2598 for (i
= 0; i
< nnames
; i
++)
2599 if (!strncmp(name
, names
[i
]->attr_name
, names
[i
]->attr_namelen
))
2605 * Some checks to prevent people abusing EAs to get over quota:
2606 * - Don't allow modifying user EAs on devices/symlinks;
2607 * - Don't allow modifying user EAs if sticky bit set;
2614 struct inode
*inode
= vn_to_inode(vp
);
2616 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
2618 if (!S_ISREG(inode
->i_mode
) && !S_ISDIR(inode
->i_mode
) &&
2619 !capable(CAP_SYS_ADMIN
))
2621 if (S_ISDIR(inode
->i_mode
) && (inode
->i_mode
& S_ISVTX
) &&
2622 (current_fsuid(cred
) != inode
->i_uid
) && !capable(CAP_FOWNER
))
2628 attr_trusted_capable(
2632 struct inode
*inode
= vn_to_inode(vp
);
2634 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
2636 if (!capable(CAP_SYS_ADMIN
))
2642 attr_secure_capable(
2646 return -ENOSECURITY
;
2651 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2653 attrnames_t
*namesp
;
2656 if (xflags
& ATTR_CREATE
)
2659 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2662 error
= namesp
->attr_set(vp
, name
, data
, size
, xflags
);
2664 error
= vn_revalidate(vp
);
2670 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2672 attrnames_t
*namesp
;
2674 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2677 return namesp
->attr_get(vp
, name
, data
, size
, xflags
);
2682 bhv_vnode_t
*vp
, char *name
, int xflags
)
2684 attrnames_t
*namesp
;
2686 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2689 return namesp
->attr_remove(vp
, name
, xflags
);
2692 struct attrnames attr_system
= {
2693 .attr_name
= "system.",
2694 .attr_namelen
= sizeof("system.") - 1,
2695 .attr_flag
= ATTR_SYSTEM
,
2696 .attr_get
= attr_system_get
,
2697 .attr_set
= attr_system_set
,
2698 .attr_remove
= attr_system_remove
,
2699 .attr_capable
= (attrcapable_t
)fs_noerr
,
2702 struct attrnames attr_trusted
= {
2703 .attr_name
= "trusted.",
2704 .attr_namelen
= sizeof("trusted.") - 1,
2705 .attr_flag
= ATTR_ROOT
,
2706 .attr_get
= attr_generic_get
,
2707 .attr_set
= attr_generic_set
,
2708 .attr_remove
= attr_generic_remove
,
2709 .attr_capable
= attr_trusted_capable
,
2712 struct attrnames attr_secure
= {
2713 .attr_name
= "security.",
2714 .attr_namelen
= sizeof("security.") - 1,
2715 .attr_flag
= ATTR_SECURE
,
2716 .attr_get
= attr_generic_get
,
2717 .attr_set
= attr_generic_set
,
2718 .attr_remove
= attr_generic_remove
,
2719 .attr_capable
= attr_secure_capable
,
2722 struct attrnames attr_user
= {
2723 .attr_name
= "user.",
2724 .attr_namelen
= sizeof("user.") - 1,
2725 .attr_get
= attr_generic_get
,
2726 .attr_set
= attr_generic_set
,
2727 .attr_remove
= attr_generic_remove
,
2728 .attr_capable
= attr_user_capable
,
2731 struct attrnames
*attr_namespaces
[] =
2732 { &attr_system
, &attr_trusted
, &attr_secure
, &attr_user
};