1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef __XFS_ATTR_LEAF_H__
19#define __XFS_ATTR_LEAF_H__
20
21
22
23
24
25
26
27
28
29
30
31struct attrlist;
32struct attrlist_cursor_kern;
33struct xfs_attr_list_context;
34struct xfs_da_args;
35struct xfs_da_state;
36struct xfs_da_state_blk;
37struct xfs_inode;
38struct xfs_trans;
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72#define XFS_ATTR_LEAF_MAPSIZE 3
73
74typedef struct xfs_attr_leaf_map {
75 __be16 base;
76 __be16 size;
77} xfs_attr_leaf_map_t;
78
79typedef struct xfs_attr_leaf_hdr {
80 xfs_da_blkinfo_t info;
81 __be16 count;
82 __be16 usedbytes;
83 __be16 firstused;
84 __u8 holes;
85 __u8 pad1;
86 xfs_attr_leaf_map_t freemap[XFS_ATTR_LEAF_MAPSIZE];
87
88} xfs_attr_leaf_hdr_t;
89
90typedef struct xfs_attr_leaf_entry {
91 __be32 hashval;
92 __be16 nameidx;
93 __u8 flags;
94 __u8 pad2;
95} xfs_attr_leaf_entry_t;
96
97typedef struct xfs_attr_leaf_name_local {
98 __be16 valuelen;
99 __u8 namelen;
100 __u8 nameval[1];
101} xfs_attr_leaf_name_local_t;
102
103typedef struct xfs_attr_leaf_name_remote {
104 __be32 valueblk;
105 __be32 valuelen;
106 __u8 namelen;
107 __u8 name[1];
108} xfs_attr_leaf_name_remote_t;
109
110typedef struct xfs_attr_leafblock {
111 xfs_attr_leaf_hdr_t hdr;
112 xfs_attr_leaf_entry_t entries[1];
113 xfs_attr_leaf_name_local_t namelist;
114 xfs_attr_leaf_name_remote_t valuelist;
115} xfs_attr_leafblock_t;
116
117
118
119
120
121
122#define XFS_ATTR_LOCAL_BIT 0
123#define XFS_ATTR_ROOT_BIT 1
124#define XFS_ATTR_SECURE_BIT 2
125#define XFS_ATTR_INCOMPLETE_BIT 7
126#define XFS_ATTR_LOCAL (1 << XFS_ATTR_LOCAL_BIT)
127#define XFS_ATTR_ROOT (1 << XFS_ATTR_ROOT_BIT)
128#define XFS_ATTR_SECURE (1 << XFS_ATTR_SECURE_BIT)
129#define XFS_ATTR_INCOMPLETE (1 << XFS_ATTR_INCOMPLETE_BIT)
130
131
132
133
134
135#define XFS_ATTR_NSP_ARGS_MASK (ATTR_ROOT | ATTR_SECURE)
136#define XFS_ATTR_NSP_ONDISK_MASK (XFS_ATTR_ROOT | XFS_ATTR_SECURE)
137#define XFS_ATTR_NSP_ONDISK(flags) ((flags) & XFS_ATTR_NSP_ONDISK_MASK)
138#define XFS_ATTR_NSP_ARGS(flags) ((flags) & XFS_ATTR_NSP_ARGS_MASK)
139#define XFS_ATTR_NSP_ARGS_TO_ONDISK(x) (((x) & ATTR_ROOT ? XFS_ATTR_ROOT : 0) |\
140 ((x) & ATTR_SECURE ? XFS_ATTR_SECURE : 0))
141#define XFS_ATTR_NSP_ONDISK_TO_ARGS(x) (((x) & XFS_ATTR_ROOT ? ATTR_ROOT : 0) |\
142 ((x) & XFS_ATTR_SECURE ? ATTR_SECURE : 0))
143
144
145
146
147
148#define XFS_ATTR_LEAF_NAME_ALIGN ((uint)sizeof(xfs_dablk_t))
149
150
151
152
153static inline xfs_attr_leaf_name_remote_t *
154xfs_attr_leaf_name_remote(xfs_attr_leafblock_t *leafp, int idx)
155{
156 return (xfs_attr_leaf_name_remote_t *)
157 &((char *)leafp)[be16_to_cpu(leafp->entries[idx].nameidx)];
158}
159
160static inline xfs_attr_leaf_name_local_t *
161xfs_attr_leaf_name_local(xfs_attr_leafblock_t *leafp, int idx)
162{
163 return (xfs_attr_leaf_name_local_t *)
164 &((char *)leafp)[be16_to_cpu(leafp->entries[idx].nameidx)];
165}
166
167static inline char *xfs_attr_leaf_name(xfs_attr_leafblock_t *leafp, int idx)
168{
169 return &((char *)leafp)[be16_to_cpu(leafp->entries[idx].nameidx)];
170}
171
172
173
174
175
176
177static inline int xfs_attr_leaf_entsize_remote(int nlen)
178{
179 return ((uint)sizeof(xfs_attr_leaf_name_remote_t) - 1 + (nlen) + \
180 XFS_ATTR_LEAF_NAME_ALIGN - 1) & ~(XFS_ATTR_LEAF_NAME_ALIGN - 1);
181}
182
183static inline int xfs_attr_leaf_entsize_local(int nlen, int vlen)
184{
185 return ((uint)sizeof(xfs_attr_leaf_name_local_t) - 1 + (nlen) + (vlen) +
186 XFS_ATTR_LEAF_NAME_ALIGN - 1) & ~(XFS_ATTR_LEAF_NAME_ALIGN - 1);
187}
188
189static inline int xfs_attr_leaf_entsize_local_max(int bsize)
190{
191 return (((bsize) >> 1) + ((bsize) >> 2));
192}
193
194
195
196
197typedef struct xfs_attr_inactive_list {
198 xfs_dablk_t valueblk;
199 int valuelen;
200} xfs_attr_inactive_list_t;
201
202
203
204
205
206
207
208
209
210void xfs_attr_shortform_create(struct xfs_da_args *args);
211void xfs_attr_shortform_add(struct xfs_da_args *args, int forkoff);
212int xfs_attr_shortform_lookup(struct xfs_da_args *args);
213int xfs_attr_shortform_getvalue(struct xfs_da_args *args);
214int xfs_attr_shortform_to_leaf(struct xfs_da_args *args);
215int xfs_attr_shortform_remove(struct xfs_da_args *args);
216int xfs_attr_shortform_list(struct xfs_attr_list_context *context);
217int xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp);
218int xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes);
219
220
221
222
223
224int xfs_attr_leaf_to_node(struct xfs_da_args *args);
225int xfs_attr_leaf_to_shortform(struct xfs_buf *bp,
226 struct xfs_da_args *args, int forkoff);
227int xfs_attr_leaf_clearflag(struct xfs_da_args *args);
228int xfs_attr_leaf_setflag(struct xfs_da_args *args);
229int xfs_attr_leaf_flipflags(xfs_da_args_t *args);
230
231
232
233
234int xfs_attr_leaf_split(struct xfs_da_state *state,
235 struct xfs_da_state_blk *oldblk,
236 struct xfs_da_state_blk *newblk);
237int xfs_attr_leaf_lookup_int(struct xfs_buf *leaf,
238 struct xfs_da_args *args);
239int xfs_attr_leaf_getvalue(struct xfs_buf *bp, struct xfs_da_args *args);
240int xfs_attr_leaf_add(struct xfs_buf *leaf_buffer,
241 struct xfs_da_args *args);
242int xfs_attr_leaf_remove(struct xfs_buf *leaf_buffer,
243 struct xfs_da_args *args);
244int xfs_attr_leaf_list_int(struct xfs_buf *bp,
245 struct xfs_attr_list_context *context);
246
247
248
249
250int xfs_attr_leaf_toosmall(struct xfs_da_state *state, int *retval);
251void xfs_attr_leaf_unbalance(struct xfs_da_state *state,
252 struct xfs_da_state_blk *drop_blk,
253 struct xfs_da_state_blk *save_blk);
254int xfs_attr_root_inactive(struct xfs_trans **trans, struct xfs_inode *dp);
255
256
257
258
259xfs_dahash_t xfs_attr_leaf_lasthash(struct xfs_buf *bp, int *count);
260int xfs_attr_leaf_order(struct xfs_buf *leaf1_bp,
261 struct xfs_buf *leaf2_bp);
262int xfs_attr_leaf_newentsize(int namelen, int valuelen, int blocksize,
263 int *local);
264#endif
265