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
28
29
30
31
32
33
34
35
36
37
38#ifndef _LINUX_NILFS_FS_H
39#define _LINUX_NILFS_FS_H
40
41#include <linux/types.h>
42#include <linux/ioctl.h>
43
44
45
46
47
48
49
50#define NILFS_SECRM_FL 0x00000001
51#define NILFS_UNRM_FL 0x00000002
52#define NILFS_SYNC_FL 0x00000008
53#define NILFS_IMMUTABLE_FL 0x00000010
54#define NILFS_APPEND_FL 0x00000020
55#define NILFS_NODUMP_FL 0x00000040
56#define NILFS_NOATIME_FL 0x00000080
57
58#define NILFS_NOTAIL_FL 0x00008000
59#define NILFS_DIRSYNC_FL 0x00010000
60
61#define NILFS_FL_USER_VISIBLE 0x0003DFFF
62#define NILFS_FL_USER_MODIFIABLE 0x000380FF
63
64
65#define NILFS_INODE_BMAP_SIZE 7
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84struct nilfs_inode {
85 __le64 i_blocks;
86 __le64 i_size;
87 __le64 i_ctime;
88 __le64 i_mtime;
89 __le32 i_ctime_nsec;
90 __le32 i_mtime_nsec;
91 __le32 i_uid;
92 __le32 i_gid;
93 __le16 i_mode;
94 __le16 i_links_count;
95 __le32 i_flags;
96 __le64 i_bmap[NILFS_INODE_BMAP_SIZE];
97#define i_device_code i_bmap[0]
98 __le64 i_xattr;
99 __le32 i_generation;
100 __le32 i_pad;
101};
102
103
104
105
106
107
108
109
110
111
112
113struct nilfs_super_root {
114 __le32 sr_sum;
115 __le16 sr_bytes;
116 __le16 sr_flags;
117 __le64 sr_nongc_ctime;
118 struct nilfs_inode sr_dat;
119 struct nilfs_inode sr_cpfile;
120 struct nilfs_inode sr_sufile;
121};
122
123#define NILFS_SR_MDT_OFFSET(inode_size, i) \
124 ((unsigned long)&((struct nilfs_super_root *)0)->sr_dat + \
125 (inode_size) * (i))
126#define NILFS_SR_DAT_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 0)
127#define NILFS_SR_CPFILE_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 1)
128#define NILFS_SR_SUFILE_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 2)
129#define NILFS_SR_BYTES (sizeof(struct nilfs_super_root))
130
131
132
133
134#define NILFS_DFL_MAX_MNT_COUNT 50
135
136
137
138
139#define NILFS_VALID_FS 0x0001
140#define NILFS_ERROR_FS 0x0002
141#define NILFS_RESIZE_FS 0x0004
142
143
144
145
146#define NILFS_MOUNT_ERROR_MODE 0x0070
147#define NILFS_MOUNT_ERRORS_CONT 0x0010
148#define NILFS_MOUNT_ERRORS_RO 0x0020
149#define NILFS_MOUNT_ERRORS_PANIC 0x0040
150#define NILFS_MOUNT_BARRIER 0x1000
151#define NILFS_MOUNT_STRICT_ORDER 0x2000
152
153#define NILFS_MOUNT_NORECOVERY 0x4000
154
155#define NILFS_MOUNT_DISCARD 0x8000
156
157
158
159
160
161struct nilfs_super_block {
162 __le32 s_rev_level;
163 __le16 s_minor_rev_level;
164 __le16 s_magic;
165
166 __le16 s_bytes;
167
168
169 __le16 s_flags;
170 __le32 s_crc_seed;
171 __le32 s_sum;
172
173 __le32 s_log_block_size;
174
175
176 __le64 s_nsegments;
177 __le64 s_dev_size;
178 __le64 s_first_data_block;
179 __le32 s_blocks_per_segment;
180 __le32 s_r_segments_percentage;
181
182 __le64 s_last_cno;
183 __le64 s_last_pseg;
184 __le64 s_last_seq;
185 __le64 s_free_blocks_count;
186
187 __le64 s_ctime;
188
189 __le64 s_mtime;
190 __le64 s_wtime;
191 __le16 s_mnt_count;
192 __le16 s_max_mnt_count;
193 __le16 s_state;
194 __le16 s_errors;
195 __le64 s_lastcheck;
196
197 __le32 s_checkinterval;
198 __le32 s_creator_os;
199 __le16 s_def_resuid;
200 __le16 s_def_resgid;
201 __le32 s_first_ino;
202
203 __le16 s_inode_size;
204 __le16 s_dat_entry_size;
205 __le16 s_checkpoint_size;
206 __le16 s_segment_usage_size;
207
208 __u8 s_uuid[16];
209 char s_volume_name[80];
210
211 __le32 s_c_interval;
212 __le32 s_c_block_max;
213
214 __le64 s_feature_compat;
215 __le64 s_feature_compat_ro;
216 __le64 s_feature_incompat;
217 __u32 s_reserved[186];
218};
219
220
221
222
223#define NILFS_OS_LINUX 0
224
225
226
227
228
229#define NILFS_CURRENT_REV 2
230#define NILFS_MINOR_REV 0
231#define NILFS_MIN_SUPP_REV 2
232
233
234
235
236
237
238
239#define NILFS_FEATURE_COMPAT_SUPP 0ULL
240#define NILFS_FEATURE_COMPAT_RO_SUPP 0ULL
241#define NILFS_FEATURE_INCOMPAT_SUPP 0ULL
242
243
244
245
246#define NILFS_SB_BYTES \
247 ((long)&((struct nilfs_super_block *)0)->s_reserved)
248
249
250
251
252#define NILFS_ROOT_INO 2
253#define NILFS_DAT_INO 3
254#define NILFS_CPFILE_INO 4
255#define NILFS_SUFILE_INO 5
256#define NILFS_IFILE_INO 6
257#define NILFS_ATIME_INO 7
258#define NILFS_XATTR_INO 8
259#define NILFS_SKETCH_INO 10
260#define NILFS_USER_INO 11
261
262#define NILFS_SB_OFFSET_BYTES 1024
263#define NILFS_SUPER_MAGIC 0x3434
264
265#define NILFS_SEG_MIN_BLOCKS 16
266
267#define NILFS_PSEG_MIN_BLOCKS 2
268
269#define NILFS_MIN_NRSVSEGS 8
270
271
272
273
274
275
276
277#define NILFS_ROOT_METADATA_FILE(ino) \
278 ((ino) >= NILFS_DAT_INO && (ino) <= NILFS_SUFILE_INO)
279
280
281
282
283#define NILFS_SB2_OFFSET_BYTES(devsize) ((((devsize) >> 12) - 1) << 12)
284
285
286
287
288#define NILFS_LINK_MAX 32000
289
290
291
292
293
294
295#define NILFS_NAME_LEN 255
296
297
298
299
300#define NILFS_MIN_BLOCK_SIZE 1024
301#define NILFS_MAX_BLOCK_SIZE 65536
302
303
304
305
306
307
308
309struct nilfs_dir_entry {
310 __le64 inode;
311 __le16 rec_len;
312 __u8 name_len;
313 __u8 file_type;
314 char name[NILFS_NAME_LEN];
315 char pad;
316};
317
318
319
320
321
322enum {
323 NILFS_FT_UNKNOWN,
324 NILFS_FT_REG_FILE,
325 NILFS_FT_DIR,
326 NILFS_FT_CHRDEV,
327 NILFS_FT_BLKDEV,
328 NILFS_FT_FIFO,
329 NILFS_FT_SOCK,
330 NILFS_FT_SYMLINK,
331 NILFS_FT_MAX
332};
333
334
335
336
337
338
339#define NILFS_DIR_PAD 8
340#define NILFS_DIR_ROUND (NILFS_DIR_PAD - 1)
341#define NILFS_DIR_REC_LEN(name_len) (((name_len) + 12 + NILFS_DIR_ROUND) & \
342 ~NILFS_DIR_ROUND)
343#define NILFS_MAX_REC_LEN ((1<<16)-1)
344
345static inline unsigned nilfs_rec_len_from_disk(__le16 dlen)
346{
347 unsigned len = le16_to_cpu(dlen);
348
349 if (len == NILFS_MAX_REC_LEN)
350 return 1 << 16;
351 return len;
352}
353
354static inline __le16 nilfs_rec_len_to_disk(unsigned len)
355{
356 if (len == (1 << 16))
357 return cpu_to_le16(NILFS_MAX_REC_LEN);
358 else if (len > (1 << 16))
359 BUG();
360 return cpu_to_le16(len);
361}
362
363
364
365
366
367
368
369
370struct nilfs_finfo {
371 __le64 fi_ino;
372 __le64 fi_cno;
373 __le32 fi_nblocks;
374 __le32 fi_ndatablk;
375
376};
377
378
379
380
381
382
383struct nilfs_binfo_v {
384 __le64 bi_vblocknr;
385 __le64 bi_blkoff;
386};
387
388
389
390
391
392
393
394struct nilfs_binfo_dat {
395 __le64 bi_blkoff;
396 __u8 bi_level;
397 __u8 bi_pad[7];
398};
399
400
401
402
403
404
405union nilfs_binfo {
406 struct nilfs_binfo_v bi_v;
407 struct nilfs_binfo_dat bi_dat;
408};
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426struct nilfs_segment_summary {
427 __le32 ss_datasum;
428 __le32 ss_sumsum;
429 __le32 ss_magic;
430 __le16 ss_bytes;
431 __le16 ss_flags;
432 __le64 ss_seq;
433 __le64 ss_create;
434 __le64 ss_next;
435 __le32 ss_nblocks;
436 __le32 ss_nfinfo;
437 __le32 ss_sumbytes;
438 __le32 ss_pad;
439 __le64 ss_cno;
440
441};
442
443#define NILFS_SEGSUM_MAGIC 0x1eaffa11
444
445
446
447
448#define NILFS_SS_LOGBGN 0x0001
449#define NILFS_SS_LOGEND 0x0002
450#define NILFS_SS_SR 0x0004
451#define NILFS_SS_SYNDT 0x0008
452#define NILFS_SS_GC 0x0010
453
454
455
456
457
458
459
460
461struct nilfs_btree_node {
462 __u8 bn_flags;
463 __u8 bn_level;
464 __le16 bn_nchildren;
465 __le32 bn_pad;
466};
467
468
469#define NILFS_BTREE_NODE_ROOT 0x01
470
471
472#define NILFS_BTREE_LEVEL_DATA 0
473#define NILFS_BTREE_LEVEL_NODE_MIN (NILFS_BTREE_LEVEL_DATA + 1)
474#define NILFS_BTREE_LEVEL_MAX 14
475
476
477
478
479
480struct nilfs_palloc_group_desc {
481 __le32 pg_nfrees;
482};
483
484
485
486
487
488
489
490
491struct nilfs_dat_entry {
492 __le64 de_blocknr;
493 __le64 de_start;
494 __le64 de_end;
495 __le64 de_rsv;
496};
497
498
499
500
501
502
503struct nilfs_snapshot_list {
504 __le64 ssl_next;
505 __le64 ssl_prev;
506};
507
508
509
510
511
512
513
514
515
516
517
518
519
520struct nilfs_checkpoint {
521 __le32 cp_flags;
522 __le32 cp_checkpoints_count;
523 struct nilfs_snapshot_list cp_snapshot_list;
524 __le64 cp_cno;
525 __le64 cp_create;
526 __le64 cp_nblk_inc;
527 __le64 cp_inodes_count;
528 __le64 cp_blocks_count;
529
530
531
532
533 struct nilfs_inode cp_ifile_inode;
534};
535
536
537enum {
538 NILFS_CHECKPOINT_SNAPSHOT,
539 NILFS_CHECKPOINT_INVALID,
540 NILFS_CHECKPOINT_SKETCH,
541 NILFS_CHECKPOINT_MINOR,
542};
543
544#define NILFS_CHECKPOINT_FNS(flag, name) \
545static inline void \
546nilfs_checkpoint_set_##name(struct nilfs_checkpoint *cp) \
547{ \
548 cp->cp_flags = cpu_to_le32(le32_to_cpu(cp->cp_flags) | \
549 (1UL << NILFS_CHECKPOINT_##flag)); \
550} \
551static inline void \
552nilfs_checkpoint_clear_##name(struct nilfs_checkpoint *cp) \
553{ \
554 cp->cp_flags = cpu_to_le32(le32_to_cpu(cp->cp_flags) & \
555 ~(1UL << NILFS_CHECKPOINT_##flag)); \
556} \
557static inline int \
558nilfs_checkpoint_##name(const struct nilfs_checkpoint *cp) \
559{ \
560 return !!(le32_to_cpu(cp->cp_flags) & \
561 (1UL << NILFS_CHECKPOINT_##flag)); \
562}
563
564NILFS_CHECKPOINT_FNS(SNAPSHOT, snapshot)
565NILFS_CHECKPOINT_FNS(INVALID, invalid)
566NILFS_CHECKPOINT_FNS(MINOR, minor)
567
568
569
570
571
572
573
574
575
576
577
578
579struct nilfs_cpinfo {
580 __u32 ci_flags;
581 __u32 ci_pad;
582 __u64 ci_cno;
583 __u64 ci_create;
584 __u64 ci_nblk_inc;
585 __u64 ci_inodes_count;
586 __u64 ci_blocks_count;
587 __u64 ci_next;
588};
589
590#define NILFS_CPINFO_FNS(flag, name) \
591static inline int \
592nilfs_cpinfo_##name(const struct nilfs_cpinfo *cpinfo) \
593{ \
594 return !!(cpinfo->ci_flags & (1UL << NILFS_CHECKPOINT_##flag)); \
595}
596
597NILFS_CPINFO_FNS(SNAPSHOT, snapshot)
598NILFS_CPINFO_FNS(INVALID, invalid)
599NILFS_CPINFO_FNS(MINOR, minor)
600
601
602
603
604
605
606
607
608struct nilfs_cpfile_header {
609 __le64 ch_ncheckpoints;
610 __le64 ch_nsnapshots;
611 struct nilfs_snapshot_list ch_snapshot_list;
612};
613
614#define NILFS_CPFILE_FIRST_CHECKPOINT_OFFSET \
615 ((sizeof(struct nilfs_cpfile_header) + \
616 sizeof(struct nilfs_checkpoint) - 1) / \
617 sizeof(struct nilfs_checkpoint))
618
619
620
621
622
623
624
625struct nilfs_segment_usage {
626 __le64 su_lastmod;
627 __le32 su_nblocks;
628 __le32 su_flags;
629};
630
631
632enum {
633 NILFS_SEGMENT_USAGE_ACTIVE,
634 NILFS_SEGMENT_USAGE_DIRTY,
635 NILFS_SEGMENT_USAGE_ERROR,
636
637
638};
639
640#define NILFS_SEGMENT_USAGE_FNS(flag, name) \
641static inline void \
642nilfs_segment_usage_set_##name(struct nilfs_segment_usage *su) \
643{ \
644 su->su_flags = cpu_to_le32(le32_to_cpu(su->su_flags) | \
645 (1UL << NILFS_SEGMENT_USAGE_##flag));\
646} \
647static inline void \
648nilfs_segment_usage_clear_##name(struct nilfs_segment_usage *su) \
649{ \
650 su->su_flags = \
651 cpu_to_le32(le32_to_cpu(su->su_flags) & \
652 ~(1UL << NILFS_SEGMENT_USAGE_##flag)); \
653} \
654static inline int \
655nilfs_segment_usage_##name(const struct nilfs_segment_usage *su) \
656{ \
657 return !!(le32_to_cpu(su->su_flags) & \
658 (1UL << NILFS_SEGMENT_USAGE_##flag)); \
659}
660
661NILFS_SEGMENT_USAGE_FNS(ACTIVE, active)
662NILFS_SEGMENT_USAGE_FNS(DIRTY, dirty)
663NILFS_SEGMENT_USAGE_FNS(ERROR, error)
664
665static inline void
666nilfs_segment_usage_set_clean(struct nilfs_segment_usage *su)
667{
668 su->su_lastmod = cpu_to_le64(0);
669 su->su_nblocks = cpu_to_le32(0);
670 su->su_flags = cpu_to_le32(0);
671}
672
673static inline int
674nilfs_segment_usage_clean(const struct nilfs_segment_usage *su)
675{
676 return !le32_to_cpu(su->su_flags);
677}
678
679
680
681
682
683
684
685struct nilfs_sufile_header {
686 __le64 sh_ncleansegs;
687 __le64 sh_ndirtysegs;
688 __le64 sh_last_alloc;
689
690};
691
692#define NILFS_SUFILE_FIRST_SEGMENT_USAGE_OFFSET \
693 ((sizeof(struct nilfs_sufile_header) + \
694 sizeof(struct nilfs_segment_usage) - 1) / \
695 sizeof(struct nilfs_segment_usage))
696
697
698
699
700
701
702
703struct nilfs_suinfo {
704 __u64 sui_lastmod;
705 __u32 sui_nblocks;
706 __u32 sui_flags;
707};
708
709#define NILFS_SUINFO_FNS(flag, name) \
710static inline int \
711nilfs_suinfo_##name(const struct nilfs_suinfo *si) \
712{ \
713 return si->sui_flags & (1UL << NILFS_SEGMENT_USAGE_##flag); \
714}
715
716NILFS_SUINFO_FNS(ACTIVE, active)
717NILFS_SUINFO_FNS(DIRTY, dirty)
718NILFS_SUINFO_FNS(ERROR, error)
719
720static inline int nilfs_suinfo_clean(const struct nilfs_suinfo *si)
721{
722 return !si->sui_flags;
723}
724
725
726enum {
727 NILFS_CHECKPOINT,
728 NILFS_SNAPSHOT,
729};
730
731
732
733
734
735
736struct nilfs_cpmode {
737 __u64 cm_cno;
738 __u32 cm_mode;
739 __u32 cm_pad;
740};
741
742
743
744
745
746
747
748
749
750struct nilfs_argv {
751 __u64 v_base;
752 __u32 v_nmembs;
753 __u16 v_size;
754 __u16 v_flags;
755 __u64 v_index;
756};
757
758
759
760
761
762
763struct nilfs_period {
764 __u64 p_start;
765 __u64 p_end;
766};
767
768
769
770
771
772
773
774struct nilfs_cpstat {
775 __u64 cs_cno;
776 __u64 cs_ncps;
777 __u64 cs_nsss;
778};
779
780
781
782
783
784
785
786
787
788
789struct nilfs_sustat {
790 __u64 ss_nsegs;
791 __u64 ss_ncleansegs;
792 __u64 ss_ndirtysegs;
793 __u64 ss_ctime;
794 __u64 ss_nongc_ctime;
795 __u64 ss_prot_seq;
796};
797
798
799
800
801
802
803
804
805struct nilfs_vinfo {
806 __u64 vi_vblocknr;
807 __u64 vi_start;
808 __u64 vi_end;
809 __u64 vi_blocknr;
810};
811
812
813
814
815struct nilfs_vdesc {
816 __u64 vd_ino;
817 __u64 vd_cno;
818 __u64 vd_vblocknr;
819 struct nilfs_period vd_period;
820 __u64 vd_blocknr;
821 __u64 vd_offset;
822 __u32 vd_flags;
823 __u32 vd_pad;
824};
825
826
827
828
829struct nilfs_bdesc {
830 __u64 bd_ino;
831 __u64 bd_oblocknr;
832 __u64 bd_blocknr;
833 __u64 bd_offset;
834 __u32 bd_level;
835 __u32 bd_pad;
836};
837
838#define NILFS_IOCTL_IDENT 'n'
839
840#define NILFS_IOCTL_CHANGE_CPMODE \
841 _IOW(NILFS_IOCTL_IDENT, 0x80, struct nilfs_cpmode)
842#define NILFS_IOCTL_DELETE_CHECKPOINT \
843 _IOW(NILFS_IOCTL_IDENT, 0x81, __u64)
844#define NILFS_IOCTL_GET_CPINFO \
845 _IOR(NILFS_IOCTL_IDENT, 0x82, struct nilfs_argv)
846#define NILFS_IOCTL_GET_CPSTAT \
847 _IOR(NILFS_IOCTL_IDENT, 0x83, struct nilfs_cpstat)
848#define NILFS_IOCTL_GET_SUINFO \
849 _IOR(NILFS_IOCTL_IDENT, 0x84, struct nilfs_argv)
850#define NILFS_IOCTL_GET_SUSTAT \
851 _IOR(NILFS_IOCTL_IDENT, 0x85, struct nilfs_sustat)
852#define NILFS_IOCTL_GET_VINFO \
853 _IOWR(NILFS_IOCTL_IDENT, 0x86, struct nilfs_argv)
854#define NILFS_IOCTL_GET_BDESCS \
855 _IOWR(NILFS_IOCTL_IDENT, 0x87, struct nilfs_argv)
856#define NILFS_IOCTL_CLEAN_SEGMENTS \
857 _IOW(NILFS_IOCTL_IDENT, 0x88, struct nilfs_argv[5])
858#define NILFS_IOCTL_SYNC \
859 _IOR(NILFS_IOCTL_IDENT, 0x8A, __u64)
860#define NILFS_IOCTL_RESIZE \
861 _IOW(NILFS_IOCTL_IDENT, 0x8B, __u64)
862
863#endif
864