Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: LGPL-2.1+ WITH Linux-syscall-note */
0002 /*
0003  * nilfs2_ondisk.h - NILFS2 on-disk structures
0004  *
0005  * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
0006  *
0007  * This program is free software; you can redistribute it and/or modify
0008  * it under the terms of the GNU Lesser General Public License as published
0009  * by the Free Software Foundation; either version 2.1 of the License, or
0010  * (at your option) any later version.
0011  */
0012 /*
0013  *  linux/include/linux/ext2_fs.h
0014  *
0015  * Copyright (C) 1992, 1993, 1994, 1995
0016  * Remy Card (card@masi.ibp.fr)
0017  * Laboratoire MASI - Institut Blaise Pascal
0018  * Universite Pierre et Marie Curie (Paris VI)
0019  *
0020  *  from
0021  *
0022  *  linux/include/linux/minix_fs.h
0023  *
0024  *  Copyright (C) 1991, 1992  Linus Torvalds
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  * struct nilfs_inode - structure of an inode on disk
0038  * @i_blocks: blocks count
0039  * @i_size: size in bytes
0040  * @i_ctime: creation time (seconds)
0041  * @i_mtime: modification time (seconds)
0042  * @i_ctime_nsec: creation time (nano seconds)
0043  * @i_mtime_nsec: modification time (nano seconds)
0044  * @i_uid: user id
0045  * @i_gid: group id
0046  * @i_mode: file mode
0047  * @i_links_count: links count
0048  * @i_flags: file flags
0049  * @i_bmap: block mapping
0050  * @i_xattr: extended attributes
0051  * @i_generation: file generation (for NFS)
0052  * @i_pad: padding
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  * struct nilfs_super_root - structure of super root
0077  * @sr_sum: check sum
0078  * @sr_bytes: byte count of the structure
0079  * @sr_flags: flags (reserved)
0080  * @sr_nongc_ctime: write time of the last segment not for cleaner operation
0081  * @sr_dat: DAT file inode
0082  * @sr_cpfile: checkpoint file inode
0083  * @sr_sufile: segment usage file inode
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  * Maximal mount counts
0105  */
0106 #define NILFS_DFL_MAX_MNT_COUNT     50      /* 50 mounts */
0107 
0108 /*
0109  * File system states (sbp->s_state, nilfs->ns_mount_state)
0110  */
0111 #define NILFS_VALID_FS          0x0001  /* Unmounted cleanly */
0112 #define NILFS_ERROR_FS          0x0002  /* Errors detected */
0113 #define NILFS_RESIZE_FS         0x0004  /* Resize required */
0114 
0115 /*
0116  * Mount flags (sbi->s_mount_opt)
0117  */
0118 #define NILFS_MOUNT_ERROR_MODE      0x0070  /* Error mode mask */
0119 #define NILFS_MOUNT_ERRORS_CONT     0x0010  /* Continue on errors */
0120 #define NILFS_MOUNT_ERRORS_RO       0x0020  /* Remount fs ro on errors */
0121 #define NILFS_MOUNT_ERRORS_PANIC    0x0040  /* Panic on errors */
0122 #define NILFS_MOUNT_BARRIER     0x1000  /* Use block barriers */
0123 #define NILFS_MOUNT_STRICT_ORDER    0x2000  /*
0124                          * Apply strict in-order
0125                          * semantics also for data
0126                          */
0127 #define NILFS_MOUNT_NORECOVERY      0x4000  /*
0128                          * Disable write access during
0129                          * mount-time recovery
0130                          */
0131 #define NILFS_MOUNT_DISCARD     0x8000  /* Issue DISCARD requests */
0132 
0133 
0134 /**
0135  * struct nilfs_super_block - structure of super block on disk
0136  */
0137 struct nilfs_super_block {
0138 /*00*/  __le32  s_rev_level;        /* Revision level */
0139     __le16  s_minor_rev_level;  /* minor revision level */
0140     __le16  s_magic;        /* Magic signature */
0141 
0142     __le16  s_bytes;        /*
0143                      * Bytes count of CRC calculation
0144                      * for this structure. s_reserved
0145                      * is excluded.
0146                      */
0147     __le16  s_flags;        /* flags */
0148     __le32  s_crc_seed;     /* Seed value of CRC calculation */
0149 /*10*/  __le32  s_sum;          /* Check sum of super block */
0150 
0151     __le32  s_log_block_size;   /*
0152                      * Block size represented as follows
0153                      * blocksize =
0154                      *     1 << (s_log_block_size + 10)
0155                      */
0156     __le64  s_nsegments;        /* Number of segments in filesystem */
0157 /*20*/  __le64  s_dev_size;     /* block device size in bytes */
0158     __le64  s_first_data_block; /* 1st seg disk block number */
0159 /*30*/  __le32  s_blocks_per_segment;   /* number of blocks per full segment */
0160     __le32  s_r_segments_percentage; /* Reserved segments percentage */
0161 
0162     __le64  s_last_cno;     /* Last checkpoint number */
0163 /*40*/  __le64  s_last_pseg;        /* disk block addr pseg written last */
0164     __le64  s_last_seq;             /* seq. number of seg written last */
0165 /*50*/  __le64  s_free_blocks_count;    /* Free blocks count */
0166 
0167     __le64  s_ctime;        /*
0168                      * Creation time (execution time of
0169                      * newfs)
0170                      */
0171 /*60*/  __le64  s_mtime;        /* Mount time */
0172     __le64  s_wtime;        /* Write time */
0173 /*70*/  __le16  s_mnt_count;        /* Mount count */
0174     __le16  s_max_mnt_count;    /* Maximal mount count */
0175     __le16  s_state;        /* File system state */
0176     __le16  s_errors;       /* Behaviour when detecting errors */
0177     __le64  s_lastcheck;        /* time of last check */
0178 
0179 /*80*/  __le32  s_checkinterval;    /* max. time between checks */
0180     __le32  s_creator_os;       /* OS */
0181     __le16  s_def_resuid;       /* Default uid for reserved blocks */
0182     __le16  s_def_resgid;       /* Default gid for reserved blocks */
0183     __le32  s_first_ino;        /* First non-reserved inode */
0184 
0185 /*90*/  __le16  s_inode_size;       /* Size of an inode */
0186     __le16  s_dat_entry_size;       /* Size of a dat entry */
0187     __le16  s_checkpoint_size;      /* Size of a checkpoint */
0188     __le16  s_segment_usage_size;   /* Size of a segment usage */
0189 
0190 /*98*/  __u8    s_uuid[16];     /* 128-bit uuid for volume */
0191 /*A8*/  char    s_volume_name[80];  /* volume name */
0192 
0193 /*F8*/  __le32  s_c_interval;           /* Commit interval of segment */
0194     __le32  s_c_block_max;          /*
0195                      * Threshold of data amount for
0196                      * the segment construction
0197                      */
0198 /*100*/ __le64  s_feature_compat;   /* Compatible feature set */
0199     __le64  s_feature_compat_ro;    /* Read-only compatible feature set */
0200     __le64  s_feature_incompat; /* Incompatible feature set */
0201     __u32   s_reserved[186];    /* padding to the end of the block */
0202 };
0203 
0204 /*
0205  * Codes for operating systems
0206  */
0207 #define NILFS_OS_LINUX      0
0208 /* Codes from 1 to 4 are reserved to keep compatibility with ext2 creator-OS */
0209 
0210 /*
0211  * Revision levels
0212  */
0213 #define NILFS_CURRENT_REV   2   /* current major revision */
0214 #define NILFS_MINOR_REV     0   /* minor revision */
0215 #define NILFS_MIN_SUPP_REV  2   /* minimum supported revision */
0216 
0217 /*
0218  * Feature set definitions
0219  *
0220  * If there is a bit set in the incompatible feature set that the kernel
0221  * doesn't know about, it should refuse to mount the filesystem.
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  * Bytes count of super_block for CRC-calculation
0231  */
0232 #define NILFS_SB_BYTES  \
0233     ((long)&((struct nilfs_super_block *)0)->s_reserved)
0234 
0235 /*
0236  * Special inode number
0237  */
0238 #define NILFS_ROOT_INO      2   /* Root file inode */
0239 #define NILFS_DAT_INO       3   /* DAT file */
0240 #define NILFS_CPFILE_INO    4   /* checkpoint file */
0241 #define NILFS_SUFILE_INO    5   /* segment usage file */
0242 #define NILFS_IFILE_INO     6   /* ifile */
0243 #define NILFS_ATIME_INO     7   /* Atime file (reserved) */
0244 #define NILFS_XATTR_INO     8   /* Xattribute file (reserved) */
0245 #define NILFS_SKETCH_INO    10  /* Sketch file */
0246 #define NILFS_USER_INO      11  /* Fisrt user's file inode number */
0247 
0248 #define NILFS_SB_OFFSET_BYTES   1024    /* byte offset of nilfs superblock */
0249 
0250 #define NILFS_SEG_MIN_BLOCKS    16  /*
0251                      * Minimum number of blocks in
0252                      * a full segment
0253                      */
0254 #define NILFS_PSEG_MIN_BLOCKS   2   /*
0255                      * Minimum number of blocks in
0256                      * a partial segment
0257                      */
0258 #define NILFS_MIN_NRSVSEGS  8   /*
0259                      * Minimum number of reserved
0260                      * segments
0261                      */
0262 
0263 /*
0264  * We call DAT, cpfile, and sufile root metadata files.  Inodes of
0265  * these files are written in super root block instead of ifile, and
0266  * garbage collector doesn't keep any past versions of these files.
0267  */
0268 #define NILFS_ROOT_METADATA_FILE(ino) \
0269     ((ino) >= NILFS_DAT_INO && (ino) <= NILFS_SUFILE_INO)
0270 
0271 /*
0272  * bytes offset of secondary super block
0273  */
0274 #define NILFS_SB2_OFFSET_BYTES(devsize) ((((devsize) >> 12) - 1) << 12)
0275 
0276 /*
0277  * Maximal count of links to a file
0278  */
0279 #define NILFS_LINK_MAX      32000
0280 
0281 /*
0282  * Structure of a directory entry
0283  *  (Same as ext2)
0284  */
0285 
0286 #define NILFS_NAME_LEN 255
0287 
0288 /*
0289  * Block size limitations
0290  */
0291 #define NILFS_MIN_BLOCK_SIZE        1024
0292 #define NILFS_MAX_BLOCK_SIZE        65536
0293 
0294 /*
0295  * The new version of the directory entry.  Since V0 structures are
0296  * stored in intel byte order, and the name_len field could never be
0297  * bigger than 255 chars, it's safe to reclaim the extra byte for the
0298  * file_type field.
0299  */
0300 struct nilfs_dir_entry {
0301     __le64  inode;          /* Inode number */
0302     __le16  rec_len;        /* Directory entry length */
0303     __u8    name_len;       /* Name length */
0304     __u8    file_type;      /* Dir entry type (file, dir, etc) */
0305     char    name[NILFS_NAME_LEN];   /* File name */
0306     char    pad;
0307 };
0308 
0309 /*
0310  * NILFS directory file types.  Only the low 3 bits are used.  The
0311  * other bits are reserved for now.
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  * NILFS_DIR_PAD defines the directory entries boundaries
0327  *
0328  * NOTE: It must be a multiple of 8
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  * struct nilfs_finfo - file information
0338  * @fi_ino: inode number
0339  * @fi_cno: checkpoint number
0340  * @fi_nblocks: number of blocks (including intermediate blocks)
0341  * @fi_ndatablk: number of file data blocks
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  * struct nilfs_binfo_v - information on a data block (except DAT)
0352  * @bi_vblocknr: virtual block number
0353  * @bi_blkoff: block offset
0354  */
0355 struct nilfs_binfo_v {
0356     __le64 bi_vblocknr;
0357     __le64 bi_blkoff;
0358 };
0359 
0360 /**
0361  * struct nilfs_binfo_dat - information on a DAT node block
0362  * @bi_blkoff: block offset
0363  * @bi_level: level
0364  * @bi_pad: padding
0365  */
0366 struct nilfs_binfo_dat {
0367     __le64 bi_blkoff;
0368     __u8 bi_level;
0369     __u8 bi_pad[7];
0370 };
0371 
0372 /**
0373  * union nilfs_binfo: block information
0374  * @bi_v: nilfs_binfo_v structure
0375  * @bi_dat: nilfs_binfo_dat structure
0376  */
0377 union nilfs_binfo {
0378     struct nilfs_binfo_v bi_v;
0379     struct nilfs_binfo_dat bi_dat;
0380 };
0381 
0382 /**
0383  * struct nilfs_segment_summary - segment summary header
0384  * @ss_datasum: checksum of data
0385  * @ss_sumsum: checksum of segment summary
0386  * @ss_magic: magic number
0387  * @ss_bytes: size of this structure in bytes
0388  * @ss_flags: flags
0389  * @ss_seq: sequence number
0390  * @ss_create: creation timestamp
0391  * @ss_next: next segment
0392  * @ss_nblocks: number of blocks
0393  * @ss_nfinfo: number of finfo structures
0394  * @ss_sumbytes: total size of segment summary in bytes
0395  * @ss_pad: padding
0396  * @ss_cno: checkpoint number
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     /* array of finfo structures */
0413 };
0414 
0415 #define NILFS_SEGSUM_MAGIC  0x1eaffa11  /* segment summary magic number */
0416 
0417 /*
0418  * Segment summary flags
0419  */
0420 #define NILFS_SS_LOGBGN 0x0001  /* begins a logical segment */
0421 #define NILFS_SS_LOGEND 0x0002  /* ends a logical segment */
0422 #define NILFS_SS_SR     0x0004  /* has super root */
0423 #define NILFS_SS_SYNDT  0x0008  /* includes data only updates */
0424 #define NILFS_SS_GC     0x0010  /* segment written for cleaner operation */
0425 
0426 /**
0427  * struct nilfs_btree_node - header of B-tree node block
0428  * @bn_flags: flags
0429  * @bn_level: level
0430  * @bn_nchildren: number of children
0431  * @bn_pad: padding
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 /* flags */
0441 #define NILFS_BTREE_NODE_ROOT   0x01
0442 
0443 /* level */
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  /* Max level (exclusive) */
0447 
0448 /**
0449  * struct nilfs_direct_node - header of built-in bmap array
0450  * @dn_flags: flags
0451  * @dn_pad: padding
0452  */
0453 struct nilfs_direct_node {
0454     __u8 dn_flags;
0455     __u8 pad[7];
0456 };
0457 
0458 /**
0459  * struct nilfs_palloc_group_desc - block group descriptor
0460  * @pg_nfrees: number of free entries in block group
0461  */
0462 struct nilfs_palloc_group_desc {
0463     __le32 pg_nfrees;
0464 };
0465 
0466 /**
0467  * struct nilfs_dat_entry - disk address translation entry
0468  * @de_blocknr: block number
0469  * @de_start: start checkpoint number
0470  * @de_end: end checkpoint number
0471  * @de_rsv: reserved for future use
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  * struct nilfs_snapshot_list - snapshot list
0484  * @ssl_next: next checkpoint number on snapshot list
0485  * @ssl_prev: previous checkpoint number on snapshot list
0486  */
0487 struct nilfs_snapshot_list {
0488     __le64 ssl_next;
0489     __le64 ssl_prev;
0490 };
0491 
0492 /**
0493  * struct nilfs_checkpoint - checkpoint structure
0494  * @cp_flags: flags
0495  * @cp_checkpoints_count: checkpoints count in a block
0496  * @cp_snapshot_list: snapshot list
0497  * @cp_cno: checkpoint number
0498  * @cp_create: creation timestamp
0499  * @cp_nblk_inc: number of blocks incremented by this checkpoint
0500  * @cp_inodes_count: inodes count
0501  * @cp_blocks_count: blocks count
0502  * @cp_ifile_inode: inode of ifile
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      * Do not change the byte offset of ifile inode.
0516      * To keep the compatibility of the disk format,
0517      * additional fields should be added behind cp_ifile_inode.
0518      */
0519     struct nilfs_inode cp_ifile_inode;
0520 };
0521 
0522 #define NILFS_MIN_CHECKPOINT_SIZE   (64 + NILFS_MIN_INODE_SIZE)
0523 
0524 /* checkpoint flags */
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  * struct nilfs_cpfile_header - checkpoint file header
0558  * @ch_ncheckpoints: number of checkpoints
0559  * @ch_nsnapshots: number of snapshots
0560  * @ch_snapshot_list: snapshot list
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  * struct nilfs_segment_usage - segment usage
0575  * @su_lastmod: last modified timestamp
0576  * @su_nblocks: number of blocks in segment
0577  * @su_flags: flags
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 /* segment usage flag */
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  * struct nilfs_sufile_header - segment usage file header
0635  * @sh_ncleansegs: number of clean segments
0636  * @sh_ndirtysegs: number of dirty segments
0637  * @sh_last_alloc: last allocated segment number
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  /* _LINUX_NILFS2_ONDISK_H */