18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. 48c2ecf20Sopenharmony_ci * All Rights Reserved. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci#ifndef __XFS_DIR2_PRIV_H__ 78c2ecf20Sopenharmony_ci#define __XFS_DIR2_PRIV_H__ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_cistruct dir_context; 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci/* 128c2ecf20Sopenharmony_ci * In-core version of the leaf and free block headers to abstract the 138c2ecf20Sopenharmony_ci * differences in the v2 and v3 disk format of the headers. 148c2ecf20Sopenharmony_ci */ 158c2ecf20Sopenharmony_cistruct xfs_dir3_icleaf_hdr { 168c2ecf20Sopenharmony_ci uint32_t forw; 178c2ecf20Sopenharmony_ci uint32_t back; 188c2ecf20Sopenharmony_ci uint16_t magic; 198c2ecf20Sopenharmony_ci uint16_t count; 208c2ecf20Sopenharmony_ci uint16_t stale; 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci /* 238c2ecf20Sopenharmony_ci * Pointer to the on-disk format entries, which are behind the 248c2ecf20Sopenharmony_ci * variable size (v4 vs v5) header in the on-disk block. 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_ci struct xfs_dir2_leaf_entry *ents; 278c2ecf20Sopenharmony_ci}; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistruct xfs_dir3_icfree_hdr { 308c2ecf20Sopenharmony_ci uint32_t magic; 318c2ecf20Sopenharmony_ci uint32_t firstdb; 328c2ecf20Sopenharmony_ci uint32_t nvalid; 338c2ecf20Sopenharmony_ci uint32_t nused; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci /* 368c2ecf20Sopenharmony_ci * Pointer to the on-disk format entries, which are behind the 378c2ecf20Sopenharmony_ci * variable size (v4 vs v5) header in the on-disk block. 388c2ecf20Sopenharmony_ci */ 398c2ecf20Sopenharmony_ci __be16 *bests; 408c2ecf20Sopenharmony_ci}; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/* xfs_dir2.c */ 438c2ecf20Sopenharmony_cixfs_dahash_t xfs_ascii_ci_hashname(struct xfs_name *name); 448c2ecf20Sopenharmony_cienum xfs_dacmp xfs_ascii_ci_compname(struct xfs_da_args *args, 458c2ecf20Sopenharmony_ci const unsigned char *name, int len); 468c2ecf20Sopenharmony_ciextern int xfs_dir2_grow_inode(struct xfs_da_args *args, int space, 478c2ecf20Sopenharmony_ci xfs_dir2_db_t *dbp); 488c2ecf20Sopenharmony_ciextern int xfs_dir_cilookup_result(struct xfs_da_args *args, 498c2ecf20Sopenharmony_ci const unsigned char *name, int len); 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* xfs_dir2_block.c */ 538c2ecf20Sopenharmony_ciextern int xfs_dir3_block_read(struct xfs_trans *tp, struct xfs_inode *dp, 548c2ecf20Sopenharmony_ci struct xfs_buf **bpp); 558c2ecf20Sopenharmony_ciextern int xfs_dir2_block_addname(struct xfs_da_args *args); 568c2ecf20Sopenharmony_ciextern int xfs_dir2_block_lookup(struct xfs_da_args *args); 578c2ecf20Sopenharmony_ciextern int xfs_dir2_block_removename(struct xfs_da_args *args); 588c2ecf20Sopenharmony_ciextern int xfs_dir2_block_replace(struct xfs_da_args *args); 598c2ecf20Sopenharmony_ciextern int xfs_dir2_leaf_to_block(struct xfs_da_args *args, 608c2ecf20Sopenharmony_ci struct xfs_buf *lbp, struct xfs_buf *dbp); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/* xfs_dir2_data.c */ 638c2ecf20Sopenharmony_cistruct xfs_dir2_data_free *xfs_dir2_data_bestfree_p(struct xfs_mount *mp, 648c2ecf20Sopenharmony_ci struct xfs_dir2_data_hdr *hdr); 658c2ecf20Sopenharmony_ci__be16 *xfs_dir2_data_entry_tag_p(struct xfs_mount *mp, 668c2ecf20Sopenharmony_ci struct xfs_dir2_data_entry *dep); 678c2ecf20Sopenharmony_ciuint8_t xfs_dir2_data_get_ftype(struct xfs_mount *mp, 688c2ecf20Sopenharmony_ci struct xfs_dir2_data_entry *dep); 698c2ecf20Sopenharmony_civoid xfs_dir2_data_put_ftype(struct xfs_mount *mp, 708c2ecf20Sopenharmony_ci struct xfs_dir2_data_entry *dep, uint8_t ftype); 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci#ifdef DEBUG 738c2ecf20Sopenharmony_ciextern void xfs_dir3_data_check(struct xfs_inode *dp, struct xfs_buf *bp); 748c2ecf20Sopenharmony_ci#else 758c2ecf20Sopenharmony_ci#define xfs_dir3_data_check(dp,bp) 768c2ecf20Sopenharmony_ci#endif 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ciextern xfs_failaddr_t __xfs_dir3_data_check(struct xfs_inode *dp, 798c2ecf20Sopenharmony_ci struct xfs_buf *bp); 808c2ecf20Sopenharmony_ciint xfs_dir3_data_read(struct xfs_trans *tp, struct xfs_inode *dp, 818c2ecf20Sopenharmony_ci xfs_dablk_t bno, unsigned int flags, struct xfs_buf **bpp); 828c2ecf20Sopenharmony_ciint xfs_dir3_data_readahead(struct xfs_inode *dp, xfs_dablk_t bno, 838c2ecf20Sopenharmony_ci unsigned int flags); 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ciextern struct xfs_dir2_data_free * 868c2ecf20Sopenharmony_cixfs_dir2_data_freeinsert(struct xfs_dir2_data_hdr *hdr, 878c2ecf20Sopenharmony_ci struct xfs_dir2_data_free *bf, struct xfs_dir2_data_unused *dup, 888c2ecf20Sopenharmony_ci int *loghead); 898c2ecf20Sopenharmony_ciextern int xfs_dir3_data_init(struct xfs_da_args *args, xfs_dir2_db_t blkno, 908c2ecf20Sopenharmony_ci struct xfs_buf **bpp); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci/* xfs_dir2_leaf.c */ 938c2ecf20Sopenharmony_civoid xfs_dir2_leaf_hdr_from_disk(struct xfs_mount *mp, 948c2ecf20Sopenharmony_ci struct xfs_dir3_icleaf_hdr *to, struct xfs_dir2_leaf *from); 958c2ecf20Sopenharmony_civoid xfs_dir2_leaf_hdr_to_disk(struct xfs_mount *mp, struct xfs_dir2_leaf *to, 968c2ecf20Sopenharmony_ci struct xfs_dir3_icleaf_hdr *from); 978c2ecf20Sopenharmony_ciint xfs_dir3_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp, 988c2ecf20Sopenharmony_ci xfs_dablk_t fbno, struct xfs_buf **bpp); 998c2ecf20Sopenharmony_ciint xfs_dir3_leafn_read(struct xfs_trans *tp, struct xfs_inode *dp, 1008c2ecf20Sopenharmony_ci xfs_dablk_t fbno, struct xfs_buf **bpp); 1018c2ecf20Sopenharmony_ciextern int xfs_dir2_block_to_leaf(struct xfs_da_args *args, 1028c2ecf20Sopenharmony_ci struct xfs_buf *dbp); 1038c2ecf20Sopenharmony_ciextern int xfs_dir2_leaf_addname(struct xfs_da_args *args); 1048c2ecf20Sopenharmony_ciextern void xfs_dir3_leaf_compact(struct xfs_da_args *args, 1058c2ecf20Sopenharmony_ci struct xfs_dir3_icleaf_hdr *leafhdr, struct xfs_buf *bp); 1068c2ecf20Sopenharmony_ciextern void xfs_dir3_leaf_compact_x1(struct xfs_dir3_icleaf_hdr *leafhdr, 1078c2ecf20Sopenharmony_ci struct xfs_dir2_leaf_entry *ents, int *indexp, 1088c2ecf20Sopenharmony_ci int *lowstalep, int *highstalep, int *lowlogp, int *highlogp); 1098c2ecf20Sopenharmony_ciextern int xfs_dir3_leaf_get_buf(struct xfs_da_args *args, xfs_dir2_db_t bno, 1108c2ecf20Sopenharmony_ci struct xfs_buf **bpp, uint16_t magic); 1118c2ecf20Sopenharmony_ciextern void xfs_dir3_leaf_log_ents(struct xfs_da_args *args, 1128c2ecf20Sopenharmony_ci struct xfs_dir3_icleaf_hdr *hdr, struct xfs_buf *bp, int first, 1138c2ecf20Sopenharmony_ci int last); 1148c2ecf20Sopenharmony_ciextern void xfs_dir3_leaf_log_header(struct xfs_da_args *args, 1158c2ecf20Sopenharmony_ci struct xfs_buf *bp); 1168c2ecf20Sopenharmony_ciextern int xfs_dir2_leaf_lookup(struct xfs_da_args *args); 1178c2ecf20Sopenharmony_ciextern int xfs_dir2_leaf_removename(struct xfs_da_args *args); 1188c2ecf20Sopenharmony_ciextern int xfs_dir2_leaf_replace(struct xfs_da_args *args); 1198c2ecf20Sopenharmony_ciextern int xfs_dir2_leaf_search_hash(struct xfs_da_args *args, 1208c2ecf20Sopenharmony_ci struct xfs_buf *lbp); 1218c2ecf20Sopenharmony_ciextern int xfs_dir2_leaf_trim_data(struct xfs_da_args *args, 1228c2ecf20Sopenharmony_ci struct xfs_buf *lbp, xfs_dir2_db_t db); 1238c2ecf20Sopenharmony_ciextern struct xfs_dir2_leaf_entry * 1248c2ecf20Sopenharmony_cixfs_dir3_leaf_find_entry(struct xfs_dir3_icleaf_hdr *leafhdr, 1258c2ecf20Sopenharmony_ci struct xfs_dir2_leaf_entry *ents, int index, int compact, 1268c2ecf20Sopenharmony_ci int lowstale, int highstale, int *lfloglow, int *lfloghigh); 1278c2ecf20Sopenharmony_ciextern int xfs_dir2_node_to_leaf(struct xfs_da_state *state); 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ciextern xfs_failaddr_t xfs_dir3_leaf_check_int(struct xfs_mount *mp, 1308c2ecf20Sopenharmony_ci struct xfs_dir3_icleaf_hdr *hdr, struct xfs_dir2_leaf *leaf); 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci/* xfs_dir2_node.c */ 1338c2ecf20Sopenharmony_civoid xfs_dir2_free_hdr_from_disk(struct xfs_mount *mp, 1348c2ecf20Sopenharmony_ci struct xfs_dir3_icfree_hdr *to, struct xfs_dir2_free *from); 1358c2ecf20Sopenharmony_ciextern int xfs_dir2_leaf_to_node(struct xfs_da_args *args, 1368c2ecf20Sopenharmony_ci struct xfs_buf *lbp); 1378c2ecf20Sopenharmony_ciextern xfs_dahash_t xfs_dir2_leaf_lasthash(struct xfs_inode *dp, 1388c2ecf20Sopenharmony_ci struct xfs_buf *bp, int *count); 1398c2ecf20Sopenharmony_ciextern int xfs_dir2_leafn_lookup_int(struct xfs_buf *bp, 1408c2ecf20Sopenharmony_ci struct xfs_da_args *args, int *indexp, 1418c2ecf20Sopenharmony_ci struct xfs_da_state *state); 1428c2ecf20Sopenharmony_ciextern int xfs_dir2_leafn_order(struct xfs_inode *dp, struct xfs_buf *leaf1_bp, 1438c2ecf20Sopenharmony_ci struct xfs_buf *leaf2_bp); 1448c2ecf20Sopenharmony_ciextern int xfs_dir2_leafn_split(struct xfs_da_state *state, 1458c2ecf20Sopenharmony_ci struct xfs_da_state_blk *oldblk, struct xfs_da_state_blk *newblk); 1468c2ecf20Sopenharmony_ciextern int xfs_dir2_leafn_toosmall(struct xfs_da_state *state, int *action); 1478c2ecf20Sopenharmony_ciextern void xfs_dir2_leafn_unbalance(struct xfs_da_state *state, 1488c2ecf20Sopenharmony_ci struct xfs_da_state_blk *drop_blk, 1498c2ecf20Sopenharmony_ci struct xfs_da_state_blk *save_blk); 1508c2ecf20Sopenharmony_ciextern int xfs_dir2_node_addname(struct xfs_da_args *args); 1518c2ecf20Sopenharmony_ciextern int xfs_dir2_node_lookup(struct xfs_da_args *args); 1528c2ecf20Sopenharmony_ciextern int xfs_dir2_node_removename(struct xfs_da_args *args); 1538c2ecf20Sopenharmony_ciextern int xfs_dir2_node_replace(struct xfs_da_args *args); 1548c2ecf20Sopenharmony_ciextern int xfs_dir2_node_trim_free(struct xfs_da_args *args, xfs_fileoff_t fo, 1558c2ecf20Sopenharmony_ci int *rvalp); 1568c2ecf20Sopenharmony_ciextern int xfs_dir2_free_read(struct xfs_trans *tp, struct xfs_inode *dp, 1578c2ecf20Sopenharmony_ci xfs_dablk_t fbno, struct xfs_buf **bpp); 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci/* xfs_dir2_sf.c */ 1608c2ecf20Sopenharmony_cixfs_ino_t xfs_dir2_sf_get_ino(struct xfs_mount *mp, struct xfs_dir2_sf_hdr *hdr, 1618c2ecf20Sopenharmony_ci struct xfs_dir2_sf_entry *sfep); 1628c2ecf20Sopenharmony_cixfs_ino_t xfs_dir2_sf_get_parent_ino(struct xfs_dir2_sf_hdr *hdr); 1638c2ecf20Sopenharmony_civoid xfs_dir2_sf_put_parent_ino(struct xfs_dir2_sf_hdr *hdr, xfs_ino_t ino); 1648c2ecf20Sopenharmony_ciuint8_t xfs_dir2_sf_get_ftype(struct xfs_mount *mp, 1658c2ecf20Sopenharmony_ci struct xfs_dir2_sf_entry *sfep); 1668c2ecf20Sopenharmony_cistruct xfs_dir2_sf_entry *xfs_dir2_sf_nextentry(struct xfs_mount *mp, 1678c2ecf20Sopenharmony_ci struct xfs_dir2_sf_hdr *hdr, struct xfs_dir2_sf_entry *sfep); 1688c2ecf20Sopenharmony_ciextern int xfs_dir2_block_sfsize(struct xfs_inode *dp, 1698c2ecf20Sopenharmony_ci struct xfs_dir2_data_hdr *block, struct xfs_dir2_sf_hdr *sfhp); 1708c2ecf20Sopenharmony_ciextern int xfs_dir2_block_to_sf(struct xfs_da_args *args, struct xfs_buf *bp, 1718c2ecf20Sopenharmony_ci int size, xfs_dir2_sf_hdr_t *sfhp); 1728c2ecf20Sopenharmony_ciextern int xfs_dir2_sf_addname(struct xfs_da_args *args); 1738c2ecf20Sopenharmony_ciextern int xfs_dir2_sf_create(struct xfs_da_args *args, xfs_ino_t pino); 1748c2ecf20Sopenharmony_ciextern int xfs_dir2_sf_lookup(struct xfs_da_args *args); 1758c2ecf20Sopenharmony_ciextern int xfs_dir2_sf_removename(struct xfs_da_args *args); 1768c2ecf20Sopenharmony_ciextern int xfs_dir2_sf_replace(struct xfs_da_args *args); 1778c2ecf20Sopenharmony_ciextern xfs_failaddr_t xfs_dir2_sf_verify(struct xfs_inode *ip); 1788c2ecf20Sopenharmony_ciint xfs_dir2_sf_entsize(struct xfs_mount *mp, 1798c2ecf20Sopenharmony_ci struct xfs_dir2_sf_hdr *hdr, int len); 1808c2ecf20Sopenharmony_civoid xfs_dir2_sf_put_ino(struct xfs_mount *mp, struct xfs_dir2_sf_hdr *hdr, 1818c2ecf20Sopenharmony_ci struct xfs_dir2_sf_entry *sfep, xfs_ino_t ino); 1828c2ecf20Sopenharmony_civoid xfs_dir2_sf_put_ftype(struct xfs_mount *mp, 1838c2ecf20Sopenharmony_ci struct xfs_dir2_sf_entry *sfep, uint8_t ftype); 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci/* xfs_dir2_readdir.c */ 1868c2ecf20Sopenharmony_ciextern int xfs_readdir(struct xfs_trans *tp, struct xfs_inode *dp, 1878c2ecf20Sopenharmony_ci struct dir_context *ctx, size_t bufsize); 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_cistatic inline unsigned int 1908c2ecf20Sopenharmony_cixfs_dir2_data_entsize( 1918c2ecf20Sopenharmony_ci struct xfs_mount *mp, 1928c2ecf20Sopenharmony_ci unsigned int namelen) 1938c2ecf20Sopenharmony_ci{ 1948c2ecf20Sopenharmony_ci unsigned int len; 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci len = offsetof(struct xfs_dir2_data_entry, name[0]) + namelen + 1978c2ecf20Sopenharmony_ci sizeof(xfs_dir2_data_off_t) /* tag */; 1988c2ecf20Sopenharmony_ci if (xfs_sb_version_hasftype(&mp->m_sb)) 1998c2ecf20Sopenharmony_ci len += sizeof(uint8_t); 2008c2ecf20Sopenharmony_ci return round_up(len, XFS_DIR2_DATA_ALIGN); 2018c2ecf20Sopenharmony_ci} 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_cixfs_dahash_t xfs_dir2_hashname(struct xfs_mount *mp, struct xfs_name *name); 2048c2ecf20Sopenharmony_cienum xfs_dacmp xfs_dir2_compname(struct xfs_da_args *args, 2058c2ecf20Sopenharmony_ci const unsigned char *name, int len); 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci#endif /* __XFS_DIR2_PRIV_H__ */ 208