162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2000,2002-2003,2005 Silicon Graphics, Inc.
462306a36Sopenharmony_ci * Copyright (c) 2013 Red Hat, Inc.
562306a36Sopenharmony_ci * All Rights Reserved.
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci#ifndef __XFS_ATTR_LEAF_H__
862306a36Sopenharmony_ci#define	__XFS_ATTR_LEAF_H__
962306a36Sopenharmony_ci
1062306a36Sopenharmony_cistruct attrlist;
1162306a36Sopenharmony_cistruct xfs_attr_list_context;
1262306a36Sopenharmony_cistruct xfs_da_args;
1362306a36Sopenharmony_cistruct xfs_da_state;
1462306a36Sopenharmony_cistruct xfs_da_state_blk;
1562306a36Sopenharmony_cistruct xfs_inode;
1662306a36Sopenharmony_cistruct xfs_trans;
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci/*
1962306a36Sopenharmony_ci * Incore version of the attribute leaf header.
2062306a36Sopenharmony_ci */
2162306a36Sopenharmony_cistruct xfs_attr3_icleaf_hdr {
2262306a36Sopenharmony_ci	uint32_t	forw;
2362306a36Sopenharmony_ci	uint32_t	back;
2462306a36Sopenharmony_ci	uint16_t	magic;
2562306a36Sopenharmony_ci	uint16_t	count;
2662306a36Sopenharmony_ci	uint16_t	usedbytes;
2762306a36Sopenharmony_ci	/*
2862306a36Sopenharmony_ci	 * Firstused is 32-bit here instead of 16-bit like the on-disk variant
2962306a36Sopenharmony_ci	 * to support maximum fsb size of 64k without overflow issues throughout
3062306a36Sopenharmony_ci	 * the attr code. Instead, the overflow condition is handled on
3162306a36Sopenharmony_ci	 * conversion to/from disk.
3262306a36Sopenharmony_ci	 */
3362306a36Sopenharmony_ci	uint32_t	firstused;
3462306a36Sopenharmony_ci	__u8		holes;
3562306a36Sopenharmony_ci	struct {
3662306a36Sopenharmony_ci		uint16_t	base;
3762306a36Sopenharmony_ci		uint16_t	size;
3862306a36Sopenharmony_ci	} freemap[XFS_ATTR_LEAF_MAPSIZE];
3962306a36Sopenharmony_ci};
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci/*========================================================================
4262306a36Sopenharmony_ci * Function prototypes for the kernel.
4362306a36Sopenharmony_ci *========================================================================*/
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci/*
4662306a36Sopenharmony_ci * Internal routines when attribute fork size < XFS_LITINO(mp).
4762306a36Sopenharmony_ci */
4862306a36Sopenharmony_civoid	xfs_attr_shortform_create(struct xfs_da_args *args);
4962306a36Sopenharmony_civoid	xfs_attr_shortform_add(struct xfs_da_args *args, int forkoff);
5062306a36Sopenharmony_ciint	xfs_attr_shortform_lookup(struct xfs_da_args *args);
5162306a36Sopenharmony_ciint	xfs_attr_shortform_getvalue(struct xfs_da_args *args);
5262306a36Sopenharmony_ciint	xfs_attr_shortform_to_leaf(struct xfs_da_args *args);
5362306a36Sopenharmony_ciint	xfs_attr_sf_removename(struct xfs_da_args *args);
5462306a36Sopenharmony_ciint	xfs_attr_sf_findname(struct xfs_da_args *args,
5562306a36Sopenharmony_ci			     struct xfs_attr_sf_entry **sfep,
5662306a36Sopenharmony_ci			     unsigned int *basep);
5762306a36Sopenharmony_ciint	xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp);
5862306a36Sopenharmony_ciint	xfs_attr_shortform_bytesfit(struct xfs_inode *dp, int bytes);
5962306a36Sopenharmony_cixfs_failaddr_t xfs_attr_shortform_verify(struct xfs_inode *ip);
6062306a36Sopenharmony_civoid	xfs_attr_fork_remove(struct xfs_inode *ip, struct xfs_trans *tp);
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci/*
6362306a36Sopenharmony_ci * Internal routines when attribute fork size == XFS_LBSIZE(mp).
6462306a36Sopenharmony_ci */
6562306a36Sopenharmony_ciint	xfs_attr3_leaf_to_node(struct xfs_da_args *args);
6662306a36Sopenharmony_ciint	xfs_attr3_leaf_to_shortform(struct xfs_buf *bp,
6762306a36Sopenharmony_ci				   struct xfs_da_args *args, int forkoff);
6862306a36Sopenharmony_ciint	xfs_attr3_leaf_clearflag(struct xfs_da_args *args);
6962306a36Sopenharmony_ciint	xfs_attr3_leaf_setflag(struct xfs_da_args *args);
7062306a36Sopenharmony_ciint	xfs_attr3_leaf_flipflags(struct xfs_da_args *args);
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/*
7362306a36Sopenharmony_ci * Routines used for growing the Btree.
7462306a36Sopenharmony_ci */
7562306a36Sopenharmony_ciint	xfs_attr3_leaf_split(struct xfs_da_state *state,
7662306a36Sopenharmony_ci				   struct xfs_da_state_blk *oldblk,
7762306a36Sopenharmony_ci				   struct xfs_da_state_blk *newblk);
7862306a36Sopenharmony_ciint	xfs_attr3_leaf_lookup_int(struct xfs_buf *leaf,
7962306a36Sopenharmony_ci					struct xfs_da_args *args);
8062306a36Sopenharmony_ciint	xfs_attr3_leaf_getvalue(struct xfs_buf *bp, struct xfs_da_args *args);
8162306a36Sopenharmony_ciint	xfs_attr3_leaf_add(struct xfs_buf *leaf_buffer,
8262306a36Sopenharmony_ci				 struct xfs_da_args *args);
8362306a36Sopenharmony_ciint	xfs_attr3_leaf_remove(struct xfs_buf *leaf_buffer,
8462306a36Sopenharmony_ci				    struct xfs_da_args *args);
8562306a36Sopenharmony_ciint	xfs_attr3_leaf_list_int(struct xfs_buf *bp,
8662306a36Sopenharmony_ci				struct xfs_attr_list_context *context);
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci/*
8962306a36Sopenharmony_ci * Routines used for shrinking the Btree.
9062306a36Sopenharmony_ci */
9162306a36Sopenharmony_ciint	xfs_attr3_leaf_toosmall(struct xfs_da_state *state, int *retval);
9262306a36Sopenharmony_civoid	xfs_attr3_leaf_unbalance(struct xfs_da_state *state,
9362306a36Sopenharmony_ci				       struct xfs_da_state_blk *drop_blk,
9462306a36Sopenharmony_ci				       struct xfs_da_state_blk *save_blk);
9562306a36Sopenharmony_ci/*
9662306a36Sopenharmony_ci * Utility routines.
9762306a36Sopenharmony_ci */
9862306a36Sopenharmony_cixfs_dahash_t	xfs_attr_leaf_lasthash(struct xfs_buf *bp, int *count);
9962306a36Sopenharmony_ciint	xfs_attr_leaf_order(struct xfs_buf *leaf1_bp,
10062306a36Sopenharmony_ci				   struct xfs_buf *leaf2_bp);
10162306a36Sopenharmony_ciint	xfs_attr_leaf_newentsize(struct xfs_da_args *args, int *local);
10262306a36Sopenharmony_ciint	xfs_attr3_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp,
10362306a36Sopenharmony_ci			xfs_dablk_t bno, struct xfs_buf **bpp);
10462306a36Sopenharmony_civoid	xfs_attr3_leaf_hdr_from_disk(struct xfs_da_geometry *geo,
10562306a36Sopenharmony_ci				     struct xfs_attr3_icleaf_hdr *to,
10662306a36Sopenharmony_ci				     struct xfs_attr_leafblock *from);
10762306a36Sopenharmony_civoid	xfs_attr3_leaf_hdr_to_disk(struct xfs_da_geometry *geo,
10862306a36Sopenharmony_ci				   struct xfs_attr_leafblock *to,
10962306a36Sopenharmony_ci				   struct xfs_attr3_icleaf_hdr *from);
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci#endif	/* __XFS_ATTR_LEAF_H__ */
112