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_shared.h"
22 #include "xfs_format.h"
23 #include "xfs_log_format.h"
24 #include "xfs_trans_resv.h"
26 #include "xfs_mount.h"
27 #include "xfs_da_format.h"
28 #include "xfs_da_btree.h"
29 #include "xfs_inode.h"
31 #include "xfs_dir2_priv.h"
34 * Shortform directory ops
38 struct xfs_dir2_sf_hdr *hdr,
41 int count = sizeof(struct xfs_dir2_sf_entry); /* namelen + offset */
43 count += len; /* name */
44 count += hdr->i8count ? sizeof(xfs_dir2_ino8_t) :
45 sizeof(xfs_dir2_ino4_t); /* ino # */
51 struct xfs_dir2_sf_hdr *hdr,
54 return xfs_dir2_sf_entsize(hdr, len) + sizeof(__uint8_t);
57 static struct xfs_dir2_sf_entry *
58 xfs_dir2_sf_nextentry(
59 struct xfs_dir2_sf_hdr *hdr,
60 struct xfs_dir2_sf_entry *sfep)
62 return (struct xfs_dir2_sf_entry *)
63 ((char *)sfep + xfs_dir2_sf_entsize(hdr, sfep->namelen));
66 static struct xfs_dir2_sf_entry *
67 xfs_dir3_sf_nextentry(
68 struct xfs_dir2_sf_hdr *hdr,
69 struct xfs_dir2_sf_entry *sfep)
71 return (struct xfs_dir2_sf_entry *)
72 ((char *)sfep + xfs_dir3_sf_entsize(hdr, sfep->namelen));
77 * For filetype enabled shortform directories, the file type field is stored at
78 * the end of the name. Because it's only a single byte, endian conversion is
79 * not necessary. For non-filetype enable directories, the type is always
80 * unknown and we never store the value.
83 xfs_dir2_sfe_get_ftype(
84 struct xfs_dir2_sf_entry *sfep)
86 return XFS_DIR3_FT_UNKNOWN;
90 xfs_dir2_sfe_put_ftype(
91 struct xfs_dir2_sf_entry *sfep,
94 ASSERT(ftype < XFS_DIR3_FT_MAX);
98 xfs_dir3_sfe_get_ftype(
99 struct xfs_dir2_sf_entry *sfep)
103 ftype = sfep->name[sfep->namelen];
104 if (ftype >= XFS_DIR3_FT_MAX)
105 return XFS_DIR3_FT_UNKNOWN;
110 xfs_dir3_sfe_put_ftype(
111 struct xfs_dir2_sf_entry *sfep,
114 ASSERT(ftype < XFS_DIR3_FT_MAX);
116 sfep->name[sfep->namelen] = ftype;
120 * Inode numbers in short-form directories can come in two versions,
121 * either 4 bytes or 8 bytes wide. These helpers deal with the
122 * two forms transparently by looking at the headers i8count field.
124 * For 64-bit inode number the most significant byte must be zero.
128 struct xfs_dir2_sf_hdr *hdr,
129 xfs_dir2_inou_t *from)
132 return get_unaligned_be64(&from->i8.i) & 0x00ffffffffffffffULL;
134 return get_unaligned_be32(&from->i4.i);
139 struct xfs_dir2_sf_hdr *hdr,
143 ASSERT((ino & 0xff00000000000000ULL) == 0);
146 put_unaligned_be64(ino, &to->i8.i);
148 put_unaligned_be32(ino, &to->i4.i);
152 xfs_dir2_sf_get_parent_ino(
153 struct xfs_dir2_sf_hdr *hdr)
155 return xfs_dir2_sf_get_ino(hdr, &hdr->parent);
159 xfs_dir2_sf_put_parent_ino(
160 struct xfs_dir2_sf_hdr *hdr,
163 xfs_dir2_sf_put_ino(hdr, &hdr->parent, ino);
167 * In short-form directory entries the inode numbers are stored at variable
168 * offset behind the entry name. If the entry stores a filetype value, then it
169 * sits between the name and the inode number. Hence the inode numbers may only
170 * be accessed through the helpers below.
173 xfs_dir2_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,
178 (xfs_dir2_inou_t *)&sfep->name[sfep->namelen]);
182 xfs_dir2_sfe_put_ino(
183 struct xfs_dir2_sf_hdr *hdr,
184 struct xfs_dir2_sf_entry *sfep,
187 xfs_dir2_sf_put_ino(hdr,
188 (xfs_dir2_inou_t *)&sfep->name[sfep->namelen], ino);
192 xfs_dir3_sfe_get_ino(
193 struct xfs_dir2_sf_hdr *hdr,
194 struct xfs_dir2_sf_entry *sfep)
196 return xfs_dir2_sf_get_ino(hdr,
197 (xfs_dir2_inou_t *)&sfep->name[sfep->namelen + 1]);
201 xfs_dir3_sfe_put_ino(
202 struct xfs_dir2_sf_hdr *hdr,
203 struct xfs_dir2_sf_entry *sfep,
206 xfs_dir2_sf_put_ino(hdr,
207 (xfs_dir2_inou_t *)&sfep->name[sfep->namelen + 1], ino);
212 * Directory data block operations
216 * For special situations, the dirent size ends up fixed because we always know
217 * what the size of the entry is. That's true for the "." and "..", and
218 * therefore we know that they are a fixed size and hence their offsets are
219 * constant, as is the first entry.
221 * Hence, this calculation is written as a macro to be able to be calculated at
222 * compile time and so certain offsets can be calculated directly in the
223 * structure initaliser via the macro. There are two macros - one for dirents
224 * with ftype and without so there are no unresolvable conditionals in the
225 * calculations. We also use round_up() as XFS_DIR2_DATA_ALIGN is always a power
226 * of 2 and the compiler doesn't reject it (unlike roundup()).
228 #define XFS_DIR2_DATA_ENTSIZE(n) \
229 round_up((offsetof(struct xfs_dir2_data_entry, name[0]) + (n) + \
230 sizeof(xfs_dir2_data_off_t)), XFS_DIR2_DATA_ALIGN)
232 #define XFS_DIR3_DATA_ENTSIZE(n) \
233 round_up((offsetof(struct xfs_dir2_data_entry, name[0]) + (n) + \
234 sizeof(xfs_dir2_data_off_t) + sizeof(__uint8_t)), \
238 xfs_dir2_data_entsize(
241 return XFS_DIR2_DATA_ENTSIZE(n);
245 xfs_dir3_data_entsize(
248 return XFS_DIR3_DATA_ENTSIZE(n);
252 xfs_dir2_data_get_ftype(
253 struct xfs_dir2_data_entry *dep)
255 return XFS_DIR3_FT_UNKNOWN;
259 xfs_dir2_data_put_ftype(
260 struct xfs_dir2_data_entry *dep,
263 ASSERT(ftype < XFS_DIR3_FT_MAX);
267 xfs_dir3_data_get_ftype(
268 struct xfs_dir2_data_entry *dep)
270 __uint8_t ftype = dep->name[dep->namelen];
272 if (ftype >= XFS_DIR3_FT_MAX)
273 return XFS_DIR3_FT_UNKNOWN;
278 xfs_dir3_data_put_ftype(
279 struct xfs_dir2_data_entry *dep,
282 ASSERT(type < XFS_DIR3_FT_MAX);
283 ASSERT(dep->namelen != 0);
285 dep->name[dep->namelen] = type;
289 * Pointer to an entry's tag word.
292 xfs_dir2_data_entry_tag_p(
293 struct xfs_dir2_data_entry *dep)
295 return (__be16 *)((char *)dep +
296 xfs_dir2_data_entsize(dep->namelen) - sizeof(__be16));
300 xfs_dir3_data_entry_tag_p(
301 struct xfs_dir2_data_entry *dep)
303 return (__be16 *)((char *)dep +
304 xfs_dir3_data_entsize(dep->namelen) - sizeof(__be16));
308 * location of . and .. in data space (always block 0)
310 static struct xfs_dir2_data_entry *
311 xfs_dir2_data_dot_entry_p(
312 struct xfs_dir2_data_hdr *hdr)
314 return (struct xfs_dir2_data_entry *)
315 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr));
318 static struct xfs_dir2_data_entry *
319 xfs_dir2_data_dotdot_entry_p(
320 struct xfs_dir2_data_hdr *hdr)
322 return (struct xfs_dir2_data_entry *)
323 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr) +
324 XFS_DIR2_DATA_ENTSIZE(1));
327 static struct xfs_dir2_data_entry *
328 xfs_dir2_data_first_entry_p(
329 struct xfs_dir2_data_hdr *hdr)
331 return (struct xfs_dir2_data_entry *)
332 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr) +
333 XFS_DIR2_DATA_ENTSIZE(1) +
334 XFS_DIR2_DATA_ENTSIZE(2));
337 static struct xfs_dir2_data_entry *
338 xfs_dir2_ftype_data_dotdot_entry_p(
339 struct xfs_dir2_data_hdr *hdr)
341 return (struct xfs_dir2_data_entry *)
342 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr) +
343 XFS_DIR3_DATA_ENTSIZE(1));
346 static struct xfs_dir2_data_entry *
347 xfs_dir2_ftype_data_first_entry_p(
348 struct xfs_dir2_data_hdr *hdr)
350 return (struct xfs_dir2_data_entry *)
351 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr) +
352 XFS_DIR3_DATA_ENTSIZE(1) +
353 XFS_DIR3_DATA_ENTSIZE(2));
356 static struct xfs_dir2_data_entry *
357 xfs_dir3_data_dot_entry_p(
358 struct xfs_dir2_data_hdr *hdr)
360 return (struct xfs_dir2_data_entry *)
361 ((char *)hdr + sizeof(struct xfs_dir3_data_hdr));
364 static struct xfs_dir2_data_entry *
365 xfs_dir3_data_dotdot_entry_p(
366 struct xfs_dir2_data_hdr *hdr)
368 return (struct xfs_dir2_data_entry *)
369 ((char *)hdr + sizeof(struct xfs_dir3_data_hdr) +
370 XFS_DIR3_DATA_ENTSIZE(1));
373 static struct xfs_dir2_data_entry *
374 xfs_dir3_data_first_entry_p(
375 struct xfs_dir2_data_hdr *hdr)
377 return (struct xfs_dir2_data_entry *)
378 ((char *)hdr + sizeof(struct xfs_dir3_data_hdr) +
379 XFS_DIR3_DATA_ENTSIZE(1) +
380 XFS_DIR3_DATA_ENTSIZE(2));
383 static struct xfs_dir2_data_free *
384 xfs_dir2_data_bestfree_p(struct xfs_dir2_data_hdr *hdr)
386 return hdr->bestfree;
389 static struct xfs_dir2_data_free *
390 xfs_dir3_data_bestfree_p(struct xfs_dir2_data_hdr *hdr)
392 return ((struct xfs_dir3_data_hdr *)hdr)->best_free;
395 static struct xfs_dir2_data_entry *
396 xfs_dir2_data_entry_p(struct xfs_dir2_data_hdr *hdr)
398 return (struct xfs_dir2_data_entry *)
399 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr));
402 static struct xfs_dir2_data_unused *
403 xfs_dir2_data_unused_p(struct xfs_dir2_data_hdr *hdr)
405 return (struct xfs_dir2_data_unused *)
406 ((char *)hdr + sizeof(struct xfs_dir2_data_hdr));
409 static struct xfs_dir2_data_entry *
410 xfs_dir3_data_entry_p(struct xfs_dir2_data_hdr *hdr)
412 return (struct xfs_dir2_data_entry *)
413 ((char *)hdr + sizeof(struct xfs_dir3_data_hdr));
416 static struct xfs_dir2_data_unused *
417 xfs_dir3_data_unused_p(struct xfs_dir2_data_hdr *hdr)
419 return (struct xfs_dir2_data_unused *)
420 ((char *)hdr + sizeof(struct xfs_dir3_data_hdr));
425 * Directory Leaf block operations
428 xfs_dir2_max_leaf_ents(struct xfs_da_geometry *geo)
430 return (geo->blksize - sizeof(struct xfs_dir2_leaf_hdr)) /
431 (uint)sizeof(struct xfs_dir2_leaf_entry);
434 static struct xfs_dir2_leaf_entry *
435 xfs_dir2_leaf_ents_p(struct xfs_dir2_leaf *lp)
441 xfs_dir3_max_leaf_ents(struct xfs_da_geometry *geo)
443 return (geo->blksize - sizeof(struct xfs_dir3_leaf_hdr)) /
444 (uint)sizeof(struct xfs_dir2_leaf_entry);
447 static struct xfs_dir2_leaf_entry *
448 xfs_dir3_leaf_ents_p(struct xfs_dir2_leaf *lp)
450 return ((struct xfs_dir3_leaf *)lp)->__ents;
454 xfs_dir2_leaf_hdr_from_disk(
455 struct xfs_dir3_icleaf_hdr *to,
456 struct xfs_dir2_leaf *from)
458 to->forw = be32_to_cpu(from->hdr.info.forw);
459 to->back = be32_to_cpu(from->hdr.info.back);
460 to->magic = be16_to_cpu(from->hdr.info.magic);
461 to->count = be16_to_cpu(from->hdr.count);
462 to->stale = be16_to_cpu(from->hdr.stale);
464 ASSERT(to->magic == XFS_DIR2_LEAF1_MAGIC ||
465 to->magic == XFS_DIR2_LEAFN_MAGIC);
469 xfs_dir2_leaf_hdr_to_disk(
470 struct xfs_dir2_leaf *to,
471 struct xfs_dir3_icleaf_hdr *from)
473 ASSERT(from->magic == XFS_DIR2_LEAF1_MAGIC ||
474 from->magic == XFS_DIR2_LEAFN_MAGIC);
476 to->hdr.info.forw = cpu_to_be32(from->forw);
477 to->hdr.info.back = cpu_to_be32(from->back);
478 to->hdr.info.magic = cpu_to_be16(from->magic);
479 to->hdr.count = cpu_to_be16(from->count);
480 to->hdr.stale = cpu_to_be16(from->stale);
484 xfs_dir3_leaf_hdr_from_disk(
485 struct xfs_dir3_icleaf_hdr *to,
486 struct xfs_dir2_leaf *from)
488 struct xfs_dir3_leaf_hdr *hdr3 = (struct xfs_dir3_leaf_hdr *)from;
490 to->forw = be32_to_cpu(hdr3->info.hdr.forw);
491 to->back = be32_to_cpu(hdr3->info.hdr.back);
492 to->magic = be16_to_cpu(hdr3->info.hdr.magic);
493 to->count = be16_to_cpu(hdr3->count);
494 to->stale = be16_to_cpu(hdr3->stale);
496 ASSERT(to->magic == XFS_DIR3_LEAF1_MAGIC ||
497 to->magic == XFS_DIR3_LEAFN_MAGIC);
501 xfs_dir3_leaf_hdr_to_disk(
502 struct xfs_dir2_leaf *to,
503 struct xfs_dir3_icleaf_hdr *from)
505 struct xfs_dir3_leaf_hdr *hdr3 = (struct xfs_dir3_leaf_hdr *)to;
507 ASSERT(from->magic == XFS_DIR3_LEAF1_MAGIC ||
508 from->magic == XFS_DIR3_LEAFN_MAGIC);
510 hdr3->info.hdr.forw = cpu_to_be32(from->forw);
511 hdr3->info.hdr.back = cpu_to_be32(from->back);
512 hdr3->info.hdr.magic = cpu_to_be16(from->magic);
513 hdr3->count = cpu_to_be16(from->count);
514 hdr3->stale = cpu_to_be16(from->stale);
519 * Directory/Attribute Node block operations
521 static struct xfs_da_node_entry *
522 xfs_da2_node_tree_p(struct xfs_da_intnode *dap)
527 static struct xfs_da_node_entry *
528 xfs_da3_node_tree_p(struct xfs_da_intnode *dap)
530 return ((struct xfs_da3_intnode *)dap)->__btree;
534 xfs_da2_node_hdr_from_disk(
535 struct xfs_da3_icnode_hdr *to,
536 struct xfs_da_intnode *from)
538 ASSERT(from->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC));
539 to->forw = be32_to_cpu(from->hdr.info.forw);
540 to->back = be32_to_cpu(from->hdr.info.back);
541 to->magic = be16_to_cpu(from->hdr.info.magic);
542 to->count = be16_to_cpu(from->hdr.__count);
543 to->level = be16_to_cpu(from->hdr.__level);
547 xfs_da2_node_hdr_to_disk(
548 struct xfs_da_intnode *to,
549 struct xfs_da3_icnode_hdr *from)
551 ASSERT(from->magic == XFS_DA_NODE_MAGIC);
552 to->hdr.info.forw = cpu_to_be32(from->forw);
553 to->hdr.info.back = cpu_to_be32(from->back);
554 to->hdr.info.magic = cpu_to_be16(from->magic);
555 to->hdr.__count = cpu_to_be16(from->count);
556 to->hdr.__level = cpu_to_be16(from->level);
560 xfs_da3_node_hdr_from_disk(
561 struct xfs_da3_icnode_hdr *to,
562 struct xfs_da_intnode *from)
564 struct xfs_da3_node_hdr *hdr3 = (struct xfs_da3_node_hdr *)from;
566 ASSERT(from->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC));
567 to->forw = be32_to_cpu(hdr3->info.hdr.forw);
568 to->back = be32_to_cpu(hdr3->info.hdr.back);
569 to->magic = be16_to_cpu(hdr3->info.hdr.magic);
570 to->count = be16_to_cpu(hdr3->__count);
571 to->level = be16_to_cpu(hdr3->__level);
575 xfs_da3_node_hdr_to_disk(
576 struct xfs_da_intnode *to,
577 struct xfs_da3_icnode_hdr *from)
579 struct xfs_da3_node_hdr *hdr3 = (struct xfs_da3_node_hdr *)to;
581 ASSERT(from->magic == XFS_DA3_NODE_MAGIC);
582 hdr3->info.hdr.forw = cpu_to_be32(from->forw);
583 hdr3->info.hdr.back = cpu_to_be32(from->back);
584 hdr3->info.hdr.magic = cpu_to_be16(from->magic);
585 hdr3->__count = cpu_to_be16(from->count);
586 hdr3->__level = cpu_to_be16(from->level);
591 * Directory free space block operations
594 xfs_dir2_free_max_bests(struct xfs_da_geometry *geo)
596 return (geo->blksize - sizeof(struct xfs_dir2_free_hdr)) /
597 sizeof(xfs_dir2_data_off_t);
601 xfs_dir2_free_bests_p(struct xfs_dir2_free *free)
603 return (__be16 *)((char *)free + sizeof(struct xfs_dir2_free_hdr));
607 * Convert data space db to the corresponding free db.
610 xfs_dir2_db_to_fdb(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
612 return xfs_dir2_byte_to_db(geo, XFS_DIR2_FREE_OFFSET) +
613 (db / xfs_dir2_free_max_bests(geo));
617 * Convert data space db to the corresponding index in a free db.
620 xfs_dir2_db_to_fdindex(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
622 return db % xfs_dir2_free_max_bests(geo);
626 xfs_dir3_free_max_bests(struct xfs_da_geometry *geo)
628 return (geo->blksize - sizeof(struct xfs_dir3_free_hdr)) /
629 sizeof(xfs_dir2_data_off_t);
633 xfs_dir3_free_bests_p(struct xfs_dir2_free *free)
635 return (__be16 *)((char *)free + sizeof(struct xfs_dir3_free_hdr));
639 * Convert data space db to the corresponding free db.
642 xfs_dir3_db_to_fdb(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
644 return xfs_dir2_byte_to_db(geo, XFS_DIR2_FREE_OFFSET) +
645 (db / xfs_dir3_free_max_bests(geo));
649 * Convert data space db to the corresponding index in a free db.
652 xfs_dir3_db_to_fdindex(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
654 return db % xfs_dir3_free_max_bests(geo);
658 xfs_dir2_free_hdr_from_disk(
659 struct xfs_dir3_icfree_hdr *to,
660 struct xfs_dir2_free *from)
662 to->magic = be32_to_cpu(from->hdr.magic);
663 to->firstdb = be32_to_cpu(from->hdr.firstdb);
664 to->nvalid = be32_to_cpu(from->hdr.nvalid);
665 to->nused = be32_to_cpu(from->hdr.nused);
666 ASSERT(to->magic == XFS_DIR2_FREE_MAGIC);
670 xfs_dir2_free_hdr_to_disk(
671 struct xfs_dir2_free *to,
672 struct xfs_dir3_icfree_hdr *from)
674 ASSERT(from->magic == XFS_DIR2_FREE_MAGIC);
676 to->hdr.magic = cpu_to_be32(from->magic);
677 to->hdr.firstdb = cpu_to_be32(from->firstdb);
678 to->hdr.nvalid = cpu_to_be32(from->nvalid);
679 to->hdr.nused = cpu_to_be32(from->nused);
683 xfs_dir3_free_hdr_from_disk(
684 struct xfs_dir3_icfree_hdr *to,
685 struct xfs_dir2_free *from)
687 struct xfs_dir3_free_hdr *hdr3 = (struct xfs_dir3_free_hdr *)from;
689 to->magic = be32_to_cpu(hdr3->hdr.magic);
690 to->firstdb = be32_to_cpu(hdr3->firstdb);
691 to->nvalid = be32_to_cpu(hdr3->nvalid);
692 to->nused = be32_to_cpu(hdr3->nused);
694 ASSERT(to->magic == XFS_DIR3_FREE_MAGIC);
698 xfs_dir3_free_hdr_to_disk(
699 struct xfs_dir2_free *to,
700 struct xfs_dir3_icfree_hdr *from)
702 struct xfs_dir3_free_hdr *hdr3 = (struct xfs_dir3_free_hdr *)to;
704 ASSERT(from->magic == XFS_DIR3_FREE_MAGIC);
706 hdr3->hdr.magic = cpu_to_be32(from->magic);
707 hdr3->firstdb = cpu_to_be32(from->firstdb);
708 hdr3->nvalid = cpu_to_be32(from->nvalid);
709 hdr3->nused = cpu_to_be32(from->nused);
712 static const struct xfs_dir_ops xfs_dir2_ops = {
713 .sf_entsize = xfs_dir2_sf_entsize,
714 .sf_nextentry = xfs_dir2_sf_nextentry,
715 .sf_get_ftype = xfs_dir2_sfe_get_ftype,
716 .sf_put_ftype = xfs_dir2_sfe_put_ftype,
717 .sf_get_ino = xfs_dir2_sfe_get_ino,
718 .sf_put_ino = xfs_dir2_sfe_put_ino,
719 .sf_get_parent_ino = xfs_dir2_sf_get_parent_ino,
720 .sf_put_parent_ino = xfs_dir2_sf_put_parent_ino,
722 .data_entsize = xfs_dir2_data_entsize,
723 .data_get_ftype = xfs_dir2_data_get_ftype,
724 .data_put_ftype = xfs_dir2_data_put_ftype,
725 .data_entry_tag_p = xfs_dir2_data_entry_tag_p,
726 .data_bestfree_p = xfs_dir2_data_bestfree_p,
728 .data_dot_offset = sizeof(struct xfs_dir2_data_hdr),
729 .data_dotdot_offset = sizeof(struct xfs_dir2_data_hdr) +
730 XFS_DIR2_DATA_ENTSIZE(1),
731 .data_first_offset = sizeof(struct xfs_dir2_data_hdr) +
732 XFS_DIR2_DATA_ENTSIZE(1) +
733 XFS_DIR2_DATA_ENTSIZE(2),
734 .data_entry_offset = sizeof(struct xfs_dir2_data_hdr),
736 .data_dot_entry_p = xfs_dir2_data_dot_entry_p,
737 .data_dotdot_entry_p = xfs_dir2_data_dotdot_entry_p,
738 .data_first_entry_p = xfs_dir2_data_first_entry_p,
739 .data_entry_p = xfs_dir2_data_entry_p,
740 .data_unused_p = xfs_dir2_data_unused_p,
742 .leaf_hdr_size = sizeof(struct xfs_dir2_leaf_hdr),
743 .leaf_hdr_to_disk = xfs_dir2_leaf_hdr_to_disk,
744 .leaf_hdr_from_disk = xfs_dir2_leaf_hdr_from_disk,
745 .leaf_max_ents = xfs_dir2_max_leaf_ents,
746 .leaf_ents_p = xfs_dir2_leaf_ents_p,
748 .node_hdr_size = sizeof(struct xfs_da_node_hdr),
749 .node_hdr_to_disk = xfs_da2_node_hdr_to_disk,
750 .node_hdr_from_disk = xfs_da2_node_hdr_from_disk,
751 .node_tree_p = xfs_da2_node_tree_p,
753 .free_hdr_size = sizeof(struct xfs_dir2_free_hdr),
754 .free_hdr_to_disk = xfs_dir2_free_hdr_to_disk,
755 .free_hdr_from_disk = xfs_dir2_free_hdr_from_disk,
756 .free_max_bests = xfs_dir2_free_max_bests,
757 .free_bests_p = xfs_dir2_free_bests_p,
758 .db_to_fdb = xfs_dir2_db_to_fdb,
759 .db_to_fdindex = xfs_dir2_db_to_fdindex,
762 static const struct xfs_dir_ops xfs_dir2_ftype_ops = {
763 .sf_entsize = xfs_dir3_sf_entsize,
764 .sf_nextentry = xfs_dir3_sf_nextentry,
765 .sf_get_ftype = xfs_dir3_sfe_get_ftype,
766 .sf_put_ftype = xfs_dir3_sfe_put_ftype,
767 .sf_get_ino = xfs_dir3_sfe_get_ino,
768 .sf_put_ino = xfs_dir3_sfe_put_ino,
769 .sf_get_parent_ino = xfs_dir2_sf_get_parent_ino,
770 .sf_put_parent_ino = xfs_dir2_sf_put_parent_ino,
772 .data_entsize = xfs_dir3_data_entsize,
773 .data_get_ftype = xfs_dir3_data_get_ftype,
774 .data_put_ftype = xfs_dir3_data_put_ftype,
775 .data_entry_tag_p = xfs_dir3_data_entry_tag_p,
776 .data_bestfree_p = xfs_dir2_data_bestfree_p,
778 .data_dot_offset = sizeof(struct xfs_dir2_data_hdr),
779 .data_dotdot_offset = sizeof(struct xfs_dir2_data_hdr) +
780 XFS_DIR3_DATA_ENTSIZE(1),
781 .data_first_offset = sizeof(struct xfs_dir2_data_hdr) +
782 XFS_DIR3_DATA_ENTSIZE(1) +
783 XFS_DIR3_DATA_ENTSIZE(2),
784 .data_entry_offset = sizeof(struct xfs_dir2_data_hdr),
786 .data_dot_entry_p = xfs_dir2_data_dot_entry_p,
787 .data_dotdot_entry_p = xfs_dir2_ftype_data_dotdot_entry_p,
788 .data_first_entry_p = xfs_dir2_ftype_data_first_entry_p,
789 .data_entry_p = xfs_dir2_data_entry_p,
790 .data_unused_p = xfs_dir2_data_unused_p,
792 .leaf_hdr_size = sizeof(struct xfs_dir2_leaf_hdr),
793 .leaf_hdr_to_disk = xfs_dir2_leaf_hdr_to_disk,
794 .leaf_hdr_from_disk = xfs_dir2_leaf_hdr_from_disk,
795 .leaf_max_ents = xfs_dir2_max_leaf_ents,
796 .leaf_ents_p = xfs_dir2_leaf_ents_p,
798 .node_hdr_size = sizeof(struct xfs_da_node_hdr),
799 .node_hdr_to_disk = xfs_da2_node_hdr_to_disk,
800 .node_hdr_from_disk = xfs_da2_node_hdr_from_disk,
801 .node_tree_p = xfs_da2_node_tree_p,
803 .free_hdr_size = sizeof(struct xfs_dir2_free_hdr),
804 .free_hdr_to_disk = xfs_dir2_free_hdr_to_disk,
805 .free_hdr_from_disk = xfs_dir2_free_hdr_from_disk,
806 .free_max_bests = xfs_dir2_free_max_bests,
807 .free_bests_p = xfs_dir2_free_bests_p,
808 .db_to_fdb = xfs_dir2_db_to_fdb,
809 .db_to_fdindex = xfs_dir2_db_to_fdindex,
812 static const struct xfs_dir_ops xfs_dir3_ops = {
813 .sf_entsize = xfs_dir3_sf_entsize,
814 .sf_nextentry = xfs_dir3_sf_nextentry,
815 .sf_get_ftype = xfs_dir3_sfe_get_ftype,
816 .sf_put_ftype = xfs_dir3_sfe_put_ftype,
817 .sf_get_ino = xfs_dir3_sfe_get_ino,
818 .sf_put_ino = xfs_dir3_sfe_put_ino,
819 .sf_get_parent_ino = xfs_dir2_sf_get_parent_ino,
820 .sf_put_parent_ino = xfs_dir2_sf_put_parent_ino,
822 .data_entsize = xfs_dir3_data_entsize,
823 .data_get_ftype = xfs_dir3_data_get_ftype,
824 .data_put_ftype = xfs_dir3_data_put_ftype,
825 .data_entry_tag_p = xfs_dir3_data_entry_tag_p,
826 .data_bestfree_p = xfs_dir3_data_bestfree_p,
828 .data_dot_offset = sizeof(struct xfs_dir3_data_hdr),
829 .data_dotdot_offset = sizeof(struct xfs_dir3_data_hdr) +
830 XFS_DIR3_DATA_ENTSIZE(1),
831 .data_first_offset = sizeof(struct xfs_dir3_data_hdr) +
832 XFS_DIR3_DATA_ENTSIZE(1) +
833 XFS_DIR3_DATA_ENTSIZE(2),
834 .data_entry_offset = sizeof(struct xfs_dir3_data_hdr),
836 .data_dot_entry_p = xfs_dir3_data_dot_entry_p,
837 .data_dotdot_entry_p = xfs_dir3_data_dotdot_entry_p,
838 .data_first_entry_p = xfs_dir3_data_first_entry_p,
839 .data_entry_p = xfs_dir3_data_entry_p,
840 .data_unused_p = xfs_dir3_data_unused_p,
842 .leaf_hdr_size = sizeof(struct xfs_dir3_leaf_hdr),
843 .leaf_hdr_to_disk = xfs_dir3_leaf_hdr_to_disk,
844 .leaf_hdr_from_disk = xfs_dir3_leaf_hdr_from_disk,
845 .leaf_max_ents = xfs_dir3_max_leaf_ents,
846 .leaf_ents_p = xfs_dir3_leaf_ents_p,
848 .node_hdr_size = sizeof(struct xfs_da3_node_hdr),
849 .node_hdr_to_disk = xfs_da3_node_hdr_to_disk,
850 .node_hdr_from_disk = xfs_da3_node_hdr_from_disk,
851 .node_tree_p = xfs_da3_node_tree_p,
853 .free_hdr_size = sizeof(struct xfs_dir3_free_hdr),
854 .free_hdr_to_disk = xfs_dir3_free_hdr_to_disk,
855 .free_hdr_from_disk = xfs_dir3_free_hdr_from_disk,
856 .free_max_bests = xfs_dir3_free_max_bests,
857 .free_bests_p = xfs_dir3_free_bests_p,
858 .db_to_fdb = xfs_dir3_db_to_fdb,
859 .db_to_fdindex = xfs_dir3_db_to_fdindex,
862 static const struct xfs_dir_ops xfs_dir2_nondir_ops = {
863 .node_hdr_size = sizeof(struct xfs_da_node_hdr),
864 .node_hdr_to_disk = xfs_da2_node_hdr_to_disk,
865 .node_hdr_from_disk = xfs_da2_node_hdr_from_disk,
866 .node_tree_p = xfs_da2_node_tree_p,
869 static const struct xfs_dir_ops xfs_dir3_nondir_ops = {
870 .node_hdr_size = sizeof(struct xfs_da3_node_hdr),
871 .node_hdr_to_disk = xfs_da3_node_hdr_to_disk,
872 .node_hdr_from_disk = xfs_da3_node_hdr_from_disk,
873 .node_tree_p = xfs_da3_node_tree_p,
877 * Return the ops structure according to the current config. If we are passed
878 * an inode, then that overrides the default config we use which is based on
881 const struct xfs_dir_ops *
883 struct xfs_mount *mp,
884 struct xfs_inode *dp)
888 if (mp->m_dir_inode_ops)
889 return mp->m_dir_inode_ops;
890 if (xfs_sb_version_hascrc(&mp->m_sb))
891 return &xfs_dir3_ops;
892 if (xfs_sb_version_hasftype(&mp->m_sb))
893 return &xfs_dir2_ftype_ops;
894 return &xfs_dir2_ops;
897 const struct xfs_dir_ops *
899 struct xfs_mount *mp,
900 struct xfs_inode *dp)
904 if (mp->m_nondir_inode_ops)
905 return mp->m_nondir_inode_ops;
906 if (xfs_sb_version_hascrc(&mp->m_sb))
907 return &xfs_dir3_nondir_ops;
908 return &xfs_dir2_nondir_ops;