1 /*
2 * This header was generated from the Linux kernel headers by update_headers.py,
3 * to provide necessary information from kernel to userspace, such as constants,
4 * structures, and macros, and thus, contains no copyrightable information.
5 */
6 #ifndef _LINUX_NILFS2_ONDISK_H
7 #define _LINUX_NILFS2_ONDISK_H
8 #include <linux/types.h>
9 #include <linux/magic.h>
10 #include <asm/byteorder.h>
11 #define NILFS_INODE_BMAP_SIZE 7
12 struct nilfs_inode {
13 __le64 i_blocks;
14 __le64 i_size;
15 __le64 i_ctime;
16 __le64 i_mtime;
17 __le32 i_ctime_nsec;
18 __le32 i_mtime_nsec;
19 __le32 i_uid;
20 __le32 i_gid;
21 __le16 i_mode;
22 __le16 i_links_count;
23 __le32 i_flags;
24 __le64 i_bmap[NILFS_INODE_BMAP_SIZE];
25 #define i_device_code i_bmap[0]
26 __le64 i_xattr;
27 __le32 i_generation;
28 __le32 i_pad;
29 };
30 #define NILFS_MIN_INODE_SIZE 128
31 struct nilfs_super_root {
32 __le32 sr_sum;
33 __le16 sr_bytes;
34 __le16 sr_flags;
35 __le64 sr_nongc_ctime;
36 struct nilfs_inode sr_dat;
37 struct nilfs_inode sr_cpfile;
38 struct nilfs_inode sr_sufile;
39 };
40 #define NILFS_SR_MDT_OFFSET(inode_size, i) \
41 ((unsigned long)&((struct nilfs_super_root *)0)->sr_dat + \
42 (inode_size) * (i))
43 #define NILFS_SR_DAT_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 0)
44 #define NILFS_SR_CPFILE_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 1)
45 #define NILFS_SR_SUFILE_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 2)
46 #define NILFS_SR_BYTES(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 3)
47 #define NILFS_DFL_MAX_MNT_COUNT 50
48 #define NILFS_VALID_FS 0x0001
49 #define NILFS_ERROR_FS 0x0002
50 #define NILFS_RESIZE_FS 0x0004
51 #define NILFS_MOUNT_ERROR_MODE 0x0070
52 #define NILFS_MOUNT_ERRORS_CONT 0x0010
53 #define NILFS_MOUNT_ERRORS_RO 0x0020
54 #define NILFS_MOUNT_ERRORS_PANIC 0x0040
55 #define NILFS_MOUNT_BARRIER 0x1000
56 #define NILFS_MOUNT_STRICT_ORDER 0x2000
57 #define NILFS_MOUNT_NORECOVERY 0x4000
58 #define NILFS_MOUNT_DISCARD 0x8000
59 struct nilfs_super_block {
60 __le16 s_minor_rev_level;
61 __le16 s_magic;
62 __le16 s_bytes;
63 __le16 s_flags;
64 __le32 s_crc_seed;
65 __le32 s_log_block_size;
66 __le64 s_nsegments;
67 __le64 s_first_data_block;
68 __le32 s_r_segments_percentage;
69 __le64 s_last_cno;
70 __le64 s_last_seq;
71 __le64 s_ctime;
72 __le64 s_wtime;
73 __le16 s_max_mnt_count;
74 __le16 s_state;
75 __le16 s_errors;
76 __le64 s_lastcheck;
77 __le32 s_creator_os;
78 __le16 s_def_resuid;
79 __le16 s_def_resgid;
80 __le32 s_first_ino;
81 __le16 s_dat_entry_size;
82 __le16 s_checkpoint_size;
83 __le16 s_segment_usage_size;
84 __le32 s_c_block_max;
85 __le64 s_feature_compat_ro;
86 __le64 s_feature_incompat;
87 __u32 s_reserved[186];
88 };
89 #define NILFS_OS_LINUX 0
90 #define NILFS_CURRENT_REV 2
91 #define NILFS_MINOR_REV 0
92 #define NILFS_MIN_SUPP_REV 2
93 #define NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT 0x00000001ULL
94 #define NILFS_FEATURE_COMPAT_SUPP 0ULL
95 #define NILFS_FEATURE_COMPAT_RO_SUPP NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT
96 #define NILFS_FEATURE_INCOMPAT_SUPP 0ULL
97 #define NILFS_SB_BYTES \
98 ((long)&((struct nilfs_super_block *)0)->s_reserved)
99 #define NILFS_ROOT_INO 2
100 #define NILFS_DAT_INO 3
101 #define NILFS_CPFILE_INO 4
102 #define NILFS_SUFILE_INO 5
103 #define NILFS_IFILE_INO 6
104 #define NILFS_ATIME_INO 7
105 #define NILFS_XATTR_INO 8
106 #define NILFS_SKETCH_INO 10
107 #define NILFS_USER_INO 11
108 #define NILFS_SB_OFFSET_BYTES 1024
109 #define NILFS_SEG_MIN_BLOCKS 16
110 #define NILFS_PSEG_MIN_BLOCKS 2
111 #define NILFS_MIN_NRSVSEGS 8
112 #define NILFS_ROOT_METADATA_FILE(ino) \
113 ((ino) >= NILFS_DAT_INO && (ino) <= NILFS_SUFILE_INO)
114 #define NILFS_SB2_OFFSET_BYTES(devsize) ((((devsize) >> 12) - 1) << 12)
115 #define NILFS_LINK_MAX 32000
116 #define NILFS_NAME_LEN 255
117 #define NILFS_MIN_BLOCK_SIZE 1024
118 #define NILFS_MAX_BLOCK_SIZE 65536
119 struct nilfs_dir_entry {
120 __le64 inode;
121 __le16 rec_len;
122 __u8 name_len;
123 __u8 file_type;
124 char name[NILFS_NAME_LEN];
125 char pad;
126 };
127 enum {
128 NILFS_FT_UNKNOWN,
129 NILFS_FT_REG_FILE,
130 NILFS_FT_DIR,
131 NILFS_FT_CHRDEV,
132 NILFS_FT_BLKDEV,
133 NILFS_FT_FIFO,
134 NILFS_FT_SOCK,
135 NILFS_FT_SYMLINK,
136 NILFS_FT_MAX
137 };
138 #define NILFS_DIR_PAD 8
139 #define NILFS_DIR_ROUND (NILFS_DIR_PAD - 1)
140 #define NILFS_DIR_REC_LEN(name_len) (((name_len) + 12 + NILFS_DIR_ROUND) & \
141 ~NILFS_DIR_ROUND)
142 #define NILFS_MAX_REC_LEN ((1 << 16) - 1)
143 struct nilfs_finfo {
144 __le64 fi_ino;
145 __le64 fi_cno;
146 __le32 fi_nblocks;
147 __le32 fi_ndatablk;
148 };
149 struct nilfs_binfo_v {
150 __le64 bi_vblocknr;
151 __le64 bi_blkoff;
152 };
153 struct nilfs_binfo_dat {
154 __le64 bi_blkoff;
155 __u8 bi_level;
156 __u8 bi_pad[7];
157 };
158 union nilfs_binfo {
159 struct nilfs_binfo_v bi_v;
160 struct nilfs_binfo_dat bi_dat;
161 };
162 struct nilfs_segment_summary {
163 __le32 ss_datasum;
164 __le32 ss_sumsum;
165 __le32 ss_magic;
166 __le16 ss_bytes;
167 __le16 ss_flags;
168 __le64 ss_seq;
169 __le64 ss_create;
170 __le64 ss_next;
171 __le32 ss_nblocks;
172 __le32 ss_nfinfo;
173 __le32 ss_sumbytes;
174 __le32 ss_pad;
175 __le64 ss_cno;
176
177 };
178 #define NILFS_SEGSUM_MAGIC 0x1eaffa11
179 #define NILFS_SS_LOGBGN 0x0001
180 #define NILFS_SS_LOGEND 0x0002
181 #define NILFS_SS_SR 0x0004
182 #define NILFS_SS_SYNDT 0x0008
183 #define NILFS_SS_GC 0x0010
184 struct nilfs_btree_node {
185 __u8 bn_flags;
186 __u8 bn_level;
187 __le16 bn_nchildren;
188 __le32 bn_pad;
189 };
190 #define NILFS_BTREE_NODE_ROOT 0x01
191 #define NILFS_BTREE_LEVEL_DATA 0
192 #define NILFS_BTREE_LEVEL_NODE_MIN (NILFS_BTREE_LEVEL_DATA + 1)
193 #define NILFS_BTREE_LEVEL_MAX 14
194 struct nilfs_direct_node {
195 __u8 dn_flags;
196 __u8 pad[7];
197 };
198 struct nilfs_palloc_group_desc {
199 __le32 pg_nfrees;
200 };
201 struct nilfs_dat_entry {
202 __le64 de_blocknr;
203 __le64 de_start;
204 __le64 de_end;
205 __le64 de_rsv;
206 };
207 #define NILFS_MIN_DAT_ENTRY_SIZE 32
208 struct nilfs_snapshot_list {
209 __le64 ssl_next;
210 __le64 ssl_prev;
211 };
212 struct nilfs_checkpoint {
213 __le32 cp_flags;
214 __le32 cp_checkpoints_count;
215 struct nilfs_snapshot_list cp_snapshot_list;
216 __le64 cp_cno;
217 __le64 cp_create;
218 __le64 cp_nblk_inc;
219 __le64 cp_inodes_count;
220 __le64 cp_blocks_count;
221
222 struct nilfs_inode cp_ifile_inode;
223 };
224 #define NILFS_MIN_CHECKPOINT_SIZE (64 + NILFS_MIN_INODE_SIZE)
225 enum {
226 NILFS_CHECKPOINT_SNAPSHOT,
227 NILFS_CHECKPOINT_INVALID,
228 NILFS_CHECKPOINT_SKETCH,
229 NILFS_CHECKPOINT_MINOR,
230 };
231 #define NILFS_CHECKPOINT_FNS(flag, name) \
232 static inline void \
233 nilfs_checkpoint_set_##name(struct nilfs_checkpoint *cp) \
234 { \
235 cp->cp_flags = __cpu_to_le32(__le32_to_cpu(cp->cp_flags) | \
236 (1UL << NILFS_CHECKPOINT_##flag)); \
237 } \
238 static inline void \
239 nilfs_checkpoint_clear_##name(struct nilfs_checkpoint *cp) \
240 { \
241 cp->cp_flags = __cpu_to_le32(__le32_to_cpu(cp->cp_flags) & \
242 ~(1UL << NILFS_CHECKPOINT_##flag)); \
243 } \
244 static inline int \
245 nilfs_checkpoint_##name(const struct nilfs_checkpoint *cp) \
246 { \
247 return !!(__le32_to_cpu(cp->cp_flags) & \
248 (1UL << NILFS_CHECKPOINT_##flag)); \
249 }
250 NILFS_CHECKPOINT_FNS(SNAPSHOT, snapshot)
251 NILFS_CHECKPOINT_FNS(INVALID, invalid)
252 NILFS_CHECKPOINT_FNS(MINOR, minor)
253 struct nilfs_cpfile_header {
254 __le64 ch_ncheckpoints;
255 __le64 ch_nsnapshots;
256 struct nilfs_snapshot_list ch_snapshot_list;
257 };
258 #define NILFS_CPFILE_FIRST_CHECKPOINT_OFFSET \
259 ((sizeof(struct nilfs_cpfile_header) + \
260 sizeof(struct nilfs_checkpoint) - 1) / \
261 sizeof(struct nilfs_checkpoint))
262 struct nilfs_segment_usage {
263 __le64 su_lastmod;
264 __le32 su_nblocks;
265 __le32 su_flags;
266 };
267 #define NILFS_MIN_SEGMENT_USAGE_SIZE 16
268 enum {
269 NILFS_SEGMENT_USAGE_ACTIVE,
270 NILFS_SEGMENT_USAGE_DIRTY,
271 NILFS_SEGMENT_USAGE_ERROR,
272 };
273 #define NILFS_SEGMENT_USAGE_FNS(flag, name) \
274 static inline void \
275 nilfs_segment_usage_set_##name(struct nilfs_segment_usage *su) \
276 { \
277 su->su_flags = __cpu_to_le32(__le32_to_cpu(su->su_flags) | \
278 (1UL << NILFS_SEGMENT_USAGE_##flag));\
279 } \
280 static inline void \
281 nilfs_segment_usage_clear_##name(struct nilfs_segment_usage *su) \
282 { \
283 su->su_flags = \
284 __cpu_to_le32(__le32_to_cpu(su->su_flags) & \
285 ~(1UL << NILFS_SEGMENT_USAGE_##flag)); \
286 } \
287 static inline int \
288 nilfs_segment_usage_##name(const struct nilfs_segment_usage *su) \
289 { \
290 return !!(__le32_to_cpu(su->su_flags) & \
291 (1UL << NILFS_SEGMENT_USAGE_##flag)); \
292 }
NILFS_SEGMENT_USAGE_FNS(ACTIVE,active)293 NILFS_SEGMENT_USAGE_FNS(ACTIVE, active)
294 NILFS_SEGMENT_USAGE_FNS(DIRTY, dirty)
295 NILFS_SEGMENT_USAGE_FNS(ERROR, error)
296 static inline void
297 nilfs_segment_usage_set_clean(struct nilfs_segment_usage *su)
298 {
299 su->su_lastmod = __cpu_to_le64(0);
300 su->su_nblocks = __cpu_to_le32(0);
301 su->su_flags = __cpu_to_le32(0);
302 }
303 static inline int
nilfs_segment_usage_clean(const struct nilfs_segment_usage * su)304 nilfs_segment_usage_clean(const struct nilfs_segment_usage *su)
305 {
306 return !__le32_to_cpu(su->su_flags);
307 }
308 struct nilfs_sufile_header {
309 __le64 sh_ncleansegs;
310 __le64 sh_ndirtysegs;
311 __le64 sh_last_alloc;
312
313 };
314 #define NILFS_SUFILE_FIRST_SEGMENT_USAGE_OFFSET \
315 ((sizeof(struct nilfs_sufile_header) + \
316 sizeof(struct nilfs_segment_usage) - 1) / \
317 sizeof(struct nilfs_segment_usage))
318 #endif
319