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; | |
13 | ||
0650b554 DC |
14 | /* |
15 | * Directory/attribute geometry information. There will be one of these for each | |
16 | * data fork type, and it will be passed around via the xfs_da_args. Global | |
17 | * structures will be attached to the xfs_mount. | |
18 | */ | |
19 | struct xfs_da_geometry { | |
b16be561 CH |
20 | unsigned int blksize; /* da block size in bytes */ |
21 | unsigned int fsbcount; /* da block size in filesystem blocks */ | |
0650b554 DC |
22 | uint8_t fsblog; /* log2 of _filesystem_ block size */ |
23 | uint8_t blklog; /* log2 of da block size */ | |
3b344413 | 24 | unsigned int node_hdr_size; /* danode header size in bytes */ |
b16be561 CH |
25 | unsigned int node_ents; /* # of entries in a danode */ |
26 | unsigned int magicpct; /* 37% of block size in bytes */ | |
0650b554 | 27 | xfs_dablk_t datablk; /* blockno of dir data v2 */ |
545910bc | 28 | unsigned int leaf_hdr_size; /* dir2 leaf header size */ |
478c7835 | 29 | unsigned int leaf_max_ents; /* # of entries in dir2 leaf */ |
0650b554 | 30 | xfs_dablk_t leafblk; /* blockno of leaf data v2 */ |
ed1d612f | 31 | unsigned int free_hdr_size; /* dir2 free header size */ |
5893e4fe | 32 | unsigned int free_max_bests; /* # of bests entries in dir2 free */ |
0650b554 | 33 | xfs_dablk_t freeblk; /* blockno of free data v2 */ |
d73e1cee CH |
34 | |
35 | xfs_dir2_data_aoff_t data_first_offset; | |
36 | size_t data_entry_offset; | |
0650b554 DC |
37 | }; |
38 | ||
1da177e4 LT |
39 | /*======================================================================== |
40 | * Btree searching and modification structure definitions. | |
41 | *========================================================================*/ | |
42 | ||
5163f95a BN |
43 | /* |
44 | * Search comparison results | |
45 | */ | |
46 | enum xfs_dacmp { | |
47 | XFS_CMP_DIFFERENT, /* names are completely different */ | |
48 | XFS_CMP_EXACT, /* names are exactly the same */ | |
49 | XFS_CMP_CASE /* names are same but differ in case */ | |
50 | }; | |
51 | ||
1da177e4 LT |
52 | /* |
53 | * Structure to ease passing around component names. | |
54 | */ | |
55 | typedef struct xfs_da_args { | |
0650b554 | 56 | struct xfs_da_geometry *geo; /* da block geometry */ |
c8ce540d | 57 | const uint8_t *name; /* string (maybe not NULL terminated) */ |
1da177e4 | 58 | int namelen; /* length of string (maybe no NULL) */ |
c8ce540d | 59 | uint8_t filetype; /* filetype of inode for directories */ |
ead189ad | 60 | void *value; /* set of bytes (maybe contain NULLs) */ |
1da177e4 | 61 | int valuelen; /* length of value */ |
d5f0f49a CH |
62 | unsigned int attr_filter; /* XFS_ATTR_{ROOT,SECURE} */ |
63 | unsigned int attr_flags; /* XATTR_{CREATE,REPLACE} */ | |
1da177e4 LT |
64 | xfs_dahash_t hashval; /* hash value of name */ |
65 | xfs_ino_t inumber; /* input/output inode number */ | |
66 | struct xfs_inode *dp; /* directory inode to manipulate */ | |
1da177e4 LT |
67 | struct xfs_trans *trans; /* current trans (changes over time) */ |
68 | xfs_extlen_t total; /* total blocks needed, for 1st bmap */ | |
69 | int whichfork; /* data or attribute fork */ | |
70 | xfs_dablk_t blkno; /* blkno of attr leaf of interest */ | |
71 | int index; /* index of attr of interest in blk */ | |
72 | xfs_dablk_t rmtblkno; /* remote attr value starting blkno */ | |
73 | int rmtblkcnt; /* remote attr value block count */ | |
8275cdd0 | 74 | int rmtvaluelen; /* remote attr value length in bytes */ |
1da177e4 LT |
75 | xfs_dablk_t blkno2; /* blkno of 2nd attr leaf of interest */ |
76 | int index2; /* index of 2nd attr in blk */ | |
77 | xfs_dablk_t rmtblkno2; /* remote attr value starting blkno */ | |
78 | int rmtblkcnt2; /* remote attr value block count */ | |
8275cdd0 | 79 | int rmtvaluelen2; /* remote attr value length in bytes */ |
6a178100 | 80 | int op_flags; /* operation flags */ |
5163f95a | 81 | enum xfs_dacmp cmpresult; /* name compare result for lookups */ |
1da177e4 LT |
82 | } xfs_da_args_t; |
83 | ||
6a178100 BN |
84 | /* |
85 | * Operation flags: | |
86 | */ | |
87 | #define XFS_DA_OP_JUSTCHECK 0x0001 /* check for ok with no space */ | |
88 | #define XFS_DA_OP_RENAME 0x0002 /* this is an atomic rename op */ | |
89 | #define XFS_DA_OP_ADDNAME 0x0004 /* this is an add operation */ | |
90 | #define XFS_DA_OP_OKNOENT 0x0008 /* lookup/add op, ENOENT ok, else die */ | |
384f3ced | 91 | #define XFS_DA_OP_CILOOKUP 0x0010 /* lookup to return CI name if found */ |
1d733019 | 92 | #define XFS_DA_OP_NOTIME 0x0020 /* don't update inode timestamps */ |
780d2905 | 93 | #define XFS_DA_OP_INCOMPLETE 0x0040 /* lookup INCOMPLETE attr keys */ |
6a178100 | 94 | |
0b1b213f CH |
95 | #define XFS_DA_OP_FLAGS \ |
96 | { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \ | |
97 | { XFS_DA_OP_RENAME, "RENAME" }, \ | |
98 | { XFS_DA_OP_ADDNAME, "ADDNAME" }, \ | |
99 | { XFS_DA_OP_OKNOENT, "OKNOENT" }, \ | |
ddbca70c | 100 | { XFS_DA_OP_CILOOKUP, "CILOOKUP" }, \ |
1d733019 | 101 | { XFS_DA_OP_NOTIME, "NOTIME" }, \ |
780d2905 | 102 | { XFS_DA_OP_INCOMPLETE, "INCOMPLETE" } |
0b1b213f | 103 | |
1da177e4 LT |
104 | /* |
105 | * Storage for holding state during Btree searches and split/join ops. | |
106 | * | |
107 | * Only need space for 5 intermediate nodes. With a minimum of 62-way | |
108 | * fanout to the Btree, we can support over 900 million directory blocks, | |
109 | * which is slightly more than enough. | |
110 | */ | |
111 | typedef struct xfs_da_state_blk { | |
1d9025e5 | 112 | struct xfs_buf *bp; /* buffer containing block */ |
1da177e4 LT |
113 | xfs_dablk_t blkno; /* filesystem blkno of buffer */ |
114 | xfs_daddr_t disk_blkno; /* on-disk blkno (in BBs) of buffer */ | |
115 | int index; /* relevant index into block */ | |
116 | xfs_dahash_t hashval; /* last hash value in block */ | |
117 | int magic; /* blk's magic number, ie: blk type */ | |
118 | } xfs_da_state_blk_t; | |
119 | ||
120 | typedef struct xfs_da_state_path { | |
121 | int active; /* number of active levels */ | |
122 | xfs_da_state_blk_t blk[XFS_DA_NODE_MAXDEPTH]; | |
123 | } xfs_da_state_path_t; | |
124 | ||
125 | typedef struct xfs_da_state { | |
126 | xfs_da_args_t *args; /* filename arguments */ | |
127 | struct xfs_mount *mp; /* filesystem mount point */ | |
1da177e4 LT |
128 | xfs_da_state_path_t path; /* search/split paths */ |
129 | xfs_da_state_path_t altpath; /* alternate path for join */ | |
130 | unsigned char inleaf; /* insert into 1->lf, 0->splf */ | |
131 | unsigned char extravalid; /* T/F: extrablk is in use */ | |
132 | unsigned char extraafter; /* T/F: extrablk is after new */ | |
9da096fd | 133 | xfs_da_state_blk_t extrablk; /* for double-splits on leaves */ |
1da177e4 LT |
134 | /* for dirv2 extrablk is data */ |
135 | } xfs_da_state_t; | |
136 | ||
a39f089a CH |
137 | /* |
138 | * In-core version of the node header to abstract the differences in the v2 and | |
139 | * v3 disk format of the headers. Callers need to convert to/from disk format as | |
140 | * appropriate. | |
141 | */ | |
142 | struct xfs_da3_icnode_hdr { | |
143 | uint32_t forw; | |
144 | uint32_t back; | |
145 | uint16_t magic; | |
146 | uint16_t count; | |
147 | uint16_t level; | |
51908ca7 CH |
148 | |
149 | /* | |
150 | * Pointer to the on-disk format entries, which are behind the | |
151 | * variable size (v4 vs v5) header in the on-disk block. | |
152 | */ | |
153 | struct xfs_da_node_entry *btree; | |
a39f089a CH |
154 | }; |
155 | ||
1da177e4 LT |
156 | /* |
157 | * Utility macros to aid in logging changed structure fields. | |
158 | */ | |
159 | #define XFS_DA_LOGOFF(BASE, ADDR) ((char *)(ADDR) - (char *)(BASE)) | |
160 | #define XFS_DA_LOGRANGE(BASE, ADDR, SIZE) \ | |
161 | (uint)(XFS_DA_LOGOFF(BASE, ADDR)), \ | |
162 | (uint)(XFS_DA_LOGOFF(BASE, ADDR)+(SIZE)-1) | |
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, |
02c57f0a CH |
194 | xfs_dablk_t bno, struct xfs_buf **bpp, int whichfork); |
195 | int xfs_da3_node_read_mapped(struct xfs_trans *tp, struct xfs_inode *dp, | |
196 | xfs_daddr_t mappedbno, struct xfs_buf **bpp, | |
197 | int whichfork); | |
1da177e4 LT |
198 | |
199 | /* | |
200 | * Utility routines. | |
201 | */ | |
199e9ba4 CH |
202 | |
203 | #define XFS_DABUF_MAP_HOLE_OK (1 << 0) | |
204 | ||
1da177e4 | 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 | 208 | int xfs_da_get_buf(struct xfs_trans *trans, struct xfs_inode *dp, |
2911edb6 | 209 | xfs_dablk_t bno, struct xfs_buf **bp, int whichfork); |
1da177e4 | 210 | int xfs_da_read_buf(struct xfs_trans *trans, struct xfs_inode *dp, |
cd2c9f1b CH |
211 | xfs_dablk_t bno, unsigned int flags, struct xfs_buf **bpp, |
212 | int whichfork, const struct xfs_buf_ops *ops); | |
7a652bbe | 213 | int xfs_da_reada_buf(struct xfs_inode *dp, xfs_dablk_t bno, |
06566fda CH |
214 | unsigned int flags, int whichfork, |
215 | const struct xfs_buf_ops *ops); | |
1da177e4 | 216 | int xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno, |
1d9025e5 | 217 | struct xfs_buf *dead_buf); |
1da177e4 | 218 | |
c8ce540d | 219 | uint xfs_da_hashname(const uint8_t *name_string, int name_length); |
5163f95a | 220 | enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args, |
2bc75421 | 221 | const unsigned char *name, int len); |
5163f95a BN |
222 | |
223 | ||
1da177e4 LT |
224 | xfs_da_state_t *xfs_da_state_alloc(void); |
225 | void xfs_da_state_free(xfs_da_state_t *state); | |
1da177e4 | 226 | |
f475dc4d CH |
227 | void xfs_da3_node_hdr_from_disk(struct xfs_mount *mp, |
228 | struct xfs_da3_icnode_hdr *to, struct xfs_da_intnode *from); | |
e1c8af1e CH |
229 | void xfs_da3_node_hdr_to_disk(struct xfs_mount *mp, |
230 | struct xfs_da_intnode *to, struct xfs_da3_icnode_hdr *from); | |
f475dc4d | 231 | |
1da177e4 | 232 | extern struct kmem_zone *xfs_da_state_zone; |
1da177e4 LT |
233 | |
234 | #endif /* __XFS_DA_BTREE_H__ */ |