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 
47 int __bch2_check_dirent_target(struct btree_trans *,
48 			       struct btree_iter *,
49 			       struct bkey_s_c_dirent,
50 			       struct bch_inode_unpacked *, bool);
51 
inode_points_to_dirent(struct bch_inode_unpacked * inode,struct bkey_s_c_dirent d)52 static inline bool inode_points_to_dirent(struct bch_inode_unpacked *inode,
53 					  struct bkey_s_c_dirent d)
54 {
55 	return  inode->bi_dir		== d.k->p.inode &&
56 		inode->bi_dir_offset	== d.k->p.offset;
57 }
58 
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)59 static inline int bch2_check_dirent_target(struct btree_trans *trans,
60 					   struct btree_iter *dirent_iter,
61 					   struct bkey_s_c_dirent d,
62 					   struct bch_inode_unpacked *target,
63 					   bool in_fsck)
64 {
65 	if (likely(inode_points_to_dirent(target, d) &&
66 		   d.v->d_type == inode_d_type(target)))
67 		return 0;
68 
69 	return __bch2_check_dirent_target(trans, dirent_iter, d, target, in_fsck);
70 }
71 
72 #endif /* _BCACHEFS_NAMEI_H */
73