xref: /openbmc/linux/fs/xfs/libxfs/xfs_attr_leaf.h (revision 7b73a9c8)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000,2002-2003,2005 Silicon Graphics, Inc.
4  * Copyright (c) 2013 Red Hat, Inc.
5  * All Rights Reserved.
6  */
7 #ifndef __XFS_ATTR_LEAF_H__
8 #define	__XFS_ATTR_LEAF_H__
9 
10 struct attrlist;
11 struct attrlist_cursor_kern;
12 struct xfs_attr_list_context;
13 struct xfs_da_args;
14 struct xfs_da_state;
15 struct xfs_da_state_blk;
16 struct xfs_inode;
17 struct xfs_trans;
18 
19 /*
20  * Incore version of the attribute leaf header.
21  */
22 struct xfs_attr3_icleaf_hdr {
23 	uint32_t	forw;
24 	uint32_t	back;
25 	uint16_t	magic;
26 	uint16_t	count;
27 	uint16_t	usedbytes;
28 	/*
29 	 * Firstused is 32-bit here instead of 16-bit like the on-disk variant
30 	 * to support maximum fsb size of 64k without overflow issues throughout
31 	 * the attr code. Instead, the overflow condition is handled on
32 	 * conversion to/from disk.
33 	 */
34 	uint32_t	firstused;
35 	__u8		holes;
36 	struct {
37 		uint16_t	base;
38 		uint16_t	size;
39 	} freemap[XFS_ATTR_LEAF_MAPSIZE];
40 };
41 
42 /*
43  * Used to keep a list of "remote value" extents when unlinking an inode.
44  */
45 typedef struct xfs_attr_inactive_list {
46 	xfs_dablk_t	valueblk;	/* block number of value bytes */
47 	int		valuelen;	/* number of bytes in value */
48 } xfs_attr_inactive_list_t;
49 
50 
51 /*========================================================================
52  * Function prototypes for the kernel.
53  *========================================================================*/
54 
55 /*
56  * Internal routines when attribute fork size < XFS_LITINO(mp).
57  */
58 void	xfs_attr_shortform_create(struct xfs_da_args *args);
59 void	xfs_attr_shortform_add(struct xfs_da_args *args, int forkoff);
60 int	xfs_attr_shortform_lookup(struct xfs_da_args *args);
61 int	xfs_attr_shortform_getvalue(struct xfs_da_args *args);
62 int	xfs_attr_shortform_to_leaf(struct xfs_da_args *args,
63 			struct xfs_buf **leaf_bp);
64 int	xfs_attr_shortform_remove(struct xfs_da_args *args);
65 int	xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp);
66 int	xfs_attr_shortform_bytesfit(struct xfs_inode *dp, int bytes);
67 xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_inode *ip);
68 void	xfs_attr_fork_remove(struct xfs_inode *ip, struct xfs_trans *tp);
69 
70 /*
71  * Internal routines when attribute fork size == XFS_LBSIZE(mp).
72  */
73 int	xfs_attr3_leaf_to_node(struct xfs_da_args *args);
74 int	xfs_attr3_leaf_to_shortform(struct xfs_buf *bp,
75 				   struct xfs_da_args *args, int forkoff);
76 int	xfs_attr3_leaf_clearflag(struct xfs_da_args *args);
77 int	xfs_attr3_leaf_setflag(struct xfs_da_args *args);
78 int	xfs_attr3_leaf_flipflags(struct xfs_da_args *args);
79 
80 /*
81  * Routines used for growing the Btree.
82  */
83 int	xfs_attr3_leaf_split(struct xfs_da_state *state,
84 				   struct xfs_da_state_blk *oldblk,
85 				   struct xfs_da_state_blk *newblk);
86 int	xfs_attr3_leaf_lookup_int(struct xfs_buf *leaf,
87 					struct xfs_da_args *args);
88 int	xfs_attr3_leaf_getvalue(struct xfs_buf *bp, struct xfs_da_args *args);
89 int	xfs_attr3_leaf_add(struct xfs_buf *leaf_buffer,
90 				 struct xfs_da_args *args);
91 int	xfs_attr3_leaf_remove(struct xfs_buf *leaf_buffer,
92 				    struct xfs_da_args *args);
93 int	xfs_attr3_leaf_list_int(struct xfs_buf *bp,
94 				struct xfs_attr_list_context *context);
95 
96 /*
97  * Routines used for shrinking the Btree.
98  */
99 int	xfs_attr3_leaf_toosmall(struct xfs_da_state *state, int *retval);
100 void	xfs_attr3_leaf_unbalance(struct xfs_da_state *state,
101 				       struct xfs_da_state_blk *drop_blk,
102 				       struct xfs_da_state_blk *save_blk);
103 /*
104  * Utility routines.
105  */
106 xfs_dahash_t	xfs_attr_leaf_lasthash(struct xfs_buf *bp, int *count);
107 int	xfs_attr_leaf_order(struct xfs_buf *leaf1_bp,
108 				   struct xfs_buf *leaf2_bp);
109 int	xfs_attr_leaf_newentsize(struct xfs_da_args *args, int *local);
110 int	xfs_attr3_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp,
111 			xfs_dablk_t bno, struct xfs_buf **bpp);
112 void	xfs_attr3_leaf_hdr_from_disk(struct xfs_da_geometry *geo,
113 				     struct xfs_attr3_icleaf_hdr *to,
114 				     struct xfs_attr_leafblock *from);
115 void	xfs_attr3_leaf_hdr_to_disk(struct xfs_da_geometry *geo,
116 				   struct xfs_attr_leafblock *to,
117 				   struct xfs_attr3_icleaf_hdr *from);
118 
119 #endif	/* __XFS_ATTR_LEAF_H__ */
120