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