]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/xfs_ialloc.h
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / include / xfs_ialloc.h
CommitLineData
2bd0ea18 1/*
854f7c66 2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
5000d01d 3 *
2bd0ea18
NS
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.
5000d01d 7 *
2bd0ea18
NS
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.
5000d01d 11 *
2bd0ea18
NS
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
dfc130f3 14 * or the like. Any license provided herein, whether implied or
2bd0ea18
NS
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.
5000d01d 18 *
2bd0ea18
NS
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.
5000d01d 22 *
2bd0ea18
NS
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
5000d01d
SL
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
2bd0ea18
NS
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32#ifndef __XFS_IALLOC_H__
dfc130f3 33#define __XFS_IALLOC_H__
2bd0ea18
NS
34
35struct xfs_buf;
36struct xfs_dinode;
37struct xfs_mount;
38struct xfs_trans;
39
40/*
41 * Allocation parameters for inode allocation.
42 */
43#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IALLOC_INODES)
44int xfs_ialloc_inodes(struct xfs_mount *mp);
dfc130f3 45#define XFS_IALLOC_INODES(mp) xfs_ialloc_inodes(mp)
2bd0ea18 46#else
dfc130f3 47#define XFS_IALLOC_INODES(mp) ((mp)->m_ialloc_inos)
2bd0ea18
NS
48#endif
49#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IALLOC_BLOCKS)
50xfs_extlen_t xfs_ialloc_blocks(struct xfs_mount *mp);
dfc130f3 51#define XFS_IALLOC_BLOCKS(mp) xfs_ialloc_blocks(mp)
2bd0ea18 52#else
dfc130f3 53#define XFS_IALLOC_BLOCKS(mp) ((mp)->m_ialloc_blks)
2bd0ea18
NS
54#endif
55
56/*
57 * For small block file systems, move inodes in clusters of this size.
58 * When we don't have a lot of memory, however, we go a bit smaller
59 * to reduce the number of AGI and ialloc btree blocks we need to keep
60 * around for xfs_dilocate(). We choose which one to use in
61 * xfs_mount_int().
62 */
dfc130f3
RC
63#define XFS_INODE_BIG_CLUSTER_SIZE 8192
64#define XFS_INODE_SMALL_CLUSTER_SIZE 4096
65#define XFS_INODE_CLUSTER_SIZE(mp) (mp)->m_inode_cluster_size
2bd0ea18
NS
66
67/*
68 * Make an inode pointer out of the buffer/offset.
69 */
70#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_MAKE_IPTR)
71struct xfs_dinode *xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o);
dfc130f3 72#define XFS_MAKE_IPTR(mp,b,o) xfs_make_iptr(mp,b,o)
2bd0ea18 73#else
dfc130f3 74#define XFS_MAKE_IPTR(mp,b,o) \
2bd0ea18
NS
75 ((xfs_dinode_t *)(xfs_buf_offset(b, (o) << (mp)->m_sb.sb_inodelog)))
76#endif
77
78/*
79 * Find a free (set) bit in the inode bitmask.
80 */
81#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IALLOC_FIND_FREE)
82int xfs_ialloc_find_free(xfs_inofree_t *fp);
dfc130f3 83#define XFS_IALLOC_FIND_FREE(fp) xfs_ialloc_find_free(fp)
2bd0ea18 84#else
dfc130f3 85#define XFS_IALLOC_FIND_FREE(fp) xfs_lowbit64(*(fp))
2bd0ea18
NS
86#endif
87
88
89#ifdef __KERNEL__
90
91/*
92 * Prototypes for visible xfs_ialloc.c routines.
93 */
94
95/*
96 * Allocate an inode on disk.
97 * Mode is used to tell whether the new inode will need space, and whether
98 * it is a directory.
99 *
100 * To work within the constraint of one allocation per transaction,
101 * xfs_dialloc() is designed to be called twice if it has to do an
dfc130f3 102 * allocation to make more free inodes. If an inode is
2bd0ea18
NS
103 * available without an allocation, agbp would be set to the current
104 * agbp and alloc_done set to false.
105 * If an allocation needed to be done, agbp would be set to the
106 * inode header of the allocation group and alloc_done set to true.
107 * The caller should then commit the current transaction and allocate a new
dfc130f3 108 * transaction. xfs_dialloc() should then be called again with
2bd0ea18
NS
109 * the agbp value returned from the previous call.
110 *
111 * Once we successfully pick an inode its number is returned and the
dfc130f3 112 * on-disk data structures are updated. The inode itself is not read
2bd0ea18
NS
113 * in, since doing so would break ordering constraints with xfs_reclaim.
114 *
115 * *agbp should be set to NULL on the first call, *alloc_done set to FALSE.
116 */
117int /* error */
118xfs_dialloc(
119 struct xfs_trans *tp, /* transaction pointer */
120 xfs_ino_t parent, /* parent inode (directory) */
121 mode_t mode, /* mode bits for new inode */
122 int okalloc, /* ok to allocate more space */
123 struct xfs_buf **agbp, /* buf for a.g. inode header */
124 boolean_t *alloc_done, /* an allocation was done to replenish
125 the free inodes */
126 xfs_ino_t *inop); /* inode number allocated */
127
128/*
129 * Free disk inode. Carefully avoids touching the incore inode, all
130 * manipulations incore are the caller's responsibility.
131 * The on-disk inode is not changed by this operation, only the
132 * btree (free inode mask) is changed.
133 */
134int /* error */
135xfs_difree(
136 struct xfs_trans *tp, /* transaction pointer */
137 xfs_ino_t inode); /* inode to be freed */
138
139/*
140 * Return the location of the inode in bno/len/off,
141 * for mapping it into a buffer.
142 */
143int
144xfs_dilocate(
145 struct xfs_mount *mp, /* file system mount structure */
146 struct xfs_trans *tp, /* transaction pointer */
147 xfs_ino_t ino, /* inode to locate */
148 xfs_fsblock_t *bno, /* output: block containing inode */
149 int *len, /* output: num blocks in cluster*/
150 int *off, /* output: index in block of inode */
151 uint flags); /* flags for inode btree lookup */
152
153/*
154 * Compute and fill in value of m_in_maxlevels.
155 */
156void
157xfs_ialloc_compute_maxlevels(
158 struct xfs_mount *mp); /* file system mount structure */
159
160/*
161 * Log specified fields for the ag hdr (inode section)
162 */
163void
164xfs_ialloc_log_agi(
165 struct xfs_trans *tp, /* transaction pointer */
166 struct xfs_buf *bp, /* allocation group header buffer */
167 int fields); /* bitmask of fields to log */
168
169/*
170 * Read in the allocation group header (inode allocation section)
171 */
172int /* error */
173xfs_ialloc_read_agi(
174 struct xfs_mount *mp, /* file system mount structure */
175 struct xfs_trans *tp, /* transaction pointer */
176 xfs_agnumber_t agno, /* allocation group number */
177 struct xfs_buf **bpp); /* allocation group hdr buf */
178
179#endif /* __KERNEL__ */
180
181#endif /* __XFS_IALLOC_H__ */