1/* SPDX-License-Identifier: GPL-2.0 */ 2 3#ifndef BTRFS_FILE_ITEM_H 4#define BTRFS_FILE_ITEM_H 5 6#include <linux/list.h> 7#include <uapi/linux/btrfs_tree.h> 8#include "accessors.h" 9 10struct extent_map; 11struct btrfs_file_extent_item; 12struct btrfs_fs_info; 13struct btrfs_path; 14struct btrfs_bio; 15struct btrfs_trans_handle; 16struct btrfs_root; 17struct btrfs_ordered_sum; 18struct btrfs_path; 19struct btrfs_inode; 20 21#define BTRFS_FILE_EXTENT_INLINE_DATA_START \ 22 (offsetof(struct btrfs_file_extent_item, disk_bytenr)) 23 24static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info *info) 25{ 26 return BTRFS_MAX_ITEM_SIZE(info) - BTRFS_FILE_EXTENT_INLINE_DATA_START; 27} 28 29/* 30 * Return the number of bytes used by the item on disk, minus the size of any 31 * extent headers. If a file is compressed on disk, this is the compressed 32 * size. 33 */ 34static inline u32 btrfs_file_extent_inline_item_len( 35 const struct extent_buffer *eb, 36 int nr) 37{ 38 return btrfs_item_size(eb, nr) - BTRFS_FILE_EXTENT_INLINE_DATA_START; 39} 40 41static inline unsigned long btrfs_file_extent_inline_start( 42 const struct btrfs_file_extent_item *e) 43{ 44 return (unsigned long)e + BTRFS_FILE_EXTENT_INLINE_DATA_START; 45} 46 47static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize) 48{ 49 return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize; 50} 51 52int btrfs_del_csums(struct btrfs_trans_handle *trans, 53 struct btrfs_root *root, u64 bytenr, u64 len); 54blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio); 55int btrfs_insert_hole_extent(struct btrfs_trans_handle *trans, 56 struct btrfs_root *root, u64 objectid, u64 pos, 57 u64 num_bytes); 58int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, 59 struct btrfs_root *root, 60 struct btrfs_path *path, u64 objectid, 61 u64 bytenr, int mod); 62int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, 63 struct btrfs_root *root, 64 struct btrfs_ordered_sum *sums); 65blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio); 66blk_status_t btrfs_alloc_dummy_sum(struct btrfs_bio *bbio); 67int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, 68 struct list_head *list, int search_commit, 69 bool nowait); 70int btrfs_lookup_csums_list(struct btrfs_root *root, u64 start, u64 end, 71 struct list_head *list, int search_commit, 72 bool nowait); 73int btrfs_lookup_csums_bitmap(struct btrfs_root *root, struct btrfs_path *path, 74 u64 start, u64 end, u8 *csum_buf, 75 unsigned long *csum_bitmap); 76void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode, 77 const struct btrfs_path *path, 78 struct btrfs_file_extent_item *fi, 79 struct extent_map *em); 80int btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start, 81 u64 len); 82int btrfs_inode_set_file_extent_range(struct btrfs_inode *inode, u64 start, u64 len); 83void btrfs_inode_safe_disk_i_size_write(struct btrfs_inode *inode, u64 new_i_size); 84u64 btrfs_file_extent_end(const struct btrfs_path *path); 85 86#endif 87