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"
27 #include "xfs_mount.h"
28 #include "xfs_da_format.h"
29 #include "xfs_inode.h"
33 * Shortform directory ops
37 struct xfs_dir2_sf_hdr
*hdr
,
40 int count
= sizeof(struct xfs_dir2_sf_entry
); /* namelen + offset */
42 count
+= len
; /* name */
43 count
+= hdr
->i8count
? sizeof(xfs_dir2_ino8_t
) :
44 sizeof(xfs_dir2_ino4_t
); /* ino # */
50 struct xfs_dir2_sf_hdr
*hdr
,
53 return xfs_dir2_sf_entsize(hdr
, len
) + sizeof(__uint8_t
);
56 static struct xfs_dir2_sf_entry
*
57 xfs_dir2_sf_nextentry(
58 struct xfs_dir2_sf_hdr
*hdr
,
59 struct xfs_dir2_sf_entry
*sfep
)
61 return (struct xfs_dir2_sf_entry
*)
62 ((char *)sfep
+ xfs_dir2_sf_entsize(hdr
, sfep
->namelen
));
65 static struct xfs_dir2_sf_entry
*
66 xfs_dir3_sf_nextentry(
67 struct xfs_dir2_sf_hdr
*hdr
,
68 struct xfs_dir2_sf_entry
*sfep
)
70 return (struct xfs_dir2_sf_entry
*)
71 ((char *)sfep
+ xfs_dir3_sf_entsize(hdr
, sfep
->namelen
));
76 * For filetype enabled shortform directories, the file type field is stored at
77 * the end of the name. Because it's only a single byte, endian conversion is
78 * not necessary. For non-filetype enable directories, the type is always
79 * unknown and we never store the value.
82 xfs_dir2_sfe_get_ftype(
83 struct xfs_dir2_sf_entry
*sfep
)
85 return XFS_DIR3_FT_UNKNOWN
;
89 xfs_dir2_sfe_put_ftype(
90 struct xfs_dir2_sf_entry
*sfep
,
93 ASSERT(ftype
< XFS_DIR3_FT_MAX
);
97 xfs_dir3_sfe_get_ftype(
98 struct xfs_dir2_sf_entry
*sfep
)
102 ftype
= sfep
->name
[sfep
->namelen
];
103 if (ftype
>= XFS_DIR3_FT_MAX
)
104 return XFS_DIR3_FT_UNKNOWN
;
109 xfs_dir3_sfe_put_ftype(
110 struct xfs_dir2_sf_entry
*sfep
,
113 ASSERT(ftype
< XFS_DIR3_FT_MAX
);
115 sfep
->name
[sfep
->namelen
] = ftype
;
119 * Inode numbers in short-form directories can come in two versions,
120 * either 4 bytes or 8 bytes wide. These helpers deal with the
121 * two forms transparently by looking at the headers i8count field.
123 * For 64-bit inode number the most significant byte must be zero.
127 struct xfs_dir2_sf_hdr
*hdr
,
128 xfs_dir2_inou_t
*from
)
131 return get_unaligned_be64(&from
->i8
.i
) & 0x00ffffffffffffffULL
;
133 return get_unaligned_be32(&from
->i4
.i
);
138 struct xfs_dir2_sf_hdr
*hdr
,
142 ASSERT((ino
& 0xff00000000000000ULL
) == 0);
145 put_unaligned_be64(ino
, &to
->i8
.i
);
147 put_unaligned_be32(ino
, &to
->i4
.i
);
151 xfs_dir2_sf_get_parent_ino(
152 struct xfs_dir2_sf_hdr
*hdr
)
154 return xfs_dir2_sf_get_ino(hdr
, &hdr
->parent
);
158 xfs_dir2_sf_put_parent_ino(
159 struct xfs_dir2_sf_hdr
*hdr
,
162 xfs_dir2_sf_put_ino(hdr
, &hdr
->parent
, ino
);
166 * In short-form directory entries the inode numbers are stored at variable
167 * offset behind the entry name. If the entry stores a filetype value, then it
168 * sits between the name and the inode number. Hence the inode numbers may only
169 * be accessed through the helpers below.
172 xfs_dir2_sfe_get_ino(
173 struct xfs_dir2_sf_hdr
*hdr
,
174 struct xfs_dir2_sf_entry
*sfep
)
176 return xfs_dir2_sf_get_ino(hdr
,
177 (xfs_dir2_inou_t
*)&sfep
->name
[sfep
->namelen
]);
181 xfs_dir2_sfe_put_ino(
182 struct xfs_dir2_sf_hdr
*hdr
,
183 struct xfs_dir2_sf_entry
*sfep
,
186 xfs_dir2_sf_put_ino(hdr
,
187 (xfs_dir2_inou_t
*)&sfep
->name
[sfep
->namelen
], ino
);
191 xfs_dir3_sfe_get_ino(
192 struct xfs_dir2_sf_hdr
*hdr
,
193 struct xfs_dir2_sf_entry
*sfep
)
195 return xfs_dir2_sf_get_ino(hdr
,
196 (xfs_dir2_inou_t
*)&sfep
->name
[sfep
->namelen
+ 1]);
200 xfs_dir3_sfe_put_ino(
201 struct xfs_dir2_sf_hdr
*hdr
,
202 struct xfs_dir2_sf_entry
*sfep
,
205 xfs_dir2_sf_put_ino(hdr
,
206 (xfs_dir2_inou_t
*)&sfep
->name
[sfep
->namelen
+ 1], ino
);
211 * Directory data block operations
215 * For special situations, the dirent size ends up fixed because we always know
216 * what the size of the entry is. That's true for the "." and "..", and
217 * therefore we know that they are a fixed size and hence their offsets are
218 * constant, as is the first entry.
220 * Hence, this calculation is written as a macro to be able to be calculated at
221 * compile time and so certain offsets can be calculated directly in the
222 * structure initaliser via the macro. There are two macros - one for dirents
223 * with ftype and without so there are no unresolvable conditionals in the
224 * calculations. We also use round_up() as XFS_DIR2_DATA_ALIGN is always a power
225 * of 2 and the compiler doesn't reject it (unlike roundup()).
227 #define XFS_DIR2_DATA_ENTSIZE(n) \
228 round_up((offsetof(struct xfs_dir2_data_entry, name[0]) + (n) + \
229 sizeof(xfs_dir2_data_off_t)), XFS_DIR2_DATA_ALIGN)
231 #define XFS_DIR3_DATA_ENTSIZE(n) \
232 round_up((offsetof(struct xfs_dir2_data_entry, name[0]) + (n) + \
233 sizeof(xfs_dir2_data_off_t) + sizeof(__uint8_t)), \
237 xfs_dir2_data_entsize(
240 return XFS_DIR2_DATA_ENTSIZE(n
);
244 xfs_dir3_data_entsize(
247 return XFS_DIR3_DATA_ENTSIZE(n
);
251 xfs_dir2_data_get_ftype(
252 struct xfs_dir2_data_entry
*dep
)
254 return XFS_DIR3_FT_UNKNOWN
;
258 xfs_dir2_data_put_ftype(
259 struct xfs_dir2_data_entry
*dep
,
262 ASSERT(ftype
< XFS_DIR3_FT_MAX
);
266 xfs_dir3_data_get_ftype(
267 struct xfs_dir2_data_entry
*dep
)
269 __uint8_t ftype
= dep
->name
[dep
->namelen
];
271 ASSERT(ftype
< XFS_DIR3_FT_MAX
);
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_mount
*mp
)
430 return (mp
->m_dirblksize
- 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_mount
*mp
)
443 return (mp
->m_dirblksize
- 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_mount
*mp
)
596 return (mp
->m_dirblksize
- 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_mount
*mp
, xfs_dir2_db_t db
)
612 return XFS_DIR2_FREE_FIRSTDB(mp
) + db
/ xfs_dir2_free_max_bests(mp
);
616 * Convert data space db to the corresponding index in a free db.
619 xfs_dir2_db_to_fdindex(struct xfs_mount
*mp
, xfs_dir2_db_t db
)
621 return db
% xfs_dir2_free_max_bests(mp
);
625 xfs_dir3_free_max_bests(struct xfs_mount
*mp
)
627 return (mp
->m_dirblksize
- sizeof(struct xfs_dir3_free_hdr
)) /
628 sizeof(xfs_dir2_data_off_t
);
632 xfs_dir3_free_bests_p(struct xfs_dir2_free
*free
)
634 return (__be16
*)((char *)free
+ sizeof(struct xfs_dir3_free_hdr
));
638 * Convert data space db to the corresponding free db.
641 xfs_dir3_db_to_fdb(struct xfs_mount
*mp
, xfs_dir2_db_t db
)
643 return XFS_DIR2_FREE_FIRSTDB(mp
) + db
/ xfs_dir3_free_max_bests(mp
);
647 * Convert data space db to the corresponding index in a free db.
650 xfs_dir3_db_to_fdindex(struct xfs_mount
*mp
, xfs_dir2_db_t db
)
652 return db
% xfs_dir3_free_max_bests(mp
);
656 xfs_dir2_free_hdr_from_disk(
657 struct xfs_dir3_icfree_hdr
*to
,
658 struct xfs_dir2_free
*from
)
660 to
->magic
= be32_to_cpu(from
->hdr
.magic
);
661 to
->firstdb
= be32_to_cpu(from
->hdr
.firstdb
);
662 to
->nvalid
= be32_to_cpu(from
->hdr
.nvalid
);
663 to
->nused
= be32_to_cpu(from
->hdr
.nused
);
664 ASSERT(to
->magic
== XFS_DIR2_FREE_MAGIC
);
668 xfs_dir2_free_hdr_to_disk(
669 struct xfs_dir2_free
*to
,
670 struct xfs_dir3_icfree_hdr
*from
)
672 ASSERT(from
->magic
== XFS_DIR2_FREE_MAGIC
);
674 to
->hdr
.magic
= cpu_to_be32(from
->magic
);
675 to
->hdr
.firstdb
= cpu_to_be32(from
->firstdb
);
676 to
->hdr
.nvalid
= cpu_to_be32(from
->nvalid
);
677 to
->hdr
.nused
= cpu_to_be32(from
->nused
);
681 xfs_dir3_free_hdr_from_disk(
682 struct xfs_dir3_icfree_hdr
*to
,
683 struct xfs_dir2_free
*from
)
685 struct xfs_dir3_free_hdr
*hdr3
= (struct xfs_dir3_free_hdr
*)from
;
687 to
->magic
= be32_to_cpu(hdr3
->hdr
.magic
);
688 to
->firstdb
= be32_to_cpu(hdr3
->firstdb
);
689 to
->nvalid
= be32_to_cpu(hdr3
->nvalid
);
690 to
->nused
= be32_to_cpu(hdr3
->nused
);
692 ASSERT(to
->magic
== XFS_DIR3_FREE_MAGIC
);
696 xfs_dir3_free_hdr_to_disk(
697 struct xfs_dir2_free
*to
,
698 struct xfs_dir3_icfree_hdr
*from
)
700 struct xfs_dir3_free_hdr
*hdr3
= (struct xfs_dir3_free_hdr
*)to
;
702 ASSERT(from
->magic
== XFS_DIR3_FREE_MAGIC
);
704 hdr3
->hdr
.magic
= cpu_to_be32(from
->magic
);
705 hdr3
->firstdb
= cpu_to_be32(from
->firstdb
);
706 hdr3
->nvalid
= cpu_to_be32(from
->nvalid
);
707 hdr3
->nused
= cpu_to_be32(from
->nused
);
710 static const struct xfs_dir_ops xfs_dir2_ops
= {
711 .sf_entsize
= xfs_dir2_sf_entsize
,
712 .sf_nextentry
= xfs_dir2_sf_nextentry
,
713 .sf_get_ftype
= xfs_dir2_sfe_get_ftype
,
714 .sf_put_ftype
= xfs_dir2_sfe_put_ftype
,
715 .sf_get_ino
= xfs_dir2_sfe_get_ino
,
716 .sf_put_ino
= xfs_dir2_sfe_put_ino
,
717 .sf_get_parent_ino
= xfs_dir2_sf_get_parent_ino
,
718 .sf_put_parent_ino
= xfs_dir2_sf_put_parent_ino
,
720 .data_entsize
= xfs_dir2_data_entsize
,
721 .data_get_ftype
= xfs_dir2_data_get_ftype
,
722 .data_put_ftype
= xfs_dir2_data_put_ftype
,
723 .data_entry_tag_p
= xfs_dir2_data_entry_tag_p
,
724 .data_bestfree_p
= xfs_dir2_data_bestfree_p
,
726 .data_dot_offset
= sizeof(struct xfs_dir2_data_hdr
),
727 .data_dotdot_offset
= sizeof(struct xfs_dir2_data_hdr
) +
728 XFS_DIR2_DATA_ENTSIZE(1),
729 .data_first_offset
= sizeof(struct xfs_dir2_data_hdr
) +
730 XFS_DIR2_DATA_ENTSIZE(1) +
731 XFS_DIR2_DATA_ENTSIZE(2),
732 .data_entry_offset
= sizeof(struct xfs_dir2_data_hdr
),
734 .data_dot_entry_p
= xfs_dir2_data_dot_entry_p
,
735 .data_dotdot_entry_p
= xfs_dir2_data_dotdot_entry_p
,
736 .data_first_entry_p
= xfs_dir2_data_first_entry_p
,
737 .data_entry_p
= xfs_dir2_data_entry_p
,
738 .data_unused_p
= xfs_dir2_data_unused_p
,
740 .leaf_hdr_size
= sizeof(struct xfs_dir2_leaf_hdr
),
741 .leaf_hdr_to_disk
= xfs_dir2_leaf_hdr_to_disk
,
742 .leaf_hdr_from_disk
= xfs_dir2_leaf_hdr_from_disk
,
743 .leaf_max_ents
= xfs_dir2_max_leaf_ents
,
744 .leaf_ents_p
= xfs_dir2_leaf_ents_p
,
746 .node_hdr_size
= sizeof(struct xfs_da_node_hdr
),
747 .node_hdr_to_disk
= xfs_da2_node_hdr_to_disk
,
748 .node_hdr_from_disk
= xfs_da2_node_hdr_from_disk
,
749 .node_tree_p
= xfs_da2_node_tree_p
,
751 .free_hdr_size
= sizeof(struct xfs_dir2_free_hdr
),
752 .free_hdr_to_disk
= xfs_dir2_free_hdr_to_disk
,
753 .free_hdr_from_disk
= xfs_dir2_free_hdr_from_disk
,
754 .free_max_bests
= xfs_dir2_free_max_bests
,
755 .free_bests_p
= xfs_dir2_free_bests_p
,
756 .db_to_fdb
= xfs_dir2_db_to_fdb
,
757 .db_to_fdindex
= xfs_dir2_db_to_fdindex
,
760 static const struct xfs_dir_ops xfs_dir2_ftype_ops
= {
761 .sf_entsize
= xfs_dir3_sf_entsize
,
762 .sf_nextentry
= xfs_dir3_sf_nextentry
,
763 .sf_get_ftype
= xfs_dir3_sfe_get_ftype
,
764 .sf_put_ftype
= xfs_dir3_sfe_put_ftype
,
765 .sf_get_ino
= xfs_dir3_sfe_get_ino
,
766 .sf_put_ino
= xfs_dir3_sfe_put_ino
,
767 .sf_get_parent_ino
= xfs_dir2_sf_get_parent_ino
,
768 .sf_put_parent_ino
= xfs_dir2_sf_put_parent_ino
,
770 .data_entsize
= xfs_dir3_data_entsize
,
771 .data_get_ftype
= xfs_dir3_data_get_ftype
,
772 .data_put_ftype
= xfs_dir3_data_put_ftype
,
773 .data_entry_tag_p
= xfs_dir3_data_entry_tag_p
,
774 .data_bestfree_p
= xfs_dir2_data_bestfree_p
,
776 .data_dot_offset
= sizeof(struct xfs_dir2_data_hdr
),
777 .data_dotdot_offset
= sizeof(struct xfs_dir2_data_hdr
) +
778 XFS_DIR3_DATA_ENTSIZE(1),
779 .data_first_offset
= sizeof(struct xfs_dir2_data_hdr
) +
780 XFS_DIR3_DATA_ENTSIZE(1) +
781 XFS_DIR3_DATA_ENTSIZE(2),
782 .data_entry_offset
= sizeof(struct xfs_dir2_data_hdr
),
784 .data_dot_entry_p
= xfs_dir2_data_dot_entry_p
,
785 .data_dotdot_entry_p
= xfs_dir2_ftype_data_dotdot_entry_p
,
786 .data_first_entry_p
= xfs_dir2_ftype_data_first_entry_p
,
787 .data_entry_p
= xfs_dir2_data_entry_p
,
788 .data_unused_p
= xfs_dir2_data_unused_p
,
790 .leaf_hdr_size
= sizeof(struct xfs_dir2_leaf_hdr
),
791 .leaf_hdr_to_disk
= xfs_dir2_leaf_hdr_to_disk
,
792 .leaf_hdr_from_disk
= xfs_dir2_leaf_hdr_from_disk
,
793 .leaf_max_ents
= xfs_dir2_max_leaf_ents
,
794 .leaf_ents_p
= xfs_dir2_leaf_ents_p
,
796 .node_hdr_size
= sizeof(struct xfs_da_node_hdr
),
797 .node_hdr_to_disk
= xfs_da2_node_hdr_to_disk
,
798 .node_hdr_from_disk
= xfs_da2_node_hdr_from_disk
,
799 .node_tree_p
= xfs_da2_node_tree_p
,
801 .free_hdr_size
= sizeof(struct xfs_dir2_free_hdr
),
802 .free_hdr_to_disk
= xfs_dir2_free_hdr_to_disk
,
803 .free_hdr_from_disk
= xfs_dir2_free_hdr_from_disk
,
804 .free_max_bests
= xfs_dir2_free_max_bests
,
805 .free_bests_p
= xfs_dir2_free_bests_p
,
806 .db_to_fdb
= xfs_dir2_db_to_fdb
,
807 .db_to_fdindex
= xfs_dir2_db_to_fdindex
,
810 static const struct xfs_dir_ops xfs_dir3_ops
= {
811 .sf_entsize
= xfs_dir3_sf_entsize
,
812 .sf_nextentry
= xfs_dir3_sf_nextentry
,
813 .sf_get_ftype
= xfs_dir3_sfe_get_ftype
,
814 .sf_put_ftype
= xfs_dir3_sfe_put_ftype
,
815 .sf_get_ino
= xfs_dir3_sfe_get_ino
,
816 .sf_put_ino
= xfs_dir3_sfe_put_ino
,
817 .sf_get_parent_ino
= xfs_dir2_sf_get_parent_ino
,
818 .sf_put_parent_ino
= xfs_dir2_sf_put_parent_ino
,
820 .data_entsize
= xfs_dir3_data_entsize
,
821 .data_get_ftype
= xfs_dir3_data_get_ftype
,
822 .data_put_ftype
= xfs_dir3_data_put_ftype
,
823 .data_entry_tag_p
= xfs_dir3_data_entry_tag_p
,
824 .data_bestfree_p
= xfs_dir3_data_bestfree_p
,
826 .data_dot_offset
= sizeof(struct xfs_dir3_data_hdr
),
827 .data_dotdot_offset
= sizeof(struct xfs_dir3_data_hdr
) +
828 XFS_DIR3_DATA_ENTSIZE(1),
829 .data_first_offset
= sizeof(struct xfs_dir3_data_hdr
) +
830 XFS_DIR3_DATA_ENTSIZE(1) +
831 XFS_DIR3_DATA_ENTSIZE(2),
832 .data_entry_offset
= sizeof(struct xfs_dir3_data_hdr
),
834 .data_dot_entry_p
= xfs_dir3_data_dot_entry_p
,
835 .data_dotdot_entry_p
= xfs_dir3_data_dotdot_entry_p
,
836 .data_first_entry_p
= xfs_dir3_data_first_entry_p
,
837 .data_entry_p
= xfs_dir3_data_entry_p
,
838 .data_unused_p
= xfs_dir3_data_unused_p
,
840 .leaf_hdr_size
= sizeof(struct xfs_dir3_leaf_hdr
),
841 .leaf_hdr_to_disk
= xfs_dir3_leaf_hdr_to_disk
,
842 .leaf_hdr_from_disk
= xfs_dir3_leaf_hdr_from_disk
,
843 .leaf_max_ents
= xfs_dir3_max_leaf_ents
,
844 .leaf_ents_p
= xfs_dir3_leaf_ents_p
,
846 .node_hdr_size
= sizeof(struct xfs_da3_node_hdr
),
847 .node_hdr_to_disk
= xfs_da3_node_hdr_to_disk
,
848 .node_hdr_from_disk
= xfs_da3_node_hdr_from_disk
,
849 .node_tree_p
= xfs_da3_node_tree_p
,
851 .free_hdr_size
= sizeof(struct xfs_dir3_free_hdr
),
852 .free_hdr_to_disk
= xfs_dir3_free_hdr_to_disk
,
853 .free_hdr_from_disk
= xfs_dir3_free_hdr_from_disk
,
854 .free_max_bests
= xfs_dir3_free_max_bests
,
855 .free_bests_p
= xfs_dir3_free_bests_p
,
856 .db_to_fdb
= xfs_dir3_db_to_fdb
,
857 .db_to_fdindex
= xfs_dir3_db_to_fdindex
,
860 static const struct xfs_dir_ops xfs_dir2_nondir_ops
= {
861 .node_hdr_size
= sizeof(struct xfs_da_node_hdr
),
862 .node_hdr_to_disk
= xfs_da2_node_hdr_to_disk
,
863 .node_hdr_from_disk
= xfs_da2_node_hdr_from_disk
,
864 .node_tree_p
= xfs_da2_node_tree_p
,
867 static const struct xfs_dir_ops xfs_dir3_nondir_ops
= {
868 .node_hdr_size
= sizeof(struct xfs_da3_node_hdr
),
869 .node_hdr_to_disk
= xfs_da3_node_hdr_to_disk
,
870 .node_hdr_from_disk
= xfs_da3_node_hdr_from_disk
,
871 .node_tree_p
= xfs_da3_node_tree_p
,
875 * Return the ops structure according to the current config. If we are passed
876 * an inode, then that overrides the default config we use which is based on
879 const struct xfs_dir_ops
*
881 struct xfs_mount
*mp
,
882 struct xfs_inode
*dp
)
886 if (mp
->m_dir_inode_ops
)
887 return mp
->m_dir_inode_ops
;
888 if (xfs_sb_version_hascrc(&mp
->m_sb
))
889 return &xfs_dir3_ops
;
890 if (xfs_sb_version_hasftype(&mp
->m_sb
))
891 return &xfs_dir2_ftype_ops
;
892 return &xfs_dir2_ops
;
895 const struct xfs_dir_ops
*
897 struct xfs_mount
*mp
,
898 struct xfs_inode
*dp
)
902 if (mp
->m_nondir_inode_ops
)
903 return mp
->m_nondir_inode_ops
;
904 if (xfs_sb_version_hascrc(&mp
->m_sb
))
905 return &xfs_dir3_nondir_ops
;
906 return &xfs_dir2_nondir_ops
;