blob: 98c75cbe6ac2ec6063bf381cead3cea002a87dff [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
Dave Chinnerf5ea1102013-04-24 18:58:02 +10003 * Copyright (c) 2013 Red Hat, Inc.
Nathan Scott7b718762005-11-02 14:58:39 +11004 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Nathan Scott7b718762005-11-02 14:58:39 +11006 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * published by the Free Software Foundation.
9 *
Nathan Scott7b718762005-11-02 14:58:39 +110010 * This program is distributed in the hope that it would be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 *
Nathan Scott7b718762005-11-02 14:58:39 +110015 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 */
19#ifndef __XFS_DA_BTREE_H__
20#define __XFS_DA_BTREE_H__
21
Darrick J. Wong310a75a2016-08-03 11:18:10 +100022struct xfs_defer_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070023struct xfs_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024struct xfs_trans;
25struct zone;
Dave Chinner32c54832013-10-29 22:11:46 +110026struct xfs_dir_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Dave Chinner0650b552014-06-06 15:01:58 +100028/*
29 * Directory/attribute geometry information. There will be one of these for each
30 * data fork type, and it will be passed around via the xfs_da_args. Global
31 * structures will be attached to the xfs_mount.
32 */
33struct xfs_da_geometry {
34 int blksize; /* da block size in bytes */
35 int fsbcount; /* da block size in filesystem blocks */
36 uint8_t fsblog; /* log2 of _filesystem_ block size */
37 uint8_t blklog; /* log2 of da block size */
38 uint node_ents; /* # of entries in a danode */
39 int magicpct; /* 37% of block size in bytes */
40 xfs_dablk_t datablk; /* blockno of dir data v2 */
41 xfs_dablk_t leafblk; /* blockno of leaf data v2 */
42 xfs_dablk_t freeblk; /* blockno of free data v2 */
43};
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/*========================================================================
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 * Btree searching and modification structure definitions.
47 *========================================================================*/
48
49/*
Barry Naujok5163f952008-05-21 16:41:01 +100050 * Search comparison results
51 */
52enum xfs_dacmp {
53 XFS_CMP_DIFFERENT, /* names are completely different */
54 XFS_CMP_EXACT, /* names are exactly the same */
55 XFS_CMP_CASE /* names are same but differ in case */
56};
57
58/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 * Structure to ease passing around component names.
60 */
61typedef struct xfs_da_args {
Dave Chinner0650b552014-06-06 15:01:58 +100062 struct xfs_da_geometry *geo; /* da block geometry */
Christoph Hellwiga5687782009-02-09 08:37:39 +010063 const __uint8_t *name; /* string (maybe not NULL terminated) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 int namelen; /* length of string (maybe no NULL) */
Dave Chinner0cb97762013-08-12 20:50:09 +100065 __uint8_t filetype; /* filetype of inode for directories */
Christoph Hellwiga5687782009-02-09 08:37:39 +010066 __uint8_t *value; /* set of bytes (maybe contain NULLs) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 int valuelen; /* length of value */
68 int flags; /* argument flags (eg: ATTR_NOCREATE) */
69 xfs_dahash_t hashval; /* hash value of name */
70 xfs_ino_t inumber; /* input/output inode number */
71 struct xfs_inode *dp; /* directory inode to manipulate */
72 xfs_fsblock_t *firstblock; /* ptr to firstblock for bmap calls */
Darrick J. Wong2c3234d2016-08-03 11:19:29 +100073 struct xfs_defer_ops *dfops; /* ptr to freelist for bmap_finish */
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 struct xfs_trans *trans; /* current trans (changes over time) */
75 xfs_extlen_t total; /* total blocks needed, for 1st bmap */
76 int whichfork; /* data or attribute fork */
77 xfs_dablk_t blkno; /* blkno of attr leaf of interest */
78 int index; /* index of attr of interest in blk */
79 xfs_dablk_t rmtblkno; /* remote attr value starting blkno */
80 int rmtblkcnt; /* remote attr value block count */
Dave Chinner8275cdd2014-05-06 07:37:31 +100081 int rmtvaluelen; /* remote attr value length in bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 xfs_dablk_t blkno2; /* blkno of 2nd attr leaf of interest */
83 int index2; /* index of 2nd attr in blk */
84 xfs_dablk_t rmtblkno2; /* remote attr value starting blkno */
85 int rmtblkcnt2; /* remote attr value block count */
Dave Chinner8275cdd2014-05-06 07:37:31 +100086 int rmtvaluelen2; /* remote attr value length in bytes */
Barry Naujok6a178102008-05-21 16:42:05 +100087 int op_flags; /* operation flags */
Barry Naujok5163f952008-05-21 16:41:01 +100088 enum xfs_dacmp cmpresult; /* name compare result for lookups */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089} xfs_da_args_t;
90
91/*
Barry Naujok6a178102008-05-21 16:42:05 +100092 * Operation flags:
93 */
94#define XFS_DA_OP_JUSTCHECK 0x0001 /* check for ok with no space */
95#define XFS_DA_OP_RENAME 0x0002 /* this is an atomic rename op */
96#define XFS_DA_OP_ADDNAME 0x0004 /* this is an add operation */
97#define XFS_DA_OP_OKNOENT 0x0008 /* lookup/add op, ENOENT ok, else die */
Barry Naujok384f3ce2008-05-21 16:58:22 +100098#define XFS_DA_OP_CILOOKUP 0x0010 /* lookup to return CI name if found */
Barry Naujok6a178102008-05-21 16:42:05 +100099
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000100#define XFS_DA_OP_FLAGS \
101 { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \
102 { XFS_DA_OP_RENAME, "RENAME" }, \
103 { XFS_DA_OP_ADDNAME, "ADDNAME" }, \
104 { XFS_DA_OP_OKNOENT, "OKNOENT" }, \
105 { XFS_DA_OP_CILOOKUP, "CILOOKUP" }
106
Barry Naujok6a178102008-05-21 16:42:05 +1000107/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 * Storage for holding state during Btree searches and split/join ops.
109 *
110 * Only need space for 5 intermediate nodes. With a minimum of 62-way
111 * fanout to the Btree, we can support over 900 million directory blocks,
112 * which is slightly more than enough.
113 */
114typedef struct xfs_da_state_blk {
Dave Chinner1d9025e2012-06-22 18:50:14 +1000115 struct xfs_buf *bp; /* buffer containing block */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 xfs_dablk_t blkno; /* filesystem blkno of buffer */
117 xfs_daddr_t disk_blkno; /* on-disk blkno (in BBs) of buffer */
118 int index; /* relevant index into block */
119 xfs_dahash_t hashval; /* last hash value in block */
120 int magic; /* blk's magic number, ie: blk type */
121} xfs_da_state_blk_t;
122
123typedef struct xfs_da_state_path {
124 int active; /* number of active levels */
125 xfs_da_state_blk_t blk[XFS_DA_NODE_MAXDEPTH];
126} xfs_da_state_path_t;
127
128typedef struct xfs_da_state {
129 xfs_da_args_t *args; /* filename arguments */
130 struct xfs_mount *mp; /* filesystem mount point */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 xfs_da_state_path_t path; /* search/split paths */
132 xfs_da_state_path_t altpath; /* alternate path for join */
133 unsigned char inleaf; /* insert into 1->lf, 0->splf */
134 unsigned char extravalid; /* T/F: extrablk is in use */
135 unsigned char extraafter; /* T/F: extrablk is after new */
Malcolm Parsons9da096f2009-03-29 09:55:42 +0200136 xfs_da_state_blk_t extrablk; /* for double-splits on leaves */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 /* for dirv2 extrablk is data */
138} xfs_da_state_t;
139
140/*
141 * Utility macros to aid in logging changed structure fields.
142 */
143#define XFS_DA_LOGOFF(BASE, ADDR) ((char *)(ADDR) - (char *)(BASE))
144#define XFS_DA_LOGRANGE(BASE, ADDR, SIZE) \
145 (uint)(XFS_DA_LOGOFF(BASE, ADDR)), \
146 (uint)(XFS_DA_LOGOFF(BASE, ADDR)+(SIZE)-1)
147
Barry Naujok5163f952008-05-21 16:41:01 +1000148/*
149 * Name ops for directory and/or attr name operations
150 */
151struct xfs_nameops {
152 xfs_dahash_t (*hashname)(struct xfs_name *);
Dave Chinner2bc75422010-01-20 10:47:17 +1100153 enum xfs_dacmp (*compname)(struct xfs_da_args *,
154 const unsigned char *, int);
Barry Naujok5163f952008-05-21 16:41:01 +1000155};
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158/*========================================================================
Barry Naujok847fff52008-10-30 17:05:38 +1100159 * Function prototypes.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 *========================================================================*/
161
162/*
163 * Routines used for growing the Btree.
164 */
Dave Chinnerf5ea1102013-04-24 18:58:02 +1000165int xfs_da3_node_create(struct xfs_da_args *args, xfs_dablk_t blkno,
166 int level, struct xfs_buf **bpp, int whichfork);
167int xfs_da3_split(xfs_da_state_t *state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169/*
170 * Routines used for shrinking the Btree.
171 */
Dave Chinnerf5ea1102013-04-24 18:58:02 +1000172int xfs_da3_join(xfs_da_state_t *state);
173void xfs_da3_fixhashpath(struct xfs_da_state *state,
174 struct xfs_da_state_path *path_to_to_fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176/*
177 * Routines used for finding things in the Btree.
178 */
Dave Chinnerf5ea1102013-04-24 18:58:02 +1000179int xfs_da3_node_lookup_int(xfs_da_state_t *state, int *result);
180int xfs_da3_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 int forward, int release, int *result);
182/*
183 * Utility routines.
184 */
Dave Chinnerf5ea1102013-04-24 18:58:02 +1000185int xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 xfs_da_state_blk_t *new_blk);
Dave Chinnerf5ea1102013-04-24 18:58:02 +1000187int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp,
Dave Chinnerd9392a42012-11-12 22:54:17 +1100188 xfs_dablk_t bno, xfs_daddr_t mappedbno,
189 struct xfs_buf **bpp, int which_fork);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191/*
192 * Utility routines.
193 */
194int xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno);
Christoph Hellwig77936d02011-07-13 13:43:49 +0200195int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno,
196 int count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197int xfs_da_get_buf(struct xfs_trans *trans, struct xfs_inode *dp,
198 xfs_dablk_t bno, xfs_daddr_t mappedbno,
Dave Chinner1d9025e2012-06-22 18:50:14 +1000199 struct xfs_buf **bp, int whichfork);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200int xfs_da_read_buf(struct xfs_trans *trans, struct xfs_inode *dp,
201 xfs_dablk_t bno, xfs_daddr_t mappedbno,
Dave Chinner4bb20a82012-11-12 22:54:10 +1100202 struct xfs_buf **bpp, int whichfork,
Dave Chinner1813dd62012-11-14 17:54:40 +1100203 const struct xfs_buf_ops *ops);
Eric Sandeen9df2dd02014-04-14 19:01:59 +1000204xfs_daddr_t xfs_da_reada_buf(struct xfs_inode *dp, xfs_dablk_t bno,
205 xfs_daddr_t mapped_bno, int whichfork,
206 const struct xfs_buf_ops *ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207int xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno,
Dave Chinner1d9025e2012-06-22 18:50:14 +1000208 struct xfs_buf *dead_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Christoph Hellwiga5687782009-02-09 08:37:39 +0100210uint xfs_da_hashname(const __uint8_t *name_string, int name_length);
Barry Naujok5163f952008-05-21 16:41:01 +1000211enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args,
Dave Chinner2bc75422010-01-20 10:47:17 +1100212 const unsigned char *name, int len);
Barry Naujok5163f952008-05-21 16:41:01 +1000213
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215xfs_da_state_t *xfs_da_state_alloc(void);
216void xfs_da_state_free(xfs_da_state_t *state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218extern struct kmem_zone *xfs_da_state_zone;
Hannes Eder24418492009-03-04 19:33:48 +0100219extern const struct xfs_nameops xfs_default_nameops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221#endif /* __XFS_DA_BTREE_H__ */