blob: f1e8d4dbb60015093a76142e149b6db5ee2f9a57 [file] [log] [blame]
Dave Chinner32c54832013-10-29 22:11:46 +11001/*
2 * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
3 * Copyright (c) 2013 Red Hat, Inc.
4 * All Rights Reserved.
5 *
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
8 * published by the Free Software Foundation.
9 *
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.
14 *
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
18 */
19#include "xfs.h"
20#include "xfs_fs.h"
Dave Chinner632b89e2013-10-29 22:11:58 +110021#include "xfs_shared.h"
Dave Chinner32c54832013-10-29 22:11:46 +110022#include "xfs_format.h"
23#include "xfs_log_format.h"
24#include "xfs_trans_resv.h"
Dave Chinner32c54832013-10-29 22:11:46 +110025#include "xfs_mount.h"
26#include "xfs_da_format.h"
Dave Chinner892e3f32014-06-06 15:04:05 +100027#include "xfs_da_btree.h"
Dave Chinner32c54832013-10-29 22:11:46 +110028#include "xfs_inode.h"
29#include "xfs_dir2.h"
Dave Chinner892e3f32014-06-06 15:04:05 +100030#include "xfs_dir2_priv.h"
Dave Chinner32c54832013-10-29 22:11:46 +110031
Dave Chinner9d23fc82013-10-29 22:11:48 +110032/*
33 * Shortform directory ops
34 */
Dave Chinner32c54832013-10-29 22:11:46 +110035static int
36xfs_dir2_sf_entsize(
37 struct xfs_dir2_sf_hdr *hdr,
38 int len)
39{
40 int count = sizeof(struct xfs_dir2_sf_entry); /* namelen + offset */
41
42 count += len; /* name */
Christoph Hellwig266b6962016-07-20 11:48:31 +100043 count += hdr->i8count ? XFS_INO64_SIZE : XFS_INO32_SIZE; /* ino # */
Dave Chinner32c54832013-10-29 22:11:46 +110044 return count;
45}
46
47static int
48xfs_dir3_sf_entsize(
49 struct xfs_dir2_sf_hdr *hdr,
50 int len)
51{
52 return xfs_dir2_sf_entsize(hdr, len) + sizeof(__uint8_t);
53}
54
55static struct xfs_dir2_sf_entry *
56xfs_dir2_sf_nextentry(
57 struct xfs_dir2_sf_hdr *hdr,
58 struct xfs_dir2_sf_entry *sfep)
59{
60 return (struct xfs_dir2_sf_entry *)
61 ((char *)sfep + xfs_dir2_sf_entsize(hdr, sfep->namelen));
62}
63
64static struct xfs_dir2_sf_entry *
65xfs_dir3_sf_nextentry(
66 struct xfs_dir2_sf_hdr *hdr,
67 struct xfs_dir2_sf_entry *sfep)
68{
69 return (struct xfs_dir2_sf_entry *)
70 ((char *)sfep + xfs_dir3_sf_entsize(hdr, sfep->namelen));
71}
72
73
Dave Chinner47401752013-10-29 22:11:47 +110074/*
75 * For filetype enabled shortform directories, the file type field is stored at
76 * the end of the name. Because it's only a single byte, endian conversion is
77 * not necessary. For non-filetype enable directories, the type is always
78 * unknown and we never store the value.
79 */
80static __uint8_t
81xfs_dir2_sfe_get_ftype(
82 struct xfs_dir2_sf_entry *sfep)
83{
84 return XFS_DIR3_FT_UNKNOWN;
85}
86
87static void
88xfs_dir2_sfe_put_ftype(
89 struct xfs_dir2_sf_entry *sfep,
90 __uint8_t ftype)
91{
92 ASSERT(ftype < XFS_DIR3_FT_MAX);
93}
94
95static __uint8_t
96xfs_dir3_sfe_get_ftype(
97 struct xfs_dir2_sf_entry *sfep)
98{
99 __uint8_t ftype;
100
101 ftype = sfep->name[sfep->namelen];
102 if (ftype >= XFS_DIR3_FT_MAX)
103 return XFS_DIR3_FT_UNKNOWN;
104 return ftype;
105}
106
107static void
108xfs_dir3_sfe_put_ftype(
109 struct xfs_dir2_sf_entry *sfep,
110 __uint8_t ftype)
111{
112 ASSERT(ftype < XFS_DIR3_FT_MAX);
113
114 sfep->name[sfep->namelen] = ftype;
115}
116
117/*
118 * Inode numbers in short-form directories can come in two versions,
119 * either 4 bytes or 8 bytes wide. These helpers deal with the
120 * two forms transparently by looking at the headers i8count field.
121 *
122 * For 64-bit inode number the most significant byte must be zero.
123 */
124static xfs_ino_t
125xfs_dir2_sf_get_ino(
126 struct xfs_dir2_sf_hdr *hdr,
Christoph Hellwig266b6962016-07-20 11:48:31 +1000127 __uint8_t *from)
Dave Chinner47401752013-10-29 22:11:47 +1100128{
129 if (hdr->i8count)
Christoph Hellwig266b6962016-07-20 11:48:31 +1000130 return get_unaligned_be64(from) & 0x00ffffffffffffffULL;
Dave Chinner47401752013-10-29 22:11:47 +1100131 else
Christoph Hellwig266b6962016-07-20 11:48:31 +1000132 return get_unaligned_be32(from);
Dave Chinner47401752013-10-29 22:11:47 +1100133}
134
135static void
136xfs_dir2_sf_put_ino(
137 struct xfs_dir2_sf_hdr *hdr,
Christoph Hellwig266b6962016-07-20 11:48:31 +1000138 __uint8_t *to,
Dave Chinner47401752013-10-29 22:11:47 +1100139 xfs_ino_t ino)
140{
141 ASSERT((ino & 0xff00000000000000ULL) == 0);
142
143 if (hdr->i8count)
Christoph Hellwig266b6962016-07-20 11:48:31 +1000144 put_unaligned_be64(ino, to);
Dave Chinner47401752013-10-29 22:11:47 +1100145 else
Christoph Hellwig266b6962016-07-20 11:48:31 +1000146 put_unaligned_be32(ino, to);
Dave Chinner47401752013-10-29 22:11:47 +1100147}
148
149static xfs_ino_t
150xfs_dir2_sf_get_parent_ino(
151 struct xfs_dir2_sf_hdr *hdr)
152{
Christoph Hellwig266b6962016-07-20 11:48:31 +1000153 return xfs_dir2_sf_get_ino(hdr, hdr->parent);
Dave Chinner47401752013-10-29 22:11:47 +1100154}
155
156static void
157xfs_dir2_sf_put_parent_ino(
158 struct xfs_dir2_sf_hdr *hdr,
159 xfs_ino_t ino)
160{
Christoph Hellwig266b6962016-07-20 11:48:31 +1000161 xfs_dir2_sf_put_ino(hdr, hdr->parent, ino);
Dave Chinner47401752013-10-29 22:11:47 +1100162}
163
164/*
165 * In short-form directory entries the inode numbers are stored at variable
166 * offset behind the entry name. If the entry stores a filetype value, then it
167 * sits between the name and the inode number. Hence the inode numbers may only
168 * be accessed through the helpers below.
169 */
170static xfs_ino_t
171xfs_dir2_sfe_get_ino(
172 struct xfs_dir2_sf_hdr *hdr,
173 struct xfs_dir2_sf_entry *sfep)
174{
Christoph Hellwig266b6962016-07-20 11:48:31 +1000175 return xfs_dir2_sf_get_ino(hdr, &sfep->name[sfep->namelen]);
Dave Chinner47401752013-10-29 22:11:47 +1100176}
177
178static void
179xfs_dir2_sfe_put_ino(
180 struct xfs_dir2_sf_hdr *hdr,
181 struct xfs_dir2_sf_entry *sfep,
182 xfs_ino_t ino)
183{
Christoph Hellwig266b6962016-07-20 11:48:31 +1000184 xfs_dir2_sf_put_ino(hdr, &sfep->name[sfep->namelen], ino);
Dave Chinner47401752013-10-29 22:11:47 +1100185}
186
187static xfs_ino_t
188xfs_dir3_sfe_get_ino(
189 struct xfs_dir2_sf_hdr *hdr,
190 struct xfs_dir2_sf_entry *sfep)
191{
Christoph Hellwig266b6962016-07-20 11:48:31 +1000192 return xfs_dir2_sf_get_ino(hdr, &sfep->name[sfep->namelen + 1]);
Dave Chinner47401752013-10-29 22:11:47 +1100193}
194
195static void
196xfs_dir3_sfe_put_ino(
197 struct xfs_dir2_sf_hdr *hdr,
198 struct xfs_dir2_sf_entry *sfep,
199 xfs_ino_t ino)
200{
Christoph Hellwig266b6962016-07-20 11:48:31 +1000201 xfs_dir2_sf_put_ino(hdr, &sfep->name[sfep->namelen + 1], ino);
Dave Chinner47401752013-10-29 22:11:47 +1100202}
203
Dave Chinner9d23fc82013-10-29 22:11:48 +1100204
205/*
206 * Directory data block operations
207 */
Dave Chinner9d23fc82013-10-29 22:11:48 +1100208
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100209/*
210 * For special situations, the dirent size ends up fixed because we always know
211 * what the size of the entry is. That's true for the "." and "..", and
212 * therefore we know that they are a fixed size and hence their offsets are
213 * constant, as is the first entry.
214 *
215 * Hence, this calculation is written as a macro to be able to be calculated at
216 * compile time and so certain offsets can be calculated directly in the
217 * structure initaliser via the macro. There are two macros - one for dirents
218 * with ftype and without so there are no unresolvable conditionals in the
219 * calculations. We also use round_up() as XFS_DIR2_DATA_ALIGN is always a power
220 * of 2 and the compiler doesn't reject it (unlike roundup()).
221 */
222#define XFS_DIR2_DATA_ENTSIZE(n) \
223 round_up((offsetof(struct xfs_dir2_data_entry, name[0]) + (n) + \
224 sizeof(xfs_dir2_data_off_t)), XFS_DIR2_DATA_ALIGN)
225
226#define XFS_DIR3_DATA_ENTSIZE(n) \
227 round_up((offsetof(struct xfs_dir2_data_entry, name[0]) + (n) + \
228 sizeof(xfs_dir2_data_off_t) + sizeof(__uint8_t)), \
229 XFS_DIR2_DATA_ALIGN)
Dave Chinner9d23fc82013-10-29 22:11:48 +1100230
231static int
232xfs_dir2_data_entsize(
233 int n)
234{
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100235 return XFS_DIR2_DATA_ENTSIZE(n);
Dave Chinner9d23fc82013-10-29 22:11:48 +1100236}
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100237
Dave Chinner9d23fc82013-10-29 22:11:48 +1100238static int
239xfs_dir3_data_entsize(
240 int n)
241{
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100242 return XFS_DIR3_DATA_ENTSIZE(n);
Dave Chinner9d23fc82013-10-29 22:11:48 +1100243}
244
245static __uint8_t
246xfs_dir2_data_get_ftype(
247 struct xfs_dir2_data_entry *dep)
248{
249 return XFS_DIR3_FT_UNKNOWN;
250}
251
252static void
253xfs_dir2_data_put_ftype(
254 struct xfs_dir2_data_entry *dep,
255 __uint8_t ftype)
256{
257 ASSERT(ftype < XFS_DIR3_FT_MAX);
258}
259
260static __uint8_t
261xfs_dir3_data_get_ftype(
262 struct xfs_dir2_data_entry *dep)
263{
264 __uint8_t ftype = dep->name[dep->namelen];
265
Dave Chinner9d23fc82013-10-29 22:11:48 +1100266 if (ftype >= XFS_DIR3_FT_MAX)
267 return XFS_DIR3_FT_UNKNOWN;
268 return ftype;
269}
270
271static void
272xfs_dir3_data_put_ftype(
273 struct xfs_dir2_data_entry *dep,
274 __uint8_t type)
275{
276 ASSERT(type < XFS_DIR3_FT_MAX);
277 ASSERT(dep->namelen != 0);
278
279 dep->name[dep->namelen] = type;
280}
281
282/*
283 * Pointer to an entry's tag word.
284 */
285static __be16 *
286xfs_dir2_data_entry_tag_p(
287 struct xfs_dir2_data_entry *dep)
288{
289 return (__be16 *)((char *)dep +
290 xfs_dir2_data_entsize(dep->namelen) - sizeof(__be16));
291}
292
293static __be16 *
294xfs_dir3_data_entry_tag_p(
295 struct xfs_dir2_data_entry *dep)
296{
297 return (__be16 *)((char *)dep +
298 xfs_dir3_data_entsize(dep->namelen) - sizeof(__be16));
299}
300
301/*
Dave Chinner9d23fc82013-10-29 22:11:48 +1100302 * location of . and .. in data space (always block 0)
303 */
304static struct xfs_dir2_data_entry *
305xfs_dir2_data_dot_entry_p(
306 struct xfs_dir2_data_hdr *hdr)
307{
308 return (struct xfs_dir2_data_entry *)
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100309 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr));
Dave Chinner9d23fc82013-10-29 22:11:48 +1100310}
311
312static struct xfs_dir2_data_entry *
313xfs_dir2_data_dotdot_entry_p(
314 struct xfs_dir2_data_hdr *hdr)
315{
316 return (struct xfs_dir2_data_entry *)
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100317 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr) +
318 XFS_DIR2_DATA_ENTSIZE(1));
Dave Chinner9d23fc82013-10-29 22:11:48 +1100319}
320
321static struct xfs_dir2_data_entry *
322xfs_dir2_data_first_entry_p(
323 struct xfs_dir2_data_hdr *hdr)
324{
325 return (struct xfs_dir2_data_entry *)
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100326 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr) +
327 XFS_DIR2_DATA_ENTSIZE(1) +
328 XFS_DIR2_DATA_ENTSIZE(2));
Dave Chinner9d23fc82013-10-29 22:11:48 +1100329}
330
331static struct xfs_dir2_data_entry *
Dave Chinnerb01ef652013-10-29 22:11:55 +1100332xfs_dir2_ftype_data_dotdot_entry_p(
333 struct xfs_dir2_data_hdr *hdr)
334{
335 return (struct xfs_dir2_data_entry *)
336 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr) +
337 XFS_DIR3_DATA_ENTSIZE(1));
338}
339
340static struct xfs_dir2_data_entry *
341xfs_dir2_ftype_data_first_entry_p(
342 struct xfs_dir2_data_hdr *hdr)
343{
344 return (struct xfs_dir2_data_entry *)
345 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr) +
346 XFS_DIR3_DATA_ENTSIZE(1) +
347 XFS_DIR3_DATA_ENTSIZE(2));
348}
349
350static struct xfs_dir2_data_entry *
Dave Chinner9d23fc82013-10-29 22:11:48 +1100351xfs_dir3_data_dot_entry_p(
352 struct xfs_dir2_data_hdr *hdr)
353{
354 return (struct xfs_dir2_data_entry *)
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100355 ((char *)hdr + sizeof(struct xfs_dir3_data_hdr));
Dave Chinner9d23fc82013-10-29 22:11:48 +1100356}
357
358static struct xfs_dir2_data_entry *
359xfs_dir3_data_dotdot_entry_p(
360 struct xfs_dir2_data_hdr *hdr)
361{
362 return (struct xfs_dir2_data_entry *)
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100363 ((char *)hdr + sizeof(struct xfs_dir3_data_hdr) +
364 XFS_DIR3_DATA_ENTSIZE(1));
Dave Chinner9d23fc82013-10-29 22:11:48 +1100365}
366
367static struct xfs_dir2_data_entry *
368xfs_dir3_data_first_entry_p(
369 struct xfs_dir2_data_hdr *hdr)
370{
371 return (struct xfs_dir2_data_entry *)
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100372 ((char *)hdr + sizeof(struct xfs_dir3_data_hdr) +
373 XFS_DIR3_DATA_ENTSIZE(1) +
374 XFS_DIR3_DATA_ENTSIZE(2));
Dave Chinner9d23fc82013-10-29 22:11:48 +1100375}
376
Dave Chinner2ca98772013-10-29 22:11:49 +1100377static struct xfs_dir2_data_free *
378xfs_dir2_data_bestfree_p(struct xfs_dir2_data_hdr *hdr)
379{
380 return hdr->bestfree;
381}
382
383static struct xfs_dir2_data_free *
384xfs_dir3_data_bestfree_p(struct xfs_dir2_data_hdr *hdr)
385{
386 return ((struct xfs_dir3_data_hdr *)hdr)->best_free;
387}
388
Dave Chinner2ca98772013-10-29 22:11:49 +1100389static struct xfs_dir2_data_entry *
390xfs_dir2_data_entry_p(struct xfs_dir2_data_hdr *hdr)
391{
392 return (struct xfs_dir2_data_entry *)
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100393 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr));
Dave Chinner2ca98772013-10-29 22:11:49 +1100394}
395
396static struct xfs_dir2_data_unused *
397xfs_dir2_data_unused_p(struct xfs_dir2_data_hdr *hdr)
398{
399 return (struct xfs_dir2_data_unused *)
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100400 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr));
Dave Chinner2ca98772013-10-29 22:11:49 +1100401}
402
403static struct xfs_dir2_data_entry *
404xfs_dir3_data_entry_p(struct xfs_dir2_data_hdr *hdr)
405{
406 return (struct xfs_dir2_data_entry *)
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100407 ((char *)hdr + sizeof(struct xfs_dir3_data_hdr));
Dave Chinner2ca98772013-10-29 22:11:49 +1100408}
409
410static struct xfs_dir2_data_unused *
411xfs_dir3_data_unused_p(struct xfs_dir2_data_hdr *hdr)
412{
413 return (struct xfs_dir2_data_unused *)
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100414 ((char *)hdr + sizeof(struct xfs_dir3_data_hdr));
Dave Chinner2ca98772013-10-29 22:11:49 +1100415}
416
Dave Chinner41419562013-10-29 22:11:50 +1100417
418/*
419 * Directory Leaf block operations
420 */
421static int
Dave Chinner8f661932014-06-06 15:15:59 +1000422xfs_dir2_max_leaf_ents(struct xfs_da_geometry *geo)
Dave Chinner41419562013-10-29 22:11:50 +1100423{
Dave Chinner8f661932014-06-06 15:15:59 +1000424 return (geo->blksize - sizeof(struct xfs_dir2_leaf_hdr)) /
Dave Chinner41419562013-10-29 22:11:50 +1100425 (uint)sizeof(struct xfs_dir2_leaf_entry);
426}
427
428static struct xfs_dir2_leaf_entry *
429xfs_dir2_leaf_ents_p(struct xfs_dir2_leaf *lp)
430{
431 return lp->__ents;
432}
433
434static int
Dave Chinner8f661932014-06-06 15:15:59 +1000435xfs_dir3_max_leaf_ents(struct xfs_da_geometry *geo)
Dave Chinner41419562013-10-29 22:11:50 +1100436{
Dave Chinner8f661932014-06-06 15:15:59 +1000437 return (geo->blksize - sizeof(struct xfs_dir3_leaf_hdr)) /
Dave Chinner41419562013-10-29 22:11:50 +1100438 (uint)sizeof(struct xfs_dir2_leaf_entry);
439}
440
Dave Chinner01ba43b2013-10-29 22:11:52 +1100441static struct xfs_dir2_leaf_entry *
Dave Chinner41419562013-10-29 22:11:50 +1100442xfs_dir3_leaf_ents_p(struct xfs_dir2_leaf *lp)
443{
444 return ((struct xfs_dir3_leaf *)lp)->__ents;
445}
446
Dave Chinner01ba43b2013-10-29 22:11:52 +1100447static void
448xfs_dir2_leaf_hdr_from_disk(
449 struct xfs_dir3_icleaf_hdr *to,
450 struct xfs_dir2_leaf *from)
451{
452 to->forw = be32_to_cpu(from->hdr.info.forw);
453 to->back = be32_to_cpu(from->hdr.info.back);
454 to->magic = be16_to_cpu(from->hdr.info.magic);
455 to->count = be16_to_cpu(from->hdr.count);
456 to->stale = be16_to_cpu(from->hdr.stale);
457
458 ASSERT(to->magic == XFS_DIR2_LEAF1_MAGIC ||
459 to->magic == XFS_DIR2_LEAFN_MAGIC);
460}
461
462static void
463xfs_dir2_leaf_hdr_to_disk(
464 struct xfs_dir2_leaf *to,
465 struct xfs_dir3_icleaf_hdr *from)
466{
467 ASSERT(from->magic == XFS_DIR2_LEAF1_MAGIC ||
468 from->magic == XFS_DIR2_LEAFN_MAGIC);
469
470 to->hdr.info.forw = cpu_to_be32(from->forw);
471 to->hdr.info.back = cpu_to_be32(from->back);
472 to->hdr.info.magic = cpu_to_be16(from->magic);
473 to->hdr.count = cpu_to_be16(from->count);
474 to->hdr.stale = cpu_to_be16(from->stale);
475}
476
477static void
478xfs_dir3_leaf_hdr_from_disk(
479 struct xfs_dir3_icleaf_hdr *to,
480 struct xfs_dir2_leaf *from)
481{
482 struct xfs_dir3_leaf_hdr *hdr3 = (struct xfs_dir3_leaf_hdr *)from;
483
484 to->forw = be32_to_cpu(hdr3->info.hdr.forw);
485 to->back = be32_to_cpu(hdr3->info.hdr.back);
486 to->magic = be16_to_cpu(hdr3->info.hdr.magic);
487 to->count = be16_to_cpu(hdr3->count);
488 to->stale = be16_to_cpu(hdr3->stale);
489
490 ASSERT(to->magic == XFS_DIR3_LEAF1_MAGIC ||
491 to->magic == XFS_DIR3_LEAFN_MAGIC);
492}
493
494static void
495xfs_dir3_leaf_hdr_to_disk(
496 struct xfs_dir2_leaf *to,
497 struct xfs_dir3_icleaf_hdr *from)
498{
499 struct xfs_dir3_leaf_hdr *hdr3 = (struct xfs_dir3_leaf_hdr *)to;
500
501 ASSERT(from->magic == XFS_DIR3_LEAF1_MAGIC ||
502 from->magic == XFS_DIR3_LEAFN_MAGIC);
503
504 hdr3->info.hdr.forw = cpu_to_be32(from->forw);
505 hdr3->info.hdr.back = cpu_to_be32(from->back);
506 hdr3->info.hdr.magic = cpu_to_be16(from->magic);
507 hdr3->count = cpu_to_be16(from->count);
508 hdr3->stale = cpu_to_be16(from->stale);
509}
510
511
Dave Chinner4bceb182013-10-29 22:11:51 +1100512/*
513 * Directory/Attribute Node block operations
514 */
Dave Chinner4bceb182013-10-29 22:11:51 +1100515static struct xfs_da_node_entry *
516xfs_da2_node_tree_p(struct xfs_da_intnode *dap)
517{
518 return dap->__btree;
519}
520
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100521static struct xfs_da_node_entry *
Dave Chinner4bceb182013-10-29 22:11:51 +1100522xfs_da3_node_tree_p(struct xfs_da_intnode *dap)
523{
524 return ((struct xfs_da3_intnode *)dap)->__btree;
525}
526
Dave Chinner01ba43b2013-10-29 22:11:52 +1100527static void
528xfs_da2_node_hdr_from_disk(
529 struct xfs_da3_icnode_hdr *to,
530 struct xfs_da_intnode *from)
531{
532 ASSERT(from->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC));
533 to->forw = be32_to_cpu(from->hdr.info.forw);
534 to->back = be32_to_cpu(from->hdr.info.back);
535 to->magic = be16_to_cpu(from->hdr.info.magic);
536 to->count = be16_to_cpu(from->hdr.__count);
537 to->level = be16_to_cpu(from->hdr.__level);
538}
539
540static void
541xfs_da2_node_hdr_to_disk(
542 struct xfs_da_intnode *to,
543 struct xfs_da3_icnode_hdr *from)
544{
545 ASSERT(from->magic == XFS_DA_NODE_MAGIC);
546 to->hdr.info.forw = cpu_to_be32(from->forw);
547 to->hdr.info.back = cpu_to_be32(from->back);
548 to->hdr.info.magic = cpu_to_be16(from->magic);
549 to->hdr.__count = cpu_to_be16(from->count);
550 to->hdr.__level = cpu_to_be16(from->level);
551}
552
553static void
554xfs_da3_node_hdr_from_disk(
555 struct xfs_da3_icnode_hdr *to,
556 struct xfs_da_intnode *from)
557{
558 struct xfs_da3_node_hdr *hdr3 = (struct xfs_da3_node_hdr *)from;
559
560 ASSERT(from->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC));
561 to->forw = be32_to_cpu(hdr3->info.hdr.forw);
562 to->back = be32_to_cpu(hdr3->info.hdr.back);
563 to->magic = be16_to_cpu(hdr3->info.hdr.magic);
564 to->count = be16_to_cpu(hdr3->__count);
565 to->level = be16_to_cpu(hdr3->__level);
566}
567
568static void
569xfs_da3_node_hdr_to_disk(
570 struct xfs_da_intnode *to,
571 struct xfs_da3_icnode_hdr *from)
572{
573 struct xfs_da3_node_hdr *hdr3 = (struct xfs_da3_node_hdr *)to;
574
575 ASSERT(from->magic == XFS_DA3_NODE_MAGIC);
576 hdr3->info.hdr.forw = cpu_to_be32(from->forw);
577 hdr3->info.hdr.back = cpu_to_be32(from->back);
578 hdr3->info.hdr.magic = cpu_to_be16(from->magic);
579 hdr3->__count = cpu_to_be16(from->count);
580 hdr3->__level = cpu_to_be16(from->level);
581}
582
583
584/*
585 * Directory free space block operations
586 */
Dave Chinner24dd0f52013-10-30 13:48:41 -0500587static int
Dave Chinner8f661932014-06-06 15:15:59 +1000588xfs_dir2_free_max_bests(struct xfs_da_geometry *geo)
Dave Chinner24dd0f52013-10-30 13:48:41 -0500589{
Dave Chinner8f661932014-06-06 15:15:59 +1000590 return (geo->blksize - sizeof(struct xfs_dir2_free_hdr)) /
Dave Chinner24dd0f52013-10-30 13:48:41 -0500591 sizeof(xfs_dir2_data_off_t);
592}
593
594static __be16 *
595xfs_dir2_free_bests_p(struct xfs_dir2_free *free)
596{
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100597 return (__be16 *)((char *)free + sizeof(struct xfs_dir2_free_hdr));
Dave Chinner24dd0f52013-10-30 13:48:41 -0500598}
599
600/*
601 * Convert data space db to the corresponding free db.
602 */
603static xfs_dir2_db_t
Dave Chinner8f661932014-06-06 15:15:59 +1000604xfs_dir2_db_to_fdb(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
Dave Chinner24dd0f52013-10-30 13:48:41 -0500605{
Dave Chinner8f661932014-06-06 15:15:59 +1000606 return xfs_dir2_byte_to_db(geo, XFS_DIR2_FREE_OFFSET) +
607 (db / xfs_dir2_free_max_bests(geo));
Dave Chinner24dd0f52013-10-30 13:48:41 -0500608}
609
610/*
611 * Convert data space db to the corresponding index in a free db.
612 */
613static int
Dave Chinner8f661932014-06-06 15:15:59 +1000614xfs_dir2_db_to_fdindex(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
Dave Chinner24dd0f52013-10-30 13:48:41 -0500615{
Dave Chinner8f661932014-06-06 15:15:59 +1000616 return db % xfs_dir2_free_max_bests(geo);
Dave Chinner24dd0f52013-10-30 13:48:41 -0500617}
618
619static int
Dave Chinner8f661932014-06-06 15:15:59 +1000620xfs_dir3_free_max_bests(struct xfs_da_geometry *geo)
Dave Chinner24dd0f52013-10-30 13:48:41 -0500621{
Dave Chinner8f661932014-06-06 15:15:59 +1000622 return (geo->blksize - sizeof(struct xfs_dir3_free_hdr)) /
Dave Chinner24dd0f52013-10-30 13:48:41 -0500623 sizeof(xfs_dir2_data_off_t);
624}
625
626static __be16 *
627xfs_dir3_free_bests_p(struct xfs_dir2_free *free)
628{
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100629 return (__be16 *)((char *)free + sizeof(struct xfs_dir3_free_hdr));
Dave Chinner24dd0f52013-10-30 13:48:41 -0500630}
631
632/*
633 * Convert data space db to the corresponding free db.
634 */
635static xfs_dir2_db_t
Dave Chinner8f661932014-06-06 15:15:59 +1000636xfs_dir3_db_to_fdb(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
Dave Chinner24dd0f52013-10-30 13:48:41 -0500637{
Dave Chinner8f661932014-06-06 15:15:59 +1000638 return xfs_dir2_byte_to_db(geo, XFS_DIR2_FREE_OFFSET) +
639 (db / xfs_dir3_free_max_bests(geo));
Dave Chinner24dd0f52013-10-30 13:48:41 -0500640}
641
642/*
643 * Convert data space db to the corresponding index in a free db.
644 */
645static int
Dave Chinner8f661932014-06-06 15:15:59 +1000646xfs_dir3_db_to_fdindex(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
Dave Chinner24dd0f52013-10-30 13:48:41 -0500647{
Dave Chinner8f661932014-06-06 15:15:59 +1000648 return db % xfs_dir3_free_max_bests(geo);
Dave Chinner24dd0f52013-10-30 13:48:41 -0500649}
650
Dave Chinner01ba43b2013-10-29 22:11:52 +1100651static void
652xfs_dir2_free_hdr_from_disk(
653 struct xfs_dir3_icfree_hdr *to,
654 struct xfs_dir2_free *from)
655{
656 to->magic = be32_to_cpu(from->hdr.magic);
657 to->firstdb = be32_to_cpu(from->hdr.firstdb);
658 to->nvalid = be32_to_cpu(from->hdr.nvalid);
659 to->nused = be32_to_cpu(from->hdr.nused);
660 ASSERT(to->magic == XFS_DIR2_FREE_MAGIC);
661}
662
663static void
664xfs_dir2_free_hdr_to_disk(
665 struct xfs_dir2_free *to,
666 struct xfs_dir3_icfree_hdr *from)
667{
668 ASSERT(from->magic == XFS_DIR2_FREE_MAGIC);
669
670 to->hdr.magic = cpu_to_be32(from->magic);
671 to->hdr.firstdb = cpu_to_be32(from->firstdb);
672 to->hdr.nvalid = cpu_to_be32(from->nvalid);
673 to->hdr.nused = cpu_to_be32(from->nused);
674}
675
676static void
677xfs_dir3_free_hdr_from_disk(
678 struct xfs_dir3_icfree_hdr *to,
679 struct xfs_dir2_free *from)
680{
681 struct xfs_dir3_free_hdr *hdr3 = (struct xfs_dir3_free_hdr *)from;
682
683 to->magic = be32_to_cpu(hdr3->hdr.magic);
684 to->firstdb = be32_to_cpu(hdr3->firstdb);
685 to->nvalid = be32_to_cpu(hdr3->nvalid);
686 to->nused = be32_to_cpu(hdr3->nused);
687
688 ASSERT(to->magic == XFS_DIR3_FREE_MAGIC);
689}
690
691static void
692xfs_dir3_free_hdr_to_disk(
693 struct xfs_dir2_free *to,
694 struct xfs_dir3_icfree_hdr *from)
695{
696 struct xfs_dir3_free_hdr *hdr3 = (struct xfs_dir3_free_hdr *)to;
697
698 ASSERT(from->magic == XFS_DIR3_FREE_MAGIC);
699
700 hdr3->hdr.magic = cpu_to_be32(from->magic);
701 hdr3->firstdb = cpu_to_be32(from->firstdb);
702 hdr3->nvalid = cpu_to_be32(from->nvalid);
703 hdr3->nused = cpu_to_be32(from->nused);
704}
705
Dave Chinner632b89e2013-10-29 22:11:58 +1100706static const struct xfs_dir_ops xfs_dir2_ops = {
Dave Chinner32c54832013-10-29 22:11:46 +1100707 .sf_entsize = xfs_dir2_sf_entsize,
708 .sf_nextentry = xfs_dir2_sf_nextentry,
Dave Chinner47401752013-10-29 22:11:47 +1100709 .sf_get_ftype = xfs_dir2_sfe_get_ftype,
710 .sf_put_ftype = xfs_dir2_sfe_put_ftype,
711 .sf_get_ino = xfs_dir2_sfe_get_ino,
712 .sf_put_ino = xfs_dir2_sfe_put_ino,
713 .sf_get_parent_ino = xfs_dir2_sf_get_parent_ino,
714 .sf_put_parent_ino = xfs_dir2_sf_put_parent_ino,
Dave Chinner9d23fc82013-10-29 22:11:48 +1100715
716 .data_entsize = xfs_dir2_data_entsize,
717 .data_get_ftype = xfs_dir2_data_get_ftype,
718 .data_put_ftype = xfs_dir2_data_put_ftype,
719 .data_entry_tag_p = xfs_dir2_data_entry_tag_p,
Dave Chinner2ca98772013-10-29 22:11:49 +1100720 .data_bestfree_p = xfs_dir2_data_bestfree_p,
Dave Chinner9d23fc82013-10-29 22:11:48 +1100721
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100722 .data_dot_offset = sizeof(struct xfs_dir2_data_hdr),
723 .data_dotdot_offset = sizeof(struct xfs_dir2_data_hdr) +
724 XFS_DIR2_DATA_ENTSIZE(1),
725 .data_first_offset = sizeof(struct xfs_dir2_data_hdr) +
726 XFS_DIR2_DATA_ENTSIZE(1) +
727 XFS_DIR2_DATA_ENTSIZE(2),
728 .data_entry_offset = sizeof(struct xfs_dir2_data_hdr),
Dave Chinner2ca98772013-10-29 22:11:49 +1100729
Dave Chinner9d23fc82013-10-29 22:11:48 +1100730 .data_dot_entry_p = xfs_dir2_data_dot_entry_p,
731 .data_dotdot_entry_p = xfs_dir2_data_dotdot_entry_p,
732 .data_first_entry_p = xfs_dir2_data_first_entry_p,
Dave Chinner2ca98772013-10-29 22:11:49 +1100733 .data_entry_p = xfs_dir2_data_entry_p,
734 .data_unused_p = xfs_dir2_data_unused_p,
735
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100736 .leaf_hdr_size = sizeof(struct xfs_dir2_leaf_hdr),
Dave Chinner01ba43b2013-10-29 22:11:52 +1100737 .leaf_hdr_to_disk = xfs_dir2_leaf_hdr_to_disk,
738 .leaf_hdr_from_disk = xfs_dir2_leaf_hdr_from_disk,
Dave Chinner41419562013-10-29 22:11:50 +1100739 .leaf_max_ents = xfs_dir2_max_leaf_ents,
740 .leaf_ents_p = xfs_dir2_leaf_ents_p,
741
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100742 .node_hdr_size = sizeof(struct xfs_da_node_hdr),
Dave Chinner01ba43b2013-10-29 22:11:52 +1100743 .node_hdr_to_disk = xfs_da2_node_hdr_to_disk,
744 .node_hdr_from_disk = xfs_da2_node_hdr_from_disk,
Dave Chinner4bceb182013-10-29 22:11:51 +1100745 .node_tree_p = xfs_da2_node_tree_p,
Dave Chinner01ba43b2013-10-29 22:11:52 +1100746
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100747 .free_hdr_size = sizeof(struct xfs_dir2_free_hdr),
Dave Chinner01ba43b2013-10-29 22:11:52 +1100748 .free_hdr_to_disk = xfs_dir2_free_hdr_to_disk,
749 .free_hdr_from_disk = xfs_dir2_free_hdr_from_disk,
Dave Chinner24dd0f52013-10-30 13:48:41 -0500750 .free_max_bests = xfs_dir2_free_max_bests,
751 .free_bests_p = xfs_dir2_free_bests_p,
752 .db_to_fdb = xfs_dir2_db_to_fdb,
753 .db_to_fdindex = xfs_dir2_db_to_fdindex,
Dave Chinner32c54832013-10-29 22:11:46 +1100754};
755
Dave Chinner632b89e2013-10-29 22:11:58 +1100756static const struct xfs_dir_ops xfs_dir2_ftype_ops = {
Dave Chinner32c54832013-10-29 22:11:46 +1100757 .sf_entsize = xfs_dir3_sf_entsize,
758 .sf_nextentry = xfs_dir3_sf_nextentry,
Dave Chinner47401752013-10-29 22:11:47 +1100759 .sf_get_ftype = xfs_dir3_sfe_get_ftype,
760 .sf_put_ftype = xfs_dir3_sfe_put_ftype,
761 .sf_get_ino = xfs_dir3_sfe_get_ino,
762 .sf_put_ino = xfs_dir3_sfe_put_ino,
763 .sf_get_parent_ino = xfs_dir2_sf_get_parent_ino,
764 .sf_put_parent_ino = xfs_dir2_sf_put_parent_ino,
Dave Chinner9d23fc82013-10-29 22:11:48 +1100765
766 .data_entsize = xfs_dir3_data_entsize,
767 .data_get_ftype = xfs_dir3_data_get_ftype,
768 .data_put_ftype = xfs_dir3_data_put_ftype,
769 .data_entry_tag_p = xfs_dir3_data_entry_tag_p,
Dave Chinner2ca98772013-10-29 22:11:49 +1100770 .data_bestfree_p = xfs_dir2_data_bestfree_p,
Dave Chinner9d23fc82013-10-29 22:11:48 +1100771
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100772 .data_dot_offset = sizeof(struct xfs_dir2_data_hdr),
773 .data_dotdot_offset = sizeof(struct xfs_dir2_data_hdr) +
774 XFS_DIR3_DATA_ENTSIZE(1),
775 .data_first_offset = sizeof(struct xfs_dir2_data_hdr) +
776 XFS_DIR3_DATA_ENTSIZE(1) +
777 XFS_DIR3_DATA_ENTSIZE(2),
778 .data_entry_offset = sizeof(struct xfs_dir2_data_hdr),
Dave Chinner2ca98772013-10-29 22:11:49 +1100779
Dave Chinner9d23fc82013-10-29 22:11:48 +1100780 .data_dot_entry_p = xfs_dir2_data_dot_entry_p,
Dave Chinnerb01ef652013-10-29 22:11:55 +1100781 .data_dotdot_entry_p = xfs_dir2_ftype_data_dotdot_entry_p,
782 .data_first_entry_p = xfs_dir2_ftype_data_first_entry_p,
Dave Chinner2ca98772013-10-29 22:11:49 +1100783 .data_entry_p = xfs_dir2_data_entry_p,
784 .data_unused_p = xfs_dir2_data_unused_p,
Dave Chinner41419562013-10-29 22:11:50 +1100785
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100786 .leaf_hdr_size = sizeof(struct xfs_dir2_leaf_hdr),
Dave Chinner01ba43b2013-10-29 22:11:52 +1100787 .leaf_hdr_to_disk = xfs_dir2_leaf_hdr_to_disk,
788 .leaf_hdr_from_disk = xfs_dir2_leaf_hdr_from_disk,
Dave Chinner41419562013-10-29 22:11:50 +1100789 .leaf_max_ents = xfs_dir2_max_leaf_ents,
790 .leaf_ents_p = xfs_dir2_leaf_ents_p,
Dave Chinner4bceb182013-10-29 22:11:51 +1100791
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100792 .node_hdr_size = sizeof(struct xfs_da_node_hdr),
Dave Chinner01ba43b2013-10-29 22:11:52 +1100793 .node_hdr_to_disk = xfs_da2_node_hdr_to_disk,
794 .node_hdr_from_disk = xfs_da2_node_hdr_from_disk,
Dave Chinner4bceb182013-10-29 22:11:51 +1100795 .node_tree_p = xfs_da2_node_tree_p,
Dave Chinner01ba43b2013-10-29 22:11:52 +1100796
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100797 .free_hdr_size = sizeof(struct xfs_dir2_free_hdr),
Dave Chinner01ba43b2013-10-29 22:11:52 +1100798 .free_hdr_to_disk = xfs_dir2_free_hdr_to_disk,
799 .free_hdr_from_disk = xfs_dir2_free_hdr_from_disk,
Dave Chinner24dd0f52013-10-30 13:48:41 -0500800 .free_max_bests = xfs_dir2_free_max_bests,
801 .free_bests_p = xfs_dir2_free_bests_p,
802 .db_to_fdb = xfs_dir2_db_to_fdb,
803 .db_to_fdindex = xfs_dir2_db_to_fdindex,
Dave Chinner32c54832013-10-29 22:11:46 +1100804};
805
Dave Chinner632b89e2013-10-29 22:11:58 +1100806static const struct xfs_dir_ops xfs_dir3_ops = {
Dave Chinner32c54832013-10-29 22:11:46 +1100807 .sf_entsize = xfs_dir3_sf_entsize,
808 .sf_nextentry = xfs_dir3_sf_nextentry,
Dave Chinner47401752013-10-29 22:11:47 +1100809 .sf_get_ftype = xfs_dir3_sfe_get_ftype,
810 .sf_put_ftype = xfs_dir3_sfe_put_ftype,
811 .sf_get_ino = xfs_dir3_sfe_get_ino,
812 .sf_put_ino = xfs_dir3_sfe_put_ino,
813 .sf_get_parent_ino = xfs_dir2_sf_get_parent_ino,
814 .sf_put_parent_ino = xfs_dir2_sf_put_parent_ino,
Dave Chinner9d23fc82013-10-29 22:11:48 +1100815
816 .data_entsize = xfs_dir3_data_entsize,
817 .data_get_ftype = xfs_dir3_data_get_ftype,
818 .data_put_ftype = xfs_dir3_data_put_ftype,
819 .data_entry_tag_p = xfs_dir3_data_entry_tag_p,
Dave Chinner2ca98772013-10-29 22:11:49 +1100820 .data_bestfree_p = xfs_dir3_data_bestfree_p,
Dave Chinner9d23fc82013-10-29 22:11:48 +1100821
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100822 .data_dot_offset = sizeof(struct xfs_dir3_data_hdr),
823 .data_dotdot_offset = sizeof(struct xfs_dir3_data_hdr) +
824 XFS_DIR3_DATA_ENTSIZE(1),
825 .data_first_offset = sizeof(struct xfs_dir3_data_hdr) +
826 XFS_DIR3_DATA_ENTSIZE(1) +
827 XFS_DIR3_DATA_ENTSIZE(2),
828 .data_entry_offset = sizeof(struct xfs_dir3_data_hdr),
Dave Chinner2ca98772013-10-29 22:11:49 +1100829
Dave Chinner9d23fc82013-10-29 22:11:48 +1100830 .data_dot_entry_p = xfs_dir3_data_dot_entry_p,
831 .data_dotdot_entry_p = xfs_dir3_data_dotdot_entry_p,
832 .data_first_entry_p = xfs_dir3_data_first_entry_p,
Dave Chinner2ca98772013-10-29 22:11:49 +1100833 .data_entry_p = xfs_dir3_data_entry_p,
834 .data_unused_p = xfs_dir3_data_unused_p,
Dave Chinner41419562013-10-29 22:11:50 +1100835
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100836 .leaf_hdr_size = sizeof(struct xfs_dir3_leaf_hdr),
Dave Chinner01ba43b2013-10-29 22:11:52 +1100837 .leaf_hdr_to_disk = xfs_dir3_leaf_hdr_to_disk,
838 .leaf_hdr_from_disk = xfs_dir3_leaf_hdr_from_disk,
Dave Chinner41419562013-10-29 22:11:50 +1100839 .leaf_max_ents = xfs_dir3_max_leaf_ents,
840 .leaf_ents_p = xfs_dir3_leaf_ents_p,
Dave Chinner4bceb182013-10-29 22:11:51 +1100841
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100842 .node_hdr_size = sizeof(struct xfs_da3_node_hdr),
Dave Chinner01ba43b2013-10-29 22:11:52 +1100843 .node_hdr_to_disk = xfs_da3_node_hdr_to_disk,
844 .node_hdr_from_disk = xfs_da3_node_hdr_from_disk,
Dave Chinner4bceb182013-10-29 22:11:51 +1100845 .node_tree_p = xfs_da3_node_tree_p,
Dave Chinner01ba43b2013-10-29 22:11:52 +1100846
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100847 .free_hdr_size = sizeof(struct xfs_dir3_free_hdr),
Dave Chinner01ba43b2013-10-29 22:11:52 +1100848 .free_hdr_to_disk = xfs_dir3_free_hdr_to_disk,
849 .free_hdr_from_disk = xfs_dir3_free_hdr_from_disk,
Dave Chinner24dd0f52013-10-30 13:48:41 -0500850 .free_max_bests = xfs_dir3_free_max_bests,
851 .free_bests_p = xfs_dir3_free_bests_p,
852 .db_to_fdb = xfs_dir3_db_to_fdb,
853 .db_to_fdindex = xfs_dir3_db_to_fdindex,
Dave Chinner4bceb182013-10-29 22:11:51 +1100854};
855
Dave Chinner632b89e2013-10-29 22:11:58 +1100856static const struct xfs_dir_ops xfs_dir2_nondir_ops = {
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100857 .node_hdr_size = sizeof(struct xfs_da_node_hdr),
Dave Chinner01ba43b2013-10-29 22:11:52 +1100858 .node_hdr_to_disk = xfs_da2_node_hdr_to_disk,
859 .node_hdr_from_disk = xfs_da2_node_hdr_from_disk,
Dave Chinner4bceb182013-10-29 22:11:51 +1100860 .node_tree_p = xfs_da2_node_tree_p,
861};
862
Dave Chinner632b89e2013-10-29 22:11:58 +1100863static const struct xfs_dir_ops xfs_dir3_nondir_ops = {
Dave Chinner1c9a5b22013-10-30 09:15:02 +1100864 .node_hdr_size = sizeof(struct xfs_da3_node_hdr),
Dave Chinner01ba43b2013-10-29 22:11:52 +1100865 .node_hdr_to_disk = xfs_da3_node_hdr_to_disk,
866 .node_hdr_from_disk = xfs_da3_node_hdr_from_disk,
Dave Chinner4bceb182013-10-29 22:11:51 +1100867 .node_tree_p = xfs_da3_node_tree_p,
Dave Chinner32c54832013-10-29 22:11:46 +1100868};
Dave Chinner41419562013-10-29 22:11:50 +1100869
870/*
871 * Return the ops structure according to the current config. If we are passed
872 * an inode, then that overrides the default config we use which is based on
873 * feature bits.
874 */
875const struct xfs_dir_ops *
876xfs_dir_get_ops(
877 struct xfs_mount *mp,
878 struct xfs_inode *dp)
879{
880 if (dp)
881 return dp->d_ops;
882 if (mp->m_dir_inode_ops)
883 return mp->m_dir_inode_ops;
884 if (xfs_sb_version_hascrc(&mp->m_sb))
885 return &xfs_dir3_ops;
886 if (xfs_sb_version_hasftype(&mp->m_sb))
887 return &xfs_dir2_ftype_ops;
888 return &xfs_dir2_ops;
889}
Dave Chinner4bceb182013-10-29 22:11:51 +1100890
891const struct xfs_dir_ops *
892xfs_nondir_get_ops(
893 struct xfs_mount *mp,
894 struct xfs_inode *dp)
895{
896 if (dp)
897 return dp->d_ops;
898 if (mp->m_nondir_inode_ops)
899 return mp->m_nondir_inode_ops;
900 if (xfs_sb_version_hascrc(&mp->m_sb))
901 return &xfs_dir3_nondir_ops;
902 return &xfs_dir2_nondir_ops;
903}