1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _BCACHEFS_DIRENT_H 3 #define _BCACHEFS_DIRENT_H 4 5 #include "str_hash.h" 6 7 extern const struct bch_hash_desc bch2_dirent_hash_desc; 8 9 int bch2_dirent_validate(struct bch_fs *, struct bkey_s_c, 10 struct bkey_validate_context); 11 void bch2_dirent_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c); 12 13 #define bch2_bkey_ops_dirent ((struct bkey_ops) { \ 14 .key_validate = bch2_dirent_validate, \ 15 .val_to_text = bch2_dirent_to_text, \ 16 .min_val_size = 16, \ 17 }) 18 19 struct qstr; 20 struct file; 21 struct dir_context; 22 struct bch_fs; 23 struct bch_hash_info; 24 struct bch_inode_info; 25 26 int bch2_casefold(struct btree_trans *, const struct bch_hash_info *, 27 const struct qstr *, struct qstr *); 28 29 static inline int bch2_maybe_casefold(struct btree_trans *trans, 30 const struct bch_hash_info *info, 31 const struct qstr *str, struct qstr *out_cf) 32 { 33 if (likely(!info->cf_encoding)) { 34 *out_cf = *str; 35 return 0; 36 } else { 37 return bch2_casefold(trans, info, str, out_cf); 38 } 39 } 40 41 struct qstr bch2_dirent_get_name(struct bkey_s_c_dirent d); 42 43 static inline unsigned dirent_val_u64s(unsigned len, unsigned cf_len) 44 { 45 unsigned bytes = cf_len 46 ? offsetof(struct bch_dirent, d_cf_name_block.d_names) + len + cf_len 47 : offsetof(struct bch_dirent, d_name) + len; 48 49 return DIV_ROUND_UP(bytes, sizeof(u64)); 50 } 51 52 int bch2_dirent_read_target(struct btree_trans *, subvol_inum, 53 struct bkey_s_c_dirent, subvol_inum *); 54 55 static inline void dirent_copy_target(struct bkey_i_dirent *dst, 56 struct bkey_s_c_dirent src) 57 { 58 dst->v.d_inum = src.v->d_inum; 59 dst->v.d_type = src.v->d_type; 60 } 61 62 int bch2_dirent_create_snapshot(struct btree_trans *, u32, u64, u32, 63 const struct bch_hash_info *, u8, 64 const struct qstr *, u64, u64 *, 65 enum btree_iter_update_trigger_flags); 66 int bch2_dirent_create(struct btree_trans *, subvol_inum, 67 const struct bch_hash_info *, u8, 68 const struct qstr *, u64, u64 *, 69 enum btree_iter_update_trigger_flags); 70 71 static inline unsigned vfs_d_type(unsigned type) 72 { 73 return type == DT_SUBVOL ? DT_DIR : type; 74 } 75 76 enum bch_rename_mode { 77 BCH_RENAME, 78 BCH_RENAME_OVERWRITE, 79 BCH_RENAME_EXCHANGE, 80 }; 81 82 int bch2_dirent_rename(struct btree_trans *, 83 subvol_inum, struct bch_hash_info *, u64 *, 84 subvol_inum, struct bch_hash_info *, u64 *, 85 const struct qstr *, subvol_inum *, u64 *, 86 const struct qstr *, subvol_inum *, u64 *, 87 enum bch_rename_mode); 88 89 int bch2_dirent_lookup_trans(struct btree_trans *, struct btree_iter *, 90 subvol_inum, const struct bch_hash_info *, 91 const struct qstr *, subvol_inum *, unsigned); 92 u64 bch2_dirent_lookup(struct bch_fs *, subvol_inum, 93 const struct bch_hash_info *, 94 const struct qstr *, subvol_inum *); 95 96 int bch2_empty_dir_snapshot(struct btree_trans *, u64, u32, u32); 97 int bch2_empty_dir_trans(struct btree_trans *, subvol_inum); 98 int bch2_readdir(struct bch_fs *, subvol_inum, struct dir_context *); 99 100 int bch2_fsck_remove_dirent(struct btree_trans *, struct bpos); 101 102 #endif /* _BCACHEFS_DIRENT_H */ 103