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