1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#ifndef _LINUX_NILFS2_ONDISK_H
28#define _LINUX_NILFS2_ONDISK_H
29
30#include <linux/types.h>
31#include <linux/magic.h>
32
33
34#define NILFS_INODE_BMAP_SIZE 7
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54struct nilfs_inode {
55 __le64 i_blocks;
56 __le64 i_size;
57 __le64 i_ctime;
58 __le64 i_mtime;
59 __le32 i_ctime_nsec;
60 __le32 i_mtime_nsec;
61 __le32 i_uid;
62 __le32 i_gid;
63 __le16 i_mode;
64 __le16 i_links_count;
65 __le32 i_flags;
66 __le64 i_bmap[NILFS_INODE_BMAP_SIZE];
67#define i_device_code i_bmap[0]
68 __le64 i_xattr;
69 __le32 i_generation;
70 __le32 i_pad;
71};
72
73#define NILFS_MIN_INODE_SIZE 128
74
75
76
77
78
79
80
81
82
83
84
85struct nilfs_super_root {
86 __le32 sr_sum;
87 __le16 sr_bytes;
88 __le16 sr_flags;
89 __le64 sr_nongc_ctime;
90 struct nilfs_inode sr_dat;
91 struct nilfs_inode sr_cpfile;
92 struct nilfs_inode sr_sufile;
93};
94
95#define NILFS_SR_MDT_OFFSET(inode_size, i) \
96 ((unsigned long)&((struct nilfs_super_root *)0)->sr_dat + \
97 (inode_size) * (i))
98#define NILFS_SR_DAT_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 0)
99#define NILFS_SR_CPFILE_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 1)
100#define NILFS_SR_SUFILE_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 2)
101#define NILFS_SR_BYTES(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 3)
102
103
104
105
106#define NILFS_DFL_MAX_MNT_COUNT 50
107
108
109
110
111#define NILFS_VALID_FS 0x0001
112#define NILFS_ERROR_FS 0x0002
113#define NILFS_RESIZE_FS 0x0004
114
115
116
117
118#define NILFS_MOUNT_ERROR_MODE 0x0070
119#define NILFS_MOUNT_ERRORS_CONT 0x0010
120#define NILFS_MOUNT_ERRORS_RO 0x0020
121#define NILFS_MOUNT_ERRORS_PANIC 0x0040
122#define NILFS_MOUNT_BARRIER 0x1000
123#define NILFS_MOUNT_STRICT_ORDER 0x2000
124
125
126
127#define NILFS_MOUNT_NORECOVERY 0x4000
128
129
130
131#define NILFS_MOUNT_DISCARD 0x8000
132
133
134
135
136
137struct nilfs_super_block {
138 __le32 s_rev_level;
139 __le16 s_minor_rev_level;
140 __le16 s_magic;
141
142 __le16 s_bytes;
143
144
145
146
147 __le16 s_flags;
148 __le32 s_crc_seed;
149 __le32 s_sum;
150
151 __le32 s_log_block_size;
152
153
154
155
156 __le64 s_nsegments;
157 __le64 s_dev_size;
158 __le64 s_first_data_block;
159 __le32 s_blocks_per_segment;
160 __le32 s_r_segments_percentage;
161
162 __le64 s_last_cno;
163 __le64 s_last_pseg;
164 __le64 s_last_seq;
165 __le64 s_free_blocks_count;
166
167 __le64 s_ctime;
168
169
170
171 __le64 s_mtime;
172 __le64 s_wtime;
173 __le16 s_mnt_count;
174 __le16 s_max_mnt_count;
175 __le16 s_state;
176 __le16 s_errors;
177 __le64 s_lastcheck;
178
179 __le32 s_checkinterval;
180 __le32 s_creator_os;
181 __le16 s_def_resuid;
182 __le16 s_def_resgid;
183 __le32 s_first_ino;
184
185 __le16 s_inode_size;
186 __le16 s_dat_entry_size;
187 __le16 s_checkpoint_size;
188 __le16 s_segment_usage_size;
189
190 __u8 s_uuid[16];
191 char s_volume_name[80];
192
193 __le32 s_c_interval;
194 __le32 s_c_block_max;
195
196
197
198 __le64 s_feature_compat;
199 __le64 s_feature_compat_ro;
200 __le64 s_feature_incompat;
201 __u32 s_reserved[186];
202};
203
204
205
206
207#define NILFS_OS_LINUX 0
208
209
210
211
212
213#define NILFS_CURRENT_REV 2
214#define NILFS_MINOR_REV 0
215#define NILFS_MIN_SUPP_REV 2
216
217
218
219
220
221
222
223#define NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT 0x00000001ULL
224
225#define NILFS_FEATURE_COMPAT_SUPP 0ULL
226#define NILFS_FEATURE_COMPAT_RO_SUPP NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT
227#define NILFS_FEATURE_INCOMPAT_SUPP 0ULL
228
229
230
231
232#define NILFS_SB_BYTES \
233 ((long)&((struct nilfs_super_block *)0)->s_reserved)
234
235
236
237
238#define NILFS_ROOT_INO 2
239#define NILFS_DAT_INO 3
240#define NILFS_CPFILE_INO 4
241#define NILFS_SUFILE_INO 5
242#define NILFS_IFILE_INO 6
243#define NILFS_ATIME_INO 7
244#define NILFS_XATTR_INO 8
245#define NILFS_SKETCH_INO 10
246#define NILFS_USER_INO 11
247
248#define NILFS_SB_OFFSET_BYTES 1024
249
250#define NILFS_SEG_MIN_BLOCKS 16
251
252
253
254#define NILFS_PSEG_MIN_BLOCKS 2
255
256
257
258#define NILFS_MIN_NRSVSEGS 8
259
260
261
262
263
264
265
266
267
268#define NILFS_ROOT_METADATA_FILE(ino) \
269 ((ino) >= NILFS_DAT_INO && (ino) <= NILFS_SUFILE_INO)
270
271
272
273
274#define NILFS_SB2_OFFSET_BYTES(devsize) ((((devsize) >> 12) - 1) << 12)
275
276
277
278
279#define NILFS_LINK_MAX 32000
280
281
282
283
284
285
286#define NILFS_NAME_LEN 255
287
288
289
290
291#define NILFS_MIN_BLOCK_SIZE 1024
292#define NILFS_MAX_BLOCK_SIZE 65536
293
294
295
296
297
298
299
300struct nilfs_dir_entry {
301 __le64 inode;
302 __le16 rec_len;
303 __u8 name_len;
304 __u8 file_type;
305 char name[NILFS_NAME_LEN];
306 char pad;
307};
308
309
310
311
312
313enum {
314 NILFS_FT_UNKNOWN,
315 NILFS_FT_REG_FILE,
316 NILFS_FT_DIR,
317 NILFS_FT_CHRDEV,
318 NILFS_FT_BLKDEV,
319 NILFS_FT_FIFO,
320 NILFS_FT_SOCK,
321 NILFS_FT_SYMLINK,
322 NILFS_FT_MAX
323};
324
325
326
327
328
329
330#define NILFS_DIR_PAD 8
331#define NILFS_DIR_ROUND (NILFS_DIR_PAD - 1)
332#define NILFS_DIR_REC_LEN(name_len) (((name_len) + 12 + NILFS_DIR_ROUND) & \
333 ~NILFS_DIR_ROUND)
334#define NILFS_MAX_REC_LEN ((1 << 16) - 1)
335
336
337
338
339
340
341
342
343struct nilfs_finfo {
344 __le64 fi_ino;
345 __le64 fi_cno;
346 __le32 fi_nblocks;
347 __le32 fi_ndatablk;
348};
349
350
351
352
353
354
355struct nilfs_binfo_v {
356 __le64 bi_vblocknr;
357 __le64 bi_blkoff;
358};
359
360
361
362
363
364
365
366struct nilfs_binfo_dat {
367 __le64 bi_blkoff;
368 __u8 bi_level;
369 __u8 bi_pad[7];
370};
371
372
373
374
375
376
377union nilfs_binfo {
378 struct nilfs_binfo_v bi_v;
379 struct nilfs_binfo_dat bi_dat;
380};
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398struct nilfs_segment_summary {
399 __le32 ss_datasum;
400 __le32 ss_sumsum;
401 __le32 ss_magic;
402 __le16 ss_bytes;
403 __le16 ss_flags;
404 __le64 ss_seq;
405 __le64 ss_create;
406 __le64 ss_next;
407 __le32 ss_nblocks;
408 __le32 ss_nfinfo;
409 __le32 ss_sumbytes;
410 __le32 ss_pad;
411 __le64 ss_cno;
412
413};
414
415#define NILFS_SEGSUM_MAGIC 0x1eaffa11
416
417
418
419
420#define NILFS_SS_LOGBGN 0x0001
421#define NILFS_SS_LOGEND 0x0002
422#define NILFS_SS_SR 0x0004
423#define NILFS_SS_SYNDT 0x0008
424#define NILFS_SS_GC 0x0010
425
426
427
428
429
430
431
432
433struct nilfs_btree_node {
434 __u8 bn_flags;
435 __u8 bn_level;
436 __le16 bn_nchildren;
437 __le32 bn_pad;
438};
439
440
441#define NILFS_BTREE_NODE_ROOT 0x01
442
443
444#define NILFS_BTREE_LEVEL_DATA 0
445#define NILFS_BTREE_LEVEL_NODE_MIN (NILFS_BTREE_LEVEL_DATA + 1)
446#define NILFS_BTREE_LEVEL_MAX 14
447
448
449
450
451
452
453struct nilfs_direct_node {
454 __u8 dn_flags;
455 __u8 pad[7];
456};
457
458
459
460
461
462struct nilfs_palloc_group_desc {
463 __le32 pg_nfrees;
464};
465
466
467
468
469
470
471
472
473struct nilfs_dat_entry {
474 __le64 de_blocknr;
475 __le64 de_start;
476 __le64 de_end;
477 __le64 de_rsv;
478};
479
480#define NILFS_MIN_DAT_ENTRY_SIZE 32
481
482
483
484
485
486
487struct nilfs_snapshot_list {
488 __le64 ssl_next;
489 __le64 ssl_prev;
490};
491
492
493
494
495
496
497
498
499
500
501
502
503
504struct nilfs_checkpoint {
505 __le32 cp_flags;
506 __le32 cp_checkpoints_count;
507 struct nilfs_snapshot_list cp_snapshot_list;
508 __le64 cp_cno;
509 __le64 cp_create;
510 __le64 cp_nblk_inc;
511 __le64 cp_inodes_count;
512 __le64 cp_blocks_count;
513
514
515
516
517
518
519 struct nilfs_inode cp_ifile_inode;
520};
521
522#define NILFS_MIN_CHECKPOINT_SIZE (64 + NILFS_MIN_INODE_SIZE)
523
524
525enum {
526 NILFS_CHECKPOINT_SNAPSHOT,
527 NILFS_CHECKPOINT_INVALID,
528 NILFS_CHECKPOINT_SKETCH,
529 NILFS_CHECKPOINT_MINOR,
530};
531
532#define NILFS_CHECKPOINT_FNS(flag, name) \
533static inline void \
534nilfs_checkpoint_set_##name(struct nilfs_checkpoint *cp) \
535{ \
536 cp->cp_flags = cpu_to_le32(le32_to_cpu(cp->cp_flags) | \
537 (1UL << NILFS_CHECKPOINT_##flag)); \
538} \
539static inline void \
540nilfs_checkpoint_clear_##name(struct nilfs_checkpoint *cp) \
541{ \
542 cp->cp_flags = cpu_to_le32(le32_to_cpu(cp->cp_flags) & \
543 ~(1UL << NILFS_CHECKPOINT_##flag)); \
544} \
545static inline int \
546nilfs_checkpoint_##name(const struct nilfs_checkpoint *cp) \
547{ \
548 return !!(le32_to_cpu(cp->cp_flags) & \
549 (1UL << NILFS_CHECKPOINT_##flag)); \
550}
551
552NILFS_CHECKPOINT_FNS(SNAPSHOT, snapshot)
553NILFS_CHECKPOINT_FNS(INVALID, invalid)
554NILFS_CHECKPOINT_FNS(MINOR, minor)
555
556
557
558
559
560
561
562struct nilfs_cpfile_header {
563 __le64 ch_ncheckpoints;
564 __le64 ch_nsnapshots;
565 struct nilfs_snapshot_list ch_snapshot_list;
566};
567
568#define NILFS_CPFILE_FIRST_CHECKPOINT_OFFSET \
569 ((sizeof(struct nilfs_cpfile_header) + \
570 sizeof(struct nilfs_checkpoint) - 1) / \
571 sizeof(struct nilfs_checkpoint))
572
573
574
575
576
577
578
579struct nilfs_segment_usage {
580 __le64 su_lastmod;
581 __le32 su_nblocks;
582 __le32 su_flags;
583};
584
585#define NILFS_MIN_SEGMENT_USAGE_SIZE 16
586
587
588enum {
589 NILFS_SEGMENT_USAGE_ACTIVE,
590 NILFS_SEGMENT_USAGE_DIRTY,
591 NILFS_SEGMENT_USAGE_ERROR,
592};
593
594#define NILFS_SEGMENT_USAGE_FNS(flag, name) \
595static inline void \
596nilfs_segment_usage_set_##name(struct nilfs_segment_usage *su) \
597{ \
598 su->su_flags = cpu_to_le32(le32_to_cpu(su->su_flags) | \
599 (1UL << NILFS_SEGMENT_USAGE_##flag));\
600} \
601static inline void \
602nilfs_segment_usage_clear_##name(struct nilfs_segment_usage *su) \
603{ \
604 su->su_flags = \
605 cpu_to_le32(le32_to_cpu(su->su_flags) & \
606 ~(1UL << NILFS_SEGMENT_USAGE_##flag)); \
607} \
608static inline int \
609nilfs_segment_usage_##name(const struct nilfs_segment_usage *su) \
610{ \
611 return !!(le32_to_cpu(su->su_flags) & \
612 (1UL << NILFS_SEGMENT_USAGE_##flag)); \
613}
614
615NILFS_SEGMENT_USAGE_FNS(ACTIVE, active)
616NILFS_SEGMENT_USAGE_FNS(DIRTY, dirty)
617NILFS_SEGMENT_USAGE_FNS(ERROR, error)
618
619static inline void
620nilfs_segment_usage_set_clean(struct nilfs_segment_usage *su)
621{
622 su->su_lastmod = cpu_to_le64(0);
623 su->su_nblocks = cpu_to_le32(0);
624 su->su_flags = cpu_to_le32(0);
625}
626
627static inline int
628nilfs_segment_usage_clean(const struct nilfs_segment_usage *su)
629{
630 return !le32_to_cpu(su->su_flags);
631}
632
633
634
635
636
637
638
639struct nilfs_sufile_header {
640 __le64 sh_ncleansegs;
641 __le64 sh_ndirtysegs;
642 __le64 sh_last_alloc;
643
644};
645
646#define NILFS_SUFILE_FIRST_SEGMENT_USAGE_OFFSET \
647 ((sizeof(struct nilfs_sufile_header) + \
648 sizeof(struct nilfs_segment_usage) - 1) / \
649 sizeof(struct nilfs_segment_usage))
650
651#endif
652