Commit | Line | Data |
---|---|---|
0b61f8a4 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 | 2 | /* |
7b718769 | 3 | * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc. |
f5ea1100 | 4 | * Copyright (c) 2013 Red Hat, Inc. |
7b718769 | 5 | * All Rights Reserved. |
1da177e4 LT |
6 | */ |
7 | #ifndef __XFS_DA_BTREE_H__ | |
8 | #define __XFS_DA_BTREE_H__ | |
9 | ||
1da177e4 | 10 | struct xfs_inode; |
1da177e4 LT |
11 | struct xfs_trans; |
12 | struct zone; | |
32c5483a | 13 | struct xfs_dir_ops; |
1da177e4 | 14 | |
0650b554 DC |
15 | /* |
16 | * Directory/attribute geometry information. There will be one of these for each | |
17 | * data fork type, and it will be passed around via the xfs_da_args. Global | |
18 | * structures will be attached to the xfs_mount. | |
19 | */ | |
20 | struct xfs_da_geometry { | |
b16be561 CH |
21 | unsigned int blksize; /* da block size in bytes */ |
22 | unsigned int fsbcount; /* da block size in filesystem blocks */ | |
0650b554 DC |
23 | uint8_t fsblog; /* log2 of _filesystem_ block size */ |
24 | uint8_t blklog; /* log2 of da block size */ | |
3b344413 | 25 | unsigned int node_hdr_size; /* danode header size in bytes */ |
b16be561 CH |
26 | unsigned int node_ents; /* # of entries in a danode */ |
27 | unsigned int magicpct; /* 37% of block size in bytes */ | |
0650b554 | 28 | xfs_dablk_t datablk; /* blockno of dir data v2 */ |
545910bc | 29 | unsigned int leaf_hdr_size; /* dir2 leaf header size */ |
478c7835 | 30 | unsigned int leaf_max_ents; /* # of entries in dir2 leaf */ |
0650b554 | 31 | xfs_dablk_t leafblk; /* blockno of leaf data v2 */ |
ed1d612f | 32 | unsigned int free_hdr_size; /* dir2 free header size */ |
5893e4fe | 33 | unsigned int free_max_bests; /* # of bests entries in dir2 free */ |
0650b554 DC |
34 | xfs_dablk_t freeblk; /* blockno of free data v2 */ |
35 | }; | |
36 | ||
1da177e4 LT |
37 | /*======================================================================== |
38 | * Btree searching and modification structure definitions. | |
39 | *========================================================================*/ | |
40 | ||
5163f95a BN |
41 | /* |
42 | * Search comparison results | |
43 | */ | |
44 | enum xfs_dacmp { | |
45 | XFS_CMP_DIFFERENT, /* names are completely different */ | |
46 | XFS_CMP_EXACT, /* names are exactly the same */ | |
47 | XFS_CMP_CASE /* names are same but differ in case */ | |
48 | }; | |
49 | ||
1da177e4 LT |
50 | /* |
51 | * Structure to ease passing around component names. | |
52 | */ | |
53 | typedef struct xfs_da_args { | |
0650b554 | 54 | struct xfs_da_geometry *geo; /* da block geometry */ |
c8ce540d | 55 | const uint8_t *name; /* string (maybe not NULL terminated) */ |
1da177e4 | 56 | int namelen; /* length of string (maybe no NULL) */ |
c8ce540d DW |
57 | uint8_t filetype; /* filetype of inode for directories */ |
58 | uint8_t *value; /* set of bytes (maybe contain NULLs) */ | |
1da177e4 LT |
59 | int valuelen; /* length of value */ |
60 | int flags; /* argument flags (eg: ATTR_NOCREATE) */ | |
61 | xfs_dahash_t hashval; /* hash value of name */ | |
62 | xfs_ino_t inumber; /* input/output inode number */ | |
63 | struct xfs_inode *dp; /* directory inode to manipulate */ | |
1da177e4 LT |
64 | struct xfs_trans *trans; /* current trans (changes over time) */ |
65 | xfs_extlen_t total; /* total blocks needed, for 1st bmap */ | |
66 | int whichfork; /* data or attribute fork */ | |
67 | xfs_dablk_t blkno; /* blkno of attr leaf of interest */ | |
68 | int index; /* index of attr of interest in blk */ | |
69 | xfs_dablk_t rmtblkno; /* remote attr value starting blkno */ | |
70 | int rmtblkcnt; /* remote attr value block count */ | |
8275cdd0 | 71 | int rmtvaluelen; /* remote attr value length in bytes */ |
1da177e4 LT |
72 | xfs_dablk_t blkno2; /* blkno of 2nd attr leaf of interest */ |
73 | int index2; /* index of 2nd attr in blk */ | |
74 | xfs_dablk_t rmtblkno2; /* remote attr value starting blkno */ | |
75 | int rmtblkcnt2; /* remote attr value block count */ | |
8275cdd0 | 76 | int rmtvaluelen2; /* remote attr value length in bytes */ |
6a178100 | 77 | int op_flags; /* operation flags */ |
5163f95a | 78 | enum xfs_dacmp cmpresult; /* name compare result for lookups */ |
1da177e4 LT |
79 | } xfs_da_args_t; |
80 | ||
6a178100 BN |
81 | /* |
82 | * Operation flags: | |
83 | */ | |
84 | #define XFS_DA_OP_JUSTCHECK 0x0001 /* check for ok with no space */ | |
85 | #define XFS_DA_OP_RENAME 0x0002 /* this is an atomic rename op */ | |
86 | #define XFS_DA_OP_ADDNAME 0x0004 /* this is an add operation */ | |
87 | #define XFS_DA_OP_OKNOENT 0x0008 /* lookup/add op, ENOENT ok, else die */ | |
384f3ced | 88 | #define XFS_DA_OP_CILOOKUP 0x0010 /* lookup to return CI name if found */ |
ddbca70c | 89 | #define XFS_DA_OP_ALLOCVAL 0x0020 /* lookup to alloc buffer if found */ |
6a178100 | 90 | |
0b1b213f CH |
91 | #define XFS_DA_OP_FLAGS \ |
92 | { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \ | |
93 | { XFS_DA_OP_RENAME, "RENAME" }, \ | |
94 | { XFS_DA_OP_ADDNAME, "ADDNAME" }, \ | |
95 | { XFS_DA_OP_OKNOENT, "OKNOENT" }, \ | |
ddbca70c DC |
96 | { XFS_DA_OP_CILOOKUP, "CILOOKUP" }, \ |
97 | { XFS_DA_OP_ALLOCVAL, "ALLOCVAL" } | |
0b1b213f | 98 | |
1da177e4 LT |
99 | /* |
100 | * Storage for holding state during Btree searches and split/join ops. | |
101 | * | |
102 | * Only need space for 5 intermediate nodes. With a minimum of 62-way | |
103 | * fanout to the Btree, we can support over 900 million directory blocks, | |
104 | * which is slightly more than enough. | |
105 | */ | |
106 | typedef struct xfs_da_state_blk { | |
1d9025e5 | 107 | struct xfs_buf *bp; /* buffer containing block */ |
1da177e4 LT |
108 | xfs_dablk_t blkno; /* filesystem blkno of buffer */ |
109 | xfs_daddr_t disk_blkno; /* on-disk blkno (in BBs) of buffer */ | |
110 | int index; /* relevant index into block */ | |
111 | xfs_dahash_t hashval; /* last hash value in block */ | |
112 | int magic; /* blk's magic number, ie: blk type */ | |
113 | } xfs_da_state_blk_t; | |
114 | ||
115 | typedef struct xfs_da_state_path { | |
116 | int active; /* number of active levels */ | |
117 | xfs_da_state_blk_t blk[XFS_DA_NODE_MAXDEPTH]; | |
118 | } xfs_da_state_path_t; | |
119 | ||
120 | typedef struct xfs_da_state { | |
121 | xfs_da_args_t *args; /* filename arguments */ | |
122 | struct xfs_mount *mp; /* filesystem mount point */ | |
1da177e4 LT |
123 | xfs_da_state_path_t path; /* search/split paths */ |
124 | xfs_da_state_path_t altpath; /* alternate path for join */ | |
125 | unsigned char inleaf; /* insert into 1->lf, 0->splf */ | |
126 | unsigned char extravalid; /* T/F: extrablk is in use */ | |
127 | unsigned char extraafter; /* T/F: extrablk is after new */ | |
9da096fd | 128 | xfs_da_state_blk_t extrablk; /* for double-splits on leaves */ |
1da177e4 LT |
129 | /* for dirv2 extrablk is data */ |
130 | } xfs_da_state_t; | |
131 | ||
a39f089a CH |
132 | /* |
133 | * In-core version of the node header to abstract the differences in the v2 and | |
134 | * v3 disk format of the headers. Callers need to convert to/from disk format as | |
135 | * appropriate. | |
136 | */ | |
137 | struct xfs_da3_icnode_hdr { | |
138 | uint32_t forw; | |
139 | uint32_t back; | |
140 | uint16_t magic; | |
141 | uint16_t count; | |
142 | uint16_t level; | |
51908ca7 CH |
143 | |
144 | /* | |
145 | * Pointer to the on-disk format entries, which are behind the | |
146 | * variable size (v4 vs v5) header in the on-disk block. | |
147 | */ | |
148 | struct xfs_da_node_entry *btree; | |
a39f089a CH |
149 | }; |
150 | ||
1da177e4 LT |
151 | /* |
152 | * Utility macros to aid in logging changed structure fields. | |
153 | */ | |
154 | #define XFS_DA_LOGOFF(BASE, ADDR) ((char *)(ADDR) - (char *)(BASE)) | |
155 | #define XFS_DA_LOGRANGE(BASE, ADDR, SIZE) \ | |
156 | (uint)(XFS_DA_LOGOFF(BASE, ADDR)), \ | |
157 | (uint)(XFS_DA_LOGOFF(BASE, ADDR)+(SIZE)-1) | |
158 | ||
5163f95a BN |
159 | /* |
160 | * Name ops for directory and/or attr name operations | |
161 | */ | |
162 | struct xfs_nameops { | |
163 | xfs_dahash_t (*hashname)(struct xfs_name *); | |
2bc75421 DC |
164 | enum xfs_dacmp (*compname)(struct xfs_da_args *, |
165 | const unsigned char *, int); | |
5163f95a BN |
166 | }; |
167 | ||
1da177e4 | 168 | |
1da177e4 | 169 | /*======================================================================== |
847fff5c | 170 | * Function prototypes. |
1da177e4 LT |
171 | *========================================================================*/ |
172 | ||
173 | /* | |
174 | * Routines used for growing the Btree. | |
175 | */ | |
f5ea1100 DC |
176 | int xfs_da3_node_create(struct xfs_da_args *args, xfs_dablk_t blkno, |
177 | int level, struct xfs_buf **bpp, int whichfork); | |
178 | int xfs_da3_split(xfs_da_state_t *state); | |
1da177e4 LT |
179 | |
180 | /* | |
181 | * Routines used for shrinking the Btree. | |
182 | */ | |
f5ea1100 DC |
183 | int xfs_da3_join(xfs_da_state_t *state); |
184 | void xfs_da3_fixhashpath(struct xfs_da_state *state, | |
185 | struct xfs_da_state_path *path_to_to_fix); | |
1da177e4 LT |
186 | |
187 | /* | |
188 | * Routines used for finding things in the Btree. | |
189 | */ | |
f5ea1100 DC |
190 | int xfs_da3_node_lookup_int(xfs_da_state_t *state, int *result); |
191 | int xfs_da3_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path, | |
1da177e4 LT |
192 | int forward, int release, int *result); |
193 | /* | |
194 | * Utility routines. | |
195 | */ | |
f5ea1100 | 196 | int xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk, |
1da177e4 | 197 | xfs_da_state_blk_t *new_blk); |
f5ea1100 | 198 | int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp, |
d9392a4b DC |
199 | xfs_dablk_t bno, xfs_daddr_t mappedbno, |
200 | struct xfs_buf **bpp, int which_fork); | |
1da177e4 LT |
201 | |
202 | /* | |
203 | * Utility routines. | |
204 | */ | |
205 | int xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno); | |
77936d02 CH |
206 | int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno, |
207 | int count); | |
1da177e4 LT |
208 | int xfs_da_get_buf(struct xfs_trans *trans, struct xfs_inode *dp, |
209 | xfs_dablk_t bno, xfs_daddr_t mappedbno, | |
1d9025e5 | 210 | struct xfs_buf **bp, int whichfork); |
1da177e4 LT |
211 | int xfs_da_read_buf(struct xfs_trans *trans, struct xfs_inode *dp, |
212 | xfs_dablk_t bno, xfs_daddr_t mappedbno, | |
4bb20a83 | 213 | struct xfs_buf **bpp, int whichfork, |
1813dd64 | 214 | const struct xfs_buf_ops *ops); |
7a652bbe | 215 | int xfs_da_reada_buf(struct xfs_inode *dp, xfs_dablk_t bno, |
9df2dd0b ES |
216 | xfs_daddr_t mapped_bno, int whichfork, |
217 | const struct xfs_buf_ops *ops); | |
1da177e4 | 218 | int xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno, |
1d9025e5 | 219 | struct xfs_buf *dead_buf); |
1da177e4 | 220 | |
c8ce540d | 221 | uint xfs_da_hashname(const uint8_t *name_string, int name_length); |
5163f95a | 222 | enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args, |
2bc75421 | 223 | const unsigned char *name, int len); |
5163f95a BN |
224 | |
225 | ||
1da177e4 LT |
226 | xfs_da_state_t *xfs_da_state_alloc(void); |
227 | void xfs_da_state_free(xfs_da_state_t *state); | |
1da177e4 | 228 | |
f475dc4d CH |
229 | void xfs_da3_node_hdr_from_disk(struct xfs_mount *mp, |
230 | struct xfs_da3_icnode_hdr *to, struct xfs_da_intnode *from); | |
e1c8af1e CH |
231 | void xfs_da3_node_hdr_to_disk(struct xfs_mount *mp, |
232 | struct xfs_da_intnode *to, struct xfs_da3_icnode_hdr *from); | |
f475dc4d | 233 | |
1da177e4 | 234 | extern struct kmem_zone *xfs_da_state_zone; |
24418492 | 235 | extern const struct xfs_nameops xfs_default_nameops; |
1da177e4 LT |
236 | |
237 | #endif /* __XFS_DA_BTREE_H__ */ |