| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 |  * Copyright (c) 2000,2005 Silicon Graphics, Inc. | 
 | 3 |  * All Rights Reserved. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 |  * | 
| Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 5 |  * This program is free software; you can redistribute it and/or | 
 | 6 |  * modify it under the terms of the GNU General Public License as | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 |  * published by the Free Software Foundation. | 
 | 8 |  * | 
| Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 9 |  * This program is distributed in the hope that it would be useful, | 
 | 10 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 11 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 12 |  * GNU General Public License for more details. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 |  * | 
| Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 14 |  * You should have received a copy of the GNU General Public License | 
 | 15 |  * along with this program; if not, write the Free Software Foundation, | 
 | 16 |  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 |  */ | 
 | 18 | #ifndef __XFS_DIR2_NODE_H__ | 
 | 19 | #define	__XFS_DIR2_NODE_H__ | 
 | 20 |  | 
 | 21 | /* | 
 | 22 |  * Directory version 2, btree node format structures | 
 | 23 |  */ | 
 | 24 |  | 
 | 25 | struct uio; | 
 | 26 | struct xfs_dabuf; | 
 | 27 | struct xfs_da_args; | 
 | 28 | struct xfs_da_state; | 
 | 29 | struct xfs_da_state_blk; | 
 | 30 | struct xfs_inode; | 
 | 31 | struct xfs_trans; | 
 | 32 |  | 
 | 33 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 |  * Offset of the freespace index. | 
 | 35 |  */ | 
 | 36 | #define	XFS_DIR2_FREE_SPACE	2 | 
 | 37 | #define	XFS_DIR2_FREE_OFFSET	(XFS_DIR2_FREE_SPACE * XFS_DIR2_SPACE_SIZE) | 
 | 38 | #define	XFS_DIR2_FREE_FIRSTDB(mp)	\ | 
| Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 39 | 	xfs_dir2_byte_to_db(mp, XFS_DIR2_FREE_OFFSET) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 |  | 
 | 41 | #define	XFS_DIR2_FREE_MAGIC	0x58443246	/* XD2F */ | 
 | 42 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | typedef	struct xfs_dir2_free_hdr { | 
| Nathan Scott | 0ba962e | 2006-03-17 17:27:07 +1100 | [diff] [blame] | 44 | 	__be32			magic;		/* XFS_DIR2_FREE_MAGIC */ | 
 | 45 | 	__be32			firstdb;	/* db of first entry */ | 
 | 46 | 	__be32			nvalid;		/* count of valid entries */ | 
 | 47 | 	__be32			nused;		/* count of used entries */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } xfs_dir2_free_hdr_t; | 
 | 49 |  | 
 | 50 | typedef struct xfs_dir2_free { | 
 | 51 | 	xfs_dir2_free_hdr_t	hdr;		/* block header */ | 
| Nathan Scott | 0ba962e | 2006-03-17 17:27:07 +1100 | [diff] [blame] | 52 | 	__be16			bests[1];	/* best free counts */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | 						/* unused entries are -1 */ | 
 | 54 | } xfs_dir2_free_t; | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 55 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #define	XFS_DIR2_MAX_FREE_BESTS(mp)	\ | 
 | 57 | 	(((mp)->m_dirblksize - (uint)sizeof(xfs_dir2_free_hdr_t)) / \ | 
 | 58 | 	 (uint)sizeof(xfs_dir2_data_off_t)) | 
 | 59 |  | 
 | 60 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 |  * Convert data space db to the corresponding free db. | 
 | 62 |  */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 63 | static inline xfs_dir2_db_t | 
 | 64 | xfs_dir2_db_to_fdb(struct xfs_mount *mp, xfs_dir2_db_t db) | 
 | 65 | { | 
 | 66 | 	return (XFS_DIR2_FREE_FIRSTDB(mp) + (db) / XFS_DIR2_MAX_FREE_BESTS(mp)); | 
 | 67 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 |  | 
 | 69 | /* | 
 | 70 |  * Convert data space db to the corresponding index in a free db. | 
 | 71 |  */ | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 72 | static inline int | 
 | 73 | xfs_dir2_db_to_fdindex(struct xfs_mount *mp, xfs_dir2_db_t db) | 
 | 74 | { | 
 | 75 | 	return ((db) % XFS_DIR2_MAX_FREE_BESTS(mp)); | 
 | 76 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 |  | 
| Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 78 | extern int xfs_dir2_leaf_to_node(struct xfs_da_args *args, | 
 | 79 | 				 struct xfs_dabuf *lbp); | 
 | 80 | extern xfs_dahash_t xfs_dir2_leafn_lasthash(struct xfs_dabuf *bp, int *count); | 
 | 81 | extern int xfs_dir2_leafn_lookup_int(struct xfs_dabuf *bp, | 
 | 82 | 				     struct xfs_da_args *args, int *indexp, | 
 | 83 | 				     struct xfs_da_state *state); | 
 | 84 | extern int xfs_dir2_leafn_order(struct xfs_dabuf *leaf1_bp, | 
 | 85 | 				struct xfs_dabuf *leaf2_bp); | 
 | 86 | extern int xfs_dir2_leafn_split(struct xfs_da_state *state, | 
 | 87 | 				struct xfs_da_state_blk *oldblk, | 
 | 88 | 				struct xfs_da_state_blk *newblk); | 
 | 89 | extern int xfs_dir2_leafn_toosmall(struct xfs_da_state *state, int *action); | 
 | 90 | extern void xfs_dir2_leafn_unbalance(struct xfs_da_state *state, | 
 | 91 | 				     struct xfs_da_state_blk *drop_blk, | 
 | 92 | 				     struct xfs_da_state_blk *save_blk); | 
 | 93 | extern int xfs_dir2_node_addname(struct xfs_da_args *args); | 
 | 94 | extern int xfs_dir2_node_lookup(struct xfs_da_args *args); | 
 | 95 | extern int xfs_dir2_node_removename(struct xfs_da_args *args); | 
 | 96 | extern int xfs_dir2_node_replace(struct xfs_da_args *args); | 
 | 97 | extern int xfs_dir2_node_trim_free(struct xfs_da_args *args, xfs_fileoff_t fo, | 
 | 98 | 				   int *rvalp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 |  | 
 | 100 | #endif	/* __XFS_DIR2_NODE_H__ */ |