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