xref: /openbmc/linux/fs/btrfs/inode-item.h (revision 829c6524)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef BTRFS_INODE_ITEM_H
4 #define BTRFS_INODE_ITEM_H
5 
6 #include <linux/types.h>
7 
8 struct btrfs_trans_handle;
9 struct btrfs_root;
10 struct btrfs_path;
11 struct btrfs_key;
12 struct btrfs_inode_extref;
13 struct btrfs_inode;
14 struct extent_buffer;
15 
16 /*
17  * Return this if we need to call truncate_block for the last bit of the
18  * truncate.
19  */
20 #define BTRFS_NEED_TRUNCATE_BLOCK		1
21 
22 struct btrfs_truncate_control {
23 	/*
24 	 * IN: the inode we're operating on, this can be NULL if
25 	 * ->clear_extent_range is false.
26 	 */
27 	struct btrfs_inode *inode;
28 
29 	/* IN: the size we're truncating to. */
30 	u64 new_size;
31 
32 	/* OUT: the number of extents truncated. */
33 	u64 extents_found;
34 
35 	/* OUT: the last size we truncated this inode to. */
36 	u64 last_size;
37 
38 	/* OUT: the number of bytes to sub from this inode. */
39 	u64 sub_bytes;
40 
41 	/* IN: the ino we are truncating. */
42 	u64 ino;
43 
44 	/*
45 	 * IN: minimum key type to remove.  All key types with this type are
46 	 * removed only if their offset >= new_size.
47 	 */
48 	u32 min_type;
49 
50 	/*
51 	 * IN: true if we don't want to do extent reference updates for any file
52 	 * extents we drop.
53 	 */
54 	bool skip_ref_updates;
55 
56 	/*
57 	 * IN: true if we need to clear the file extent range for the inode as
58 	 * we drop the file extent items.
59 	 */
60 	bool clear_extent_range;
61 };
62 
63 /*
64  * btrfs_inode_item stores flags in a u64, btrfs_inode stores them in two
65  * separate u32s. These two functions convert between the two representations.
66  */
67 static inline u64 btrfs_inode_combine_flags(u32 flags, u32 ro_flags)
68 {
69 	return (flags | ((u64)ro_flags << 32));
70 }
71 
72 static inline void btrfs_inode_split_flags(u64 inode_item_flags,
73 					   u32 *flags, u32 *ro_flags)
74 {
75 	*flags = (u32)inode_item_flags;
76 	*ro_flags = (u32)(inode_item_flags >> 32);
77 }
78 
79 int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
80 			       struct btrfs_root *root,
81 			       struct btrfs_truncate_control *control);
82 int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
83 			   struct btrfs_root *root, const struct fscrypt_str *name,
84 			   u64 inode_objectid, u64 ref_objectid, u64 index);
85 int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
86 			struct btrfs_root *root, const struct fscrypt_str *name,
87 			u64 inode_objectid, u64 ref_objectid, u64 *index);
88 int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
89 			     struct btrfs_root *root,
90 			     struct btrfs_path *path, u64 objectid);
91 int btrfs_lookup_inode(struct btrfs_trans_handle *trans,
92 		       struct btrfs_root *root, struct btrfs_path *path,
93 		       struct btrfs_key *location, int mod);
94 
95 struct btrfs_inode_extref *btrfs_lookup_inode_extref(
96 			  struct btrfs_trans_handle *trans,
97 			  struct btrfs_root *root,
98 			  struct btrfs_path *path,
99 			  const struct fscrypt_str *name,
100 			  u64 inode_objectid, u64 ref_objectid, int ins_len,
101 			  int cow);
102 
103 struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
104 						   int slot,
105 						   const struct fscrypt_str *name);
106 struct btrfs_inode_extref *btrfs_find_name_in_ext_backref(
107 		struct extent_buffer *leaf, int slot, u64 ref_objectid,
108 		const struct fscrypt_str *name);
109 
110 #endif
111