xref: /linux/fs/bcachefs/namei.h (revision 4ba99dde330b2d4b6de65f27ced60e7f0fbc21c2)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_NAMEI_H
3 #define _BCACHEFS_NAMEI_H
4 
5 #include "dirent.h"
6 
7 struct posix_acl;
8 
9 #define BCH_CREATE_TMPFILE		(1U << 0)
10 #define BCH_CREATE_SUBVOL		(1U << 1)
11 #define BCH_CREATE_SNAPSHOT		(1U << 2)
12 #define BCH_CREATE_SNAPSHOT_RO		(1U << 3)
13 
14 int bch2_create_trans(struct btree_trans *, subvol_inum,
15 		      struct bch_inode_unpacked *,
16 		      struct bch_inode_unpacked *,
17 		      const struct qstr *,
18 		      uid_t, gid_t, umode_t, dev_t,
19 		      struct posix_acl *,
20 		      struct posix_acl *,
21 		      subvol_inum, unsigned);
22 
23 int bch2_link_trans(struct btree_trans *,
24 		    subvol_inum, struct bch_inode_unpacked *,
25 		    subvol_inum, struct bch_inode_unpacked *,
26 		    const struct qstr *);
27 
28 int bch2_unlink_trans(struct btree_trans *, subvol_inum,
29 		      struct bch_inode_unpacked *,
30 		      struct bch_inode_unpacked *,
31 		      const struct qstr *, bool);
32 
33 int bch2_rename_trans(struct btree_trans *,
34 		      subvol_inum, struct bch_inode_unpacked *,
35 		      subvol_inum, struct bch_inode_unpacked *,
36 		      struct bch_inode_unpacked *,
37 		      struct bch_inode_unpacked *,
38 		      const struct qstr *,
39 		      const struct qstr *,
40 		      enum bch_rename_mode);
41 
42 bool bch2_reinherit_attrs(struct bch_inode_unpacked *,
43 			  struct bch_inode_unpacked *);
44 
45 int bch2_inum_to_path(struct btree_trans *, subvol_inum, struct printbuf *);
46 int bch2_inum_snapshot_to_path(struct btree_trans *, u64, u32,
47 			       snapshot_id_list *, struct printbuf *);
48 
49 int __bch2_check_dirent_target(struct btree_trans *,
50 			       struct btree_iter *,
51 			       struct bkey_s_c_dirent,
52 			       struct bch_inode_unpacked *, bool);
53 
inode_points_to_dirent(struct bch_inode_unpacked * inode,struct bkey_s_c_dirent d)54 static inline bool inode_points_to_dirent(struct bch_inode_unpacked *inode,
55 					  struct bkey_s_c_dirent d)
56 {
57 	return  inode->bi_dir		== d.k->p.inode &&
58 		inode->bi_dir_offset	== d.k->p.offset;
59 }
60 
bch2_check_dirent_target(struct btree_trans * trans,struct btree_iter * dirent_iter,struct bkey_s_c_dirent d,struct bch_inode_unpacked * target,bool in_fsck)61 static inline int bch2_check_dirent_target(struct btree_trans *trans,
62 					   struct btree_iter *dirent_iter,
63 					   struct bkey_s_c_dirent d,
64 					   struct bch_inode_unpacked *target,
65 					   bool in_fsck)
66 {
67 	if (likely(inode_points_to_dirent(target, d) &&
68 		   d.v->d_type == inode_d_type(target)))
69 		return 0;
70 
71 	return __bch2_check_dirent_target(trans, dirent_iter, d, target, in_fsck);
72 }
73 
74 int bch2_maybe_propagate_has_case_insensitive(struct btree_trans *, subvol_inum,
75 					      struct bch_inode_unpacked *);
76 int bch2_check_inode_has_case_insensitive(struct btree_trans *, struct bch_inode_unpacked *,
77 					  snapshot_id_list *, bool *);
78 
79 #endif /* _BCACHEFS_NAMEI_H */
80