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
22 * Shortform directory ops
26 struct xfs_dir2_sf_hdr
*hdr
,
29 int count
= sizeof(struct xfs_dir2_sf_entry
); /* namelen + offset */
31 count
+= len
; /* name */
32 count
+= hdr
->i8count
? sizeof(xfs_dir2_ino8_t
) :
33 sizeof(xfs_dir2_ino4_t
); /* ino # */
39 struct xfs_dir2_sf_hdr
*hdr
,
42 return xfs_dir2_sf_entsize(hdr
, len
) + sizeof(__uint8_t
);
45 static struct xfs_dir2_sf_entry
*
46 xfs_dir2_sf_nextentry(
47 struct xfs_dir2_sf_hdr
*hdr
,
48 struct xfs_dir2_sf_entry
*sfep
)
50 return (struct xfs_dir2_sf_entry
*)
51 ((char *)sfep
+ xfs_dir2_sf_entsize(hdr
, sfep
->namelen
));
54 static struct xfs_dir2_sf_entry
*
55 xfs_dir3_sf_nextentry(
56 struct xfs_dir2_sf_hdr
*hdr
,
57 struct xfs_dir2_sf_entry
*sfep
)
59 return (struct xfs_dir2_sf_entry
*)
60 ((char *)sfep
+ xfs_dir3_sf_entsize(hdr
, sfep
->namelen
));
65 * For filetype enabled shortform directories, the file type field is stored at
66 * the end of the name. Because it's only a single byte, endian conversion is
67 * not necessary. For non-filetype enable directories, the type is always
68 * unknown and we never store the value.
71 xfs_dir2_sfe_get_ftype(
72 struct xfs_dir2_sf_entry
*sfep
)
74 return XFS_DIR3_FT_UNKNOWN
;
78 xfs_dir2_sfe_put_ftype(
79 struct xfs_dir2_sf_entry
*sfep
,
82 ASSERT(ftype
< XFS_DIR3_FT_MAX
);
86 xfs_dir3_sfe_get_ftype(
87 struct xfs_dir2_sf_entry
*sfep
)
91 ftype
= sfep
->name
[sfep
->namelen
];
92 if (ftype
>= XFS_DIR3_FT_MAX
)
93 return XFS_DIR3_FT_UNKNOWN
;
98 xfs_dir3_sfe_put_ftype(
99 struct xfs_dir2_sf_entry
*sfep
,
102 ASSERT(ftype
< XFS_DIR3_FT_MAX
);
104 sfep
->name
[sfep
->namelen
] = ftype
;
108 * Inode numbers in short-form directories can come in two versions,
109 * either 4 bytes or 8 bytes wide. These helpers deal with the
110 * two forms transparently by looking at the headers i8count field.
112 * For 64-bit inode number the most significant byte must be zero.
116 struct xfs_dir2_sf_hdr
*hdr
,
117 xfs_dir2_inou_t
*from
)
120 return get_unaligned_be64(&from
->i8
.i
) & 0x00ffffffffffffffULL
;
122 return get_unaligned_be32(&from
->i4
.i
);
127 struct xfs_dir2_sf_hdr
*hdr
,
131 ASSERT((ino
& 0xff00000000000000ULL
) == 0);
134 put_unaligned_be64(ino
, &to
->i8
.i
);
136 put_unaligned_be32(ino
, &to
->i4
.i
);
140 xfs_dir2_sf_get_parent_ino(
141 struct xfs_dir2_sf_hdr
*hdr
)
143 return xfs_dir2_sf_get_ino(hdr
, &hdr
->parent
);
147 xfs_dir2_sf_put_parent_ino(
148 struct xfs_dir2_sf_hdr
*hdr
,
151 xfs_dir2_sf_put_ino(hdr
, &hdr
->parent
, ino
);
155 * In short-form directory entries the inode numbers are stored at variable
156 * offset behind the entry name. If the entry stores a filetype value, then it
157 * sits between the name and the inode number. Hence the inode numbers may only
158 * be accessed through the helpers below.
161 xfs_dir2_sfe_get_ino(
162 struct xfs_dir2_sf_hdr
*hdr
,
163 struct xfs_dir2_sf_entry
*sfep
)
165 return xfs_dir2_sf_get_ino(hdr
,
166 (xfs_dir2_inou_t
*)&sfep
->name
[sfep
->namelen
]);
170 xfs_dir2_sfe_put_ino(
171 struct xfs_dir2_sf_hdr
*hdr
,
172 struct xfs_dir2_sf_entry
*sfep
,
175 xfs_dir2_sf_put_ino(hdr
,
176 (xfs_dir2_inou_t
*)&sfep
->name
[sfep
->namelen
], ino
);
180 xfs_dir3_sfe_get_ino(
181 struct xfs_dir2_sf_hdr
*hdr
,
182 struct xfs_dir2_sf_entry
*sfep
)
184 return xfs_dir2_sf_get_ino(hdr
,
185 (xfs_dir2_inou_t
*)&sfep
->name
[sfep
->namelen
+ 1]);
189 xfs_dir3_sfe_put_ino(
190 struct xfs_dir2_sf_hdr
*hdr
,
191 struct xfs_dir2_sf_entry
*sfep
,
194 xfs_dir2_sf_put_ino(hdr
,
195 (xfs_dir2_inou_t
*)&sfep
->name
[sfep
->namelen
+ 1], ino
);
200 * Directory data block operations
204 * For special situations, the dirent size ends up fixed because we always know
205 * what the size of the entry is. That's true for the "." and "..", and
206 * therefore we know that they are a fixed size and hence their offsets are
207 * constant, as is the first entry.
209 * Hence, this calculation is written as a macro to be able to be calculated at
210 * compile time and so certain offsets can be calculated directly in the
211 * structure initaliser via the macro. There are two macros - one for dirents
212 * with ftype and without so there are no unresolvable conditionals in the
213 * calculations. We also use round_up() as XFS_DIR2_DATA_ALIGN is always a power
214 * of 2 and the compiler doesn't reject it (unlike roundup()).
216 #define XFS_DIR2_DATA_ENTSIZE(n) \
217 round_up((offsetof(struct xfs_dir2_data_entry, name[0]) + (n) + \
218 sizeof(xfs_dir2_data_off_t)), XFS_DIR2_DATA_ALIGN)
220 #define XFS_DIR3_DATA_ENTSIZE(n) \
221 round_up((offsetof(struct xfs_dir2_data_entry, name[0]) + (n) + \
222 sizeof(xfs_dir2_data_off_t) + sizeof(__uint8_t)), \
226 xfs_dir2_data_entsize(
229 return XFS_DIR2_DATA_ENTSIZE(n
);
233 xfs_dir3_data_entsize(
236 return XFS_DIR3_DATA_ENTSIZE(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 * location of . and .. in data space (always block 0)
299 static struct xfs_dir2_data_entry
*
300 xfs_dir2_data_dot_entry_p(
301 struct xfs_dir2_data_hdr
*hdr
)
303 return (struct xfs_dir2_data_entry
*)
304 ((char *)hdr
+ sizeof(struct xfs_dir2_data_hdr
));
307 static struct xfs_dir2_data_entry
*
308 xfs_dir2_data_dotdot_entry_p(
309 struct xfs_dir2_data_hdr
*hdr
)
311 return (struct xfs_dir2_data_entry
*)
312 ((char *)hdr
+ sizeof(struct xfs_dir2_data_hdr
) +
313 XFS_DIR2_DATA_ENTSIZE(1));
316 static struct xfs_dir2_data_entry
*
317 xfs_dir2_data_first_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_DIR2_DATA_ENTSIZE(1) +
323 XFS_DIR2_DATA_ENTSIZE(2));
326 static struct xfs_dir2_data_entry
*
327 xfs_dir2_ftype_data_dotdot_entry_p(
328 struct xfs_dir2_data_hdr
*hdr
)
330 return (struct xfs_dir2_data_entry
*)
331 ((char *)hdr
+ sizeof(struct xfs_dir2_data_hdr
) +
332 XFS_DIR3_DATA_ENTSIZE(1));
335 static struct xfs_dir2_data_entry
*
336 xfs_dir2_ftype_data_first_entry_p(
337 struct xfs_dir2_data_hdr
*hdr
)
339 return (struct xfs_dir2_data_entry
*)
340 ((char *)hdr
+ sizeof(struct xfs_dir2_data_hdr
) +
341 XFS_DIR3_DATA_ENTSIZE(1) +
342 XFS_DIR3_DATA_ENTSIZE(2));
345 static struct xfs_dir2_data_entry
*
346 xfs_dir3_data_dot_entry_p(
347 struct xfs_dir2_data_hdr
*hdr
)
349 return (struct xfs_dir2_data_entry
*)
350 ((char *)hdr
+ sizeof(struct xfs_dir3_data_hdr
));
353 static struct xfs_dir2_data_entry
*
354 xfs_dir3_data_dotdot_entry_p(
355 struct xfs_dir2_data_hdr
*hdr
)
357 return (struct xfs_dir2_data_entry
*)
358 ((char *)hdr
+ sizeof(struct xfs_dir3_data_hdr
) +
359 XFS_DIR3_DATA_ENTSIZE(1));
362 static struct xfs_dir2_data_entry
*
363 xfs_dir3_data_first_entry_p(
364 struct xfs_dir2_data_hdr
*hdr
)
366 return (struct xfs_dir2_data_entry
*)
367 ((char *)hdr
+ sizeof(struct xfs_dir3_data_hdr
) +
368 XFS_DIR3_DATA_ENTSIZE(1) +
369 XFS_DIR3_DATA_ENTSIZE(2));
372 static struct xfs_dir2_data_free
*
373 xfs_dir2_data_bestfree_p(struct xfs_dir2_data_hdr
*hdr
)
375 return hdr
->bestfree
;
378 static struct xfs_dir2_data_free
*
379 xfs_dir3_data_bestfree_p(struct xfs_dir2_data_hdr
*hdr
)
381 return ((struct xfs_dir3_data_hdr
*)hdr
)->best_free
;
384 static struct xfs_dir2_data_entry
*
385 xfs_dir2_data_entry_p(struct xfs_dir2_data_hdr
*hdr
)
387 return (struct xfs_dir2_data_entry
*)
388 ((char *)hdr
+ sizeof(struct xfs_dir2_data_hdr
));
391 static struct xfs_dir2_data_unused
*
392 xfs_dir2_data_unused_p(struct xfs_dir2_data_hdr
*hdr
)
394 return (struct xfs_dir2_data_unused
*)
395 ((char *)hdr
+ sizeof(struct xfs_dir2_data_hdr
));
398 static struct xfs_dir2_data_entry
*
399 xfs_dir3_data_entry_p(struct xfs_dir2_data_hdr
*hdr
)
401 return (struct xfs_dir2_data_entry
*)
402 ((char *)hdr
+ sizeof(struct xfs_dir3_data_hdr
));
405 static struct xfs_dir2_data_unused
*
406 xfs_dir3_data_unused_p(struct xfs_dir2_data_hdr
*hdr
)
408 return (struct xfs_dir2_data_unused
*)
409 ((char *)hdr
+ sizeof(struct xfs_dir3_data_hdr
));
414 * Directory Leaf block operations
417 xfs_dir2_max_leaf_ents(struct xfs_da_geometry
*geo
)
419 return (geo
->blksize
- sizeof(struct xfs_dir2_leaf_hdr
)) /
420 (uint
)sizeof(struct xfs_dir2_leaf_entry
);
423 static struct xfs_dir2_leaf_entry
*
424 xfs_dir2_leaf_ents_p(struct xfs_dir2_leaf
*lp
)
430 xfs_dir3_max_leaf_ents(struct xfs_da_geometry
*geo
)
432 return (geo
->blksize
- sizeof(struct xfs_dir3_leaf_hdr
)) /
433 (uint
)sizeof(struct xfs_dir2_leaf_entry
);
436 static struct xfs_dir2_leaf_entry
*
437 xfs_dir3_leaf_ents_p(struct xfs_dir2_leaf
*lp
)
439 return ((struct xfs_dir3_leaf
*)lp
)->__ents
;
443 xfs_dir2_leaf_hdr_from_disk(
444 struct xfs_dir3_icleaf_hdr
*to
,
445 struct xfs_dir2_leaf
*from
)
447 to
->forw
= be32_to_cpu(from
->hdr
.info
.forw
);
448 to
->back
= be32_to_cpu(from
->hdr
.info
.back
);
449 to
->magic
= be16_to_cpu(from
->hdr
.info
.magic
);
450 to
->count
= be16_to_cpu(from
->hdr
.count
);
451 to
->stale
= be16_to_cpu(from
->hdr
.stale
);
453 ASSERT(to
->magic
== XFS_DIR2_LEAF1_MAGIC
||
454 to
->magic
== XFS_DIR2_LEAFN_MAGIC
);
458 xfs_dir2_leaf_hdr_to_disk(
459 struct xfs_dir2_leaf
*to
,
460 struct xfs_dir3_icleaf_hdr
*from
)
462 ASSERT(from
->magic
== XFS_DIR2_LEAF1_MAGIC
||
463 from
->magic
== XFS_DIR2_LEAFN_MAGIC
);
465 to
->hdr
.info
.forw
= cpu_to_be32(from
->forw
);
466 to
->hdr
.info
.back
= cpu_to_be32(from
->back
);
467 to
->hdr
.info
.magic
= cpu_to_be16(from
->magic
);
468 to
->hdr
.count
= cpu_to_be16(from
->count
);
469 to
->hdr
.stale
= cpu_to_be16(from
->stale
);
473 xfs_dir3_leaf_hdr_from_disk(
474 struct xfs_dir3_icleaf_hdr
*to
,
475 struct xfs_dir2_leaf
*from
)
477 struct xfs_dir3_leaf_hdr
*hdr3
= (struct xfs_dir3_leaf_hdr
*)from
;
479 to
->forw
= be32_to_cpu(hdr3
->info
.hdr
.forw
);
480 to
->back
= be32_to_cpu(hdr3
->info
.hdr
.back
);
481 to
->magic
= be16_to_cpu(hdr3
->info
.hdr
.magic
);
482 to
->count
= be16_to_cpu(hdr3
->count
);
483 to
->stale
= be16_to_cpu(hdr3
->stale
);
485 ASSERT(to
->magic
== XFS_DIR3_LEAF1_MAGIC
||
486 to
->magic
== XFS_DIR3_LEAFN_MAGIC
);
490 xfs_dir3_leaf_hdr_to_disk(
491 struct xfs_dir2_leaf
*to
,
492 struct xfs_dir3_icleaf_hdr
*from
)
494 struct xfs_dir3_leaf_hdr
*hdr3
= (struct xfs_dir3_leaf_hdr
*)to
;
496 ASSERT(from
->magic
== XFS_DIR3_LEAF1_MAGIC
||
497 from
->magic
== XFS_DIR3_LEAFN_MAGIC
);
499 hdr3
->info
.hdr
.forw
= cpu_to_be32(from
->forw
);
500 hdr3
->info
.hdr
.back
= cpu_to_be32(from
->back
);
501 hdr3
->info
.hdr
.magic
= cpu_to_be16(from
->magic
);
502 hdr3
->count
= cpu_to_be16(from
->count
);
503 hdr3
->stale
= cpu_to_be16(from
->stale
);
508 * Directory/Attribute Node block operations
510 static struct xfs_da_node_entry
*
511 xfs_da2_node_tree_p(struct xfs_da_intnode
*dap
)
516 static struct xfs_da_node_entry
*
517 xfs_da3_node_tree_p(struct xfs_da_intnode
*dap
)
519 return ((struct xfs_da3_intnode
*)dap
)->__btree
;
523 xfs_da2_node_hdr_from_disk(
524 struct xfs_da3_icnode_hdr
*to
,
525 struct xfs_da_intnode
*from
)
527 ASSERT(from
->hdr
.info
.magic
== cpu_to_be16(XFS_DA_NODE_MAGIC
));
528 to
->forw
= be32_to_cpu(from
->hdr
.info
.forw
);
529 to
->back
= be32_to_cpu(from
->hdr
.info
.back
);
530 to
->magic
= be16_to_cpu(from
->hdr
.info
.magic
);
531 to
->count
= be16_to_cpu(from
->hdr
.__count
);
532 to
->level
= be16_to_cpu(from
->hdr
.__level
);
536 xfs_da2_node_hdr_to_disk(
537 struct xfs_da_intnode
*to
,
538 struct xfs_da3_icnode_hdr
*from
)
540 ASSERT(from
->magic
== XFS_DA_NODE_MAGIC
);
541 to
->hdr
.info
.forw
= cpu_to_be32(from
->forw
);
542 to
->hdr
.info
.back
= cpu_to_be32(from
->back
);
543 to
->hdr
.info
.magic
= cpu_to_be16(from
->magic
);
544 to
->hdr
.__count
= cpu_to_be16(from
->count
);
545 to
->hdr
.__level
= cpu_to_be16(from
->level
);
549 xfs_da3_node_hdr_from_disk(
550 struct xfs_da3_icnode_hdr
*to
,
551 struct xfs_da_intnode
*from
)
553 struct xfs_da3_node_hdr
*hdr3
= (struct xfs_da3_node_hdr
*)from
;
555 ASSERT(from
->hdr
.info
.magic
== cpu_to_be16(XFS_DA3_NODE_MAGIC
));
556 to
->forw
= be32_to_cpu(hdr3
->info
.hdr
.forw
);
557 to
->back
= be32_to_cpu(hdr3
->info
.hdr
.back
);
558 to
->magic
= be16_to_cpu(hdr3
->info
.hdr
.magic
);
559 to
->count
= be16_to_cpu(hdr3
->__count
);
560 to
->level
= be16_to_cpu(hdr3
->__level
);
564 xfs_da3_node_hdr_to_disk(
565 struct xfs_da_intnode
*to
,
566 struct xfs_da3_icnode_hdr
*from
)
568 struct xfs_da3_node_hdr
*hdr3
= (struct xfs_da3_node_hdr
*)to
;
570 ASSERT(from
->magic
== XFS_DA3_NODE_MAGIC
);
571 hdr3
->info
.hdr
.forw
= cpu_to_be32(from
->forw
);
572 hdr3
->info
.hdr
.back
= cpu_to_be32(from
->back
);
573 hdr3
->info
.hdr
.magic
= cpu_to_be16(from
->magic
);
574 hdr3
->__count
= cpu_to_be16(from
->count
);
575 hdr3
->__level
= cpu_to_be16(from
->level
);
580 * Directory free space block operations
583 xfs_dir2_free_max_bests(struct xfs_da_geometry
*geo
)
585 return (geo
->blksize
- sizeof(struct xfs_dir2_free_hdr
)) /
586 sizeof(xfs_dir2_data_off_t
);
590 xfs_dir2_free_bests_p(struct xfs_dir2_free
*free
)
592 return (__be16
*)((char *)free
+ sizeof(struct xfs_dir2_free_hdr
));
596 * Convert data space db to the corresponding free db.
599 xfs_dir2_db_to_fdb(struct xfs_da_geometry
*geo
, xfs_dir2_db_t db
)
601 return xfs_dir2_byte_to_db(geo
, XFS_DIR2_FREE_OFFSET
) +
602 (db
/ xfs_dir2_free_max_bests(geo
));
606 * Convert data space db to the corresponding index in a free db.
609 xfs_dir2_db_to_fdindex(struct xfs_da_geometry
*geo
, xfs_dir2_db_t db
)
611 return db
% xfs_dir2_free_max_bests(geo
);
615 xfs_dir3_free_max_bests(struct xfs_da_geometry
*geo
)
617 return (geo
->blksize
- sizeof(struct xfs_dir3_free_hdr
)) /
618 sizeof(xfs_dir2_data_off_t
);
622 xfs_dir3_free_bests_p(struct xfs_dir2_free
*free
)
624 return (__be16
*)((char *)free
+ sizeof(struct xfs_dir3_free_hdr
));
628 * Convert data space db to the corresponding free db.
631 xfs_dir3_db_to_fdb(struct xfs_da_geometry
*geo
, xfs_dir2_db_t db
)
633 return xfs_dir2_byte_to_db(geo
, XFS_DIR2_FREE_OFFSET
) +
634 (db
/ xfs_dir3_free_max_bests(geo
));
638 * Convert data space db to the corresponding index in a free db.
641 xfs_dir3_db_to_fdindex(struct xfs_da_geometry
*geo
, xfs_dir2_db_t db
)
643 return db
% xfs_dir3_free_max_bests(geo
);
647 xfs_dir2_free_hdr_from_disk(
648 struct xfs_dir3_icfree_hdr
*to
,
649 struct xfs_dir2_free
*from
)
651 to
->magic
= be32_to_cpu(from
->hdr
.magic
);
652 to
->firstdb
= be32_to_cpu(from
->hdr
.firstdb
);
653 to
->nvalid
= be32_to_cpu(from
->hdr
.nvalid
);
654 to
->nused
= be32_to_cpu(from
->hdr
.nused
);
655 ASSERT(to
->magic
== XFS_DIR2_FREE_MAGIC
);
659 xfs_dir2_free_hdr_to_disk(
660 struct xfs_dir2_free
*to
,
661 struct xfs_dir3_icfree_hdr
*from
)
663 ASSERT(from
->magic
== XFS_DIR2_FREE_MAGIC
);
665 to
->hdr
.magic
= cpu_to_be32(from
->magic
);
666 to
->hdr
.firstdb
= cpu_to_be32(from
->firstdb
);
667 to
->hdr
.nvalid
= cpu_to_be32(from
->nvalid
);
668 to
->hdr
.nused
= cpu_to_be32(from
->nused
);
672 xfs_dir3_free_hdr_from_disk(
673 struct xfs_dir3_icfree_hdr
*to
,
674 struct xfs_dir2_free
*from
)
676 struct xfs_dir3_free_hdr
*hdr3
= (struct xfs_dir3_free_hdr
*)from
;
678 to
->magic
= be32_to_cpu(hdr3
->hdr
.magic
);
679 to
->firstdb
= be32_to_cpu(hdr3
->firstdb
);
680 to
->nvalid
= be32_to_cpu(hdr3
->nvalid
);
681 to
->nused
= be32_to_cpu(hdr3
->nused
);
683 ASSERT(to
->magic
== XFS_DIR3_FREE_MAGIC
);
687 xfs_dir3_free_hdr_to_disk(
688 struct xfs_dir2_free
*to
,
689 struct xfs_dir3_icfree_hdr
*from
)
691 struct xfs_dir3_free_hdr
*hdr3
= (struct xfs_dir3_free_hdr
*)to
;
693 ASSERT(from
->magic
== XFS_DIR3_FREE_MAGIC
);
695 hdr3
->hdr
.magic
= cpu_to_be32(from
->magic
);
696 hdr3
->firstdb
= cpu_to_be32(from
->firstdb
);
697 hdr3
->nvalid
= cpu_to_be32(from
->nvalid
);
698 hdr3
->nused
= cpu_to_be32(from
->nused
);
701 static const struct xfs_dir_ops xfs_dir2_ops
= {
702 .sf_entsize
= xfs_dir2_sf_entsize
,
703 .sf_nextentry
= xfs_dir2_sf_nextentry
,
704 .sf_get_ftype
= xfs_dir2_sfe_get_ftype
,
705 .sf_put_ftype
= xfs_dir2_sfe_put_ftype
,
706 .sf_get_ino
= xfs_dir2_sfe_get_ino
,
707 .sf_put_ino
= xfs_dir2_sfe_put_ino
,
708 .sf_get_parent_ino
= xfs_dir2_sf_get_parent_ino
,
709 .sf_put_parent_ino
= xfs_dir2_sf_put_parent_ino
,
711 .data_entsize
= xfs_dir2_data_entsize
,
712 .data_get_ftype
= xfs_dir2_data_get_ftype
,
713 .data_put_ftype
= xfs_dir2_data_put_ftype
,
714 .data_entry_tag_p
= xfs_dir2_data_entry_tag_p
,
715 .data_bestfree_p
= xfs_dir2_data_bestfree_p
,
717 .data_dot_offset
= sizeof(struct xfs_dir2_data_hdr
),
718 .data_dotdot_offset
= sizeof(struct xfs_dir2_data_hdr
) +
719 XFS_DIR2_DATA_ENTSIZE(1),
720 .data_first_offset
= sizeof(struct xfs_dir2_data_hdr
) +
721 XFS_DIR2_DATA_ENTSIZE(1) +
722 XFS_DIR2_DATA_ENTSIZE(2),
723 .data_entry_offset
= sizeof(struct xfs_dir2_data_hdr
),
725 .data_dot_entry_p
= xfs_dir2_data_dot_entry_p
,
726 .data_dotdot_entry_p
= xfs_dir2_data_dotdot_entry_p
,
727 .data_first_entry_p
= xfs_dir2_data_first_entry_p
,
728 .data_entry_p
= xfs_dir2_data_entry_p
,
729 .data_unused_p
= xfs_dir2_data_unused_p
,
731 .leaf_hdr_size
= sizeof(struct xfs_dir2_leaf_hdr
),
732 .leaf_hdr_to_disk
= xfs_dir2_leaf_hdr_to_disk
,
733 .leaf_hdr_from_disk
= xfs_dir2_leaf_hdr_from_disk
,
734 .leaf_max_ents
= xfs_dir2_max_leaf_ents
,
735 .leaf_ents_p
= xfs_dir2_leaf_ents_p
,
737 .node_hdr_size
= sizeof(struct xfs_da_node_hdr
),
738 .node_hdr_to_disk
= xfs_da2_node_hdr_to_disk
,
739 .node_hdr_from_disk
= xfs_da2_node_hdr_from_disk
,
740 .node_tree_p
= xfs_da2_node_tree_p
,
742 .free_hdr_size
= sizeof(struct xfs_dir2_free_hdr
),
743 .free_hdr_to_disk
= xfs_dir2_free_hdr_to_disk
,
744 .free_hdr_from_disk
= xfs_dir2_free_hdr_from_disk
,
745 .free_max_bests
= xfs_dir2_free_max_bests
,
746 .free_bests_p
= xfs_dir2_free_bests_p
,
747 .db_to_fdb
= xfs_dir2_db_to_fdb
,
748 .db_to_fdindex
= xfs_dir2_db_to_fdindex
,
751 static const struct xfs_dir_ops xfs_dir2_ftype_ops
= {
752 .sf_entsize
= xfs_dir3_sf_entsize
,
753 .sf_nextentry
= xfs_dir3_sf_nextentry
,
754 .sf_get_ftype
= xfs_dir3_sfe_get_ftype
,
755 .sf_put_ftype
= xfs_dir3_sfe_put_ftype
,
756 .sf_get_ino
= xfs_dir3_sfe_get_ino
,
757 .sf_put_ino
= xfs_dir3_sfe_put_ino
,
758 .sf_get_parent_ino
= xfs_dir2_sf_get_parent_ino
,
759 .sf_put_parent_ino
= xfs_dir2_sf_put_parent_ino
,
761 .data_entsize
= xfs_dir3_data_entsize
,
762 .data_get_ftype
= xfs_dir3_data_get_ftype
,
763 .data_put_ftype
= xfs_dir3_data_put_ftype
,
764 .data_entry_tag_p
= xfs_dir3_data_entry_tag_p
,
765 .data_bestfree_p
= xfs_dir2_data_bestfree_p
,
767 .data_dot_offset
= sizeof(struct xfs_dir2_data_hdr
),
768 .data_dotdot_offset
= sizeof(struct xfs_dir2_data_hdr
) +
769 XFS_DIR3_DATA_ENTSIZE(1),
770 .data_first_offset
= sizeof(struct xfs_dir2_data_hdr
) +
771 XFS_DIR3_DATA_ENTSIZE(1) +
772 XFS_DIR3_DATA_ENTSIZE(2),
773 .data_entry_offset
= sizeof(struct xfs_dir2_data_hdr
),
775 .data_dot_entry_p
= xfs_dir2_data_dot_entry_p
,
776 .data_dotdot_entry_p
= xfs_dir2_ftype_data_dotdot_entry_p
,
777 .data_first_entry_p
= xfs_dir2_ftype_data_first_entry_p
,
778 .data_entry_p
= xfs_dir2_data_entry_p
,
779 .data_unused_p
= xfs_dir2_data_unused_p
,
781 .leaf_hdr_size
= sizeof(struct xfs_dir2_leaf_hdr
),
782 .leaf_hdr_to_disk
= xfs_dir2_leaf_hdr_to_disk
,
783 .leaf_hdr_from_disk
= xfs_dir2_leaf_hdr_from_disk
,
784 .leaf_max_ents
= xfs_dir2_max_leaf_ents
,
785 .leaf_ents_p
= xfs_dir2_leaf_ents_p
,
787 .node_hdr_size
= sizeof(struct xfs_da_node_hdr
),
788 .node_hdr_to_disk
= xfs_da2_node_hdr_to_disk
,
789 .node_hdr_from_disk
= xfs_da2_node_hdr_from_disk
,
790 .node_tree_p
= xfs_da2_node_tree_p
,
792 .free_hdr_size
= sizeof(struct xfs_dir2_free_hdr
),
793 .free_hdr_to_disk
= xfs_dir2_free_hdr_to_disk
,
794 .free_hdr_from_disk
= xfs_dir2_free_hdr_from_disk
,
795 .free_max_bests
= xfs_dir2_free_max_bests
,
796 .free_bests_p
= xfs_dir2_free_bests_p
,
797 .db_to_fdb
= xfs_dir2_db_to_fdb
,
798 .db_to_fdindex
= xfs_dir2_db_to_fdindex
,
801 static const struct xfs_dir_ops xfs_dir3_ops
= {
802 .sf_entsize
= xfs_dir3_sf_entsize
,
803 .sf_nextentry
= xfs_dir3_sf_nextentry
,
804 .sf_get_ftype
= xfs_dir3_sfe_get_ftype
,
805 .sf_put_ftype
= xfs_dir3_sfe_put_ftype
,
806 .sf_get_ino
= xfs_dir3_sfe_get_ino
,
807 .sf_put_ino
= xfs_dir3_sfe_put_ino
,
808 .sf_get_parent_ino
= xfs_dir2_sf_get_parent_ino
,
809 .sf_put_parent_ino
= xfs_dir2_sf_put_parent_ino
,
811 .data_entsize
= xfs_dir3_data_entsize
,
812 .data_get_ftype
= xfs_dir3_data_get_ftype
,
813 .data_put_ftype
= xfs_dir3_data_put_ftype
,
814 .data_entry_tag_p
= xfs_dir3_data_entry_tag_p
,
815 .data_bestfree_p
= xfs_dir3_data_bestfree_p
,
817 .data_dot_offset
= sizeof(struct xfs_dir3_data_hdr
),
818 .data_dotdot_offset
= sizeof(struct xfs_dir3_data_hdr
) +
819 XFS_DIR3_DATA_ENTSIZE(1),
820 .data_first_offset
= sizeof(struct xfs_dir3_data_hdr
) +
821 XFS_DIR3_DATA_ENTSIZE(1) +
822 XFS_DIR3_DATA_ENTSIZE(2),
823 .data_entry_offset
= sizeof(struct xfs_dir3_data_hdr
),
825 .data_dot_entry_p
= xfs_dir3_data_dot_entry_p
,
826 .data_dotdot_entry_p
= xfs_dir3_data_dotdot_entry_p
,
827 .data_first_entry_p
= xfs_dir3_data_first_entry_p
,
828 .data_entry_p
= xfs_dir3_data_entry_p
,
829 .data_unused_p
= xfs_dir3_data_unused_p
,
831 .leaf_hdr_size
= sizeof(struct xfs_dir3_leaf_hdr
),
832 .leaf_hdr_to_disk
= xfs_dir3_leaf_hdr_to_disk
,
833 .leaf_hdr_from_disk
= xfs_dir3_leaf_hdr_from_disk
,
834 .leaf_max_ents
= xfs_dir3_max_leaf_ents
,
835 .leaf_ents_p
= xfs_dir3_leaf_ents_p
,
837 .node_hdr_size
= sizeof(struct xfs_da3_node_hdr
),
838 .node_hdr_to_disk
= xfs_da3_node_hdr_to_disk
,
839 .node_hdr_from_disk
= xfs_da3_node_hdr_from_disk
,
840 .node_tree_p
= xfs_da3_node_tree_p
,
842 .free_hdr_size
= sizeof(struct xfs_dir3_free_hdr
),
843 .free_hdr_to_disk
= xfs_dir3_free_hdr_to_disk
,
844 .free_hdr_from_disk
= xfs_dir3_free_hdr_from_disk
,
845 .free_max_bests
= xfs_dir3_free_max_bests
,
846 .free_bests_p
= xfs_dir3_free_bests_p
,
847 .db_to_fdb
= xfs_dir3_db_to_fdb
,
848 .db_to_fdindex
= xfs_dir3_db_to_fdindex
,
851 static const struct xfs_dir_ops xfs_dir2_nondir_ops
= {
852 .node_hdr_size
= sizeof(struct xfs_da_node_hdr
),
853 .node_hdr_to_disk
= xfs_da2_node_hdr_to_disk
,
854 .node_hdr_from_disk
= xfs_da2_node_hdr_from_disk
,
855 .node_tree_p
= xfs_da2_node_tree_p
,
858 static const struct xfs_dir_ops xfs_dir3_nondir_ops
= {
859 .node_hdr_size
= sizeof(struct xfs_da3_node_hdr
),
860 .node_hdr_to_disk
= xfs_da3_node_hdr_to_disk
,
861 .node_hdr_from_disk
= xfs_da3_node_hdr_from_disk
,
862 .node_tree_p
= xfs_da3_node_tree_p
,
866 * Return the ops structure according to the current config. If we are passed
867 * an inode, then that overrides the default config we use which is based on
870 const struct xfs_dir_ops
*
872 struct xfs_mount
*mp
,
873 struct xfs_inode
*dp
)
877 if (mp
->m_dir_inode_ops
)
878 return mp
->m_dir_inode_ops
;
879 if (xfs_sb_version_hascrc(&mp
->m_sb
))
880 return &xfs_dir3_ops
;
881 if (xfs_sb_version_hasftype(&mp
->m_sb
))
882 return &xfs_dir2_ftype_ops
;
883 return &xfs_dir2_ops
;
886 const struct xfs_dir_ops
*
888 struct xfs_mount
*mp
,
889 struct xfs_inode
*dp
)
893 if (mp
->m_nondir_inode_ops
)
894 return mp
->m_nondir_inode_ops
;
895 if (xfs_sb_version_hascrc(&mp
->m_sb
))
896 return &xfs_dir3_nondir_ops
;
897 return &xfs_dir2_nondir_ops
;