]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/xfs_bmap.h
fix unused var warning
[thirdparty/xfsprogs-dev.git] / include / xfs_bmap.h
CommitLineData
2bd0ea18 1/*
f302e9e4
NS
2 * Copyright (c) 2000-2003,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_BMAP_H__
dfc130f3 19#define __XFS_BMAP_H__
2bd0ea18
NS
20
21struct getbmap;
22struct xfs_bmbt_irec;
23struct xfs_inode;
24struct xfs_mount;
25struct xfs_trans;
26
27/*
28 * List of extents to be free "later".
29 * The list is kept sorted on xbf_startblock.
30 */
31typedef struct xfs_bmap_free_item
32{
33 xfs_fsblock_t xbfi_startblock;/* starting fs block number */
34 xfs_extlen_t xbfi_blockcount;/* number of blocks in extent */
35 struct xfs_bmap_free_item *xbfi_next; /* link to next entry */
36} xfs_bmap_free_item_t;
37
38/*
39 * Header for free extent list.
40 */
dfc130f3 41typedef struct xfs_bmap_free
2bd0ea18
NS
42{
43 xfs_bmap_free_item_t *xbf_first; /* list of to-be-free extents */
44 int xbf_count; /* count of items on list */
45 int xbf_low; /* kludge: alloc in low mode */
46} xfs_bmap_free_t;
47
dfc130f3 48#define XFS_BMAP_MAX_NMAP 4
2bd0ea18
NS
49
50/*
51 * Flags for xfs_bmapi
52 */
dfc130f3 53#define XFS_BMAPI_WRITE 0x001 /* write operation: allocate space */
2bd0ea18
NS
54#define XFS_BMAPI_DELAY 0x002 /* delayed write operation */
55#define XFS_BMAPI_ENTIRE 0x004 /* return entire extent, not trimmed */
56#define XFS_BMAPI_METADATA 0x008 /* mapping metadata not user data */
57#define XFS_BMAPI_EXACT 0x010 /* allocate only to spec'd bounds */
58#define XFS_BMAPI_ATTRFORK 0x020 /* use attribute fork not data */
59#define XFS_BMAPI_ASYNC 0x040 /* bunmapi xactions can be async */
60#define XFS_BMAPI_RSVBLOCKS 0x080 /* OK to alloc. reserved data blocks */
dfc130f3
RC
61#define XFS_BMAPI_PREALLOC 0x100 /* preallocation op: unwritten space */
62#define XFS_BMAPI_IGSTATE 0x200 /* Ignore state - */
2bd0ea18 63 /* combine contig. space */
dfc130f3 64#define XFS_BMAPI_CONTIG 0x400 /* must allocate only one extent */
399ab595
NS
65/* XFS_BMAPI_DIRECT_IO 0x800 */
66#define XFS_BMAPI_CONVERT 0x1000 /* unwritten extent conversion - */
67 /* need write cache flushing and no */
68 /* additional allocation alignments */
2bd0ea18 69
dfc130f3 70#define XFS_BMAPI_AFLAG(w) xfs_bmapi_aflag(w)
f302e9e4
NS
71static inline int xfs_bmapi_aflag(int w)
72{
73 return (w == XFS_ATTR_FORK ? XFS_BMAPI_ATTRFORK : 0);
74}
2bd0ea18
NS
75
76/*
77 * Special values for xfs_bmbt_irec_t br_startblock field.
78 */
dfc130f3
RC
79#define DELAYSTARTBLOCK ((xfs_fsblock_t)-1LL)
80#define HOLESTARTBLOCK ((xfs_fsblock_t)-2LL)
2bd0ea18 81
dfc130f3 82#define XFS_BMAP_INIT(flp,fbp) xfs_bmap_init(flp,fbp)
f302e9e4
NS
83static inline void xfs_bmap_init(xfs_bmap_free_t *flp, xfs_fsblock_t *fbp)
84{
2bd0ea18 85 ((flp)->xbf_first = NULL, (flp)->xbf_count = 0, \
f302e9e4
NS
86 (flp)->xbf_low = 0, *(fbp) = NULLFSBLOCK);
87}
2bd0ea18
NS
88
89/*
90 * Argument structure for xfs_bmap_alloc.
91 */
92typedef struct xfs_bmalloca {
93 xfs_fsblock_t firstblock; /* i/o first block allocated */
94 xfs_fsblock_t rval; /* starting block of new extent */
95 xfs_fileoff_t off; /* offset in file filling in */
96 struct xfs_trans *tp; /* transaction pointer */
97 struct xfs_inode *ip; /* incore inode pointer */
dfc130f3 98 struct xfs_bmbt_irec *prevp; /* extent before the new one */
2bd0ea18
NS
99 struct xfs_bmbt_irec *gotp; /* extent after, or delayed */
100 xfs_extlen_t alen; /* i/o length asked/allocated */
101 xfs_extlen_t total; /* total blocks needed for xaction */
dfc130f3 102 xfs_extlen_t minlen; /* mininum allocation size (blocks) */
2bd0ea18 103 xfs_extlen_t minleft; /* amount must be left after alloc */
85a875e9 104 char eof; /* set if allocating past last extent */
dfc130f3 105 char wasdel; /* replacing a delayed allocation */
85a875e9
ES
106 char userdata;/* set if is user data */
107 char low; /* low on space, using seq'l ags */
dfc130f3 108 char aeof; /* allocated space at eof */
399ab595 109 char conv; /* overwriting unwritten extents */
2bd0ea18
NS
110} xfs_bmalloca_t;
111
112#ifdef __KERNEL__
23aab3f9
NS
113
114#if defined(XFS_BMAP_TRACE)
115/*
116 * Trace operations for bmap extent tracing
117 */
118#define XFS_BMAP_KTRACE_DELETE 1
119#define XFS_BMAP_KTRACE_INSERT 2
120#define XFS_BMAP_KTRACE_PRE_UP 3
121#define XFS_BMAP_KTRACE_POST_UP 4
122
123#define XFS_BMAP_TRACE_SIZE 4096 /* size of global trace buffer */
124#define XFS_BMAP_KTRACE_SIZE 32 /* size of per-inode trace buffer */
125extern ktrace_t *xfs_bmap_trace_buf;
126
127/*
128 * Add bmap trace insert entries for all the contents of the extent list.
129 */
130void
131xfs_bmap_trace_exlist(
132 char *fname, /* function name */
133 struct xfs_inode *ip, /* incore inode pointer */
134 xfs_extnum_t cnt, /* count of entries in list */
135 int whichfork); /* data or attr fork */
136#else
137#define xfs_bmap_trace_exlist(f,ip,c,w)
138#endif
139
2bd0ea18
NS
140/*
141 * Convert inode from non-attributed to attributed.
142 * Must not be in a transaction, ip must not be locked.
143 */
144int /* error code */
145xfs_bmap_add_attrfork(
146 struct xfs_inode *ip, /* incore inode pointer */
ca86e759
NS
147 int size, /* space needed for new attribute */
148 int rsvd); /* flag for reserved block allocation */
2bd0ea18
NS
149
150/*
151 * Add the extent to the list of extents to be free at transaction end.
152 * The list is maintained sorted (by block number).
153 */
154void
155xfs_bmap_add_free(
156 xfs_fsblock_t bno, /* fs block number of extent */
157 xfs_filblks_t len, /* length of extent */
158 xfs_bmap_free_t *flist, /* list of extents */
159 struct xfs_mount *mp); /* mount point structure */
160
161/*
162 * Routine to clean up the free list data structure when
163 * an error occurs during a transaction.
164 */
165void
166xfs_bmap_cancel(
167 xfs_bmap_free_t *flist); /* free list to clean up */
168
5000d01d 169/*
2bd0ea18 170 * Compute and fill in the value of the maximum depth of a bmap btree
dfc130f3 171 * in this filesystem. Done once, during mount.
2bd0ea18
NS
172 */
173void
174xfs_bmap_compute_maxlevels(
175 struct xfs_mount *mp, /* file system mount structure */
176 int whichfork); /* data or attr fork */
177
178/*
5000d01d 179 * Routine to be called at transaction's end by xfs_bmapi, xfs_bunmapi
2bd0ea18
NS
180 * caller. Frees all the extents that need freeing, which must be done
181 * last due to locking considerations.
182 *
183 * Return 1 if the given transaction was committed and a new one allocated,
184 * and 0 otherwise.
185 */
186int /* error */
187xfs_bmap_finish(
188 struct xfs_trans **tp, /* transaction pointer addr */
189 xfs_bmap_free_t *flist, /* i/o: list extents to free */
190 xfs_fsblock_t firstblock, /* controlled a.g. for allocs */
191 int *committed); /* xact committed or not */
192
193/*
194 * Returns the file-relative block number of the first unused block in the file.
195 * This is the lowest-address hole if the file has holes, else the first block
196 * past the end of file.
197 */
198int /* error */
199xfs_bmap_first_unused(
200 struct xfs_trans *tp, /* transaction pointer */
201 struct xfs_inode *ip, /* incore inode */
202 xfs_extlen_t len, /* size of hole to find */
203 xfs_fileoff_t *unused, /* unused block num */
204 int whichfork); /* data or attr fork */
205
206/*
207 * Returns the file-relative block number of the last block + 1 before
208 * last_block (input value) in the file.
209 * This is not based on i_size, it is based on the extent list.
210 * Returns 0 for local files, as they do not have an extent list.
211 */
212int /* error */
213xfs_bmap_last_before(
214 struct xfs_trans *tp, /* transaction pointer */
215 struct xfs_inode *ip, /* incore inode */
216 xfs_fileoff_t *last_block, /* last block */
217 int whichfork); /* data or attr fork */
218
219/*
220 * Returns the file-relative block number of the first block past eof in
221 * the file. This is not based on i_size, it is based on the extent list.
222 * Returns 0 for local files, as they do not have an extent list.
223 */
224int /* error */
225xfs_bmap_last_offset(
226 struct xfs_trans *tp, /* transaction pointer */
227 struct xfs_inode *ip, /* incore inode */
228 xfs_fileoff_t *unused, /* last block num */
229 int whichfork); /* data or attr fork */
230
231/*
232 * Returns whether the selected fork of the inode has exactly one
233 * block or not. For the data fork we check this matches di_size,
234 * implying the file's range is 0..bsize-1.
235 */
236int
237xfs_bmap_one_block(
238 struct xfs_inode *ip, /* incore inode */
239 int whichfork); /* data or attr fork */
240
241/*
242 * Read in the extents to iu_extents.
243 * All inode fields are set up by caller, we just traverse the btree
244 * and copy the records in.
245 */
246int /* error */
247xfs_bmap_read_extents(
248 struct xfs_trans *tp, /* transaction pointer */
249 struct xfs_inode *ip, /* incore inode */
250 int whichfork); /* data or attr fork */
251
2bd0ea18
NS
252/*
253 * Map file blocks to filesystem blocks.
254 * File range is given by the bno/len pair.
255 * Adds blocks to file if a write ("flags & XFS_BMAPI_WRITE" set)
256 * into a hole or past eof.
257 * Only allocates blocks from a single allocation group,
258 * to avoid locking problems.
259 * The returned value in "firstblock" from the first call in a transaction
260 * must be remembered and presented to subsequent calls in "firstblock".
261 * An upper bound for the number of blocks to be allocated is supplied to
262 * the first call in "total"; if no allocation group has that many free
5000d01d 263 * blocks then the call will fail (return NULLFSBLOCK in "firstblock").
2bd0ea18
NS
264 */
265int /* error */
266xfs_bmapi(
267 struct xfs_trans *tp, /* transaction pointer */
268 struct xfs_inode *ip, /* incore inode */
269 xfs_fileoff_t bno, /* starting file offs. mapped */
270 xfs_filblks_t len, /* length to map in file */
271 int flags, /* XFS_BMAPI_... */
272 xfs_fsblock_t *firstblock, /* first allocated block
273 controls a.g. for allocs */
274 xfs_extlen_t total, /* total blocks needed */
275 struct xfs_bmbt_irec *mval, /* output: map values */
276 int *nmap, /* i/o: mval size/count */
277 xfs_bmap_free_t *flist); /* i/o: list extents to free */
278
279/*
280 * Map file blocks to filesystem blocks, simple version.
281 * One block only, read-only.
282 * For flags, only the XFS_BMAPI_ATTRFORK flag is examined.
283 * For the other flag values, the effect is as if XFS_BMAPI_METADATA
284 * was set and all the others were clear.
285 */
286int /* error */
287xfs_bmapi_single(
288 struct xfs_trans *tp, /* transaction pointer */
289 struct xfs_inode *ip, /* incore inode */
290 int whichfork, /* data or attr fork */
291 xfs_fsblock_t *fsb, /* output: mapped block */
292 xfs_fileoff_t bno); /* starting file offs. mapped */
293
294/*
295 * Unmap (remove) blocks from a file.
296 * If nexts is nonzero then the number of extents to remove is limited to
dfc130f3 297 * that value. If not all extents in the block range can be removed then
2bd0ea18
NS
298 * *done is set.
299 */
300int /* error */
301xfs_bunmapi(
302 struct xfs_trans *tp, /* transaction pointer */
303 struct xfs_inode *ip, /* incore inode */
304 xfs_fileoff_t bno, /* starting offset to unmap */
305 xfs_filblks_t len, /* length to unmap in file */
306 int flags, /* XFS_BMAPI_... */
307 xfs_extnum_t nexts, /* number of extents max */
308 xfs_fsblock_t *firstblock, /* first allocated block
309 controls a.g. for allocs */
310 xfs_bmap_free_t *flist, /* i/o: list extents to free */
311 int *done); /* set if not done yet */
312
313/*
314 * Fcntl interface to xfs_bmapi.
315 */
316int /* error code */
317xfs_getbmap(
318 bhv_desc_t *bdp, /* XFS behavior descriptor*/
319 struct getbmap *bmv, /* user bmap structure */
062998e3 320 void __user *ap, /* pointer to user's array */
2bd0ea18
NS
321 int iflags); /* interface flags */
322
2bd0ea18 323/*
5000d01d 324 * Check if the endoff is outside the last extent. If so the caller will grow
2bd0ea18
NS
325 * the allocation to a stripe unit boundary
326 */
327int
328xfs_bmap_eof(
dfc130f3
RC
329 struct xfs_inode *ip,
330 xfs_fileoff_t endoff,
331 int whichfork,
332 int *eof);
2bd0ea18
NS
333
334/*
335 * Count fsblocks of the given fork.
336 */
337int
338xfs_bmap_count_blocks(
339 xfs_trans_t *tp,
23aab3f9 340 struct xfs_inode *ip,
2bd0ea18
NS
341 int whichfork,
342 int *count);
343
344/*
345 * Check an extent list, which has just been read, for
346 * any bit in the extent flag field.
347 */
348int
349xfs_check_nostate_extents(
350 xfs_bmbt_rec_t *ep,
351 xfs_extnum_t num);
352
353#endif /* __KERNEL__ */
354
355#endif /* __XFS_BMAP_H__ */