0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 #ifndef _LINUX_NILFS2_ONDISK_H
0028 #define _LINUX_NILFS2_ONDISK_H
0029
0030 #include <linux/types.h>
0031 #include <linux/magic.h>
0032 #include <asm/byteorder.h>
0033
0034 #define NILFS_INODE_BMAP_SIZE 7
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 struct nilfs_inode {
0055 __le64 i_blocks;
0056 __le64 i_size;
0057 __le64 i_ctime;
0058 __le64 i_mtime;
0059 __le32 i_ctime_nsec;
0060 __le32 i_mtime_nsec;
0061 __le32 i_uid;
0062 __le32 i_gid;
0063 __le16 i_mode;
0064 __le16 i_links_count;
0065 __le32 i_flags;
0066 __le64 i_bmap[NILFS_INODE_BMAP_SIZE];
0067 #define i_device_code i_bmap[0]
0068 __le64 i_xattr;
0069 __le32 i_generation;
0070 __le32 i_pad;
0071 };
0072
0073 #define NILFS_MIN_INODE_SIZE 128
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085 struct nilfs_super_root {
0086 __le32 sr_sum;
0087 __le16 sr_bytes;
0088 __le16 sr_flags;
0089 __le64 sr_nongc_ctime;
0090 struct nilfs_inode sr_dat;
0091 struct nilfs_inode sr_cpfile;
0092 struct nilfs_inode sr_sufile;
0093 };
0094
0095 #define NILFS_SR_MDT_OFFSET(inode_size, i) \
0096 ((unsigned long)&((struct nilfs_super_root *)0)->sr_dat + \
0097 (inode_size) * (i))
0098 #define NILFS_SR_DAT_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 0)
0099 #define NILFS_SR_CPFILE_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 1)
0100 #define NILFS_SR_SUFILE_OFFSET(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 2)
0101 #define NILFS_SR_BYTES(inode_size) NILFS_SR_MDT_OFFSET(inode_size, 3)
0102
0103
0104
0105
0106 #define NILFS_DFL_MAX_MNT_COUNT 50
0107
0108
0109
0110
0111 #define NILFS_VALID_FS 0x0001
0112 #define NILFS_ERROR_FS 0x0002
0113 #define NILFS_RESIZE_FS 0x0004
0114
0115
0116
0117
0118 #define NILFS_MOUNT_ERROR_MODE 0x0070
0119 #define NILFS_MOUNT_ERRORS_CONT 0x0010
0120 #define NILFS_MOUNT_ERRORS_RO 0x0020
0121 #define NILFS_MOUNT_ERRORS_PANIC 0x0040
0122 #define NILFS_MOUNT_BARRIER 0x1000
0123 #define NILFS_MOUNT_STRICT_ORDER 0x2000
0124
0125
0126
0127 #define NILFS_MOUNT_NORECOVERY 0x4000
0128
0129
0130
0131 #define NILFS_MOUNT_DISCARD 0x8000
0132
0133
0134
0135
0136
0137 struct nilfs_super_block {
0138 __le32 s_rev_level;
0139 __le16 s_minor_rev_level;
0140 __le16 s_magic;
0141
0142 __le16 s_bytes;
0143
0144
0145
0146
0147 __le16 s_flags;
0148 __le32 s_crc_seed;
0149 __le32 s_sum;
0150
0151 __le32 s_log_block_size;
0152
0153
0154
0155
0156 __le64 s_nsegments;
0157 __le64 s_dev_size;
0158 __le64 s_first_data_block;
0159 __le32 s_blocks_per_segment;
0160 __le32 s_r_segments_percentage;
0161
0162 __le64 s_last_cno;
0163 __le64 s_last_pseg;
0164 __le64 s_last_seq;
0165 __le64 s_free_blocks_count;
0166
0167 __le64 s_ctime;
0168
0169
0170
0171 __le64 s_mtime;
0172 __le64 s_wtime;
0173 __le16 s_mnt_count;
0174 __le16 s_max_mnt_count;
0175 __le16 s_state;
0176 __le16 s_errors;
0177 __le64 s_lastcheck;
0178
0179 __le32 s_checkinterval;
0180 __le32 s_creator_os;
0181 __le16 s_def_resuid;
0182 __le16 s_def_resgid;
0183 __le32 s_first_ino;
0184
0185 __le16 s_inode_size;
0186 __le16 s_dat_entry_size;
0187 __le16 s_checkpoint_size;
0188 __le16 s_segment_usage_size;
0189
0190 __u8 s_uuid[16];
0191 char s_volume_name[80];
0192
0193 __le32 s_c_interval;
0194 __le32 s_c_block_max;
0195
0196
0197
0198 __le64 s_feature_compat;
0199 __le64 s_feature_compat_ro;
0200 __le64 s_feature_incompat;
0201 __u32 s_reserved[186];
0202 };
0203
0204
0205
0206
0207 #define NILFS_OS_LINUX 0
0208
0209
0210
0211
0212
0213 #define NILFS_CURRENT_REV 2
0214 #define NILFS_MINOR_REV 0
0215 #define NILFS_MIN_SUPP_REV 2
0216
0217
0218
0219
0220
0221
0222
0223 #define NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT 0x00000001ULL
0224
0225 #define NILFS_FEATURE_COMPAT_SUPP 0ULL
0226 #define NILFS_FEATURE_COMPAT_RO_SUPP NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT
0227 #define NILFS_FEATURE_INCOMPAT_SUPP 0ULL
0228
0229
0230
0231
0232 #define NILFS_SB_BYTES \
0233 ((long)&((struct nilfs_super_block *)0)->s_reserved)
0234
0235
0236
0237
0238 #define NILFS_ROOT_INO 2
0239 #define NILFS_DAT_INO 3
0240 #define NILFS_CPFILE_INO 4
0241 #define NILFS_SUFILE_INO 5
0242 #define NILFS_IFILE_INO 6
0243 #define NILFS_ATIME_INO 7
0244 #define NILFS_XATTR_INO 8
0245 #define NILFS_SKETCH_INO 10
0246 #define NILFS_USER_INO 11
0247
0248 #define NILFS_SB_OFFSET_BYTES 1024
0249
0250 #define NILFS_SEG_MIN_BLOCKS 16
0251
0252
0253
0254 #define NILFS_PSEG_MIN_BLOCKS 2
0255
0256
0257
0258 #define NILFS_MIN_NRSVSEGS 8
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268 #define NILFS_ROOT_METADATA_FILE(ino) \
0269 ((ino) >= NILFS_DAT_INO && (ino) <= NILFS_SUFILE_INO)
0270
0271
0272
0273
0274 #define NILFS_SB2_OFFSET_BYTES(devsize) ((((devsize) >> 12) - 1) << 12)
0275
0276
0277
0278
0279 #define NILFS_LINK_MAX 32000
0280
0281
0282
0283
0284
0285
0286 #define NILFS_NAME_LEN 255
0287
0288
0289
0290
0291 #define NILFS_MIN_BLOCK_SIZE 1024
0292 #define NILFS_MAX_BLOCK_SIZE 65536
0293
0294
0295
0296
0297
0298
0299
0300 struct nilfs_dir_entry {
0301 __le64 inode;
0302 __le16 rec_len;
0303 __u8 name_len;
0304 __u8 file_type;
0305 char name[NILFS_NAME_LEN];
0306 char pad;
0307 };
0308
0309
0310
0311
0312
0313 enum {
0314 NILFS_FT_UNKNOWN,
0315 NILFS_FT_REG_FILE,
0316 NILFS_FT_DIR,
0317 NILFS_FT_CHRDEV,
0318 NILFS_FT_BLKDEV,
0319 NILFS_FT_FIFO,
0320 NILFS_FT_SOCK,
0321 NILFS_FT_SYMLINK,
0322 NILFS_FT_MAX
0323 };
0324
0325
0326
0327
0328
0329
0330 #define NILFS_DIR_PAD 8
0331 #define NILFS_DIR_ROUND (NILFS_DIR_PAD - 1)
0332 #define NILFS_DIR_REC_LEN(name_len) (((name_len) + 12 + NILFS_DIR_ROUND) & \
0333 ~NILFS_DIR_ROUND)
0334 #define NILFS_MAX_REC_LEN ((1 << 16) - 1)
0335
0336
0337
0338
0339
0340
0341
0342
0343 struct nilfs_finfo {
0344 __le64 fi_ino;
0345 __le64 fi_cno;
0346 __le32 fi_nblocks;
0347 __le32 fi_ndatablk;
0348 };
0349
0350
0351
0352
0353
0354
0355 struct nilfs_binfo_v {
0356 __le64 bi_vblocknr;
0357 __le64 bi_blkoff;
0358 };
0359
0360
0361
0362
0363
0364
0365
0366 struct nilfs_binfo_dat {
0367 __le64 bi_blkoff;
0368 __u8 bi_level;
0369 __u8 bi_pad[7];
0370 };
0371
0372
0373
0374
0375
0376
0377 union nilfs_binfo {
0378 struct nilfs_binfo_v bi_v;
0379 struct nilfs_binfo_dat bi_dat;
0380 };
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398 struct nilfs_segment_summary {
0399 __le32 ss_datasum;
0400 __le32 ss_sumsum;
0401 __le32 ss_magic;
0402 __le16 ss_bytes;
0403 __le16 ss_flags;
0404 __le64 ss_seq;
0405 __le64 ss_create;
0406 __le64 ss_next;
0407 __le32 ss_nblocks;
0408 __le32 ss_nfinfo;
0409 __le32 ss_sumbytes;
0410 __le32 ss_pad;
0411 __le64 ss_cno;
0412
0413 };
0414
0415 #define NILFS_SEGSUM_MAGIC 0x1eaffa11
0416
0417
0418
0419
0420 #define NILFS_SS_LOGBGN 0x0001
0421 #define NILFS_SS_LOGEND 0x0002
0422 #define NILFS_SS_SR 0x0004
0423 #define NILFS_SS_SYNDT 0x0008
0424 #define NILFS_SS_GC 0x0010
0425
0426
0427
0428
0429
0430
0431
0432
0433 struct nilfs_btree_node {
0434 __u8 bn_flags;
0435 __u8 bn_level;
0436 __le16 bn_nchildren;
0437 __le32 bn_pad;
0438 };
0439
0440
0441 #define NILFS_BTREE_NODE_ROOT 0x01
0442
0443
0444 #define NILFS_BTREE_LEVEL_DATA 0
0445 #define NILFS_BTREE_LEVEL_NODE_MIN (NILFS_BTREE_LEVEL_DATA + 1)
0446 #define NILFS_BTREE_LEVEL_MAX 14
0447
0448
0449
0450
0451
0452
0453 struct nilfs_direct_node {
0454 __u8 dn_flags;
0455 __u8 pad[7];
0456 };
0457
0458
0459
0460
0461
0462 struct nilfs_palloc_group_desc {
0463 __le32 pg_nfrees;
0464 };
0465
0466
0467
0468
0469
0470
0471
0472
0473 struct nilfs_dat_entry {
0474 __le64 de_blocknr;
0475 __le64 de_start;
0476 __le64 de_end;
0477 __le64 de_rsv;
0478 };
0479
0480 #define NILFS_MIN_DAT_ENTRY_SIZE 32
0481
0482
0483
0484
0485
0486
0487 struct nilfs_snapshot_list {
0488 __le64 ssl_next;
0489 __le64 ssl_prev;
0490 };
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504 struct nilfs_checkpoint {
0505 __le32 cp_flags;
0506 __le32 cp_checkpoints_count;
0507 struct nilfs_snapshot_list cp_snapshot_list;
0508 __le64 cp_cno;
0509 __le64 cp_create;
0510 __le64 cp_nblk_inc;
0511 __le64 cp_inodes_count;
0512 __le64 cp_blocks_count;
0513
0514
0515
0516
0517
0518
0519 struct nilfs_inode cp_ifile_inode;
0520 };
0521
0522 #define NILFS_MIN_CHECKPOINT_SIZE (64 + NILFS_MIN_INODE_SIZE)
0523
0524
0525 enum {
0526 NILFS_CHECKPOINT_SNAPSHOT,
0527 NILFS_CHECKPOINT_INVALID,
0528 NILFS_CHECKPOINT_SKETCH,
0529 NILFS_CHECKPOINT_MINOR,
0530 };
0531
0532 #define NILFS_CHECKPOINT_FNS(flag, name) \
0533 static inline void \
0534 nilfs_checkpoint_set_##name(struct nilfs_checkpoint *cp) \
0535 { \
0536 cp->cp_flags = __cpu_to_le32(__le32_to_cpu(cp->cp_flags) | \
0537 (1UL << NILFS_CHECKPOINT_##flag)); \
0538 } \
0539 static inline void \
0540 nilfs_checkpoint_clear_##name(struct nilfs_checkpoint *cp) \
0541 { \
0542 cp->cp_flags = __cpu_to_le32(__le32_to_cpu(cp->cp_flags) & \
0543 ~(1UL << NILFS_CHECKPOINT_##flag)); \
0544 } \
0545 static inline int \
0546 nilfs_checkpoint_##name(const struct nilfs_checkpoint *cp) \
0547 { \
0548 return !!(__le32_to_cpu(cp->cp_flags) & \
0549 (1UL << NILFS_CHECKPOINT_##flag)); \
0550 }
0551
0552 NILFS_CHECKPOINT_FNS(SNAPSHOT, snapshot)
0553 NILFS_CHECKPOINT_FNS(INVALID, invalid)
0554 NILFS_CHECKPOINT_FNS(MINOR, minor)
0555
0556
0557
0558
0559
0560
0561
0562 struct nilfs_cpfile_header {
0563 __le64 ch_ncheckpoints;
0564 __le64 ch_nsnapshots;
0565 struct nilfs_snapshot_list ch_snapshot_list;
0566 };
0567
0568 #define NILFS_CPFILE_FIRST_CHECKPOINT_OFFSET \
0569 ((sizeof(struct nilfs_cpfile_header) + \
0570 sizeof(struct nilfs_checkpoint) - 1) / \
0571 sizeof(struct nilfs_checkpoint))
0572
0573
0574
0575
0576
0577
0578
0579 struct nilfs_segment_usage {
0580 __le64 su_lastmod;
0581 __le32 su_nblocks;
0582 __le32 su_flags;
0583 };
0584
0585 #define NILFS_MIN_SEGMENT_USAGE_SIZE 16
0586
0587
0588 enum {
0589 NILFS_SEGMENT_USAGE_ACTIVE,
0590 NILFS_SEGMENT_USAGE_DIRTY,
0591 NILFS_SEGMENT_USAGE_ERROR,
0592 };
0593
0594 #define NILFS_SEGMENT_USAGE_FNS(flag, name) \
0595 static inline void \
0596 nilfs_segment_usage_set_##name(struct nilfs_segment_usage *su) \
0597 { \
0598 su->su_flags = __cpu_to_le32(__le32_to_cpu(su->su_flags) | \
0599 (1UL << NILFS_SEGMENT_USAGE_##flag));\
0600 } \
0601 static inline void \
0602 nilfs_segment_usage_clear_##name(struct nilfs_segment_usage *su) \
0603 { \
0604 su->su_flags = \
0605 __cpu_to_le32(__le32_to_cpu(su->su_flags) & \
0606 ~(1UL << NILFS_SEGMENT_USAGE_##flag)); \
0607 } \
0608 static inline int \
0609 nilfs_segment_usage_##name(const struct nilfs_segment_usage *su) \
0610 { \
0611 return !!(__le32_to_cpu(su->su_flags) & \
0612 (1UL << NILFS_SEGMENT_USAGE_##flag)); \
0613 }
0614
0615 NILFS_SEGMENT_USAGE_FNS(ACTIVE, active)
0616 NILFS_SEGMENT_USAGE_FNS(DIRTY, dirty)
0617 NILFS_SEGMENT_USAGE_FNS(ERROR, error)
0618
0619 static inline void
0620 nilfs_segment_usage_set_clean(struct nilfs_segment_usage *su)
0621 {
0622 su->su_lastmod = __cpu_to_le64(0);
0623 su->su_nblocks = __cpu_to_le32(0);
0624 su->su_flags = __cpu_to_le32(0);
0625 }
0626
0627 static inline int
0628 nilfs_segment_usage_clean(const struct nilfs_segment_usage *su)
0629 {
0630 return !__le32_to_cpu(su->su_flags);
0631 }
0632
0633
0634
0635
0636
0637
0638
0639 struct nilfs_sufile_header {
0640 __le64 sh_ncleansegs;
0641 __le64 sh_ndirtysegs;
0642 __le64 sh_last_alloc;
0643
0644 };
0645
0646 #define NILFS_SUFILE_FIRST_SEGMENT_USAGE_OFFSET \
0647 ((sizeof(struct nilfs_sufile_header) + \
0648 sizeof(struct nilfs_segment_usage) - 1) / \
0649 sizeof(struct nilfs_segment_usage))
0650
0651 #endif