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