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
);
332 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
335 * Hit the inode change time.
337 if (!error
&& (flags
& ATTR_KERNOTIME
) == 0) {
338 xfs_ichgtime(dp
, XFS_ICHGTIME_CHG
);
340 return(error
== 0 ? err2
: error
);
344 * It won't fit in the shortform, transform to a leaf block.
345 * GROT: another possible req'mt for a double-split btree op.
347 XFS_BMAP_INIT(args
.flist
, args
.firstblock
);
348 error
= xfs_attr_shortform_to_leaf(&args
);
350 error
= xfs_bmap_finish(&args
.trans
, args
.flist
,
356 xfs_bmap_cancel(&flist
);
361 * bmap_finish() may have committed the last trans and started
362 * a new one. We need the inode to be in all transactions.
365 xfs_trans_ijoin(args
.trans
, dp
, XFS_ILOCK_EXCL
);
366 xfs_trans_ihold(args
.trans
, dp
);
370 * Commit the leaf transformation. We'll need another (linked)
371 * transaction to add the new attribute to the leaf.
373 if ((error
= xfs_attr_rolltrans(&args
.trans
, dp
)))
378 if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
379 error
= xfs_attr_leaf_addname(&args
);
381 error
= xfs_attr_node_addname(&args
);
388 * If this is a synchronous mount, make sure that the
389 * transaction goes to disk before returning to the user.
391 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
392 xfs_trans_set_sync(args
.trans
);
396 * Commit the last in the sequence of transactions.
398 xfs_trans_log_inode(args
.trans
, dp
, XFS_ILOG_CORE
);
399 error
= xfs_trans_commit(args
.trans
, XFS_TRANS_RELEASE_LOG_RES
);
400 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
403 * Hit the inode change time.
405 if (!error
&& (flags
& ATTR_KERNOTIME
) == 0) {
406 xfs_ichgtime(dp
, XFS_ICHGTIME_CHG
);
413 xfs_trans_cancel(args
.trans
,
414 XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
415 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
420 xfs_attr_set(bhv_desc_t
*bdp
, const char *name
, char *value
, int valuelen
, int flags
,
426 namelen
= strlen(name
);
427 if (namelen
>= MAXNAMELEN
)
428 return EFAULT
; /* match IRIX behaviour */
430 XFS_STATS_INC(xs_attr_set
);
432 dp
= XFS_BHVTOI(bdp
);
433 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
436 return xfs_attr_set_int(dp
, name
, namelen
, value
, valuelen
, flags
);
440 * Generic handler routine to remove a name from an attribute list.
441 * Transitions attribute list from Btree to shortform as necessary.
444 xfs_attr_remove_int(xfs_inode_t
*dp
, const char *name
, int namelen
, int flags
)
447 xfs_fsblock_t firstblock
;
448 xfs_bmap_free_t flist
;
450 xfs_mount_t
*mp
= dp
->i_mount
;
453 * Fill in the arg structure for this request.
455 memset((char *)&args
, 0, sizeof(args
));
457 args
.namelen
= namelen
;
459 args
.hashval
= xfs_da_hashname(args
.name
, args
.namelen
);
461 args
.firstblock
= &firstblock
;
464 args
.whichfork
= XFS_ATTR_FORK
;
467 * Attach the dquots to the inode.
469 if ((error
= XFS_QM_DQATTACH(mp
, dp
, 0)))
473 * Start our first transaction of the day.
475 * All future transactions during this code must be "chained" off
476 * this one via the trans_dup() call. All transactions will contain
477 * the inode, and the inode will always be marked with trans_ihold().
478 * Since the inode will be locked in all transactions, we must log
479 * the inode in every transaction to let it float upward through
482 args
.trans
= xfs_trans_alloc(mp
, XFS_TRANS_ATTR_RM
);
485 * Root fork attributes can use reserved data blocks for this
486 * operation if necessary
489 if (flags
& ATTR_ROOT
)
490 args
.trans
->t_flags
|= XFS_TRANS_RESERVE
;
492 if ((error
= xfs_trans_reserve(args
.trans
,
493 XFS_ATTRRM_SPACE_RES(mp
),
494 XFS_ATTRRM_LOG_RES(mp
),
495 0, XFS_TRANS_PERM_LOG_RES
,
496 XFS_ATTRRM_LOG_COUNT
))) {
497 xfs_trans_cancel(args
.trans
, 0);
501 xfs_ilock(dp
, XFS_ILOCK_EXCL
);
503 * No need to make quota reservations here. We expect to release some
504 * blocks not allocate in the common case.
506 xfs_trans_ijoin(args
.trans
, dp
, XFS_ILOCK_EXCL
);
507 xfs_trans_ihold(args
.trans
, dp
);
510 * Decide on what work routines to call based on the inode size.
512 if (XFS_IFORK_Q(dp
) == 0 ||
513 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
514 dp
->i_d
.di_anextents
== 0)) {
515 error
= XFS_ERROR(ENOATTR
);
518 if (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) {
519 ASSERT(dp
->i_afp
->if_flags
& XFS_IFINLINE
);
520 error
= xfs_attr_shortform_remove(&args
);
524 } else if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
525 error
= xfs_attr_leaf_removename(&args
);
527 error
= xfs_attr_node_removename(&args
);
534 * If this is a synchronous mount, make sure that the
535 * transaction goes to disk before returning to the user.
537 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
538 xfs_trans_set_sync(args
.trans
);
542 * Commit the last in the sequence of transactions.
544 xfs_trans_log_inode(args
.trans
, dp
, XFS_ILOG_CORE
);
545 error
= xfs_trans_commit(args
.trans
, XFS_TRANS_RELEASE_LOG_RES
);
546 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
549 * Hit the inode change time.
551 if (!error
&& (flags
& ATTR_KERNOTIME
) == 0) {
552 xfs_ichgtime(dp
, XFS_ICHGTIME_CHG
);
559 xfs_trans_cancel(args
.trans
,
560 XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
561 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
566 xfs_attr_remove(bhv_desc_t
*bdp
, const char *name
, int flags
, struct cred
*cred
)
571 namelen
= strlen(name
);
572 if (namelen
>= MAXNAMELEN
)
573 return EFAULT
; /* match IRIX behaviour */
575 XFS_STATS_INC(xs_attr_remove
);
577 dp
= XFS_BHVTOI(bdp
);
578 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
581 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
582 if (XFS_IFORK_Q(dp
) == 0 ||
583 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
584 dp
->i_d
.di_anextents
== 0)) {
585 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
586 return(XFS_ERROR(ENOATTR
));
588 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
590 return xfs_attr_remove_int(dp
, name
, namelen
, flags
);
594 xfs_attr_list_int(xfs_attr_list_context_t
*context
)
597 xfs_inode_t
*dp
= context
->dp
;
600 * Decide on what work routines to call based on the inode size.
602 if (XFS_IFORK_Q(dp
) == 0 ||
603 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
604 dp
->i_d
.di_anextents
== 0)) {
606 } else if (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) {
607 error
= xfs_attr_shortform_list(context
);
608 } else if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
609 error
= xfs_attr_leaf_list(context
);
611 error
= xfs_attr_node_list(context
);
616 #define ATTR_ENTBASESIZE /* minimum bytes used by an attr */ \
617 (((struct attrlist_ent *) 0)->a_name - (char *) 0)
618 #define ATTR_ENTSIZE(namelen) /* actual bytes used by an attr */ \
619 ((ATTR_ENTBASESIZE + (namelen) + 1 + sizeof(u_int32_t)-1) \
620 & ~(sizeof(u_int32_t)-1))
623 * Format an attribute and copy it out to the user's buffer.
624 * Take care to check values and protect against them changing later,
625 * we may be reading them directly out of a user buffer.
629 xfs_attr_put_listent(xfs_attr_list_context_t
*context
, attrnames_t
*namesp
,
630 char *name
, int namelen
,
631 int valuelen
, char *value
)
636 ASSERT(!(context
->flags
& ATTR_KERNOVAL
));
637 ASSERT(context
->count
>= 0);
638 ASSERT(context
->count
< (ATTR_MAX_VALUELEN
/8));
639 ASSERT(context
->firstu
>= sizeof(*context
->alist
));
640 ASSERT(context
->firstu
<= context
->bufsize
);
642 arraytop
= sizeof(*context
->alist
) +
643 context
->count
* sizeof(context
->alist
->al_offset
[0]);
644 context
->firstu
-= ATTR_ENTSIZE(namelen
);
645 if (context
->firstu
< arraytop
) {
646 xfs_attr_trace_l_c("buffer full", context
);
647 context
->alist
->al_more
= 1;
648 context
->seen_enough
= 1;
652 aep
= (attrlist_ent_t
*)&(((char *)context
->alist
)[ context
->firstu
]);
653 aep
->a_valuelen
= valuelen
;
654 memcpy(aep
->a_name
, name
, namelen
);
655 aep
->a_name
[ namelen
] = 0;
656 context
->alist
->al_offset
[ context
->count
++ ] = context
->firstu
;
657 context
->alist
->al_count
= context
->count
;
658 xfs_attr_trace_l_c("add", context
);
663 xfs_attr_kern_list(xfs_attr_list_context_t
*context
, attrnames_t
*namesp
,
664 char *name
, int namelen
,
665 int valuelen
, char *value
)
670 ASSERT(context
->count
>= 0);
672 arraytop
= context
->count
+ namesp
->attr_namelen
+ namelen
+ 1;
673 if (arraytop
> context
->firstu
) {
674 context
->count
= -1; /* insufficient space */
677 offset
= (char *)context
->alist
+ context
->count
;
678 strncpy(offset
, namesp
->attr_name
, namesp
->attr_namelen
);
679 offset
+= namesp
->attr_namelen
;
680 strncpy(offset
, name
, namelen
); /* real name */
683 context
->count
+= namesp
->attr_namelen
+ namelen
+ 1;
689 xfs_attr_kern_list_sizes(xfs_attr_list_context_t
*context
, attrnames_t
*namesp
,
690 char *name
, int namelen
,
691 int valuelen
, char *value
)
693 context
->count
+= namesp
->attr_namelen
+ namelen
+ 1;
698 * Generate a list of extended attribute names and optionally
699 * also value lengths. Positive return value follows the XFS
700 * convention of being an error, zero or negative return code
701 * is the length of the buffer returned (negated), indicating
705 xfs_attr_list(bhv_desc_t
*bdp
, char *buffer
, int bufsize
, int flags
,
706 attrlist_cursor_kern_t
*cursor
, struct cred
*cred
)
708 xfs_attr_list_context_t context
;
712 XFS_STATS_INC(xs_attr_list
);
715 * Validate the cursor.
717 if (cursor
->pad1
|| cursor
->pad2
)
718 return(XFS_ERROR(EINVAL
));
719 if ((cursor
->initted
== 0) &&
720 (cursor
->hashval
|| cursor
->blkno
|| cursor
->offset
))
721 return XFS_ERROR(EINVAL
);
724 * Check for a properly aligned buffer.
726 if (((long)buffer
) & (sizeof(int)-1))
727 return XFS_ERROR(EFAULT
);
728 if (flags
& ATTR_KERNOVAL
)
732 * Initialize the output buffer.
734 context
.dp
= dp
= XFS_BHVTOI(bdp
);
735 context
.cursor
= cursor
;
739 context
.flags
= flags
;
740 context
.seen_enough
= 0;
741 context
.alist
= (attrlist_t
*)buffer
;
742 context
.put_value
= 0;
744 if (flags
& ATTR_KERNAMELS
) {
745 context
.bufsize
= bufsize
;
746 context
.firstu
= context
.bufsize
;
747 if (flags
& ATTR_KERNOVAL
)
748 context
.put_listent
= xfs_attr_kern_list_sizes
;
750 context
.put_listent
= xfs_attr_kern_list
;
752 context
.bufsize
= (bufsize
& ~(sizeof(int)-1)); /* align */
753 context
.firstu
= context
.bufsize
;
754 context
.alist
->al_count
= 0;
755 context
.alist
->al_more
= 0;
756 context
.alist
->al_offset
[0] = context
.bufsize
;
757 context
.put_listent
= xfs_attr_put_listent
;
760 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
763 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
764 xfs_attr_trace_l_c("syscall start", &context
);
766 error
= xfs_attr_list_int(&context
);
768 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
769 xfs_attr_trace_l_c("syscall end", &context
);
771 if (context
.flags
& (ATTR_KERNOVAL
|ATTR_KERNAMELS
)) {
772 /* must return negated buffer size or the error */
773 if (context
.count
< 0)
774 error
= XFS_ERROR(ERANGE
);
776 error
= -context
.count
;
784 xfs_attr_inactive(xfs_inode_t
*dp
)
791 ASSERT(! XFS_NOT_DQATTACHED(mp
, dp
));
793 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
794 if ((XFS_IFORK_Q(dp
) == 0) ||
795 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
796 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
797 dp
->i_d
.di_anextents
== 0)) {
798 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
801 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
804 * Start our first transaction of the day.
806 * All future transactions during this code must be "chained" off
807 * this one via the trans_dup() call. All transactions will contain
808 * the inode, and the inode will always be marked with trans_ihold().
809 * Since the inode will be locked in all transactions, we must log
810 * the inode in every transaction to let it float upward through
813 trans
= xfs_trans_alloc(mp
, XFS_TRANS_ATTRINVAL
);
814 if ((error
= xfs_trans_reserve(trans
, 0, XFS_ATTRINVAL_LOG_RES(mp
), 0,
815 XFS_TRANS_PERM_LOG_RES
,
816 XFS_ATTRINVAL_LOG_COUNT
))) {
817 xfs_trans_cancel(trans
, 0);
820 xfs_ilock(dp
, XFS_ILOCK_EXCL
);
823 * No need to make quota reservations here. We expect to release some
824 * blocks, not allocate, in the common case.
826 xfs_trans_ijoin(trans
, dp
, XFS_ILOCK_EXCL
);
827 xfs_trans_ihold(trans
, dp
);
830 * Decide on what work routines to call based on the inode size.
832 if ((XFS_IFORK_Q(dp
) == 0) ||
833 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
834 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
835 dp
->i_d
.di_anextents
== 0)) {
839 error
= xfs_attr_root_inactive(&trans
, dp
);
843 * signal synchronous inactive transactions unless this
844 * is a synchronous mount filesystem in which case we
845 * know that we're here because we've been called out of
846 * xfs_inactive which means that the last reference is gone
847 * and the unlink transaction has already hit the disk so
848 * async inactive transactions are safe.
850 if ((error
= xfs_itruncate_finish(&trans
, dp
, 0LL, XFS_ATTR_FORK
,
851 (!(mp
->m_flags
& XFS_MOUNT_WSYNC
)
856 * Commit the last in the sequence of transactions.
858 xfs_trans_log_inode(trans
, dp
, XFS_ILOG_CORE
);
859 error
= xfs_trans_commit(trans
, XFS_TRANS_RELEASE_LOG_RES
);
860 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
865 xfs_trans_cancel(trans
, XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
866 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
872 /*========================================================================
873 * External routines when attribute list is inside the inode
874 *========================================================================*/
877 * Add a name to the shortform attribute list structure
878 * This is the external routine.
881 xfs_attr_shortform_addname(xfs_da_args_t
*args
)
883 int newsize
, forkoff
, retval
;
885 retval
= xfs_attr_shortform_lookup(args
);
886 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
888 } else if (retval
== EEXIST
) {
889 if (args
->flags
& ATTR_CREATE
)
891 retval
= xfs_attr_shortform_remove(args
);
895 if (args
->namelen
>= XFS_ATTR_SF_ENTSIZE_MAX
||
896 args
->valuelen
>= XFS_ATTR_SF_ENTSIZE_MAX
)
897 return(XFS_ERROR(ENOSPC
));
899 newsize
= XFS_ATTR_SF_TOTSIZE(args
->dp
);
900 newsize
+= XFS_ATTR_SF_ENTSIZE_BYNAME(args
->namelen
, args
->valuelen
);
902 forkoff
= xfs_attr_shortform_bytesfit(args
->dp
, newsize
);
904 return(XFS_ERROR(ENOSPC
));
906 xfs_attr_shortform_add(args
, forkoff
);
911 /*========================================================================
912 * External routines when attribute list is one block
913 *========================================================================*/
916 * Add a name to the leaf attribute list structure
918 * This leaf block cannot have a "remote" value, we only call this routine
919 * if bmap_one_block() says there is only one block (ie: no remote blks).
922 xfs_attr_leaf_addname(xfs_da_args_t
*args
)
926 int retval
, error
, committed
, forkoff
;
929 * Read the (only) block in the attribute list in.
933 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
940 * Look up the given attribute in the leaf block. Figure out if
941 * the given flags produce an error or call for an atomic rename.
943 retval
= xfs_attr_leaf_lookup_int(bp
, args
);
944 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
945 xfs_da_brelse(args
->trans
, bp
);
947 } else if (retval
== EEXIST
) {
948 if (args
->flags
& ATTR_CREATE
) { /* pure create op */
949 xfs_da_brelse(args
->trans
, bp
);
952 args
->rename
= 1; /* an atomic rename */
953 args
->blkno2
= args
->blkno
; /* set 2nd entry info*/
954 args
->index2
= args
->index
;
955 args
->rmtblkno2
= args
->rmtblkno
;
956 args
->rmtblkcnt2
= args
->rmtblkcnt
;
960 * Add the attribute to the leaf block, transitioning to a Btree
963 retval
= xfs_attr_leaf_add(bp
, args
);
965 if (retval
== ENOSPC
) {
967 * Promote the attribute list to the Btree format, then
968 * Commit that transaction so that the node_addname() call
969 * can manage its own transactions.
971 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
972 error
= xfs_attr_leaf_to_node(args
);
974 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
980 xfs_bmap_cancel(args
->flist
);
985 * bmap_finish() may have committed the last trans and started
986 * a new one. We need the inode to be in all transactions.
989 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
990 xfs_trans_ihold(args
->trans
, dp
);
994 * Commit the current trans (including the inode) and start
997 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1001 * Fob the whole rest of the problem off on the Btree code.
1003 error
= xfs_attr_node_addname(args
);
1008 * Commit the transaction that added the attr name so that
1009 * later routines can manage their own transactions.
1011 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1015 * If there was an out-of-line value, allocate the blocks we
1016 * identified for its storage and copy the value. This is done
1017 * after we create the attribute so that we don't overflow the
1018 * maximum size of a transaction and/or hit a deadlock.
1020 if (args
->rmtblkno
> 0) {
1021 error
= xfs_attr_rmtval_set(args
);
1027 * If this is an atomic rename operation, we must "flip" the
1028 * incomplete flags on the "new" and "old" attribute/value pairs
1029 * so that one disappears and one appears atomically. Then we
1030 * must remove the "old" attribute/value pair.
1034 * In a separate transaction, set the incomplete flag on the
1035 * "old" attr and clear the incomplete flag on the "new" attr.
1037 error
= xfs_attr_leaf_flipflags(args
);
1042 * Dismantle the "old" attribute/value pair by removing
1043 * a "remote" value (if it exists).
1045 args
->index
= args
->index2
;
1046 args
->blkno
= args
->blkno2
;
1047 args
->rmtblkno
= args
->rmtblkno2
;
1048 args
->rmtblkcnt
= args
->rmtblkcnt2
;
1049 if (args
->rmtblkno
) {
1050 error
= xfs_attr_rmtval_remove(args
);
1056 * Read in the block containing the "old" attr, then
1057 * remove the "old" attr from that block (neat, huh!)
1059 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1,
1060 &bp
, XFS_ATTR_FORK
);
1064 (void)xfs_attr_leaf_remove(bp
, args
);
1067 * If the result is small enough, shrink it all into the inode.
1069 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1070 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1071 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1072 /* bp is gone due to xfs_da_shrink_inode */
1074 error
= xfs_bmap_finish(&args
->trans
,
1081 xfs_bmap_cancel(args
->flist
);
1086 * bmap_finish() may have committed the last trans
1087 * and started a new one. We need the inode to be
1088 * in all transactions.
1091 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1092 xfs_trans_ihold(args
->trans
, dp
);
1095 xfs_da_buf_done(bp
);
1098 * Commit the remove and start the next trans in series.
1100 error
= xfs_attr_rolltrans(&args
->trans
, dp
);
1102 } else if (args
->rmtblkno
> 0) {
1104 * Added a "remote" value, just clear the incomplete flag.
1106 error
= xfs_attr_leaf_clearflag(args
);
1112 * Remove a name from the leaf attribute list structure
1114 * This leaf block cannot have a "remote" value, we only call this routine
1115 * if bmap_one_block() says there is only one block (ie: no remote blks).
1118 xfs_attr_leaf_removename(xfs_da_args_t
*args
)
1122 int error
, committed
, forkoff
;
1125 * Remove the attribute.
1129 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
1136 error
= xfs_attr_leaf_lookup_int(bp
, args
);
1137 if (error
== ENOATTR
) {
1138 xfs_da_brelse(args
->trans
, bp
);
1142 (void)xfs_attr_leaf_remove(bp
, args
);
1145 * If the result is small enough, shrink it all into the inode.
1147 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1148 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1149 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1150 /* bp is gone due to xfs_da_shrink_inode */
1152 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1158 xfs_bmap_cancel(args
->flist
);
1163 * bmap_finish() may have committed the last trans and started
1164 * a new one. We need the inode to be in all transactions.
1167 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1168 xfs_trans_ihold(args
->trans
, dp
);
1171 xfs_da_buf_done(bp
);
1176 * Look up a name in a leaf attribute list structure.
1178 * This leaf block cannot have a "remote" value, we only call this routine
1179 * if bmap_one_block() says there is only one block (ie: no remote blks).
1182 xfs_attr_leaf_get(xfs_da_args_t
*args
)
1188 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
1194 error
= xfs_attr_leaf_lookup_int(bp
, args
);
1195 if (error
!= EEXIST
) {
1196 xfs_da_brelse(args
->trans
, bp
);
1199 error
= xfs_attr_leaf_getvalue(bp
, args
);
1200 xfs_da_brelse(args
->trans
, bp
);
1201 if (!error
&& (args
->rmtblkno
> 0) && !(args
->flags
& ATTR_KERNOVAL
)) {
1202 error
= xfs_attr_rmtval_get(args
);
1208 * Copy out attribute entries for attr_list(), for leaf attribute lists.
1211 xfs_attr_leaf_list(xfs_attr_list_context_t
*context
)
1213 xfs_attr_leafblock_t
*leaf
;
1217 context
->cursor
->blkno
= 0;
1218 error
= xfs_da_read_buf(NULL
, context
->dp
, 0, -1, &bp
, XFS_ATTR_FORK
);
1220 return XFS_ERROR(error
);
1223 if (unlikely(be16_to_cpu(leaf
->hdr
.info
.magic
) != XFS_ATTR_LEAF_MAGIC
)) {
1224 XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW
,
1225 context
->dp
->i_mount
, leaf
);
1226 xfs_da_brelse(NULL
, bp
);
1227 return XFS_ERROR(EFSCORRUPTED
);
1230 error
= xfs_attr_leaf_list_int(bp
, context
);
1231 xfs_da_brelse(NULL
, bp
);
1232 return XFS_ERROR(error
);
1236 /*========================================================================
1237 * External routines when attribute list size > XFS_LBSIZE(mp).
1238 *========================================================================*/
1241 * Add a name to a Btree-format attribute list.
1243 * This will involve walking down the Btree, and may involve splitting
1244 * leaf nodes and even splitting intermediate nodes up to and including
1245 * the root node (a special case of an intermediate node).
1247 * "Remote" attribute values confuse the issue and atomic rename operations
1248 * add a whole extra layer of confusion on top of that.
1251 xfs_attr_node_addname(xfs_da_args_t
*args
)
1253 xfs_da_state_t
*state
;
1254 xfs_da_state_blk_t
*blk
;
1257 int committed
, retval
, error
;
1260 * Fill in bucket of arguments/results/context to carry around.
1265 state
= xfs_da_state_alloc();
1268 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1269 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1272 * Search to see if name already exists, and get back a pointer
1273 * to where it should go.
1275 error
= xfs_da_node_lookup_int(state
, &retval
);
1278 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1279 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1280 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
1282 } else if (retval
== EEXIST
) {
1283 if (args
->flags
& ATTR_CREATE
)
1285 args
->rename
= 1; /* atomic rename op */
1286 args
->blkno2
= args
->blkno
; /* set 2nd entry info*/
1287 args
->index2
= args
->index
;
1288 args
->rmtblkno2
= args
->rmtblkno
;
1289 args
->rmtblkcnt2
= args
->rmtblkcnt
;
1291 args
->rmtblkcnt
= 0;
1294 retval
= xfs_attr_leaf_add(blk
->bp
, state
->args
);
1295 if (retval
== ENOSPC
) {
1296 if (state
->path
.active
== 1) {
1298 * Its really a single leaf node, but it had
1299 * out-of-line values so it looked like it *might*
1300 * have been a b-tree.
1302 xfs_da_state_free(state
);
1303 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1304 error
= xfs_attr_leaf_to_node(args
);
1306 error
= xfs_bmap_finish(&args
->trans
,
1313 xfs_bmap_cancel(args
->flist
);
1318 * bmap_finish() may have committed the last trans
1319 * and started a new one. We need the inode to be
1320 * in all transactions.
1323 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1324 xfs_trans_ihold(args
->trans
, dp
);
1328 * Commit the node conversion and start the next
1329 * trans in the chain.
1331 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1338 * Split as many Btree elements as required.
1339 * This code tracks the new and old attr's location
1340 * in the index/blkno/rmtblkno/rmtblkcnt fields and
1341 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
1343 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1344 error
= xfs_da_split(state
);
1346 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1352 xfs_bmap_cancel(args
->flist
);
1357 * bmap_finish() may have committed the last trans and started
1358 * a new one. We need the inode to be in all transactions.
1361 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1362 xfs_trans_ihold(args
->trans
, dp
);
1366 * Addition succeeded, update Btree hashvals.
1368 xfs_da_fixhashpath(state
, &state
->path
);
1372 * Kill the state structure, we're done with it and need to
1373 * allow the buffers to come back later.
1375 xfs_da_state_free(state
);
1379 * Commit the leaf addition or btree split and start the next
1380 * trans in the chain.
1382 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1386 * If there was an out-of-line value, allocate the blocks we
1387 * identified for its storage and copy the value. This is done
1388 * after we create the attribute so that we don't overflow the
1389 * maximum size of a transaction and/or hit a deadlock.
1391 if (args
->rmtblkno
> 0) {
1392 error
= xfs_attr_rmtval_set(args
);
1398 * If this is an atomic rename operation, we must "flip" the
1399 * incomplete flags on the "new" and "old" attribute/value pairs
1400 * so that one disappears and one appears atomically. Then we
1401 * must remove the "old" attribute/value pair.
1405 * In a separate transaction, set the incomplete flag on the
1406 * "old" attr and clear the incomplete flag on the "new" attr.
1408 error
= xfs_attr_leaf_flipflags(args
);
1413 * Dismantle the "old" attribute/value pair by removing
1414 * a "remote" value (if it exists).
1416 args
->index
= args
->index2
;
1417 args
->blkno
= args
->blkno2
;
1418 args
->rmtblkno
= args
->rmtblkno2
;
1419 args
->rmtblkcnt
= args
->rmtblkcnt2
;
1420 if (args
->rmtblkno
) {
1421 error
= xfs_attr_rmtval_remove(args
);
1427 * Re-find the "old" attribute entry after any split ops.
1428 * The INCOMPLETE flag means that we will find the "old"
1429 * attr, not the "new" one.
1431 args
->flags
|= XFS_ATTR_INCOMPLETE
;
1432 state
= xfs_da_state_alloc();
1435 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1436 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1438 error
= xfs_da_node_lookup_int(state
, &retval
);
1443 * Remove the name and update the hashvals in the tree.
1445 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1446 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1447 error
= xfs_attr_leaf_remove(blk
->bp
, args
);
1448 xfs_da_fixhashpath(state
, &state
->path
);
1451 * Check to see if the tree needs to be collapsed.
1453 if (retval
&& (state
->path
.active
> 1)) {
1454 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1455 error
= xfs_da_join(state
);
1457 error
= xfs_bmap_finish(&args
->trans
,
1464 xfs_bmap_cancel(args
->flist
);
1469 * bmap_finish() may have committed the last trans
1470 * and started a new one. We need the inode to be
1471 * in all transactions.
1474 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1475 xfs_trans_ihold(args
->trans
, dp
);
1480 * Commit and start the next trans in the chain.
1482 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1485 } else if (args
->rmtblkno
> 0) {
1487 * Added a "remote" value, just clear the incomplete flag.
1489 error
= xfs_attr_leaf_clearflag(args
);
1497 xfs_da_state_free(state
);
1504 * Remove a name from a B-tree attribute list.
1506 * This will involve walking down the Btree, and may involve joining
1507 * leaf nodes and even joining intermediate nodes up to and including
1508 * the root node (a special case of an intermediate node).
1511 xfs_attr_node_removename(xfs_da_args_t
*args
)
1513 xfs_da_state_t
*state
;
1514 xfs_da_state_blk_t
*blk
;
1517 int retval
, error
, committed
, forkoff
;
1520 * Tie a string around our finger to remind us where we are.
1523 state
= xfs_da_state_alloc();
1525 state
->mp
= dp
->i_mount
;
1526 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1527 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1530 * Search to see if name exists, and get back a pointer to it.
1532 error
= xfs_da_node_lookup_int(state
, &retval
);
1533 if (error
|| (retval
!= EEXIST
)) {
1540 * If there is an out-of-line value, de-allocate the blocks.
1541 * This is done before we remove the attribute so that we don't
1542 * overflow the maximum size of a transaction and/or hit a deadlock.
1544 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1545 ASSERT(blk
->bp
!= NULL
);
1546 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1547 if (args
->rmtblkno
> 0) {
1549 * Fill in disk block numbers in the state structure
1550 * so that we can get the buffers back after we commit
1551 * several transactions in the following calls.
1553 error
= xfs_attr_fillstate(state
);
1558 * Mark the attribute as INCOMPLETE, then bunmapi() the
1561 error
= xfs_attr_leaf_setflag(args
);
1564 error
= xfs_attr_rmtval_remove(args
);
1569 * Refill the state structure with buffers, the prior calls
1570 * released our buffers.
1572 error
= xfs_attr_refillstate(state
);
1578 * Remove the name and update the hashvals in the tree.
1580 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1581 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1582 retval
= xfs_attr_leaf_remove(blk
->bp
, args
);
1583 xfs_da_fixhashpath(state
, &state
->path
);
1586 * Check to see if the tree needs to be collapsed.
1588 if (retval
&& (state
->path
.active
> 1)) {
1589 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1590 error
= xfs_da_join(state
);
1592 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1598 xfs_bmap_cancel(args
->flist
);
1603 * bmap_finish() may have committed the last trans and started
1604 * a new one. We need the inode to be in all transactions.
1607 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1608 xfs_trans_ihold(args
->trans
, dp
);
1612 * Commit the Btree join operation and start a new trans.
1614 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1619 * If the result is small enough, push it all into the inode.
1621 if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
1623 * Have to get rid of the copy of this dabuf in the state.
1625 ASSERT(state
->path
.active
== 1);
1626 ASSERT(state
->path
.blk
[0].bp
);
1627 xfs_da_buf_done(state
->path
.blk
[0].bp
);
1628 state
->path
.blk
[0].bp
= NULL
;
1630 error
= xfs_da_read_buf(args
->trans
, args
->dp
, 0, -1, &bp
,
1634 ASSERT(be16_to_cpu(((xfs_attr_leafblock_t
*)
1635 bp
->data
)->hdr
.info
.magic
)
1636 == XFS_ATTR_LEAF_MAGIC
);
1638 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1639 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1640 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1641 /* bp is gone due to xfs_da_shrink_inode */
1643 error
= xfs_bmap_finish(&args
->trans
,
1650 xfs_bmap_cancel(args
->flist
);
1655 * bmap_finish() may have committed the last trans
1656 * and started a new one. We need the inode to be
1657 * in all transactions.
1660 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1661 xfs_trans_ihold(args
->trans
, dp
);
1664 xfs_da_brelse(args
->trans
, bp
);
1669 xfs_da_state_free(state
);
1674 * Fill in the disk block numbers in the state structure for the buffers
1675 * that are attached to the state structure.
1676 * This is done so that we can quickly reattach ourselves to those buffers
1677 * after some set of transaction commits have released these buffers.
1680 xfs_attr_fillstate(xfs_da_state_t
*state
)
1682 xfs_da_state_path_t
*path
;
1683 xfs_da_state_blk_t
*blk
;
1687 * Roll down the "path" in the state structure, storing the on-disk
1688 * block number for those buffers in the "path".
1690 path
= &state
->path
;
1691 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1692 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1694 blk
->disk_blkno
= xfs_da_blkno(blk
->bp
);
1695 xfs_da_buf_done(blk
->bp
);
1698 blk
->disk_blkno
= 0;
1703 * Roll down the "altpath" in the state structure, storing the on-disk
1704 * block number for those buffers in the "altpath".
1706 path
= &state
->altpath
;
1707 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1708 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1710 blk
->disk_blkno
= xfs_da_blkno(blk
->bp
);
1711 xfs_da_buf_done(blk
->bp
);
1714 blk
->disk_blkno
= 0;
1722 * Reattach the buffers to the state structure based on the disk block
1723 * numbers stored in the state structure.
1724 * This is done after some set of transaction commits have released those
1725 * buffers from our grip.
1728 xfs_attr_refillstate(xfs_da_state_t
*state
)
1730 xfs_da_state_path_t
*path
;
1731 xfs_da_state_blk_t
*blk
;
1735 * Roll down the "path" in the state structure, storing the on-disk
1736 * block number for those buffers in the "path".
1738 path
= &state
->path
;
1739 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1740 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1741 if (blk
->disk_blkno
) {
1742 error
= xfs_da_read_buf(state
->args
->trans
,
1744 blk
->blkno
, blk
->disk_blkno
,
1745 &blk
->bp
, XFS_ATTR_FORK
);
1754 * Roll down the "altpath" in the state structure, storing the on-disk
1755 * block number for those buffers in the "altpath".
1757 path
= &state
->altpath
;
1758 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1759 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1760 if (blk
->disk_blkno
) {
1761 error
= xfs_da_read_buf(state
->args
->trans
,
1763 blk
->blkno
, blk
->disk_blkno
,
1764 &blk
->bp
, XFS_ATTR_FORK
);
1776 * Look up a filename in a node attribute list.
1778 * This routine gets called for any attribute fork that has more than one
1779 * block, ie: both true Btree attr lists and for single-leaf-blocks with
1780 * "remote" values taking up more blocks.
1783 xfs_attr_node_get(xfs_da_args_t
*args
)
1785 xfs_da_state_t
*state
;
1786 xfs_da_state_blk_t
*blk
;
1790 state
= xfs_da_state_alloc();
1792 state
->mp
= args
->dp
->i_mount
;
1793 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1794 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1797 * Search to see if name exists, and get back a pointer to it.
1799 error
= xfs_da_node_lookup_int(state
, &retval
);
1802 } else if (retval
== EEXIST
) {
1803 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1804 ASSERT(blk
->bp
!= NULL
);
1805 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1808 * Get the value, local or "remote"
1810 retval
= xfs_attr_leaf_getvalue(blk
->bp
, args
);
1811 if (!retval
&& (args
->rmtblkno
> 0)
1812 && !(args
->flags
& ATTR_KERNOVAL
)) {
1813 retval
= xfs_attr_rmtval_get(args
);
1818 * If not in a transaction, we have to release all the buffers.
1820 for (i
= 0; i
< state
->path
.active
; i
++) {
1821 xfs_da_brelse(args
->trans
, state
->path
.blk
[i
].bp
);
1822 state
->path
.blk
[i
].bp
= NULL
;
1825 xfs_da_state_free(state
);
1829 STATIC
int /* error */
1830 xfs_attr_node_list(xfs_attr_list_context_t
*context
)
1832 attrlist_cursor_kern_t
*cursor
;
1833 xfs_attr_leafblock_t
*leaf
;
1834 xfs_da_intnode_t
*node
;
1835 xfs_da_node_entry_t
*btree
;
1839 cursor
= context
->cursor
;
1840 cursor
->initted
= 1;
1843 * Do all sorts of validation on the passed-in cursor structure.
1844 * If anything is amiss, ignore the cursor and look up the hashval
1845 * starting from the btree root.
1848 if (cursor
->blkno
> 0) {
1849 error
= xfs_da_read_buf(NULL
, context
->dp
, cursor
->blkno
, -1,
1850 &bp
, XFS_ATTR_FORK
);
1851 if ((error
!= 0) && (error
!= EFSCORRUPTED
))
1855 switch (be16_to_cpu(node
->hdr
.info
.magic
)) {
1856 case XFS_DA_NODE_MAGIC
:
1857 xfs_attr_trace_l_cn("wrong blk", context
, node
);
1858 xfs_da_brelse(NULL
, bp
);
1861 case XFS_ATTR_LEAF_MAGIC
:
1863 if (cursor
->hashval
> be32_to_cpu(leaf
->entries
[
1864 be16_to_cpu(leaf
->hdr
.count
)-1].hashval
)) {
1865 xfs_attr_trace_l_cl("wrong blk",
1867 xfs_da_brelse(NULL
, bp
);
1869 } else if (cursor
->hashval
<=
1870 be32_to_cpu(leaf
->entries
[0].hashval
)) {
1871 xfs_attr_trace_l_cl("maybe wrong blk",
1873 xfs_da_brelse(NULL
, bp
);
1878 xfs_attr_trace_l_c("wrong blk - ??", context
);
1879 xfs_da_brelse(NULL
, bp
);
1886 * We did not find what we expected given the cursor's contents,
1887 * so we start from the top and work down based on the hash value.
1888 * Note that start of node block is same as start of leaf block.
1893 error
= xfs_da_read_buf(NULL
, context
->dp
,
1894 cursor
->blkno
, -1, &bp
,
1898 if (unlikely(bp
== NULL
)) {
1899 XFS_ERROR_REPORT("xfs_attr_node_list(2)",
1901 context
->dp
->i_mount
);
1902 return(XFS_ERROR(EFSCORRUPTED
));
1905 if (be16_to_cpu(node
->hdr
.info
.magic
)
1906 == XFS_ATTR_LEAF_MAGIC
)
1908 if (unlikely(be16_to_cpu(node
->hdr
.info
.magic
)
1909 != XFS_DA_NODE_MAGIC
)) {
1910 XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
1912 context
->dp
->i_mount
,
1914 xfs_da_brelse(NULL
, bp
);
1915 return(XFS_ERROR(EFSCORRUPTED
));
1917 btree
= node
->btree
;
1918 for (i
= 0; i
< be16_to_cpu(node
->hdr
.count
);
1921 <= be32_to_cpu(btree
->hashval
)) {
1922 cursor
->blkno
= be32_to_cpu(btree
->before
);
1923 xfs_attr_trace_l_cb("descending",
1928 if (i
== be16_to_cpu(node
->hdr
.count
)) {
1929 xfs_da_brelse(NULL
, bp
);
1932 xfs_da_brelse(NULL
, bp
);
1938 * Roll upward through the blocks, processing each leaf block in
1939 * order. As long as there is space in the result buffer, keep
1940 * adding the information.
1944 if (unlikely(be16_to_cpu(leaf
->hdr
.info
.magic
)
1945 != XFS_ATTR_LEAF_MAGIC
)) {
1946 XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
1948 context
->dp
->i_mount
, leaf
);
1949 xfs_da_brelse(NULL
, bp
);
1950 return(XFS_ERROR(EFSCORRUPTED
));
1952 error
= xfs_attr_leaf_list_int(bp
, context
);
1954 xfs_da_brelse(NULL
, bp
);
1957 if (context
->seen_enough
|| leaf
->hdr
.info
.forw
== 0)
1959 cursor
->blkno
= be32_to_cpu(leaf
->hdr
.info
.forw
);
1960 xfs_da_brelse(NULL
, bp
);
1961 error
= xfs_da_read_buf(NULL
, context
->dp
, cursor
->blkno
, -1,
1962 &bp
, XFS_ATTR_FORK
);
1965 if (unlikely((bp
== NULL
))) {
1966 XFS_ERROR_REPORT("xfs_attr_node_list(5)",
1968 context
->dp
->i_mount
);
1969 return(XFS_ERROR(EFSCORRUPTED
));
1972 xfs_da_brelse(NULL
, bp
);
1977 /*========================================================================
1978 * External routines for manipulating out-of-line attribute values.
1979 *========================================================================*/
1982 * Read the value associated with an attribute from the out-of-line buffer
1983 * that we stored it in.
1986 xfs_attr_rmtval_get(xfs_da_args_t
*args
)
1988 xfs_bmbt_irec_t map
[ATTR_RMTVALUE_MAPSIZE
];
1993 int nmap
, error
, tmp
, valuelen
, blkcnt
, i
;
1996 ASSERT(!(args
->flags
& ATTR_KERNOVAL
));
1998 mp
= args
->dp
->i_mount
;
2000 valuelen
= args
->valuelen
;
2001 lblkno
= args
->rmtblkno
;
2002 while (valuelen
> 0) {
2003 nmap
= ATTR_RMTVALUE_MAPSIZE
;
2004 error
= xfs_bmapi(args
->trans
, args
->dp
, (xfs_fileoff_t
)lblkno
,
2006 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2007 NULL
, 0, map
, &nmap
, NULL
, NULL
);
2012 for (i
= 0; (i
< nmap
) && (valuelen
> 0); i
++) {
2013 ASSERT((map
[i
].br_startblock
!= DELAYSTARTBLOCK
) &&
2014 (map
[i
].br_startblock
!= HOLESTARTBLOCK
));
2015 dblkno
= XFS_FSB_TO_DADDR(mp
, map
[i
].br_startblock
);
2016 blkcnt
= XFS_FSB_TO_BB(mp
, map
[i
].br_blockcount
);
2017 error
= xfs_read_buf(mp
, mp
->m_ddev_targp
, dblkno
,
2018 blkcnt
, XFS_BUF_LOCK
, &bp
);
2022 tmp
= (valuelen
< XFS_BUF_SIZE(bp
))
2023 ? valuelen
: XFS_BUF_SIZE(bp
);
2024 xfs_biomove(bp
, 0, tmp
, dst
, XFS_B_READ
);
2029 lblkno
+= map
[i
].br_blockcount
;
2032 ASSERT(valuelen
== 0);
2037 * Write the value associated with an attribute into the out-of-line buffer
2038 * that we have defined for it.
2041 xfs_attr_rmtval_set(xfs_da_args_t
*args
)
2044 xfs_fileoff_t lfileoff
;
2046 xfs_bmbt_irec_t map
;
2051 int blkcnt
, valuelen
, nmap
, error
, tmp
, committed
;
2058 * Find a "hole" in the attribute address space large enough for
2059 * us to drop the new attribute's value into.
2061 blkcnt
= XFS_B_TO_FSB(mp
, args
->valuelen
);
2063 error
= xfs_bmap_first_unused(args
->trans
, args
->dp
, blkcnt
, &lfileoff
,
2068 args
->rmtblkno
= lblkno
= (xfs_dablk_t
)lfileoff
;
2069 args
->rmtblkcnt
= blkcnt
;
2072 * Roll through the "value", allocating blocks on disk as required.
2074 while (blkcnt
> 0) {
2076 * Allocate a single extent, up to the size of the value.
2078 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2080 error
= xfs_bmapi(args
->trans
, dp
, (xfs_fileoff_t
)lblkno
,
2082 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
|
2084 args
->firstblock
, args
->total
, &map
, &nmap
,
2087 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
2093 xfs_bmap_cancel(args
->flist
);
2098 * bmap_finish() may have committed the last trans and started
2099 * a new one. We need the inode to be in all transactions.
2102 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
2103 xfs_trans_ihold(args
->trans
, dp
);
2107 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2108 (map
.br_startblock
!= HOLESTARTBLOCK
));
2109 lblkno
+= map
.br_blockcount
;
2110 blkcnt
-= map
.br_blockcount
;
2113 * Start the next trans in the chain.
2115 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
2120 * Roll through the "value", copying the attribute value to the
2121 * already-allocated blocks. Blocks are written synchronously
2122 * so that we can know they are all on disk before we turn off
2123 * the INCOMPLETE flag.
2125 lblkno
= args
->rmtblkno
;
2126 valuelen
= args
->valuelen
;
2127 while (valuelen
> 0) {
2129 * Try to remember where we decided to put the value.
2131 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2133 error
= xfs_bmapi(NULL
, dp
, (xfs_fileoff_t
)lblkno
,
2135 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2136 args
->firstblock
, 0, &map
, &nmap
,
2142 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2143 (map
.br_startblock
!= HOLESTARTBLOCK
));
2145 dblkno
= XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
2146 blkcnt
= XFS_FSB_TO_BB(mp
, map
.br_blockcount
);
2148 bp
= xfs_buf_get_flags(mp
->m_ddev_targp
, dblkno
,
2149 blkcnt
, XFS_BUF_LOCK
);
2151 ASSERT(!XFS_BUF_GETERROR(bp
));
2153 tmp
= (valuelen
< XFS_BUF_SIZE(bp
)) ? valuelen
:
2155 xfs_biomove(bp
, 0, tmp
, src
, XFS_B_WRITE
);
2156 if (tmp
< XFS_BUF_SIZE(bp
))
2157 xfs_biozero(bp
, tmp
, XFS_BUF_SIZE(bp
) - tmp
);
2158 if ((error
= xfs_bwrite(mp
, bp
))) {/* GROT: NOTE: synchronous write */
2164 lblkno
+= map
.br_blockcount
;
2166 ASSERT(valuelen
== 0);
2171 * Remove the value associated with an attribute by deleting the
2172 * out-of-line buffer that it is stored on.
2175 xfs_attr_rmtval_remove(xfs_da_args_t
*args
)
2178 xfs_bmbt_irec_t map
;
2182 int valuelen
, blkcnt
, nmap
, error
, done
, committed
;
2184 mp
= args
->dp
->i_mount
;
2187 * Roll through the "value", invalidating the attribute value's
2190 lblkno
= args
->rmtblkno
;
2191 valuelen
= args
->rmtblkcnt
;
2192 while (valuelen
> 0) {
2194 * Try to remember where we decided to put the value.
2196 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2198 error
= xfs_bmapi(NULL
, args
->dp
, (xfs_fileoff_t
)lblkno
,
2200 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2201 args
->firstblock
, 0, &map
, &nmap
,
2207 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2208 (map
.br_startblock
!= HOLESTARTBLOCK
));
2210 dblkno
= XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
2211 blkcnt
= XFS_FSB_TO_BB(mp
, map
.br_blockcount
);
2214 * If the "remote" value is in the cache, remove it.
2216 bp
= xfs_incore(mp
->m_ddev_targp
, dblkno
, blkcnt
,
2217 XFS_INCORE_TRYLOCK
);
2220 XFS_BUF_UNDELAYWRITE(bp
);
2225 valuelen
-= map
.br_blockcount
;
2227 lblkno
+= map
.br_blockcount
;
2231 * Keep de-allocating extents until the remote-value region is gone.
2233 lblkno
= args
->rmtblkno
;
2234 blkcnt
= args
->rmtblkcnt
;
2237 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2238 error
= xfs_bunmapi(args
->trans
, args
->dp
, lblkno
, blkcnt
,
2239 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2240 1, args
->firstblock
, args
->flist
,
2243 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
2249 xfs_bmap_cancel(args
->flist
);
2254 * bmap_finish() may have committed the last trans and started
2255 * a new one. We need the inode to be in all transactions.
2258 xfs_trans_ijoin(args
->trans
, args
->dp
, XFS_ILOCK_EXCL
);
2259 xfs_trans_ihold(args
->trans
, args
->dp
);
2263 * Close out trans and start the next one in the chain.
2265 if ((error
= xfs_attr_rolltrans(&args
->trans
, args
->dp
)))
2271 #if defined(XFS_ATTR_TRACE)
2273 * Add a trace buffer entry for an attr_list context structure.
2276 xfs_attr_trace_l_c(char *where
, struct xfs_attr_list_context
*context
)
2278 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_C
, where
,
2279 (__psunsigned_t
)context
->dp
,
2280 (__psunsigned_t
)context
->cursor
->hashval
,
2281 (__psunsigned_t
)context
->cursor
->blkno
,
2282 (__psunsigned_t
)context
->cursor
->offset
,
2283 (__psunsigned_t
)context
->alist
,
2284 (__psunsigned_t
)context
->bufsize
,
2285 (__psunsigned_t
)context
->count
,
2286 (__psunsigned_t
)context
->firstu
,
2288 ((context
->count
> 0) &&
2289 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2290 ? (ATTR_ENTRY(context
->alist
,
2291 context
->count
-1)->a_valuelen
)
2293 (__psunsigned_t
)context
->dupcnt
,
2294 (__psunsigned_t
)context
->flags
,
2295 (__psunsigned_t
)NULL
,
2296 (__psunsigned_t
)NULL
,
2297 (__psunsigned_t
)NULL
);
2301 * Add a trace buffer entry for a context structure and a Btree node.
2304 xfs_attr_trace_l_cn(char *where
, struct xfs_attr_list_context
*context
,
2305 struct xfs_da_intnode
*node
)
2307 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CN
, where
,
2308 (__psunsigned_t
)context
->dp
,
2309 (__psunsigned_t
)context
->cursor
->hashval
,
2310 (__psunsigned_t
)context
->cursor
->blkno
,
2311 (__psunsigned_t
)context
->cursor
->offset
,
2312 (__psunsigned_t
)context
->alist
,
2313 (__psunsigned_t
)context
->bufsize
,
2314 (__psunsigned_t
)context
->count
,
2315 (__psunsigned_t
)context
->firstu
,
2317 ((context
->count
> 0) &&
2318 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2319 ? (ATTR_ENTRY(context
->alist
,
2320 context
->count
-1)->a_valuelen
)
2322 (__psunsigned_t
)context
->dupcnt
,
2323 (__psunsigned_t
)context
->flags
,
2324 (__psunsigned_t
)be16_to_cpu(node
->hdr
.count
),
2325 (__psunsigned_t
)be32_to_cpu(node
->btree
[0].hashval
),
2326 (__psunsigned_t
)be32_to_cpu(node
->btree
[
2327 be16_to_cpu(node
->hdr
.count
)-1].hashval
));
2331 * Add a trace buffer entry for a context structure and a Btree element.
2334 xfs_attr_trace_l_cb(char *where
, struct xfs_attr_list_context
*context
,
2335 struct xfs_da_node_entry
*btree
)
2337 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CB
, where
,
2338 (__psunsigned_t
)context
->dp
,
2339 (__psunsigned_t
)context
->cursor
->hashval
,
2340 (__psunsigned_t
)context
->cursor
->blkno
,
2341 (__psunsigned_t
)context
->cursor
->offset
,
2342 (__psunsigned_t
)context
->alist
,
2343 (__psunsigned_t
)context
->bufsize
,
2344 (__psunsigned_t
)context
->count
,
2345 (__psunsigned_t
)context
->firstu
,
2347 ((context
->count
> 0) &&
2348 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2349 ? (ATTR_ENTRY(context
->alist
,
2350 context
->count
-1)->a_valuelen
)
2352 (__psunsigned_t
)context
->dupcnt
,
2353 (__psunsigned_t
)context
->flags
,
2354 (__psunsigned_t
)be32_to_cpu(btree
->hashval
),
2355 (__psunsigned_t
)be32_to_cpu(btree
->before
),
2356 (__psunsigned_t
)NULL
);
2360 * Add a trace buffer entry for a context structure and a leaf block.
2363 xfs_attr_trace_l_cl(char *where
, struct xfs_attr_list_context
*context
,
2364 struct xfs_attr_leafblock
*leaf
)
2366 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CL
, where
,
2367 (__psunsigned_t
)context
->dp
,
2368 (__psunsigned_t
)context
->cursor
->hashval
,
2369 (__psunsigned_t
)context
->cursor
->blkno
,
2370 (__psunsigned_t
)context
->cursor
->offset
,
2371 (__psunsigned_t
)context
->alist
,
2372 (__psunsigned_t
)context
->bufsize
,
2373 (__psunsigned_t
)context
->count
,
2374 (__psunsigned_t
)context
->firstu
,
2376 ((context
->count
> 0) &&
2377 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2378 ? (ATTR_ENTRY(context
->alist
,
2379 context
->count
-1)->a_valuelen
)
2381 (__psunsigned_t
)context
->dupcnt
,
2382 (__psunsigned_t
)context
->flags
,
2383 (__psunsigned_t
)be16_to_cpu(leaf
->hdr
.count
),
2384 (__psunsigned_t
)be32_to_cpu(leaf
->entries
[0].hashval
),
2385 (__psunsigned_t
)be32_to_cpu(leaf
->entries
[
2386 be16_to_cpu(leaf
->hdr
.count
)-1].hashval
));
2390 * Add a trace buffer entry for the arguments given to the routine,
2394 xfs_attr_trace_enter(int type
, char *where
,
2395 __psunsigned_t a2
, __psunsigned_t a3
,
2396 __psunsigned_t a4
, __psunsigned_t a5
,
2397 __psunsigned_t a6
, __psunsigned_t a7
,
2398 __psunsigned_t a8
, __psunsigned_t a9
,
2399 __psunsigned_t a10
, __psunsigned_t a11
,
2400 __psunsigned_t a12
, __psunsigned_t a13
,
2401 __psunsigned_t a14
, __psunsigned_t a15
)
2403 ASSERT(xfs_attr_trace_buf
);
2404 ktrace_enter(xfs_attr_trace_buf
, (void *)((__psunsigned_t
)type
),
2406 (void *)a2
, (void *)a3
, (void *)a4
,
2407 (void *)a5
, (void *)a6
, (void *)a7
,
2408 (void *)a8
, (void *)a9
, (void *)a10
,
2409 (void *)a11
, (void *)a12
, (void *)a13
,
2410 (void *)a14
, (void *)a15
);
2412 #endif /* XFS_ATTR_TRACE */
2415 /*========================================================================
2416 * System (pseudo) namespace attribute interface routines.
2417 *========================================================================*/
2420 posix_acl_access_set(
2421 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2423 return xfs_acl_vset(vp
, data
, size
, _ACL_TYPE_ACCESS
);
2427 posix_acl_access_remove(
2428 bhv_vnode_t
*vp
, char *name
, int xflags
)
2430 return xfs_acl_vremove(vp
, _ACL_TYPE_ACCESS
);
2434 posix_acl_access_get(
2435 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2437 return xfs_acl_vget(vp
, data
, size
, _ACL_TYPE_ACCESS
);
2441 posix_acl_access_exists(
2444 return xfs_acl_vhasacl_access(vp
);
2448 posix_acl_default_set(
2449 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2451 return xfs_acl_vset(vp
, data
, size
, _ACL_TYPE_DEFAULT
);
2455 posix_acl_default_get(
2456 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2458 return xfs_acl_vget(vp
, data
, size
, _ACL_TYPE_DEFAULT
);
2462 posix_acl_default_remove(
2463 bhv_vnode_t
*vp
, char *name
, int xflags
)
2465 return xfs_acl_vremove(vp
, _ACL_TYPE_DEFAULT
);
2469 posix_acl_default_exists(
2472 return xfs_acl_vhasacl_default(vp
);
2475 static struct attrnames posix_acl_access
= {
2476 .attr_name
= "posix_acl_access",
2477 .attr_namelen
= sizeof("posix_acl_access") - 1,
2478 .attr_get
= posix_acl_access_get
,
2479 .attr_set
= posix_acl_access_set
,
2480 .attr_remove
= posix_acl_access_remove
,
2481 .attr_exists
= posix_acl_access_exists
,
2484 static struct attrnames posix_acl_default
= {
2485 .attr_name
= "posix_acl_default",
2486 .attr_namelen
= sizeof("posix_acl_default") - 1,
2487 .attr_get
= posix_acl_default_get
,
2488 .attr_set
= posix_acl_default_set
,
2489 .attr_remove
= posix_acl_default_remove
,
2490 .attr_exists
= posix_acl_default_exists
,
2493 static struct attrnames
*attr_system_names
[] =
2494 { &posix_acl_access
, &posix_acl_default
};
2497 /*========================================================================
2498 * Namespace-prefix-style attribute name interface routines.
2499 *========================================================================*/
2503 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2505 return -bhv_vop_attr_set(vp
, name
, data
, size
, xflags
, NULL
);
2510 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2512 int error
, asize
= size
;
2514 error
= bhv_vop_attr_get(vp
, name
, data
, &asize
, xflags
, NULL
);
2521 attr_generic_remove(
2522 bhv_vnode_t
*vp
, char *name
, int xflags
)
2524 return -bhv_vop_attr_remove(vp
, name
, xflags
, NULL
);
2528 attr_generic_listadd(
2529 attrnames_t
*prefix
,
2530 attrnames_t
*namesp
,
2535 char *p
= data
+ *result
;
2537 *result
+= prefix
->attr_namelen
;
2538 *result
+= namesp
->attr_namelen
+ 1;
2543 strcpy(p
, prefix
->attr_name
);
2544 p
+= prefix
->attr_namelen
;
2545 strcpy(p
, namesp
->attr_name
);
2546 p
+= namesp
->attr_namelen
+ 1;
2557 attrnames_t
*namesp
;
2560 for (i
= 0; i
< ATTR_SYSCOUNT
; i
++) {
2561 namesp
= attr_system_names
[i
];
2562 if (!namesp
->attr_exists
|| !namesp
->attr_exists(vp
))
2564 error
= attr_generic_listadd(&attr_system
, namesp
,
2565 data
, size
, result
);
2574 bhv_vnode_t
*vp
, void *data
, size_t size
, int xflags
, ssize_t
*result
)
2576 attrlist_cursor_kern_t cursor
= { 0 };
2579 error
= bhv_vop_attr_list(vp
, data
, size
, xflags
, &cursor
, NULL
);
2583 return attr_system_list(vp
, data
, size
, result
);
2587 attr_lookup_namespace(
2589 struct attrnames
**names
,
2594 for (i
= 0; i
< nnames
; i
++)
2595 if (!strncmp(name
, names
[i
]->attr_name
, names
[i
]->attr_namelen
))
2601 * Some checks to prevent people abusing EAs to get over quota:
2602 * - Don't allow modifying user EAs on devices/symlinks;
2603 * - Don't allow modifying user EAs if sticky bit set;
2610 struct inode
*inode
= vn_to_inode(vp
);
2612 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
2614 if (!S_ISREG(inode
->i_mode
) && !S_ISDIR(inode
->i_mode
) &&
2615 !capable(CAP_SYS_ADMIN
))
2617 if (S_ISDIR(inode
->i_mode
) && (inode
->i_mode
& S_ISVTX
) &&
2618 (current_fsuid(cred
) != inode
->i_uid
) && !capable(CAP_FOWNER
))
2624 attr_trusted_capable(
2628 struct inode
*inode
= vn_to_inode(vp
);
2630 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
2632 if (!capable(CAP_SYS_ADMIN
))
2638 attr_secure_capable(
2642 return -ENOSECURITY
;
2647 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2649 attrnames_t
*namesp
;
2652 if (xflags
& ATTR_CREATE
)
2655 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2658 error
= namesp
->attr_set(vp
, name
, data
, size
, xflags
);
2660 error
= vn_revalidate(vp
);
2666 bhv_vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2668 attrnames_t
*namesp
;
2670 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2673 return namesp
->attr_get(vp
, name
, data
, size
, xflags
);
2678 bhv_vnode_t
*vp
, char *name
, int xflags
)
2680 attrnames_t
*namesp
;
2682 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2685 return namesp
->attr_remove(vp
, name
, xflags
);
2688 struct attrnames attr_system
= {
2689 .attr_name
= "system.",
2690 .attr_namelen
= sizeof("system.") - 1,
2691 .attr_flag
= ATTR_SYSTEM
,
2692 .attr_get
= attr_system_get
,
2693 .attr_set
= attr_system_set
,
2694 .attr_remove
= attr_system_remove
,
2695 .attr_capable
= (attrcapable_t
)fs_noerr
,
2698 struct attrnames attr_trusted
= {
2699 .attr_name
= "trusted.",
2700 .attr_namelen
= sizeof("trusted.") - 1,
2701 .attr_flag
= ATTR_ROOT
,
2702 .attr_get
= attr_generic_get
,
2703 .attr_set
= attr_generic_set
,
2704 .attr_remove
= attr_generic_remove
,
2705 .attr_capable
= attr_trusted_capable
,
2708 struct attrnames attr_secure
= {
2709 .attr_name
= "security.",
2710 .attr_namelen
= sizeof("security.") - 1,
2711 .attr_flag
= ATTR_SECURE
,
2712 .attr_get
= attr_generic_get
,
2713 .attr_set
= attr_generic_set
,
2714 .attr_remove
= attr_generic_remove
,
2715 .attr_capable
= attr_secure_capable
,
2718 struct attrnames attr_user
= {
2719 .attr_name
= "user.",
2720 .attr_namelen
= sizeof("user.") - 1,
2721 .attr_get
= attr_generic_get
,
2722 .attr_set
= attr_generic_set
,
2723 .attr_remove
= attr_generic_remove
,
2724 .attr_capable
= attr_user_capable
,
2727 struct attrnames
*attr_namespaces
[] =
2728 { &attr_system
, &attr_trusted
, &attr_secure
, &attr_user
};