file-item.h 2.9 KB

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