inode-item.h 3.3 KB

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