]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0 |
2bd0ea18 | 2 | /* |
da23017d NS |
3 | * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. |
4 | * All Rights Reserved. | |
2bd0ea18 NS |
5 | */ |
6 | ||
610f3285 BN |
7 | #ifndef _XFS_REPAIR_BMAP_H |
8 | #define _XFS_REPAIR_BMAP_H | |
2bd0ea18 NS |
9 | |
10 | /* | |
610f3285 | 11 | * Extent descriptor. |
2bd0ea18 | 12 | */ |
610f3285 | 13 | typedef struct bmap_ext { |
5a35bf2c DC |
14 | xfs_fileoff_t startoff; |
15 | xfs_fsblock_t startblock; | |
16 | xfs_filblks_t blockcount; | |
610f3285 | 17 | } bmap_ext_t; |
2bd0ea18 NS |
18 | |
19 | /* | |
20 | * Block map. | |
21 | */ | |
22 | typedef struct blkmap { | |
610f3285 BN |
23 | int naexts; |
24 | int nexts; | |
25 | bmap_ext_t exts[1]; | |
2bd0ea18 | 26 | } blkmap_t; |
2bd0ea18 | 27 | |
610f3285 BN |
28 | #define BLKMAP_SIZE(n) \ |
29 | (offsetof(blkmap_t, exts) + (sizeof(bmap_ext_t) * (n))) | |
2bd0ea18 | 30 | |
df63c43b DC |
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 | ||
52cb19dc CH |
44 | extern pthread_key_t dblkmap_key; |
45 | extern pthread_key_t ablkmap_key; | |
46 | ||
610f3285 | 47 | blkmap_t *blkmap_alloc(xfs_extnum_t nex, int whichfork); |
2bd0ea18 | 48 | void blkmap_free(blkmap_t *blkmap); |
bd758142 | 49 | void blkmap_free_final(void); |
610f3285 | 50 | |
5a35bf2c DC |
51 | int blkmap_set_ext(blkmap_t **blkmapp, xfs_fileoff_t o, |
52 | xfs_fsblock_t b, xfs_filblks_t c); | |
610f3285 | 53 | |
5a35bf2c DC |
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, | |
1e77098c | 57 | bmap_ext_t *bmpp_single); |
5a35bf2c DC |
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); | |
610f3285 BN |
60 | |
61 | #endif /* _XFS_REPAIR_BMAP_H */ |