1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_FS_IOCTL_H
3 #define _BCACHEFS_FS_IOCTL_H
4
5 /* Inode flags: */
6
7 /* bcachefs inode flags -> vfs inode flags: */
8 static const __maybe_unused unsigned bch_flags_to_vfs[] = {
9 [__BCH_INODE_sync] = S_SYNC,
10 [__BCH_INODE_immutable] = S_IMMUTABLE,
11 [__BCH_INODE_append] = S_APPEND,
12 [__BCH_INODE_noatime] = S_NOATIME,
13 [__BCH_INODE_casefolded] = S_CASEFOLD,
14 };
15
16 /* bcachefs inode flags -> FS_IOC_GETFLAGS: */
17 static const __maybe_unused unsigned bch_flags_to_uflags[] = {
18 [__BCH_INODE_sync] = FS_SYNC_FL,
19 [__BCH_INODE_immutable] = FS_IMMUTABLE_FL,
20 [__BCH_INODE_append] = FS_APPEND_FL,
21 [__BCH_INODE_nodump] = FS_NODUMP_FL,
22 [__BCH_INODE_noatime] = FS_NOATIME_FL,
23 [__BCH_INODE_casefolded] = FS_CASEFOLD_FL,
24 };
25
26 /* bcachefs inode flags -> FS_IOC_FSGETXATTR: */
27 static const __maybe_unused unsigned bch_flags_to_xflags[] = {
28 [__BCH_INODE_sync] = FS_XFLAG_SYNC,
29 [__BCH_INODE_immutable] = FS_XFLAG_IMMUTABLE,
30 [__BCH_INODE_append] = FS_XFLAG_APPEND,
31 [__BCH_INODE_nodump] = FS_XFLAG_NODUMP,
32 [__BCH_INODE_noatime] = FS_XFLAG_NOATIME,
33 //[__BCH_INODE_PROJINHERIT] = FS_XFLAG_PROJINHERIT;
34 };
35
36 #define set_flags(_map, _in, _out) \
37 do { \
38 unsigned _i; \
39 \
40 for (_i = 0; _i < ARRAY_SIZE(_map); _i++) \
41 if ((_in) & (1 << _i)) \
42 (_out) |= _map[_i]; \
43 else \
44 (_out) &= ~_map[_i]; \
45 } while (0)
46
47 #define map_flags(_map, _in) \
48 ({ \
49 unsigned _out = 0; \
50 \
51 set_flags(_map, _in, _out); \
52 _out; \
53 })
54
55 #define map_flags_rev(_map, _in) \
56 ({ \
57 unsigned _i, _out = 0; \
58 \
59 for (_i = 0; _i < ARRAY_SIZE(_map); _i++) \
60 if ((_in) & _map[_i]) { \
61 (_out) |= 1 << _i; \
62 (_in) &= ~_map[_i]; \
63 } \
64 (_out); \
65 })
66
67 #define map_defined(_map) \
68 ({ \
69 unsigned _in = ~0; \
70 \
71 map_flags_rev(_map, _in); \
72 })
73
74 /* Set VFS inode flags from bcachefs inode: */
bch2_inode_flags_to_vfs(struct bch_inode_info * inode)75 static inline void bch2_inode_flags_to_vfs(struct bch_inode_info *inode)
76 {
77 set_flags(bch_flags_to_vfs, inode->ei_inode.bi_flags, inode->v.i_flags);
78 }
79
80 long bch2_fs_file_ioctl(struct file *, unsigned, unsigned long);
81 long bch2_compat_fs_ioctl(struct file *, unsigned, unsigned long);
82
83 #endif /* _BCACHEFS_FS_IOCTL_H */
84