Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /**
0003  * include/linux/f2fs_fs.h
0004  *
0005  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
0006  *             http://www.samsung.com/
0007  */
0008 #ifndef _LINUX_F2FS_FS_H
0009 #define _LINUX_F2FS_FS_H
0010 
0011 #include <linux/pagemap.h>
0012 #include <linux/types.h>
0013 
0014 #define F2FS_SUPER_OFFSET       1024    /* byte-size offset */
0015 #define F2FS_MIN_LOG_SECTOR_SIZE    9   /* 9 bits for 512 bytes */
0016 #define F2FS_MAX_LOG_SECTOR_SIZE    12  /* 12 bits for 4096 bytes */
0017 #define F2FS_LOG_SECTORS_PER_BLOCK  3   /* log number for sector/blk */
0018 #define F2FS_BLKSIZE            4096    /* support only 4KB block */
0019 #define F2FS_BLKSIZE_BITS       12  /* bits for F2FS_BLKSIZE */
0020 #define F2FS_MAX_EXTENSION      64  /* # of extension entries */
0021 #define F2FS_EXTENSION_LEN      8   /* max size of extension */
0022 #define F2FS_BLK_ALIGN(x)   (((x) + F2FS_BLKSIZE - 1) >> F2FS_BLKSIZE_BITS)
0023 
0024 #define NULL_ADDR       ((block_t)0)    /* used as block_t addresses */
0025 #define NEW_ADDR        ((block_t)-1)   /* used as block_t addresses */
0026 #define COMPRESS_ADDR       ((block_t)-2)   /* used as compressed data flag */
0027 
0028 #define F2FS_BYTES_TO_BLK(bytes)    ((bytes) >> F2FS_BLKSIZE_BITS)
0029 #define F2FS_BLK_TO_BYTES(blk)      ((blk) << F2FS_BLKSIZE_BITS)
0030 
0031 /* 0, 1(node nid), 2(meta nid) are reserved node id */
0032 #define F2FS_RESERVED_NODE_NUM      3
0033 
0034 #define F2FS_ROOT_INO(sbi)  ((sbi)->root_ino_num)
0035 #define F2FS_NODE_INO(sbi)  ((sbi)->node_ino_num)
0036 #define F2FS_META_INO(sbi)  ((sbi)->meta_ino_num)
0037 #define F2FS_COMPRESS_INO(sbi)  (NM_I(sbi)->max_nid)
0038 
0039 #define F2FS_MAX_QUOTAS     3
0040 
0041 #define F2FS_ENC_UTF8_12_1  1
0042 
0043 #define F2FS_IO_SIZE(sbi)   (1 << F2FS_OPTION(sbi).write_io_size_bits) /* Blocks */
0044 #define F2FS_IO_SIZE_KB(sbi)    (1 << (F2FS_OPTION(sbi).write_io_size_bits + 2)) /* KB */
0045 #define F2FS_IO_SIZE_BYTES(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 12)) /* B */
0046 #define F2FS_IO_SIZE_BITS(sbi)  (F2FS_OPTION(sbi).write_io_size_bits) /* power of 2 */
0047 #define F2FS_IO_SIZE_MASK(sbi)  (F2FS_IO_SIZE(sbi) - 1)
0048 #define F2FS_IO_ALIGNED(sbi)    (F2FS_IO_SIZE(sbi) > 1)
0049 
0050 /* This flag is used by node and meta inodes, and by recovery */
0051 #define GFP_F2FS_ZERO       (GFP_NOFS | __GFP_ZERO)
0052 
0053 /*
0054  * For further optimization on multi-head logs, on-disk layout supports maximum
0055  * 16 logs by default. The number, 16, is expected to cover all the cases
0056  * enoughly. The implementaion currently uses no more than 6 logs.
0057  * Half the logs are used for nodes, and the other half are used for data.
0058  */
0059 #define MAX_ACTIVE_LOGS 16
0060 #define MAX_ACTIVE_NODE_LOGS    8
0061 #define MAX_ACTIVE_DATA_LOGS    8
0062 
0063 #define VERSION_LEN 256
0064 #define MAX_VOLUME_NAME     512
0065 #define MAX_PATH_LEN        64
0066 #define MAX_DEVICES     8
0067 
0068 /*
0069  * For superblock
0070  */
0071 struct f2fs_device {
0072     __u8 path[MAX_PATH_LEN];
0073     __le32 total_segments;
0074 } __packed;
0075 
0076 struct f2fs_super_block {
0077     __le32 magic;           /* Magic Number */
0078     __le16 major_ver;       /* Major Version */
0079     __le16 minor_ver;       /* Minor Version */
0080     __le32 log_sectorsize;      /* log2 sector size in bytes */
0081     __le32 log_sectors_per_block;   /* log2 # of sectors per block */
0082     __le32 log_blocksize;       /* log2 block size in bytes */
0083     __le32 log_blocks_per_seg;  /* log2 # of blocks per segment */
0084     __le32 segs_per_sec;        /* # of segments per section */
0085     __le32 secs_per_zone;       /* # of sections per zone */
0086     __le32 checksum_offset;     /* checksum offset inside super block */
0087     __le64 block_count;     /* total # of user blocks */
0088     __le32 section_count;       /* total # of sections */
0089     __le32 segment_count;       /* total # of segments */
0090     __le32 segment_count_ckpt;  /* # of segments for checkpoint */
0091     __le32 segment_count_sit;   /* # of segments for SIT */
0092     __le32 segment_count_nat;   /* # of segments for NAT */
0093     __le32 segment_count_ssa;   /* # of segments for SSA */
0094     __le32 segment_count_main;  /* # of segments for main area */
0095     __le32 segment0_blkaddr;    /* start block address of segment 0 */
0096     __le32 cp_blkaddr;      /* start block address of checkpoint */
0097     __le32 sit_blkaddr;     /* start block address of SIT */
0098     __le32 nat_blkaddr;     /* start block address of NAT */
0099     __le32 ssa_blkaddr;     /* start block address of SSA */
0100     __le32 main_blkaddr;        /* start block address of main area */
0101     __le32 root_ino;        /* root inode number */
0102     __le32 node_ino;        /* node inode number */
0103     __le32 meta_ino;        /* meta inode number */
0104     __u8 uuid[16];          /* 128-bit uuid for volume */
0105     __le16 volume_name[MAX_VOLUME_NAME];    /* volume name */
0106     __le32 extension_count;     /* # of extensions below */
0107     __u8 extension_list[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN];/* extension array */
0108     __le32 cp_payload;
0109     __u8 version[VERSION_LEN];  /* the kernel version */
0110     __u8 init_version[VERSION_LEN]; /* the initial kernel version */
0111     __le32 feature;         /* defined features */
0112     __u8 encryption_level;      /* versioning level for encryption */
0113     __u8 encrypt_pw_salt[16];   /* Salt used for string2key algorithm */
0114     struct f2fs_device devs[MAX_DEVICES];   /* device list */
0115     __le32 qf_ino[F2FS_MAX_QUOTAS]; /* quota inode numbers */
0116     __u8 hot_ext_count;     /* # of hot file extension */
0117     __le16  s_encoding;     /* Filename charset encoding */
0118     __le16  s_encoding_flags;   /* Filename charset encoding flags */
0119     __u8 reserved[306];     /* valid reserved region */
0120     __le32 crc;         /* checksum of superblock */
0121 } __packed;
0122 
0123 /*
0124  * For checkpoint
0125  */
0126 #define CP_RESIZEFS_FLAG        0x00004000
0127 #define CP_DISABLED_QUICK_FLAG      0x00002000
0128 #define CP_DISABLED_FLAG        0x00001000
0129 #define CP_QUOTA_NEED_FSCK_FLAG     0x00000800
0130 #define CP_LARGE_NAT_BITMAP_FLAG    0x00000400
0131 #define CP_NOCRC_RECOVERY_FLAG  0x00000200
0132 #define CP_TRIMMED_FLAG     0x00000100
0133 #define CP_NAT_BITS_FLAG    0x00000080
0134 #define CP_CRC_RECOVERY_FLAG    0x00000040
0135 #define CP_FASTBOOT_FLAG    0x00000020
0136 #define CP_FSCK_FLAG        0x00000010
0137 #define CP_ERROR_FLAG       0x00000008
0138 #define CP_COMPACT_SUM_FLAG 0x00000004
0139 #define CP_ORPHAN_PRESENT_FLAG  0x00000002
0140 #define CP_UMOUNT_FLAG      0x00000001
0141 
0142 #define F2FS_CP_PACKS       2   /* # of checkpoint packs */
0143 
0144 struct f2fs_checkpoint {
0145     __le64 checkpoint_ver;      /* checkpoint block version number */
0146     __le64 user_block_count;    /* # of user blocks */
0147     __le64 valid_block_count;   /* # of valid blocks in main area */
0148     __le32 rsvd_segment_count;  /* # of reserved segments for gc */
0149     __le32 overprov_segment_count;  /* # of overprovision segments */
0150     __le32 free_segment_count;  /* # of free segments in main area */
0151 
0152     /* information of current node segments */
0153     __le32 cur_node_segno[MAX_ACTIVE_NODE_LOGS];
0154     __le16 cur_node_blkoff[MAX_ACTIVE_NODE_LOGS];
0155     /* information of current data segments */
0156     __le32 cur_data_segno[MAX_ACTIVE_DATA_LOGS];
0157     __le16 cur_data_blkoff[MAX_ACTIVE_DATA_LOGS];
0158     __le32 ckpt_flags;      /* Flags : umount and journal_present */
0159     __le32 cp_pack_total_block_count;   /* total # of one cp pack */
0160     __le32 cp_pack_start_sum;   /* start block number of data summary */
0161     __le32 valid_node_count;    /* Total number of valid nodes */
0162     __le32 valid_inode_count;   /* Total number of valid inodes */
0163     __le32 next_free_nid;       /* Next free node number */
0164     __le32 sit_ver_bitmap_bytesize; /* Default value 64 */
0165     __le32 nat_ver_bitmap_bytesize; /* Default value 256 */
0166     __le32 checksum_offset;     /* checksum offset inside cp block */
0167     __le64 elapsed_time;        /* mounted time */
0168     /* allocation type of current segment */
0169     unsigned char alloc_type[MAX_ACTIVE_LOGS];
0170 
0171     /* SIT and NAT version bitmap */
0172     unsigned char sit_nat_version_bitmap[];
0173 } __packed;
0174 
0175 #define CP_CHKSUM_OFFSET    4092    /* default chksum offset in checkpoint */
0176 #define CP_MIN_CHKSUM_OFFSET                        \
0177     (offsetof(struct f2fs_checkpoint, sit_nat_version_bitmap))
0178 
0179 /*
0180  * For orphan inode management
0181  */
0182 #define F2FS_ORPHANS_PER_BLOCK  1020
0183 
0184 #define GET_ORPHAN_BLOCKS(n)    (((n) + F2FS_ORPHANS_PER_BLOCK - 1) / \
0185                     F2FS_ORPHANS_PER_BLOCK)
0186 
0187 struct f2fs_orphan_block {
0188     __le32 ino[F2FS_ORPHANS_PER_BLOCK]; /* inode numbers */
0189     __le32 reserved;    /* reserved */
0190     __le16 blk_addr;    /* block index in current CP */
0191     __le16 blk_count;   /* Number of orphan inode blocks in CP */
0192     __le32 entry_count; /* Total number of orphan nodes in current CP */
0193     __le32 check_sum;   /* CRC32 for orphan inode block */
0194 } __packed;
0195 
0196 /*
0197  * For NODE structure
0198  */
0199 struct f2fs_extent {
0200     __le32 fofs;        /* start file offset of the extent */
0201     __le32 blk;     /* start block address of the extent */
0202     __le32 len;     /* length of the extent */
0203 } __packed;
0204 
0205 #define F2FS_NAME_LEN       255
0206 /* 200 bytes for inline xattrs by default */
0207 #define DEFAULT_INLINE_XATTR_ADDRS  50
0208 #define DEF_ADDRS_PER_INODE 923 /* Address Pointers in an Inode */
0209 #define CUR_ADDRS_PER_INODE(inode)  (DEF_ADDRS_PER_INODE - \
0210                     get_extra_isize(inode))
0211 #define DEF_NIDS_PER_INODE  5   /* Node IDs in an Inode */
0212 #define ADDRS_PER_INODE(inode)  addrs_per_inode(inode)
0213 #define DEF_ADDRS_PER_BLOCK 1018    /* Address Pointers in a Direct Block */
0214 #define ADDRS_PER_BLOCK(inode)  addrs_per_block(inode)
0215 #define NIDS_PER_BLOCK      1018    /* Node IDs in an Indirect Block */
0216 
0217 #define ADDRS_PER_PAGE(page, inode) \
0218     (IS_INODE(page) ? ADDRS_PER_INODE(inode) : ADDRS_PER_BLOCK(inode))
0219 
0220 #define NODE_DIR1_BLOCK     (DEF_ADDRS_PER_INODE + 1)
0221 #define NODE_DIR2_BLOCK     (DEF_ADDRS_PER_INODE + 2)
0222 #define NODE_IND1_BLOCK     (DEF_ADDRS_PER_INODE + 3)
0223 #define NODE_IND2_BLOCK     (DEF_ADDRS_PER_INODE + 4)
0224 #define NODE_DIND_BLOCK     (DEF_ADDRS_PER_INODE + 5)
0225 
0226 #define F2FS_INLINE_XATTR   0x01    /* file inline xattr flag */
0227 #define F2FS_INLINE_DATA    0x02    /* file inline data flag */
0228 #define F2FS_INLINE_DENTRY  0x04    /* file inline dentry flag */
0229 #define F2FS_DATA_EXIST     0x08    /* file inline data exist flag */
0230 #define F2FS_INLINE_DOTS    0x10    /* file having implicit dot dentries */
0231 #define F2FS_EXTRA_ATTR     0x20    /* file having extra attribute */
0232 #define F2FS_PIN_FILE       0x40    /* file should not be gced */
0233 #define F2FS_COMPRESS_RELEASED  0x80    /* file released compressed blocks */
0234 
0235 struct f2fs_inode {
0236     __le16 i_mode;          /* file mode */
0237     __u8 i_advise;          /* file hints */
0238     __u8 i_inline;          /* file inline flags */
0239     __le32 i_uid;           /* user ID */
0240     __le32 i_gid;           /* group ID */
0241     __le32 i_links;         /* links count */
0242     __le64 i_size;          /* file size in bytes */
0243     __le64 i_blocks;        /* file size in blocks */
0244     __le64 i_atime;         /* access time */
0245     __le64 i_ctime;         /* change time */
0246     __le64 i_mtime;         /* modification time */
0247     __le32 i_atime_nsec;        /* access time in nano scale */
0248     __le32 i_ctime_nsec;        /* change time in nano scale */
0249     __le32 i_mtime_nsec;        /* modification time in nano scale */
0250     __le32 i_generation;        /* file version (for NFS) */
0251     union {
0252         __le32 i_current_depth; /* only for directory depth */
0253         __le16 i_gc_failures;   /*
0254                      * # of gc failures on pinned file.
0255                      * only for regular files.
0256                      */
0257     };
0258     __le32 i_xattr_nid;     /* nid to save xattr */
0259     __le32 i_flags;         /* file attributes */
0260     __le32 i_pino;          /* parent inode number */
0261     __le32 i_namelen;       /* file name length */
0262     __u8 i_name[F2FS_NAME_LEN]; /* file name for SPOR */
0263     __u8 i_dir_level;       /* dentry_level for large dir */
0264 
0265     struct f2fs_extent i_ext;   /* caching a largest extent */
0266 
0267     union {
0268         struct {
0269             __le16 i_extra_isize;   /* extra inode attribute size */
0270             __le16 i_inline_xattr_size; /* inline xattr size, unit: 4 bytes */
0271             __le32 i_projid;    /* project id */
0272             __le32 i_inode_checksum;/* inode meta checksum */
0273             __le64 i_crtime;    /* creation time */
0274             __le32 i_crtime_nsec;   /* creation time in nano scale */
0275             __le64 i_compr_blocks;  /* # of compressed blocks */
0276             __u8 i_compress_algorithm;  /* compress algorithm */
0277             __u8 i_log_cluster_size;    /* log of cluster size */
0278             __le16 i_compress_flag;     /* compress flag */
0279                         /* 0 bit: chksum flag
0280                          * [10,15] bits: compress level
0281                          */
0282             __le32 i_extra_end[0];  /* for attribute size calculation */
0283         } __packed;
0284         __le32 i_addr[DEF_ADDRS_PER_INODE]; /* Pointers to data blocks */
0285     };
0286     __le32 i_nid[DEF_NIDS_PER_INODE];   /* direct(2), indirect(2),
0287                         double_indirect(1) node id */
0288 } __packed;
0289 
0290 struct direct_node {
0291     __le32 addr[DEF_ADDRS_PER_BLOCK];   /* array of data block address */
0292 } __packed;
0293 
0294 struct indirect_node {
0295     __le32 nid[NIDS_PER_BLOCK]; /* array of data block address */
0296 } __packed;
0297 
0298 enum {
0299     COLD_BIT_SHIFT = 0,
0300     FSYNC_BIT_SHIFT,
0301     DENT_BIT_SHIFT,
0302     OFFSET_BIT_SHIFT
0303 };
0304 
0305 #define OFFSET_BIT_MASK     (0x07)  /* (0x01 << OFFSET_BIT_SHIFT) - 1 */
0306 
0307 struct node_footer {
0308     __le32 nid;     /* node id */
0309     __le32 ino;     /* inode number */
0310     __le32 flag;        /* include cold/fsync/dentry marks and offset */
0311     __le64 cp_ver;      /* checkpoint version */
0312     __le32 next_blkaddr;    /* next node page block address */
0313 } __packed;
0314 
0315 struct f2fs_node {
0316     /* can be one of three types: inode, direct, and indirect types */
0317     union {
0318         struct f2fs_inode i;
0319         struct direct_node dn;
0320         struct indirect_node in;
0321     };
0322     struct node_footer footer;
0323 } __packed;
0324 
0325 /*
0326  * For NAT entries
0327  */
0328 #define NAT_ENTRY_PER_BLOCK (PAGE_SIZE / sizeof(struct f2fs_nat_entry))
0329 
0330 struct f2fs_nat_entry {
0331     __u8 version;       /* latest version of cached nat entry */
0332     __le32 ino;     /* inode number */
0333     __le32 block_addr;  /* block address */
0334 } __packed;
0335 
0336 struct f2fs_nat_block {
0337     struct f2fs_nat_entry entries[NAT_ENTRY_PER_BLOCK];
0338 } __packed;
0339 
0340 /*
0341  * For SIT entries
0342  *
0343  * Each segment is 2MB in size by default so that a bitmap for validity of
0344  * there-in blocks should occupy 64 bytes, 512 bits.
0345  * Not allow to change this.
0346  */
0347 #define SIT_VBLOCK_MAP_SIZE 64
0348 #define SIT_ENTRY_PER_BLOCK (PAGE_SIZE / sizeof(struct f2fs_sit_entry))
0349 
0350 /*
0351  * F2FS uses 4 bytes to represent block address. As a result, supported size of
0352  * disk is 16 TB and it equals to 16 * 1024 * 1024 / 2 segments.
0353  */
0354 #define F2FS_MAX_SEGMENT       ((16 * 1024 * 1024) / 2)
0355 
0356 /*
0357  * Note that f2fs_sit_entry->vblocks has the following bit-field information.
0358  * [15:10] : allocation type such as CURSEG_XXXX_TYPE
0359  * [9:0] : valid block count
0360  */
0361 #define SIT_VBLOCKS_SHIFT   10
0362 #define SIT_VBLOCKS_MASK    ((1 << SIT_VBLOCKS_SHIFT) - 1)
0363 #define GET_SIT_VBLOCKS(raw_sit)                \
0364     (le16_to_cpu((raw_sit)->vblocks) & SIT_VBLOCKS_MASK)
0365 #define GET_SIT_TYPE(raw_sit)                   \
0366     ((le16_to_cpu((raw_sit)->vblocks) & ~SIT_VBLOCKS_MASK)  \
0367      >> SIT_VBLOCKS_SHIFT)
0368 
0369 struct f2fs_sit_entry {
0370     __le16 vblocks;             /* reference above */
0371     __u8 valid_map[SIT_VBLOCK_MAP_SIZE];    /* bitmap for valid blocks */
0372     __le64 mtime;               /* segment age for cleaning */
0373 } __packed;
0374 
0375 struct f2fs_sit_block {
0376     struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK];
0377 } __packed;
0378 
0379 /*
0380  * For segment summary
0381  *
0382  * One summary block contains exactly 512 summary entries, which represents
0383  * exactly 2MB segment by default. Not allow to change the basic units.
0384  *
0385  * NOTE: For initializing fields, you must use set_summary
0386  *
0387  * - If data page, nid represents dnode's nid
0388  * - If node page, nid represents the node page's nid.
0389  *
0390  * The ofs_in_node is used by only data page. It represents offset
0391  * from node's page's beginning to get a data block address.
0392  * ex) data_blkaddr = (block_t)(nodepage_start_address + ofs_in_node)
0393  */
0394 #define ENTRIES_IN_SUM      512
0395 #define SUMMARY_SIZE        (7) /* sizeof(struct summary) */
0396 #define SUM_FOOTER_SIZE     (5) /* sizeof(struct summary_footer) */
0397 #define SUM_ENTRY_SIZE      (SUMMARY_SIZE * ENTRIES_IN_SUM)
0398 
0399 /* a summary entry for a 4KB-sized block in a segment */
0400 struct f2fs_summary {
0401     __le32 nid;     /* parent node id */
0402     union {
0403         __u8 reserved[3];
0404         struct {
0405             __u8 version;       /* node version number */
0406             __le16 ofs_in_node; /* block index in parent node */
0407         } __packed;
0408     };
0409 } __packed;
0410 
0411 /* summary block type, node or data, is stored to the summary_footer */
0412 #define SUM_TYPE_NODE       (1)
0413 #define SUM_TYPE_DATA       (0)
0414 
0415 struct summary_footer {
0416     unsigned char entry_type;   /* SUM_TYPE_XXX */
0417     __le32 check_sum;       /* summary checksum */
0418 } __packed;
0419 
0420 #define SUM_JOURNAL_SIZE    (F2FS_BLKSIZE - SUM_FOOTER_SIZE -\
0421                 SUM_ENTRY_SIZE)
0422 #define NAT_JOURNAL_ENTRIES ((SUM_JOURNAL_SIZE - 2) /\
0423                 sizeof(struct nat_journal_entry))
0424 #define NAT_JOURNAL_RESERVED    ((SUM_JOURNAL_SIZE - 2) %\
0425                 sizeof(struct nat_journal_entry))
0426 #define SIT_JOURNAL_ENTRIES ((SUM_JOURNAL_SIZE - 2) /\
0427                 sizeof(struct sit_journal_entry))
0428 #define SIT_JOURNAL_RESERVED    ((SUM_JOURNAL_SIZE - 2) %\
0429                 sizeof(struct sit_journal_entry))
0430 
0431 /* Reserved area should make size of f2fs_extra_info equals to
0432  * that of nat_journal and sit_journal.
0433  */
0434 #define EXTRA_INFO_RESERVED (SUM_JOURNAL_SIZE - 2 - 8)
0435 
0436 /*
0437  * frequently updated NAT/SIT entries can be stored in the spare area in
0438  * summary blocks
0439  */
0440 enum {
0441     NAT_JOURNAL = 0,
0442     SIT_JOURNAL
0443 };
0444 
0445 struct nat_journal_entry {
0446     __le32 nid;
0447     struct f2fs_nat_entry ne;
0448 } __packed;
0449 
0450 struct nat_journal {
0451     struct nat_journal_entry entries[NAT_JOURNAL_ENTRIES];
0452     __u8 reserved[NAT_JOURNAL_RESERVED];
0453 } __packed;
0454 
0455 struct sit_journal_entry {
0456     __le32 segno;
0457     struct f2fs_sit_entry se;
0458 } __packed;
0459 
0460 struct sit_journal {
0461     struct sit_journal_entry entries[SIT_JOURNAL_ENTRIES];
0462     __u8 reserved[SIT_JOURNAL_RESERVED];
0463 } __packed;
0464 
0465 struct f2fs_extra_info {
0466     __le64 kbytes_written;
0467     __u8 reserved[EXTRA_INFO_RESERVED];
0468 } __packed;
0469 
0470 struct f2fs_journal {
0471     union {
0472         __le16 n_nats;
0473         __le16 n_sits;
0474     };
0475     /* spare area is used by NAT or SIT journals or extra info */
0476     union {
0477         struct nat_journal nat_j;
0478         struct sit_journal sit_j;
0479         struct f2fs_extra_info info;
0480     };
0481 } __packed;
0482 
0483 /* 4KB-sized summary block structure */
0484 struct f2fs_summary_block {
0485     struct f2fs_summary entries[ENTRIES_IN_SUM];
0486     struct f2fs_journal journal;
0487     struct summary_footer footer;
0488 } __packed;
0489 
0490 /*
0491  * For directory operations
0492  */
0493 #define F2FS_DOT_HASH       0
0494 #define F2FS_DDOT_HASH      F2FS_DOT_HASH
0495 #define F2FS_MAX_HASH       (~((0x3ULL) << 62))
0496 #define F2FS_HASH_COL_BIT   ((0x1ULL) << 63)
0497 
0498 typedef __le32  f2fs_hash_t;
0499 
0500 /* One directory entry slot covers 8bytes-long file name */
0501 #define F2FS_SLOT_LEN       8
0502 #define F2FS_SLOT_LEN_BITS  3
0503 
0504 #define GET_DENTRY_SLOTS(x) (((x) + F2FS_SLOT_LEN - 1) >> F2FS_SLOT_LEN_BITS)
0505 
0506 /* MAX level for dir lookup */
0507 #define MAX_DIR_HASH_DEPTH  63
0508 
0509 /* MAX buckets in one level of dir */
0510 #define MAX_DIR_BUCKETS     (1 << ((MAX_DIR_HASH_DEPTH / 2) - 1))
0511 
0512 /*
0513  * space utilization of regular dentry and inline dentry (w/o extra reservation)
0514  *      regular dentry      inline dentry (def) inline dentry (min)
0515  * bitmap   1 * 27 = 27     1 * 23 = 23     1 * 1 = 1
0516  * reserved 1 * 3 = 3       1 * 7 = 7       1 * 1 = 1
0517  * dentry   11 * 214 = 2354     11 * 182 = 2002     11 * 2 = 22
0518  * filename 8 * 214 = 1712      8 * 182 = 1456      8 * 2 = 16
0519  * total    4096            3488            40
0520  *
0521  * Note: there are more reserved space in inline dentry than in regular
0522  * dentry, when converting inline dentry we should handle this carefully.
0523  */
0524 #define NR_DENTRY_IN_BLOCK  214 /* the number of dentry in a block */
0525 #define SIZE_OF_DIR_ENTRY   11  /* by byte */
0526 #define SIZE_OF_DENTRY_BITMAP   ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \
0527                     BITS_PER_BYTE)
0528 #define SIZE_OF_RESERVED    (PAGE_SIZE - ((SIZE_OF_DIR_ENTRY + \
0529                 F2FS_SLOT_LEN) * \
0530                 NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP))
0531 #define MIN_INLINE_DENTRY_SIZE      40  /* just include '.' and '..' entries */
0532 
0533 /* One directory entry slot representing F2FS_SLOT_LEN-sized file name */
0534 struct f2fs_dir_entry {
0535     __le32 hash_code;   /* hash code of file name */
0536     __le32 ino;     /* inode number */
0537     __le16 name_len;    /* length of file name */
0538     __u8 file_type;     /* file type */
0539 } __packed;
0540 
0541 /* 4KB-sized directory entry block */
0542 struct f2fs_dentry_block {
0543     /* validity bitmap for directory entries in each block */
0544     __u8 dentry_bitmap[SIZE_OF_DENTRY_BITMAP];
0545     __u8 reserved[SIZE_OF_RESERVED];
0546     struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK];
0547     __u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN];
0548 } __packed;
0549 
0550 /* file types used in inode_info->flags */
0551 enum {
0552     F2FS_FT_UNKNOWN,
0553     F2FS_FT_REG_FILE,
0554     F2FS_FT_DIR,
0555     F2FS_FT_CHRDEV,
0556     F2FS_FT_BLKDEV,
0557     F2FS_FT_FIFO,
0558     F2FS_FT_SOCK,
0559     F2FS_FT_SYMLINK,
0560     F2FS_FT_MAX
0561 };
0562 
0563 #define S_SHIFT 12
0564 
0565 #define F2FS_DEF_PROJID     0   /* default project ID */
0566 
0567 #endif  /* _LINUX_F2FS_FS_H */