]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/dirent.h
Update bcachefs sources to 82c5cc8f00 bcachefs: Improve transaction restart handling...
[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 const char *bch2_dirent_invalid(const struct bch_fs *, struct bkey_s_c);
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_create(struct btree_trans *, subvol_inum,
33                        const struct bch_hash_info *, u8,
34                        const struct qstr *, u64, u64 *, int);
35
36 static inline unsigned vfs_d_type(unsigned type)
37 {
38         return type == DT_SUBVOL ? DT_DIR : type;
39 }
40
41 enum bch_rename_mode {
42         BCH_RENAME,
43         BCH_RENAME_OVERWRITE,
44         BCH_RENAME_EXCHANGE,
45 };
46
47 int bch2_dirent_rename(struct btree_trans *,
48                        subvol_inum, struct bch_hash_info *,
49                        subvol_inum, struct bch_hash_info *,
50                        const struct qstr *, subvol_inum *, u64 *,
51                        const struct qstr *, subvol_inum *, u64 *,
52                        enum bch_rename_mode);
53
54 int __bch2_dirent_lookup_trans(struct btree_trans *, struct btree_iter *,
55                                subvol_inum, const struct bch_hash_info *,
56                                const struct qstr *, subvol_inum *, unsigned);
57 u64 bch2_dirent_lookup(struct bch_fs *, subvol_inum,
58                        const struct bch_hash_info *,
59                        const struct qstr *, subvol_inum *);
60
61 int bch2_empty_dir_trans(struct btree_trans *, subvol_inum);
62 int bch2_readdir(struct bch_fs *, subvol_inum, struct dir_context *);
63
64 #endif /* _BCACHEFS_DIRENT_H */