xref: /linux/fs/bcachefs/inode_format.h (revision c1e822754cc7f28b98c6897d62e8b47b4001e422)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_INODE_FORMAT_H
3 #define _BCACHEFS_INODE_FORMAT_H
4 
5 #define BLOCKDEV_INODE_MAX	4096
6 #define BCACHEFS_ROOT_INO	4096
7 
8 struct bch_inode {
9 	struct bch_val		v;
10 
11 	__le64			bi_hash_seed;
12 	__le32			bi_flags;
13 	__le16			bi_mode;
14 	__u8			fields[];
15 } __packed __aligned(8);
16 
17 struct bch_inode_v2 {
18 	struct bch_val		v;
19 
20 	__le64			bi_journal_seq;
21 	__le64			bi_hash_seed;
22 	__le64			bi_flags;
23 	__le16			bi_mode;
24 	__u8			fields[];
25 } __packed __aligned(8);
26 
27 struct bch_inode_v3 {
28 	struct bch_val		v;
29 
30 	__le64			bi_journal_seq;
31 	__le64			bi_hash_seed;
32 	__le64			bi_flags;
33 	__le64			bi_sectors;
34 	__le64			bi_size;
35 	__le64			bi_version;
36 	__u8			fields[];
37 } __packed __aligned(8);
38 
39 #define INODEv3_FIELDS_START_INITIAL	6
40 #define INODEv3_FIELDS_START_CUR	(offsetof(struct bch_inode_v3, fields) / sizeof(__u64))
41 
42 struct bch_inode_generation {
43 	struct bch_val		v;
44 
45 	__le32			bi_generation;
46 	__le32			pad;
47 } __packed __aligned(8);
48 
49 /*
50  * bi_subvol and bi_parent_subvol are only set for subvolume roots:
51  */
52 
53 #define BCH_INODE_FIELDS_v2()			\
54 	x(bi_atime,			96)	\
55 	x(bi_ctime,			96)	\
56 	x(bi_mtime,			96)	\
57 	x(bi_otime,			96)	\
58 	x(bi_size,			64)	\
59 	x(bi_sectors,			64)	\
60 	x(bi_uid,			32)	\
61 	x(bi_gid,			32)	\
62 	x(bi_nlink,			32)	\
63 	x(bi_generation,		32)	\
64 	x(bi_dev,			32)	\
65 	x(bi_data_checksum,		8)	\
66 	x(bi_compression,		8)	\
67 	x(bi_project,			32)	\
68 	x(bi_background_compression,	8)	\
69 	x(bi_data_replicas,		8)	\
70 	x(bi_promote_target,		16)	\
71 	x(bi_foreground_target,		16)	\
72 	x(bi_background_target,		16)	\
73 	x(bi_erasure_code,		16)	\
74 	x(bi_fields_set,		16)	\
75 	x(bi_dir,			64)	\
76 	x(bi_dir_offset,		64)	\
77 	x(bi_subvol,			32)	\
78 	x(bi_parent_subvol,		32)
79 
80 #define BCH_INODE_FIELDS_v3()			\
81 	x(bi_atime,			96)	\
82 	x(bi_ctime,			96)	\
83 	x(bi_mtime,			96)	\
84 	x(bi_otime,			96)	\
85 	x(bi_uid,			32)	\
86 	x(bi_gid,			32)	\
87 	x(bi_nlink,			32)	\
88 	x(bi_generation,		32)	\
89 	x(bi_dev,			32)	\
90 	x(bi_data_checksum,		8)	\
91 	x(bi_compression,		8)	\
92 	x(bi_project,			32)	\
93 	x(bi_background_compression,	8)	\
94 	x(bi_data_replicas,		8)	\
95 	x(bi_promote_target,		16)	\
96 	x(bi_foreground_target,		16)	\
97 	x(bi_background_target,		16)	\
98 	x(bi_erasure_code,		16)	\
99 	x(bi_fields_set,		16)	\
100 	x(bi_dir,			64)	\
101 	x(bi_dir_offset,		64)	\
102 	x(bi_subvol,			32)	\
103 	x(bi_parent_subvol,		32)	\
104 	x(bi_nocow,			8)
105 
106 /* subset of BCH_INODE_FIELDS */
107 #define BCH_INODE_OPTS()			\
108 	x(data_checksum,		8)	\
109 	x(compression,			8)	\
110 	x(project,			32)	\
111 	x(background_compression,	8)	\
112 	x(data_replicas,		8)	\
113 	x(promote_target,		16)	\
114 	x(foreground_target,		16)	\
115 	x(background_target,		16)	\
116 	x(erasure_code,			16)	\
117 	x(nocow,			8)
118 
119 enum inode_opt_id {
120 #define x(name, ...)				\
121 	Inode_opt_##name,
122 	BCH_INODE_OPTS()
123 #undef  x
124 	Inode_opt_nr,
125 };
126 
127 #define BCH_INODE_FLAGS()			\
128 	x(sync,				0)	\
129 	x(immutable,			1)	\
130 	x(append,			2)	\
131 	x(nodump,			3)	\
132 	x(noatime,			4)	\
133 	x(i_size_dirty,			5)	\
134 	x(i_sectors_dirty,		6)	\
135 	x(unlinked,			7)	\
136 	x(backptr_untrusted,		8)	\
137 	x(has_child_snapshot,		9)
138 
139 /* bits 20+ reserved for packed fields below: */
140 
141 enum bch_inode_flags {
142 #define x(t, n)	BCH_INODE_##t = 1U << n,
143 	BCH_INODE_FLAGS()
144 #undef x
145 };
146 
147 enum __bch_inode_flags {
148 #define x(t, n)	__BCH_INODE_##t = n,
149 	BCH_INODE_FLAGS()
150 #undef x
151 };
152 
153 LE32_BITMASK(INODEv1_STR_HASH,	struct bch_inode, bi_flags, 20, 24);
154 LE32_BITMASK(INODEv1_NR_FIELDS,	struct bch_inode, bi_flags, 24, 31);
155 LE32_BITMASK(INODEv1_NEW_VARINT,struct bch_inode, bi_flags, 31, 32);
156 
157 LE64_BITMASK(INODEv2_STR_HASH,	struct bch_inode_v2, bi_flags, 20, 24);
158 LE64_BITMASK(INODEv2_NR_FIELDS,	struct bch_inode_v2, bi_flags, 24, 31);
159 
160 LE64_BITMASK(INODEv3_STR_HASH,	struct bch_inode_v3, bi_flags, 20, 24);
161 LE64_BITMASK(INODEv3_NR_FIELDS,	struct bch_inode_v3, bi_flags, 24, 31);
162 
163 LE64_BITMASK(INODEv3_FIELDS_START,
164 				struct bch_inode_v3, bi_flags, 31, 36);
165 LE64_BITMASK(INODEv3_MODE,	struct bch_inode_v3, bi_flags, 36, 52);
166 
167 #endif /* _BCACHEFS_INODE_FORMAT_H */
168