]>
Commit | Line | Data |
---|---|---|
37b3b4d6 | 1 | // SPDX-License-Identifier: GPL-2.0 |
2bd0ea18 | 2 | /* |
f302e9e4 | 3 | * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc. |
88b32f06 | 4 | * Copyright (c) 2013 Red Hat, Inc. |
f302e9e4 | 5 | * All Rights Reserved. |
2bd0ea18 NS |
6 | */ |
7 | #ifndef __XFS_DA_BTREE_H__ | |
dfc130f3 | 8 | #define __XFS_DA_BTREE_H__ |
2bd0ea18 | 9 | |
2bd0ea18 | 10 | struct xfs_inode; |
2bd0ea18 NS |
11 | struct xfs_trans; |
12 | struct zone; | |
ff105f75 DC |
13 | struct xfs_dir_ops; |
14 | ||
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 { | |
21 | int blksize; /* da block size in bytes */ | |
22 | int fsbcount; /* da block size in filesystem blocks */ | |
23 | uint8_t fsblog; /* log2 of _filesystem_ block size */ | |
24 | uint8_t blklog; /* log2 of da block size */ | |
25 | uint node_ents; /* # of entries in a danode */ | |
26 | int magicpct; /* 37% of block size in bytes */ | |
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 | }; | |
2bd0ea18 | 31 | |
2bd0ea18 NS |
32 | /*======================================================================== |
33 | * Btree searching and modification structure definitions. | |
34 | *========================================================================*/ | |
35 | ||
51ca7008 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 | ||
2bd0ea18 NS |
45 | /* |
46 | * Structure to ease passing around component names. | |
47 | */ | |
48 | typedef struct xfs_da_args { | |
ff105f75 | 49 | struct xfs_da_geometry *geo; /* da block geometry */ |
4a492e72 | 50 | const uint8_t *name; /* string (maybe not NULL terminated) */ |
2bd0ea18 | 51 | int namelen; /* length of string (maybe no NULL) */ |
4a492e72 DW |
52 | uint8_t filetype; /* filetype of inode for directories */ |
53 | uint8_t *value; /* set of bytes (maybe contain NULLs) */ | |
2bd0ea18 NS |
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 */ | |
2bd0ea18 NS |
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 */ | |
ff105f75 | 66 | int rmtvaluelen; /* remote attr value length in bytes */ |
2bd0ea18 NS |
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 */ | |
ff105f75 | 71 | int rmtvaluelen2; /* remote attr value length in bytes */ |
5e656dbb | 72 | int op_flags; /* operation flags */ |
51ca7008 | 73 | enum xfs_dacmp cmpresult; /* name compare result for lookups */ |
2bd0ea18 NS |
74 | } xfs_da_args_t; |
75 | ||
5e656dbb 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 */ | |
83 | #define XFS_DA_OP_CILOOKUP 0x0010 /* lookup to return CI name if found */ | |
84 | ||
56b2de80 DC |
85 | #define XFS_DA_OP_FLAGS \ |
86 | { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \ | |
87 | { XFS_DA_OP_RENAME, "RENAME" }, \ | |
88 | { XFS_DA_OP_ADDNAME, "ADDNAME" }, \ | |
89 | { XFS_DA_OP_OKNOENT, "OKNOENT" }, \ | |
90 | { XFS_DA_OP_CILOOKUP, "CILOOKUP" } | |
91 | ||
2bd0ea18 NS |
92 | /* |
93 | * Storage for holding state during Btree searches and split/join ops. | |
94 | * | |
95 | * Only need space for 5 intermediate nodes. With a minimum of 62-way | |
96 | * fanout to the Btree, we can support over 900 million directory blocks, | |
97 | * which is slightly more than enough. | |
98 | */ | |
99 | typedef struct xfs_da_state_blk { | |
a2ceac1f | 100 | struct xfs_buf *bp; /* buffer containing block */ |
2bd0ea18 | 101 | xfs_dablk_t blkno; /* filesystem blkno of buffer */ |
6bef826c | 102 | xfs_daddr_t disk_blkno; /* on-disk blkno (in BBs) of buffer */ |
2bd0ea18 NS |
103 | int index; /* relevant index into block */ |
104 | xfs_dahash_t hashval; /* last hash value in block */ | |
105 | int magic; /* blk's magic number, ie: blk type */ | |
106 | } xfs_da_state_blk_t; | |
107 | ||
108 | typedef struct xfs_da_state_path { | |
109 | int active; /* number of active levels */ | |
110 | xfs_da_state_blk_t blk[XFS_DA_NODE_MAXDEPTH]; | |
111 | } xfs_da_state_path_t; | |
112 | ||
113 | typedef struct xfs_da_state { | |
114 | xfs_da_args_t *args; /* filename arguments */ | |
115 | struct xfs_mount *mp; /* filesystem mount point */ | |
2bd0ea18 NS |
116 | xfs_da_state_path_t path; /* search/split paths */ |
117 | xfs_da_state_path_t altpath; /* alternate path for join */ | |
32a82561 NS |
118 | unsigned char inleaf; /* insert into 1->lf, 0->splf */ |
119 | unsigned char extravalid; /* T/F: extrablk is in use */ | |
120 | unsigned char extraafter; /* T/F: extrablk is after new */ | |
56b2de80 | 121 | xfs_da_state_blk_t extrablk; /* for double-splits on leaves */ |
2bd0ea18 NS |
122 | /* for dirv2 extrablk is data */ |
123 | } xfs_da_state_t; | |
124 | ||
125 | /* | |
126 | * Utility macros to aid in logging changed structure fields. | |
127 | */ | |
128 | #define XFS_DA_LOGOFF(BASE, ADDR) ((char *)(ADDR) - (char *)(BASE)) | |
129 | #define XFS_DA_LOGRANGE(BASE, ADDR, SIZE) \ | |
130 | (uint)(XFS_DA_LOGOFF(BASE, ADDR)), \ | |
131 | (uint)(XFS_DA_LOGOFF(BASE, ADDR)+(SIZE)-1) | |
132 | ||
51ca7008 BN |
133 | /* |
134 | * Name ops for directory and/or attr name operations | |
135 | */ | |
136 | struct xfs_nameops { | |
5e656dbb | 137 | xfs_dahash_t (*hashname)(struct xfs_name *); |
56b2de80 DC |
138 | enum xfs_dacmp (*compname)(struct xfs_da_args *, |
139 | const unsigned char *, int); | |
51ca7008 BN |
140 | }; |
141 | ||
836f654f | 142 | |
2bd0ea18 | 143 | /*======================================================================== |
5e656dbb | 144 | * Function prototypes. |
2bd0ea18 NS |
145 | *========================================================================*/ |
146 | ||
147 | /* | |
148 | * Routines used for growing the Btree. | |
149 | */ | |
88b32f06 DC |
150 | int xfs_da3_node_create(struct xfs_da_args *args, xfs_dablk_t blkno, |
151 | int level, struct xfs_buf **bpp, int whichfork); | |
152 | int xfs_da3_split(xfs_da_state_t *state); | |
2bd0ea18 NS |
153 | |
154 | /* | |
155 | * Routines used for shrinking the Btree. | |
156 | */ | |
88b32f06 DC |
157 | int xfs_da3_join(xfs_da_state_t *state); |
158 | void xfs_da3_fixhashpath(struct xfs_da_state *state, | |
159 | struct xfs_da_state_path *path_to_to_fix); | |
2bd0ea18 NS |
160 | |
161 | /* | |
162 | * Routines used for finding things in the Btree. | |
163 | */ | |
88b32f06 DC |
164 | int xfs_da3_node_lookup_int(xfs_da_state_t *state, int *result); |
165 | int xfs_da3_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path, | |
2bd0ea18 NS |
166 | int forward, int release, int *result); |
167 | /* | |
168 | * Utility routines. | |
169 | */ | |
88b32f06 | 170 | int xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk, |
2bd0ea18 | 171 | xfs_da_state_blk_t *new_blk); |
88b32f06 | 172 | int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp, |
a2ceac1f DC |
173 | xfs_dablk_t bno, xfs_daddr_t mappedbno, |
174 | struct xfs_buf **bpp, int which_fork); | |
2bd0ea18 NS |
175 | |
176 | /* | |
177 | * Utility routines. | |
178 | */ | |
179 | int xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno); | |
a2ceac1f DC |
180 | int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno, |
181 | int count); | |
2bd0ea18 NS |
182 | int xfs_da_get_buf(struct xfs_trans *trans, struct xfs_inode *dp, |
183 | xfs_dablk_t bno, xfs_daddr_t mappedbno, | |
a2ceac1f | 184 | struct xfs_buf **bp, int whichfork); |
2bd0ea18 NS |
185 | int xfs_da_read_buf(struct xfs_trans *trans, struct xfs_inode *dp, |
186 | xfs_dablk_t bno, xfs_daddr_t mappedbno, | |
a2ceac1f DC |
187 | struct xfs_buf **bpp, int whichfork, |
188 | const struct xfs_buf_ops *ops); | |
3a65062f | 189 | int xfs_da_reada_buf(struct xfs_inode *dp, xfs_dablk_t bno, |
ff105f75 DC |
190 | xfs_daddr_t mapped_bno, int whichfork, |
191 | const struct xfs_buf_ops *ops); | |
2bd0ea18 | 192 | int xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno, |
a2ceac1f | 193 | struct xfs_buf *dead_buf); |
2bd0ea18 | 194 | |
4a492e72 | 195 | uint xfs_da_hashname(const uint8_t *name_string, int name_length); |
5e656dbb | 196 | enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args, |
56b2de80 | 197 | const unsigned char *name, int len); |
5e656dbb | 198 | |
51ca7008 | 199 | |
2bd0ea18 NS |
200 | xfs_da_state_t *xfs_da_state_alloc(void); |
201 | void xfs_da_state_free(xfs_da_state_t *state); | |
2bd0ea18 | 202 | |
836f654f | 203 | extern struct kmem_zone *xfs_da_state_zone; |
56b2de80 | 204 | extern const struct xfs_nameops xfs_default_nameops; |
2bd0ea18 NS |
205 | |
206 | #endif /* __XFS_DA_BTREE_H__ */ |