2 * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
3 * Copyright (c) 2013 Red Hat, Inc.
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.
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.
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
21 #include "xfs_format.h"
22 #include "xfs_log_format.h"
23 #include "xfs_trans_resv.h"
26 #include "xfs_mount.h"
27 #include "xfs_da_format.h"
28 #include "xfs_inode.h"
32 * Shortform directory ops
36 struct xfs_dir2_sf_hdr *hdr,
39 int count = sizeof(struct xfs_dir2_sf_entry); /* namelen + offset */
41 count += len; /* name */
42 count += hdr->i8count ? sizeof(xfs_dir2_ino8_t) :
43 sizeof(xfs_dir2_ino4_t); /* ino # */
49 struct xfs_dir2_sf_hdr *hdr,
52 return xfs_dir2_sf_entsize(hdr, len) + sizeof(__uint8_t);
55 static struct xfs_dir2_sf_entry *
56 xfs_dir2_sf_nextentry(
57 struct xfs_dir2_sf_hdr *hdr,
58 struct xfs_dir2_sf_entry *sfep)
60 return (struct xfs_dir2_sf_entry *)
61 ((char *)sfep + xfs_dir2_sf_entsize(hdr, sfep->namelen));
64 static struct xfs_dir2_sf_entry *
65 xfs_dir3_sf_nextentry(
66 struct xfs_dir2_sf_hdr *hdr,
67 struct xfs_dir2_sf_entry *sfep)
69 return (struct xfs_dir2_sf_entry *)
70 ((char *)sfep + xfs_dir3_sf_entsize(hdr, sfep->namelen));
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.
81 xfs_dir2_sfe_get_ftype(
82 struct xfs_dir2_sf_entry *sfep)
84 return XFS_DIR3_FT_UNKNOWN;
88 xfs_dir2_sfe_put_ftype(
89 struct xfs_dir2_sf_entry *sfep,
92 ASSERT(ftype < XFS_DIR3_FT_MAX);
96 xfs_dir3_sfe_get_ftype(
97 struct xfs_dir2_sf_entry *sfep)
101 ftype = sfep->name[sfep->namelen];
102 if (ftype >= XFS_DIR3_FT_MAX)
103 return XFS_DIR3_FT_UNKNOWN;
108 xfs_dir3_sfe_put_ftype(
109 struct xfs_dir2_sf_entry *sfep,
112 ASSERT(ftype < XFS_DIR3_FT_MAX);
114 sfep->name[sfep->namelen] = ftype;
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.
122 * For 64-bit inode number the most significant byte must be zero.
126 struct xfs_dir2_sf_hdr *hdr,
127 xfs_dir2_inou_t *from)
130 return get_unaligned_be64(&from->i8.i) & 0x00ffffffffffffffULL;
132 return get_unaligned_be32(&from->i4.i);
137 struct xfs_dir2_sf_hdr *hdr,
141 ASSERT((ino & 0xff00000000000000ULL) == 0);
144 put_unaligned_be64(ino, &to->i8.i);
146 put_unaligned_be32(ino, &to->i4.i);
150 xfs_dir2_sf_get_parent_ino(
151 struct xfs_dir2_sf_hdr *hdr)
153 return xfs_dir2_sf_get_ino(hdr, &hdr->parent);
157 xfs_dir2_sf_put_parent_ino(
158 struct xfs_dir2_sf_hdr *hdr,
161 xfs_dir2_sf_put_ino(hdr, &hdr->parent, ino);
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.
171 xfs_dir2_sfe_get_ino(
172 struct xfs_dir2_sf_hdr *hdr,
173 struct xfs_dir2_sf_entry *sfep)
175 return xfs_dir2_sf_get_ino(hdr,
176 (xfs_dir2_inou_t *)&sfep->name[sfep->namelen]);
180 xfs_dir2_sfe_put_ino(
181 struct xfs_dir2_sf_hdr *hdr,
182 struct xfs_dir2_sf_entry *sfep,
185 xfs_dir2_sf_put_ino(hdr,
186 (xfs_dir2_inou_t *)&sfep->name[sfep->namelen], ino);
190 xfs_dir3_sfe_get_ino(
191 struct xfs_dir2_sf_hdr *hdr,
192 struct xfs_dir2_sf_entry *sfep)
194 return xfs_dir2_sf_get_ino(hdr,
195 (xfs_dir2_inou_t *)&sfep->name[sfep->namelen + 1]);
199 xfs_dir3_sfe_put_ino(
200 struct xfs_dir2_sf_hdr *hdr,
201 struct xfs_dir2_sf_entry *sfep,
204 xfs_dir2_sf_put_ino(hdr,
205 (xfs_dir2_inou_t *)&sfep->name[sfep->namelen + 1], ino);
210 * Directory data block operations
213 __xfs_dir3_data_entsize(
217 int size = offsetof(struct xfs_dir2_data_entry, name[0]);
220 size += sizeof(xfs_dir2_data_off_t);
222 size += sizeof(__uint8_t);
223 return roundup(size, XFS_DIR2_DATA_ALIGN);
227 xfs_dir2_data_entsize(
230 return __xfs_dir3_data_entsize(false, n);
233 xfs_dir3_data_entsize(
236 return __xfs_dir3_data_entsize(true, n);
240 xfs_dir2_data_get_ftype(
241 struct xfs_dir2_data_entry *dep)
243 return XFS_DIR3_FT_UNKNOWN;
247 xfs_dir2_data_put_ftype(
248 struct xfs_dir2_data_entry *dep,
251 ASSERT(ftype < XFS_DIR3_FT_MAX);
255 xfs_dir3_data_get_ftype(
256 struct xfs_dir2_data_entry *dep)
258 __uint8_t ftype = dep->name[dep->namelen];
260 ASSERT(ftype < XFS_DIR3_FT_MAX);
261 if (ftype >= XFS_DIR3_FT_MAX)
262 return XFS_DIR3_FT_UNKNOWN;
267 xfs_dir3_data_put_ftype(
268 struct xfs_dir2_data_entry *dep,
271 ASSERT(type < XFS_DIR3_FT_MAX);
272 ASSERT(dep->namelen != 0);
274 dep->name[dep->namelen] = type;
278 * Pointer to an entry's tag word.
281 xfs_dir2_data_entry_tag_p(
282 struct xfs_dir2_data_entry *dep)
284 return (__be16 *)((char *)dep +
285 xfs_dir2_data_entsize(dep->namelen) - sizeof(__be16));
289 xfs_dir3_data_entry_tag_p(
290 struct xfs_dir2_data_entry *dep)
292 return (__be16 *)((char *)dep +
293 xfs_dir3_data_entsize(dep->namelen) - sizeof(__be16));
297 * Offsets of . and .. in data space (always block 0)
299 static xfs_dir2_data_aoff_t
300 xfs_dir2_data_dot_offset(void)
302 return sizeof(struct xfs_dir2_data_hdr);
305 static xfs_dir2_data_aoff_t
306 xfs_dir2_data_dotdot_offset(void)
308 return xfs_dir2_data_dot_offset() + xfs_dir2_data_entsize(1);
311 static xfs_dir2_data_aoff_t
312 xfs_dir2_data_first_offset(void)
314 return xfs_dir2_data_dotdot_offset() + xfs_dir2_data_entsize(2);
317 static xfs_dir2_data_aoff_t
318 xfs_dir3_data_dot_offset(void)
320 return sizeof(struct xfs_dir3_data_hdr);
323 static xfs_dir2_data_aoff_t
324 xfs_dir3_data_dotdot_offset(void)
326 return xfs_dir3_data_dot_offset() + xfs_dir3_data_entsize(1);
329 static xfs_dir2_data_aoff_t
330 xfs_dir3_data_first_offset(void)
332 return xfs_dir3_data_dotdot_offset() + xfs_dir3_data_entsize(2);
336 * location of . and .. in data space (always block 0)
338 static struct xfs_dir2_data_entry *
339 xfs_dir2_data_dot_entry_p(
340 struct xfs_dir2_data_hdr *hdr)
342 return (struct xfs_dir2_data_entry *)
343 ((char *)hdr + xfs_dir2_data_dot_offset());
346 static struct xfs_dir2_data_entry *
347 xfs_dir2_data_dotdot_entry_p(
348 struct xfs_dir2_data_hdr *hdr)
350 return (struct xfs_dir2_data_entry *)
351 ((char *)hdr + xfs_dir2_data_dotdot_offset());
354 static struct xfs_dir2_data_entry *
355 xfs_dir2_data_first_entry_p(
356 struct xfs_dir2_data_hdr *hdr)
358 return (struct xfs_dir2_data_entry *)
359 ((char *)hdr + xfs_dir2_data_first_offset());
362 static struct xfs_dir2_data_entry *
363 xfs_dir3_data_dot_entry_p(
364 struct xfs_dir2_data_hdr *hdr)
366 return (struct xfs_dir2_data_entry *)
367 ((char *)hdr + xfs_dir3_data_dot_offset());
370 static struct xfs_dir2_data_entry *
371 xfs_dir3_data_dotdot_entry_p(
372 struct xfs_dir2_data_hdr *hdr)
374 return (struct xfs_dir2_data_entry *)
375 ((char *)hdr + xfs_dir3_data_dotdot_offset());
378 static struct xfs_dir2_data_entry *
379 xfs_dir3_data_first_entry_p(
380 struct xfs_dir2_data_hdr *hdr)
382 return (struct xfs_dir2_data_entry *)
383 ((char *)hdr + xfs_dir3_data_first_offset());
386 static struct xfs_dir2_data_free *
387 xfs_dir2_data_bestfree_p(struct xfs_dir2_data_hdr *hdr)
389 return hdr->bestfree;
392 static struct xfs_dir2_data_free *
393 xfs_dir3_data_bestfree_p(struct xfs_dir2_data_hdr *hdr)
395 return ((struct xfs_dir3_data_hdr *)hdr)->best_free;
399 xfs_dir2_data_entry_offset(void)
401 return sizeof(struct xfs_dir2_data_hdr);
404 static struct xfs_dir2_data_entry *
405 xfs_dir2_data_entry_p(struct xfs_dir2_data_hdr *hdr)
407 return (struct xfs_dir2_data_entry *)
408 ((char *)hdr + xfs_dir2_data_entry_offset());
411 static struct xfs_dir2_data_unused *
412 xfs_dir2_data_unused_p(struct xfs_dir2_data_hdr *hdr)
414 return (struct xfs_dir2_data_unused *)
415 ((char *)hdr + xfs_dir2_data_entry_offset());
419 xfs_dir3_data_entry_offset(void)
421 return sizeof(struct xfs_dir3_data_hdr);
424 static struct xfs_dir2_data_entry *
425 xfs_dir3_data_entry_p(struct xfs_dir2_data_hdr *hdr)
427 return (struct xfs_dir2_data_entry *)
428 ((char *)hdr + xfs_dir3_data_entry_offset());
431 static struct xfs_dir2_data_unused *
432 xfs_dir3_data_unused_p(struct xfs_dir2_data_hdr *hdr)
434 return (struct xfs_dir2_data_unused *)
435 ((char *)hdr + xfs_dir3_data_entry_offset());
440 * Directory Leaf block operations
443 xfs_dir2_leaf_hdr_size(void)
445 return sizeof(struct xfs_dir2_leaf_hdr);
449 xfs_dir2_max_leaf_ents(struct xfs_mount *mp)
451 return (mp->m_dirblksize - xfs_dir2_leaf_hdr_size()) /
452 (uint)sizeof(struct xfs_dir2_leaf_entry);
455 static struct xfs_dir2_leaf_entry *
456 xfs_dir2_leaf_ents_p(struct xfs_dir2_leaf *lp)
462 xfs_dir3_leaf_hdr_size(void)
464 return sizeof(struct xfs_dir3_leaf_hdr);
468 xfs_dir3_max_leaf_ents(struct xfs_mount *mp)
470 return (mp->m_dirblksize - xfs_dir3_leaf_hdr_size()) /
471 (uint)sizeof(struct xfs_dir2_leaf_entry);
474 static struct xfs_dir2_leaf_entry *
475 xfs_dir3_leaf_ents_p(struct xfs_dir2_leaf *lp)
477 return ((struct xfs_dir3_leaf *)lp)->__ents;
481 xfs_dir2_leaf_hdr_from_disk(
482 struct xfs_dir3_icleaf_hdr *to,
483 struct xfs_dir2_leaf *from)
485 to->forw = be32_to_cpu(from->hdr.info.forw);
486 to->back = be32_to_cpu(from->hdr.info.back);
487 to->magic = be16_to_cpu(from->hdr.info.magic);
488 to->count = be16_to_cpu(from->hdr.count);
489 to->stale = be16_to_cpu(from->hdr.stale);
491 ASSERT(to->magic == XFS_DIR2_LEAF1_MAGIC ||
492 to->magic == XFS_DIR2_LEAFN_MAGIC);
496 xfs_dir2_leaf_hdr_to_disk(
497 struct xfs_dir2_leaf *to,
498 struct xfs_dir3_icleaf_hdr *from)
500 ASSERT(from->magic == XFS_DIR2_LEAF1_MAGIC ||
501 from->magic == XFS_DIR2_LEAFN_MAGIC);
503 to->hdr.info.forw = cpu_to_be32(from->forw);
504 to->hdr.info.back = cpu_to_be32(from->back);
505 to->hdr.info.magic = cpu_to_be16(from->magic);
506 to->hdr.count = cpu_to_be16(from->count);
507 to->hdr.stale = cpu_to_be16(from->stale);
511 xfs_dir3_leaf_hdr_from_disk(
512 struct xfs_dir3_icleaf_hdr *to,
513 struct xfs_dir2_leaf *from)
515 struct xfs_dir3_leaf_hdr *hdr3 = (struct xfs_dir3_leaf_hdr *)from;
517 to->forw = be32_to_cpu(hdr3->info.hdr.forw);
518 to->back = be32_to_cpu(hdr3->info.hdr.back);
519 to->magic = be16_to_cpu(hdr3->info.hdr.magic);
520 to->count = be16_to_cpu(hdr3->count);
521 to->stale = be16_to_cpu(hdr3->stale);
523 ASSERT(to->magic == XFS_DIR3_LEAF1_MAGIC ||
524 to->magic == XFS_DIR3_LEAFN_MAGIC);
528 xfs_dir3_leaf_hdr_to_disk(
529 struct xfs_dir2_leaf *to,
530 struct xfs_dir3_icleaf_hdr *from)
532 struct xfs_dir3_leaf_hdr *hdr3 = (struct xfs_dir3_leaf_hdr *)to;
534 ASSERT(from->magic == XFS_DIR3_LEAF1_MAGIC ||
535 from->magic == XFS_DIR3_LEAFN_MAGIC);
537 hdr3->info.hdr.forw = cpu_to_be32(from->forw);
538 hdr3->info.hdr.back = cpu_to_be32(from->back);
539 hdr3->info.hdr.magic = cpu_to_be16(from->magic);
540 hdr3->count = cpu_to_be16(from->count);
541 hdr3->stale = cpu_to_be16(from->stale);
546 * Directory/Attribute Node block operations
549 xfs_da2_node_hdr_size(void)
551 return sizeof(struct xfs_da_node_hdr);
554 static struct xfs_da_node_entry *
555 xfs_da2_node_tree_p(struct xfs_da_intnode *dap)
561 xfs_da3_node_hdr_size(void)
563 return sizeof(struct xfs_da3_node_hdr);
566 static inline struct xfs_da_node_entry *
567 xfs_da3_node_tree_p(struct xfs_da_intnode *dap)
569 return ((struct xfs_da3_intnode *)dap)->__btree;
573 xfs_da2_node_hdr_from_disk(
574 struct xfs_da3_icnode_hdr *to,
575 struct xfs_da_intnode *from)
577 ASSERT(from->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC));
578 to->forw = be32_to_cpu(from->hdr.info.forw);
579 to->back = be32_to_cpu(from->hdr.info.back);
580 to->magic = be16_to_cpu(from->hdr.info.magic);
581 to->count = be16_to_cpu(from->hdr.__count);
582 to->level = be16_to_cpu(from->hdr.__level);
586 xfs_da2_node_hdr_to_disk(
587 struct xfs_da_intnode *to,
588 struct xfs_da3_icnode_hdr *from)
590 ASSERT(from->magic == XFS_DA_NODE_MAGIC);
591 to->hdr.info.forw = cpu_to_be32(from->forw);
592 to->hdr.info.back = cpu_to_be32(from->back);
593 to->hdr.info.magic = cpu_to_be16(from->magic);
594 to->hdr.__count = cpu_to_be16(from->count);
595 to->hdr.__level = cpu_to_be16(from->level);
599 xfs_da3_node_hdr_from_disk(
600 struct xfs_da3_icnode_hdr *to,
601 struct xfs_da_intnode *from)
603 struct xfs_da3_node_hdr *hdr3 = (struct xfs_da3_node_hdr *)from;
605 ASSERT(from->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC));
606 to->forw = be32_to_cpu(hdr3->info.hdr.forw);
607 to->back = be32_to_cpu(hdr3->info.hdr.back);
608 to->magic = be16_to_cpu(hdr3->info.hdr.magic);
609 to->count = be16_to_cpu(hdr3->__count);
610 to->level = be16_to_cpu(hdr3->__level);
614 xfs_da3_node_hdr_to_disk(
615 struct xfs_da_intnode *to,
616 struct xfs_da3_icnode_hdr *from)
618 struct xfs_da3_node_hdr *hdr3 = (struct xfs_da3_node_hdr *)to;
620 ASSERT(from->magic == XFS_DA3_NODE_MAGIC);
621 hdr3->info.hdr.forw = cpu_to_be32(from->forw);
622 hdr3->info.hdr.back = cpu_to_be32(from->back);
623 hdr3->info.hdr.magic = cpu_to_be16(from->magic);
624 hdr3->__count = cpu_to_be16(from->count);
625 hdr3->__level = cpu_to_be16(from->level);
630 * Directory free space block operations
633 xfs_dir2_free_hdr_from_disk(
634 struct xfs_dir3_icfree_hdr *to,
635 struct xfs_dir2_free *from)
637 to->magic = be32_to_cpu(from->hdr.magic);
638 to->firstdb = be32_to_cpu(from->hdr.firstdb);
639 to->nvalid = be32_to_cpu(from->hdr.nvalid);
640 to->nused = be32_to_cpu(from->hdr.nused);
641 ASSERT(to->magic == XFS_DIR2_FREE_MAGIC);
645 xfs_dir2_free_hdr_to_disk(
646 struct xfs_dir2_free *to,
647 struct xfs_dir3_icfree_hdr *from)
649 ASSERT(from->magic == XFS_DIR2_FREE_MAGIC);
651 to->hdr.magic = cpu_to_be32(from->magic);
652 to->hdr.firstdb = cpu_to_be32(from->firstdb);
653 to->hdr.nvalid = cpu_to_be32(from->nvalid);
654 to->hdr.nused = cpu_to_be32(from->nused);
658 xfs_dir3_free_hdr_from_disk(
659 struct xfs_dir3_icfree_hdr *to,
660 struct xfs_dir2_free *from)
662 struct xfs_dir3_free_hdr *hdr3 = (struct xfs_dir3_free_hdr *)from;
664 to->magic = be32_to_cpu(hdr3->hdr.magic);
665 to->firstdb = be32_to_cpu(hdr3->firstdb);
666 to->nvalid = be32_to_cpu(hdr3->nvalid);
667 to->nused = be32_to_cpu(hdr3->nused);
669 ASSERT(to->magic == XFS_DIR3_FREE_MAGIC);
673 xfs_dir3_free_hdr_to_disk(
674 struct xfs_dir2_free *to,
675 struct xfs_dir3_icfree_hdr *from)
677 struct xfs_dir3_free_hdr *hdr3 = (struct xfs_dir3_free_hdr *)to;
679 ASSERT(from->magic == XFS_DIR3_FREE_MAGIC);
681 hdr3->hdr.magic = cpu_to_be32(from->magic);
682 hdr3->firstdb = cpu_to_be32(from->firstdb);
683 hdr3->nvalid = cpu_to_be32(from->nvalid);
684 hdr3->nused = cpu_to_be32(from->nused);
687 const struct xfs_dir_ops xfs_dir2_ops = {
688 .sf_entsize = xfs_dir2_sf_entsize,
689 .sf_nextentry = xfs_dir2_sf_nextentry,
690 .sf_get_ftype = xfs_dir2_sfe_get_ftype,
691 .sf_put_ftype = xfs_dir2_sfe_put_ftype,
692 .sf_get_ino = xfs_dir2_sfe_get_ino,
693 .sf_put_ino = xfs_dir2_sfe_put_ino,
694 .sf_get_parent_ino = xfs_dir2_sf_get_parent_ino,
695 .sf_put_parent_ino = xfs_dir2_sf_put_parent_ino,
697 .data_entsize = xfs_dir2_data_entsize,
698 .data_get_ftype = xfs_dir2_data_get_ftype,
699 .data_put_ftype = xfs_dir2_data_put_ftype,
700 .data_entry_tag_p = xfs_dir2_data_entry_tag_p,
701 .data_bestfree_p = xfs_dir2_data_bestfree_p,
703 .data_dot_offset = xfs_dir2_data_dot_offset,
704 .data_dotdot_offset = xfs_dir2_data_dotdot_offset,
705 .data_first_offset = xfs_dir2_data_first_offset,
706 .data_entry_offset = xfs_dir2_data_entry_offset,
708 .data_dot_entry_p = xfs_dir2_data_dot_entry_p,
709 .data_dotdot_entry_p = xfs_dir2_data_dotdot_entry_p,
710 .data_first_entry_p = xfs_dir2_data_first_entry_p,
711 .data_entry_p = xfs_dir2_data_entry_p,
712 .data_unused_p = xfs_dir2_data_unused_p,
714 .leaf_hdr_size = xfs_dir2_leaf_hdr_size,
715 .leaf_hdr_to_disk = xfs_dir2_leaf_hdr_to_disk,
716 .leaf_hdr_from_disk = xfs_dir2_leaf_hdr_from_disk,
717 .leaf_max_ents = xfs_dir2_max_leaf_ents,
718 .leaf_ents_p = xfs_dir2_leaf_ents_p,
720 .node_hdr_size = xfs_da2_node_hdr_size,
721 .node_hdr_to_disk = xfs_da2_node_hdr_to_disk,
722 .node_hdr_from_disk = xfs_da2_node_hdr_from_disk,
723 .node_tree_p = xfs_da2_node_tree_p,
725 .free_hdr_to_disk = xfs_dir2_free_hdr_to_disk,
726 .free_hdr_from_disk = xfs_dir2_free_hdr_from_disk,
729 const struct xfs_dir_ops xfs_dir2_ftype_ops = {
730 .sf_entsize = xfs_dir3_sf_entsize,
731 .sf_nextentry = xfs_dir3_sf_nextentry,
732 .sf_get_ftype = xfs_dir3_sfe_get_ftype,
733 .sf_put_ftype = xfs_dir3_sfe_put_ftype,
734 .sf_get_ino = xfs_dir3_sfe_get_ino,
735 .sf_put_ino = xfs_dir3_sfe_put_ino,
736 .sf_get_parent_ino = xfs_dir2_sf_get_parent_ino,
737 .sf_put_parent_ino = xfs_dir2_sf_put_parent_ino,
739 .data_entsize = xfs_dir3_data_entsize,
740 .data_get_ftype = xfs_dir3_data_get_ftype,
741 .data_put_ftype = xfs_dir3_data_put_ftype,
742 .data_entry_tag_p = xfs_dir3_data_entry_tag_p,
743 .data_bestfree_p = xfs_dir2_data_bestfree_p,
745 .data_dot_offset = xfs_dir2_data_dot_offset,
746 .data_dotdot_offset = xfs_dir2_data_dotdot_offset,
747 .data_first_offset = xfs_dir2_data_first_offset,
748 .data_entry_offset = xfs_dir2_data_entry_offset,
750 .data_dot_entry_p = xfs_dir2_data_dot_entry_p,
751 .data_dotdot_entry_p = xfs_dir2_data_dotdot_entry_p,
752 .data_first_entry_p = xfs_dir2_data_first_entry_p,
753 .data_entry_p = xfs_dir2_data_entry_p,
754 .data_unused_p = xfs_dir2_data_unused_p,
756 .leaf_hdr_size = xfs_dir2_leaf_hdr_size,
757 .leaf_hdr_to_disk = xfs_dir2_leaf_hdr_to_disk,
758 .leaf_hdr_from_disk = xfs_dir2_leaf_hdr_from_disk,
759 .leaf_max_ents = xfs_dir2_max_leaf_ents,
760 .leaf_ents_p = xfs_dir2_leaf_ents_p,
762 .node_hdr_size = xfs_da2_node_hdr_size,
763 .node_hdr_to_disk = xfs_da2_node_hdr_to_disk,
764 .node_hdr_from_disk = xfs_da2_node_hdr_from_disk,
765 .node_tree_p = xfs_da2_node_tree_p,
767 .free_hdr_to_disk = xfs_dir2_free_hdr_to_disk,
768 .free_hdr_from_disk = xfs_dir2_free_hdr_from_disk,
771 const struct xfs_dir_ops xfs_dir3_ops = {
772 .sf_entsize = xfs_dir3_sf_entsize,
773 .sf_nextentry = xfs_dir3_sf_nextentry,
774 .sf_get_ftype = xfs_dir3_sfe_get_ftype,
775 .sf_put_ftype = xfs_dir3_sfe_put_ftype,
776 .sf_get_ino = xfs_dir3_sfe_get_ino,
777 .sf_put_ino = xfs_dir3_sfe_put_ino,
778 .sf_get_parent_ino = xfs_dir2_sf_get_parent_ino,
779 .sf_put_parent_ino = xfs_dir2_sf_put_parent_ino,
781 .data_entsize = xfs_dir3_data_entsize,
782 .data_get_ftype = xfs_dir3_data_get_ftype,
783 .data_put_ftype = xfs_dir3_data_put_ftype,
784 .data_entry_tag_p = xfs_dir3_data_entry_tag_p,
785 .data_bestfree_p = xfs_dir3_data_bestfree_p,
787 .data_dot_offset = xfs_dir3_data_dot_offset,
788 .data_dotdot_offset = xfs_dir3_data_dotdot_offset,
789 .data_first_offset = xfs_dir3_data_first_offset,
790 .data_entry_offset = xfs_dir3_data_entry_offset,
792 .data_dot_entry_p = xfs_dir3_data_dot_entry_p,
793 .data_dotdot_entry_p = xfs_dir3_data_dotdot_entry_p,
794 .data_first_entry_p = xfs_dir3_data_first_entry_p,
795 .data_entry_p = xfs_dir3_data_entry_p,
796 .data_unused_p = xfs_dir3_data_unused_p,
798 .leaf_hdr_size = xfs_dir3_leaf_hdr_size,
799 .leaf_hdr_to_disk = xfs_dir3_leaf_hdr_to_disk,
800 .leaf_hdr_from_disk = xfs_dir3_leaf_hdr_from_disk,
801 .leaf_max_ents = xfs_dir3_max_leaf_ents,
802 .leaf_ents_p = xfs_dir3_leaf_ents_p,
804 .node_hdr_size = xfs_da3_node_hdr_size,
805 .node_hdr_to_disk = xfs_da3_node_hdr_to_disk,
806 .node_hdr_from_disk = xfs_da3_node_hdr_from_disk,
807 .node_tree_p = xfs_da3_node_tree_p,
809 .free_hdr_to_disk = xfs_dir3_free_hdr_to_disk,
810 .free_hdr_from_disk = xfs_dir3_free_hdr_from_disk,
813 const struct xfs_dir_ops xfs_dir2_nondir_ops = {
814 .node_hdr_size = xfs_da2_node_hdr_size,
815 .node_hdr_to_disk = xfs_da2_node_hdr_to_disk,
816 .node_hdr_from_disk = xfs_da2_node_hdr_from_disk,
817 .node_tree_p = xfs_da2_node_tree_p,
820 const struct xfs_dir_ops xfs_dir3_nondir_ops = {
821 .node_hdr_size = xfs_da3_node_hdr_size,
822 .node_hdr_to_disk = xfs_da3_node_hdr_to_disk,
823 .node_hdr_from_disk = xfs_da3_node_hdr_from_disk,
824 .node_tree_p = xfs_da3_node_tree_p,
828 * Return the ops structure according to the current config. If we are passed
829 * an inode, then that overrides the default config we use which is based on
832 const struct xfs_dir_ops *
834 struct xfs_mount *mp,
835 struct xfs_inode *dp)
839 if (mp->m_dir_inode_ops)
840 return mp->m_dir_inode_ops;
841 if (xfs_sb_version_hascrc(&mp->m_sb))
842 return &xfs_dir3_ops;
843 if (xfs_sb_version_hasftype(&mp->m_sb))
844 return &xfs_dir2_ftype_ops;
845 return &xfs_dir2_ops;
848 const struct xfs_dir_ops *
850 struct xfs_mount *mp,
851 struct xfs_inode *dp)
855 if (mp->m_nondir_inode_ops)
856 return mp->m_nondir_inode_ops;
857 if (xfs_sb_version_hascrc(&mp->m_sb))
858 return &xfs_dir3_nondir_ops;
859 return &xfs_dir2_nondir_ops;