blob: 6e95ea79f5d73aa2447fc49eb0e4c7e9bb73a25d [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070022struct xfs_bmap_free;
23struct 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
28/*========================================================================
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 * Btree searching and modification structure definitions.
30 *========================================================================*/
31
32/*
Barry Naujok5163f952008-05-21 16:41:01 +100033 * Search comparison results
34 */
35enum xfs_dacmp {
36 XFS_CMP_DIFFERENT, /* names are completely different */
37 XFS_CMP_EXACT, /* names are exactly the same */
38 XFS_CMP_CASE /* names are same but differ in case */
39};
40
41/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 * Structure to ease passing around component names.
43 */
44typedef struct xfs_da_args {
Christoph Hellwiga5687782009-02-09 08:37:39 +010045 const __uint8_t *name; /* string (maybe not NULL terminated) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 int namelen; /* length of string (maybe no NULL) */
Dave Chinner0cb97762013-08-12 20:50:09 +100047 __uint8_t filetype; /* filetype of inode for directories */
Christoph Hellwiga5687782009-02-09 08:37:39 +010048 __uint8_t *value; /* set of bytes (maybe contain NULLs) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 int valuelen; /* length of value */
50 int flags; /* argument flags (eg: ATTR_NOCREATE) */
51 xfs_dahash_t hashval; /* hash value of name */
52 xfs_ino_t inumber; /* input/output inode number */
53 struct xfs_inode *dp; /* directory inode to manipulate */
54 xfs_fsblock_t *firstblock; /* ptr to firstblock for bmap calls */
55 struct xfs_bmap_free *flist; /* ptr to freelist for bmap_finish */
56 struct xfs_trans *trans; /* current trans (changes over time) */
57 xfs_extlen_t total; /* total blocks needed, for 1st bmap */
58 int whichfork; /* data or attribute fork */
59 xfs_dablk_t blkno; /* blkno of attr leaf of interest */
60 int index; /* index of attr of interest in blk */
61 xfs_dablk_t rmtblkno; /* remote attr value starting blkno */
62 int rmtblkcnt; /* remote attr value block count */
63 xfs_dablk_t blkno2; /* blkno of 2nd attr leaf of interest */
64 int index2; /* index of 2nd attr in blk */
65 xfs_dablk_t rmtblkno2; /* remote attr value starting blkno */
66 int rmtblkcnt2; /* remote attr value block count */
Barry Naujok6a178102008-05-21 16:42:05 +100067 int op_flags; /* operation flags */
Barry Naujok5163f952008-05-21 16:41:01 +100068 enum xfs_dacmp cmpresult; /* name compare result for lookups */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069} xfs_da_args_t;
70
71/*
Barry Naujok6a178102008-05-21 16:42:05 +100072 * Operation flags:
73 */
74#define XFS_DA_OP_JUSTCHECK 0x0001 /* check for ok with no space */
75#define XFS_DA_OP_RENAME 0x0002 /* this is an atomic rename op */
76#define XFS_DA_OP_ADDNAME 0x0004 /* this is an add operation */
77#define XFS_DA_OP_OKNOENT 0x0008 /* lookup/add op, ENOENT ok, else die */
Barry Naujok384f3ce2008-05-21 16:58:22 +100078#define XFS_DA_OP_CILOOKUP 0x0010 /* lookup to return CI name if found */
Barry Naujok6a178102008-05-21 16:42:05 +100079
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000080#define XFS_DA_OP_FLAGS \
81 { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \
82 { XFS_DA_OP_RENAME, "RENAME" }, \
83 { XFS_DA_OP_ADDNAME, "ADDNAME" }, \
84 { XFS_DA_OP_OKNOENT, "OKNOENT" }, \
85 { XFS_DA_OP_CILOOKUP, "CILOOKUP" }
86
Barry Naujok6a178102008-05-21 16:42:05 +100087/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 * Storage for holding state during Btree searches and split/join ops.
89 *
90 * Only need space for 5 intermediate nodes. With a minimum of 62-way
91 * fanout to the Btree, we can support over 900 million directory blocks,
92 * which is slightly more than enough.
93 */
94typedef struct xfs_da_state_blk {
Dave Chinner1d9025e2012-06-22 18:50:14 +100095 struct xfs_buf *bp; /* buffer containing block */
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 xfs_dablk_t blkno; /* filesystem blkno of buffer */
97 xfs_daddr_t disk_blkno; /* on-disk blkno (in BBs) of buffer */
98 int index; /* relevant index into block */
99 xfs_dahash_t hashval; /* last hash value in block */
100 int magic; /* blk's magic number, ie: blk type */
101} xfs_da_state_blk_t;
102
103typedef struct xfs_da_state_path {
104 int active; /* number of active levels */
105 xfs_da_state_blk_t blk[XFS_DA_NODE_MAXDEPTH];
106} xfs_da_state_path_t;
107
108typedef struct xfs_da_state {
109 xfs_da_args_t *args; /* filename arguments */
110 struct xfs_mount *mp; /* filesystem mount point */
111 unsigned int blocksize; /* logical block size */
112 unsigned int node_ents; /* how many entries in danode */
113 xfs_da_state_path_t path; /* search/split paths */
114 xfs_da_state_path_t altpath; /* alternate path for join */
115 unsigned char inleaf; /* insert into 1->lf, 0->splf */
116 unsigned char extravalid; /* T/F: extrablk is in use */
117 unsigned char extraafter; /* T/F: extrablk is after new */
Malcolm Parsons9da096f2009-03-29 09:55:42 +0200118 xfs_da_state_blk_t extrablk; /* for double-splits on leaves */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 /* for dirv2 extrablk is data */
120} xfs_da_state_t;
121
122/*
123 * Utility macros to aid in logging changed structure fields.
124 */
125#define XFS_DA_LOGOFF(BASE, ADDR) ((char *)(ADDR) - (char *)(BASE))
126#define XFS_DA_LOGRANGE(BASE, ADDR, SIZE) \
127 (uint)(XFS_DA_LOGOFF(BASE, ADDR)), \
128 (uint)(XFS_DA_LOGOFF(BASE, ADDR)+(SIZE)-1)
129
Barry Naujok5163f952008-05-21 16:41:01 +1000130/*
131 * Name ops for directory and/or attr name operations
132 */
133struct xfs_nameops {
134 xfs_dahash_t (*hashname)(struct xfs_name *);
Dave Chinner2bc75422010-01-20 10:47:17 +1100135 enum xfs_dacmp (*compname)(struct xfs_da_args *,
136 const unsigned char *, int);
Barry Naujok5163f952008-05-21 16:41:01 +1000137};
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140/*========================================================================
Barry Naujok847fff52008-10-30 17:05:38 +1100141 * Function prototypes.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 *========================================================================*/
143
144/*
145 * Routines used for growing the Btree.
146 */
Dave Chinnerf5ea1102013-04-24 18:58:02 +1000147int xfs_da3_node_create(struct xfs_da_args *args, xfs_dablk_t blkno,
148 int level, struct xfs_buf **bpp, int whichfork);
149int xfs_da3_split(xfs_da_state_t *state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151/*
152 * Routines used for shrinking the Btree.
153 */
Dave Chinnerf5ea1102013-04-24 18:58:02 +1000154int xfs_da3_join(xfs_da_state_t *state);
155void xfs_da3_fixhashpath(struct xfs_da_state *state,
156 struct xfs_da_state_path *path_to_to_fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158/*
159 * Routines used for finding things in the Btree.
160 */
Dave Chinnerf5ea1102013-04-24 18:58:02 +1000161int xfs_da3_node_lookup_int(xfs_da_state_t *state, int *result);
162int xfs_da3_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 int forward, int release, int *result);
164/*
165 * Utility routines.
166 */
Dave Chinnerf5ea1102013-04-24 18:58:02 +1000167int xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 xfs_da_state_blk_t *new_blk);
Dave Chinnerf5ea1102013-04-24 18:58:02 +1000169int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp,
Dave Chinnerd9392a42012-11-12 22:54:17 +1100170 xfs_dablk_t bno, xfs_daddr_t mappedbno,
171 struct xfs_buf **bpp, int which_fork);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173/*
174 * Utility routines.
175 */
176int xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno);
Christoph Hellwig77936d02011-07-13 13:43:49 +0200177int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno,
178 int count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179int xfs_da_get_buf(struct xfs_trans *trans, struct xfs_inode *dp,
180 xfs_dablk_t bno, xfs_daddr_t mappedbno,
Dave Chinner1d9025e2012-06-22 18:50:14 +1000181 struct xfs_buf **bp, int whichfork);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182int xfs_da_read_buf(struct xfs_trans *trans, struct xfs_inode *dp,
183 xfs_dablk_t bno, xfs_daddr_t mappedbno,
Dave Chinner4bb20a82012-11-12 22:54:10 +1100184 struct xfs_buf **bpp, int whichfork,
Dave Chinner1813dd62012-11-14 17:54:40 +1100185 const struct xfs_buf_ops *ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186xfs_daddr_t xfs_da_reada_buf(struct xfs_trans *trans, struct xfs_inode *dp,
Dave Chinnerda6958c2012-11-12 22:54:18 +1100187 xfs_dablk_t bno, xfs_daddr_t mapped_bno,
Dave Chinner1813dd62012-11-14 17:54:40 +1100188 int whichfork, const struct xfs_buf_ops *ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189int xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno,
Dave Chinner1d9025e2012-06-22 18:50:14 +1000190 struct xfs_buf *dead_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Christoph Hellwiga5687782009-02-09 08:37:39 +0100192uint xfs_da_hashname(const __uint8_t *name_string, int name_length);
Barry Naujok5163f952008-05-21 16:41:01 +1000193enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args,
Dave Chinner2bc75422010-01-20 10:47:17 +1100194 const unsigned char *name, int len);
Barry Naujok5163f952008-05-21 16:41:01 +1000195
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197xfs_da_state_t *xfs_da_state_alloc(void);
198void xfs_da_state_free(xfs_da_state_t *state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200extern struct kmem_zone *xfs_da_state_zone;
Hannes Eder24418492009-03-04 19:33:48 +0100201extern const struct xfs_nameops xfs_default_nameops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203#endif /* __XFS_DA_BTREE_H__ */