xref: /linux/fs/xfs/libxfs/xfs_attr_leaf.h (revision 6f7e6393d1ce636bb7ec77a7fe7b77458fddf701)
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 xfs_attr_list_context;
12 struct xfs_da_args;
13 struct xfs_da_state;
14 struct xfs_da_state_blk;
15 struct xfs_inode;
16 struct xfs_trans;
17 
18 /*
19  * Incore version of the attribute leaf header.
20  */
21 struct xfs_attr3_icleaf_hdr {
22 	uint32_t	forw;
23 	uint32_t	back;
24 	uint16_t	magic;
25 	uint16_t	count;
26 	uint16_t	usedbytes;
27 	/*
28 	 * Firstused is 32-bit here instead of 16-bit like the on-disk variant
29 	 * to support maximum fsb size of 64k without overflow issues throughout
30 	 * the attr code. Instead, the overflow condition is handled on
31 	 * conversion to/from disk.
32 	 */
33 	uint32_t	firstused;
34 	__u8		holes;
35 	struct {
36 		uint16_t	base;
37 		uint16_t	size;
38 	} freemap[XFS_ATTR_LEAF_MAPSIZE];
39 };
40 
41 /*========================================================================
42  * Function prototypes for the kernel.
43  *========================================================================*/
44 
45 /*
46  * Internal routines when attribute fork size < XFS_LITINO(mp).
47  */
48 void	xfs_attr_shortform_create(struct xfs_da_args *args);
49 int	xfs_attr_shortform_replace(struct xfs_da_args *args);
50 void	xfs_attr_shortform_add(struct xfs_da_args *args, int forkoff);
51 int	xfs_attr_shortform_getvalue(struct xfs_da_args *args);
52 int	xfs_attr_shortform_to_leaf(struct xfs_da_args *args);
53 int	xfs_attr_sf_removename(struct xfs_da_args *args);
54 struct xfs_attr_sf_entry *xfs_attr_sf_findname(struct xfs_da_args *args);
55 int	xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp);
56 int	xfs_attr_shortform_bytesfit(struct xfs_inode *dp, int bytes);
57 xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_attr_sf_hdr *sfp,
58 		size_t size);
59 void	xfs_attr_fork_remove(struct xfs_inode *ip, struct xfs_trans *tp);
60 
61 /*
62  * Internal routines when attribute fork size == XFS_LBSIZE(mp).
63  */
64 int	xfs_attr3_leaf_to_node(struct xfs_da_args *args);
65 int	xfs_attr3_leaf_to_shortform(struct xfs_buf *bp,
66 				   struct xfs_da_args *args, int forkoff);
67 int	xfs_attr3_leaf_clearflag(struct xfs_da_args *args);
68 int	xfs_attr3_leaf_setflag(struct xfs_da_args *args);
69 int	xfs_attr3_leaf_flipflags(struct xfs_da_args *args);
70 
71 /*
72  * Routines used for growing the Btree.
73  */
74 int	xfs_attr3_leaf_split(struct xfs_da_state *state,
75 				   struct xfs_da_state_blk *oldblk,
76 				   struct xfs_da_state_blk *newblk);
77 int	xfs_attr3_leaf_lookup_int(struct xfs_buf *leaf,
78 					struct xfs_da_args *args);
79 int	xfs_attr3_leaf_getvalue(struct xfs_buf *bp, struct xfs_da_args *args);
80 bool	xfs_attr3_leaf_add(struct xfs_buf *leaf_buffer,
81 				 struct xfs_da_args *args);
82 int	xfs_attr3_leaf_remove(struct xfs_buf *leaf_buffer,
83 				    struct xfs_da_args *args);
84 int	xfs_attr3_leaf_list_int(struct xfs_buf *bp,
85 				struct xfs_attr_list_context *context);
86 
87 /*
88  * Routines used for shrinking the Btree.
89  */
90 int	xfs_attr3_leaf_toosmall(struct xfs_da_state *state, int *retval);
91 void	xfs_attr3_leaf_unbalance(struct xfs_da_state *state,
92 				       struct xfs_da_state_blk *drop_blk,
93 				       struct xfs_da_state_blk *save_blk);
94 /*
95  * Utility routines.
96  */
97 xfs_dahash_t	xfs_attr_leaf_lasthash(struct xfs_buf *bp, int *count);
98 int	xfs_attr_leaf_order(struct xfs_buf *leaf1_bp,
99 				   struct xfs_buf *leaf2_bp);
100 int	xfs_attr_leaf_newentsize(struct xfs_da_args *args, int *local);
101 int	xfs_attr3_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp,
102 			xfs_ino_t owner, xfs_dablk_t bno, struct xfs_buf **bpp);
103 void	xfs_attr3_leaf_hdr_from_disk(struct xfs_da_geometry *geo,
104 				     struct xfs_attr3_icleaf_hdr *to,
105 				     struct xfs_attr_leafblock *from);
106 void	xfs_attr3_leaf_hdr_to_disk(struct xfs_da_geometry *geo,
107 				   struct xfs_attr_leafblock *to,
108 				   struct xfs_attr3_icleaf_hdr *from);
109 xfs_failaddr_t xfs_attr3_leaf_header_check(struct xfs_buf *bp,
110 		xfs_ino_t owner);
111 
112 #endif	/* __XFS_ATTR_LEAF_H__ */
113