]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/dirent.h
Update bcachefs sources to fd381c355c bcachefs: Fix a null ptr deref in fsck check_ex...
[bcachefs-tools-debian] / libbcachefs / dirent.h
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_invalid(const struct bch_fs *, struct bkey_s_c, unsigned, struct printbuf *);
10 void bch2_dirent_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
11
12 #define bch2_bkey_ops_dirent ((struct bkey_ops) {       \
13         .key_invalid    = bch2_dirent_invalid,          \
14         .val_to_text    = bch2_dirent_to_text,          \
15 })
16
17 struct qstr;
18 struct file;
19 struct dir_context;
20 struct bch_fs;
21 struct bch_hash_info;
22 struct bch_inode_info;
23
24 unsigned bch2_dirent_name_bytes(struct bkey_s_c_dirent);
25
26 static inline unsigned dirent_val_u64s(unsigned len)
27 {
28         return DIV_ROUND_UP(offsetof(struct bch_dirent, d_name) + len,
29                             sizeof(u64));
30 }
31
32 int bch2_dirent_read_target(struct btree_trans *, subvol_inum,
33                             struct bkey_s_c_dirent, subvol_inum *);
34
35 int bch2_dirent_create(struct btree_trans *, subvol_inum,
36                        const struct bch_hash_info *, u8,
37                        const struct qstr *, u64, u64 *, int);
38
39 static inline unsigned vfs_d_type(unsigned type)
40 {
41         return type == DT_SUBVOL ? DT_DIR : type;
42 }
43
44 enum bch_rename_mode {
45         BCH_RENAME,
46         BCH_RENAME_OVERWRITE,
47         BCH_RENAME_EXCHANGE,
48 };
49
50 int bch2_dirent_rename(struct btree_trans *,
51                        subvol_inum, struct bch_hash_info *,
52                        subvol_inum, struct bch_hash_info *,
53                        const struct qstr *, subvol_inum *, u64 *,
54                        const struct qstr *, subvol_inum *, u64 *,
55                        enum bch_rename_mode);
56
57 int __bch2_dirent_lookup_trans(struct btree_trans *, struct btree_iter *,
58                                subvol_inum, const struct bch_hash_info *,
59                                const struct qstr *, subvol_inum *, unsigned);
60 u64 bch2_dirent_lookup(struct bch_fs *, subvol_inum,
61                        const struct bch_hash_info *,
62                        const struct qstr *, subvol_inum *);
63
64 int bch2_empty_dir_trans(struct btree_trans *, subvol_inum);
65 int bch2_readdir(struct bch_fs *, subvol_inum, struct dir_context *);
66
67 #endif /* _BCACHEFS_DIRENT_H */