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