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