17c8ede16SJosef Bacik /* SPDX-License-Identifier: GPL-2.0 */
27c8ede16SJosef Bacik
37c8ede16SJosef Bacik #ifndef BTRFS_FILE_ITEM_H
47c8ede16SJosef Bacik #define BTRFS_FILE_ITEM_H
57c8ede16SJosef Bacik
66bfd0ffaSJosef Bacik #include "accessors.h"
76bfd0ffaSJosef Bacik
86bfd0ffaSJosef Bacik #define BTRFS_FILE_EXTENT_INLINE_DATA_START \
96bfd0ffaSJosef Bacik (offsetof(struct btrfs_file_extent_item, disk_bytenr))
106bfd0ffaSJosef Bacik
BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info * info)116bfd0ffaSJosef Bacik static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info *info)
126bfd0ffaSJosef Bacik {
136bfd0ffaSJosef Bacik return BTRFS_MAX_ITEM_SIZE(info) - BTRFS_FILE_EXTENT_INLINE_DATA_START;
146bfd0ffaSJosef Bacik }
156bfd0ffaSJosef Bacik
166bfd0ffaSJosef Bacik /*
176bfd0ffaSJosef Bacik * Return the number of bytes used by the item on disk, minus the size of any
186bfd0ffaSJosef Bacik * extent headers. If a file is compressed on disk, this is the compressed
196bfd0ffaSJosef Bacik * size.
206bfd0ffaSJosef Bacik */
btrfs_file_extent_inline_item_len(const struct extent_buffer * eb,int nr)216bfd0ffaSJosef Bacik static inline u32 btrfs_file_extent_inline_item_len(
226bfd0ffaSJosef Bacik const struct extent_buffer *eb,
236bfd0ffaSJosef Bacik int nr)
246bfd0ffaSJosef Bacik {
256bfd0ffaSJosef Bacik return btrfs_item_size(eb, nr) - BTRFS_FILE_EXTENT_INLINE_DATA_START;
266bfd0ffaSJosef Bacik }
276bfd0ffaSJosef Bacik
btrfs_file_extent_inline_start(const struct btrfs_file_extent_item * e)286bfd0ffaSJosef Bacik static inline unsigned long btrfs_file_extent_inline_start(
296bfd0ffaSJosef Bacik const struct btrfs_file_extent_item *e)
306bfd0ffaSJosef Bacik {
316bfd0ffaSJosef Bacik return (unsigned long)e + BTRFS_FILE_EXTENT_INLINE_DATA_START;
326bfd0ffaSJosef Bacik }
336bfd0ffaSJosef Bacik
btrfs_file_extent_calc_inline_size(u32 datasize)346bfd0ffaSJosef Bacik static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
356bfd0ffaSJosef Bacik {
366bfd0ffaSJosef Bacik return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize;
376bfd0ffaSJosef Bacik }
386bfd0ffaSJosef Bacik
397c8ede16SJosef Bacik int btrfs_del_csums(struct btrfs_trans_handle *trans,
407c8ede16SJosef Bacik struct btrfs_root *root, u64 bytenr, u64 len);
414ae2edf1SChristoph Hellwig blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio);
427c8ede16SJosef Bacik int btrfs_insert_hole_extent(struct btrfs_trans_handle *trans,
437c8ede16SJosef Bacik struct btrfs_root *root, u64 objectid, u64 pos,
447c8ede16SJosef Bacik u64 num_bytes);
457c8ede16SJosef Bacik int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
467c8ede16SJosef Bacik struct btrfs_root *root,
477c8ede16SJosef Bacik struct btrfs_path *path, u64 objectid,
487c8ede16SJosef Bacik u64 bytenr, int mod);
497c8ede16SJosef Bacik int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
507c8ede16SJosef Bacik struct btrfs_root *root,
517c8ede16SJosef Bacik struct btrfs_ordered_sum *sums);
52f8c44673SChristoph Hellwig blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio);
53cbfce4c7SChristoph Hellwig blk_status_t btrfs_alloc_dummy_sum(struct btrfs_bio *bbio);
54f8c44673SChristoph Hellwig int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
55f8c44673SChristoph Hellwig struct list_head *list, int search_commit,
56f8c44673SChristoph Hellwig bool nowait);
5797e38239SQu Wenruo int btrfs_lookup_csums_list(struct btrfs_root *root, u64 start, u64 end,
587c8ede16SJosef Bacik struct list_head *list, int search_commit,
597c8ede16SJosef Bacik bool nowait);
60*3c771c19SQu Wenruo int btrfs_lookup_csums_bitmap(struct btrfs_root *root, struct btrfs_path *path,
61*3c771c19SQu Wenruo u64 start, u64 end, u8 *csum_buf,
62*3c771c19SQu Wenruo unsigned long *csum_bitmap);
637c8ede16SJosef Bacik void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
647c8ede16SJosef Bacik const struct btrfs_path *path,
657c8ede16SJosef Bacik struct btrfs_file_extent_item *fi,
667c8ede16SJosef Bacik struct extent_map *em);
677c8ede16SJosef Bacik int btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start,
687c8ede16SJosef Bacik u64 len);
697c8ede16SJosef Bacik int btrfs_inode_set_file_extent_range(struct btrfs_inode *inode, u64 start, u64 len);
707c8ede16SJosef Bacik void btrfs_inode_safe_disk_i_size_write(struct btrfs_inode *inode, u64 new_i_size);
717c8ede16SJosef Bacik u64 btrfs_file_extent_end(const struct btrfs_path *path);
727c8ede16SJosef Bacik
737c8ede16SJosef Bacik #endif
74