1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6 #ifndef __XFS_BMAP_UTIL_H__
7 #define __XFS_BMAP_UTIL_H__
8
9 /* Kernel only BMAP related definitions and functions */
10
11 struct xfs_bmbt_irec;
12 struct xfs_extent_free_item;
13 struct xfs_ifork;
14 struct xfs_inode;
15 struct xfs_mount;
16 struct xfs_trans;
17 struct xfs_bmalloca;
18 struct xfs_zone_alloc_ctx;
19
20 #ifdef CONFIG_XFS_RT
21 int xfs_bmap_rtalloc(struct xfs_bmalloca *ap);
22 #else /* !CONFIG_XFS_RT */
23 /*
24 * Attempts to allocate RT extents when RT is disable indicates corruption and
25 * should trigger a shutdown.
26 */
27 static inline int
xfs_bmap_rtalloc(struct xfs_bmalloca * ap)28 xfs_bmap_rtalloc(struct xfs_bmalloca *ap)
29 {
30 return -EFSCORRUPTED;
31 }
32 #endif /* CONFIG_XFS_RT */
33
34 void xfs_bmap_punch_delalloc_range(struct xfs_inode *ip, int whichfork,
35 xfs_off_t start_byte, xfs_off_t end_byte,
36 struct xfs_zone_alloc_ctx *ac);
37
38 struct kgetbmap {
39 __s64 bmv_offset; /* file offset of segment in blocks */
40 __s64 bmv_block; /* starting block (64-bit daddr_t) */
41 __s64 bmv_length; /* length of segment, blocks */
42 __s32 bmv_oflags; /* output flags */
43 };
44 int xfs_getbmap(struct xfs_inode *ip, struct getbmapx *bmv,
45 struct kgetbmap *out);
46
47 /* functions in xfs_bmap.c that are only needed by xfs_bmap_util.c */
48 int xfs_bmap_extsize_align(struct xfs_mount *mp, struct xfs_bmbt_irec *gotp,
49 struct xfs_bmbt_irec *prevp, xfs_extlen_t extsz,
50 int rt, int eof, int delay, int convert,
51 xfs_fileoff_t *offp, xfs_extlen_t *lenp);
52 bool xfs_bmap_adjacent(struct xfs_bmalloca *ap);
53 int xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip,
54 int whichfork, struct xfs_bmbt_irec *rec,
55 int *is_empty);
56
57 /* preallocation and hole punch interface */
58 enum xfs_alloc_file_space_mode {
59 XFS_ALLOC_FILE_SPACE_PREALLOC,
60 XFS_ALLOC_FILE_SPACE_WRITE_ZEROES,
61 };
62
63 int xfs_alloc_file_space(struct xfs_inode *ip, xfs_off_t offset,
64 xfs_off_t len, enum xfs_alloc_file_space_mode mode);
65 int xfs_free_file_space(struct xfs_inode *ip, xfs_off_t offset,
66 xfs_off_t len, struct xfs_zone_alloc_ctx *ac);
67 int xfs_collapse_file_space(struct xfs_inode *, xfs_off_t offset,
68 xfs_off_t len, struct xfs_zone_alloc_ctx *ac);
69 int xfs_insert_file_space(struct xfs_inode *, xfs_off_t offset,
70 xfs_off_t len);
71
72 /* EOF block manipulation functions */
73 bool xfs_can_free_eofblocks(struct xfs_inode *ip);
74 int xfs_free_eofblocks(struct xfs_inode *ip);
75
76 int xfs_swap_extents(struct xfs_inode *ip, struct xfs_inode *tip,
77 struct xfs_swapext *sx);
78
79 xfs_daddr_t xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb);
80
81 xfs_extnum_t xfs_bmap_count_leaves(struct xfs_ifork *ifp, xfs_filblks_t *count);
82 int xfs_bmap_count_blocks(struct xfs_trans *tp, struct xfs_inode *ip,
83 int whichfork, xfs_extnum_t *nextents,
84 xfs_filblks_t *count);
85
86 int xfs_flush_unmap_range(struct xfs_inode *ip, xfs_off_t offset,
87 xfs_off_t len);
88
89 void xfs_bmap_replace_cow_mapping(struct xfs_inode *ip,
90 struct xfs_iext_cursor *icur, struct xfs_bmbt_irec *got,
91 struct xfs_bmbt_irec *rep);
92
93 #endif /* __XFS_BMAP_UTIL_H__ */
94