1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
4 * Copyright (c) 2013 Red Hat, Inc.
9 #include "xfs_shared.h"
10 #include "xfs_format.h"
11 #include "xfs_log_format.h"
12 #include "xfs_trans_resv.h"
13 #include "xfs_mount.h"
14 #include "xfs_inode.h"
18 * Shortform directory ops
22 struct xfs_dir2_sf_hdr *hdr,
25 int count = sizeof(struct xfs_dir2_sf_entry); /* namelen + offset */
27 count += len; /* name */
28 count += hdr->i8count ? XFS_INO64_SIZE : XFS_INO32_SIZE; /* ino # */
34 struct xfs_dir2_sf_hdr *hdr,
37 return xfs_dir2_sf_entsize(hdr, len) + sizeof(uint8_t);
40 static struct xfs_dir2_sf_entry *
41 xfs_dir2_sf_nextentry(
42 struct xfs_dir2_sf_hdr *hdr,
43 struct xfs_dir2_sf_entry *sfep)
45 return (struct xfs_dir2_sf_entry *)
46 ((char *)sfep + xfs_dir2_sf_entsize(hdr, sfep->namelen));
49 static struct xfs_dir2_sf_entry *
50 xfs_dir3_sf_nextentry(
51 struct xfs_dir2_sf_hdr *hdr,
52 struct xfs_dir2_sf_entry *sfep)
54 return (struct xfs_dir2_sf_entry *)
55 ((char *)sfep + xfs_dir3_sf_entsize(hdr, sfep->namelen));
60 * For filetype enabled shortform directories, the file type field is stored at
61 * the end of the name. Because it's only a single byte, endian conversion is
62 * not necessary. For non-filetype enable directories, the type is always
63 * unknown and we never store the value.
66 xfs_dir2_sfe_get_ftype(
67 struct xfs_dir2_sf_entry *sfep)
69 return XFS_DIR3_FT_UNKNOWN;
73 xfs_dir2_sfe_put_ftype(
74 struct xfs_dir2_sf_entry *sfep,
77 ASSERT(ftype < XFS_DIR3_FT_MAX);
81 xfs_dir3_sfe_get_ftype(
82 struct xfs_dir2_sf_entry *sfep)
86 ftype = sfep->name[sfep->namelen];
87 if (ftype >= XFS_DIR3_FT_MAX)
88 return XFS_DIR3_FT_UNKNOWN;
93 xfs_dir3_sfe_put_ftype(
94 struct xfs_dir2_sf_entry *sfep,
97 ASSERT(ftype < XFS_DIR3_FT_MAX);
99 sfep->name[sfep->namelen] = ftype;
103 * Inode numbers in short-form directories can come in two versions,
104 * either 4 bytes or 8 bytes wide. These helpers deal with the
105 * two forms transparently by looking at the headers i8count field.
107 * For 64-bit inode number the most significant byte must be zero.
111 struct xfs_dir2_sf_hdr *hdr,
115 return get_unaligned_be64(from) & 0x00ffffffffffffffULL;
117 return get_unaligned_be32(from);
122 struct xfs_dir2_sf_hdr *hdr,
126 ASSERT((ino & 0xff00000000000000ULL) == 0);
129 put_unaligned_be64(ino, to);
131 put_unaligned_be32(ino, to);
135 xfs_dir2_sf_get_parent_ino(
136 struct xfs_dir2_sf_hdr *hdr)
138 return xfs_dir2_sf_get_ino(hdr, hdr->parent);
142 xfs_dir2_sf_put_parent_ino(
143 struct xfs_dir2_sf_hdr *hdr,
146 xfs_dir2_sf_put_ino(hdr, hdr->parent, ino);
150 * In short-form directory entries the inode numbers are stored at variable
151 * offset behind the entry name. If the entry stores a filetype value, then it
152 * sits between the name and the inode number. Hence the inode numbers may only
153 * be accessed through the helpers below.
156 xfs_dir2_sfe_get_ino(
157 struct xfs_dir2_sf_hdr *hdr,
158 struct xfs_dir2_sf_entry *sfep)
160 return xfs_dir2_sf_get_ino(hdr, &sfep->name[sfep->namelen]);
164 xfs_dir2_sfe_put_ino(
165 struct xfs_dir2_sf_hdr *hdr,
166 struct xfs_dir2_sf_entry *sfep,
169 xfs_dir2_sf_put_ino(hdr, &sfep->name[sfep->namelen], ino);
173 xfs_dir3_sfe_get_ino(
174 struct xfs_dir2_sf_hdr *hdr,
175 struct xfs_dir2_sf_entry *sfep)
177 return xfs_dir2_sf_get_ino(hdr, &sfep->name[sfep->namelen + 1]);
181 xfs_dir3_sfe_put_ino(
182 struct xfs_dir2_sf_hdr *hdr,
183 struct xfs_dir2_sf_entry *sfep,
186 xfs_dir2_sf_put_ino(hdr, &sfep->name[sfep->namelen + 1], ino);
191 * Directory data block operations
195 * For special situations, the dirent size ends up fixed because we always know
196 * what the size of the entry is. That's true for the "." and "..", and
197 * therefore we know that they are a fixed size and hence their offsets are
198 * constant, as is the first entry.
200 * Hence, this calculation is written as a macro to be able to be calculated at
201 * compile time and so certain offsets can be calculated directly in the
202 * structure initaliser via the macro. There are two macros - one for dirents
203 * with ftype and without so there are no unresolvable conditionals in the
204 * calculations. We also use round_up() as XFS_DIR2_DATA_ALIGN is always a power
205 * of 2 and the compiler doesn't reject it (unlike roundup()).
207 #define XFS_DIR2_DATA_ENTSIZE(n) \
208 round_up((offsetof(struct xfs_dir2_data_entry, name[0]) + (n) + \
209 sizeof(xfs_dir2_data_off_t)), XFS_DIR2_DATA_ALIGN)
211 #define XFS_DIR3_DATA_ENTSIZE(n) \
212 round_up((offsetof(struct xfs_dir2_data_entry, name[0]) + (n) + \
213 sizeof(xfs_dir2_data_off_t) + sizeof(uint8_t)), \
217 xfs_dir2_data_entsize(
220 return XFS_DIR2_DATA_ENTSIZE(n);
224 xfs_dir3_data_entsize(
227 return XFS_DIR3_DATA_ENTSIZE(n);
231 xfs_dir2_data_get_ftype(
232 struct xfs_dir2_data_entry *dep)
234 return XFS_DIR3_FT_UNKNOWN;
238 xfs_dir2_data_put_ftype(
239 struct xfs_dir2_data_entry *dep,
242 ASSERT(ftype < XFS_DIR3_FT_MAX);
246 xfs_dir3_data_get_ftype(
247 struct xfs_dir2_data_entry *dep)
249 uint8_t ftype = dep->name[dep->namelen];
251 if (ftype >= XFS_DIR3_FT_MAX)
252 return XFS_DIR3_FT_UNKNOWN;
257 xfs_dir3_data_put_ftype(
258 struct xfs_dir2_data_entry *dep,
261 ASSERT(type < XFS_DIR3_FT_MAX);
262 ASSERT(dep->namelen != 0);
264 dep->name[dep->namelen] = type;
268 * Pointer to an entry's tag word.
271 xfs_dir2_data_entry_tag_p(
272 struct xfs_dir2_data_entry *dep)
274 return (__be16 *)((char *)dep +
275 xfs_dir2_data_entsize(dep->namelen) - sizeof(__be16));
279 xfs_dir3_data_entry_tag_p(
280 struct xfs_dir2_data_entry *dep)
282 return (__be16 *)((char *)dep +
283 xfs_dir3_data_entsize(dep->namelen) - sizeof(__be16));
287 * location of . and .. in data space (always block 0)
289 static struct xfs_dir2_data_entry *
290 xfs_dir2_data_dot_entry_p(
291 struct xfs_dir2_data_hdr *hdr)
293 return (struct xfs_dir2_data_entry *)
294 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr));
297 static struct xfs_dir2_data_entry *
298 xfs_dir2_data_dotdot_entry_p(
299 struct xfs_dir2_data_hdr *hdr)
301 return (struct xfs_dir2_data_entry *)
302 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr) +
303 XFS_DIR2_DATA_ENTSIZE(1));
306 static struct xfs_dir2_data_entry *
307 xfs_dir2_data_first_entry_p(
308 struct xfs_dir2_data_hdr *hdr)
310 return (struct xfs_dir2_data_entry *)
311 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr) +
312 XFS_DIR2_DATA_ENTSIZE(1) +
313 XFS_DIR2_DATA_ENTSIZE(2));
316 static struct xfs_dir2_data_entry *
317 xfs_dir2_ftype_data_dotdot_entry_p(
318 struct xfs_dir2_data_hdr *hdr)
320 return (struct xfs_dir2_data_entry *)
321 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr) +
322 XFS_DIR3_DATA_ENTSIZE(1));
325 static struct xfs_dir2_data_entry *
326 xfs_dir2_ftype_data_first_entry_p(
327 struct xfs_dir2_data_hdr *hdr)
329 return (struct xfs_dir2_data_entry *)
330 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr) +
331 XFS_DIR3_DATA_ENTSIZE(1) +
332 XFS_DIR3_DATA_ENTSIZE(2));
335 static struct xfs_dir2_data_entry *
336 xfs_dir3_data_dot_entry_p(
337 struct xfs_dir2_data_hdr *hdr)
339 return (struct xfs_dir2_data_entry *)
340 ((char *)hdr + sizeof(struct xfs_dir3_data_hdr));
343 static struct xfs_dir2_data_entry *
344 xfs_dir3_data_dotdot_entry_p(
345 struct xfs_dir2_data_hdr *hdr)
347 return (struct xfs_dir2_data_entry *)
348 ((char *)hdr + sizeof(struct xfs_dir3_data_hdr) +
349 XFS_DIR3_DATA_ENTSIZE(1));
352 static struct xfs_dir2_data_entry *
353 xfs_dir3_data_first_entry_p(
354 struct xfs_dir2_data_hdr *hdr)
356 return (struct xfs_dir2_data_entry *)
357 ((char *)hdr + sizeof(struct xfs_dir3_data_hdr) +
358 XFS_DIR3_DATA_ENTSIZE(1) +
359 XFS_DIR3_DATA_ENTSIZE(2));
362 static struct xfs_dir2_data_free *
363 xfs_dir2_data_bestfree_p(struct xfs_dir2_data_hdr *hdr)
365 return hdr->bestfree;
368 static struct xfs_dir2_data_free *
369 xfs_dir3_data_bestfree_p(struct xfs_dir2_data_hdr *hdr)
371 return ((struct xfs_dir3_data_hdr *)hdr)->best_free;
374 static struct xfs_dir2_data_entry *
375 xfs_dir2_data_entry_p(struct xfs_dir2_data_hdr *hdr)
377 return (struct xfs_dir2_data_entry *)
378 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr));
381 static struct xfs_dir2_data_unused *
382 xfs_dir2_data_unused_p(struct xfs_dir2_data_hdr *hdr)
384 return (struct xfs_dir2_data_unused *)
385 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr));
388 static struct xfs_dir2_data_entry *
389 xfs_dir3_data_entry_p(struct xfs_dir2_data_hdr *hdr)
391 return (struct xfs_dir2_data_entry *)
392 ((char *)hdr + sizeof(struct xfs_dir3_data_hdr));
395 static struct xfs_dir2_data_unused *
396 xfs_dir3_data_unused_p(struct xfs_dir2_data_hdr *hdr)
398 return (struct xfs_dir2_data_unused *)
399 ((char *)hdr + sizeof(struct xfs_dir3_data_hdr));
404 * Directory Leaf block operations
407 xfs_dir2_max_leaf_ents(struct xfs_da_geometry *geo)
409 return (geo->blksize - sizeof(struct xfs_dir2_leaf_hdr)) /
410 (uint)sizeof(struct xfs_dir2_leaf_entry);
413 static struct xfs_dir2_leaf_entry *
414 xfs_dir2_leaf_ents_p(struct xfs_dir2_leaf *lp)
420 xfs_dir3_max_leaf_ents(struct xfs_da_geometry *geo)
422 return (geo->blksize - sizeof(struct xfs_dir3_leaf_hdr)) /
423 (uint)sizeof(struct xfs_dir2_leaf_entry);
426 static struct xfs_dir2_leaf_entry *
427 xfs_dir3_leaf_ents_p(struct xfs_dir2_leaf *lp)
429 return ((struct xfs_dir3_leaf *)lp)->__ents;
433 xfs_dir2_leaf_hdr_from_disk(
434 struct xfs_dir3_icleaf_hdr *to,
435 struct xfs_dir2_leaf *from)
437 to->forw = be32_to_cpu(from->hdr.info.forw);
438 to->back = be32_to_cpu(from->hdr.info.back);
439 to->magic = be16_to_cpu(from->hdr.info.magic);
440 to->count = be16_to_cpu(from->hdr.count);
441 to->stale = be16_to_cpu(from->hdr.stale);
443 ASSERT(to->magic == XFS_DIR2_LEAF1_MAGIC ||
444 to->magic == XFS_DIR2_LEAFN_MAGIC);
448 xfs_dir2_leaf_hdr_to_disk(
449 struct xfs_dir2_leaf *to,
450 struct xfs_dir3_icleaf_hdr *from)
452 ASSERT(from->magic == XFS_DIR2_LEAF1_MAGIC ||
453 from->magic == XFS_DIR2_LEAFN_MAGIC);
455 to->hdr.info.forw = cpu_to_be32(from->forw);
456 to->hdr.info.back = cpu_to_be32(from->back);
457 to->hdr.info.magic = cpu_to_be16(from->magic);
458 to->hdr.count = cpu_to_be16(from->count);
459 to->hdr.stale = cpu_to_be16(from->stale);
463 xfs_dir3_leaf_hdr_from_disk(
464 struct xfs_dir3_icleaf_hdr *to,
465 struct xfs_dir2_leaf *from)
467 struct xfs_dir3_leaf_hdr *hdr3 = (struct xfs_dir3_leaf_hdr *)from;
469 to->forw = be32_to_cpu(hdr3->info.hdr.forw);
470 to->back = be32_to_cpu(hdr3->info.hdr.back);
471 to->magic = be16_to_cpu(hdr3->info.hdr.magic);
472 to->count = be16_to_cpu(hdr3->count);
473 to->stale = be16_to_cpu(hdr3->stale);
475 ASSERT(to->magic == XFS_DIR3_LEAF1_MAGIC ||
476 to->magic == XFS_DIR3_LEAFN_MAGIC);
480 xfs_dir3_leaf_hdr_to_disk(
481 struct xfs_dir2_leaf *to,
482 struct xfs_dir3_icleaf_hdr *from)
484 struct xfs_dir3_leaf_hdr *hdr3 = (struct xfs_dir3_leaf_hdr *)to;
486 ASSERT(from->magic == XFS_DIR3_LEAF1_MAGIC ||
487 from->magic == XFS_DIR3_LEAFN_MAGIC);
489 hdr3->info.hdr.forw = cpu_to_be32(from->forw);
490 hdr3->info.hdr.back = cpu_to_be32(from->back);
491 hdr3->info.hdr.magic = cpu_to_be16(from->magic);
492 hdr3->count = cpu_to_be16(from->count);
493 hdr3->stale = cpu_to_be16(from->stale);
498 * Directory/Attribute Node block operations
500 static struct xfs_da_node_entry *
501 xfs_da2_node_tree_p(struct xfs_da_intnode *dap)
506 static struct xfs_da_node_entry *
507 xfs_da3_node_tree_p(struct xfs_da_intnode *dap)
509 return ((struct xfs_da3_intnode *)dap)->__btree;
513 xfs_da2_node_hdr_from_disk(
514 struct xfs_da3_icnode_hdr *to,
515 struct xfs_da_intnode *from)
517 ASSERT(from->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC));
518 to->forw = be32_to_cpu(from->hdr.info.forw);
519 to->back = be32_to_cpu(from->hdr.info.back);
520 to->magic = be16_to_cpu(from->hdr.info.magic);
521 to->count = be16_to_cpu(from->hdr.__count);
522 to->level = be16_to_cpu(from->hdr.__level);
526 xfs_da2_node_hdr_to_disk(
527 struct xfs_da_intnode *to,
528 struct xfs_da3_icnode_hdr *from)
530 ASSERT(from->magic == XFS_DA_NODE_MAGIC);
531 to->hdr.info.forw = cpu_to_be32(from->forw);
532 to->hdr.info.back = cpu_to_be32(from->back);
533 to->hdr.info.magic = cpu_to_be16(from->magic);
534 to->hdr.__count = cpu_to_be16(from->count);
535 to->hdr.__level = cpu_to_be16(from->level);
539 xfs_da3_node_hdr_from_disk(
540 struct xfs_da3_icnode_hdr *to,
541 struct xfs_da_intnode *from)
543 struct xfs_da3_node_hdr *hdr3 = (struct xfs_da3_node_hdr *)from;
545 ASSERT(from->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC));
546 to->forw = be32_to_cpu(hdr3->info.hdr.forw);
547 to->back = be32_to_cpu(hdr3->info.hdr.back);
548 to->magic = be16_to_cpu(hdr3->info.hdr.magic);
549 to->count = be16_to_cpu(hdr3->__count);
550 to->level = be16_to_cpu(hdr3->__level);
554 xfs_da3_node_hdr_to_disk(
555 struct xfs_da_intnode *to,
556 struct xfs_da3_icnode_hdr *from)
558 struct xfs_da3_node_hdr *hdr3 = (struct xfs_da3_node_hdr *)to;
560 ASSERT(from->magic == XFS_DA3_NODE_MAGIC);
561 hdr3->info.hdr.forw = cpu_to_be32(from->forw);
562 hdr3->info.hdr.back = cpu_to_be32(from->back);
563 hdr3->info.hdr.magic = cpu_to_be16(from->magic);
564 hdr3->__count = cpu_to_be16(from->count);
565 hdr3->__level = cpu_to_be16(from->level);
570 * Directory free space block operations
573 xfs_dir2_free_max_bests(struct xfs_da_geometry *geo)
575 return (geo->blksize - sizeof(struct xfs_dir2_free_hdr)) /
576 sizeof(xfs_dir2_data_off_t);
580 xfs_dir2_free_bests_p(struct xfs_dir2_free *free)
582 return (__be16 *)((char *)free + sizeof(struct xfs_dir2_free_hdr));
586 * Convert data space db to the corresponding free db.
589 xfs_dir2_db_to_fdb(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
591 return xfs_dir2_byte_to_db(geo, XFS_DIR2_FREE_OFFSET) +
592 (db / xfs_dir2_free_max_bests(geo));
596 * Convert data space db to the corresponding index in a free db.
599 xfs_dir2_db_to_fdindex(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
601 return db % xfs_dir2_free_max_bests(geo);
605 xfs_dir3_free_max_bests(struct xfs_da_geometry *geo)
607 return (geo->blksize - sizeof(struct xfs_dir3_free_hdr)) /
608 sizeof(xfs_dir2_data_off_t);
612 xfs_dir3_free_bests_p(struct xfs_dir2_free *free)
614 return (__be16 *)((char *)free + sizeof(struct xfs_dir3_free_hdr));
618 * Convert data space db to the corresponding free db.
621 xfs_dir3_db_to_fdb(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
623 return xfs_dir2_byte_to_db(geo, XFS_DIR2_FREE_OFFSET) +
624 (db / xfs_dir3_free_max_bests(geo));
628 * Convert data space db to the corresponding index in a free db.
631 xfs_dir3_db_to_fdindex(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
633 return db % xfs_dir3_free_max_bests(geo);
637 xfs_dir2_free_hdr_from_disk(
638 struct xfs_dir3_icfree_hdr *to,
639 struct xfs_dir2_free *from)
641 to->magic = be32_to_cpu(from->hdr.magic);
642 to->firstdb = be32_to_cpu(from->hdr.firstdb);
643 to->nvalid = be32_to_cpu(from->hdr.nvalid);
644 to->nused = be32_to_cpu(from->hdr.nused);
645 ASSERT(to->magic == XFS_DIR2_FREE_MAGIC);
649 xfs_dir2_free_hdr_to_disk(
650 struct xfs_dir2_free *to,
651 struct xfs_dir3_icfree_hdr *from)
653 ASSERT(from->magic == XFS_DIR2_FREE_MAGIC);
655 to->hdr.magic = cpu_to_be32(from->magic);
656 to->hdr.firstdb = cpu_to_be32(from->firstdb);
657 to->hdr.nvalid = cpu_to_be32(from->nvalid);
658 to->hdr.nused = cpu_to_be32(from->nused);
662 xfs_dir3_free_hdr_from_disk(
663 struct xfs_dir3_icfree_hdr *to,
664 struct xfs_dir2_free *from)
666 struct xfs_dir3_free_hdr *hdr3 = (struct xfs_dir3_free_hdr *)from;
668 to->magic = be32_to_cpu(hdr3->hdr.magic);
669 to->firstdb = be32_to_cpu(hdr3->firstdb);
670 to->nvalid = be32_to_cpu(hdr3->nvalid);
671 to->nused = be32_to_cpu(hdr3->nused);
673 ASSERT(to->magic == XFS_DIR3_FREE_MAGIC);
677 xfs_dir3_free_hdr_to_disk(
678 struct xfs_dir2_free *to,
679 struct xfs_dir3_icfree_hdr *from)
681 struct xfs_dir3_free_hdr *hdr3 = (struct xfs_dir3_free_hdr *)to;
683 ASSERT(from->magic == XFS_DIR3_FREE_MAGIC);
685 hdr3->hdr.magic = cpu_to_be32(from->magic);
686 hdr3->firstdb = cpu_to_be32(from->firstdb);
687 hdr3->nvalid = cpu_to_be32(from->nvalid);
688 hdr3->nused = cpu_to_be32(from->nused);
691 static const struct xfs_dir_ops xfs_dir2_ops = {
692 .sf_entsize = xfs_dir2_sf_entsize,
693 .sf_nextentry = xfs_dir2_sf_nextentry,
694 .sf_get_ftype = xfs_dir2_sfe_get_ftype,
695 .sf_put_ftype = xfs_dir2_sfe_put_ftype,
696 .sf_get_ino = xfs_dir2_sfe_get_ino,
697 .sf_put_ino = xfs_dir2_sfe_put_ino,
698 .sf_get_parent_ino = xfs_dir2_sf_get_parent_ino,
699 .sf_put_parent_ino = xfs_dir2_sf_put_parent_ino,
701 .data_entsize = xfs_dir2_data_entsize,
702 .data_get_ftype = xfs_dir2_data_get_ftype,
703 .data_put_ftype = xfs_dir2_data_put_ftype,
704 .data_entry_tag_p = xfs_dir2_data_entry_tag_p,
705 .data_bestfree_p = xfs_dir2_data_bestfree_p,
707 .data_dot_offset = sizeof(struct xfs_dir2_data_hdr),
708 .data_dotdot_offset = sizeof(struct xfs_dir2_data_hdr) +
709 XFS_DIR2_DATA_ENTSIZE(1),
710 .data_first_offset = sizeof(struct xfs_dir2_data_hdr) +
711 XFS_DIR2_DATA_ENTSIZE(1) +
712 XFS_DIR2_DATA_ENTSIZE(2),
713 .data_entry_offset = sizeof(struct xfs_dir2_data_hdr),
715 .data_dot_entry_p = xfs_dir2_data_dot_entry_p,
716 .data_dotdot_entry_p = xfs_dir2_data_dotdot_entry_p,
717 .data_first_entry_p = xfs_dir2_data_first_entry_p,
718 .data_entry_p = xfs_dir2_data_entry_p,
719 .data_unused_p = xfs_dir2_data_unused_p,
721 .leaf_hdr_size = sizeof(struct xfs_dir2_leaf_hdr),
722 .leaf_hdr_to_disk = xfs_dir2_leaf_hdr_to_disk,
723 .leaf_hdr_from_disk = xfs_dir2_leaf_hdr_from_disk,
724 .leaf_max_ents = xfs_dir2_max_leaf_ents,
725 .leaf_ents_p = xfs_dir2_leaf_ents_p,
727 .node_hdr_size = sizeof(struct xfs_da_node_hdr),
728 .node_hdr_to_disk = xfs_da2_node_hdr_to_disk,
729 .node_hdr_from_disk = xfs_da2_node_hdr_from_disk,
730 .node_tree_p = xfs_da2_node_tree_p,
732 .free_hdr_size = sizeof(struct xfs_dir2_free_hdr),
733 .free_hdr_to_disk = xfs_dir2_free_hdr_to_disk,
734 .free_hdr_from_disk = xfs_dir2_free_hdr_from_disk,
735 .free_max_bests = xfs_dir2_free_max_bests,
736 .free_bests_p = xfs_dir2_free_bests_p,
737 .db_to_fdb = xfs_dir2_db_to_fdb,
738 .db_to_fdindex = xfs_dir2_db_to_fdindex,
741 static const struct xfs_dir_ops xfs_dir2_ftype_ops = {
742 .sf_entsize = xfs_dir3_sf_entsize,
743 .sf_nextentry = xfs_dir3_sf_nextentry,
744 .sf_get_ftype = xfs_dir3_sfe_get_ftype,
745 .sf_put_ftype = xfs_dir3_sfe_put_ftype,
746 .sf_get_ino = xfs_dir3_sfe_get_ino,
747 .sf_put_ino = xfs_dir3_sfe_put_ino,
748 .sf_get_parent_ino = xfs_dir2_sf_get_parent_ino,
749 .sf_put_parent_ino = xfs_dir2_sf_put_parent_ino,
751 .data_entsize = xfs_dir3_data_entsize,
752 .data_get_ftype = xfs_dir3_data_get_ftype,
753 .data_put_ftype = xfs_dir3_data_put_ftype,
754 .data_entry_tag_p = xfs_dir3_data_entry_tag_p,
755 .data_bestfree_p = xfs_dir2_data_bestfree_p,
757 .data_dot_offset = sizeof(struct xfs_dir2_data_hdr),
758 .data_dotdot_offset = sizeof(struct xfs_dir2_data_hdr) +
759 XFS_DIR3_DATA_ENTSIZE(1),
760 .data_first_offset = sizeof(struct xfs_dir2_data_hdr) +
761 XFS_DIR3_DATA_ENTSIZE(1) +
762 XFS_DIR3_DATA_ENTSIZE(2),
763 .data_entry_offset = sizeof(struct xfs_dir2_data_hdr),
765 .data_dot_entry_p = xfs_dir2_data_dot_entry_p,
766 .data_dotdot_entry_p = xfs_dir2_ftype_data_dotdot_entry_p,
767 .data_first_entry_p = xfs_dir2_ftype_data_first_entry_p,
768 .data_entry_p = xfs_dir2_data_entry_p,
769 .data_unused_p = xfs_dir2_data_unused_p,
771 .leaf_hdr_size = sizeof(struct xfs_dir2_leaf_hdr),
772 .leaf_hdr_to_disk = xfs_dir2_leaf_hdr_to_disk,
773 .leaf_hdr_from_disk = xfs_dir2_leaf_hdr_from_disk,
774 .leaf_max_ents = xfs_dir2_max_leaf_ents,
775 .leaf_ents_p = xfs_dir2_leaf_ents_p,
777 .node_hdr_size = sizeof(struct xfs_da_node_hdr),
778 .node_hdr_to_disk = xfs_da2_node_hdr_to_disk,
779 .node_hdr_from_disk = xfs_da2_node_hdr_from_disk,
780 .node_tree_p = xfs_da2_node_tree_p,
782 .free_hdr_size = sizeof(struct xfs_dir2_free_hdr),
783 .free_hdr_to_disk = xfs_dir2_free_hdr_to_disk,
784 .free_hdr_from_disk = xfs_dir2_free_hdr_from_disk,
785 .free_max_bests = xfs_dir2_free_max_bests,
786 .free_bests_p = xfs_dir2_free_bests_p,
787 .db_to_fdb = xfs_dir2_db_to_fdb,
788 .db_to_fdindex = xfs_dir2_db_to_fdindex,
791 static const struct xfs_dir_ops xfs_dir3_ops = {
792 .sf_entsize = xfs_dir3_sf_entsize,
793 .sf_nextentry = xfs_dir3_sf_nextentry,
794 .sf_get_ftype = xfs_dir3_sfe_get_ftype,
795 .sf_put_ftype = xfs_dir3_sfe_put_ftype,
796 .sf_get_ino = xfs_dir3_sfe_get_ino,
797 .sf_put_ino = xfs_dir3_sfe_put_ino,
798 .sf_get_parent_ino = xfs_dir2_sf_get_parent_ino,
799 .sf_put_parent_ino = xfs_dir2_sf_put_parent_ino,
801 .data_entsize = xfs_dir3_data_entsize,
802 .data_get_ftype = xfs_dir3_data_get_ftype,
803 .data_put_ftype = xfs_dir3_data_put_ftype,
804 .data_entry_tag_p = xfs_dir3_data_entry_tag_p,
805 .data_bestfree_p = xfs_dir3_data_bestfree_p,
807 .data_dot_offset = sizeof(struct xfs_dir3_data_hdr),
808 .data_dotdot_offset = sizeof(struct xfs_dir3_data_hdr) +
809 XFS_DIR3_DATA_ENTSIZE(1),
810 .data_first_offset = sizeof(struct xfs_dir3_data_hdr) +
811 XFS_DIR3_DATA_ENTSIZE(1) +
812 XFS_DIR3_DATA_ENTSIZE(2),
813 .data_entry_offset = sizeof(struct xfs_dir3_data_hdr),
815 .data_dot_entry_p = xfs_dir3_data_dot_entry_p,
816 .data_dotdot_entry_p = xfs_dir3_data_dotdot_entry_p,
817 .data_first_entry_p = xfs_dir3_data_first_entry_p,
818 .data_entry_p = xfs_dir3_data_entry_p,
819 .data_unused_p = xfs_dir3_data_unused_p,
821 .leaf_hdr_size = sizeof(struct xfs_dir3_leaf_hdr),
822 .leaf_hdr_to_disk = xfs_dir3_leaf_hdr_to_disk,
823 .leaf_hdr_from_disk = xfs_dir3_leaf_hdr_from_disk,
824 .leaf_max_ents = xfs_dir3_max_leaf_ents,
825 .leaf_ents_p = xfs_dir3_leaf_ents_p,
827 .node_hdr_size = sizeof(struct xfs_da3_node_hdr),
828 .node_hdr_to_disk = xfs_da3_node_hdr_to_disk,
829 .node_hdr_from_disk = xfs_da3_node_hdr_from_disk,
830 .node_tree_p = xfs_da3_node_tree_p,
832 .free_hdr_size = sizeof(struct xfs_dir3_free_hdr),
833 .free_hdr_to_disk = xfs_dir3_free_hdr_to_disk,
834 .free_hdr_from_disk = xfs_dir3_free_hdr_from_disk,
835 .free_max_bests = xfs_dir3_free_max_bests,
836 .free_bests_p = xfs_dir3_free_bests_p,
837 .db_to_fdb = xfs_dir3_db_to_fdb,
838 .db_to_fdindex = xfs_dir3_db_to_fdindex,
841 static const struct xfs_dir_ops xfs_dir2_nondir_ops = {
842 .node_hdr_size = sizeof(struct xfs_da_node_hdr),
843 .node_hdr_to_disk = xfs_da2_node_hdr_to_disk,
844 .node_hdr_from_disk = xfs_da2_node_hdr_from_disk,
845 .node_tree_p = xfs_da2_node_tree_p,
848 static const struct xfs_dir_ops xfs_dir3_nondir_ops = {
849 .node_hdr_size = sizeof(struct xfs_da3_node_hdr),
850 .node_hdr_to_disk = xfs_da3_node_hdr_to_disk,
851 .node_hdr_from_disk = xfs_da3_node_hdr_from_disk,
852 .node_tree_p = xfs_da3_node_tree_p,
856 * Return the ops structure according to the current config. If we are passed
857 * an inode, then that overrides the default config we use which is based on
860 const struct xfs_dir_ops *
862 struct xfs_mount *mp,
863 struct xfs_inode *dp)
867 if (mp->m_dir_inode_ops)
868 return mp->m_dir_inode_ops;
869 if (xfs_sb_version_hascrc(&mp->m_sb))
870 return &xfs_dir3_ops;
871 if (xfs_sb_version_hasftype(&mp->m_sb))
872 return &xfs_dir2_ftype_ops;
873 return &xfs_dir2_ops;
876 const struct xfs_dir_ops *
878 struct xfs_mount *mp,
879 struct xfs_inode *dp)
883 if (mp->m_nondir_inode_ops)
884 return mp->m_nondir_inode_ops;
885 if (xfs_sb_version_hascrc(&mp->m_sb))
886 return &xfs_dir3_nondir_ops;
887 return &xfs_dir2_nondir_ops;