]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/xfs_ialloc.h
Merge back recent changes from xfs kernel headers.
[thirdparty/xfsprogs-dev.git] / include / xfs_ialloc.h
CommitLineData
2bd0ea18 1/*
f302e9e4
NS
2 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
5000d01d 4 *
f302e9e4
NS
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
2bd0ea18 7 * published by the Free Software Foundation.
5000d01d 8 *
f302e9e4
NS
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.
5000d01d 13 *
f302e9e4
NS
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
2bd0ea18
NS
17 */
18#ifndef __XFS_IALLOC_H__
dfc130f3 19#define __XFS_IALLOC_H__
2bd0ea18
NS
20
21struct xfs_buf;
22struct xfs_dinode;
23struct xfs_mount;
24struct xfs_trans;
25
26/*
27 * Allocation parameters for inode allocation.
28 */
f302e9e4
NS
29#define XFS_IALLOC_INODES(mp) (mp)->m_ialloc_inos
30#define XFS_IALLOC_BLOCKS(mp) (mp)->m_ialloc_blks
2bd0ea18
NS
31
32/*
33 * For small block file systems, move inodes in clusters of this size.
34 * When we don't have a lot of memory, however, we go a bit smaller
35 * to reduce the number of AGI and ialloc btree blocks we need to keep
36 * around for xfs_dilocate(). We choose which one to use in
37 * xfs_mount_int().
38 */
dfc130f3
RC
39#define XFS_INODE_BIG_CLUSTER_SIZE 8192
40#define XFS_INODE_SMALL_CLUSTER_SIZE 4096
41#define XFS_INODE_CLUSTER_SIZE(mp) (mp)->m_inode_cluster_size
2bd0ea18
NS
42
43/*
44 * Make an inode pointer out of the buffer/offset.
45 */
dfc130f3 46#define XFS_MAKE_IPTR(mp,b,o) xfs_make_iptr(mp,b,o)
f302e9e4
NS
47static inline struct xfs_dinode *
48xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o)
49{
50 return (xfs_dinode_t *)
51 (xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog));
52}
2bd0ea18
NS
53
54/*
55 * Find a free (set) bit in the inode bitmask.
56 */
dfc130f3 57#define XFS_IALLOC_FIND_FREE(fp) xfs_ialloc_find_free(fp)
f302e9e4
NS
58static inline int xfs_ialloc_find_free(xfs_inofree_t *fp)
59{
60 return xfs_lowbit64(*fp);
61}
2bd0ea18
NS
62
63
64#ifdef __KERNEL__
2bd0ea18
NS
65/*
66 * Allocate an inode on disk.
67 * Mode is used to tell whether the new inode will need space, and whether
68 * it is a directory.
69 *
70 * To work within the constraint of one allocation per transaction,
71 * xfs_dialloc() is designed to be called twice if it has to do an
dfc130f3 72 * allocation to make more free inodes. If an inode is
2bd0ea18
NS
73 * available without an allocation, agbp would be set to the current
74 * agbp and alloc_done set to false.
75 * If an allocation needed to be done, agbp would be set to the
76 * inode header of the allocation group and alloc_done set to true.
77 * The caller should then commit the current transaction and allocate a new
dfc130f3 78 * transaction. xfs_dialloc() should then be called again with
2bd0ea18
NS
79 * the agbp value returned from the previous call.
80 *
81 * Once we successfully pick an inode its number is returned and the
dfc130f3 82 * on-disk data structures are updated. The inode itself is not read
2bd0ea18
NS
83 * in, since doing so would break ordering constraints with xfs_reclaim.
84 *
85 * *agbp should be set to NULL on the first call, *alloc_done set to FALSE.
86 */
87int /* error */
88xfs_dialloc(
89 struct xfs_trans *tp, /* transaction pointer */
90 xfs_ino_t parent, /* parent inode (directory) */
91 mode_t mode, /* mode bits for new inode */
92 int okalloc, /* ok to allocate more space */
93 struct xfs_buf **agbp, /* buf for a.g. inode header */
94 boolean_t *alloc_done, /* an allocation was done to replenish
95 the free inodes */
96 xfs_ino_t *inop); /* inode number allocated */
97
98/*
99 * Free disk inode. Carefully avoids touching the incore inode, all
100 * manipulations incore are the caller's responsibility.
101 * The on-disk inode is not changed by this operation, only the
102 * btree (free inode mask) is changed.
103 */
104int /* error */
105xfs_difree(
106 struct xfs_trans *tp, /* transaction pointer */
23aab3f9
NS
107 xfs_ino_t inode, /* inode to be freed */
108 struct xfs_bmap_free *flist, /* extents to free */
109 int *delete, /* set if inode cluster was deleted */
110 xfs_ino_t *first_ino); /* first inode in deleted cluster */
2bd0ea18
NS
111
112/*
113 * Return the location of the inode in bno/len/off,
114 * for mapping it into a buffer.
115 */
116int
117xfs_dilocate(
118 struct xfs_mount *mp, /* file system mount structure */
119 struct xfs_trans *tp, /* transaction pointer */
120 xfs_ino_t ino, /* inode to locate */
121 xfs_fsblock_t *bno, /* output: block containing inode */
122 int *len, /* output: num blocks in cluster*/
123 int *off, /* output: index in block of inode */
124 uint flags); /* flags for inode btree lookup */
125
126/*
127 * Compute and fill in value of m_in_maxlevels.
128 */
129void
130xfs_ialloc_compute_maxlevels(
131 struct xfs_mount *mp); /* file system mount structure */
132
133/*
134 * Log specified fields for the ag hdr (inode section)
135 */
136void
137xfs_ialloc_log_agi(
138 struct xfs_trans *tp, /* transaction pointer */
139 struct xfs_buf *bp, /* allocation group header buffer */
140 int fields); /* bitmask of fields to log */
141
142/*
143 * Read in the allocation group header (inode allocation section)
144 */
145int /* error */
146xfs_ialloc_read_agi(
147 struct xfs_mount *mp, /* file system mount structure */
148 struct xfs_trans *tp, /* transaction pointer */
149 xfs_agnumber_t agno, /* allocation group number */
150 struct xfs_buf **bpp); /* allocation group hdr buf */
151
152#endif /* __KERNEL__ */
153
154#endif /* __XFS_IALLOC_H__ */