1508578f2SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
230f712c9SDave Chinner /*
330f712c9SDave Chinner * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
430f712c9SDave Chinner * All Rights Reserved.
530f712c9SDave Chinner */
630f712c9SDave Chinner #ifndef __XFS_DIR2_PRIV_H__
730f712c9SDave Chinner #define __XFS_DIR2_PRIV_H__
830f712c9SDave Chinner
930f712c9SDave Chinner struct dir_context;
1030f712c9SDave Chinner
11a39f089aSChristoph Hellwig /*
12a39f089aSChristoph Hellwig * In-core version of the leaf and free block headers to abstract the
13a39f089aSChristoph Hellwig * differences in the v2 and v3 disk format of the headers.
14a39f089aSChristoph Hellwig */
15a39f089aSChristoph Hellwig struct xfs_dir3_icleaf_hdr {
16a39f089aSChristoph Hellwig uint32_t forw;
17a39f089aSChristoph Hellwig uint32_t back;
18a39f089aSChristoph Hellwig uint16_t magic;
19a39f089aSChristoph Hellwig uint16_t count;
20a39f089aSChristoph Hellwig uint16_t stale;
21787b0893SChristoph Hellwig
22787b0893SChristoph Hellwig /*
23787b0893SChristoph Hellwig * Pointer to the on-disk format entries, which are behind the
24787b0893SChristoph Hellwig * variable size (v4 vs v5) header in the on-disk block.
25787b0893SChristoph Hellwig */
26787b0893SChristoph Hellwig struct xfs_dir2_leaf_entry *ents;
27a39f089aSChristoph Hellwig };
28a39f089aSChristoph Hellwig
29a39f089aSChristoph Hellwig struct xfs_dir3_icfree_hdr {
30a39f089aSChristoph Hellwig uint32_t magic;
31a39f089aSChristoph Hellwig uint32_t firstdb;
32a39f089aSChristoph Hellwig uint32_t nvalid;
33a39f089aSChristoph Hellwig uint32_t nused;
34a84f3d5cSChristoph Hellwig
35a84f3d5cSChristoph Hellwig /*
36a84f3d5cSChristoph Hellwig * Pointer to the on-disk format entries, which are behind the
37a84f3d5cSChristoph Hellwig * variable size (v4 vs v5) header in the on-disk block.
38a84f3d5cSChristoph Hellwig */
39a84f3d5cSChristoph Hellwig __be16 *bests;
40a39f089aSChristoph Hellwig };
41a39f089aSChristoph Hellwig
4230f712c9SDave Chinner /* xfs_dir2.c */
43996b2329SDarrick J. Wong xfs_dahash_t xfs_ascii_ci_hashname(const struct xfs_name *name);
44d8d11fc7SChristoph Hellwig enum xfs_dacmp xfs_ascii_ci_compname(struct xfs_da_args *args,
45d8d11fc7SChristoph Hellwig const unsigned char *name, int len);
4630f712c9SDave Chinner extern int xfs_dir2_grow_inode(struct xfs_da_args *args, int space,
4730f712c9SDave Chinner xfs_dir2_db_t *dbp);
4830f712c9SDave Chinner extern int xfs_dir_cilookup_result(struct xfs_da_args *args,
4930f712c9SDave Chinner const unsigned char *name, int len);
5030f712c9SDave Chinner
5130f712c9SDave Chinner
5230f712c9SDave Chinner /* xfs_dir2_block.c */
5329b41ce9SDarrick J. Wong int xfs_dir3_block_read(struct xfs_trans *tp, struct xfs_inode *dp,
5429b41ce9SDarrick J. Wong xfs_ino_t owner, struct xfs_buf **bpp);
5530f712c9SDave Chinner extern int xfs_dir2_block_addname(struct xfs_da_args *args);
5630f712c9SDave Chinner extern int xfs_dir2_block_lookup(struct xfs_da_args *args);
5730f712c9SDave Chinner extern int xfs_dir2_block_removename(struct xfs_da_args *args);
5830f712c9SDave Chinner extern int xfs_dir2_block_replace(struct xfs_da_args *args);
5930f712c9SDave Chinner extern int xfs_dir2_leaf_to_block(struct xfs_da_args *args,
6030f712c9SDave Chinner struct xfs_buf *lbp, struct xfs_buf *dbp);
6130f712c9SDave Chinner
6230f712c9SDave Chinner /* xfs_dir2_data.c */
631848b607SChristoph Hellwig struct xfs_dir2_data_free *xfs_dir2_data_bestfree_p(struct xfs_mount *mp,
641848b607SChristoph Hellwig struct xfs_dir2_data_hdr *hdr);
657e8ae7bdSChristoph Hellwig __be16 *xfs_dir2_data_entry_tag_p(struct xfs_mount *mp,
667e8ae7bdSChristoph Hellwig struct xfs_dir2_data_entry *dep);
6759b8b465SChristoph Hellwig uint8_t xfs_dir2_data_get_ftype(struct xfs_mount *mp,
6859b8b465SChristoph Hellwig struct xfs_dir2_data_entry *dep);
6959b8b465SChristoph Hellwig void xfs_dir2_data_put_ftype(struct xfs_mount *mp,
7059b8b465SChristoph Hellwig struct xfs_dir2_data_entry *dep, uint8_t ftype);
71fdbb8c5bSChristoph Hellwig
7230f712c9SDave Chinner #ifdef DEBUG
73a6a781a5SDarrick J. Wong extern void xfs_dir3_data_check(struct xfs_inode *dp, struct xfs_buf *bp);
7430f712c9SDave Chinner #else
7530f712c9SDave Chinner #define xfs_dir3_data_check(dp,bp)
7630f712c9SDave Chinner #endif
7730f712c9SDave Chinner
78a6a781a5SDarrick J. Wong extern xfs_failaddr_t __xfs_dir3_data_check(struct xfs_inode *dp,
79a6a781a5SDarrick J. Wong struct xfs_buf *bp);
80cd2c9f1bSChristoph Hellwig int xfs_dir3_data_read(struct xfs_trans *tp, struct xfs_inode *dp,
81cc6740ddSDarrick J. Wong xfs_ino_t owner, xfs_dablk_t bno, unsigned int flags,
82cc6740ddSDarrick J. Wong struct xfs_buf **bpp);
8306566fdaSChristoph Hellwig int xfs_dir3_data_readahead(struct xfs_inode *dp, xfs_dablk_t bno,
8406566fdaSChristoph Hellwig unsigned int flags);
8530f712c9SDave Chinner
8630f712c9SDave Chinner extern struct xfs_dir2_data_free *
8730f712c9SDave Chinner xfs_dir2_data_freeinsert(struct xfs_dir2_data_hdr *hdr,
8830f712c9SDave Chinner struct xfs_dir2_data_free *bf, struct xfs_dir2_data_unused *dup,
8930f712c9SDave Chinner int *loghead);
9030f712c9SDave Chinner extern int xfs_dir3_data_init(struct xfs_da_args *args, xfs_dir2_db_t blkno,
9130f712c9SDave Chinner struct xfs_buf **bpp);
9230f712c9SDave Chinner
9330f712c9SDave Chinner /* xfs_dir2_leaf.c */
9451842556SChristoph Hellwig void xfs_dir2_leaf_hdr_from_disk(struct xfs_mount *mp,
9551842556SChristoph Hellwig struct xfs_dir3_icleaf_hdr *to, struct xfs_dir2_leaf *from);
96163fbbb3SChristoph Hellwig void xfs_dir2_leaf_hdr_to_disk(struct xfs_mount *mp, struct xfs_dir2_leaf *to,
97163fbbb3SChristoph Hellwig struct xfs_dir3_icleaf_hdr *from);
98c943c0b2SChristoph Hellwig int xfs_dir3_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp,
99402eef10SDarrick J. Wong xfs_ino_t owner, xfs_dablk_t fbno, struct xfs_buf **bpp);
100f3fcb314SChristoph Hellwig int xfs_dir3_leafn_read(struct xfs_trans *tp, struct xfs_inode *dp,
101402eef10SDarrick J. Wong xfs_ino_t owner, xfs_dablk_t fbno, struct xfs_buf **bpp);
10230f712c9SDave Chinner extern int xfs_dir2_block_to_leaf(struct xfs_da_args *args,
10330f712c9SDave Chinner struct xfs_buf *dbp);
10430f712c9SDave Chinner extern int xfs_dir2_leaf_addname(struct xfs_da_args *args);
10530f712c9SDave Chinner extern void xfs_dir3_leaf_compact(struct xfs_da_args *args,
10630f712c9SDave Chinner struct xfs_dir3_icleaf_hdr *leafhdr, struct xfs_buf *bp);
10730f712c9SDave Chinner extern void xfs_dir3_leaf_compact_x1(struct xfs_dir3_icleaf_hdr *leafhdr,
10830f712c9SDave Chinner struct xfs_dir2_leaf_entry *ents, int *indexp,
10930f712c9SDave Chinner int *lowstalep, int *highstalep, int *lowlogp, int *highlogp);
11030f712c9SDave Chinner extern int xfs_dir3_leaf_get_buf(struct xfs_da_args *args, xfs_dir2_db_t bno,
111c8ce540dSDarrick J. Wong struct xfs_buf **bpp, uint16_t magic);
11230f712c9SDave Chinner extern void xfs_dir3_leaf_log_ents(struct xfs_da_args *args,
113787b0893SChristoph Hellwig struct xfs_dir3_icleaf_hdr *hdr, struct xfs_buf *bp, int first,
114787b0893SChristoph Hellwig int last);
11530f712c9SDave Chinner extern void xfs_dir3_leaf_log_header(struct xfs_da_args *args,
11630f712c9SDave Chinner struct xfs_buf *bp);
11730f712c9SDave Chinner extern int xfs_dir2_leaf_lookup(struct xfs_da_args *args);
11830f712c9SDave Chinner extern int xfs_dir2_leaf_removename(struct xfs_da_args *args);
11930f712c9SDave Chinner extern int xfs_dir2_leaf_replace(struct xfs_da_args *args);
12030f712c9SDave Chinner extern int xfs_dir2_leaf_search_hash(struct xfs_da_args *args,
12130f712c9SDave Chinner struct xfs_buf *lbp);
12230f712c9SDave Chinner extern int xfs_dir2_leaf_trim_data(struct xfs_da_args *args,
12330f712c9SDave Chinner struct xfs_buf *lbp, xfs_dir2_db_t db);
12430f712c9SDave Chinner extern struct xfs_dir2_leaf_entry *
12530f712c9SDave Chinner xfs_dir3_leaf_find_entry(struct xfs_dir3_icleaf_hdr *leafhdr,
12630f712c9SDave Chinner struct xfs_dir2_leaf_entry *ents, int index, int compact,
12730f712c9SDave Chinner int lowstale, int highstale, int *lfloglow, int *lfloghigh);
12830f712c9SDave Chinner extern int xfs_dir2_node_to_leaf(struct xfs_da_state *state);
12930f712c9SDave Chinner
130a6a781a5SDarrick J. Wong extern xfs_failaddr_t xfs_dir3_leaf_check_int(struct xfs_mount *mp,
1311fea323fSDave Chinner struct xfs_dir3_icleaf_hdr *hdr, struct xfs_dir2_leaf *leaf,
1321fea323fSDave Chinner bool expensive_checks);
13330f712c9SDave Chinner
13430f712c9SDave Chinner /* xfs_dir2_node.c */
1355ba30919SChristoph Hellwig void xfs_dir2_free_hdr_from_disk(struct xfs_mount *mp,
1365ba30919SChristoph Hellwig struct xfs_dir3_icfree_hdr *to, struct xfs_dir2_free *from);
13730f712c9SDave Chinner extern int xfs_dir2_leaf_to_node(struct xfs_da_args *args,
13830f712c9SDave Chinner struct xfs_buf *lbp);
1398e8877e6SDarrick J. Wong extern xfs_dahash_t xfs_dir2_leaf_lasthash(struct xfs_inode *dp,
14030f712c9SDave Chinner struct xfs_buf *bp, int *count);
14130f712c9SDave Chinner extern int xfs_dir2_leafn_lookup_int(struct xfs_buf *bp,
14230f712c9SDave Chinner struct xfs_da_args *args, int *indexp,
14330f712c9SDave Chinner struct xfs_da_state *state);
14430f712c9SDave Chinner extern int xfs_dir2_leafn_order(struct xfs_inode *dp, struct xfs_buf *leaf1_bp,
14530f712c9SDave Chinner struct xfs_buf *leaf2_bp);
14630f712c9SDave Chinner extern int xfs_dir2_leafn_split(struct xfs_da_state *state,
14730f712c9SDave Chinner struct xfs_da_state_blk *oldblk, struct xfs_da_state_blk *newblk);
14830f712c9SDave Chinner extern int xfs_dir2_leafn_toosmall(struct xfs_da_state *state, int *action);
14930f712c9SDave Chinner extern void xfs_dir2_leafn_unbalance(struct xfs_da_state *state,
15030f712c9SDave Chinner struct xfs_da_state_blk *drop_blk,
15130f712c9SDave Chinner struct xfs_da_state_blk *save_blk);
15230f712c9SDave Chinner extern int xfs_dir2_node_addname(struct xfs_da_args *args);
15330f712c9SDave Chinner extern int xfs_dir2_node_lookup(struct xfs_da_args *args);
15430f712c9SDave Chinner extern int xfs_dir2_node_removename(struct xfs_da_args *args);
15530f712c9SDave Chinner extern int xfs_dir2_node_replace(struct xfs_da_args *args);
15630f712c9SDave Chinner extern int xfs_dir2_node_trim_free(struct xfs_da_args *args, xfs_fileoff_t fo,
15730f712c9SDave Chinner int *rvalp);
158fe6c9f8eSDarrick J. Wong int xfs_dir2_free_read(struct xfs_trans *tp, struct xfs_inode *dp,
159fe6c9f8eSDarrick J. Wong xfs_ino_t owner, xfs_dablk_t fbno, struct xfs_buf **bpp);
16030f712c9SDave Chinner
16130f712c9SDave Chinner /* xfs_dir2_sf.c */
16293b1e96aSChristoph Hellwig xfs_ino_t xfs_dir2_sf_get_ino(struct xfs_mount *mp, struct xfs_dir2_sf_hdr *hdr,
16393b1e96aSChristoph Hellwig struct xfs_dir2_sf_entry *sfep);
16484915e1bSChristoph Hellwig xfs_ino_t xfs_dir2_sf_get_parent_ino(struct xfs_dir2_sf_hdr *hdr);
16584915e1bSChristoph Hellwig void xfs_dir2_sf_put_parent_ino(struct xfs_dir2_sf_hdr *hdr, xfs_ino_t ino);
1664501ed2aSChristoph Hellwig uint8_t xfs_dir2_sf_get_ftype(struct xfs_mount *mp,
1674501ed2aSChristoph Hellwig struct xfs_dir2_sf_entry *sfep);
16850f6bb6bSChristoph Hellwig struct xfs_dir2_sf_entry *xfs_dir2_sf_nextentry(struct xfs_mount *mp,
16950f6bb6bSChristoph Hellwig struct xfs_dir2_sf_hdr *hdr, struct xfs_dir2_sf_entry *sfep);
17030f712c9SDave Chinner extern int xfs_dir2_block_sfsize(struct xfs_inode *dp,
17130f712c9SDave Chinner struct xfs_dir2_data_hdr *block, struct xfs_dir2_sf_hdr *sfhp);
17230f712c9SDave Chinner extern int xfs_dir2_block_to_sf(struct xfs_da_args *args, struct xfs_buf *bp,
17330f712c9SDave Chinner int size, xfs_dir2_sf_hdr_t *sfhp);
17430f712c9SDave Chinner extern int xfs_dir2_sf_addname(struct xfs_da_args *args);
17530f712c9SDave Chinner extern int xfs_dir2_sf_create(struct xfs_da_args *args, xfs_ino_t pino);
17630f712c9SDave Chinner extern int xfs_dir2_sf_lookup(struct xfs_da_args *args);
17730f712c9SDave Chinner extern int xfs_dir2_sf_removename(struct xfs_da_args *args);
17830f712c9SDave Chinner extern int xfs_dir2_sf_replace(struct xfs_da_args *args);
179e744cef2SDarrick J. Wong xfs_failaddr_t xfs_dir2_sf_verify(struct xfs_mount *mp,
180e744cef2SDarrick J. Wong struct xfs_dir2_sf_hdr *sfp, int64_t size);
181af952aebSDarrick J. Wong int xfs_dir2_sf_entsize(struct xfs_mount *mp,
182af952aebSDarrick J. Wong struct xfs_dir2_sf_hdr *hdr, int len);
183af952aebSDarrick J. Wong void xfs_dir2_sf_put_ino(struct xfs_mount *mp, struct xfs_dir2_sf_hdr *hdr,
184af952aebSDarrick J. Wong struct xfs_dir2_sf_entry *sfep, xfs_ino_t ino);
185af952aebSDarrick J. Wong void xfs_dir2_sf_put_ftype(struct xfs_mount *mp,
186af952aebSDarrick J. Wong struct xfs_dir2_sf_entry *sfep, uint8_t ftype);
18730f712c9SDave Chinner
18830f712c9SDave Chinner /* xfs_dir2_readdir.c */
189acb9553cSDarrick J. Wong extern int xfs_readdir(struct xfs_trans *tp, struct xfs_inode *dp,
190acb9553cSDarrick J. Wong struct dir_context *ctx, size_t bufsize);
19130f712c9SDave Chinner
192711c7dbfSChristoph Hellwig static inline unsigned int
xfs_dir2_data_unusedsize(unsigned int len)193*0c7fcdb6Slei lu xfs_dir2_data_unusedsize(
194*0c7fcdb6Slei lu unsigned int len)
195*0c7fcdb6Slei lu {
196*0c7fcdb6Slei lu return round_up(len, XFS_DIR2_DATA_ALIGN);
197*0c7fcdb6Slei lu }
198*0c7fcdb6Slei lu
199*0c7fcdb6Slei lu static inline unsigned int
xfs_dir2_data_entsize(struct xfs_mount * mp,unsigned int namelen)200711c7dbfSChristoph Hellwig xfs_dir2_data_entsize(
201711c7dbfSChristoph Hellwig struct xfs_mount *mp,
202711c7dbfSChristoph Hellwig unsigned int namelen)
203711c7dbfSChristoph Hellwig {
204711c7dbfSChristoph Hellwig unsigned int len;
205711c7dbfSChristoph Hellwig
206711c7dbfSChristoph Hellwig len = offsetof(struct xfs_dir2_data_entry, name[0]) + namelen +
207711c7dbfSChristoph Hellwig sizeof(xfs_dir2_data_off_t) /* tag */;
208ebd9027dSDave Chinner if (xfs_has_ftype(mp))
209711c7dbfSChristoph Hellwig len += sizeof(uint8_t);
210711c7dbfSChristoph Hellwig return round_up(len, XFS_DIR2_DATA_ALIGN);
211711c7dbfSChristoph Hellwig }
212711c7dbfSChristoph Hellwig
213996b2329SDarrick J. Wong xfs_dahash_t xfs_dir2_hashname(struct xfs_mount *mp,
214996b2329SDarrick J. Wong const struct xfs_name *name);
215af952aebSDarrick J. Wong enum xfs_dacmp xfs_dir2_compname(struct xfs_da_args *args,
216af952aebSDarrick J. Wong const unsigned char *name, int len);
217d8d11fc7SChristoph Hellwig
21830f712c9SDave Chinner #endif /* __XFS_DIR2_PRIV_H__ */
219