Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
7b718769 | 2 | * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc. |
f5ea1100 | 3 | * Copyright (c) 2013 Red Hat, Inc. |
7b718769 | 4 | * All Rights Reserved. |
1da177e4 | 5 | * |
7b718769 NS |
6 | * This program is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU General Public License as | |
1da177e4 LT |
8 | * published by the Free Software Foundation. |
9 | * | |
7b718769 NS |
10 | * 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. | |
1da177e4 | 14 | * |
7b718769 NS |
15 | * 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 | |
1da177e4 LT |
18 | */ |
19 | #ifndef __XFS_DA_BTREE_H__ | |
20 | #define __XFS_DA_BTREE_H__ | |
21 | ||
1da177e4 LT |
22 | struct xfs_bmap_free; |
23 | struct xfs_inode; | |
1da177e4 LT |
24 | struct xfs_trans; |
25 | struct zone; | |
26 | ||
1da177e4 LT |
27 | /*======================================================================== |
28 | * Btree searching and modification structure definitions. | |
29 | *========================================================================*/ | |
30 | ||
5163f95a BN |
31 | /* |
32 | * Search comparison results | |
33 | */ | |
34 | enum xfs_dacmp { | |
35 | XFS_CMP_DIFFERENT, /* names are completely different */ | |
36 | XFS_CMP_EXACT, /* names are exactly the same */ | |
37 | XFS_CMP_CASE /* names are same but differ in case */ | |
38 | }; | |
39 | ||
1da177e4 LT |
40 | /* |
41 | * Structure to ease passing around component names. | |
42 | */ | |
43 | typedef struct xfs_da_args { | |
a5687787 | 44 | const __uint8_t *name; /* string (maybe not NULL terminated) */ |
1da177e4 | 45 | int namelen; /* length of string (maybe no NULL) */ |
0cb97766 | 46 | __uint8_t filetype; /* filetype of inode for directories */ |
a5687787 | 47 | __uint8_t *value; /* set of bytes (maybe contain NULLs) */ |
1da177e4 LT |
48 | int valuelen; /* length of value */ |
49 | int flags; /* argument flags (eg: ATTR_NOCREATE) */ | |
50 | xfs_dahash_t hashval; /* hash value of name */ | |
51 | xfs_ino_t inumber; /* input/output inode number */ | |
52 | struct xfs_inode *dp; /* directory inode to manipulate */ | |
53 | xfs_fsblock_t *firstblock; /* ptr to firstblock for bmap calls */ | |
54 | struct xfs_bmap_free *flist; /* ptr to freelist for bmap_finish */ | |
55 | struct xfs_trans *trans; /* current trans (changes over time) */ | |
56 | xfs_extlen_t total; /* total blocks needed, for 1st bmap */ | |
57 | int whichfork; /* data or attribute fork */ | |
58 | xfs_dablk_t blkno; /* blkno of attr leaf of interest */ | |
59 | int index; /* index of attr of interest in blk */ | |
60 | xfs_dablk_t rmtblkno; /* remote attr value starting blkno */ | |
61 | int rmtblkcnt; /* remote attr value block count */ | |
62 | xfs_dablk_t blkno2; /* blkno of 2nd attr leaf of interest */ | |
63 | int index2; /* index of 2nd attr in blk */ | |
64 | xfs_dablk_t rmtblkno2; /* remote attr value starting blkno */ | |
65 | int rmtblkcnt2; /* remote attr value block count */ | |
6a178100 | 66 | int op_flags; /* operation flags */ |
5163f95a | 67 | enum xfs_dacmp cmpresult; /* name compare result for lookups */ |
1da177e4 LT |
68 | } xfs_da_args_t; |
69 | ||
6a178100 BN |
70 | /* |
71 | * Operation flags: | |
72 | */ | |
73 | #define XFS_DA_OP_JUSTCHECK 0x0001 /* check for ok with no space */ | |
74 | #define XFS_DA_OP_RENAME 0x0002 /* this is an atomic rename op */ | |
75 | #define XFS_DA_OP_ADDNAME 0x0004 /* this is an add operation */ | |
76 | #define XFS_DA_OP_OKNOENT 0x0008 /* lookup/add op, ENOENT ok, else die */ | |
384f3ced | 77 | #define XFS_DA_OP_CILOOKUP 0x0010 /* lookup to return CI name if found */ |
6a178100 | 78 | |
0b1b213f CH |
79 | #define XFS_DA_OP_FLAGS \ |
80 | { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \ | |
81 | { XFS_DA_OP_RENAME, "RENAME" }, \ | |
82 | { XFS_DA_OP_ADDNAME, "ADDNAME" }, \ | |
83 | { XFS_DA_OP_OKNOENT, "OKNOENT" }, \ | |
84 | { XFS_DA_OP_CILOOKUP, "CILOOKUP" } | |
85 | ||
1da177e4 LT |
86 | /* |
87 | * Storage for holding state during Btree searches and split/join ops. | |
88 | * | |
89 | * Only need space for 5 intermediate nodes. With a minimum of 62-way | |
90 | * fanout to the Btree, we can support over 900 million directory blocks, | |
91 | * which is slightly more than enough. | |
92 | */ | |
93 | typedef struct xfs_da_state_blk { | |
1d9025e5 | 94 | struct xfs_buf *bp; /* buffer containing block */ |
1da177e4 LT |
95 | xfs_dablk_t blkno; /* filesystem blkno of buffer */ |
96 | xfs_daddr_t disk_blkno; /* on-disk blkno (in BBs) of buffer */ | |
97 | int index; /* relevant index into block */ | |
98 | xfs_dahash_t hashval; /* last hash value in block */ | |
99 | int magic; /* blk's magic number, ie: blk type */ | |
100 | } xfs_da_state_blk_t; | |
101 | ||
102 | typedef struct xfs_da_state_path { | |
103 | int active; /* number of active levels */ | |
104 | xfs_da_state_blk_t blk[XFS_DA_NODE_MAXDEPTH]; | |
105 | } xfs_da_state_path_t; | |
106 | ||
107 | typedef struct xfs_da_state { | |
108 | xfs_da_args_t *args; /* filename arguments */ | |
109 | struct xfs_mount *mp; /* filesystem mount point */ | |
110 | unsigned int blocksize; /* logical block size */ | |
111 | unsigned int node_ents; /* how many entries in danode */ | |
112 | xfs_da_state_path_t path; /* search/split paths */ | |
113 | xfs_da_state_path_t altpath; /* alternate path for join */ | |
114 | unsigned char inleaf; /* insert into 1->lf, 0->splf */ | |
115 | unsigned char extravalid; /* T/F: extrablk is in use */ | |
116 | unsigned char extraafter; /* T/F: extrablk is after new */ | |
9da096fd | 117 | xfs_da_state_blk_t extrablk; /* for double-splits on leaves */ |
1da177e4 LT |
118 | /* for dirv2 extrablk is data */ |
119 | } xfs_da_state_t; | |
120 | ||
121 | /* | |
122 | * Utility macros to aid in logging changed structure fields. | |
123 | */ | |
124 | #define XFS_DA_LOGOFF(BASE, ADDR) ((char *)(ADDR) - (char *)(BASE)) | |
125 | #define XFS_DA_LOGRANGE(BASE, ADDR, SIZE) \ | |
126 | (uint)(XFS_DA_LOGOFF(BASE, ADDR)), \ | |
127 | (uint)(XFS_DA_LOGOFF(BASE, ADDR)+(SIZE)-1) | |
128 | ||
5163f95a BN |
129 | /* |
130 | * Name ops for directory and/or attr name operations | |
131 | */ | |
132 | struct xfs_nameops { | |
133 | xfs_dahash_t (*hashname)(struct xfs_name *); | |
2bc75421 DC |
134 | enum xfs_dacmp (*compname)(struct xfs_da_args *, |
135 | const unsigned char *, int); | |
5163f95a BN |
136 | }; |
137 | ||
1da177e4 | 138 | |
1da177e4 | 139 | /*======================================================================== |
847fff5c | 140 | * Function prototypes. |
1da177e4 LT |
141 | *========================================================================*/ |
142 | ||
143 | /* | |
144 | * Routines used for growing the Btree. | |
145 | */ | |
f5ea1100 DC |
146 | int xfs_da3_node_create(struct xfs_da_args *args, xfs_dablk_t blkno, |
147 | int level, struct xfs_buf **bpp, int whichfork); | |
148 | int xfs_da3_split(xfs_da_state_t *state); | |
1da177e4 LT |
149 | |
150 | /* | |
151 | * Routines used for shrinking the Btree. | |
152 | */ | |
f5ea1100 DC |
153 | int xfs_da3_join(xfs_da_state_t *state); |
154 | void xfs_da3_fixhashpath(struct xfs_da_state *state, | |
155 | struct xfs_da_state_path *path_to_to_fix); | |
1da177e4 LT |
156 | |
157 | /* | |
158 | * Routines used for finding things in the Btree. | |
159 | */ | |
f5ea1100 DC |
160 | int xfs_da3_node_lookup_int(xfs_da_state_t *state, int *result); |
161 | int xfs_da3_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path, | |
1da177e4 LT |
162 | int forward, int release, int *result); |
163 | /* | |
164 | * Utility routines. | |
165 | */ | |
f5ea1100 | 166 | int xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk, |
1da177e4 | 167 | xfs_da_state_blk_t *new_blk); |
f5ea1100 | 168 | int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp, |
d9392a4b DC |
169 | xfs_dablk_t bno, xfs_daddr_t mappedbno, |
170 | struct xfs_buf **bpp, int which_fork); | |
1da177e4 LT |
171 | |
172 | /* | |
173 | * Utility routines. | |
174 | */ | |
175 | int xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno); | |
77936d02 CH |
176 | int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno, |
177 | int count); | |
1da177e4 LT |
178 | int xfs_da_get_buf(struct xfs_trans *trans, struct xfs_inode *dp, |
179 | xfs_dablk_t bno, xfs_daddr_t mappedbno, | |
1d9025e5 | 180 | struct xfs_buf **bp, int whichfork); |
1da177e4 LT |
181 | int xfs_da_read_buf(struct xfs_trans *trans, struct xfs_inode *dp, |
182 | xfs_dablk_t bno, xfs_daddr_t mappedbno, | |
4bb20a83 | 183 | struct xfs_buf **bpp, int whichfork, |
1813dd64 | 184 | const struct xfs_buf_ops *ops); |
1da177e4 | 185 | xfs_daddr_t xfs_da_reada_buf(struct xfs_trans *trans, struct xfs_inode *dp, |
da6958c8 | 186 | xfs_dablk_t bno, xfs_daddr_t mapped_bno, |
1813dd64 | 187 | int whichfork, const struct xfs_buf_ops *ops); |
1da177e4 | 188 | int xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno, |
1d9025e5 | 189 | struct xfs_buf *dead_buf); |
1da177e4 | 190 | |
a5687787 | 191 | uint xfs_da_hashname(const __uint8_t *name_string, int name_length); |
5163f95a | 192 | enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args, |
2bc75421 | 193 | const unsigned char *name, int len); |
5163f95a BN |
194 | |
195 | ||
1da177e4 LT |
196 | xfs_da_state_t *xfs_da_state_alloc(void); |
197 | void xfs_da_state_free(xfs_da_state_t *state); | |
1da177e4 | 198 | |
1da177e4 | 199 | extern struct kmem_zone *xfs_da_state_zone; |
24418492 | 200 | extern const struct xfs_nameops xfs_default_nameops; |
1da177e4 LT |
201 | |
202 | #endif /* __XFS_DA_BTREE_H__ */ |