18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2000,2005 Silicon Graphics, Inc. 48c2ecf20Sopenharmony_ci * All Rights Reserved. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci#ifndef __XFS_IALLOC_H__ 78c2ecf20Sopenharmony_ci#define __XFS_IALLOC_H__ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_cistruct xfs_buf; 108c2ecf20Sopenharmony_cistruct xfs_dinode; 118c2ecf20Sopenharmony_cistruct xfs_imap; 128c2ecf20Sopenharmony_cistruct xfs_mount; 138c2ecf20Sopenharmony_cistruct xfs_trans; 148c2ecf20Sopenharmony_cistruct xfs_btree_cur; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* Move inodes in clusters of this size */ 178c2ecf20Sopenharmony_ci#define XFS_INODE_BIG_CLUSTER_SIZE 8192 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cistruct xfs_icluster { 208c2ecf20Sopenharmony_ci bool deleted; /* record is deleted */ 218c2ecf20Sopenharmony_ci xfs_ino_t first_ino; /* first inode number */ 228c2ecf20Sopenharmony_ci uint64_t alloc; /* inode phys. allocation bitmap for 238c2ecf20Sopenharmony_ci * sparse chunks */ 248c2ecf20Sopenharmony_ci}; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci/* 278c2ecf20Sopenharmony_ci * Make an inode pointer out of the buffer/offset. 288c2ecf20Sopenharmony_ci */ 298c2ecf20Sopenharmony_cistatic inline struct xfs_dinode * 308c2ecf20Sopenharmony_cixfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o) 318c2ecf20Sopenharmony_ci{ 328c2ecf20Sopenharmony_ci return xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog); 338c2ecf20Sopenharmony_ci} 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* 368c2ecf20Sopenharmony_ci * Allocate an inode on disk. 378c2ecf20Sopenharmony_ci * Mode is used to tell whether the new inode will need space, and whether 388c2ecf20Sopenharmony_ci * it is a directory. 398c2ecf20Sopenharmony_ci * 408c2ecf20Sopenharmony_ci * To work within the constraint of one allocation per transaction, 418c2ecf20Sopenharmony_ci * xfs_dialloc() is designed to be called twice if it has to do an 428c2ecf20Sopenharmony_ci * allocation to make more free inodes. If an inode is 438c2ecf20Sopenharmony_ci * available without an allocation, agbp would be set to the current 448c2ecf20Sopenharmony_ci * agbp and alloc_done set to false. 458c2ecf20Sopenharmony_ci * If an allocation needed to be done, agbp would be set to the 468c2ecf20Sopenharmony_ci * inode header of the allocation group and alloc_done set to true. 478c2ecf20Sopenharmony_ci * The caller should then commit the current transaction and allocate a new 488c2ecf20Sopenharmony_ci * transaction. xfs_dialloc() should then be called again with 498c2ecf20Sopenharmony_ci * the agbp value returned from the previous call. 508c2ecf20Sopenharmony_ci * 518c2ecf20Sopenharmony_ci * Once we successfully pick an inode its number is returned and the 528c2ecf20Sopenharmony_ci * on-disk data structures are updated. The inode itself is not read 538c2ecf20Sopenharmony_ci * in, since doing so would break ordering constraints with xfs_reclaim. 548c2ecf20Sopenharmony_ci * 558c2ecf20Sopenharmony_ci * *agbp should be set to NULL on the first call, *alloc_done set to FALSE. 568c2ecf20Sopenharmony_ci */ 578c2ecf20Sopenharmony_ciint /* error */ 588c2ecf20Sopenharmony_cixfs_dialloc( 598c2ecf20Sopenharmony_ci struct xfs_trans *tp, /* transaction pointer */ 608c2ecf20Sopenharmony_ci xfs_ino_t parent, /* parent inode (directory) */ 618c2ecf20Sopenharmony_ci umode_t mode, /* mode bits for new inode */ 628c2ecf20Sopenharmony_ci struct xfs_buf **agbp, /* buf for a.g. inode header */ 638c2ecf20Sopenharmony_ci xfs_ino_t *inop); /* inode number allocated */ 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci/* 668c2ecf20Sopenharmony_ci * Free disk inode. Carefully avoids touching the incore inode, all 678c2ecf20Sopenharmony_ci * manipulations incore are the caller's responsibility. 688c2ecf20Sopenharmony_ci * The on-disk inode is not changed by this operation, only the 698c2ecf20Sopenharmony_ci * btree (free inode mask) is changed. 708c2ecf20Sopenharmony_ci */ 718c2ecf20Sopenharmony_ciint /* error */ 728c2ecf20Sopenharmony_cixfs_difree( 738c2ecf20Sopenharmony_ci struct xfs_trans *tp, /* transaction pointer */ 748c2ecf20Sopenharmony_ci xfs_ino_t inode, /* inode to be freed */ 758c2ecf20Sopenharmony_ci struct xfs_icluster *ifree); /* cluster info if deleted */ 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/* 788c2ecf20Sopenharmony_ci * Return the location of the inode in imap, for mapping it into a buffer. 798c2ecf20Sopenharmony_ci */ 808c2ecf20Sopenharmony_ciint 818c2ecf20Sopenharmony_cixfs_imap( 828c2ecf20Sopenharmony_ci struct xfs_mount *mp, /* file system mount structure */ 838c2ecf20Sopenharmony_ci struct xfs_trans *tp, /* transaction pointer */ 848c2ecf20Sopenharmony_ci xfs_ino_t ino, /* inode to locate */ 858c2ecf20Sopenharmony_ci struct xfs_imap *imap, /* location map structure */ 868c2ecf20Sopenharmony_ci uint flags); /* flags for inode btree lookup */ 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* 898c2ecf20Sopenharmony_ci * Log specified fields for the ag hdr (inode section) 908c2ecf20Sopenharmony_ci */ 918c2ecf20Sopenharmony_civoid 928c2ecf20Sopenharmony_cixfs_ialloc_log_agi( 938c2ecf20Sopenharmony_ci struct xfs_trans *tp, /* transaction pointer */ 948c2ecf20Sopenharmony_ci struct xfs_buf *bp, /* allocation group header buffer */ 958c2ecf20Sopenharmony_ci int fields); /* bitmask of fields to log */ 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci/* 988c2ecf20Sopenharmony_ci * Read in the allocation group header (inode allocation section) 998c2ecf20Sopenharmony_ci */ 1008c2ecf20Sopenharmony_ciint /* error */ 1018c2ecf20Sopenharmony_cixfs_ialloc_read_agi( 1028c2ecf20Sopenharmony_ci struct xfs_mount *mp, /* file system mount structure */ 1038c2ecf20Sopenharmony_ci struct xfs_trans *tp, /* transaction pointer */ 1048c2ecf20Sopenharmony_ci xfs_agnumber_t agno, /* allocation group number */ 1058c2ecf20Sopenharmony_ci struct xfs_buf **bpp); /* allocation group hdr buf */ 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci/* 1088c2ecf20Sopenharmony_ci * Read in the allocation group header to initialise the per-ag data 1098c2ecf20Sopenharmony_ci * in the mount structure 1108c2ecf20Sopenharmony_ci */ 1118c2ecf20Sopenharmony_ciint 1128c2ecf20Sopenharmony_cixfs_ialloc_pagi_init( 1138c2ecf20Sopenharmony_ci struct xfs_mount *mp, /* file system mount structure */ 1148c2ecf20Sopenharmony_ci struct xfs_trans *tp, /* transaction pointer */ 1158c2ecf20Sopenharmony_ci xfs_agnumber_t agno); /* allocation group number */ 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci/* 1188c2ecf20Sopenharmony_ci * Lookup a record by ino in the btree given by cur. 1198c2ecf20Sopenharmony_ci */ 1208c2ecf20Sopenharmony_ciint xfs_inobt_lookup(struct xfs_btree_cur *cur, xfs_agino_t ino, 1218c2ecf20Sopenharmony_ci xfs_lookup_t dir, int *stat); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/* 1248c2ecf20Sopenharmony_ci * Get the data from the pointed-to record. 1258c2ecf20Sopenharmony_ci */ 1268c2ecf20Sopenharmony_ciint xfs_inobt_get_rec(struct xfs_btree_cur *cur, 1278c2ecf20Sopenharmony_ci xfs_inobt_rec_incore_t *rec, int *stat); 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci/* 1308c2ecf20Sopenharmony_ci * Inode chunk initialisation routine 1318c2ecf20Sopenharmony_ci */ 1328c2ecf20Sopenharmony_ciint xfs_ialloc_inode_init(struct xfs_mount *mp, struct xfs_trans *tp, 1338c2ecf20Sopenharmony_ci struct list_head *buffer_list, int icount, 1348c2ecf20Sopenharmony_ci xfs_agnumber_t agno, xfs_agblock_t agbno, 1358c2ecf20Sopenharmony_ci xfs_agblock_t length, unsigned int gen); 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ciint xfs_read_agi(struct xfs_mount *mp, struct xfs_trans *tp, 1388c2ecf20Sopenharmony_ci xfs_agnumber_t agno, struct xfs_buf **bpp); 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ciunion xfs_btree_rec; 1418c2ecf20Sopenharmony_civoid xfs_inobt_btrec_to_irec(struct xfs_mount *mp, union xfs_btree_rec *rec, 1428c2ecf20Sopenharmony_ci struct xfs_inobt_rec_incore *irec); 1438c2ecf20Sopenharmony_ciint xfs_ialloc_has_inodes_at_extent(struct xfs_btree_cur *cur, 1448c2ecf20Sopenharmony_ci xfs_agblock_t bno, xfs_extlen_t len, bool *exists); 1458c2ecf20Sopenharmony_ciint xfs_ialloc_has_inode_record(struct xfs_btree_cur *cur, xfs_agino_t low, 1468c2ecf20Sopenharmony_ci xfs_agino_t high, bool *exists); 1478c2ecf20Sopenharmony_ciint xfs_ialloc_count_inodes(struct xfs_btree_cur *cur, xfs_agino_t *count, 1488c2ecf20Sopenharmony_ci xfs_agino_t *freecount); 1498c2ecf20Sopenharmony_ciint xfs_inobt_insert_rec(struct xfs_btree_cur *cur, uint16_t holemask, 1508c2ecf20Sopenharmony_ci uint8_t count, int32_t freecount, xfs_inofree_t free, 1518c2ecf20Sopenharmony_ci int *stat); 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ciint xfs_ialloc_cluster_alignment(struct xfs_mount *mp); 1548c2ecf20Sopenharmony_civoid xfs_ialloc_setup_geometry(struct xfs_mount *mp); 1558c2ecf20Sopenharmony_cixfs_ino_t xfs_ialloc_calc_rootino(struct xfs_mount *mp, int sunit); 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci#endif /* __XFS_IALLOC_H__ */ 158