2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 #ifndef __XFS_BMAP_H__
33 #define __XFS_BMAP_H__
42 * List of extents to be free "later".
43 * The list is kept sorted on xbf_startblock.
45 typedef struct xfs_bmap_free_item
47 xfs_fsblock_t xbfi_startblock
;/* starting fs block number */
48 xfs_extlen_t xbfi_blockcount
;/* number of blocks in extent */
49 struct xfs_bmap_free_item
*xbfi_next
; /* link to next entry */
50 } xfs_bmap_free_item_t
;
53 * Header for free extent list.
55 typedef struct xfs_bmap_free
57 xfs_bmap_free_item_t
*xbf_first
; /* list of to-be-free extents */
58 int xbf_count
; /* count of items on list */
59 int xbf_low
; /* kludge: alloc in low mode */
62 #define XFS_BMAP_MAX_NMAP 4
67 #define XFS_BMAPI_WRITE 0x001 /* write operation: allocate space */
68 #define XFS_BMAPI_DELAY 0x002 /* delayed write operation */
69 #define XFS_BMAPI_ENTIRE 0x004 /* return entire extent, not trimmed */
70 #define XFS_BMAPI_METADATA 0x008 /* mapping metadata not user data */
71 #define XFS_BMAPI_EXACT 0x010 /* allocate only to spec'd bounds */
72 #define XFS_BMAPI_ATTRFORK 0x020 /* use attribute fork not data */
73 #define XFS_BMAPI_ASYNC 0x040 /* bunmapi xactions can be async */
74 #define XFS_BMAPI_RSVBLOCKS 0x080 /* OK to alloc. reserved data blocks */
75 #define XFS_BMAPI_PREALLOC 0x100 /* preallocation op: unwritten space */
76 #define XFS_BMAPI_IGSTATE 0x200 /* Ignore state - */
77 /* combine contig. space */
78 #define XFS_BMAPI_CONTIG 0x400 /* must allocate only one extent */
79 #define XFS_BMAPI_DIRECT_IO 0x800 /* Flag from cxfs client, not used
80 * by xfs directly. Indicates alloc
81 * request is for direct I/O not
82 * extent conversion by server */
84 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BMAPI_AFLAG)
85 int xfs_bmapi_aflag(int w
);
86 #define XFS_BMAPI_AFLAG(w) xfs_bmapi_aflag(w)
88 #define XFS_BMAPI_AFLAG(w) ((w) == XFS_ATTR_FORK ? XFS_BMAPI_ATTRFORK : 0)
92 * Special values for xfs_bmbt_irec_t br_startblock field.
94 #define DELAYSTARTBLOCK ((xfs_fsblock_t)-1LL)
95 #define HOLESTARTBLOCK ((xfs_fsblock_t)-2LL)
98 * Trace operations for bmap extent tracing
100 #define XFS_BMAP_KTRACE_DELETE 1
101 #define XFS_BMAP_KTRACE_INSERT 2
102 #define XFS_BMAP_KTRACE_PRE_UP 3
103 #define XFS_BMAP_KTRACE_POST_UP 4
105 #define XFS_BMAP_TRACE_SIZE 4096 /* size of global trace buffer */
106 #define XFS_BMAP_KTRACE_SIZE 32 /* size of per-inode trace buffer */
108 #if defined(XFS_ALL_TRACE)
109 #define XFS_BMAP_TRACE
113 #undef XFS_BMAP_TRACE
117 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BMAP_INIT)
118 void xfs_bmap_init(xfs_bmap_free_t
*flp
, xfs_fsblock_t
*fbp
);
119 #define XFS_BMAP_INIT(flp,fbp) xfs_bmap_init(flp,fbp)
121 #define XFS_BMAP_INIT(flp,fbp) \
122 ((flp)->xbf_first = NULL, (flp)->xbf_count = 0, \
123 (flp)->xbf_low = 0, *(fbp) = NULLFSBLOCK)
127 * Argument structure for xfs_bmap_alloc.
129 typedef struct xfs_bmalloca
{
130 xfs_fsblock_t firstblock
; /* i/o first block allocated */
131 xfs_fsblock_t rval
; /* starting block of new extent */
132 xfs_fileoff_t off
; /* offset in file filling in */
133 struct xfs_trans
*tp
; /* transaction pointer */
134 struct xfs_inode
*ip
; /* incore inode pointer */
135 struct xfs_bmbt_irec
*prevp
; /* extent before the new one */
136 struct xfs_bmbt_irec
*gotp
; /* extent after, or delayed */
137 xfs_extlen_t alen
; /* i/o length asked/allocated */
138 xfs_extlen_t total
; /* total blocks needed for xaction */
139 xfs_extlen_t minlen
; /* mininum allocation size (blocks) */
140 xfs_extlen_t minleft
; /* amount must be left after alloc */
141 int eof
; /* set if allocating past last extent */
142 int wasdel
; /* replacing a delayed allocation */
143 int userdata
;/* set if is user data */
144 int low
; /* low on space, using seq'l ags */
145 int aeof
; /* allocated space at eof */
150 * Convert inode from non-attributed to attributed.
151 * Must not be in a transaction, ip must not be locked.
154 xfs_bmap_add_attrfork(
155 struct xfs_inode
*ip
, /* incore inode pointer */
156 int rsvd
); /* flag for reserved block allocation */
159 * Add the extent to the list of extents to be free at transaction end.
160 * The list is maintained sorted (by block number).
164 xfs_fsblock_t bno
, /* fs block number of extent */
165 xfs_filblks_t len
, /* length of extent */
166 xfs_bmap_free_t
*flist
, /* list of extents */
167 struct xfs_mount
*mp
); /* mount point structure */
170 * Routine to clean up the free list data structure when
171 * an error occurs during a transaction.
175 xfs_bmap_free_t
*flist
); /* free list to clean up */
178 * Routine to check if a specified inode is swap capable.
181 xfs_bmap_check_swappable(
182 struct xfs_inode
*ip
); /* incore inode */
185 * Compute and fill in the value of the maximum depth of a bmap btree
186 * in this filesystem. Done once, during mount.
189 xfs_bmap_compute_maxlevels(
190 struct xfs_mount
*mp
, /* file system mount structure */
191 int whichfork
); /* data or attr fork */
194 * Routine to be called at transaction's end by xfs_bmapi, xfs_bunmapi
195 * caller. Frees all the extents that need freeing, which must be done
196 * last due to locking considerations.
198 * Return 1 if the given transaction was committed and a new one allocated,
203 struct xfs_trans
**tp
, /* transaction pointer addr */
204 xfs_bmap_free_t
*flist
, /* i/o: list extents to free */
205 xfs_fsblock_t firstblock
, /* controlled a.g. for allocs */
206 int *committed
); /* xact committed or not */
209 * Returns the file-relative block number of the first unused block in the file.
210 * This is the lowest-address hole if the file has holes, else the first block
211 * past the end of file.
214 xfs_bmap_first_unused(
215 struct xfs_trans
*tp
, /* transaction pointer */
216 struct xfs_inode
*ip
, /* incore inode */
217 xfs_extlen_t len
, /* size of hole to find */
218 xfs_fileoff_t
*unused
, /* unused block num */
219 int whichfork
); /* data or attr fork */
222 * Returns the file-relative block number of the last block + 1 before
223 * last_block (input value) in the file.
224 * This is not based on i_size, it is based on the extent list.
225 * Returns 0 for local files, as they do not have an extent list.
228 xfs_bmap_last_before(
229 struct xfs_trans
*tp
, /* transaction pointer */
230 struct xfs_inode
*ip
, /* incore inode */
231 xfs_fileoff_t
*last_block
, /* last block */
232 int whichfork
); /* data or attr fork */
235 * Returns the file-relative block number of the first block past eof in
236 * the file. This is not based on i_size, it is based on the extent list.
237 * Returns 0 for local files, as they do not have an extent list.
240 xfs_bmap_last_offset(
241 struct xfs_trans
*tp
, /* transaction pointer */
242 struct xfs_inode
*ip
, /* incore inode */
243 xfs_fileoff_t
*unused
, /* last block num */
244 int whichfork
); /* data or attr fork */
247 * Returns whether the selected fork of the inode has exactly one
248 * block or not. For the data fork we check this matches di_size,
249 * implying the file's range is 0..bsize-1.
253 struct xfs_inode
*ip
, /* incore inode */
254 int whichfork
); /* data or attr fork */
257 * Read in the extents to iu_extents.
258 * All inode fields are set up by caller, we just traverse the btree
259 * and copy the records in.
262 xfs_bmap_read_extents(
263 struct xfs_trans
*tp
, /* transaction pointer */
264 struct xfs_inode
*ip
, /* incore inode */
265 int whichfork
); /* data or attr fork */
267 #if defined(XFS_BMAP_TRACE)
269 * Add bmap trace insert entries for all the contents of the extent list.
272 xfs_bmap_trace_exlist(
273 char *fname
, /* function name */
274 struct xfs_inode
*ip
, /* incore inode pointer */
275 xfs_extnum_t cnt
, /* count of entries in list */
276 int whichfork
); /* data or attr fork */
278 #define xfs_bmap_trace_exlist(f,ip,c,w)
282 * Map file blocks to filesystem blocks.
283 * File range is given by the bno/len pair.
284 * Adds blocks to file if a write ("flags & XFS_BMAPI_WRITE" set)
285 * into a hole or past eof.
286 * Only allocates blocks from a single allocation group,
287 * to avoid locking problems.
288 * The returned value in "firstblock" from the first call in a transaction
289 * must be remembered and presented to subsequent calls in "firstblock".
290 * An upper bound for the number of blocks to be allocated is supplied to
291 * the first call in "total"; if no allocation group has that many free
292 * blocks then the call will fail (return NULLFSBLOCK in "firstblock").
296 struct xfs_trans
*tp
, /* transaction pointer */
297 struct xfs_inode
*ip
, /* incore inode */
298 xfs_fileoff_t bno
, /* starting file offs. mapped */
299 xfs_filblks_t len
, /* length to map in file */
300 int flags
, /* XFS_BMAPI_... */
301 xfs_fsblock_t
*firstblock
, /* first allocated block
302 controls a.g. for allocs */
303 xfs_extlen_t total
, /* total blocks needed */
304 struct xfs_bmbt_irec
*mval
, /* output: map values */
305 int *nmap
, /* i/o: mval size/count */
306 xfs_bmap_free_t
*flist
); /* i/o: list extents to free */
309 * Map file blocks to filesystem blocks, simple version.
310 * One block only, read-only.
311 * For flags, only the XFS_BMAPI_ATTRFORK flag is examined.
312 * For the other flag values, the effect is as if XFS_BMAPI_METADATA
313 * was set and all the others were clear.
317 struct xfs_trans
*tp
, /* transaction pointer */
318 struct xfs_inode
*ip
, /* incore inode */
319 int whichfork
, /* data or attr fork */
320 xfs_fsblock_t
*fsb
, /* output: mapped block */
321 xfs_fileoff_t bno
); /* starting file offs. mapped */
324 * Unmap (remove) blocks from a file.
325 * If nexts is nonzero then the number of extents to remove is limited to
326 * that value. If not all extents in the block range can be removed then
331 struct xfs_trans
*tp
, /* transaction pointer */
332 struct xfs_inode
*ip
, /* incore inode */
333 xfs_fileoff_t bno
, /* starting offset to unmap */
334 xfs_filblks_t len
, /* length to unmap in file */
335 int flags
, /* XFS_BMAPI_... */
336 xfs_extnum_t nexts
, /* number of extents max */
337 xfs_fsblock_t
*firstblock
, /* first allocated block
338 controls a.g. for allocs */
339 xfs_bmap_free_t
*flist
, /* i/o: list extents to free */
340 int *done
); /* set if not done yet */
343 * Fcntl interface to xfs_bmapi.
347 bhv_desc_t
*bdp
, /* XFS behavior descriptor*/
348 struct getbmap
*bmv
, /* user bmap structure */
349 void *ap
, /* pointer to user's array */
350 int iflags
); /* interface flags */
353 * Check the last inode extent to determine whether this allocation will result
354 * in blocks being allocated at the end of the file. When we allocate new data
355 * blocks at the end of the file which do not start at the previous data block,
356 * we will try to align the new blocks at stripe unit boundaries.
360 struct xfs_inode
*ip
,
366 * Check if the endoff is outside the last extent. If so the caller will grow
367 * the allocation to a stripe unit boundary
371 struct xfs_inode
*ip
,
372 xfs_fileoff_t endoff
,
377 * Count fsblocks of the given fork.
380 xfs_bmap_count_blocks(
387 * Check an extent list, which has just been read, for
388 * any bit in the extent flag field.
391 xfs_check_nostate_extents(
395 #endif /* __KERNEL__ */
397 #endif /* __XFS_BMAP_H__ */