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
20 #include "xfs_types.h"
24 #include "xfs_trans.h"
29 #include "xfs_dmapi.h"
30 #include "xfs_mount.h"
31 #include "xfs_da_btree.h"
32 #include "xfs_bmap_btree.h"
33 #include "xfs_alloc_btree.h"
34 #include "xfs_ialloc_btree.h"
35 #include "xfs_dir_sf.h"
36 #include "xfs_dir2_sf.h"
37 #include "xfs_attr_sf.h"
38 #include "xfs_dinode.h"
39 #include "xfs_inode.h"
40 #include "xfs_alloc.h"
41 #include "xfs_btree.h"
42 #include "xfs_inode_item.h"
45 #include "xfs_attr_leaf.h"
46 #include "xfs_error.h"
47 #include "xfs_quota.h"
48 #include "xfs_trans_space.h"
55 * Provide the external interfaces to manage attribute lists.
58 #define ATTR_SYSCOUNT 2
59 STATIC
struct attrnames posix_acl_access
;
60 STATIC
struct attrnames posix_acl_default
;
61 STATIC
struct attrnames
*attr_system_names
[ATTR_SYSCOUNT
];
63 /*========================================================================
64 * Function prototypes for the kernel.
65 *========================================================================*/
68 * Internal routines when attribute list fits inside the inode.
70 STATIC
int xfs_attr_shortform_addname(xfs_da_args_t
*args
);
73 * Internal routines when attribute list is one block.
75 STATIC
int xfs_attr_leaf_get(xfs_da_args_t
*args
);
76 STATIC
int xfs_attr_leaf_addname(xfs_da_args_t
*args
);
77 STATIC
int xfs_attr_leaf_removename(xfs_da_args_t
*args
);
78 STATIC
int xfs_attr_leaf_list(xfs_attr_list_context_t
*context
);
81 * Internal routines when attribute list is more than one block.
83 STATIC
int xfs_attr_node_get(xfs_da_args_t
*args
);
84 STATIC
int xfs_attr_node_addname(xfs_da_args_t
*args
);
85 STATIC
int xfs_attr_node_removename(xfs_da_args_t
*args
);
86 STATIC
int xfs_attr_node_list(xfs_attr_list_context_t
*context
);
87 STATIC
int xfs_attr_fillstate(xfs_da_state_t
*state
);
88 STATIC
int xfs_attr_refillstate(xfs_da_state_t
*state
);
91 * Routines to manipulate out-of-line attribute values.
93 STATIC
int xfs_attr_rmtval_get(xfs_da_args_t
*args
);
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 * Determine space new attribute will use, and if it would be
203 * "local" or "remote" (note: local != inline).
205 size
= xfs_attr_leaf_newentsize(namelen
, valuelen
,
206 mp
->m_sb
.sb_blocksize
, &local
);
209 * If the inode doesn't have an attribute fork, add one.
210 * (inode must not be locked when we call this routine)
212 if (XFS_IFORK_Q(dp
) == 0) {
213 if ((error
= xfs_bmap_add_attrfork(dp
, size
, rsvd
)))
218 * Fill in the arg structure for this request.
220 memset((char *)&args
, 0, sizeof(args
));
222 args
.namelen
= namelen
;
224 args
.valuelen
= valuelen
;
226 args
.hashval
= xfs_da_hashname(args
.name
, args
.namelen
);
228 args
.firstblock
= &firstblock
;
230 args
.whichfork
= XFS_ATTR_FORK
;
234 nblks
= XFS_DAENTER_SPACE_RES(mp
, XFS_ATTR_FORK
);
236 if (size
> (mp
->m_sb
.sb_blocksize
>> 1)) {
237 /* Double split possible */
241 uint dblocks
= XFS_B_TO_FSB(mp
, valuelen
);
242 /* Out of line attribute, cannot double split, but make
243 * room for the attribute value itself.
246 nblks
+= XFS_NEXTENTADD_SPACE_RES(mp
, dblocks
, XFS_ATTR_FORK
);
249 /* Size is now blocks for attribute data */
253 * Start our first transaction of the day.
255 * All future transactions during this code must be "chained" off
256 * this one via the trans_dup() call. All transactions will contain
257 * the inode, and the inode will always be marked with trans_ihold().
258 * Since the inode will be locked in all transactions, we must log
259 * the inode in every transaction to let it float upward through
262 args
.trans
= xfs_trans_alloc(mp
, XFS_TRANS_ATTR_SET
);
265 * Root fork attributes can use reserved data blocks for this
266 * operation if necessary
270 args
.trans
->t_flags
|= XFS_TRANS_RESERVE
;
272 if ((error
= xfs_trans_reserve(args
.trans
, (uint
) nblks
,
273 XFS_ATTRSET_LOG_RES(mp
, nblks
),
274 0, XFS_TRANS_PERM_LOG_RES
,
275 XFS_ATTRSET_LOG_COUNT
))) {
276 xfs_trans_cancel(args
.trans
, 0);
279 xfs_ilock(dp
, XFS_ILOCK_EXCL
);
281 error
= XFS_TRANS_RESERVE_QUOTA_NBLKS(mp
, args
.trans
, dp
, nblks
, 0,
282 rsvd
? XFS_QMOPT_RES_REGBLKS
| XFS_QMOPT_FORCE_RES
:
283 XFS_QMOPT_RES_REGBLKS
);
285 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
286 xfs_trans_cancel(args
.trans
, XFS_TRANS_RELEASE_LOG_RES
);
290 xfs_trans_ijoin(args
.trans
, dp
, XFS_ILOCK_EXCL
);
291 xfs_trans_ihold(args
.trans
, dp
);
294 * If the attribute list is non-existant or a shortform list,
295 * upgrade it to a single-leaf-block attribute list.
297 if ((dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
298 ((dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
) &&
299 (dp
->i_d
.di_anextents
== 0))) {
302 * Build initial attribute list (if required).
304 if (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
)
305 xfs_attr_shortform_create(&args
);
308 * Try to add the attr to the attribute list in
311 error
= xfs_attr_shortform_addname(&args
);
312 if (error
!= ENOSPC
) {
314 * Commit the shortform mods, and we're done.
315 * NOTE: this is also the error path (EEXIST, etc).
317 ASSERT(args
.trans
!= NULL
);
320 * If this is a synchronous mount, make sure that
321 * the transaction goes to disk before returning
324 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
325 xfs_trans_set_sync(args
.trans
);
327 err2
= xfs_trans_commit(args
.trans
,
328 XFS_TRANS_RELEASE_LOG_RES
,
330 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
333 * Hit the inode change time.
335 if (!error
&& (flags
& ATTR_KERNOTIME
) == 0) {
336 xfs_ichgtime(dp
, XFS_ICHGTIME_CHG
);
338 return(error
== 0 ? err2
: error
);
342 * It won't fit in the shortform, transform to a leaf block.
343 * GROT: another possible req'mt for a double-split btree op.
345 XFS_BMAP_INIT(args
.flist
, args
.firstblock
);
346 error
= xfs_attr_shortform_to_leaf(&args
);
348 error
= xfs_bmap_finish(&args
.trans
, args
.flist
,
349 *args
.firstblock
, &committed
);
354 xfs_bmap_cancel(&flist
);
359 * bmap_finish() may have committed the last trans and started
360 * a new one. We need the inode to be in all transactions.
363 xfs_trans_ijoin(args
.trans
, dp
, XFS_ILOCK_EXCL
);
364 xfs_trans_ihold(args
.trans
, dp
);
368 * Commit the leaf transformation. We'll need another (linked)
369 * transaction to add the new attribute to the leaf.
371 if ((error
= xfs_attr_rolltrans(&args
.trans
, dp
)))
376 if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
377 error
= xfs_attr_leaf_addname(&args
);
379 error
= xfs_attr_node_addname(&args
);
386 * If this is a synchronous mount, make sure that the
387 * transaction goes to disk before returning to the user.
389 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
390 xfs_trans_set_sync(args
.trans
);
394 * Commit the last in the sequence of transactions.
396 xfs_trans_log_inode(args
.trans
, dp
, XFS_ILOG_CORE
);
397 error
= xfs_trans_commit(args
.trans
, XFS_TRANS_RELEASE_LOG_RES
,
399 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
402 * Hit the inode change time.
404 if (!error
&& (flags
& ATTR_KERNOTIME
) == 0) {
405 xfs_ichgtime(dp
, XFS_ICHGTIME_CHG
);
412 xfs_trans_cancel(args
.trans
,
413 XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
414 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
419 xfs_attr_set(bhv_desc_t
*bdp
, const char *name
, char *value
, int valuelen
, int flags
,
425 namelen
= strlen(name
);
426 if (namelen
>= MAXNAMELEN
)
427 return EFAULT
; /* match IRIX behaviour */
429 XFS_STATS_INC(xs_attr_set
);
431 dp
= XFS_BHVTOI(bdp
);
432 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
435 return xfs_attr_set_int(dp
, name
, namelen
, value
, valuelen
, flags
);
439 * Generic handler routine to remove a name from an attribute list.
440 * Transitions attribute list from Btree to shortform as necessary.
443 xfs_attr_remove_int(xfs_inode_t
*dp
, const char *name
, int namelen
, int flags
)
446 xfs_fsblock_t firstblock
;
447 xfs_bmap_free_t flist
;
449 xfs_mount_t
*mp
= dp
->i_mount
;
452 * Fill in the arg structure for this request.
454 memset((char *)&args
, 0, sizeof(args
));
456 args
.namelen
= namelen
;
458 args
.hashval
= xfs_da_hashname(args
.name
, args
.namelen
);
460 args
.firstblock
= &firstblock
;
463 args
.whichfork
= XFS_ATTR_FORK
;
466 * Attach the dquots to the inode.
468 if ((error
= XFS_QM_DQATTACH(mp
, dp
, 0)))
472 * Start our first transaction of the day.
474 * All future transactions during this code must be "chained" off
475 * this one via the trans_dup() call. All transactions will contain
476 * the inode, and the inode will always be marked with trans_ihold().
477 * Since the inode will be locked in all transactions, we must log
478 * the inode in every transaction to let it float upward through
481 args
.trans
= xfs_trans_alloc(mp
, XFS_TRANS_ATTR_RM
);
484 * Root fork attributes can use reserved data blocks for this
485 * operation if necessary
488 if (flags
& ATTR_ROOT
)
489 args
.trans
->t_flags
|= XFS_TRANS_RESERVE
;
491 if ((error
= xfs_trans_reserve(args
.trans
,
492 XFS_ATTRRM_SPACE_RES(mp
),
493 XFS_ATTRRM_LOG_RES(mp
),
494 0, XFS_TRANS_PERM_LOG_RES
,
495 XFS_ATTRRM_LOG_COUNT
))) {
496 xfs_trans_cancel(args
.trans
, 0);
500 xfs_ilock(dp
, XFS_ILOCK_EXCL
);
502 * No need to make quota reservations here. We expect to release some
503 * blocks not allocate in the common case.
505 xfs_trans_ijoin(args
.trans
, dp
, XFS_ILOCK_EXCL
);
506 xfs_trans_ihold(args
.trans
, dp
);
509 * Decide on what work routines to call based on the inode size.
511 if (XFS_IFORK_Q(dp
) == 0 ||
512 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
513 dp
->i_d
.di_anextents
== 0)) {
514 error
= XFS_ERROR(ENOATTR
);
517 if (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) {
518 ASSERT(dp
->i_afp
->if_flags
& XFS_IFINLINE
);
519 error
= xfs_attr_shortform_remove(&args
);
523 } else if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
524 error
= xfs_attr_leaf_removename(&args
);
526 error
= xfs_attr_node_removename(&args
);
533 * If this is a synchronous mount, make sure that the
534 * transaction goes to disk before returning to the user.
536 if (mp
->m_flags
& XFS_MOUNT_WSYNC
) {
537 xfs_trans_set_sync(args
.trans
);
541 * Commit the last in the sequence of transactions.
543 xfs_trans_log_inode(args
.trans
, dp
, XFS_ILOG_CORE
);
544 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 * Generate a list of extended attribute names and optionally
595 * also value lengths. Positive return value follows the XFS
596 * convention of being an error, zero or negative return code
597 * is the length of the buffer returned (negated), indicating
601 xfs_attr_list(bhv_desc_t
*bdp
, char *buffer
, int bufsize
, int flags
,
602 attrlist_cursor_kern_t
*cursor
, struct cred
*cred
)
604 xfs_attr_list_context_t context
;
608 XFS_STATS_INC(xs_attr_list
);
611 * Validate the cursor.
613 if (cursor
->pad1
|| cursor
->pad2
)
614 return(XFS_ERROR(EINVAL
));
615 if ((cursor
->initted
== 0) &&
616 (cursor
->hashval
|| cursor
->blkno
|| cursor
->offset
))
617 return(XFS_ERROR(EINVAL
));
620 * Check for a properly aligned buffer.
622 if (((long)buffer
) & (sizeof(int)-1))
623 return(XFS_ERROR(EFAULT
));
624 if (flags
& ATTR_KERNOVAL
)
628 * Initialize the output buffer.
630 context
.dp
= dp
= XFS_BHVTOI(bdp
);
631 context
.cursor
= cursor
;
635 context
.flags
= flags
;
636 if (!(flags
& ATTR_KERNAMELS
)) {
637 context
.bufsize
= (bufsize
& ~(sizeof(int)-1)); /* align */
638 context
.firstu
= context
.bufsize
;
639 context
.alist
= (attrlist_t
*)buffer
;
640 context
.alist
->al_count
= 0;
641 context
.alist
->al_more
= 0;
642 context
.alist
->al_offset
[0] = context
.bufsize
;
645 context
.bufsize
= bufsize
;
646 context
.firstu
= context
.bufsize
;
647 context
.alist
= (attrlist_t
*)buffer
;
650 if (XFS_FORCED_SHUTDOWN(dp
->i_mount
))
653 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
655 * Decide on what work routines to call based on the inode size.
657 xfs_attr_trace_l_c("syscall start", &context
);
658 if (XFS_IFORK_Q(dp
) == 0 ||
659 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
660 dp
->i_d
.di_anextents
== 0)) {
662 } else if (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) {
663 error
= xfs_attr_shortform_list(&context
);
664 } else if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
665 error
= xfs_attr_leaf_list(&context
);
667 error
= xfs_attr_node_list(&context
);
669 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
670 xfs_attr_trace_l_c("syscall end", &context
);
672 if (!(context
.flags
& (ATTR_KERNOVAL
|ATTR_KERNAMELS
))) {
675 else { /* must return negated buffer size or the error */
676 if (context
.count
< 0)
677 error
= XFS_ERROR(ERANGE
);
679 error
= -context
.count
;
686 xfs_attr_inactive(xfs_inode_t
*dp
)
693 ASSERT(! XFS_NOT_DQATTACHED(mp
, dp
));
695 xfs_ilock(dp
, XFS_ILOCK_SHARED
);
696 if ((XFS_IFORK_Q(dp
) == 0) ||
697 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
698 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
699 dp
->i_d
.di_anextents
== 0)) {
700 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
703 xfs_iunlock(dp
, XFS_ILOCK_SHARED
);
706 * Start our first transaction of the day.
708 * All future transactions during this code must be "chained" off
709 * this one via the trans_dup() call. All transactions will contain
710 * the inode, and the inode will always be marked with trans_ihold().
711 * Since the inode will be locked in all transactions, we must log
712 * the inode in every transaction to let it float upward through
715 trans
= xfs_trans_alloc(mp
, XFS_TRANS_ATTRINVAL
);
716 if ((error
= xfs_trans_reserve(trans
, 0, XFS_ATTRINVAL_LOG_RES(mp
), 0,
717 XFS_TRANS_PERM_LOG_RES
,
718 XFS_ATTRINVAL_LOG_COUNT
))) {
719 xfs_trans_cancel(trans
, 0);
722 xfs_ilock(dp
, XFS_ILOCK_EXCL
);
725 * No need to make quota reservations here. We expect to release some
726 * blocks, not allocate, in the common case.
728 xfs_trans_ijoin(trans
, dp
, XFS_ILOCK_EXCL
);
729 xfs_trans_ihold(trans
, dp
);
732 * Decide on what work routines to call based on the inode size.
734 if ((XFS_IFORK_Q(dp
) == 0) ||
735 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_LOCAL
) ||
736 (dp
->i_d
.di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
737 dp
->i_d
.di_anextents
== 0)) {
741 error
= xfs_attr_root_inactive(&trans
, dp
);
745 * signal synchronous inactive transactions unless this
746 * is a synchronous mount filesystem in which case we
747 * know that we're here because we've been called out of
748 * xfs_inactive which means that the last reference is gone
749 * and the unlink transaction has already hit the disk so
750 * async inactive transactions are safe.
752 if ((error
= xfs_itruncate_finish(&trans
, dp
, 0LL, XFS_ATTR_FORK
,
753 (!(mp
->m_flags
& XFS_MOUNT_WSYNC
)
758 * Commit the last in the sequence of transactions.
760 xfs_trans_log_inode(trans
, dp
, XFS_ILOG_CORE
);
761 error
= xfs_trans_commit(trans
, XFS_TRANS_RELEASE_LOG_RES
,
763 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
768 xfs_trans_cancel(trans
, XFS_TRANS_RELEASE_LOG_RES
|XFS_TRANS_ABORT
);
769 xfs_iunlock(dp
, XFS_ILOCK_EXCL
);
775 /*========================================================================
776 * External routines when attribute list is inside the inode
777 *========================================================================*/
780 * Add a name to the shortform attribute list structure
781 * This is the external routine.
784 xfs_attr_shortform_addname(xfs_da_args_t
*args
)
786 int newsize
, forkoff
, retval
;
788 retval
= xfs_attr_shortform_lookup(args
);
789 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
791 } else if (retval
== EEXIST
) {
792 if (args
->flags
& ATTR_CREATE
)
794 retval
= xfs_attr_shortform_remove(args
);
798 if (args
->namelen
>= XFS_ATTR_SF_ENTSIZE_MAX
||
799 args
->valuelen
>= XFS_ATTR_SF_ENTSIZE_MAX
)
800 return(XFS_ERROR(ENOSPC
));
802 newsize
= XFS_ATTR_SF_TOTSIZE(args
->dp
);
803 newsize
+= XFS_ATTR_SF_ENTSIZE_BYNAME(args
->namelen
, args
->valuelen
);
805 forkoff
= xfs_attr_shortform_bytesfit(args
->dp
, newsize
);
807 return(XFS_ERROR(ENOSPC
));
809 xfs_attr_shortform_add(args
, forkoff
);
814 /*========================================================================
815 * External routines when attribute list is one block
816 *========================================================================*/
819 * Add a name to the leaf attribute list structure
821 * This leaf block cannot have a "remote" value, we only call this routine
822 * if bmap_one_block() says there is only one block (ie: no remote blks).
825 xfs_attr_leaf_addname(xfs_da_args_t
*args
)
829 int retval
, error
, committed
, forkoff
;
832 * Read the (only) block in the attribute list in.
836 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
843 * Look up the given attribute in the leaf block. Figure out if
844 * the given flags produce an error or call for an atomic rename.
846 retval
= xfs_attr_leaf_lookup_int(bp
, args
);
847 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
848 xfs_da_brelse(args
->trans
, bp
);
850 } else if (retval
== EEXIST
) {
851 if (args
->flags
& ATTR_CREATE
) { /* pure create op */
852 xfs_da_brelse(args
->trans
, bp
);
855 args
->rename
= 1; /* an atomic rename */
856 args
->blkno2
= args
->blkno
; /* set 2nd entry info*/
857 args
->index2
= args
->index
;
858 args
->rmtblkno2
= args
->rmtblkno
;
859 args
->rmtblkcnt2
= args
->rmtblkcnt
;
863 * Add the attribute to the leaf block, transitioning to a Btree
866 retval
= xfs_attr_leaf_add(bp
, args
);
868 if (retval
== ENOSPC
) {
870 * Promote the attribute list to the Btree format, then
871 * Commit that transaction so that the node_addname() call
872 * can manage its own transactions.
874 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
875 error
= xfs_attr_leaf_to_node(args
);
877 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
878 *args
->firstblock
, &committed
);
883 xfs_bmap_cancel(args
->flist
);
888 * bmap_finish() may have committed the last trans and started
889 * a new one. We need the inode to be in all transactions.
892 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
893 xfs_trans_ihold(args
->trans
, dp
);
897 * Commit the current trans (including the inode) and start
900 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
904 * Fob the whole rest of the problem off on the Btree code.
906 error
= xfs_attr_node_addname(args
);
911 * Commit the transaction that added the attr name so that
912 * later routines can manage their own transactions.
914 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
918 * If there was an out-of-line value, allocate the blocks we
919 * identified for its storage and copy the value. This is done
920 * after we create the attribute so that we don't overflow the
921 * maximum size of a transaction and/or hit a deadlock.
923 if (args
->rmtblkno
> 0) {
924 error
= xfs_attr_rmtval_set(args
);
930 * If this is an atomic rename operation, we must "flip" the
931 * incomplete flags on the "new" and "old" attribute/value pairs
932 * so that one disappears and one appears atomically. Then we
933 * must remove the "old" attribute/value pair.
937 * In a separate transaction, set the incomplete flag on the
938 * "old" attr and clear the incomplete flag on the "new" attr.
940 error
= xfs_attr_leaf_flipflags(args
);
945 * Dismantle the "old" attribute/value pair by removing
946 * a "remote" value (if it exists).
948 args
->index
= args
->index2
;
949 args
->blkno
= args
->blkno2
;
950 args
->rmtblkno
= args
->rmtblkno2
;
951 args
->rmtblkcnt
= args
->rmtblkcnt2
;
952 if (args
->rmtblkno
) {
953 error
= xfs_attr_rmtval_remove(args
);
959 * Read in the block containing the "old" attr, then
960 * remove the "old" attr from that block (neat, huh!)
962 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1,
967 (void)xfs_attr_leaf_remove(bp
, args
);
970 * If the result is small enough, shrink it all into the inode.
972 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
973 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
974 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
975 /* bp is gone due to xfs_da_shrink_inode */
977 error
= xfs_bmap_finish(&args
->trans
,
985 xfs_bmap_cancel(args
->flist
);
990 * bmap_finish() may have committed the last trans
991 * and started a new one. We need the inode to be
992 * in all transactions.
995 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
996 xfs_trans_ihold(args
->trans
, dp
);
1002 * Commit the remove and start the next trans in series.
1004 error
= xfs_attr_rolltrans(&args
->trans
, dp
);
1006 } else if (args
->rmtblkno
> 0) {
1008 * Added a "remote" value, just clear the incomplete flag.
1010 error
= xfs_attr_leaf_clearflag(args
);
1016 * Remove a name from the leaf attribute list structure
1018 * This leaf block cannot have a "remote" value, we only call this routine
1019 * if bmap_one_block() says there is only one block (ie: no remote blks).
1022 xfs_attr_leaf_removename(xfs_da_args_t
*args
)
1026 int error
, committed
, forkoff
;
1029 * Remove the attribute.
1033 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
1040 error
= xfs_attr_leaf_lookup_int(bp
, args
);
1041 if (error
== ENOATTR
) {
1042 xfs_da_brelse(args
->trans
, bp
);
1046 (void)xfs_attr_leaf_remove(bp
, args
);
1049 * If the result is small enough, shrink it all into the inode.
1051 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1052 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1053 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1054 /* bp is gone due to xfs_da_shrink_inode */
1056 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1057 *args
->firstblock
, &committed
);
1062 xfs_bmap_cancel(args
->flist
);
1067 * bmap_finish() may have committed the last trans and started
1068 * a new one. We need the inode to be in all transactions.
1071 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1072 xfs_trans_ihold(args
->trans
, dp
);
1075 xfs_da_buf_done(bp
);
1080 * Look up a name in a leaf attribute list structure.
1082 * This leaf block cannot have a "remote" value, we only call this routine
1083 * if bmap_one_block() says there is only one block (ie: no remote blks).
1086 xfs_attr_leaf_get(xfs_da_args_t
*args
)
1092 error
= xfs_da_read_buf(args
->trans
, args
->dp
, args
->blkno
, -1, &bp
,
1098 error
= xfs_attr_leaf_lookup_int(bp
, args
);
1099 if (error
!= EEXIST
) {
1100 xfs_da_brelse(args
->trans
, bp
);
1103 error
= xfs_attr_leaf_getvalue(bp
, args
);
1104 xfs_da_brelse(args
->trans
, bp
);
1105 if (!error
&& (args
->rmtblkno
> 0) && !(args
->flags
& ATTR_KERNOVAL
)) {
1106 error
= xfs_attr_rmtval_get(args
);
1112 * Copy out attribute entries for attr_list(), for leaf attribute lists.
1115 xfs_attr_leaf_list(xfs_attr_list_context_t
*context
)
1117 xfs_attr_leafblock_t
*leaf
;
1121 context
->cursor
->blkno
= 0;
1122 error
= xfs_da_read_buf(NULL
, context
->dp
, 0, -1, &bp
, XFS_ATTR_FORK
);
1127 if (unlikely(INT_GET(leaf
->hdr
.info
.magic
, ARCH_CONVERT
)
1128 != XFS_ATTR_LEAF_MAGIC
)) {
1129 XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW
,
1130 context
->dp
->i_mount
, leaf
);
1131 xfs_da_brelse(NULL
, bp
);
1132 return(XFS_ERROR(EFSCORRUPTED
));
1135 (void)xfs_attr_leaf_list_int(bp
, context
);
1136 xfs_da_brelse(NULL
, bp
);
1141 /*========================================================================
1142 * External routines when attribute list size > XFS_LBSIZE(mp).
1143 *========================================================================*/
1146 * Add a name to a Btree-format attribute list.
1148 * This will involve walking down the Btree, and may involve splitting
1149 * leaf nodes and even splitting intermediate nodes up to and including
1150 * the root node (a special case of an intermediate node).
1152 * "Remote" attribute values confuse the issue and atomic rename operations
1153 * add a whole extra layer of confusion on top of that.
1156 xfs_attr_node_addname(xfs_da_args_t
*args
)
1158 xfs_da_state_t
*state
;
1159 xfs_da_state_blk_t
*blk
;
1162 int committed
, retval
, error
;
1165 * Fill in bucket of arguments/results/context to carry around.
1170 state
= xfs_da_state_alloc();
1173 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1174 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1177 * Search to see if name already exists, and get back a pointer
1178 * to where it should go.
1180 error
= xfs_da_node_lookup_int(state
, &retval
);
1183 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1184 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1185 if ((args
->flags
& ATTR_REPLACE
) && (retval
== ENOATTR
)) {
1187 } else if (retval
== EEXIST
) {
1188 if (args
->flags
& ATTR_CREATE
)
1190 args
->rename
= 1; /* atomic rename op */
1191 args
->blkno2
= args
->blkno
; /* set 2nd entry info*/
1192 args
->index2
= args
->index
;
1193 args
->rmtblkno2
= args
->rmtblkno
;
1194 args
->rmtblkcnt2
= args
->rmtblkcnt
;
1196 args
->rmtblkcnt
= 0;
1199 retval
= xfs_attr_leaf_add(blk
->bp
, state
->args
);
1200 if (retval
== ENOSPC
) {
1201 if (state
->path
.active
== 1) {
1203 * Its really a single leaf node, but it had
1204 * out-of-line values so it looked like it *might*
1205 * have been a b-tree.
1207 xfs_da_state_free(state
);
1208 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1209 error
= xfs_attr_leaf_to_node(args
);
1211 error
= xfs_bmap_finish(&args
->trans
,
1219 xfs_bmap_cancel(args
->flist
);
1224 * bmap_finish() may have committed the last trans
1225 * and started a new one. We need the inode to be
1226 * in all transactions.
1229 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1230 xfs_trans_ihold(args
->trans
, dp
);
1234 * Commit the node conversion and start the next
1235 * trans in the chain.
1237 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1244 * Split as many Btree elements as required.
1245 * This code tracks the new and old attr's location
1246 * in the index/blkno/rmtblkno/rmtblkcnt fields and
1247 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
1249 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1250 error
= xfs_da_split(state
);
1252 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1253 *args
->firstblock
, &committed
);
1258 xfs_bmap_cancel(args
->flist
);
1263 * bmap_finish() may have committed the last trans and started
1264 * a new one. We need the inode to be in all transactions.
1267 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1268 xfs_trans_ihold(args
->trans
, dp
);
1272 * Addition succeeded, update Btree hashvals.
1274 xfs_da_fixhashpath(state
, &state
->path
);
1278 * Kill the state structure, we're done with it and need to
1279 * allow the buffers to come back later.
1281 xfs_da_state_free(state
);
1285 * Commit the leaf addition or btree split and start the next
1286 * trans in the chain.
1288 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1292 * If there was an out-of-line value, allocate the blocks we
1293 * identified for its storage and copy the value. This is done
1294 * after we create the attribute so that we don't overflow the
1295 * maximum size of a transaction and/or hit a deadlock.
1297 if (args
->rmtblkno
> 0) {
1298 error
= xfs_attr_rmtval_set(args
);
1304 * If this is an atomic rename operation, we must "flip" the
1305 * incomplete flags on the "new" and "old" attribute/value pairs
1306 * so that one disappears and one appears atomically. Then we
1307 * must remove the "old" attribute/value pair.
1311 * In a separate transaction, set the incomplete flag on the
1312 * "old" attr and clear the incomplete flag on the "new" attr.
1314 error
= xfs_attr_leaf_flipflags(args
);
1319 * Dismantle the "old" attribute/value pair by removing
1320 * a "remote" value (if it exists).
1322 args
->index
= args
->index2
;
1323 args
->blkno
= args
->blkno2
;
1324 args
->rmtblkno
= args
->rmtblkno2
;
1325 args
->rmtblkcnt
= args
->rmtblkcnt2
;
1326 if (args
->rmtblkno
) {
1327 error
= xfs_attr_rmtval_remove(args
);
1333 * Re-find the "old" attribute entry after any split ops.
1334 * The INCOMPLETE flag means that we will find the "old"
1335 * attr, not the "new" one.
1337 args
->flags
|= XFS_ATTR_INCOMPLETE
;
1338 state
= xfs_da_state_alloc();
1341 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1342 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1344 error
= xfs_da_node_lookup_int(state
, &retval
);
1349 * Remove the name and update the hashvals in the tree.
1351 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1352 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1353 error
= xfs_attr_leaf_remove(blk
->bp
, args
);
1354 xfs_da_fixhashpath(state
, &state
->path
);
1357 * Check to see if the tree needs to be collapsed.
1359 if (retval
&& (state
->path
.active
> 1)) {
1360 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1361 error
= xfs_da_join(state
);
1363 error
= xfs_bmap_finish(&args
->trans
,
1371 xfs_bmap_cancel(args
->flist
);
1376 * bmap_finish() may have committed the last trans
1377 * and started a new one. We need the inode to be
1378 * in all transactions.
1381 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1382 xfs_trans_ihold(args
->trans
, dp
);
1387 * Commit and start the next trans in the chain.
1389 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1392 } else if (args
->rmtblkno
> 0) {
1394 * Added a "remote" value, just clear the incomplete flag.
1396 error
= xfs_attr_leaf_clearflag(args
);
1404 xfs_da_state_free(state
);
1411 * Remove a name from a B-tree attribute list.
1413 * This will involve walking down the Btree, and may involve joining
1414 * leaf nodes and even joining intermediate nodes up to and including
1415 * the root node (a special case of an intermediate node).
1418 xfs_attr_node_removename(xfs_da_args_t
*args
)
1420 xfs_da_state_t
*state
;
1421 xfs_da_state_blk_t
*blk
;
1424 int retval
, error
, committed
, forkoff
;
1427 * Tie a string around our finger to remind us where we are.
1430 state
= xfs_da_state_alloc();
1432 state
->mp
= dp
->i_mount
;
1433 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1434 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1437 * Search to see if name exists, and get back a pointer to it.
1439 error
= xfs_da_node_lookup_int(state
, &retval
);
1440 if (error
|| (retval
!= EEXIST
)) {
1447 * If there is an out-of-line value, de-allocate the blocks.
1448 * This is done before we remove the attribute so that we don't
1449 * overflow the maximum size of a transaction and/or hit a deadlock.
1451 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1452 ASSERT(blk
->bp
!= NULL
);
1453 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1454 if (args
->rmtblkno
> 0) {
1456 * Fill in disk block numbers in the state structure
1457 * so that we can get the buffers back after we commit
1458 * several transactions in the following calls.
1460 error
= xfs_attr_fillstate(state
);
1465 * Mark the attribute as INCOMPLETE, then bunmapi() the
1468 error
= xfs_attr_leaf_setflag(args
);
1471 error
= xfs_attr_rmtval_remove(args
);
1476 * Refill the state structure with buffers, the prior calls
1477 * released our buffers.
1479 error
= xfs_attr_refillstate(state
);
1485 * Remove the name and update the hashvals in the tree.
1487 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1488 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1489 retval
= xfs_attr_leaf_remove(blk
->bp
, args
);
1490 xfs_da_fixhashpath(state
, &state
->path
);
1493 * Check to see if the tree needs to be collapsed.
1495 if (retval
&& (state
->path
.active
> 1)) {
1496 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1497 error
= xfs_da_join(state
);
1499 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1500 *args
->firstblock
, &committed
);
1505 xfs_bmap_cancel(args
->flist
);
1510 * bmap_finish() may have committed the last trans and started
1511 * a new one. We need the inode to be in all transactions.
1514 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1515 xfs_trans_ihold(args
->trans
, dp
);
1519 * Commit the Btree join operation and start a new trans.
1521 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
1526 * If the result is small enough, push it all into the inode.
1528 if (xfs_bmap_one_block(dp
, XFS_ATTR_FORK
)) {
1530 * Have to get rid of the copy of this dabuf in the state.
1532 ASSERT(state
->path
.active
== 1);
1533 ASSERT(state
->path
.blk
[0].bp
);
1534 xfs_da_buf_done(state
->path
.blk
[0].bp
);
1535 state
->path
.blk
[0].bp
= NULL
;
1537 error
= xfs_da_read_buf(args
->trans
, args
->dp
, 0, -1, &bp
,
1541 ASSERT(INT_GET(((xfs_attr_leafblock_t
*)
1542 bp
->data
)->hdr
.info
.magic
, ARCH_CONVERT
)
1543 == XFS_ATTR_LEAF_MAGIC
);
1545 if ((forkoff
= xfs_attr_shortform_allfit(bp
, dp
))) {
1546 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1547 error
= xfs_attr_leaf_to_shortform(bp
, args
, forkoff
);
1548 /* bp is gone due to xfs_da_shrink_inode */
1550 error
= xfs_bmap_finish(&args
->trans
,
1558 xfs_bmap_cancel(args
->flist
);
1563 * bmap_finish() may have committed the last trans
1564 * and started a new one. We need the inode to be
1565 * in all transactions.
1568 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
1569 xfs_trans_ihold(args
->trans
, dp
);
1572 xfs_da_brelse(args
->trans
, bp
);
1577 xfs_da_state_free(state
);
1582 * Fill in the disk block numbers in the state structure for the buffers
1583 * that are attached to the state structure.
1584 * This is done so that we can quickly reattach ourselves to those buffers
1585 * after some set of transaction commit's has released these buffers.
1588 xfs_attr_fillstate(xfs_da_state_t
*state
)
1590 xfs_da_state_path_t
*path
;
1591 xfs_da_state_blk_t
*blk
;
1595 * Roll down the "path" in the state structure, storing the on-disk
1596 * block number for those buffers in the "path".
1598 path
= &state
->path
;
1599 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1600 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1602 blk
->disk_blkno
= xfs_da_blkno(blk
->bp
);
1603 xfs_da_buf_done(blk
->bp
);
1606 blk
->disk_blkno
= 0;
1611 * Roll down the "altpath" in the state structure, storing the on-disk
1612 * block number for those buffers in the "altpath".
1614 path
= &state
->altpath
;
1615 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1616 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1618 blk
->disk_blkno
= xfs_da_blkno(blk
->bp
);
1619 xfs_da_buf_done(blk
->bp
);
1622 blk
->disk_blkno
= 0;
1630 * Reattach the buffers to the state structure based on the disk block
1631 * numbers stored in the state structure.
1632 * This is done after some set of transaction commit's has released those
1633 * buffers from our grip.
1636 xfs_attr_refillstate(xfs_da_state_t
*state
)
1638 xfs_da_state_path_t
*path
;
1639 xfs_da_state_blk_t
*blk
;
1643 * Roll down the "path" in the state structure, storing the on-disk
1644 * block number for those buffers in the "path".
1646 path
= &state
->path
;
1647 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1648 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1649 if (blk
->disk_blkno
) {
1650 error
= xfs_da_read_buf(state
->args
->trans
,
1652 blk
->blkno
, blk
->disk_blkno
,
1653 &blk
->bp
, XFS_ATTR_FORK
);
1662 * Roll down the "altpath" in the state structure, storing the on-disk
1663 * block number for those buffers in the "altpath".
1665 path
= &state
->altpath
;
1666 ASSERT((path
->active
>= 0) && (path
->active
< XFS_DA_NODE_MAXDEPTH
));
1667 for (blk
= path
->blk
, level
= 0; level
< path
->active
; blk
++, level
++) {
1668 if (blk
->disk_blkno
) {
1669 error
= xfs_da_read_buf(state
->args
->trans
,
1671 blk
->blkno
, blk
->disk_blkno
,
1672 &blk
->bp
, XFS_ATTR_FORK
);
1684 * Look up a filename in a node attribute list.
1686 * This routine gets called for any attribute fork that has more than one
1687 * block, ie: both true Btree attr lists and for single-leaf-blocks with
1688 * "remote" values taking up more blocks.
1691 xfs_attr_node_get(xfs_da_args_t
*args
)
1693 xfs_da_state_t
*state
;
1694 xfs_da_state_blk_t
*blk
;
1698 state
= xfs_da_state_alloc();
1700 state
->mp
= args
->dp
->i_mount
;
1701 state
->blocksize
= state
->mp
->m_sb
.sb_blocksize
;
1702 state
->node_ents
= state
->mp
->m_attr_node_ents
;
1705 * Search to see if name exists, and get back a pointer to it.
1707 error
= xfs_da_node_lookup_int(state
, &retval
);
1710 } else if (retval
== EEXIST
) {
1711 blk
= &state
->path
.blk
[ state
->path
.active
-1 ];
1712 ASSERT(blk
->bp
!= NULL
);
1713 ASSERT(blk
->magic
== XFS_ATTR_LEAF_MAGIC
);
1716 * Get the value, local or "remote"
1718 retval
= xfs_attr_leaf_getvalue(blk
->bp
, args
);
1719 if (!retval
&& (args
->rmtblkno
> 0)
1720 && !(args
->flags
& ATTR_KERNOVAL
)) {
1721 retval
= xfs_attr_rmtval_get(args
);
1726 * If not in a transaction, we have to release all the buffers.
1728 for (i
= 0; i
< state
->path
.active
; i
++) {
1729 xfs_da_brelse(args
->trans
, state
->path
.blk
[i
].bp
);
1730 state
->path
.blk
[i
].bp
= NULL
;
1733 xfs_da_state_free(state
);
1737 STATIC
int /* error */
1738 xfs_attr_node_list(xfs_attr_list_context_t
*context
)
1740 attrlist_cursor_kern_t
*cursor
;
1741 xfs_attr_leafblock_t
*leaf
;
1742 xfs_da_intnode_t
*node
;
1743 xfs_da_node_entry_t
*btree
;
1747 cursor
= context
->cursor
;
1748 cursor
->initted
= 1;
1751 * Do all sorts of validation on the passed-in cursor structure.
1752 * If anything is amiss, ignore the cursor and look up the hashval
1753 * starting from the btree root.
1756 if (cursor
->blkno
> 0) {
1757 error
= xfs_da_read_buf(NULL
, context
->dp
, cursor
->blkno
, -1,
1758 &bp
, XFS_ATTR_FORK
);
1759 if ((error
!= 0) && (error
!= EFSCORRUPTED
))
1763 switch (INT_GET(node
->hdr
.info
.magic
, ARCH_CONVERT
)) {
1764 case XFS_DA_NODE_MAGIC
:
1765 xfs_attr_trace_l_cn("wrong blk", context
, node
);
1766 xfs_da_brelse(NULL
, bp
);
1769 case XFS_ATTR_LEAF_MAGIC
:
1771 if (cursor
->hashval
>
1772 INT_GET(leaf
->entries
[
1773 INT_GET(leaf
->hdr
.count
,
1774 ARCH_CONVERT
)-1].hashval
,
1776 xfs_attr_trace_l_cl("wrong blk",
1778 xfs_da_brelse(NULL
, bp
);
1780 } else if (cursor
->hashval
<=
1781 INT_GET(leaf
->entries
[0].hashval
,
1783 xfs_attr_trace_l_cl("maybe wrong blk",
1785 xfs_da_brelse(NULL
, bp
);
1790 xfs_attr_trace_l_c("wrong blk - ??", context
);
1791 xfs_da_brelse(NULL
, bp
);
1798 * We did not find what we expected given the cursor's contents,
1799 * so we start from the top and work down based on the hash value.
1800 * Note that start of node block is same as start of leaf block.
1805 error
= xfs_da_read_buf(NULL
, context
->dp
,
1806 cursor
->blkno
, -1, &bp
,
1810 if (unlikely(bp
== NULL
)) {
1811 XFS_ERROR_REPORT("xfs_attr_node_list(2)",
1813 context
->dp
->i_mount
);
1814 return(XFS_ERROR(EFSCORRUPTED
));
1817 if (INT_GET(node
->hdr
.info
.magic
, ARCH_CONVERT
)
1818 == XFS_ATTR_LEAF_MAGIC
)
1820 if (unlikely(INT_GET(node
->hdr
.info
.magic
, ARCH_CONVERT
)
1821 != XFS_DA_NODE_MAGIC
)) {
1822 XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
1824 context
->dp
->i_mount
,
1826 xfs_da_brelse(NULL
, bp
);
1827 return(XFS_ERROR(EFSCORRUPTED
));
1829 btree
= node
->btree
;
1831 i
< INT_GET(node
->hdr
.count
, ARCH_CONVERT
);
1834 <= INT_GET(btree
->hashval
,
1836 cursor
->blkno
= INT_GET(btree
->before
, ARCH_CONVERT
);
1837 xfs_attr_trace_l_cb("descending",
1842 if (i
== INT_GET(node
->hdr
.count
, ARCH_CONVERT
)) {
1843 xfs_da_brelse(NULL
, bp
);
1846 xfs_da_brelse(NULL
, bp
);
1852 * Roll upward through the blocks, processing each leaf block in
1853 * order. As long as there is space in the result buffer, keep
1854 * adding the information.
1858 if (unlikely(INT_GET(leaf
->hdr
.info
.magic
, ARCH_CONVERT
)
1859 != XFS_ATTR_LEAF_MAGIC
)) {
1860 XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
1862 context
->dp
->i_mount
, leaf
);
1863 xfs_da_brelse(NULL
, bp
);
1864 return(XFS_ERROR(EFSCORRUPTED
));
1866 error
= xfs_attr_leaf_list_int(bp
, context
);
1867 if (error
|| !leaf
->hdr
.info
.forw
)
1868 break; /* not really an error, buffer full or EOF */
1869 cursor
->blkno
= INT_GET(leaf
->hdr
.info
.forw
, ARCH_CONVERT
);
1870 xfs_da_brelse(NULL
, bp
);
1871 error
= xfs_da_read_buf(NULL
, context
->dp
, cursor
->blkno
, -1,
1872 &bp
, XFS_ATTR_FORK
);
1875 if (unlikely((bp
== NULL
))) {
1876 XFS_ERROR_REPORT("xfs_attr_node_list(5)",
1878 context
->dp
->i_mount
);
1879 return(XFS_ERROR(EFSCORRUPTED
));
1882 xfs_da_brelse(NULL
, bp
);
1887 /*========================================================================
1888 * External routines for manipulating out-of-line attribute values.
1889 *========================================================================*/
1892 * Read the value associated with an attribute from the out-of-line buffer
1893 * that we stored it in.
1896 xfs_attr_rmtval_get(xfs_da_args_t
*args
)
1898 xfs_bmbt_irec_t map
[ATTR_RMTVALUE_MAPSIZE
];
1903 int nmap
, error
, tmp
, valuelen
, blkcnt
, i
;
1906 ASSERT(!(args
->flags
& ATTR_KERNOVAL
));
1908 mp
= args
->dp
->i_mount
;
1910 valuelen
= args
->valuelen
;
1911 lblkno
= args
->rmtblkno
;
1912 while (valuelen
> 0) {
1913 nmap
= ATTR_RMTVALUE_MAPSIZE
;
1914 error
= xfs_bmapi(args
->trans
, args
->dp
, (xfs_fileoff_t
)lblkno
,
1916 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
1917 NULL
, 0, map
, &nmap
, NULL
);
1922 for (i
= 0; (i
< nmap
) && (valuelen
> 0); i
++) {
1923 ASSERT((map
[i
].br_startblock
!= DELAYSTARTBLOCK
) &&
1924 (map
[i
].br_startblock
!= HOLESTARTBLOCK
));
1925 dblkno
= XFS_FSB_TO_DADDR(mp
, map
[i
].br_startblock
);
1926 blkcnt
= XFS_FSB_TO_BB(mp
, map
[i
].br_blockcount
);
1927 error
= xfs_read_buf(mp
, mp
->m_ddev_targp
, dblkno
,
1928 blkcnt
, XFS_BUF_LOCK
, &bp
);
1932 tmp
= (valuelen
< XFS_BUF_SIZE(bp
))
1933 ? valuelen
: XFS_BUF_SIZE(bp
);
1934 xfs_biomove(bp
, 0, tmp
, dst
, XFS_B_READ
);
1939 lblkno
+= map
[i
].br_blockcount
;
1942 ASSERT(valuelen
== 0);
1947 * Write the value associated with an attribute into the out-of-line buffer
1948 * that we have defined for it.
1951 xfs_attr_rmtval_set(xfs_da_args_t
*args
)
1954 xfs_fileoff_t lfileoff
;
1956 xfs_bmbt_irec_t map
;
1961 int blkcnt
, valuelen
, nmap
, error
, tmp
, committed
;
1968 * Find a "hole" in the attribute address space large enough for
1969 * us to drop the new attribute's value into.
1971 blkcnt
= XFS_B_TO_FSB(mp
, args
->valuelen
);
1973 error
= xfs_bmap_first_unused(args
->trans
, args
->dp
, blkcnt
, &lfileoff
,
1978 args
->rmtblkno
= lblkno
= (xfs_dablk_t
)lfileoff
;
1979 args
->rmtblkcnt
= blkcnt
;
1982 * Roll through the "value", allocating blocks on disk as required.
1984 while (blkcnt
> 0) {
1986 * Allocate a single extent, up to the size of the value.
1988 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
1990 error
= xfs_bmapi(args
->trans
, dp
, (xfs_fileoff_t
)lblkno
,
1992 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
|
1994 args
->firstblock
, args
->total
, &map
, &nmap
,
1997 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
1998 *args
->firstblock
, &committed
);
2003 xfs_bmap_cancel(args
->flist
);
2008 * bmap_finish() may have committed the last trans and started
2009 * a new one. We need the inode to be in all transactions.
2012 xfs_trans_ijoin(args
->trans
, dp
, XFS_ILOCK_EXCL
);
2013 xfs_trans_ihold(args
->trans
, dp
);
2017 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2018 (map
.br_startblock
!= HOLESTARTBLOCK
));
2019 lblkno
+= map
.br_blockcount
;
2020 blkcnt
-= map
.br_blockcount
;
2023 * Start the next trans in the chain.
2025 if ((error
= xfs_attr_rolltrans(&args
->trans
, dp
)))
2030 * Roll through the "value", copying the attribute value to the
2031 * already-allocated blocks. Blocks are written synchronously
2032 * so that we can know they are all on disk before we turn off
2033 * the INCOMPLETE flag.
2035 lblkno
= args
->rmtblkno
;
2036 valuelen
= args
->valuelen
;
2037 while (valuelen
> 0) {
2039 * Try to remember where we decided to put the value.
2041 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2043 error
= xfs_bmapi(NULL
, dp
, (xfs_fileoff_t
)lblkno
,
2045 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2046 args
->firstblock
, 0, &map
, &nmap
, NULL
);
2051 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2052 (map
.br_startblock
!= HOLESTARTBLOCK
));
2054 dblkno
= XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
2055 blkcnt
= XFS_FSB_TO_BB(mp
, map
.br_blockcount
);
2057 bp
= xfs_buf_get_flags(mp
->m_ddev_targp
, dblkno
,
2058 blkcnt
, XFS_BUF_LOCK
);
2060 ASSERT(!XFS_BUF_GETERROR(bp
));
2062 tmp
= (valuelen
< XFS_BUF_SIZE(bp
)) ? valuelen
:
2064 xfs_biomove(bp
, 0, tmp
, src
, XFS_B_WRITE
);
2065 if (tmp
< XFS_BUF_SIZE(bp
))
2066 xfs_biozero(bp
, tmp
, XFS_BUF_SIZE(bp
) - tmp
);
2067 if ((error
= xfs_bwrite(mp
, bp
))) {/* GROT: NOTE: synchronous write */
2073 lblkno
+= map
.br_blockcount
;
2075 ASSERT(valuelen
== 0);
2080 * Remove the value associated with an attribute by deleting the
2081 * out-of-line buffer that it is stored on.
2084 xfs_attr_rmtval_remove(xfs_da_args_t
*args
)
2087 xfs_bmbt_irec_t map
;
2091 int valuelen
, blkcnt
, nmap
, error
, done
, committed
;
2093 mp
= args
->dp
->i_mount
;
2096 * Roll through the "value", invalidating the attribute value's
2099 lblkno
= args
->rmtblkno
;
2100 valuelen
= args
->rmtblkcnt
;
2101 while (valuelen
> 0) {
2103 * Try to remember where we decided to put the value.
2105 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2107 error
= xfs_bmapi(NULL
, args
->dp
, (xfs_fileoff_t
)lblkno
,
2109 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2110 args
->firstblock
, 0, &map
, &nmap
,
2116 ASSERT((map
.br_startblock
!= DELAYSTARTBLOCK
) &&
2117 (map
.br_startblock
!= HOLESTARTBLOCK
));
2119 dblkno
= XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
2120 blkcnt
= XFS_FSB_TO_BB(mp
, map
.br_blockcount
);
2123 * If the "remote" value is in the cache, remove it.
2125 bp
= xfs_incore(mp
->m_ddev_targp
, dblkno
, blkcnt
,
2126 XFS_INCORE_TRYLOCK
);
2129 XFS_BUF_UNDELAYWRITE(bp
);
2134 valuelen
-= map
.br_blockcount
;
2136 lblkno
+= map
.br_blockcount
;
2140 * Keep de-allocating extents until the remote-value region is gone.
2142 lblkno
= args
->rmtblkno
;
2143 blkcnt
= args
->rmtblkcnt
;
2146 XFS_BMAP_INIT(args
->flist
, args
->firstblock
);
2147 error
= xfs_bunmapi(args
->trans
, args
->dp
, lblkno
, blkcnt
,
2148 XFS_BMAPI_ATTRFORK
| XFS_BMAPI_METADATA
,
2149 1, args
->firstblock
, args
->flist
, &done
);
2151 error
= xfs_bmap_finish(&args
->trans
, args
->flist
,
2152 *args
->firstblock
, &committed
);
2157 xfs_bmap_cancel(args
->flist
);
2162 * bmap_finish() may have committed the last trans and started
2163 * a new one. We need the inode to be in all transactions.
2166 xfs_trans_ijoin(args
->trans
, args
->dp
, XFS_ILOCK_EXCL
);
2167 xfs_trans_ihold(args
->trans
, args
->dp
);
2171 * Close out trans and start the next one in the chain.
2173 if ((error
= xfs_attr_rolltrans(&args
->trans
, args
->dp
)))
2179 #if defined(XFS_ATTR_TRACE)
2181 * Add a trace buffer entry for an attr_list context structure.
2184 xfs_attr_trace_l_c(char *where
, struct xfs_attr_list_context
*context
)
2186 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_C
, where
,
2187 (__psunsigned_t
)context
->dp
,
2188 (__psunsigned_t
)context
->cursor
->hashval
,
2189 (__psunsigned_t
)context
->cursor
->blkno
,
2190 (__psunsigned_t
)context
->cursor
->offset
,
2191 (__psunsigned_t
)context
->alist
,
2192 (__psunsigned_t
)context
->bufsize
,
2193 (__psunsigned_t
)context
->count
,
2194 (__psunsigned_t
)context
->firstu
,
2196 ((context
->count
> 0) &&
2197 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2198 ? (ATTR_ENTRY(context
->alist
,
2199 context
->count
-1)->a_valuelen
)
2201 (__psunsigned_t
)context
->dupcnt
,
2202 (__psunsigned_t
)context
->flags
,
2203 (__psunsigned_t
)NULL
,
2204 (__psunsigned_t
)NULL
,
2205 (__psunsigned_t
)NULL
);
2209 * Add a trace buffer entry for a context structure and a Btree node.
2212 xfs_attr_trace_l_cn(char *where
, struct xfs_attr_list_context
*context
,
2213 struct xfs_da_intnode
*node
)
2215 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CN
, where
,
2216 (__psunsigned_t
)context
->dp
,
2217 (__psunsigned_t
)context
->cursor
->hashval
,
2218 (__psunsigned_t
)context
->cursor
->blkno
,
2219 (__psunsigned_t
)context
->cursor
->offset
,
2220 (__psunsigned_t
)context
->alist
,
2221 (__psunsigned_t
)context
->bufsize
,
2222 (__psunsigned_t
)context
->count
,
2223 (__psunsigned_t
)context
->firstu
,
2225 ((context
->count
> 0) &&
2226 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2227 ? (ATTR_ENTRY(context
->alist
,
2228 context
->count
-1)->a_valuelen
)
2230 (__psunsigned_t
)context
->dupcnt
,
2231 (__psunsigned_t
)context
->flags
,
2232 (__psunsigned_t
)INT_GET(node
->hdr
.count
, ARCH_CONVERT
),
2233 (__psunsigned_t
)INT_GET(node
->btree
[0].hashval
, ARCH_CONVERT
),
2234 (__psunsigned_t
)INT_GET(node
->btree
[INT_GET(node
->hdr
.count
, ARCH_CONVERT
)-1].hashval
, ARCH_CONVERT
));
2238 * Add a trace buffer entry for a context structure and a Btree element.
2241 xfs_attr_trace_l_cb(char *where
, struct xfs_attr_list_context
*context
,
2242 struct xfs_da_node_entry
*btree
)
2244 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CB
, where
,
2245 (__psunsigned_t
)context
->dp
,
2246 (__psunsigned_t
)context
->cursor
->hashval
,
2247 (__psunsigned_t
)context
->cursor
->blkno
,
2248 (__psunsigned_t
)context
->cursor
->offset
,
2249 (__psunsigned_t
)context
->alist
,
2250 (__psunsigned_t
)context
->bufsize
,
2251 (__psunsigned_t
)context
->count
,
2252 (__psunsigned_t
)context
->firstu
,
2254 ((context
->count
> 0) &&
2255 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2256 ? (ATTR_ENTRY(context
->alist
,
2257 context
->count
-1)->a_valuelen
)
2259 (__psunsigned_t
)context
->dupcnt
,
2260 (__psunsigned_t
)context
->flags
,
2261 (__psunsigned_t
)INT_GET(btree
->hashval
, ARCH_CONVERT
),
2262 (__psunsigned_t
)INT_GET(btree
->before
, ARCH_CONVERT
),
2263 (__psunsigned_t
)NULL
);
2267 * Add a trace buffer entry for a context structure and a leaf block.
2270 xfs_attr_trace_l_cl(char *where
, struct xfs_attr_list_context
*context
,
2271 struct xfs_attr_leafblock
*leaf
)
2273 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CL
, where
,
2274 (__psunsigned_t
)context
->dp
,
2275 (__psunsigned_t
)context
->cursor
->hashval
,
2276 (__psunsigned_t
)context
->cursor
->blkno
,
2277 (__psunsigned_t
)context
->cursor
->offset
,
2278 (__psunsigned_t
)context
->alist
,
2279 (__psunsigned_t
)context
->bufsize
,
2280 (__psunsigned_t
)context
->count
,
2281 (__psunsigned_t
)context
->firstu
,
2283 ((context
->count
> 0) &&
2284 !(context
->flags
& (ATTR_KERNAMELS
|ATTR_KERNOVAL
)))
2285 ? (ATTR_ENTRY(context
->alist
,
2286 context
->count
-1)->a_valuelen
)
2288 (__psunsigned_t
)context
->dupcnt
,
2289 (__psunsigned_t
)context
->flags
,
2290 (__psunsigned_t
)INT_GET(leaf
->hdr
.count
, ARCH_CONVERT
),
2291 (__psunsigned_t
)INT_GET(leaf
->entries
[0].hashval
, ARCH_CONVERT
),
2292 (__psunsigned_t
)INT_GET(leaf
->entries
[INT_GET(leaf
->hdr
.count
, ARCH_CONVERT
)-1].hashval
, ARCH_CONVERT
));
2296 * Add a trace buffer entry for the arguments given to the routine,
2300 xfs_attr_trace_enter(int type
, char *where
,
2301 __psunsigned_t a2
, __psunsigned_t a3
,
2302 __psunsigned_t a4
, __psunsigned_t a5
,
2303 __psunsigned_t a6
, __psunsigned_t a7
,
2304 __psunsigned_t a8
, __psunsigned_t a9
,
2305 __psunsigned_t a10
, __psunsigned_t a11
,
2306 __psunsigned_t a12
, __psunsigned_t a13
,
2307 __psunsigned_t a14
, __psunsigned_t a15
)
2309 ASSERT(xfs_attr_trace_buf
);
2310 ktrace_enter(xfs_attr_trace_buf
, (void *)((__psunsigned_t
)type
),
2312 (void *)a2
, (void *)a3
, (void *)a4
,
2313 (void *)a5
, (void *)a6
, (void *)a7
,
2314 (void *)a8
, (void *)a9
, (void *)a10
,
2315 (void *)a11
, (void *)a12
, (void *)a13
,
2316 (void *)a14
, (void *)a15
);
2318 #endif /* XFS_ATTR_TRACE */
2321 /*========================================================================
2322 * System (pseudo) namespace attribute interface routines.
2323 *========================================================================*/
2326 posix_acl_access_set(
2327 vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2329 return xfs_acl_vset(vp
, data
, size
, _ACL_TYPE_ACCESS
);
2333 posix_acl_access_remove(
2334 struct vnode
*vp
, char *name
, int xflags
)
2336 return xfs_acl_vremove(vp
, _ACL_TYPE_ACCESS
);
2340 posix_acl_access_get(
2341 vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2343 return xfs_acl_vget(vp
, data
, size
, _ACL_TYPE_ACCESS
);
2347 posix_acl_access_exists(
2350 return xfs_acl_vhasacl_access(vp
);
2354 posix_acl_default_set(
2355 vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2357 return xfs_acl_vset(vp
, data
, size
, _ACL_TYPE_DEFAULT
);
2361 posix_acl_default_get(
2362 vnode_t
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2364 return xfs_acl_vget(vp
, data
, size
, _ACL_TYPE_DEFAULT
);
2368 posix_acl_default_remove(
2369 struct vnode
*vp
, char *name
, int xflags
)
2371 return xfs_acl_vremove(vp
, _ACL_TYPE_DEFAULT
);
2375 posix_acl_default_exists(
2378 return xfs_acl_vhasacl_default(vp
);
2381 STATIC
struct attrnames posix_acl_access
= {
2382 .attr_name
= "posix_acl_access",
2383 .attr_namelen
= sizeof("posix_acl_access") - 1,
2384 .attr_get
= posix_acl_access_get
,
2385 .attr_set
= posix_acl_access_set
,
2386 .attr_remove
= posix_acl_access_remove
,
2387 .attr_exists
= posix_acl_access_exists
,
2390 STATIC
struct attrnames posix_acl_default
= {
2391 .attr_name
= "posix_acl_default",
2392 .attr_namelen
= sizeof("posix_acl_default") - 1,
2393 .attr_get
= posix_acl_default_get
,
2394 .attr_set
= posix_acl_default_set
,
2395 .attr_remove
= posix_acl_default_remove
,
2396 .attr_exists
= posix_acl_default_exists
,
2399 STATIC
struct attrnames
*attr_system_names
[] =
2400 { &posix_acl_access
, &posix_acl_default
};
2403 /*========================================================================
2404 * Namespace-prefix-style attribute name interface routines.
2405 *========================================================================*/
2409 struct vnode
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2413 VOP_ATTR_SET(vp
, name
, data
, size
, xflags
, NULL
, error
);
2419 struct vnode
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2421 int error
, asize
= size
;
2423 VOP_ATTR_GET(vp
, name
, data
, &asize
, xflags
, NULL
, error
);
2430 attr_generic_remove(
2431 struct vnode
*vp
, char *name
, int xflags
)
2435 VOP_ATTR_REMOVE(vp
, name
, xflags
, NULL
, error
);
2440 attr_generic_listadd(
2441 attrnames_t
*prefix
,
2442 attrnames_t
*namesp
,
2447 char *p
= data
+ *result
;
2449 *result
+= prefix
->attr_namelen
;
2450 *result
+= namesp
->attr_namelen
+ 1;
2455 strcpy(p
, prefix
->attr_name
);
2456 p
+= prefix
->attr_namelen
;
2457 strcpy(p
, namesp
->attr_name
);
2458 p
+= namesp
->attr_namelen
+ 1;
2469 attrnames_t
*namesp
;
2472 for (i
= 0; i
< ATTR_SYSCOUNT
; i
++) {
2473 namesp
= attr_system_names
[i
];
2474 if (!namesp
->attr_exists
|| !namesp
->attr_exists(vp
))
2476 error
= attr_generic_listadd(&attr_system
, namesp
,
2477 data
, size
, result
);
2486 struct vnode
*vp
, void *data
, size_t size
, int xflags
, ssize_t
*result
)
2488 attrlist_cursor_kern_t cursor
= { 0 };
2491 VOP_ATTR_LIST(vp
, data
, size
, xflags
, &cursor
, NULL
, error
);
2495 return attr_system_list(vp
, data
, size
, result
);
2499 attr_lookup_namespace(
2501 struct attrnames
**names
,
2506 for (i
= 0; i
< nnames
; i
++)
2507 if (!strncmp(name
, names
[i
]->attr_name
, names
[i
]->attr_namelen
))
2513 * Some checks to prevent people abusing EAs to get over quota:
2514 * - Don't allow modifying user EAs on devices/symlinks;
2515 * - Don't allow modifying user EAs if sticky bit set;
2522 struct inode
*inode
= LINVFS_GET_IP(vp
);
2524 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
2526 if (!S_ISREG(inode
->i_mode
) && !S_ISDIR(inode
->i_mode
) &&
2527 !capable(CAP_SYS_ADMIN
))
2529 if (S_ISDIR(inode
->i_mode
) && (inode
->i_mode
& S_ISVTX
) &&
2530 (current_fsuid(cred
) != inode
->i_uid
) && !capable(CAP_FOWNER
))
2536 attr_trusted_capable(
2540 struct inode
*inode
= LINVFS_GET_IP(vp
);
2542 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
2544 if (!capable(CAP_SYS_ADMIN
))
2550 attr_secure_capable(
2554 return -ENOSECURITY
;
2559 struct vnode
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2561 attrnames_t
*namesp
;
2564 if (xflags
& ATTR_CREATE
)
2567 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2570 error
= namesp
->attr_set(vp
, name
, data
, size
, xflags
);
2572 error
= vn_revalidate(vp
);
2578 struct vnode
*vp
, char *name
, void *data
, size_t size
, int xflags
)
2580 attrnames_t
*namesp
;
2582 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2585 return namesp
->attr_get(vp
, name
, data
, size
, xflags
);
2590 struct vnode
*vp
, char *name
, int xflags
)
2592 attrnames_t
*namesp
;
2594 namesp
= attr_lookup_namespace(name
, attr_system_names
, ATTR_SYSCOUNT
);
2597 return namesp
->attr_remove(vp
, name
, xflags
);
2600 struct attrnames attr_system
= {
2601 .attr_name
= "system.",
2602 .attr_namelen
= sizeof("system.") - 1,
2603 .attr_flag
= ATTR_SYSTEM
,
2604 .attr_get
= attr_system_get
,
2605 .attr_set
= attr_system_set
,
2606 .attr_remove
= attr_system_remove
,
2607 .attr_capable
= (attrcapable_t
)fs_noerr
,
2610 struct attrnames attr_trusted
= {
2611 .attr_name
= "trusted.",
2612 .attr_namelen
= sizeof("trusted.") - 1,
2613 .attr_flag
= ATTR_ROOT
,
2614 .attr_get
= attr_generic_get
,
2615 .attr_set
= attr_generic_set
,
2616 .attr_remove
= attr_generic_remove
,
2617 .attr_capable
= attr_trusted_capable
,
2620 struct attrnames attr_secure
= {
2621 .attr_name
= "security.",
2622 .attr_namelen
= sizeof("security.") - 1,
2623 .attr_flag
= ATTR_SECURE
,
2624 .attr_get
= attr_generic_get
,
2625 .attr_set
= attr_generic_set
,
2626 .attr_remove
= attr_generic_remove
,
2627 .attr_capable
= attr_secure_capable
,
2630 struct attrnames attr_user
= {
2631 .attr_name
= "user.",
2632 .attr_namelen
= sizeof("user.") - 1,
2633 .attr_get
= attr_generic_get
,
2634 .attr_set
= attr_generic_set
,
2635 .attr_remove
= attr_generic_remove
,
2636 .attr_capable
= attr_user_capable
,
2639 struct attrnames
*attr_namespaces
[] =
2640 { &attr_system
, &attr_trusted
, &attr_secure
, &attr_user
};