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"
32 #include "xfs_dmapi.h"
33 #include "xfs_mount.h"
34 #include "xfs_da_btree.h"
35 #include "xfs_bmap_btree.h"
36 #include "xfs_alloc_btree.h"
37 #include "xfs_ialloc_btree.h"
38 #include "xfs_dir_sf.h"
39 #include "xfs_dir2_sf.h"
40 #include "xfs_attr_sf.h"
41 #include "xfs_dinode.h"
42 #include "xfs_inode.h"
43 #include "xfs_alloc.h"
44 #include "xfs_btree.h"
45 #include "xfs_inode_item.h"
48 #include "xfs_attr_leaf.h"
49 #include "xfs_error.h"
50 #include "xfs_quota.h"
51 #include "xfs_trans_space.h"
58 * Provide the external interfaces to manage attribute lists.
61 #define ATTR_SYSCOUNT 2
62 STATIC
struct attrnames posix_acl_access
;
63 STATIC
struct attrnames posix_acl_default
;
64 STATIC
struct attrnames
*attr_system_names
[ATTR_SYSCOUNT
];
66 /*========================================================================
67 * Function prototypes for the kernel.
68 *========================================================================*/
71 * Internal routines when attribute list fits inside the inode.
73 STATIC
int xfs_attr_shortform_addname(xfs_da_args_t
*args
);
76 * Internal routines when attribute list is one block.
78 STATIC
int xfs_attr_leaf_get(xfs_da_args_t
*args
);
79 STATIC
int xfs_attr_leaf_addname(xfs_da_args_t
*args
);
80 STATIC
int xfs_attr_leaf_removename(xfs_da_args_t
*args
);
81 STATIC
int xfs_attr_leaf_list(xfs_attr_list_context_t
*context
);
84 * Internal routines when attribute list is more than one block.
86 STATIC
int xfs_attr_node_get(xfs_da_args_t
*args
);
87 STATIC
int xfs_attr_node_addname(xfs_da_args_t
*args
);
88 STATIC
int xfs_attr_node_removename(xfs_da_args_t
*args
);
89 STATIC
int xfs_attr_node_list(xfs_attr_list_context_t
*context
);
90 STATIC
int xfs_attr_fillstate(xfs_da_state_t
*state
);
91 STATIC
int xfs_attr_refillstate(xfs_da_state_t
*state
);
94 * Routines to manipulate out-of-line attribute values.
96 STATIC
int xfs_attr_rmtval_get(xfs_da_args_t
*args
);
97 STATIC
int xfs_attr_rmtval_set(xfs_da_args_t
*args
);
98 STATIC
int xfs_attr_rmtval_remove(xfs_da_args_t
*args
);
100 #define ATTR_RMTVALUE_MAPSIZE 1 /* # of map entries at once */
102 #if defined(XFS_ATTR_TRACE)
103 ktrace_t
*xfs_attr_trace_buf
;
107 /*========================================================================
108 * Overall external interface routines.
109 *========================================================================*/
112 xfs_attr_fetch(xfs_inode_t
*ip
, const char *name
, int namelen
,
113 char *value
, int *valuelenp
, int flags
, struct cred
*cred
)
118 if ((XFS_IFORK_Q(ip
) == 0) ||
119 (ip
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
120 ip
->i_d
.di_anextents
== 0))
124 * Fill in the arg structure for this request.
126 memset((char *)&args
, 0, sizeof(args
));
128 args
.namelen
= namelen
;
130 args
.valuelen
= *valuelenp
;
132 args
.hashval
= xfs_da_hashname(args
.name
, args
.namelen
);
134 args
.whichfork
= XFS_ATTR_FORK
;
137 * Decide on what work routines to call based on the inode size.
139 if (XFS_IFORK_Q(ip
) == 0 ||
140 (ip
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
141 ip
->i_d
.di_anextents
== 0)) {
142 error
= XFS_ERROR(ENOATTR
);
143 } else if (ip
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) {
144 error
= xfs_attr_shortform_getvalue(&args
);
145 } else if (xfs_bmap_one_block(ip
, XFS_ATTR_FORK
)) {
146 error
= xfs_attr_leaf_get(&args
);
148 error
= xfs_attr_node_get(&args
);
152 * Return the number of bytes in the value to the caller.
154 *valuelenp
= args
.valuelen
;
162 xfs_attr_get(bhv_desc_t
*bdp
, const char *name
, char *value
, int *valuelenp
,
163 int flags
, struct cred
*cred
)
165 xfs_inode_t
*ip
= XFS_BHVTOI(bdp
);
168 XFS_STATS_INC(xs_attr_get
);
172 namelen
= strlen(name
);
173 if (namelen
>= MAXNAMELEN
)
174 return(EFAULT
); /* match IRIX behaviour */
176 if (XFS_FORCED_SHUTDOWN(ip
->i_mount
))
179 xfs_ilock(ip
, XFS_ILOCK_SHARED
);
180 error
= xfs_attr_fetch(ip
, name
, namelen
, value
, valuelenp
, flags
, cred
);
181 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
186 xfs_attr_set_int(xfs_inode_t
*dp
, const char *name
, int namelen
,
187 char *value
, int valuelen
, int flags
)
190 xfs_fsblock_t firstblock
;
191 xfs_bmap_free_t flist
;
192 int error
, err2
, committed
;
195 xfs_mount_t
*mp
= dp
->i_mount
;
196 int rsvd
= (flags
& ATTR_ROOT
) != 0;
199 * Attach the dquots to the inode.
201 if ((error
= XFS_QM_DQATTACH(mp
, dp
, 0)))
205 * Determine space new attribute will use, and if it would be
206 * "local" or "remote" (note: local != inline).
208 size
= xfs_attr_leaf_newentsize(namelen
, valuelen
,
209 mp
->m_sb
.sb_blocksize
, &local
);
212 * If the inode doesn't have an attribute fork, add one.
213 * (inode must not be locked when we call this routine)
215 if (XFS_IFORK_Q(dp
) == 0) {
216 if ((error
= xfs_bmap_add_attrfork(dp
, size
, rsvd
)))
221 * Fill in the arg structure for this request.
223 memset((char *)&args
, 0, sizeof(args
));
225 args
.namelen
= namelen
;
227 args
.valuelen
= valuelen
;
229 args
.hashval
= xfs_da_hashname(args
.name
, args
.namelen
);
231 args
.firstblock
= &firstblock
;
233 args
.whichfork
= XFS_ATTR_FORK
;
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
,
352 *args
.firstblock
, &committed
);
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 * Generate a list of extended attribute names and optionally
598 * also value lengths. Positive return value follows the XFS
599 * convention of being an error, zero or negative return code
600 * is the length of the buffer returned (negated), indicating
604 xfs_attr_list(bhv_desc_t
*bdp
, char *buffer
, int bufsize
, int flags
,
605 attrlist_cursor_kern_t
*cursor
, struct cred
*cred
)
607 xfs_attr_list_context_t context
;
611 XFS_STATS_INC(xs_attr_list
);
614 * Validate the cursor.
616 if (cursor
->pad1
|| cursor
->pad2
)
617 return(XFS_ERROR(EINVAL
));
618 if ((cursor
->initted
== 0) &&
619 (cursor
->hashval
|| cursor
->blkno
|| cursor
->offset
))
620 return(XFS_ERROR(EINVAL
));
623 * Check for a properly aligned buffer.
625 if (((long)buffer
) & (sizeof(int)-1))
626 return(XFS_ERROR(EFAULT
));
627 if (flags
& ATTR_KERNOVAL
)
631 * Initialize the output buffer.
633 context
.dp
= dp
= XFS_BHVTOI(bdp
);
634 context
.cursor
= cursor
;
638 context
.flags
= flags
;
639 if (!(flags
& ATTR_KERNAMELS
)) {
640 context
.bufsize
= (bufsize
& ~(sizeof(int)-1)); /* align */
641 context
.firstu
= context
.bufsize
;
642 context
.alist
= (attrlist_t
*)buffer
;
643 context
.alist
->al_count
= 0;
644 context
.alist
->al_more
= 0;
645 context
.alist
->al_offset
[0] = context
.bufsize
;
648 context
.bufsize
= bufsize
;
649 context
.firstu
= context
.bufsize
;
650 context
.alist
= (attrlist_t
*)buffer
;
653 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
656 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
658 * Decide on what work routines to call based on the inode size.
660 xfs_attr_trace_l_c("syscall start", &context
);
661 if (XFS_IFORK_Q(dp
) == 0 ||
662 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
663 dp
->i_d
.di_anextents
== 0)) {
665 } else if (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) {
666 error
= xfs_attr_shortform_list(&context
);
667 } else if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
668 error
= xfs_attr_leaf_list(&context
);
670 error
= xfs_attr_node_list(&context
);
672 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
673 xfs_attr_trace_l_c("syscall end", &context
);
675 if (!(context
.flags
& (ATTR_KERNOVAL
|ATTR_KERNAMELS
))) {
678 else { /* must return negated buffer size or the error */
679 if (context
.count
< 0)
680 error
= XFS_ERROR(ERANGE
);
682 error
= -context
.count
;
689 xfs_attr_inactive(xfs_inode_t
*dp
)
696 ASSERT(! XFS_NOT_DQATTACHED(mp
, dp
));
698 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
699 if ((XFS_IFORK_Q(dp
) == 0) ||
700 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
701 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
702 dp
->i_d
.di_anextents
== 0)) {
703 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
706 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
709 * Start our first transaction of the day.
711 * All future transactions during this code must be "chained" off
712 * this one via the trans_dup() call. All transactions will contain
713 * the inode, and the inode will always be marked with trans_ihold().
714 * Since the inode will be locked in all transactions, we must log
715 * the inode in every transaction to let it float upward through
718 trans
= xfs_trans_alloc(mp
, XFS_TRANS_ATTRINVAL
);
719 if ((error
= xfs_trans_reserve(trans
, 0, XFS_ATTRINVAL_LOG_RES(mp
), 0,
720 XFS_TRANS_PERM_LOG_RES
,
721 XFS_ATTRINVAL_LOG_COUNT
))) {
722 xfs_trans_cancel(trans
, 0);
725 xfs_ilock(dp
, XFS_ILOCK_EXCL
);
728 * No need to make quota reservations here. We expect to release some
729 * blocks, not allocate, in the common case.
731 xfs_trans_ijoin(trans
, dp
, XFS_ILOCK_EXCL
);
732 xfs_trans_ihold(trans
, dp
);
735 * Decide on what work routines to call based on the inode size.
737 if ((XFS_IFORK_Q(dp
) == 0) ||
738 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
739 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
740 dp
->i_d
.di_anextents
== 0)) {
744 error
= xfs_attr_root_inactive(&trans
, dp
);
748 * signal synchronous inactive transactions unless this
749 * is a synchronous mount filesystem in which case we
750 * know that we're here because we've been called out of
751 * xfs_inactive which means that the last reference is gone
752 * and the unlink transaction has already hit the disk so
753 * async inactive transactions are safe.
755 if ((error
= xfs_itruncate_finish(&trans
, dp
, 0LL, XFS_ATTR_FORK
,
756 (!(mp
->m_flags
& XFS_MOUNT_WSYNC
)
761 * Commit the last in the sequence of transactions.
763 xfs_trans_log_inode(trans
, dp
, XFS_ILOG_CORE
);
764 error
= xfs_trans_commit(trans
, XFS_TRANS_RELEASE_LOG_RES
,
766 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
771 xfs_trans_cancel(trans
, XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
772 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
778 /*========================================================================
779 * External routines when attribute list is inside the inode
780 *========================================================================*/
783 * Add a name to the shortform attribute list structure
784 * This is the external routine.
787 xfs_attr_shortform_addname(xfs_da_args_t
*args
)
789 int newsize
, forkoff
, retval
;
791 retval
= xfs_attr_shortform_lookup(args
);
792 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
794 } else if (retval
== EEXIST
) {
795 if (args
->flags
& ATTR_CREATE
)
797 retval
= xfs_attr_shortform_remove(args
);
801 if (args
->namelen
>= XFS_ATTR_SF_ENTSIZE_MAX
||
802 args
->valuelen
>= XFS_ATTR_SF_ENTSIZE_MAX
)
803 return(XFS_ERROR(ENOSPC
));
805 newsize
= XFS_ATTR_SF_TOTSIZE(args
->dp
);
806 newsize
+= XFS_ATTR_SF_ENTSIZE_BYNAME(args
->namelen
, args
->valuelen
);
808 forkoff
= xfs_attr_shortform_bytesfit(args
->dp
, newsize
);
810 return(XFS_ERROR(ENOSPC
));
812 xfs_attr_shortform_add(args
, forkoff
);
817 /*========================================================================
818 * External routines when attribute list is one block
819 *========================================================================*/
822 * Add a name to the leaf attribute list structure
824 * This leaf block cannot have a "remote" value, we only call this routine
825 * if bmap_one_block() says there is only one block (ie: no remote blks).
828 xfs_attr_leaf_addname(xfs_da_args_t
*args
)
832 int retval
, error
, committed
, forkoff
;
835 * Read the (only) block in the attribute list in.
839 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
846 * Look up the given attribute in the leaf block. Figure out if
847 * the given flags produce an error or call for an atomic rename.
849 retval
= xfs_attr_leaf_lookup_int(bp
, args
);
850 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
851 xfs_da_brelse(args
->trans
, bp
);
853 } else if (retval
== EEXIST
) {
854 if (args
->flags
& ATTR_CREATE
) { /* pure create op */
855 xfs_da_brelse(args
->trans
, bp
);
858 args
->rename
= 1; /* an atomic rename */
859 args
->blkno2
= args
->blkno
; /* set 2nd entry info*/
860 args
->index2
= args
->index
;
861 args
->rmtblkno2
= args
->rmtblkno
;
862 args
->rmtblkcnt2
= args
->rmtblkcnt
;
866 * Add the attribute to the leaf block, transitioning to a Btree
869 retval
= xfs_attr_leaf_add(bp
, args
);
871 if (retval
== ENOSPC
) {
873 * Promote the attribute list to the Btree format, then
874 * Commit that transaction so that the node_addname() call
875 * can manage its own transactions.
877 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
878 error
= xfs_attr_leaf_to_node(args
);
880 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
881 *args
->firstblock
, &committed
);
886 xfs_bmap_cancel(args
->flist
);
891 * bmap_finish() may have committed the last trans and started
892 * a new one. We need the inode to be in all transactions.
895 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
896 xfs_trans_ihold(args
->trans
, dp
);
900 * Commit the current trans (including the inode) and start
903 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
907 * Fob the whole rest of the problem off on the Btree code.
909 error
= xfs_attr_node_addname(args
);
914 * Commit the transaction that added the attr name so that
915 * later routines can manage their own transactions.
917 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
921 * If there was an out-of-line value, allocate the blocks we
922 * identified for its storage and copy the value. This is done
923 * after we create the attribute so that we don't overflow the
924 * maximum size of a transaction and/or hit a deadlock.
926 if (args
->rmtblkno
> 0) {
927 error
= xfs_attr_rmtval_set(args
);
933 * If this is an atomic rename operation, we must "flip" the
934 * incomplete flags on the "new" and "old" attribute/value pairs
935 * so that one disappears and one appears atomically. Then we
936 * must remove the "old" attribute/value pair.
940 * In a separate transaction, set the incomplete flag on the
941 * "old" attr and clear the incomplete flag on the "new" attr.
943 error
= xfs_attr_leaf_flipflags(args
);
948 * Dismantle the "old" attribute/value pair by removing
949 * a "remote" value (if it exists).
951 args
->index
= args
->index2
;
952 args
->blkno
= args
->blkno2
;
953 args
->rmtblkno
= args
->rmtblkno2
;
954 args
->rmtblkcnt
= args
->rmtblkcnt2
;
955 if (args
->rmtblkno
) {
956 error
= xfs_attr_rmtval_remove(args
);
962 * Read in the block containing the "old" attr, then
963 * remove the "old" attr from that block (neat, huh!)
965 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1,
970 (void)xfs_attr_leaf_remove(bp
, args
);
973 * If the result is small enough, shrink it all into the inode.
975 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
976 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
977 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
978 /* bp is gone due to xfs_da_shrink_inode */
980 error
= xfs_bmap_finish(&args
->trans
,
988 xfs_bmap_cancel(args
->flist
);
993 * bmap_finish() may have committed the last trans
994 * and started a new one. We need the inode to be
995 * in all transactions.
998 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
999 xfs_trans_ihold(args
->trans
, dp
);
1002 xfs_da_buf_done(bp
);
1005 * Commit the remove and start the next trans in series.
1007 error
= xfs_attr_rolltrans(&args
->trans
, dp
);
1009 } else if (args
->rmtblkno
> 0) {
1011 * Added a "remote" value, just clear the incomplete flag.
1013 error
= xfs_attr_leaf_clearflag(args
);
1019 * Remove a name from the leaf attribute list structure
1021 * This leaf block cannot have a "remote" value, we only call this routine
1022 * if bmap_one_block() says there is only one block (ie: no remote blks).
1025 xfs_attr_leaf_removename(xfs_da_args_t
*args
)
1029 int error
, committed
, forkoff
;
1032 * Remove the attribute.
1036 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
1043 error
= xfs_attr_leaf_lookup_int(bp
, args
);
1044 if (error
== ENOATTR
) {
1045 xfs_da_brelse(args
->trans
, bp
);
1049 (void)xfs_attr_leaf_remove(bp
, args
);
1052 * If the result is small enough, shrink it all into the inode.
1054 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1055 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1056 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1057 /* bp is gone due to xfs_da_shrink_inode */
1059 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1060 *args
->firstblock
, &committed
);
1065 xfs_bmap_cancel(args
->flist
);
1070 * bmap_finish() may have committed the last trans and started
1071 * a new one. We need the inode to be in all transactions.
1074 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1075 xfs_trans_ihold(args
->trans
, dp
);
1078 xfs_da_buf_done(bp
);
1083 * Look up a name in a leaf attribute list structure.
1085 * This leaf block cannot have a "remote" value, we only call this routine
1086 * if bmap_one_block() says there is only one block (ie: no remote blks).
1089 xfs_attr_leaf_get(xfs_da_args_t
*args
)
1095 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
1101 error
= xfs_attr_leaf_lookup_int(bp
, args
);
1102 if (error
!= EEXIST
) {
1103 xfs_da_brelse(args
->trans
, bp
);
1106 error
= xfs_attr_leaf_getvalue(bp
, args
);
1107 xfs_da_brelse(args
->trans
, bp
);
1108 if (!error
&& (args
->rmtblkno
> 0) && !(args
->flags
& ATTR_KERNOVAL
)) {
1109 error
= xfs_attr_rmtval_get(args
);
1115 * Copy out attribute entries for attr_list(), for leaf attribute lists.
1118 xfs_attr_leaf_list(xfs_attr_list_context_t
*context
)
1120 xfs_attr_leafblock_t
*leaf
;
1124 context
->cursor
->blkno
= 0;
1125 error
= xfs_da_read_buf(NULL
, context
->dp
, 0, -1, &bp
, XFS_ATTR_FORK
);
1130 if (unlikely(be16_to_cpu(leaf
->hdr
.info
.magic
) != XFS_ATTR_LEAF_MAGIC
)) {
1131 XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW
,
1132 context
->dp
->i_mount
, leaf
);
1133 xfs_da_brelse(NULL
, bp
);
1134 return(XFS_ERROR(EFSCORRUPTED
));
1137 (void)xfs_attr_leaf_list_int(bp
, context
);
1138 xfs_da_brelse(NULL
, bp
);
1143 /*========================================================================
1144 * External routines when attribute list size > XFS_LBSIZE(mp).
1145 *========================================================================*/
1148 * Add a name to a Btree-format attribute list.
1150 * This will involve walking down the Btree, and may involve splitting
1151 * leaf nodes and even splitting intermediate nodes up to and including
1152 * the root node (a special case of an intermediate node).
1154 * "Remote" attribute values confuse the issue and atomic rename operations
1155 * add a whole extra layer of confusion on top of that.
1158 xfs_attr_node_addname(xfs_da_args_t
*args
)
1160 xfs_da_state_t
*state
;
1161 xfs_da_state_blk_t
*blk
;
1164 int committed
, retval
, error
;
1167 * Fill in bucket of arguments/results/context to carry around.
1172 state
= xfs_da_state_alloc();
1175 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1176 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1179 * Search to see if name already exists, and get back a pointer
1180 * to where it should go.
1182 error
= xfs_da_node_lookup_int(state
, &retval
);
1185 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1186 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1187 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
1189 } else if (retval
== EEXIST
) {
1190 if (args
->flags
& ATTR_CREATE
)
1192 args
->rename
= 1; /* atomic rename op */
1193 args
->blkno2
= args
->blkno
; /* set 2nd entry info*/
1194 args
->index2
= args
->index
;
1195 args
->rmtblkno2
= args
->rmtblkno
;
1196 args
->rmtblkcnt2
= args
->rmtblkcnt
;
1198 args
->rmtblkcnt
= 0;
1201 retval
= xfs_attr_leaf_add(blk
->bp
, state
->args
);
1202 if (retval
== ENOSPC
) {
1203 if (state
->path
.active
== 1) {
1205 * Its really a single leaf node, but it had
1206 * out-of-line values so it looked like it *might*
1207 * have been a b-tree.
1209 xfs_da_state_free(state
);
1210 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1211 error
= xfs_attr_leaf_to_node(args
);
1213 error
= xfs_bmap_finish(&args
->trans
,
1221 xfs_bmap_cancel(args
->flist
);
1226 * bmap_finish() may have committed the last trans
1227 * and started a new one. We need the inode to be
1228 * in all transactions.
1231 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1232 xfs_trans_ihold(args
->trans
, dp
);
1236 * Commit the node conversion and start the next
1237 * trans in the chain.
1239 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1246 * Split as many Btree elements as required.
1247 * This code tracks the new and old attr's location
1248 * in the index/blkno/rmtblkno/rmtblkcnt fields and
1249 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
1251 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1252 error
= xfs_da_split(state
);
1254 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1255 *args
->firstblock
, &committed
);
1260 xfs_bmap_cancel(args
->flist
);
1265 * bmap_finish() may have committed the last trans and started
1266 * a new one. We need the inode to be in all transactions.
1269 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1270 xfs_trans_ihold(args
->trans
, dp
);
1274 * Addition succeeded, update Btree hashvals.
1276 xfs_da_fixhashpath(state
, &state
->path
);
1280 * Kill the state structure, we're done with it and need to
1281 * allow the buffers to come back later.
1283 xfs_da_state_free(state
);
1287 * Commit the leaf addition or btree split and start the next
1288 * trans in the chain.
1290 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1294 * If there was an out-of-line value, allocate the blocks we
1295 * identified for its storage and copy the value. This is done
1296 * after we create the attribute so that we don't overflow the
1297 * maximum size of a transaction and/or hit a deadlock.
1299 if (args
->rmtblkno
> 0) {
1300 error
= xfs_attr_rmtval_set(args
);
1306 * If this is an atomic rename operation, we must "flip" the
1307 * incomplete flags on the "new" and "old" attribute/value pairs
1308 * so that one disappears and one appears atomically. Then we
1309 * must remove the "old" attribute/value pair.
1313 * In a separate transaction, set the incomplete flag on the
1314 * "old" attr and clear the incomplete flag on the "new" attr.
1316 error
= xfs_attr_leaf_flipflags(args
);
1321 * Dismantle the "old" attribute/value pair by removing
1322 * a "remote" value (if it exists).
1324 args
->index
= args
->index2
;
1325 args
->blkno
= args
->blkno2
;
1326 args
->rmtblkno
= args
->rmtblkno2
;
1327 args
->rmtblkcnt
= args
->rmtblkcnt2
;
1328 if (args
->rmtblkno
) {
1329 error
= xfs_attr_rmtval_remove(args
);
1335 * Re-find the "old" attribute entry after any split ops.
1336 * The INCOMPLETE flag means that we will find the "old"
1337 * attr, not the "new" one.
1339 args
->flags
|= XFS_ATTR_INCOMPLETE
;
1340 state
= xfs_da_state_alloc();
1343 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1344 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1346 error
= xfs_da_node_lookup_int(state
, &retval
);
1351 * Remove the name and update the hashvals in the tree.
1353 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1354 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1355 error
= xfs_attr_leaf_remove(blk
->bp
, args
);
1356 xfs_da_fixhashpath(state
, &state
->path
);
1359 * Check to see if the tree needs to be collapsed.
1361 if (retval
&& (state
->path
.active
> 1)) {
1362 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1363 error
= xfs_da_join(state
);
1365 error
= xfs_bmap_finish(&args
->trans
,
1373 xfs_bmap_cancel(args
->flist
);
1378 * bmap_finish() may have committed the last trans
1379 * and started a new one. We need the inode to be
1380 * in all transactions.
1383 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1384 xfs_trans_ihold(args
->trans
, dp
);
1389 * Commit and start the next trans in the chain.
1391 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1394 } else if (args
->rmtblkno
> 0) {
1396 * Added a "remote" value, just clear the incomplete flag.
1398 error
= xfs_attr_leaf_clearflag(args
);
1406 xfs_da_state_free(state
);
1413 * Remove a name from a B-tree attribute list.
1415 * This will involve walking down the Btree, and may involve joining
1416 * leaf nodes and even joining intermediate nodes up to and including
1417 * the root node (a special case of an intermediate node).
1420 xfs_attr_node_removename(xfs_da_args_t
*args
)
1422 xfs_da_state_t
*state
;
1423 xfs_da_state_blk_t
*blk
;
1426 int retval
, error
, committed
, forkoff
;
1429 * Tie a string around our finger to remind us where we are.
1432 state
= xfs_da_state_alloc();
1434 state
->mp
= dp
->i_mount
;
1435 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1436 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1439 * Search to see if name exists, and get back a pointer to it.
1441 error
= xfs_da_node_lookup_int(state
, &retval
);
1442 if (error
|| (retval
!= EEXIST
)) {
1449 * If there is an out-of-line value, de-allocate the blocks.
1450 * This is done before we remove the attribute so that we don't
1451 * overflow the maximum size of a transaction and/or hit a deadlock.
1453 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1454 ASSERT(blk
->bp
!= NULL
);
1455 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1456 if (args
->rmtblkno
> 0) {
1458 * Fill in disk block numbers in the state structure
1459 * so that we can get the buffers back after we commit
1460 * several transactions in the following calls.
1462 error
= xfs_attr_fillstate(state
);
1467 * Mark the attribute as INCOMPLETE, then bunmapi() the
1470 error
= xfs_attr_leaf_setflag(args
);
1473 error
= xfs_attr_rmtval_remove(args
);
1478 * Refill the state structure with buffers, the prior calls
1479 * released our buffers.
1481 error
= xfs_attr_refillstate(state
);
1487 * Remove the name and update the hashvals in the tree.
1489 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1490 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1491 retval
= xfs_attr_leaf_remove(blk
->bp
, args
);
1492 xfs_da_fixhashpath(state
, &state
->path
);
1495 * Check to see if the tree needs to be collapsed.
1497 if (retval
&& (state
->path
.active
> 1)) {
1498 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1499 error
= xfs_da_join(state
);
1501 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1502 *args
->firstblock
, &committed
);
1507 xfs_bmap_cancel(args
->flist
);
1512 * bmap_finish() may have committed the last trans and started
1513 * a new one. We need the inode to be in all transactions.
1516 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1517 xfs_trans_ihold(args
->trans
, dp
);
1521 * Commit the Btree join operation and start a new trans.
1523 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1528 * If the result is small enough, push it all into the inode.
1530 if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
1532 * Have to get rid of the copy of this dabuf in the state.
1534 ASSERT(state
->path
.active
== 1);
1535 ASSERT(state
->path
.blk
[0].bp
);
1536 xfs_da_buf_done(state
->path
.blk
[0].bp
);
1537 state
->path
.blk
[0].bp
= NULL
;
1539 error
= xfs_da_read_buf(args
->trans
, args
->dp
, 0, -1, &bp
,
1543 ASSERT(be16_to_cpu(((xfs_attr_leafblock_t
*)
1544 bp
->data
)->hdr
.info
.magic
)
1545 == XFS_ATTR_LEAF_MAGIC
);
1547 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1548 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1549 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1550 /* bp is gone due to xfs_da_shrink_inode */
1552 error
= xfs_bmap_finish(&args
->trans
,
1560 xfs_bmap_cancel(args
->flist
);
1565 * bmap_finish() may have committed the last trans
1566 * and started a new one. We need the inode to be
1567 * in all transactions.
1570 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1571 xfs_trans_ihold(args
->trans
, dp
);
1574 xfs_da_brelse(args
->trans
, bp
);
1579 xfs_da_state_free(state
);
1584 * Fill in the disk block numbers in the state structure for the buffers
1585 * that are attached to the state structure.
1586 * This is done so that we can quickly reattach ourselves to those buffers
1587 * after some set of transaction commits have released these buffers.
1590 xfs_attr_fillstate(xfs_da_state_t
*state
)
1592 xfs_da_state_path_t
*path
;
1593 xfs_da_state_blk_t
*blk
;
1597 * Roll down the "path" in the state structure, storing the on-disk
1598 * block number for those buffers in the "path".
1600 path
= &state
->path
;
1601 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1602 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1604 blk
->disk_blkno
= xfs_da_blkno(blk
->bp
);
1605 xfs_da_buf_done(blk
->bp
);
1608 blk
->disk_blkno
= 0;
1613 * Roll down the "altpath" in the state structure, storing the on-disk
1614 * block number for those buffers in the "altpath".
1616 path
= &state
->altpath
;
1617 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1618 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1620 blk
->disk_blkno
= xfs_da_blkno(blk
->bp
);
1621 xfs_da_buf_done(blk
->bp
);
1624 blk
->disk_blkno
= 0;
1632 * Reattach the buffers to the state structure based on the disk block
1633 * numbers stored in the state structure.
1634 * This is done after some set of transaction commits have released those
1635 * buffers from our grip.
1638 xfs_attr_refillstate(xfs_da_state_t
*state
)
1640 xfs_da_state_path_t
*path
;
1641 xfs_da_state_blk_t
*blk
;
1645 * Roll down the "path" in the state structure, storing the on-disk
1646 * block number for those buffers in the "path".
1648 path
= &state
->path
;
1649 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1650 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1651 if (blk
->disk_blkno
) {
1652 error
= xfs_da_read_buf(state
->args
->trans
,
1654 blk
->blkno
, blk
->disk_blkno
,
1655 &blk
->bp
, XFS_ATTR_FORK
);
1664 * Roll down the "altpath" in the state structure, storing the on-disk
1665 * block number for those buffers in the "altpath".
1667 path
= &state
->altpath
;
1668 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1669 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1670 if (blk
->disk_blkno
) {
1671 error
= xfs_da_read_buf(state
->args
->trans
,
1673 blk
->blkno
, blk
->disk_blkno
,
1674 &blk
->bp
, XFS_ATTR_FORK
);
1686 * Look up a filename in a node attribute list.
1688 * This routine gets called for any attribute fork that has more than one
1689 * block, ie: both true Btree attr lists and for single-leaf-blocks with
1690 * "remote" values taking up more blocks.
1693 xfs_attr_node_get(xfs_da_args_t
*args
)
1695 xfs_da_state_t
*state
;
1696 xfs_da_state_blk_t
*blk
;
1700 state
= xfs_da_state_alloc();
1702 state
->mp
= args
->dp
->i_mount
;
1703 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1704 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1707 * Search to see if name exists, and get back a pointer to it.
1709 error
= xfs_da_node_lookup_int(state
, &retval
);
1712 } else if (retval
== EEXIST
) {
1713 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1714 ASSERT(blk
->bp
!= NULL
);
1715 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1718 * Get the value, local or "remote"
1720 retval
= xfs_attr_leaf_getvalue(blk
->bp
, args
);
1721 if (!retval
&& (args
->rmtblkno
> 0)
1722 && !(args
->flags
& ATTR_KERNOVAL
)) {
1723 retval
= xfs_attr_rmtval_get(args
);
1728 * If not in a transaction, we have to release all the buffers.
1730 for (i
= 0; i
< state
->path
.active
; i
++) {
1731 xfs_da_brelse(args
->trans
, state
->path
.blk
[i
].bp
);
1732 state
->path
.blk
[i
].bp
= NULL
;
1735 xfs_da_state_free(state
);
1739 STATIC
int /* error */
1740 xfs_attr_node_list(xfs_attr_list_context_t
*context
)
1742 attrlist_cursor_kern_t
*cursor
;
1743 xfs_attr_leafblock_t
*leaf
;
1744 xfs_da_intnode_t
*node
;
1745 xfs_da_node_entry_t
*btree
;
1749 cursor
= context
->cursor
;
1750 cursor
->initted
= 1;
1753 * Do all sorts of validation on the passed-in cursor structure.
1754 * If anything is amiss, ignore the cursor and look up the hashval
1755 * starting from the btree root.
1758 if (cursor
->blkno
> 0) {
1759 error
= xfs_da_read_buf(NULL
, context
->dp
, cursor
->blkno
, -1,
1760 &bp
, XFS_ATTR_FORK
);
1761 if ((error
!= 0) && (error
!= EFSCORRUPTED
))
1765 switch (be16_to_cpu(node
->hdr
.info
.magic
)) {
1766 case XFS_DA_NODE_MAGIC
:
1767 xfs_attr_trace_l_cn("wrong blk", context
, node
);
1768 xfs_da_brelse(NULL
, bp
);
1771 case XFS_ATTR_LEAF_MAGIC
:
1773 if (cursor
->hashval
> be32_to_cpu(leaf
->entries
[
1774 be16_to_cpu(leaf
->hdr
.count
)-1].hashval
)) {
1775 xfs_attr_trace_l_cl("wrong blk",
1777 xfs_da_brelse(NULL
, bp
);
1779 } else if (cursor
->hashval
<=
1780 be32_to_cpu(leaf
->entries
[0].hashval
)) {
1781 xfs_attr_trace_l_cl("maybe wrong blk",
1783 xfs_da_brelse(NULL
, bp
);
1788 xfs_attr_trace_l_c("wrong blk - ??", context
);
1789 xfs_da_brelse(NULL
, bp
);
1796 * We did not find what we expected given the cursor's contents,
1797 * so we start from the top and work down based on the hash value.
1798 * Note that start of node block is same as start of leaf block.
1803 error
= xfs_da_read_buf(NULL
, context
->dp
,
1804 cursor
->blkno
, -1, &bp
,
1808 if (unlikely(bp
== NULL
)) {
1809 XFS_ERROR_REPORT("xfs_attr_node_list(2)",
1811 context
->dp
->i_mount
);
1812 return(XFS_ERROR(EFSCORRUPTED
));
1815 if (be16_to_cpu(node
->hdr
.info
.magic
)
1816 == XFS_ATTR_LEAF_MAGIC
)
1818 if (unlikely(be16_to_cpu(node
->hdr
.info
.magic
)
1819 != XFS_DA_NODE_MAGIC
)) {
1820 XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
1822 context
->dp
->i_mount
,
1824 xfs_da_brelse(NULL
, bp
);
1825 return(XFS_ERROR(EFSCORRUPTED
));
1827 btree
= node
->btree
;
1828 for (i
= 0; i
< be16_to_cpu(node
->hdr
.count
);
1831 <= be32_to_cpu(btree
->hashval
)) {
1832 cursor
->blkno
= be32_to_cpu(btree
->before
);
1833 xfs_attr_trace_l_cb("descending",
1838 if (i
== be16_to_cpu(node
->hdr
.count
)) {
1839 xfs_da_brelse(NULL
, bp
);
1842 xfs_da_brelse(NULL
, bp
);
1848 * Roll upward through the blocks, processing each leaf block in
1849 * order. As long as there is space in the result buffer, keep
1850 * adding the information.
1854 if (unlikely(be16_to_cpu(leaf
->hdr
.info
.magic
)
1855 != XFS_ATTR_LEAF_MAGIC
)) {
1856 XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
1858 context
->dp
->i_mount
, leaf
);
1859 xfs_da_brelse(NULL
, bp
);
1860 return(XFS_ERROR(EFSCORRUPTED
));
1862 error
= xfs_attr_leaf_list_int(bp
, context
);
1863 if (error
|| !leaf
->hdr
.info
.forw
)
1864 break; /* not really an error, buffer full or EOF */
1865 cursor
->blkno
= be32_to_cpu(leaf
->hdr
.info
.forw
);
1866 xfs_da_brelse(NULL
, bp
);
1867 error
= xfs_da_read_buf(NULL
, context
->dp
, cursor
->blkno
, -1,
1868 &bp
, XFS_ATTR_FORK
);
1871 if (unlikely((bp
== NULL
))) {
1872 XFS_ERROR_REPORT("xfs_attr_node_list(5)",
1874 context
->dp
->i_mount
);
1875 return(XFS_ERROR(EFSCORRUPTED
));
1878 xfs_da_brelse(NULL
, bp
);
1883 /*========================================================================
1884 * External routines for manipulating out-of-line attribute values.
1885 *========================================================================*/
1888 * Read the value associated with an attribute from the out-of-line buffer
1889 * that we stored it in.
1892 xfs_attr_rmtval_get(xfs_da_args_t
*args
)
1894 xfs_bmbt_irec_t map
[ATTR_RMTVALUE_MAPSIZE
];
1899 int nmap
, error
, tmp
, valuelen
, blkcnt
, i
;
1902 ASSERT(!(args
->flags
& ATTR_KERNOVAL
));
1904 mp
= args
->dp
->i_mount
;
1906 valuelen
= args
->valuelen
;
1907 lblkno
= args
->rmtblkno
;
1908 while (valuelen
> 0) {
1909 nmap
= ATTR_RMTVALUE_MAPSIZE
;
1910 error
= xfs_bmapi(args
->trans
, args
->dp
, (xfs_fileoff_t
)lblkno
,
1912 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
1913 NULL
, 0, map
, &nmap
, NULL
);
1918 for (i
= 0; (i
< nmap
) && (valuelen
> 0); i
++) {
1919 ASSERT((map
[i
].br_startblock
!= DELAYSTARTBLOCK
) &&
1920 (map
[i
].br_startblock
!= HOLESTARTBLOCK
));
1921 dblkno
= XFS_FSB_TO_DADDR(mp
, map
[i
].br_startblock
);
1922 blkcnt
= XFS_FSB_TO_BB(mp
, map
[i
].br_blockcount
);
1923 error
= xfs_read_buf(mp
, mp
->m_ddev_targp
, dblkno
,
1924 blkcnt
, XFS_BUF_LOCK
, &bp
);
1928 tmp
= (valuelen
< XFS_BUF_SIZE(bp
))
1929 ? valuelen
: XFS_BUF_SIZE(bp
);
1930 xfs_biomove(bp
, 0, tmp
, dst
, XFS_B_READ
);
1935 lblkno
+= map
[i
].br_blockcount
;
1938 ASSERT(valuelen
== 0);
1943 * Write the value associated with an attribute into the out-of-line buffer
1944 * that we have defined for it.
1947 xfs_attr_rmtval_set(xfs_da_args_t
*args
)
1950 xfs_fileoff_t lfileoff
;
1952 xfs_bmbt_irec_t map
;
1957 int blkcnt
, valuelen
, nmap
, error
, tmp
, committed
;
1964 * Find a "hole" in the attribute address space large enough for
1965 * us to drop the new attribute's value into.
1967 blkcnt
= XFS_B_TO_FSB(mp
, args
->valuelen
);
1969 error
= xfs_bmap_first_unused(args
->trans
, args
->dp
, blkcnt
, &lfileoff
,
1974 args
->rmtblkno
= lblkno
= (xfs_dablk_t
)lfileoff
;
1975 args
->rmtblkcnt
= blkcnt
;
1978 * Roll through the "value", allocating blocks on disk as required.
1980 while (blkcnt
> 0) {
1982 * Allocate a single extent, up to the size of the value.
1984 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1986 error
= xfs_bmapi(args
->trans
, dp
, (xfs_fileoff_t
)lblkno
,
1988 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
|
1990 args
->firstblock
, args
->total
, &map
, &nmap
,
1993 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1994 *args
->firstblock
, &committed
);
1999 xfs_bmap_cancel(args
->flist
);
2004 * bmap_finish() may have committed the last trans and started
2005 * a new one. We need the inode to be in all transactions.
2008 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
2009 xfs_trans_ihold(args
->trans
, dp
);
2013 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2014 (map
.br_startblock
!= HOLESTARTBLOCK
));
2015 lblkno
+= map
.br_blockcount
;
2016 blkcnt
-= map
.br_blockcount
;
2019 * Start the next trans in the chain.
2021 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
2026 * Roll through the "value", copying the attribute value to the
2027 * already-allocated blocks. Blocks are written synchronously
2028 * so that we can know they are all on disk before we turn off
2029 * the INCOMPLETE flag.
2031 lblkno
= args
->rmtblkno
;
2032 valuelen
= args
->valuelen
;
2033 while (valuelen
> 0) {
2035 * Try to remember where we decided to put the value.
2037 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2039 error
= xfs_bmapi(NULL
, dp
, (xfs_fileoff_t
)lblkno
,
2041 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2042 args
->firstblock
, 0, &map
, &nmap
, NULL
);
2047 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2048 (map
.br_startblock
!= HOLESTARTBLOCK
));
2050 dblkno
= XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
2051 blkcnt
= XFS_FSB_TO_BB(mp
, map
.br_blockcount
);
2053 bp
= xfs_buf_get_flags(mp
->m_ddev_targp
, dblkno
,
2054 blkcnt
, XFS_BUF_LOCK
);
2056 ASSERT(!XFS_BUF_GETERROR(bp
));
2058 tmp
= (valuelen
< XFS_BUF_SIZE(bp
)) ? valuelen
:
2060 xfs_biomove(bp
, 0, tmp
, src
, XFS_B_WRITE
);
2061 if (tmp
< XFS_BUF_SIZE(bp
))
2062 xfs_biozero(bp
, tmp
, XFS_BUF_SIZE(bp
) - tmp
);
2063 if ((error
= xfs_bwrite(mp
, bp
))) {/* GROT: NOTE: synchronous write */
2069 lblkno
+= map
.br_blockcount
;
2071 ASSERT(valuelen
== 0);
2076 * Remove the value associated with an attribute by deleting the
2077 * out-of-line buffer that it is stored on.
2080 xfs_attr_rmtval_remove(xfs_da_args_t
*args
)
2083 xfs_bmbt_irec_t map
;
2087 int valuelen
, blkcnt
, nmap
, error
, done
, committed
;
2089 mp
= args
->dp
->i_mount
;
2092 * Roll through the "value", invalidating the attribute value's
2095 lblkno
= args
->rmtblkno
;
2096 valuelen
= args
->rmtblkcnt
;
2097 while (valuelen
> 0) {
2099 * Try to remember where we decided to put the value.
2101 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2103 error
= xfs_bmapi(NULL
, args
->dp
, (xfs_fileoff_t
)lblkno
,
2105 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2106 args
->firstblock
, 0, &map
, &nmap
,
2112 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2113 (map
.br_startblock
!= HOLESTARTBLOCK
));
2115 dblkno
= XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
2116 blkcnt
= XFS_FSB_TO_BB(mp
, map
.br_blockcount
);
2119 * If the "remote" value is in the cache, remove it.
2121 bp
= xfs_incore(mp
->m_ddev_targp
, dblkno
, blkcnt
,
2122 XFS_INCORE_TRYLOCK
);
2125 XFS_BUF_UNDELAYWRITE(bp
);
2130 valuelen
-= map
.br_blockcount
;
2132 lblkno
+= map
.br_blockcount
;
2136 * Keep de-allocating extents until the remote-value region is gone.
2138 lblkno
= args
->rmtblkno
;
2139 blkcnt
= args
->rmtblkcnt
;
2142 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2143 error
= xfs_bunmapi(args
->trans
, args
->dp
, lblkno
, blkcnt
,
2144 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2145 1, args
->firstblock
, args
->flist
, &done
);
2147 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
2148 *args
->firstblock
, &committed
);
2153 xfs_bmap_cancel(args
->flist
);
2158 * bmap_finish() may have committed the last trans and started
2159 * a new one. We need the inode to be in all transactions.
2162 xfs_trans_ijoin(args
->trans
, args
->dp
, XFS_ILOCK_EXCL
);
2163 xfs_trans_ihold(args
->trans
, args
->dp
);
2167 * Close out trans and start the next one in the chain.
2169 if ((error
= xfs_attr_rolltrans(&args
->trans
, args
->dp
)))
2175 #if defined(XFS_ATTR_TRACE)
2177 * Add a trace buffer entry for an attr_list context structure.
2180 xfs_attr_trace_l_c(char *where
, struct xfs_attr_list_context
*context
)
2182 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_C
, where
,
2183 (__psunsigned_t
)context
->dp
,
2184 (__psunsigned_t
)context
->cursor
->hashval
,
2185 (__psunsigned_t
)context
->cursor
->blkno
,
2186 (__psunsigned_t
)context
->cursor
->offset
,
2187 (__psunsigned_t
)context
->alist
,
2188 (__psunsigned_t
)context
->bufsize
,
2189 (__psunsigned_t
)context
->count
,
2190 (__psunsigned_t
)context
->firstu
,
2192 ((context
->count
> 0) &&
2193 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2194 ? (ATTR_ENTRY(context
->alist
,
2195 context
->count
-1)->a_valuelen
)
2197 (__psunsigned_t
)context
->dupcnt
,
2198 (__psunsigned_t
)context
->flags
,
2199 (__psunsigned_t
)NULL
,
2200 (__psunsigned_t
)NULL
,
2201 (__psunsigned_t
)NULL
);
2205 * Add a trace buffer entry for a context structure and a Btree node.
2208 xfs_attr_trace_l_cn(char *where
, struct xfs_attr_list_context
*context
,
2209 struct xfs_da_intnode
*node
)
2211 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CN
, where
,
2212 (__psunsigned_t
)context
->dp
,
2213 (__psunsigned_t
)context
->cursor
->hashval
,
2214 (__psunsigned_t
)context
->cursor
->blkno
,
2215 (__psunsigned_t
)context
->cursor
->offset
,
2216 (__psunsigned_t
)context
->alist
,
2217 (__psunsigned_t
)context
->bufsize
,
2218 (__psunsigned_t
)context
->count
,
2219 (__psunsigned_t
)context
->firstu
,
2221 ((context
->count
> 0) &&
2222 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2223 ? (ATTR_ENTRY(context
->alist
,
2224 context
->count
-1)->a_valuelen
)
2226 (__psunsigned_t
)context
->dupcnt
,
2227 (__psunsigned_t
)context
->flags
,
2228 (__psunsigned_t
)be16_to_cpu(node
->hdr
.count
),
2229 (__psunsigned_t
)be32_to_cpu(node
->btree
[0].hashval
),
2230 (__psunsigned_t
)be32_to_cpu(node
->btree
[
2231 be16_to_cpu(node
->hdr
.count
)-1].hashval
));
2235 * Add a trace buffer entry for a context structure and a Btree element.
2238 xfs_attr_trace_l_cb(char *where
, struct xfs_attr_list_context
*context
,
2239 struct xfs_da_node_entry
*btree
)
2241 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CB
, where
,
2242 (__psunsigned_t
)context
->dp
,
2243 (__psunsigned_t
)context
->cursor
->hashval
,
2244 (__psunsigned_t
)context
->cursor
->blkno
,
2245 (__psunsigned_t
)context
->cursor
->offset
,
2246 (__psunsigned_t
)context
->alist
,
2247 (__psunsigned_t
)context
->bufsize
,
2248 (__psunsigned_t
)context
->count
,
2249 (__psunsigned_t
)context
->firstu
,
2251 ((context
->count
> 0) &&
2252 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2253 ? (ATTR_ENTRY(context
->alist
,
2254 context
->count
-1)->a_valuelen
)
2256 (__psunsigned_t
)context
->dupcnt
,
2257 (__psunsigned_t
)context
->flags
,
2258 (__psunsigned_t
)be32_to_cpu(btree
->hashval
),
2259 (__psunsigned_t
)be32_to_cpu(btree
->before
),
2260 (__psunsigned_t
)NULL
);
2264 * Add a trace buffer entry for a context structure and a leaf block.
2267 xfs_attr_trace_l_cl(char *where
, struct xfs_attr_list_context
*context
,
2268 struct xfs_attr_leafblock
*leaf
)
2270 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CL
, where
,
2271 (__psunsigned_t
)context
->dp
,
2272 (__psunsigned_t
)context
->cursor
->hashval
,
2273 (__psunsigned_t
)context
->cursor
->blkno
,
2274 (__psunsigned_t
)context
->cursor
->offset
,
2275 (__psunsigned_t
)context
->alist
,
2276 (__psunsigned_t
)context
->bufsize
,
2277 (__psunsigned_t
)context
->count
,
2278 (__psunsigned_t
)context
->firstu
,
2280 ((context
->count
> 0) &&
2281 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2282 ? (ATTR_ENTRY(context
->alist
,
2283 context
->count
-1)->a_valuelen
)
2285 (__psunsigned_t
)context
->dupcnt
,
2286 (__psunsigned_t
)context
->flags
,
2287 (__psunsigned_t
)be16_to_cpu(leaf
->hdr
.count
),
2288 (__psunsigned_t
)be32_to_cpu(leaf
->entries
[0].hashval
),
2289 (__psunsigned_t
)be32_to_cpu(leaf
->entries
[
2290 be16_to_cpu(leaf
->hdr
.count
)-1].hashval
));
2294 * Add a trace buffer entry for the arguments given to the routine,
2298 xfs_attr_trace_enter(int type
, char *where
,
2299 __psunsigned_t a2
, __psunsigned_t a3
,
2300 __psunsigned_t a4
, __psunsigned_t a5
,
2301 __psunsigned_t a6
, __psunsigned_t a7
,
2302 __psunsigned_t a8
, __psunsigned_t a9
,
2303 __psunsigned_t a10
, __psunsigned_t a11
,
2304 __psunsigned_t a12
, __psunsigned_t a13
,
2305 __psunsigned_t a14
, __psunsigned_t a15
)
2307 ASSERT(xfs_attr_trace_buf
);
2308 ktrace_enter(xfs_attr_trace_buf
, (void *)((__psunsigned_t
)type
),
2310 (void *)a2
, (void *)a3
, (void *)a4
,
2311 (void *)a5
, (void *)a6
, (void *)a7
,
2312 (void *)a8
, (void *)a9
, (void *)a10
,
2313 (void *)a11
, (void *)a12
, (void *)a13
,
2314 (void *)a14
, (void *)a15
);
2316 #endif /* XFS_ATTR_TRACE */
2319 /*========================================================================
2320 * System (pseudo) namespace attribute interface routines.
2321 *========================================================================*/
2324 posix_acl_access_set(
2325 vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2327 return xfs_acl_vset(vp
, data
, size
, _ACL_TYPE_ACCESS
);
2331 posix_acl_access_remove(
2332 struct vnode
*vp
, char *name
, int xflags
)
2334 return xfs_acl_vremove(vp
, _ACL_TYPE_ACCESS
);
2338 posix_acl_access_get(
2339 vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2341 return xfs_acl_vget(vp
, data
, size
, _ACL_TYPE_ACCESS
);
2345 posix_acl_access_exists(
2348 return xfs_acl_vhasacl_access(vp
);
2352 posix_acl_default_set(
2353 vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2355 return xfs_acl_vset(vp
, data
, size
, _ACL_TYPE_DEFAULT
);
2359 posix_acl_default_get(
2360 vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2362 return xfs_acl_vget(vp
, data
, size
, _ACL_TYPE_DEFAULT
);
2366 posix_acl_default_remove(
2367 struct vnode
*vp
, char *name
, int xflags
)
2369 return xfs_acl_vremove(vp
, _ACL_TYPE_DEFAULT
);
2373 posix_acl_default_exists(
2376 return xfs_acl_vhasacl_default(vp
);
2379 STATIC
struct attrnames posix_acl_access
= {
2380 .attr_name
= "posix_acl_access",
2381 .attr_namelen
= sizeof("posix_acl_access") - 1,
2382 .attr_get
= posix_acl_access_get
,
2383 .attr_set
= posix_acl_access_set
,
2384 .attr_remove
= posix_acl_access_remove
,
2385 .attr_exists
= posix_acl_access_exists
,
2388 STATIC
struct attrnames posix_acl_default
= {
2389 .attr_name
= "posix_acl_default",
2390 .attr_namelen
= sizeof("posix_acl_default") - 1,
2391 .attr_get
= posix_acl_default_get
,
2392 .attr_set
= posix_acl_default_set
,
2393 .attr_remove
= posix_acl_default_remove
,
2394 .attr_exists
= posix_acl_default_exists
,
2397 STATIC
struct attrnames
*attr_system_names
[] =
2398 { &posix_acl_access
, &posix_acl_default
};
2401 /*========================================================================
2402 * Namespace-prefix-style attribute name interface routines.
2403 *========================================================================*/
2407 struct vnode
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2411 VOP_ATTR_SET(vp
, name
, data
, size
, xflags
, NULL
, error
);
2417 struct vnode
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2419 int error
, asize
= size
;
2421 VOP_ATTR_GET(vp
, name
, data
, &asize
, xflags
, NULL
, error
);
2428 attr_generic_remove(
2429 struct vnode
*vp
, char *name
, int xflags
)
2433 VOP_ATTR_REMOVE(vp
, name
, xflags
, NULL
, error
);
2438 attr_generic_listadd(
2439 attrnames_t
*prefix
,
2440 attrnames_t
*namesp
,
2445 char *p
= data
+ *result
;
2447 *result
+= prefix
->attr_namelen
;
2448 *result
+= namesp
->attr_namelen
+ 1;
2453 strcpy(p
, prefix
->attr_name
);
2454 p
+= prefix
->attr_namelen
;
2455 strcpy(p
, namesp
->attr_name
);
2456 p
+= namesp
->attr_namelen
+ 1;
2467 attrnames_t
*namesp
;
2470 for (i
= 0; i
< ATTR_SYSCOUNT
; i
++) {
2471 namesp
= attr_system_names
[i
];
2472 if (!namesp
->attr_exists
|| !namesp
->attr_exists(vp
))
2474 error
= attr_generic_listadd(&attr_system
, namesp
,
2475 data
, size
, result
);
2484 struct vnode
*vp
, void *data
, size_t size
, int xflags
, ssize_t
*result
)
2486 attrlist_cursor_kern_t cursor
= { 0 };
2489 VOP_ATTR_LIST(vp
, data
, size
, xflags
, &cursor
, NULL
, error
);
2493 return attr_system_list(vp
, data
, size
, result
);
2497 attr_lookup_namespace(
2499 struct attrnames
**names
,
2504 for (i
= 0; i
< nnames
; i
++)
2505 if (!strncmp(name
, names
[i
]->attr_name
, names
[i
]->attr_namelen
))
2511 * Some checks to prevent people abusing EAs to get over quota:
2512 * - Don't allow modifying user EAs on devices/symlinks;
2513 * - Don't allow modifying user EAs if sticky bit set;
2520 struct inode
*inode
= vn_to_inode(vp
);
2522 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
2524 if (!S_ISREG(inode
->i_mode
) && !S_ISDIR(inode
->i_mode
) &&
2525 !capable(CAP_SYS_ADMIN
))
2527 if (S_ISDIR(inode
->i_mode
) && (inode
->i_mode
& S_ISVTX
) &&
2528 (current_fsuid(cred
) != inode
->i_uid
) && !capable(CAP_FOWNER
))
2534 attr_trusted_capable(
2538 struct inode
*inode
= vn_to_inode(vp
);
2540 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
2542 if (!capable(CAP_SYS_ADMIN
))
2548 attr_secure_capable(
2552 return -ENOSECURITY
;
2557 struct vnode
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2559 attrnames_t
*namesp
;
2562 if (xflags
& ATTR_CREATE
)
2565 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2568 error
= namesp
->attr_set(vp
, name
, data
, size
, xflags
);
2570 error
= vn_revalidate(vp
);
2576 struct vnode
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2578 attrnames_t
*namesp
;
2580 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2583 return namesp
->attr_get(vp
, name
, data
, size
, xflags
);
2588 struct vnode
*vp
, char *name
, int xflags
)
2590 attrnames_t
*namesp
;
2592 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2595 return namesp
->attr_remove(vp
, name
, xflags
);
2598 struct attrnames attr_system
= {
2599 .attr_name
= "system.",
2600 .attr_namelen
= sizeof("system.") - 1,
2601 .attr_flag
= ATTR_SYSTEM
,
2602 .attr_get
= attr_system_get
,
2603 .attr_set
= attr_system_set
,
2604 .attr_remove
= attr_system_remove
,
2605 .attr_capable
= (attrcapable_t
)fs_noerr
,
2608 struct attrnames attr_trusted
= {
2609 .attr_name
= "trusted.",
2610 .attr_namelen
= sizeof("trusted.") - 1,
2611 .attr_flag
= ATTR_ROOT
,
2612 .attr_get
= attr_generic_get
,
2613 .attr_set
= attr_generic_set
,
2614 .attr_remove
= attr_generic_remove
,
2615 .attr_capable
= attr_trusted_capable
,
2618 struct attrnames attr_secure
= {
2619 .attr_name
= "security.",
2620 .attr_namelen
= sizeof("security.") - 1,
2621 .attr_flag
= ATTR_SECURE
,
2622 .attr_get
= attr_generic_get
,
2623 .attr_set
= attr_generic_set
,
2624 .attr_remove
= attr_generic_remove
,
2625 .attr_capable
= attr_secure_capable
,
2628 struct attrnames attr_user
= {
2629 .attr_name
= "user.",
2630 .attr_namelen
= sizeof("user.") - 1,
2631 .attr_get
= attr_generic_get
,
2632 .attr_set
= attr_generic_set
,
2633 .attr_remove
= attr_generic_remove
,
2634 .attr_capable
= attr_user_capable
,
2637 struct attrnames
*attr_namespaces
[] =
2638 { &attr_system
, &attr_trusted
, &attr_secure
, &attr_user
};