xref: /linux/fs/xfs/xfs_iomap.h (revision a7f25dc23ff6d238ed70e8a3a8a3792cde3bcc68)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2003-2005 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6 #ifndef __XFS_IOMAP_H__
7 #define __XFS_IOMAP_H__
8 
9 #include <linux/iomap.h>
10 
11 struct xfs_inode;
12 struct xfs_bmbt_irec;
13 struct xfs_zone_alloc_ctx;
14 
15 int xfs_iomap_write_direct(struct xfs_inode *ip, xfs_fileoff_t offset_fsb,
16 		xfs_fileoff_t count_fsb, unsigned int flags,
17 		struct xfs_bmbt_irec *imap, u64 *sequence);
18 int xfs_iomap_write_unwritten(struct xfs_inode *, xfs_off_t, xfs_off_t, bool);
19 xfs_fileoff_t xfs_iomap_eof_align_last_fsb(struct xfs_inode *ip,
20 		xfs_fileoff_t end_fsb);
21 
22 u64 xfs_iomap_inode_sequence(struct xfs_inode *ip, u16 iomap_flags);
23 int xfs_bmbt_to_iomap(struct xfs_inode *ip, struct iomap *iomap,
24 		struct xfs_bmbt_irec *imap, unsigned int mapping_flags,
25 		u16 iomap_flags, u64 sequence_cookie);
26 
27 int xfs_zero_range(struct xfs_inode *ip, loff_t pos, loff_t len,
28 		struct xfs_zone_alloc_ctx *ac, bool *did_zero);
29 int xfs_truncate_page(struct xfs_inode *ip, loff_t pos,
30 		struct xfs_zone_alloc_ctx *ac, bool *did_zero);
31 
32 static inline void
xfs_iomap_set_anon_write(struct xfs_inode * ip,struct iomap * iomap,loff_t offset,loff_t length)33 xfs_iomap_set_anon_write(
34 	struct xfs_inode		*ip,
35 	struct iomap			*iomap,
36 	loff_t				offset,
37 	loff_t				length)
38 {
39 	iomap->type = IOMAP_MAPPED;
40 	iomap->bdev = ip->i_mount->m_rtdev_targp->bt_bdev;
41 	iomap->offset = offset;
42 	iomap->length = length;
43 	iomap->flags = IOMAP_F_ANON_WRITE | IOMAP_F_DIRTY;
44 }
45 
46 static inline xfs_filblks_t
xfs_aligned_fsb_count(xfs_fileoff_t offset_fsb,xfs_filblks_t count_fsb,xfs_extlen_t extsz)47 xfs_aligned_fsb_count(
48 	xfs_fileoff_t		offset_fsb,
49 	xfs_filblks_t		count_fsb,
50 	xfs_extlen_t		extsz)
51 {
52 	if (extsz) {
53 		xfs_extlen_t	align;
54 
55 		div_u64_rem(offset_fsb, extsz, &align);
56 		if (align)
57 			count_fsb += align;
58 		div_u64_rem(count_fsb, extsz, &align);
59 		if (align)
60 			count_fsb += extsz - align;
61 	}
62 
63 	return count_fsb;
64 }
65 
66 int xfs_read_iomap_begin(struct inode *inode, loff_t offset,
67 		loff_t length, unsigned flags, struct iomap *iomap,
68 		struct iomap *srcmap);
69 
70 extern const struct iomap_ops xfs_buffered_write_iomap_ops;
71 extern const struct iomap_ops xfs_direct_write_iomap_ops;
72 extern const struct iomap_ops xfs_zoned_direct_write_iomap_ops;
73 extern const struct iomap_ops xfs_read_iomap_ops;
74 extern const struct iomap_ops xfs_seek_iomap_ops;
75 extern const struct iomap_ops xfs_xattr_iomap_ops;
76 extern const struct iomap_ops xfs_dax_write_iomap_ops;
77 extern const struct iomap_ops xfs_atomic_write_cow_iomap_ops;
78 extern const struct iomap_write_ops xfs_iomap_write_ops;
79 
80 #endif /* __XFS_IOMAP_H__*/
81