blob: b8c7e72ed8379eccc4f6388d40f9642cee74bae0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32#ifndef __XFS_IALLOC_BTREE_H__
33#define __XFS_IALLOC_BTREE_H__
34
35/*
36 * Inode map on-disk structures
37 */
38
39struct xfs_buf;
40struct xfs_btree_cur;
41struct xfs_btree_sblock;
42struct xfs_mount;
43
44/*
45 * There is a btree for the inode map per allocation group.
46 */
47#define XFS_IBT_MAGIC 0x49414254 /* 'IABT' */
48
49typedef __uint64_t xfs_inofree_t;
50#define XFS_INODES_PER_CHUNK (NBBY * sizeof(xfs_inofree_t))
51#define XFS_INODES_PER_CHUNK_LOG (XFS_NBBYLOG + 3)
52#define XFS_INOBT_ALL_FREE ((xfs_inofree_t)-1)
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#define XFS_INOBT_MASKN(i,n) xfs_inobt_maskn(i,n)
Nathan Scotta844f452005-11-02 14:38:42 +110055static inline xfs_inofree_t xfs_inobt_maskn(int i, int n)
56{
57 return (((n) >= XFS_INODES_PER_CHUNK ? \
58 (xfs_inofree_t)0 : ((xfs_inofree_t)1 << (n))) - 1) << (i);
59}
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61/*
62 * Data record structure
63 */
64typedef struct xfs_inobt_rec
65{
66 xfs_agino_t ir_startino; /* starting inode number */
67 __int32_t ir_freecount; /* count of free inodes (set bits) */
68 xfs_inofree_t ir_free; /* free inode mask */
69} xfs_inobt_rec_t;
70
71/*
72 * Key structure
73 */
74typedef struct xfs_inobt_key
75{
76 xfs_agino_t ir_startino; /* starting inode number */
77} xfs_inobt_key_t;
78
79typedef xfs_agblock_t xfs_inobt_ptr_t; /* btree pointer type */
80 /* btree block header type */
81typedef struct xfs_btree_sblock xfs_inobt_block_t;
82
Nathan Scotta844f452005-11-02 14:38:42 +110083#define XFS_BUF_TO_INOBT_BLOCK(bp) ((xfs_inobt_block_t *)XFS_BUF_PTR(bp))
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85/*
86 * Bit manipulations for ir_free.
87 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define XFS_INOBT_MASK(i) ((xfs_inofree_t)1 << (i))
Nathan Scotta844f452005-11-02 14:38:42 +110089#define XFS_INOBT_IS_FREE(rp,i) \
90 (((rp)->ir_free & XFS_INOBT_MASK(i)) != 0)
91#define XFS_INOBT_IS_FREE_DISK(rp,i) \
92 ((INT_GET((rp)->ir_free,ARCH_CONVERT) & XFS_INOBT_MASK(i)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#define XFS_INOBT_SET_FREE(rp,i) ((rp)->ir_free |= XFS_INOBT_MASK(i))
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#define XFS_INOBT_CLR_FREE(rp,i) ((rp)->ir_free &= ~XFS_INOBT_MASK(i))
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96/*
97 * Real block structures have a size equal to the disk block size.
98 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#define XFS_INOBT_BLOCK_SIZE(lev,cur) (1 << (cur)->bc_blocklog)
Nathan Scotta844f452005-11-02 14:38:42 +1100100#define XFS_INOBT_BLOCK_MAXRECS(lev,cur) ((cur)->bc_mp->m_inobt_mxr[lev != 0])
101#define XFS_INOBT_BLOCK_MINRECS(lev,cur) ((cur)->bc_mp->m_inobt_mnr[lev != 0])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#define XFS_INOBT_IS_LAST_REC(cur) \
Nathan Scotta844f452005-11-02 14:38:42 +1100103 ((cur)->bc_ptrs[0] == INT_GET(XFS_BUF_TO_INOBT_BLOCK((cur)->bc_bufs[0])->bb_numrecs, ARCH_CONVERT))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105/*
106 * Maximum number of inode btree levels.
107 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#define XFS_IN_MAXLEVELS(mp) ((mp)->m_in_maxlevels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110/*
111 * block numbers in the AG.
112 */
Nathan Scotta844f452005-11-02 14:38:42 +1100113#define XFS_IBT_BLOCK(mp) ((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1))
114#define XFS_PREALLOC_BLOCKS(mp) ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116/*
117 * Record, key, and pointer address macros for btree blocks.
118 */
Nathan Scotta844f452005-11-02 14:38:42 +1100119#define XFS_INOBT_REC_ADDR(bb,i,cur) \
120 (XFS_BTREE_REC_ADDR(XFS_INOBT_BLOCK_SIZE(0,cur), xfs_inobt, bb, \
121 i, XFS_INOBT_BLOCK_MAXRECS(0, cur)))
122#define XFS_INOBT_KEY_ADDR(bb,i,cur) \
123 (XFS_BTREE_KEY_ADDR(XFS_INOBT_BLOCK_SIZE(1,cur), xfs_inobt, bb, \
124 i, XFS_INOBT_BLOCK_MAXRECS(1, cur)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Nathan Scotta844f452005-11-02 14:38:42 +1100126#define XFS_INOBT_PTR_ADDR(bb,i,cur) \
127 (XFS_BTREE_PTR_ADDR(XFS_INOBT_BLOCK_SIZE(1,cur), xfs_inobt, bb, \
128 i, XFS_INOBT_BLOCK_MAXRECS(1, cur)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130/*
131 * Decrement cursor by one record at the level.
132 * For nonzero levels the leaf-ward information is untouched.
133 */
Nathan Scotta844f452005-11-02 14:38:42 +1100134extern int xfs_inobt_decrement(struct xfs_btree_cur *cur, int level, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136/*
137 * Delete the record pointed to by cur.
138 * The cursor refers to the place where the record was (could be inserted)
139 * when the operation returns.
140 */
Nathan Scotta844f452005-11-02 14:38:42 +1100141extern int xfs_inobt_delete(struct xfs_btree_cur *cur, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143/*
144 * Get the data from the pointed-to record.
145 */
Nathan Scotta844f452005-11-02 14:38:42 +1100146extern int xfs_inobt_get_rec(struct xfs_btree_cur *cur, xfs_agino_t *ino,
147 __int32_t *fcnt, xfs_inofree_t *free, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149/*
150 * Increment cursor by one record at the level.
151 * For nonzero levels the leaf-ward information is untouched.
152 */
Nathan Scotta844f452005-11-02 14:38:42 +1100153extern int xfs_inobt_increment(struct xfs_btree_cur *cur, int level, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155/*
156 * Insert the current record at the point referenced by cur.
157 * The cursor may be inconsistent on return if splits have been done.
158 */
Nathan Scotta844f452005-11-02 14:38:42 +1100159extern int xfs_inobt_insert(struct xfs_btree_cur *cur, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161/*
162 * Lookup the record equal to ino in the btree given by cur.
163 */
Nathan Scotta844f452005-11-02 14:38:42 +1100164extern int xfs_inobt_lookup_eq(struct xfs_btree_cur *cur, xfs_agino_t ino,
165 __int32_t fcnt, xfs_inofree_t free, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167/*
168 * Lookup the first record greater than or equal to ino
169 * in the btree given by cur.
170 */
Nathan Scotta844f452005-11-02 14:38:42 +1100171extern int xfs_inobt_lookup_ge(struct xfs_btree_cur *cur, xfs_agino_t ino,
172 __int32_t fcnt, xfs_inofree_t free, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174/*
175 * Lookup the first record less than or equal to ino
176 * in the btree given by cur.
177 */
Nathan Scotta844f452005-11-02 14:38:42 +1100178extern int xfs_inobt_lookup_le(struct xfs_btree_cur *cur, xfs_agino_t ino,
179 __int32_t fcnt, xfs_inofree_t free, int *stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181/*
182 * Update the record referred to by cur, to the value given
183 * by [ino, fcnt, free].
184 * This either works (return 0) or gets an EFSCORRUPTED error.
185 */
Nathan Scotta844f452005-11-02 14:38:42 +1100186extern int xfs_inobt_update(struct xfs_btree_cur *cur, xfs_agino_t ino,
187 __int32_t fcnt, xfs_inofree_t free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189#endif /* __XFS_IALLOC_BTREE_H__ */