162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci#ifndef BTRFS_INODE_ITEM_H
462306a36Sopenharmony_ci#define BTRFS_INODE_ITEM_H
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#include <linux/types.h>
762306a36Sopenharmony_ci
862306a36Sopenharmony_cistruct btrfs_trans_handle;
962306a36Sopenharmony_cistruct btrfs_root;
1062306a36Sopenharmony_cistruct btrfs_path;
1162306a36Sopenharmony_cistruct btrfs_key;
1262306a36Sopenharmony_cistruct btrfs_inode_extref;
1362306a36Sopenharmony_cistruct btrfs_inode;
1462306a36Sopenharmony_cistruct extent_buffer;
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci/*
1762306a36Sopenharmony_ci * Return this if we need to call truncate_block for the last bit of the
1862306a36Sopenharmony_ci * truncate.
1962306a36Sopenharmony_ci */
2062306a36Sopenharmony_ci#define BTRFS_NEED_TRUNCATE_BLOCK		1
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_cistruct btrfs_truncate_control {
2362306a36Sopenharmony_ci	/*
2462306a36Sopenharmony_ci	 * IN: the inode we're operating on, this can be NULL if
2562306a36Sopenharmony_ci	 * ->clear_extent_range is false.
2662306a36Sopenharmony_ci	 */
2762306a36Sopenharmony_ci	struct btrfs_inode *inode;
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci	/* IN: the size we're truncating to. */
3062306a36Sopenharmony_ci	u64 new_size;
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci	/* OUT: the number of extents truncated. */
3362306a36Sopenharmony_ci	u64 extents_found;
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci	/* OUT: the last size we truncated this inode to. */
3662306a36Sopenharmony_ci	u64 last_size;
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci	/* OUT: the number of bytes to sub from this inode. */
3962306a36Sopenharmony_ci	u64 sub_bytes;
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci	/* IN: the ino we are truncating. */
4262306a36Sopenharmony_ci	u64 ino;
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci	/*
4562306a36Sopenharmony_ci	 * IN: minimum key type to remove.  All key types with this type are
4662306a36Sopenharmony_ci	 * removed only if their offset >= new_size.
4762306a36Sopenharmony_ci	 */
4862306a36Sopenharmony_ci	u32 min_type;
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci	/*
5162306a36Sopenharmony_ci	 * IN: true if we don't want to do extent reference updates for any file
5262306a36Sopenharmony_ci	 * extents we drop.
5362306a36Sopenharmony_ci	 */
5462306a36Sopenharmony_ci	bool skip_ref_updates;
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci	/*
5762306a36Sopenharmony_ci	 * IN: true if we need to clear the file extent range for the inode as
5862306a36Sopenharmony_ci	 * we drop the file extent items.
5962306a36Sopenharmony_ci	 */
6062306a36Sopenharmony_ci	bool clear_extent_range;
6162306a36Sopenharmony_ci};
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci/*
6462306a36Sopenharmony_ci * btrfs_inode_item stores flags in a u64, btrfs_inode stores them in two
6562306a36Sopenharmony_ci * separate u32s. These two functions convert between the two representations.
6662306a36Sopenharmony_ci */
6762306a36Sopenharmony_cistatic inline u64 btrfs_inode_combine_flags(u32 flags, u32 ro_flags)
6862306a36Sopenharmony_ci{
6962306a36Sopenharmony_ci	return (flags | ((u64)ro_flags << 32));
7062306a36Sopenharmony_ci}
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_cistatic inline void btrfs_inode_split_flags(u64 inode_item_flags,
7362306a36Sopenharmony_ci					   u32 *flags, u32 *ro_flags)
7462306a36Sopenharmony_ci{
7562306a36Sopenharmony_ci	*flags = (u32)inode_item_flags;
7662306a36Sopenharmony_ci	*ro_flags = (u32)(inode_item_flags >> 32);
7762306a36Sopenharmony_ci}
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ciint btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
8062306a36Sopenharmony_ci			       struct btrfs_root *root,
8162306a36Sopenharmony_ci			       struct btrfs_truncate_control *control);
8262306a36Sopenharmony_ciint btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
8362306a36Sopenharmony_ci			   struct btrfs_root *root, const struct fscrypt_str *name,
8462306a36Sopenharmony_ci			   u64 inode_objectid, u64 ref_objectid, u64 index);
8562306a36Sopenharmony_ciint btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
8662306a36Sopenharmony_ci			struct btrfs_root *root, const struct fscrypt_str *name,
8762306a36Sopenharmony_ci			u64 inode_objectid, u64 ref_objectid, u64 *index);
8862306a36Sopenharmony_ciint btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
8962306a36Sopenharmony_ci			     struct btrfs_root *root,
9062306a36Sopenharmony_ci			     struct btrfs_path *path, u64 objectid);
9162306a36Sopenharmony_ciint btrfs_lookup_inode(struct btrfs_trans_handle *trans,
9262306a36Sopenharmony_ci		       struct btrfs_root *root, struct btrfs_path *path,
9362306a36Sopenharmony_ci		       struct btrfs_key *location, int mod);
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_cistruct btrfs_inode_extref *btrfs_lookup_inode_extref(
9662306a36Sopenharmony_ci			  struct btrfs_trans_handle *trans,
9762306a36Sopenharmony_ci			  struct btrfs_root *root,
9862306a36Sopenharmony_ci			  struct btrfs_path *path,
9962306a36Sopenharmony_ci			  const struct fscrypt_str *name,
10062306a36Sopenharmony_ci			  u64 inode_objectid, u64 ref_objectid, int ins_len,
10162306a36Sopenharmony_ci			  int cow);
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_cistruct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
10462306a36Sopenharmony_ci						   int slot,
10562306a36Sopenharmony_ci						   const struct fscrypt_str *name);
10662306a36Sopenharmony_cistruct btrfs_inode_extref *btrfs_find_name_in_ext_backref(
10762306a36Sopenharmony_ci		struct extent_buffer *leaf, int slot, u64 ref_objectid,
10862306a36Sopenharmony_ci		const struct fscrypt_str *name);
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci#endif
111