]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - repair/bmap.h
libxfs: refactor manage_zones()
[thirdparty/xfsprogs-dev.git] / repair / bmap.h
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6
7 #ifndef _XFS_REPAIR_BMAP_H
8 #define _XFS_REPAIR_BMAP_H
9
10 /*
11 * Extent descriptor.
12 */
13 typedef struct bmap_ext {
14 xfs_fileoff_t startoff;
15 xfs_fsblock_t startblock;
16 xfs_filblks_t blockcount;
17 } bmap_ext_t;
18
19 /*
20 * Block map.
21 */
22 typedef struct blkmap {
23 int naexts;
24 int nexts;
25 bmap_ext_t exts[1];
26 } blkmap_t;
27
28 #define BLKMAP_SIZE(n) \
29 (offsetof(blkmap_t, exts) + (sizeof(bmap_ext_t) * (n)))
30
31 /*
32 * For 32 bit platforms, we are limited to extent arrays of 2^31 bytes, which
33 * limits the number of extents in an inode we can check. If we don't limit the
34 * valid range, we can overflow the BLKMAP_SIZE() calculation and allocate less
35 * memory than we think we needed, and hence walk off the end of the array and
36 * corrupt memory.
37 */
38 #if BITS_PER_LONG == 32
39 #define BLKMAP_NEXTS_MAX ((INT_MAX / sizeof(bmap_ext_t)) - 1)
40 #else
41 #define BLKMAP_NEXTS_MAX INT_MAX
42 #endif
43
44 extern pthread_key_t dblkmap_key;
45 extern pthread_key_t ablkmap_key;
46
47 blkmap_t *blkmap_alloc(xfs_extnum_t nex, int whichfork);
48 void blkmap_free(blkmap_t *blkmap);
49 void blkmap_free_final(void);
50
51 int blkmap_set_ext(blkmap_t **blkmapp, xfs_fileoff_t o,
52 xfs_fsblock_t b, xfs_filblks_t c);
53
54 xfs_fsblock_t blkmap_get(blkmap_t *blkmap, xfs_fileoff_t o);
55 int blkmap_getn(blkmap_t *blkmap, xfs_fileoff_t o,
56 xfs_filblks_t nb, bmap_ext_t **bmpp,
57 bmap_ext_t *bmpp_single);
58 xfs_fileoff_t blkmap_last_off(blkmap_t *blkmap);
59 xfs_fileoff_t blkmap_next_off(blkmap_t *blkmap, xfs_fileoff_t o, int *t);
60
61 #endif /* _XFS_REPAIR_BMAP_H */