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