162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2016 Oracle.  All Rights Reserved.
462306a36Sopenharmony_ci * Author: Darrick J. Wong <darrick.wong@oracle.com>
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#ifndef __XFS_REFLINK_H
762306a36Sopenharmony_ci#define __XFS_REFLINK_H 1
862306a36Sopenharmony_ci
962306a36Sopenharmony_cistatic inline bool xfs_is_always_cow_inode(struct xfs_inode *ip)
1062306a36Sopenharmony_ci{
1162306a36Sopenharmony_ci	return ip->i_mount->m_always_cow && xfs_has_reflink(ip->i_mount);
1262306a36Sopenharmony_ci}
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_cistatic inline bool xfs_is_cow_inode(struct xfs_inode *ip)
1562306a36Sopenharmony_ci{
1662306a36Sopenharmony_ci	return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip);
1762306a36Sopenharmony_ci}
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ciextern int xfs_reflink_trim_around_shared(struct xfs_inode *ip,
2062306a36Sopenharmony_ci		struct xfs_bmbt_irec *irec, bool *shared);
2162306a36Sopenharmony_ciint xfs_bmap_trim_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap,
2262306a36Sopenharmony_ci		bool *shared);
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ciint xfs_reflink_allocate_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap,
2562306a36Sopenharmony_ci		struct xfs_bmbt_irec *cmap, bool *shared, uint *lockmode,
2662306a36Sopenharmony_ci		bool convert_now);
2762306a36Sopenharmony_ciextern int xfs_reflink_convert_cow(struct xfs_inode *ip, xfs_off_t offset,
2862306a36Sopenharmony_ci		xfs_off_t count);
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ciextern int xfs_reflink_cancel_cow_blocks(struct xfs_inode *ip,
3162306a36Sopenharmony_ci		struct xfs_trans **tpp, xfs_fileoff_t offset_fsb,
3262306a36Sopenharmony_ci		xfs_fileoff_t end_fsb, bool cancel_real);
3362306a36Sopenharmony_ciextern int xfs_reflink_cancel_cow_range(struct xfs_inode *ip, xfs_off_t offset,
3462306a36Sopenharmony_ci		xfs_off_t count, bool cancel_real);
3562306a36Sopenharmony_ciextern int xfs_reflink_end_cow(struct xfs_inode *ip, xfs_off_t offset,
3662306a36Sopenharmony_ci		xfs_off_t count);
3762306a36Sopenharmony_ciextern int xfs_reflink_recover_cow(struct xfs_mount *mp);
3862306a36Sopenharmony_ciextern loff_t xfs_reflink_remap_range(struct file *file_in, loff_t pos_in,
3962306a36Sopenharmony_ci		struct file *file_out, loff_t pos_out, loff_t len,
4062306a36Sopenharmony_ci		unsigned int remap_flags);
4162306a36Sopenharmony_ciextern int xfs_reflink_inode_has_shared_extents(struct xfs_trans *tp,
4262306a36Sopenharmony_ci		struct xfs_inode *ip, bool *has_shared);
4362306a36Sopenharmony_ciextern int xfs_reflink_clear_inode_flag(struct xfs_inode *ip,
4462306a36Sopenharmony_ci		struct xfs_trans **tpp);
4562306a36Sopenharmony_ciextern int xfs_reflink_unshare(struct xfs_inode *ip, xfs_off_t offset,
4662306a36Sopenharmony_ci		xfs_off_t len);
4762306a36Sopenharmony_ciextern int xfs_reflink_remap_prep(struct file *file_in, loff_t pos_in,
4862306a36Sopenharmony_ci		struct file *file_out, loff_t pos_out, loff_t *len,
4962306a36Sopenharmony_ci		unsigned int remap_flags);
5062306a36Sopenharmony_ciextern int xfs_reflink_remap_blocks(struct xfs_inode *src, loff_t pos_in,
5162306a36Sopenharmony_ci		struct xfs_inode *dest, loff_t pos_out, loff_t remap_len,
5262306a36Sopenharmony_ci		loff_t *remapped);
5362306a36Sopenharmony_ciextern int xfs_reflink_update_dest(struct xfs_inode *dest, xfs_off_t newlen,
5462306a36Sopenharmony_ci		xfs_extlen_t cowextsize, unsigned int remap_flags);
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci#endif /* __XFS_REFLINK_H */
57